blob: ce5a5ff06d0fbc25a48704a5b7ade1fe07d6102e [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +02009 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020026 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010027 *
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020034 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +020035 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010036 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
47 * distribution.
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *
64 *****************************************************************************/
65#include <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>
Johannes Berg8ca151b2013-01-24 14:25:36 +010073#include <net/mac80211.h>
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +020074#include <net/ieee80211_radiotap.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010075#include <net/tcp.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010076
77#include "iwl-op-mode.h"
78#include "iwl-io.h"
79#include "mvm.h"
80#include "sta.h"
81#include "time-event.h"
82#include "iwl-eeprom-parse.h"
83#include "fw-api-scan.h"
84#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"
Johannes Berg8ca151b2013-01-24 14:25:36 +010089
90static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
91 {
92 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030093 .types = BIT(NL80211_IFTYPE_STATION),
Johannes Berg8ca151b2013-01-24 14:25:36 +010094 },
Johannes Berg3c15a0f2013-05-31 10:17:19 +020095 {
96 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030097 .types = BIT(NL80211_IFTYPE_AP) |
98 BIT(NL80211_IFTYPE_P2P_CLIENT) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +020099 BIT(NL80211_IFTYPE_P2P_GO),
100 },
101 {
102 .max = 1,
103 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
104 },
Johannes Berg8ca151b2013-01-24 14:25:36 +0100105};
106
107static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
108 {
Emmanuel Grumbach2624a5c2014-12-16 13:02:03 +0200109 .num_different_channels = 2,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100110 .max_interfaces = 3,
111 .limits = iwl_mvm_limits,
112 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
113 },
114};
115
Johannes Bergf0c26462013-01-22 20:41:58 +0100116#ifdef CONFIG_PM_SLEEP
117static const struct nl80211_wowlan_tcp_data_token_feature
118iwl_mvm_wowlan_tcp_token_feature = {
119 .min_len = 0,
120 .max_len = 255,
121 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
122};
123
124static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
125 .tok = &iwl_mvm_wowlan_tcp_token_feature,
126 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
127 sizeof(struct ethhdr) -
128 sizeof(struct iphdr) -
129 sizeof(struct tcphdr),
130 .data_interval_max = 65535, /* __le16 in API */
131 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
132 sizeof(struct ethhdr) -
133 sizeof(struct iphdr) -
134 sizeof(struct tcphdr),
135 .seq = true,
136};
137#endif
138
Eliad Peller77736922014-01-14 12:35:49 +0200139#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
Eliad Peller2ee8f022014-01-13 19:07:09 +0200140/*
141 * Use the reserved field to indicate magic values.
142 * these values will only be used internally by the driver,
143 * and won't make it to the fw (reserved will be 0).
144 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
145 * be the vif's ip address. in case there is not a single
146 * ip address (0, or more than 1), this attribute will
147 * be skipped.
148 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
149 * the LSB bytes of the vif's mac address
150 */
151enum {
152 BC_FILTER_MAGIC_NONE = 0,
153 BC_FILTER_MAGIC_IP,
154 BC_FILTER_MAGIC_MAC,
155};
156
Eliad Peller77736922014-01-14 12:35:49 +0200157static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
158 {
159 /* arp */
160 .discard = 0,
161 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
162 .attrs = {
163 {
164 /* frame type - arp, hw type - ethernet */
165 .offset_type =
166 BCAST_FILTER_OFFSET_PAYLOAD_START,
167 .offset = sizeof(rfc1042_header),
168 .val = cpu_to_be32(0x08060001),
169 .mask = cpu_to_be32(0xffffffff),
170 },
Eliad Peller2ee8f022014-01-13 19:07:09 +0200171 {
172 /* arp dest ip */
173 .offset_type =
174 BCAST_FILTER_OFFSET_PAYLOAD_START,
175 .offset = sizeof(rfc1042_header) + 2 +
176 sizeof(struct arphdr) +
177 ETH_ALEN + sizeof(__be32) +
178 ETH_ALEN,
179 .mask = cpu_to_be32(0xffffffff),
180 /* mark it as special field */
181 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
182 },
183 },
184 },
185 {
186 /* dhcp offer bcast */
187 .discard = 0,
188 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
189 .attrs = {
190 {
191 /* udp dest port - 68 (bootp client)*/
192 .offset_type = BCAST_FILTER_OFFSET_IP_END,
193 .offset = offsetof(struct udphdr, dest),
194 .val = cpu_to_be32(0x00440000),
195 .mask = cpu_to_be32(0xffff0000),
196 },
197 {
198 /* dhcp - lsb bytes of client hw address */
199 .offset_type = BCAST_FILTER_OFFSET_IP_END,
200 .offset = 38,
201 .mask = cpu_to_be32(0xffffffff),
202 /* mark it as special field */
203 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
204 },
Eliad Peller77736922014-01-14 12:35:49 +0200205 },
206 },
207 /* last filter must be empty */
208 {},
209};
210#endif
211
Eliad Peller7498cf42014-01-16 17:10:44 +0200212void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
213{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200214 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200215 return;
216
217 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
Eliad Peller576eeee2014-07-01 18:38:38 +0300218 spin_lock_bh(&mvm->refs_lock);
219 mvm->refs[ref_type]++;
220 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200221 iwl_trans_ref(mvm->trans);
222}
223
224void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
225{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200226 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200227 return;
228
229 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
Eliad Peller576eeee2014-07-01 18:38:38 +0300230 spin_lock_bh(&mvm->refs_lock);
231 WARN_ON(!mvm->refs[ref_type]--);
232 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200233 iwl_trans_unref(mvm->trans);
234}
235
Eliad Peller576eeee2014-07-01 18:38:38 +0300236static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
237 enum iwl_mvm_ref_type except_ref)
Eliad Peller7498cf42014-01-16 17:10:44 +0200238{
Eliad Peller576eeee2014-07-01 18:38:38 +0300239 int i, j;
Eliad Peller7498cf42014-01-16 17:10:44 +0200240
Eliad Peller7bb426e2014-02-24 12:54:37 +0200241 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200242 return;
243
Eliad Peller576eeee2014-07-01 18:38:38 +0300244 spin_lock_bh(&mvm->refs_lock);
245 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
246 if (except_ref == i || !mvm->refs[i])
Eliad Peller7498cf42014-01-16 17:10:44 +0200247 continue;
248
Eliad Peller576eeee2014-07-01 18:38:38 +0300249 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
250 i, mvm->refs[i]);
251 for (j = 0; j < mvm->refs[i]; j++)
252 iwl_trans_unref(mvm->trans);
253 mvm->refs[i] = 0;
Eliad Peller7498cf42014-01-16 17:10:44 +0200254 }
Eliad Peller576eeee2014-07-01 18:38:38 +0300255 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200256}
257
Eliad Pellerf4cf8682014-11-04 16:57:06 +0200258bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
259{
260 int i;
261 bool taken = false;
262
263 if (!iwl_mvm_is_d0i3_supported(mvm))
264 return true;
265
266 spin_lock_bh(&mvm->refs_lock);
267 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
268 if (mvm->refs[i]) {
269 taken = true;
270 break;
271 }
272 }
273 spin_unlock_bh(&mvm->refs_lock);
274
275 return taken;
276}
277
Eliad Peller576eeee2014-07-01 18:38:38 +0300278int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
Gregory Greenmand40fc482014-06-25 14:08:50 +0200279{
280 iwl_mvm_ref(mvm, ref_type);
281
282 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
283 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
284 HZ)) {
285 WARN_ON_ONCE(1);
286 iwl_mvm_unref(mvm, ref_type);
287 return -EIO;
288 }
289
290 return 0;
291}
292
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200293static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
294{
295 int i;
296
297 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
298 for (i = 0; i < NUM_PHY_CTX; i++) {
299 mvm->phy_ctxts[i].id = i;
300 mvm->phy_ctxts[i].ref = 0;
301 }
302}
303
Johannes Berg8ca151b2013-01-24 14:25:36 +0100304int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
305{
306 struct ieee80211_hw *hw = mvm->hw;
Ilan Peer831e85f2013-02-07 17:09:09 +0200307 int num_mac, ret, i;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100308
309 /* Tell mac80211 our characteristics */
310 hw->flags = IEEE80211_HW_SIGNAL_DBM |
311 IEEE80211_HW_SPECTRUM_MGMT |
312 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
313 IEEE80211_HW_QUEUE_CONTROL |
314 IEEE80211_HW_WANT_MONITOR_VIF |
Johannes Berg8ca151b2013-01-24 14:25:36 +0100315 IEEE80211_HW_SUPPORTS_PS |
316 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Johannes Bergd2931bb2013-02-05 18:10:04 +0100317 IEEE80211_HW_AMPDU_AGGREGATION |
Hila Gonend64048e2013-03-13 18:00:03 +0200318 IEEE80211_HW_TIMING_BEACON_ONLY |
Emmanuel Grumbach147fc9b2013-07-28 11:00:52 +0300319 IEEE80211_HW_CONNECTION_MONITOR |
Ido Yarivb71d9c82014-07-23 09:31:14 -0400320 IEEE80211_HW_CHANCTX_STA_CSA |
321 IEEE80211_HW_SUPPORTS_CLONED_SKBS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100322
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200323 hw->queues = mvm->first_agg_queue;
Ilan Peer398e8c62013-03-13 15:20:35 +0200324 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +0200325 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
326 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
Eyal Shapira339b3082014-11-18 16:43:55 +0200327 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
328 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100329 hw->rate_control_algorithm = "iwl-mvm-rs";
Johannes Berg848955c2014-11-11 12:48:42 +0100330 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
331 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100332
333 /*
334 * Enable 11w if advertised by firmware and software crypto
335 * is not enabled (as the firmware will interpret some mgmt
336 * packets, so enabling it with software crypto isn't safe)
337 */
338 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
339 !iwlwifi_mod_params.sw_crypto)
340 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
341
Luciano Coelho1f940382015-02-10 13:03:38 +0200342 hw->flags |= IEEE80211_SINGLE_HW_SCAN_ON_ALL_BANDS;
343 hw->wiphy->features |=
344 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
345 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
David Spinadelfb98be52014-05-04 12:51:10 +0300346
Johannes Berg8ca151b2013-01-24 14:25:36 +0100347 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
348 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200349 hw->chanctx_data_size = sizeof(u16);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100350
351 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200352 BIT(NL80211_IFTYPE_P2P_CLIENT) |
353 BIT(NL80211_IFTYPE_AP) |
354 BIT(NL80211_IFTYPE_P2P_GO) |
Emmanuel Grumbachc13b1722014-03-27 19:12:12 +0200355 BIT(NL80211_IFTYPE_P2P_DEVICE) |
356 BIT(NL80211_IFTYPE_ADHOC);
Johannes Berg5023d962013-07-31 14:07:43 +0200357
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +0100358 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
359 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
360 REGULATORY_DISABLE_BEACON_HINTS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100361
Johannes Berg3e56ead2013-02-15 22:23:18 +0100362 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
363 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
364
Emmanuel Grumbach94bbed72014-11-24 08:53:33 +0200365 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +0200366
Johannes Berg8ca151b2013-01-24 14:25:36 +0100367 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
368 hw->wiphy->n_iface_combinations =
369 ARRAY_SIZE(iwl_mvm_iface_combinations);
370
Ilan Peerc451e6d2013-02-20 08:41:54 +0200371 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100372 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
Emmanuel Grumbachf1a68542014-12-16 12:31:13 +0200373 /* we can compensate an offset of up to 3 channels = 15 MHz */
374 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100375
376 /* Extract MAC address */
377 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
378 hw->wiphy->addresses = mvm->addresses;
379 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200380
381 /* Extract additional MAC addresses if available */
382 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
383 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
384
385 for (i = 1; i < num_mac; i++) {
386 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100387 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200388 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100389 hw->wiphy->n_addresses++;
390 }
391
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200392 iwl_mvm_reset_phy_ctxts(mvm);
393
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300394 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm, false);
David Spinadel20f1a5d2013-08-21 09:14:27 +0300395
Johannes Berg8ca151b2013-01-24 14:25:36 +0100396 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
397
398 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
399 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
400 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
Eyal Shapira3d44eeb2015-01-16 22:37:04 +0200401 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100402 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
403 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
404
Eyal Shapira3d44eeb2015-01-16 22:37:04 +0200405 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_BEAMFORMER)
406 hw->wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap.cap |=
407 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
408 }
409
Johannes Berg8ca151b2013-01-24 14:25:36 +0100410 hw->wiphy->hw_version = mvm->trans->hw_id;
411
Alexander Bondarade50652013-04-03 16:28:47 +0300412 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100413 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
414 else
415 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
416
Emmanuel Grumbach6efaaf32014-09-01 10:03:21 +0300417 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 10) {
418 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
419 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
420 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
421 /* we create the 802.11 header and zero length SSID IE. */
422 hw->wiphy->max_sched_scan_ie_len =
423 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
424 }
David Spinadel35a000b2013-08-28 09:29:43 +0300425
Johannes Berg8ca151b2013-01-24 14:25:36 +0100426 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
Johannes Bergab480032014-06-04 10:13:50 +0200427 NL80211_FEATURE_LOW_PRIORITY_SCAN |
Eliad Peller0d8614b2014-09-10 14:07:36 +0300428 NL80211_FEATURE_P2P_GO_OPPPS |
429 NL80211_FEATURE_DYNAMIC_SMPS |
Emmanuel Grumbach9b5452f2014-10-07 10:38:53 +0300430 NL80211_FEATURE_STATIC_SMPS |
431 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100432
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300433 if (mvm->fw->ucode_capa.capa[0] &
434 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)
435 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
Assaf Krauss226bcd42014-03-13 08:12:15 +0200436 if (mvm->fw->ucode_capa.capa[0] &
437 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)
438 hw->wiphy->features |= NL80211_FEATURE_QUIET;
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300439
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300440 if (mvm->fw->ucode_capa.capa[0] &
441 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)
442 hw->wiphy->features |=
443 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
444
445 if (mvm->fw->ucode_capa.capa[0] &
446 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)
447 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
448
Johannes Berg8ca151b2013-01-24 14:25:36 +0100449 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
450
Max Stepanove36e5432013-08-27 19:56:13 +0300451 /* currently FW API supports only one optional cipher scheme */
Johannes Berg9ddca862014-01-06 09:29:40 +0100452 if (mvm->fw->cs[0].cipher) {
Max Stepanove36e5432013-08-27 19:56:13 +0300453 mvm->hw->n_cipher_schemes = 1;
Johannes Berg9ddca862014-01-06 09:29:40 +0100454 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
Max Stepanove36e5432013-08-27 19:56:13 +0300455 }
456
Johannes Berg8ca151b2013-01-24 14:25:36 +0100457#ifdef CONFIG_PM_SLEEP
Eliad Pellerd15a7472014-03-27 18:53:12 +0200458 if (iwl_mvm_is_d0i3_supported(mvm) &&
459 device_can_wakeup(mvm->trans->dev)) {
460 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
461 hw->wiphy->wowlan = &mvm->wowlan;
Eliad Peller91742442014-12-09 15:54:46 +0200462 }
463
464 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100465 mvm->trans->ops->d3_suspend &&
466 mvm->trans->ops->d3_resume &&
467 device_can_wakeup(mvm->trans->dev)) {
Eliad Peller91742442014-12-09 15:54:46 +0200468 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
469 WIPHY_WOWLAN_DISCONNECT |
470 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
471 WIPHY_WOWLAN_RFKILL_RELEASE |
472 WIPHY_WOWLAN_NET_DETECT;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100473 if (!iwlwifi_mod_params.sw_crypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200474 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
475 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
476 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100477
Johannes Berg964dc9e2013-06-03 17:25:34 +0200478 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
479 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
480 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
Luciano Coelhoc55385f2014-10-24 10:39:51 +0300481 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
Johannes Berg964dc9e2013-06-03 17:25:34 +0200482 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
483 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100484 }
485#endif
486
Eliad Peller77736922014-01-14 12:35:49 +0200487#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
488 /* assign default bcast filtering configuration */
489 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
490#endif
491
Johannes Berg8ca151b2013-01-24 14:25:36 +0100492 ret = iwl_mvm_leds_init(mvm);
493 if (ret)
494 return ret;
495
Arik Nemtsovd8f1c512014-05-11 18:13:04 +0300496 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_TDLS_SUPPORT) {
497 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
498 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
499 }
500
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +0300501 if (mvm->fw->ucode_capa.capa[0] &
502 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH) {
503 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
504 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
505 }
506
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300507 ret = ieee80211_register_hw(mvm->hw);
508 if (ret)
509 iwl_mvm_leds_exit(mvm);
510
511 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100512}
513
Arik Nemtsovb2492502014-03-13 12:21:50 +0200514static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
515 struct ieee80211_sta *sta,
516 struct sk_buff *skb)
517{
518 struct iwl_mvm_sta *mvmsta;
519 bool defer = false;
520
521 /*
522 * double check the IN_D0I3 flag both before and after
523 * taking the spinlock, in order to prevent taking
524 * the spinlock when not needed.
525 */
526 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
527 return false;
528
529 spin_lock(&mvm->d0i3_tx_lock);
530 /*
531 * testing the flag again ensures the skb dequeue
532 * loop (on d0i3 exit) hasn't run yet.
533 */
534 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
535 goto out;
536
537 mvmsta = iwl_mvm_sta_from_mac80211(sta);
538 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
539 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
540 goto out;
541
542 __skb_queue_tail(&mvm->d0i3_tx, skb);
543 ieee80211_stop_queues(mvm->hw);
544
545 /* trigger wakeup */
546 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
547 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
548
549 defer = true;
550out:
551 spin_unlock(&mvm->d0i3_tx_lock);
552 return defer;
553}
554
Johannes Berg8ca151b2013-01-24 14:25:36 +0100555static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
556 struct ieee80211_tx_control *control,
557 struct sk_buff *skb)
558{
559 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg3e56ead2013-02-15 22:23:18 +0100560 struct ieee80211_sta *sta = control->sta;
561 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
562 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100563
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300564 if (iwl_mvm_is_radio_killed(mvm)) {
565 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100566 goto drop;
567 }
568
Ilan Peer398e8c62013-03-13 15:20:35 +0200569 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Matti Gottlieba6cc5162014-09-29 11:46:04 +0300570 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
571 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100572 goto drop;
573
Johannes Berg3e56ead2013-02-15 22:23:18 +0100574 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
575 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
576 ieee80211_is_mgmt(hdr->frame_control) &&
577 !ieee80211_is_deauth(hdr->frame_control) &&
578 !ieee80211_is_disassoc(hdr->frame_control) &&
579 !ieee80211_is_action(hdr->frame_control)))
580 sta = NULL;
581
582 if (sta) {
Arik Nemtsovb2492502014-03-13 12:21:50 +0200583 if (iwl_mvm_defer_tx(mvm, sta, skb))
584 return;
Johannes Berg3e56ead2013-02-15 22:23:18 +0100585 if (iwl_mvm_tx_skb(mvm, skb, sta))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100586 goto drop;
587 return;
588 }
589
590 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
591 goto drop;
592 return;
593 drop:
594 ieee80211_free_txskb(hw, skb);
595}
596
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200597static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
598{
599 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
600 return false;
601 return true;
602}
603
604static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
605{
606 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
607 return false;
608 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
609 return true;
610
611 /* enabled by default */
612 return true;
613}
614
Johannes Berg8ca151b2013-01-24 14:25:36 +0100615static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
616 struct ieee80211_vif *vif,
617 enum ieee80211_ampdu_mlme_action action,
618 struct ieee80211_sta *sta, u16 tid,
619 u16 *ssn, u8 buf_size)
620{
621 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
622 int ret;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200623 bool tx_agg_ref = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100624
625 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
626 sta->addr, tid, action);
627
628 if (!(mvm->nvm_data->sku_cap_11n_enable))
629 return -EACCES;
630
Arik Nemtsovb2492502014-03-13 12:21:50 +0200631 /* return from D0i3 before starting a new Tx aggregation */
Eliad Peller9256c202014-04-22 13:33:29 +0300632 switch (action) {
633 case IEEE80211_AMPDU_TX_START:
634 case IEEE80211_AMPDU_TX_STOP_CONT:
635 case IEEE80211_AMPDU_TX_STOP_FLUSH:
636 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
637 case IEEE80211_AMPDU_TX_OPERATIONAL:
Arik Nemtsovb2492502014-03-13 12:21:50 +0200638 /*
Eliad Peller9256c202014-04-22 13:33:29 +0300639 * for tx start, wait synchronously until D0i3 exit to
640 * get the correct sequence number for the tid.
641 * additionally, some other ampdu actions use direct
642 * target access, which is not handled automatically
643 * by the trans layer (unlike commands), so wait for
644 * d0i3 exit in these cases as well.
Arik Nemtsovb2492502014-03-13 12:21:50 +0200645 */
Gregory Greenmand40fc482014-06-25 14:08:50 +0200646 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
647 if (ret)
648 return ret;
649
650 tx_agg_ref = true;
Eliad Peller9256c202014-04-22 13:33:29 +0300651 break;
652 default:
653 break;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200654 }
655
Johannes Berg8ca151b2013-01-24 14:25:36 +0100656 mutex_lock(&mvm->mutex);
657
658 switch (action) {
659 case IEEE80211_AMPDU_RX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200660 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100661 ret = -EINVAL;
662 break;
663 }
664 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
665 break;
666 case IEEE80211_AMPDU_RX_STOP:
667 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
668 break;
669 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200670 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200671 ret = -EINVAL;
672 break;
673 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100674 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
675 break;
676 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200677 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
678 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100679 case IEEE80211_AMPDU_TX_STOP_FLUSH:
680 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200681 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100682 break;
683 case IEEE80211_AMPDU_TX_OPERATIONAL:
684 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
685 break;
686 default:
687 WARN_ON_ONCE(1);
688 ret = -EINVAL;
689 break;
690 }
691 mutex_unlock(&mvm->mutex);
692
Arik Nemtsovb2492502014-03-13 12:21:50 +0200693 /*
694 * If the tid is marked as started, we won't use it for offloaded
695 * traffic on the next D0i3 entry. It's safe to unref.
696 */
697 if (tx_agg_ref)
698 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
699
Johannes Berg8ca151b2013-01-24 14:25:36 +0100700 return ret;
701}
702
703static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
704 struct ieee80211_vif *vif)
705{
706 struct iwl_mvm *mvm = data;
707 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
708
709 mvmvif->uploaded = false;
710 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
711
Johannes Berg8ca151b2013-01-24 14:25:36 +0100712 spin_lock_bh(&mvm->time_event_lock);
713 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
714 spin_unlock_bh(&mvm->time_event_lock);
715
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200716 mvmvif->phy_ctxt = NULL;
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +0300717 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100718}
719
Johannes Bergaadede62014-10-09 17:01:36 +0200720static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count,
721 const void *data, size_t datalen)
722{
723 const struct iwl_mvm_dump_ptrs *dump_ptrs = data;
724 ssize_t bytes_read;
725 ssize_t bytes_read_trans;
726
727 if (offset < dump_ptrs->op_mode_len) {
728 bytes_read = min_t(ssize_t, count,
729 dump_ptrs->op_mode_len - offset);
730 memcpy(buffer, (u8 *)dump_ptrs->op_mode_ptr + offset,
731 bytes_read);
732 offset += bytes_read;
733 count -= bytes_read;
734
735 if (count == 0)
736 return bytes_read;
737 } else {
738 bytes_read = 0;
739 }
740
741 if (!dump_ptrs->trans_ptr)
742 return bytes_read;
743
744 offset -= dump_ptrs->op_mode_len;
745 bytes_read_trans = min_t(ssize_t, count,
746 dump_ptrs->trans_ptr->len - offset);
747 memcpy(buffer + bytes_read,
748 (u8 *)dump_ptrs->trans_ptr->data + offset,
749 bytes_read_trans);
750
751 return bytes_read + bytes_read_trans;
752}
753
754static void iwl_mvm_free_coredump(const void *data)
755{
756 const struct iwl_mvm_dump_ptrs *fw_error_dump = data;
757
758 vfree(fw_error_dump->op_mode_ptr);
759 vfree(fw_error_dump->trans_ptr);
760 kfree(fw_error_dump);
761}
762
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200763static void iwl_mvm_dump_fifos(struct iwl_mvm *mvm,
764 struct iwl_fw_error_dump_data **dump_data)
765{
766 struct iwl_fw_error_dump_fifo *fifo_hdr;
767 u32 *fifo_data;
768 u32 fifo_len;
769 unsigned long flags;
770 int i, j;
771
772 if (!iwl_trans_grab_nic_access(mvm->trans, false, &flags))
773 return;
774
775 /* Pull RXF data from all RXFs */
776 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++) {
777 /*
778 * Keep aside the additional offset that might be needed for
779 * next RXF
780 */
781 u32 offset_diff = RXF_DIFF_FROM_PREV * i;
782
783 fifo_hdr = (void *)(*dump_data)->data;
784 fifo_data = (void *)fifo_hdr->data;
785 fifo_len = mvm->shared_mem_cfg.rxfifo_size[i];
786
787 /* No need to try to read the data if the length is 0 */
788 if (fifo_len == 0)
789 continue;
790
791 /* Add a TLV for the RXF */
792 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
793 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
794
795 fifo_hdr->fifo_num = cpu_to_le32(i);
796 fifo_hdr->available_bytes =
797 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
798 RXF_RD_D_SPACE +
799 offset_diff));
800 fifo_hdr->wr_ptr =
801 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
802 RXF_RD_WR_PTR +
803 offset_diff));
804 fifo_hdr->rd_ptr =
805 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
806 RXF_RD_RD_PTR +
807 offset_diff));
808 fifo_hdr->fence_ptr =
809 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
810 RXF_RD_FENCE_PTR +
811 offset_diff));
812 fifo_hdr->fence_mode =
813 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
814 RXF_SET_FENCE_MODE +
815 offset_diff));
816
817 /* Lock fence */
818 iwl_trans_write_prph(mvm->trans,
819 RXF_SET_FENCE_MODE + offset_diff, 0x1);
820 /* Set fence pointer to the same place like WR pointer */
821 iwl_trans_write_prph(mvm->trans,
822 RXF_LD_WR2FENCE + offset_diff, 0x1);
823 /* Set fence offset */
824 iwl_trans_write_prph(mvm->trans,
825 RXF_LD_FENCE_OFFSET_ADDR + offset_diff,
826 0x0);
827
828 /* Read FIFO */
829 fifo_len /= sizeof(u32); /* Size in DWORDS */
830 for (j = 0; j < fifo_len; j++)
831 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
832 RXF_FIFO_RD_FENCE_INC +
833 offset_diff);
834 *dump_data = iwl_fw_error_next_data(*dump_data);
835 }
836
837 /* Pull TXF data from all TXFs */
838 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++) {
839 /* Mark the number of TXF we're pulling now */
840 iwl_trans_write_prph(mvm->trans, TXF_LARC_NUM, i);
841
842 fifo_hdr = (void *)(*dump_data)->data;
843 fifo_data = (void *)fifo_hdr->data;
844 fifo_len = mvm->shared_mem_cfg.txfifo_size[i];
845
846 /* No need to try to read the data if the length is 0 */
847 if (fifo_len == 0)
848 continue;
849
850 /* Add a TLV for the FIFO */
851 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXF);
852 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
853
854 fifo_hdr->fifo_num = cpu_to_le32(i);
855 fifo_hdr->available_bytes =
856 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
857 TXF_FIFO_ITEM_CNT));
858 fifo_hdr->wr_ptr =
859 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
860 TXF_WR_PTR));
861 fifo_hdr->rd_ptr =
862 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
863 TXF_RD_PTR));
864 fifo_hdr->fence_ptr =
865 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
866 TXF_FENCE_PTR));
867 fifo_hdr->fence_mode =
868 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
869 TXF_LOCK_FENCE));
870
871 /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */
872 iwl_trans_write_prph(mvm->trans, TXF_READ_MODIFY_ADDR,
873 TXF_WR_PTR);
874
875 /* Dummy-read to advance the read pointer to the head */
876 iwl_trans_read_prph(mvm->trans, TXF_READ_MODIFY_DATA);
877
878 /* Read FIFO */
879 fifo_len /= sizeof(u32); /* Size in DWORDS */
880 for (j = 0; j < fifo_len; j++)
881 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
882 TXF_READ_MODIFY_DATA);
883 *dump_data = iwl_fw_error_next_data(*dump_data);
884 }
885
886 iwl_trans_release_nic_access(mvm->trans, &flags);
887}
888
Emmanuel Grumbach4bfa47f2014-09-11 16:19:43 +0300889void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300890{
891 struct iwl_fw_error_dump_file *dump_file;
892 struct iwl_fw_error_dump_data *dump_data;
893 struct iwl_fw_error_dump_info *dump_info;
Emmanuel Grumbacha549b292014-12-09 14:47:57 +0200894 struct iwl_fw_error_dump_mem *dump_mem;
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300895 struct iwl_mvm_dump_ptrs *fw_error_dump;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300896 u32 sram_len, sram_ofs;
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200897 u32 file_len, fifo_data_len = 0;
Liad Kaufmanaddfaad2014-12-02 11:16:04 +0200898 u32 smem_len = mvm->cfg->smem_len;
Ido Yariv86138322014-12-10 12:39:27 -0500899 u32 sram2_len = mvm->cfg->dccm2_len;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300900
901 lockdep_assert_held(&mvm->mutex);
902
Liad Kaufmanaddfaad2014-12-02 11:16:04 +0200903 /* W/A for 8000 HW family A-step */
Ido Yariv86138322014-12-10 12:39:27 -0500904 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
905 CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_A_STEP) {
906 if (smem_len)
907 smem_len = 0x38000;
908
909 if (sram2_len)
910 sram2_len = 0x10000;
911 }
Liad Kaufmanaddfaad2014-12-02 11:16:04 +0200912
Johannes Bergaadede62014-10-09 17:01:36 +0200913 fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300914 if (!fw_error_dump)
915 return;
916
Liad Kaufmanf53bf4c2014-12-01 10:44:18 +0200917 /* SRAM - include stack CCM if driver knows the values for it */
918 if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
919 const struct fw_img *img;
920
921 img = &mvm->fw->img[mvm->cur_ucode];
922 sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
923 sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
924 } else {
925 sram_ofs = mvm->cfg->dccm_offset;
926 sram_len = mvm->cfg->dccm_len;
927 }
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300928
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200929 /* reading RXF/TXF sizes */
930 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
931 struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->shared_mem_cfg;
932 int i;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300933
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200934 fifo_data_len = 0;
935
936 /* Count RXF size */
937 for (i = 0; i < ARRAY_SIZE(mem_cfg->rxfifo_size); i++) {
938 if (!mem_cfg->rxfifo_size[i])
939 continue;
940
941 /* Add header info */
942 fifo_data_len += mem_cfg->rxfifo_size[i] +
943 sizeof(*dump_data) +
944 sizeof(struct iwl_fw_error_dump_fifo);
945 }
946
947 for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++) {
948 if (!mem_cfg->txfifo_size[i])
949 continue;
950
951 /* Add header info */
952 fifo_data_len += mem_cfg->txfifo_size[i] +
953 sizeof(*dump_data) +
954 sizeof(struct iwl_fw_error_dump_fifo);
955 }
956 }
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300957
958 file_len = sizeof(*dump_file) +
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200959 sizeof(*dump_data) * 2 +
Emmanuel Grumbacha549b292014-12-09 14:47:57 +0200960 sram_len + sizeof(*dump_mem) +
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200961 fifo_data_len +
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300962 sizeof(*dump_info);
963
Liad Kaufmanaddfaad2014-12-02 11:16:04 +0200964 /* Make room for the SMEM, if it exists */
965 if (smem_len)
Emmanuel Grumbacha549b292014-12-09 14:47:57 +0200966 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
Liad Kaufmanaddfaad2014-12-02 11:16:04 +0200967
Ido Yariv86138322014-12-10 12:39:27 -0500968 /* Make room for the secondary SRAM, if it exists */
969 if (sram2_len)
970 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len;
971
Emmanuel Grumbach5bfe6f52014-06-25 16:21:43 +0300972 dump_file = vzalloc(file_len);
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300973 if (!dump_file) {
974 kfree(fw_error_dump);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300975 return;
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300976 }
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300977
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300978 fw_error_dump->op_mode_ptr = dump_file;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300979
980 dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300981 dump_data = (void *)dump_file->data;
982
983 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
984 dump_data->len = cpu_to_le32(sizeof(*dump_info));
985 dump_info = (void *) dump_data->data;
986 dump_info->device_family =
987 mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
988 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
989 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
Ido Yariv435da2c2014-12-11 16:11:01 -0500990 dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300991 memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
992 sizeof(dump_info->fw_human_readable));
993 strncpy(dump_info->dev_human_readable, mvm->cfg->name,
994 sizeof(dump_info->dev_human_readable));
995 strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
996 sizeof(dump_info->bus_human_readable));
997
998 dump_data = iwl_fw_error_next_data(dump_data);
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200999 /* We only dump the FIFOs if the FW is in error state */
1000 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status))
1001 iwl_mvm_dump_fifos(mvm, &dump_data);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001002
Emmanuel Grumbacha549b292014-12-09 14:47:57 +02001003 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1004 dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
1005 dump_mem = (void *)dump_data->data;
1006 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
1007 dump_mem->offset = cpu_to_le32(sram_ofs);
1008 iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001009 sram_len);
1010
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001011 if (smem_len) {
1012 dump_data = iwl_fw_error_next_data(dump_data);
Emmanuel Grumbache06d8432014-12-09 14:36:41 +02001013 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1014 dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
1015 dump_mem = (void *)dump_data->data;
1016 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
1017 dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001018 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
Emmanuel Grumbache06d8432014-12-09 14:36:41 +02001019 dump_mem->data, smem_len);
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001020 }
1021
Ido Yariv86138322014-12-10 12:39:27 -05001022 if (sram2_len) {
1023 dump_data = iwl_fw_error_next_data(dump_data);
1024 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1025 dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem));
1026 dump_mem = (void *)dump_data->data;
1027 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
1028 dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset);
1029 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset,
1030 dump_mem->data, sram2_len);
1031 }
1032
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +03001033 fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans);
1034 fw_error_dump->op_mode_len = file_len;
1035 if (fw_error_dump->trans_ptr)
1036 file_len += fw_error_dump->trans_ptr->len;
1037 dump_file->file_len = cpu_to_le32(file_len);
Emmanuel Grumbach4bfa47f2014-09-11 16:19:43 +03001038
Johannes Bergaadede62014-10-09 17:01:36 +02001039 dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
1040 GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001041}
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001042
Johannes Berg8ca151b2013-01-24 14:25:36 +01001043static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1044{
Johannes Berg58629d92014-11-06 09:40:50 +01001045 /* clear the D3 reconfig, we only need it to avoid dumping a
1046 * firmware coredump on reconfiguration, we shouldn't do that
1047 * on D3->D0 transition
1048 */
1049 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status))
1050 iwl_mvm_fw_error_dump(mvm);
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +02001051
Eliad Peller744cb692014-12-10 18:44:13 +02001052 /* cleanup all stale references (scan, roc), but keep the
1053 * ucode_down ref until reconfig is complete
1054 */
1055 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1056
Johannes Berg8ca151b2013-01-24 14:25:36 +01001057 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001058
1059 mvm->scan_status = IWL_MVM_SCAN_NONE;
Luciano Coelhob1873302014-08-08 17:12:07 +03001060 mvm->ps_disabled = false;
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +02001061 mvm->calibrating = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001062
1063 /* just in case one was running */
1064 ieee80211_remain_on_channel_expired(mvm->hw);
1065
1066 ieee80211_iterate_active_interfaces_atomic(
1067 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1068 iwl_mvm_cleanup_iterator, mvm);
1069
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001070 mvm->p2p_device_vif = NULL;
Eliad Peller37577fe2013-12-05 17:19:39 +02001071 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001072
1073 iwl_mvm_reset_phy_ctxts(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001074 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1075 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001076 memset(mvm->tfd_drained, 0, sizeof(mvm->tfd_drained));
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +03001077 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1078 memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
1079 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1080 memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
1081 memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk));
1082 memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001083
1084 ieee80211_wake_queues(mvm->hw);
1085
Eliad Peller228670b2014-08-10 17:00:15 +03001086 /* clear any stale d0i3 state */
1087 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1088
Johannes Berg8ca151b2013-01-24 14:25:36 +01001089 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03001090 mvm->rx_ba_sessions = 0;
Johannes Berg91a8bcd2015-01-14 18:12:41 +01001091
1092 /* keep statistics ticking */
1093 iwl_mvm_accu_radio_stats(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001094}
1095
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001096int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001097{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001098 int ret;
1099
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001100 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001101
1102 /* Clean up some internal and mac80211 state on restart */
1103 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1104 iwl_mvm_restart_cleanup(mvm);
1105
1106 ret = iwl_mvm_up(mvm);
Johannes Bergc47af222014-04-30 16:34:45 +02001107
1108 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1109 /* Something went wrong - we need to finish some cleanup
1110 * that normally iwl_mvm_mac_restart_complete() below
1111 * would do.
1112 */
1113 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1114 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1115 }
1116
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001117 return ret;
1118}
1119
1120static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1121{
1122 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1123 int ret;
1124
Eliad Peller37948fc2014-12-11 10:48:18 +02001125 /* Some hw restart cleanups must not hold the mutex */
1126 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1127 /*
1128 * Make sure we are out of d0i3. This is needed
1129 * to make sure the reference accounting is correct
1130 * (and there is no stale d0i3_exit_work).
1131 */
1132 wait_event_timeout(mvm->d0i3_exit_waitq,
1133 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1134 &mvm->status),
1135 HZ);
1136 }
1137
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001138 mutex_lock(&mvm->mutex);
1139 ret = __iwl_mvm_mac_start(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001140 mutex_unlock(&mvm->mutex);
1141
1142 return ret;
1143}
1144
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001145static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001146{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001147 int ret;
1148
1149 mutex_lock(&mvm->mutex);
1150
1151 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
Arik Nemtsovb2492502014-03-13 12:21:50 +02001152 iwl_mvm_d0i3_enable_tx(mvm, NULL);
Johannes Berg01662302014-06-06 15:18:45 +02001153 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001154 if (ret)
1155 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1156 ret);
1157
Eliad Peller7498cf42014-01-16 17:10:44 +02001158 /* allow transport/FW low power modes */
1159 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1160
Arik Nemtsovcbd2ae22014-09-14 19:13:54 +03001161 /*
1162 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1163 * of packets the FW sent out, so we must reconnect.
1164 */
1165 iwl_mvm_teardown_tdls_peers(mvm);
1166
Johannes Berg8ca151b2013-01-24 14:25:36 +01001167 mutex_unlock(&mvm->mutex);
1168}
1169
Eliad Peller088070a2014-10-20 18:42:58 +03001170static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1171{
1172 bool exit_now;
1173
1174 if (!iwl_mvm_is_d0i3_supported(mvm))
1175 return;
1176
1177 mutex_lock(&mvm->d0i3_suspend_mutex);
1178 __clear_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags);
1179 exit_now = __test_and_clear_bit(D0I3_PENDING_WAKEUP,
1180 &mvm->d0i3_suspend_flags);
1181 mutex_unlock(&mvm->d0i3_suspend_mutex);
1182
1183 if (exit_now) {
1184 IWL_DEBUG_RPM(mvm, "Run deferred d0i3 exit\n");
1185 _iwl_mvm_exit_d0i3(mvm);
1186 }
Eliad Peller67359432014-12-09 15:23:54 +02001187
1188 if (mvm->trans->d0i3_mode == IWL_D0I3_MODE_ON_SUSPEND)
1189 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
1190 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1191 &mvm->status),
1192 HZ))
1193 WARN_ONCE(1, "D0i3 exit on resume timed out\n");
Eliad Peller088070a2014-10-20 18:42:58 +03001194}
1195
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001196static void
1197iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1198 enum ieee80211_reconfig_type reconfig_type)
1199{
1200 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1201
1202 switch (reconfig_type) {
1203 case IEEE80211_RECONFIG_TYPE_RESTART:
1204 iwl_mvm_restart_complete(mvm);
1205 break;
1206 case IEEE80211_RECONFIG_TYPE_SUSPEND:
Eliad Peller088070a2014-10-20 18:42:58 +03001207 iwl_mvm_resume_complete(mvm);
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001208 break;
1209 }
1210}
1211
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001212void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001213{
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001214 lockdep_assert_held(&mvm->mutex);
Eliad Peller7498cf42014-01-16 17:10:44 +02001215
Johannes Berg91a8bcd2015-01-14 18:12:41 +01001216 /* firmware counters are obviously reset now, but we shouldn't
1217 * partially track so also clear the fw_reset_accu counters.
1218 */
1219 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1220
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001221 /*
1222 * Disallow low power states when the FW is down by taking
1223 * the UCODE_DOWN ref. in case of ongoing hw restart the
1224 * ref is already taken, so don't take it again.
1225 */
1226 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1227 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
Eliad Peller7498cf42014-01-16 17:10:44 +02001228
Johannes Berg8ca151b2013-01-24 14:25:36 +01001229 /* async_handlers_wk is now blocked */
1230
1231 /*
1232 * The work item could be running or queued if the
1233 * ROC time event stops just as we get here.
1234 */
1235 cancel_work_sync(&mvm->roc_done_wk);
1236
1237 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001238
1239 iwl_mvm_async_handlers_purge(mvm);
1240 /* async_handlers_list is empty and will stay empty: HW is stopped */
1241
1242 /* the fw is stopped, the aux sta is dead: clean up driver state */
Johannes Berg712b24a2014-08-04 14:14:14 +02001243 iwl_mvm_del_aux_sta(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001244
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001245 /*
1246 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1247 * won't be called in this case).
1248 */
1249 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1250
Luciano Coelhobc448862014-08-20 11:49:11 +03001251 mvm->ucode_loaded = false;
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001252}
Luciano Coelhobc448862014-08-20 11:49:11 +03001253
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001254static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1255{
1256 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1257
1258 flush_work(&mvm->d0i3_exit_work);
1259 flush_work(&mvm->async_handlers_wk);
Emmanuel Grumbach4bfa47f2014-09-11 16:19:43 +03001260 flush_work(&mvm->fw_error_dump_wk);
Luciano Coelhoa0a09242014-09-04 12:29:15 +03001261
1262 mutex_lock(&mvm->mutex);
1263 __iwl_mvm_mac_stop(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001264 mutex_unlock(&mvm->mutex);
1265
1266 /*
1267 * The worker might have been waiting for the mutex, let it run and
1268 * discover that its list is now empty.
1269 */
1270 cancel_work_sync(&mvm->async_handlers_wk);
1271}
1272
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001273static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1274{
1275 u16 i;
1276
1277 lockdep_assert_held(&mvm->mutex);
1278
1279 for (i = 0; i < NUM_PHY_CTX; i++)
1280 if (!mvm->phy_ctxts[i].ref)
1281 return &mvm->phy_ctxts[i];
1282
1283 IWL_ERR(mvm, "No available PHY context\n");
1284 return NULL;
1285}
1286
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +02001287static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1288 s8 tx_power)
1289{
1290 /* FW is in charge of regulatory enforcement */
1291 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
1292 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
1293 .pwr_restriction = cpu_to_le16(tx_power),
1294 };
1295
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001296 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +02001297 sizeof(reduce_txpwr_cmd),
1298 &reduce_txpwr_cmd);
1299}
1300
Johannes Berg8ca151b2013-01-24 14:25:36 +01001301static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1302 struct ieee80211_vif *vif)
1303{
1304 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1305 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1306 int ret;
1307
1308 /*
Gregory Greenmand40fc482014-06-25 14:08:50 +02001309 * make sure D0i3 exit is completed, otherwise a target access
1310 * during tx queue configuration could be done when still in
1311 * D0i3 state.
1312 */
1313 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1314 if (ret)
1315 return ret;
1316
1317 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001318 * Not much to do here. The stack will not allow interface
1319 * types or combinations that we didn't advertise, so we
1320 * don't really have to check the types.
1321 */
1322
1323 mutex_lock(&mvm->mutex);
1324
Johannes Berg33cef922015-01-21 21:41:29 +01001325 /* make sure that beacon statistics don't go backwards with FW reset */
1326 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1327 mvmvif->beacon_stats.accu_num_beacons +=
1328 mvmvif->beacon_stats.num_beacons;
1329
Eliad Pellere89044d2013-07-16 17:33:26 +03001330 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001331 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1332 if (ret)
1333 goto out_unlock;
1334
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001335 /* Counting number of interfaces is needed for legacy PM */
Ilan Peerea183d02013-07-23 14:41:53 +03001336 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1337 mvm->vif_count++;
Ilan Peerea183d02013-07-23 14:41:53 +03001338
1339 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001340 * The AP binding flow can be done only after the beacon
1341 * template is configured (which happens only in the mac80211
1342 * start_ap() flow), and adding the broadcast station can happen
1343 * only after the binding.
1344 * In addition, since modifying the MAC before adding a bcast
1345 * station is not allowed by the FW, delay the adding of MAC context to
1346 * the point where we can also add the bcast station.
1347 * In short: there's not much we can do at this point, other than
1348 * allocating resources :)
1349 */
Johannes Berg5023d962013-07-31 14:07:43 +02001350 if (vif->type == NL80211_IFTYPE_AP ||
1351 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg013290a2014-08-04 13:38:48 +02001352 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001353 if (ret) {
1354 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1355 goto out_release;
1356 }
1357
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +03001358 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001359 goto out_unlock;
1360 }
1361
Johannes Berg8ca151b2013-01-24 14:25:36 +01001362 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1363 if (ret)
1364 goto out_release;
1365
Arik Nemtsov999609f2014-05-15 17:31:51 +03001366 ret = iwl_mvm_power_update_mac(mvm);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001367 if (ret)
Luciano Coelhofd66fc12015-01-27 15:06:57 +02001368 goto out_remove_mac;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001369
Hila Gonen7df15b12012-12-12 11:16:19 +02001370 /* beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001371 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001372 if (ret)
1373 goto out_remove_mac;
1374
Hila Gonen7df15b12012-12-12 11:16:19 +02001375 if (!mvm->bf_allowed_vif &&
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +03001376 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001377 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001378 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1379 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +02001380 }
1381
Johannes Berg8ca151b2013-01-24 14:25:36 +01001382 /*
1383 * P2P_DEVICE interface does not have a channel context assigned to it,
1384 * so a dedicated PHY context is allocated to it and the corresponding
1385 * MAC context is bound to it at this stage.
1386 */
1387 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001388
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001389 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1390 if (!mvmvif->phy_ctxt) {
1391 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001392 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001393 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001394
Ilan Peer53a9d612013-04-28 11:55:08 +03001395 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001396 ret = iwl_mvm_binding_add_vif(mvm, vif);
1397 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +03001398 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001399
Johannes Berg013290a2014-08-04 13:38:48 +02001400 ret = iwl_mvm_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001401 if (ret)
1402 goto out_unbind;
1403
1404 /* Save a pointer to p2p device vif, so it can later be used to
1405 * update the p2p device MAC when a GO is started/stopped */
1406 mvm->p2p_device_vif = vif;
1407 }
1408
Johannes Berg63494372013-03-26 10:47:53 +01001409 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001410 goto out_unlock;
1411
1412 out_unbind:
1413 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +03001414 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001415 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001416 out_free_bf:
1417 if (mvm->bf_allowed_vif == mvmvif) {
1418 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001419 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1420 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001421 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001422 out_remove_mac:
1423 mvmvif->phy_ctxt = NULL;
1424 iwl_mvm_mac_ctxt_remove(mvm, vif);
1425 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001426 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1427 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001428
Johannes Berg8ca151b2013-01-24 14:25:36 +01001429 iwl_mvm_mac_ctxt_release(mvm, vif);
1430 out_unlock:
1431 mutex_unlock(&mvm->mutex);
1432
Gregory Greenmand40fc482014-06-25 14:08:50 +02001433 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1434
Johannes Berg8ca151b2013-01-24 14:25:36 +01001435 return ret;
1436}
1437
Johannes Berg38a12b52013-02-22 14:07:56 +01001438static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1439 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001440{
Arik Nemtsovd92b732e2014-09-21 19:00:42 +03001441 u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001442
1443 if (tfd_msk) {
1444 mutex_lock(&mvm->mutex);
1445 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
1446 mutex_unlock(&mvm->mutex);
1447 }
1448
1449 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1450 /*
1451 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1452 * We assume here that all the packets sent to the OFFCHANNEL
1453 * queue are sent in ROC session.
1454 */
1455 flush_work(&mvm->roc_done_wk);
1456 } else {
1457 /*
1458 * By now, all the AC queues are empty. The AGG queues are
1459 * empty too. We already got all the Tx responses for all the
1460 * packets in the queues. The drain work can have been
Emmanuel Grumbach0742a752013-06-10 14:10:33 +03001461 * triggered. Flush it.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001462 */
1463 flush_work(&mvm->sta_drained_wk);
1464 }
Johannes Berg38a12b52013-02-22 14:07:56 +01001465}
1466
1467static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1468 struct ieee80211_vif *vif)
1469{
1470 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1471 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1472
1473 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001474
1475 mutex_lock(&mvm->mutex);
1476
Hila Gonen7df15b12012-12-12 11:16:19 +02001477 if (mvm->bf_allowed_vif == mvmvif) {
1478 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001479 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1480 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +02001481 }
1482
Johannes Berg63494372013-03-26 10:47:53 +01001483 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1484
Johannes Berg8ca151b2013-01-24 14:25:36 +01001485 /*
1486 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +01001487 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001488 */
Johannes Berg5023d962013-07-31 14:07:43 +02001489 if (vif->type == NL80211_IFTYPE_AP ||
1490 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +03001491#ifdef CONFIG_NL80211_TESTMODE
1492 if (vif == mvm->noa_vif) {
1493 mvm->noa_vif = NULL;
1494 mvm->noa_duration = 0;
1495 }
1496#endif
Johannes Berg013290a2014-08-04 13:38:48 +02001497 iwl_mvm_dealloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001498 goto out_release;
1499 }
1500
1501 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1502 mvm->p2p_device_vif = NULL;
Johannes Berg013290a2014-08-04 13:38:48 +02001503 iwl_mvm_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001504 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001505 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001506 mvmvif->phy_ctxt = NULL;
1507 }
1508
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001509 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001510 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001511
Arik Nemtsov999609f2014-05-15 17:31:51 +03001512 iwl_mvm_power_update_mac(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001513 iwl_mvm_mac_ctxt_remove(mvm, vif);
1514
1515out_release:
1516 iwl_mvm_mac_ctxt_release(mvm, vif);
1517 mutex_unlock(&mvm->mutex);
1518}
1519
1520static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1521{
1522 return 0;
1523}
1524
Eliad Pellere59647e2013-11-28 14:08:50 +02001525struct iwl_mvm_mc_iter_data {
1526 struct iwl_mvm *mvm;
1527 int port_id;
1528};
1529
1530static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1531 struct ieee80211_vif *vif)
1532{
1533 struct iwl_mvm_mc_iter_data *data = _data;
1534 struct iwl_mvm *mvm = data->mvm;
1535 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1536 int ret, len;
1537
1538 /* if we don't have free ports, mcast frames will be dropped */
1539 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1540 return;
1541
1542 if (vif->type != NL80211_IFTYPE_STATION ||
1543 !vif->bss_conf.assoc)
1544 return;
1545
1546 cmd->port_id = data->port_id++;
1547 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1548 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1549
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001550 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
Eliad Pellere59647e2013-11-28 14:08:50 +02001551 if (ret)
1552 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1553}
1554
1555static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1556{
1557 struct iwl_mvm_mc_iter_data iter_data = {
1558 .mvm = mvm,
1559 };
1560
1561 lockdep_assert_held(&mvm->mutex);
1562
1563 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1564 return;
1565
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001566 ieee80211_iterate_active_interfaces_atomic(
Eliad Pellere59647e2013-11-28 14:08:50 +02001567 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1568 iwl_mvm_mc_iface_iterator, &iter_data);
1569}
1570
1571static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1572 struct netdev_hw_addr_list *mc_list)
1573{
1574 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1575 struct iwl_mcast_filter_cmd *cmd;
1576 struct netdev_hw_addr *addr;
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001577 int addr_count;
1578 bool pass_all;
Eliad Pellere59647e2013-11-28 14:08:50 +02001579 int len;
1580
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001581 addr_count = netdev_hw_addr_list_count(mc_list);
1582 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1583 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1584 if (pass_all)
Eliad Pellere59647e2013-11-28 14:08:50 +02001585 addr_count = 0;
Eliad Pellere59647e2013-11-28 14:08:50 +02001586
1587 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1588 cmd = kzalloc(len, GFP_ATOMIC);
1589 if (!cmd)
1590 return 0;
1591
1592 if (pass_all) {
1593 cmd->pass_all = 1;
1594 return (u64)(unsigned long)cmd;
1595 }
1596
1597 netdev_hw_addr_list_for_each(addr, mc_list) {
1598 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1599 cmd->count, addr->addr);
1600 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1601 addr->addr, ETH_ALEN);
1602 cmd->count++;
1603 }
1604
1605 return (u64)(unsigned long)cmd;
1606}
1607
Johannes Berg8ca151b2013-01-24 14:25:36 +01001608static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1609 unsigned int changed_flags,
1610 unsigned int *total_flags,
1611 u64 multicast)
1612{
Eliad Pellere59647e2013-11-28 14:08:50 +02001613 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1614 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1615
1616 mutex_lock(&mvm->mutex);
1617
1618 /* replace previous configuration */
1619 kfree(mvm->mcast_filter_cmd);
1620 mvm->mcast_filter_cmd = cmd;
1621
1622 if (!cmd)
1623 goto out;
1624
1625 iwl_mvm_recalc_multicast(mvm);
1626out:
1627 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001628 *total_flags = 0;
1629}
1630
Eliad Pellerc87163b2014-01-08 10:11:11 +02001631#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1632struct iwl_bcast_iter_data {
1633 struct iwl_mvm *mvm;
1634 struct iwl_bcast_filter_cmd *cmd;
1635 u8 current_filter;
1636};
1637
1638static void
1639iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1640 const struct iwl_fw_bcast_filter *in_filter,
1641 struct iwl_fw_bcast_filter *out_filter)
1642{
1643 struct iwl_fw_bcast_filter_attr *attr;
1644 int i;
1645
1646 memcpy(out_filter, in_filter, sizeof(*out_filter));
1647
1648 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1649 attr = &out_filter->attrs[i];
1650
1651 if (!attr->mask)
1652 break;
1653
Eliad Peller2ee8f022014-01-13 19:07:09 +02001654 switch (attr->reserved1) {
1655 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1656 if (vif->bss_conf.arp_addr_cnt != 1) {
1657 attr->mask = 0;
1658 continue;
1659 }
1660
1661 attr->val = vif->bss_conf.arp_addr_list[0];
1662 break;
1663 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1664 attr->val = *(__be32 *)&vif->addr[2];
1665 break;
1666 default:
1667 break;
1668 }
1669 attr->reserved1 = 0;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001670 out_filter->num_attrs++;
1671 }
1672}
1673
1674static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1675 struct ieee80211_vif *vif)
1676{
1677 struct iwl_bcast_iter_data *data = _data;
1678 struct iwl_mvm *mvm = data->mvm;
1679 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1680 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1681 struct iwl_fw_bcast_mac *bcast_mac;
1682 int i;
1683
1684 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1685 return;
1686
1687 bcast_mac = &cmd->macs[mvmvif->id];
1688
Ilan Peere48393e2014-05-22 11:19:02 +03001689 /*
1690 * enable filtering only for associated stations, but not for P2P
1691 * Clients
1692 */
1693 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1694 !vif->bss_conf.assoc)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001695 return;
1696
1697 bcast_mac->default_discard = 1;
1698
1699 /* copy all configured filters */
1700 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1701 /*
1702 * Make sure we don't exceed our filters limit.
1703 * if there is still a valid filter to be configured,
1704 * be on the safe side and just allow bcast for this mac.
1705 */
1706 if (WARN_ON_ONCE(data->current_filter >=
1707 ARRAY_SIZE(cmd->filters))) {
1708 bcast_mac->default_discard = 0;
1709 bcast_mac->attached_filters = 0;
1710 break;
1711 }
1712
1713 iwl_mvm_set_bcast_filter(vif,
1714 &mvm->bcast_filters[i],
1715 &cmd->filters[data->current_filter]);
1716
1717 /* skip current filter if it contains no attributes */
1718 if (!cmd->filters[data->current_filter].num_attrs)
1719 continue;
1720
1721 /* attach the filter to current mac */
1722 bcast_mac->attached_filters |=
1723 cpu_to_le16(BIT(data->current_filter));
1724
1725 data->current_filter++;
1726 }
1727}
1728
Eliad Pellerde06a592014-01-08 10:11:12 +02001729bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1730 struct iwl_bcast_filter_cmd *cmd)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001731{
Eliad Pellerc87163b2014-01-08 10:11:11 +02001732 struct iwl_bcast_iter_data iter_data = {
1733 .mvm = mvm,
Eliad Pellerde06a592014-01-08 10:11:12 +02001734 .cmd = cmd,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001735 };
1736
Max Stepanov3b8983b2014-10-15 11:27:16 +03001737 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1738 return false;
1739
Eliad Pellerde06a592014-01-08 10:11:12 +02001740 memset(cmd, 0, sizeof(*cmd));
1741 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1742 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1743
1744#ifdef CONFIG_IWLWIFI_DEBUGFS
1745 /* use debugfs filters/macs if override is configured */
1746 if (mvm->dbgfs_bcast_filtering.override) {
1747 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1748 sizeof(cmd->filters));
1749 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1750 sizeof(cmd->macs));
1751 return true;
1752 }
1753#endif
Eliad Pellerc87163b2014-01-08 10:11:11 +02001754
1755 /* if no filters are configured, do nothing */
1756 if (!mvm->bcast_filters)
Eliad Pellerde06a592014-01-08 10:11:12 +02001757 return false;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001758
1759 /* configure and attach these filters for each associated sta vif */
1760 ieee80211_iterate_active_interfaces(
1761 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1762 iwl_mvm_bcast_filter_iterator, &iter_data);
1763
Eliad Pellerde06a592014-01-08 10:11:12 +02001764 return true;
1765}
1766static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1767 struct ieee80211_vif *vif)
1768{
1769 struct iwl_bcast_filter_cmd cmd;
1770
1771 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1772 return 0;
1773
1774 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1775 return 0;
1776
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001777 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001778 sizeof(cmd), &cmd);
1779}
1780#else
1781static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1782 struct ieee80211_vif *vif)
1783{
1784 return 0;
1785}
1786#endif
1787
Johannes Berg8ca151b2013-01-24 14:25:36 +01001788static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1789 struct ieee80211_vif *vif,
1790 struct ieee80211_bss_conf *bss_conf,
1791 u32 changes)
1792{
1793 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1794 int ret;
1795
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001796 /*
1797 * Re-calculate the tsf id, as the master-slave relations depend on the
1798 * beacon interval, which was not known when the station interface was
1799 * added.
1800 */
1801 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1802 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1803
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001804 /*
1805 * If we're not associated yet, take the (new) BSSID before associating
1806 * so the firmware knows. If we're already associated, then use the old
1807 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1808 * branch for disassociation below.
1809 */
1810 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1811 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1812
1813 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001814 if (ret)
1815 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1816
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001817 /* after sending it once, adopt mac80211 data */
1818 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1819 mvmvif->associated = bss_conf->assoc;
1820
Johannes Berg8ca151b2013-01-24 14:25:36 +01001821 if (changes & BSS_CHANGED_ASSOC) {
1822 if (bss_conf->assoc) {
Johannes Berg33cef922015-01-21 21:41:29 +01001823 /* clear statistics to get clean beacon counter */
1824 iwl_mvm_request_statistics(mvm, true);
1825 memset(&mvmvif->beacon_stats, 0,
1826 sizeof(mvmvif->beacon_stats));
1827
Johannes Berg8ca151b2013-01-24 14:25:36 +01001828 /* add quota for this interface */
Johannes Berg01662302014-06-06 15:18:45 +02001829 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001830 if (ret) {
1831 IWL_ERR(mvm, "failed to update quotas\n");
1832 return;
1833 }
Johannes Berg016d27e2013-05-03 11:16:15 +02001834
1835 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1836 &mvm->status)) {
1837 /*
1838 * If we're restarting then the firmware will
1839 * obviously have lost synchronisation with
1840 * the AP. It will attempt to synchronise by
1841 * itself, but we can make it more reliable by
1842 * scheduling a session protection time event.
1843 *
1844 * The firmware needs to receive a beacon to
1845 * catch up with synchronisation, use 110% of
1846 * the beacon interval.
1847 *
1848 * Set a large maximum delay to allow for more
1849 * than a single interface.
1850 */
1851 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1852 iwl_mvm_protect_session(mvm, vif, dur, dur,
Liad Kaufmand20d37b2014-07-06 17:14:39 +03001853 5 * dur, false);
Johannes Berg016d27e2013-05-03 11:16:15 +02001854 }
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001855
1856 iwl_mvm_sf_update(mvm, vif, false);
Alexander Bondar175a70b2013-04-14 20:59:37 +03001857 iwl_mvm_power_vif_assoc(mvm, vif);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001858 if (vif->p2p) {
Eliad Peller29a90a42013-11-05 14:06:29 +02001859 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001860 iwl_mvm_update_smps(mvm, vif,
1861 IWL_MVM_SMPS_REQ_PROT,
1862 IEEE80211_SMPS_DYNAMIC);
1863 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001864 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001865 /*
1866 * If update fails - SF might be running in associated
1867 * mode while disassociated - which is forbidden.
1868 */
1869 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1870 "Failed to update SF upon disassociation\n");
1871
Johannes Berg8ca151b2013-01-24 14:25:36 +01001872 /* remove AP station now that the MAC is unassoc */
1873 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1874 if (ret)
1875 IWL_ERR(mvm, "failed to remove AP station\n");
Eliad Peller37577fe2013-12-05 17:19:39 +02001876
1877 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1878 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001879 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1880 /* remove quota for this interface */
Johannes Berg01662302014-06-06 15:18:45 +02001881 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001882 if (ret)
1883 IWL_ERR(mvm, "failed to update quotas\n");
Eliad Peller29a90a42013-11-05 14:06:29 +02001884
1885 if (vif->p2p)
1886 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001887
1888 /* this will take the cleared BSSID from bss_conf */
1889 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1890 if (ret)
1891 IWL_ERR(mvm,
1892 "failed to update MAC %pM (clear after unassoc)\n",
1893 vif->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001894 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001895
Eliad Pellere59647e2013-11-28 14:08:50 +02001896 iwl_mvm_recalc_multicast(mvm);
Eliad Pellerc87163b2014-01-08 10:11:11 +02001897 iwl_mvm_configure_bcast_filter(mvm, vif);
Eliad Pellere59647e2013-11-28 14:08:50 +02001898
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001899 /* reset rssi values */
1900 mvmvif->bf_data.ave_beacon_signal = 0;
1901
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001902 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachf94045e2014-01-06 13:38:55 +02001903 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1904 IEEE80211_SMPS_AUTOMATIC);
Alexander Bondar989c6502013-05-16 17:34:17 +03001905 } else if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +01001906 /*
1907 * We received a beacon _after_ association so
1908 * remove the session protection.
1909 */
1910 iwl_mvm_remove_time_event(mvm, mvmvif,
1911 &mvmvif->time_event_data);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001912 }
Eran Hararycc87d322014-07-15 14:04:23 +03001913
1914 if (changes & BSS_CHANGED_BEACON_INFO) {
1915 iwl_mvm_sf_update(mvm, vif, false);
1916 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
1917 }
1918
Johannes Berg1bc10d32014-08-26 14:25:46 +02001919 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS)) {
1920 ret = iwl_mvm_power_update_mac(mvm);
1921 if (ret)
1922 IWL_ERR(mvm, "failed to update power mode\n");
1923 }
1924
Matti Gottlieb88f2fd72013-07-09 15:25:46 +03001925 if (changes & BSS_CHANGED_TXPOWER) {
1926 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1927 bss_conf->txpower);
1928 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1929 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001930
1931 if (changes & BSS_CHANGED_CQM) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02001932 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001933 /* reset cqm events tracking */
1934 mvmvif->bf_data.last_cqm_event = 0;
Avri Altmanfa7b2e72014-05-20 08:03:24 +03001935 if (mvmvif->bf_data.bf_enabled) {
1936 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1937 if (ret)
1938 IWL_ERR(mvm,
1939 "failed to update CQM thresholds\n");
1940 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001941 }
Eliad Peller2ee8f022014-01-13 19:07:09 +02001942
1943 if (changes & BSS_CHANGED_ARP_FILTER) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02001944 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
Eliad Peller2ee8f022014-01-13 19:07:09 +02001945 iwl_mvm_configure_bcast_filter(mvm, vif);
1946 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001947}
1948
Johannes Berg5023d962013-07-31 14:07:43 +02001949static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1950 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001951{
1952 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1953 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1954 int ret;
1955
Eliad Peller576eeee2014-07-01 18:38:38 +03001956 /*
1957 * iwl_mvm_mac_ctxt_add() might read directly from the device
1958 * (the system time), so make sure it is available.
1959 */
1960 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
1961 if (ret)
1962 return ret;
1963
Johannes Berg8ca151b2013-01-24 14:25:36 +01001964 mutex_lock(&mvm->mutex);
1965
1966 /* Send the beacon template */
1967 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1968 if (ret)
1969 goto out_unlock;
1970
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001971 /*
1972 * Re-calculate the tsf id, as the master-slave relations depend on the
1973 * beacon interval, which was not known when the AP interface was added.
1974 */
1975 if (vif->type == NL80211_IFTYPE_AP)
1976 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1977
Johannes Berg8ca151b2013-01-24 14:25:36 +01001978 /* Add the mac context */
1979 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1980 if (ret)
1981 goto out_unlock;
1982
1983 /* Perform the binding */
1984 ret = iwl_mvm_binding_add_vif(mvm, vif);
1985 if (ret)
1986 goto out_remove;
1987
Johannes Berg8ca151b2013-01-24 14:25:36 +01001988 /* Send the bcast station. At this stage the TBTT and DTIM time events
1989 * are added and applied to the scheduler */
Johannes Berg013290a2014-08-04 13:38:48 +02001990 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001991 if (ret)
1992 goto out_unbind;
1993
Ilan Peer5691e212013-12-31 21:05:50 +02001994 /* must be set before quota calculations */
1995 mvmvif->ap_ibss_active = true;
1996
Ilan Peera11e1442013-12-31 21:19:55 +02001997 /* power updated needs to be done before quotas */
Arik Nemtsov999609f2014-05-15 17:31:51 +03001998 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02001999
Johannes Berg01662302014-06-06 15:18:45 +02002000 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002001 if (ret)
Ilan Peera11e1442013-12-31 21:19:55 +02002002 goto out_quota_failed;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002003
Johannes Berg5023d962013-07-31 14:07:43 +02002004 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002005 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002006 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002007
Eliad Peller29a90a42013-11-05 14:06:29 +02002008 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2009
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002010 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03002011
Arik Nemtsovf6972672014-06-15 16:03:55 +03002012 /* we don't support TDLS during DCM */
2013 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2014 iwl_mvm_teardown_tdls_peers(mvm);
2015
Johannes Berg8ca151b2013-01-24 14:25:36 +01002016 mutex_unlock(&mvm->mutex);
2017 return 0;
2018
Ilan Peera11e1442013-12-31 21:19:55 +02002019out_quota_failed:
Arik Nemtsov999609f2014-05-15 17:31:51 +03002020 iwl_mvm_power_update_mac(mvm);
Ilan Peer5691e212013-12-31 21:05:50 +02002021 mvmvif->ap_ibss_active = false;
Johannes Berg013290a2014-08-04 13:38:48 +02002022 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002023out_unbind:
2024 iwl_mvm_binding_remove_vif(mvm, vif);
2025out_remove:
2026 iwl_mvm_mac_ctxt_remove(mvm, vif);
2027out_unlock:
2028 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002029 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002030 return ret;
2031}
2032
Johannes Berg5023d962013-07-31 14:07:43 +02002033static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2034 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002035{
2036 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2037 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2038
Johannes Berg38a12b52013-02-22 14:07:56 +01002039 iwl_mvm_prepare_mac_removal(mvm, vif);
2040
Johannes Berg8ca151b2013-01-24 14:25:36 +01002041 mutex_lock(&mvm->mutex);
2042
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002043 /* Handle AP stop while in CSA */
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03002044 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2045 iwl_mvm_remove_time_event(mvm, mvmvif,
2046 &mvmvif->time_event_data);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002047 RCU_INIT_POINTER(mvm->csa_vif, NULL);
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03002048 }
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002049
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03002050 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2051 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2052 mvm->csa_tx_block_bcn_timeout = 0;
2053 }
2054
Johannes Berg5023d962013-07-31 14:07:43 +02002055 mvmvif->ap_ibss_active = false;
David Spinadel1c87bba2014-02-27 16:41:52 +02002056 mvm->ap_last_beacon_gp2 = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002057
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002058 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03002059
Eliad Peller29a90a42013-11-05 14:06:29 +02002060 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2061
Johannes Berg5023d962013-07-31 14:07:43 +02002062 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002063 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002064 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002065
Johannes Berg01662302014-06-06 15:18:45 +02002066 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg013290a2014-08-04 13:38:48 +02002067 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002068 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02002069
Arik Nemtsov999609f2014-05-15 17:31:51 +03002070 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02002071
Johannes Berg8ca151b2013-01-24 14:25:36 +01002072 iwl_mvm_mac_ctxt_remove(mvm, vif);
2073
2074 mutex_unlock(&mvm->mutex);
2075}
2076
Johannes Berg5023d962013-07-31 14:07:43 +02002077static void
2078iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2079 struct ieee80211_vif *vif,
2080 struct ieee80211_bss_conf *bss_conf,
2081 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002082{
Ilan Peerbe2056f2013-12-04 16:47:14 +02002083 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman8a5e3662013-11-12 19:16:03 +02002084
Ilan Peerbe2056f2013-12-04 16:47:14 +02002085 /* Changes will be applied when the AP/IBSS is started */
2086 if (!mvmvif->ap_ibss_active)
2087 return;
2088
Johannes Berg863230da2013-12-04 17:08:40 +01002089 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
Johannes Bergf7d8b702014-09-09 15:49:19 +02002090 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002091 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
Johannes Berg863230da2013-12-04 17:08:40 +01002092 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
Avri Altman8a5e3662013-11-12 19:16:03 +02002093
Johannes Berg8ca151b2013-01-24 14:25:36 +01002094 /* Need to send a new beacon template to the FW */
Johannes Berg863230da2013-12-04 17:08:40 +01002095 if (changes & BSS_CHANGED_BEACON &&
2096 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2097 IWL_WARN(mvm, "Failed updating beacon data\n");
Haim Dreyfuss79b7a692014-09-14 12:40:00 +03002098
2099 if (changes & BSS_CHANGED_TXPOWER) {
2100 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2101 bss_conf->txpower);
2102 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2103 }
2104
Johannes Berg8ca151b2013-01-24 14:25:36 +01002105}
2106
2107static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2108 struct ieee80211_vif *vif,
2109 struct ieee80211_bss_conf *bss_conf,
2110 u32 changes)
2111{
2112 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2113
Eliad Peller576eeee2014-07-01 18:38:38 +03002114 /*
2115 * iwl_mvm_bss_info_changed_station() might call
2116 * iwl_mvm_protect_session(), which reads directly from
2117 * the device (the system time), so make sure it is available.
2118 */
2119 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2120 return;
2121
Johannes Berg8ca151b2013-01-24 14:25:36 +01002122 mutex_lock(&mvm->mutex);
2123
David Spinadel723f02e2014-04-27 09:54:54 +03002124 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
David Spinadelfb98be52014-05-04 12:51:10 +03002125 iwl_mvm_scan_offload_stop(mvm, true);
David Spinadel723f02e2014-04-27 09:54:54 +03002126
Johannes Berg8ca151b2013-01-24 14:25:36 +01002127 switch (vif->type) {
2128 case NL80211_IFTYPE_STATION:
2129 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2130 break;
2131 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02002132 case NL80211_IFTYPE_ADHOC:
2133 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002134 break;
2135 default:
2136 /* shouldn't happen */
2137 WARN_ON_ONCE(1);
2138 }
2139
2140 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002141 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002142}
2143
Eliad Peller4660dfb2014-06-22 18:15:59 +03002144static int iwl_mvm_cancel_scan_wait_notif(struct iwl_mvm *mvm,
2145 enum iwl_scan_status scan_type)
2146{
2147 int ret;
2148 bool wait_for_handlers = false;
2149
2150 mutex_lock(&mvm->mutex);
2151
2152 if (mvm->scan_status != scan_type) {
2153 ret = 0;
2154 /* make sure there are no pending notifications */
2155 wait_for_handlers = true;
2156 goto out;
2157 }
2158
2159 switch (scan_type) {
2160 case IWL_MVM_SCAN_SCHED:
2161 ret = iwl_mvm_scan_offload_stop(mvm, true);
2162 break;
2163 case IWL_MVM_SCAN_OS:
2164 ret = iwl_mvm_cancel_scan(mvm);
2165 break;
2166 case IWL_MVM_SCAN_NONE:
2167 default:
2168 WARN_ON_ONCE(1);
2169 ret = -EINVAL;
2170 break;
2171 }
2172 if (ret)
2173 goto out;
2174
2175 wait_for_handlers = true;
2176out:
2177 mutex_unlock(&mvm->mutex);
2178
2179 /* make sure we consume the completion notification */
2180 if (wait_for_handlers)
2181 iwl_mvm_wait_for_async_handlers(mvm);
2182
2183 return ret;
2184}
Johannes Berg8ca151b2013-01-24 14:25:36 +01002185static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2186 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02002187 struct ieee80211_scan_request *hw_req)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002188{
2189 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
David Spinadelc56ef672014-02-05 15:21:13 +02002190 struct cfg80211_scan_request *req = &hw_req->req;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002191 int ret;
2192
David Spinadel762533b2014-06-05 11:20:43 +03002193 if (req->n_channels == 0 ||
2194 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002195 return -EINVAL;
2196
David Spinadeld2496222014-05-20 12:46:37 +03002197 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2198 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_SCHED);
2199 if (ret)
2200 return ret;
2201 }
Eliad Peller4660dfb2014-06-22 18:15:59 +03002202
Johannes Berg8ca151b2013-01-24 14:25:36 +01002203 mutex_lock(&mvm->mutex);
2204
Eliad Peller4660dfb2014-06-22 18:15:59 +03002205 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002206 ret = -EBUSY;
Arik Nemtsov519e2022013-10-17 17:51:35 +03002207 goto out;
2208 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002209
Arik Nemtsov519e2022013-10-17 17:51:35 +03002210 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
2211
David Spinadelb975e552014-11-17 12:30:05 +02002212 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
David Spinadeld2496222014-05-20 12:46:37 +03002213 ret = iwl_mvm_scan_umac(mvm, vif, hw_req);
David Spinadelfb98be52014-05-04 12:51:10 +03002214 else
Luciano Coelho1f940382015-02-10 13:03:38 +02002215 ret = iwl_mvm_unified_scan_lmac(mvm, vif, hw_req);
David Spinadelfb98be52014-05-04 12:51:10 +03002216
Arik Nemtsov519e2022013-10-17 17:51:35 +03002217 if (ret)
2218 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
2219out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002220 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002221 return ret;
2222}
2223
2224static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2225 struct ieee80211_vif *vif)
2226{
2227 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2228
2229 mutex_lock(&mvm->mutex);
2230
2231 iwl_mvm_cancel_scan(mvm);
2232
2233 mutex_unlock(&mvm->mutex);
2234}
2235
2236static void
2237iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
Johannes Berg3e56ead2013-02-15 22:23:18 +01002238 struct ieee80211_sta *sta, u16 tids,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002239 int num_frames,
2240 enum ieee80211_frame_release_type reason,
2241 bool more_data)
2242{
2243 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002244
Johannes Berg3e56ead2013-02-15 22:23:18 +01002245 /* Called when we need to transmit (a) frame(s) from mac80211 */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002246
Johannes Berg3e56ead2013-02-15 22:23:18 +01002247 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2248 tids, more_data, false);
2249}
2250
2251static void
2252iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2253 struct ieee80211_sta *sta, u16 tids,
2254 int num_frames,
2255 enum ieee80211_frame_release_type reason,
2256 bool more_data)
2257{
2258 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2259
2260 /* Called when we need to transmit (a) frame(s) from agg queue */
2261
2262 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2263 tids, more_data, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002264}
2265
2266static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2267 struct ieee80211_vif *vif,
2268 enum sta_notify_cmd cmd,
2269 struct ieee80211_sta *sta)
2270{
2271 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01002272 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg3e56ead2013-02-15 22:23:18 +01002273 int tid;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002274
2275 switch (cmd) {
2276 case STA_NOTIFY_SLEEP:
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03002277 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002278 ieee80211_sta_block_awake(hw, sta, true);
Johannes Berg3e56ead2013-02-15 22:23:18 +01002279 spin_lock_bh(&mvmsta->lock);
2280 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2281 struct iwl_mvm_tid_data *tid_data;
2282
2283 tid_data = &mvmsta->tid_data[tid];
2284 if (tid_data->state != IWL_AGG_ON &&
2285 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
2286 continue;
2287 if (iwl_mvm_tid_queued(tid_data) == 0)
2288 continue;
2289 ieee80211_sta_set_buffered(sta, tid, true);
2290 }
2291 spin_unlock_bh(&mvmsta->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002292 /*
2293 * The fw updates the STA to be asleep. Tx packets on the Tx
2294 * queues to this station will not be transmitted. The fw will
2295 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2296 */
2297 break;
2298 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02002299 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01002300 break;
Johannes Berg9cc40712013-02-15 22:47:48 +01002301 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002302 break;
2303 default:
2304 break;
2305 }
2306}
2307
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002308static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2309 struct ieee80211_vif *vif,
2310 struct ieee80211_sta *sta)
2311{
2312 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01002313 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002314
2315 /*
2316 * This is called before mac80211 does RCU synchronisation,
2317 * so here we already invalidate our internal RCU-protected
2318 * station pointer. The rest of the code will thus no longer
2319 * be able to find the station this way, and we don't rely
2320 * on further RCU synchronisation after the sta_state()
2321 * callback deleted the station.
2322 */
2323 mutex_lock(&mvm->mutex);
2324 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2325 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2326 ERR_PTR(-ENOENT));
2327 mutex_unlock(&mvm->mutex);
2328}
2329
Johannes Bergbd1ba662014-11-13 20:53:45 +01002330static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2331 const u8 *bssid)
2332{
2333 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2334 return;
2335
2336 if (iwlwifi_mod_params.uapsd_disable) {
2337 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2338 return;
2339 }
2340
2341 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2342}
2343
Johannes Berg8ca151b2013-01-24 14:25:36 +01002344static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2345 struct ieee80211_vif *vif,
2346 struct ieee80211_sta *sta,
2347 enum ieee80211_sta_state old_state,
2348 enum ieee80211_sta_state new_state)
2349{
2350 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2351 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2352 int ret;
2353
2354 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2355 sta->addr, old_state, new_state);
2356
2357 /* this would be a mac80211 bug ... but don't crash */
2358 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2359 return -EINVAL;
2360
2361 /* if a STA is being removed, reuse its ID */
2362 flush_work(&mvm->sta_drained_wk);
2363
2364 mutex_lock(&mvm->mutex);
2365 if (old_state == IEEE80211_STA_NOTEXIST &&
2366 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02002367 /*
2368 * Firmware bug - it'll crash if the beacon interval is less
2369 * than 16. We can't avoid connecting at all, so refuse the
2370 * station state change, this will cause mac80211 to abandon
2371 * attempts to connect to this AP, and eventually wpa_s will
2372 * blacklist the AP...
2373 */
2374 if (vif->type == NL80211_IFTYPE_STATION &&
2375 vif->bss_conf.beacon_int < 16) {
2376 IWL_ERR(mvm,
2377 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2378 sta->addr, vif->bss_conf.beacon_int);
2379 ret = -EINVAL;
2380 goto out_unlock;
2381 }
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002382
2383 if (sta->tdls &&
2384 (vif->p2p ||
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002385 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2386 IWL_MVM_TDLS_STA_COUNT ||
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002387 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2388 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2389 ret = -EBUSY;
2390 goto out_unlock;
2391 }
2392
Johannes Berg8ca151b2013-01-24 14:25:36 +01002393 ret = iwl_mvm_add_sta(mvm, vif, sta);
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002394 if (sta->tdls && ret == 0)
2395 iwl_mvm_recalc_tdls_state(mvm, vif, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002396 } else if (old_state == IEEE80211_STA_NONE &&
2397 new_state == IEEE80211_STA_AUTH) {
Haim Dreyfusse820c2d2014-04-06 11:19:09 +03002398 /*
2399 * EBS may be disabled due to previous failures reported by FW.
2400 * Reset EBS status here assuming environment has been changed.
2401 */
2402 mvm->last_ebs_successful = true;
Johannes Bergbd1ba662014-11-13 20:53:45 +01002403 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002404 ret = 0;
2405 } else if (old_state == IEEE80211_STA_AUTH &&
2406 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01002407 ret = iwl_mvm_update_sta(mvm, vif, sta);
2408 if (ret == 0)
2409 iwl_mvm_rs_rate_init(mvm, sta,
Eyal Shapirab87c2172013-11-09 23:37:55 +02002410 mvmvif->phy_ctxt->channel->band,
2411 true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002412 } else if (old_state == IEEE80211_STA_ASSOC &&
2413 new_state == IEEE80211_STA_AUTHORIZED) {
Arik Nemtsovf59e0e3c2014-06-10 19:56:27 +03002414
2415 /* we don't support TDLS during DCM */
2416 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2417 iwl_mvm_teardown_tdls_peers(mvm);
2418
Hila Gonen7df15b12012-12-12 11:16:19 +02002419 /* enable beacon filtering */
Avri Altmanfa7b2e72014-05-20 08:03:24 +03002420 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002421 ret = 0;
2422 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2423 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02002424 /* disable beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002425 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002426 ret = 0;
2427 } else if (old_state == IEEE80211_STA_ASSOC &&
2428 new_state == IEEE80211_STA_AUTH) {
2429 ret = 0;
2430 } else if (old_state == IEEE80211_STA_AUTH &&
2431 new_state == IEEE80211_STA_NONE) {
2432 ret = 0;
2433 } else if (old_state == IEEE80211_STA_NONE &&
2434 new_state == IEEE80211_STA_NOTEXIST) {
2435 ret = iwl_mvm_rm_sta(mvm, vif, sta);
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002436 if (sta->tdls)
2437 iwl_mvm_recalc_tdls_state(mvm, vif, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002438 } else {
2439 ret = -EIO;
2440 }
Johannes Berg48bc1302013-07-04 15:55:29 +02002441 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002442 mutex_unlock(&mvm->mutex);
2443
Liad Kaufman9c126cd2014-10-06 19:08:56 +02002444 if (sta->tdls && ret == 0) {
2445 if (old_state == IEEE80211_STA_NOTEXIST &&
2446 new_state == IEEE80211_STA_NONE)
2447 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2448 else if (old_state == IEEE80211_STA_NONE &&
2449 new_state == IEEE80211_STA_NOTEXIST)
2450 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2451 }
2452
Johannes Berg8ca151b2013-01-24 14:25:36 +01002453 return ret;
2454}
2455
2456static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2457{
2458 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2459
2460 mvm->rts_threshold = value;
2461
2462 return 0;
2463}
2464
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002465static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2466 struct ieee80211_vif *vif,
2467 struct ieee80211_sta *sta, u32 changed)
2468{
2469 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2470
2471 if (vif->type == NL80211_IFTYPE_STATION &&
2472 changed & IEEE80211_RC_NSS_CHANGED)
2473 iwl_mvm_sf_update(mvm, vif, false);
2474}
2475
Johannes Berg8ca151b2013-01-24 14:25:36 +01002476static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2477 struct ieee80211_vif *vif, u16 ac,
2478 const struct ieee80211_tx_queue_params *params)
2479{
2480 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2481 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2482
2483 mvmvif->queue_params[ac] = *params;
2484
2485 /*
2486 * No need to update right away, we'll get BSS_CHANGED_QOS
2487 * The exception is P2P_DEVICE interface which needs immediate update.
2488 */
2489 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2490 int ret;
2491
2492 mutex_lock(&mvm->mutex);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002493 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002494 mutex_unlock(&mvm->mutex);
2495 return ret;
2496 }
2497 return 0;
2498}
2499
2500static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2501 struct ieee80211_vif *vif)
2502{
2503 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2504 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
2505 200 + vif->bss_conf.beacon_int);
2506 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
2507 100 + vif->bss_conf.beacon_int);
2508
2509 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2510 return;
2511
Eliad Peller576eeee2014-07-01 18:38:38 +03002512 /*
2513 * iwl_mvm_protect_session() reads directly from the device
2514 * (the system time), so make sure it is available.
2515 */
2516 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2517 return;
2518
Johannes Berg8ca151b2013-01-24 14:25:36 +01002519 mutex_lock(&mvm->mutex);
2520 /* Try really hard to protect the session and hear a beacon */
Liad Kaufmand20d37b2014-07-06 17:14:39 +03002521 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002522 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002523
2524 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002525}
2526
David Spinadel35a000b2013-08-28 09:29:43 +03002527static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2528 struct ieee80211_vif *vif,
2529 struct cfg80211_sched_scan_request *req,
David Spinadel633e2712014-02-06 16:15:23 +02002530 struct ieee80211_scan_ies *ies)
David Spinadel35a000b2013-08-28 09:29:43 +03002531{
2532 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2533 int ret;
2534
David Spinadeld2496222014-05-20 12:46:37 +03002535 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2536 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_OS);
2537 if (ret)
2538 return ret;
2539 }
Eliad Peller4660dfb2014-06-22 18:15:59 +03002540
David Spinadel35a000b2013-08-28 09:29:43 +03002541 mutex_lock(&mvm->mutex);
2542
Luciano Coelho1f940382015-02-10 13:03:38 +02002543 if (!vif->bss_conf.idle) {
David Spinadelbd5e4742014-04-24 13:15:29 +03002544 ret = -EBUSY;
2545 goto out;
2546 }
2547
Eliad Peller4660dfb2014-06-22 18:15:59 +03002548 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
David Spinadel35a000b2013-08-28 09:29:43 +03002549 ret = -EBUSY;
2550 goto out;
2551 }
2552
Luciano Coelhob141c232014-10-01 13:22:40 +03002553 ret = iwl_mvm_scan_offload_start(mvm, vif, req, ies);
David Spinadel35a000b2013-08-28 09:29:43 +03002554 if (ret)
Luciano Coelhob141c232014-10-01 13:22:40 +03002555 mvm->scan_status = IWL_MVM_SCAN_NONE;
David Spinadeld2496222014-05-20 12:46:37 +03002556
David Spinadel35a000b2013-08-28 09:29:43 +03002557out:
2558 mutex_unlock(&mvm->mutex);
2559 return ret;
2560}
2561
Johannes Berg37e33082014-02-17 10:48:17 +01002562static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2563 struct ieee80211_vif *vif)
David Spinadel35a000b2013-08-28 09:29:43 +03002564{
2565 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002566 int ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002567
2568 mutex_lock(&mvm->mutex);
David Spinadelfb98be52014-05-04 12:51:10 +03002569 ret = iwl_mvm_scan_offload_stop(mvm, false);
David Spinadel35a000b2013-08-28 09:29:43 +03002570 mutex_unlock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002571 iwl_mvm_wait_for_async_handlers(mvm);
Johannes Berg37e33082014-02-17 10:48:17 +01002572
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002573 return ret;
David Spinadeld2496222014-05-20 12:46:37 +03002574
David Spinadel35a000b2013-08-28 09:29:43 +03002575}
2576
Johannes Berg8ca151b2013-01-24 14:25:36 +01002577static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2578 enum set_key_cmd cmd,
2579 struct ieee80211_vif *vif,
2580 struct ieee80211_sta *sta,
2581 struct ieee80211_key_conf *key)
2582{
2583 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2584 int ret;
2585
2586 if (iwlwifi_mod_params.sw_crypto) {
2587 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2588 return -EOPNOTSUPP;
2589 }
2590
2591 switch (key->cipher) {
2592 case WLAN_CIPHER_SUITE_TKIP:
2593 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2594 /* fall-through */
2595 case WLAN_CIPHER_SUITE_CCMP:
2596 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2597 break;
2598 case WLAN_CIPHER_SUITE_AES_CMAC:
2599 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
2600 break;
2601 case WLAN_CIPHER_SUITE_WEP40:
2602 case WLAN_CIPHER_SUITE_WEP104:
Johannes Bergba3943b2014-11-12 23:54:48 +01002603 /* For non-client mode, only use WEP keys for TX as we probably
2604 * don't have a station yet anyway and would then have to keep
2605 * track of the keys, linking them to each of the clients/peers
2606 * as they appear. For now, don't do that, for performance WEP
2607 * offload doesn't really matter much, but we need it for some
2608 * other offload features in client mode.
Johannes Berg8ca151b2013-01-24 14:25:36 +01002609 */
Johannes Bergba3943b2014-11-12 23:54:48 +01002610 if (vif->type != NL80211_IFTYPE_STATION)
2611 return 0;
2612 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002613 default:
Max Stepanove36e5432013-08-27 19:56:13 +03002614 /* currently FW supports only one optional cipher scheme */
2615 if (hw->n_cipher_schemes &&
2616 hw->cipher_schemes->cipher == key->cipher)
2617 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2618 else
2619 return -EOPNOTSUPP;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002620 }
2621
2622 mutex_lock(&mvm->mutex);
2623
2624 switch (cmd) {
2625 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02002626 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2627 vif->type == NL80211_IFTYPE_AP) && !sta) {
2628 /*
2629 * GTK on AP interface is a TX-only key, return 0;
2630 * on IBSS they're per-station and because we're lazy
2631 * we don't support them for RX, so do the same.
2632 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002633 ret = 0;
2634 key->hw_key_idx = STA_KEY_IDX_INVALID;
2635 break;
2636 }
2637
Johannes Berg8ca151b2013-01-24 14:25:36 +01002638 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
2639 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
2640 if (ret) {
2641 IWL_WARN(mvm, "set key failed\n");
2642 /*
2643 * can't add key for RX, but we don't need it
2644 * in the device for TX so still return 0
2645 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002646 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002647 ret = 0;
2648 }
2649
2650 break;
2651 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01002652 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2653 ret = 0;
2654 break;
2655 }
2656
Johannes Berg8ca151b2013-01-24 14:25:36 +01002657 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
2658 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
2659 break;
2660 default:
2661 ret = -EINVAL;
2662 }
2663
2664 mutex_unlock(&mvm->mutex);
2665 return ret;
2666}
2667
2668static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2669 struct ieee80211_vif *vif,
2670 struct ieee80211_key_conf *keyconf,
2671 struct ieee80211_sta *sta,
2672 u32 iv32, u16 *phase1key)
2673{
2674 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2675
Johannes Berg5023d962013-07-31 14:07:43 +02002676 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2677 return;
2678
Johannes Berg8ca151b2013-01-24 14:25:36 +01002679 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2680}
2681
2682
Ariej Marjiehb1128892014-07-16 21:11:12 +03002683static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
2684 struct iwl_rx_packet *pkt, void *data)
2685{
2686 struct iwl_mvm *mvm =
2687 container_of(notif_wait, struct iwl_mvm, notif_wait);
2688 struct iwl_hs20_roc_res *resp;
2689 int resp_len = iwl_rx_packet_payload_len(pkt);
2690 struct iwl_mvm_time_event_data *te_data = data;
2691
2692 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
2693 return true;
2694
2695 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
2696 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
2697 return true;
2698 }
2699
2700 resp = (void *)pkt->data;
2701
2702 IWL_DEBUG_TE(mvm,
2703 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
2704 resp->status, resp->event_unique_id);
2705
2706 te_data->uid = le32_to_cpu(resp->event_unique_id);
2707 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
2708 te_data->uid);
2709
2710 spin_lock_bh(&mvm->time_event_lock);
2711 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
2712 spin_unlock_bh(&mvm->time_event_lock);
2713
2714 return true;
2715}
2716
2717#define AUX_ROC_MAX_DELAY_ON_CHANNEL 5000
2718static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
2719 struct ieee80211_channel *channel,
2720 struct ieee80211_vif *vif,
2721 int duration)
2722{
2723 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
2724 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2725 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
2726 static const u8 time_event_response[] = { HOT_SPOT_CMD };
2727 struct iwl_notification_wait wait_time_event;
2728 struct iwl_hs20_roc_req aux_roc_req = {
2729 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
2730 .id_and_color =
2731 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
2732 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
2733 /* Set the channel info data */
2734 .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ?
2735 PHY_BAND_24 : PHY_BAND_5,
2736 .channel_info.channel = channel->hw_value,
2737 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
2738 /* Set the time and duration */
2739 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
2740 .apply_time_max_delay =
2741 cpu_to_le32(MSEC_TO_TU(AUX_ROC_MAX_DELAY_ON_CHANNEL)),
2742 .duration = cpu_to_le32(MSEC_TO_TU(duration)),
2743 };
2744
2745 /* Set the node address */
2746 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
2747
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002748 lockdep_assert_held(&mvm->mutex);
2749
2750 spin_lock_bh(&mvm->time_event_lock);
2751
2752 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
2753 spin_unlock_bh(&mvm->time_event_lock);
2754 return -EIO;
2755 }
2756
Ariej Marjiehb1128892014-07-16 21:11:12 +03002757 te_data->vif = vif;
2758 te_data->duration = duration;
2759 te_data->id = HOT_SPOT_CMD;
2760
Ariej Marjiehb1128892014-07-16 21:11:12 +03002761 spin_unlock_bh(&mvm->time_event_lock);
2762
2763 /*
2764 * Use a notification wait, which really just processes the
2765 * command response and doesn't wait for anything, in order
2766 * to be able to process the response and get the UID inside
2767 * the RX path. Using CMD_WANT_SKB doesn't work because it
2768 * stores the buffer and then wakes up this thread, by which
2769 * time another notification (that the time event started)
2770 * might already be processed unsuccessfully.
2771 */
2772 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
2773 time_event_response,
2774 ARRAY_SIZE(time_event_response),
2775 iwl_mvm_rx_aux_roc, te_data);
2776
2777 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
2778 &aux_roc_req);
2779
2780 if (res) {
2781 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
2782 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
2783 goto out_clear_te;
2784 }
2785
2786 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
2787 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
2788 /* should never fail */
2789 WARN_ON_ONCE(res);
2790
2791 if (res) {
2792 out_clear_te:
2793 spin_lock_bh(&mvm->time_event_lock);
2794 iwl_mvm_te_clear_data(mvm, te_data);
2795 spin_unlock_bh(&mvm->time_event_lock);
2796 }
2797
2798 return res;
2799}
2800
Johannes Berg8ca151b2013-01-24 14:25:36 +01002801static int iwl_mvm_roc(struct ieee80211_hw *hw,
2802 struct ieee80211_vif *vif,
2803 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002804 int duration,
2805 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002806{
2807 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002808 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002809 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03002810 struct iwl_mvm_phy_ctxt *phy_ctxt;
2811 int ret, i;
2812
2813 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
2814 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002815
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002816 mutex_lock(&mvm->mutex);
2817
Ariej Marjiehb1128892014-07-16 21:11:12 +03002818 switch (vif->type) {
2819 case NL80211_IFTYPE_STATION:
Luciano Coelho5ac6c722014-10-21 16:12:18 +03002820 if (mvm->fw->ucode_capa.capa[0] &
2821 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT) {
2822 /* Use aux roc framework (HS20) */
2823 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
2824 vif, duration);
2825 goto out_unlock;
2826 }
2827 IWL_ERR(mvm, "hotspot not supported\n");
2828 ret = -EINVAL;
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002829 goto out_unlock;
Ariej Marjiehb1128892014-07-16 21:11:12 +03002830 case NL80211_IFTYPE_P2P_DEVICE:
2831 /* handle below */
2832 break;
2833 default:
2834 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002835 ret = -EINVAL;
2836 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002837 }
2838
Ilan Peer31d385a2013-04-02 10:25:46 +03002839 for (i = 0; i < NUM_PHY_CTX; i++) {
2840 phy_ctxt = &mvm->phy_ctxts[i];
2841 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
2842 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002843
Ilan Peer31d385a2013-04-02 10:25:46 +03002844 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
2845 /*
2846 * Unbind the P2P_DEVICE from the current PHY context,
2847 * and if the PHY context is not used remove it.
2848 */
2849 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2850 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2851 goto out_unlock;
2852
2853 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2854
2855 /* Bind the P2P_DEVICE to the current PHY Context */
2856 mvmvif->phy_ctxt = phy_ctxt;
2857
2858 ret = iwl_mvm_binding_add_vif(mvm, vif);
2859 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2860 goto out_unlock;
2861
2862 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2863 goto schedule_time_event;
2864 }
2865 }
2866
2867 /* Need to update the PHY context only if the ROC channel changed */
2868 if (channel == mvmvif->phy_ctxt->channel)
2869 goto schedule_time_event;
2870
2871 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
2872
2873 /*
2874 * Change the PHY context configuration as it is currently referenced
2875 * only by the P2P Device MAC
2876 */
2877 if (mvmvif->phy_ctxt->ref == 1) {
2878 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2879 &chandef, 1, 1);
2880 if (ret)
2881 goto out_unlock;
2882 } else {
2883 /*
2884 * The PHY context is shared with other MACs. Need to remove the
2885 * P2P Device from the binding, allocate an new PHY context and
2886 * create a new binding
2887 */
2888 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2889 if (!phy_ctxt) {
2890 ret = -ENOSPC;
2891 goto out_unlock;
2892 }
2893
2894 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2895 1, 1);
2896 if (ret) {
2897 IWL_ERR(mvm, "Failed to change PHY context\n");
2898 goto out_unlock;
2899 }
2900
2901 /* Unbind the P2P_DEVICE from the current PHY context */
2902 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2903 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2904 goto out_unlock;
2905
2906 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2907
2908 /* Bind the P2P_DEVICE to the new allocated PHY context */
2909 mvmvif->phy_ctxt = phy_ctxt;
2910
2911 ret = iwl_mvm_binding_add_vif(mvm, vif);
2912 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2913 goto out_unlock;
2914
2915 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2916 }
2917
2918schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002919 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02002920 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002921
Ilan Peer31d385a2013-04-02 10:25:46 +03002922out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002923 mutex_unlock(&mvm->mutex);
2924 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01002925 return ret;
2926}
2927
2928static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
2929{
2930 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2931
2932 IWL_DEBUG_MAC80211(mvm, "enter\n");
2933
2934 mutex_lock(&mvm->mutex);
Matti Gottliebbf5da872014-11-16 10:25:12 +02002935 iwl_mvm_stop_roc(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002936 mutex_unlock(&mvm->mutex);
2937
2938 IWL_DEBUG_MAC80211(mvm, "leave\n");
2939 return 0;
2940}
2941
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002942static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
2943 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002944{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002945 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2946 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002947 int ret;
2948
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002949 lockdep_assert_held(&mvm->mutex);
2950
Ilan Peer53a9d612013-04-28 11:55:08 +03002951 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002952
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002953 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2954 if (!phy_ctxt) {
2955 ret = -ENOSPC;
2956 goto out;
2957 }
2958
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02002959 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Ilan Peer53a9d612013-04-28 11:55:08 +03002960 ctx->rx_chains_static,
2961 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002962 if (ret) {
2963 IWL_ERR(mvm, "Failed to add PHY context\n");
2964 goto out;
2965 }
2966
Ilan Peer53a9d612013-04-28 11:55:08 +03002967 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002968 *phy_ctxt_id = phy_ctxt->id;
2969out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002970 return ret;
2971}
2972
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002973static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2974 struct ieee80211_chanctx_conf *ctx)
2975{
2976 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2977 int ret;
2978
2979 mutex_lock(&mvm->mutex);
2980 ret = __iwl_mvm_add_chanctx(mvm, ctx);
2981 mutex_unlock(&mvm->mutex);
2982
2983 return ret;
2984}
2985
2986static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
2987 struct ieee80211_chanctx_conf *ctx)
2988{
2989 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2990 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2991
2992 lockdep_assert_held(&mvm->mutex);
2993
2994 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
2995}
2996
Johannes Berg8ca151b2013-01-24 14:25:36 +01002997static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2998 struct ieee80211_chanctx_conf *ctx)
2999{
3000 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003001
3002 mutex_lock(&mvm->mutex);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003003 __iwl_mvm_remove_chanctx(mvm, ctx);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003004 mutex_unlock(&mvm->mutex);
3005}
3006
3007static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3008 struct ieee80211_chanctx_conf *ctx,
3009 u32 changed)
3010{
3011 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003012 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3013 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01003014
Ilan Peer31d385a2013-04-02 10:25:46 +03003015 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3016 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3017 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
Arik Nemtsov2dceeda2013-12-29 17:57:53 +02003018 IEEE80211_CHANCTX_CHANGE_RADAR |
3019 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
Ilan Peer31d385a2013-04-02 10:25:46 +03003020 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3021 phy_ctxt->ref, changed))
3022 return;
3023
Johannes Berg8ca151b2013-01-24 14:25:36 +01003024 mutex_lock(&mvm->mutex);
Emmanuel Grumbach4d664492014-04-30 18:09:59 +03003025 iwl_mvm_bt_coex_vif_change(mvm);
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02003026 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003027 ctx->rx_chains_static,
3028 ctx->rx_chains_dynamic);
3029 mutex_unlock(&mvm->mutex);
3030}
3031
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003032static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3033 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02003034 struct ieee80211_chanctx_conf *ctx,
3035 bool switching_chanctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003036{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003037 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3038 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01003039 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3040 int ret;
3041
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003042 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003043
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003044 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003045
3046 switch (vif->type) {
3047 case NL80211_IFTYPE_AP:
Luciano Coelho4741dd02014-11-10 11:10:13 +02003048 /* only needed if we're switching chanctx (i.e. during CSA) */
3049 if (switching_chanctx) {
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003050 mvmvif->ap_ibss_active = true;
3051 break;
3052 }
Johannes Berg5023d962013-07-31 14:07:43 +02003053 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003054 /*
3055 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02003056 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01003057 */
3058 ret = 0;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003059 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003060 case NL80211_IFTYPE_STATION:
Luciano Coelho2533edc2014-08-08 19:50:46 +03003061 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003062 case NL80211_IFTYPE_MONITOR:
Luciano Coelho2533edc2014-08-08 19:50:46 +03003063 /* always disable PS when a monitor interface is active */
3064 mvmvif->ps_disabled = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003065 break;
3066 default:
3067 ret = -EINVAL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003068 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003069 }
3070
3071 ret = iwl_mvm_binding_add_vif(mvm, vif);
3072 if (ret)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003073 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003074
3075 /*
Alexander Bondar92d85562013-10-23 11:50:34 +02003076 * Power state must be updated before quotas,
3077 * otherwise fw will complain.
3078 */
Arik Nemtsov999609f2014-05-15 17:31:51 +03003079 iwl_mvm_power_update_mac(mvm);
Alexander Bondar92d85562013-10-23 11:50:34 +02003080
3081 /* Setting the quota at this stage is only required for monitor
Johannes Berg8ca151b2013-01-24 14:25:36 +01003082 * interfaces. For the other types, the bss_info changed flow
3083 * will handle quota settings.
3084 */
3085 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02003086 mvmvif->monitor_active = true;
Johannes Berg01662302014-06-06 15:18:45 +02003087 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003088 if (ret)
3089 goto out_remove_binding;
3090 }
3091
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003092 /* Handle binding during CSA */
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003093 if (vif->type == NL80211_IFTYPE_AP) {
Johannes Berg01662302014-06-06 15:18:45 +02003094 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02003095 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003096 }
3097
Luciano Coelho4741dd02014-11-10 11:10:13 +02003098 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
Luciano Coelho686e7fe2014-11-10 11:10:21 +02003099 u32 duration = 2 * vif->bss_conf.beacon_int;
3100
3101 /* iwl_mvm_protect_session() reads directly from the
3102 * device (the system time), so make sure it is
3103 * available.
3104 */
3105 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3106 if (ret)
3107 goto out_remove_binding;
3108
3109 /* Protect the session to make sure we hear the first
3110 * beacon on the new channel.
3111 */
3112 iwl_mvm_protect_session(mvm, vif, duration, duration,
3113 vif->bss_conf.beacon_int / 2,
3114 true);
3115
3116 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3117
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003118 iwl_mvm_update_quotas(mvm, NULL);
Luciano Coelho0ce04ce2014-05-08 16:03:39 +03003119 }
3120
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003121 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003122
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003123out_remove_binding:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003124 iwl_mvm_binding_remove_vif(mvm, vif);
Arik Nemtsov999609f2014-05-15 17:31:51 +03003125 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003126out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003127 if (ret)
3128 mvmvif->phy_ctxt = NULL;
3129 return ret;
3130}
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003131static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3132 struct ieee80211_vif *vif,
3133 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003134{
3135 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003136 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003137
3138 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003139 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003140 mutex_unlock(&mvm->mutex);
3141
3142 return ret;
3143}
3144
3145static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3146 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02003147 struct ieee80211_chanctx_conf *ctx,
3148 bool switching_chanctx)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003149{
3150 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003151 struct ieee80211_vif *disabled_vif = NULL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003152
3153 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003154
3155 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3156
Johannes Berg8ca151b2013-01-24 14:25:36 +01003157 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02003158 case NL80211_IFTYPE_ADHOC:
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003159 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003160 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02003161 mvmvif->monitor_active = false;
Luciano Coelho2533edc2014-08-08 19:50:46 +03003162 mvmvif->ps_disabled = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003163 break;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003164 case NL80211_IFTYPE_AP:
3165 /* This part is triggered only during CSA */
Luciano Coelho4741dd02014-11-10 11:10:13 +02003166 if (!switching_chanctx || !mvmvif->ap_ibss_active)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003167 goto out;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003168
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003169 mvmvif->csa_countdown = false;
3170
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03003171 /* Set CS bit on all the stations */
3172 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3173
3174 /* Save blocked iface, the timeout is set on the next beacon */
3175 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3176
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003177 mvmvif->ap_ibss_active = false;
Luciano Coelhof0c97782014-03-05 15:41:48 +02003178 break;
3179 case NL80211_IFTYPE_STATION:
3180 if (!switching_chanctx)
3181 break;
3182
3183 disabled_vif = vif;
3184
Johannes Berg3dfd3a92014-08-11 21:37:30 +02003185 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003186 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003187 default:
3188 break;
3189 }
3190
Luciano Coelhof0c97782014-03-05 15:41:48 +02003191 iwl_mvm_update_quotas(mvm, disabled_vif);
Ilan Peer1e1391c2013-03-13 14:52:04 +02003192 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03003193
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003194out:
Ilan Peera11e1442013-12-31 21:19:55 +02003195 mvmvif->phy_ctxt = NULL;
Arik Nemtsov999609f2014-05-15 17:31:51 +03003196 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003197}
3198
3199static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3200 struct ieee80211_vif *vif,
3201 struct ieee80211_chanctx_conf *ctx)
3202{
3203 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3204
3205 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003206 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003207 mutex_unlock(&mvm->mutex);
3208}
3209
Luciano Coelho50cc9572014-11-10 11:10:08 +02003210static int
3211iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3212 struct ieee80211_vif_chanctx_switch *vifs)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003213{
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003214 int ret;
3215
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003216 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003217 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003218 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3219
3220 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3221 if (ret) {
3222 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3223 goto out_reassign;
3224 }
3225
Luciano Coelhof0c97782014-03-05 15:41:48 +02003226 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3227 true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003228 if (ret) {
3229 IWL_ERR(mvm,
3230 "failed to assign new_ctx during channel switch\n");
3231 goto out_remove;
3232 }
3233
Arik Nemtsovf6972672014-06-15 16:03:55 +03003234 /* we don't support TDLS during DCM - can be caused by channel switch */
3235 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3236 iwl_mvm_teardown_tdls_peers(mvm);
3237
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003238 goto out;
3239
3240out_remove:
3241 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3242
3243out_reassign:
Luciano Coelho6fd1fb62014-11-10 11:10:10 +02003244 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003245 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3246 goto out_restart;
3247 }
3248
Luciano Coelho6fd1fb62014-11-10 11:10:10 +02003249 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3250 true)) {
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003251 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3252 goto out_restart;
3253 }
3254
3255 goto out;
3256
3257out_restart:
3258 /* things keep failing, better restart the hw */
3259 iwl_mvm_nic_restart(mvm, false);
3260
3261out:
3262 mutex_unlock(&mvm->mutex);
Luciano Coelho50cc9572014-11-10 11:10:08 +02003263
3264 return ret;
3265}
3266
Luciano Coelho48a256e2014-11-10 11:10:09 +02003267static int
3268iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3269 struct ieee80211_vif_chanctx_switch *vifs)
3270{
3271 int ret;
3272
3273 mutex_lock(&mvm->mutex);
3274 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3275
3276 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3277 true);
3278 if (ret) {
3279 IWL_ERR(mvm,
3280 "failed to assign new_ctx during channel switch\n");
3281 goto out_reassign;
3282 }
3283
3284 goto out;
3285
3286out_reassign:
3287 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3288 true)) {
3289 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3290 goto out_restart;
3291 }
3292
3293 goto out;
3294
3295out_restart:
3296 /* things keep failing, better restart the hw */
3297 iwl_mvm_nic_restart(mvm, false);
3298
3299out:
3300 mutex_unlock(&mvm->mutex);
3301
3302 return ret;
3303}
3304
Luciano Coelho50cc9572014-11-10 11:10:08 +02003305static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3306 struct ieee80211_vif_chanctx_switch *vifs,
3307 int n_vifs,
3308 enum ieee80211_chanctx_switch_mode mode)
3309{
3310 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3311 int ret;
3312
3313 /* we only support a single-vif right now */
3314 if (n_vifs > 1)
3315 return -EOPNOTSUPP;
3316
3317 switch (mode) {
3318 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3319 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3320 break;
3321 case CHANCTX_SWMODE_REASSIGN_VIF:
Luciano Coelho48a256e2014-11-10 11:10:09 +02003322 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
Luciano Coelho50cc9572014-11-10 11:10:08 +02003323 break;
3324 default:
3325 ret = -EOPNOTSUPP;
3326 break;
3327 }
3328
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003329 return ret;
3330}
3331
Johannes Berg8ca151b2013-01-24 14:25:36 +01003332static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3333 struct ieee80211_sta *sta,
3334 bool set)
3335{
3336 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01003337 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003338
3339 if (!mvm_sta || !mvm_sta->vif) {
3340 IWL_ERR(mvm, "Station is not associated to a vif\n");
3341 return -EINVAL;
3342 }
3343
3344 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3345}
3346
David Spinadel507cadf2013-07-31 18:07:21 +03003347#ifdef CONFIG_NL80211_TESTMODE
3348static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3349 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3350 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad422013-08-01 14:17:15 +02003351 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03003352};
3353
3354static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3355 struct ieee80211_vif *vif,
3356 void *data, int len)
3357{
3358 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3359 int err;
3360 u32 noa_duration;
3361
3362 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
3363 if (err)
3364 return err;
3365
3366 if (!tb[IWL_MVM_TM_ATTR_CMD])
3367 return -EINVAL;
3368
3369 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3370 case IWL_MVM_TM_CMD_SET_NOA:
3371 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3372 !vif->bss_conf.enable_beacon ||
3373 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3374 return -EINVAL;
3375
3376 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3377 if (noa_duration >= vif->bss_conf.beacon_int)
3378 return -EINVAL;
3379
3380 mvm->noa_duration = noa_duration;
3381 mvm->noa_vif = vif;
3382
Johannes Berg01662302014-06-06 15:18:45 +02003383 return iwl_mvm_update_quotas(mvm, NULL);
Johannes Bergf6c6ad422013-08-01 14:17:15 +02003384 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3385 /* must be associated client vif - ignore authorized */
3386 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3387 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3388 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3389 return -EINVAL;
3390
3391 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03003392 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3393 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
David Spinadel507cadf2013-07-31 18:07:21 +03003394 }
3395
3396 return -EOPNOTSUPP;
3397}
3398
3399static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3400 struct ieee80211_vif *vif,
3401 void *data, int len)
3402{
3403 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3404 int err;
3405
3406 mutex_lock(&mvm->mutex);
3407 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3408 mutex_unlock(&mvm->mutex);
3409
3410 return err;
3411}
3412#endif
3413
Luciano Coelho622e3f92014-11-10 11:10:17 +02003414static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3415 struct ieee80211_vif *vif,
3416 struct ieee80211_channel_switch *chsw)
3417{
3418 /* By implementing this operation, we prevent mac80211 from
3419 * starting its own channel switch timer, so that we can call
3420 * ieee80211_chswitch_done() ourselves at the right time
3421 * (which is when the absence time event starts).
3422 */
3423
3424 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3425 "dummy channel switch op\n");
3426}
3427
Luciano Coelhof0289052014-11-10 11:10:06 +02003428static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3429 struct ieee80211_vif *vif,
3430 struct ieee80211_channel_switch *chsw)
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003431{
3432 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003433 struct ieee80211_vif *csa_vif;
Luciano Coelhof6c34822014-11-10 11:10:12 +02003434 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003435 u32 apply_time;
Luciano Coelhof0289052014-11-10 11:10:06 +02003436 int ret;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003437
3438 mutex_lock(&mvm->mutex);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003439
Luciano Coelho6b20d772014-11-10 11:10:07 +02003440 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
Luciano Coelhof0289052014-11-10 11:10:06 +02003441 chsw->chandef.center_freq1);
Luciano Coelho6b20d772014-11-10 11:10:07 +02003442
3443 switch (vif->type) {
3444 case NL80211_IFTYPE_AP:
3445 csa_vif =
3446 rcu_dereference_protected(mvm->csa_vif,
3447 lockdep_is_held(&mvm->mutex));
3448 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3449 "Another CSA is already in progress")) {
3450 ret = -EBUSY;
3451 goto out_unlock;
3452 }
3453
3454 rcu_assign_pointer(mvm->csa_vif, vif);
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003455
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003456 if (WARN_ONCE(mvmvif->csa_countdown,
3457 "Previous CSA countdown didn't complete")) {
3458 ret = -EBUSY;
3459 goto out_unlock;
3460 }
3461
Luciano Coelho6b20d772014-11-10 11:10:07 +02003462 break;
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003463 case NL80211_IFTYPE_STATION:
Luciano Coelho4500e132014-11-10 11:10:15 +02003464 /* Schedule the time event to a bit before beacon 1,
3465 * to make sure we're in the new channel when the
3466 * GO/AP arrives.
3467 */
3468 apply_time = chsw->device_timestamp +
3469 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3470 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003471
3472 if (chsw->block_tx)
3473 iwl_mvm_csa_client_absent(mvm, vif);
3474
Luciano Coelho4500e132014-11-10 11:10:15 +02003475 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003476 apply_time);
Luciano Coelhoc6e0a3e02014-11-10 11:10:18 +02003477 if (mvmvif->bf_data.bf_enabled) {
3478 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3479 if (ret)
3480 goto out_unlock;
3481 }
3482
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003483 break;
Luciano Coelho6b20d772014-11-10 11:10:07 +02003484 default:
3485 break;
3486 }
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003487
Luciano Coelhof6c34822014-11-10 11:10:12 +02003488 mvmvif->ps_disabled = true;
3489
3490 ret = iwl_mvm_power_update_ps(mvm);
3491 if (ret)
3492 goto out_unlock;
Luciano Coelhof0289052014-11-10 11:10:06 +02003493
Arik Nemtsove198f5e2014-09-14 19:13:54 +03003494 /* we won't be on this channel any longer */
3495 iwl_mvm_teardown_tdls_peers(mvm);
3496
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003497out_unlock:
3498 mutex_unlock(&mvm->mutex);
Luciano Coelhof0289052014-11-10 11:10:06 +02003499
3500 return ret;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003501}
3502
Luciano Coelhof6c34822014-11-10 11:10:12 +02003503static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
3504 struct ieee80211_vif *vif)
3505{
3506 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3507 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3508 int ret;
3509
3510 mutex_lock(&mvm->mutex);
3511
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003512 if (vif->type == NL80211_IFTYPE_STATION) {
3513 struct iwl_mvm_sta *mvmsta;
3514
3515 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
3516 mvmvif->ap_sta_id);
3517
3518 if (WARN_ON(!mvmsta)) {
3519 ret = -EIO;
3520 goto out_unlock;
3521 }
3522
3523 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
3524
3525 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Luciano Coelhoc6e0a3e02014-11-10 11:10:18 +02003526
3527 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3528 if (ret)
3529 goto out_unlock;
Luciano Coelho686e7fe2014-11-10 11:10:21 +02003530
3531 iwl_mvm_stop_session_protection(mvm, vif);
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003532 }
3533
Luciano Coelhof6c34822014-11-10 11:10:12 +02003534 mvmvif->ps_disabled = false;
3535
3536 ret = iwl_mvm_power_update_ps(mvm);
3537
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003538out_unlock:
Luciano Coelhof6c34822014-11-10 11:10:12 +02003539 mutex_unlock(&mvm->mutex);
3540
3541 return ret;
3542}
3543
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003544static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
3545 struct ieee80211_vif *vif, u32 queues, bool drop)
3546{
3547 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3548 struct iwl_mvm_vif *mvmvif;
3549 struct iwl_mvm_sta *mvmsta;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03003550 struct ieee80211_sta *sta;
3551 int i;
3552 u32 msk = 0;
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003553
3554 if (!vif || vif->type != NL80211_IFTYPE_STATION)
3555 return;
3556
3557 mutex_lock(&mvm->mutex);
3558 mvmvif = iwl_mvm_vif_from_mac80211(vif);
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003559
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03003560 /* flush the AP-station and all TDLS peers */
3561 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
3562 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3563 lockdep_is_held(&mvm->mutex));
3564 if (IS_ERR_OR_NULL(sta))
3565 continue;
3566
3567 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3568 if (mvmsta->vif != vif)
3569 continue;
3570
3571 /* make sure only TDLS peers or the AP are flushed */
3572 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
3573
3574 msk |= mvmsta->tfd_queue_msk;
Johannes Berg480acbc2014-10-10 08:59:27 +02003575 }
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003576
Emmanuel Grumbach6d440b22015-01-20 09:25:19 +02003577 if (drop) {
3578 if (iwl_mvm_flush_tx_path(mvm, msk, true))
3579 IWL_ERR(mvm, "flush request fail\n");
3580 mutex_unlock(&mvm->mutex);
3581 } else {
3582 mutex_unlock(&mvm->mutex);
Johannes Berg480acbc2014-10-10 08:59:27 +02003583
Emmanuel Grumbach6d440b22015-01-20 09:25:19 +02003584 /* this can take a while, and we may need/want other operations
3585 * to succeed while doing this, so do it without the mutex held
3586 */
3587 iwl_trans_wait_tx_queue_empty(mvm->trans, msk);
3588 }
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003589}
3590
Johannes Berg91a8bcd2015-01-14 18:12:41 +01003591static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
3592 struct survey_info *survey)
3593{
3594 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3595 int ret;
3596
3597 memset(survey, 0, sizeof(*survey));
3598
3599 /* only support global statistics right now */
3600 if (idx != 0)
3601 return -ENOENT;
3602
3603 if (!(mvm->fw->ucode_capa.capa[0] &
3604 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
3605 return -ENOENT;
3606
3607 mutex_lock(&mvm->mutex);
3608
3609 if (mvm->ucode_loaded) {
Johannes Berg33cef922015-01-21 21:41:29 +01003610 ret = iwl_mvm_request_statistics(mvm, false);
Johannes Berg91a8bcd2015-01-14 18:12:41 +01003611 if (ret)
3612 goto out;
3613 }
3614
3615 survey->filled = SURVEY_INFO_TIME |
3616 SURVEY_INFO_TIME_RX |
3617 SURVEY_INFO_TIME_TX |
3618 SURVEY_INFO_TIME_SCAN;
3619 survey->time = mvm->accu_radio_stats.on_time_rf +
3620 mvm->radio_stats.on_time_rf;
3621 do_div(survey->time, USEC_PER_MSEC);
3622
3623 survey->time_rx = mvm->accu_radio_stats.rx_time +
3624 mvm->radio_stats.rx_time;
3625 do_div(survey->time_rx, USEC_PER_MSEC);
3626
3627 survey->time_tx = mvm->accu_radio_stats.tx_time +
3628 mvm->radio_stats.tx_time;
3629 do_div(survey->time_tx, USEC_PER_MSEC);
3630
3631 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
3632 mvm->radio_stats.on_time_scan;
3633 do_div(survey->time_scan, USEC_PER_MSEC);
3634
3635 out:
3636 mutex_unlock(&mvm->mutex);
3637 return ret;
3638}
3639
Johannes Berg33cef922015-01-21 21:41:29 +01003640static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
3641 struct ieee80211_vif *vif,
3642 struct ieee80211_sta *sta,
3643 struct station_info *sinfo)
3644{
3645 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3646 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3647 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3648
3649 if (!(mvm->fw->ucode_capa.capa[0] &
3650 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
3651 return;
3652
3653 /* if beacon filtering isn't on mac80211 does it anyway */
3654 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
3655 return;
3656
3657 if (!vif->bss_conf.assoc)
3658 return;
3659
3660 mutex_lock(&mvm->mutex);
3661
3662 if (mvmvif->ap_sta_id != mvmsta->sta_id)
3663 goto unlock;
3664
3665 if (iwl_mvm_request_statistics(mvm, false))
3666 goto unlock;
3667
3668 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
3669 mvmvif->beacon_stats.accu_num_beacons;
3670 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX);
3671 if (mvmvif->beacon_stats.avg_signal) {
3672 /* firmware only reports a value after RXing a few beacons */
3673 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
3674 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
3675 }
3676 unlock:
3677 mutex_unlock(&mvm->mutex);
3678}
3679
Johannes Berge5209262014-01-20 23:38:59 +01003680const struct ieee80211_ops iwl_mvm_hw_ops = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01003681 .tx = iwl_mvm_mac_tx,
3682 .ampdu_action = iwl_mvm_mac_ampdu_action,
3683 .start = iwl_mvm_mac_start,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02003684 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003685 .stop = iwl_mvm_mac_stop,
3686 .add_interface = iwl_mvm_mac_add_interface,
3687 .remove_interface = iwl_mvm_mac_remove_interface,
3688 .config = iwl_mvm_mac_config,
Eliad Pellere59647e2013-11-28 14:08:50 +02003689 .prepare_multicast = iwl_mvm_prepare_multicast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003690 .configure_filter = iwl_mvm_configure_filter,
3691 .bss_info_changed = iwl_mvm_bss_info_changed,
3692 .hw_scan = iwl_mvm_mac_hw_scan,
3693 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
Johannes Berg1ddbbb02013-12-04 22:39:17 +01003694 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003695 .sta_state = iwl_mvm_mac_sta_state,
3696 .sta_notify = iwl_mvm_mac_sta_notify,
3697 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
Johannes Berg3e56ead2013-02-15 22:23:18 +01003698 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003699 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02003700 .sta_rc_update = iwl_mvm_sta_rc_update,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003701 .conf_tx = iwl_mvm_mac_conf_tx,
3702 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
Arik Nemtsov07ecd892014-05-20 18:16:42 +03003703 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003704 .flush = iwl_mvm_mac_flush,
David Spinadel35a000b2013-08-28 09:29:43 +03003705 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
3706 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003707 .set_key = iwl_mvm_mac_set_key,
3708 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
3709 .remain_on_channel = iwl_mvm_roc,
3710 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003711 .add_chanctx = iwl_mvm_add_chanctx,
3712 .remove_chanctx = iwl_mvm_remove_chanctx,
3713 .change_chanctx = iwl_mvm_change_chanctx,
3714 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
3715 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003716 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003717
Johannes Berg5023d962013-07-31 14:07:43 +02003718 .start_ap = iwl_mvm_start_ap_ibss,
3719 .stop_ap = iwl_mvm_stop_ap_ibss,
3720 .join_ibss = iwl_mvm_start_ap_ibss,
3721 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003722
3723 .set_tim = iwl_mvm_set_tim,
3724
Luciano Coelho622e3f92014-11-10 11:10:17 +02003725 .channel_switch = iwl_mvm_channel_switch,
Luciano Coelhof0289052014-11-10 11:10:06 +02003726 .pre_channel_switch = iwl_mvm_pre_channel_switch,
Luciano Coelhof6c34822014-11-10 11:10:12 +02003727 .post_channel_switch = iwl_mvm_post_channel_switch,
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003728
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +03003729 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
3730 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
3731 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
3732
David Spinadel507cadf2013-07-31 18:07:21 +03003733 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
3734
Johannes Berg8ca151b2013-01-24 14:25:36 +01003735#ifdef CONFIG_PM_SLEEP
3736 /* look at d3.c */
3737 .suspend = iwl_mvm_suspend,
3738 .resume = iwl_mvm_resume,
3739 .set_wakeup = iwl_mvm_set_wakeup,
3740 .set_rekey_data = iwl_mvm_set_rekey_data,
3741#if IS_ENABLED(CONFIG_IPV6)
3742 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
3743#endif
3744 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
3745#endif
Johannes Berg91a8bcd2015-01-14 18:12:41 +01003746 .get_survey = iwl_mvm_mac_get_survey,
Johannes Berg33cef922015-01-21 21:41:29 +01003747 .sta_statistics = iwl_mvm_mac_sta_statistics,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003748};