blob: 19aff50648ef8dc2ce8d71ec11a24403b151d793 [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"
Johannes Berg8ca151b2013-01-24 14:25:36 +010088
89static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
90 {
91 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030092 .types = BIT(NL80211_IFTYPE_STATION),
Johannes Berg8ca151b2013-01-24 14:25:36 +010093 },
Johannes Berg3c15a0f2013-05-31 10:17:19 +020094 {
95 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030096 .types = BIT(NL80211_IFTYPE_AP) |
97 BIT(NL80211_IFTYPE_P2P_CLIENT) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +020098 BIT(NL80211_IFTYPE_P2P_GO),
99 },
100 {
101 .max = 1,
102 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
103 },
Johannes Berg8ca151b2013-01-24 14:25:36 +0100104};
105
106static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
107 {
108 .num_different_channels = 1,
109 .max_interfaces = 3,
110 .limits = iwl_mvm_limits,
111 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
112 },
113};
114
Johannes Bergf0c26462013-01-22 20:41:58 +0100115#ifdef CONFIG_PM_SLEEP
116static const struct nl80211_wowlan_tcp_data_token_feature
117iwl_mvm_wowlan_tcp_token_feature = {
118 .min_len = 0,
119 .max_len = 255,
120 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
121};
122
123static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
124 .tok = &iwl_mvm_wowlan_tcp_token_feature,
125 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
126 sizeof(struct ethhdr) -
127 sizeof(struct iphdr) -
128 sizeof(struct tcphdr),
129 .data_interval_max = 65535, /* __le16 in API */
130 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
131 sizeof(struct ethhdr) -
132 sizeof(struct iphdr) -
133 sizeof(struct tcphdr),
134 .seq = true,
135};
136#endif
137
Eliad Peller77736922014-01-14 12:35:49 +0200138#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
Eliad Peller2ee8f022014-01-13 19:07:09 +0200139/*
140 * Use the reserved field to indicate magic values.
141 * these values will only be used internally by the driver,
142 * and won't make it to the fw (reserved will be 0).
143 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
144 * be the vif's ip address. in case there is not a single
145 * ip address (0, or more than 1), this attribute will
146 * be skipped.
147 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
148 * the LSB bytes of the vif's mac address
149 */
150enum {
151 BC_FILTER_MAGIC_NONE = 0,
152 BC_FILTER_MAGIC_IP,
153 BC_FILTER_MAGIC_MAC,
154};
155
Eliad Peller77736922014-01-14 12:35:49 +0200156static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
157 {
158 /* arp */
159 .discard = 0,
160 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
161 .attrs = {
162 {
163 /* frame type - arp, hw type - ethernet */
164 .offset_type =
165 BCAST_FILTER_OFFSET_PAYLOAD_START,
166 .offset = sizeof(rfc1042_header),
167 .val = cpu_to_be32(0x08060001),
168 .mask = cpu_to_be32(0xffffffff),
169 },
Eliad Peller2ee8f022014-01-13 19:07:09 +0200170 {
171 /* arp dest ip */
172 .offset_type =
173 BCAST_FILTER_OFFSET_PAYLOAD_START,
174 .offset = sizeof(rfc1042_header) + 2 +
175 sizeof(struct arphdr) +
176 ETH_ALEN + sizeof(__be32) +
177 ETH_ALEN,
178 .mask = cpu_to_be32(0xffffffff),
179 /* mark it as special field */
180 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
181 },
182 },
183 },
184 {
185 /* dhcp offer bcast */
186 .discard = 0,
187 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
188 .attrs = {
189 {
190 /* udp dest port - 68 (bootp client)*/
191 .offset_type = BCAST_FILTER_OFFSET_IP_END,
192 .offset = offsetof(struct udphdr, dest),
193 .val = cpu_to_be32(0x00440000),
194 .mask = cpu_to_be32(0xffff0000),
195 },
196 {
197 /* dhcp - lsb bytes of client hw address */
198 .offset_type = BCAST_FILTER_OFFSET_IP_END,
199 .offset = 38,
200 .mask = cpu_to_be32(0xffffffff),
201 /* mark it as special field */
202 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
203 },
Eliad Peller77736922014-01-14 12:35:49 +0200204 },
205 },
206 /* last filter must be empty */
207 {},
208};
209#endif
210
Eliad Peller7498cf42014-01-16 17:10:44 +0200211void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
212{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200213 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200214 return;
215
216 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
Eliad Peller576eeee2014-07-01 18:38:38 +0300217 spin_lock_bh(&mvm->refs_lock);
218 mvm->refs[ref_type]++;
219 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200220 iwl_trans_ref(mvm->trans);
221}
222
223void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
224{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200225 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200226 return;
227
228 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
Eliad Peller576eeee2014-07-01 18:38:38 +0300229 spin_lock_bh(&mvm->refs_lock);
230 WARN_ON(!mvm->refs[ref_type]--);
231 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200232 iwl_trans_unref(mvm->trans);
233}
234
Eliad Peller576eeee2014-07-01 18:38:38 +0300235static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
236 enum iwl_mvm_ref_type except_ref)
Eliad Peller7498cf42014-01-16 17:10:44 +0200237{
Eliad Peller576eeee2014-07-01 18:38:38 +0300238 int i, j;
Eliad Peller7498cf42014-01-16 17:10:44 +0200239
Eliad Peller7bb426e2014-02-24 12:54:37 +0200240 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200241 return;
242
Eliad Peller576eeee2014-07-01 18:38:38 +0300243 spin_lock_bh(&mvm->refs_lock);
244 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
245 if (except_ref == i || !mvm->refs[i])
Eliad Peller7498cf42014-01-16 17:10:44 +0200246 continue;
247
Eliad Peller576eeee2014-07-01 18:38:38 +0300248 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
249 i, mvm->refs[i]);
250 for (j = 0; j < mvm->refs[i]; j++)
251 iwl_trans_unref(mvm->trans);
252 mvm->refs[i] = 0;
Eliad Peller7498cf42014-01-16 17:10:44 +0200253 }
Eliad Peller576eeee2014-07-01 18:38:38 +0300254 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200255}
256
Eliad Pellerf4cf8682014-11-04 16:57:06 +0200257bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
258{
259 int i;
260 bool taken = false;
261
262 if (!iwl_mvm_is_d0i3_supported(mvm))
263 return true;
264
265 spin_lock_bh(&mvm->refs_lock);
266 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
267 if (mvm->refs[i]) {
268 taken = true;
269 break;
270 }
271 }
272 spin_unlock_bh(&mvm->refs_lock);
273
274 return taken;
275}
276
Eliad Peller576eeee2014-07-01 18:38:38 +0300277int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
Gregory Greenmand40fc482014-06-25 14:08:50 +0200278{
279 iwl_mvm_ref(mvm, ref_type);
280
281 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
282 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
283 HZ)) {
284 WARN_ON_ONCE(1);
285 iwl_mvm_unref(mvm, ref_type);
286 return -EIO;
287 }
288
289 return 0;
290}
291
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200292static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
293{
294 int i;
295
296 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
297 for (i = 0; i < NUM_PHY_CTX; i++) {
298 mvm->phy_ctxts[i].id = i;
299 mvm->phy_ctxts[i].ref = 0;
300 }
301}
302
Johannes Berg8ca151b2013-01-24 14:25:36 +0100303int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
304{
305 struct ieee80211_hw *hw = mvm->hw;
Ilan Peer831e85f2013-02-07 17:09:09 +0200306 int num_mac, ret, i;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100307
308 /* Tell mac80211 our characteristics */
309 hw->flags = IEEE80211_HW_SIGNAL_DBM |
310 IEEE80211_HW_SPECTRUM_MGMT |
311 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
312 IEEE80211_HW_QUEUE_CONTROL |
313 IEEE80211_HW_WANT_MONITOR_VIF |
Johannes Berg8ca151b2013-01-24 14:25:36 +0100314 IEEE80211_HW_SUPPORTS_PS |
315 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Johannes Bergd2931bb2013-02-05 18:10:04 +0100316 IEEE80211_HW_AMPDU_AGGREGATION |
Hila Gonend64048e2013-03-13 18:00:03 +0200317 IEEE80211_HW_TIMING_BEACON_ONLY |
Emmanuel Grumbach147fc9b2013-07-28 11:00:52 +0300318 IEEE80211_HW_CONNECTION_MONITOR |
Ido Yarivb71d9c82014-07-23 09:31:14 -0400319 IEEE80211_HW_CHANCTX_STA_CSA |
320 IEEE80211_HW_SUPPORTS_CLONED_SKBS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100321
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200322 hw->queues = mvm->first_agg_queue;
Ilan Peer398e8c62013-03-13 15:20:35 +0200323 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +0200324 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
325 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
326 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100327 hw->rate_control_algorithm = "iwl-mvm-rs";
328
329 /*
330 * Enable 11w if advertised by firmware and software crypto
331 * is not enabled (as the firmware will interpret some mgmt
332 * packets, so enabling it with software crypto isn't safe)
333 */
334 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
335 !iwlwifi_mod_params.sw_crypto)
336 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
337
Matt Chen1504f482014-04-24 18:43:18 +0800338 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT &&
339 IWL_UCODE_API(mvm->fw->ucode_ver) >= 9 &&
340 !iwlwifi_mod_params.uapsd_disable) {
341 hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
Eliad Peller4cb832d2014-08-06 10:52:27 +0300342 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
Matt Chen1504f482014-04-24 18:43:18 +0800343 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
344 }
Alexander Bondare8e626a2013-10-16 00:21:34 +0200345
David Spinadelfb98be52014-05-04 12:51:10 +0300346 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
347 hw->flags |= IEEE80211_SINGLE_HW_SCAN_ON_ALL_BANDS;
348
Johannes Berg8ca151b2013-01-24 14:25:36 +0100349 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
350 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200351 hw->chanctx_data_size = sizeof(u16);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100352
353 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200354 BIT(NL80211_IFTYPE_P2P_CLIENT) |
355 BIT(NL80211_IFTYPE_AP) |
356 BIT(NL80211_IFTYPE_P2P_GO) |
Emmanuel Grumbachc13b1722014-03-27 19:12:12 +0200357 BIT(NL80211_IFTYPE_P2P_DEVICE) |
358 BIT(NL80211_IFTYPE_ADHOC);
Johannes Berg5023d962013-07-31 14:07:43 +0200359
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +0100360 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
361 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
362 REGULATORY_DISABLE_BEACON_HINTS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100363
Johannes Berg3e56ead2013-02-15 22:23:18 +0100364 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
365 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
366
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +0200367 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_CSA_FLOW)
368 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
369
Johannes Berg8ca151b2013-01-24 14:25:36 +0100370 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
371 hw->wiphy->n_iface_combinations =
372 ARRAY_SIZE(iwl_mvm_iface_combinations);
373
Ilan Peerc451e6d2013-02-20 08:41:54 +0200374 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100375 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
376
377 /* Extract MAC address */
378 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
379 hw->wiphy->addresses = mvm->addresses;
380 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200381
382 /* Extract additional MAC addresses if available */
383 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
384 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
385
386 for (i = 1; i < num_mac; i++) {
387 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100388 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200389 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100390 hw->wiphy->n_addresses++;
391 }
392
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200393 iwl_mvm_reset_phy_ctxts(mvm);
394
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300395 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm, false);
David Spinadel20f1a5d2013-08-21 09:14:27 +0300396
Johannes Berg8ca151b2013-01-24 14:25:36 +0100397 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
398
399 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
400 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
401 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
402 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
403 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
404 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
405
406 hw->wiphy->hw_version = mvm->trans->hw_id;
407
Alexander Bondarade50652013-04-03 16:28:47 +0300408 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100409 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
410 else
411 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
412
Emmanuel Grumbach6efaaf32014-09-01 10:03:21 +0300413 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 10) {
414 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
415 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
416 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
417 /* we create the 802.11 header and zero length SSID IE. */
418 hw->wiphy->max_sched_scan_ie_len =
419 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
420 }
David Spinadel35a000b2013-08-28 09:29:43 +0300421
Johannes Berg8ca151b2013-01-24 14:25:36 +0100422 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
Johannes Bergab480032014-06-04 10:13:50 +0200423 NL80211_FEATURE_LOW_PRIORITY_SCAN |
Eliad Peller0d8614b2014-09-10 14:07:36 +0300424 NL80211_FEATURE_P2P_GO_OPPPS |
425 NL80211_FEATURE_DYNAMIC_SMPS |
Emmanuel Grumbach9b5452f2014-10-07 10:38:53 +0300426 NL80211_FEATURE_STATIC_SMPS |
427 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100428
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300429 if (mvm->fw->ucode_capa.capa[0] &
430 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)
431 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
Assaf Krauss226bcd42014-03-13 08:12:15 +0200432 if (mvm->fw->ucode_capa.capa[0] &
433 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)
434 hw->wiphy->features |= NL80211_FEATURE_QUIET;
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300435
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300436 if (mvm->fw->ucode_capa.capa[0] &
437 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)
438 hw->wiphy->features |=
439 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
440
441 if (mvm->fw->ucode_capa.capa[0] &
442 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)
443 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
444
Johannes Berg8ca151b2013-01-24 14:25:36 +0100445 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
446
Max Stepanove36e5432013-08-27 19:56:13 +0300447 /* currently FW API supports only one optional cipher scheme */
Johannes Berg9ddca862014-01-06 09:29:40 +0100448 if (mvm->fw->cs[0].cipher) {
Max Stepanove36e5432013-08-27 19:56:13 +0300449 mvm->hw->n_cipher_schemes = 1;
Johannes Berg9ddca862014-01-06 09:29:40 +0100450 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
Max Stepanove36e5432013-08-27 19:56:13 +0300451 }
452
Johannes Berg8ca151b2013-01-24 14:25:36 +0100453#ifdef CONFIG_PM_SLEEP
Eliad Pellerd15a7472014-03-27 18:53:12 +0200454 if (iwl_mvm_is_d0i3_supported(mvm) &&
455 device_can_wakeup(mvm->trans->dev)) {
456 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
457 hw->wiphy->wowlan = &mvm->wowlan;
458 } else if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100459 mvm->trans->ops->d3_suspend &&
460 mvm->trans->ops->d3_resume &&
461 device_can_wakeup(mvm->trans->dev)) {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200462 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
463 WIPHY_WOWLAN_DISCONNECT |
464 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
465 WIPHY_WOWLAN_RFKILL_RELEASE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100466 if (!iwlwifi_mod_params.sw_crypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200467 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
468 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
469 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100470
Johannes Berg964dc9e2013-06-03 17:25:34 +0200471 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
472 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
473 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
474 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
475 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100476 }
477#endif
478
Eliad Peller77736922014-01-14 12:35:49 +0200479#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
480 /* assign default bcast filtering configuration */
481 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
482#endif
483
Johannes Berg8ca151b2013-01-24 14:25:36 +0100484 ret = iwl_mvm_leds_init(mvm);
485 if (ret)
486 return ret;
487
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300488 ret = ieee80211_register_hw(mvm->hw);
489 if (ret)
490 iwl_mvm_leds_exit(mvm);
491
492 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100493}
494
Arik Nemtsovb2492502014-03-13 12:21:50 +0200495static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
496 struct ieee80211_sta *sta,
497 struct sk_buff *skb)
498{
499 struct iwl_mvm_sta *mvmsta;
500 bool defer = false;
501
502 /*
503 * double check the IN_D0I3 flag both before and after
504 * taking the spinlock, in order to prevent taking
505 * the spinlock when not needed.
506 */
507 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
508 return false;
509
510 spin_lock(&mvm->d0i3_tx_lock);
511 /*
512 * testing the flag again ensures the skb dequeue
513 * loop (on d0i3 exit) hasn't run yet.
514 */
515 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
516 goto out;
517
518 mvmsta = iwl_mvm_sta_from_mac80211(sta);
519 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
520 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
521 goto out;
522
523 __skb_queue_tail(&mvm->d0i3_tx, skb);
524 ieee80211_stop_queues(mvm->hw);
525
526 /* trigger wakeup */
527 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
528 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
529
530 defer = true;
531out:
532 spin_unlock(&mvm->d0i3_tx_lock);
533 return defer;
534}
535
Johannes Berg8ca151b2013-01-24 14:25:36 +0100536static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
537 struct ieee80211_tx_control *control,
538 struct sk_buff *skb)
539{
540 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg3e56ead2013-02-15 22:23:18 +0100541 struct ieee80211_sta *sta = control->sta;
542 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
543 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100544
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300545 if (iwl_mvm_is_radio_killed(mvm)) {
546 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100547 goto drop;
548 }
549
Ilan Peer398e8c62013-03-13 15:20:35 +0200550 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Matti Gottlieba6cc5162014-09-29 11:46:04 +0300551 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
552 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100553 goto drop;
554
Johannes Berg3e56ead2013-02-15 22:23:18 +0100555 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
556 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
557 ieee80211_is_mgmt(hdr->frame_control) &&
558 !ieee80211_is_deauth(hdr->frame_control) &&
559 !ieee80211_is_disassoc(hdr->frame_control) &&
560 !ieee80211_is_action(hdr->frame_control)))
561 sta = NULL;
562
563 if (sta) {
Arik Nemtsovb2492502014-03-13 12:21:50 +0200564 if (iwl_mvm_defer_tx(mvm, sta, skb))
565 return;
Johannes Berg3e56ead2013-02-15 22:23:18 +0100566 if (iwl_mvm_tx_skb(mvm, skb, sta))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100567 goto drop;
568 return;
569 }
570
571 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
572 goto drop;
573 return;
574 drop:
575 ieee80211_free_txskb(hw, skb);
576}
577
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200578static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
579{
580 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
581 return false;
582 return true;
583}
584
585static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
586{
587 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
588 return false;
589 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
590 return true;
591
592 /* enabled by default */
593 return true;
594}
595
Johannes Berg8ca151b2013-01-24 14:25:36 +0100596static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
597 struct ieee80211_vif *vif,
598 enum ieee80211_ampdu_mlme_action action,
599 struct ieee80211_sta *sta, u16 tid,
600 u16 *ssn, u8 buf_size)
601{
602 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
603 int ret;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200604 bool tx_agg_ref = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100605
606 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
607 sta->addr, tid, action);
608
609 if (!(mvm->nvm_data->sku_cap_11n_enable))
610 return -EACCES;
611
Arik Nemtsovb2492502014-03-13 12:21:50 +0200612 /* return from D0i3 before starting a new Tx aggregation */
Eliad Peller9256c202014-04-22 13:33:29 +0300613 switch (action) {
614 case IEEE80211_AMPDU_TX_START:
615 case IEEE80211_AMPDU_TX_STOP_CONT:
616 case IEEE80211_AMPDU_TX_STOP_FLUSH:
617 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
618 case IEEE80211_AMPDU_TX_OPERATIONAL:
Arik Nemtsovb2492502014-03-13 12:21:50 +0200619 /*
Eliad Peller9256c202014-04-22 13:33:29 +0300620 * for tx start, wait synchronously until D0i3 exit to
621 * get the correct sequence number for the tid.
622 * additionally, some other ampdu actions use direct
623 * target access, which is not handled automatically
624 * by the trans layer (unlike commands), so wait for
625 * d0i3 exit in these cases as well.
Arik Nemtsovb2492502014-03-13 12:21:50 +0200626 */
Gregory Greenmand40fc482014-06-25 14:08:50 +0200627 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
628 if (ret)
629 return ret;
630
631 tx_agg_ref = true;
Eliad Peller9256c202014-04-22 13:33:29 +0300632 break;
633 default:
634 break;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200635 }
636
Johannes Berg8ca151b2013-01-24 14:25:36 +0100637 mutex_lock(&mvm->mutex);
638
639 switch (action) {
640 case IEEE80211_AMPDU_RX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200641 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100642 ret = -EINVAL;
643 break;
644 }
645 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
646 break;
647 case IEEE80211_AMPDU_RX_STOP:
648 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
649 break;
650 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200651 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200652 ret = -EINVAL;
653 break;
654 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100655 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
656 break;
657 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200658 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
659 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100660 case IEEE80211_AMPDU_TX_STOP_FLUSH:
661 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200662 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100663 break;
664 case IEEE80211_AMPDU_TX_OPERATIONAL:
665 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
666 break;
667 default:
668 WARN_ON_ONCE(1);
669 ret = -EINVAL;
670 break;
671 }
672 mutex_unlock(&mvm->mutex);
673
Arik Nemtsovb2492502014-03-13 12:21:50 +0200674 /*
675 * If the tid is marked as started, we won't use it for offloaded
676 * traffic on the next D0i3 entry. It's safe to unref.
677 */
678 if (tx_agg_ref)
679 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
680
Johannes Berg8ca151b2013-01-24 14:25:36 +0100681 return ret;
682}
683
684static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
685 struct ieee80211_vif *vif)
686{
687 struct iwl_mvm *mvm = data;
688 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
689
690 mvmvif->uploaded = false;
691 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
692
693 /* does this make sense at all? */
694 mvmvif->color++;
695
696 spin_lock_bh(&mvm->time_event_lock);
697 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
698 spin_unlock_bh(&mvm->time_event_lock);
699
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200700 mvmvif->phy_ctxt = NULL;
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +0300701 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100702}
703
Johannes Bergaadede62014-10-09 17:01:36 +0200704static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count,
705 const void *data, size_t datalen)
706{
707 const struct iwl_mvm_dump_ptrs *dump_ptrs = data;
708 ssize_t bytes_read;
709 ssize_t bytes_read_trans;
710
711 if (offset < dump_ptrs->op_mode_len) {
712 bytes_read = min_t(ssize_t, count,
713 dump_ptrs->op_mode_len - offset);
714 memcpy(buffer, (u8 *)dump_ptrs->op_mode_ptr + offset,
715 bytes_read);
716 offset += bytes_read;
717 count -= bytes_read;
718
719 if (count == 0)
720 return bytes_read;
721 } else {
722 bytes_read = 0;
723 }
724
725 if (!dump_ptrs->trans_ptr)
726 return bytes_read;
727
728 offset -= dump_ptrs->op_mode_len;
729 bytes_read_trans = min_t(ssize_t, count,
730 dump_ptrs->trans_ptr->len - offset);
731 memcpy(buffer + bytes_read,
732 (u8 *)dump_ptrs->trans_ptr->data + offset,
733 bytes_read_trans);
734
735 return bytes_read + bytes_read_trans;
736}
737
738static void iwl_mvm_free_coredump(const void *data)
739{
740 const struct iwl_mvm_dump_ptrs *fw_error_dump = data;
741
742 vfree(fw_error_dump->op_mode_ptr);
743 vfree(fw_error_dump->trans_ptr);
744 kfree(fw_error_dump);
745}
746
Emmanuel Grumbach4bfa47f2014-09-11 16:19:43 +0300747void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300748{
749 struct iwl_fw_error_dump_file *dump_file;
750 struct iwl_fw_error_dump_data *dump_data;
751 struct iwl_fw_error_dump_info *dump_info;
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300752 struct iwl_mvm_dump_ptrs *fw_error_dump;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300753 const struct fw_img *img;
754 u32 sram_len, sram_ofs;
755 u32 file_len, rxf_len;
756 unsigned long flags;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300757 int reg_val;
758
759 lockdep_assert_held(&mvm->mutex);
760
Johannes Bergaadede62014-10-09 17:01:36 +0200761 fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300762 if (!fw_error_dump)
763 return;
764
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300765 img = &mvm->fw->img[mvm->cur_ucode];
766 sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
767 sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
768
769 /* reading buffer size */
770 reg_val = iwl_trans_read_prph(mvm->trans, RXF_SIZE_ADDR);
771 rxf_len = (reg_val & RXF_SIZE_BYTE_CNT_MSK) >> RXF_SIZE_BYTE_CND_POS;
772
773 /* the register holds the value divided by 128 */
774 rxf_len = rxf_len << 7;
775
776 file_len = sizeof(*dump_file) +
777 sizeof(*dump_data) * 3 +
778 sram_len +
779 rxf_len +
780 sizeof(*dump_info);
781
Emmanuel Grumbach5bfe6f52014-06-25 16:21:43 +0300782 dump_file = vzalloc(file_len);
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300783 if (!dump_file) {
784 kfree(fw_error_dump);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300785 return;
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300786 }
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300787
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300788 fw_error_dump->op_mode_ptr = dump_file;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300789
790 dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300791 dump_data = (void *)dump_file->data;
792
793 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
794 dump_data->len = cpu_to_le32(sizeof(*dump_info));
795 dump_info = (void *) dump_data->data;
796 dump_info->device_family =
797 mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
798 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
799 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
800 memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
801 sizeof(dump_info->fw_human_readable));
802 strncpy(dump_info->dev_human_readable, mvm->cfg->name,
803 sizeof(dump_info->dev_human_readable));
804 strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
805 sizeof(dump_info->bus_human_readable));
806
807 dump_data = iwl_fw_error_next_data(dump_data);
808 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
809 dump_data->len = cpu_to_le32(rxf_len);
810
811 if (iwl_trans_grab_nic_access(mvm->trans, false, &flags)) {
812 u32 *rxf = (void *)dump_data->data;
813 int i;
814
815 for (i = 0; i < (rxf_len / sizeof(u32)); i++) {
816 iwl_trans_write_prph(mvm->trans,
817 RXF_LD_FENCE_OFFSET_ADDR,
818 i * sizeof(u32));
819 rxf[i] = iwl_trans_read_prph(mvm->trans,
820 RXF_FIFO_RD_FENCE_ADDR);
821 }
822 iwl_trans_release_nic_access(mvm->trans, &flags);
823 }
824
825 dump_data = iwl_fw_error_next_data(dump_data);
826 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_SRAM);
827 dump_data->len = cpu_to_le32(sram_len);
828 iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_data->data,
829 sram_len);
830
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300831 fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans);
832 fw_error_dump->op_mode_len = file_len;
833 if (fw_error_dump->trans_ptr)
834 file_len += fw_error_dump->trans_ptr->len;
835 dump_file->file_len = cpu_to_le32(file_len);
Emmanuel Grumbach4bfa47f2014-09-11 16:19:43 +0300836
Johannes Bergaadede62014-10-09 17:01:36 +0200837 dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
838 GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300839}
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300840
Johannes Berg8ca151b2013-01-24 14:25:36 +0100841static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
842{
Johannes Berg58629d92014-11-06 09:40:50 +0100843 /* clear the D3 reconfig, we only need it to avoid dumping a
844 * firmware coredump on reconfiguration, we shouldn't do that
845 * on D3->D0 transition
846 */
847 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status))
848 iwl_mvm_fw_error_dump(mvm);
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +0200849
Johannes Berg8ca151b2013-01-24 14:25:36 +0100850 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100851
852 mvm->scan_status = IWL_MVM_SCAN_NONE;
Luciano Coelhob1873302014-08-08 17:12:07 +0300853 mvm->ps_disabled = false;
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200854 mvm->calibrating = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100855
856 /* just in case one was running */
857 ieee80211_remain_on_channel_expired(mvm->hw);
858
859 ieee80211_iterate_active_interfaces_atomic(
860 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
861 iwl_mvm_cleanup_iterator, mvm);
862
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200863 mvm->p2p_device_vif = NULL;
Eliad Peller37577fe2013-12-05 17:19:39 +0200864 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200865
866 iwl_mvm_reset_phy_ctxts(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100867 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
868 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +0300869 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
870 memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
871 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
872 memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
873 memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk));
874 memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100875
876 ieee80211_wake_queues(mvm->hw);
877
Eliad Peller7498cf42014-01-16 17:10:44 +0200878 /* cleanup all stale references (scan, roc), but keep the
879 * ucode_down ref until reconfig is complete */
880 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
881
Eliad Peller228670b2014-08-10 17:00:15 +0300882 /* clear any stale d0i3 state */
883 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
884
Johannes Berg8ca151b2013-01-24 14:25:36 +0100885 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +0300886 mvm->rx_ba_sessions = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100887}
888
Luciano Coelhoa0a09242014-09-04 12:29:15 +0300889int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100890{
Johannes Berg8ca151b2013-01-24 14:25:36 +0100891 int ret;
892
Luciano Coelhoa0a09242014-09-04 12:29:15 +0300893 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100894
895 /* Clean up some internal and mac80211 state on restart */
896 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
897 iwl_mvm_restart_cleanup(mvm);
898
899 ret = iwl_mvm_up(mvm);
Johannes Bergc47af222014-04-30 16:34:45 +0200900
901 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
902 /* Something went wrong - we need to finish some cleanup
903 * that normally iwl_mvm_mac_restart_complete() below
904 * would do.
905 */
906 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
907 iwl_mvm_d0i3_enable_tx(mvm, NULL);
908 }
909
Luciano Coelhoa0a09242014-09-04 12:29:15 +0300910 return ret;
911}
912
913static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
914{
915 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
916 int ret;
917
918 mutex_lock(&mvm->mutex);
919 ret = __iwl_mvm_mac_start(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100920 mutex_unlock(&mvm->mutex);
921
922 return ret;
923}
924
Eliad Pellercf2c92d2014-11-04 11:43:54 +0200925static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100926{
Johannes Berg8ca151b2013-01-24 14:25:36 +0100927 int ret;
928
929 mutex_lock(&mvm->mutex);
930
931 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
Arik Nemtsovb2492502014-03-13 12:21:50 +0200932 iwl_mvm_d0i3_enable_tx(mvm, NULL);
Johannes Berg01662302014-06-06 15:18:45 +0200933 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100934 if (ret)
935 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
936 ret);
937
Eliad Peller7498cf42014-01-16 17:10:44 +0200938 /* allow transport/FW low power modes */
939 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
940
Johannes Berg8ca151b2013-01-24 14:25:36 +0100941 mutex_unlock(&mvm->mutex);
942}
943
Eliad Pellercf2c92d2014-11-04 11:43:54 +0200944static void
945iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
946 enum ieee80211_reconfig_type reconfig_type)
947{
948 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
949
950 switch (reconfig_type) {
951 case IEEE80211_RECONFIG_TYPE_RESTART:
952 iwl_mvm_restart_complete(mvm);
953 break;
954 case IEEE80211_RECONFIG_TYPE_SUSPEND:
955 break;
956 }
957}
958
Luciano Coelhoa0a09242014-09-04 12:29:15 +0300959void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100960{
Luciano Coelhoa0a09242014-09-04 12:29:15 +0300961 lockdep_assert_held(&mvm->mutex);
Eliad Peller7498cf42014-01-16 17:10:44 +0200962
963 /* disallow low power states when the FW is down */
964 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
965
Johannes Berg8ca151b2013-01-24 14:25:36 +0100966 /* async_handlers_wk is now blocked */
967
968 /*
969 * The work item could be running or queued if the
970 * ROC time event stops just as we get here.
971 */
972 cancel_work_sync(&mvm->roc_done_wk);
973
974 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100975
976 iwl_mvm_async_handlers_purge(mvm);
977 /* async_handlers_list is empty and will stay empty: HW is stopped */
978
979 /* the fw is stopped, the aux sta is dead: clean up driver state */
Johannes Berg712b24a2014-08-04 14:14:14 +0200980 iwl_mvm_del_aux_sta(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100981
Luciano Coelhobc448862014-08-20 11:49:11 +0300982 mvm->ucode_loaded = false;
Luciano Coelhoa0a09242014-09-04 12:29:15 +0300983}
Luciano Coelhobc448862014-08-20 11:49:11 +0300984
Luciano Coelhoa0a09242014-09-04 12:29:15 +0300985static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
986{
987 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
988
989 flush_work(&mvm->d0i3_exit_work);
990 flush_work(&mvm->async_handlers_wk);
Emmanuel Grumbach4bfa47f2014-09-11 16:19:43 +0300991 flush_work(&mvm->fw_error_dump_wk);
Luciano Coelhoa0a09242014-09-04 12:29:15 +0300992
993 mutex_lock(&mvm->mutex);
994 __iwl_mvm_mac_stop(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100995 mutex_unlock(&mvm->mutex);
996
997 /*
998 * The worker might have been waiting for the mutex, let it run and
999 * discover that its list is now empty.
1000 */
1001 cancel_work_sync(&mvm->async_handlers_wk);
1002}
1003
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001004static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1005{
1006 u16 i;
1007
1008 lockdep_assert_held(&mvm->mutex);
1009
1010 for (i = 0; i < NUM_PHY_CTX; i++)
1011 if (!mvm->phy_ctxts[i].ref)
1012 return &mvm->phy_ctxts[i];
1013
1014 IWL_ERR(mvm, "No available PHY context\n");
1015 return NULL;
1016}
1017
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +02001018static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1019 s8 tx_power)
1020{
1021 /* FW is in charge of regulatory enforcement */
1022 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
1023 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
1024 .pwr_restriction = cpu_to_le16(tx_power),
1025 };
1026
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001027 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +02001028 sizeof(reduce_txpwr_cmd),
1029 &reduce_txpwr_cmd);
1030}
1031
Johannes Berg8ca151b2013-01-24 14:25:36 +01001032static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1033 struct ieee80211_vif *vif)
1034{
1035 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1036 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1037 int ret;
1038
1039 /*
Gregory Greenmand40fc482014-06-25 14:08:50 +02001040 * make sure D0i3 exit is completed, otherwise a target access
1041 * during tx queue configuration could be done when still in
1042 * D0i3 state.
1043 */
1044 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1045 if (ret)
1046 return ret;
1047
1048 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001049 * Not much to do here. The stack will not allow interface
1050 * types or combinations that we didn't advertise, so we
1051 * don't really have to check the types.
1052 */
1053
1054 mutex_lock(&mvm->mutex);
1055
Eliad Pellere89044d2013-07-16 17:33:26 +03001056 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001057 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1058 if (ret)
1059 goto out_unlock;
1060
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001061 /* Counting number of interfaces is needed for legacy PM */
Ilan Peerea183d02013-07-23 14:41:53 +03001062 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1063 mvm->vif_count++;
Ilan Peerea183d02013-07-23 14:41:53 +03001064
1065 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001066 * The AP binding flow can be done only after the beacon
1067 * template is configured (which happens only in the mac80211
1068 * start_ap() flow), and adding the broadcast station can happen
1069 * only after the binding.
1070 * In addition, since modifying the MAC before adding a bcast
1071 * station is not allowed by the FW, delay the adding of MAC context to
1072 * the point where we can also add the bcast station.
1073 * In short: there's not much we can do at this point, other than
1074 * allocating resources :)
1075 */
Johannes Berg5023d962013-07-31 14:07:43 +02001076 if (vif->type == NL80211_IFTYPE_AP ||
1077 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg013290a2014-08-04 13:38:48 +02001078 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001079 if (ret) {
1080 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1081 goto out_release;
1082 }
1083
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +03001084 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001085 goto out_unlock;
1086 }
1087
Johannes Berg8ca151b2013-01-24 14:25:36 +01001088 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1089 if (ret)
1090 goto out_release;
1091
Arik Nemtsov999609f2014-05-15 17:31:51 +03001092 ret = iwl_mvm_power_update_mac(mvm);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001093 if (ret)
1094 goto out_release;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001095
Hila Gonen7df15b12012-12-12 11:16:19 +02001096 /* beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001097 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001098 if (ret)
1099 goto out_remove_mac;
1100
Hila Gonen7df15b12012-12-12 11:16:19 +02001101 if (!mvm->bf_allowed_vif &&
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +03001102 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001103 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001104 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1105 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +02001106 }
1107
Johannes Berg8ca151b2013-01-24 14:25:36 +01001108 /*
1109 * P2P_DEVICE interface does not have a channel context assigned to it,
1110 * so a dedicated PHY context is allocated to it and the corresponding
1111 * MAC context is bound to it at this stage.
1112 */
1113 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001114
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001115 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1116 if (!mvmvif->phy_ctxt) {
1117 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001118 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001119 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001120
Ilan Peer53a9d612013-04-28 11:55:08 +03001121 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001122 ret = iwl_mvm_binding_add_vif(mvm, vif);
1123 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +03001124 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001125
Johannes Berg013290a2014-08-04 13:38:48 +02001126 ret = iwl_mvm_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001127 if (ret)
1128 goto out_unbind;
1129
1130 /* Save a pointer to p2p device vif, so it can later be used to
1131 * update the p2p device MAC when a GO is started/stopped */
1132 mvm->p2p_device_vif = vif;
1133 }
1134
Johannes Berg63494372013-03-26 10:47:53 +01001135 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001136 goto out_unlock;
1137
1138 out_unbind:
1139 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +03001140 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001141 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001142 out_free_bf:
1143 if (mvm->bf_allowed_vif == mvmvif) {
1144 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001145 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1146 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001147 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001148 out_remove_mac:
1149 mvmvif->phy_ctxt = NULL;
1150 iwl_mvm_mac_ctxt_remove(mvm, vif);
1151 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001152 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1153 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001154
Johannes Berg8ca151b2013-01-24 14:25:36 +01001155 iwl_mvm_mac_ctxt_release(mvm, vif);
1156 out_unlock:
1157 mutex_unlock(&mvm->mutex);
1158
Gregory Greenmand40fc482014-06-25 14:08:50 +02001159 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1160
Johannes Berg8ca151b2013-01-24 14:25:36 +01001161 return ret;
1162}
1163
Johannes Berg38a12b52013-02-22 14:07:56 +01001164static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1165 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001166{
Arik Nemtsovd92b732e2014-09-21 19:00:42 +03001167 u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001168
1169 if (tfd_msk) {
1170 mutex_lock(&mvm->mutex);
1171 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
1172 mutex_unlock(&mvm->mutex);
1173 }
1174
1175 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1176 /*
1177 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1178 * We assume here that all the packets sent to the OFFCHANNEL
1179 * queue are sent in ROC session.
1180 */
1181 flush_work(&mvm->roc_done_wk);
1182 } else {
1183 /*
1184 * By now, all the AC queues are empty. The AGG queues are
1185 * empty too. We already got all the Tx responses for all the
1186 * packets in the queues. The drain work can have been
Emmanuel Grumbach0742a752013-06-10 14:10:33 +03001187 * triggered. Flush it.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001188 */
1189 flush_work(&mvm->sta_drained_wk);
1190 }
Johannes Berg38a12b52013-02-22 14:07:56 +01001191}
1192
1193static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1194 struct ieee80211_vif *vif)
1195{
1196 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1197 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1198
1199 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001200
1201 mutex_lock(&mvm->mutex);
1202
Hila Gonen7df15b12012-12-12 11:16:19 +02001203 if (mvm->bf_allowed_vif == mvmvif) {
1204 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001205 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1206 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +02001207 }
1208
Johannes Berg63494372013-03-26 10:47:53 +01001209 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1210
Johannes Berg8ca151b2013-01-24 14:25:36 +01001211 /*
1212 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +01001213 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001214 */
Johannes Berg5023d962013-07-31 14:07:43 +02001215 if (vif->type == NL80211_IFTYPE_AP ||
1216 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +03001217#ifdef CONFIG_NL80211_TESTMODE
1218 if (vif == mvm->noa_vif) {
1219 mvm->noa_vif = NULL;
1220 mvm->noa_duration = 0;
1221 }
1222#endif
Johannes Berg013290a2014-08-04 13:38:48 +02001223 iwl_mvm_dealloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001224 goto out_release;
1225 }
1226
1227 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1228 mvm->p2p_device_vif = NULL;
Johannes Berg013290a2014-08-04 13:38:48 +02001229 iwl_mvm_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001230 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001231 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001232 mvmvif->phy_ctxt = NULL;
1233 }
1234
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001235 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001236 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001237
Arik Nemtsov999609f2014-05-15 17:31:51 +03001238 iwl_mvm_power_update_mac(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001239 iwl_mvm_mac_ctxt_remove(mvm, vif);
1240
1241out_release:
1242 iwl_mvm_mac_ctxt_release(mvm, vif);
1243 mutex_unlock(&mvm->mutex);
1244}
1245
1246static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1247{
1248 return 0;
1249}
1250
Eliad Pellere59647e2013-11-28 14:08:50 +02001251struct iwl_mvm_mc_iter_data {
1252 struct iwl_mvm *mvm;
1253 int port_id;
1254};
1255
1256static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1257 struct ieee80211_vif *vif)
1258{
1259 struct iwl_mvm_mc_iter_data *data = _data;
1260 struct iwl_mvm *mvm = data->mvm;
1261 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1262 int ret, len;
1263
1264 /* if we don't have free ports, mcast frames will be dropped */
1265 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1266 return;
1267
1268 if (vif->type != NL80211_IFTYPE_STATION ||
1269 !vif->bss_conf.assoc)
1270 return;
1271
1272 cmd->port_id = data->port_id++;
1273 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1274 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1275
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001276 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
Eliad Pellere59647e2013-11-28 14:08:50 +02001277 if (ret)
1278 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1279}
1280
1281static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1282{
1283 struct iwl_mvm_mc_iter_data iter_data = {
1284 .mvm = mvm,
1285 };
1286
1287 lockdep_assert_held(&mvm->mutex);
1288
1289 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1290 return;
1291
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001292 ieee80211_iterate_active_interfaces_atomic(
Eliad Pellere59647e2013-11-28 14:08:50 +02001293 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1294 iwl_mvm_mc_iface_iterator, &iter_data);
1295}
1296
1297static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1298 struct netdev_hw_addr_list *mc_list)
1299{
1300 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1301 struct iwl_mcast_filter_cmd *cmd;
1302 struct netdev_hw_addr *addr;
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001303 int addr_count;
1304 bool pass_all;
Eliad Pellere59647e2013-11-28 14:08:50 +02001305 int len;
1306
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001307 addr_count = netdev_hw_addr_list_count(mc_list);
1308 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1309 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1310 if (pass_all)
Eliad Pellere59647e2013-11-28 14:08:50 +02001311 addr_count = 0;
Eliad Pellere59647e2013-11-28 14:08:50 +02001312
1313 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1314 cmd = kzalloc(len, GFP_ATOMIC);
1315 if (!cmd)
1316 return 0;
1317
1318 if (pass_all) {
1319 cmd->pass_all = 1;
1320 return (u64)(unsigned long)cmd;
1321 }
1322
1323 netdev_hw_addr_list_for_each(addr, mc_list) {
1324 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1325 cmd->count, addr->addr);
1326 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1327 addr->addr, ETH_ALEN);
1328 cmd->count++;
1329 }
1330
1331 return (u64)(unsigned long)cmd;
1332}
1333
Johannes Berg8ca151b2013-01-24 14:25:36 +01001334static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1335 unsigned int changed_flags,
1336 unsigned int *total_flags,
1337 u64 multicast)
1338{
Eliad Pellere59647e2013-11-28 14:08:50 +02001339 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1340 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1341
1342 mutex_lock(&mvm->mutex);
1343
1344 /* replace previous configuration */
1345 kfree(mvm->mcast_filter_cmd);
1346 mvm->mcast_filter_cmd = cmd;
1347
1348 if (!cmd)
1349 goto out;
1350
1351 iwl_mvm_recalc_multicast(mvm);
1352out:
1353 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001354 *total_flags = 0;
1355}
1356
Eliad Pellerc87163b2014-01-08 10:11:11 +02001357#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1358struct iwl_bcast_iter_data {
1359 struct iwl_mvm *mvm;
1360 struct iwl_bcast_filter_cmd *cmd;
1361 u8 current_filter;
1362};
1363
1364static void
1365iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1366 const struct iwl_fw_bcast_filter *in_filter,
1367 struct iwl_fw_bcast_filter *out_filter)
1368{
1369 struct iwl_fw_bcast_filter_attr *attr;
1370 int i;
1371
1372 memcpy(out_filter, in_filter, sizeof(*out_filter));
1373
1374 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1375 attr = &out_filter->attrs[i];
1376
1377 if (!attr->mask)
1378 break;
1379
Eliad Peller2ee8f022014-01-13 19:07:09 +02001380 switch (attr->reserved1) {
1381 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1382 if (vif->bss_conf.arp_addr_cnt != 1) {
1383 attr->mask = 0;
1384 continue;
1385 }
1386
1387 attr->val = vif->bss_conf.arp_addr_list[0];
1388 break;
1389 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1390 attr->val = *(__be32 *)&vif->addr[2];
1391 break;
1392 default:
1393 break;
1394 }
1395 attr->reserved1 = 0;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001396 out_filter->num_attrs++;
1397 }
1398}
1399
1400static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1401 struct ieee80211_vif *vif)
1402{
1403 struct iwl_bcast_iter_data *data = _data;
1404 struct iwl_mvm *mvm = data->mvm;
1405 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1406 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1407 struct iwl_fw_bcast_mac *bcast_mac;
1408 int i;
1409
1410 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1411 return;
1412
1413 bcast_mac = &cmd->macs[mvmvif->id];
1414
Ilan Peere48393e2014-05-22 11:19:02 +03001415 /*
1416 * enable filtering only for associated stations, but not for P2P
1417 * Clients
1418 */
1419 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1420 !vif->bss_conf.assoc)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001421 return;
1422
1423 bcast_mac->default_discard = 1;
1424
1425 /* copy all configured filters */
1426 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1427 /*
1428 * Make sure we don't exceed our filters limit.
1429 * if there is still a valid filter to be configured,
1430 * be on the safe side and just allow bcast for this mac.
1431 */
1432 if (WARN_ON_ONCE(data->current_filter >=
1433 ARRAY_SIZE(cmd->filters))) {
1434 bcast_mac->default_discard = 0;
1435 bcast_mac->attached_filters = 0;
1436 break;
1437 }
1438
1439 iwl_mvm_set_bcast_filter(vif,
1440 &mvm->bcast_filters[i],
1441 &cmd->filters[data->current_filter]);
1442
1443 /* skip current filter if it contains no attributes */
1444 if (!cmd->filters[data->current_filter].num_attrs)
1445 continue;
1446
1447 /* attach the filter to current mac */
1448 bcast_mac->attached_filters |=
1449 cpu_to_le16(BIT(data->current_filter));
1450
1451 data->current_filter++;
1452 }
1453}
1454
Eliad Pellerde06a592014-01-08 10:11:12 +02001455bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1456 struct iwl_bcast_filter_cmd *cmd)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001457{
Eliad Pellerc87163b2014-01-08 10:11:11 +02001458 struct iwl_bcast_iter_data iter_data = {
1459 .mvm = mvm,
Eliad Pellerde06a592014-01-08 10:11:12 +02001460 .cmd = cmd,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001461 };
1462
Max Stepanov3b8983b2014-10-15 11:27:16 +03001463 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1464 return false;
1465
Eliad Pellerde06a592014-01-08 10:11:12 +02001466 memset(cmd, 0, sizeof(*cmd));
1467 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1468 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1469
1470#ifdef CONFIG_IWLWIFI_DEBUGFS
1471 /* use debugfs filters/macs if override is configured */
1472 if (mvm->dbgfs_bcast_filtering.override) {
1473 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1474 sizeof(cmd->filters));
1475 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1476 sizeof(cmd->macs));
1477 return true;
1478 }
1479#endif
Eliad Pellerc87163b2014-01-08 10:11:11 +02001480
1481 /* if no filters are configured, do nothing */
1482 if (!mvm->bcast_filters)
Eliad Pellerde06a592014-01-08 10:11:12 +02001483 return false;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001484
1485 /* configure and attach these filters for each associated sta vif */
1486 ieee80211_iterate_active_interfaces(
1487 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1488 iwl_mvm_bcast_filter_iterator, &iter_data);
1489
Eliad Pellerde06a592014-01-08 10:11:12 +02001490 return true;
1491}
1492static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1493 struct ieee80211_vif *vif)
1494{
1495 struct iwl_bcast_filter_cmd cmd;
1496
1497 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1498 return 0;
1499
1500 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1501 return 0;
1502
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001503 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001504 sizeof(cmd), &cmd);
1505}
1506#else
1507static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1508 struct ieee80211_vif *vif)
1509{
1510 return 0;
1511}
1512#endif
1513
Johannes Berg8ca151b2013-01-24 14:25:36 +01001514static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1515 struct ieee80211_vif *vif,
1516 struct ieee80211_bss_conf *bss_conf,
1517 u32 changes)
1518{
1519 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1520 int ret;
1521
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001522 /*
1523 * Re-calculate the tsf id, as the master-slave relations depend on the
1524 * beacon interval, which was not known when the station interface was
1525 * added.
1526 */
1527 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1528 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1529
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001530 /*
1531 * If we're not associated yet, take the (new) BSSID before associating
1532 * so the firmware knows. If we're already associated, then use the old
1533 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1534 * branch for disassociation below.
1535 */
1536 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1537 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1538
1539 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001540 if (ret)
1541 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1542
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001543 /* after sending it once, adopt mac80211 data */
1544 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1545 mvmvif->associated = bss_conf->assoc;
1546
Johannes Berg8ca151b2013-01-24 14:25:36 +01001547 if (changes & BSS_CHANGED_ASSOC) {
1548 if (bss_conf->assoc) {
1549 /* add quota for this interface */
Johannes Berg01662302014-06-06 15:18:45 +02001550 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001551 if (ret) {
1552 IWL_ERR(mvm, "failed to update quotas\n");
1553 return;
1554 }
Johannes Berg016d27e2013-05-03 11:16:15 +02001555
1556 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1557 &mvm->status)) {
1558 /*
1559 * If we're restarting then the firmware will
1560 * obviously have lost synchronisation with
1561 * the AP. It will attempt to synchronise by
1562 * itself, but we can make it more reliable by
1563 * scheduling a session protection time event.
1564 *
1565 * The firmware needs to receive a beacon to
1566 * catch up with synchronisation, use 110% of
1567 * the beacon interval.
1568 *
1569 * Set a large maximum delay to allow for more
1570 * than a single interface.
1571 */
1572 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1573 iwl_mvm_protect_session(mvm, vif, dur, dur,
Liad Kaufmand20d37b2014-07-06 17:14:39 +03001574 5 * dur, false);
Johannes Berg016d27e2013-05-03 11:16:15 +02001575 }
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001576
1577 iwl_mvm_sf_update(mvm, vif, false);
Alexander Bondar175a70b2013-04-14 20:59:37 +03001578 iwl_mvm_power_vif_assoc(mvm, vif);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001579 if (vif->p2p) {
Eliad Peller29a90a42013-11-05 14:06:29 +02001580 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001581 iwl_mvm_update_smps(mvm, vif,
1582 IWL_MVM_SMPS_REQ_PROT,
1583 IEEE80211_SMPS_DYNAMIC);
1584 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001585 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001586 /*
1587 * If update fails - SF might be running in associated
1588 * mode while disassociated - which is forbidden.
1589 */
1590 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1591 "Failed to update SF upon disassociation\n");
1592
Johannes Berg8ca151b2013-01-24 14:25:36 +01001593 /* remove AP station now that the MAC is unassoc */
1594 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1595 if (ret)
1596 IWL_ERR(mvm, "failed to remove AP station\n");
Eliad Peller37577fe2013-12-05 17:19:39 +02001597
1598 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1599 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001600 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1601 /* remove quota for this interface */
Johannes Berg01662302014-06-06 15:18:45 +02001602 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001603 if (ret)
1604 IWL_ERR(mvm, "failed to update quotas\n");
Eliad Peller29a90a42013-11-05 14:06:29 +02001605
1606 if (vif->p2p)
1607 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001608
1609 /* this will take the cleared BSSID from bss_conf */
1610 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1611 if (ret)
1612 IWL_ERR(mvm,
1613 "failed to update MAC %pM (clear after unassoc)\n",
1614 vif->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001615 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001616
Eliad Pellere59647e2013-11-28 14:08:50 +02001617 iwl_mvm_recalc_multicast(mvm);
Eliad Pellerc87163b2014-01-08 10:11:11 +02001618 iwl_mvm_configure_bcast_filter(mvm, vif);
Eliad Pellere59647e2013-11-28 14:08:50 +02001619
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001620 /* reset rssi values */
1621 mvmvif->bf_data.ave_beacon_signal = 0;
1622
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001623 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachf94045e2014-01-06 13:38:55 +02001624 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1625 IEEE80211_SMPS_AUTOMATIC);
Alexander Bondar989c6502013-05-16 17:34:17 +03001626 } else if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +01001627 /*
1628 * We received a beacon _after_ association so
1629 * remove the session protection.
1630 */
1631 iwl_mvm_remove_time_event(mvm, mvmvif,
1632 &mvmvif->time_event_data);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001633 }
Eran Hararycc87d322014-07-15 14:04:23 +03001634
1635 if (changes & BSS_CHANGED_BEACON_INFO) {
1636 iwl_mvm_sf_update(mvm, vif, false);
1637 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
1638 }
1639
Johannes Berg1bc10d32014-08-26 14:25:46 +02001640 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS)) {
1641 ret = iwl_mvm_power_update_mac(mvm);
1642 if (ret)
1643 IWL_ERR(mvm, "failed to update power mode\n");
1644 }
1645
Matti Gottlieb88f2fd72013-07-09 15:25:46 +03001646 if (changes & BSS_CHANGED_TXPOWER) {
1647 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1648 bss_conf->txpower);
1649 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1650 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001651
1652 if (changes & BSS_CHANGED_CQM) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02001653 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001654 /* reset cqm events tracking */
1655 mvmvif->bf_data.last_cqm_event = 0;
Avri Altmanfa7b2e72014-05-20 08:03:24 +03001656 if (mvmvif->bf_data.bf_enabled) {
1657 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1658 if (ret)
1659 IWL_ERR(mvm,
1660 "failed to update CQM thresholds\n");
1661 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001662 }
Eliad Peller2ee8f022014-01-13 19:07:09 +02001663
1664 if (changes & BSS_CHANGED_ARP_FILTER) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02001665 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
Eliad Peller2ee8f022014-01-13 19:07:09 +02001666 iwl_mvm_configure_bcast_filter(mvm, vif);
1667 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001668}
1669
Johannes Berg5023d962013-07-31 14:07:43 +02001670static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1671 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001672{
1673 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1674 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1675 int ret;
1676
Eliad Peller576eeee2014-07-01 18:38:38 +03001677 /*
1678 * iwl_mvm_mac_ctxt_add() might read directly from the device
1679 * (the system time), so make sure it is available.
1680 */
1681 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
1682 if (ret)
1683 return ret;
1684
Johannes Berg8ca151b2013-01-24 14:25:36 +01001685 mutex_lock(&mvm->mutex);
1686
1687 /* Send the beacon template */
1688 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1689 if (ret)
1690 goto out_unlock;
1691
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001692 /*
1693 * Re-calculate the tsf id, as the master-slave relations depend on the
1694 * beacon interval, which was not known when the AP interface was added.
1695 */
1696 if (vif->type == NL80211_IFTYPE_AP)
1697 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1698
Johannes Berg8ca151b2013-01-24 14:25:36 +01001699 /* Add the mac context */
1700 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1701 if (ret)
1702 goto out_unlock;
1703
1704 /* Perform the binding */
1705 ret = iwl_mvm_binding_add_vif(mvm, vif);
1706 if (ret)
1707 goto out_remove;
1708
Johannes Berg8ca151b2013-01-24 14:25:36 +01001709 /* Send the bcast station. At this stage the TBTT and DTIM time events
1710 * are added and applied to the scheduler */
Johannes Berg013290a2014-08-04 13:38:48 +02001711 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001712 if (ret)
1713 goto out_unbind;
1714
Ilan Peer5691e212013-12-31 21:05:50 +02001715 /* must be set before quota calculations */
1716 mvmvif->ap_ibss_active = true;
1717
Ilan Peera11e1442013-12-31 21:19:55 +02001718 /* power updated needs to be done before quotas */
Arik Nemtsov999609f2014-05-15 17:31:51 +03001719 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02001720
Johannes Berg01662302014-06-06 15:18:45 +02001721 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001722 if (ret)
Ilan Peera11e1442013-12-31 21:19:55 +02001723 goto out_quota_failed;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001724
Johannes Berg5023d962013-07-31 14:07:43 +02001725 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001726 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001727 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001728
Eliad Peller29a90a42013-11-05 14:06:29 +02001729 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1730
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001731 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001732
Arik Nemtsovf6972672014-06-15 16:03:55 +03001733 /* we don't support TDLS during DCM */
1734 if (iwl_mvm_phy_ctx_count(mvm) > 1)
1735 iwl_mvm_teardown_tdls_peers(mvm);
1736
Johannes Berg8ca151b2013-01-24 14:25:36 +01001737 mutex_unlock(&mvm->mutex);
1738 return 0;
1739
Ilan Peera11e1442013-12-31 21:19:55 +02001740out_quota_failed:
Arik Nemtsov999609f2014-05-15 17:31:51 +03001741 iwl_mvm_power_update_mac(mvm);
Ilan Peer5691e212013-12-31 21:05:50 +02001742 mvmvif->ap_ibss_active = false;
Johannes Berg013290a2014-08-04 13:38:48 +02001743 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001744out_unbind:
1745 iwl_mvm_binding_remove_vif(mvm, vif);
1746out_remove:
1747 iwl_mvm_mac_ctxt_remove(mvm, vif);
1748out_unlock:
1749 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03001750 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001751 return ret;
1752}
1753
Johannes Berg5023d962013-07-31 14:07:43 +02001754static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
1755 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001756{
1757 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1758 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1759
Johannes Berg38a12b52013-02-22 14:07:56 +01001760 iwl_mvm_prepare_mac_removal(mvm, vif);
1761
Johannes Berg8ca151b2013-01-24 14:25:36 +01001762 mutex_lock(&mvm->mutex);
1763
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03001764 /* Handle AP stop while in CSA */
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03001765 if (rcu_access_pointer(mvm->csa_vif) == vif) {
1766 iwl_mvm_remove_time_event(mvm, mvmvif,
1767 &mvmvif->time_event_data);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03001768 RCU_INIT_POINTER(mvm->csa_vif, NULL);
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03001769 }
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03001770
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03001771 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
1772 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
1773 mvm->csa_tx_block_bcn_timeout = 0;
1774 }
1775
Johannes Berg5023d962013-07-31 14:07:43 +02001776 mvmvif->ap_ibss_active = false;
David Spinadel1c87bba2014-02-27 16:41:52 +02001777 mvm->ap_last_beacon_gp2 = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001778
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001779 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001780
Eliad Peller29a90a42013-11-05 14:06:29 +02001781 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
1782
Johannes Berg5023d962013-07-31 14:07:43 +02001783 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001784 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001785 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001786
Johannes Berg01662302014-06-06 15:18:45 +02001787 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg013290a2014-08-04 13:38:48 +02001788 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001789 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02001790
Arik Nemtsov999609f2014-05-15 17:31:51 +03001791 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02001792
Johannes Berg8ca151b2013-01-24 14:25:36 +01001793 iwl_mvm_mac_ctxt_remove(mvm, vif);
1794
1795 mutex_unlock(&mvm->mutex);
1796}
1797
Johannes Berg5023d962013-07-31 14:07:43 +02001798static void
1799iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
1800 struct ieee80211_vif *vif,
1801 struct ieee80211_bss_conf *bss_conf,
1802 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001803{
Ilan Peerbe2056f2013-12-04 16:47:14 +02001804 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman8a5e3662013-11-12 19:16:03 +02001805
Ilan Peerbe2056f2013-12-04 16:47:14 +02001806 /* Changes will be applied when the AP/IBSS is started */
1807 if (!mvmvif->ap_ibss_active)
1808 return;
1809
Johannes Berg863230da2013-12-04 17:08:40 +01001810 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
Johannes Bergf7d8b702014-09-09 15:49:19 +02001811 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001812 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
Johannes Berg863230da2013-12-04 17:08:40 +01001813 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
Avri Altman8a5e3662013-11-12 19:16:03 +02001814
Johannes Berg8ca151b2013-01-24 14:25:36 +01001815 /* Need to send a new beacon template to the FW */
Johannes Berg863230da2013-12-04 17:08:40 +01001816 if (changes & BSS_CHANGED_BEACON &&
1817 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1818 IWL_WARN(mvm, "Failed updating beacon data\n");
Haim Dreyfuss79b7a692014-09-14 12:40:00 +03001819
1820 if (changes & BSS_CHANGED_TXPOWER) {
1821 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1822 bss_conf->txpower);
1823 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1824 }
1825
Johannes Berg8ca151b2013-01-24 14:25:36 +01001826}
1827
1828static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1829 struct ieee80211_vif *vif,
1830 struct ieee80211_bss_conf *bss_conf,
1831 u32 changes)
1832{
1833 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1834
Eliad Peller576eeee2014-07-01 18:38:38 +03001835 /*
1836 * iwl_mvm_bss_info_changed_station() might call
1837 * iwl_mvm_protect_session(), which reads directly from
1838 * the device (the system time), so make sure it is available.
1839 */
1840 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
1841 return;
1842
Johannes Berg8ca151b2013-01-24 14:25:36 +01001843 mutex_lock(&mvm->mutex);
1844
David Spinadel723f02e2014-04-27 09:54:54 +03001845 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
David Spinadelfb98be52014-05-04 12:51:10 +03001846 iwl_mvm_scan_offload_stop(mvm, true);
David Spinadel723f02e2014-04-27 09:54:54 +03001847
Johannes Berg8ca151b2013-01-24 14:25:36 +01001848 switch (vif->type) {
1849 case NL80211_IFTYPE_STATION:
1850 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1851 break;
1852 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02001853 case NL80211_IFTYPE_ADHOC:
1854 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001855 break;
1856 default:
1857 /* shouldn't happen */
1858 WARN_ON_ONCE(1);
1859 }
1860
1861 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03001862 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001863}
1864
Eliad Peller4660dfb2014-06-22 18:15:59 +03001865static int iwl_mvm_cancel_scan_wait_notif(struct iwl_mvm *mvm,
1866 enum iwl_scan_status scan_type)
1867{
1868 int ret;
1869 bool wait_for_handlers = false;
1870
1871 mutex_lock(&mvm->mutex);
1872
1873 if (mvm->scan_status != scan_type) {
1874 ret = 0;
1875 /* make sure there are no pending notifications */
1876 wait_for_handlers = true;
1877 goto out;
1878 }
1879
1880 switch (scan_type) {
1881 case IWL_MVM_SCAN_SCHED:
1882 ret = iwl_mvm_scan_offload_stop(mvm, true);
1883 break;
1884 case IWL_MVM_SCAN_OS:
1885 ret = iwl_mvm_cancel_scan(mvm);
1886 break;
1887 case IWL_MVM_SCAN_NONE:
1888 default:
1889 WARN_ON_ONCE(1);
1890 ret = -EINVAL;
1891 break;
1892 }
1893 if (ret)
1894 goto out;
1895
1896 wait_for_handlers = true;
1897out:
1898 mutex_unlock(&mvm->mutex);
1899
1900 /* make sure we consume the completion notification */
1901 if (wait_for_handlers)
1902 iwl_mvm_wait_for_async_handlers(mvm);
1903
1904 return ret;
1905}
Johannes Berg8ca151b2013-01-24 14:25:36 +01001906static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
1907 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02001908 struct ieee80211_scan_request *hw_req)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001909{
1910 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
David Spinadelc56ef672014-02-05 15:21:13 +02001911 struct cfg80211_scan_request *req = &hw_req->req;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001912 int ret;
1913
David Spinadel762533b2014-06-05 11:20:43 +03001914 if (req->n_channels == 0 ||
1915 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001916 return -EINVAL;
1917
Eliad Peller4660dfb2014-06-22 18:15:59 +03001918 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_SCHED);
1919 if (ret)
1920 return ret;
1921
Johannes Berg8ca151b2013-01-24 14:25:36 +01001922 mutex_lock(&mvm->mutex);
1923
Eliad Peller4660dfb2014-06-22 18:15:59 +03001924 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001925 ret = -EBUSY;
Arik Nemtsov519e2022013-10-17 17:51:35 +03001926 goto out;
1927 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001928
Arik Nemtsov519e2022013-10-17 17:51:35 +03001929 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
1930
David Spinadelfb98be52014-05-04 12:51:10 +03001931 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
1932 ret = iwl_mvm_unified_scan_lmac(mvm, vif, hw_req);
1933 else
1934 ret = iwl_mvm_scan_request(mvm, vif, req);
1935
Arik Nemtsov519e2022013-10-17 17:51:35 +03001936 if (ret)
1937 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1938out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001939 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001940 return ret;
1941}
1942
1943static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1944 struct ieee80211_vif *vif)
1945{
1946 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1947
1948 mutex_lock(&mvm->mutex);
1949
1950 iwl_mvm_cancel_scan(mvm);
1951
1952 mutex_unlock(&mvm->mutex);
1953}
1954
1955static void
1956iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
Johannes Berg3e56ead2013-02-15 22:23:18 +01001957 struct ieee80211_sta *sta, u16 tids,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001958 int num_frames,
1959 enum ieee80211_frame_release_type reason,
1960 bool more_data)
1961{
1962 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001963
Johannes Berg3e56ead2013-02-15 22:23:18 +01001964 /* Called when we need to transmit (a) frame(s) from mac80211 */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001965
Johannes Berg3e56ead2013-02-15 22:23:18 +01001966 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1967 tids, more_data, false);
1968}
1969
1970static void
1971iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
1972 struct ieee80211_sta *sta, u16 tids,
1973 int num_frames,
1974 enum ieee80211_frame_release_type reason,
1975 bool more_data)
1976{
1977 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1978
1979 /* Called when we need to transmit (a) frame(s) from agg queue */
1980
1981 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1982 tids, more_data, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001983}
1984
1985static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1986 struct ieee80211_vif *vif,
1987 enum sta_notify_cmd cmd,
1988 struct ieee80211_sta *sta)
1989{
1990 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01001991 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg3e56ead2013-02-15 22:23:18 +01001992 int tid;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001993
1994 switch (cmd) {
1995 case STA_NOTIFY_SLEEP:
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03001996 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001997 ieee80211_sta_block_awake(hw, sta, true);
Johannes Berg3e56ead2013-02-15 22:23:18 +01001998 spin_lock_bh(&mvmsta->lock);
1999 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2000 struct iwl_mvm_tid_data *tid_data;
2001
2002 tid_data = &mvmsta->tid_data[tid];
2003 if (tid_data->state != IWL_AGG_ON &&
2004 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
2005 continue;
2006 if (iwl_mvm_tid_queued(tid_data) == 0)
2007 continue;
2008 ieee80211_sta_set_buffered(sta, tid, true);
2009 }
2010 spin_unlock_bh(&mvmsta->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002011 /*
2012 * The fw updates the STA to be asleep. Tx packets on the Tx
2013 * queues to this station will not be transmitted. The fw will
2014 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2015 */
2016 break;
2017 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02002018 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01002019 break;
Johannes Berg9cc40712013-02-15 22:47:48 +01002020 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002021 break;
2022 default:
2023 break;
2024 }
2025}
2026
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002027static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2028 struct ieee80211_vif *vif,
2029 struct ieee80211_sta *sta)
2030{
2031 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2032 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
2033
2034 /*
2035 * This is called before mac80211 does RCU synchronisation,
2036 * so here we already invalidate our internal RCU-protected
2037 * station pointer. The rest of the code will thus no longer
2038 * be able to find the station this way, and we don't rely
2039 * on further RCU synchronisation after the sta_state()
2040 * callback deleted the station.
2041 */
2042 mutex_lock(&mvm->mutex);
2043 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2044 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2045 ERR_PTR(-ENOENT));
2046 mutex_unlock(&mvm->mutex);
2047}
2048
Johannes Berg8ca151b2013-01-24 14:25:36 +01002049static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2050 struct ieee80211_vif *vif,
2051 struct ieee80211_sta *sta,
2052 enum ieee80211_sta_state old_state,
2053 enum ieee80211_sta_state new_state)
2054{
2055 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2056 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2057 int ret;
2058
2059 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2060 sta->addr, old_state, new_state);
2061
2062 /* this would be a mac80211 bug ... but don't crash */
2063 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2064 return -EINVAL;
2065
2066 /* if a STA is being removed, reuse its ID */
2067 flush_work(&mvm->sta_drained_wk);
2068
2069 mutex_lock(&mvm->mutex);
2070 if (old_state == IEEE80211_STA_NOTEXIST &&
2071 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02002072 /*
2073 * Firmware bug - it'll crash if the beacon interval is less
2074 * than 16. We can't avoid connecting at all, so refuse the
2075 * station state change, this will cause mac80211 to abandon
2076 * attempts to connect to this AP, and eventually wpa_s will
2077 * blacklist the AP...
2078 */
2079 if (vif->type == NL80211_IFTYPE_STATION &&
2080 vif->bss_conf.beacon_int < 16) {
2081 IWL_ERR(mvm,
2082 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2083 sta->addr, vif->bss_conf.beacon_int);
2084 ret = -EINVAL;
2085 goto out_unlock;
2086 }
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002087
2088 if (sta->tdls &&
2089 (vif->p2p ||
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002090 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2091 IWL_MVM_TDLS_STA_COUNT ||
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002092 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2093 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2094 ret = -EBUSY;
2095 goto out_unlock;
2096 }
2097
Johannes Berg8ca151b2013-01-24 14:25:36 +01002098 ret = iwl_mvm_add_sta(mvm, vif, sta);
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002099 if (sta->tdls && ret == 0)
2100 iwl_mvm_recalc_tdls_state(mvm, vif, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002101 } else if (old_state == IEEE80211_STA_NONE &&
2102 new_state == IEEE80211_STA_AUTH) {
Haim Dreyfusse820c2d2014-04-06 11:19:09 +03002103 /*
2104 * EBS may be disabled due to previous failures reported by FW.
2105 * Reset EBS status here assuming environment has been changed.
2106 */
2107 mvm->last_ebs_successful = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002108 ret = 0;
2109 } else if (old_state == IEEE80211_STA_AUTH &&
2110 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01002111 ret = iwl_mvm_update_sta(mvm, vif, sta);
2112 if (ret == 0)
2113 iwl_mvm_rs_rate_init(mvm, sta,
Eyal Shapirab87c2172013-11-09 23:37:55 +02002114 mvmvif->phy_ctxt->channel->band,
2115 true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002116 } else if (old_state == IEEE80211_STA_ASSOC &&
2117 new_state == IEEE80211_STA_AUTHORIZED) {
Arik Nemtsovf59e0e3c2014-06-10 19:56:27 +03002118
2119 /* we don't support TDLS during DCM */
2120 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2121 iwl_mvm_teardown_tdls_peers(mvm);
2122
Hila Gonen7df15b12012-12-12 11:16:19 +02002123 /* enable beacon filtering */
Avri Altmanfa7b2e72014-05-20 08:03:24 +03002124 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002125 ret = 0;
2126 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2127 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02002128 /* disable beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002129 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002130 ret = 0;
2131 } else if (old_state == IEEE80211_STA_ASSOC &&
2132 new_state == IEEE80211_STA_AUTH) {
2133 ret = 0;
2134 } else if (old_state == IEEE80211_STA_AUTH &&
2135 new_state == IEEE80211_STA_NONE) {
2136 ret = 0;
2137 } else if (old_state == IEEE80211_STA_NONE &&
2138 new_state == IEEE80211_STA_NOTEXIST) {
2139 ret = iwl_mvm_rm_sta(mvm, vif, sta);
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002140 if (sta->tdls)
2141 iwl_mvm_recalc_tdls_state(mvm, vif, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002142 } else {
2143 ret = -EIO;
2144 }
Johannes Berg48bc1302013-07-04 15:55:29 +02002145 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002146 mutex_unlock(&mvm->mutex);
2147
2148 return ret;
2149}
2150
2151static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2152{
2153 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2154
2155 mvm->rts_threshold = value;
2156
2157 return 0;
2158}
2159
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002160static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2161 struct ieee80211_vif *vif,
2162 struct ieee80211_sta *sta, u32 changed)
2163{
2164 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2165
2166 if (vif->type == NL80211_IFTYPE_STATION &&
2167 changed & IEEE80211_RC_NSS_CHANGED)
2168 iwl_mvm_sf_update(mvm, vif, false);
2169}
2170
Johannes Berg8ca151b2013-01-24 14:25:36 +01002171static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2172 struct ieee80211_vif *vif, u16 ac,
2173 const struct ieee80211_tx_queue_params *params)
2174{
2175 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2176 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2177
2178 mvmvif->queue_params[ac] = *params;
2179
2180 /*
2181 * No need to update right away, we'll get BSS_CHANGED_QOS
2182 * The exception is P2P_DEVICE interface which needs immediate update.
2183 */
2184 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2185 int ret;
2186
2187 mutex_lock(&mvm->mutex);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002188 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002189 mutex_unlock(&mvm->mutex);
2190 return ret;
2191 }
2192 return 0;
2193}
2194
2195static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2196 struct ieee80211_vif *vif)
2197{
2198 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2199 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
2200 200 + vif->bss_conf.beacon_int);
2201 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
2202 100 + vif->bss_conf.beacon_int);
2203
2204 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2205 return;
2206
Eliad Peller576eeee2014-07-01 18:38:38 +03002207 /*
2208 * iwl_mvm_protect_session() reads directly from the device
2209 * (the system time), so make sure it is available.
2210 */
2211 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2212 return;
2213
Johannes Berg8ca151b2013-01-24 14:25:36 +01002214 mutex_lock(&mvm->mutex);
2215 /* Try really hard to protect the session and hear a beacon */
Liad Kaufmand20d37b2014-07-06 17:14:39 +03002216 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002217 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002218
2219 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002220}
2221
David Spinadel35a000b2013-08-28 09:29:43 +03002222static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2223 struct ieee80211_vif *vif,
2224 struct cfg80211_sched_scan_request *req,
David Spinadel633e2712014-02-06 16:15:23 +02002225 struct ieee80211_scan_ies *ies)
David Spinadel35a000b2013-08-28 09:29:43 +03002226{
2227 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2228 int ret;
2229
Eliad Peller4660dfb2014-06-22 18:15:59 +03002230 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_OS);
2231 if (ret)
2232 return ret;
2233
David Spinadel35a000b2013-08-28 09:29:43 +03002234 mutex_lock(&mvm->mutex);
2235
Alexander Bondar59ecb122014-07-30 17:40:28 +03002236 /* Newest FW fixes sched scan while connected on another interface */
2237 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) {
2238 if (!vif->bss_conf.idle) {
2239 ret = -EBUSY;
2240 goto out;
2241 }
2242 } else if (!iwl_mvm_is_idle(mvm)) {
David Spinadelbd5e4742014-04-24 13:15:29 +03002243 ret = -EBUSY;
2244 goto out;
2245 }
2246
Eliad Peller4660dfb2014-06-22 18:15:59 +03002247 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
David Spinadel35a000b2013-08-28 09:29:43 +03002248 ret = -EBUSY;
2249 goto out;
2250 }
2251
2252 mvm->scan_status = IWL_MVM_SCAN_SCHED;
2253
Luciano Coelhob141c232014-10-01 13:22:40 +03002254 ret = iwl_mvm_scan_offload_start(mvm, vif, req, ies);
David Spinadel35a000b2013-08-28 09:29:43 +03002255 if (ret)
Luciano Coelhob141c232014-10-01 13:22:40 +03002256 mvm->scan_status = IWL_MVM_SCAN_NONE;
David Spinadel35a000b2013-08-28 09:29:43 +03002257out:
2258 mutex_unlock(&mvm->mutex);
2259 return ret;
2260}
2261
Johannes Berg37e33082014-02-17 10:48:17 +01002262static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2263 struct ieee80211_vif *vif)
David Spinadel35a000b2013-08-28 09:29:43 +03002264{
2265 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002266 int ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002267
2268 mutex_lock(&mvm->mutex);
David Spinadelfb98be52014-05-04 12:51:10 +03002269 ret = iwl_mvm_scan_offload_stop(mvm, false);
David Spinadel35a000b2013-08-28 09:29:43 +03002270 mutex_unlock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002271 iwl_mvm_wait_for_async_handlers(mvm);
Johannes Berg37e33082014-02-17 10:48:17 +01002272
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002273 return ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002274}
2275
Johannes Berg8ca151b2013-01-24 14:25:36 +01002276static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2277 enum set_key_cmd cmd,
2278 struct ieee80211_vif *vif,
2279 struct ieee80211_sta *sta,
2280 struct ieee80211_key_conf *key)
2281{
2282 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2283 int ret;
2284
2285 if (iwlwifi_mod_params.sw_crypto) {
2286 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2287 return -EOPNOTSUPP;
2288 }
2289
2290 switch (key->cipher) {
2291 case WLAN_CIPHER_SUITE_TKIP:
2292 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2293 /* fall-through */
2294 case WLAN_CIPHER_SUITE_CCMP:
2295 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2296 break;
2297 case WLAN_CIPHER_SUITE_AES_CMAC:
2298 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
2299 break;
2300 case WLAN_CIPHER_SUITE_WEP40:
2301 case WLAN_CIPHER_SUITE_WEP104:
2302 /*
2303 * Support for TX only, at least for now, so accept
2304 * the key and do nothing else. Then mac80211 will
2305 * pass it for TX but we don't have to use it for RX.
2306 */
2307 return 0;
2308 default:
Max Stepanove36e5432013-08-27 19:56:13 +03002309 /* currently FW supports only one optional cipher scheme */
2310 if (hw->n_cipher_schemes &&
2311 hw->cipher_schemes->cipher == key->cipher)
2312 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2313 else
2314 return -EOPNOTSUPP;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002315 }
2316
2317 mutex_lock(&mvm->mutex);
2318
2319 switch (cmd) {
2320 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02002321 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2322 vif->type == NL80211_IFTYPE_AP) && !sta) {
2323 /*
2324 * GTK on AP interface is a TX-only key, return 0;
2325 * on IBSS they're per-station and because we're lazy
2326 * we don't support them for RX, so do the same.
2327 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002328 ret = 0;
2329 key->hw_key_idx = STA_KEY_IDX_INVALID;
2330 break;
2331 }
2332
Johannes Berg8ca151b2013-01-24 14:25:36 +01002333 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
2334 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
2335 if (ret) {
2336 IWL_WARN(mvm, "set key failed\n");
2337 /*
2338 * can't add key for RX, but we don't need it
2339 * in the device for TX so still return 0
2340 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002341 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002342 ret = 0;
2343 }
2344
2345 break;
2346 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01002347 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2348 ret = 0;
2349 break;
2350 }
2351
Johannes Berg8ca151b2013-01-24 14:25:36 +01002352 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
2353 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
2354 break;
2355 default:
2356 ret = -EINVAL;
2357 }
2358
2359 mutex_unlock(&mvm->mutex);
2360 return ret;
2361}
2362
2363static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2364 struct ieee80211_vif *vif,
2365 struct ieee80211_key_conf *keyconf,
2366 struct ieee80211_sta *sta,
2367 u32 iv32, u16 *phase1key)
2368{
2369 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2370
Johannes Berg5023d962013-07-31 14:07:43 +02002371 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2372 return;
2373
Johannes Berg8ca151b2013-01-24 14:25:36 +01002374 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2375}
2376
2377
Ariej Marjiehb1128892014-07-16 21:11:12 +03002378static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
2379 struct iwl_rx_packet *pkt, void *data)
2380{
2381 struct iwl_mvm *mvm =
2382 container_of(notif_wait, struct iwl_mvm, notif_wait);
2383 struct iwl_hs20_roc_res *resp;
2384 int resp_len = iwl_rx_packet_payload_len(pkt);
2385 struct iwl_mvm_time_event_data *te_data = data;
2386
2387 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
2388 return true;
2389
2390 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
2391 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
2392 return true;
2393 }
2394
2395 resp = (void *)pkt->data;
2396
2397 IWL_DEBUG_TE(mvm,
2398 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
2399 resp->status, resp->event_unique_id);
2400
2401 te_data->uid = le32_to_cpu(resp->event_unique_id);
2402 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
2403 te_data->uid);
2404
2405 spin_lock_bh(&mvm->time_event_lock);
2406 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
2407 spin_unlock_bh(&mvm->time_event_lock);
2408
2409 return true;
2410}
2411
2412#define AUX_ROC_MAX_DELAY_ON_CHANNEL 5000
2413static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
2414 struct ieee80211_channel *channel,
2415 struct ieee80211_vif *vif,
2416 int duration)
2417{
2418 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
2419 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2420 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
2421 static const u8 time_event_response[] = { HOT_SPOT_CMD };
2422 struct iwl_notification_wait wait_time_event;
2423 struct iwl_hs20_roc_req aux_roc_req = {
2424 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
2425 .id_and_color =
2426 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
2427 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
2428 /* Set the channel info data */
2429 .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ?
2430 PHY_BAND_24 : PHY_BAND_5,
2431 .channel_info.channel = channel->hw_value,
2432 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
2433 /* Set the time and duration */
2434 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
2435 .apply_time_max_delay =
2436 cpu_to_le32(MSEC_TO_TU(AUX_ROC_MAX_DELAY_ON_CHANNEL)),
2437 .duration = cpu_to_le32(MSEC_TO_TU(duration)),
2438 };
2439
2440 /* Set the node address */
2441 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
2442
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002443 lockdep_assert_held(&mvm->mutex);
2444
2445 spin_lock_bh(&mvm->time_event_lock);
2446
2447 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
2448 spin_unlock_bh(&mvm->time_event_lock);
2449 return -EIO;
2450 }
2451
Ariej Marjiehb1128892014-07-16 21:11:12 +03002452 te_data->vif = vif;
2453 te_data->duration = duration;
2454 te_data->id = HOT_SPOT_CMD;
2455
Ariej Marjiehb1128892014-07-16 21:11:12 +03002456 spin_unlock_bh(&mvm->time_event_lock);
2457
2458 /*
2459 * Use a notification wait, which really just processes the
2460 * command response and doesn't wait for anything, in order
2461 * to be able to process the response and get the UID inside
2462 * the RX path. Using CMD_WANT_SKB doesn't work because it
2463 * stores the buffer and then wakes up this thread, by which
2464 * time another notification (that the time event started)
2465 * might already be processed unsuccessfully.
2466 */
2467 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
2468 time_event_response,
2469 ARRAY_SIZE(time_event_response),
2470 iwl_mvm_rx_aux_roc, te_data);
2471
2472 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
2473 &aux_roc_req);
2474
2475 if (res) {
2476 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
2477 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
2478 goto out_clear_te;
2479 }
2480
2481 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
2482 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
2483 /* should never fail */
2484 WARN_ON_ONCE(res);
2485
2486 if (res) {
2487 out_clear_te:
2488 spin_lock_bh(&mvm->time_event_lock);
2489 iwl_mvm_te_clear_data(mvm, te_data);
2490 spin_unlock_bh(&mvm->time_event_lock);
2491 }
2492
2493 return res;
2494}
2495
Johannes Berg8ca151b2013-01-24 14:25:36 +01002496static int iwl_mvm_roc(struct ieee80211_hw *hw,
2497 struct ieee80211_vif *vif,
2498 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002499 int duration,
2500 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002501{
2502 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002503 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002504 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03002505 struct iwl_mvm_phy_ctxt *phy_ctxt;
2506 int ret, i;
2507
2508 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
2509 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002510
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002511 mutex_lock(&mvm->mutex);
2512
Ariej Marjiehb1128892014-07-16 21:11:12 +03002513 switch (vif->type) {
2514 case NL80211_IFTYPE_STATION:
2515 /* Use aux roc framework (HS20) */
2516 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
2517 vif, duration);
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002518 goto out_unlock;
Ariej Marjiehb1128892014-07-16 21:11:12 +03002519 case NL80211_IFTYPE_P2P_DEVICE:
2520 /* handle below */
2521 break;
2522 default:
2523 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002524 ret = -EINVAL;
2525 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002526 }
2527
Ilan Peer31d385a2013-04-02 10:25:46 +03002528 for (i = 0; i < NUM_PHY_CTX; i++) {
2529 phy_ctxt = &mvm->phy_ctxts[i];
2530 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
2531 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002532
Ilan Peer31d385a2013-04-02 10:25:46 +03002533 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
2534 /*
2535 * Unbind the P2P_DEVICE from the current PHY context,
2536 * and if the PHY context is not used remove it.
2537 */
2538 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2539 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2540 goto out_unlock;
2541
2542 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2543
2544 /* Bind the P2P_DEVICE to the current PHY Context */
2545 mvmvif->phy_ctxt = phy_ctxt;
2546
2547 ret = iwl_mvm_binding_add_vif(mvm, vif);
2548 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2549 goto out_unlock;
2550
2551 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2552 goto schedule_time_event;
2553 }
2554 }
2555
2556 /* Need to update the PHY context only if the ROC channel changed */
2557 if (channel == mvmvif->phy_ctxt->channel)
2558 goto schedule_time_event;
2559
2560 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
2561
2562 /*
2563 * Change the PHY context configuration as it is currently referenced
2564 * only by the P2P Device MAC
2565 */
2566 if (mvmvif->phy_ctxt->ref == 1) {
2567 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2568 &chandef, 1, 1);
2569 if (ret)
2570 goto out_unlock;
2571 } else {
2572 /*
2573 * The PHY context is shared with other MACs. Need to remove the
2574 * P2P Device from the binding, allocate an new PHY context and
2575 * create a new binding
2576 */
2577 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2578 if (!phy_ctxt) {
2579 ret = -ENOSPC;
2580 goto out_unlock;
2581 }
2582
2583 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2584 1, 1);
2585 if (ret) {
2586 IWL_ERR(mvm, "Failed to change PHY context\n");
2587 goto out_unlock;
2588 }
2589
2590 /* Unbind the P2P_DEVICE from the current PHY context */
2591 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2592 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2593 goto out_unlock;
2594
2595 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2596
2597 /* Bind the P2P_DEVICE to the new allocated PHY context */
2598 mvmvif->phy_ctxt = phy_ctxt;
2599
2600 ret = iwl_mvm_binding_add_vif(mvm, vif);
2601 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2602 goto out_unlock;
2603
2604 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2605 }
2606
2607schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002608 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02002609 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002610
Ilan Peer31d385a2013-04-02 10:25:46 +03002611out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002612 mutex_unlock(&mvm->mutex);
2613 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01002614 return ret;
2615}
2616
2617static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
2618{
2619 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2620
2621 IWL_DEBUG_MAC80211(mvm, "enter\n");
2622
2623 mutex_lock(&mvm->mutex);
2624 iwl_mvm_stop_p2p_roc(mvm);
2625 mutex_unlock(&mvm->mutex);
2626
2627 IWL_DEBUG_MAC80211(mvm, "leave\n");
2628 return 0;
2629}
2630
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002631static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
2632 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002633{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002634 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2635 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002636 int ret;
2637
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002638 lockdep_assert_held(&mvm->mutex);
2639
Ilan Peer53a9d612013-04-28 11:55:08 +03002640 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002641
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002642 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2643 if (!phy_ctxt) {
2644 ret = -ENOSPC;
2645 goto out;
2646 }
2647
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02002648 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Ilan Peer53a9d612013-04-28 11:55:08 +03002649 ctx->rx_chains_static,
2650 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002651 if (ret) {
2652 IWL_ERR(mvm, "Failed to add PHY context\n");
2653 goto out;
2654 }
2655
Ilan Peer53a9d612013-04-28 11:55:08 +03002656 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002657 *phy_ctxt_id = phy_ctxt->id;
2658out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002659 return ret;
2660}
2661
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002662static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2663 struct ieee80211_chanctx_conf *ctx)
2664{
2665 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2666 int ret;
2667
2668 mutex_lock(&mvm->mutex);
2669 ret = __iwl_mvm_add_chanctx(mvm, ctx);
2670 mutex_unlock(&mvm->mutex);
2671
2672 return ret;
2673}
2674
2675static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
2676 struct ieee80211_chanctx_conf *ctx)
2677{
2678 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2679 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2680
2681 lockdep_assert_held(&mvm->mutex);
2682
2683 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
2684}
2685
Johannes Berg8ca151b2013-01-24 14:25:36 +01002686static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2687 struct ieee80211_chanctx_conf *ctx)
2688{
2689 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002690
2691 mutex_lock(&mvm->mutex);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002692 __iwl_mvm_remove_chanctx(mvm, ctx);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002693 mutex_unlock(&mvm->mutex);
2694}
2695
2696static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
2697 struct ieee80211_chanctx_conf *ctx,
2698 u32 changed)
2699{
2700 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002701 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2702 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002703
Ilan Peer31d385a2013-04-02 10:25:46 +03002704 if (WARN_ONCE((phy_ctxt->ref > 1) &&
2705 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
2706 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
Arik Nemtsov2dceeda2013-12-29 17:57:53 +02002707 IEEE80211_CHANCTX_CHANGE_RADAR |
2708 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
Ilan Peer31d385a2013-04-02 10:25:46 +03002709 "Cannot change PHY. Ref=%d, changed=0x%X\n",
2710 phy_ctxt->ref, changed))
2711 return;
2712
Johannes Berg8ca151b2013-01-24 14:25:36 +01002713 mutex_lock(&mvm->mutex);
Emmanuel Grumbach4d664492014-04-30 18:09:59 +03002714 iwl_mvm_bt_coex_vif_change(mvm);
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02002715 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002716 ctx->rx_chains_static,
2717 ctx->rx_chains_dynamic);
2718 mutex_unlock(&mvm->mutex);
2719}
2720
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002721static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
2722 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02002723 struct ieee80211_chanctx_conf *ctx,
2724 bool switching_chanctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002725{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002726 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2727 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002728 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2729 int ret;
2730
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002731 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002732
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002733 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002734
2735 switch (vif->type) {
2736 case NL80211_IFTYPE_AP:
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002737 /* Unless it's a CSA flow we have nothing to do here */
2738 if (vif->csa_active) {
2739 mvmvif->ap_ibss_active = true;
2740 break;
2741 }
Johannes Berg5023d962013-07-31 14:07:43 +02002742 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002743 /*
2744 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02002745 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01002746 */
2747 ret = 0;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002748 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002749 case NL80211_IFTYPE_STATION:
Luciano Coelho2533edc2014-08-08 19:50:46 +03002750 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002751 case NL80211_IFTYPE_MONITOR:
Luciano Coelho2533edc2014-08-08 19:50:46 +03002752 /* always disable PS when a monitor interface is active */
2753 mvmvif->ps_disabled = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002754 break;
2755 default:
2756 ret = -EINVAL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002757 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002758 }
2759
2760 ret = iwl_mvm_binding_add_vif(mvm, vif);
2761 if (ret)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002762 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002763
2764 /*
Alexander Bondar92d85562013-10-23 11:50:34 +02002765 * Power state must be updated before quotas,
2766 * otherwise fw will complain.
2767 */
Arik Nemtsov999609f2014-05-15 17:31:51 +03002768 iwl_mvm_power_update_mac(mvm);
Alexander Bondar92d85562013-10-23 11:50:34 +02002769
2770 /* Setting the quota at this stage is only required for monitor
Johannes Berg8ca151b2013-01-24 14:25:36 +01002771 * interfaces. For the other types, the bss_info changed flow
2772 * will handle quota settings.
2773 */
2774 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02002775 mvmvif->monitor_active = true;
Johannes Berg01662302014-06-06 15:18:45 +02002776 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002777 if (ret)
2778 goto out_remove_binding;
2779 }
2780
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002781 /* Handle binding during CSA */
Luciano Coelhof0c97782014-03-05 15:41:48 +02002782 if ((vif->type == NL80211_IFTYPE_AP) ||
2783 (switching_chanctx && (vif->type == NL80211_IFTYPE_STATION))) {
Johannes Berg01662302014-06-06 15:18:45 +02002784 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002785 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002786 }
2787
Luciano Coelho0ce04ce2014-05-08 16:03:39 +03002788 if (vif->csa_active && vif->type == NL80211_IFTYPE_STATION) {
2789 struct iwl_mvm_sta *mvmsta;
2790
2791 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
2792 mvmvif->ap_sta_id);
2793
2794 if (WARN_ON(!mvmsta))
2795 goto out;
2796
2797 /* TODO: only re-enable after the first beacon */
2798 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
2799 }
2800
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002801 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002802
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002803out_remove_binding:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002804 iwl_mvm_binding_remove_vif(mvm, vif);
Arik Nemtsov999609f2014-05-15 17:31:51 +03002805 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002806out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002807 if (ret)
2808 mvmvif->phy_ctxt = NULL;
2809 return ret;
2810}
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002811static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
2812 struct ieee80211_vif *vif,
2813 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002814{
2815 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002816 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002817
2818 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02002819 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002820 mutex_unlock(&mvm->mutex);
2821
2822 return ret;
2823}
2824
2825static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
2826 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02002827 struct ieee80211_chanctx_conf *ctx,
2828 bool switching_chanctx)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002829{
2830 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhof0c97782014-03-05 15:41:48 +02002831 struct ieee80211_vif *disabled_vif = NULL;
Luciano Coelho0ce04ce2014-05-08 16:03:39 +03002832 struct iwl_mvm_sta *mvmsta;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002833
2834 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002835
2836 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
2837
Johannes Berg8ca151b2013-01-24 14:25:36 +01002838 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02002839 case NL80211_IFTYPE_ADHOC:
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002840 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002841 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02002842 mvmvif->monitor_active = false;
Luciano Coelho2533edc2014-08-08 19:50:46 +03002843 mvmvif->ps_disabled = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002844 break;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002845 case NL80211_IFTYPE_AP:
2846 /* This part is triggered only during CSA */
2847 if (!vif->csa_active || !mvmvif->ap_ibss_active)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002848 goto out;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002849
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03002850 /* Set CS bit on all the stations */
2851 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
2852
2853 /* Save blocked iface, the timeout is set on the next beacon */
2854 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
2855
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002856 mvmvif->ap_ibss_active = false;
Luciano Coelhof0c97782014-03-05 15:41:48 +02002857 break;
2858 case NL80211_IFTYPE_STATION:
2859 if (!switching_chanctx)
2860 break;
2861
2862 disabled_vif = vif;
2863
Luciano Coelho0ce04ce2014-05-08 16:03:39 +03002864 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
2865 mvmvif->ap_sta_id);
2866
2867 if (!WARN_ON(!mvmsta))
2868 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true);
2869
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002870 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
Luciano Coelhof0c97782014-03-05 15:41:48 +02002871 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002872 default:
2873 break;
2874 }
2875
Luciano Coelhof0c97782014-03-05 15:41:48 +02002876 iwl_mvm_update_quotas(mvm, disabled_vif);
Ilan Peer1e1391c2013-03-13 14:52:04 +02002877 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03002878
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002879out:
Ilan Peera11e1442013-12-31 21:19:55 +02002880 mvmvif->phy_ctxt = NULL;
Arik Nemtsov999609f2014-05-15 17:31:51 +03002881 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002882}
2883
2884static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
2885 struct ieee80211_vif *vif,
2886 struct ieee80211_chanctx_conf *ctx)
2887{
2888 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2889
2890 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02002891 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002892 mutex_unlock(&mvm->mutex);
2893}
2894
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002895static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
2896 struct ieee80211_vif_chanctx_switch *vifs,
2897 int n_vifs,
2898 enum ieee80211_chanctx_switch_mode mode)
2899{
2900 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2901 int ret;
2902
2903 /* we only support SWAP_CONTEXTS and with a single-vif right now */
2904 if (mode != CHANCTX_SWMODE_SWAP_CONTEXTS || n_vifs > 1)
2905 return -EOPNOTSUPP;
2906
2907 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02002908 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002909 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
2910
2911 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
2912 if (ret) {
2913 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
2914 goto out_reassign;
2915 }
2916
Luciano Coelhof0c97782014-03-05 15:41:48 +02002917 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
2918 true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002919 if (ret) {
2920 IWL_ERR(mvm,
2921 "failed to assign new_ctx during channel switch\n");
2922 goto out_remove;
2923 }
2924
Arik Nemtsovf6972672014-06-15 16:03:55 +03002925 /* we don't support TDLS during DCM - can be caused by channel switch */
2926 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2927 iwl_mvm_teardown_tdls_peers(mvm);
2928
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002929 goto out;
2930
2931out_remove:
2932 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
2933
2934out_reassign:
2935 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx);
2936 if (ret) {
2937 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
2938 goto out_restart;
2939 }
2940
Luciano Coelhof0c97782014-03-05 15:41:48 +02002941 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
2942 true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002943 if (ret) {
2944 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
2945 goto out_restart;
2946 }
2947
2948 goto out;
2949
2950out_restart:
2951 /* things keep failing, better restart the hw */
2952 iwl_mvm_nic_restart(mvm, false);
2953
2954out:
2955 mutex_unlock(&mvm->mutex);
2956 return ret;
2957}
2958
Johannes Berg8ca151b2013-01-24 14:25:36 +01002959static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
2960 struct ieee80211_sta *sta,
2961 bool set)
2962{
2963 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2964 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
2965
2966 if (!mvm_sta || !mvm_sta->vif) {
2967 IWL_ERR(mvm, "Station is not associated to a vif\n");
2968 return -EINVAL;
2969 }
2970
2971 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
2972}
2973
David Spinadel507cadf2013-07-31 18:07:21 +03002974#ifdef CONFIG_NL80211_TESTMODE
2975static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
2976 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
2977 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad422013-08-01 14:17:15 +02002978 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03002979};
2980
2981static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
2982 struct ieee80211_vif *vif,
2983 void *data, int len)
2984{
2985 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
2986 int err;
2987 u32 noa_duration;
2988
2989 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
2990 if (err)
2991 return err;
2992
2993 if (!tb[IWL_MVM_TM_ATTR_CMD])
2994 return -EINVAL;
2995
2996 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
2997 case IWL_MVM_TM_CMD_SET_NOA:
2998 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
2999 !vif->bss_conf.enable_beacon ||
3000 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3001 return -EINVAL;
3002
3003 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3004 if (noa_duration >= vif->bss_conf.beacon_int)
3005 return -EINVAL;
3006
3007 mvm->noa_duration = noa_duration;
3008 mvm->noa_vif = vif;
3009
Johannes Berg01662302014-06-06 15:18:45 +02003010 return iwl_mvm_update_quotas(mvm, NULL);
Johannes Bergf6c6ad422013-08-01 14:17:15 +02003011 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3012 /* must be associated client vif - ignore authorized */
3013 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3014 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3015 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3016 return -EINVAL;
3017
3018 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03003019 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3020 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
David Spinadel507cadf2013-07-31 18:07:21 +03003021 }
3022
3023 return -EOPNOTSUPP;
3024}
3025
3026static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3027 struct ieee80211_vif *vif,
3028 void *data, int len)
3029{
3030 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3031 int err;
3032
3033 mutex_lock(&mvm->mutex);
3034 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3035 mutex_unlock(&mvm->mutex);
3036
3037 return err;
3038}
3039#endif
3040
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003041static void iwl_mvm_channel_switch_beacon(struct ieee80211_hw *hw,
3042 struct ieee80211_vif *vif,
3043 struct cfg80211_chan_def *chandef)
3044{
3045 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003046 struct ieee80211_vif *csa_vif;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003047
3048 mutex_lock(&mvm->mutex);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003049
3050 csa_vif = rcu_dereference_protected(mvm->csa_vif,
3051 lockdep_is_held(&mvm->mutex));
3052 if (WARN(csa_vif && csa_vif->csa_active,
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003053 "Another CSA is already in progress"))
3054 goto out_unlock;
3055
3056 IWL_DEBUG_MAC80211(mvm, "CSA started to freq %d\n",
3057 chandef->center_freq1);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003058 rcu_assign_pointer(mvm->csa_vif, vif);
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003059
3060out_unlock:
3061 mutex_unlock(&mvm->mutex);
3062}
3063
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003064static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
3065 struct ieee80211_vif *vif, u32 queues, bool drop)
3066{
3067 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3068 struct iwl_mvm_vif *mvmvif;
3069 struct iwl_mvm_sta *mvmsta;
3070
3071 if (!vif || vif->type != NL80211_IFTYPE_STATION)
3072 return;
3073
3074 mutex_lock(&mvm->mutex);
3075 mvmvif = iwl_mvm_vif_from_mac80211(vif);
3076 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, mvmvif->ap_sta_id);
3077
Johannes Berg480acbc2014-10-10 08:59:27 +02003078 if (WARN_ON_ONCE(!mvmsta)) {
3079 mutex_unlock(&mvm->mutex);
3080 return;
3081 }
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003082
3083 if (drop) {
3084 if (iwl_mvm_flush_tx_path(mvm, mvmsta->tfd_queue_msk, true))
3085 IWL_ERR(mvm, "flush request fail\n");
Johannes Berg480acbc2014-10-10 08:59:27 +02003086 mutex_unlock(&mvm->mutex);
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003087 } else {
Johannes Berg480acbc2014-10-10 08:59:27 +02003088 u32 tfd_queue_msk = mvmsta->tfd_queue_msk;
3089 mutex_unlock(&mvm->mutex);
3090
3091 /* this can take a while, and we may need/want other operations
3092 * to succeed while doing this, so do it without the mutex held
3093 */
3094 iwl_trans_wait_tx_queue_empty(mvm->trans, tfd_queue_msk);
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003095 }
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003096}
3097
Johannes Berge5209262014-01-20 23:38:59 +01003098const struct ieee80211_ops iwl_mvm_hw_ops = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01003099 .tx = iwl_mvm_mac_tx,
3100 .ampdu_action = iwl_mvm_mac_ampdu_action,
3101 .start = iwl_mvm_mac_start,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02003102 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003103 .stop = iwl_mvm_mac_stop,
3104 .add_interface = iwl_mvm_mac_add_interface,
3105 .remove_interface = iwl_mvm_mac_remove_interface,
3106 .config = iwl_mvm_mac_config,
Eliad Pellere59647e2013-11-28 14:08:50 +02003107 .prepare_multicast = iwl_mvm_prepare_multicast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003108 .configure_filter = iwl_mvm_configure_filter,
3109 .bss_info_changed = iwl_mvm_bss_info_changed,
3110 .hw_scan = iwl_mvm_mac_hw_scan,
3111 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
Johannes Berg1ddbbb02013-12-04 22:39:17 +01003112 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003113 .sta_state = iwl_mvm_mac_sta_state,
3114 .sta_notify = iwl_mvm_mac_sta_notify,
3115 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
Johannes Berg3e56ead2013-02-15 22:23:18 +01003116 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003117 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02003118 .sta_rc_update = iwl_mvm_sta_rc_update,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003119 .conf_tx = iwl_mvm_mac_conf_tx,
3120 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
Arik Nemtsov07ecd892014-05-20 18:16:42 +03003121 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003122 .flush = iwl_mvm_mac_flush,
David Spinadel35a000b2013-08-28 09:29:43 +03003123 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
3124 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003125 .set_key = iwl_mvm_mac_set_key,
3126 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
3127 .remain_on_channel = iwl_mvm_roc,
3128 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003129 .add_chanctx = iwl_mvm_add_chanctx,
3130 .remove_chanctx = iwl_mvm_remove_chanctx,
3131 .change_chanctx = iwl_mvm_change_chanctx,
3132 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
3133 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003134 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003135
Johannes Berg5023d962013-07-31 14:07:43 +02003136 .start_ap = iwl_mvm_start_ap_ibss,
3137 .stop_ap = iwl_mvm_stop_ap_ibss,
3138 .join_ibss = iwl_mvm_start_ap_ibss,
3139 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003140
3141 .set_tim = iwl_mvm_set_tim,
3142
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003143 .channel_switch_beacon = iwl_mvm_channel_switch_beacon,
3144
David Spinadel507cadf2013-07-31 18:07:21 +03003145 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
3146
Johannes Berg8ca151b2013-01-24 14:25:36 +01003147#ifdef CONFIG_PM_SLEEP
3148 /* look at d3.c */
3149 .suspend = iwl_mvm_suspend,
3150 .resume = iwl_mvm_resume,
3151 .set_wakeup = iwl_mvm_set_wakeup,
3152 .set_rekey_data = iwl_mvm_set_rekey_data,
3153#if IS_ENABLED(CONFIG_IPV6)
3154 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
3155#endif
3156 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
3157#endif
3158};