blob: 0227b29d43c8fca2db0452791fc17c85c89c44d4 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +02009 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020026 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010027 *
28 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020029 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg8ca151b2013-01-24 14:25:36 +010030 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020034 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +020035 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010036 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
47 * distribution.
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *
64 *****************************************************************************/
65#include <linux/kernel.h>
66#include <linux/slab.h>
67#include <linux/skbuff.h>
68#include <linux/netdevice.h>
69#include <linux/etherdevice.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010070#include <linux/ip.h>
Eliad Peller2ee8f022014-01-13 19:07:09 +020071#include <linux/if_arp.h>
Johannes Bergaadede62014-10-09 17:01:36 +020072#include <linux/devcoredump.h>
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +020073#include <linux/time.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010074#include <net/mac80211.h>
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +020075#include <net/ieee80211_radiotap.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010076#include <net/tcp.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010077
78#include "iwl-op-mode.h"
79#include "iwl-io.h"
80#include "mvm.h"
81#include "sta.h"
82#include "time-event.h"
83#include "iwl-eeprom-parse.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010084#include "iwl-phy-db.h"
David Spinadel507cadf2013-07-31 18:07:21 +030085#include "testmode.h"
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +030086#include "iwl-fw-error-dump.h"
87#include "iwl-prph.h"
Eran Harary363039b2014-12-02 15:19:22 +020088#include "iwl-csr.h"
Arik Nemtsov88931cc2014-03-05 12:26:15 +020089#include "iwl-nvm-parse.h"
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +020090#include "fw-dbg.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010091
92static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
93 {
94 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030095 .types = BIT(NL80211_IFTYPE_STATION),
Johannes Berg8ca151b2013-01-24 14:25:36 +010096 },
Johannes Berg3c15a0f2013-05-31 10:17:19 +020097 {
98 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030099 .types = BIT(NL80211_IFTYPE_AP) |
100 BIT(NL80211_IFTYPE_P2P_CLIENT) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200101 BIT(NL80211_IFTYPE_P2P_GO),
102 },
103 {
104 .max = 1,
105 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
106 },
Johannes Berg8ca151b2013-01-24 14:25:36 +0100107};
108
109static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
110 {
Emmanuel Grumbach2624a5c2014-12-16 13:02:03 +0200111 .num_different_channels = 2,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100112 .max_interfaces = 3,
113 .limits = iwl_mvm_limits,
114 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
115 },
116};
117
Johannes Bergf0c26462013-01-22 20:41:58 +0100118#ifdef CONFIG_PM_SLEEP
119static const struct nl80211_wowlan_tcp_data_token_feature
120iwl_mvm_wowlan_tcp_token_feature = {
121 .min_len = 0,
122 .max_len = 255,
123 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
124};
125
126static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
127 .tok = &iwl_mvm_wowlan_tcp_token_feature,
128 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
129 sizeof(struct ethhdr) -
130 sizeof(struct iphdr) -
131 sizeof(struct tcphdr),
132 .data_interval_max = 65535, /* __le16 in API */
133 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
134 sizeof(struct ethhdr) -
135 sizeof(struct iphdr) -
136 sizeof(struct tcphdr),
137 .seq = true,
138};
139#endif
140
Eliad Peller77736922014-01-14 12:35:49 +0200141#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
Eliad Peller2ee8f022014-01-13 19:07:09 +0200142/*
143 * Use the reserved field to indicate magic values.
144 * these values will only be used internally by the driver,
145 * and won't make it to the fw (reserved will be 0).
146 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
147 * be the vif's ip address. in case there is not a single
148 * ip address (0, or more than 1), this attribute will
149 * be skipped.
150 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
151 * the LSB bytes of the vif's mac address
152 */
153enum {
154 BC_FILTER_MAGIC_NONE = 0,
155 BC_FILTER_MAGIC_IP,
156 BC_FILTER_MAGIC_MAC,
157};
158
Eliad Peller77736922014-01-14 12:35:49 +0200159static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
160 {
161 /* arp */
162 .discard = 0,
163 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
164 .attrs = {
165 {
166 /* frame type - arp, hw type - ethernet */
167 .offset_type =
168 BCAST_FILTER_OFFSET_PAYLOAD_START,
169 .offset = sizeof(rfc1042_header),
170 .val = cpu_to_be32(0x08060001),
171 .mask = cpu_to_be32(0xffffffff),
172 },
Eliad Peller2ee8f022014-01-13 19:07:09 +0200173 {
174 /* arp dest ip */
175 .offset_type =
176 BCAST_FILTER_OFFSET_PAYLOAD_START,
177 .offset = sizeof(rfc1042_header) + 2 +
178 sizeof(struct arphdr) +
179 ETH_ALEN + sizeof(__be32) +
180 ETH_ALEN,
181 .mask = cpu_to_be32(0xffffffff),
182 /* mark it as special field */
183 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
184 },
185 },
186 },
187 {
188 /* dhcp offer bcast */
189 .discard = 0,
190 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
191 .attrs = {
192 {
193 /* udp dest port - 68 (bootp client)*/
194 .offset_type = BCAST_FILTER_OFFSET_IP_END,
195 .offset = offsetof(struct udphdr, dest),
196 .val = cpu_to_be32(0x00440000),
197 .mask = cpu_to_be32(0xffff0000),
198 },
199 {
200 /* dhcp - lsb bytes of client hw address */
201 .offset_type = BCAST_FILTER_OFFSET_IP_END,
202 .offset = 38,
203 .mask = cpu_to_be32(0xffffffff),
204 /* mark it as special field */
205 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
206 },
Eliad Peller77736922014-01-14 12:35:49 +0200207 },
208 },
209 /* last filter must be empty */
210 {},
211};
212#endif
213
Eliad Peller7498cf42014-01-16 17:10:44 +0200214void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
215{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200216 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200217 return;
218
219 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
Eliad Peller576eeee2014-07-01 18:38:38 +0300220 spin_lock_bh(&mvm->refs_lock);
221 mvm->refs[ref_type]++;
222 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200223 iwl_trans_ref(mvm->trans);
224}
225
226void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
227{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200228 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200229 return;
230
231 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
Eliad Peller576eeee2014-07-01 18:38:38 +0300232 spin_lock_bh(&mvm->refs_lock);
233 WARN_ON(!mvm->refs[ref_type]--);
234 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200235 iwl_trans_unref(mvm->trans);
236}
237
Eliad Peller576eeee2014-07-01 18:38:38 +0300238static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
239 enum iwl_mvm_ref_type except_ref)
Eliad Peller7498cf42014-01-16 17:10:44 +0200240{
Eliad Peller576eeee2014-07-01 18:38:38 +0300241 int i, j;
Eliad Peller7498cf42014-01-16 17:10:44 +0200242
Eliad Peller7bb426e2014-02-24 12:54:37 +0200243 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200244 return;
245
Eliad Peller576eeee2014-07-01 18:38:38 +0300246 spin_lock_bh(&mvm->refs_lock);
247 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
248 if (except_ref == i || !mvm->refs[i])
Eliad Peller7498cf42014-01-16 17:10:44 +0200249 continue;
250
Eliad Peller576eeee2014-07-01 18:38:38 +0300251 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
252 i, mvm->refs[i]);
253 for (j = 0; j < mvm->refs[i]; j++)
254 iwl_trans_unref(mvm->trans);
255 mvm->refs[i] = 0;
Eliad Peller7498cf42014-01-16 17:10:44 +0200256 }
Eliad Peller576eeee2014-07-01 18:38:38 +0300257 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200258}
259
Eliad Pellerf4cf8682014-11-04 16:57:06 +0200260bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
261{
262 int i;
263 bool taken = false;
264
265 if (!iwl_mvm_is_d0i3_supported(mvm))
266 return true;
267
268 spin_lock_bh(&mvm->refs_lock);
269 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
270 if (mvm->refs[i]) {
271 taken = true;
272 break;
273 }
274 }
275 spin_unlock_bh(&mvm->refs_lock);
276
277 return taken;
278}
279
Eliad Peller576eeee2014-07-01 18:38:38 +0300280int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
Gregory Greenmand40fc482014-06-25 14:08:50 +0200281{
282 iwl_mvm_ref(mvm, ref_type);
283
284 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
285 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
286 HZ)) {
287 WARN_ON_ONCE(1);
288 iwl_mvm_unref(mvm, ref_type);
289 return -EIO;
290 }
291
292 return 0;
293}
294
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200295static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
296{
297 int i;
298
299 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
300 for (i = 0; i < NUM_PHY_CTX; i++) {
301 mvm->phy_ctxts[i].id = i;
302 mvm->phy_ctxts[i].ref = 0;
303 }
304}
305
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200306struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200307 const char *alpha2,
Jonathan Doron47c8b152014-11-27 16:55:25 +0200308 enum iwl_mcc_source src_id,
309 bool *changed)
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200310{
311 struct ieee80211_regdomain *regd = NULL;
312 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
313 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
314 struct iwl_mcc_update_resp *resp;
315
316 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
317
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200318 lockdep_assert_held(&mvm->mutex);
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200319
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200320 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200321 if (IS_ERR_OR_NULL(resp)) {
322 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
Nicholas Krauseb8c474d2015-05-23 20:53:21 -0400323 PTR_ERR_OR_ZERO(resp));
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200324 goto out;
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200325 }
326
Jonathan Doron47c8b152014-11-27 16:55:25 +0200327 if (changed)
328 *changed = (resp->status == MCC_RESP_NEW_CHAN_PROFILE);
329
Arik Nemtsov162ee3c2014-06-10 11:25:35 +0300330 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200331 __le32_to_cpu(resp->n_channels),
332 resp->channels,
333 __le16_to_cpu(resp->mcc));
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200334 /* Store the return source id */
335 src_id = resp->source_id;
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200336 kfree(resp);
337 if (IS_ERR_OR_NULL(regd)) {
338 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
Nicholas Krauseb8c474d2015-05-23 20:53:21 -0400339 PTR_ERR_OR_ZERO(regd));
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200340 goto out;
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200341 }
342
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200343 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
344 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200345 mvm->lar_regdom_set = true;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200346 mvm->mcc_src = src_id;
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200347
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200348out:
Arik Nemtsov88931cc2014-03-05 12:26:15 +0200349 return regd;
350}
351
Jonathan Doron47c8b152014-11-27 16:55:25 +0200352void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
353{
354 bool changed;
355 struct ieee80211_regdomain *regd;
356
357 if (!iwl_mvm_is_lar_supported(mvm))
358 return;
359
360 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
361 if (!IS_ERR_OR_NULL(regd)) {
362 /* only update the regulatory core if changed */
363 if (changed)
364 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
365
366 kfree(regd);
367 }
368}
369
370struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
371 bool *changed)
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200372{
373 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
374 iwl_mvm_is_wifi_mcc_supported(mvm) ?
375 MCC_SOURCE_GET_CURRENT :
Jonathan Doron47c8b152014-11-27 16:55:25 +0200376 MCC_SOURCE_OLD_FW, changed);
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200377}
378
379int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
380{
381 enum iwl_mcc_source used_src;
382 struct ieee80211_regdomain *regd;
Arik Nemtsovb6e160a2015-03-23 14:32:53 +0200383 int ret;
384 bool changed;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200385 const struct ieee80211_regdomain *r =
386 rtnl_dereference(mvm->hw->wiphy->regd);
387
388 if (!r)
Arik Nemtsovb6e160a2015-03-23 14:32:53 +0200389 return -ENOENT;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200390
391 /* save the last source in case we overwrite it below */
392 used_src = mvm->mcc_src;
393 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
394 /* Notify the firmware we support wifi location updates */
Jonathan Doron47c8b152014-11-27 16:55:25 +0200395 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200396 if (!IS_ERR_OR_NULL(regd))
397 kfree(regd);
398 }
399
400 /* Now set our last stored MCC and source */
Arik Nemtsovb6e160a2015-03-23 14:32:53 +0200401 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
402 &changed);
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200403 if (IS_ERR_OR_NULL(regd))
404 return -EIO;
405
Arik Nemtsovb6e160a2015-03-23 14:32:53 +0200406 /* update cfg80211 if the regdomain was changed */
407 if (changed)
408 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
409 else
410 ret = 0;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200411
Arik Nemtsovb6e160a2015-03-23 14:32:53 +0200412 kfree(regd);
413 return ret;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200414}
415
Johannes Berg8ca151b2013-01-24 14:25:36 +0100416int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
417{
418 struct ieee80211_hw *hw = mvm->hw;
Ilan Peer831e85f2013-02-07 17:09:09 +0200419 int num_mac, ret, i;
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200420 static const u32 mvm_ciphers[] = {
421 WLAN_CIPHER_SUITE_WEP40,
422 WLAN_CIPHER_SUITE_WEP104,
423 WLAN_CIPHER_SUITE_TKIP,
424 WLAN_CIPHER_SUITE_CCMP,
425 };
Johannes Berg8ca151b2013-01-24 14:25:36 +0100426
427 /* Tell mac80211 our characteristics */
Johannes Berg30686bf2015-06-02 21:39:54 +0200428 ieee80211_hw_set(hw, SIGNAL_DBM);
429 ieee80211_hw_set(hw, SPECTRUM_MGMT);
430 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
431 ieee80211_hw_set(hw, QUEUE_CONTROL);
432 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
433 ieee80211_hw_set(hw, SUPPORTS_PS);
434 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
435 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
436 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
437 ieee80211_hw_set(hw, CONNECTION_MONITOR);
438 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
439 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
440 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100441
Johannes Berg2d7cf542015-04-17 16:39:12 +0200442 if (mvm->trans->max_skb_frags)
443 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
444
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200445 hw->queues = mvm->first_agg_queue;
Ilan Peer398e8c62013-03-13 15:20:35 +0200446 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +0200447 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
448 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
Eyal Shapira339b3082014-11-18 16:43:55 +0200449 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
450 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100451 hw->rate_control_algorithm = "iwl-mvm-rs";
Johannes Berg848955c2014-11-11 12:48:42 +0100452 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
453 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100454
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200455 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 2);
456 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
457 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
458 hw->wiphy->cipher_suites = mvm->ciphers;
459
Johannes Berg8ca151b2013-01-24 14:25:36 +0100460 /*
461 * Enable 11w if advertised by firmware and software crypto
462 * is not enabled (as the firmware will interpret some mgmt
463 * packets, so enabling it with software crypto isn't safe)
464 */
465 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200466 !iwlwifi_mod_params.sw_crypto) {
Johannes Berg30686bf2015-06-02 21:39:54 +0200467 ieee80211_hw_set(hw, MFP_CAPABLE);
Johannes Berg5f4c02e2015-05-20 16:51:28 +0200468 mvm->ciphers[hw->wiphy->n_cipher_suites] =
469 WLAN_CIPHER_SUITE_AES_CMAC;
470 hw->wiphy->n_cipher_suites++;
471 }
472
473 /* currently FW API supports only one optional cipher scheme */
474 if (mvm->fw->cs[0].cipher) {
475 mvm->hw->n_cipher_schemes = 1;
476 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
477 mvm->ciphers[hw->wiphy->n_cipher_suites] =
478 mvm->fw->cs[0].cipher;
479 hw->wiphy->n_cipher_suites++;
480 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100481
Johannes Berg30686bf2015-06-02 21:39:54 +0200482 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
Luciano Coelho1f940382015-02-10 13:03:38 +0200483 hw->wiphy->features |=
484 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
Johannes Berg3db93422015-05-06 14:56:51 +0200485 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
486 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
David Spinadelfb98be52014-05-04 12:51:10 +0300487
Johannes Berg8ca151b2013-01-24 14:25:36 +0100488 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
489 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200490 hw->chanctx_data_size = sizeof(u16);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100491
492 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200493 BIT(NL80211_IFTYPE_P2P_CLIENT) |
494 BIT(NL80211_IFTYPE_AP) |
495 BIT(NL80211_IFTYPE_P2P_GO) |
Emmanuel Grumbachc13b1722014-03-27 19:12:12 +0200496 BIT(NL80211_IFTYPE_P2P_DEVICE) |
497 BIT(NL80211_IFTYPE_ADHOC);
Johannes Berg5023d962013-07-31 14:07:43 +0200498
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +0100499 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Eran Harary8ba2d7a2015-02-08 11:41:43 +0200500 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
501 if (iwl_mvm_is_lar_supported(mvm))
502 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
503 else
504 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
505 REGULATORY_DISABLE_BEACON_HINTS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100506
Johannes Berg3e56ead2013-02-15 22:23:18 +0100507 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
508 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
509
Emmanuel Grumbach94bbed72014-11-24 08:53:33 +0200510 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +0200511
Johannes Berg8ca151b2013-01-24 14:25:36 +0100512 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
513 hw->wiphy->n_iface_combinations =
514 ARRAY_SIZE(iwl_mvm_iface_combinations);
515
Ilan Peerc451e6d2013-02-20 08:41:54 +0200516 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100517 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
Emmanuel Grumbachf1a68542014-12-16 12:31:13 +0200518 /* we can compensate an offset of up to 3 channels = 15 MHz */
519 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100520
521 /* Extract MAC address */
522 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
523 hw->wiphy->addresses = mvm->addresses;
524 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200525
526 /* Extract additional MAC addresses if available */
527 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
528 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
529
530 for (i = 1; i < num_mac; i++) {
531 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100532 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200533 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100534 hw->wiphy->n_addresses++;
535 }
536
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200537 iwl_mvm_reset_phy_ctxts(mvm);
538
Luciano Coelho999d2562015-03-27 10:28:26 +0300539 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
David Spinadel20f1a5d2013-08-21 09:14:27 +0300540
Johannes Berg8ca151b2013-01-24 14:25:36 +0100541 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
542
Luciano Coelhoc7d42482015-05-07 16:00:26 +0300543 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
Luciano Coelho507e4cd2015-03-19 22:58:33 +0200544 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
545 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
546
Johannes Berg859d9142015-06-01 17:11:11 +0200547 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
Luciano Coelho507e4cd2015-03-19 22:58:33 +0200548 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
549 else
550 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
551
Johannes Berg8ca151b2013-01-24 14:25:36 +0100552 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
553 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
554 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
Eyal Shapira3d44eeb2015-01-16 22:37:04 +0200555 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100556 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
557 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
558
Johannes Berg859d9142015-06-01 17:11:11 +0200559 if (fw_has_capa(&mvm->fw->ucode_capa,
560 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
561 fw_has_api(&mvm->fw->ucode_capa,
562 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
Eyal Shapira3d44eeb2015-01-16 22:37:04 +0200563 hw->wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap.cap |=
564 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
565 }
566
Johannes Berg8ca151b2013-01-24 14:25:36 +0100567 hw->wiphy->hw_version = mvm->trans->hw_id;
568
Alexander Bondarade50652013-04-03 16:28:47 +0300569 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100570 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
571 else
572 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
573
Emmanuel Grumbach9954b372015-03-16 14:49:55 +0200574 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
575 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
576 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
577 /* we create the 802.11 header and zero length SSID IE. */
578 hw->wiphy->max_sched_scan_ie_len =
579 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
Avraham Sterncd55cce2015-08-19 12:46:12 +0300580 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
581 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
582
583 /*
584 * the firmware uses u8 for num of iterations, but 0xff is saved for
585 * infinite loop, so the maximum number of iterations is actually 254.
586 */
587 hw->wiphy->max_sched_scan_plan_iterations = 254;
David Spinadel35a000b2013-08-28 09:29:43 +0300588
Johannes Berg8ca151b2013-01-24 14:25:36 +0100589 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
Johannes Bergab480032014-06-04 10:13:50 +0200590 NL80211_FEATURE_LOW_PRIORITY_SCAN |
Eliad Peller0d8614b2014-09-10 14:07:36 +0300591 NL80211_FEATURE_P2P_GO_OPPPS |
592 NL80211_FEATURE_DYNAMIC_SMPS |
Emmanuel Grumbach9b5452f2014-10-07 10:38:53 +0300593 NL80211_FEATURE_STATIC_SMPS |
594 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100595
Johannes Berg859d9142015-06-01 17:11:11 +0200596 if (fw_has_capa(&mvm->fw->ucode_capa,
597 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300598 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
Johannes Berg859d9142015-06-01 17:11:11 +0200599 if (fw_has_capa(&mvm->fw->ucode_capa,
600 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
Assaf Krauss226bcd42014-03-13 08:12:15 +0200601 hw->wiphy->features |= NL80211_FEATURE_QUIET;
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300602
Johannes Berg859d9142015-06-01 17:11:11 +0200603 if (fw_has_capa(&mvm->fw->ucode_capa,
604 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300605 hw->wiphy->features |=
606 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
607
Johannes Berg859d9142015-06-01 17:11:11 +0200608 if (fw_has_capa(&mvm->fw->ucode_capa,
609 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300610 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
611
Johannes Berg8ca151b2013-01-24 14:25:36 +0100612 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
613
614#ifdef CONFIG_PM_SLEEP
Eliad Pellerd15a7472014-03-27 18:53:12 +0200615 if (iwl_mvm_is_d0i3_supported(mvm) &&
616 device_can_wakeup(mvm->trans->dev)) {
617 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
618 hw->wiphy->wowlan = &mvm->wowlan;
Eliad Peller91742442014-12-09 15:54:46 +0200619 }
620
621 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100622 mvm->trans->ops->d3_suspend &&
623 mvm->trans->ops->d3_resume &&
624 device_can_wakeup(mvm->trans->dev)) {
Eliad Peller91742442014-12-09 15:54:46 +0200625 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
626 WIPHY_WOWLAN_DISCONNECT |
627 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
628 WIPHY_WOWLAN_RFKILL_RELEASE |
629 WIPHY_WOWLAN_NET_DETECT;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100630 if (!iwlwifi_mod_params.sw_crypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200631 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
632 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
633 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100634
Johannes Berg964dc9e2013-06-03 17:25:34 +0200635 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
636 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
637 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
Luciano Coelhoc55385f2014-10-24 10:39:51 +0300638 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
Johannes Berg964dc9e2013-06-03 17:25:34 +0200639 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
640 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100641 }
642#endif
643
Eliad Peller77736922014-01-14 12:35:49 +0200644#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
645 /* assign default bcast filtering configuration */
646 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
647#endif
648
Johannes Berg8ca151b2013-01-24 14:25:36 +0100649 ret = iwl_mvm_leds_init(mvm);
650 if (ret)
651 return ret;
652
Johannes Berg859d9142015-06-01 17:11:11 +0200653 if (fw_has_capa(&mvm->fw->ucode_capa,
654 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
Arik Nemtsovd8f1c512014-05-11 18:13:04 +0300655 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
656 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
Arik Nemtsov7c4f0842015-04-30 18:31:45 +0300657 ieee80211_hw_set(hw, TDLS_WIDER_BW);
Arik Nemtsovd8f1c512014-05-11 18:13:04 +0300658 }
659
Johannes Berg859d9142015-06-01 17:11:11 +0200660 if (fw_has_capa(&mvm->fw->ucode_capa,
661 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +0300662 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
663 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
664 }
665
Avri Altman93190fb2014-12-27 09:09:47 +0200666 hw->netdev_features |= mvm->cfg->features;
667 if (!iwl_mvm_is_csum_supported(mvm))
668 hw->netdev_features &= ~NETIF_F_RXCSUM;
669
Emmanuel Grumbach41837ca92015-10-21 09:00:07 +0300670 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
671 hw->netdev_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
672
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300673 ret = ieee80211_register_hw(mvm->hw);
674 if (ret)
675 iwl_mvm_leds_exit(mvm);
676
677 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100678}
679
Arik Nemtsovb2492502014-03-13 12:21:50 +0200680static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
681 struct ieee80211_sta *sta,
682 struct sk_buff *skb)
683{
684 struct iwl_mvm_sta *mvmsta;
685 bool defer = false;
686
687 /*
688 * double check the IN_D0I3 flag both before and after
689 * taking the spinlock, in order to prevent taking
690 * the spinlock when not needed.
691 */
692 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
693 return false;
694
695 spin_lock(&mvm->d0i3_tx_lock);
696 /*
697 * testing the flag again ensures the skb dequeue
698 * loop (on d0i3 exit) hasn't run yet.
699 */
700 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
701 goto out;
702
703 mvmsta = iwl_mvm_sta_from_mac80211(sta);
704 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
705 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
706 goto out;
707
708 __skb_queue_tail(&mvm->d0i3_tx, skb);
709 ieee80211_stop_queues(mvm->hw);
710
711 /* trigger wakeup */
712 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
713 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
714
715 defer = true;
716out:
717 spin_unlock(&mvm->d0i3_tx_lock);
718 return defer;
719}
720
Johannes Berg8ca151b2013-01-24 14:25:36 +0100721static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
722 struct ieee80211_tx_control *control,
723 struct sk_buff *skb)
724{
725 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg3e56ead2013-02-15 22:23:18 +0100726 struct ieee80211_sta *sta = control->sta;
727 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
728 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100729
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300730 if (iwl_mvm_is_radio_killed(mvm)) {
731 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100732 goto drop;
733 }
734
Ilan Peer398e8c62013-03-13 15:20:35 +0200735 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Matti Gottlieba6cc5162014-09-29 11:46:04 +0300736 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
737 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100738 goto drop;
739
Johannes Berg3e56ead2013-02-15 22:23:18 +0100740 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
741 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
742 ieee80211_is_mgmt(hdr->frame_control) &&
743 !ieee80211_is_deauth(hdr->frame_control) &&
744 !ieee80211_is_disassoc(hdr->frame_control) &&
745 !ieee80211_is_action(hdr->frame_control)))
746 sta = NULL;
747
748 if (sta) {
Arik Nemtsovb2492502014-03-13 12:21:50 +0200749 if (iwl_mvm_defer_tx(mvm, sta, skb))
750 return;
Johannes Berg3e56ead2013-02-15 22:23:18 +0100751 if (iwl_mvm_tx_skb(mvm, skb, sta))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100752 goto drop;
753 return;
754 }
755
756 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
757 goto drop;
758 return;
759 drop:
760 ieee80211_free_txskb(hw, skb);
761}
762
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200763static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
764{
765 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
766 return false;
767 return true;
768}
769
770static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
771{
772 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
773 return false;
774 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
775 return true;
776
777 /* enabled by default */
778 return true;
779}
780
Emmanuel Grumbach42032632015-04-15 12:43:46 +0300781#define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
782 do { \
783 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
784 break; \
785 iwl_mvm_fw_dbg_collect_trig(_mvm, _trig, _fmt); \
786 } while (0)
787
788static void
789iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
790 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
791 enum ieee80211_ampdu_mlme_action action)
792{
793 struct iwl_fw_dbg_trigger_tlv *trig;
794 struct iwl_fw_dbg_trigger_ba *ba_trig;
795
796 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
797 return;
798
799 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
800 ba_trig = (void *)trig->data;
801
802 if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig))
803 return;
804
805 switch (action) {
806 case IEEE80211_AMPDU_TX_OPERATIONAL: {
807 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
808 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
809
810 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
811 "TX AGG START: MAC %pM tid %d ssn %d\n",
812 sta->addr, tid, tid_data->ssn);
813 break;
814 }
815 case IEEE80211_AMPDU_TX_STOP_CONT:
816 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
817 "TX AGG STOP: MAC %pM tid %d\n",
818 sta->addr, tid);
819 break;
820 case IEEE80211_AMPDU_RX_START:
821 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
822 "RX AGG START: MAC %pM tid %d ssn %d\n",
823 sta->addr, tid, rx_ba_ssn);
824 break;
825 case IEEE80211_AMPDU_RX_STOP:
826 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
827 "RX AGG STOP: MAC %pM tid %d\n",
828 sta->addr, tid);
829 break;
830 default:
831 break;
832 }
833}
834
Johannes Berg8ca151b2013-01-24 14:25:36 +0100835static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
836 struct ieee80211_vif *vif,
837 enum ieee80211_ampdu_mlme_action action,
838 struct ieee80211_sta *sta, u16 tid,
Emmanuel Grumbache3abc8f2015-08-16 11:13:22 +0300839 u16 *ssn, u8 buf_size, bool amsdu)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100840{
841 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
842 int ret;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200843 bool tx_agg_ref = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100844
845 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
846 sta->addr, tid, action);
847
848 if (!(mvm->nvm_data->sku_cap_11n_enable))
849 return -EACCES;
850
Arik Nemtsovb2492502014-03-13 12:21:50 +0200851 /* return from D0i3 before starting a new Tx aggregation */
Eliad Peller9256c202014-04-22 13:33:29 +0300852 switch (action) {
853 case IEEE80211_AMPDU_TX_START:
854 case IEEE80211_AMPDU_TX_STOP_CONT:
855 case IEEE80211_AMPDU_TX_STOP_FLUSH:
856 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
857 case IEEE80211_AMPDU_TX_OPERATIONAL:
Arik Nemtsovb2492502014-03-13 12:21:50 +0200858 /*
Eliad Peller9256c202014-04-22 13:33:29 +0300859 * for tx start, wait synchronously until D0i3 exit to
860 * get the correct sequence number for the tid.
861 * additionally, some other ampdu actions use direct
862 * target access, which is not handled automatically
863 * by the trans layer (unlike commands), so wait for
864 * d0i3 exit in these cases as well.
Arik Nemtsovb2492502014-03-13 12:21:50 +0200865 */
Gregory Greenmand40fc482014-06-25 14:08:50 +0200866 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
867 if (ret)
868 return ret;
869
870 tx_agg_ref = true;
Eliad Peller9256c202014-04-22 13:33:29 +0300871 break;
872 default:
873 break;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200874 }
875
Johannes Berg8ca151b2013-01-24 14:25:36 +0100876 mutex_lock(&mvm->mutex);
877
878 switch (action) {
879 case IEEE80211_AMPDU_RX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200880 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100881 ret = -EINVAL;
882 break;
883 }
884 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
885 break;
886 case IEEE80211_AMPDU_RX_STOP:
887 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
888 break;
889 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200890 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200891 ret = -EINVAL;
892 break;
893 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100894 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
895 break;
896 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200897 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
898 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100899 case IEEE80211_AMPDU_TX_STOP_FLUSH:
900 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200901 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100902 break;
903 case IEEE80211_AMPDU_TX_OPERATIONAL:
904 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
905 break;
906 default:
907 WARN_ON_ONCE(1);
908 ret = -EINVAL;
909 break;
910 }
Emmanuel Grumbach42032632015-04-15 12:43:46 +0300911
912 if (!ret) {
913 u16 rx_ba_ssn = 0;
914
915 if (action == IEEE80211_AMPDU_RX_START)
916 rx_ba_ssn = *ssn;
917
918 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
919 rx_ba_ssn, action);
920 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100921 mutex_unlock(&mvm->mutex);
922
Arik Nemtsovb2492502014-03-13 12:21:50 +0200923 /*
924 * If the tid is marked as started, we won't use it for offloaded
925 * traffic on the next D0i3 entry. It's safe to unref.
926 */
927 if (tx_agg_ref)
928 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
929
Johannes Berg8ca151b2013-01-24 14:25:36 +0100930 return ret;
931}
932
933static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
934 struct ieee80211_vif *vif)
935{
936 struct iwl_mvm *mvm = data;
937 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
938
939 mvmvif->uploaded = false;
940 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
941
Johannes Berg8ca151b2013-01-24 14:25:36 +0100942 spin_lock_bh(&mvm->time_event_lock);
943 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
944 spin_unlock_bh(&mvm->time_event_lock);
945
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200946 mvmvif->phy_ctxt = NULL;
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +0300947 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100948}
949
950static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
951{
Johannes Berg58629d92014-11-06 09:40:50 +0100952 /* clear the D3 reconfig, we only need it to avoid dumping a
953 * firmware coredump on reconfiguration, we shouldn't do that
954 * on D3->D0 transition
955 */
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +0200956 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
957 mvm->fw_dump_desc = &iwl_mvm_dump_desc_assert;
Johannes Berg58629d92014-11-06 09:40:50 +0100958 iwl_mvm_fw_error_dump(mvm);
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +0200959 }
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +0200960
Eliad Peller744cb692014-12-10 18:44:13 +0200961 /* cleanup all stale references (scan, roc), but keep the
962 * ucode_down ref until reconfig is complete
963 */
964 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
965
Johannes Berg8ca151b2013-01-24 14:25:36 +0100966 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100967
Luciano Coelho9af91f42015-02-10 10:42:26 +0200968 mvm->scan_status = 0;
Luciano Coelhob1873302014-08-08 17:12:07 +0300969 mvm->ps_disabled = false;
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200970 mvm->calibrating = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100971
972 /* just in case one was running */
Eliad Peller305d2362015-12-09 16:33:20 +0200973 iwl_mvm_cleanup_roc_te(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100974 ieee80211_remain_on_channel_expired(mvm->hw);
975
Arik Nemtsov737719f2015-02-23 14:42:41 +0200976 /*
977 * cleanup all interfaces, even inactive ones, as some might have
978 * gone down during the HW restart
979 */
980 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100981
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200982 mvm->p2p_device_vif = NULL;
Eliad Peller37577fe2013-12-05 17:19:39 +0200983 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200984
985 iwl_mvm_reset_phy_ctxts(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100986 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300987 memset(mvm->tfd_drained, 0, sizeof(mvm->tfd_drained));
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +0300988 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
989 memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
990 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
991 memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
992 memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk));
993 memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100994
995 ieee80211_wake_queues(mvm->hw);
996
Eliad Peller228670b2014-08-10 17:00:15 +0300997 /* clear any stale d0i3 state */
998 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
999
Johannes Berg8ca151b2013-01-24 14:25:36 +01001000 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03001001 mvm->rx_ba_sessions = 0;
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001002 mvm->fw_dbg_conf = FW_DBG_INVALID;
Avraham Stern355346b2015-11-26 11:22:33 +02001003 mvm->scan_type = IWL_SCAN_TYPE_NOT_SET;
Johannes Berg91a8bcd2015-01-14 18:12:41 +01001004
1005 /* keep statistics ticking */
1006 iwl_mvm_accu_radio_stats(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001007}
1008
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001009int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001010{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001011 int ret;
1012
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001013 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001014
Luca Coelhoa42b2af32015-11-25 22:15:32 +02001015 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1016 /* Clean up some internal and mac80211 state on restart */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001017 iwl_mvm_restart_cleanup(mvm);
Luca Coelhoa42b2af32015-11-25 22:15:32 +02001018 } else {
1019 /* Hold the reference to prevent runtime suspend while
1020 * the start procedure runs. It's a bit confusing
1021 * that the UCODE_DOWN reference is taken, but it just
1022 * means "UCODE is not UP yet". ( TODO: rename this
1023 * reference).
1024 */
1025 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1026 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001027 ret = iwl_mvm_up(mvm);
Johannes Bergc47af222014-04-30 16:34:45 +02001028
1029 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1030 /* Something went wrong - we need to finish some cleanup
1031 * that normally iwl_mvm_mac_restart_complete() below
1032 * would do.
1033 */
1034 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1035 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1036 }
1037
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001038 return ret;
1039}
1040
1041static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1042{
1043 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1044 int ret;
1045
Eliad Peller37948fc2014-12-11 10:48:18 +02001046 /* Some hw restart cleanups must not hold the mutex */
1047 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1048 /*
1049 * Make sure we are out of d0i3. This is needed
1050 * to make sure the reference accounting is correct
1051 * (and there is no stale d0i3_exit_work).
1052 */
1053 wait_event_timeout(mvm->d0i3_exit_waitq,
1054 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1055 &mvm->status),
1056 HZ);
1057 }
1058
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001059 mutex_lock(&mvm->mutex);
1060 ret = __iwl_mvm_mac_start(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001061 mutex_unlock(&mvm->mutex);
1062
1063 return ret;
1064}
1065
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001066static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001067{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001068 int ret;
1069
1070 mutex_lock(&mvm->mutex);
1071
1072 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
Arik Nemtsovb2492502014-03-13 12:21:50 +02001073 iwl_mvm_d0i3_enable_tx(mvm, NULL);
Johannes Berge7afe892015-04-21 09:21:46 +02001074 ret = iwl_mvm_update_quotas(mvm, true, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001075 if (ret)
1076 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1077 ret);
1078
Eliad Peller7498cf42014-01-16 17:10:44 +02001079 /* allow transport/FW low power modes */
1080 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1081
Arik Nemtsovcbd2ae22014-09-14 19:13:54 +03001082 /*
1083 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1084 * of packets the FW sent out, so we must reconnect.
1085 */
1086 iwl_mvm_teardown_tdls_peers(mvm);
1087
Johannes Berg8ca151b2013-01-24 14:25:36 +01001088 mutex_unlock(&mvm->mutex);
1089}
1090
Eliad Peller088070a2014-10-20 18:42:58 +03001091static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1092{
Luca Coelhob7282642015-09-17 23:44:14 +03001093 if (iwl_mvm_is_d0i3_supported(mvm) &&
1094 iwl_mvm_enter_d0i3_on_suspend(mvm))
1095 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1096 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1097 &mvm->status),
1098 HZ),
1099 "D0i3 exit on resume timed out\n");
Eliad Peller088070a2014-10-20 18:42:58 +03001100}
1101
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001102static void
1103iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1104 enum ieee80211_reconfig_type reconfig_type)
1105{
1106 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1107
1108 switch (reconfig_type) {
1109 case IEEE80211_RECONFIG_TYPE_RESTART:
1110 iwl_mvm_restart_complete(mvm);
1111 break;
1112 case IEEE80211_RECONFIG_TYPE_SUSPEND:
Eliad Peller088070a2014-10-20 18:42:58 +03001113 iwl_mvm_resume_complete(mvm);
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001114 break;
1115 }
1116}
1117
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001118void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001119{
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001120 lockdep_assert_held(&mvm->mutex);
Eliad Peller7498cf42014-01-16 17:10:44 +02001121
Johannes Berg91a8bcd2015-01-14 18:12:41 +01001122 /* firmware counters are obviously reset now, but we shouldn't
1123 * partially track so also clear the fw_reset_accu counters.
1124 */
1125 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1126
Johannes Berg8ca151b2013-01-24 14:25:36 +01001127 /* async_handlers_wk is now blocked */
1128
1129 /*
1130 * The work item could be running or queued if the
1131 * ROC time event stops just as we get here.
1132 */
Eliad Pellerc7792732015-04-19 11:41:04 +03001133 flush_work(&mvm->roc_done_wk);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001134
1135 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001136
1137 iwl_mvm_async_handlers_purge(mvm);
1138 /* async_handlers_list is empty and will stay empty: HW is stopped */
1139
1140 /* the fw is stopped, the aux sta is dead: clean up driver state */
Johannes Berg712b24a2014-08-04 14:14:14 +02001141 iwl_mvm_del_aux_sta(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001142
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001143 /*
1144 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1145 * won't be called in this case).
Arik Nemtsov8b2b9fb2015-03-04 13:16:03 +02001146 * But make sure to cleanup interfaces that have gone down before/during
1147 * HW restart was requested.
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001148 */
Arik Nemtsov8b2b9fb2015-03-04 13:16:03 +02001149 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1150 ieee80211_iterate_interfaces(mvm->hw, 0,
1151 iwl_mvm_cleanup_iterator, mvm);
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001152
Alexander Bondar963221b2015-03-26 11:07:35 +02001153 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1154 * make sure there's nothing left there and warn if any is found.
1155 */
Johannes Berg859d9142015-06-01 17:11:11 +02001156 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
Alexander Bondar963221b2015-03-26 11:07:35 +02001157 int i;
1158
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001159 for (i = 0; i < mvm->max_scans; i++) {
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001160 if (WARN_ONCE(mvm->scan_uid_status[i],
1161 "UMAC scan UID %d status was not cleaned\n",
1162 i))
1163 mvm->scan_uid_status[i] = 0;
Alexander Bondar963221b2015-03-26 11:07:35 +02001164 }
1165 }
1166
Luciano Coelhobc448862014-08-20 11:49:11 +03001167 mvm->ucode_loaded = false;
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001168}
Luciano Coelhobc448862014-08-20 11:49:11 +03001169
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001170static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1171{
1172 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1173
1174 flush_work(&mvm->d0i3_exit_work);
1175 flush_work(&mvm->async_handlers_wk);
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001176 cancel_delayed_work_sync(&mvm->fw_dump_wk);
Emmanuel Grumbachb6eaa452015-01-29 14:58:20 +02001177 iwl_mvm_free_fw_dump_desc(mvm);
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001178
1179 mutex_lock(&mvm->mutex);
1180 __iwl_mvm_mac_stop(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001181 mutex_unlock(&mvm->mutex);
1182
1183 /*
1184 * The worker might have been waiting for the mutex, let it run and
1185 * discover that its list is now empty.
1186 */
1187 cancel_work_sync(&mvm->async_handlers_wk);
1188}
1189
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001190static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1191{
1192 u16 i;
1193
1194 lockdep_assert_held(&mvm->mutex);
1195
1196 for (i = 0; i < NUM_PHY_CTX; i++)
1197 if (!mvm->phy_ctxts[i].ref)
1198 return &mvm->phy_ctxts[i];
1199
1200 IWL_ERR(mvm, "No available PHY context\n");
1201 return NULL;
1202}
1203
Avri Altmand44c3fe2015-04-18 22:16:42 +03001204static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1205 s16 tx_power)
1206{
1207 struct iwl_dev_tx_power_cmd cmd = {
Johannes Bergda03f022015-08-18 15:15:36 +02001208 .v2.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1209 .v2.mac_context_id =
Avri Altmand44c3fe2015-04-18 22:16:42 +03001210 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
Johannes Bergda03f022015-08-18 15:15:36 +02001211 .v2.pwr_restriction = cpu_to_le16(8 * tx_power),
Avri Altmand44c3fe2015-04-18 22:16:42 +03001212 };
Johannes Bergda03f022015-08-18 15:15:36 +02001213 int len = sizeof(cmd);
Avri Altmand44c3fe2015-04-18 22:16:42 +03001214
Avri Altmand44c3fe2015-04-18 22:16:42 +03001215 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
Johannes Bergda03f022015-08-18 15:15:36 +02001216 cmd.v2.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
Avri Altmand44c3fe2015-04-18 22:16:42 +03001217
Johannes Bergda03f022015-08-18 15:15:36 +02001218 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_TX_POWER_CHAIN))
1219 len = sizeof(cmd.v2);
1220
1221 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
Avri Altmand44c3fe2015-04-18 22:16:42 +03001222}
1223
Johannes Berg8ca151b2013-01-24 14:25:36 +01001224static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1225 struct ieee80211_vif *vif)
1226{
1227 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1228 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1229 int ret;
1230
Emmanuel Grumbachaa5e1832015-03-07 19:35:37 +02001231 mvmvif->mvm = mvm;
1232
Johannes Berg8ca151b2013-01-24 14:25:36 +01001233 /*
Gregory Greenmand40fc482014-06-25 14:08:50 +02001234 * make sure D0i3 exit is completed, otherwise a target access
1235 * during tx queue configuration could be done when still in
1236 * D0i3 state.
1237 */
1238 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1239 if (ret)
1240 return ret;
1241
1242 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001243 * Not much to do here. The stack will not allow interface
1244 * types or combinations that we didn't advertise, so we
1245 * don't really have to check the types.
1246 */
1247
1248 mutex_lock(&mvm->mutex);
1249
Johannes Berg33cef922015-01-21 21:41:29 +01001250 /* make sure that beacon statistics don't go backwards with FW reset */
1251 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1252 mvmvif->beacon_stats.accu_num_beacons +=
1253 mvmvif->beacon_stats.num_beacons;
1254
Eliad Pellere89044d2013-07-16 17:33:26 +03001255 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001256 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1257 if (ret)
1258 goto out_unlock;
1259
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001260 /* Counting number of interfaces is needed for legacy PM */
Ilan Peerea183d02013-07-23 14:41:53 +03001261 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1262 mvm->vif_count++;
Ilan Peerea183d02013-07-23 14:41:53 +03001263
1264 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001265 * The AP binding flow can be done only after the beacon
1266 * template is configured (which happens only in the mac80211
1267 * start_ap() flow), and adding the broadcast station can happen
1268 * only after the binding.
1269 * In addition, since modifying the MAC before adding a bcast
1270 * station is not allowed by the FW, delay the adding of MAC context to
1271 * the point where we can also add the bcast station.
1272 * In short: there's not much we can do at this point, other than
1273 * allocating resources :)
1274 */
Johannes Berg5023d962013-07-31 14:07:43 +02001275 if (vif->type == NL80211_IFTYPE_AP ||
1276 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg013290a2014-08-04 13:38:48 +02001277 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001278 if (ret) {
1279 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1280 goto out_release;
1281 }
1282
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +03001283 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001284 goto out_unlock;
1285 }
1286
Avri Altman93190fb2014-12-27 09:09:47 +02001287 mvmvif->features |= hw->netdev_features;
1288
Johannes Berg8ca151b2013-01-24 14:25:36 +01001289 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1290 if (ret)
1291 goto out_release;
1292
Arik Nemtsov999609f2014-05-15 17:31:51 +03001293 ret = iwl_mvm_power_update_mac(mvm);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001294 if (ret)
Luciano Coelhofd66fc12015-01-27 15:06:57 +02001295 goto out_remove_mac;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001296
Hila Gonen7df15b12012-12-12 11:16:19 +02001297 /* beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001298 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001299 if (ret)
1300 goto out_remove_mac;
1301
Hila Gonen7df15b12012-12-12 11:16:19 +02001302 if (!mvm->bf_allowed_vif &&
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +03001303 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001304 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001305 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1306 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +02001307 }
1308
Johannes Berg8ca151b2013-01-24 14:25:36 +01001309 /*
1310 * P2P_DEVICE interface does not have a channel context assigned to it,
1311 * so a dedicated PHY context is allocated to it and the corresponding
1312 * MAC context is bound to it at this stage.
1313 */
1314 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001315
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001316 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1317 if (!mvmvif->phy_ctxt) {
1318 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001319 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001320 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001321
Ilan Peer53a9d612013-04-28 11:55:08 +03001322 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001323 ret = iwl_mvm_binding_add_vif(mvm, vif);
1324 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +03001325 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001326
Johannes Berg013290a2014-08-04 13:38:48 +02001327 ret = iwl_mvm_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001328 if (ret)
1329 goto out_unbind;
1330
1331 /* Save a pointer to p2p device vif, so it can later be used to
1332 * update the p2p device MAC when a GO is started/stopped */
1333 mvm->p2p_device_vif = vif;
1334 }
1335
Johannes Berg63494372013-03-26 10:47:53 +01001336 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001337 goto out_unlock;
1338
1339 out_unbind:
1340 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +03001341 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001342 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001343 out_free_bf:
1344 if (mvm->bf_allowed_vif == mvmvif) {
1345 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001346 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1347 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001348 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001349 out_remove_mac:
1350 mvmvif->phy_ctxt = NULL;
1351 iwl_mvm_mac_ctxt_remove(mvm, vif);
1352 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001353 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1354 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001355
Johannes Berg8ca151b2013-01-24 14:25:36 +01001356 iwl_mvm_mac_ctxt_release(mvm, vif);
1357 out_unlock:
1358 mutex_unlock(&mvm->mutex);
1359
Gregory Greenmand40fc482014-06-25 14:08:50 +02001360 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1361
Johannes Berg8ca151b2013-01-24 14:25:36 +01001362 return ret;
1363}
1364
Johannes Berg38a12b52013-02-22 14:07:56 +01001365static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1366 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001367{
Arik Nemtsovd92b732e2014-09-21 19:00:42 +03001368 u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001369
1370 if (tfd_msk) {
Emmanuel Grumbachfe92e322015-03-11 09:34:31 +02001371 /*
1372 * mac80211 first removes all the stations of the vif and
1373 * then removes the vif. When it removes a station it also
1374 * flushes the AMPDU session. So by now, all the AMPDU sessions
1375 * of all the stations of this vif are closed, and the queues
1376 * of these AMPDU sessions are properly closed.
1377 * We still need to take care of the shared queues of the vif.
1378 * Flush them here.
1379 */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001380 mutex_lock(&mvm->mutex);
Luca Coelho5888a402015-10-06 09:54:57 +03001381 iwl_mvm_flush_tx_path(mvm, tfd_msk, 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001382 mutex_unlock(&mvm->mutex);
Emmanuel Grumbachfe92e322015-03-11 09:34:31 +02001383
1384 /*
1385 * There are transports that buffer a few frames in the host.
1386 * For these, the flush above isn't enough since while we were
1387 * flushing, the transport might have sent more frames to the
1388 * device. To solve this, wait here until the transport is
1389 * empty. Technically, this could have replaced the flush
1390 * above, but flush is much faster than draining. So flush
1391 * first, and drain to make sure we have no frames in the
1392 * transport anymore.
1393 * If a station still had frames on the shared queues, it is
1394 * already marked as draining, so to complete the draining, we
1395 * just need to wait until the transport is empty.
1396 */
1397 iwl_trans_wait_tx_queue_empty(mvm->trans, tfd_msk);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001398 }
1399
1400 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1401 /*
1402 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1403 * We assume here that all the packets sent to the OFFCHANNEL
1404 * queue are sent in ROC session.
1405 */
1406 flush_work(&mvm->roc_done_wk);
1407 } else {
1408 /*
1409 * By now, all the AC queues are empty. The AGG queues are
1410 * empty too. We already got all the Tx responses for all the
1411 * packets in the queues. The drain work can have been
Emmanuel Grumbach0742a752013-06-10 14:10:33 +03001412 * triggered. Flush it.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001413 */
1414 flush_work(&mvm->sta_drained_wk);
1415 }
Johannes Berg38a12b52013-02-22 14:07:56 +01001416}
1417
1418static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1419 struct ieee80211_vif *vif)
1420{
1421 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1422 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1423
1424 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001425
1426 mutex_lock(&mvm->mutex);
1427
Hila Gonen7df15b12012-12-12 11:16:19 +02001428 if (mvm->bf_allowed_vif == mvmvif) {
1429 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001430 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1431 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +02001432 }
1433
Johannes Berg63494372013-03-26 10:47:53 +01001434 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1435
Johannes Berg8ca151b2013-01-24 14:25:36 +01001436 /*
1437 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +01001438 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001439 */
Johannes Berg5023d962013-07-31 14:07:43 +02001440 if (vif->type == NL80211_IFTYPE_AP ||
1441 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +03001442#ifdef CONFIG_NL80211_TESTMODE
1443 if (vif == mvm->noa_vif) {
1444 mvm->noa_vif = NULL;
1445 mvm->noa_duration = 0;
1446 }
1447#endif
Johannes Berg013290a2014-08-04 13:38:48 +02001448 iwl_mvm_dealloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001449 goto out_release;
1450 }
1451
1452 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1453 mvm->p2p_device_vif = NULL;
Johannes Berg013290a2014-08-04 13:38:48 +02001454 iwl_mvm_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001455 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001456 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001457 mvmvif->phy_ctxt = NULL;
1458 }
1459
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001460 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001461 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001462
Arik Nemtsov999609f2014-05-15 17:31:51 +03001463 iwl_mvm_power_update_mac(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001464 iwl_mvm_mac_ctxt_remove(mvm, vif);
1465
1466out_release:
1467 iwl_mvm_mac_ctxt_release(mvm, vif);
1468 mutex_unlock(&mvm->mutex);
1469}
1470
1471static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1472{
1473 return 0;
1474}
1475
Eliad Pellere59647e2013-11-28 14:08:50 +02001476struct iwl_mvm_mc_iter_data {
1477 struct iwl_mvm *mvm;
1478 int port_id;
1479};
1480
1481static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1482 struct ieee80211_vif *vif)
1483{
1484 struct iwl_mvm_mc_iter_data *data = _data;
1485 struct iwl_mvm *mvm = data->mvm;
1486 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1487 int ret, len;
1488
1489 /* if we don't have free ports, mcast frames will be dropped */
1490 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1491 return;
1492
1493 if (vif->type != NL80211_IFTYPE_STATION ||
1494 !vif->bss_conf.assoc)
1495 return;
1496
1497 cmd->port_id = data->port_id++;
1498 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1499 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1500
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001501 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
Eliad Pellere59647e2013-11-28 14:08:50 +02001502 if (ret)
1503 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1504}
1505
1506static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1507{
1508 struct iwl_mvm_mc_iter_data iter_data = {
1509 .mvm = mvm,
1510 };
1511
1512 lockdep_assert_held(&mvm->mutex);
1513
1514 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1515 return;
1516
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001517 ieee80211_iterate_active_interfaces_atomic(
Eliad Pellere59647e2013-11-28 14:08:50 +02001518 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1519 iwl_mvm_mc_iface_iterator, &iter_data);
1520}
1521
1522static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1523 struct netdev_hw_addr_list *mc_list)
1524{
1525 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1526 struct iwl_mcast_filter_cmd *cmd;
1527 struct netdev_hw_addr *addr;
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001528 int addr_count;
1529 bool pass_all;
Eliad Pellere59647e2013-11-28 14:08:50 +02001530 int len;
1531
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001532 addr_count = netdev_hw_addr_list_count(mc_list);
1533 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1534 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1535 if (pass_all)
Eliad Pellere59647e2013-11-28 14:08:50 +02001536 addr_count = 0;
Eliad Pellere59647e2013-11-28 14:08:50 +02001537
1538 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1539 cmd = kzalloc(len, GFP_ATOMIC);
1540 if (!cmd)
1541 return 0;
1542
1543 if (pass_all) {
1544 cmd->pass_all = 1;
1545 return (u64)(unsigned long)cmd;
1546 }
1547
1548 netdev_hw_addr_list_for_each(addr, mc_list) {
1549 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1550 cmd->count, addr->addr);
1551 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1552 addr->addr, ETH_ALEN);
1553 cmd->count++;
1554 }
1555
1556 return (u64)(unsigned long)cmd;
1557}
1558
Johannes Berg8ca151b2013-01-24 14:25:36 +01001559static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1560 unsigned int changed_flags,
1561 unsigned int *total_flags,
1562 u64 multicast)
1563{
Eliad Pellere59647e2013-11-28 14:08:50 +02001564 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1565 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1566
1567 mutex_lock(&mvm->mutex);
1568
1569 /* replace previous configuration */
1570 kfree(mvm->mcast_filter_cmd);
1571 mvm->mcast_filter_cmd = cmd;
1572
1573 if (!cmd)
1574 goto out;
1575
1576 iwl_mvm_recalc_multicast(mvm);
1577out:
1578 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001579 *total_flags = 0;
1580}
1581
Andrei Otcheretianskieffd1922015-06-30 12:08:28 +03001582static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1583 struct ieee80211_vif *vif,
1584 unsigned int filter_flags,
1585 unsigned int changed_flags)
1586{
1587 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1588
1589 /* We support only filter for probe requests */
1590 if (!(changed_flags & FIF_PROBE_REQ))
1591 return;
1592
1593 /* Supported only for p2p client interfaces */
1594 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1595 !vif->p2p)
1596 return;
1597
1598 mutex_lock(&mvm->mutex);
1599 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1600 mutex_unlock(&mvm->mutex);
1601}
1602
Eliad Pellerc87163b2014-01-08 10:11:11 +02001603#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1604struct iwl_bcast_iter_data {
1605 struct iwl_mvm *mvm;
1606 struct iwl_bcast_filter_cmd *cmd;
1607 u8 current_filter;
1608};
1609
1610static void
1611iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1612 const struct iwl_fw_bcast_filter *in_filter,
1613 struct iwl_fw_bcast_filter *out_filter)
1614{
1615 struct iwl_fw_bcast_filter_attr *attr;
1616 int i;
1617
1618 memcpy(out_filter, in_filter, sizeof(*out_filter));
1619
1620 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1621 attr = &out_filter->attrs[i];
1622
1623 if (!attr->mask)
1624 break;
1625
Eliad Peller2ee8f022014-01-13 19:07:09 +02001626 switch (attr->reserved1) {
1627 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1628 if (vif->bss_conf.arp_addr_cnt != 1) {
1629 attr->mask = 0;
1630 continue;
1631 }
1632
1633 attr->val = vif->bss_conf.arp_addr_list[0];
1634 break;
1635 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1636 attr->val = *(__be32 *)&vif->addr[2];
1637 break;
1638 default:
1639 break;
1640 }
1641 attr->reserved1 = 0;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001642 out_filter->num_attrs++;
1643 }
1644}
1645
1646static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1647 struct ieee80211_vif *vif)
1648{
1649 struct iwl_bcast_iter_data *data = _data;
1650 struct iwl_mvm *mvm = data->mvm;
1651 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1652 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1653 struct iwl_fw_bcast_mac *bcast_mac;
1654 int i;
1655
1656 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1657 return;
1658
1659 bcast_mac = &cmd->macs[mvmvif->id];
1660
Ilan Peere48393e2014-05-22 11:19:02 +03001661 /*
1662 * enable filtering only for associated stations, but not for P2P
1663 * Clients
1664 */
1665 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1666 !vif->bss_conf.assoc)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001667 return;
1668
1669 bcast_mac->default_discard = 1;
1670
1671 /* copy all configured filters */
1672 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1673 /*
1674 * Make sure we don't exceed our filters limit.
1675 * if there is still a valid filter to be configured,
1676 * be on the safe side and just allow bcast for this mac.
1677 */
1678 if (WARN_ON_ONCE(data->current_filter >=
1679 ARRAY_SIZE(cmd->filters))) {
1680 bcast_mac->default_discard = 0;
1681 bcast_mac->attached_filters = 0;
1682 break;
1683 }
1684
1685 iwl_mvm_set_bcast_filter(vif,
1686 &mvm->bcast_filters[i],
1687 &cmd->filters[data->current_filter]);
1688
1689 /* skip current filter if it contains no attributes */
1690 if (!cmd->filters[data->current_filter].num_attrs)
1691 continue;
1692
1693 /* attach the filter to current mac */
1694 bcast_mac->attached_filters |=
1695 cpu_to_le16(BIT(data->current_filter));
1696
1697 data->current_filter++;
1698 }
1699}
1700
Eliad Pellerde06a592014-01-08 10:11:12 +02001701bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1702 struct iwl_bcast_filter_cmd *cmd)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001703{
Eliad Pellerc87163b2014-01-08 10:11:11 +02001704 struct iwl_bcast_iter_data iter_data = {
1705 .mvm = mvm,
Eliad Pellerde06a592014-01-08 10:11:12 +02001706 .cmd = cmd,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001707 };
1708
Max Stepanov3b8983b2014-10-15 11:27:16 +03001709 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1710 return false;
1711
Eliad Pellerde06a592014-01-08 10:11:12 +02001712 memset(cmd, 0, sizeof(*cmd));
1713 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1714 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1715
1716#ifdef CONFIG_IWLWIFI_DEBUGFS
1717 /* use debugfs filters/macs if override is configured */
1718 if (mvm->dbgfs_bcast_filtering.override) {
1719 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1720 sizeof(cmd->filters));
1721 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1722 sizeof(cmd->macs));
1723 return true;
1724 }
1725#endif
Eliad Pellerc87163b2014-01-08 10:11:11 +02001726
1727 /* if no filters are configured, do nothing */
1728 if (!mvm->bcast_filters)
Eliad Pellerde06a592014-01-08 10:11:12 +02001729 return false;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001730
1731 /* configure and attach these filters for each associated sta vif */
1732 ieee80211_iterate_active_interfaces(
1733 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1734 iwl_mvm_bcast_filter_iterator, &iter_data);
1735
Eliad Pellerde06a592014-01-08 10:11:12 +02001736 return true;
1737}
Eliad Peller34672bb2015-12-03 16:10:07 +02001738
1739static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
Eliad Pellerde06a592014-01-08 10:11:12 +02001740{
1741 struct iwl_bcast_filter_cmd cmd;
1742
1743 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1744 return 0;
1745
1746 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1747 return 0;
1748
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001749 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001750 sizeof(cmd), &cmd);
1751}
1752#else
Eliad Peller34672bb2015-12-03 16:10:07 +02001753static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001754{
1755 return 0;
1756}
1757#endif
1758
Johannes Berg8ca151b2013-01-24 14:25:36 +01001759static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1760 struct ieee80211_vif *vif,
1761 struct ieee80211_bss_conf *bss_conf,
1762 u32 changes)
1763{
1764 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1765 int ret;
1766
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001767 /*
1768 * Re-calculate the tsf id, as the master-slave relations depend on the
1769 * beacon interval, which was not known when the station interface was
1770 * added.
1771 */
1772 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1773 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1774
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001775 /*
1776 * If we're not associated yet, take the (new) BSSID before associating
1777 * so the firmware knows. If we're already associated, then use the old
1778 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1779 * branch for disassociation below.
1780 */
1781 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1782 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1783
1784 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001785 if (ret)
1786 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1787
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001788 /* after sending it once, adopt mac80211 data */
1789 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1790 mvmvif->associated = bss_conf->assoc;
1791
Johannes Berg8ca151b2013-01-24 14:25:36 +01001792 if (changes & BSS_CHANGED_ASSOC) {
1793 if (bss_conf->assoc) {
Johannes Berg33cef922015-01-21 21:41:29 +01001794 /* clear statistics to get clean beacon counter */
1795 iwl_mvm_request_statistics(mvm, true);
1796 memset(&mvmvif->beacon_stats, 0,
1797 sizeof(mvmvif->beacon_stats));
1798
Johannes Berg8ca151b2013-01-24 14:25:36 +01001799 /* add quota for this interface */
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02001800 ret = iwl_mvm_update_quotas(mvm, true, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001801 if (ret) {
1802 IWL_ERR(mvm, "failed to update quotas\n");
1803 return;
1804 }
Johannes Berg016d27e2013-05-03 11:16:15 +02001805
1806 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1807 &mvm->status)) {
1808 /*
1809 * If we're restarting then the firmware will
1810 * obviously have lost synchronisation with
1811 * the AP. It will attempt to synchronise by
1812 * itself, but we can make it more reliable by
1813 * scheduling a session protection time event.
1814 *
1815 * The firmware needs to receive a beacon to
1816 * catch up with synchronisation, use 110% of
1817 * the beacon interval.
1818 *
1819 * Set a large maximum delay to allow for more
1820 * than a single interface.
1821 */
1822 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1823 iwl_mvm_protect_session(mvm, vif, dur, dur,
Liad Kaufmand20d37b2014-07-06 17:14:39 +03001824 5 * dur, false);
Johannes Berg016d27e2013-05-03 11:16:15 +02001825 }
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001826
1827 iwl_mvm_sf_update(mvm, vif, false);
Alexander Bondar175a70b2013-04-14 20:59:37 +03001828 iwl_mvm_power_vif_assoc(mvm, vif);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001829 if (vif->p2p) {
Eliad Peller29a90a42013-11-05 14:06:29 +02001830 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001831 iwl_mvm_update_smps(mvm, vif,
1832 IWL_MVM_SMPS_REQ_PROT,
1833 IEEE80211_SMPS_DYNAMIC);
1834 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001835 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001836 /*
1837 * If update fails - SF might be running in associated
1838 * mode while disassociated - which is forbidden.
1839 */
1840 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1841 "Failed to update SF upon disassociation\n");
1842
Johannes Berg8ca151b2013-01-24 14:25:36 +01001843 /* remove AP station now that the MAC is unassoc */
1844 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1845 if (ret)
1846 IWL_ERR(mvm, "failed to remove AP station\n");
Eliad Peller37577fe2013-12-05 17:19:39 +02001847
1848 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1849 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001850 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1851 /* remove quota for this interface */
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02001852 ret = iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001853 if (ret)
1854 IWL_ERR(mvm, "failed to update quotas\n");
Eliad Peller29a90a42013-11-05 14:06:29 +02001855
1856 if (vif->p2p)
1857 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001858
1859 /* this will take the cleared BSSID from bss_conf */
1860 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1861 if (ret)
1862 IWL_ERR(mvm,
1863 "failed to update MAC %pM (clear after unassoc)\n",
1864 vif->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001865 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001866
Eliad Pellere59647e2013-11-28 14:08:50 +02001867 iwl_mvm_recalc_multicast(mvm);
Eliad Peller34672bb2015-12-03 16:10:07 +02001868 iwl_mvm_configure_bcast_filter(mvm);
Eliad Pellere59647e2013-11-28 14:08:50 +02001869
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001870 /* reset rssi values */
1871 mvmvif->bf_data.ave_beacon_signal = 0;
1872
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001873 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachf94045e2014-01-06 13:38:55 +02001874 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1875 IEEE80211_SMPS_AUTOMATIC);
Avraham Stern355346b2015-11-26 11:22:33 +02001876 if (fw_has_capa(&mvm->fw->ucode_capa,
1877 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
1878 iwl_mvm_config_scan(mvm);
Alexander Bondar989c6502013-05-16 17:34:17 +03001879 } else if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +01001880 /*
1881 * We received a beacon _after_ association so
1882 * remove the session protection.
1883 */
1884 iwl_mvm_remove_time_event(mvm, mvmvif,
1885 &mvmvif->time_event_data);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001886 }
Eran Hararycc87d322014-07-15 14:04:23 +03001887
1888 if (changes & BSS_CHANGED_BEACON_INFO) {
1889 iwl_mvm_sf_update(mvm, vif, false);
1890 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
1891 }
1892
Johannes Berg1bc10d32014-08-26 14:25:46 +02001893 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS)) {
1894 ret = iwl_mvm_power_update_mac(mvm);
1895 if (ret)
1896 IWL_ERR(mvm, "failed to update power mode\n");
1897 }
1898
Matti Gottlieb88f2fd72013-07-09 15:25:46 +03001899 if (changes & BSS_CHANGED_TXPOWER) {
1900 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1901 bss_conf->txpower);
1902 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1903 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001904
1905 if (changes & BSS_CHANGED_CQM) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02001906 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001907 /* reset cqm events tracking */
1908 mvmvif->bf_data.last_cqm_event = 0;
Avri Altmanfa7b2e72014-05-20 08:03:24 +03001909 if (mvmvif->bf_data.bf_enabled) {
1910 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1911 if (ret)
1912 IWL_ERR(mvm,
1913 "failed to update CQM thresholds\n");
1914 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001915 }
Eliad Peller2ee8f022014-01-13 19:07:09 +02001916
1917 if (changes & BSS_CHANGED_ARP_FILTER) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02001918 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
Eliad Peller34672bb2015-12-03 16:10:07 +02001919 iwl_mvm_configure_bcast_filter(mvm);
Eliad Peller2ee8f022014-01-13 19:07:09 +02001920 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001921}
1922
Johannes Berg5023d962013-07-31 14:07:43 +02001923static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1924 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001925{
1926 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1927 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1928 int ret;
1929
Eliad Peller576eeee2014-07-01 18:38:38 +03001930 /*
1931 * iwl_mvm_mac_ctxt_add() might read directly from the device
1932 * (the system time), so make sure it is available.
1933 */
1934 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
1935 if (ret)
1936 return ret;
1937
Johannes Berg8ca151b2013-01-24 14:25:36 +01001938 mutex_lock(&mvm->mutex);
1939
1940 /* Send the beacon template */
1941 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1942 if (ret)
1943 goto out_unlock;
1944
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001945 /*
1946 * Re-calculate the tsf id, as the master-slave relations depend on the
1947 * beacon interval, which was not known when the AP interface was added.
1948 */
1949 if (vif->type == NL80211_IFTYPE_AP)
1950 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1951
Gregory Greenman94939082015-08-24 14:38:35 +03001952 mvmvif->ap_assoc_sta_count = 0;
1953
Johannes Berg8ca151b2013-01-24 14:25:36 +01001954 /* Add the mac context */
1955 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1956 if (ret)
1957 goto out_unlock;
1958
1959 /* Perform the binding */
1960 ret = iwl_mvm_binding_add_vif(mvm, vif);
1961 if (ret)
1962 goto out_remove;
1963
Johannes Berg8ca151b2013-01-24 14:25:36 +01001964 /* Send the bcast station. At this stage the TBTT and DTIM time events
1965 * are added and applied to the scheduler */
Johannes Berg013290a2014-08-04 13:38:48 +02001966 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001967 if (ret)
1968 goto out_unbind;
1969
Ilan Peer5691e212013-12-31 21:05:50 +02001970 /* must be set before quota calculations */
1971 mvmvif->ap_ibss_active = true;
1972
Ilan Peera11e1442013-12-31 21:19:55 +02001973 /* power updated needs to be done before quotas */
Arik Nemtsov999609f2014-05-15 17:31:51 +03001974 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02001975
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02001976 ret = iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001977 if (ret)
Ilan Peera11e1442013-12-31 21:19:55 +02001978 goto out_quota_failed;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001979
Johannes Berg5023d962013-07-31 14:07:43 +02001980 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001981 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001982 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001983
Eliad Peller29a90a42013-11-05 14:06:29 +02001984 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1985
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001986 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001987
Arik Nemtsovf6972672014-06-15 16:03:55 +03001988 /* we don't support TDLS during DCM */
1989 if (iwl_mvm_phy_ctx_count(mvm) > 1)
1990 iwl_mvm_teardown_tdls_peers(mvm);
1991
Arik Nemtsov939e4902015-03-08 12:19:42 +02001992 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001993
Ilan Peera11e1442013-12-31 21:19:55 +02001994out_quota_failed:
Arik Nemtsov999609f2014-05-15 17:31:51 +03001995 iwl_mvm_power_update_mac(mvm);
Ilan Peer5691e212013-12-31 21:05:50 +02001996 mvmvif->ap_ibss_active = false;
Johannes Berg013290a2014-08-04 13:38:48 +02001997 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001998out_unbind:
1999 iwl_mvm_binding_remove_vif(mvm, vif);
2000out_remove:
2001 iwl_mvm_mac_ctxt_remove(mvm, vif);
2002out_unlock:
2003 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002004 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002005 return ret;
2006}
2007
Johannes Berg5023d962013-07-31 14:07:43 +02002008static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2009 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002010{
2011 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2012 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2013
Johannes Berg38a12b52013-02-22 14:07:56 +01002014 iwl_mvm_prepare_mac_removal(mvm, vif);
2015
Johannes Berg8ca151b2013-01-24 14:25:36 +01002016 mutex_lock(&mvm->mutex);
2017
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002018 /* Handle AP stop while in CSA */
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03002019 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2020 iwl_mvm_remove_time_event(mvm, mvmvif,
2021 &mvmvif->time_event_data);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002022 RCU_INIT_POINTER(mvm->csa_vif, NULL);
Avraham Sterne9cb0322015-08-31 11:08:27 +03002023 mvmvif->csa_countdown = false;
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03002024 }
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002025
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03002026 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2027 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2028 mvm->csa_tx_block_bcn_timeout = 0;
2029 }
2030
Johannes Berg5023d962013-07-31 14:07:43 +02002031 mvmvif->ap_ibss_active = false;
David Spinadel1c87bba2014-02-27 16:41:52 +02002032 mvm->ap_last_beacon_gp2 = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002033
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002034 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03002035
Eliad Peller29a90a42013-11-05 14:06:29 +02002036 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2037
Johannes Berg5023d962013-07-31 14:07:43 +02002038 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002039 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002040 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002041
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02002042 iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg013290a2014-08-04 13:38:48 +02002043 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002044 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02002045
Arik Nemtsov999609f2014-05-15 17:31:51 +03002046 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02002047
Johannes Berg8ca151b2013-01-24 14:25:36 +01002048 iwl_mvm_mac_ctxt_remove(mvm, vif);
2049
2050 mutex_unlock(&mvm->mutex);
2051}
2052
Johannes Berg5023d962013-07-31 14:07:43 +02002053static void
2054iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2055 struct ieee80211_vif *vif,
2056 struct ieee80211_bss_conf *bss_conf,
2057 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002058{
Ilan Peerbe2056f2013-12-04 16:47:14 +02002059 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman8a5e3662013-11-12 19:16:03 +02002060
Ilan Peerbe2056f2013-12-04 16:47:14 +02002061 /* Changes will be applied when the AP/IBSS is started */
2062 if (!mvmvif->ap_ibss_active)
2063 return;
2064
Johannes Berg863230da2013-12-04 17:08:40 +01002065 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
Johannes Bergf7d8b702014-09-09 15:49:19 +02002066 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002067 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
Johannes Berg863230da2013-12-04 17:08:40 +01002068 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
Avri Altman8a5e3662013-11-12 19:16:03 +02002069
Johannes Berg8ca151b2013-01-24 14:25:36 +01002070 /* Need to send a new beacon template to the FW */
Johannes Berg863230da2013-12-04 17:08:40 +01002071 if (changes & BSS_CHANGED_BEACON &&
2072 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2073 IWL_WARN(mvm, "Failed updating beacon data\n");
Haim Dreyfuss79b7a692014-09-14 12:40:00 +03002074
2075 if (changes & BSS_CHANGED_TXPOWER) {
2076 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2077 bss_conf->txpower);
2078 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2079 }
2080
Johannes Berg8ca151b2013-01-24 14:25:36 +01002081}
2082
2083static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2084 struct ieee80211_vif *vif,
2085 struct ieee80211_bss_conf *bss_conf,
2086 u32 changes)
2087{
2088 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2089
Eliad Peller576eeee2014-07-01 18:38:38 +03002090 /*
2091 * iwl_mvm_bss_info_changed_station() might call
2092 * iwl_mvm_protect_session(), which reads directly from
2093 * the device (the system time), so make sure it is available.
2094 */
2095 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2096 return;
2097
Johannes Berg8ca151b2013-01-24 14:25:36 +01002098 mutex_lock(&mvm->mutex);
2099
David Spinadel723f02e2014-04-27 09:54:54 +03002100 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
Luciano Coelhoc7d42482015-05-07 16:00:26 +03002101 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
David Spinadel723f02e2014-04-27 09:54:54 +03002102
Johannes Berg8ca151b2013-01-24 14:25:36 +01002103 switch (vif->type) {
2104 case NL80211_IFTYPE_STATION:
2105 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2106 break;
2107 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02002108 case NL80211_IFTYPE_ADHOC:
2109 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002110 break;
2111 default:
2112 /* shouldn't happen */
2113 WARN_ON_ONCE(1);
2114 }
2115
2116 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002117 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002118}
2119
2120static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2121 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02002122 struct ieee80211_scan_request *hw_req)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002123{
2124 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2125 int ret;
2126
Luciano Coelho6749dd82015-03-20 15:51:36 +02002127 if (hw_req->req.n_channels == 0 ||
2128 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002129 return -EINVAL;
2130
2131 mutex_lock(&mvm->mutex);
Luciano Coelho6749dd82015-03-20 15:51:36 +02002132 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002133 mutex_unlock(&mvm->mutex);
Luciano Coelho6749dd82015-03-20 15:51:36 +02002134
Johannes Berg8ca151b2013-01-24 14:25:36 +01002135 return ret;
2136}
2137
2138static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2139 struct ieee80211_vif *vif)
2140{
2141 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2142
2143 mutex_lock(&mvm->mutex);
2144
Luciano Coelhoe7d3aba2015-02-06 10:19:05 +02002145 /* Due to a race condition, it's possible that mac80211 asks
2146 * us to stop a hw_scan when it's already stopped. This can
2147 * happen, for instance, if we stopped the scan ourselves,
2148 * called ieee80211_scan_completed() and the userspace called
2149 * cancel scan scan before ieee80211_scan_work() could run.
2150 * To handle that, simply return if the scan is not running.
2151 */
Luciano Coelho262888f2015-05-07 17:21:09 +03002152 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
Luciano Coelhoc7d42482015-05-07 16:00:26 +03002153 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002154
2155 mutex_unlock(&mvm->mutex);
2156}
2157
2158static void
2159iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
Johannes Berg3e56ead2013-02-15 22:23:18 +01002160 struct ieee80211_sta *sta, u16 tids,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002161 int num_frames,
2162 enum ieee80211_frame_release_type reason,
2163 bool more_data)
2164{
2165 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002166
Johannes Berg3e56ead2013-02-15 22:23:18 +01002167 /* Called when we need to transmit (a) frame(s) from mac80211 */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002168
Johannes Berg3e56ead2013-02-15 22:23:18 +01002169 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2170 tids, more_data, false);
2171}
2172
2173static void
2174iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2175 struct ieee80211_sta *sta, u16 tids,
2176 int num_frames,
2177 enum ieee80211_frame_release_type reason,
2178 bool more_data)
2179{
2180 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2181
2182 /* Called when we need to transmit (a) frame(s) from agg queue */
2183
2184 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2185 tids, more_data, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002186}
2187
2188static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2189 struct ieee80211_vif *vif,
2190 enum sta_notify_cmd cmd,
2191 struct ieee80211_sta *sta)
2192{
2193 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01002194 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002195 unsigned long txqs = 0, tids = 0;
Johannes Berg3e56ead2013-02-15 22:23:18 +01002196 int tid;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002197
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002198 spin_lock_bh(&mvmsta->lock);
2199 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2200 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2201
2202 if (tid_data->state != IWL_AGG_ON &&
2203 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
2204 continue;
2205
2206 __set_bit(tid_data->txq_id, &txqs);
2207
2208 if (iwl_mvm_tid_queued(tid_data) == 0)
2209 continue;
2210
2211 __set_bit(tid, &tids);
2212 }
2213
Johannes Berg8ca151b2013-01-24 14:25:36 +01002214 switch (cmd) {
2215 case STA_NOTIFY_SLEEP:
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03002216 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002217 ieee80211_sta_block_awake(hw, sta, true);
Johannes Berg3e56ead2013-02-15 22:23:18 +01002218
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002219 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
Johannes Berg3e56ead2013-02-15 22:23:18 +01002220 ieee80211_sta_set_buffered(sta, tid, true);
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002221
2222 if (txqs)
2223 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002224 /*
2225 * The fw updates the STA to be asleep. Tx packets on the Tx
2226 * queues to this station will not be transmitted. The fw will
2227 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2228 */
2229 break;
2230 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02002231 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01002232 break;
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002233
2234 if (txqs)
2235 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
Johannes Berg9cc40712013-02-15 22:47:48 +01002236 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002237 break;
2238 default:
2239 break;
2240 }
Emmanuel Grumbachc22b0ff2015-01-22 13:15:15 +02002241 spin_unlock_bh(&mvmsta->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002242}
2243
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002244static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2245 struct ieee80211_vif *vif,
2246 struct ieee80211_sta *sta)
2247{
2248 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Gregory Greenman94939082015-08-24 14:38:35 +03002249 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01002250 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002251
2252 /*
2253 * This is called before mac80211 does RCU synchronisation,
2254 * so here we already invalidate our internal RCU-protected
2255 * station pointer. The rest of the code will thus no longer
2256 * be able to find the station this way, and we don't rely
2257 * on further RCU synchronisation after the sta_state()
2258 * callback deleted the station.
2259 */
2260 mutex_lock(&mvm->mutex);
2261 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2262 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2263 ERR_PTR(-ENOENT));
Gregory Greenman94939082015-08-24 14:38:35 +03002264
2265 if (mvm_sta->vif->type == NL80211_IFTYPE_AP) {
2266 mvmvif->ap_assoc_sta_count--;
Ilan Peerf82c8332015-09-10 12:54:38 +03002267 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Gregory Greenman94939082015-08-24 14:38:35 +03002268 }
2269
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002270 mutex_unlock(&mvm->mutex);
2271}
2272
Johannes Bergbd1ba662014-11-13 20:53:45 +01002273static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2274 const u8 *bssid)
2275{
2276 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2277 return;
2278
2279 if (iwlwifi_mod_params.uapsd_disable) {
2280 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2281 return;
2282 }
2283
2284 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2285}
2286
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002287static void
2288iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2289 struct ieee80211_vif *vif, u8 *peer_addr,
2290 enum nl80211_tdls_operation action)
2291{
2292 struct iwl_fw_dbg_trigger_tlv *trig;
2293 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2294
2295 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TDLS))
2296 return;
2297
2298 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TDLS);
2299 tdls_trig = (void *)trig->data;
2300 if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig))
2301 return;
2302
2303 if (!(tdls_trig->action_bitmap & BIT(action)))
2304 return;
2305
2306 if (tdls_trig->peer_mode &&
2307 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2308 return;
2309
2310 iwl_mvm_fw_dbg_collect_trig(mvm, trig,
2311 "TDLS event occurred, peer %pM, action %d",
2312 peer_addr, action);
2313}
2314
Johannes Berg8ca151b2013-01-24 14:25:36 +01002315static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2316 struct ieee80211_vif *vif,
2317 struct ieee80211_sta *sta,
2318 enum ieee80211_sta_state old_state,
2319 enum ieee80211_sta_state new_state)
2320{
2321 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2322 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2323 int ret;
2324
2325 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2326 sta->addr, old_state, new_state);
2327
2328 /* this would be a mac80211 bug ... but don't crash */
2329 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2330 return -EINVAL;
2331
2332 /* if a STA is being removed, reuse its ID */
2333 flush_work(&mvm->sta_drained_wk);
2334
2335 mutex_lock(&mvm->mutex);
2336 if (old_state == IEEE80211_STA_NOTEXIST &&
2337 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02002338 /*
2339 * Firmware bug - it'll crash if the beacon interval is less
2340 * than 16. We can't avoid connecting at all, so refuse the
2341 * station state change, this will cause mac80211 to abandon
2342 * attempts to connect to this AP, and eventually wpa_s will
2343 * blacklist the AP...
2344 */
2345 if (vif->type == NL80211_IFTYPE_STATION &&
2346 vif->bss_conf.beacon_int < 16) {
2347 IWL_ERR(mvm,
2348 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2349 sta->addr, vif->bss_conf.beacon_int);
2350 ret = -EINVAL;
2351 goto out_unlock;
2352 }
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002353
2354 if (sta->tdls &&
2355 (vif->p2p ||
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002356 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2357 IWL_MVM_TDLS_STA_COUNT ||
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002358 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2359 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2360 ret = -EBUSY;
2361 goto out_unlock;
2362 }
2363
Johannes Berg8ca151b2013-01-24 14:25:36 +01002364 ret = iwl_mvm_add_sta(mvm, vif, sta);
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002365 if (sta->tdls && ret == 0) {
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002366 iwl_mvm_recalc_tdls_state(mvm, vif, true);
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002367 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2368 NL80211_TDLS_SETUP);
2369 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002370 } else if (old_state == IEEE80211_STA_NONE &&
2371 new_state == IEEE80211_STA_AUTH) {
Haim Dreyfusse820c2d2014-04-06 11:19:09 +03002372 /*
2373 * EBS may be disabled due to previous failures reported by FW.
2374 * Reset EBS status here assuming environment has been changed.
2375 */
2376 mvm->last_ebs_successful = true;
Johannes Bergbd1ba662014-11-13 20:53:45 +01002377 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002378 ret = 0;
2379 } else if (old_state == IEEE80211_STA_AUTH &&
2380 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01002381 ret = iwl_mvm_update_sta(mvm, vif, sta);
2382 if (ret == 0)
2383 iwl_mvm_rs_rate_init(mvm, sta,
Eyal Shapirab87c2172013-11-09 23:37:55 +02002384 mvmvif->phy_ctxt->channel->band,
2385 true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002386 } else if (old_state == IEEE80211_STA_ASSOC &&
2387 new_state == IEEE80211_STA_AUTHORIZED) {
Arik Nemtsovf59e0e3c2014-06-10 19:56:27 +03002388
2389 /* we don't support TDLS during DCM */
2390 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2391 iwl_mvm_teardown_tdls_peers(mvm);
2392
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002393 if (sta->tdls)
2394 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2395 NL80211_TDLS_ENABLE_LINK);
2396
Hila Gonen7df15b12012-12-12 11:16:19 +02002397 /* enable beacon filtering */
Avri Altmanfa7b2e72014-05-20 08:03:24 +03002398 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002399 ret = 0;
2400 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2401 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02002402 /* disable beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002403 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002404 ret = 0;
2405 } else if (old_state == IEEE80211_STA_ASSOC &&
2406 new_state == IEEE80211_STA_AUTH) {
2407 ret = 0;
2408 } else if (old_state == IEEE80211_STA_AUTH &&
2409 new_state == IEEE80211_STA_NONE) {
2410 ret = 0;
2411 } else if (old_state == IEEE80211_STA_NONE &&
2412 new_state == IEEE80211_STA_NOTEXIST) {
2413 ret = iwl_mvm_rm_sta(mvm, vif, sta);
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002414 if (sta->tdls) {
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002415 iwl_mvm_recalc_tdls_state(mvm, vif, false);
Golan Ben-Ami1e8f1322015-08-23 17:57:33 +03002416 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2417 NL80211_TDLS_DISABLE_LINK);
2418 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002419 } else {
2420 ret = -EIO;
2421 }
Johannes Berg48bc1302013-07-04 15:55:29 +02002422 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002423 mutex_unlock(&mvm->mutex);
2424
Liad Kaufman9c126cd2014-10-06 19:08:56 +02002425 if (sta->tdls && ret == 0) {
2426 if (old_state == IEEE80211_STA_NOTEXIST &&
2427 new_state == IEEE80211_STA_NONE)
2428 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2429 else if (old_state == IEEE80211_STA_NONE &&
2430 new_state == IEEE80211_STA_NOTEXIST)
2431 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2432 }
2433
Johannes Berg8ca151b2013-01-24 14:25:36 +01002434 return ret;
2435}
2436
2437static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2438{
2439 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2440
2441 mvm->rts_threshold = value;
2442
2443 return 0;
2444}
2445
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002446static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2447 struct ieee80211_vif *vif,
2448 struct ieee80211_sta *sta, u32 changed)
2449{
2450 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2451
2452 if (vif->type == NL80211_IFTYPE_STATION &&
2453 changed & IEEE80211_RC_NSS_CHANGED)
2454 iwl_mvm_sf_update(mvm, vif, false);
2455}
2456
Johannes Berg8ca151b2013-01-24 14:25:36 +01002457static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2458 struct ieee80211_vif *vif, u16 ac,
2459 const struct ieee80211_tx_queue_params *params)
2460{
2461 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2462 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2463
2464 mvmvif->queue_params[ac] = *params;
2465
2466 /*
2467 * No need to update right away, we'll get BSS_CHANGED_QOS
2468 * The exception is P2P_DEVICE interface which needs immediate update.
2469 */
2470 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2471 int ret;
2472
2473 mutex_lock(&mvm->mutex);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002474 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002475 mutex_unlock(&mvm->mutex);
2476 return ret;
2477 }
2478 return 0;
2479}
2480
2481static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2482 struct ieee80211_vif *vif)
2483{
2484 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2485 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
2486 200 + vif->bss_conf.beacon_int);
2487 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
2488 100 + vif->bss_conf.beacon_int);
2489
2490 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2491 return;
2492
Eliad Peller576eeee2014-07-01 18:38:38 +03002493 /*
2494 * iwl_mvm_protect_session() reads directly from the device
2495 * (the system time), so make sure it is available.
2496 */
2497 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2498 return;
2499
Johannes Berg8ca151b2013-01-24 14:25:36 +01002500 mutex_lock(&mvm->mutex);
2501 /* Try really hard to protect the session and hear a beacon */
Liad Kaufmand20d37b2014-07-06 17:14:39 +03002502 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002503 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002504
2505 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002506}
2507
David Spinadel35a000b2013-08-28 09:29:43 +03002508static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2509 struct ieee80211_vif *vif,
2510 struct cfg80211_sched_scan_request *req,
David Spinadel633e2712014-02-06 16:15:23 +02002511 struct ieee80211_scan_ies *ies)
David Spinadel35a000b2013-08-28 09:29:43 +03002512{
2513 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luciano Coelho6749dd82015-03-20 15:51:36 +02002514
David Spinadel35a000b2013-08-28 09:29:43 +03002515 int ret;
2516
2517 mutex_lock(&mvm->mutex);
2518
Luciano Coelho1f940382015-02-10 13:03:38 +02002519 if (!vif->bss_conf.idle) {
David Spinadelbd5e4742014-04-24 13:15:29 +03002520 ret = -EBUSY;
2521 goto out;
2522 }
2523
Luciano Coelho19945df2015-03-20 16:11:28 +02002524 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
David Spinadeld2496222014-05-20 12:46:37 +03002525
David Spinadel35a000b2013-08-28 09:29:43 +03002526out:
2527 mutex_unlock(&mvm->mutex);
2528 return ret;
2529}
2530
Johannes Berg37e33082014-02-17 10:48:17 +01002531static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2532 struct ieee80211_vif *vif)
David Spinadel35a000b2013-08-28 09:29:43 +03002533{
2534 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002535 int ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002536
2537 mutex_lock(&mvm->mutex);
Luciano Coelhoe7d3aba2015-02-06 10:19:05 +02002538
2539 /* Due to a race condition, it's possible that mac80211 asks
2540 * us to stop a sched_scan when it's already stopped. This
2541 * can happen, for instance, if we stopped the scan ourselves,
2542 * called ieee80211_sched_scan_stopped() and the userspace called
2543 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
2544 * could run. To handle this, simply return if the scan is
2545 * not running.
2546 */
Luciano Coelho262888f2015-05-07 17:21:09 +03002547 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
Luciano Coelhoe7d3aba2015-02-06 10:19:05 +02002548 mutex_unlock(&mvm->mutex);
2549 return 0;
2550 }
2551
Luciano Coelhoc7d42482015-05-07 16:00:26 +03002552 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
David Spinadel35a000b2013-08-28 09:29:43 +03002553 mutex_unlock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002554 iwl_mvm_wait_for_async_handlers(mvm);
Johannes Berg37e33082014-02-17 10:48:17 +01002555
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002556 return ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002557}
2558
Johannes Berg8ca151b2013-01-24 14:25:36 +01002559static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2560 enum set_key_cmd cmd,
2561 struct ieee80211_vif *vif,
2562 struct ieee80211_sta *sta,
2563 struct ieee80211_key_conf *key)
2564{
2565 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2566 int ret;
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002567 u8 key_offset;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002568
2569 if (iwlwifi_mod_params.sw_crypto) {
2570 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2571 return -EOPNOTSUPP;
2572 }
2573
2574 switch (key->cipher) {
2575 case WLAN_CIPHER_SUITE_TKIP:
2576 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002577 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2578 break;
Johannes Bergca8c0f42015-04-20 17:54:54 +02002579 case WLAN_CIPHER_SUITE_CCMP:
2580 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2581 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002582 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg30686bf2015-06-02 21:39:54 +02002583 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002584 break;
2585 case WLAN_CIPHER_SUITE_WEP40:
2586 case WLAN_CIPHER_SUITE_WEP104:
Johannes Bergba3943b2014-11-12 23:54:48 +01002587 /* For non-client mode, only use WEP keys for TX as we probably
2588 * don't have a station yet anyway and would then have to keep
2589 * track of the keys, linking them to each of the clients/peers
2590 * as they appear. For now, don't do that, for performance WEP
2591 * offload doesn't really matter much, but we need it for some
2592 * other offload features in client mode.
Johannes Berg8ca151b2013-01-24 14:25:36 +01002593 */
Johannes Bergba3943b2014-11-12 23:54:48 +01002594 if (vif->type != NL80211_IFTYPE_STATION)
2595 return 0;
2596 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002597 default:
Max Stepanove36e5432013-08-27 19:56:13 +03002598 /* currently FW supports only one optional cipher scheme */
2599 if (hw->n_cipher_schemes &&
2600 hw->cipher_schemes->cipher == key->cipher)
2601 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2602 else
2603 return -EOPNOTSUPP;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002604 }
2605
2606 mutex_lock(&mvm->mutex);
2607
2608 switch (cmd) {
2609 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02002610 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2611 vif->type == NL80211_IFTYPE_AP) && !sta) {
2612 /*
2613 * GTK on AP interface is a TX-only key, return 0;
2614 * on IBSS they're per-station and because we're lazy
2615 * we don't support them for RX, so do the same.
2616 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002617 ret = 0;
2618 key->hw_key_idx = STA_KEY_IDX_INVALID;
2619 break;
2620 }
2621
Johannes Bergb546dcd2015-04-20 17:31:10 +02002622 /* During FW restart, in order to restore the state as it was,
2623 * don't try to reprogram keys we previously failed for.
2624 */
2625 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2626 key->hw_key_idx == STA_KEY_IDX_INVALID) {
2627 IWL_DEBUG_MAC80211(mvm,
2628 "skip invalid idx key programming during restart\n");
2629 ret = 0;
2630 break;
2631 }
2632
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002633 /* in HW restart reuse the index, otherwise request a new one */
2634 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
2635 key_offset = key->hw_key_idx;
2636 else
2637 key_offset = STA_KEY_IDX_INVALID;
2638
Johannes Berg8ca151b2013-01-24 14:25:36 +01002639 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002640 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002641 if (ret) {
2642 IWL_WARN(mvm, "set key failed\n");
2643 /*
2644 * can't add key for RX, but we don't need it
2645 * in the device for TX so still return 0
2646 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002647 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002648 ret = 0;
2649 }
2650
2651 break;
2652 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01002653 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2654 ret = 0;
2655 break;
2656 }
2657
Johannes Berg8ca151b2013-01-24 14:25:36 +01002658 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
2659 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
2660 break;
2661 default:
2662 ret = -EINVAL;
2663 }
2664
2665 mutex_unlock(&mvm->mutex);
2666 return ret;
2667}
2668
2669static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2670 struct ieee80211_vif *vif,
2671 struct ieee80211_key_conf *keyconf,
2672 struct ieee80211_sta *sta,
2673 u32 iv32, u16 *phase1key)
2674{
2675 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2676
Johannes Berg5023d962013-07-31 14:07:43 +02002677 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2678 return;
2679
Johannes Berg8ca151b2013-01-24 14:25:36 +01002680 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2681}
2682
2683
Ariej Marjiehb1128892014-07-16 21:11:12 +03002684static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
2685 struct iwl_rx_packet *pkt, void *data)
2686{
2687 struct iwl_mvm *mvm =
2688 container_of(notif_wait, struct iwl_mvm, notif_wait);
2689 struct iwl_hs20_roc_res *resp;
2690 int resp_len = iwl_rx_packet_payload_len(pkt);
2691 struct iwl_mvm_time_event_data *te_data = data;
2692
2693 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
2694 return true;
2695
2696 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
2697 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
2698 return true;
2699 }
2700
2701 resp = (void *)pkt->data;
2702
2703 IWL_DEBUG_TE(mvm,
2704 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
2705 resp->status, resp->event_unique_id);
2706
2707 te_data->uid = le32_to_cpu(resp->event_unique_id);
2708 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
2709 te_data->uid);
2710
2711 spin_lock_bh(&mvm->time_event_lock);
2712 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
2713 spin_unlock_bh(&mvm->time_event_lock);
2714
2715 return true;
2716}
2717
Matti Gottliebdc28e122015-11-22 10:08:56 +02002718#define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
2719#define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
2720#define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
2721#define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
2722#define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
Ariej Marjiehb1128892014-07-16 21:11:12 +03002723static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
2724 struct ieee80211_channel *channel,
2725 struct ieee80211_vif *vif,
2726 int duration)
2727{
2728 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
2729 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2730 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
Sara Sharon6eb031d2015-07-13 14:50:47 +03002731 static const u16 time_event_response[] = { HOT_SPOT_CMD };
Ariej Marjiehb1128892014-07-16 21:11:12 +03002732 struct iwl_notification_wait wait_time_event;
Matti Gottliebdc28e122015-11-22 10:08:56 +02002733 u32 dtim_interval = vif->bss_conf.dtim_period *
2734 vif->bss_conf.beacon_int;
2735 u32 req_dur, delay;
Ariej Marjiehb1128892014-07-16 21:11:12 +03002736 struct iwl_hs20_roc_req aux_roc_req = {
2737 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
2738 .id_and_color =
2739 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
2740 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
2741 /* Set the channel info data */
2742 .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ?
2743 PHY_BAND_24 : PHY_BAND_5,
2744 .channel_info.channel = channel->hw_value,
2745 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
2746 /* Set the time and duration */
2747 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
Ariej Marjiehb1128892014-07-16 21:11:12 +03002748 };
2749
Matti Gottliebdc28e122015-11-22 10:08:56 +02002750 delay = AUX_ROC_MIN_DELAY;
2751 req_dur = MSEC_TO_TU(duration);
2752
2753 /*
2754 * If we are associated we want the delay time to be at least one
2755 * dtim interval so that the FW can wait until after the DTIM and
2756 * then start the time event, this will potentially allow us to
2757 * remain off-channel for the max duration.
2758 * Since we want to use almost a whole dtim interval we would also
2759 * like the delay to be for 2-3 dtim intervals, in case there are
2760 * other time events with higher priority.
2761 */
2762 if (vif->bss_conf.assoc) {
2763 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
2764 /* We cannot remain off-channel longer than the DTIM interval */
2765 if (dtim_interval <= req_dur) {
2766 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
2767 if (req_dur <= AUX_ROC_MIN_DURATION)
2768 req_dur = dtim_interval -
2769 AUX_ROC_MIN_SAFETY_BUFFER;
2770 }
2771 }
2772
2773 aux_roc_req.duration = cpu_to_le32(req_dur);
2774 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
2775
2776 IWL_DEBUG_TE(mvm,
2777 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
2778 channel->hw_value, req_dur, duration, delay,
2779 dtim_interval);
Ariej Marjiehb1128892014-07-16 21:11:12 +03002780 /* Set the node address */
2781 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
2782
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002783 lockdep_assert_held(&mvm->mutex);
2784
2785 spin_lock_bh(&mvm->time_event_lock);
2786
2787 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
2788 spin_unlock_bh(&mvm->time_event_lock);
2789 return -EIO;
2790 }
2791
Ariej Marjiehb1128892014-07-16 21:11:12 +03002792 te_data->vif = vif;
2793 te_data->duration = duration;
2794 te_data->id = HOT_SPOT_CMD;
2795
Ariej Marjiehb1128892014-07-16 21:11:12 +03002796 spin_unlock_bh(&mvm->time_event_lock);
2797
2798 /*
2799 * Use a notification wait, which really just processes the
2800 * command response and doesn't wait for anything, in order
2801 * to be able to process the response and get the UID inside
2802 * the RX path. Using CMD_WANT_SKB doesn't work because it
2803 * stores the buffer and then wakes up this thread, by which
2804 * time another notification (that the time event started)
2805 * might already be processed unsuccessfully.
2806 */
2807 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
2808 time_event_response,
2809 ARRAY_SIZE(time_event_response),
2810 iwl_mvm_rx_aux_roc, te_data);
2811
2812 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
2813 &aux_roc_req);
2814
2815 if (res) {
2816 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
2817 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
2818 goto out_clear_te;
2819 }
2820
2821 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
2822 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
2823 /* should never fail */
2824 WARN_ON_ONCE(res);
2825
2826 if (res) {
2827 out_clear_te:
2828 spin_lock_bh(&mvm->time_event_lock);
2829 iwl_mvm_te_clear_data(mvm, te_data);
2830 spin_unlock_bh(&mvm->time_event_lock);
2831 }
2832
2833 return res;
2834}
2835
Johannes Berg8ca151b2013-01-24 14:25:36 +01002836static int iwl_mvm_roc(struct ieee80211_hw *hw,
2837 struct ieee80211_vif *vif,
2838 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002839 int duration,
2840 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002841{
2842 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002843 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002844 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03002845 struct iwl_mvm_phy_ctxt *phy_ctxt;
2846 int ret, i;
2847
2848 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
2849 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002850
Matti Gottlieb6ed13162015-03-30 16:50:07 +03002851 flush_work(&mvm->roc_done_wk);
2852
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002853 mutex_lock(&mvm->mutex);
2854
Ariej Marjiehb1128892014-07-16 21:11:12 +03002855 switch (vif->type) {
2856 case NL80211_IFTYPE_STATION:
Johannes Berg859d9142015-06-01 17:11:11 +02002857 if (fw_has_capa(&mvm->fw->ucode_capa,
2858 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
Luciano Coelho5ac6c722014-10-21 16:12:18 +03002859 /* Use aux roc framework (HS20) */
2860 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
2861 vif, duration);
2862 goto out_unlock;
2863 }
2864 IWL_ERR(mvm, "hotspot not supported\n");
2865 ret = -EINVAL;
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002866 goto out_unlock;
Ariej Marjiehb1128892014-07-16 21:11:12 +03002867 case NL80211_IFTYPE_P2P_DEVICE:
2868 /* handle below */
2869 break;
2870 default:
2871 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002872 ret = -EINVAL;
2873 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002874 }
2875
Ilan Peer31d385a2013-04-02 10:25:46 +03002876 for (i = 0; i < NUM_PHY_CTX; i++) {
2877 phy_ctxt = &mvm->phy_ctxts[i];
2878 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
2879 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002880
Ilan Peer31d385a2013-04-02 10:25:46 +03002881 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
2882 /*
2883 * Unbind the P2P_DEVICE from the current PHY context,
2884 * and if the PHY context is not used remove it.
2885 */
2886 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2887 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2888 goto out_unlock;
2889
2890 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2891
2892 /* Bind the P2P_DEVICE to the current PHY Context */
2893 mvmvif->phy_ctxt = phy_ctxt;
2894
2895 ret = iwl_mvm_binding_add_vif(mvm, vif);
2896 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2897 goto out_unlock;
2898
2899 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2900 goto schedule_time_event;
2901 }
2902 }
2903
2904 /* Need to update the PHY context only if the ROC channel changed */
2905 if (channel == mvmvif->phy_ctxt->channel)
2906 goto schedule_time_event;
2907
2908 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
2909
2910 /*
2911 * Change the PHY context configuration as it is currently referenced
2912 * only by the P2P Device MAC
2913 */
2914 if (mvmvif->phy_ctxt->ref == 1) {
2915 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2916 &chandef, 1, 1);
2917 if (ret)
2918 goto out_unlock;
2919 } else {
2920 /*
2921 * The PHY context is shared with other MACs. Need to remove the
2922 * P2P Device from the binding, allocate an new PHY context and
2923 * create a new binding
2924 */
2925 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2926 if (!phy_ctxt) {
2927 ret = -ENOSPC;
2928 goto out_unlock;
2929 }
2930
2931 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2932 1, 1);
2933 if (ret) {
2934 IWL_ERR(mvm, "Failed to change PHY context\n");
2935 goto out_unlock;
2936 }
2937
2938 /* Unbind the P2P_DEVICE from the current PHY context */
2939 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2940 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2941 goto out_unlock;
2942
2943 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2944
2945 /* Bind the P2P_DEVICE to the new allocated PHY context */
2946 mvmvif->phy_ctxt = phy_ctxt;
2947
2948 ret = iwl_mvm_binding_add_vif(mvm, vif);
2949 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2950 goto out_unlock;
2951
2952 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2953 }
2954
2955schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002956 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02002957 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002958
Ilan Peer31d385a2013-04-02 10:25:46 +03002959out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002960 mutex_unlock(&mvm->mutex);
2961 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01002962 return ret;
2963}
2964
2965static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
2966{
2967 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2968
2969 IWL_DEBUG_MAC80211(mvm, "enter\n");
2970
2971 mutex_lock(&mvm->mutex);
Matti Gottliebbf5da872014-11-16 10:25:12 +02002972 iwl_mvm_stop_roc(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002973 mutex_unlock(&mvm->mutex);
2974
2975 IWL_DEBUG_MAC80211(mvm, "leave\n");
2976 return 0;
2977}
2978
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002979static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
2980 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002981{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002982 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2983 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002984 int ret;
2985
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002986 lockdep_assert_held(&mvm->mutex);
2987
Ilan Peer53a9d612013-04-28 11:55:08 +03002988 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002989
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002990 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2991 if (!phy_ctxt) {
2992 ret = -ENOSPC;
2993 goto out;
2994 }
2995
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02002996 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Ilan Peer53a9d612013-04-28 11:55:08 +03002997 ctx->rx_chains_static,
2998 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002999 if (ret) {
3000 IWL_ERR(mvm, "Failed to add PHY context\n");
3001 goto out;
3002 }
3003
Ilan Peer53a9d612013-04-28 11:55:08 +03003004 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003005 *phy_ctxt_id = phy_ctxt->id;
3006out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003007 return ret;
3008}
3009
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003010static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3011 struct ieee80211_chanctx_conf *ctx)
3012{
3013 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3014 int ret;
3015
3016 mutex_lock(&mvm->mutex);
3017 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3018 mutex_unlock(&mvm->mutex);
3019
3020 return ret;
3021}
3022
3023static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3024 struct ieee80211_chanctx_conf *ctx)
3025{
3026 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3027 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3028
3029 lockdep_assert_held(&mvm->mutex);
3030
3031 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3032}
3033
Johannes Berg8ca151b2013-01-24 14:25:36 +01003034static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3035 struct ieee80211_chanctx_conf *ctx)
3036{
3037 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003038
3039 mutex_lock(&mvm->mutex);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003040 __iwl_mvm_remove_chanctx(mvm, ctx);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003041 mutex_unlock(&mvm->mutex);
3042}
3043
3044static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3045 struct ieee80211_chanctx_conf *ctx,
3046 u32 changed)
3047{
3048 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003049 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3050 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01003051
Ilan Peer31d385a2013-04-02 10:25:46 +03003052 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3053 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3054 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
Arik Nemtsov2dceeda2013-12-29 17:57:53 +02003055 IEEE80211_CHANCTX_CHANGE_RADAR |
3056 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
Ilan Peer31d385a2013-04-02 10:25:46 +03003057 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3058 phy_ctxt->ref, changed))
3059 return;
3060
Johannes Berg8ca151b2013-01-24 14:25:36 +01003061 mutex_lock(&mvm->mutex);
Emmanuel Grumbach4d664492014-04-30 18:09:59 +03003062 iwl_mvm_bt_coex_vif_change(mvm);
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02003063 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003064 ctx->rx_chains_static,
3065 ctx->rx_chains_dynamic);
3066 mutex_unlock(&mvm->mutex);
3067}
3068
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003069static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3070 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02003071 struct ieee80211_chanctx_conf *ctx,
3072 bool switching_chanctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003073{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003074 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3075 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01003076 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3077 int ret;
3078
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003079 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003080
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003081 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003082
3083 switch (vif->type) {
3084 case NL80211_IFTYPE_AP:
Luciano Coelho4741dd02014-11-10 11:10:13 +02003085 /* only needed if we're switching chanctx (i.e. during CSA) */
3086 if (switching_chanctx) {
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003087 mvmvif->ap_ibss_active = true;
3088 break;
3089 }
Johannes Berg5023d962013-07-31 14:07:43 +02003090 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003091 /*
3092 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02003093 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01003094 */
3095 ret = 0;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003096 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003097 case NL80211_IFTYPE_STATION:
Luciano Coelho2533edc2014-08-08 19:50:46 +03003098 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003099 case NL80211_IFTYPE_MONITOR:
Luciano Coelho2533edc2014-08-08 19:50:46 +03003100 /* always disable PS when a monitor interface is active */
3101 mvmvif->ps_disabled = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003102 break;
3103 default:
3104 ret = -EINVAL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003105 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003106 }
3107
3108 ret = iwl_mvm_binding_add_vif(mvm, vif);
3109 if (ret)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003110 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003111
3112 /*
Alexander Bondar92d85562013-10-23 11:50:34 +02003113 * Power state must be updated before quotas,
3114 * otherwise fw will complain.
3115 */
Arik Nemtsov999609f2014-05-15 17:31:51 +03003116 iwl_mvm_power_update_mac(mvm);
Alexander Bondar92d85562013-10-23 11:50:34 +02003117
3118 /* Setting the quota at this stage is only required for monitor
Johannes Berg8ca151b2013-01-24 14:25:36 +01003119 * interfaces. For the other types, the bss_info changed flow
3120 * will handle quota settings.
3121 */
3122 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02003123 mvmvif->monitor_active = true;
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003124 ret = iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003125 if (ret)
3126 goto out_remove_binding;
3127 }
3128
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003129 /* Handle binding during CSA */
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003130 if (vif->type == NL80211_IFTYPE_AP) {
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003131 iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02003132 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003133 }
3134
Luciano Coelho4741dd02014-11-10 11:10:13 +02003135 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
Luciano Coelho686e7fe2014-11-10 11:10:21 +02003136 u32 duration = 2 * vif->bss_conf.beacon_int;
3137
3138 /* iwl_mvm_protect_session() reads directly from the
3139 * device (the system time), so make sure it is
3140 * available.
3141 */
3142 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3143 if (ret)
3144 goto out_remove_binding;
3145
3146 /* Protect the session to make sure we hear the first
3147 * beacon on the new channel.
3148 */
3149 iwl_mvm_protect_session(mvm, vif, duration, duration,
3150 vif->bss_conf.beacon_int / 2,
3151 true);
3152
3153 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3154
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003155 iwl_mvm_update_quotas(mvm, false, NULL);
Luciano Coelho0ce04ce2014-05-08 16:03:39 +03003156 }
3157
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003158 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003159
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003160out_remove_binding:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003161 iwl_mvm_binding_remove_vif(mvm, vif);
Arik Nemtsov999609f2014-05-15 17:31:51 +03003162 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003163out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003164 if (ret)
3165 mvmvif->phy_ctxt = NULL;
3166 return ret;
3167}
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003168static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3169 struct ieee80211_vif *vif,
3170 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003171{
3172 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003173 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003174
3175 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003176 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003177 mutex_unlock(&mvm->mutex);
3178
3179 return ret;
3180}
3181
3182static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3183 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02003184 struct ieee80211_chanctx_conf *ctx,
3185 bool switching_chanctx)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003186{
3187 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003188 struct ieee80211_vif *disabled_vif = NULL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003189
3190 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003191
3192 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3193
Johannes Berg8ca151b2013-01-24 14:25:36 +01003194 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02003195 case NL80211_IFTYPE_ADHOC:
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003196 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003197 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02003198 mvmvif->monitor_active = false;
Luciano Coelho2533edc2014-08-08 19:50:46 +03003199 mvmvif->ps_disabled = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003200 break;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003201 case NL80211_IFTYPE_AP:
3202 /* This part is triggered only during CSA */
Luciano Coelho4741dd02014-11-10 11:10:13 +02003203 if (!switching_chanctx || !mvmvif->ap_ibss_active)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003204 goto out;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003205
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003206 mvmvif->csa_countdown = false;
3207
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03003208 /* Set CS bit on all the stations */
3209 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3210
3211 /* Save blocked iface, the timeout is set on the next beacon */
3212 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3213
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003214 mvmvif->ap_ibss_active = false;
Luciano Coelhof0c97782014-03-05 15:41:48 +02003215 break;
3216 case NL80211_IFTYPE_STATION:
3217 if (!switching_chanctx)
3218 break;
3219
3220 disabled_vif = vif;
3221
Johannes Berg3dfd3a92014-08-11 21:37:30 +02003222 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003223 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003224 default:
3225 break;
3226 }
3227
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003228 iwl_mvm_update_quotas(mvm, false, disabled_vif);
Ilan Peer1e1391c2013-03-13 14:52:04 +02003229 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03003230
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003231out:
Ilan Peera11e1442013-12-31 21:19:55 +02003232 mvmvif->phy_ctxt = NULL;
Arik Nemtsov999609f2014-05-15 17:31:51 +03003233 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003234}
3235
3236static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3237 struct ieee80211_vif *vif,
3238 struct ieee80211_chanctx_conf *ctx)
3239{
3240 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3241
3242 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003243 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003244 mutex_unlock(&mvm->mutex);
3245}
3246
Luciano Coelho50cc9572014-11-10 11:10:08 +02003247static int
3248iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3249 struct ieee80211_vif_chanctx_switch *vifs)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003250{
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003251 int ret;
3252
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003253 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003254 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003255 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3256
3257 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3258 if (ret) {
3259 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3260 goto out_reassign;
3261 }
3262
Luciano Coelhof0c97782014-03-05 15:41:48 +02003263 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3264 true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003265 if (ret) {
3266 IWL_ERR(mvm,
3267 "failed to assign new_ctx during channel switch\n");
3268 goto out_remove;
3269 }
3270
Arik Nemtsovf6972672014-06-15 16:03:55 +03003271 /* we don't support TDLS during DCM - can be caused by channel switch */
3272 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3273 iwl_mvm_teardown_tdls_peers(mvm);
3274
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003275 goto out;
3276
3277out_remove:
3278 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3279
3280out_reassign:
Luciano Coelho6fd1fb62014-11-10 11:10:10 +02003281 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003282 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3283 goto out_restart;
3284 }
3285
Luciano Coelho6fd1fb62014-11-10 11:10:10 +02003286 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3287 true)) {
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003288 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3289 goto out_restart;
3290 }
3291
3292 goto out;
3293
3294out_restart:
3295 /* things keep failing, better restart the hw */
3296 iwl_mvm_nic_restart(mvm, false);
3297
3298out:
3299 mutex_unlock(&mvm->mutex);
Luciano Coelho50cc9572014-11-10 11:10:08 +02003300
3301 return ret;
3302}
3303
Luciano Coelho48a256e2014-11-10 11:10:09 +02003304static int
3305iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3306 struct ieee80211_vif_chanctx_switch *vifs)
3307{
3308 int ret;
3309
3310 mutex_lock(&mvm->mutex);
3311 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3312
3313 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3314 true);
3315 if (ret) {
3316 IWL_ERR(mvm,
3317 "failed to assign new_ctx during channel switch\n");
3318 goto out_reassign;
3319 }
3320
3321 goto out;
3322
3323out_reassign:
3324 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3325 true)) {
3326 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3327 goto out_restart;
3328 }
3329
3330 goto out;
3331
3332out_restart:
3333 /* things keep failing, better restart the hw */
3334 iwl_mvm_nic_restart(mvm, false);
3335
3336out:
3337 mutex_unlock(&mvm->mutex);
3338
3339 return ret;
3340}
3341
Luciano Coelho50cc9572014-11-10 11:10:08 +02003342static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3343 struct ieee80211_vif_chanctx_switch *vifs,
3344 int n_vifs,
3345 enum ieee80211_chanctx_switch_mode mode)
3346{
3347 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3348 int ret;
3349
3350 /* we only support a single-vif right now */
3351 if (n_vifs > 1)
3352 return -EOPNOTSUPP;
3353
3354 switch (mode) {
3355 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3356 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3357 break;
3358 case CHANCTX_SWMODE_REASSIGN_VIF:
Luciano Coelho48a256e2014-11-10 11:10:09 +02003359 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
Luciano Coelho50cc9572014-11-10 11:10:08 +02003360 break;
3361 default:
3362 ret = -EOPNOTSUPP;
3363 break;
3364 }
3365
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003366 return ret;
3367}
3368
Johannes Berg8ca151b2013-01-24 14:25:36 +01003369static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3370 struct ieee80211_sta *sta,
3371 bool set)
3372{
3373 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01003374 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003375
3376 if (!mvm_sta || !mvm_sta->vif) {
3377 IWL_ERR(mvm, "Station is not associated to a vif\n");
3378 return -EINVAL;
3379 }
3380
3381 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3382}
3383
David Spinadel507cadf2013-07-31 18:07:21 +03003384#ifdef CONFIG_NL80211_TESTMODE
3385static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3386 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3387 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad422013-08-01 14:17:15 +02003388 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03003389};
3390
3391static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3392 struct ieee80211_vif *vif,
3393 void *data, int len)
3394{
3395 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3396 int err;
3397 u32 noa_duration;
3398
3399 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
3400 if (err)
3401 return err;
3402
3403 if (!tb[IWL_MVM_TM_ATTR_CMD])
3404 return -EINVAL;
3405
3406 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3407 case IWL_MVM_TM_CMD_SET_NOA:
3408 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3409 !vif->bss_conf.enable_beacon ||
3410 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3411 return -EINVAL;
3412
3413 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3414 if (noa_duration >= vif->bss_conf.beacon_int)
3415 return -EINVAL;
3416
3417 mvm->noa_duration = noa_duration;
3418 mvm->noa_vif = vif;
3419
Emmanuel Grumbach7754ae72015-02-26 15:14:35 +02003420 return iwl_mvm_update_quotas(mvm, false, NULL);
Johannes Bergf6c6ad422013-08-01 14:17:15 +02003421 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3422 /* must be associated client vif - ignore authorized */
3423 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3424 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3425 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3426 return -EINVAL;
3427
3428 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03003429 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3430 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
David Spinadel507cadf2013-07-31 18:07:21 +03003431 }
3432
3433 return -EOPNOTSUPP;
3434}
3435
3436static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3437 struct ieee80211_vif *vif,
3438 void *data, int len)
3439{
3440 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3441 int err;
3442
3443 mutex_lock(&mvm->mutex);
3444 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3445 mutex_unlock(&mvm->mutex);
3446
3447 return err;
3448}
3449#endif
3450
Luciano Coelho622e3f92014-11-10 11:10:17 +02003451static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3452 struct ieee80211_vif *vif,
3453 struct ieee80211_channel_switch *chsw)
3454{
3455 /* By implementing this operation, we prevent mac80211 from
3456 * starting its own channel switch timer, so that we can call
3457 * ieee80211_chswitch_done() ourselves at the right time
3458 * (which is when the absence time event starts).
3459 */
3460
3461 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3462 "dummy channel switch op\n");
3463}
3464
Luciano Coelhof0289052014-11-10 11:10:06 +02003465static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3466 struct ieee80211_vif *vif,
3467 struct ieee80211_channel_switch *chsw)
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003468{
3469 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003470 struct ieee80211_vif *csa_vif;
Luciano Coelhof6c34822014-11-10 11:10:12 +02003471 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003472 u32 apply_time;
Luciano Coelhof0289052014-11-10 11:10:06 +02003473 int ret;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003474
3475 mutex_lock(&mvm->mutex);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003476
Johannes Berg81d62d52015-03-10 14:44:00 +01003477 mvmvif->csa_failed = false;
3478
Luciano Coelho6b20d772014-11-10 11:10:07 +02003479 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
Luciano Coelhof0289052014-11-10 11:10:06 +02003480 chsw->chandef.center_freq1);
Luciano Coelho6b20d772014-11-10 11:10:07 +02003481
Johannes Berg21023b12015-03-31 08:58:16 +02003482 iwl_fw_dbg_trigger_simple_stop(mvm, vif, FW_DBG_TRIGGER_CHANNEL_SWITCH);
Emmanuel Grumbachf35d9c52015-02-10 10:49:51 +02003483
Luciano Coelho6b20d772014-11-10 11:10:07 +02003484 switch (vif->type) {
3485 case NL80211_IFTYPE_AP:
3486 csa_vif =
3487 rcu_dereference_protected(mvm->csa_vif,
3488 lockdep_is_held(&mvm->mutex));
3489 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3490 "Another CSA is already in progress")) {
3491 ret = -EBUSY;
3492 goto out_unlock;
3493 }
3494
3495 rcu_assign_pointer(mvm->csa_vif, vif);
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003496
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003497 if (WARN_ONCE(mvmvif->csa_countdown,
3498 "Previous CSA countdown didn't complete")) {
3499 ret = -EBUSY;
3500 goto out_unlock;
3501 }
3502
Luciano Coelho6b20d772014-11-10 11:10:07 +02003503 break;
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003504 case NL80211_IFTYPE_STATION:
Luciano Coelho4500e132014-11-10 11:10:15 +02003505 /* Schedule the time event to a bit before beacon 1,
3506 * to make sure we're in the new channel when the
3507 * GO/AP arrives.
3508 */
3509 apply_time = chsw->device_timestamp +
3510 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3511 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003512
3513 if (chsw->block_tx)
3514 iwl_mvm_csa_client_absent(mvm, vif);
3515
Luciano Coelho4500e132014-11-10 11:10:15 +02003516 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003517 apply_time);
Luciano Coelhoc6e0a3e02014-11-10 11:10:18 +02003518 if (mvmvif->bf_data.bf_enabled) {
3519 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3520 if (ret)
3521 goto out_unlock;
3522 }
3523
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003524 break;
Luciano Coelho6b20d772014-11-10 11:10:07 +02003525 default:
3526 break;
3527 }
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003528
Luciano Coelhof6c34822014-11-10 11:10:12 +02003529 mvmvif->ps_disabled = true;
3530
3531 ret = iwl_mvm_power_update_ps(mvm);
3532 if (ret)
3533 goto out_unlock;
Luciano Coelhof0289052014-11-10 11:10:06 +02003534
Arik Nemtsove198f5e2014-09-14 19:13:54 +03003535 /* we won't be on this channel any longer */
3536 iwl_mvm_teardown_tdls_peers(mvm);
3537
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003538out_unlock:
3539 mutex_unlock(&mvm->mutex);
Luciano Coelhof0289052014-11-10 11:10:06 +02003540
3541 return ret;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003542}
3543
Luciano Coelhof6c34822014-11-10 11:10:12 +02003544static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
3545 struct ieee80211_vif *vif)
3546{
3547 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3548 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3549 int ret;
3550
3551 mutex_lock(&mvm->mutex);
3552
Johannes Berg81d62d52015-03-10 14:44:00 +01003553 if (mvmvif->csa_failed) {
3554 mvmvif->csa_failed = false;
3555 ret = -EIO;
3556 goto out_unlock;
3557 }
3558
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003559 if (vif->type == NL80211_IFTYPE_STATION) {
3560 struct iwl_mvm_sta *mvmsta;
3561
3562 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
3563 mvmvif->ap_sta_id);
3564
3565 if (WARN_ON(!mvmsta)) {
3566 ret = -EIO;
3567 goto out_unlock;
3568 }
3569
3570 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
3571
3572 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Luciano Coelhoc6e0a3e02014-11-10 11:10:18 +02003573
3574 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3575 if (ret)
3576 goto out_unlock;
Luciano Coelho686e7fe2014-11-10 11:10:21 +02003577
3578 iwl_mvm_stop_session_protection(mvm, vif);
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003579 }
3580
Luciano Coelhof6c34822014-11-10 11:10:12 +02003581 mvmvif->ps_disabled = false;
3582
3583 ret = iwl_mvm_power_update_ps(mvm);
3584
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003585out_unlock:
Luciano Coelhof6c34822014-11-10 11:10:12 +02003586 mutex_unlock(&mvm->mutex);
3587
3588 return ret;
3589}
3590
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003591static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
3592 struct ieee80211_vif *vif, u32 queues, bool drop)
3593{
3594 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3595 struct iwl_mvm_vif *mvmvif;
3596 struct iwl_mvm_sta *mvmsta;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03003597 struct ieee80211_sta *sta;
3598 int i;
3599 u32 msk = 0;
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003600
3601 if (!vif || vif->type != NL80211_IFTYPE_STATION)
3602 return;
3603
3604 mutex_lock(&mvm->mutex);
3605 mvmvif = iwl_mvm_vif_from_mac80211(vif);
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003606
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03003607 /* flush the AP-station and all TDLS peers */
3608 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
3609 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3610 lockdep_is_held(&mvm->mutex));
3611 if (IS_ERR_OR_NULL(sta))
3612 continue;
3613
3614 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3615 if (mvmsta->vif != vif)
3616 continue;
3617
3618 /* make sure only TDLS peers or the AP are flushed */
3619 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
3620
3621 msk |= mvmsta->tfd_queue_msk;
Johannes Berg480acbc2014-10-10 08:59:27 +02003622 }
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003623
Emmanuel Grumbach6d440b22015-01-20 09:25:19 +02003624 if (drop) {
Luca Coelho5888a402015-10-06 09:54:57 +03003625 if (iwl_mvm_flush_tx_path(mvm, msk, 0))
Emmanuel Grumbach6d440b22015-01-20 09:25:19 +02003626 IWL_ERR(mvm, "flush request fail\n");
3627 mutex_unlock(&mvm->mutex);
3628 } else {
3629 mutex_unlock(&mvm->mutex);
Johannes Berg480acbc2014-10-10 08:59:27 +02003630
Emmanuel Grumbach6d440b22015-01-20 09:25:19 +02003631 /* this can take a while, and we may need/want other operations
3632 * to succeed while doing this, so do it without the mutex held
3633 */
3634 iwl_trans_wait_tx_queue_empty(mvm->trans, msk);
3635 }
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003636}
3637
Johannes Berg91a8bcd2015-01-14 18:12:41 +01003638static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
3639 struct survey_info *survey)
3640{
3641 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3642 int ret;
3643
3644 memset(survey, 0, sizeof(*survey));
3645
3646 /* only support global statistics right now */
3647 if (idx != 0)
3648 return -ENOENT;
3649
Johannes Berg859d9142015-06-01 17:11:11 +02003650 if (fw_has_capa(&mvm->fw->ucode_capa,
Johannes Berg91a8bcd2015-01-14 18:12:41 +01003651 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
3652 return -ENOENT;
3653
3654 mutex_lock(&mvm->mutex);
3655
3656 if (mvm->ucode_loaded) {
Johannes Berg33cef922015-01-21 21:41:29 +01003657 ret = iwl_mvm_request_statistics(mvm, false);
Johannes Berg91a8bcd2015-01-14 18:12:41 +01003658 if (ret)
3659 goto out;
3660 }
3661
3662 survey->filled = SURVEY_INFO_TIME |
3663 SURVEY_INFO_TIME_RX |
3664 SURVEY_INFO_TIME_TX |
3665 SURVEY_INFO_TIME_SCAN;
3666 survey->time = mvm->accu_radio_stats.on_time_rf +
3667 mvm->radio_stats.on_time_rf;
3668 do_div(survey->time, USEC_PER_MSEC);
3669
3670 survey->time_rx = mvm->accu_radio_stats.rx_time +
3671 mvm->radio_stats.rx_time;
3672 do_div(survey->time_rx, USEC_PER_MSEC);
3673
3674 survey->time_tx = mvm->accu_radio_stats.tx_time +
3675 mvm->radio_stats.tx_time;
3676 do_div(survey->time_tx, USEC_PER_MSEC);
3677
3678 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
3679 mvm->radio_stats.on_time_scan;
3680 do_div(survey->time_scan, USEC_PER_MSEC);
3681
Johannes Berg10a7c0282015-04-01 10:00:31 +02003682 ret = 0;
Johannes Berg91a8bcd2015-01-14 18:12:41 +01003683 out:
3684 mutex_unlock(&mvm->mutex);
3685 return ret;
3686}
3687
Johannes Berg33cef922015-01-21 21:41:29 +01003688static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
3689 struct ieee80211_vif *vif,
3690 struct ieee80211_sta *sta,
3691 struct station_info *sinfo)
3692{
3693 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3694 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3695 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3696
Johannes Berg859d9142015-06-01 17:11:11 +02003697 if (fw_has_capa(&mvm->fw->ucode_capa,
3698 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
Johannes Berg33cef922015-01-21 21:41:29 +01003699 return;
3700
3701 /* if beacon filtering isn't on mac80211 does it anyway */
3702 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
3703 return;
3704
3705 if (!vif->bss_conf.assoc)
3706 return;
3707
3708 mutex_lock(&mvm->mutex);
3709
3710 if (mvmvif->ap_sta_id != mvmsta->sta_id)
3711 goto unlock;
3712
3713 if (iwl_mvm_request_statistics(mvm, false))
3714 goto unlock;
3715
3716 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
3717 mvmvif->beacon_stats.accu_num_beacons;
3718 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX);
3719 if (mvmvif->beacon_stats.avg_signal) {
3720 /* firmware only reports a value after RXing a few beacons */
3721 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
3722 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
3723 }
3724 unlock:
3725 mutex_unlock(&mvm->mutex);
3726}
3727
Emmanuel Grumbach42032632015-04-15 12:43:46 +03003728static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
3729 struct ieee80211_vif *vif,
3730 const struct ieee80211_event *event)
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02003731{
Johannes Berg5d4f9292015-03-31 09:12:54 +02003732#define CHECK_MLME_TRIGGER(_mvm, _trig, _buf, _cnt, _fmt...) \
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02003733 do { \
3734 if ((_cnt) && --(_cnt)) \
3735 break; \
Johannes Berg5d4f9292015-03-31 09:12:54 +02003736 iwl_mvm_fw_dbg_collect_trig(_mvm, _trig, _fmt);\
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02003737 } while (0)
3738
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02003739 struct iwl_fw_dbg_trigger_tlv *trig;
3740 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02003741
3742 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
3743 return;
3744
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02003745 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
3746 trig_mlme = (void *)trig->data;
3747 if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig))
3748 return;
3749
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02003750 if (event->u.mlme.data == ASSOC_EVENT) {
3751 if (event->u.mlme.status == MLME_DENIED)
3752 CHECK_MLME_TRIGGER(mvm, trig, buf,
3753 trig_mlme->stop_assoc_denied,
3754 "DENIED ASSOC: reason %d",
3755 event->u.mlme.reason);
3756 else if (event->u.mlme.status == MLME_TIMEOUT)
3757 CHECK_MLME_TRIGGER(mvm, trig, buf,
3758 trig_mlme->stop_assoc_timeout,
3759 "ASSOC TIMEOUT");
3760 } else if (event->u.mlme.data == AUTH_EVENT) {
3761 if (event->u.mlme.status == MLME_DENIED)
3762 CHECK_MLME_TRIGGER(mvm, trig, buf,
3763 trig_mlme->stop_auth_denied,
3764 "DENIED AUTH: reason %d",
3765 event->u.mlme.reason);
3766 else if (event->u.mlme.status == MLME_TIMEOUT)
3767 CHECK_MLME_TRIGGER(mvm, trig, buf,
3768 trig_mlme->stop_auth_timeout,
3769 "AUTH TIMEOUT");
3770 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
3771 CHECK_MLME_TRIGGER(mvm, trig, buf,
3772 trig_mlme->stop_rx_deauth,
3773 "DEAUTH RX %d", event->u.mlme.reason);
3774 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
3775 CHECK_MLME_TRIGGER(mvm, trig, buf,
3776 trig_mlme->stop_tx_deauth,
3777 "DEAUTH TX %d", event->u.mlme.reason);
3778 }
3779#undef CHECK_MLME_TRIGGER
3780}
3781
Emmanuel Grumbach42032632015-04-15 12:43:46 +03003782static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
3783 struct ieee80211_vif *vif,
3784 const struct ieee80211_event *event)
3785{
3786 struct iwl_fw_dbg_trigger_tlv *trig;
3787 struct iwl_fw_dbg_trigger_ba *ba_trig;
3788
3789 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
3790 return;
3791
3792 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
3793 ba_trig = (void *)trig->data;
3794 if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig))
3795 return;
3796
3797 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
3798 return;
3799
3800 iwl_mvm_fw_dbg_collect_trig(mvm, trig,
3801 "BAR received from %pM, tid %d, ssn %d",
3802 event->u.ba.sta->addr, event->u.ba.tid,
3803 event->u.ba.ssn);
3804}
3805
3806static void
3807iwl_mvm_event_frame_timeout_callback(struct iwl_mvm *mvm,
3808 struct ieee80211_vif *vif,
3809 const struct ieee80211_event *event)
3810{
3811 struct iwl_fw_dbg_trigger_tlv *trig;
3812 struct iwl_fw_dbg_trigger_ba *ba_trig;
3813
3814 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
3815 return;
3816
3817 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
3818 ba_trig = (void *)trig->data;
3819 if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig))
3820 return;
3821
3822 if (!(le16_to_cpu(ba_trig->frame_timeout) & BIT(event->u.ba.tid)))
3823 return;
3824
3825 iwl_mvm_fw_dbg_collect_trig(mvm, trig,
3826 "Frame from %pM timed out, tid %d",
3827 event->u.ba.sta->addr, event->u.ba.tid);
3828}
3829
3830static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
3831 struct ieee80211_vif *vif,
3832 const struct ieee80211_event *event)
3833{
3834 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3835
3836 switch (event->type) {
3837 case MLME_EVENT:
3838 iwl_mvm_event_mlme_callback(mvm, vif, event);
3839 break;
3840 case BAR_RX_EVENT:
3841 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
3842 break;
3843 case BA_FRAME_TIMEOUT:
3844 iwl_mvm_event_frame_timeout_callback(mvm, vif, event);
3845 break;
3846 default:
3847 break;
3848 }
3849}
3850
Johannes Berge5209262014-01-20 23:38:59 +01003851const struct ieee80211_ops iwl_mvm_hw_ops = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01003852 .tx = iwl_mvm_mac_tx,
3853 .ampdu_action = iwl_mvm_mac_ampdu_action,
3854 .start = iwl_mvm_mac_start,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02003855 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003856 .stop = iwl_mvm_mac_stop,
3857 .add_interface = iwl_mvm_mac_add_interface,
3858 .remove_interface = iwl_mvm_mac_remove_interface,
3859 .config = iwl_mvm_mac_config,
Eliad Pellere59647e2013-11-28 14:08:50 +02003860 .prepare_multicast = iwl_mvm_prepare_multicast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003861 .configure_filter = iwl_mvm_configure_filter,
Andrei Otcheretianskieffd1922015-06-30 12:08:28 +03003862 .config_iface_filter = iwl_mvm_config_iface_filter,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003863 .bss_info_changed = iwl_mvm_bss_info_changed,
3864 .hw_scan = iwl_mvm_mac_hw_scan,
3865 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
Johannes Berg1ddbbb02013-12-04 22:39:17 +01003866 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003867 .sta_state = iwl_mvm_mac_sta_state,
3868 .sta_notify = iwl_mvm_mac_sta_notify,
3869 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
Johannes Berg3e56ead2013-02-15 22:23:18 +01003870 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003871 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02003872 .sta_rc_update = iwl_mvm_sta_rc_update,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003873 .conf_tx = iwl_mvm_mac_conf_tx,
3874 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
Arik Nemtsov07ecd892014-05-20 18:16:42 +03003875 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003876 .flush = iwl_mvm_mac_flush,
David Spinadel35a000b2013-08-28 09:29:43 +03003877 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
3878 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003879 .set_key = iwl_mvm_mac_set_key,
3880 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
3881 .remain_on_channel = iwl_mvm_roc,
3882 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003883 .add_chanctx = iwl_mvm_add_chanctx,
3884 .remove_chanctx = iwl_mvm_remove_chanctx,
3885 .change_chanctx = iwl_mvm_change_chanctx,
3886 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
3887 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003888 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003889
Johannes Berg5023d962013-07-31 14:07:43 +02003890 .start_ap = iwl_mvm_start_ap_ibss,
3891 .stop_ap = iwl_mvm_stop_ap_ibss,
3892 .join_ibss = iwl_mvm_start_ap_ibss,
3893 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003894
3895 .set_tim = iwl_mvm_set_tim,
3896
Luciano Coelho622e3f92014-11-10 11:10:17 +02003897 .channel_switch = iwl_mvm_channel_switch,
Luciano Coelhof0289052014-11-10 11:10:06 +02003898 .pre_channel_switch = iwl_mvm_pre_channel_switch,
Luciano Coelhof6c34822014-11-10 11:10:12 +02003899 .post_channel_switch = iwl_mvm_post_channel_switch,
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003900
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +03003901 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
3902 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
3903 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
3904
Emmanuel Grumbachd42f5352015-02-10 14:29:48 +02003905 .event_callback = iwl_mvm_mac_event_callback,
3906
David Spinadel507cadf2013-07-31 18:07:21 +03003907 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
3908
Johannes Berg8ca151b2013-01-24 14:25:36 +01003909#ifdef CONFIG_PM_SLEEP
3910 /* look at d3.c */
3911 .suspend = iwl_mvm_suspend,
3912 .resume = iwl_mvm_resume,
3913 .set_wakeup = iwl_mvm_set_wakeup,
3914 .set_rekey_data = iwl_mvm_set_rekey_data,
3915#if IS_ENABLED(CONFIG_IPV6)
3916 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
3917#endif
3918 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
3919#endif
Johannes Berg91a8bcd2015-01-14 18:12:41 +01003920 .get_survey = iwl_mvm_mac_get_survey,
Johannes Berg33cef922015-01-21 21:41:29 +01003921 .sta_statistics = iwl_mvm_mac_sta_statistics,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003922};