blob: e0226d2315bb08b2e8517120058de4a94efb82c1 [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.
Sara Sharon26d6c162017-01-03 12:00:19 +02009 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * USA
25 *
26 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020027 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010028 *
29 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020030 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg8ca151b2013-01-24 14:25:36 +010031 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020035 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Sara Sharon26d6c162017-01-03 12:00:19 +020036 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
37 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010038 * All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 *
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * * Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in
48 * the documentation and/or other materials provided with the
49 * distribution.
50 * * Neither the name Intel Corporation nor the names of its
51 * contributors may be used to endorse or promote products derived
52 * from this software without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 *
66 *****************************************************************************/
67#include <linux/kernel.h>
68#include <linux/slab.h>
69#include <linux/skbuff.h>
70#include <linux/netdevice.h>
71#include <linux/etherdevice.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010072#include <linux/ip.h>
Eliad Peller2ee8f022014-01-13 19:07:09 +020073#include <linux/if_arp.h>
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +020074#include <linux/time.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010075#include <net/mac80211.h>
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +020076#include <net/ieee80211_radiotap.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010077#include <net/tcp.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010078
79#include "iwl-op-mode.h"
80#include "iwl-io.h"
81#include "mvm.h"
82#include "sta.h"
83#include "time-event.h"
84#include "iwl-eeprom-parse.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010085#include "iwl-phy-db.h"
David Spinadel507cadf2013-07-31 18:07:21 +030086#include "testmode.h"
Johannes Bergd962f9b2017-06-01 10:22:09 +020087#include "fw/error-dump.h"
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +030088#include "iwl-prph.h"
Arik Nemtsov88931cc2014-03-05 12:26:15 +020089#include "iwl-nvm-parse.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010090
91static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
92 {
93 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030094 .types = BIT(NL80211_IFTYPE_STATION),
Johannes Berg8ca151b2013-01-24 14:25:36 +010095 },
Johannes Berg3c15a0f2013-05-31 10:17:19 +020096 {
97 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030098 .types = BIT(NL80211_IFTYPE_AP) |
99 BIT(NL80211_IFTYPE_P2P_CLIENT) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200100 BIT(NL80211_IFTYPE_P2P_GO),
101 },
102 {
103 .max = 1,
104 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
105 },
Johannes Berg8ca151b2013-01-24 14:25:36 +0100106};
107
108static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
109 {
Emmanuel Grumbach2624a5c2014-12-16 13:02:03 +0200110 .num_different_channels = 2,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100111 .max_interfaces = 3,
112 .limits = iwl_mvm_limits,
113 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
114 },
115};
116
Eliad Peller77736922014-01-14 12:35:49 +0200117#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
Eliad Peller2ee8f022014-01-13 19:07:09 +0200118/*
119 * Use the reserved field to indicate magic values.
120 * these values will only be used internally by the driver,
121 * and won't make it to the fw (reserved will be 0).
122 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
123 * be the vif's ip address. in case there is not a single
124 * ip address (0, or more than 1), this attribute will
125 * be skipped.
126 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
127 * the LSB bytes of the vif's mac address
128 */
129enum {
130 BC_FILTER_MAGIC_NONE = 0,
131 BC_FILTER_MAGIC_IP,
132 BC_FILTER_MAGIC_MAC,
133};
134
Eliad Peller77736922014-01-14 12:35:49 +0200135static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
136 {
137 /* arp */
138 .discard = 0,
139 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
140 .attrs = {
141 {
142 /* frame type - arp, hw type - ethernet */
143 .offset_type =
144 BCAST_FILTER_OFFSET_PAYLOAD_START,
145 .offset = sizeof(rfc1042_header),
146 .val = cpu_to_be32(0x08060001),
147 .mask = cpu_to_be32(0xffffffff),
148 },
Eliad Peller2ee8f022014-01-13 19:07:09 +0200149 {
150 /* arp dest ip */
151 .offset_type =
152 BCAST_FILTER_OFFSET_PAYLOAD_START,
153 .offset = sizeof(rfc1042_header) + 2 +
154 sizeof(struct arphdr) +
155 ETH_ALEN + sizeof(__be32) +
156 ETH_ALEN,
157 .mask = cpu_to_be32(0xffffffff),
158 /* mark it as special field */
159 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
160 },
161 },
162 },
163 {
164 /* dhcp offer bcast */
165 .discard = 0,
166 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
167 .attrs = {
168 {
169 /* udp dest port - 68 (bootp client)*/
170 .offset_type = BCAST_FILTER_OFFSET_IP_END,
171 .offset = offsetof(struct udphdr, dest),
172 .val = cpu_to_be32(0x00440000),
173 .mask = cpu_to_be32(0xffff0000),
174 },
175 {
176 /* dhcp - lsb bytes of client hw address */
177 .offset_type = BCAST_FILTER_OFFSET_IP_END,
178 .offset = 38,
179 .mask = cpu_to_be32(0xffffffff),
180 /* mark it as special field */
181 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
182 },
Eliad Peller77736922014-01-14 12:35:49 +0200183 },
184 },
185 /* last filter must be empty */
186 {},
187};
188#endif
189
Eliad Peller7498cf42014-01-16 17:10:44 +0200190void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
191{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200192 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200193 return;
194
195 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
Eliad Peller576eeee2014-07-01 18:38:38 +0300196 spin_lock_bh(&mvm->refs_lock);
197 mvm->refs[ref_type]++;
198 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200199 iwl_trans_ref(mvm->trans);
200}
201
202void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
203{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200204 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200205 return;
206
207 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
Eliad Peller576eeee2014-07-01 18:38:38 +0300208 spin_lock_bh(&mvm->refs_lock);
Sara Sharon16c45822016-04-04 19:30:05 +0300209 if (WARN_ON(!mvm->refs[ref_type])) {
210 spin_unlock_bh(&mvm->refs_lock);
211 return;
212 }
213 mvm->refs[ref_type]--;
Eliad Peller576eeee2014-07-01 18:38:38 +0300214 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200215 iwl_trans_unref(mvm->trans);
216}
217
Eliad Peller576eeee2014-07-01 18:38:38 +0300218static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
219 enum iwl_mvm_ref_type except_ref)
Eliad Peller7498cf42014-01-16 17:10:44 +0200220{
Eliad Peller576eeee2014-07-01 18:38:38 +0300221 int i, j;
Eliad Peller7498cf42014-01-16 17:10:44 +0200222
Eliad Peller7bb426e2014-02-24 12:54:37 +0200223 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200224 return;
225
Eliad Peller576eeee2014-07-01 18:38:38 +0300226 spin_lock_bh(&mvm->refs_lock);
227 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
228 if (except_ref == i || !mvm->refs[i])
Eliad Peller7498cf42014-01-16 17:10:44 +0200229 continue;
230
Eliad Peller576eeee2014-07-01 18:38:38 +0300231 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
232 i, mvm->refs[i]);
233 for (j = 0; j < mvm->refs[i]; j++)
234 iwl_trans_unref(mvm->trans);
235 mvm->refs[i] = 0;
Eliad Peller7498cf42014-01-16 17:10:44 +0200236 }
Eliad Peller576eeee2014-07-01 18:38:38 +0300237 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200238}
239
Eliad Pellerf4cf8682014-11-04 16:57:06 +0200240bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
241{
242 int i;
243 bool taken = false;
244
245 if (!iwl_mvm_is_d0i3_supported(mvm))
246 return true;
247
248 spin_lock_bh(&mvm->refs_lock);
249 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
250 if (mvm->refs[i]) {
251 taken = true;
252 break;
253 }
254 }
255 spin_unlock_bh(&mvm->refs_lock);
256
257 return taken;
258}
259
Eliad Peller576eeee2014-07-01 18:38:38 +0300260int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
Gregory Greenmand40fc482014-06-25 14:08:50 +0200261{
262 iwl_mvm_ref(mvm, ref_type);
263
264 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
265 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
266 HZ)) {
267 WARN_ON_ONCE(1);
268 iwl_mvm_unref(mvm, ref_type);
269 return -EIO;
270 }
271
272 return 0;
273}
274
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200275static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
276{
277 int i;
278
279 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
280 for (i = 0; i < NUM_PHY_CTX; i++) {
281 mvm->phy_ctxts[i].id = i;
282 mvm->phy_ctxts[i].ref = 0;
283 }
284}
285
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200286struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200287 const char *alpha2,
Jonathan Doron47c8b152014-11-27 16:55:25 +0200288 enum iwl_mcc_source src_id,
289 bool *changed)
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200290{
291 struct ieee80211_regdomain *regd = NULL;
292 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
293 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
294 struct iwl_mcc_update_resp *resp;
295
296 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
297
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200298 lockdep_assert_held(&mvm->mutex);
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200299
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200300 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200301 if (IS_ERR_OR_NULL(resp)) {
302 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
Nicholas Krauseb8c474d2015-05-23 20:53:21 -0400303 PTR_ERR_OR_ZERO(resp));
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200304 goto out;
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200305 }
306
Jonathan Doron47c8b152014-11-27 16:55:25 +0200307 if (changed)
308 *changed = (resp->status == MCC_RESP_NEW_CHAN_PROFILE);
309
Arik Nemtsov162ee3c2014-06-10 11:25:35 +0300310 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200311 __le32_to_cpu(resp->n_channels),
312 resp->channels,
313 __le16_to_cpu(resp->mcc));
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200314 /* Store the return source id */
315 src_id = resp->source_id;
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200316 kfree(resp);
317 if (IS_ERR_OR_NULL(regd)) {
318 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
Nicholas Krauseb8c474d2015-05-23 20:53:21 -0400319 PTR_ERR_OR_ZERO(regd));
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200320 goto out;
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200321 }
322
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200323 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
324 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200325 mvm->lar_regdom_set = true;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200326 mvm->mcc_src = src_id;
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200327
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200328out:
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200329 return regd;
330}
331
Jonathan Doron47c8b152014-11-27 16:55:25 +0200332void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
333{
334 bool changed;
335 struct ieee80211_regdomain *regd;
336
337 if (!iwl_mvm_is_lar_supported(mvm))
338 return;
339
340 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
341 if (!IS_ERR_OR_NULL(regd)) {
342 /* only update the regulatory core if changed */
343 if (changed)
344 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
345
346 kfree(regd);
347 }
348}
349
350struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
351 bool *changed)
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200352{
353 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
354 iwl_mvm_is_wifi_mcc_supported(mvm) ?
355 MCC_SOURCE_GET_CURRENT :
Jonathan Doron47c8b152014-11-27 16:55:25 +0200356 MCC_SOURCE_OLD_FW, changed);
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200357}
358
359int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
360{
361 enum iwl_mcc_source used_src;
362 struct ieee80211_regdomain *regd;
Arik Nemtsovb6e160a2015-03-23 14:32:53 +0200363 int ret;
364 bool changed;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200365 const struct ieee80211_regdomain *r =
366 rtnl_dereference(mvm->hw->wiphy->regd);
367
368 if (!r)
Arik Nemtsovb6e160a2015-03-23 14:32:53 +0200369 return -ENOENT;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200370
371 /* save the last source in case we overwrite it below */
372 used_src = mvm->mcc_src;
373 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
374 /* Notify the firmware we support wifi location updates */
Jonathan Doron47c8b152014-11-27 16:55:25 +0200375 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200376 if (!IS_ERR_OR_NULL(regd))
377 kfree(regd);
378 }
379
380 /* Now set our last stored MCC and source */
Arik Nemtsovb6e160a2015-03-23 14:32:53 +0200381 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
382 &changed);
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200383 if (IS_ERR_OR_NULL(regd))
384 return -EIO;
385
Arik Nemtsovb6e160a2015-03-23 14:32:53 +0200386 /* update cfg80211 if the regdomain was changed */
387 if (changed)
388 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
389 else
390 ret = 0;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200391
Arik Nemtsovb6e160a2015-03-23 14:32:53 +0200392 kfree(regd);
393 return ret;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200394}
395
Johannes Berg8ca151b2013-01-24 14:25:36 +0100396int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
397{
398 struct ieee80211_hw *hw = mvm->hw;
Ilan Peer831e85f2013-02-07 17:09:09 +0200399 int num_mac, ret, i;
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200400 static const u32 mvm_ciphers[] = {
401 WLAN_CIPHER_SUITE_WEP40,
402 WLAN_CIPHER_SUITE_WEP104,
403 WLAN_CIPHER_SUITE_TKIP,
404 WLAN_CIPHER_SUITE_CCMP,
405 };
Johannes Berg8ca151b2013-01-24 14:25:36 +0100406
407 /* Tell mac80211 our characteristics */
Johannes Berg30686bf2015-06-02 21:39:54 +0200408 ieee80211_hw_set(hw, SIGNAL_DBM);
409 ieee80211_hw_set(hw, SPECTRUM_MGMT);
410 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
411 ieee80211_hw_set(hw, QUEUE_CONTROL);
412 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
413 ieee80211_hw_set(hw, SUPPORTS_PS);
414 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
415 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
416 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
417 ieee80211_hw_set(hw, CONNECTION_MONITOR);
418 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
419 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
420 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
Johannes Berg909ddf02015-09-21 14:09:17 +0200421 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
Johannes Berg30433d32015-09-24 18:14:55 +0200422 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
Sara Sharonb915c102016-03-23 16:32:02 +0200423 if (iwl_mvm_has_new_rx_api(mvm))
424 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
Johannes Berg960f8642017-06-20 15:18:43 +0200425
426 if (fw_has_capa(&mvm->fw->ucode_capa,
427 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
Johannes Berg65e25482016-04-13 14:24:22 +0200428 ieee80211_hw_set(hw, AP_LINK_PS);
Johannes Berg960f8642017-06-20 15:18:43 +0200429 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
430 /*
431 * we absolutely need this for the new TX API since that comes
432 * with many more queues than the current code can deal with
433 * for station powersave
434 */
435 return -EINVAL;
436 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100437
Johannes Berg80938ab2016-03-30 11:05:16 +0200438 if (mvm->trans->num_rx_queues > 1)
439 ieee80211_hw_set(hw, USES_RSS);
440
Johannes Berg2d7cf542015-04-17 16:39:12 +0200441 if (mvm->trans->max_skb_frags)
442 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
443
Johannes Bergc8f54702017-06-19 23:50:31 +0200444 hw->queues = IEEE80211_MAX_QUEUES;
Ilan Peer398e8c62013-03-13 15:20:35 +0200445 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +0200446 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
447 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
Eyal Shapira339b3082014-11-18 16:43:55 +0200448 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
449 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
Johannes Berg371a17e2016-08-15 09:26:32 +0200450
451 hw->radiotap_timestamp.units_pos =
452 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
453 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
454 /* this is the case for CCK frames, it's better (only 8) for OFDM */
455 hw->radiotap_timestamp.accuracy = 22;
456
Johannes Berg8ca151b2013-01-24 14:25:36 +0100457 hw->rate_control_algorithm = "iwl-mvm-rs";
Johannes Berg848955c2014-11-11 12:48:42 +0100458 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
459 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100460
Ayala Beker8e160ab2016-04-11 11:37:38 +0300461 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200462 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
463 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
464 hw->wiphy->cipher_suites = mvm->ciphers;
465
Ayala Beker2a53d162016-04-07 16:21:57 +0300466 if (iwl_mvm_has_new_rx_api(mvm)) {
467 mvm->ciphers[hw->wiphy->n_cipher_suites] =
468 WLAN_CIPHER_SUITE_GCMP;
469 hw->wiphy->n_cipher_suites++;
470 mvm->ciphers[hw->wiphy->n_cipher_suites] =
471 WLAN_CIPHER_SUITE_GCMP_256;
472 hw->wiphy->n_cipher_suites++;
473 }
474
Luca Coelho4b87e5a2016-09-12 16:03:30 +0300475 /* Enable 11w if software crypto is not enabled (as the
476 * firmware will interpret some mgmt packets, so enabling it
477 * with software crypto isn't safe).
Johannes Berg8ca151b2013-01-24 14:25:36 +0100478 */
Johannes Berg3b37f4c2017-05-30 16:45:31 +0200479 if (!iwlwifi_mod_params.swcrypto) {
Johannes Berg30686bf2015-06-02 21:39:54 +0200480 ieee80211_hw_set(hw, MFP_CAPABLE);
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200481 mvm->ciphers[hw->wiphy->n_cipher_suites] =
482 WLAN_CIPHER_SUITE_AES_CMAC;
483 hw->wiphy->n_cipher_suites++;
Ayala Beker8e160ab2016-04-11 11:37:38 +0300484 if (iwl_mvm_has_new_rx_api(mvm)) {
485 mvm->ciphers[hw->wiphy->n_cipher_suites] =
486 WLAN_CIPHER_SUITE_BIP_GMAC_128;
487 hw->wiphy->n_cipher_suites++;
488 mvm->ciphers[hw->wiphy->n_cipher_suites] =
489 WLAN_CIPHER_SUITE_BIP_GMAC_256;
490 hw->wiphy->n_cipher_suites++;
491 }
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200492 }
493
494 /* currently FW API supports only one optional cipher scheme */
495 if (mvm->fw->cs[0].cipher) {
Johannes Berg24ddddf2016-06-21 12:34:36 +0200496 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
497 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
498
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200499 mvm->hw->n_cipher_schemes = 1;
Johannes Berg24ddddf2016-06-21 12:34:36 +0200500
501 cs->cipher = le32_to_cpu(fwcs->cipher);
502 cs->iftype = BIT(NL80211_IFTYPE_STATION);
503 cs->hdr_len = fwcs->hdr_len;
504 cs->pn_len = fwcs->pn_len;
505 cs->pn_off = fwcs->pn_off;
506 cs->key_idx_off = fwcs->key_idx_off;
507 cs->key_idx_mask = fwcs->key_idx_mask;
508 cs->key_idx_shift = fwcs->key_idx_shift;
509 cs->mic_len = fwcs->mic_len;
510
511 mvm->hw->cipher_schemes = mvm->cs;
512 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200513 hw->wiphy->n_cipher_suites++;
514 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100515
Johannes Berg30686bf2015-06-02 21:39:54 +0200516 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
Luciano Coelho1f940382015-02-10 13:03:38 +0200517 hw->wiphy->features |=
518 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
Johannes Berg3db93422015-05-06 14:56:51 +0200519 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
520 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
David Spinadelfb98be52014-05-04 12:51:10 +0300521
Johannes Berg8ca151b2013-01-24 14:25:36 +0100522 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
523 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200524 hw->chanctx_data_size = sizeof(u16);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100525
526 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200527 BIT(NL80211_IFTYPE_P2P_CLIENT) |
528 BIT(NL80211_IFTYPE_AP) |
529 BIT(NL80211_IFTYPE_P2P_GO) |
Emmanuel Grumbachc13b1722014-03-27 19:12:12 +0200530 BIT(NL80211_IFTYPE_P2P_DEVICE) |
531 BIT(NL80211_IFTYPE_ADHOC);
Johannes Berg5023d962013-07-31 14:07:43 +0200532
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +0100533 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200534 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
535 if (iwl_mvm_is_lar_supported(mvm))
536 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
537 else
538 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
539 REGULATORY_DISABLE_BEACON_HINTS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100540
Luca Coelho4b87e5a2016-09-12 16:03:30 +0300541 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Emmanuel Grumbach94bbed72014-11-24 08:53:33 +0200542 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +0200543
Johannes Berg8ca151b2013-01-24 14:25:36 +0100544 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
545 hw->wiphy->n_iface_combinations =
546 ARRAY_SIZE(iwl_mvm_iface_combinations);
547
Ilan Peerc451e6d2013-02-20 08:41:54 +0200548 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100549 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
Emmanuel Grumbachf1a68542014-12-16 12:31:13 +0200550 /* we can compensate an offset of up to 3 channels = 15 MHz */
551 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100552
553 /* Extract MAC address */
554 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
555 hw->wiphy->addresses = mvm->addresses;
556 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200557
558 /* Extract additional MAC addresses if available */
559 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
560 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
561
562 for (i = 1; i < num_mac; i++) {
563 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100564 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200565 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100566 hw->wiphy->n_addresses++;
567 }
568
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200569 iwl_mvm_reset_phy_ctxts(mvm);
570
Luciano Coelho999d2562015-03-27 10:28:26 +0300571 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
David Spinadel20f1a5d2013-08-21 09:14:27 +0300572
Johannes Berg8ca151b2013-01-24 14:25:36 +0100573 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
574
Luciano Coelhoc7d42482015-05-07 16:00:26 +0300575 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
Luciano Coelho507e4cd2015-03-19 22:58:33 +0200576 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
577 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
578
Johannes Berg859d9142015-06-01 17:11:11 +0200579 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
Luciano Coelho507e4cd2015-03-19 22:58:33 +0200580 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
581 else
582 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
583
Johannes Berg57fbcce2016-04-12 15:56:15 +0200584 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
585 hw->wiphy->bands[NL80211_BAND_2GHZ] =
586 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
587 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
588 hw->wiphy->bands[NL80211_BAND_5GHZ] =
589 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
Johannes Berg8ca151b2013-01-24 14:25:36 +0100590
Johannes Berg859d9142015-06-01 17:11:11 +0200591 if (fw_has_capa(&mvm->fw->ucode_capa,
592 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
593 fw_has_api(&mvm->fw->ucode_capa,
594 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
Johannes Berg57fbcce2016-04-12 15:56:15 +0200595 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
Eyal Shapira3d44eeb2015-01-16 22:37:04 +0200596 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
597 }
598
Johannes Berg8ca151b2013-01-24 14:25:36 +0100599 hw->wiphy->hw_version = mvm->trans->hw_id;
600
Alexander Bondarade50652013-04-03 16:28:47 +0300601 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100602 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
603 else
604 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
605
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100606 hw->wiphy->max_sched_scan_reqs = 1;
Emmanuel Grumbach9954b372015-03-16 14:49:55 +0200607 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
608 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
609 /* we create the 802.11 header and zero length SSID IE. */
610 hw->wiphy->max_sched_scan_ie_len =
611 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
Avraham Sterncd55cce2015-08-19 12:46:12 +0300612 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
613 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
614
615 /*
616 * the firmware uses u8 for num of iterations, but 0xff is saved for
617 * infinite loop, so the maximum number of iterations is actually 254.
618 */
619 hw->wiphy->max_sched_scan_plan_iterations = 254;
David Spinadel35a000b2013-08-28 09:29:43 +0300620
Johannes Berg8ca151b2013-01-24 14:25:36 +0100621 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
Johannes Bergab480032014-06-04 10:13:50 +0200622 NL80211_FEATURE_LOW_PRIORITY_SCAN |
Eliad Peller0d8614b2014-09-10 14:07:36 +0300623 NL80211_FEATURE_P2P_GO_OPPPS |
Peer, Ilana904a082016-08-10 13:48:35 +0300624 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
Eliad Peller0d8614b2014-09-10 14:07:36 +0300625 NL80211_FEATURE_DYNAMIC_SMPS |
Emmanuel Grumbach9b5452f2014-10-07 10:38:53 +0300626 NL80211_FEATURE_STATIC_SMPS |
627 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100628
Johannes Berg859d9142015-06-01 17:11:11 +0200629 if (fw_has_capa(&mvm->fw->ucode_capa,
630 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300631 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
Johannes Berg859d9142015-06-01 17:11:11 +0200632 if (fw_has_capa(&mvm->fw->ucode_capa,
633 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
Assaf Krauss226bcd42014-03-13 08:12:15 +0200634 hw->wiphy->features |= NL80211_FEATURE_QUIET;
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300635
Johannes Berg859d9142015-06-01 17:11:11 +0200636 if (fw_has_capa(&mvm->fw->ucode_capa,
637 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300638 hw->wiphy->features |=
639 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
640
Johannes Berg859d9142015-06-01 17:11:11 +0200641 if (fw_has_capa(&mvm->fw->ucode_capa,
642 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300643 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
644
Avrahams Sternaacf8f12016-07-19 11:15:09 +0300645 if (fw_has_api(&mvm->fw->ucode_capa,
646 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
647 wiphy_ext_feature_set(hw->wiphy,
648 NL80211_EXT_FEATURE_SCAN_START_TIME);
649 wiphy_ext_feature_set(hw->wiphy,
650 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
651 wiphy_ext_feature_set(hw->wiphy,
652 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
653 }
654
Johannes Berg8ca151b2013-01-24 14:25:36 +0100655 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
656
657#ifdef CONFIG_PM_SLEEP
Eliad Pellerd15a7472014-03-27 18:53:12 +0200658 if (iwl_mvm_is_d0i3_supported(mvm) &&
659 device_can_wakeup(mvm->trans->dev)) {
660 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
661 hw->wiphy->wowlan = &mvm->wowlan;
Eliad Peller91742442014-12-09 15:54:46 +0200662 }
663
Sara Sharoneef187a2016-10-25 11:38:31 +0300664 if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100665 mvm->trans->ops->d3_suspend &&
666 mvm->trans->ops->d3_resume &&
667 device_can_wakeup(mvm->trans->dev)) {
Eliad Peller91742442014-12-09 15:54:46 +0200668 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
669 WIPHY_WOWLAN_DISCONNECT |
670 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
671 WIPHY_WOWLAN_RFKILL_RELEASE |
672 WIPHY_WOWLAN_NET_DETECT;
Johannes Berg3b37f4c2017-05-30 16:45:31 +0200673 if (!iwlwifi_mod_params.swcrypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200674 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
675 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
676 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100677
Johannes Berg964dc9e2013-06-03 17:25:34 +0200678 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
679 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
680 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
Luciano Coelhoc55385f2014-10-24 10:39:51 +0300681 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
Johannes Berg964dc9e2013-06-03 17:25:34 +0200682 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100683 }
684#endif
685
Eliad Peller77736922014-01-14 12:35:49 +0200686#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
687 /* assign default bcast filtering configuration */
688 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
689#endif
690
Johannes Berg8ca151b2013-01-24 14:25:36 +0100691 ret = iwl_mvm_leds_init(mvm);
692 if (ret)
693 return ret;
694
Johannes Berg859d9142015-06-01 17:11:11 +0200695 if (fw_has_capa(&mvm->fw->ucode_capa,
696 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
Arik Nemtsovd8f1c512014-05-11 18:13:04 +0300697 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
698 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
Arik Nemtsov7c4f0842015-04-30 18:31:45 +0300699 ieee80211_hw_set(hw, TDLS_WIDER_BW);
Arik Nemtsovd8f1c512014-05-11 18:13:04 +0300700 }
701
Johannes Berg859d9142015-06-01 17:11:11 +0200702 if (fw_has_capa(&mvm->fw->ucode_capa,
703 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +0300704 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
705 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
706 }
707
Avri Altman93190fb2014-12-27 09:09:47 +0200708 hw->netdev_features |= mvm->cfg->features;
Sara Sharon5e6a98d2016-03-10 17:40:56 +0200709 if (!iwl_mvm_is_csum_supported(mvm)) {
710 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
711 NETIF_F_RXCSUM);
712 /* We may support SW TX CSUM */
713 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
714 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
715 }
Emmanuel Grumbach41837ca92015-10-21 09:00:07 +0300716
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300717 ret = ieee80211_register_hw(mvm->hw);
718 if (ret)
719 iwl_mvm_leds_exit(mvm);
Liad Kaufmande8ba412017-03-16 13:00:59 +0200720 mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300721
Aviya Erenfeld91b08c2d2016-03-27 14:53:49 +0300722 if (mvm->cfg->vht_mu_mimo_supported)
723 wiphy_ext_feature_set(hw->wiphy,
724 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
725
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300726 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100727}
728
Arik Nemtsovb2492502014-03-13 12:21:50 +0200729static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
730 struct ieee80211_sta *sta,
731 struct sk_buff *skb)
732{
733 struct iwl_mvm_sta *mvmsta;
734 bool defer = false;
735
736 /*
737 * double check the IN_D0I3 flag both before and after
738 * taking the spinlock, in order to prevent taking
739 * the spinlock when not needed.
740 */
741 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
742 return false;
743
744 spin_lock(&mvm->d0i3_tx_lock);
745 /*
746 * testing the flag again ensures the skb dequeue
747 * loop (on d0i3 exit) hasn't run yet.
748 */
749 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
750 goto out;
751
752 mvmsta = iwl_mvm_sta_from_mac80211(sta);
Sara Sharon0ae98812017-01-04 14:53:58 +0200753 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
Arik Nemtsovb2492502014-03-13 12:21:50 +0200754 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
755 goto out;
756
757 __skb_queue_tail(&mvm->d0i3_tx, skb);
758 ieee80211_stop_queues(mvm->hw);
759
760 /* trigger wakeup */
761 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
762 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
763
764 defer = true;
765out:
766 spin_unlock(&mvm->d0i3_tx_lock);
767 return defer;
768}
769
Johannes Berg8ca151b2013-01-24 14:25:36 +0100770static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
771 struct ieee80211_tx_control *control,
772 struct sk_buff *skb)
773{
774 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg3e56ead2013-02-15 22:23:18 +0100775 struct ieee80211_sta *sta = control->sta;
776 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
777 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100778
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300779 if (iwl_mvm_is_radio_killed(mvm)) {
780 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100781 goto drop;
782 }
783
Emmanuel Grumbachd20e30a2017-06-25 10:38:12 +0300784 if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Matti Gottlieba6cc5162014-09-29 11:46:04 +0300785 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
786 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100787 goto drop;
788
David Spinadeleb045e62017-08-17 17:28:22 +0300789 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
790 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
791 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
792 ieee80211_is_mgmt(hdr->frame_control) &&
793 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
Johannes Berg3e56ead2013-02-15 22:23:18 +0100794 sta = NULL;
795
796 if (sta) {
Arik Nemtsovb2492502014-03-13 12:21:50 +0200797 if (iwl_mvm_defer_tx(mvm, sta, skb))
798 return;
Johannes Berg3e56ead2013-02-15 22:23:18 +0100799 if (iwl_mvm_tx_skb(mvm, skb, sta))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100800 goto drop;
801 return;
802 }
803
804 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
805 goto drop;
806 return;
807 drop:
808 ieee80211_free_txskb(hw, skb);
809}
810
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200811static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
812{
813 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
814 return false;
815 return true;
816}
817
818static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
819{
820 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
821 return false;
822 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
823 return true;
824
825 /* enabled by default */
826 return true;
827}
828
Johannes Berg7174beb2017-06-01 16:03:19 +0200829#define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
830 do { \
831 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
832 break; \
833 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
Emmanuel Grumbach42032632015-04-15 12:43:46 +0300834 } while (0)
835
836static void
837iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
838 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
839 enum ieee80211_ampdu_mlme_action action)
840{
841 struct iwl_fw_dbg_trigger_tlv *trig;
842 struct iwl_fw_dbg_trigger_ba *ba_trig;
843
844 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
845 return;
846
847 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
848 ba_trig = (void *)trig->data;
849
Johannes Berg7174beb2017-06-01 16:03:19 +0200850 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
851 ieee80211_vif_to_wdev(vif), trig))
Emmanuel Grumbach42032632015-04-15 12:43:46 +0300852 return;
853
854 switch (action) {
855 case IEEE80211_AMPDU_TX_OPERATIONAL: {
856 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
857 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
858
859 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
860 "TX AGG START: MAC %pM tid %d ssn %d\n",
861 sta->addr, tid, tid_data->ssn);
862 break;
863 }
864 case IEEE80211_AMPDU_TX_STOP_CONT:
865 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
866 "TX AGG STOP: MAC %pM tid %d\n",
867 sta->addr, tid);
868 break;
869 case IEEE80211_AMPDU_RX_START:
870 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
871 "RX AGG START: MAC %pM tid %d ssn %d\n",
872 sta->addr, tid, rx_ba_ssn);
873 break;
874 case IEEE80211_AMPDU_RX_STOP:
875 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
876 "RX AGG STOP: MAC %pM tid %d\n",
877 sta->addr, tid);
878 break;
879 default:
880 break;
881 }
882}
883
Johannes Berg8ca151b2013-01-24 14:25:36 +0100884static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
885 struct ieee80211_vif *vif,
Sara Sharon50ea05e2015-12-30 16:06:04 +0200886 struct ieee80211_ampdu_params *params)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100887{
888 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
889 int ret;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200890 bool tx_agg_ref = false;
Sara Sharon50ea05e2015-12-30 16:06:04 +0200891 struct ieee80211_sta *sta = params->sta;
892 enum ieee80211_ampdu_mlme_action action = params->action;
893 u16 tid = params->tid;
894 u16 *ssn = &params->ssn;
895 u8 buf_size = params->buf_size;
Emmanuel Grumbachbb81bb62015-10-26 16:00:29 +0200896 bool amsdu = params->amsdu;
Sara Sharon10b2b202016-03-20 16:23:41 +0200897 u16 timeout = params->timeout;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100898
899 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
900 sta->addr, tid, action);
901
902 if (!(mvm->nvm_data->sku_cap_11n_enable))
903 return -EACCES;
904
Arik Nemtsovb2492502014-03-13 12:21:50 +0200905 /* return from D0i3 before starting a new Tx aggregation */
Eliad Peller9256c202014-04-22 13:33:29 +0300906 switch (action) {
907 case IEEE80211_AMPDU_TX_START:
908 case IEEE80211_AMPDU_TX_STOP_CONT:
909 case IEEE80211_AMPDU_TX_STOP_FLUSH:
910 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
911 case IEEE80211_AMPDU_TX_OPERATIONAL:
Arik Nemtsovb2492502014-03-13 12:21:50 +0200912 /*
Eliad Peller9256c202014-04-22 13:33:29 +0300913 * for tx start, wait synchronously until D0i3 exit to
914 * get the correct sequence number for the tid.
915 * additionally, some other ampdu actions use direct
916 * target access, which is not handled automatically
917 * by the trans layer (unlike commands), so wait for
918 * d0i3 exit in these cases as well.
Arik Nemtsovb2492502014-03-13 12:21:50 +0200919 */
Gregory Greenmand40fc482014-06-25 14:08:50 +0200920 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
921 if (ret)
922 return ret;
923
924 tx_agg_ref = true;
Eliad Peller9256c202014-04-22 13:33:29 +0300925 break;
926 default:
927 break;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200928 }
929
Johannes Berg8ca151b2013-01-24 14:25:36 +0100930 mutex_lock(&mvm->mutex);
931
932 switch (action) {
933 case IEEE80211_AMPDU_RX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200934 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100935 ret = -EINVAL;
936 break;
937 }
Sara Sharon10b2b202016-03-20 16:23:41 +0200938 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
939 timeout);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100940 break;
941 case IEEE80211_AMPDU_RX_STOP:
Sara Sharon10b2b202016-03-20 16:23:41 +0200942 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
943 timeout);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100944 break;
945 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200946 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200947 ret = -EINVAL;
948 break;
949 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100950 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
951 break;
952 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200953 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
954 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100955 case IEEE80211_AMPDU_TX_STOP_FLUSH:
956 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200957 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100958 break;
959 case IEEE80211_AMPDU_TX_OPERATIONAL:
Emmanuel Grumbachbb81bb62015-10-26 16:00:29 +0200960 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
961 buf_size, amsdu);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100962 break;
963 default:
964 WARN_ON_ONCE(1);
965 ret = -EINVAL;
966 break;
967 }
Emmanuel Grumbach42032632015-04-15 12:43:46 +0300968
969 if (!ret) {
970 u16 rx_ba_ssn = 0;
971
972 if (action == IEEE80211_AMPDU_RX_START)
973 rx_ba_ssn = *ssn;
974
975 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
976 rx_ba_ssn, action);
977 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100978 mutex_unlock(&mvm->mutex);
979
Arik Nemtsovb2492502014-03-13 12:21:50 +0200980 /*
981 * If the tid is marked as started, we won't use it for offloaded
982 * traffic on the next D0i3 entry. It's safe to unref.
983 */
984 if (tx_agg_ref)
985 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
986
Johannes Berg8ca151b2013-01-24 14:25:36 +0100987 return ret;
988}
989
990static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
991 struct ieee80211_vif *vif)
992{
993 struct iwl_mvm *mvm = data;
994 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
995
996 mvmvif->uploaded = false;
Sara Sharon0ae98812017-01-04 14:53:58 +0200997 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100998
Johannes Berg8ca151b2013-01-24 14:25:36 +0100999 spin_lock_bh(&mvm->time_event_lock);
1000 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1001 spin_unlock_bh(&mvm->time_event_lock);
1002
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001003 mvmvif->phy_ctxt = NULL;
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +03001004 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001005}
1006
1007static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1008{
Johannes Berg58629d92014-11-06 09:40:50 +01001009 /* clear the D3 reconfig, we only need it to avoid dumping a
1010 * firmware coredump on reconfiguration, we shouldn't do that
1011 * on D3->D0 transition
1012 */
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001013 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
Johannes Berg7174beb2017-06-01 16:03:19 +02001014 mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
1015 iwl_fw_error_dump(&mvm->fwrt);
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001016 }
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +02001017
Eliad Peller744cb692014-12-10 18:44:13 +02001018 /* cleanup all stale references (scan, roc), but keep the
1019 * ucode_down ref until reconfig is complete
1020 */
1021 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1022
Chaya Rachel Ivgifcb6b922016-02-22 10:21:41 +02001023 iwl_mvm_stop_device(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001024
Luciano Coelho9af91f42015-02-10 10:42:26 +02001025 mvm->scan_status = 0;
Luciano Coelhob1873302014-08-08 17:12:07 +03001026 mvm->ps_disabled = false;
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +02001027 mvm->calibrating = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001028
1029 /* just in case one was running */
Eliad Peller305d2362015-12-09 16:33:20 +02001030 iwl_mvm_cleanup_roc_te(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001031 ieee80211_remain_on_channel_expired(mvm->hw);
1032
Arik Nemtsov737719f2015-02-23 14:42:41 +02001033 /*
1034 * cleanup all interfaces, even inactive ones, as some might have
1035 * gone down during the HW restart
1036 */
1037 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001038
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001039 mvm->p2p_device_vif = NULL;
Sara Sharon0ae98812017-01-04 14:53:58 +02001040 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001041
1042 iwl_mvm_reset_phy_ctxts(mvm);
Luca Coelho9c3deeb2015-11-11 01:06:17 +02001043 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
Liad Kaufman24afba72015-07-28 18:56:08 +03001044 memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +03001045 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +03001046 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001047
1048 ieee80211_wake_queues(mvm->hw);
1049
Eliad Peller228670b2014-08-10 17:00:15 +03001050 /* clear any stale d0i3 state */
1051 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1052
Johannes Berg8ca151b2013-01-24 14:25:36 +01001053 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03001054 mvm->rx_ba_sessions = 0;
Johannes Berg7174beb2017-06-01 16:03:19 +02001055 mvm->fwrt.dump.conf = FW_DBG_INVALID;
Shaul Triebitzbaf41bc2017-09-13 16:46:14 +03001056 mvm->monitor_on = false;
Johannes Berg91a8bcd2015-01-14 18:12:41 +01001057
1058 /* keep statistics ticking */
1059 iwl_mvm_accu_radio_stats(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001060}
1061
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001062int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001063{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001064 int ret;
1065
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001066 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001067
Johannes Bergbf8b2862017-06-30 10:48:28 +02001068 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1069 /*
1070 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1071 * so later code will - from now on - see that we're doing it.
1072 */
1073 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1074 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
Luca Coelhoa42b2af32015-11-25 22:15:32 +02001075 /* Clean up some internal and mac80211 state on restart */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001076 iwl_mvm_restart_cleanup(mvm);
Luca Coelhoa42b2af32015-11-25 22:15:32 +02001077 } else {
1078 /* Hold the reference to prevent runtime suspend while
1079 * the start procedure runs. It's a bit confusing
1080 * that the UCODE_DOWN reference is taken, but it just
1081 * means "UCODE is not UP yet". ( TODO: rename this
1082 * reference).
1083 */
1084 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1085 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001086 ret = iwl_mvm_up(mvm);
Johannes Bergc47af222014-04-30 16:34:45 +02001087
1088 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1089 /* Something went wrong - we need to finish some cleanup
1090 * that normally iwl_mvm_mac_restart_complete() below
1091 * would do.
1092 */
1093 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1094 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1095 }
1096
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001097 return ret;
1098}
1099
1100static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1101{
1102 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1103 int ret;
1104
Eliad Peller37948fc2014-12-11 10:48:18 +02001105 /* Some hw restart cleanups must not hold the mutex */
1106 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1107 /*
1108 * Make sure we are out of d0i3. This is needed
1109 * to make sure the reference accounting is correct
1110 * (and there is no stale d0i3_exit_work).
1111 */
1112 wait_event_timeout(mvm->d0i3_exit_waitq,
1113 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1114 &mvm->status),
1115 HZ);
1116 }
1117
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001118 mutex_lock(&mvm->mutex);
1119 ret = __iwl_mvm_mac_start(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001120 mutex_unlock(&mvm->mutex);
1121
1122 return ret;
1123}
1124
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001125static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001126{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001127 int ret;
1128
1129 mutex_lock(&mvm->mutex);
1130
1131 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
Arik Nemtsovb2492502014-03-13 12:21:50 +02001132 iwl_mvm_d0i3_enable_tx(mvm, NULL);
Johannes Berge7afe892015-04-21 09:21:46 +02001133 ret = iwl_mvm_update_quotas(mvm, true, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001134 if (ret)
1135 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1136 ret);
1137
Eliad Peller7498cf42014-01-16 17:10:44 +02001138 /* allow transport/FW low power modes */
1139 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1140
Arik Nemtsovcbd2ae22014-09-14 19:13:54 +03001141 /*
1142 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1143 * of packets the FW sent out, so we must reconnect.
1144 */
1145 iwl_mvm_teardown_tdls_peers(mvm);
1146
Johannes Berg8ca151b2013-01-24 14:25:36 +01001147 mutex_unlock(&mvm->mutex);
1148}
1149
Eliad Peller088070a22014-10-20 18:42:58 +03001150static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1151{
Luca Coelhob7282642015-09-17 23:44:14 +03001152 if (iwl_mvm_is_d0i3_supported(mvm) &&
1153 iwl_mvm_enter_d0i3_on_suspend(mvm))
1154 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1155 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1156 &mvm->status),
1157 HZ),
1158 "D0i3 exit on resume timed out\n");
Eliad Peller088070a22014-10-20 18:42:58 +03001159}
1160
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001161static void
1162iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1163 enum ieee80211_reconfig_type reconfig_type)
1164{
1165 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1166
1167 switch (reconfig_type) {
1168 case IEEE80211_RECONFIG_TYPE_RESTART:
1169 iwl_mvm_restart_complete(mvm);
1170 break;
1171 case IEEE80211_RECONFIG_TYPE_SUSPEND:
Eliad Peller088070a22014-10-20 18:42:58 +03001172 iwl_mvm_resume_complete(mvm);
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001173 break;
1174 }
1175}
1176
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001177void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001178{
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001179 lockdep_assert_held(&mvm->mutex);
Eliad Peller7498cf42014-01-16 17:10:44 +02001180
Johannes Berg91a8bcd2015-01-14 18:12:41 +01001181 /* firmware counters are obviously reset now, but we shouldn't
1182 * partially track so also clear the fw_reset_accu counters.
1183 */
1184 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1185
Johannes Berg8ca151b2013-01-24 14:25:36 +01001186 /* async_handlers_wk is now blocked */
1187
1188 /*
1189 * The work item could be running or queued if the
1190 * ROC time event stops just as we get here.
1191 */
Eliad Pellerc7792732015-04-19 11:41:04 +03001192 flush_work(&mvm->roc_done_wk);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001193
Chaya Rachel Ivgifcb6b922016-02-22 10:21:41 +02001194 iwl_mvm_stop_device(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001195
1196 iwl_mvm_async_handlers_purge(mvm);
1197 /* async_handlers_list is empty and will stay empty: HW is stopped */
1198
1199 /* the fw is stopped, the aux sta is dead: clean up driver state */
Johannes Berg712b24a2014-08-04 14:14:14 +02001200 iwl_mvm_del_aux_sta(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001201
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001202 /*
1203 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1204 * won't be called in this case).
Arik Nemtsov8b2b9fb2015-03-04 13:16:03 +02001205 * But make sure to cleanup interfaces that have gone down before/during
1206 * HW restart was requested.
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001207 */
Arik Nemtsov8b2b9fb2015-03-04 13:16:03 +02001208 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1209 ieee80211_iterate_interfaces(mvm->hw, 0,
1210 iwl_mvm_cleanup_iterator, mvm);
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001211
Alexander Bondar963221b2015-03-26 11:07:35 +02001212 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1213 * make sure there's nothing left there and warn if any is found.
1214 */
Johannes Berg859d9142015-06-01 17:11:11 +02001215 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
Alexander Bondar963221b2015-03-26 11:07:35 +02001216 int i;
1217
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001218 for (i = 0; i < mvm->max_scans; i++) {
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001219 if (WARN_ONCE(mvm->scan_uid_status[i],
1220 "UMAC scan UID %d status was not cleaned\n",
1221 i))
1222 mvm->scan_uid_status[i] = 0;
Alexander Bondar963221b2015-03-26 11:07:35 +02001223 }
1224 }
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001225}
Luciano Coelhobc448862014-08-20 11:49:11 +03001226
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001227static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1228{
1229 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1230
1231 flush_work(&mvm->d0i3_exit_work);
1232 flush_work(&mvm->async_handlers_wk);
Liad Kaufman24afba72015-07-28 18:56:08 +03001233 flush_work(&mvm->add_stream_wk);
Johannes Berg771147b2017-03-22 22:26:03 +01001234
1235 /*
1236 * Lock and clear the firmware running bit here already, so that
1237 * new commands coming in elsewhere, e.g. from debugfs, will not
1238 * be able to proceed. This is important here because one of those
Johannes Berg7174beb2017-06-01 16:03:19 +02001239 * debugfs files causes the firmware dump to be triggered, and if we
Johannes Berg771147b2017-03-22 22:26:03 +01001240 * don't stop debugfs accesses before canceling that it could be
1241 * retriggered after we flush it but before we've cleared the bit.
1242 */
1243 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1244
Johannes Berg7174beb2017-06-01 16:03:19 +02001245 iwl_fw_cancel_dump(&mvm->fwrt);
Andrei Otcheretianskid3a108a2016-02-28 17:12:21 +02001246 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
Luca Coelho69e04642016-05-03 12:18:33 +03001247 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
Johannes Berg7174beb2017-06-01 16:03:19 +02001248 iwl_fw_free_dump_desc(&mvm->fwrt);
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001249
1250 mutex_lock(&mvm->mutex);
1251 __iwl_mvm_mac_stop(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001252 mutex_unlock(&mvm->mutex);
1253
1254 /*
1255 * The worker might have been waiting for the mutex, let it run and
1256 * discover that its list is now empty.
1257 */
1258 cancel_work_sync(&mvm->async_handlers_wk);
1259}
1260
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001261static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1262{
1263 u16 i;
1264
1265 lockdep_assert_held(&mvm->mutex);
1266
1267 for (i = 0; i < NUM_PHY_CTX; i++)
1268 if (!mvm->phy_ctxts[i].ref)
1269 return &mvm->phy_ctxts[i];
1270
1271 IWL_ERR(mvm, "No available PHY context\n");
1272 return NULL;
1273}
1274
Avri Altmand44c3fe2015-04-18 22:16:42 +03001275static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1276 s16 tx_power)
1277{
1278 struct iwl_dev_tx_power_cmd cmd = {
Luca Coelho4b87e5a2016-09-12 16:03:30 +03001279 .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1280 .v3.mac_context_id =
Avri Altmand44c3fe2015-04-18 22:16:42 +03001281 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
Luca Coelho4b87e5a2016-09-12 16:03:30 +03001282 .v3.pwr_restriction = cpu_to_le16(8 * tx_power),
Avri Altmand44c3fe2015-04-18 22:16:42 +03001283 };
Johannes Bergda03f022015-08-18 15:15:36 +02001284 int len = sizeof(cmd);
Avri Altmand44c3fe2015-04-18 22:16:42 +03001285
Avri Altmand44c3fe2015-04-18 22:16:42 +03001286 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
Luca Coelho4b87e5a2016-09-12 16:03:30 +03001287 cmd.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
Avri Altmand44c3fe2015-04-18 22:16:42 +03001288
Luca Coelho55bfa4b2016-06-29 00:38:40 +03001289 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1290 len = sizeof(cmd.v3);
Johannes Bergda03f022015-08-18 15:15:36 +02001291
1292 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
Avri Altmand44c3fe2015-04-18 22:16:42 +03001293}
1294
Johannes Berg8ca151b2013-01-24 14:25:36 +01001295static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1296 struct ieee80211_vif *vif)
1297{
1298 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1299 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1300 int ret;
1301
Emmanuel Grumbachaa5e1832015-03-07 19:35:37 +02001302 mvmvif->mvm = mvm;
1303
Johannes Berg8ca151b2013-01-24 14:25:36 +01001304 /*
Gregory Greenmand40fc482014-06-25 14:08:50 +02001305 * make sure D0i3 exit is completed, otherwise a target access
1306 * during tx queue configuration could be done when still in
1307 * D0i3 state.
1308 */
1309 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1310 if (ret)
1311 return ret;
1312
1313 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001314 * Not much to do here. The stack will not allow interface
1315 * types or combinations that we didn't advertise, so we
1316 * don't really have to check the types.
1317 */
1318
1319 mutex_lock(&mvm->mutex);
1320
Johannes Berg33cef922015-01-21 21:41:29 +01001321 /* make sure that beacon statistics don't go backwards with FW reset */
1322 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1323 mvmvif->beacon_stats.accu_num_beacons +=
1324 mvmvif->beacon_stats.num_beacons;
1325
Eliad Pellere89044d2013-07-16 17:33:26 +03001326 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001327 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1328 if (ret)
1329 goto out_unlock;
1330
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001331 /* Counting number of interfaces is needed for legacy PM */
Ilan Peerea183d02013-07-23 14:41:53 +03001332 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1333 mvm->vif_count++;
Ilan Peerea183d02013-07-23 14:41:53 +03001334
1335 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001336 * The AP binding flow can be done only after the beacon
1337 * template is configured (which happens only in the mac80211
1338 * start_ap() flow), and adding the broadcast station can happen
1339 * only after the binding.
1340 * In addition, since modifying the MAC before adding a bcast
1341 * station is not allowed by the FW, delay the adding of MAC context to
1342 * the point where we can also add the bcast station.
1343 * In short: there's not much we can do at this point, other than
1344 * allocating resources :)
1345 */
Johannes Berg5023d962013-07-31 14:07:43 +02001346 if (vif->type == NL80211_IFTYPE_AP ||
1347 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg013290a2014-08-04 13:38:48 +02001348 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001349 if (ret) {
1350 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1351 goto out_release;
1352 }
1353
Johannes Bergc8f54702017-06-19 23:50:31 +02001354 /*
1355 * Only queue for this station is the mcast queue,
1356 * which shouldn't be in TFD mask anyway
1357 */
1358 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1359 0, vif->type,
1360 IWL_STA_MULTICAST);
1361 if (ret)
1362 goto out_release;
Sara Sharon26d6c162017-01-03 12:00:19 +02001363
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +03001364 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001365 goto out_unlock;
1366 }
1367
Avri Altman93190fb2014-12-27 09:09:47 +02001368 mvmvif->features |= hw->netdev_features;
1369
Johannes Berg8ca151b2013-01-24 14:25:36 +01001370 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1371 if (ret)
1372 goto out_release;
1373
Arik Nemtsov999609f2014-05-15 17:31:51 +03001374 ret = iwl_mvm_power_update_mac(mvm);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001375 if (ret)
Luciano Coelhofd66fc12015-01-27 15:06:57 +02001376 goto out_remove_mac;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001377
Hila Gonen7df15b12012-12-12 11:16:19 +02001378 /* beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001379 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001380 if (ret)
1381 goto out_remove_mac;
1382
Hila Gonen7df15b12012-12-12 11:16:19 +02001383 if (!mvm->bf_allowed_vif &&
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +03001384 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001385 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001386 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1387 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +02001388 }
1389
Johannes Berg8ca151b2013-01-24 14:25:36 +01001390 /*
1391 * P2P_DEVICE interface does not have a channel context assigned to it,
1392 * so a dedicated PHY context is allocated to it and the corresponding
1393 * MAC context is bound to it at this stage.
1394 */
1395 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001396
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001397 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1398 if (!mvmvif->phy_ctxt) {
1399 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001400 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001401 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001402
Ilan Peer53a9d612013-04-28 11:55:08 +03001403 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001404 ret = iwl_mvm_binding_add_vif(mvm, vif);
1405 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +03001406 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001407
Luca Coelhod1973582017-06-22 16:00:25 +03001408 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001409 if (ret)
1410 goto out_unbind;
1411
1412 /* Save a pointer to p2p device vif, so it can later be used to
1413 * update the p2p device MAC when a GO is started/stopped */
1414 mvm->p2p_device_vif = vif;
1415 }
1416
Shaul Triebitzbaf41bc2017-09-13 16:46:14 +03001417 if (vif->type == NL80211_IFTYPE_MONITOR)
1418 mvm->monitor_on = true;
1419
Johannes Berg63494372013-03-26 10:47:53 +01001420 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001421 goto out_unlock;
1422
1423 out_unbind:
1424 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +03001425 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001426 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001427 out_free_bf:
1428 if (mvm->bf_allowed_vif == mvmvif) {
1429 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001430 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1431 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001432 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001433 out_remove_mac:
1434 mvmvif->phy_ctxt = NULL;
1435 iwl_mvm_mac_ctxt_remove(mvm, vif);
1436 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001437 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1438 mvm->vif_count--;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001439 out_unlock:
1440 mutex_unlock(&mvm->mutex);
1441
Gregory Greenmand40fc482014-06-25 14:08:50 +02001442 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1443
Johannes Berg8ca151b2013-01-24 14:25:36 +01001444 return ret;
1445}
1446
Johannes Berg38a12b52013-02-22 14:07:56 +01001447static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1448 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001449{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001450 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1451 /*
1452 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1453 * We assume here that all the packets sent to the OFFCHANNEL
1454 * queue are sent in ROC session.
1455 */
1456 flush_work(&mvm->roc_done_wk);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001457 }
Johannes Berg38a12b52013-02-22 14:07:56 +01001458}
1459
1460static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1461 struct ieee80211_vif *vif)
1462{
1463 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1464 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1465
1466 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001467
1468 mutex_lock(&mvm->mutex);
1469
Hila Gonen7df15b12012-12-12 11:16:19 +02001470 if (mvm->bf_allowed_vif == mvmvif) {
1471 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001472 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1473 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +02001474 }
1475
Johannes Berg63494372013-03-26 10:47:53 +01001476 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1477
Johannes Berg8ca151b2013-01-24 14:25:36 +01001478 /*
1479 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +01001480 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001481 */
Johannes Berg5023d962013-07-31 14:07:43 +02001482 if (vif->type == NL80211_IFTYPE_AP ||
1483 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +03001484#ifdef CONFIG_NL80211_TESTMODE
1485 if (vif == mvm->noa_vif) {
1486 mvm->noa_vif = NULL;
1487 mvm->noa_duration = 0;
1488 }
1489#endif
Sara Sharon26d6c162017-01-03 12:00:19 +02001490 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
Johannes Berg013290a2014-08-04 13:38:48 +02001491 iwl_mvm_dealloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001492 goto out_release;
1493 }
1494
1495 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1496 mvm->p2p_device_vif = NULL;
Luca Coelhod1973582017-06-22 16:00:25 +03001497 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001498 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001499 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001500 mvmvif->phy_ctxt = NULL;
1501 }
1502
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001503 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001504 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001505
Arik Nemtsov999609f2014-05-15 17:31:51 +03001506 iwl_mvm_power_update_mac(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001507 iwl_mvm_mac_ctxt_remove(mvm, vif);
1508
Shaul Triebitzbaf41bc2017-09-13 16:46:14 +03001509 if (vif->type == NL80211_IFTYPE_MONITOR)
1510 mvm->monitor_on = false;
1511
Johannes Berg8ca151b2013-01-24 14:25:36 +01001512out_release:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001513 mutex_unlock(&mvm->mutex);
1514}
1515
1516static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1517{
1518 return 0;
1519}
1520
Eliad Pellere59647e2013-11-28 14:08:50 +02001521struct iwl_mvm_mc_iter_data {
1522 struct iwl_mvm *mvm;
1523 int port_id;
1524};
1525
1526static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1527 struct ieee80211_vif *vif)
1528{
1529 struct iwl_mvm_mc_iter_data *data = _data;
1530 struct iwl_mvm *mvm = data->mvm;
1531 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
Luca Coelho97bce572017-09-01 17:59:15 +03001532 struct iwl_host_cmd hcmd = {
1533 .id = MCAST_FILTER_CMD,
1534 .flags = CMD_ASYNC,
1535 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1536 };
Eliad Pellere59647e2013-11-28 14:08:50 +02001537 int ret, len;
1538
1539 /* if we don't have free ports, mcast frames will be dropped */
1540 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1541 return;
1542
1543 if (vif->type != NL80211_IFTYPE_STATION ||
1544 !vif->bss_conf.assoc)
1545 return;
1546
1547 cmd->port_id = data->port_id++;
1548 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1549 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1550
Luca Coelho97bce572017-09-01 17:59:15 +03001551 hcmd.len[0] = len;
1552 hcmd.data[0] = cmd;
1553
1554 ret = iwl_mvm_send_cmd(mvm, &hcmd);
Eliad Pellere59647e2013-11-28 14:08:50 +02001555 if (ret)
1556 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1557}
1558
1559static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1560{
1561 struct iwl_mvm_mc_iter_data iter_data = {
1562 .mvm = mvm,
1563 };
1564
1565 lockdep_assert_held(&mvm->mutex);
1566
1567 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1568 return;
1569
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001570 ieee80211_iterate_active_interfaces_atomic(
Eliad Pellere59647e2013-11-28 14:08:50 +02001571 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1572 iwl_mvm_mc_iface_iterator, &iter_data);
1573}
1574
1575static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1576 struct netdev_hw_addr_list *mc_list)
1577{
1578 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1579 struct iwl_mcast_filter_cmd *cmd;
1580 struct netdev_hw_addr *addr;
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001581 int addr_count;
1582 bool pass_all;
Eliad Pellere59647e2013-11-28 14:08:50 +02001583 int len;
1584
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001585 addr_count = netdev_hw_addr_list_count(mc_list);
1586 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1587 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1588 if (pass_all)
Eliad Pellere59647e2013-11-28 14:08:50 +02001589 addr_count = 0;
Eliad Pellere59647e2013-11-28 14:08:50 +02001590
1591 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1592 cmd = kzalloc(len, GFP_ATOMIC);
1593 if (!cmd)
1594 return 0;
1595
1596 if (pass_all) {
1597 cmd->pass_all = 1;
1598 return (u64)(unsigned long)cmd;
1599 }
1600
1601 netdev_hw_addr_list_for_each(addr, mc_list) {
1602 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1603 cmd->count, addr->addr);
1604 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1605 addr->addr, ETH_ALEN);
1606 cmd->count++;
1607 }
1608
1609 return (u64)(unsigned long)cmd;
1610}
1611
Johannes Berg8ca151b2013-01-24 14:25:36 +01001612static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1613 unsigned int changed_flags,
1614 unsigned int *total_flags,
1615 u64 multicast)
1616{
Eliad Pellere59647e2013-11-28 14:08:50 +02001617 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1618 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1619
1620 mutex_lock(&mvm->mutex);
1621
1622 /* replace previous configuration */
1623 kfree(mvm->mcast_filter_cmd);
1624 mvm->mcast_filter_cmd = cmd;
1625
1626 if (!cmd)
1627 goto out;
1628
Luca Coelho61e7d912017-09-01 18:57:35 +03001629 if (changed_flags & FIF_ALLMULTI)
1630 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1631
1632 if (cmd->pass_all)
1633 cmd->count = 0;
1634
Eliad Pellere59647e2013-11-28 14:08:50 +02001635 iwl_mvm_recalc_multicast(mvm);
1636out:
1637 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001638 *total_flags = 0;
1639}
1640
Andrei Otcheretianskieffd1922015-06-30 12:08:28 +03001641static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1642 struct ieee80211_vif *vif,
1643 unsigned int filter_flags,
1644 unsigned int changed_flags)
1645{
1646 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1647
1648 /* We support only filter for probe requests */
1649 if (!(changed_flags & FIF_PROBE_REQ))
1650 return;
1651
1652 /* Supported only for p2p client interfaces */
1653 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1654 !vif->p2p)
1655 return;
1656
1657 mutex_lock(&mvm->mutex);
1658 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1659 mutex_unlock(&mvm->mutex);
1660}
1661
Eliad Pellerc87163b2014-01-08 10:11:11 +02001662#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1663struct iwl_bcast_iter_data {
1664 struct iwl_mvm *mvm;
1665 struct iwl_bcast_filter_cmd *cmd;
1666 u8 current_filter;
1667};
1668
1669static void
1670iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1671 const struct iwl_fw_bcast_filter *in_filter,
1672 struct iwl_fw_bcast_filter *out_filter)
1673{
1674 struct iwl_fw_bcast_filter_attr *attr;
1675 int i;
1676
1677 memcpy(out_filter, in_filter, sizeof(*out_filter));
1678
1679 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1680 attr = &out_filter->attrs[i];
1681
1682 if (!attr->mask)
1683 break;
1684
Eliad Peller2ee8f022014-01-13 19:07:09 +02001685 switch (attr->reserved1) {
1686 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1687 if (vif->bss_conf.arp_addr_cnt != 1) {
1688 attr->mask = 0;
1689 continue;
1690 }
1691
1692 attr->val = vif->bss_conf.arp_addr_list[0];
1693 break;
1694 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1695 attr->val = *(__be32 *)&vif->addr[2];
1696 break;
1697 default:
1698 break;
1699 }
1700 attr->reserved1 = 0;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001701 out_filter->num_attrs++;
1702 }
1703}
1704
1705static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1706 struct ieee80211_vif *vif)
1707{
1708 struct iwl_bcast_iter_data *data = _data;
1709 struct iwl_mvm *mvm = data->mvm;
1710 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1711 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1712 struct iwl_fw_bcast_mac *bcast_mac;
1713 int i;
1714
1715 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1716 return;
1717
1718 bcast_mac = &cmd->macs[mvmvif->id];
1719
Ilan Peere48393e2014-05-22 11:19:02 +03001720 /*
1721 * enable filtering only for associated stations, but not for P2P
1722 * Clients
1723 */
1724 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1725 !vif->bss_conf.assoc)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001726 return;
1727
1728 bcast_mac->default_discard = 1;
1729
1730 /* copy all configured filters */
1731 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1732 /*
1733 * Make sure we don't exceed our filters limit.
1734 * if there is still a valid filter to be configured,
1735 * be on the safe side and just allow bcast for this mac.
1736 */
1737 if (WARN_ON_ONCE(data->current_filter >=
1738 ARRAY_SIZE(cmd->filters))) {
1739 bcast_mac->default_discard = 0;
1740 bcast_mac->attached_filters = 0;
1741 break;
1742 }
1743
1744 iwl_mvm_set_bcast_filter(vif,
1745 &mvm->bcast_filters[i],
1746 &cmd->filters[data->current_filter]);
1747
1748 /* skip current filter if it contains no attributes */
1749 if (!cmd->filters[data->current_filter].num_attrs)
1750 continue;
1751
1752 /* attach the filter to current mac */
1753 bcast_mac->attached_filters |=
1754 cpu_to_le16(BIT(data->current_filter));
1755
1756 data->current_filter++;
1757 }
1758}
1759
Eliad Pellerde06a592014-01-08 10:11:12 +02001760bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1761 struct iwl_bcast_filter_cmd *cmd)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001762{
Eliad Pellerc87163b2014-01-08 10:11:11 +02001763 struct iwl_bcast_iter_data iter_data = {
1764 .mvm = mvm,
Eliad Pellerde06a592014-01-08 10:11:12 +02001765 .cmd = cmd,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001766 };
1767
Max Stepanov3b8983b2014-10-15 11:27:16 +03001768 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1769 return false;
1770
Eliad Pellerde06a592014-01-08 10:11:12 +02001771 memset(cmd, 0, sizeof(*cmd));
1772 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1773 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1774
1775#ifdef CONFIG_IWLWIFI_DEBUGFS
1776 /* use debugfs filters/macs if override is configured */
1777 if (mvm->dbgfs_bcast_filtering.override) {
1778 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1779 sizeof(cmd->filters));
1780 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1781 sizeof(cmd->macs));
1782 return true;
1783 }
1784#endif
Eliad Pellerc87163b2014-01-08 10:11:11 +02001785
1786 /* if no filters are configured, do nothing */
1787 if (!mvm->bcast_filters)
Eliad Pellerde06a592014-01-08 10:11:12 +02001788 return false;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001789
1790 /* configure and attach these filters for each associated sta vif */
1791 ieee80211_iterate_active_interfaces(
1792 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1793 iwl_mvm_bcast_filter_iterator, &iter_data);
1794
Eliad Pellerde06a592014-01-08 10:11:12 +02001795 return true;
1796}
Eliad Peller34672bb2015-12-03 16:10:07 +02001797
1798static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
Eliad Pellerde06a592014-01-08 10:11:12 +02001799{
1800 struct iwl_bcast_filter_cmd cmd;
1801
1802 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1803 return 0;
1804
1805 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1806 return 0;
1807
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001808 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001809 sizeof(cmd), &cmd);
1810}
1811#else
Eliad Peller34672bb2015-12-03 16:10:07 +02001812static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001813{
1814 return 0;
1815}
1816#endif
1817
Sara Sharona07a8f32015-11-15 11:11:59 +02001818static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1819 struct ieee80211_vif *vif)
1820{
1821 struct iwl_mu_group_mgmt_cmd cmd = {};
1822
1823 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1824 WLAN_MEMBERSHIP_LEN);
1825 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1826 WLAN_USER_POSITION_LEN);
1827
1828 return iwl_mvm_send_cmd_pdu(mvm,
1829 WIDE_ID(DATA_PATH_GROUP,
1830 UPDATE_MU_GROUPS_CMD),
1831 0, sizeof(cmd), &cmd);
1832}
1833
Sara Sharonf92659a2016-02-03 15:04:49 +02001834static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1835 struct ieee80211_vif *vif)
1836{
1837 if (vif->mu_mimo_owner) {
1838 struct iwl_mu_group_mgmt_notif *notif = _data;
1839
1840 /*
1841 * MU-MIMO Group Id action frame is little endian. We treat
1842 * the data received from firmware as if it came from the
1843 * action frame, so no conversion is needed.
1844 */
1845 ieee80211_update_mu_groups(vif,
1846 (u8 *)&notif->membership_status,
1847 (u8 *)&notif->user_position);
1848 }
1849}
1850
1851void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1852 struct iwl_rx_cmd_buffer *rxb)
1853{
1854 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1855 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1856
1857 ieee80211_iterate_active_interfaces_atomic(
1858 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1859 iwl_mvm_mu_mimo_iface_iterator, notif);
1860}
1861
Johannes Berg8ca151b2013-01-24 14:25:36 +01001862static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1863 struct ieee80211_vif *vif,
1864 struct ieee80211_bss_conf *bss_conf,
1865 u32 changes)
1866{
1867 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1868 int ret;
1869
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001870 /*
1871 * Re-calculate the tsf id, as the master-slave relations depend on the
1872 * beacon interval, which was not known when the station interface was
1873 * added.
1874 */
1875 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1876 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1877
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001878 /*
1879 * If we're not associated yet, take the (new) BSSID before associating
1880 * so the firmware knows. If we're already associated, then use the old
1881 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1882 * branch for disassociation below.
1883 */
1884 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1885 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1886
1887 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001888 if (ret)
1889 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1890
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001891 /* after sending it once, adopt mac80211 data */
1892 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1893 mvmvif->associated = bss_conf->assoc;
1894
Johannes Berg8ca151b2013-01-24 14:25:36 +01001895 if (changes & BSS_CHANGED_ASSOC) {
1896 if (bss_conf->assoc) {
Johannes Berg33cef922015-01-21 21:41:29 +01001897 /* clear statistics to get clean beacon counter */
1898 iwl_mvm_request_statistics(mvm, true);
1899 memset(&mvmvif->beacon_stats, 0,
1900 sizeof(mvmvif->beacon_stats));
1901
Johannes Berg8ca151b2013-01-24 14:25:36 +01001902 /* add quota for this interface */
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02001903 ret = iwl_mvm_update_quotas(mvm, true, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001904 if (ret) {
1905 IWL_ERR(mvm, "failed to update quotas\n");
1906 return;
1907 }
Johannes Berg016d27e2013-05-03 11:16:15 +02001908
1909 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1910 &mvm->status)) {
1911 /*
1912 * If we're restarting then the firmware will
1913 * obviously have lost synchronisation with
1914 * the AP. It will attempt to synchronise by
1915 * itself, but we can make it more reliable by
1916 * scheduling a session protection time event.
1917 *
1918 * The firmware needs to receive a beacon to
1919 * catch up with synchronisation, use 110% of
1920 * the beacon interval.
1921 *
1922 * Set a large maximum delay to allow for more
1923 * than a single interface.
1924 */
1925 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1926 iwl_mvm_protect_session(mvm, vif, dur, dur,
Liad Kaufmand20d37b2014-07-06 17:14:39 +03001927 5 * dur, false);
Johannes Berg016d27e2013-05-03 11:16:15 +02001928 }
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001929
1930 iwl_mvm_sf_update(mvm, vif, false);
Alexander Bondar175a70b2013-04-14 20:59:37 +03001931 iwl_mvm_power_vif_assoc(mvm, vif);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001932 if (vif->p2p) {
Eliad Peller29a90a42013-11-05 14:06:29 +02001933 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001934 iwl_mvm_update_smps(mvm, vif,
1935 IWL_MVM_SMPS_REQ_PROT,
1936 IEEE80211_SMPS_DYNAMIC);
1937 }
Sara Sharon0ae98812017-01-04 14:53:58 +02001938 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001939 /*
1940 * If update fails - SF might be running in associated
1941 * mode while disassociated - which is forbidden.
1942 */
1943 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1944 "Failed to update SF upon disassociation\n");
1945
Emmanuel Grumbach6b28f972017-05-05 08:51:24 +03001946 /*
1947 * If we get an assert during the connection (after the
1948 * station has been added, but before the vif is set
1949 * to associated), mac80211 will re-add the station and
1950 * then configure the vif. Since the vif is not
1951 * associated, we would remove the station here and
1952 * this would fail the recovery.
1953 */
1954 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1955 &mvm->status)) {
1956 /*
1957 * Remove AP station now that
1958 * the MAC is unassoc
1959 */
1960 ret = iwl_mvm_rm_sta_id(mvm, vif,
1961 mvmvif->ap_sta_id);
1962 if (ret)
1963 IWL_ERR(mvm,
1964 "failed to remove AP station\n");
Eliad Peller37577fe2013-12-05 17:19:39 +02001965
Emmanuel Grumbach6b28f972017-05-05 08:51:24 +03001966 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1967 mvm->d0i3_ap_sta_id =
1968 IWL_MVM_INVALID_STA;
1969 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1970 }
1971
Johannes Berg8ca151b2013-01-24 14:25:36 +01001972 /* remove quota for this interface */
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02001973 ret = iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001974 if (ret)
1975 IWL_ERR(mvm, "failed to update quotas\n");
Eliad Peller29a90a42013-11-05 14:06:29 +02001976
1977 if (vif->p2p)
1978 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001979
1980 /* this will take the cleared BSSID from bss_conf */
1981 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1982 if (ret)
1983 IWL_ERR(mvm,
1984 "failed to update MAC %pM (clear after unassoc)\n",
1985 vif->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001986 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001987
Sara Sharona07a8f32015-11-15 11:11:59 +02001988 /*
1989 * The firmware tracks the MU-MIMO group on its own.
Sara Sharonf92659a2016-02-03 15:04:49 +02001990 * However, on HW restart we should restore this data.
Sara Sharona07a8f32015-11-15 11:11:59 +02001991 */
1992 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
Sara Sharonf92659a2016-02-03 15:04:49 +02001993 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
Sara Sharona07a8f32015-11-15 11:11:59 +02001994 ret = iwl_mvm_update_mu_groups(mvm, vif);
1995 if (ret)
1996 IWL_ERR(mvm,
1997 "failed to update VHT MU_MIMO groups\n");
1998 }
1999
Eliad Pellere59647e2013-11-28 14:08:50 +02002000 iwl_mvm_recalc_multicast(mvm);
Eliad Peller34672bb2015-12-03 16:10:07 +02002001 iwl_mvm_configure_bcast_filter(mvm);
Eliad Pellere59647e2013-11-28 14:08:50 +02002002
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002003 /* reset rssi values */
2004 mvmvif->bf_data.ave_beacon_signal = 0;
2005
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002006 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachf94045e2014-01-06 13:38:55 +02002007 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2008 IEEE80211_SMPS_AUTOMATIC);
Avraham Stern355346b2015-11-26 11:22:33 +02002009 if (fw_has_capa(&mvm->fw->ucode_capa,
2010 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2011 iwl_mvm_config_scan(mvm);
Avraham Sternb45242c2017-01-09 15:39:15 +02002012 }
2013
2014 if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +01002015 /*
Avraham Sternb45242c2017-01-09 15:39:15 +02002016 * We received a beacon from the associated AP so
Johannes Berg210a5442013-01-24 23:48:23 +01002017 * remove the session protection.
2018 */
Avraham Stern3edfb5f2017-08-02 12:13:20 +03002019 iwl_mvm_stop_session_protection(mvm, vif);
Eran Hararycc87d322014-07-15 14:04:23 +03002020
Eran Hararycc87d322014-07-15 14:04:23 +03002021 iwl_mvm_sf_update(mvm, vif, false);
2022 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2023 }
2024
Avri Altman283115f2016-01-24 22:16:08 +02002025 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2026 /*
2027 * Send power command on every beacon change,
2028 * because we may have not enabled beacon abort yet.
2029 */
2030 BSS_CHANGED_BEACON_INFO)) {
Johannes Berg1bc10d32014-08-26 14:25:46 +02002031 ret = iwl_mvm_power_update_mac(mvm);
2032 if (ret)
2033 IWL_ERR(mvm, "failed to update power mode\n");
2034 }
2035
Matti Gottlieb88f2fd72013-07-09 15:25:46 +03002036 if (changes & BSS_CHANGED_TXPOWER) {
2037 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2038 bss_conf->txpower);
2039 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2040 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002041
2042 if (changes & BSS_CHANGED_CQM) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02002043 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002044 /* reset cqm events tracking */
2045 mvmvif->bf_data.last_cqm_event = 0;
Avri Altmanfa7b2e72014-05-20 08:03:24 +03002046 if (mvmvif->bf_data.bf_enabled) {
2047 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2048 if (ret)
2049 IWL_ERR(mvm,
2050 "failed to update CQM thresholds\n");
2051 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002052 }
Eliad Peller2ee8f022014-01-13 19:07:09 +02002053
2054 if (changes & BSS_CHANGED_ARP_FILTER) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02002055 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
Eliad Peller34672bb2015-12-03 16:10:07 +02002056 iwl_mvm_configure_bcast_filter(mvm);
Eliad Peller2ee8f022014-01-13 19:07:09 +02002057 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002058}
2059
Johannes Berg5023d962013-07-31 14:07:43 +02002060static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2061 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002062{
2063 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2064 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2065 int ret;
2066
Eliad Peller576eeee2014-07-01 18:38:38 +03002067 /*
2068 * iwl_mvm_mac_ctxt_add() might read directly from the device
2069 * (the system time), so make sure it is available.
2070 */
2071 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2072 if (ret)
2073 return ret;
2074
Johannes Berg8ca151b2013-01-24 14:25:36 +01002075 mutex_lock(&mvm->mutex);
2076
2077 /* Send the beacon template */
2078 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2079 if (ret)
2080 goto out_unlock;
2081
Ilan Peer6e97b0d2013-12-23 22:18:02 +02002082 /*
2083 * Re-calculate the tsf id, as the master-slave relations depend on the
2084 * beacon interval, which was not known when the AP interface was added.
2085 */
2086 if (vif->type == NL80211_IFTYPE_AP)
2087 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2088
Gregory Greenman94939082015-08-24 14:38:35 +03002089 mvmvif->ap_assoc_sta_count = 0;
2090
Johannes Berg8ca151b2013-01-24 14:25:36 +01002091 /* Add the mac context */
2092 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2093 if (ret)
2094 goto out_unlock;
2095
2096 /* Perform the binding */
2097 ret = iwl_mvm_binding_add_vif(mvm, vif);
2098 if (ret)
2099 goto out_remove;
2100
Sara Sharonced19f22017-02-06 19:09:32 +02002101 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2102 if (ret)
2103 goto out_unbind;
2104
Johannes Berg8ca151b2013-01-24 14:25:36 +01002105 /* Send the bcast station. At this stage the TBTT and DTIM time events
2106 * are added and applied to the scheduler */
Johannes Berg013290a2014-08-04 13:38:48 +02002107 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002108 if (ret)
Sara Sharonced19f22017-02-06 19:09:32 +02002109 goto out_rm_mcast;
Sara Sharon26d6c162017-01-03 12:00:19 +02002110
Ilan Peer5691e212013-12-31 21:05:50 +02002111 /* must be set before quota calculations */
2112 mvmvif->ap_ibss_active = true;
2113
Ilan Peera11e1442013-12-31 21:19:55 +02002114 /* power updated needs to be done before quotas */
Arik Nemtsov999609f2014-05-15 17:31:51 +03002115 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02002116
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02002117 ret = iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002118 if (ret)
Ilan Peera11e1442013-12-31 21:19:55 +02002119 goto out_quota_failed;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002120
Johannes Berg5023d962013-07-31 14:07:43 +02002121 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002122 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002123 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002124
Eliad Peller29a90a42013-11-05 14:06:29 +02002125 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2126
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002127 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03002128
Arik Nemtsovf6972672014-06-15 16:03:55 +03002129 /* we don't support TDLS during DCM */
2130 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2131 iwl_mvm_teardown_tdls_peers(mvm);
2132
Arik Nemtsov939e4902015-03-08 12:19:42 +02002133 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002134
Ilan Peera11e1442013-12-31 21:19:55 +02002135out_quota_failed:
Arik Nemtsov999609f2014-05-15 17:31:51 +03002136 iwl_mvm_power_update_mac(mvm);
Ilan Peer5691e212013-12-31 21:05:50 +02002137 mvmvif->ap_ibss_active = false;
Johannes Berg013290a2014-08-04 13:38:48 +02002138 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Sara Sharonced19f22017-02-06 19:09:32 +02002139out_rm_mcast:
2140 iwl_mvm_rm_mcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002141out_unbind:
2142 iwl_mvm_binding_remove_vif(mvm, vif);
2143out_remove:
2144 iwl_mvm_mac_ctxt_remove(mvm, vif);
2145out_unlock:
2146 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002147 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002148 return ret;
2149}
2150
Johannes Berg5023d962013-07-31 14:07:43 +02002151static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2152 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002153{
2154 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2155 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2156
Johannes Berg38a12b52013-02-22 14:07:56 +01002157 iwl_mvm_prepare_mac_removal(mvm, vif);
2158
Johannes Berg8ca151b2013-01-24 14:25:36 +01002159 mutex_lock(&mvm->mutex);
2160
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002161 /* Handle AP stop while in CSA */
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03002162 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2163 iwl_mvm_remove_time_event(mvm, mvmvif,
2164 &mvmvif->time_event_data);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002165 RCU_INIT_POINTER(mvm->csa_vif, NULL);
Avraham Sterne9cb0322015-08-31 11:08:27 +03002166 mvmvif->csa_countdown = false;
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03002167 }
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002168
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03002169 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2170 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2171 mvm->csa_tx_block_bcn_timeout = 0;
2172 }
2173
Johannes Berg5023d962013-07-31 14:07:43 +02002174 mvmvif->ap_ibss_active = false;
David Spinadel1c87bba2014-02-27 16:41:52 +02002175 mvm->ap_last_beacon_gp2 = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002176
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002177 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03002178
Eliad Peller29a90a42013-11-05 14:06:29 +02002179 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2180
Johannes Berg5023d962013-07-31 14:07:43 +02002181 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002182 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002183 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002184
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02002185 iwl_mvm_update_quotas(mvm, false, NULL);
Sara Sharonced19f22017-02-06 19:09:32 +02002186
2187 /*
2188 * This is not very nice, but the simplest:
2189 * For older FWs removing the mcast sta before the bcast station may
2190 * cause assert 0x2b00.
2191 * This is fixed in later FW (which will stop beaconing when removing
2192 * bcast station).
2193 * So make the order of removal depend on the TLV
2194 */
2195 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2196 iwl_mvm_rm_mcast_sta(mvm, vif);
Johannes Berg013290a2014-08-04 13:38:48 +02002197 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Sara Sharonced19f22017-02-06 19:09:32 +02002198 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2199 iwl_mvm_rm_mcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002200 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02002201
Arik Nemtsov999609f2014-05-15 17:31:51 +03002202 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02002203
Johannes Berg8ca151b2013-01-24 14:25:36 +01002204 iwl_mvm_mac_ctxt_remove(mvm, vif);
2205
2206 mutex_unlock(&mvm->mutex);
2207}
2208
Johannes Berg5023d962013-07-31 14:07:43 +02002209static void
2210iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2211 struct ieee80211_vif *vif,
2212 struct ieee80211_bss_conf *bss_conf,
2213 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002214{
Ilan Peerbe2056f2013-12-04 16:47:14 +02002215 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman8a5e3662013-11-12 19:16:03 +02002216
Ilan Peerbe2056f2013-12-04 16:47:14 +02002217 /* Changes will be applied when the AP/IBSS is started */
2218 if (!mvmvif->ap_ibss_active)
2219 return;
2220
Johannes Berg863230da2013-12-04 17:08:40 +01002221 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
Johannes Bergf7d8b702014-09-09 15:49:19 +02002222 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002223 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
Johannes Berg863230da2013-12-04 17:08:40 +01002224 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
Avri Altman8a5e3662013-11-12 19:16:03 +02002225
Johannes Berg8ca151b2013-01-24 14:25:36 +01002226 /* Need to send a new beacon template to the FW */
Johannes Berg863230da2013-12-04 17:08:40 +01002227 if (changes & BSS_CHANGED_BEACON &&
2228 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2229 IWL_WARN(mvm, "Failed updating beacon data\n");
Haim Dreyfuss79b7a692014-09-14 12:40:00 +03002230
2231 if (changes & BSS_CHANGED_TXPOWER) {
2232 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2233 bss_conf->txpower);
2234 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2235 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002236}
2237
2238static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2239 struct ieee80211_vif *vif,
2240 struct ieee80211_bss_conf *bss_conf,
2241 u32 changes)
2242{
2243 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2244
Eliad Peller576eeee2014-07-01 18:38:38 +03002245 /*
2246 * iwl_mvm_bss_info_changed_station() might call
2247 * iwl_mvm_protect_session(), which reads directly from
2248 * the device (the system time), so make sure it is available.
2249 */
2250 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2251 return;
2252
Johannes Berg8ca151b2013-01-24 14:25:36 +01002253 mutex_lock(&mvm->mutex);
2254
David Spinadel723f02e2014-04-27 09:54:54 +03002255 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
Luciano Coelhoc7d42482015-05-07 16:00:26 +03002256 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
David Spinadel723f02e2014-04-27 09:54:54 +03002257
Johannes Berg8ca151b2013-01-24 14:25:36 +01002258 switch (vif->type) {
2259 case NL80211_IFTYPE_STATION:
2260 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2261 break;
2262 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02002263 case NL80211_IFTYPE_ADHOC:
2264 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002265 break;
Aviya Erenfeld91b08c2d2016-03-27 14:53:49 +03002266 case NL80211_IFTYPE_MONITOR:
2267 if (changes & BSS_CHANGED_MU_GROUPS)
2268 iwl_mvm_update_mu_groups(mvm, vif);
2269 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002270 default:
2271 /* shouldn't happen */
2272 WARN_ON_ONCE(1);
2273 }
2274
2275 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002276 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002277}
2278
2279static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2280 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02002281 struct ieee80211_scan_request *hw_req)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002282{
2283 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2284 int ret;
2285
Luciano Coelho6749dd82015-03-20 15:51:36 +02002286 if (hw_req->req.n_channels == 0 ||
2287 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002288 return -EINVAL;
2289
2290 mutex_lock(&mvm->mutex);
Luciano Coelho6749dd82015-03-20 15:51:36 +02002291 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002292 mutex_unlock(&mvm->mutex);
Luciano Coelho6749dd82015-03-20 15:51:36 +02002293
Johannes Berg8ca151b2013-01-24 14:25:36 +01002294 return ret;
2295}
2296
2297static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2298 struct ieee80211_vif *vif)
2299{
2300 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2301
2302 mutex_lock(&mvm->mutex);
2303
Luciano Coelhoe7d3aba2015-02-06 10:19:05 +02002304 /* Due to a race condition, it's possible that mac80211 asks
2305 * us to stop a hw_scan when it's already stopped. This can
2306 * happen, for instance, if we stopped the scan ourselves,
2307 * called ieee80211_scan_completed() and the userspace called
2308 * cancel scan scan before ieee80211_scan_work() could run.
2309 * To handle that, simply return if the scan is not running.
2310 */
Luciano Coelho262888f2015-05-07 17:21:09 +03002311 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
Luciano Coelhoc7d42482015-05-07 16:00:26 +03002312 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002313
2314 mutex_unlock(&mvm->mutex);
2315}
2316
2317static void
2318iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
Johannes Berg3e56ead2013-02-15 22:23:18 +01002319 struct ieee80211_sta *sta, u16 tids,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002320 int num_frames,
2321 enum ieee80211_frame_release_type reason,
2322 bool more_data)
2323{
2324 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002325
Johannes Berg3e56ead2013-02-15 22:23:18 +01002326 /* Called when we need to transmit (a) frame(s) from mac80211 */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002327
Johannes Berg3e56ead2013-02-15 22:23:18 +01002328 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2329 tids, more_data, false);
2330}
2331
2332static void
2333iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2334 struct ieee80211_sta *sta, u16 tids,
2335 int num_frames,
2336 enum ieee80211_frame_release_type reason,
2337 bool more_data)
2338{
2339 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2340
Sara Sharon9a3fcf92017-03-14 09:50:35 +02002341 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
Johannes Berg3e56ead2013-02-15 22:23:18 +01002342
2343 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2344 tids, more_data, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002345}
2346
Johannes Berg65e25482016-04-13 14:24:22 +02002347static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2348 enum sta_notify_cmd cmd,
2349 struct ieee80211_sta *sta)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002350{
2351 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01002352 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002353 unsigned long txqs = 0, tids = 0;
Johannes Berg3e56ead2013-02-15 22:23:18 +01002354 int tid;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002355
Johannes Berg960f8642017-06-20 15:18:43 +02002356 /*
2357 * If we have TVQM then we get too high queue numbers - luckily
2358 * we really shouldn't get here with that because such hardware
2359 * should have firmware supporting buffer station offload.
2360 */
2361 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2362 return;
2363
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002364 spin_lock_bh(&mvmsta->lock);
2365 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2366 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2367
Sara Sharon6862fce2017-02-22 19:34:17 +02002368 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
Sara Sharon1c176272016-12-22 13:03:40 +02002369 continue;
2370
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002371 __set_bit(tid_data->txq_id, &txqs);
2372
Liad Kaufmandd321622017-04-05 16:25:11 +03002373 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002374 continue;
2375
2376 __set_bit(tid, &tids);
2377 }
2378
Johannes Berg8ca151b2013-01-24 14:25:36 +01002379 switch (cmd) {
2380 case STA_NOTIFY_SLEEP:
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002381 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
Johannes Berg3e56ead2013-02-15 22:23:18 +01002382 ieee80211_sta_set_buffered(sta, tid, true);
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002383
2384 if (txqs)
2385 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002386 /*
2387 * The fw updates the STA to be asleep. Tx packets on the Tx
2388 * queues to this station will not be transmitted. The fw will
2389 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2390 */
2391 break;
2392 case STA_NOTIFY_AWAKE:
Sara Sharon0ae98812017-01-04 14:53:58 +02002393 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
Johannes Berg8ca151b2013-01-24 14:25:36 +01002394 break;
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002395
2396 if (txqs)
2397 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
Johannes Berg9cc40712013-02-15 22:47:48 +01002398 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002399 break;
2400 default:
2401 break;
2402 }
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002403 spin_unlock_bh(&mvmsta->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002404}
2405
Johannes Berg65e25482016-04-13 14:24:22 +02002406static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2407 struct ieee80211_vif *vif,
2408 enum sta_notify_cmd cmd,
2409 struct ieee80211_sta *sta)
2410{
2411 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2412}
2413
2414void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2415{
2416 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2417 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2418 struct ieee80211_sta *sta;
2419 struct iwl_mvm_sta *mvmsta;
2420 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2421
2422 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2423 return;
2424
2425 rcu_read_lock();
Sara Sharona9560022017-01-26 14:43:32 +02002426 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
Johannes Berg65e25482016-04-13 14:24:22 +02002427 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2428 rcu_read_unlock();
2429 return;
2430 }
2431
2432 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2433
2434 if (!mvmsta->vif ||
2435 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2436 rcu_read_unlock();
2437 return;
2438 }
2439
2440 if (mvmsta->sleeping != sleeping) {
2441 mvmsta->sleeping = sleeping;
2442 __iwl_mvm_mac_sta_notify(mvm->hw,
2443 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2444 sta);
2445 ieee80211_sta_ps_transition(sta, sleeping);
2446 }
2447
2448 if (sleeping) {
2449 switch (notif->type) {
2450 case IWL_MVM_PM_EVENT_AWAKE:
2451 case IWL_MVM_PM_EVENT_ASLEEP:
2452 break;
2453 case IWL_MVM_PM_EVENT_UAPSD:
2454 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2455 break;
2456 case IWL_MVM_PM_EVENT_PS_POLL:
2457 ieee80211_sta_pspoll(sta);
2458 break;
2459 default:
2460 break;
2461 }
2462 }
2463
2464 rcu_read_unlock();
2465}
2466
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002467static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2468 struct ieee80211_vif *vif,
2469 struct ieee80211_sta *sta)
2470{
2471 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01002472 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002473
2474 /*
2475 * This is called before mac80211 does RCU synchronisation,
2476 * so here we already invalidate our internal RCU-protected
2477 * station pointer. The rest of the code will thus no longer
2478 * be able to find the station this way, and we don't rely
2479 * on further RCU synchronisation after the sta_state()
2480 * callback deleted the station.
2481 */
2482 mutex_lock(&mvm->mutex);
2483 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2484 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2485 ERR_PTR(-ENOENT));
Gregory Greenman94939082015-08-24 14:38:35 +03002486
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002487 mutex_unlock(&mvm->mutex);
2488}
2489
Johannes Bergbd1ba662014-11-13 20:53:45 +01002490static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2491 const u8 *bssid)
2492{
2493 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2494 return;
2495
Avraham Sternc5241b02016-04-20 09:29:18 +03002496 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
Avri Altmancee5a882016-02-03 16:28:25 +02002497 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2498 return;
2499 }
2500
Emmanuel Grumbach11dee0b2016-03-15 11:04:29 +02002501 if (!vif->p2p &&
2502 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
Johannes Bergbd1ba662014-11-13 20:53:45 +01002503 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2504 return;
2505 }
2506
2507 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2508}
2509
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002510static void
2511iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2512 struct ieee80211_vif *vif, u8 *peer_addr,
2513 enum nl80211_tdls_operation action)
2514{
2515 struct iwl_fw_dbg_trigger_tlv *trig;
2516 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2517
2518 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TDLS))
2519 return;
2520
2521 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TDLS);
2522 tdls_trig = (void *)trig->data;
Johannes Berg7174beb2017-06-01 16:03:19 +02002523 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
2524 ieee80211_vif_to_wdev(vif), trig))
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002525 return;
2526
2527 if (!(tdls_trig->action_bitmap & BIT(action)))
2528 return;
2529
2530 if (tdls_trig->peer_mode &&
2531 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2532 return;
2533
Johannes Berg7174beb2017-06-01 16:03:19 +02002534 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2535 "TDLS event occurred, peer %pM, action %d",
2536 peer_addr, action);
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002537}
2538
Liad Kaufman24afba72015-07-28 18:56:08 +03002539static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2540 struct iwl_mvm_sta *mvm_sta)
2541{
2542 struct iwl_mvm_tid_data *tid_data;
2543 struct sk_buff *skb;
2544 int i;
2545
2546 spin_lock_bh(&mvm_sta->lock);
2547 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2548 tid_data = &mvm_sta->tid_data[i];
Avraham Stern7e39a002017-07-26 15:08:45 +03002549
2550 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2551 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2552
2553 /*
2554 * The first deferred frame should've stopped the MAC
2555 * queues, so we should never get a second deferred
2556 * frame for the RA/TID.
2557 */
Avraham Stern8458e482017-09-03 16:04:38 +03002558 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
Liad Kaufman24afba72015-07-28 18:56:08 +03002559 ieee80211_free_txskb(mvm->hw, skb);
Avraham Stern7e39a002017-07-26 15:08:45 +03002560 }
Liad Kaufman24afba72015-07-28 18:56:08 +03002561 }
2562 spin_unlock_bh(&mvm_sta->lock);
2563}
2564
Johannes Berg8ca151b2013-01-24 14:25:36 +01002565static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2566 struct ieee80211_vif *vif,
2567 struct ieee80211_sta *sta,
2568 enum ieee80211_sta_state old_state,
2569 enum ieee80211_sta_state new_state)
2570{
2571 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2572 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg6ea29ce2016-12-01 16:25:30 +01002573 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002574 int ret;
2575
2576 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2577 sta->addr, old_state, new_state);
2578
2579 /* this would be a mac80211 bug ... but don't crash */
2580 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2581 return -EINVAL;
2582
Liad Kaufman24afba72015-07-28 18:56:08 +03002583 /*
2584 * If we are in a STA removal flow and in DQA mode:
2585 *
2586 * This is after the sync_rcu part, so the queues have already been
2587 * flushed. No more TXs on their way in mac80211's path, and no more in
2588 * the queues.
2589 * Also, we won't be getting any new TX frames for this station.
2590 * What we might have are deferred TX frames that need to be taken care
2591 * of.
2592 *
2593 * Drop any still-queued deferred-frame before removing the STA, and
2594 * make sure the worker is no longer handling frames for this STA.
2595 */
2596 if (old_state == IEEE80211_STA_NONE &&
Johannes Bergc8f54702017-06-19 23:50:31 +02002597 new_state == IEEE80211_STA_NOTEXIST) {
Liad Kaufman24afba72015-07-28 18:56:08 +03002598 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2599 flush_work(&mvm->add_stream_wk);
2600
2601 /*
2602 * No need to make sure deferred TX indication is off since the
2603 * worker will already remove it if it was on
2604 */
2605 }
2606
Johannes Berg8ca151b2013-01-24 14:25:36 +01002607 mutex_lock(&mvm->mutex);
Johannes Berg6ea29ce2016-12-01 16:25:30 +01002608 /* track whether or not the station is associated */
2609 mvm_sta->associated = new_state >= IEEE80211_STA_ASSOC;
2610
Johannes Berg8ca151b2013-01-24 14:25:36 +01002611 if (old_state == IEEE80211_STA_NOTEXIST &&
2612 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02002613 /*
2614 * Firmware bug - it'll crash if the beacon interval is less
2615 * than 16. We can't avoid connecting at all, so refuse the
2616 * station state change, this will cause mac80211 to abandon
2617 * attempts to connect to this AP, and eventually wpa_s will
2618 * blacklist the AP...
2619 */
2620 if (vif->type == NL80211_IFTYPE_STATION &&
2621 vif->bss_conf.beacon_int < 16) {
2622 IWL_ERR(mvm,
2623 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2624 sta->addr, vif->bss_conf.beacon_int);
2625 ret = -EINVAL;
2626 goto out_unlock;
2627 }
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002628
2629 if (sta->tdls &&
2630 (vif->p2p ||
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002631 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2632 IWL_MVM_TDLS_STA_COUNT ||
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002633 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2634 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2635 ret = -EBUSY;
2636 goto out_unlock;
2637 }
2638
Johannes Berg8ca151b2013-01-24 14:25:36 +01002639 ret = iwl_mvm_add_sta(mvm, vif, sta);
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002640 if (sta->tdls && ret == 0) {
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002641 iwl_mvm_recalc_tdls_state(mvm, vif, true);
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002642 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2643 NL80211_TDLS_SETUP);
2644 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002645 } else if (old_state == IEEE80211_STA_NONE &&
2646 new_state == IEEE80211_STA_AUTH) {
Haim Dreyfusse820c2d2014-04-06 11:19:09 +03002647 /*
2648 * EBS may be disabled due to previous failures reported by FW.
2649 * Reset EBS status here assuming environment has been changed.
2650 */
2651 mvm->last_ebs_successful = true;
Johannes Bergbd1ba662014-11-13 20:53:45 +01002652 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002653 ret = 0;
2654 } else if (old_state == IEEE80211_STA_AUTH &&
2655 new_state == IEEE80211_STA_ASSOC) {
Ayala Beker8be30c12015-12-16 00:32:07 +02002656 if (vif->type == NL80211_IFTYPE_AP) {
2657 mvmvif->ap_assoc_sta_count++;
2658 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2659 }
Goodstein, Mordechay735a0042017-01-15 16:00:12 +02002660
2661 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2662 true);
Johannes Berg7a453972013-02-12 13:10:44 +01002663 ret = iwl_mvm_update_sta(mvm, vif, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002664 } else if (old_state == IEEE80211_STA_ASSOC &&
2665 new_state == IEEE80211_STA_AUTHORIZED) {
Arik Nemtsovf59e0e3c2014-06-10 19:56:27 +03002666
2667 /* we don't support TDLS during DCM */
2668 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2669 iwl_mvm_teardown_tdls_peers(mvm);
2670
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002671 if (sta->tdls)
2672 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2673 NL80211_TDLS_ENABLE_LINK);
2674
Hila Gonen7df15b12012-12-12 11:16:19 +02002675 /* enable beacon filtering */
Avri Altmanfa7b2e72014-05-20 08:03:24 +03002676 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002677 ret = 0;
2678 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2679 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02002680 /* disable beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002681 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002682 ret = 0;
2683 } else if (old_state == IEEE80211_STA_ASSOC &&
2684 new_state == IEEE80211_STA_AUTH) {
Ayala Beker8be30c12015-12-16 00:32:07 +02002685 if (vif->type == NL80211_IFTYPE_AP) {
2686 mvmvif->ap_assoc_sta_count--;
2687 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2688 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002689 ret = 0;
2690 } else if (old_state == IEEE80211_STA_AUTH &&
2691 new_state == IEEE80211_STA_NONE) {
2692 ret = 0;
2693 } else if (old_state == IEEE80211_STA_NONE &&
2694 new_state == IEEE80211_STA_NOTEXIST) {
2695 ret = iwl_mvm_rm_sta(mvm, vif, sta);
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002696 if (sta->tdls) {
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002697 iwl_mvm_recalc_tdls_state(mvm, vif, false);
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002698 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2699 NL80211_TDLS_DISABLE_LINK);
2700 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002701 } else {
2702 ret = -EIO;
2703 }
Johannes Berg48bc1302013-07-04 15:55:29 +02002704 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002705 mutex_unlock(&mvm->mutex);
2706
Liad Kaufman9c126cd2014-10-06 19:08:56 +02002707 if (sta->tdls && ret == 0) {
2708 if (old_state == IEEE80211_STA_NOTEXIST &&
2709 new_state == IEEE80211_STA_NONE)
2710 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2711 else if (old_state == IEEE80211_STA_NONE &&
2712 new_state == IEEE80211_STA_NOTEXIST)
2713 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2714 }
2715
Johannes Berg8ca151b2013-01-24 14:25:36 +01002716 return ret;
2717}
2718
2719static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2720{
2721 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2722
2723 mvm->rts_threshold = value;
2724
2725 return 0;
2726}
2727
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002728static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2729 struct ieee80211_vif *vif,
2730 struct ieee80211_sta *sta, u32 changed)
2731{
2732 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2733
2734 if (vif->type == NL80211_IFTYPE_STATION &&
2735 changed & IEEE80211_RC_NSS_CHANGED)
2736 iwl_mvm_sf_update(mvm, vif, false);
2737}
2738
Johannes Berg8ca151b2013-01-24 14:25:36 +01002739static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2740 struct ieee80211_vif *vif, u16 ac,
2741 const struct ieee80211_tx_queue_params *params)
2742{
2743 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2744 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2745
2746 mvmvif->queue_params[ac] = *params;
2747
2748 /*
2749 * No need to update right away, we'll get BSS_CHANGED_QOS
2750 * The exception is P2P_DEVICE interface which needs immediate update.
2751 */
2752 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2753 int ret;
2754
2755 mutex_lock(&mvm->mutex);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002756 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002757 mutex_unlock(&mvm->mutex);
2758 return ret;
2759 }
2760 return 0;
2761}
2762
2763static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2764 struct ieee80211_vif *vif)
2765{
2766 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Sara Sharon7c70fee2016-02-02 11:55:53 +02002767 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
2768 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002769
2770 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2771 return;
2772
Eliad Peller576eeee2014-07-01 18:38:38 +03002773 /*
2774 * iwl_mvm_protect_session() reads directly from the device
2775 * (the system time), so make sure it is available.
2776 */
2777 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2778 return;
2779
Johannes Berg8ca151b2013-01-24 14:25:36 +01002780 mutex_lock(&mvm->mutex);
2781 /* Try really hard to protect the session and hear a beacon */
Liad Kaufmand20d37b2014-07-06 17:14:39 +03002782 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002783 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002784
2785 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002786}
2787
David Spinadel35a000b2013-08-28 09:29:43 +03002788static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2789 struct ieee80211_vif *vif,
2790 struct cfg80211_sched_scan_request *req,
David Spinadel633e2712014-02-06 16:15:23 +02002791 struct ieee80211_scan_ies *ies)
David Spinadel35a000b2013-08-28 09:29:43 +03002792{
2793 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luciano Coelho6749dd82015-03-20 15:51:36 +02002794
David Spinadel35a000b2013-08-28 09:29:43 +03002795 int ret;
2796
2797 mutex_lock(&mvm->mutex);
2798
Luciano Coelho1f940382015-02-10 13:03:38 +02002799 if (!vif->bss_conf.idle) {
David Spinadelbd5e4742014-04-24 13:15:29 +03002800 ret = -EBUSY;
2801 goto out;
2802 }
2803
Luciano Coelho19945df2015-03-20 16:11:28 +02002804 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
David Spinadeld2496222014-05-20 12:46:37 +03002805
David Spinadel35a000b2013-08-28 09:29:43 +03002806out:
2807 mutex_unlock(&mvm->mutex);
2808 return ret;
2809}
2810
Johannes Berg37e33082014-02-17 10:48:17 +01002811static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2812 struct ieee80211_vif *vif)
David Spinadel35a000b2013-08-28 09:29:43 +03002813{
2814 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002815 int ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002816
2817 mutex_lock(&mvm->mutex);
Luciano Coelhoe7d3aba2015-02-06 10:19:05 +02002818
2819 /* Due to a race condition, it's possible that mac80211 asks
2820 * us to stop a sched_scan when it's already stopped. This
2821 * can happen, for instance, if we stopped the scan ourselves,
2822 * called ieee80211_sched_scan_stopped() and the userspace called
2823 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
2824 * could run. To handle this, simply return if the scan is
2825 * not running.
2826 */
Luciano Coelho262888f2015-05-07 17:21:09 +03002827 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
Luciano Coelhoe7d3aba2015-02-06 10:19:05 +02002828 mutex_unlock(&mvm->mutex);
2829 return 0;
2830 }
2831
Luciano Coelhoc7d42482015-05-07 16:00:26 +03002832 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
David Spinadel35a000b2013-08-28 09:29:43 +03002833 mutex_unlock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002834 iwl_mvm_wait_for_async_handlers(mvm);
Johannes Berg37e33082014-02-17 10:48:17 +01002835
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002836 return ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002837}
2838
Johannes Berg8ca151b2013-01-24 14:25:36 +01002839static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2840 enum set_key_cmd cmd,
2841 struct ieee80211_vif *vif,
2842 struct ieee80211_sta *sta,
2843 struct ieee80211_key_conf *key)
2844{
2845 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Bergf5e28ea2015-12-06 14:58:08 +02002846 struct iwl_mvm_sta *mvmsta;
2847 struct iwl_mvm_key_pn *ptk_pn;
2848 int keyidx = key->keyidx;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002849 int ret;
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002850 u8 key_offset;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002851
Johannes Berg3b37f4c2017-05-30 16:45:31 +02002852 if (iwlwifi_mod_params.swcrypto) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002853 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2854 return -EOPNOTSUPP;
2855 }
2856
2857 switch (key->cipher) {
2858 case WLAN_CIPHER_SUITE_TKIP:
2859 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Eliad Peller1ad4f632016-02-14 13:56:36 +02002860 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002861 break;
Johannes Bergca8c0f42015-04-20 17:54:54 +02002862 case WLAN_CIPHER_SUITE_CCMP:
Ayala Beker2a53d162016-04-07 16:21:57 +03002863 case WLAN_CIPHER_SUITE_GCMP:
2864 case WLAN_CIPHER_SUITE_GCMP_256:
David Spinadel85aeb582017-03-30 19:43:53 +03002865 if (!iwl_mvm_has_new_tx_api(mvm))
2866 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
Johannes Bergca8c0f42015-04-20 17:54:54 +02002867 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002868 case WLAN_CIPHER_SUITE_AES_CMAC:
Ayala Beker8e160ab2016-04-11 11:37:38 +03002869 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2870 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
Johannes Berg30686bf2015-06-02 21:39:54 +02002871 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002872 break;
2873 case WLAN_CIPHER_SUITE_WEP40:
2874 case WLAN_CIPHER_SUITE_WEP104:
Johannes Bergba3943b2014-11-12 23:54:48 +01002875 /* For non-client mode, only use WEP keys for TX as we probably
2876 * don't have a station yet anyway and would then have to keep
2877 * track of the keys, linking them to each of the clients/peers
2878 * as they appear. For now, don't do that, for performance WEP
2879 * offload doesn't really matter much, but we need it for some
2880 * other offload features in client mode.
Johannes Berg8ca151b2013-01-24 14:25:36 +01002881 */
Johannes Bergba3943b2014-11-12 23:54:48 +01002882 if (vif->type != NL80211_IFTYPE_STATION)
2883 return 0;
2884 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002885 default:
Max Stepanove36e5432013-08-27 19:56:13 +03002886 /* currently FW supports only one optional cipher scheme */
2887 if (hw->n_cipher_schemes &&
2888 hw->cipher_schemes->cipher == key->cipher)
2889 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2890 else
2891 return -EOPNOTSUPP;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002892 }
2893
2894 mutex_lock(&mvm->mutex);
2895
2896 switch (cmd) {
2897 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02002898 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2899 vif->type == NL80211_IFTYPE_AP) && !sta) {
2900 /*
2901 * GTK on AP interface is a TX-only key, return 0;
2902 * on IBSS they're per-station and because we're lazy
2903 * we don't support them for RX, so do the same.
Ayala Beker8e160ab2016-04-11 11:37:38 +03002904 * CMAC/GMAC in AP/IBSS modes must be done in software.
Johannes Berg5023d962013-07-31 14:07:43 +02002905 */
Ayala Beker8e160ab2016-04-11 11:37:38 +03002906 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
2907 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
2908 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
Johannes Berg81279c42016-03-09 14:58:47 +01002909 ret = -EOPNOTSUPP;
2910 else
2911 ret = 0;
David Spinadel85aeb582017-03-30 19:43:53 +03002912
2913 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
2914 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
2915 !iwl_mvm_has_new_tx_api(mvm)) {
2916 key->hw_key_idx = STA_KEY_IDX_INVALID;
2917 break;
2918 }
Johannes Berg6caffd42013-03-06 13:15:21 +01002919 }
2920
Johannes Bergb546dcd2015-04-20 17:31:10 +02002921 /* During FW restart, in order to restore the state as it was,
2922 * don't try to reprogram keys we previously failed for.
2923 */
2924 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2925 key->hw_key_idx == STA_KEY_IDX_INVALID) {
2926 IWL_DEBUG_MAC80211(mvm,
2927 "skip invalid idx key programming during restart\n");
2928 ret = 0;
2929 break;
2930 }
2931
Johannes Bergf5e28ea2015-12-06 14:58:08 +02002932 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2933 sta && iwl_mvm_has_new_rx_api(mvm) &&
2934 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
2935 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
Ayala Beker2a53d162016-04-07 16:21:57 +03002936 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
2937 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
Johannes Bergf5e28ea2015-12-06 14:58:08 +02002938 struct ieee80211_key_seq seq;
2939 int tid, q;
2940
2941 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2942 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
2943 ptk_pn = kzalloc(sizeof(*ptk_pn) +
2944 mvm->trans->num_rx_queues *
2945 sizeof(ptk_pn->q[0]),
2946 GFP_KERNEL);
2947 if (!ptk_pn) {
2948 ret = -ENOMEM;
2949 break;
2950 }
2951
2952 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2953 ieee80211_get_key_rx_seq(key, tid, &seq);
2954 for (q = 0; q < mvm->trans->num_rx_queues; q++)
2955 memcpy(ptk_pn->q[q].pn[tid],
2956 seq.ccmp.pn,
2957 IEEE80211_CCMP_PN_LEN);
2958 }
2959
2960 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
2961 }
2962
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002963 /* in HW restart reuse the index, otherwise request a new one */
2964 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
2965 key_offset = key->hw_key_idx;
2966 else
2967 key_offset = STA_KEY_IDX_INVALID;
2968
Johannes Berg8ca151b2013-01-24 14:25:36 +01002969 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002970 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002971 if (ret) {
2972 IWL_WARN(mvm, "set key failed\n");
2973 /*
2974 * can't add key for RX, but we don't need it
2975 * in the device for TX so still return 0
2976 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002977 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002978 ret = 0;
2979 }
2980
2981 break;
2982 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01002983 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2984 ret = 0;
2985 break;
2986 }
2987
Johannes Bergf5e28ea2015-12-06 14:58:08 +02002988 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
2989 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
2990 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
Ayala Beker2a53d162016-04-07 16:21:57 +03002991 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
2992 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
Johannes Bergf5e28ea2015-12-06 14:58:08 +02002993 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2994 ptk_pn = rcu_dereference_protected(
2995 mvmsta->ptk_pn[keyidx],
2996 lockdep_is_held(&mvm->mutex));
2997 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
2998 if (ptk_pn)
2999 kfree_rcu(ptk_pn, rcu_head);
3000 }
3001
Johannes Berg8ca151b2013-01-24 14:25:36 +01003002 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3003 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3004 break;
3005 default:
3006 ret = -EINVAL;
3007 }
3008
3009 mutex_unlock(&mvm->mutex);
3010 return ret;
3011}
3012
3013static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3014 struct ieee80211_vif *vif,
3015 struct ieee80211_key_conf *keyconf,
3016 struct ieee80211_sta *sta,
3017 u32 iv32, u16 *phase1key)
3018{
3019 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3020
Johannes Berg5023d962013-07-31 14:07:43 +02003021 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3022 return;
3023
Johannes Berg8ca151b2013-01-24 14:25:36 +01003024 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3025}
3026
3027
Ariej Marjiehb1128892014-07-16 21:11:12 +03003028static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3029 struct iwl_rx_packet *pkt, void *data)
3030{
3031 struct iwl_mvm *mvm =
3032 container_of(notif_wait, struct iwl_mvm, notif_wait);
3033 struct iwl_hs20_roc_res *resp;
3034 int resp_len = iwl_rx_packet_payload_len(pkt);
3035 struct iwl_mvm_time_event_data *te_data = data;
3036
3037 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3038 return true;
3039
3040 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3041 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3042 return true;
3043 }
3044
3045 resp = (void *)pkt->data;
3046
3047 IWL_DEBUG_TE(mvm,
3048 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
3049 resp->status, resp->event_unique_id);
3050
3051 te_data->uid = le32_to_cpu(resp->event_unique_id);
3052 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3053 te_data->uid);
3054
3055 spin_lock_bh(&mvm->time_event_lock);
3056 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3057 spin_unlock_bh(&mvm->time_event_lock);
3058
3059 return true;
3060}
3061
Matti Gottliebdc28e122015-11-22 10:08:56 +02003062#define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3063#define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3064#define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3065#define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3066#define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
Ariej Marjiehb1128892014-07-16 21:11:12 +03003067static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3068 struct ieee80211_channel *channel,
3069 struct ieee80211_vif *vif,
3070 int duration)
3071{
3072 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3073 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3074 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
Sara Sharon6eb031d2015-07-13 14:50:47 +03003075 static const u16 time_event_response[] = { HOT_SPOT_CMD };
Ariej Marjiehb1128892014-07-16 21:11:12 +03003076 struct iwl_notification_wait wait_time_event;
Matti Gottliebdc28e122015-11-22 10:08:56 +02003077 u32 dtim_interval = vif->bss_conf.dtim_period *
3078 vif->bss_conf.beacon_int;
3079 u32 req_dur, delay;
Ariej Marjiehb1128892014-07-16 21:11:12 +03003080 struct iwl_hs20_roc_req aux_roc_req = {
3081 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3082 .id_and_color =
3083 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3084 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3085 /* Set the channel info data */
Johannes Berg57fbcce2016-04-12 15:56:15 +02003086 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
Ariej Marjiehb1128892014-07-16 21:11:12 +03003087 PHY_BAND_24 : PHY_BAND_5,
3088 .channel_info.channel = channel->hw_value,
3089 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3090 /* Set the time and duration */
3091 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
Ariej Marjiehb1128892014-07-16 21:11:12 +03003092 };
3093
Matti Gottliebdc28e122015-11-22 10:08:56 +02003094 delay = AUX_ROC_MIN_DELAY;
3095 req_dur = MSEC_TO_TU(duration);
3096
3097 /*
3098 * If we are associated we want the delay time to be at least one
3099 * dtim interval so that the FW can wait until after the DTIM and
3100 * then start the time event, this will potentially allow us to
3101 * remain off-channel for the max duration.
3102 * Since we want to use almost a whole dtim interval we would also
3103 * like the delay to be for 2-3 dtim intervals, in case there are
3104 * other time events with higher priority.
3105 */
3106 if (vif->bss_conf.assoc) {
3107 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3108 /* We cannot remain off-channel longer than the DTIM interval */
3109 if (dtim_interval <= req_dur) {
3110 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3111 if (req_dur <= AUX_ROC_MIN_DURATION)
3112 req_dur = dtim_interval -
3113 AUX_ROC_MIN_SAFETY_BUFFER;
3114 }
3115 }
3116
3117 aux_roc_req.duration = cpu_to_le32(req_dur);
3118 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3119
3120 IWL_DEBUG_TE(mvm,
3121 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3122 channel->hw_value, req_dur, duration, delay,
3123 dtim_interval);
Ariej Marjiehb1128892014-07-16 21:11:12 +03003124 /* Set the node address */
3125 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3126
Matti Gottlieba6cc5162014-09-29 11:46:04 +03003127 lockdep_assert_held(&mvm->mutex);
3128
3129 spin_lock_bh(&mvm->time_event_lock);
3130
3131 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3132 spin_unlock_bh(&mvm->time_event_lock);
3133 return -EIO;
3134 }
3135
Ariej Marjiehb1128892014-07-16 21:11:12 +03003136 te_data->vif = vif;
3137 te_data->duration = duration;
3138 te_data->id = HOT_SPOT_CMD;
3139
Ariej Marjiehb1128892014-07-16 21:11:12 +03003140 spin_unlock_bh(&mvm->time_event_lock);
3141
3142 /*
3143 * Use a notification wait, which really just processes the
3144 * command response and doesn't wait for anything, in order
3145 * to be able to process the response and get the UID inside
3146 * the RX path. Using CMD_WANT_SKB doesn't work because it
3147 * stores the buffer and then wakes up this thread, by which
3148 * time another notification (that the time event started)
3149 * might already be processed unsuccessfully.
3150 */
3151 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3152 time_event_response,
3153 ARRAY_SIZE(time_event_response),
3154 iwl_mvm_rx_aux_roc, te_data);
3155
3156 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3157 &aux_roc_req);
3158
3159 if (res) {
3160 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3161 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3162 goto out_clear_te;
3163 }
3164
3165 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3166 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3167 /* should never fail */
3168 WARN_ON_ONCE(res);
3169
3170 if (res) {
3171 out_clear_te:
3172 spin_lock_bh(&mvm->time_event_lock);
3173 iwl_mvm_te_clear_data(mvm, te_data);
3174 spin_unlock_bh(&mvm->time_event_lock);
3175 }
3176
3177 return res;
3178}
3179
Johannes Berg8ca151b2013-01-24 14:25:36 +01003180static int iwl_mvm_roc(struct ieee80211_hw *hw,
3181 struct ieee80211_vif *vif,
3182 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02003183 int duration,
3184 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003185{
3186 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003187 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003188 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03003189 struct iwl_mvm_phy_ctxt *phy_ctxt;
3190 int ret, i;
3191
3192 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3193 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003194
Johannes Berg98347812017-11-15 10:16:47 +01003195 /*
3196 * Flush the done work, just in case it's still pending, so that
3197 * the work it does can complete and we can accept new frames.
3198 */
Matti Gottlieb6ed13162015-03-30 16:50:07 +03003199 flush_work(&mvm->roc_done_wk);
3200
Matti Gottlieba6cc5162014-09-29 11:46:04 +03003201 mutex_lock(&mvm->mutex);
3202
Ariej Marjiehb1128892014-07-16 21:11:12 +03003203 switch (vif->type) {
3204 case NL80211_IFTYPE_STATION:
Johannes Berg859d9142015-06-01 17:11:11 +02003205 if (fw_has_capa(&mvm->fw->ucode_capa,
3206 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
Luciano Coelho5ac6c722014-10-21 16:12:18 +03003207 /* Use aux roc framework (HS20) */
3208 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3209 vif, duration);
3210 goto out_unlock;
3211 }
3212 IWL_ERR(mvm, "hotspot not supported\n");
3213 ret = -EINVAL;
Matti Gottlieba6cc5162014-09-29 11:46:04 +03003214 goto out_unlock;
Ariej Marjiehb1128892014-07-16 21:11:12 +03003215 case NL80211_IFTYPE_P2P_DEVICE:
3216 /* handle below */
3217 break;
3218 default:
3219 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
Matti Gottlieba6cc5162014-09-29 11:46:04 +03003220 ret = -EINVAL;
3221 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003222 }
3223
Ilan Peer31d385a2013-04-02 10:25:46 +03003224 for (i = 0; i < NUM_PHY_CTX; i++) {
3225 phy_ctxt = &mvm->phy_ctxts[i];
3226 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3227 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003228
Ilan Peer31d385a2013-04-02 10:25:46 +03003229 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3230 /*
3231 * Unbind the P2P_DEVICE from the current PHY context,
3232 * and if the PHY context is not used remove it.
3233 */
3234 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3235 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3236 goto out_unlock;
3237
3238 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3239
3240 /* Bind the P2P_DEVICE to the current PHY Context */
3241 mvmvif->phy_ctxt = phy_ctxt;
3242
3243 ret = iwl_mvm_binding_add_vif(mvm, vif);
3244 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3245 goto out_unlock;
3246
3247 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3248 goto schedule_time_event;
3249 }
3250 }
3251
3252 /* Need to update the PHY context only if the ROC channel changed */
3253 if (channel == mvmvif->phy_ctxt->channel)
3254 goto schedule_time_event;
3255
3256 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3257
3258 /*
3259 * Change the PHY context configuration as it is currently referenced
3260 * only by the P2P Device MAC
3261 */
3262 if (mvmvif->phy_ctxt->ref == 1) {
3263 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3264 &chandef, 1, 1);
3265 if (ret)
3266 goto out_unlock;
3267 } else {
3268 /*
3269 * The PHY context is shared with other MACs. Need to remove the
3270 * P2P Device from the binding, allocate an new PHY context and
3271 * create a new binding
3272 */
3273 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3274 if (!phy_ctxt) {
3275 ret = -ENOSPC;
3276 goto out_unlock;
3277 }
3278
3279 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3280 1, 1);
3281 if (ret) {
3282 IWL_ERR(mvm, "Failed to change PHY context\n");
3283 goto out_unlock;
3284 }
3285
3286 /* Unbind the P2P_DEVICE from the current PHY context */
3287 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3288 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3289 goto out_unlock;
3290
3291 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3292
3293 /* Bind the P2P_DEVICE to the new allocated PHY context */
3294 mvmvif->phy_ctxt = phy_ctxt;
3295
3296 ret = iwl_mvm_binding_add_vif(mvm, vif);
3297 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3298 goto out_unlock;
3299
3300 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3301 }
3302
3303schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003304 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02003305 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003306
Ilan Peer31d385a2013-04-02 10:25:46 +03003307out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003308 mutex_unlock(&mvm->mutex);
3309 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01003310 return ret;
3311}
3312
3313static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3314{
3315 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3316
3317 IWL_DEBUG_MAC80211(mvm, "enter\n");
3318
3319 mutex_lock(&mvm->mutex);
Matti Gottliebbf5da872014-11-16 10:25:12 +02003320 iwl_mvm_stop_roc(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003321 mutex_unlock(&mvm->mutex);
3322
3323 IWL_DEBUG_MAC80211(mvm, "leave\n");
3324 return 0;
3325}
3326
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003327static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3328 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003329{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003330 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3331 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003332 int ret;
3333
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003334 lockdep_assert_held(&mvm->mutex);
3335
Ilan Peer53a9d612013-04-28 11:55:08 +03003336 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003337
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003338 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3339 if (!phy_ctxt) {
3340 ret = -ENOSPC;
3341 goto out;
3342 }
3343
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02003344 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Ilan Peer53a9d612013-04-28 11:55:08 +03003345 ctx->rx_chains_static,
3346 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003347 if (ret) {
3348 IWL_ERR(mvm, "Failed to add PHY context\n");
3349 goto out;
3350 }
3351
Ilan Peer53a9d612013-04-28 11:55:08 +03003352 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003353 *phy_ctxt_id = phy_ctxt->id;
3354out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003355 return ret;
3356}
3357
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003358static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3359 struct ieee80211_chanctx_conf *ctx)
3360{
3361 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3362 int ret;
3363
3364 mutex_lock(&mvm->mutex);
3365 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3366 mutex_unlock(&mvm->mutex);
3367
3368 return ret;
3369}
3370
3371static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3372 struct ieee80211_chanctx_conf *ctx)
3373{
3374 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3375 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3376
3377 lockdep_assert_held(&mvm->mutex);
3378
3379 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3380}
3381
Johannes Berg8ca151b2013-01-24 14:25:36 +01003382static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3383 struct ieee80211_chanctx_conf *ctx)
3384{
3385 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003386
3387 mutex_lock(&mvm->mutex);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003388 __iwl_mvm_remove_chanctx(mvm, ctx);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003389 mutex_unlock(&mvm->mutex);
3390}
3391
3392static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3393 struct ieee80211_chanctx_conf *ctx,
3394 u32 changed)
3395{
3396 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003397 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3398 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01003399
Ilan Peer31d385a2013-04-02 10:25:46 +03003400 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3401 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3402 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
Arik Nemtsov2dceeda2013-12-29 17:57:53 +02003403 IEEE80211_CHANCTX_CHANGE_RADAR |
3404 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
Ilan Peer31d385a2013-04-02 10:25:46 +03003405 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3406 phy_ctxt->ref, changed))
3407 return;
3408
Johannes Berg8ca151b2013-01-24 14:25:36 +01003409 mutex_lock(&mvm->mutex);
Emmanuel Grumbach7a20bcc2017-09-14 15:45:44 +03003410
3411 /* we are only changing the min_width, may be a noop */
3412 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
3413 if (phy_ctxt->width == ctx->min_def.width)
3414 goto out_unlock;
3415
3416 /* we are just toggling between 20_NOHT and 20 */
3417 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
3418 ctx->min_def.width <= NL80211_CHAN_WIDTH_20)
3419 goto out_unlock;
3420 }
3421
Emmanuel Grumbach4d664492014-04-30 18:09:59 +03003422 iwl_mvm_bt_coex_vif_change(mvm);
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02003423 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003424 ctx->rx_chains_static,
3425 ctx->rx_chains_dynamic);
Emmanuel Grumbach7a20bcc2017-09-14 15:45:44 +03003426
3427out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003428 mutex_unlock(&mvm->mutex);
3429}
3430
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003431static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3432 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02003433 struct ieee80211_chanctx_conf *ctx,
3434 bool switching_chanctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003435{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003436 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3437 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01003438 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3439 int ret;
3440
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003441 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003442
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003443 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003444
3445 switch (vif->type) {
3446 case NL80211_IFTYPE_AP:
Luciano Coelho4741dd02014-11-10 11:10:13 +02003447 /* only needed if we're switching chanctx (i.e. during CSA) */
3448 if (switching_chanctx) {
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003449 mvmvif->ap_ibss_active = true;
3450 break;
3451 }
Johannes Berg5023d962013-07-31 14:07:43 +02003452 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003453 /*
3454 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02003455 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01003456 */
3457 ret = 0;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003458 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003459 case NL80211_IFTYPE_STATION:
Luciano Coelho2533edc2014-08-08 19:50:46 +03003460 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003461 case NL80211_IFTYPE_MONITOR:
Luciano Coelho2533edc2014-08-08 19:50:46 +03003462 /* always disable PS when a monitor interface is active */
3463 mvmvif->ps_disabled = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003464 break;
3465 default:
3466 ret = -EINVAL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003467 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003468 }
3469
3470 ret = iwl_mvm_binding_add_vif(mvm, vif);
3471 if (ret)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003472 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003473
3474 /*
Alexander Bondar92d85562013-10-23 11:50:34 +02003475 * Power state must be updated before quotas,
3476 * otherwise fw will complain.
3477 */
Arik Nemtsov999609f2014-05-15 17:31:51 +03003478 iwl_mvm_power_update_mac(mvm);
Alexander Bondar92d85562013-10-23 11:50:34 +02003479
3480 /* Setting the quota at this stage is only required for monitor
Johannes Berg8ca151b2013-01-24 14:25:36 +01003481 * interfaces. For the other types, the bss_info changed flow
3482 * will handle quota settings.
3483 */
3484 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02003485 mvmvif->monitor_active = true;
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003486 ret = iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003487 if (ret)
3488 goto out_remove_binding;
Chaya Rachel Ivgi0e39eb02015-12-03 15:51:46 +02003489
3490 ret = iwl_mvm_add_snif_sta(mvm, vif);
3491 if (ret)
3492 goto out_remove_binding;
3493
Johannes Berg8ca151b2013-01-24 14:25:36 +01003494 }
3495
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003496 /* Handle binding during CSA */
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003497 if (vif->type == NL80211_IFTYPE_AP) {
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003498 iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02003499 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003500 }
3501
Luciano Coelho4741dd02014-11-10 11:10:13 +02003502 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
Luciano Coelho686e7fe2014-11-10 11:10:21 +02003503 u32 duration = 2 * vif->bss_conf.beacon_int;
3504
3505 /* iwl_mvm_protect_session() reads directly from the
3506 * device (the system time), so make sure it is
3507 * available.
3508 */
3509 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3510 if (ret)
3511 goto out_remove_binding;
3512
3513 /* Protect the session to make sure we hear the first
3514 * beacon on the new channel.
3515 */
3516 iwl_mvm_protect_session(mvm, vif, duration, duration,
3517 vif->bss_conf.beacon_int / 2,
3518 true);
3519
3520 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3521
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003522 iwl_mvm_update_quotas(mvm, false, NULL);
Luciano Coelho0ce04ce2014-05-08 16:03:39 +03003523 }
3524
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003525 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003526
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003527out_remove_binding:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003528 iwl_mvm_binding_remove_vif(mvm, vif);
Arik Nemtsov999609f2014-05-15 17:31:51 +03003529 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003530out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003531 if (ret)
3532 mvmvif->phy_ctxt = NULL;
3533 return ret;
3534}
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003535static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3536 struct ieee80211_vif *vif,
3537 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003538{
3539 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003540 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003541
3542 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003543 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003544 mutex_unlock(&mvm->mutex);
3545
3546 return ret;
3547}
3548
3549static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3550 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02003551 struct ieee80211_chanctx_conf *ctx,
3552 bool switching_chanctx)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003553{
3554 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003555 struct ieee80211_vif *disabled_vif = NULL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003556
3557 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003558
3559 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3560
Johannes Berg8ca151b2013-01-24 14:25:36 +01003561 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02003562 case NL80211_IFTYPE_ADHOC:
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003563 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003564 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02003565 mvmvif->monitor_active = false;
Luciano Coelho2533edc2014-08-08 19:50:46 +03003566 mvmvif->ps_disabled = false;
Chaya Rachel Ivgi0e39eb02015-12-03 15:51:46 +02003567 iwl_mvm_rm_snif_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003568 break;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003569 case NL80211_IFTYPE_AP:
3570 /* This part is triggered only during CSA */
Luciano Coelho4741dd02014-11-10 11:10:13 +02003571 if (!switching_chanctx || !mvmvif->ap_ibss_active)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003572 goto out;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003573
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003574 mvmvif->csa_countdown = false;
3575
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03003576 /* Set CS bit on all the stations */
3577 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3578
3579 /* Save blocked iface, the timeout is set on the next beacon */
3580 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3581
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003582 mvmvif->ap_ibss_active = false;
Luciano Coelhof0c97782014-03-05 15:41:48 +02003583 break;
3584 case NL80211_IFTYPE_STATION:
3585 if (!switching_chanctx)
3586 break;
3587
3588 disabled_vif = vif;
3589
Johannes Berg3dfd3a92014-08-11 21:37:30 +02003590 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003591 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003592 default:
3593 break;
3594 }
3595
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003596 iwl_mvm_update_quotas(mvm, false, disabled_vif);
Ilan Peer1e1391c2013-03-13 14:52:04 +02003597 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03003598
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003599out:
Ilan Peera11e1442013-12-31 21:19:55 +02003600 mvmvif->phy_ctxt = NULL;
Arik Nemtsov999609f2014-05-15 17:31:51 +03003601 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003602}
3603
3604static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3605 struct ieee80211_vif *vif,
3606 struct ieee80211_chanctx_conf *ctx)
3607{
3608 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3609
3610 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003611 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003612 mutex_unlock(&mvm->mutex);
3613}
3614
Luciano Coelho50cc9572014-11-10 11:10:08 +02003615static int
3616iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3617 struct ieee80211_vif_chanctx_switch *vifs)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003618{
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003619 int ret;
3620
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003621 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003622 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003623 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3624
3625 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3626 if (ret) {
3627 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3628 goto out_reassign;
3629 }
3630
Luciano Coelhof0c97782014-03-05 15:41:48 +02003631 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3632 true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003633 if (ret) {
3634 IWL_ERR(mvm,
3635 "failed to assign new_ctx during channel switch\n");
3636 goto out_remove;
3637 }
3638
Arik Nemtsovf6972672014-06-15 16:03:55 +03003639 /* we don't support TDLS during DCM - can be caused by channel switch */
3640 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3641 iwl_mvm_teardown_tdls_peers(mvm);
3642
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003643 goto out;
3644
3645out_remove:
3646 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3647
3648out_reassign:
Luciano Coelho6fd1fb62014-11-10 11:10:10 +02003649 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003650 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3651 goto out_restart;
3652 }
3653
Luciano Coelho6fd1fb62014-11-10 11:10:10 +02003654 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3655 true)) {
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003656 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3657 goto out_restart;
3658 }
3659
3660 goto out;
3661
3662out_restart:
3663 /* things keep failing, better restart the hw */
3664 iwl_mvm_nic_restart(mvm, false);
3665
3666out:
3667 mutex_unlock(&mvm->mutex);
Luciano Coelho50cc9572014-11-10 11:10:08 +02003668
3669 return ret;
3670}
3671
Luciano Coelho48a256e2014-11-10 11:10:09 +02003672static int
3673iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3674 struct ieee80211_vif_chanctx_switch *vifs)
3675{
3676 int ret;
3677
3678 mutex_lock(&mvm->mutex);
3679 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3680
3681 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3682 true);
3683 if (ret) {
3684 IWL_ERR(mvm,
3685 "failed to assign new_ctx during channel switch\n");
3686 goto out_reassign;
3687 }
3688
3689 goto out;
3690
3691out_reassign:
3692 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3693 true)) {
3694 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3695 goto out_restart;
3696 }
3697
3698 goto out;
3699
3700out_restart:
3701 /* things keep failing, better restart the hw */
3702 iwl_mvm_nic_restart(mvm, false);
3703
3704out:
3705 mutex_unlock(&mvm->mutex);
3706
3707 return ret;
3708}
3709
Luciano Coelho50cc9572014-11-10 11:10:08 +02003710static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3711 struct ieee80211_vif_chanctx_switch *vifs,
3712 int n_vifs,
3713 enum ieee80211_chanctx_switch_mode mode)
3714{
3715 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3716 int ret;
3717
3718 /* we only support a single-vif right now */
3719 if (n_vifs > 1)
3720 return -EOPNOTSUPP;
3721
3722 switch (mode) {
3723 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3724 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3725 break;
3726 case CHANCTX_SWMODE_REASSIGN_VIF:
Luciano Coelho48a256e2014-11-10 11:10:09 +02003727 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
Luciano Coelho50cc9572014-11-10 11:10:08 +02003728 break;
3729 default:
3730 ret = -EOPNOTSUPP;
3731 break;
3732 }
3733
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003734 return ret;
3735}
3736
Johannes Berg2f0282d2017-04-20 10:29:03 +02003737static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
3738{
3739 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3740
3741 return mvm->ibss_manager;
3742}
3743
Johannes Berg8ca151b2013-01-24 14:25:36 +01003744static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3745 struct ieee80211_sta *sta,
3746 bool set)
3747{
3748 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01003749 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003750
3751 if (!mvm_sta || !mvm_sta->vif) {
3752 IWL_ERR(mvm, "Station is not associated to a vif\n");
3753 return -EINVAL;
3754 }
3755
3756 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3757}
3758
David Spinadel507cadf2013-07-31 18:07:21 +03003759#ifdef CONFIG_NL80211_TESTMODE
3760static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3761 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3762 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad422013-08-01 14:17:15 +02003763 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03003764};
3765
3766static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3767 struct ieee80211_vif *vif,
3768 void *data, int len)
3769{
3770 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3771 int err;
3772 u32 noa_duration;
3773
Johannes Bergfceb6432017-04-12 14:34:07 +02003774 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
3775 NULL);
David Spinadel507cadf2013-07-31 18:07:21 +03003776 if (err)
3777 return err;
3778
3779 if (!tb[IWL_MVM_TM_ATTR_CMD])
3780 return -EINVAL;
3781
3782 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3783 case IWL_MVM_TM_CMD_SET_NOA:
3784 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3785 !vif->bss_conf.enable_beacon ||
3786 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3787 return -EINVAL;
3788
3789 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3790 if (noa_duration >= vif->bss_conf.beacon_int)
3791 return -EINVAL;
3792
3793 mvm->noa_duration = noa_duration;
3794 mvm->noa_vif = vif;
3795
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003796 return iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Bergf6c6ad422013-08-01 14:17:15 +02003797 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3798 /* must be associated client vif - ignore authorized */
3799 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3800 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3801 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3802 return -EINVAL;
3803
3804 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03003805 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3806 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
David Spinadel507cadf2013-07-31 18:07:21 +03003807 }
3808
3809 return -EOPNOTSUPP;
3810}
3811
3812static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3813 struct ieee80211_vif *vif,
3814 void *data, int len)
3815{
3816 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3817 int err;
3818
3819 mutex_lock(&mvm->mutex);
3820 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3821 mutex_unlock(&mvm->mutex);
3822
3823 return err;
3824}
3825#endif
3826
Luciano Coelho622e3f92014-11-10 11:10:17 +02003827static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3828 struct ieee80211_vif *vif,
3829 struct ieee80211_channel_switch *chsw)
3830{
3831 /* By implementing this operation, we prevent mac80211 from
3832 * starting its own channel switch timer, so that we can call
3833 * ieee80211_chswitch_done() ourselves at the right time
3834 * (which is when the absence time event starts).
3835 */
3836
3837 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3838 "dummy channel switch op\n");
3839}
3840
Luciano Coelhof0289052014-11-10 11:10:06 +02003841static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3842 struct ieee80211_vif *vif,
3843 struct ieee80211_channel_switch *chsw)
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003844{
3845 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003846 struct ieee80211_vif *csa_vif;
Luciano Coelhof6c34822014-11-10 11:10:12 +02003847 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003848 u32 apply_time;
Luciano Coelhof0289052014-11-10 11:10:06 +02003849 int ret;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003850
3851 mutex_lock(&mvm->mutex);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003852
Johannes Berg81d62d52015-03-10 14:44:00 +01003853 mvmvif->csa_failed = false;
3854
Luciano Coelho6b20d772014-11-10 11:10:07 +02003855 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
Luciano Coelhof0289052014-11-10 11:10:06 +02003856 chsw->chandef.center_freq1);
Luciano Coelho6b20d772014-11-10 11:10:07 +02003857
Johannes Berg7174beb2017-06-01 16:03:19 +02003858 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
3859 ieee80211_vif_to_wdev(vif),
3860 FW_DBG_TRIGGER_CHANNEL_SWITCH);
Emmanuel Grumbachf35d9c52015-02-10 10:49:51 +02003861
Luciano Coelho6b20d772014-11-10 11:10:07 +02003862 switch (vif->type) {
3863 case NL80211_IFTYPE_AP:
3864 csa_vif =
3865 rcu_dereference_protected(mvm->csa_vif,
3866 lockdep_is_held(&mvm->mutex));
3867 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3868 "Another CSA is already in progress")) {
3869 ret = -EBUSY;
3870 goto out_unlock;
3871 }
3872
Andrei Otcheretianskid3a108a2016-02-28 17:12:21 +02003873 /* we still didn't unblock tx. prevent new CS meanwhile */
3874 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
3875 lockdep_is_held(&mvm->mutex))) {
3876 ret = -EBUSY;
3877 goto out_unlock;
3878 }
3879
Luciano Coelho6b20d772014-11-10 11:10:07 +02003880 rcu_assign_pointer(mvm->csa_vif, vif);
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003881
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003882 if (WARN_ONCE(mvmvif->csa_countdown,
3883 "Previous CSA countdown didn't complete")) {
3884 ret = -EBUSY;
3885 goto out_unlock;
3886 }
3887
Andrei Otcheretianskid3a108a2016-02-28 17:12:21 +02003888 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
3889
Luciano Coelho6b20d772014-11-10 11:10:07 +02003890 break;
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003891 case NL80211_IFTYPE_STATION:
Luciano Coelho4500e132014-11-10 11:10:15 +02003892 /* Schedule the time event to a bit before beacon 1,
3893 * to make sure we're in the new channel when the
Ilan Peerf5d8f502017-08-08 14:56:58 +03003894 * GO/AP arrives. In case count <= 1 immediately schedule the
3895 * TE (this might result with some packet loss or connection
3896 * loss).
Luciano Coelho4500e132014-11-10 11:10:15 +02003897 */
Ilan Peerf5d8f502017-08-08 14:56:58 +03003898 if (chsw->count <= 1)
3899 apply_time = 0;
3900 else
3901 apply_time = chsw->device_timestamp +
3902 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3903 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003904
3905 if (chsw->block_tx)
3906 iwl_mvm_csa_client_absent(mvm, vif);
3907
Luciano Coelho4500e132014-11-10 11:10:15 +02003908 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003909 apply_time);
Luciano Coelhoc6e0a3e02014-11-10 11:10:18 +02003910 if (mvmvif->bf_data.bf_enabled) {
3911 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3912 if (ret)
3913 goto out_unlock;
3914 }
3915
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003916 break;
Luciano Coelho6b20d772014-11-10 11:10:07 +02003917 default:
3918 break;
3919 }
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003920
Luciano Coelhof6c34822014-11-10 11:10:12 +02003921 mvmvif->ps_disabled = true;
3922
3923 ret = iwl_mvm_power_update_ps(mvm);
3924 if (ret)
3925 goto out_unlock;
Luciano Coelhof0289052014-11-10 11:10:06 +02003926
Arik Nemtsove198f5e2014-09-14 19:13:54 +03003927 /* we won't be on this channel any longer */
3928 iwl_mvm_teardown_tdls_peers(mvm);
3929
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003930out_unlock:
3931 mutex_unlock(&mvm->mutex);
Luciano Coelhof0289052014-11-10 11:10:06 +02003932
3933 return ret;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003934}
3935
Luciano Coelhof6c34822014-11-10 11:10:12 +02003936static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
3937 struct ieee80211_vif *vif)
3938{
3939 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3940 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3941 int ret;
3942
3943 mutex_lock(&mvm->mutex);
3944
Johannes Berg81d62d52015-03-10 14:44:00 +01003945 if (mvmvif->csa_failed) {
3946 mvmvif->csa_failed = false;
3947 ret = -EIO;
3948 goto out_unlock;
3949 }
3950
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003951 if (vif->type == NL80211_IFTYPE_STATION) {
3952 struct iwl_mvm_sta *mvmsta;
3953
3954 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
3955 mvmvif->ap_sta_id);
3956
3957 if (WARN_ON(!mvmsta)) {
3958 ret = -EIO;
3959 goto out_unlock;
3960 }
3961
3962 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
3963
3964 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Luciano Coelhoc6e0a3e02014-11-10 11:10:18 +02003965
3966 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3967 if (ret)
3968 goto out_unlock;
Luciano Coelho686e7fe2014-11-10 11:10:21 +02003969
3970 iwl_mvm_stop_session_protection(mvm, vif);
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003971 }
3972
Luciano Coelhof6c34822014-11-10 11:10:12 +02003973 mvmvif->ps_disabled = false;
3974
3975 ret = iwl_mvm_power_update_ps(mvm);
3976
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003977out_unlock:
Luciano Coelhof6c34822014-11-10 11:10:12 +02003978 mutex_unlock(&mvm->mutex);
3979
3980 return ret;
3981}
3982
David Spinadel6110d9e2017-08-29 13:56:02 +03003983static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
3984{
Sara Sharon435d0822017-09-12 11:06:24 +03003985 int i;
3986
Sara Sharon06195632017-09-12 10:52:53 +03003987 if (!iwl_mvm_has_new_tx_api(mvm)) {
Luca Coelho309c4842017-10-24 22:04:15 +03003988 if (drop) {
3989 mutex_lock(&mvm->mutex);
David Spinadel6110d9e2017-08-29 13:56:02 +03003990 iwl_mvm_flush_tx_path(mvm,
Sara Sharon435d0822017-09-12 11:06:24 +03003991 iwl_mvm_flushable_queues(mvm) & queues, 0);
Luca Coelho309c4842017-10-24 22:04:15 +03003992 mutex_unlock(&mvm->mutex);
3993 } else {
Sara Sharon06195632017-09-12 10:52:53 +03003994 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
Luca Coelho309c4842017-10-24 22:04:15 +03003995 }
Sara Sharon435d0822017-09-12 11:06:24 +03003996 return;
3997 }
3998
3999 mutex_lock(&mvm->mutex);
4000 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4001 struct ieee80211_sta *sta;
4002
4003 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4004 lockdep_is_held(&mvm->mutex));
4005 if (IS_ERR_OR_NULL(sta))
4006 continue;
4007
Sara Sharon06195632017-09-12 10:52:53 +03004008 if (drop)
4009 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4010 else
4011 iwl_mvm_wait_sta_queues_empty(mvm,
4012 iwl_mvm_sta_from_mac80211(sta));
Sara Sharon435d0822017-09-12 11:06:24 +03004013 }
4014 mutex_unlock(&mvm->mutex);
David Spinadel6110d9e2017-08-29 13:56:02 +03004015}
4016
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004017static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4018 struct ieee80211_vif *vif, u32 queues, bool drop)
4019{
4020 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4021 struct iwl_mvm_vif *mvmvif;
4022 struct iwl_mvm_sta *mvmsta;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03004023 struct ieee80211_sta *sta;
4024 int i;
4025 u32 msk = 0;
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004026
David Spinadel6110d9e2017-08-29 13:56:02 +03004027 if (!vif) {
4028 iwl_mvm_flush_no_vif(mvm, queues, drop);
4029 return;
4030 }
4031
4032 if (vif->type != NL80211_IFTYPE_STATION)
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004033 return;
4034
Liad Kaufman24afba72015-07-28 18:56:08 +03004035 /* Make sure we're done with the deferred traffic before flushing */
Johannes Bergc8f54702017-06-19 23:50:31 +02004036 flush_work(&mvm->add_stream_wk);
Liad Kaufman24afba72015-07-28 18:56:08 +03004037
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004038 mutex_lock(&mvm->mutex);
4039 mvmvif = iwl_mvm_vif_from_mac80211(vif);
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004040
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03004041 /* flush the AP-station and all TDLS peers */
Sara Sharon0ae98812017-01-04 14:53:58 +02004042 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03004043 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4044 lockdep_is_held(&mvm->mutex));
4045 if (IS_ERR_OR_NULL(sta))
4046 continue;
4047
4048 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4049 if (mvmsta->vif != vif)
4050 continue;
4051
4052 /* make sure only TDLS peers or the AP are flushed */
4053 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4054
Sara Sharond49394a2017-03-05 13:01:08 +02004055 if (drop) {
4056 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4057 IWL_ERR(mvm, "flush request fail\n");
4058 } else {
4059 msk |= mvmsta->tfd_queue_msk;
Sara Sharond6d517b2017-03-06 10:16:11 +02004060 if (iwl_mvm_has_new_tx_api(mvm))
4061 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
Sara Sharond49394a2017-03-05 13:01:08 +02004062 }
Johannes Berg480acbc2014-10-10 08:59:27 +02004063 }
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004064
Sara Sharond49394a2017-03-05 13:01:08 +02004065 mutex_unlock(&mvm->mutex);
Johannes Berg480acbc2014-10-10 08:59:27 +02004066
Sara Sharond49394a2017-03-05 13:01:08 +02004067 /* this can take a while, and we may need/want other operations
4068 * to succeed while doing this, so do it without the mutex held
4069 */
Sara Sharond6d517b2017-03-06 10:16:11 +02004070 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
Sara Sharona1a57872017-03-05 11:38:58 +02004071 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004072}
4073
Johannes Berg91a8bcd2015-01-14 18:12:41 +01004074static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4075 struct survey_info *survey)
4076{
4077 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4078 int ret;
4079
4080 memset(survey, 0, sizeof(*survey));
4081
4082 /* only support global statistics right now */
4083 if (idx != 0)
4084 return -ENOENT;
4085
Johannes Berg280a3ef2016-06-07 14:46:37 +02004086 if (!fw_has_capa(&mvm->fw->ucode_capa,
4087 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
Johannes Berg91a8bcd2015-01-14 18:12:41 +01004088 return -ENOENT;
4089
4090 mutex_lock(&mvm->mutex);
4091
Johannes Bergaab69302017-03-22 22:05:12 +01004092 if (iwl_mvm_firmware_running(mvm)) {
Johannes Berg33cef922015-01-21 21:41:29 +01004093 ret = iwl_mvm_request_statistics(mvm, false);
Johannes Berg91a8bcd2015-01-14 18:12:41 +01004094 if (ret)
4095 goto out;
4096 }
4097
4098 survey->filled = SURVEY_INFO_TIME |
4099 SURVEY_INFO_TIME_RX |
4100 SURVEY_INFO_TIME_TX |
4101 SURVEY_INFO_TIME_SCAN;
4102 survey->time = mvm->accu_radio_stats.on_time_rf +
4103 mvm->radio_stats.on_time_rf;
4104 do_div(survey->time, USEC_PER_MSEC);
4105
4106 survey->time_rx = mvm->accu_radio_stats.rx_time +
4107 mvm->radio_stats.rx_time;
4108 do_div(survey->time_rx, USEC_PER_MSEC);
4109
4110 survey->time_tx = mvm->accu_radio_stats.tx_time +
4111 mvm->radio_stats.tx_time;
4112 do_div(survey->time_tx, USEC_PER_MSEC);
4113
4114 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4115 mvm->radio_stats.on_time_scan;
4116 do_div(survey->time_scan, USEC_PER_MSEC);
4117
Johannes Berg10a7c0282015-04-01 10:00:31 +02004118 ret = 0;
Johannes Berg91a8bcd2015-01-14 18:12:41 +01004119 out:
4120 mutex_unlock(&mvm->mutex);
4121 return ret;
4122}
4123
Johannes Berg33cef922015-01-21 21:41:29 +01004124static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4125 struct ieee80211_vif *vif,
4126 struct ieee80211_sta *sta,
4127 struct station_info *sinfo)
4128{
4129 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4130 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4131 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4132
Sara Sharon988b5962016-04-10 15:06:55 +03004133 if (mvmsta->avg_energy) {
4134 sinfo->signal_avg = mvmsta->avg_energy;
4135 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL_AVG);
4136 }
4137
Johannes Berg280a3ef2016-06-07 14:46:37 +02004138 if (!fw_has_capa(&mvm->fw->ucode_capa,
4139 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
Johannes Berg33cef922015-01-21 21:41:29 +01004140 return;
4141
4142 /* if beacon filtering isn't on mac80211 does it anyway */
4143 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4144 return;
4145
4146 if (!vif->bss_conf.assoc)
4147 return;
4148
4149 mutex_lock(&mvm->mutex);
4150
4151 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4152 goto unlock;
4153
4154 if (iwl_mvm_request_statistics(mvm, false))
4155 goto unlock;
4156
4157 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4158 mvmvif->beacon_stats.accu_num_beacons;
4159 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX);
4160 if (mvmvif->beacon_stats.avg_signal) {
4161 /* firmware only reports a value after RXing a few beacons */
4162 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4163 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4164 }
4165 unlock:
4166 mutex_unlock(&mvm->mutex);
4167}
4168
Emmanuel Grumbach42032632015-04-15 12:43:46 +03004169static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4170 struct ieee80211_vif *vif,
4171 const struct ieee80211_event *event)
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004172{
Johannes Berg7174beb2017-06-01 16:03:19 +02004173#define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4174 do { \
4175 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4176 break; \
4177 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004178 } while (0)
4179
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004180 struct iwl_fw_dbg_trigger_tlv *trig;
4181 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004182
4183 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
4184 return;
4185
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004186 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
4187 trig_mlme = (void *)trig->data;
Johannes Berg7174beb2017-06-01 16:03:19 +02004188 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4189 ieee80211_vif_to_wdev(vif), trig))
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004190 return;
4191
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004192 if (event->u.mlme.data == ASSOC_EVENT) {
4193 if (event->u.mlme.status == MLME_DENIED)
Luca Coelho4c324a52017-05-19 15:06:29 +03004194 CHECK_MLME_TRIGGER(stop_assoc_denied,
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004195 "DENIED ASSOC: reason %d",
4196 event->u.mlme.reason);
4197 else if (event->u.mlme.status == MLME_TIMEOUT)
Luca Coelho4c324a52017-05-19 15:06:29 +03004198 CHECK_MLME_TRIGGER(stop_assoc_timeout,
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004199 "ASSOC TIMEOUT");
4200 } else if (event->u.mlme.data == AUTH_EVENT) {
4201 if (event->u.mlme.status == MLME_DENIED)
Luca Coelho4c324a52017-05-19 15:06:29 +03004202 CHECK_MLME_TRIGGER(stop_auth_denied,
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004203 "DENIED AUTH: reason %d",
4204 event->u.mlme.reason);
4205 else if (event->u.mlme.status == MLME_TIMEOUT)
Luca Coelho4c324a52017-05-19 15:06:29 +03004206 CHECK_MLME_TRIGGER(stop_auth_timeout,
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004207 "AUTH TIMEOUT");
4208 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
Luca Coelho4c324a52017-05-19 15:06:29 +03004209 CHECK_MLME_TRIGGER(stop_rx_deauth,
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004210 "DEAUTH RX %d", event->u.mlme.reason);
4211 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
Luca Coelho4c324a52017-05-19 15:06:29 +03004212 CHECK_MLME_TRIGGER(stop_tx_deauth,
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004213 "DEAUTH TX %d", event->u.mlme.reason);
4214 }
4215#undef CHECK_MLME_TRIGGER
4216}
4217
Emmanuel Grumbach42032632015-04-15 12:43:46 +03004218static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4219 struct ieee80211_vif *vif,
4220 const struct ieee80211_event *event)
4221{
4222 struct iwl_fw_dbg_trigger_tlv *trig;
4223 struct iwl_fw_dbg_trigger_ba *ba_trig;
4224
4225 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
4226 return;
4227
4228 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
4229 ba_trig = (void *)trig->data;
Johannes Berg7174beb2017-06-01 16:03:19 +02004230 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4231 ieee80211_vif_to_wdev(vif), trig))
Emmanuel Grumbach42032632015-04-15 12:43:46 +03004232 return;
4233
4234 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4235 return;
4236
Johannes Berg7174beb2017-06-01 16:03:19 +02004237 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4238 "BAR received from %pM, tid %d, ssn %d",
4239 event->u.ba.sta->addr, event->u.ba.tid,
4240 event->u.ba.ssn);
Emmanuel Grumbach42032632015-04-15 12:43:46 +03004241}
4242
Emmanuel Grumbach42032632015-04-15 12:43:46 +03004243static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4244 struct ieee80211_vif *vif,
4245 const struct ieee80211_event *event)
4246{
4247 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4248
4249 switch (event->type) {
4250 case MLME_EVENT:
4251 iwl_mvm_event_mlme_callback(mvm, vif, event);
4252 break;
4253 case BAR_RX_EVENT:
4254 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4255 break;
4256 case BA_FRAME_TIMEOUT:
Emmanuel Grumbach528a5422017-08-31 11:52:30 +03004257 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
4258 event->u.ba.tid);
Emmanuel Grumbach42032632015-04-15 12:43:46 +03004259 break;
4260 default:
4261 break;
4262 }
4263}
4264
Sara Sharond0ff5d22016-03-23 16:31:43 +02004265void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4266 struct iwl_mvm_internal_rxq_notif *notif,
4267 u32 size)
Sara Sharon0636b932016-02-18 14:21:12 +02004268{
Sara Sharon0636b932016-02-18 14:21:12 +02004269 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4270 int ret;
4271
4272 lockdep_assert_held(&mvm->mutex);
4273
Sara Sharoncb8550e2017-10-19 08:46:50 +03004274 if (!iwl_mvm_has_new_rx_api(mvm))
Sara Sharon0636b932016-02-18 14:21:12 +02004275 return;
4276
Sara Sharond0ff5d22016-03-23 16:31:43 +02004277 notif->cookie = mvm->queue_sync_cookie;
Sara Sharon0636b932016-02-18 14:21:12 +02004278
Sara Sharond0ff5d22016-03-23 16:31:43 +02004279 if (notif->sync)
4280 atomic_set(&mvm->queue_sync_counter,
4281 mvm->trans->num_rx_queues);
4282
Sara Sharoncb8550e2017-10-19 08:46:50 +03004283 /* TODO - remove this when we have RXQ config API */
4284 if (mvm->trans->cfg->device_family == IWL_DEVICE_FAMILY_A000) {
4285 qmask = BIT(0);
4286 if (notif->sync)
4287 atomic_set(&mvm->queue_sync_counter, 1);
4288 }
4289
Sara Sharond0ff5d22016-03-23 16:31:43 +02004290 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
Sara Sharon0636b932016-02-18 14:21:12 +02004291 if (ret) {
4292 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4293 goto out;
4294 }
Sara Sharond0ff5d22016-03-23 16:31:43 +02004295
Johannes Berg6ad04352017-04-25 10:21:18 +02004296 if (notif->sync) {
Sara Sharon3a732c62016-10-09 17:34:24 +03004297 ret = wait_event_timeout(mvm->rx_sync_waitq,
Johannes Berg6ad04352017-04-25 10:21:18 +02004298 atomic_read(&mvm->queue_sync_counter) == 0 ||
4299 iwl_mvm_is_radio_killed(mvm),
Sara Sharond0ff5d22016-03-23 16:31:43 +02004300 HZ);
Johannes Berg6ad04352017-04-25 10:21:18 +02004301 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4302 }
Sara Sharon0636b932016-02-18 14:21:12 +02004303
4304out:
4305 atomic_set(&mvm->queue_sync_counter, 0);
4306 mvm->queue_sync_cookie++;
4307}
4308
4309static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4310{
4311 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Sara Sharond0ff5d22016-03-23 16:31:43 +02004312 struct iwl_mvm_internal_rxq_notif data = {
4313 .type = IWL_MVM_RXQ_EMPTY,
4314 .sync = 1,
4315 };
Sara Sharon0636b932016-02-18 14:21:12 +02004316
4317 mutex_lock(&mvm->mutex);
Sara Sharond0ff5d22016-03-23 16:31:43 +02004318 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
Sara Sharon0636b932016-02-18 14:21:12 +02004319 mutex_unlock(&mvm->mutex);
4320}
4321
Johannes Berge5209262014-01-20 23:38:59 +01004322const struct ieee80211_ops iwl_mvm_hw_ops = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01004323 .tx = iwl_mvm_mac_tx,
4324 .ampdu_action = iwl_mvm_mac_ampdu_action,
4325 .start = iwl_mvm_mac_start,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004326 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004327 .stop = iwl_mvm_mac_stop,
4328 .add_interface = iwl_mvm_mac_add_interface,
4329 .remove_interface = iwl_mvm_mac_remove_interface,
4330 .config = iwl_mvm_mac_config,
Eliad Pellere59647e2013-11-28 14:08:50 +02004331 .prepare_multicast = iwl_mvm_prepare_multicast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004332 .configure_filter = iwl_mvm_configure_filter,
Andrei Otcheretianskieffd1922015-06-30 12:08:28 +03004333 .config_iface_filter = iwl_mvm_config_iface_filter,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004334 .bss_info_changed = iwl_mvm_bss_info_changed,
4335 .hw_scan = iwl_mvm_mac_hw_scan,
4336 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
Johannes Berg1ddbbb02013-12-04 22:39:17 +01004337 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004338 .sta_state = iwl_mvm_mac_sta_state,
4339 .sta_notify = iwl_mvm_mac_sta_notify,
4340 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
Johannes Berg3e56ead2013-02-15 22:23:18 +01004341 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004342 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02004343 .sta_rc_update = iwl_mvm_sta_rc_update,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004344 .conf_tx = iwl_mvm_mac_conf_tx,
4345 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
Arik Nemtsov07ecd892014-05-20 18:16:42 +03004346 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004347 .flush = iwl_mvm_mac_flush,
David Spinadel35a000b2013-08-28 09:29:43 +03004348 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4349 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004350 .set_key = iwl_mvm_mac_set_key,
4351 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4352 .remain_on_channel = iwl_mvm_roc,
4353 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004354 .add_chanctx = iwl_mvm_add_chanctx,
4355 .remove_chanctx = iwl_mvm_remove_chanctx,
4356 .change_chanctx = iwl_mvm_change_chanctx,
4357 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4358 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
Luciano Coelhob08c1d92014-05-20 23:31:05 +03004359 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004360
Johannes Berg5023d962013-07-31 14:07:43 +02004361 .start_ap = iwl_mvm_start_ap_ibss,
4362 .stop_ap = iwl_mvm_stop_ap_ibss,
4363 .join_ibss = iwl_mvm_start_ap_ibss,
4364 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004365
Johannes Berg2f0282d2017-04-20 10:29:03 +02004366 .tx_last_beacon = iwl_mvm_tx_last_beacon,
4367
Johannes Berg8ca151b2013-01-24 14:25:36 +01004368 .set_tim = iwl_mvm_set_tim,
4369
Luciano Coelho622e3f92014-11-10 11:10:17 +02004370 .channel_switch = iwl_mvm_channel_switch,
Luciano Coelhof0289052014-11-10 11:10:06 +02004371 .pre_channel_switch = iwl_mvm_pre_channel_switch,
Luciano Coelhof6c34822014-11-10 11:10:12 +02004372 .post_channel_switch = iwl_mvm_post_channel_switch,
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02004373
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +03004374 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4375 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4376 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4377
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004378 .event_callback = iwl_mvm_mac_event_callback,
4379
Sara Sharon0636b932016-02-18 14:21:12 +02004380 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4381
David Spinadel507cadf2013-07-31 18:07:21 +03004382 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4383
Johannes Berg8ca151b2013-01-24 14:25:36 +01004384#ifdef CONFIG_PM_SLEEP
4385 /* look at d3.c */
4386 .suspend = iwl_mvm_suspend,
4387 .resume = iwl_mvm_resume,
4388 .set_wakeup = iwl_mvm_set_wakeup,
4389 .set_rekey_data = iwl_mvm_set_rekey_data,
4390#if IS_ENABLED(CONFIG_IPV6)
4391 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4392#endif
4393 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4394#endif
Johannes Berg91a8bcd2015-01-14 18:12:41 +01004395 .get_survey = iwl_mvm_mac_get_survey,
Johannes Berg33cef922015-01-21 21:41:29 +01004396 .sta_statistics = iwl_mvm_mac_sta_statistics,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004397};