blob: 4ff099f462fb628a2260627dc36497745887b71d [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);
Gregory Greenmanecaf71d2017-11-01 07:16:29 +0200423
424 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TLC_OFFLOAD)) {
425 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
426 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
427 }
428
Sara Sharonb915c102016-03-23 16:32:02 +0200429 if (iwl_mvm_has_new_rx_api(mvm))
430 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
Johannes Berg960f8642017-06-20 15:18:43 +0200431
432 if (fw_has_capa(&mvm->fw->ucode_capa,
433 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
Johannes Berg65e25482016-04-13 14:24:22 +0200434 ieee80211_hw_set(hw, AP_LINK_PS);
Johannes Berg960f8642017-06-20 15:18:43 +0200435 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
436 /*
437 * we absolutely need this for the new TX API since that comes
438 * with many more queues than the current code can deal with
439 * for station powersave
440 */
441 return -EINVAL;
442 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100443
Johannes Berg80938ab2016-03-30 11:05:16 +0200444 if (mvm->trans->num_rx_queues > 1)
445 ieee80211_hw_set(hw, USES_RSS);
446
Johannes Berg2d7cf542015-04-17 16:39:12 +0200447 if (mvm->trans->max_skb_frags)
448 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
449
Johannes Bergc8f54702017-06-19 23:50:31 +0200450 hw->queues = IEEE80211_MAX_QUEUES;
Ilan Peer398e8c62013-03-13 15:20:35 +0200451 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +0200452 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
453 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
Eyal Shapira339b3082014-11-18 16:43:55 +0200454 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
455 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
Johannes Berg371a17e2016-08-15 09:26:32 +0200456
457 hw->radiotap_timestamp.units_pos =
458 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
459 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
460 /* this is the case for CCK frames, it's better (only 8) for OFDM */
461 hw->radiotap_timestamp.accuracy = 22;
462
Johannes Berg8ca151b2013-01-24 14:25:36 +0100463 hw->rate_control_algorithm = "iwl-mvm-rs";
Johannes Berg848955c2014-11-11 12:48:42 +0100464 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
465 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100466
Ayala Beker8e160ab2016-04-11 11:37:38 +0300467 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200468 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
469 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
470 hw->wiphy->cipher_suites = mvm->ciphers;
471
Ayala Beker2a53d162016-04-07 16:21:57 +0300472 if (iwl_mvm_has_new_rx_api(mvm)) {
473 mvm->ciphers[hw->wiphy->n_cipher_suites] =
474 WLAN_CIPHER_SUITE_GCMP;
475 hw->wiphy->n_cipher_suites++;
476 mvm->ciphers[hw->wiphy->n_cipher_suites] =
477 WLAN_CIPHER_SUITE_GCMP_256;
478 hw->wiphy->n_cipher_suites++;
479 }
480
Luca Coelho4b87e5a2016-09-12 16:03:30 +0300481 /* Enable 11w if software crypto is not enabled (as the
482 * firmware will interpret some mgmt packets, so enabling it
483 * with software crypto isn't safe).
Johannes Berg8ca151b2013-01-24 14:25:36 +0100484 */
Johannes Berg3b37f4c2017-05-30 16:45:31 +0200485 if (!iwlwifi_mod_params.swcrypto) {
Johannes Berg30686bf2015-06-02 21:39:54 +0200486 ieee80211_hw_set(hw, MFP_CAPABLE);
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200487 mvm->ciphers[hw->wiphy->n_cipher_suites] =
488 WLAN_CIPHER_SUITE_AES_CMAC;
489 hw->wiphy->n_cipher_suites++;
Ayala Beker8e160ab2016-04-11 11:37:38 +0300490 if (iwl_mvm_has_new_rx_api(mvm)) {
491 mvm->ciphers[hw->wiphy->n_cipher_suites] =
492 WLAN_CIPHER_SUITE_BIP_GMAC_128;
493 hw->wiphy->n_cipher_suites++;
494 mvm->ciphers[hw->wiphy->n_cipher_suites] =
495 WLAN_CIPHER_SUITE_BIP_GMAC_256;
496 hw->wiphy->n_cipher_suites++;
497 }
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200498 }
499
500 /* currently FW API supports only one optional cipher scheme */
501 if (mvm->fw->cs[0].cipher) {
Johannes Berg24ddddf2016-06-21 12:34:36 +0200502 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
503 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
504
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200505 mvm->hw->n_cipher_schemes = 1;
Johannes Berg24ddddf2016-06-21 12:34:36 +0200506
507 cs->cipher = le32_to_cpu(fwcs->cipher);
508 cs->iftype = BIT(NL80211_IFTYPE_STATION);
509 cs->hdr_len = fwcs->hdr_len;
510 cs->pn_len = fwcs->pn_len;
511 cs->pn_off = fwcs->pn_off;
512 cs->key_idx_off = fwcs->key_idx_off;
513 cs->key_idx_mask = fwcs->key_idx_mask;
514 cs->key_idx_shift = fwcs->key_idx_shift;
515 cs->mic_len = fwcs->mic_len;
516
517 mvm->hw->cipher_schemes = mvm->cs;
518 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200519 hw->wiphy->n_cipher_suites++;
520 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100521
Johannes Berg30686bf2015-06-02 21:39:54 +0200522 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
Luciano Coelho1f940382015-02-10 13:03:38 +0200523 hw->wiphy->features |=
524 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
Johannes Berg3db93422015-05-06 14:56:51 +0200525 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
526 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
David Spinadelfb98be52014-05-04 12:51:10 +0300527
Johannes Berg8ca151b2013-01-24 14:25:36 +0100528 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
529 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200530 hw->chanctx_data_size = sizeof(u16);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100531
532 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200533 BIT(NL80211_IFTYPE_P2P_CLIENT) |
534 BIT(NL80211_IFTYPE_AP) |
535 BIT(NL80211_IFTYPE_P2P_GO) |
Emmanuel Grumbachc13b1722014-03-27 19:12:12 +0200536 BIT(NL80211_IFTYPE_P2P_DEVICE) |
537 BIT(NL80211_IFTYPE_ADHOC);
Johannes Berg5023d962013-07-31 14:07:43 +0200538
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +0100539 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200540 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
541 if (iwl_mvm_is_lar_supported(mvm))
542 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
543 else
544 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
545 REGULATORY_DISABLE_BEACON_HINTS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100546
Luca Coelho4b87e5a2016-09-12 16:03:30 +0300547 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Emmanuel Grumbach94bbed72014-11-24 08:53:33 +0200548 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +0200549
Johannes Berg8ca151b2013-01-24 14:25:36 +0100550 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
551 hw->wiphy->n_iface_combinations =
552 ARRAY_SIZE(iwl_mvm_iface_combinations);
553
Ilan Peerc451e6d2013-02-20 08:41:54 +0200554 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100555 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
Emmanuel Grumbachf1a68542014-12-16 12:31:13 +0200556 /* we can compensate an offset of up to 3 channels = 15 MHz */
557 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100558
559 /* Extract MAC address */
560 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
561 hw->wiphy->addresses = mvm->addresses;
562 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200563
564 /* Extract additional MAC addresses if available */
565 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
566 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
567
568 for (i = 1; i < num_mac; i++) {
569 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100570 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200571 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100572 hw->wiphy->n_addresses++;
573 }
574
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200575 iwl_mvm_reset_phy_ctxts(mvm);
576
Luciano Coelho999d2562015-03-27 10:28:26 +0300577 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
David Spinadel20f1a5d2013-08-21 09:14:27 +0300578
Johannes Berg8ca151b2013-01-24 14:25:36 +0100579 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
580
Luciano Coelhoc7d42482015-05-07 16:00:26 +0300581 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
Luciano Coelho507e4cd2015-03-19 22:58:33 +0200582 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
583 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
584
Johannes Berg859d9142015-06-01 17:11:11 +0200585 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
Luciano Coelho507e4cd2015-03-19 22:58:33 +0200586 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
587 else
588 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
589
Johannes Berg57fbcce2016-04-12 15:56:15 +0200590 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
591 hw->wiphy->bands[NL80211_BAND_2GHZ] =
592 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
593 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
594 hw->wiphy->bands[NL80211_BAND_5GHZ] =
595 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
Johannes Berg8ca151b2013-01-24 14:25:36 +0100596
Johannes Berg859d9142015-06-01 17:11:11 +0200597 if (fw_has_capa(&mvm->fw->ucode_capa,
598 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
599 fw_has_api(&mvm->fw->ucode_capa,
600 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
Johannes Berg57fbcce2016-04-12 15:56:15 +0200601 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
Eyal Shapira3d44eeb2015-01-16 22:37:04 +0200602 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
603 }
604
Johannes Berg8ca151b2013-01-24 14:25:36 +0100605 hw->wiphy->hw_version = mvm->trans->hw_id;
606
Alexander Bondarade50652013-04-03 16:28:47 +0300607 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100608 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
609 else
610 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
611
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100612 hw->wiphy->max_sched_scan_reqs = 1;
Emmanuel Grumbach9954b372015-03-16 14:49:55 +0200613 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
614 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
615 /* we create the 802.11 header and zero length SSID IE. */
616 hw->wiphy->max_sched_scan_ie_len =
617 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
Avraham Sterncd55cce2015-08-19 12:46:12 +0300618 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
619 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
620
621 /*
622 * the firmware uses u8 for num of iterations, but 0xff is saved for
623 * infinite loop, so the maximum number of iterations is actually 254.
624 */
625 hw->wiphy->max_sched_scan_plan_iterations = 254;
David Spinadel35a000b2013-08-28 09:29:43 +0300626
Johannes Berg8ca151b2013-01-24 14:25:36 +0100627 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
Johannes Bergab480032014-06-04 10:13:50 +0200628 NL80211_FEATURE_LOW_PRIORITY_SCAN |
Eliad Peller0d8614b2014-09-10 14:07:36 +0300629 NL80211_FEATURE_P2P_GO_OPPPS |
Peer, Ilana904a082016-08-10 13:48:35 +0300630 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
Eliad Peller0d8614b2014-09-10 14:07:36 +0300631 NL80211_FEATURE_DYNAMIC_SMPS |
Emmanuel Grumbach9b5452f2014-10-07 10:38:53 +0300632 NL80211_FEATURE_STATIC_SMPS |
633 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100634
Johannes Berg859d9142015-06-01 17:11:11 +0200635 if (fw_has_capa(&mvm->fw->ucode_capa,
636 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300637 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
Johannes Berg859d9142015-06-01 17:11:11 +0200638 if (fw_has_capa(&mvm->fw->ucode_capa,
639 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
Assaf Krauss226bcd42014-03-13 08:12:15 +0200640 hw->wiphy->features |= NL80211_FEATURE_QUIET;
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300641
Johannes Berg859d9142015-06-01 17:11:11 +0200642 if (fw_has_capa(&mvm->fw->ucode_capa,
643 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300644 hw->wiphy->features |=
645 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
646
Johannes Berg859d9142015-06-01 17:11:11 +0200647 if (fw_has_capa(&mvm->fw->ucode_capa,
648 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300649 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
650
Avrahams Sternaacf8f12016-07-19 11:15:09 +0300651 if (fw_has_api(&mvm->fw->ucode_capa,
652 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
653 wiphy_ext_feature_set(hw->wiphy,
654 NL80211_EXT_FEATURE_SCAN_START_TIME);
655 wiphy_ext_feature_set(hw->wiphy,
656 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
657 wiphy_ext_feature_set(hw->wiphy,
658 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
659 }
660
Johannes Berg8ca151b2013-01-24 14:25:36 +0100661 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
662
663#ifdef CONFIG_PM_SLEEP
Eliad Pellerd15a7472014-03-27 18:53:12 +0200664 if (iwl_mvm_is_d0i3_supported(mvm) &&
665 device_can_wakeup(mvm->trans->dev)) {
666 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
667 hw->wiphy->wowlan = &mvm->wowlan;
Eliad Peller91742442014-12-09 15:54:46 +0200668 }
669
Sara Sharoneef187a2016-10-25 11:38:31 +0300670 if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100671 mvm->trans->ops->d3_suspend &&
672 mvm->trans->ops->d3_resume &&
673 device_can_wakeup(mvm->trans->dev)) {
Eliad Peller91742442014-12-09 15:54:46 +0200674 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
675 WIPHY_WOWLAN_DISCONNECT |
676 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
677 WIPHY_WOWLAN_RFKILL_RELEASE |
678 WIPHY_WOWLAN_NET_DETECT;
Johannes Berg3b37f4c2017-05-30 16:45:31 +0200679 if (!iwlwifi_mod_params.swcrypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200680 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
681 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
682 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100683
Johannes Berg964dc9e2013-06-03 17:25:34 +0200684 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
685 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
686 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
Luciano Coelhoc55385f2014-10-24 10:39:51 +0300687 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
Johannes Berg964dc9e2013-06-03 17:25:34 +0200688 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100689 }
690#endif
691
Eliad Peller77736922014-01-14 12:35:49 +0200692#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
693 /* assign default bcast filtering configuration */
694 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
695#endif
696
Johannes Berg8ca151b2013-01-24 14:25:36 +0100697 ret = iwl_mvm_leds_init(mvm);
698 if (ret)
699 return ret;
700
Johannes Berg859d9142015-06-01 17:11:11 +0200701 if (fw_has_capa(&mvm->fw->ucode_capa,
702 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
Arik Nemtsovd8f1c512014-05-11 18:13:04 +0300703 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
704 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
Arik Nemtsov7c4f0842015-04-30 18:31:45 +0300705 ieee80211_hw_set(hw, TDLS_WIDER_BW);
Arik Nemtsovd8f1c512014-05-11 18:13:04 +0300706 }
707
Johannes Berg859d9142015-06-01 17:11:11 +0200708 if (fw_has_capa(&mvm->fw->ucode_capa,
709 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +0300710 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
711 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
712 }
713
Avri Altman93190fb2014-12-27 09:09:47 +0200714 hw->netdev_features |= mvm->cfg->features;
Sara Sharon5e6a98d2016-03-10 17:40:56 +0200715 if (!iwl_mvm_is_csum_supported(mvm)) {
716 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
717 NETIF_F_RXCSUM);
718 /* We may support SW TX CSUM */
719 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
720 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
721 }
Emmanuel Grumbach41837ca92015-10-21 09:00:07 +0300722
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300723 ret = ieee80211_register_hw(mvm->hw);
724 if (ret)
725 iwl_mvm_leds_exit(mvm);
Liad Kaufmande8ba412017-03-16 13:00:59 +0200726 mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300727
Aviya Erenfeld91b08c2d2016-03-27 14:53:49 +0300728 if (mvm->cfg->vht_mu_mimo_supported)
729 wiphy_ext_feature_set(hw->wiphy,
730 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
731
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300732 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100733}
734
Arik Nemtsovb2492502014-03-13 12:21:50 +0200735static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
736 struct ieee80211_sta *sta,
737 struct sk_buff *skb)
738{
739 struct iwl_mvm_sta *mvmsta;
740 bool defer = false;
741
742 /*
743 * double check the IN_D0I3 flag both before and after
744 * taking the spinlock, in order to prevent taking
745 * the spinlock when not needed.
746 */
747 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
748 return false;
749
750 spin_lock(&mvm->d0i3_tx_lock);
751 /*
752 * testing the flag again ensures the skb dequeue
753 * loop (on d0i3 exit) hasn't run yet.
754 */
755 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
756 goto out;
757
758 mvmsta = iwl_mvm_sta_from_mac80211(sta);
Sara Sharon0ae98812017-01-04 14:53:58 +0200759 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
Arik Nemtsovb2492502014-03-13 12:21:50 +0200760 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
761 goto out;
762
763 __skb_queue_tail(&mvm->d0i3_tx, skb);
764 ieee80211_stop_queues(mvm->hw);
765
766 /* trigger wakeup */
767 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
768 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
769
770 defer = true;
771out:
772 spin_unlock(&mvm->d0i3_tx_lock);
773 return defer;
774}
775
Johannes Berg8ca151b2013-01-24 14:25:36 +0100776static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
777 struct ieee80211_tx_control *control,
778 struct sk_buff *skb)
779{
780 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg3e56ead2013-02-15 22:23:18 +0100781 struct ieee80211_sta *sta = control->sta;
782 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
783 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100784
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300785 if (iwl_mvm_is_radio_killed(mvm)) {
786 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100787 goto drop;
788 }
789
Emmanuel Grumbachd20e30a2017-06-25 10:38:12 +0300790 if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Matti Gottlieba6cc5162014-09-29 11:46:04 +0300791 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
792 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100793 goto drop;
794
David Spinadeleb045e62017-08-17 17:28:22 +0300795 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
796 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
797 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
798 ieee80211_is_mgmt(hdr->frame_control) &&
799 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
Johannes Berg3e56ead2013-02-15 22:23:18 +0100800 sta = NULL;
801
802 if (sta) {
Arik Nemtsovb2492502014-03-13 12:21:50 +0200803 if (iwl_mvm_defer_tx(mvm, sta, skb))
804 return;
Johannes Berg3e56ead2013-02-15 22:23:18 +0100805 if (iwl_mvm_tx_skb(mvm, skb, sta))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100806 goto drop;
807 return;
808 }
809
810 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
811 goto drop;
812 return;
813 drop:
814 ieee80211_free_txskb(hw, skb);
815}
816
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200817static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
818{
819 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
820 return false;
821 return true;
822}
823
824static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
825{
826 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
827 return false;
828 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
829 return true;
830
831 /* enabled by default */
832 return true;
833}
834
Johannes Berg7174beb2017-06-01 16:03:19 +0200835#define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
836 do { \
837 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
838 break; \
839 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
Emmanuel Grumbach42032632015-04-15 12:43:46 +0300840 } while (0)
841
842static void
843iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
844 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
845 enum ieee80211_ampdu_mlme_action action)
846{
847 struct iwl_fw_dbg_trigger_tlv *trig;
848 struct iwl_fw_dbg_trigger_ba *ba_trig;
849
850 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
851 return;
852
853 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
854 ba_trig = (void *)trig->data;
855
Johannes Berg7174beb2017-06-01 16:03:19 +0200856 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
857 ieee80211_vif_to_wdev(vif), trig))
Emmanuel Grumbach42032632015-04-15 12:43:46 +0300858 return;
859
860 switch (action) {
861 case IEEE80211_AMPDU_TX_OPERATIONAL: {
862 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
863 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
864
865 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
866 "TX AGG START: MAC %pM tid %d ssn %d\n",
867 sta->addr, tid, tid_data->ssn);
868 break;
869 }
870 case IEEE80211_AMPDU_TX_STOP_CONT:
871 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
872 "TX AGG STOP: MAC %pM tid %d\n",
873 sta->addr, tid);
874 break;
875 case IEEE80211_AMPDU_RX_START:
876 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
877 "RX AGG START: MAC %pM tid %d ssn %d\n",
878 sta->addr, tid, rx_ba_ssn);
879 break;
880 case IEEE80211_AMPDU_RX_STOP:
881 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
882 "RX AGG STOP: MAC %pM tid %d\n",
883 sta->addr, tid);
884 break;
885 default:
886 break;
887 }
888}
889
Johannes Berg8ca151b2013-01-24 14:25:36 +0100890static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
891 struct ieee80211_vif *vif,
Sara Sharon50ea05e2015-12-30 16:06:04 +0200892 struct ieee80211_ampdu_params *params)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100893{
894 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
895 int ret;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200896 bool tx_agg_ref = false;
Sara Sharon50ea05e2015-12-30 16:06:04 +0200897 struct ieee80211_sta *sta = params->sta;
898 enum ieee80211_ampdu_mlme_action action = params->action;
899 u16 tid = params->tid;
900 u16 *ssn = &params->ssn;
901 u8 buf_size = params->buf_size;
Emmanuel Grumbachbb81bb62015-10-26 16:00:29 +0200902 bool amsdu = params->amsdu;
Sara Sharon10b2b202016-03-20 16:23:41 +0200903 u16 timeout = params->timeout;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100904
905 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
906 sta->addr, tid, action);
907
908 if (!(mvm->nvm_data->sku_cap_11n_enable))
909 return -EACCES;
910
Arik Nemtsovb2492502014-03-13 12:21:50 +0200911 /* return from D0i3 before starting a new Tx aggregation */
Eliad Peller9256c202014-04-22 13:33:29 +0300912 switch (action) {
913 case IEEE80211_AMPDU_TX_START:
914 case IEEE80211_AMPDU_TX_STOP_CONT:
915 case IEEE80211_AMPDU_TX_STOP_FLUSH:
916 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
917 case IEEE80211_AMPDU_TX_OPERATIONAL:
Arik Nemtsovb2492502014-03-13 12:21:50 +0200918 /*
Eliad Peller9256c202014-04-22 13:33:29 +0300919 * for tx start, wait synchronously until D0i3 exit to
920 * get the correct sequence number for the tid.
921 * additionally, some other ampdu actions use direct
922 * target access, which is not handled automatically
923 * by the trans layer (unlike commands), so wait for
924 * d0i3 exit in these cases as well.
Arik Nemtsovb2492502014-03-13 12:21:50 +0200925 */
Gregory Greenmand40fc482014-06-25 14:08:50 +0200926 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
927 if (ret)
928 return ret;
929
930 tx_agg_ref = true;
Eliad Peller9256c202014-04-22 13:33:29 +0300931 break;
932 default:
933 break;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200934 }
935
Johannes Berg8ca151b2013-01-24 14:25:36 +0100936 mutex_lock(&mvm->mutex);
937
938 switch (action) {
939 case IEEE80211_AMPDU_RX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200940 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100941 ret = -EINVAL;
942 break;
943 }
Sara Sharon10b2b202016-03-20 16:23:41 +0200944 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
945 timeout);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100946 break;
947 case IEEE80211_AMPDU_RX_STOP:
Sara Sharon10b2b202016-03-20 16:23:41 +0200948 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
949 timeout);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100950 break;
951 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200952 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200953 ret = -EINVAL;
954 break;
955 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100956 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
957 break;
958 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200959 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
960 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100961 case IEEE80211_AMPDU_TX_STOP_FLUSH:
962 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200963 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100964 break;
965 case IEEE80211_AMPDU_TX_OPERATIONAL:
Emmanuel Grumbachbb81bb62015-10-26 16:00:29 +0200966 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
967 buf_size, amsdu);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100968 break;
969 default:
970 WARN_ON_ONCE(1);
971 ret = -EINVAL;
972 break;
973 }
Emmanuel Grumbach42032632015-04-15 12:43:46 +0300974
975 if (!ret) {
976 u16 rx_ba_ssn = 0;
977
978 if (action == IEEE80211_AMPDU_RX_START)
979 rx_ba_ssn = *ssn;
980
981 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
982 rx_ba_ssn, action);
983 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100984 mutex_unlock(&mvm->mutex);
985
Arik Nemtsovb2492502014-03-13 12:21:50 +0200986 /*
987 * If the tid is marked as started, we won't use it for offloaded
988 * traffic on the next D0i3 entry. It's safe to unref.
989 */
990 if (tx_agg_ref)
991 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
992
Johannes Berg8ca151b2013-01-24 14:25:36 +0100993 return ret;
994}
995
996static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
997 struct ieee80211_vif *vif)
998{
999 struct iwl_mvm *mvm = data;
1000 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1001
1002 mvmvif->uploaded = false;
Sara Sharon0ae98812017-01-04 14:53:58 +02001003 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001004
Johannes Berg8ca151b2013-01-24 14:25:36 +01001005 spin_lock_bh(&mvm->time_event_lock);
1006 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1007 spin_unlock_bh(&mvm->time_event_lock);
1008
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001009 mvmvif->phy_ctxt = NULL;
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +03001010 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001011}
1012
1013static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1014{
Johannes Berg58629d92014-11-06 09:40:50 +01001015 /* clear the D3 reconfig, we only need it to avoid dumping a
1016 * firmware coredump on reconfiguration, we shouldn't do that
1017 * on D3->D0 transition
1018 */
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001019 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
Johannes Berg7174beb2017-06-01 16:03:19 +02001020 mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
1021 iwl_fw_error_dump(&mvm->fwrt);
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001022 }
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +02001023
Eliad Peller744cb692014-12-10 18:44:13 +02001024 /* cleanup all stale references (scan, roc), but keep the
1025 * ucode_down ref until reconfig is complete
1026 */
1027 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1028
Chaya Rachel Ivgifcb6b922016-02-22 10:21:41 +02001029 iwl_mvm_stop_device(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001030
Luciano Coelho9af91f42015-02-10 10:42:26 +02001031 mvm->scan_status = 0;
Luciano Coelhob1873302014-08-08 17:12:07 +03001032 mvm->ps_disabled = false;
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +02001033 mvm->calibrating = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001034
1035 /* just in case one was running */
Eliad Peller305d2362015-12-09 16:33:20 +02001036 iwl_mvm_cleanup_roc_te(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001037 ieee80211_remain_on_channel_expired(mvm->hw);
1038
Arik Nemtsov737719f2015-02-23 14:42:41 +02001039 /*
1040 * cleanup all interfaces, even inactive ones, as some might have
1041 * gone down during the HW restart
1042 */
1043 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001044
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001045 mvm->p2p_device_vif = NULL;
Sara Sharon0ae98812017-01-04 14:53:58 +02001046 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001047
1048 iwl_mvm_reset_phy_ctxts(mvm);
Luca Coelho9c3deeb2015-11-11 01:06:17 +02001049 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
Liad Kaufman24afba72015-07-28 18:56:08 +03001050 memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +03001051 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +03001052 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001053
1054 ieee80211_wake_queues(mvm->hw);
1055
Eliad Peller228670b2014-08-10 17:00:15 +03001056 /* clear any stale d0i3 state */
1057 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1058
Johannes Berg8ca151b2013-01-24 14:25:36 +01001059 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03001060 mvm->rx_ba_sessions = 0;
Johannes Berg7174beb2017-06-01 16:03:19 +02001061 mvm->fwrt.dump.conf = FW_DBG_INVALID;
Shaul Triebitzbaf41bc2017-09-13 16:46:14 +03001062 mvm->monitor_on = false;
Johannes Berg91a8bcd2015-01-14 18:12:41 +01001063
1064 /* keep statistics ticking */
1065 iwl_mvm_accu_radio_stats(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001066}
1067
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001068int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001069{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001070 int ret;
1071
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001072 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001073
Johannes Bergbf8b2862017-06-30 10:48:28 +02001074 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1075 /*
1076 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1077 * so later code will - from now on - see that we're doing it.
1078 */
1079 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1080 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
Luca Coelhoa42b2af32015-11-25 22:15:32 +02001081 /* Clean up some internal and mac80211 state on restart */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001082 iwl_mvm_restart_cleanup(mvm);
Luca Coelhoa42b2af32015-11-25 22:15:32 +02001083 } else {
1084 /* Hold the reference to prevent runtime suspend while
1085 * the start procedure runs. It's a bit confusing
1086 * that the UCODE_DOWN reference is taken, but it just
1087 * means "UCODE is not UP yet". ( TODO: rename this
1088 * reference).
1089 */
1090 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1091 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001092 ret = iwl_mvm_up(mvm);
Johannes Bergc47af222014-04-30 16:34:45 +02001093
1094 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1095 /* Something went wrong - we need to finish some cleanup
1096 * that normally iwl_mvm_mac_restart_complete() below
1097 * would do.
1098 */
1099 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1100 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1101 }
1102
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001103 return ret;
1104}
1105
1106static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1107{
1108 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1109 int ret;
1110
Eliad Peller37948fc2014-12-11 10:48:18 +02001111 /* Some hw restart cleanups must not hold the mutex */
1112 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1113 /*
1114 * Make sure we are out of d0i3. This is needed
1115 * to make sure the reference accounting is correct
1116 * (and there is no stale d0i3_exit_work).
1117 */
1118 wait_event_timeout(mvm->d0i3_exit_waitq,
1119 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1120 &mvm->status),
1121 HZ);
1122 }
1123
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001124 mutex_lock(&mvm->mutex);
1125 ret = __iwl_mvm_mac_start(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001126 mutex_unlock(&mvm->mutex);
1127
1128 return ret;
1129}
1130
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001131static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001132{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001133 int ret;
1134
1135 mutex_lock(&mvm->mutex);
1136
1137 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
Arik Nemtsovb2492502014-03-13 12:21:50 +02001138 iwl_mvm_d0i3_enable_tx(mvm, NULL);
Johannes Berge7afe892015-04-21 09:21:46 +02001139 ret = iwl_mvm_update_quotas(mvm, true, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001140 if (ret)
1141 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1142 ret);
1143
Eliad Peller7498cf42014-01-16 17:10:44 +02001144 /* allow transport/FW low power modes */
1145 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1146
Arik Nemtsovcbd2ae22014-09-14 19:13:54 +03001147 /*
1148 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1149 * of packets the FW sent out, so we must reconnect.
1150 */
1151 iwl_mvm_teardown_tdls_peers(mvm);
1152
Johannes Berg8ca151b2013-01-24 14:25:36 +01001153 mutex_unlock(&mvm->mutex);
1154}
1155
Eliad Peller088070a22014-10-20 18:42:58 +03001156static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1157{
Luca Coelhob7282642015-09-17 23:44:14 +03001158 if (iwl_mvm_is_d0i3_supported(mvm) &&
1159 iwl_mvm_enter_d0i3_on_suspend(mvm))
1160 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1161 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1162 &mvm->status),
1163 HZ),
1164 "D0i3 exit on resume timed out\n");
Eliad Peller088070a22014-10-20 18:42:58 +03001165}
1166
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001167static void
1168iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1169 enum ieee80211_reconfig_type reconfig_type)
1170{
1171 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1172
1173 switch (reconfig_type) {
1174 case IEEE80211_RECONFIG_TYPE_RESTART:
1175 iwl_mvm_restart_complete(mvm);
1176 break;
1177 case IEEE80211_RECONFIG_TYPE_SUSPEND:
Eliad Peller088070a22014-10-20 18:42:58 +03001178 iwl_mvm_resume_complete(mvm);
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001179 break;
1180 }
1181}
1182
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001183void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001184{
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001185 lockdep_assert_held(&mvm->mutex);
Eliad Peller7498cf42014-01-16 17:10:44 +02001186
Johannes Berg91a8bcd2015-01-14 18:12:41 +01001187 /* firmware counters are obviously reset now, but we shouldn't
1188 * partially track so also clear the fw_reset_accu counters.
1189 */
1190 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1191
Johannes Berg8ca151b2013-01-24 14:25:36 +01001192 /* async_handlers_wk is now blocked */
1193
1194 /*
1195 * The work item could be running or queued if the
1196 * ROC time event stops just as we get here.
1197 */
Eliad Pellerc7792732015-04-19 11:41:04 +03001198 flush_work(&mvm->roc_done_wk);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001199
Chaya Rachel Ivgifcb6b922016-02-22 10:21:41 +02001200 iwl_mvm_stop_device(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001201
1202 iwl_mvm_async_handlers_purge(mvm);
1203 /* async_handlers_list is empty and will stay empty: HW is stopped */
1204
1205 /* the fw is stopped, the aux sta is dead: clean up driver state */
Johannes Berg712b24a2014-08-04 14:14:14 +02001206 iwl_mvm_del_aux_sta(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001207
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001208 /*
1209 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1210 * won't be called in this case).
Arik Nemtsov8b2b9fb2015-03-04 13:16:03 +02001211 * But make sure to cleanup interfaces that have gone down before/during
1212 * HW restart was requested.
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001213 */
Arik Nemtsov8b2b9fb2015-03-04 13:16:03 +02001214 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1215 ieee80211_iterate_interfaces(mvm->hw, 0,
1216 iwl_mvm_cleanup_iterator, mvm);
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001217
Alexander Bondar963221b2015-03-26 11:07:35 +02001218 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1219 * make sure there's nothing left there and warn if any is found.
1220 */
Johannes Berg859d9142015-06-01 17:11:11 +02001221 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
Alexander Bondar963221b2015-03-26 11:07:35 +02001222 int i;
1223
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001224 for (i = 0; i < mvm->max_scans; i++) {
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001225 if (WARN_ONCE(mvm->scan_uid_status[i],
1226 "UMAC scan UID %d status was not cleaned\n",
1227 i))
1228 mvm->scan_uid_status[i] = 0;
Alexander Bondar963221b2015-03-26 11:07:35 +02001229 }
1230 }
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001231}
Luciano Coelhobc448862014-08-20 11:49:11 +03001232
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001233static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1234{
1235 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1236
1237 flush_work(&mvm->d0i3_exit_work);
1238 flush_work(&mvm->async_handlers_wk);
Liad Kaufman24afba72015-07-28 18:56:08 +03001239 flush_work(&mvm->add_stream_wk);
Johannes Berg771147b2017-03-22 22:26:03 +01001240
1241 /*
1242 * Lock and clear the firmware running bit here already, so that
1243 * new commands coming in elsewhere, e.g. from debugfs, will not
1244 * be able to proceed. This is important here because one of those
Johannes Berg7174beb2017-06-01 16:03:19 +02001245 * debugfs files causes the firmware dump to be triggered, and if we
Johannes Berg771147b2017-03-22 22:26:03 +01001246 * don't stop debugfs accesses before canceling that it could be
1247 * retriggered after we flush it but before we've cleared the bit.
1248 */
1249 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1250
Johannes Berg7174beb2017-06-01 16:03:19 +02001251 iwl_fw_cancel_dump(&mvm->fwrt);
Andrei Otcheretianskid3a108a2016-02-28 17:12:21 +02001252 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
Luca Coelho69e04642016-05-03 12:18:33 +03001253 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
Johannes Berg7174beb2017-06-01 16:03:19 +02001254 iwl_fw_free_dump_desc(&mvm->fwrt);
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001255
1256 mutex_lock(&mvm->mutex);
1257 __iwl_mvm_mac_stop(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001258 mutex_unlock(&mvm->mutex);
1259
1260 /*
1261 * The worker might have been waiting for the mutex, let it run and
1262 * discover that its list is now empty.
1263 */
1264 cancel_work_sync(&mvm->async_handlers_wk);
1265}
1266
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001267static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1268{
1269 u16 i;
1270
1271 lockdep_assert_held(&mvm->mutex);
1272
1273 for (i = 0; i < NUM_PHY_CTX; i++)
1274 if (!mvm->phy_ctxts[i].ref)
1275 return &mvm->phy_ctxts[i];
1276
1277 IWL_ERR(mvm, "No available PHY context\n");
1278 return NULL;
1279}
1280
Avri Altmand44c3fe2015-04-18 22:16:42 +03001281static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1282 s16 tx_power)
1283{
1284 struct iwl_dev_tx_power_cmd cmd = {
Luca Coelho4b87e5a2016-09-12 16:03:30 +03001285 .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1286 .v3.mac_context_id =
Avri Altmand44c3fe2015-04-18 22:16:42 +03001287 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
Luca Coelho4b87e5a2016-09-12 16:03:30 +03001288 .v3.pwr_restriction = cpu_to_le16(8 * tx_power),
Avri Altmand44c3fe2015-04-18 22:16:42 +03001289 };
Johannes Bergda03f022015-08-18 15:15:36 +02001290 int len = sizeof(cmd);
Avri Altmand44c3fe2015-04-18 22:16:42 +03001291
Avri Altmand44c3fe2015-04-18 22:16:42 +03001292 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
Luca Coelho4b87e5a2016-09-12 16:03:30 +03001293 cmd.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
Avri Altmand44c3fe2015-04-18 22:16:42 +03001294
Luca Coelho55bfa4b2016-06-29 00:38:40 +03001295 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1296 len = sizeof(cmd.v3);
Johannes Bergda03f022015-08-18 15:15:36 +02001297
1298 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
Avri Altmand44c3fe2015-04-18 22:16:42 +03001299}
1300
Johannes Berg8ca151b2013-01-24 14:25:36 +01001301static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1302 struct ieee80211_vif *vif)
1303{
1304 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1305 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1306 int ret;
1307
Emmanuel Grumbachaa5e1832015-03-07 19:35:37 +02001308 mvmvif->mvm = mvm;
1309
Johannes Berg8ca151b2013-01-24 14:25:36 +01001310 /*
Gregory Greenmand40fc482014-06-25 14:08:50 +02001311 * make sure D0i3 exit is completed, otherwise a target access
1312 * during tx queue configuration could be done when still in
1313 * D0i3 state.
1314 */
1315 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1316 if (ret)
1317 return ret;
1318
1319 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001320 * Not much to do here. The stack will not allow interface
1321 * types or combinations that we didn't advertise, so we
1322 * don't really have to check the types.
1323 */
1324
1325 mutex_lock(&mvm->mutex);
1326
Johannes Berg33cef922015-01-21 21:41:29 +01001327 /* make sure that beacon statistics don't go backwards with FW reset */
1328 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1329 mvmvif->beacon_stats.accu_num_beacons +=
1330 mvmvif->beacon_stats.num_beacons;
1331
Eliad Pellere89044d2013-07-16 17:33:26 +03001332 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001333 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1334 if (ret)
1335 goto out_unlock;
1336
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001337 /* Counting number of interfaces is needed for legacy PM */
Ilan Peerea183d02013-07-23 14:41:53 +03001338 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1339 mvm->vif_count++;
Ilan Peerea183d02013-07-23 14:41:53 +03001340
1341 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001342 * The AP binding flow can be done only after the beacon
1343 * template is configured (which happens only in the mac80211
1344 * start_ap() flow), and adding the broadcast station can happen
1345 * only after the binding.
1346 * In addition, since modifying the MAC before adding a bcast
1347 * station is not allowed by the FW, delay the adding of MAC context to
1348 * the point where we can also add the bcast station.
1349 * In short: there's not much we can do at this point, other than
1350 * allocating resources :)
1351 */
Johannes Berg5023d962013-07-31 14:07:43 +02001352 if (vif->type == NL80211_IFTYPE_AP ||
1353 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg013290a2014-08-04 13:38:48 +02001354 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001355 if (ret) {
1356 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1357 goto out_release;
1358 }
1359
Johannes Bergc8f54702017-06-19 23:50:31 +02001360 /*
1361 * Only queue for this station is the mcast queue,
1362 * which shouldn't be in TFD mask anyway
1363 */
1364 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1365 0, vif->type,
1366 IWL_STA_MULTICAST);
1367 if (ret)
1368 goto out_release;
Sara Sharon26d6c162017-01-03 12:00:19 +02001369
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +03001370 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001371 goto out_unlock;
1372 }
1373
Avri Altman93190fb2014-12-27 09:09:47 +02001374 mvmvif->features |= hw->netdev_features;
1375
Johannes Berg8ca151b2013-01-24 14:25:36 +01001376 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1377 if (ret)
1378 goto out_release;
1379
Arik Nemtsov999609f2014-05-15 17:31:51 +03001380 ret = iwl_mvm_power_update_mac(mvm);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001381 if (ret)
Luciano Coelhofd66fc12015-01-27 15:06:57 +02001382 goto out_remove_mac;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001383
Hila Gonen7df15b12012-12-12 11:16:19 +02001384 /* beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001385 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001386 if (ret)
1387 goto out_remove_mac;
1388
Hila Gonen7df15b12012-12-12 11:16:19 +02001389 if (!mvm->bf_allowed_vif &&
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +03001390 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001391 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001392 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1393 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +02001394 }
1395
Johannes Berg8ca151b2013-01-24 14:25:36 +01001396 /*
1397 * P2P_DEVICE interface does not have a channel context assigned to it,
1398 * so a dedicated PHY context is allocated to it and the corresponding
1399 * MAC context is bound to it at this stage.
1400 */
1401 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001402
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001403 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1404 if (!mvmvif->phy_ctxt) {
1405 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001406 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001407 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001408
Ilan Peer53a9d612013-04-28 11:55:08 +03001409 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001410 ret = iwl_mvm_binding_add_vif(mvm, vif);
1411 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +03001412 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001413
Luca Coelhod1973582017-06-22 16:00:25 +03001414 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001415 if (ret)
1416 goto out_unbind;
1417
1418 /* Save a pointer to p2p device vif, so it can later be used to
1419 * update the p2p device MAC when a GO is started/stopped */
1420 mvm->p2p_device_vif = vif;
1421 }
1422
Shaul Triebitzbaf41bc2017-09-13 16:46:14 +03001423 if (vif->type == NL80211_IFTYPE_MONITOR)
1424 mvm->monitor_on = true;
1425
Johannes Berg63494372013-03-26 10:47:53 +01001426 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001427 goto out_unlock;
1428
1429 out_unbind:
1430 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +03001431 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001432 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001433 out_free_bf:
1434 if (mvm->bf_allowed_vif == mvmvif) {
1435 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001436 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1437 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001438 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001439 out_remove_mac:
1440 mvmvif->phy_ctxt = NULL;
1441 iwl_mvm_mac_ctxt_remove(mvm, vif);
1442 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001443 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1444 mvm->vif_count--;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001445 out_unlock:
1446 mutex_unlock(&mvm->mutex);
1447
Gregory Greenmand40fc482014-06-25 14:08:50 +02001448 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1449
Johannes Berg8ca151b2013-01-24 14:25:36 +01001450 return ret;
1451}
1452
Johannes Berg38a12b52013-02-22 14:07:56 +01001453static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1454 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001455{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001456 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1457 /*
1458 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1459 * We assume here that all the packets sent to the OFFCHANNEL
1460 * queue are sent in ROC session.
1461 */
1462 flush_work(&mvm->roc_done_wk);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001463 }
Johannes Berg38a12b52013-02-22 14:07:56 +01001464}
1465
1466static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1467 struct ieee80211_vif *vif)
1468{
1469 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1470 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1471
1472 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001473
1474 mutex_lock(&mvm->mutex);
1475
Hila Gonen7df15b12012-12-12 11:16:19 +02001476 if (mvm->bf_allowed_vif == mvmvif) {
1477 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001478 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1479 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +02001480 }
1481
Johannes Berg63494372013-03-26 10:47:53 +01001482 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1483
Johannes Berg8ca151b2013-01-24 14:25:36 +01001484 /*
1485 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +01001486 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001487 */
Johannes Berg5023d962013-07-31 14:07:43 +02001488 if (vif->type == NL80211_IFTYPE_AP ||
1489 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +03001490#ifdef CONFIG_NL80211_TESTMODE
1491 if (vif == mvm->noa_vif) {
1492 mvm->noa_vif = NULL;
1493 mvm->noa_duration = 0;
1494 }
1495#endif
Sara Sharon26d6c162017-01-03 12:00:19 +02001496 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
Johannes Berg013290a2014-08-04 13:38:48 +02001497 iwl_mvm_dealloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001498 goto out_release;
1499 }
1500
1501 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1502 mvm->p2p_device_vif = NULL;
Luca Coelhod1973582017-06-22 16:00:25 +03001503 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001504 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001505 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001506 mvmvif->phy_ctxt = NULL;
1507 }
1508
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001509 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001510 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001511
Arik Nemtsov999609f2014-05-15 17:31:51 +03001512 iwl_mvm_power_update_mac(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001513 iwl_mvm_mac_ctxt_remove(mvm, vif);
1514
Shaul Triebitzbaf41bc2017-09-13 16:46:14 +03001515 if (vif->type == NL80211_IFTYPE_MONITOR)
1516 mvm->monitor_on = false;
1517
Johannes Berg8ca151b2013-01-24 14:25:36 +01001518out_release:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001519 mutex_unlock(&mvm->mutex);
1520}
1521
1522static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1523{
1524 return 0;
1525}
1526
Eliad Pellere59647e2013-11-28 14:08:50 +02001527struct iwl_mvm_mc_iter_data {
1528 struct iwl_mvm *mvm;
1529 int port_id;
1530};
1531
1532static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1533 struct ieee80211_vif *vif)
1534{
1535 struct iwl_mvm_mc_iter_data *data = _data;
1536 struct iwl_mvm *mvm = data->mvm;
1537 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
Luca Coelho97bce572017-09-01 17:59:15 +03001538 struct iwl_host_cmd hcmd = {
1539 .id = MCAST_FILTER_CMD,
1540 .flags = CMD_ASYNC,
1541 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1542 };
Eliad Pellere59647e2013-11-28 14:08:50 +02001543 int ret, len;
1544
1545 /* if we don't have free ports, mcast frames will be dropped */
1546 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1547 return;
1548
1549 if (vif->type != NL80211_IFTYPE_STATION ||
1550 !vif->bss_conf.assoc)
1551 return;
1552
1553 cmd->port_id = data->port_id++;
1554 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1555 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1556
Luca Coelho97bce572017-09-01 17:59:15 +03001557 hcmd.len[0] = len;
1558 hcmd.data[0] = cmd;
1559
1560 ret = iwl_mvm_send_cmd(mvm, &hcmd);
Eliad Pellere59647e2013-11-28 14:08:50 +02001561 if (ret)
1562 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1563}
1564
1565static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1566{
1567 struct iwl_mvm_mc_iter_data iter_data = {
1568 .mvm = mvm,
1569 };
1570
1571 lockdep_assert_held(&mvm->mutex);
1572
1573 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1574 return;
1575
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001576 ieee80211_iterate_active_interfaces_atomic(
Eliad Pellere59647e2013-11-28 14:08:50 +02001577 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1578 iwl_mvm_mc_iface_iterator, &iter_data);
1579}
1580
1581static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1582 struct netdev_hw_addr_list *mc_list)
1583{
1584 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1585 struct iwl_mcast_filter_cmd *cmd;
1586 struct netdev_hw_addr *addr;
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001587 int addr_count;
1588 bool pass_all;
Eliad Pellere59647e2013-11-28 14:08:50 +02001589 int len;
1590
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001591 addr_count = netdev_hw_addr_list_count(mc_list);
1592 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1593 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1594 if (pass_all)
Eliad Pellere59647e2013-11-28 14:08:50 +02001595 addr_count = 0;
Eliad Pellere59647e2013-11-28 14:08:50 +02001596
1597 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1598 cmd = kzalloc(len, GFP_ATOMIC);
1599 if (!cmd)
1600 return 0;
1601
1602 if (pass_all) {
1603 cmd->pass_all = 1;
1604 return (u64)(unsigned long)cmd;
1605 }
1606
1607 netdev_hw_addr_list_for_each(addr, mc_list) {
1608 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1609 cmd->count, addr->addr);
1610 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1611 addr->addr, ETH_ALEN);
1612 cmd->count++;
1613 }
1614
1615 return (u64)(unsigned long)cmd;
1616}
1617
Johannes Berg8ca151b2013-01-24 14:25:36 +01001618static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1619 unsigned int changed_flags,
1620 unsigned int *total_flags,
1621 u64 multicast)
1622{
Eliad Pellere59647e2013-11-28 14:08:50 +02001623 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1624 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1625
1626 mutex_lock(&mvm->mutex);
1627
1628 /* replace previous configuration */
1629 kfree(mvm->mcast_filter_cmd);
1630 mvm->mcast_filter_cmd = cmd;
1631
1632 if (!cmd)
1633 goto out;
1634
Luca Coelho61e7d912017-09-01 18:57:35 +03001635 if (changed_flags & FIF_ALLMULTI)
1636 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1637
1638 if (cmd->pass_all)
1639 cmd->count = 0;
1640
Eliad Pellere59647e2013-11-28 14:08:50 +02001641 iwl_mvm_recalc_multicast(mvm);
1642out:
1643 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001644 *total_flags = 0;
1645}
1646
Andrei Otcheretianskieffd1922015-06-30 12:08:28 +03001647static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1648 struct ieee80211_vif *vif,
1649 unsigned int filter_flags,
1650 unsigned int changed_flags)
1651{
1652 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1653
1654 /* We support only filter for probe requests */
1655 if (!(changed_flags & FIF_PROBE_REQ))
1656 return;
1657
1658 /* Supported only for p2p client interfaces */
1659 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1660 !vif->p2p)
1661 return;
1662
1663 mutex_lock(&mvm->mutex);
1664 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1665 mutex_unlock(&mvm->mutex);
1666}
1667
Eliad Pellerc87163b2014-01-08 10:11:11 +02001668#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1669struct iwl_bcast_iter_data {
1670 struct iwl_mvm *mvm;
1671 struct iwl_bcast_filter_cmd *cmd;
1672 u8 current_filter;
1673};
1674
1675static void
1676iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1677 const struct iwl_fw_bcast_filter *in_filter,
1678 struct iwl_fw_bcast_filter *out_filter)
1679{
1680 struct iwl_fw_bcast_filter_attr *attr;
1681 int i;
1682
1683 memcpy(out_filter, in_filter, sizeof(*out_filter));
1684
1685 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1686 attr = &out_filter->attrs[i];
1687
1688 if (!attr->mask)
1689 break;
1690
Eliad Peller2ee8f022014-01-13 19:07:09 +02001691 switch (attr->reserved1) {
1692 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1693 if (vif->bss_conf.arp_addr_cnt != 1) {
1694 attr->mask = 0;
1695 continue;
1696 }
1697
1698 attr->val = vif->bss_conf.arp_addr_list[0];
1699 break;
1700 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1701 attr->val = *(__be32 *)&vif->addr[2];
1702 break;
1703 default:
1704 break;
1705 }
1706 attr->reserved1 = 0;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001707 out_filter->num_attrs++;
1708 }
1709}
1710
1711static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1712 struct ieee80211_vif *vif)
1713{
1714 struct iwl_bcast_iter_data *data = _data;
1715 struct iwl_mvm *mvm = data->mvm;
1716 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1717 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1718 struct iwl_fw_bcast_mac *bcast_mac;
1719 int i;
1720
1721 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1722 return;
1723
1724 bcast_mac = &cmd->macs[mvmvif->id];
1725
Ilan Peere48393e2014-05-22 11:19:02 +03001726 /*
1727 * enable filtering only for associated stations, but not for P2P
1728 * Clients
1729 */
1730 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1731 !vif->bss_conf.assoc)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001732 return;
1733
1734 bcast_mac->default_discard = 1;
1735
1736 /* copy all configured filters */
1737 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1738 /*
1739 * Make sure we don't exceed our filters limit.
1740 * if there is still a valid filter to be configured,
1741 * be on the safe side and just allow bcast for this mac.
1742 */
1743 if (WARN_ON_ONCE(data->current_filter >=
1744 ARRAY_SIZE(cmd->filters))) {
1745 bcast_mac->default_discard = 0;
1746 bcast_mac->attached_filters = 0;
1747 break;
1748 }
1749
1750 iwl_mvm_set_bcast_filter(vif,
1751 &mvm->bcast_filters[i],
1752 &cmd->filters[data->current_filter]);
1753
1754 /* skip current filter if it contains no attributes */
1755 if (!cmd->filters[data->current_filter].num_attrs)
1756 continue;
1757
1758 /* attach the filter to current mac */
1759 bcast_mac->attached_filters |=
1760 cpu_to_le16(BIT(data->current_filter));
1761
1762 data->current_filter++;
1763 }
1764}
1765
Eliad Pellerde06a592014-01-08 10:11:12 +02001766bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1767 struct iwl_bcast_filter_cmd *cmd)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001768{
Eliad Pellerc87163b2014-01-08 10:11:11 +02001769 struct iwl_bcast_iter_data iter_data = {
1770 .mvm = mvm,
Eliad Pellerde06a592014-01-08 10:11:12 +02001771 .cmd = cmd,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001772 };
1773
Max Stepanov3b8983b2014-10-15 11:27:16 +03001774 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1775 return false;
1776
Eliad Pellerde06a592014-01-08 10:11:12 +02001777 memset(cmd, 0, sizeof(*cmd));
1778 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1779 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1780
1781#ifdef CONFIG_IWLWIFI_DEBUGFS
1782 /* use debugfs filters/macs if override is configured */
1783 if (mvm->dbgfs_bcast_filtering.override) {
1784 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1785 sizeof(cmd->filters));
1786 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1787 sizeof(cmd->macs));
1788 return true;
1789 }
1790#endif
Eliad Pellerc87163b2014-01-08 10:11:11 +02001791
1792 /* if no filters are configured, do nothing */
1793 if (!mvm->bcast_filters)
Eliad Pellerde06a592014-01-08 10:11:12 +02001794 return false;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001795
1796 /* configure and attach these filters for each associated sta vif */
1797 ieee80211_iterate_active_interfaces(
1798 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1799 iwl_mvm_bcast_filter_iterator, &iter_data);
1800
Eliad Pellerde06a592014-01-08 10:11:12 +02001801 return true;
1802}
Eliad Peller34672bb2015-12-03 16:10:07 +02001803
1804static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
Eliad Pellerde06a592014-01-08 10:11:12 +02001805{
1806 struct iwl_bcast_filter_cmd cmd;
1807
1808 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1809 return 0;
1810
1811 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1812 return 0;
1813
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001814 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001815 sizeof(cmd), &cmd);
1816}
1817#else
Eliad Peller34672bb2015-12-03 16:10:07 +02001818static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001819{
1820 return 0;
1821}
1822#endif
1823
Sara Sharona07a8f32015-11-15 11:11:59 +02001824static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1825 struct ieee80211_vif *vif)
1826{
1827 struct iwl_mu_group_mgmt_cmd cmd = {};
1828
1829 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1830 WLAN_MEMBERSHIP_LEN);
1831 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1832 WLAN_USER_POSITION_LEN);
1833
1834 return iwl_mvm_send_cmd_pdu(mvm,
1835 WIDE_ID(DATA_PATH_GROUP,
1836 UPDATE_MU_GROUPS_CMD),
1837 0, sizeof(cmd), &cmd);
1838}
1839
Sara Sharonf92659a2016-02-03 15:04:49 +02001840static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1841 struct ieee80211_vif *vif)
1842{
1843 if (vif->mu_mimo_owner) {
1844 struct iwl_mu_group_mgmt_notif *notif = _data;
1845
1846 /*
1847 * MU-MIMO Group Id action frame is little endian. We treat
1848 * the data received from firmware as if it came from the
1849 * action frame, so no conversion is needed.
1850 */
1851 ieee80211_update_mu_groups(vif,
1852 (u8 *)&notif->membership_status,
1853 (u8 *)&notif->user_position);
1854 }
1855}
1856
1857void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1858 struct iwl_rx_cmd_buffer *rxb)
1859{
1860 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1861 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1862
1863 ieee80211_iterate_active_interfaces_atomic(
1864 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1865 iwl_mvm_mu_mimo_iface_iterator, notif);
1866}
1867
Johannes Berg8ca151b2013-01-24 14:25:36 +01001868static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1869 struct ieee80211_vif *vif,
1870 struct ieee80211_bss_conf *bss_conf,
1871 u32 changes)
1872{
1873 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1874 int ret;
1875
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001876 /*
1877 * Re-calculate the tsf id, as the master-slave relations depend on the
1878 * beacon interval, which was not known when the station interface was
1879 * added.
1880 */
1881 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1882 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1883
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001884 /*
1885 * If we're not associated yet, take the (new) BSSID before associating
1886 * so the firmware knows. If we're already associated, then use the old
1887 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1888 * branch for disassociation below.
1889 */
1890 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1891 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1892
1893 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001894 if (ret)
1895 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1896
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001897 /* after sending it once, adopt mac80211 data */
1898 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1899 mvmvif->associated = bss_conf->assoc;
1900
Johannes Berg8ca151b2013-01-24 14:25:36 +01001901 if (changes & BSS_CHANGED_ASSOC) {
1902 if (bss_conf->assoc) {
Johannes Berg33cef922015-01-21 21:41:29 +01001903 /* clear statistics to get clean beacon counter */
1904 iwl_mvm_request_statistics(mvm, true);
1905 memset(&mvmvif->beacon_stats, 0,
1906 sizeof(mvmvif->beacon_stats));
1907
Johannes Berg8ca151b2013-01-24 14:25:36 +01001908 /* add quota for this interface */
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02001909 ret = iwl_mvm_update_quotas(mvm, true, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001910 if (ret) {
1911 IWL_ERR(mvm, "failed to update quotas\n");
1912 return;
1913 }
Johannes Berg016d27e2013-05-03 11:16:15 +02001914
1915 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1916 &mvm->status)) {
1917 /*
1918 * If we're restarting then the firmware will
1919 * obviously have lost synchronisation with
1920 * the AP. It will attempt to synchronise by
1921 * itself, but we can make it more reliable by
1922 * scheduling a session protection time event.
1923 *
1924 * The firmware needs to receive a beacon to
1925 * catch up with synchronisation, use 110% of
1926 * the beacon interval.
1927 *
1928 * Set a large maximum delay to allow for more
1929 * than a single interface.
1930 */
1931 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1932 iwl_mvm_protect_session(mvm, vif, dur, dur,
Liad Kaufmand20d37b2014-07-06 17:14:39 +03001933 5 * dur, false);
Johannes Berg016d27e2013-05-03 11:16:15 +02001934 }
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001935
1936 iwl_mvm_sf_update(mvm, vif, false);
Alexander Bondar175a70b2013-04-14 20:59:37 +03001937 iwl_mvm_power_vif_assoc(mvm, vif);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001938 if (vif->p2p) {
Eliad Peller29a90a42013-11-05 14:06:29 +02001939 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001940 iwl_mvm_update_smps(mvm, vif,
1941 IWL_MVM_SMPS_REQ_PROT,
1942 IEEE80211_SMPS_DYNAMIC);
1943 }
Sara Sharon0ae98812017-01-04 14:53:58 +02001944 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001945 /*
1946 * If update fails - SF might be running in associated
1947 * mode while disassociated - which is forbidden.
1948 */
1949 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1950 "Failed to update SF upon disassociation\n");
1951
Emmanuel Grumbach6b28f972017-05-05 08:51:24 +03001952 /*
1953 * If we get an assert during the connection (after the
1954 * station has been added, but before the vif is set
1955 * to associated), mac80211 will re-add the station and
1956 * then configure the vif. Since the vif is not
1957 * associated, we would remove the station here and
1958 * this would fail the recovery.
1959 */
1960 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1961 &mvm->status)) {
1962 /*
1963 * Remove AP station now that
1964 * the MAC is unassoc
1965 */
1966 ret = iwl_mvm_rm_sta_id(mvm, vif,
1967 mvmvif->ap_sta_id);
1968 if (ret)
1969 IWL_ERR(mvm,
1970 "failed to remove AP station\n");
Eliad Peller37577fe2013-12-05 17:19:39 +02001971
Emmanuel Grumbach6b28f972017-05-05 08:51:24 +03001972 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1973 mvm->d0i3_ap_sta_id =
1974 IWL_MVM_INVALID_STA;
1975 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1976 }
1977
Johannes Berg8ca151b2013-01-24 14:25:36 +01001978 /* remove quota for this interface */
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02001979 ret = iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001980 if (ret)
1981 IWL_ERR(mvm, "failed to update quotas\n");
Eliad Peller29a90a42013-11-05 14:06:29 +02001982
1983 if (vif->p2p)
1984 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001985
1986 /* this will take the cleared BSSID from bss_conf */
1987 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1988 if (ret)
1989 IWL_ERR(mvm,
1990 "failed to update MAC %pM (clear after unassoc)\n",
1991 vif->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001992 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001993
Sara Sharona07a8f32015-11-15 11:11:59 +02001994 /*
1995 * The firmware tracks the MU-MIMO group on its own.
Sara Sharonf92659a2016-02-03 15:04:49 +02001996 * However, on HW restart we should restore this data.
Sara Sharona07a8f32015-11-15 11:11:59 +02001997 */
1998 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
Sara Sharonf92659a2016-02-03 15:04:49 +02001999 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
Sara Sharona07a8f32015-11-15 11:11:59 +02002000 ret = iwl_mvm_update_mu_groups(mvm, vif);
2001 if (ret)
2002 IWL_ERR(mvm,
2003 "failed to update VHT MU_MIMO groups\n");
2004 }
2005
Eliad Pellere59647e2013-11-28 14:08:50 +02002006 iwl_mvm_recalc_multicast(mvm);
Eliad Peller34672bb2015-12-03 16:10:07 +02002007 iwl_mvm_configure_bcast_filter(mvm);
Eliad Pellere59647e2013-11-28 14:08:50 +02002008
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002009 /* reset rssi values */
2010 mvmvif->bf_data.ave_beacon_signal = 0;
2011
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002012 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachf94045e2014-01-06 13:38:55 +02002013 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2014 IEEE80211_SMPS_AUTOMATIC);
Avraham Stern355346b2015-11-26 11:22:33 +02002015 if (fw_has_capa(&mvm->fw->ucode_capa,
2016 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2017 iwl_mvm_config_scan(mvm);
Avraham Sternb45242c2017-01-09 15:39:15 +02002018 }
2019
2020 if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +01002021 /*
Avraham Sternb45242c2017-01-09 15:39:15 +02002022 * We received a beacon from the associated AP so
Johannes Berg210a5442013-01-24 23:48:23 +01002023 * remove the session protection.
2024 */
Avraham Stern3edfb5f2017-08-02 12:13:20 +03002025 iwl_mvm_stop_session_protection(mvm, vif);
Eran Hararycc87d322014-07-15 14:04:23 +03002026
Eran Hararycc87d322014-07-15 14:04:23 +03002027 iwl_mvm_sf_update(mvm, vif, false);
2028 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2029 }
2030
Avri Altman283115f2016-01-24 22:16:08 +02002031 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2032 /*
2033 * Send power command on every beacon change,
2034 * because we may have not enabled beacon abort yet.
2035 */
2036 BSS_CHANGED_BEACON_INFO)) {
Johannes Berg1bc10d32014-08-26 14:25:46 +02002037 ret = iwl_mvm_power_update_mac(mvm);
2038 if (ret)
2039 IWL_ERR(mvm, "failed to update power mode\n");
2040 }
2041
Matti Gottlieb88f2fd72013-07-09 15:25:46 +03002042 if (changes & BSS_CHANGED_TXPOWER) {
2043 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2044 bss_conf->txpower);
2045 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2046 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002047
2048 if (changes & BSS_CHANGED_CQM) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02002049 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002050 /* reset cqm events tracking */
2051 mvmvif->bf_data.last_cqm_event = 0;
Avri Altmanfa7b2e72014-05-20 08:03:24 +03002052 if (mvmvif->bf_data.bf_enabled) {
2053 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2054 if (ret)
2055 IWL_ERR(mvm,
2056 "failed to update CQM thresholds\n");
2057 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03002058 }
Eliad Peller2ee8f022014-01-13 19:07:09 +02002059
2060 if (changes & BSS_CHANGED_ARP_FILTER) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02002061 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
Eliad Peller34672bb2015-12-03 16:10:07 +02002062 iwl_mvm_configure_bcast_filter(mvm);
Eliad Peller2ee8f022014-01-13 19:07:09 +02002063 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002064}
2065
Johannes Berg5023d962013-07-31 14:07:43 +02002066static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2067 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002068{
2069 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2070 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2071 int ret;
2072
Eliad Peller576eeee2014-07-01 18:38:38 +03002073 /*
2074 * iwl_mvm_mac_ctxt_add() might read directly from the device
2075 * (the system time), so make sure it is available.
2076 */
2077 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2078 if (ret)
2079 return ret;
2080
Johannes Berg8ca151b2013-01-24 14:25:36 +01002081 mutex_lock(&mvm->mutex);
2082
2083 /* Send the beacon template */
2084 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2085 if (ret)
2086 goto out_unlock;
2087
Ilan Peer6e97b0d2013-12-23 22:18:02 +02002088 /*
2089 * Re-calculate the tsf id, as the master-slave relations depend on the
2090 * beacon interval, which was not known when the AP interface was added.
2091 */
2092 if (vif->type == NL80211_IFTYPE_AP)
2093 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2094
Gregory Greenman94939082015-08-24 14:38:35 +03002095 mvmvif->ap_assoc_sta_count = 0;
2096
Johannes Berg8ca151b2013-01-24 14:25:36 +01002097 /* Add the mac context */
2098 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2099 if (ret)
2100 goto out_unlock;
2101
2102 /* Perform the binding */
2103 ret = iwl_mvm_binding_add_vif(mvm, vif);
2104 if (ret)
2105 goto out_remove;
2106
Sara Sharonced19f22017-02-06 19:09:32 +02002107 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2108 if (ret)
2109 goto out_unbind;
2110
Johannes Berg8ca151b2013-01-24 14:25:36 +01002111 /* Send the bcast station. At this stage the TBTT and DTIM time events
2112 * are added and applied to the scheduler */
Johannes Berg013290a2014-08-04 13:38:48 +02002113 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002114 if (ret)
Sara Sharonced19f22017-02-06 19:09:32 +02002115 goto out_rm_mcast;
Sara Sharon26d6c162017-01-03 12:00:19 +02002116
Ilan Peer5691e212013-12-31 21:05:50 +02002117 /* must be set before quota calculations */
2118 mvmvif->ap_ibss_active = true;
2119
Ilan Peera11e1442013-12-31 21:19:55 +02002120 /* power updated needs to be done before quotas */
Arik Nemtsov999609f2014-05-15 17:31:51 +03002121 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02002122
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02002123 ret = iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002124 if (ret)
Ilan Peera11e1442013-12-31 21:19:55 +02002125 goto out_quota_failed;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002126
Johannes Berg5023d962013-07-31 14:07:43 +02002127 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002128 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002129 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002130
Eliad Peller29a90a42013-11-05 14:06:29 +02002131 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2132
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002133 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03002134
Arik Nemtsovf6972672014-06-15 16:03:55 +03002135 /* we don't support TDLS during DCM */
2136 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2137 iwl_mvm_teardown_tdls_peers(mvm);
2138
Arik Nemtsov939e4902015-03-08 12:19:42 +02002139 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002140
Ilan Peera11e1442013-12-31 21:19:55 +02002141out_quota_failed:
Arik Nemtsov999609f2014-05-15 17:31:51 +03002142 iwl_mvm_power_update_mac(mvm);
Ilan Peer5691e212013-12-31 21:05:50 +02002143 mvmvif->ap_ibss_active = false;
Johannes Berg013290a2014-08-04 13:38:48 +02002144 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Sara Sharonced19f22017-02-06 19:09:32 +02002145out_rm_mcast:
2146 iwl_mvm_rm_mcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002147out_unbind:
2148 iwl_mvm_binding_remove_vif(mvm, vif);
2149out_remove:
2150 iwl_mvm_mac_ctxt_remove(mvm, vif);
2151out_unlock:
2152 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002153 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002154 return ret;
2155}
2156
Johannes Berg5023d962013-07-31 14:07:43 +02002157static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2158 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002159{
2160 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2161 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2162
Johannes Berg38a12b52013-02-22 14:07:56 +01002163 iwl_mvm_prepare_mac_removal(mvm, vif);
2164
Johannes Berg8ca151b2013-01-24 14:25:36 +01002165 mutex_lock(&mvm->mutex);
2166
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002167 /* Handle AP stop while in CSA */
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03002168 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2169 iwl_mvm_remove_time_event(mvm, mvmvif,
2170 &mvmvif->time_event_data);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002171 RCU_INIT_POINTER(mvm->csa_vif, NULL);
Avraham Sterne9cb0322015-08-31 11:08:27 +03002172 mvmvif->csa_countdown = false;
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03002173 }
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002174
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03002175 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2176 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2177 mvm->csa_tx_block_bcn_timeout = 0;
2178 }
2179
Johannes Berg5023d962013-07-31 14:07:43 +02002180 mvmvif->ap_ibss_active = false;
David Spinadel1c87bba2014-02-27 16:41:52 +02002181 mvm->ap_last_beacon_gp2 = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002182
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002183 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03002184
Eliad Peller29a90a42013-11-05 14:06:29 +02002185 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2186
Johannes Berg5023d962013-07-31 14:07:43 +02002187 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002188 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002189 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002190
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02002191 iwl_mvm_update_quotas(mvm, false, NULL);
Sara Sharonced19f22017-02-06 19:09:32 +02002192
2193 /*
2194 * This is not very nice, but the simplest:
2195 * For older FWs removing the mcast sta before the bcast station may
2196 * cause assert 0x2b00.
2197 * This is fixed in later FW (which will stop beaconing when removing
2198 * bcast station).
2199 * So make the order of removal depend on the TLV
2200 */
2201 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2202 iwl_mvm_rm_mcast_sta(mvm, vif);
Johannes Berg013290a2014-08-04 13:38:48 +02002203 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Sara Sharonced19f22017-02-06 19:09:32 +02002204 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2205 iwl_mvm_rm_mcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002206 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02002207
Arik Nemtsov999609f2014-05-15 17:31:51 +03002208 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02002209
Johannes Berg8ca151b2013-01-24 14:25:36 +01002210 iwl_mvm_mac_ctxt_remove(mvm, vif);
2211
2212 mutex_unlock(&mvm->mutex);
2213}
2214
Johannes Berg5023d962013-07-31 14:07:43 +02002215static void
2216iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2217 struct ieee80211_vif *vif,
2218 struct ieee80211_bss_conf *bss_conf,
2219 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002220{
Ilan Peerbe2056f2013-12-04 16:47:14 +02002221 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman8a5e3662013-11-12 19:16:03 +02002222
Ilan Peerbe2056f2013-12-04 16:47:14 +02002223 /* Changes will be applied when the AP/IBSS is started */
2224 if (!mvmvif->ap_ibss_active)
2225 return;
2226
Johannes Berg863230da2013-12-04 17:08:40 +01002227 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
Johannes Bergf7d8b702014-09-09 15:49:19 +02002228 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002229 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
Johannes Berg863230da2013-12-04 17:08:40 +01002230 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
Avri Altman8a5e3662013-11-12 19:16:03 +02002231
Johannes Berg8ca151b2013-01-24 14:25:36 +01002232 /* Need to send a new beacon template to the FW */
Johannes Berg863230da2013-12-04 17:08:40 +01002233 if (changes & BSS_CHANGED_BEACON &&
2234 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2235 IWL_WARN(mvm, "Failed updating beacon data\n");
Haim Dreyfuss79b7a692014-09-14 12:40:00 +03002236
2237 if (changes & BSS_CHANGED_TXPOWER) {
2238 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2239 bss_conf->txpower);
2240 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2241 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002242}
2243
2244static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2245 struct ieee80211_vif *vif,
2246 struct ieee80211_bss_conf *bss_conf,
2247 u32 changes)
2248{
2249 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2250
Eliad Peller576eeee2014-07-01 18:38:38 +03002251 /*
2252 * iwl_mvm_bss_info_changed_station() might call
2253 * iwl_mvm_protect_session(), which reads directly from
2254 * the device (the system time), so make sure it is available.
2255 */
2256 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2257 return;
2258
Johannes Berg8ca151b2013-01-24 14:25:36 +01002259 mutex_lock(&mvm->mutex);
2260
David Spinadel723f02e2014-04-27 09:54:54 +03002261 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
Luciano Coelhoc7d42482015-05-07 16:00:26 +03002262 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
David Spinadel723f02e2014-04-27 09:54:54 +03002263
Johannes Berg8ca151b2013-01-24 14:25:36 +01002264 switch (vif->type) {
2265 case NL80211_IFTYPE_STATION:
2266 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2267 break;
2268 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02002269 case NL80211_IFTYPE_ADHOC:
2270 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002271 break;
Aviya Erenfeld91b08c2d2016-03-27 14:53:49 +03002272 case NL80211_IFTYPE_MONITOR:
2273 if (changes & BSS_CHANGED_MU_GROUPS)
2274 iwl_mvm_update_mu_groups(mvm, vif);
2275 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002276 default:
2277 /* shouldn't happen */
2278 WARN_ON_ONCE(1);
2279 }
2280
2281 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002282 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002283}
2284
2285static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2286 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02002287 struct ieee80211_scan_request *hw_req)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002288{
2289 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2290 int ret;
2291
Luciano Coelho6749dd82015-03-20 15:51:36 +02002292 if (hw_req->req.n_channels == 0 ||
2293 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002294 return -EINVAL;
2295
2296 mutex_lock(&mvm->mutex);
Luciano Coelho6749dd82015-03-20 15:51:36 +02002297 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002298 mutex_unlock(&mvm->mutex);
Luciano Coelho6749dd82015-03-20 15:51:36 +02002299
Johannes Berg8ca151b2013-01-24 14:25:36 +01002300 return ret;
2301}
2302
2303static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2304 struct ieee80211_vif *vif)
2305{
2306 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2307
2308 mutex_lock(&mvm->mutex);
2309
Luciano Coelhoe7d3aba2015-02-06 10:19:05 +02002310 /* Due to a race condition, it's possible that mac80211 asks
2311 * us to stop a hw_scan when it's already stopped. This can
2312 * happen, for instance, if we stopped the scan ourselves,
2313 * called ieee80211_scan_completed() and the userspace called
2314 * cancel scan scan before ieee80211_scan_work() could run.
2315 * To handle that, simply return if the scan is not running.
2316 */
Luciano Coelho262888f2015-05-07 17:21:09 +03002317 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
Luciano Coelhoc7d42482015-05-07 16:00:26 +03002318 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002319
2320 mutex_unlock(&mvm->mutex);
2321}
2322
2323static void
2324iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
Johannes Berg3e56ead2013-02-15 22:23:18 +01002325 struct ieee80211_sta *sta, u16 tids,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002326 int num_frames,
2327 enum ieee80211_frame_release_type reason,
2328 bool more_data)
2329{
2330 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002331
Johannes Berg3e56ead2013-02-15 22:23:18 +01002332 /* Called when we need to transmit (a) frame(s) from mac80211 */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002333
Johannes Berg3e56ead2013-02-15 22:23:18 +01002334 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2335 tids, more_data, false);
2336}
2337
2338static void
2339iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2340 struct ieee80211_sta *sta, u16 tids,
2341 int num_frames,
2342 enum ieee80211_frame_release_type reason,
2343 bool more_data)
2344{
2345 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2346
Sara Sharon9a3fcf92017-03-14 09:50:35 +02002347 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
Johannes Berg3e56ead2013-02-15 22:23:18 +01002348
2349 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2350 tids, more_data, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002351}
2352
Johannes Berg65e25482016-04-13 14:24:22 +02002353static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2354 enum sta_notify_cmd cmd,
2355 struct ieee80211_sta *sta)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002356{
2357 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01002358 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002359 unsigned long txqs = 0, tids = 0;
Johannes Berg3e56ead2013-02-15 22:23:18 +01002360 int tid;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002361
Johannes Berg960f8642017-06-20 15:18:43 +02002362 /*
2363 * If we have TVQM then we get too high queue numbers - luckily
2364 * we really shouldn't get here with that because such hardware
2365 * should have firmware supporting buffer station offload.
2366 */
2367 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2368 return;
2369
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002370 spin_lock_bh(&mvmsta->lock);
2371 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2372 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2373
Sara Sharon6862fce2017-02-22 19:34:17 +02002374 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
Sara Sharon1c176272016-12-22 13:03:40 +02002375 continue;
2376
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002377 __set_bit(tid_data->txq_id, &txqs);
2378
Liad Kaufmandd321622017-04-05 16:25:11 +03002379 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002380 continue;
2381
2382 __set_bit(tid, &tids);
2383 }
2384
Johannes Berg8ca151b2013-01-24 14:25:36 +01002385 switch (cmd) {
2386 case STA_NOTIFY_SLEEP:
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002387 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
Johannes Berg3e56ead2013-02-15 22:23:18 +01002388 ieee80211_sta_set_buffered(sta, tid, true);
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002389
2390 if (txqs)
2391 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002392 /*
2393 * The fw updates the STA to be asleep. Tx packets on the Tx
2394 * queues to this station will not be transmitted. The fw will
2395 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2396 */
2397 break;
2398 case STA_NOTIFY_AWAKE:
Sara Sharon0ae98812017-01-04 14:53:58 +02002399 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
Johannes Berg8ca151b2013-01-24 14:25:36 +01002400 break;
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002401
2402 if (txqs)
2403 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
Johannes Berg9cc40712013-02-15 22:47:48 +01002404 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002405 break;
2406 default:
2407 break;
2408 }
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002409 spin_unlock_bh(&mvmsta->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002410}
2411
Johannes Berg65e25482016-04-13 14:24:22 +02002412static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2413 struct ieee80211_vif *vif,
2414 enum sta_notify_cmd cmd,
2415 struct ieee80211_sta *sta)
2416{
2417 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2418}
2419
2420void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2421{
2422 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2423 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2424 struct ieee80211_sta *sta;
2425 struct iwl_mvm_sta *mvmsta;
2426 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2427
2428 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2429 return;
2430
2431 rcu_read_lock();
Sara Sharona9560022017-01-26 14:43:32 +02002432 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
Johannes Berg65e25482016-04-13 14:24:22 +02002433 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2434 rcu_read_unlock();
2435 return;
2436 }
2437
2438 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2439
2440 if (!mvmsta->vif ||
2441 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2442 rcu_read_unlock();
2443 return;
2444 }
2445
2446 if (mvmsta->sleeping != sleeping) {
2447 mvmsta->sleeping = sleeping;
2448 __iwl_mvm_mac_sta_notify(mvm->hw,
2449 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2450 sta);
2451 ieee80211_sta_ps_transition(sta, sleeping);
2452 }
2453
2454 if (sleeping) {
2455 switch (notif->type) {
2456 case IWL_MVM_PM_EVENT_AWAKE:
2457 case IWL_MVM_PM_EVENT_ASLEEP:
2458 break;
2459 case IWL_MVM_PM_EVENT_UAPSD:
2460 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2461 break;
2462 case IWL_MVM_PM_EVENT_PS_POLL:
2463 ieee80211_sta_pspoll(sta);
2464 break;
2465 default:
2466 break;
2467 }
2468 }
2469
2470 rcu_read_unlock();
2471}
2472
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002473static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2474 struct ieee80211_vif *vif,
2475 struct ieee80211_sta *sta)
2476{
2477 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01002478 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002479
2480 /*
2481 * This is called before mac80211 does RCU synchronisation,
2482 * so here we already invalidate our internal RCU-protected
2483 * station pointer. The rest of the code will thus no longer
2484 * be able to find the station this way, and we don't rely
2485 * on further RCU synchronisation after the sta_state()
2486 * callback deleted the station.
2487 */
2488 mutex_lock(&mvm->mutex);
2489 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2490 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2491 ERR_PTR(-ENOENT));
Gregory Greenman94939082015-08-24 14:38:35 +03002492
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002493 mutex_unlock(&mvm->mutex);
2494}
2495
Johannes Bergbd1ba662014-11-13 20:53:45 +01002496static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2497 const u8 *bssid)
2498{
2499 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2500 return;
2501
Avraham Sternc5241b02016-04-20 09:29:18 +03002502 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
Avri Altmancee5a882016-02-03 16:28:25 +02002503 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2504 return;
2505 }
2506
Emmanuel Grumbach11dee0b2016-03-15 11:04:29 +02002507 if (!vif->p2p &&
2508 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
Johannes Bergbd1ba662014-11-13 20:53:45 +01002509 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2510 return;
2511 }
2512
2513 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2514}
2515
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002516static void
2517iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2518 struct ieee80211_vif *vif, u8 *peer_addr,
2519 enum nl80211_tdls_operation action)
2520{
2521 struct iwl_fw_dbg_trigger_tlv *trig;
2522 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2523
2524 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TDLS))
2525 return;
2526
2527 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TDLS);
2528 tdls_trig = (void *)trig->data;
Johannes Berg7174beb2017-06-01 16:03:19 +02002529 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
2530 ieee80211_vif_to_wdev(vif), trig))
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002531 return;
2532
2533 if (!(tdls_trig->action_bitmap & BIT(action)))
2534 return;
2535
2536 if (tdls_trig->peer_mode &&
2537 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2538 return;
2539
Johannes Berg7174beb2017-06-01 16:03:19 +02002540 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2541 "TDLS event occurred, peer %pM, action %d",
2542 peer_addr, action);
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002543}
2544
Liad Kaufman24afba72015-07-28 18:56:08 +03002545static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2546 struct iwl_mvm_sta *mvm_sta)
2547{
2548 struct iwl_mvm_tid_data *tid_data;
2549 struct sk_buff *skb;
2550 int i;
2551
2552 spin_lock_bh(&mvm_sta->lock);
2553 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2554 tid_data = &mvm_sta->tid_data[i];
Avraham Stern7e39a002017-07-26 15:08:45 +03002555
2556 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2557 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2558
2559 /*
2560 * The first deferred frame should've stopped the MAC
2561 * queues, so we should never get a second deferred
2562 * frame for the RA/TID.
2563 */
Avraham Stern8458e482017-09-03 16:04:38 +03002564 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
Liad Kaufman24afba72015-07-28 18:56:08 +03002565 ieee80211_free_txskb(mvm->hw, skb);
Avraham Stern7e39a002017-07-26 15:08:45 +03002566 }
Liad Kaufman24afba72015-07-28 18:56:08 +03002567 }
2568 spin_unlock_bh(&mvm_sta->lock);
2569}
2570
Johannes Berg8ca151b2013-01-24 14:25:36 +01002571static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2572 struct ieee80211_vif *vif,
2573 struct ieee80211_sta *sta,
2574 enum ieee80211_sta_state old_state,
2575 enum ieee80211_sta_state new_state)
2576{
2577 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2578 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg6ea29ce2016-12-01 16:25:30 +01002579 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002580 int ret;
2581
2582 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2583 sta->addr, old_state, new_state);
2584
2585 /* this would be a mac80211 bug ... but don't crash */
2586 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2587 return -EINVAL;
2588
Liad Kaufman24afba72015-07-28 18:56:08 +03002589 /*
2590 * If we are in a STA removal flow and in DQA mode:
2591 *
2592 * This is after the sync_rcu part, so the queues have already been
2593 * flushed. No more TXs on their way in mac80211's path, and no more in
2594 * the queues.
2595 * Also, we won't be getting any new TX frames for this station.
2596 * What we might have are deferred TX frames that need to be taken care
2597 * of.
2598 *
2599 * Drop any still-queued deferred-frame before removing the STA, and
2600 * make sure the worker is no longer handling frames for this STA.
2601 */
2602 if (old_state == IEEE80211_STA_NONE &&
Johannes Bergc8f54702017-06-19 23:50:31 +02002603 new_state == IEEE80211_STA_NOTEXIST) {
Liad Kaufman24afba72015-07-28 18:56:08 +03002604 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2605 flush_work(&mvm->add_stream_wk);
2606
2607 /*
2608 * No need to make sure deferred TX indication is off since the
2609 * worker will already remove it if it was on
2610 */
2611 }
2612
Johannes Berg8ca151b2013-01-24 14:25:36 +01002613 mutex_lock(&mvm->mutex);
Johannes Berg6ea29ce2016-12-01 16:25:30 +01002614 /* track whether or not the station is associated */
2615 mvm_sta->associated = new_state >= IEEE80211_STA_ASSOC;
2616
Johannes Berg8ca151b2013-01-24 14:25:36 +01002617 if (old_state == IEEE80211_STA_NOTEXIST &&
2618 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02002619 /*
2620 * Firmware bug - it'll crash if the beacon interval is less
2621 * than 16. We can't avoid connecting at all, so refuse the
2622 * station state change, this will cause mac80211 to abandon
2623 * attempts to connect to this AP, and eventually wpa_s will
2624 * blacklist the AP...
2625 */
2626 if (vif->type == NL80211_IFTYPE_STATION &&
2627 vif->bss_conf.beacon_int < 16) {
2628 IWL_ERR(mvm,
2629 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2630 sta->addr, vif->bss_conf.beacon_int);
2631 ret = -EINVAL;
2632 goto out_unlock;
2633 }
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002634
2635 if (sta->tdls &&
2636 (vif->p2p ||
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002637 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2638 IWL_MVM_TDLS_STA_COUNT ||
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002639 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2640 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2641 ret = -EBUSY;
2642 goto out_unlock;
2643 }
2644
Johannes Berg8ca151b2013-01-24 14:25:36 +01002645 ret = iwl_mvm_add_sta(mvm, vif, sta);
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002646 if (sta->tdls && ret == 0) {
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002647 iwl_mvm_recalc_tdls_state(mvm, vif, true);
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002648 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2649 NL80211_TDLS_SETUP);
2650 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002651 } else if (old_state == IEEE80211_STA_NONE &&
2652 new_state == IEEE80211_STA_AUTH) {
Haim Dreyfusse820c2d2014-04-06 11:19:09 +03002653 /*
2654 * EBS may be disabled due to previous failures reported by FW.
2655 * Reset EBS status here assuming environment has been changed.
2656 */
2657 mvm->last_ebs_successful = true;
Johannes Bergbd1ba662014-11-13 20:53:45 +01002658 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002659 ret = 0;
2660 } else if (old_state == IEEE80211_STA_AUTH &&
2661 new_state == IEEE80211_STA_ASSOC) {
Ayala Beker8be30c12015-12-16 00:32:07 +02002662 if (vif->type == NL80211_IFTYPE_AP) {
2663 mvmvif->ap_assoc_sta_count++;
2664 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2665 }
Goodstein, Mordechay735a0042017-01-15 16:00:12 +02002666
2667 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2668 true);
Johannes Berg7a453972013-02-12 13:10:44 +01002669 ret = iwl_mvm_update_sta(mvm, vif, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002670 } else if (old_state == IEEE80211_STA_ASSOC &&
2671 new_state == IEEE80211_STA_AUTHORIZED) {
Arik Nemtsovf59e0e3c2014-06-10 19:56:27 +03002672
2673 /* we don't support TDLS during DCM */
2674 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2675 iwl_mvm_teardown_tdls_peers(mvm);
2676
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002677 if (sta->tdls)
2678 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2679 NL80211_TDLS_ENABLE_LINK);
2680
Hila Gonen7df15b12012-12-12 11:16:19 +02002681 /* enable beacon filtering */
Avri Altmanfa7b2e72014-05-20 08:03:24 +03002682 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002683 ret = 0;
2684 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2685 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02002686 /* disable beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002687 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002688 ret = 0;
2689 } else if (old_state == IEEE80211_STA_ASSOC &&
2690 new_state == IEEE80211_STA_AUTH) {
Ayala Beker8be30c12015-12-16 00:32:07 +02002691 if (vif->type == NL80211_IFTYPE_AP) {
2692 mvmvif->ap_assoc_sta_count--;
2693 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2694 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002695 ret = 0;
2696 } else if (old_state == IEEE80211_STA_AUTH &&
2697 new_state == IEEE80211_STA_NONE) {
2698 ret = 0;
2699 } else if (old_state == IEEE80211_STA_NONE &&
2700 new_state == IEEE80211_STA_NOTEXIST) {
2701 ret = iwl_mvm_rm_sta(mvm, vif, sta);
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002702 if (sta->tdls) {
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002703 iwl_mvm_recalc_tdls_state(mvm, vif, false);
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002704 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2705 NL80211_TDLS_DISABLE_LINK);
2706 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002707 } else {
2708 ret = -EIO;
2709 }
Johannes Berg48bc1302013-07-04 15:55:29 +02002710 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002711 mutex_unlock(&mvm->mutex);
2712
Liad Kaufman9c126cd2014-10-06 19:08:56 +02002713 if (sta->tdls && ret == 0) {
2714 if (old_state == IEEE80211_STA_NOTEXIST &&
2715 new_state == IEEE80211_STA_NONE)
2716 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2717 else if (old_state == IEEE80211_STA_NONE &&
2718 new_state == IEEE80211_STA_NOTEXIST)
2719 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2720 }
2721
Johannes Berg8ca151b2013-01-24 14:25:36 +01002722 return ret;
2723}
2724
2725static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2726{
2727 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2728
2729 mvm->rts_threshold = value;
2730
2731 return 0;
2732}
2733
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002734static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2735 struct ieee80211_vif *vif,
2736 struct ieee80211_sta *sta, u32 changed)
2737{
2738 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2739
2740 if (vif->type == NL80211_IFTYPE_STATION &&
2741 changed & IEEE80211_RC_NSS_CHANGED)
2742 iwl_mvm_sf_update(mvm, vif, false);
2743}
2744
Johannes Berg8ca151b2013-01-24 14:25:36 +01002745static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2746 struct ieee80211_vif *vif, u16 ac,
2747 const struct ieee80211_tx_queue_params *params)
2748{
2749 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2750 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2751
2752 mvmvif->queue_params[ac] = *params;
2753
2754 /*
2755 * No need to update right away, we'll get BSS_CHANGED_QOS
2756 * The exception is P2P_DEVICE interface which needs immediate update.
2757 */
2758 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2759 int ret;
2760
2761 mutex_lock(&mvm->mutex);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002762 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002763 mutex_unlock(&mvm->mutex);
2764 return ret;
2765 }
2766 return 0;
2767}
2768
2769static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2770 struct ieee80211_vif *vif)
2771{
2772 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Sara Sharon7c70fee2016-02-02 11:55:53 +02002773 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
2774 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002775
2776 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2777 return;
2778
Eliad Peller576eeee2014-07-01 18:38:38 +03002779 /*
2780 * iwl_mvm_protect_session() reads directly from the device
2781 * (the system time), so make sure it is available.
2782 */
2783 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2784 return;
2785
Johannes Berg8ca151b2013-01-24 14:25:36 +01002786 mutex_lock(&mvm->mutex);
2787 /* Try really hard to protect the session and hear a beacon */
Liad Kaufmand20d37b2014-07-06 17:14:39 +03002788 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002789 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002790
2791 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002792}
2793
David Spinadel35a000b2013-08-28 09:29:43 +03002794static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2795 struct ieee80211_vif *vif,
2796 struct cfg80211_sched_scan_request *req,
David Spinadel633e2712014-02-06 16:15:23 +02002797 struct ieee80211_scan_ies *ies)
David Spinadel35a000b2013-08-28 09:29:43 +03002798{
2799 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luciano Coelho6749dd82015-03-20 15:51:36 +02002800
David Spinadel35a000b2013-08-28 09:29:43 +03002801 int ret;
2802
2803 mutex_lock(&mvm->mutex);
2804
Luciano Coelho1f940382015-02-10 13:03:38 +02002805 if (!vif->bss_conf.idle) {
David Spinadelbd5e4742014-04-24 13:15:29 +03002806 ret = -EBUSY;
2807 goto out;
2808 }
2809
Luciano Coelho19945df2015-03-20 16:11:28 +02002810 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
David Spinadeld2496222014-05-20 12:46:37 +03002811
David Spinadel35a000b2013-08-28 09:29:43 +03002812out:
2813 mutex_unlock(&mvm->mutex);
2814 return ret;
2815}
2816
Johannes Berg37e33082014-02-17 10:48:17 +01002817static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2818 struct ieee80211_vif *vif)
David Spinadel35a000b2013-08-28 09:29:43 +03002819{
2820 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002821 int ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002822
2823 mutex_lock(&mvm->mutex);
Luciano Coelhoe7d3aba2015-02-06 10:19:05 +02002824
2825 /* Due to a race condition, it's possible that mac80211 asks
2826 * us to stop a sched_scan when it's already stopped. This
2827 * can happen, for instance, if we stopped the scan ourselves,
2828 * called ieee80211_sched_scan_stopped() and the userspace called
2829 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
2830 * could run. To handle this, simply return if the scan is
2831 * not running.
2832 */
Luciano Coelho262888f2015-05-07 17:21:09 +03002833 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
Luciano Coelhoe7d3aba2015-02-06 10:19:05 +02002834 mutex_unlock(&mvm->mutex);
2835 return 0;
2836 }
2837
Luciano Coelhoc7d42482015-05-07 16:00:26 +03002838 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
David Spinadel35a000b2013-08-28 09:29:43 +03002839 mutex_unlock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002840 iwl_mvm_wait_for_async_handlers(mvm);
Johannes Berg37e33082014-02-17 10:48:17 +01002841
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002842 return ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002843}
2844
Johannes Berg8ca151b2013-01-24 14:25:36 +01002845static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2846 enum set_key_cmd cmd,
2847 struct ieee80211_vif *vif,
2848 struct ieee80211_sta *sta,
2849 struct ieee80211_key_conf *key)
2850{
2851 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Bergf5e28ea2015-12-06 14:58:08 +02002852 struct iwl_mvm_sta *mvmsta;
2853 struct iwl_mvm_key_pn *ptk_pn;
2854 int keyidx = key->keyidx;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002855 int ret;
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002856 u8 key_offset;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002857
Johannes Berg3b37f4c2017-05-30 16:45:31 +02002858 if (iwlwifi_mod_params.swcrypto) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002859 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2860 return -EOPNOTSUPP;
2861 }
2862
2863 switch (key->cipher) {
2864 case WLAN_CIPHER_SUITE_TKIP:
2865 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Eliad Peller1ad4f632016-02-14 13:56:36 +02002866 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002867 break;
Johannes Bergca8c0f42015-04-20 17:54:54 +02002868 case WLAN_CIPHER_SUITE_CCMP:
Ayala Beker2a53d162016-04-07 16:21:57 +03002869 case WLAN_CIPHER_SUITE_GCMP:
2870 case WLAN_CIPHER_SUITE_GCMP_256:
David Spinadel85aeb582017-03-30 19:43:53 +03002871 if (!iwl_mvm_has_new_tx_api(mvm))
2872 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
Johannes Bergca8c0f42015-04-20 17:54:54 +02002873 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002874 case WLAN_CIPHER_SUITE_AES_CMAC:
Ayala Beker8e160ab2016-04-11 11:37:38 +03002875 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2876 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
Johannes Berg30686bf2015-06-02 21:39:54 +02002877 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002878 break;
2879 case WLAN_CIPHER_SUITE_WEP40:
2880 case WLAN_CIPHER_SUITE_WEP104:
Johannes Bergba3943b2014-11-12 23:54:48 +01002881 /* For non-client mode, only use WEP keys for TX as we probably
2882 * don't have a station yet anyway and would then have to keep
2883 * track of the keys, linking them to each of the clients/peers
2884 * as they appear. For now, don't do that, for performance WEP
2885 * offload doesn't really matter much, but we need it for some
2886 * other offload features in client mode.
Johannes Berg8ca151b2013-01-24 14:25:36 +01002887 */
Johannes Bergba3943b2014-11-12 23:54:48 +01002888 if (vif->type != NL80211_IFTYPE_STATION)
2889 return 0;
2890 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002891 default:
Max Stepanove36e5432013-08-27 19:56:13 +03002892 /* currently FW supports only one optional cipher scheme */
2893 if (hw->n_cipher_schemes &&
2894 hw->cipher_schemes->cipher == key->cipher)
2895 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2896 else
2897 return -EOPNOTSUPP;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002898 }
2899
2900 mutex_lock(&mvm->mutex);
2901
2902 switch (cmd) {
2903 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02002904 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2905 vif->type == NL80211_IFTYPE_AP) && !sta) {
2906 /*
2907 * GTK on AP interface is a TX-only key, return 0;
2908 * on IBSS they're per-station and because we're lazy
2909 * we don't support them for RX, so do the same.
Ayala Beker8e160ab2016-04-11 11:37:38 +03002910 * CMAC/GMAC in AP/IBSS modes must be done in software.
Johannes Berg5023d962013-07-31 14:07:43 +02002911 */
Ayala Beker8e160ab2016-04-11 11:37:38 +03002912 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
2913 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
2914 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
Johannes Berg81279c42016-03-09 14:58:47 +01002915 ret = -EOPNOTSUPP;
2916 else
2917 ret = 0;
David Spinadel85aeb582017-03-30 19:43:53 +03002918
2919 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
2920 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
2921 !iwl_mvm_has_new_tx_api(mvm)) {
2922 key->hw_key_idx = STA_KEY_IDX_INVALID;
2923 break;
2924 }
Johannes Berg6caffd42013-03-06 13:15:21 +01002925 }
2926
Johannes Bergb546dcd2015-04-20 17:31:10 +02002927 /* During FW restart, in order to restore the state as it was,
2928 * don't try to reprogram keys we previously failed for.
2929 */
2930 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2931 key->hw_key_idx == STA_KEY_IDX_INVALID) {
2932 IWL_DEBUG_MAC80211(mvm,
2933 "skip invalid idx key programming during restart\n");
2934 ret = 0;
2935 break;
2936 }
2937
Johannes Bergf5e28ea2015-12-06 14:58:08 +02002938 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2939 sta && iwl_mvm_has_new_rx_api(mvm) &&
2940 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
2941 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
Ayala Beker2a53d162016-04-07 16:21:57 +03002942 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
2943 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
Johannes Bergf5e28ea2015-12-06 14:58:08 +02002944 struct ieee80211_key_seq seq;
2945 int tid, q;
2946
2947 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2948 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
2949 ptk_pn = kzalloc(sizeof(*ptk_pn) +
2950 mvm->trans->num_rx_queues *
2951 sizeof(ptk_pn->q[0]),
2952 GFP_KERNEL);
2953 if (!ptk_pn) {
2954 ret = -ENOMEM;
2955 break;
2956 }
2957
2958 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2959 ieee80211_get_key_rx_seq(key, tid, &seq);
2960 for (q = 0; q < mvm->trans->num_rx_queues; q++)
2961 memcpy(ptk_pn->q[q].pn[tid],
2962 seq.ccmp.pn,
2963 IEEE80211_CCMP_PN_LEN);
2964 }
2965
2966 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
2967 }
2968
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002969 /* in HW restart reuse the index, otherwise request a new one */
2970 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
2971 key_offset = key->hw_key_idx;
2972 else
2973 key_offset = STA_KEY_IDX_INVALID;
2974
Johannes Berg8ca151b2013-01-24 14:25:36 +01002975 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002976 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002977 if (ret) {
2978 IWL_WARN(mvm, "set key failed\n");
2979 /*
2980 * can't add key for RX, but we don't need it
2981 * in the device for TX so still return 0
2982 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002983 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002984 ret = 0;
2985 }
2986
2987 break;
2988 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01002989 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2990 ret = 0;
2991 break;
2992 }
2993
Johannes Bergf5e28ea2015-12-06 14:58:08 +02002994 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
2995 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
2996 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
Ayala Beker2a53d162016-04-07 16:21:57 +03002997 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
2998 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
Johannes Bergf5e28ea2015-12-06 14:58:08 +02002999 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3000 ptk_pn = rcu_dereference_protected(
3001 mvmsta->ptk_pn[keyidx],
3002 lockdep_is_held(&mvm->mutex));
3003 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3004 if (ptk_pn)
3005 kfree_rcu(ptk_pn, rcu_head);
3006 }
3007
Johannes Berg8ca151b2013-01-24 14:25:36 +01003008 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3009 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3010 break;
3011 default:
3012 ret = -EINVAL;
3013 }
3014
3015 mutex_unlock(&mvm->mutex);
3016 return ret;
3017}
3018
3019static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3020 struct ieee80211_vif *vif,
3021 struct ieee80211_key_conf *keyconf,
3022 struct ieee80211_sta *sta,
3023 u32 iv32, u16 *phase1key)
3024{
3025 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3026
Johannes Berg5023d962013-07-31 14:07:43 +02003027 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3028 return;
3029
Johannes Berg8ca151b2013-01-24 14:25:36 +01003030 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3031}
3032
3033
Ariej Marjiehb1128892014-07-16 21:11:12 +03003034static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3035 struct iwl_rx_packet *pkt, void *data)
3036{
3037 struct iwl_mvm *mvm =
3038 container_of(notif_wait, struct iwl_mvm, notif_wait);
3039 struct iwl_hs20_roc_res *resp;
3040 int resp_len = iwl_rx_packet_payload_len(pkt);
3041 struct iwl_mvm_time_event_data *te_data = data;
3042
3043 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3044 return true;
3045
3046 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3047 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3048 return true;
3049 }
3050
3051 resp = (void *)pkt->data;
3052
3053 IWL_DEBUG_TE(mvm,
3054 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
3055 resp->status, resp->event_unique_id);
3056
3057 te_data->uid = le32_to_cpu(resp->event_unique_id);
3058 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3059 te_data->uid);
3060
3061 spin_lock_bh(&mvm->time_event_lock);
3062 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3063 spin_unlock_bh(&mvm->time_event_lock);
3064
3065 return true;
3066}
3067
Matti Gottliebdc28e122015-11-22 10:08:56 +02003068#define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3069#define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3070#define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3071#define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3072#define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
Ariej Marjiehb1128892014-07-16 21:11:12 +03003073static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3074 struct ieee80211_channel *channel,
3075 struct ieee80211_vif *vif,
3076 int duration)
3077{
3078 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3079 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3080 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
Sara Sharon6eb031d2015-07-13 14:50:47 +03003081 static const u16 time_event_response[] = { HOT_SPOT_CMD };
Ariej Marjiehb1128892014-07-16 21:11:12 +03003082 struct iwl_notification_wait wait_time_event;
Matti Gottliebdc28e122015-11-22 10:08:56 +02003083 u32 dtim_interval = vif->bss_conf.dtim_period *
3084 vif->bss_conf.beacon_int;
3085 u32 req_dur, delay;
Ariej Marjiehb1128892014-07-16 21:11:12 +03003086 struct iwl_hs20_roc_req aux_roc_req = {
3087 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3088 .id_and_color =
3089 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3090 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3091 /* Set the channel info data */
Johannes Berg57fbcce2016-04-12 15:56:15 +02003092 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
Ariej Marjiehb1128892014-07-16 21:11:12 +03003093 PHY_BAND_24 : PHY_BAND_5,
3094 .channel_info.channel = channel->hw_value,
3095 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3096 /* Set the time and duration */
3097 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
Ariej Marjiehb1128892014-07-16 21:11:12 +03003098 };
3099
Matti Gottliebdc28e122015-11-22 10:08:56 +02003100 delay = AUX_ROC_MIN_DELAY;
3101 req_dur = MSEC_TO_TU(duration);
3102
3103 /*
3104 * If we are associated we want the delay time to be at least one
3105 * dtim interval so that the FW can wait until after the DTIM and
3106 * then start the time event, this will potentially allow us to
3107 * remain off-channel for the max duration.
3108 * Since we want to use almost a whole dtim interval we would also
3109 * like the delay to be for 2-3 dtim intervals, in case there are
3110 * other time events with higher priority.
3111 */
3112 if (vif->bss_conf.assoc) {
3113 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3114 /* We cannot remain off-channel longer than the DTIM interval */
3115 if (dtim_interval <= req_dur) {
3116 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3117 if (req_dur <= AUX_ROC_MIN_DURATION)
3118 req_dur = dtim_interval -
3119 AUX_ROC_MIN_SAFETY_BUFFER;
3120 }
3121 }
3122
3123 aux_roc_req.duration = cpu_to_le32(req_dur);
3124 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3125
3126 IWL_DEBUG_TE(mvm,
3127 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3128 channel->hw_value, req_dur, duration, delay,
3129 dtim_interval);
Ariej Marjiehb1128892014-07-16 21:11:12 +03003130 /* Set the node address */
3131 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3132
Matti Gottlieba6cc5162014-09-29 11:46:04 +03003133 lockdep_assert_held(&mvm->mutex);
3134
3135 spin_lock_bh(&mvm->time_event_lock);
3136
3137 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3138 spin_unlock_bh(&mvm->time_event_lock);
3139 return -EIO;
3140 }
3141
Ariej Marjiehb1128892014-07-16 21:11:12 +03003142 te_data->vif = vif;
3143 te_data->duration = duration;
3144 te_data->id = HOT_SPOT_CMD;
3145
Ariej Marjiehb1128892014-07-16 21:11:12 +03003146 spin_unlock_bh(&mvm->time_event_lock);
3147
3148 /*
3149 * Use a notification wait, which really just processes the
3150 * command response and doesn't wait for anything, in order
3151 * to be able to process the response and get the UID inside
3152 * the RX path. Using CMD_WANT_SKB doesn't work because it
3153 * stores the buffer and then wakes up this thread, by which
3154 * time another notification (that the time event started)
3155 * might already be processed unsuccessfully.
3156 */
3157 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3158 time_event_response,
3159 ARRAY_SIZE(time_event_response),
3160 iwl_mvm_rx_aux_roc, te_data);
3161
3162 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3163 &aux_roc_req);
3164
3165 if (res) {
3166 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3167 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3168 goto out_clear_te;
3169 }
3170
3171 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3172 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3173 /* should never fail */
3174 WARN_ON_ONCE(res);
3175
3176 if (res) {
3177 out_clear_te:
3178 spin_lock_bh(&mvm->time_event_lock);
3179 iwl_mvm_te_clear_data(mvm, te_data);
3180 spin_unlock_bh(&mvm->time_event_lock);
3181 }
3182
3183 return res;
3184}
3185
Johannes Berg8ca151b2013-01-24 14:25:36 +01003186static int iwl_mvm_roc(struct ieee80211_hw *hw,
3187 struct ieee80211_vif *vif,
3188 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02003189 int duration,
3190 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003191{
3192 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003193 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003194 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03003195 struct iwl_mvm_phy_ctxt *phy_ctxt;
3196 int ret, i;
3197
3198 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3199 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003200
Johannes Berg98347812017-11-15 10:16:47 +01003201 /*
3202 * Flush the done work, just in case it's still pending, so that
3203 * the work it does can complete and we can accept new frames.
3204 */
Matti Gottlieb6ed13162015-03-30 16:50:07 +03003205 flush_work(&mvm->roc_done_wk);
3206
Matti Gottlieba6cc5162014-09-29 11:46:04 +03003207 mutex_lock(&mvm->mutex);
3208
Ariej Marjiehb1128892014-07-16 21:11:12 +03003209 switch (vif->type) {
3210 case NL80211_IFTYPE_STATION:
Johannes Berg859d9142015-06-01 17:11:11 +02003211 if (fw_has_capa(&mvm->fw->ucode_capa,
3212 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
Luciano Coelho5ac6c722014-10-21 16:12:18 +03003213 /* Use aux roc framework (HS20) */
3214 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3215 vif, duration);
3216 goto out_unlock;
3217 }
3218 IWL_ERR(mvm, "hotspot not supported\n");
3219 ret = -EINVAL;
Matti Gottlieba6cc5162014-09-29 11:46:04 +03003220 goto out_unlock;
Ariej Marjiehb1128892014-07-16 21:11:12 +03003221 case NL80211_IFTYPE_P2P_DEVICE:
3222 /* handle below */
3223 break;
3224 default:
3225 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
Matti Gottlieba6cc5162014-09-29 11:46:04 +03003226 ret = -EINVAL;
3227 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003228 }
3229
Ilan Peer31d385a2013-04-02 10:25:46 +03003230 for (i = 0; i < NUM_PHY_CTX; i++) {
3231 phy_ctxt = &mvm->phy_ctxts[i];
3232 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3233 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003234
Ilan Peer31d385a2013-04-02 10:25:46 +03003235 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3236 /*
3237 * Unbind the P2P_DEVICE from the current PHY context,
3238 * and if the PHY context is not used remove it.
3239 */
3240 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3241 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3242 goto out_unlock;
3243
3244 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3245
3246 /* Bind the P2P_DEVICE to the current PHY Context */
3247 mvmvif->phy_ctxt = phy_ctxt;
3248
3249 ret = iwl_mvm_binding_add_vif(mvm, vif);
3250 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3251 goto out_unlock;
3252
3253 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3254 goto schedule_time_event;
3255 }
3256 }
3257
3258 /* Need to update the PHY context only if the ROC channel changed */
3259 if (channel == mvmvif->phy_ctxt->channel)
3260 goto schedule_time_event;
3261
3262 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3263
3264 /*
3265 * Change the PHY context configuration as it is currently referenced
3266 * only by the P2P Device MAC
3267 */
3268 if (mvmvif->phy_ctxt->ref == 1) {
3269 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3270 &chandef, 1, 1);
3271 if (ret)
3272 goto out_unlock;
3273 } else {
3274 /*
3275 * The PHY context is shared with other MACs. Need to remove the
3276 * P2P Device from the binding, allocate an new PHY context and
3277 * create a new binding
3278 */
3279 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3280 if (!phy_ctxt) {
3281 ret = -ENOSPC;
3282 goto out_unlock;
3283 }
3284
3285 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3286 1, 1);
3287 if (ret) {
3288 IWL_ERR(mvm, "Failed to change PHY context\n");
3289 goto out_unlock;
3290 }
3291
3292 /* Unbind the P2P_DEVICE from the current PHY context */
3293 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3294 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3295 goto out_unlock;
3296
3297 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3298
3299 /* Bind the P2P_DEVICE to the new allocated PHY context */
3300 mvmvif->phy_ctxt = phy_ctxt;
3301
3302 ret = iwl_mvm_binding_add_vif(mvm, vif);
3303 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3304 goto out_unlock;
3305
3306 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3307 }
3308
3309schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003310 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02003311 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003312
Ilan Peer31d385a2013-04-02 10:25:46 +03003313out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003314 mutex_unlock(&mvm->mutex);
3315 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01003316 return ret;
3317}
3318
3319static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3320{
3321 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3322
3323 IWL_DEBUG_MAC80211(mvm, "enter\n");
3324
3325 mutex_lock(&mvm->mutex);
Matti Gottliebbf5da872014-11-16 10:25:12 +02003326 iwl_mvm_stop_roc(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003327 mutex_unlock(&mvm->mutex);
3328
3329 IWL_DEBUG_MAC80211(mvm, "leave\n");
3330 return 0;
3331}
3332
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003333static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3334 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003335{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003336 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3337 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003338 int ret;
3339
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003340 lockdep_assert_held(&mvm->mutex);
3341
Ilan Peer53a9d612013-04-28 11:55:08 +03003342 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003343
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003344 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3345 if (!phy_ctxt) {
3346 ret = -ENOSPC;
3347 goto out;
3348 }
3349
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02003350 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Ilan Peer53a9d612013-04-28 11:55:08 +03003351 ctx->rx_chains_static,
3352 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003353 if (ret) {
3354 IWL_ERR(mvm, "Failed to add PHY context\n");
3355 goto out;
3356 }
3357
Ilan Peer53a9d612013-04-28 11:55:08 +03003358 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003359 *phy_ctxt_id = phy_ctxt->id;
3360out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003361 return ret;
3362}
3363
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003364static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3365 struct ieee80211_chanctx_conf *ctx)
3366{
3367 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3368 int ret;
3369
3370 mutex_lock(&mvm->mutex);
3371 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3372 mutex_unlock(&mvm->mutex);
3373
3374 return ret;
3375}
3376
3377static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3378 struct ieee80211_chanctx_conf *ctx)
3379{
3380 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3381 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3382
3383 lockdep_assert_held(&mvm->mutex);
3384
3385 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3386}
3387
Johannes Berg8ca151b2013-01-24 14:25:36 +01003388static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3389 struct ieee80211_chanctx_conf *ctx)
3390{
3391 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003392
3393 mutex_lock(&mvm->mutex);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003394 __iwl_mvm_remove_chanctx(mvm, ctx);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003395 mutex_unlock(&mvm->mutex);
3396}
3397
3398static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3399 struct ieee80211_chanctx_conf *ctx,
3400 u32 changed)
3401{
3402 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003403 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3404 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01003405
Ilan Peer31d385a2013-04-02 10:25:46 +03003406 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3407 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3408 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
Arik Nemtsov2dceeda2013-12-29 17:57:53 +02003409 IEEE80211_CHANCTX_CHANGE_RADAR |
3410 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
Ilan Peer31d385a2013-04-02 10:25:46 +03003411 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3412 phy_ctxt->ref, changed))
3413 return;
3414
Johannes Berg8ca151b2013-01-24 14:25:36 +01003415 mutex_lock(&mvm->mutex);
Emmanuel Grumbach7a20bcc2017-09-14 15:45:44 +03003416
3417 /* we are only changing the min_width, may be a noop */
3418 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
3419 if (phy_ctxt->width == ctx->min_def.width)
3420 goto out_unlock;
3421
3422 /* we are just toggling between 20_NOHT and 20 */
3423 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
3424 ctx->min_def.width <= NL80211_CHAN_WIDTH_20)
3425 goto out_unlock;
3426 }
3427
Emmanuel Grumbach4d664492014-04-30 18:09:59 +03003428 iwl_mvm_bt_coex_vif_change(mvm);
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02003429 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003430 ctx->rx_chains_static,
3431 ctx->rx_chains_dynamic);
Emmanuel Grumbach7a20bcc2017-09-14 15:45:44 +03003432
3433out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003434 mutex_unlock(&mvm->mutex);
3435}
3436
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003437static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3438 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02003439 struct ieee80211_chanctx_conf *ctx,
3440 bool switching_chanctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003441{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003442 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3443 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01003444 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3445 int ret;
3446
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003447 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003448
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003449 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003450
3451 switch (vif->type) {
3452 case NL80211_IFTYPE_AP:
Luciano Coelho4741dd02014-11-10 11:10:13 +02003453 /* only needed if we're switching chanctx (i.e. during CSA) */
3454 if (switching_chanctx) {
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003455 mvmvif->ap_ibss_active = true;
3456 break;
3457 }
Johannes Berg5023d962013-07-31 14:07:43 +02003458 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003459 /*
3460 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02003461 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01003462 */
3463 ret = 0;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003464 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003465 case NL80211_IFTYPE_STATION:
Luciano Coelho2533edc2014-08-08 19:50:46 +03003466 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003467 case NL80211_IFTYPE_MONITOR:
Luciano Coelho2533edc2014-08-08 19:50:46 +03003468 /* always disable PS when a monitor interface is active */
3469 mvmvif->ps_disabled = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003470 break;
3471 default:
3472 ret = -EINVAL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003473 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003474 }
3475
3476 ret = iwl_mvm_binding_add_vif(mvm, vif);
3477 if (ret)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003478 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003479
3480 /*
Alexander Bondar92d85562013-10-23 11:50:34 +02003481 * Power state must be updated before quotas,
3482 * otherwise fw will complain.
3483 */
Arik Nemtsov999609f2014-05-15 17:31:51 +03003484 iwl_mvm_power_update_mac(mvm);
Alexander Bondar92d85562013-10-23 11:50:34 +02003485
3486 /* Setting the quota at this stage is only required for monitor
Johannes Berg8ca151b2013-01-24 14:25:36 +01003487 * interfaces. For the other types, the bss_info changed flow
3488 * will handle quota settings.
3489 */
3490 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02003491 mvmvif->monitor_active = true;
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003492 ret = iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003493 if (ret)
3494 goto out_remove_binding;
Chaya Rachel Ivgi0e39eb02015-12-03 15:51:46 +02003495
3496 ret = iwl_mvm_add_snif_sta(mvm, vif);
3497 if (ret)
3498 goto out_remove_binding;
3499
Johannes Berg8ca151b2013-01-24 14:25:36 +01003500 }
3501
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003502 /* Handle binding during CSA */
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003503 if (vif->type == NL80211_IFTYPE_AP) {
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003504 iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02003505 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003506 }
3507
Luciano Coelho4741dd02014-11-10 11:10:13 +02003508 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
Luciano Coelho686e7fe2014-11-10 11:10:21 +02003509 u32 duration = 2 * vif->bss_conf.beacon_int;
3510
3511 /* iwl_mvm_protect_session() reads directly from the
3512 * device (the system time), so make sure it is
3513 * available.
3514 */
3515 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3516 if (ret)
3517 goto out_remove_binding;
3518
3519 /* Protect the session to make sure we hear the first
3520 * beacon on the new channel.
3521 */
3522 iwl_mvm_protect_session(mvm, vif, duration, duration,
3523 vif->bss_conf.beacon_int / 2,
3524 true);
3525
3526 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3527
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003528 iwl_mvm_update_quotas(mvm, false, NULL);
Luciano Coelho0ce04ce2014-05-08 16:03:39 +03003529 }
3530
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003531 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003532
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003533out_remove_binding:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003534 iwl_mvm_binding_remove_vif(mvm, vif);
Arik Nemtsov999609f2014-05-15 17:31:51 +03003535 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003536out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003537 if (ret)
3538 mvmvif->phy_ctxt = NULL;
3539 return ret;
3540}
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003541static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3542 struct ieee80211_vif *vif,
3543 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003544{
3545 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003546 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003547
3548 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003549 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003550 mutex_unlock(&mvm->mutex);
3551
3552 return ret;
3553}
3554
3555static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3556 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02003557 struct ieee80211_chanctx_conf *ctx,
3558 bool switching_chanctx)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003559{
3560 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003561 struct ieee80211_vif *disabled_vif = NULL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003562
3563 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003564
3565 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3566
Johannes Berg8ca151b2013-01-24 14:25:36 +01003567 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02003568 case NL80211_IFTYPE_ADHOC:
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003569 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003570 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02003571 mvmvif->monitor_active = false;
Luciano Coelho2533edc2014-08-08 19:50:46 +03003572 mvmvif->ps_disabled = false;
Chaya Rachel Ivgi0e39eb02015-12-03 15:51:46 +02003573 iwl_mvm_rm_snif_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003574 break;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003575 case NL80211_IFTYPE_AP:
3576 /* This part is triggered only during CSA */
Luciano Coelho4741dd02014-11-10 11:10:13 +02003577 if (!switching_chanctx || !mvmvif->ap_ibss_active)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003578 goto out;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003579
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003580 mvmvif->csa_countdown = false;
3581
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03003582 /* Set CS bit on all the stations */
3583 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3584
3585 /* Save blocked iface, the timeout is set on the next beacon */
3586 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3587
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003588 mvmvif->ap_ibss_active = false;
Luciano Coelhof0c97782014-03-05 15:41:48 +02003589 break;
3590 case NL80211_IFTYPE_STATION:
3591 if (!switching_chanctx)
3592 break;
3593
3594 disabled_vif = vif;
3595
Johannes Berg3dfd3a92014-08-11 21:37:30 +02003596 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003597 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003598 default:
3599 break;
3600 }
3601
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003602 iwl_mvm_update_quotas(mvm, false, disabled_vif);
Ilan Peer1e1391c2013-03-13 14:52:04 +02003603 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03003604
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003605out:
Ilan Peera11e1442013-12-31 21:19:55 +02003606 mvmvif->phy_ctxt = NULL;
Arik Nemtsov999609f2014-05-15 17:31:51 +03003607 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003608}
3609
3610static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3611 struct ieee80211_vif *vif,
3612 struct ieee80211_chanctx_conf *ctx)
3613{
3614 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3615
3616 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003617 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003618 mutex_unlock(&mvm->mutex);
3619}
3620
Luciano Coelho50cc9572014-11-10 11:10:08 +02003621static int
3622iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3623 struct ieee80211_vif_chanctx_switch *vifs)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003624{
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003625 int ret;
3626
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003627 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003628 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003629 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3630
3631 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3632 if (ret) {
3633 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3634 goto out_reassign;
3635 }
3636
Luciano Coelhof0c97782014-03-05 15:41:48 +02003637 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3638 true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003639 if (ret) {
3640 IWL_ERR(mvm,
3641 "failed to assign new_ctx during channel switch\n");
3642 goto out_remove;
3643 }
3644
Arik Nemtsovf6972672014-06-15 16:03:55 +03003645 /* we don't support TDLS during DCM - can be caused by channel switch */
3646 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3647 iwl_mvm_teardown_tdls_peers(mvm);
3648
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003649 goto out;
3650
3651out_remove:
3652 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3653
3654out_reassign:
Luciano Coelho6fd1fb62014-11-10 11:10:10 +02003655 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003656 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3657 goto out_restart;
3658 }
3659
Luciano Coelho6fd1fb62014-11-10 11:10:10 +02003660 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3661 true)) {
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003662 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3663 goto out_restart;
3664 }
3665
3666 goto out;
3667
3668out_restart:
3669 /* things keep failing, better restart the hw */
3670 iwl_mvm_nic_restart(mvm, false);
3671
3672out:
3673 mutex_unlock(&mvm->mutex);
Luciano Coelho50cc9572014-11-10 11:10:08 +02003674
3675 return ret;
3676}
3677
Luciano Coelho48a256e2014-11-10 11:10:09 +02003678static int
3679iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3680 struct ieee80211_vif_chanctx_switch *vifs)
3681{
3682 int ret;
3683
3684 mutex_lock(&mvm->mutex);
3685 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3686
3687 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3688 true);
3689 if (ret) {
3690 IWL_ERR(mvm,
3691 "failed to assign new_ctx during channel switch\n");
3692 goto out_reassign;
3693 }
3694
3695 goto out;
3696
3697out_reassign:
3698 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3699 true)) {
3700 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3701 goto out_restart;
3702 }
3703
3704 goto out;
3705
3706out_restart:
3707 /* things keep failing, better restart the hw */
3708 iwl_mvm_nic_restart(mvm, false);
3709
3710out:
3711 mutex_unlock(&mvm->mutex);
3712
3713 return ret;
3714}
3715
Luciano Coelho50cc9572014-11-10 11:10:08 +02003716static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3717 struct ieee80211_vif_chanctx_switch *vifs,
3718 int n_vifs,
3719 enum ieee80211_chanctx_switch_mode mode)
3720{
3721 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3722 int ret;
3723
3724 /* we only support a single-vif right now */
3725 if (n_vifs > 1)
3726 return -EOPNOTSUPP;
3727
3728 switch (mode) {
3729 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3730 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3731 break;
3732 case CHANCTX_SWMODE_REASSIGN_VIF:
Luciano Coelho48a256e2014-11-10 11:10:09 +02003733 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
Luciano Coelho50cc9572014-11-10 11:10:08 +02003734 break;
3735 default:
3736 ret = -EOPNOTSUPP;
3737 break;
3738 }
3739
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003740 return ret;
3741}
3742
Johannes Berg2f0282d2017-04-20 10:29:03 +02003743static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
3744{
3745 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3746
3747 return mvm->ibss_manager;
3748}
3749
Johannes Berg8ca151b2013-01-24 14:25:36 +01003750static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3751 struct ieee80211_sta *sta,
3752 bool set)
3753{
3754 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01003755 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003756
3757 if (!mvm_sta || !mvm_sta->vif) {
3758 IWL_ERR(mvm, "Station is not associated to a vif\n");
3759 return -EINVAL;
3760 }
3761
3762 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3763}
3764
David Spinadel507cadf2013-07-31 18:07:21 +03003765#ifdef CONFIG_NL80211_TESTMODE
3766static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3767 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3768 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad422013-08-01 14:17:15 +02003769 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03003770};
3771
3772static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3773 struct ieee80211_vif *vif,
3774 void *data, int len)
3775{
3776 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3777 int err;
3778 u32 noa_duration;
3779
Johannes Bergfceb6432017-04-12 14:34:07 +02003780 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
3781 NULL);
David Spinadel507cadf2013-07-31 18:07:21 +03003782 if (err)
3783 return err;
3784
3785 if (!tb[IWL_MVM_TM_ATTR_CMD])
3786 return -EINVAL;
3787
3788 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3789 case IWL_MVM_TM_CMD_SET_NOA:
3790 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3791 !vif->bss_conf.enable_beacon ||
3792 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3793 return -EINVAL;
3794
3795 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3796 if (noa_duration >= vif->bss_conf.beacon_int)
3797 return -EINVAL;
3798
3799 mvm->noa_duration = noa_duration;
3800 mvm->noa_vif = vif;
3801
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003802 return iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Bergf6c6ad422013-08-01 14:17:15 +02003803 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3804 /* must be associated client vif - ignore authorized */
3805 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3806 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3807 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3808 return -EINVAL;
3809
3810 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03003811 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3812 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
David Spinadel507cadf2013-07-31 18:07:21 +03003813 }
3814
3815 return -EOPNOTSUPP;
3816}
3817
3818static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3819 struct ieee80211_vif *vif,
3820 void *data, int len)
3821{
3822 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3823 int err;
3824
3825 mutex_lock(&mvm->mutex);
3826 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3827 mutex_unlock(&mvm->mutex);
3828
3829 return err;
3830}
3831#endif
3832
Luciano Coelho622e3f92014-11-10 11:10:17 +02003833static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3834 struct ieee80211_vif *vif,
3835 struct ieee80211_channel_switch *chsw)
3836{
3837 /* By implementing this operation, we prevent mac80211 from
3838 * starting its own channel switch timer, so that we can call
3839 * ieee80211_chswitch_done() ourselves at the right time
3840 * (which is when the absence time event starts).
3841 */
3842
3843 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3844 "dummy channel switch op\n");
3845}
3846
Luciano Coelhof0289052014-11-10 11:10:06 +02003847static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3848 struct ieee80211_vif *vif,
3849 struct ieee80211_channel_switch *chsw)
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003850{
3851 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003852 struct ieee80211_vif *csa_vif;
Luciano Coelhof6c34822014-11-10 11:10:12 +02003853 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003854 u32 apply_time;
Luciano Coelhof0289052014-11-10 11:10:06 +02003855 int ret;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003856
3857 mutex_lock(&mvm->mutex);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003858
Johannes Berg81d62d52015-03-10 14:44:00 +01003859 mvmvif->csa_failed = false;
3860
Luciano Coelho6b20d772014-11-10 11:10:07 +02003861 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
Luciano Coelhof0289052014-11-10 11:10:06 +02003862 chsw->chandef.center_freq1);
Luciano Coelho6b20d772014-11-10 11:10:07 +02003863
Johannes Berg7174beb2017-06-01 16:03:19 +02003864 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
3865 ieee80211_vif_to_wdev(vif),
3866 FW_DBG_TRIGGER_CHANNEL_SWITCH);
Emmanuel Grumbachf35d9c52015-02-10 10:49:51 +02003867
Luciano Coelho6b20d772014-11-10 11:10:07 +02003868 switch (vif->type) {
3869 case NL80211_IFTYPE_AP:
3870 csa_vif =
3871 rcu_dereference_protected(mvm->csa_vif,
3872 lockdep_is_held(&mvm->mutex));
3873 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3874 "Another CSA is already in progress")) {
3875 ret = -EBUSY;
3876 goto out_unlock;
3877 }
3878
Andrei Otcheretianskid3a108a2016-02-28 17:12:21 +02003879 /* we still didn't unblock tx. prevent new CS meanwhile */
3880 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
3881 lockdep_is_held(&mvm->mutex))) {
3882 ret = -EBUSY;
3883 goto out_unlock;
3884 }
3885
Luciano Coelho6b20d772014-11-10 11:10:07 +02003886 rcu_assign_pointer(mvm->csa_vif, vif);
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003887
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003888 if (WARN_ONCE(mvmvif->csa_countdown,
3889 "Previous CSA countdown didn't complete")) {
3890 ret = -EBUSY;
3891 goto out_unlock;
3892 }
3893
Andrei Otcheretianskid3a108a2016-02-28 17:12:21 +02003894 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
3895
Luciano Coelho6b20d772014-11-10 11:10:07 +02003896 break;
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003897 case NL80211_IFTYPE_STATION:
Luciano Coelho4500e132014-11-10 11:10:15 +02003898 /* Schedule the time event to a bit before beacon 1,
3899 * to make sure we're in the new channel when the
Ilan Peerf5d8f502017-08-08 14:56:58 +03003900 * GO/AP arrives. In case count <= 1 immediately schedule the
3901 * TE (this might result with some packet loss or connection
3902 * loss).
Luciano Coelho4500e132014-11-10 11:10:15 +02003903 */
Ilan Peerf5d8f502017-08-08 14:56:58 +03003904 if (chsw->count <= 1)
3905 apply_time = 0;
3906 else
3907 apply_time = chsw->device_timestamp +
3908 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3909 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003910
3911 if (chsw->block_tx)
3912 iwl_mvm_csa_client_absent(mvm, vif);
3913
Luciano Coelho4500e132014-11-10 11:10:15 +02003914 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003915 apply_time);
Luciano Coelhoc6e0a3e02014-11-10 11:10:18 +02003916 if (mvmvif->bf_data.bf_enabled) {
3917 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3918 if (ret)
3919 goto out_unlock;
3920 }
3921
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003922 break;
Luciano Coelho6b20d772014-11-10 11:10:07 +02003923 default:
3924 break;
3925 }
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003926
Luciano Coelhof6c34822014-11-10 11:10:12 +02003927 mvmvif->ps_disabled = true;
3928
3929 ret = iwl_mvm_power_update_ps(mvm);
3930 if (ret)
3931 goto out_unlock;
Luciano Coelhof0289052014-11-10 11:10:06 +02003932
Arik Nemtsove198f5e2014-09-14 19:13:54 +03003933 /* we won't be on this channel any longer */
3934 iwl_mvm_teardown_tdls_peers(mvm);
3935
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003936out_unlock:
3937 mutex_unlock(&mvm->mutex);
Luciano Coelhof0289052014-11-10 11:10:06 +02003938
3939 return ret;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003940}
3941
Luciano Coelhof6c34822014-11-10 11:10:12 +02003942static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
3943 struct ieee80211_vif *vif)
3944{
3945 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3946 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3947 int ret;
3948
3949 mutex_lock(&mvm->mutex);
3950
Johannes Berg81d62d52015-03-10 14:44:00 +01003951 if (mvmvif->csa_failed) {
3952 mvmvif->csa_failed = false;
3953 ret = -EIO;
3954 goto out_unlock;
3955 }
3956
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003957 if (vif->type == NL80211_IFTYPE_STATION) {
3958 struct iwl_mvm_sta *mvmsta;
3959
3960 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
3961 mvmvif->ap_sta_id);
3962
3963 if (WARN_ON(!mvmsta)) {
3964 ret = -EIO;
3965 goto out_unlock;
3966 }
3967
3968 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
3969
3970 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Luciano Coelhoc6e0a3e02014-11-10 11:10:18 +02003971
3972 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3973 if (ret)
3974 goto out_unlock;
Luciano Coelho686e7fe2014-11-10 11:10:21 +02003975
3976 iwl_mvm_stop_session_protection(mvm, vif);
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003977 }
3978
Luciano Coelhof6c34822014-11-10 11:10:12 +02003979 mvmvif->ps_disabled = false;
3980
3981 ret = iwl_mvm_power_update_ps(mvm);
3982
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003983out_unlock:
Luciano Coelhof6c34822014-11-10 11:10:12 +02003984 mutex_unlock(&mvm->mutex);
3985
3986 return ret;
3987}
3988
David Spinadel6110d9e2017-08-29 13:56:02 +03003989static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
3990{
Sara Sharon435d0822017-09-12 11:06:24 +03003991 int i;
3992
Sara Sharon06195632017-09-12 10:52:53 +03003993 if (!iwl_mvm_has_new_tx_api(mvm)) {
Luca Coelho309c4842017-10-24 22:04:15 +03003994 if (drop) {
3995 mutex_lock(&mvm->mutex);
David Spinadel6110d9e2017-08-29 13:56:02 +03003996 iwl_mvm_flush_tx_path(mvm,
Sara Sharon435d0822017-09-12 11:06:24 +03003997 iwl_mvm_flushable_queues(mvm) & queues, 0);
Luca Coelho309c4842017-10-24 22:04:15 +03003998 mutex_unlock(&mvm->mutex);
3999 } else {
Sara Sharon06195632017-09-12 10:52:53 +03004000 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
Luca Coelho309c4842017-10-24 22:04:15 +03004001 }
Sara Sharon435d0822017-09-12 11:06:24 +03004002 return;
4003 }
4004
4005 mutex_lock(&mvm->mutex);
4006 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4007 struct ieee80211_sta *sta;
4008
4009 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4010 lockdep_is_held(&mvm->mutex));
4011 if (IS_ERR_OR_NULL(sta))
4012 continue;
4013
Sara Sharon06195632017-09-12 10:52:53 +03004014 if (drop)
4015 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4016 else
4017 iwl_mvm_wait_sta_queues_empty(mvm,
4018 iwl_mvm_sta_from_mac80211(sta));
Sara Sharon435d0822017-09-12 11:06:24 +03004019 }
4020 mutex_unlock(&mvm->mutex);
David Spinadel6110d9e2017-08-29 13:56:02 +03004021}
4022
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004023static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4024 struct ieee80211_vif *vif, u32 queues, bool drop)
4025{
4026 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4027 struct iwl_mvm_vif *mvmvif;
4028 struct iwl_mvm_sta *mvmsta;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03004029 struct ieee80211_sta *sta;
4030 int i;
4031 u32 msk = 0;
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004032
David Spinadel6110d9e2017-08-29 13:56:02 +03004033 if (!vif) {
4034 iwl_mvm_flush_no_vif(mvm, queues, drop);
4035 return;
4036 }
4037
4038 if (vif->type != NL80211_IFTYPE_STATION)
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004039 return;
4040
Liad Kaufman24afba72015-07-28 18:56:08 +03004041 /* Make sure we're done with the deferred traffic before flushing */
Johannes Bergc8f54702017-06-19 23:50:31 +02004042 flush_work(&mvm->add_stream_wk);
Liad Kaufman24afba72015-07-28 18:56:08 +03004043
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004044 mutex_lock(&mvm->mutex);
4045 mvmvif = iwl_mvm_vif_from_mac80211(vif);
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004046
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03004047 /* flush the AP-station and all TDLS peers */
Sara Sharon0ae98812017-01-04 14:53:58 +02004048 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03004049 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4050 lockdep_is_held(&mvm->mutex));
4051 if (IS_ERR_OR_NULL(sta))
4052 continue;
4053
4054 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4055 if (mvmsta->vif != vif)
4056 continue;
4057
4058 /* make sure only TDLS peers or the AP are flushed */
4059 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4060
Sara Sharond49394a2017-03-05 13:01:08 +02004061 if (drop) {
4062 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4063 IWL_ERR(mvm, "flush request fail\n");
4064 } else {
4065 msk |= mvmsta->tfd_queue_msk;
Sara Sharond6d517b2017-03-06 10:16:11 +02004066 if (iwl_mvm_has_new_tx_api(mvm))
4067 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
Sara Sharond49394a2017-03-05 13:01:08 +02004068 }
Johannes Berg480acbc2014-10-10 08:59:27 +02004069 }
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004070
Sara Sharond49394a2017-03-05 13:01:08 +02004071 mutex_unlock(&mvm->mutex);
Johannes Berg480acbc2014-10-10 08:59:27 +02004072
Sara Sharond49394a2017-03-05 13:01:08 +02004073 /* this can take a while, and we may need/want other operations
4074 * to succeed while doing this, so do it without the mutex held
4075 */
Sara Sharond6d517b2017-03-06 10:16:11 +02004076 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
Sara Sharona1a57872017-03-05 11:38:58 +02004077 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004078}
4079
Johannes Berg91a8bcd2015-01-14 18:12:41 +01004080static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4081 struct survey_info *survey)
4082{
4083 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4084 int ret;
4085
4086 memset(survey, 0, sizeof(*survey));
4087
4088 /* only support global statistics right now */
4089 if (idx != 0)
4090 return -ENOENT;
4091
Johannes Berg280a3ef2016-06-07 14:46:37 +02004092 if (!fw_has_capa(&mvm->fw->ucode_capa,
4093 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
Johannes Berg91a8bcd2015-01-14 18:12:41 +01004094 return -ENOENT;
4095
4096 mutex_lock(&mvm->mutex);
4097
Johannes Bergaab69302017-03-22 22:05:12 +01004098 if (iwl_mvm_firmware_running(mvm)) {
Johannes Berg33cef922015-01-21 21:41:29 +01004099 ret = iwl_mvm_request_statistics(mvm, false);
Johannes Berg91a8bcd2015-01-14 18:12:41 +01004100 if (ret)
4101 goto out;
4102 }
4103
4104 survey->filled = SURVEY_INFO_TIME |
4105 SURVEY_INFO_TIME_RX |
4106 SURVEY_INFO_TIME_TX |
4107 SURVEY_INFO_TIME_SCAN;
4108 survey->time = mvm->accu_radio_stats.on_time_rf +
4109 mvm->radio_stats.on_time_rf;
4110 do_div(survey->time, USEC_PER_MSEC);
4111
4112 survey->time_rx = mvm->accu_radio_stats.rx_time +
4113 mvm->radio_stats.rx_time;
4114 do_div(survey->time_rx, USEC_PER_MSEC);
4115
4116 survey->time_tx = mvm->accu_radio_stats.tx_time +
4117 mvm->radio_stats.tx_time;
4118 do_div(survey->time_tx, USEC_PER_MSEC);
4119
4120 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4121 mvm->radio_stats.on_time_scan;
4122 do_div(survey->time_scan, USEC_PER_MSEC);
4123
Johannes Berg10a7c0282015-04-01 10:00:31 +02004124 ret = 0;
Johannes Berg91a8bcd2015-01-14 18:12:41 +01004125 out:
4126 mutex_unlock(&mvm->mutex);
4127 return ret;
4128}
4129
Johannes Berg33cef922015-01-21 21:41:29 +01004130static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4131 struct ieee80211_vif *vif,
4132 struct ieee80211_sta *sta,
4133 struct station_info *sinfo)
4134{
4135 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4136 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4137 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4138
Sara Sharon988b5962016-04-10 15:06:55 +03004139 if (mvmsta->avg_energy) {
4140 sinfo->signal_avg = mvmsta->avg_energy;
4141 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL_AVG);
4142 }
4143
Johannes Berg280a3ef2016-06-07 14:46:37 +02004144 if (!fw_has_capa(&mvm->fw->ucode_capa,
4145 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
Johannes Berg33cef922015-01-21 21:41:29 +01004146 return;
4147
4148 /* if beacon filtering isn't on mac80211 does it anyway */
4149 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4150 return;
4151
4152 if (!vif->bss_conf.assoc)
4153 return;
4154
4155 mutex_lock(&mvm->mutex);
4156
4157 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4158 goto unlock;
4159
4160 if (iwl_mvm_request_statistics(mvm, false))
4161 goto unlock;
4162
4163 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4164 mvmvif->beacon_stats.accu_num_beacons;
4165 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX);
4166 if (mvmvif->beacon_stats.avg_signal) {
4167 /* firmware only reports a value after RXing a few beacons */
4168 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4169 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4170 }
4171 unlock:
4172 mutex_unlock(&mvm->mutex);
4173}
4174
Emmanuel Grumbach42032632015-04-15 12:43:46 +03004175static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4176 struct ieee80211_vif *vif,
4177 const struct ieee80211_event *event)
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004178{
Johannes Berg7174beb2017-06-01 16:03:19 +02004179#define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4180 do { \
4181 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4182 break; \
4183 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004184 } while (0)
4185
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004186 struct iwl_fw_dbg_trigger_tlv *trig;
4187 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004188
4189 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
4190 return;
4191
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004192 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
4193 trig_mlme = (void *)trig->data;
Johannes Berg7174beb2017-06-01 16:03:19 +02004194 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4195 ieee80211_vif_to_wdev(vif), trig))
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004196 return;
4197
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004198 if (event->u.mlme.data == ASSOC_EVENT) {
4199 if (event->u.mlme.status == MLME_DENIED)
Luca Coelho4c324a52017-05-19 15:06:29 +03004200 CHECK_MLME_TRIGGER(stop_assoc_denied,
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004201 "DENIED ASSOC: reason %d",
4202 event->u.mlme.reason);
4203 else if (event->u.mlme.status == MLME_TIMEOUT)
Luca Coelho4c324a52017-05-19 15:06:29 +03004204 CHECK_MLME_TRIGGER(stop_assoc_timeout,
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004205 "ASSOC TIMEOUT");
4206 } else if (event->u.mlme.data == AUTH_EVENT) {
4207 if (event->u.mlme.status == MLME_DENIED)
Luca Coelho4c324a52017-05-19 15:06:29 +03004208 CHECK_MLME_TRIGGER(stop_auth_denied,
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004209 "DENIED AUTH: reason %d",
4210 event->u.mlme.reason);
4211 else if (event->u.mlme.status == MLME_TIMEOUT)
Luca Coelho4c324a52017-05-19 15:06:29 +03004212 CHECK_MLME_TRIGGER(stop_auth_timeout,
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004213 "AUTH TIMEOUT");
4214 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
Luca Coelho4c324a52017-05-19 15:06:29 +03004215 CHECK_MLME_TRIGGER(stop_rx_deauth,
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004216 "DEAUTH RX %d", event->u.mlme.reason);
4217 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
Luca Coelho4c324a52017-05-19 15:06:29 +03004218 CHECK_MLME_TRIGGER(stop_tx_deauth,
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004219 "DEAUTH TX %d", event->u.mlme.reason);
4220 }
4221#undef CHECK_MLME_TRIGGER
4222}
4223
Emmanuel Grumbach42032632015-04-15 12:43:46 +03004224static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4225 struct ieee80211_vif *vif,
4226 const struct ieee80211_event *event)
4227{
4228 struct iwl_fw_dbg_trigger_tlv *trig;
4229 struct iwl_fw_dbg_trigger_ba *ba_trig;
4230
4231 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
4232 return;
4233
4234 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
4235 ba_trig = (void *)trig->data;
Johannes Berg7174beb2017-06-01 16:03:19 +02004236 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4237 ieee80211_vif_to_wdev(vif), trig))
Emmanuel Grumbach42032632015-04-15 12:43:46 +03004238 return;
4239
4240 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4241 return;
4242
Johannes Berg7174beb2017-06-01 16:03:19 +02004243 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4244 "BAR received from %pM, tid %d, ssn %d",
4245 event->u.ba.sta->addr, event->u.ba.tid,
4246 event->u.ba.ssn);
Emmanuel Grumbach42032632015-04-15 12:43:46 +03004247}
4248
Emmanuel Grumbach42032632015-04-15 12:43:46 +03004249static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4250 struct ieee80211_vif *vif,
4251 const struct ieee80211_event *event)
4252{
4253 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4254
4255 switch (event->type) {
4256 case MLME_EVENT:
4257 iwl_mvm_event_mlme_callback(mvm, vif, event);
4258 break;
4259 case BAR_RX_EVENT:
4260 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4261 break;
4262 case BA_FRAME_TIMEOUT:
Emmanuel Grumbach528a5422017-08-31 11:52:30 +03004263 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
4264 event->u.ba.tid);
Emmanuel Grumbach42032632015-04-15 12:43:46 +03004265 break;
4266 default:
4267 break;
4268 }
4269}
4270
Sara Sharond0ff5d22016-03-23 16:31:43 +02004271void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4272 struct iwl_mvm_internal_rxq_notif *notif,
4273 u32 size)
Sara Sharon0636b932016-02-18 14:21:12 +02004274{
Sara Sharon0636b932016-02-18 14:21:12 +02004275 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4276 int ret;
4277
4278 lockdep_assert_held(&mvm->mutex);
4279
Sara Sharoncb8550e2017-10-19 08:46:50 +03004280 if (!iwl_mvm_has_new_rx_api(mvm))
Sara Sharon0636b932016-02-18 14:21:12 +02004281 return;
4282
Sara Sharond0ff5d22016-03-23 16:31:43 +02004283 notif->cookie = mvm->queue_sync_cookie;
Sara Sharon0636b932016-02-18 14:21:12 +02004284
Sara Sharond0ff5d22016-03-23 16:31:43 +02004285 if (notif->sync)
4286 atomic_set(&mvm->queue_sync_counter,
4287 mvm->trans->num_rx_queues);
4288
Sara Sharoncb8550e2017-10-19 08:46:50 +03004289 /* TODO - remove this when we have RXQ config API */
Luca Coelho2f7a3862017-11-15 15:07:34 +02004290 if (mvm->trans->cfg->device_family == IWL_DEVICE_FAMILY_22000) {
Sara Sharoncb8550e2017-10-19 08:46:50 +03004291 qmask = BIT(0);
4292 if (notif->sync)
4293 atomic_set(&mvm->queue_sync_counter, 1);
4294 }
4295
Sara Sharond0ff5d22016-03-23 16:31:43 +02004296 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
Sara Sharon0636b932016-02-18 14:21:12 +02004297 if (ret) {
4298 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4299 goto out;
4300 }
Sara Sharond0ff5d22016-03-23 16:31:43 +02004301
Johannes Berg6ad04352017-04-25 10:21:18 +02004302 if (notif->sync) {
Sara Sharon3a732c62016-10-09 17:34:24 +03004303 ret = wait_event_timeout(mvm->rx_sync_waitq,
Johannes Berg6ad04352017-04-25 10:21:18 +02004304 atomic_read(&mvm->queue_sync_counter) == 0 ||
4305 iwl_mvm_is_radio_killed(mvm),
Sara Sharond0ff5d22016-03-23 16:31:43 +02004306 HZ);
Johannes Berg6ad04352017-04-25 10:21:18 +02004307 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4308 }
Sara Sharon0636b932016-02-18 14:21:12 +02004309
4310out:
4311 atomic_set(&mvm->queue_sync_counter, 0);
4312 mvm->queue_sync_cookie++;
4313}
4314
4315static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4316{
4317 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Sara Sharond0ff5d22016-03-23 16:31:43 +02004318 struct iwl_mvm_internal_rxq_notif data = {
4319 .type = IWL_MVM_RXQ_EMPTY,
4320 .sync = 1,
4321 };
Sara Sharon0636b932016-02-18 14:21:12 +02004322
4323 mutex_lock(&mvm->mutex);
Sara Sharond0ff5d22016-03-23 16:31:43 +02004324 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
Sara Sharon0636b932016-02-18 14:21:12 +02004325 mutex_unlock(&mvm->mutex);
4326}
4327
Johannes Berge5209262014-01-20 23:38:59 +01004328const struct ieee80211_ops iwl_mvm_hw_ops = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01004329 .tx = iwl_mvm_mac_tx,
4330 .ampdu_action = iwl_mvm_mac_ampdu_action,
4331 .start = iwl_mvm_mac_start,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004332 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004333 .stop = iwl_mvm_mac_stop,
4334 .add_interface = iwl_mvm_mac_add_interface,
4335 .remove_interface = iwl_mvm_mac_remove_interface,
4336 .config = iwl_mvm_mac_config,
Eliad Pellere59647e2013-11-28 14:08:50 +02004337 .prepare_multicast = iwl_mvm_prepare_multicast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004338 .configure_filter = iwl_mvm_configure_filter,
Andrei Otcheretianskieffd1922015-06-30 12:08:28 +03004339 .config_iface_filter = iwl_mvm_config_iface_filter,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004340 .bss_info_changed = iwl_mvm_bss_info_changed,
4341 .hw_scan = iwl_mvm_mac_hw_scan,
4342 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
Johannes Berg1ddbbb02013-12-04 22:39:17 +01004343 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004344 .sta_state = iwl_mvm_mac_sta_state,
4345 .sta_notify = iwl_mvm_mac_sta_notify,
4346 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
Johannes Berg3e56ead2013-02-15 22:23:18 +01004347 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004348 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02004349 .sta_rc_update = iwl_mvm_sta_rc_update,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004350 .conf_tx = iwl_mvm_mac_conf_tx,
4351 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
Arik Nemtsov07ecd892014-05-20 18:16:42 +03004352 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02004353 .flush = iwl_mvm_mac_flush,
David Spinadel35a000b2013-08-28 09:29:43 +03004354 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4355 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004356 .set_key = iwl_mvm_mac_set_key,
4357 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4358 .remain_on_channel = iwl_mvm_roc,
4359 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004360 .add_chanctx = iwl_mvm_add_chanctx,
4361 .remove_chanctx = iwl_mvm_remove_chanctx,
4362 .change_chanctx = iwl_mvm_change_chanctx,
4363 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4364 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
Luciano Coelhob08c1d92014-05-20 23:31:05 +03004365 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004366
Johannes Berg5023d962013-07-31 14:07:43 +02004367 .start_ap = iwl_mvm_start_ap_ibss,
4368 .stop_ap = iwl_mvm_stop_ap_ibss,
4369 .join_ibss = iwl_mvm_start_ap_ibss,
4370 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004371
Johannes Berg2f0282d2017-04-20 10:29:03 +02004372 .tx_last_beacon = iwl_mvm_tx_last_beacon,
4373
Johannes Berg8ca151b2013-01-24 14:25:36 +01004374 .set_tim = iwl_mvm_set_tim,
4375
Luciano Coelho622e3f92014-11-10 11:10:17 +02004376 .channel_switch = iwl_mvm_channel_switch,
Luciano Coelhof0289052014-11-10 11:10:06 +02004377 .pre_channel_switch = iwl_mvm_pre_channel_switch,
Luciano Coelhof6c34822014-11-10 11:10:12 +02004378 .post_channel_switch = iwl_mvm_post_channel_switch,
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02004379
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +03004380 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4381 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4382 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4383
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02004384 .event_callback = iwl_mvm_mac_event_callback,
4385
Sara Sharon0636b932016-02-18 14:21:12 +02004386 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4387
David Spinadel507cadf2013-07-31 18:07:21 +03004388 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4389
Johannes Berg8ca151b2013-01-24 14:25:36 +01004390#ifdef CONFIG_PM_SLEEP
4391 /* look at d3.c */
4392 .suspend = iwl_mvm_suspend,
4393 .resume = iwl_mvm_resume,
4394 .set_wakeup = iwl_mvm_set_wakeup,
4395 .set_rekey_data = iwl_mvm_set_rekey_data,
4396#if IS_ENABLED(CONFIG_IPV6)
4397 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4398#endif
4399 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4400#endif
Johannes Berg91a8bcd2015-01-14 18:12:41 +01004401 .get_survey = iwl_mvm_mac_get_survey,
Johannes Berg33cef922015-01-21 21:41:29 +01004402 .sta_statistics = iwl_mvm_mac_sta_statistics,
Johannes Berg8ca151b2013-01-24 14:25:36 +01004403};