blob: 09654e73a533f7733c2a5b1e47bf6251d6267585 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +02009 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020026 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010027 *
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020034 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +020035 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010036 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
47 * distribution.
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *
64 *****************************************************************************/
65#include <linux/kernel.h>
66#include <linux/slab.h>
67#include <linux/skbuff.h>
68#include <linux/netdevice.h>
69#include <linux/etherdevice.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010070#include <linux/ip.h>
Eliad Peller2ee8f022014-01-13 19:07:09 +020071#include <linux/if_arp.h>
Johannes Bergaadede62014-10-09 17:01:36 +020072#include <linux/devcoredump.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010073#include <net/mac80211.h>
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +020074#include <net/ieee80211_radiotap.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010075#include <net/tcp.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010076
77#include "iwl-op-mode.h"
78#include "iwl-io.h"
79#include "mvm.h"
80#include "sta.h"
81#include "time-event.h"
82#include "iwl-eeprom-parse.h"
83#include "fw-api-scan.h"
84#include "iwl-phy-db.h"
David Spinadel507cadf2013-07-31 18:07:21 +030085#include "testmode.h"
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +030086#include "iwl-fw-error-dump.h"
87#include "iwl-prph.h"
Eran Harary363039b2014-12-02 15:19:22 +020088#include "iwl-csr.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010089
90static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
91 {
92 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030093 .types = BIT(NL80211_IFTYPE_STATION),
Johannes Berg8ca151b2013-01-24 14:25:36 +010094 },
Johannes Berg3c15a0f2013-05-31 10:17:19 +020095 {
96 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030097 .types = BIT(NL80211_IFTYPE_AP) |
98 BIT(NL80211_IFTYPE_P2P_CLIENT) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +020099 BIT(NL80211_IFTYPE_P2P_GO),
100 },
101 {
102 .max = 1,
103 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
104 },
Johannes Berg8ca151b2013-01-24 14:25:36 +0100105};
106
107static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
108 {
Emmanuel Grumbach2624a5c2014-12-16 13:02:03 +0200109 .num_different_channels = 2,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100110 .max_interfaces = 3,
111 .limits = iwl_mvm_limits,
112 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
113 },
114};
115
Johannes Bergf0c26462013-01-22 20:41:58 +0100116#ifdef CONFIG_PM_SLEEP
117static const struct nl80211_wowlan_tcp_data_token_feature
118iwl_mvm_wowlan_tcp_token_feature = {
119 .min_len = 0,
120 .max_len = 255,
121 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
122};
123
124static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
125 .tok = &iwl_mvm_wowlan_tcp_token_feature,
126 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
127 sizeof(struct ethhdr) -
128 sizeof(struct iphdr) -
129 sizeof(struct tcphdr),
130 .data_interval_max = 65535, /* __le16 in API */
131 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
132 sizeof(struct ethhdr) -
133 sizeof(struct iphdr) -
134 sizeof(struct tcphdr),
135 .seq = true,
136};
137#endif
138
Eliad Peller77736922014-01-14 12:35:49 +0200139#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
Eliad Peller2ee8f022014-01-13 19:07:09 +0200140/*
141 * Use the reserved field to indicate magic values.
142 * these values will only be used internally by the driver,
143 * and won't make it to the fw (reserved will be 0).
144 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
145 * be the vif's ip address. in case there is not a single
146 * ip address (0, or more than 1), this attribute will
147 * be skipped.
148 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
149 * the LSB bytes of the vif's mac address
150 */
151enum {
152 BC_FILTER_MAGIC_NONE = 0,
153 BC_FILTER_MAGIC_IP,
154 BC_FILTER_MAGIC_MAC,
155};
156
Eliad Peller77736922014-01-14 12:35:49 +0200157static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
158 {
159 /* arp */
160 .discard = 0,
161 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
162 .attrs = {
163 {
164 /* frame type - arp, hw type - ethernet */
165 .offset_type =
166 BCAST_FILTER_OFFSET_PAYLOAD_START,
167 .offset = sizeof(rfc1042_header),
168 .val = cpu_to_be32(0x08060001),
169 .mask = cpu_to_be32(0xffffffff),
170 },
Eliad Peller2ee8f022014-01-13 19:07:09 +0200171 {
172 /* arp dest ip */
173 .offset_type =
174 BCAST_FILTER_OFFSET_PAYLOAD_START,
175 .offset = sizeof(rfc1042_header) + 2 +
176 sizeof(struct arphdr) +
177 ETH_ALEN + sizeof(__be32) +
178 ETH_ALEN,
179 .mask = cpu_to_be32(0xffffffff),
180 /* mark it as special field */
181 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
182 },
183 },
184 },
185 {
186 /* dhcp offer bcast */
187 .discard = 0,
188 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
189 .attrs = {
190 {
191 /* udp dest port - 68 (bootp client)*/
192 .offset_type = BCAST_FILTER_OFFSET_IP_END,
193 .offset = offsetof(struct udphdr, dest),
194 .val = cpu_to_be32(0x00440000),
195 .mask = cpu_to_be32(0xffff0000),
196 },
197 {
198 /* dhcp - lsb bytes of client hw address */
199 .offset_type = BCAST_FILTER_OFFSET_IP_END,
200 .offset = 38,
201 .mask = cpu_to_be32(0xffffffff),
202 /* mark it as special field */
203 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
204 },
Eliad Peller77736922014-01-14 12:35:49 +0200205 },
206 },
207 /* last filter must be empty */
208 {},
209};
210#endif
211
Eliad Peller7498cf42014-01-16 17:10:44 +0200212void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
213{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200214 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200215 return;
216
217 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
Eliad Peller576eeee2014-07-01 18:38:38 +0300218 spin_lock_bh(&mvm->refs_lock);
219 mvm->refs[ref_type]++;
220 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200221 iwl_trans_ref(mvm->trans);
222}
223
224void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
225{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200226 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200227 return;
228
229 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
Eliad Peller576eeee2014-07-01 18:38:38 +0300230 spin_lock_bh(&mvm->refs_lock);
231 WARN_ON(!mvm->refs[ref_type]--);
232 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200233 iwl_trans_unref(mvm->trans);
234}
235
Eliad Peller576eeee2014-07-01 18:38:38 +0300236static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
237 enum iwl_mvm_ref_type except_ref)
Eliad Peller7498cf42014-01-16 17:10:44 +0200238{
Eliad Peller576eeee2014-07-01 18:38:38 +0300239 int i, j;
Eliad Peller7498cf42014-01-16 17:10:44 +0200240
Eliad Peller7bb426e2014-02-24 12:54:37 +0200241 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200242 return;
243
Eliad Peller576eeee2014-07-01 18:38:38 +0300244 spin_lock_bh(&mvm->refs_lock);
245 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
246 if (except_ref == i || !mvm->refs[i])
Eliad Peller7498cf42014-01-16 17:10:44 +0200247 continue;
248
Eliad Peller576eeee2014-07-01 18:38:38 +0300249 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
250 i, mvm->refs[i]);
251 for (j = 0; j < mvm->refs[i]; j++)
252 iwl_trans_unref(mvm->trans);
253 mvm->refs[i] = 0;
Eliad Peller7498cf42014-01-16 17:10:44 +0200254 }
Eliad Peller576eeee2014-07-01 18:38:38 +0300255 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200256}
257
Eliad Pellerf4cf8682014-11-04 16:57:06 +0200258bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
259{
260 int i;
261 bool taken = false;
262
263 if (!iwl_mvm_is_d0i3_supported(mvm))
264 return true;
265
266 spin_lock_bh(&mvm->refs_lock);
267 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
268 if (mvm->refs[i]) {
269 taken = true;
270 break;
271 }
272 }
273 spin_unlock_bh(&mvm->refs_lock);
274
275 return taken;
276}
277
Eliad Peller576eeee2014-07-01 18:38:38 +0300278int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
Gregory Greenmand40fc482014-06-25 14:08:50 +0200279{
280 iwl_mvm_ref(mvm, ref_type);
281
282 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
283 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
284 HZ)) {
285 WARN_ON_ONCE(1);
286 iwl_mvm_unref(mvm, ref_type);
287 return -EIO;
288 }
289
290 return 0;
291}
292
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200293static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
294{
295 int i;
296
297 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
298 for (i = 0; i < NUM_PHY_CTX; i++) {
299 mvm->phy_ctxts[i].id = i;
300 mvm->phy_ctxts[i].ref = 0;
301 }
302}
303
Johannes Berg8ca151b2013-01-24 14:25:36 +0100304int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
305{
306 struct ieee80211_hw *hw = mvm->hw;
Ilan Peer831e85f2013-02-07 17:09:09 +0200307 int num_mac, ret, i;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100308
309 /* Tell mac80211 our characteristics */
310 hw->flags = IEEE80211_HW_SIGNAL_DBM |
311 IEEE80211_HW_SPECTRUM_MGMT |
312 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
313 IEEE80211_HW_QUEUE_CONTROL |
314 IEEE80211_HW_WANT_MONITOR_VIF |
Johannes Berg8ca151b2013-01-24 14:25:36 +0100315 IEEE80211_HW_SUPPORTS_PS |
316 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Johannes Bergd2931bb2013-02-05 18:10:04 +0100317 IEEE80211_HW_AMPDU_AGGREGATION |
Hila Gonend64048e2013-03-13 18:00:03 +0200318 IEEE80211_HW_TIMING_BEACON_ONLY |
Emmanuel Grumbach147fc9b2013-07-28 11:00:52 +0300319 IEEE80211_HW_CONNECTION_MONITOR |
Ido Yarivb71d9c82014-07-23 09:31:14 -0400320 IEEE80211_HW_CHANCTX_STA_CSA |
321 IEEE80211_HW_SUPPORTS_CLONED_SKBS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100322
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200323 hw->queues = mvm->first_agg_queue;
Ilan Peer398e8c62013-03-13 15:20:35 +0200324 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +0200325 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
326 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
Eyal Shapira339b3082014-11-18 16:43:55 +0200327 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
328 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100329 hw->rate_control_algorithm = "iwl-mvm-rs";
Johannes Berg848955c2014-11-11 12:48:42 +0100330 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
331 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100332
333 /*
334 * Enable 11w if advertised by firmware and software crypto
335 * is not enabled (as the firmware will interpret some mgmt
336 * packets, so enabling it with software crypto isn't safe)
337 */
338 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
339 !iwlwifi_mod_params.sw_crypto)
340 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
341
David Spinadeld2496222014-05-20 12:46:37 +0300342 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN ||
Johannes Bergeffd05a2014-11-18 17:21:19 +0100343 mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) {
David Spinadelfb98be52014-05-04 12:51:10 +0300344 hw->flags |= IEEE80211_SINGLE_HW_SCAN_ON_ALL_BANDS;
Johannes Bergeffd05a2014-11-18 17:21:19 +0100345 hw->wiphy->features |=
346 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
347 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
348 }
David Spinadelfb98be52014-05-04 12:51:10 +0300349
Johannes Berg8ca151b2013-01-24 14:25:36 +0100350 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
351 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200352 hw->chanctx_data_size = sizeof(u16);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100353
354 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200355 BIT(NL80211_IFTYPE_P2P_CLIENT) |
356 BIT(NL80211_IFTYPE_AP) |
357 BIT(NL80211_IFTYPE_P2P_GO) |
Emmanuel Grumbachc13b1722014-03-27 19:12:12 +0200358 BIT(NL80211_IFTYPE_P2P_DEVICE) |
359 BIT(NL80211_IFTYPE_ADHOC);
Johannes Berg5023d962013-07-31 14:07:43 +0200360
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +0100361 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
362 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
363 REGULATORY_DISABLE_BEACON_HINTS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100364
Johannes Berg3e56ead2013-02-15 22:23:18 +0100365 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
366 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
367
Emmanuel Grumbach94bbed72014-11-24 08:53:33 +0200368 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +0200369
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;
Emmanuel Grumbachf1a68542014-12-16 12:31:13 +0200376 /* we can compensate an offset of up to 3 channels = 15 MHz */
377 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100378
379 /* Extract MAC address */
380 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
381 hw->wiphy->addresses = mvm->addresses;
382 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200383
384 /* Extract additional MAC addresses if available */
385 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
386 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
387
388 for (i = 1; i < num_mac; i++) {
389 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100390 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200391 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100392 hw->wiphy->n_addresses++;
393 }
394
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200395 iwl_mvm_reset_phy_ctxts(mvm);
396
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300397 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm, false);
David Spinadel20f1a5d2013-08-21 09:14:27 +0300398
Johannes Berg8ca151b2013-01-24 14:25:36 +0100399 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
400
401 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
402 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
403 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
Eyal Shapira3d44eeb2015-01-16 22:37:04 +0200404 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100405 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
406 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
407
Eyal Shapirac9faccc2015-02-23 10:02:23 +0200408 if ((mvm->fw->ucode_capa.capa[0] &
409 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
410 (mvm->fw->ucode_capa.api[0] &
411 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
Eyal Shapira3d44eeb2015-01-16 22:37:04 +0200412 hw->wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap.cap |=
413 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
414 }
415
Johannes Berg8ca151b2013-01-24 14:25:36 +0100416 hw->wiphy->hw_version = mvm->trans->hw_id;
417
Alexander Bondarade50652013-04-03 16:28:47 +0300418 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100419 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
420 else
421 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
422
Emmanuel Grumbach6efaaf32014-09-01 10:03:21 +0300423 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 10) {
424 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
425 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
426 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
427 /* we create the 802.11 header and zero length SSID IE. */
428 hw->wiphy->max_sched_scan_ie_len =
429 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
430 }
David Spinadel35a000b2013-08-28 09:29:43 +0300431
Johannes Berg8ca151b2013-01-24 14:25:36 +0100432 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
Johannes Bergab480032014-06-04 10:13:50 +0200433 NL80211_FEATURE_LOW_PRIORITY_SCAN |
Eliad Peller0d8614b2014-09-10 14:07:36 +0300434 NL80211_FEATURE_P2P_GO_OPPPS |
435 NL80211_FEATURE_DYNAMIC_SMPS |
Emmanuel Grumbach9b5452f2014-10-07 10:38:53 +0300436 NL80211_FEATURE_STATIC_SMPS |
437 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100438
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300439 if (mvm->fw->ucode_capa.capa[0] &
440 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)
441 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
Assaf Krauss226bcd42014-03-13 08:12:15 +0200442 if (mvm->fw->ucode_capa.capa[0] &
443 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)
444 hw->wiphy->features |= NL80211_FEATURE_QUIET;
Andrei Otcheretianskif1daa002014-07-01 12:54:25 +0300445
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300446 if (mvm->fw->ucode_capa.capa[0] &
447 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)
448 hw->wiphy->features |=
449 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
450
451 if (mvm->fw->ucode_capa.capa[0] &
452 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)
453 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
454
Johannes Berg8ca151b2013-01-24 14:25:36 +0100455 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
456
Max Stepanove36e5432013-08-27 19:56:13 +0300457 /* currently FW API supports only one optional cipher scheme */
Johannes Berg9ddca862014-01-06 09:29:40 +0100458 if (mvm->fw->cs[0].cipher) {
Max Stepanove36e5432013-08-27 19:56:13 +0300459 mvm->hw->n_cipher_schemes = 1;
Johannes Berg9ddca862014-01-06 09:29:40 +0100460 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
Max Stepanove36e5432013-08-27 19:56:13 +0300461 }
462
Johannes Berg8ca151b2013-01-24 14:25:36 +0100463#ifdef CONFIG_PM_SLEEP
Eliad Pellerd15a7472014-03-27 18:53:12 +0200464 if (iwl_mvm_is_d0i3_supported(mvm) &&
465 device_can_wakeup(mvm->trans->dev)) {
466 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
467 hw->wiphy->wowlan = &mvm->wowlan;
Eliad Peller91742442014-12-09 15:54:46 +0200468 }
469
470 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100471 mvm->trans->ops->d3_suspend &&
472 mvm->trans->ops->d3_resume &&
473 device_can_wakeup(mvm->trans->dev)) {
Eliad Peller91742442014-12-09 15:54:46 +0200474 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
475 WIPHY_WOWLAN_DISCONNECT |
476 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
477 WIPHY_WOWLAN_RFKILL_RELEASE |
478 WIPHY_WOWLAN_NET_DETECT;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100479 if (!iwlwifi_mod_params.sw_crypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200480 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
481 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
482 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100483
Johannes Berg964dc9e2013-06-03 17:25:34 +0200484 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
485 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
486 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
Luciano Coelhoc55385f2014-10-24 10:39:51 +0300487 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
Johannes Berg964dc9e2013-06-03 17:25:34 +0200488 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
489 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100490 }
491#endif
492
Eliad Peller77736922014-01-14 12:35:49 +0200493#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
494 /* assign default bcast filtering configuration */
495 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
496#endif
497
Johannes Berg8ca151b2013-01-24 14:25:36 +0100498 ret = iwl_mvm_leds_init(mvm);
499 if (ret)
500 return ret;
501
Arik Nemtsovd8f1c512014-05-11 18:13:04 +0300502 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_TDLS_SUPPORT) {
503 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
504 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
505 }
506
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +0300507 if (mvm->fw->ucode_capa.capa[0] &
508 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH) {
509 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
510 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
511 }
512
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300513 ret = ieee80211_register_hw(mvm->hw);
514 if (ret)
515 iwl_mvm_leds_exit(mvm);
516
517 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100518}
519
Arik Nemtsovb2492502014-03-13 12:21:50 +0200520static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
521 struct ieee80211_sta *sta,
522 struct sk_buff *skb)
523{
524 struct iwl_mvm_sta *mvmsta;
525 bool defer = false;
526
527 /*
528 * double check the IN_D0I3 flag both before and after
529 * taking the spinlock, in order to prevent taking
530 * the spinlock when not needed.
531 */
532 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
533 return false;
534
535 spin_lock(&mvm->d0i3_tx_lock);
536 /*
537 * testing the flag again ensures the skb dequeue
538 * loop (on d0i3 exit) hasn't run yet.
539 */
540 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
541 goto out;
542
543 mvmsta = iwl_mvm_sta_from_mac80211(sta);
544 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
545 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
546 goto out;
547
548 __skb_queue_tail(&mvm->d0i3_tx, skb);
549 ieee80211_stop_queues(mvm->hw);
550
551 /* trigger wakeup */
552 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
553 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
554
555 defer = true;
556out:
557 spin_unlock(&mvm->d0i3_tx_lock);
558 return defer;
559}
560
Johannes Berg8ca151b2013-01-24 14:25:36 +0100561static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
562 struct ieee80211_tx_control *control,
563 struct sk_buff *skb)
564{
565 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg3e56ead2013-02-15 22:23:18 +0100566 struct ieee80211_sta *sta = control->sta;
567 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
568 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100569
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300570 if (iwl_mvm_is_radio_killed(mvm)) {
571 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100572 goto drop;
573 }
574
Ilan Peer398e8c62013-03-13 15:20:35 +0200575 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Matti Gottlieba6cc5162014-09-29 11:46:04 +0300576 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
577 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100578 goto drop;
579
Johannes Berg3e56ead2013-02-15 22:23:18 +0100580 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
581 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
582 ieee80211_is_mgmt(hdr->frame_control) &&
583 !ieee80211_is_deauth(hdr->frame_control) &&
584 !ieee80211_is_disassoc(hdr->frame_control) &&
585 !ieee80211_is_action(hdr->frame_control)))
586 sta = NULL;
587
588 if (sta) {
Arik Nemtsovb2492502014-03-13 12:21:50 +0200589 if (iwl_mvm_defer_tx(mvm, sta, skb))
590 return;
Johannes Berg3e56ead2013-02-15 22:23:18 +0100591 if (iwl_mvm_tx_skb(mvm, skb, sta))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100592 goto drop;
593 return;
594 }
595
596 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
597 goto drop;
598 return;
599 drop:
600 ieee80211_free_txskb(hw, skb);
601}
602
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200603static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
604{
605 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
606 return false;
607 return true;
608}
609
610static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
611{
612 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
613 return false;
614 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
615 return true;
616
617 /* enabled by default */
618 return true;
619}
620
Johannes Berg8ca151b2013-01-24 14:25:36 +0100621static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
622 struct ieee80211_vif *vif,
623 enum ieee80211_ampdu_mlme_action action,
624 struct ieee80211_sta *sta, u16 tid,
625 u16 *ssn, u8 buf_size)
626{
627 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
628 int ret;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200629 bool tx_agg_ref = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100630
631 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
632 sta->addr, tid, action);
633
634 if (!(mvm->nvm_data->sku_cap_11n_enable))
635 return -EACCES;
636
Arik Nemtsovb2492502014-03-13 12:21:50 +0200637 /* return from D0i3 before starting a new Tx aggregation */
Eliad Peller9256c202014-04-22 13:33:29 +0300638 switch (action) {
639 case IEEE80211_AMPDU_TX_START:
640 case IEEE80211_AMPDU_TX_STOP_CONT:
641 case IEEE80211_AMPDU_TX_STOP_FLUSH:
642 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
643 case IEEE80211_AMPDU_TX_OPERATIONAL:
Arik Nemtsovb2492502014-03-13 12:21:50 +0200644 /*
Eliad Peller9256c202014-04-22 13:33:29 +0300645 * for tx start, wait synchronously until D0i3 exit to
646 * get the correct sequence number for the tid.
647 * additionally, some other ampdu actions use direct
648 * target access, which is not handled automatically
649 * by the trans layer (unlike commands), so wait for
650 * d0i3 exit in these cases as well.
Arik Nemtsovb2492502014-03-13 12:21:50 +0200651 */
Gregory Greenmand40fc482014-06-25 14:08:50 +0200652 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
653 if (ret)
654 return ret;
655
656 tx_agg_ref = true;
Eliad Peller9256c202014-04-22 13:33:29 +0300657 break;
658 default:
659 break;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200660 }
661
Johannes Berg8ca151b2013-01-24 14:25:36 +0100662 mutex_lock(&mvm->mutex);
663
664 switch (action) {
665 case IEEE80211_AMPDU_RX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200666 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100667 ret = -EINVAL;
668 break;
669 }
670 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
671 break;
672 case IEEE80211_AMPDU_RX_STOP:
673 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
674 break;
675 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200676 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200677 ret = -EINVAL;
678 break;
679 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100680 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
681 break;
682 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200683 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
684 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100685 case IEEE80211_AMPDU_TX_STOP_FLUSH:
686 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200687 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100688 break;
689 case IEEE80211_AMPDU_TX_OPERATIONAL:
690 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
691 break;
692 default:
693 WARN_ON_ONCE(1);
694 ret = -EINVAL;
695 break;
696 }
697 mutex_unlock(&mvm->mutex);
698
Arik Nemtsovb2492502014-03-13 12:21:50 +0200699 /*
700 * If the tid is marked as started, we won't use it for offloaded
701 * traffic on the next D0i3 entry. It's safe to unref.
702 */
703 if (tx_agg_ref)
704 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
705
Johannes Berg8ca151b2013-01-24 14:25:36 +0100706 return ret;
707}
708
709static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
710 struct ieee80211_vif *vif)
711{
712 struct iwl_mvm *mvm = data;
713 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
714
715 mvmvif->uploaded = false;
716 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
717
Johannes Berg8ca151b2013-01-24 14:25:36 +0100718 spin_lock_bh(&mvm->time_event_lock);
719 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
720 spin_unlock_bh(&mvm->time_event_lock);
721
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200722 mvmvif->phy_ctxt = NULL;
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +0300723 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100724}
725
Johannes Bergaadede62014-10-09 17:01:36 +0200726static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count,
727 const void *data, size_t datalen)
728{
729 const struct iwl_mvm_dump_ptrs *dump_ptrs = data;
730 ssize_t bytes_read;
731 ssize_t bytes_read_trans;
732
733 if (offset < dump_ptrs->op_mode_len) {
734 bytes_read = min_t(ssize_t, count,
735 dump_ptrs->op_mode_len - offset);
736 memcpy(buffer, (u8 *)dump_ptrs->op_mode_ptr + offset,
737 bytes_read);
738 offset += bytes_read;
739 count -= bytes_read;
740
741 if (count == 0)
742 return bytes_read;
743 } else {
744 bytes_read = 0;
745 }
746
747 if (!dump_ptrs->trans_ptr)
748 return bytes_read;
749
750 offset -= dump_ptrs->op_mode_len;
751 bytes_read_trans = min_t(ssize_t, count,
752 dump_ptrs->trans_ptr->len - offset);
753 memcpy(buffer + bytes_read,
754 (u8 *)dump_ptrs->trans_ptr->data + offset,
755 bytes_read_trans);
756
757 return bytes_read + bytes_read_trans;
758}
759
760static void iwl_mvm_free_coredump(const void *data)
761{
762 const struct iwl_mvm_dump_ptrs *fw_error_dump = data;
763
764 vfree(fw_error_dump->op_mode_ptr);
765 vfree(fw_error_dump->trans_ptr);
766 kfree(fw_error_dump);
767}
768
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200769static void iwl_mvm_dump_fifos(struct iwl_mvm *mvm,
770 struct iwl_fw_error_dump_data **dump_data)
771{
772 struct iwl_fw_error_dump_fifo *fifo_hdr;
773 u32 *fifo_data;
774 u32 fifo_len;
775 unsigned long flags;
776 int i, j;
777
778 if (!iwl_trans_grab_nic_access(mvm->trans, false, &flags))
779 return;
780
781 /* Pull RXF data from all RXFs */
782 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++) {
783 /*
784 * Keep aside the additional offset that might be needed for
785 * next RXF
786 */
787 u32 offset_diff = RXF_DIFF_FROM_PREV * i;
788
789 fifo_hdr = (void *)(*dump_data)->data;
790 fifo_data = (void *)fifo_hdr->data;
791 fifo_len = mvm->shared_mem_cfg.rxfifo_size[i];
792
793 /* No need to try to read the data if the length is 0 */
794 if (fifo_len == 0)
795 continue;
796
797 /* Add a TLV for the RXF */
798 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
799 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
800
801 fifo_hdr->fifo_num = cpu_to_le32(i);
802 fifo_hdr->available_bytes =
803 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
804 RXF_RD_D_SPACE +
805 offset_diff));
806 fifo_hdr->wr_ptr =
807 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
808 RXF_RD_WR_PTR +
809 offset_diff));
810 fifo_hdr->rd_ptr =
811 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
812 RXF_RD_RD_PTR +
813 offset_diff));
814 fifo_hdr->fence_ptr =
815 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
816 RXF_RD_FENCE_PTR +
817 offset_diff));
818 fifo_hdr->fence_mode =
819 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
820 RXF_SET_FENCE_MODE +
821 offset_diff));
822
823 /* Lock fence */
824 iwl_trans_write_prph(mvm->trans,
825 RXF_SET_FENCE_MODE + offset_diff, 0x1);
826 /* Set fence pointer to the same place like WR pointer */
827 iwl_trans_write_prph(mvm->trans,
828 RXF_LD_WR2FENCE + offset_diff, 0x1);
829 /* Set fence offset */
830 iwl_trans_write_prph(mvm->trans,
831 RXF_LD_FENCE_OFFSET_ADDR + offset_diff,
832 0x0);
833
834 /* Read FIFO */
835 fifo_len /= sizeof(u32); /* Size in DWORDS */
836 for (j = 0; j < fifo_len; j++)
837 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
838 RXF_FIFO_RD_FENCE_INC +
839 offset_diff);
840 *dump_data = iwl_fw_error_next_data(*dump_data);
841 }
842
843 /* Pull TXF data from all TXFs */
844 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++) {
845 /* Mark the number of TXF we're pulling now */
846 iwl_trans_write_prph(mvm->trans, TXF_LARC_NUM, i);
847
848 fifo_hdr = (void *)(*dump_data)->data;
849 fifo_data = (void *)fifo_hdr->data;
850 fifo_len = mvm->shared_mem_cfg.txfifo_size[i];
851
852 /* No need to try to read the data if the length is 0 */
853 if (fifo_len == 0)
854 continue;
855
856 /* Add a TLV for the FIFO */
857 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXF);
858 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
859
860 fifo_hdr->fifo_num = cpu_to_le32(i);
861 fifo_hdr->available_bytes =
862 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
863 TXF_FIFO_ITEM_CNT));
864 fifo_hdr->wr_ptr =
865 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
866 TXF_WR_PTR));
867 fifo_hdr->rd_ptr =
868 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
869 TXF_RD_PTR));
870 fifo_hdr->fence_ptr =
871 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
872 TXF_FENCE_PTR));
873 fifo_hdr->fence_mode =
874 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
875 TXF_LOCK_FENCE));
876
877 /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */
878 iwl_trans_write_prph(mvm->trans, TXF_READ_MODIFY_ADDR,
879 TXF_WR_PTR);
880
881 /* Dummy-read to advance the read pointer to the head */
882 iwl_trans_read_prph(mvm->trans, TXF_READ_MODIFY_DATA);
883
884 /* Read FIFO */
885 fifo_len /= sizeof(u32); /* Size in DWORDS */
886 for (j = 0; j < fifo_len; j++)
887 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
888 TXF_READ_MODIFY_DATA);
889 *dump_data = iwl_fw_error_next_data(*dump_data);
890 }
891
892 iwl_trans_release_nic_access(mvm->trans, &flags);
893}
894
Emmanuel Grumbach4bfa47f2014-09-11 16:19:43 +0300895void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300896{
897 struct iwl_fw_error_dump_file *dump_file;
898 struct iwl_fw_error_dump_data *dump_data;
899 struct iwl_fw_error_dump_info *dump_info;
Emmanuel Grumbacha549b292014-12-09 14:47:57 +0200900 struct iwl_fw_error_dump_mem *dump_mem;
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300901 struct iwl_mvm_dump_ptrs *fw_error_dump;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300902 u32 sram_len, sram_ofs;
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200903 u32 file_len, fifo_data_len = 0;
Liad Kaufmanaddfaad2014-12-02 11:16:04 +0200904 u32 smem_len = mvm->cfg->smem_len;
Ido Yariv86138322014-12-10 12:39:27 -0500905 u32 sram2_len = mvm->cfg->dccm2_len;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300906
907 lockdep_assert_held(&mvm->mutex);
908
Liad Kaufmanaddfaad2014-12-02 11:16:04 +0200909 /* W/A for 8000 HW family A-step */
Ido Yariv86138322014-12-10 12:39:27 -0500910 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
911 CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_A_STEP) {
912 if (smem_len)
913 smem_len = 0x38000;
914
915 if (sram2_len)
916 sram2_len = 0x10000;
917 }
Liad Kaufmanaddfaad2014-12-02 11:16:04 +0200918
Johannes Bergaadede62014-10-09 17:01:36 +0200919 fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300920 if (!fw_error_dump)
921 return;
922
Liad Kaufmanf53bf4c2014-12-01 10:44:18 +0200923 /* SRAM - include stack CCM if driver knows the values for it */
924 if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
925 const struct fw_img *img;
926
927 img = &mvm->fw->img[mvm->cur_ucode];
928 sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
929 sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
930 } else {
931 sram_ofs = mvm->cfg->dccm_offset;
932 sram_len = mvm->cfg->dccm_len;
933 }
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300934
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200935 /* reading RXF/TXF sizes */
936 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
937 struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->shared_mem_cfg;
938 int i;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300939
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200940 fifo_data_len = 0;
941
942 /* Count RXF size */
943 for (i = 0; i < ARRAY_SIZE(mem_cfg->rxfifo_size); i++) {
944 if (!mem_cfg->rxfifo_size[i])
945 continue;
946
947 /* Add header info */
948 fifo_data_len += mem_cfg->rxfifo_size[i] +
949 sizeof(*dump_data) +
950 sizeof(struct iwl_fw_error_dump_fifo);
951 }
952
953 for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++) {
954 if (!mem_cfg->txfifo_size[i])
955 continue;
956
957 /* Add header info */
958 fifo_data_len += mem_cfg->txfifo_size[i] +
959 sizeof(*dump_data) +
960 sizeof(struct iwl_fw_error_dump_fifo);
961 }
962 }
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300963
964 file_len = sizeof(*dump_file) +
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200965 sizeof(*dump_data) * 2 +
Emmanuel Grumbacha549b292014-12-09 14:47:57 +0200966 sram_len + sizeof(*dump_mem) +
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200967 fifo_data_len +
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300968 sizeof(*dump_info);
969
Liad Kaufmanaddfaad2014-12-02 11:16:04 +0200970 /* Make room for the SMEM, if it exists */
971 if (smem_len)
Emmanuel Grumbacha549b292014-12-09 14:47:57 +0200972 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
Liad Kaufmanaddfaad2014-12-02 11:16:04 +0200973
Ido Yariv86138322014-12-10 12:39:27 -0500974 /* Make room for the secondary SRAM, if it exists */
975 if (sram2_len)
976 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len;
977
Emmanuel Grumbach5bfe6f52014-06-25 16:21:43 +0300978 dump_file = vzalloc(file_len);
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300979 if (!dump_file) {
980 kfree(fw_error_dump);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300981 return;
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300982 }
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300983
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300984 fw_error_dump->op_mode_ptr = dump_file;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300985
986 dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300987 dump_data = (void *)dump_file->data;
988
989 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
990 dump_data->len = cpu_to_le32(sizeof(*dump_info));
991 dump_info = (void *) dump_data->data;
992 dump_info->device_family =
993 mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
994 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
995 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
Ido Yariv435da2c2014-12-11 16:11:01 -0500996 dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300997 memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
998 sizeof(dump_info->fw_human_readable));
999 strncpy(dump_info->dev_human_readable, mvm->cfg->name,
1000 sizeof(dump_info->dev_human_readable));
1001 strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
1002 sizeof(dump_info->bus_human_readable));
1003
1004 dump_data = iwl_fw_error_next_data(dump_data);
Liad Kaufman04fd2c22014-12-15 17:54:16 +02001005 /* We only dump the FIFOs if the FW is in error state */
1006 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status))
1007 iwl_mvm_dump_fifos(mvm, &dump_data);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001008
Emmanuel Grumbacha549b292014-12-09 14:47:57 +02001009 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1010 dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
1011 dump_mem = (void *)dump_data->data;
1012 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
1013 dump_mem->offset = cpu_to_le32(sram_ofs);
1014 iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001015 sram_len);
1016
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001017 if (smem_len) {
1018 dump_data = iwl_fw_error_next_data(dump_data);
Emmanuel Grumbache06d8432014-12-09 14:36:41 +02001019 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1020 dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
1021 dump_mem = (void *)dump_data->data;
1022 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
1023 dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001024 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
Emmanuel Grumbache06d8432014-12-09 14:36:41 +02001025 dump_mem->data, smem_len);
Liad Kaufmanaddfaad2014-12-02 11:16:04 +02001026 }
1027
Ido Yariv86138322014-12-10 12:39:27 -05001028 if (sram2_len) {
1029 dump_data = iwl_fw_error_next_data(dump_data);
1030 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1031 dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem));
1032 dump_mem = (void *)dump_data->data;
1033 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
1034 dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset);
1035 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset,
1036 dump_mem->data, sram2_len);
1037 }
1038
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +03001039 fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans);
1040 fw_error_dump->op_mode_len = file_len;
1041 if (fw_error_dump->trans_ptr)
1042 file_len += fw_error_dump->trans_ptr->len;
1043 dump_file->file_len = cpu_to_le32(file_len);
Emmanuel Grumbach4bfa47f2014-09-11 16:19:43 +03001044
Johannes Bergaadede62014-10-09 17:01:36 +02001045 dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
1046 GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001047}
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +03001048
Johannes Berg8ca151b2013-01-24 14:25:36 +01001049static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1050{
Johannes Berg58629d92014-11-06 09:40:50 +01001051 /* clear the D3 reconfig, we only need it to avoid dumping a
1052 * firmware coredump on reconfiguration, we shouldn't do that
1053 * on D3->D0 transition
1054 */
1055 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status))
1056 iwl_mvm_fw_error_dump(mvm);
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +02001057
Eliad Peller744cb692014-12-10 18:44:13 +02001058 /* cleanup all stale references (scan, roc), but keep the
1059 * ucode_down ref until reconfig is complete
1060 */
1061 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1062
Johannes Berg8ca151b2013-01-24 14:25:36 +01001063 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001064
1065 mvm->scan_status = IWL_MVM_SCAN_NONE;
Luciano Coelhob1873302014-08-08 17:12:07 +03001066 mvm->ps_disabled = false;
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +02001067 mvm->calibrating = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001068
1069 /* just in case one was running */
1070 ieee80211_remain_on_channel_expired(mvm->hw);
1071
1072 ieee80211_iterate_active_interfaces_atomic(
1073 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1074 iwl_mvm_cleanup_iterator, mvm);
1075
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001076 mvm->p2p_device_vif = NULL;
Eliad Peller37577fe2013-12-05 17:19:39 +02001077 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001078
1079 iwl_mvm_reset_phy_ctxts(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001080 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1081 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001082 memset(mvm->tfd_drained, 0, sizeof(mvm->tfd_drained));
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +03001083 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1084 memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
1085 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1086 memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
1087 memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk));
1088 memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001089
1090 ieee80211_wake_queues(mvm->hw);
1091
Eliad Peller228670b2014-08-10 17:00:15 +03001092 /* clear any stale d0i3 state */
1093 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1094
Johannes Berg8ca151b2013-01-24 14:25:36 +01001095 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03001096 mvm->rx_ba_sessions = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001097}
1098
Luciano Coelhoa0a092432014-09-04 12:29:15 +03001099int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001100{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001101 int ret;
1102
Luciano Coelhoa0a092432014-09-04 12:29:15 +03001103 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001104
1105 /* Clean up some internal and mac80211 state on restart */
1106 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1107 iwl_mvm_restart_cleanup(mvm);
1108
1109 ret = iwl_mvm_up(mvm);
Johannes Bergc47af222014-04-30 16:34:45 +02001110
1111 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1112 /* Something went wrong - we need to finish some cleanup
1113 * that normally iwl_mvm_mac_restart_complete() below
1114 * would do.
1115 */
1116 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1117 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1118 }
1119
Luciano Coelhoa0a092432014-09-04 12:29:15 +03001120 return ret;
1121}
1122
1123static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1124{
1125 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1126 int ret;
1127
Eliad Peller37948fc2014-12-11 10:48:18 +02001128 /* Some hw restart cleanups must not hold the mutex */
1129 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1130 /*
1131 * Make sure we are out of d0i3. This is needed
1132 * to make sure the reference accounting is correct
1133 * (and there is no stale d0i3_exit_work).
1134 */
1135 wait_event_timeout(mvm->d0i3_exit_waitq,
1136 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1137 &mvm->status),
1138 HZ);
1139 }
1140
Luciano Coelhoa0a092432014-09-04 12:29:15 +03001141 mutex_lock(&mvm->mutex);
1142 ret = __iwl_mvm_mac_start(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001143 mutex_unlock(&mvm->mutex);
1144
1145 return ret;
1146}
1147
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001148static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001149{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001150 int ret;
1151
1152 mutex_lock(&mvm->mutex);
1153
1154 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
Arik Nemtsovb2492502014-03-13 12:21:50 +02001155 iwl_mvm_d0i3_enable_tx(mvm, NULL);
Johannes Berg01662302014-06-06 15:18:45 +02001156 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001157 if (ret)
1158 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1159 ret);
1160
Eliad Peller7498cf42014-01-16 17:10:44 +02001161 /* allow transport/FW low power modes */
1162 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1163
Arik Nemtsovcbd2ae22014-09-14 19:13:54 +03001164 /*
1165 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1166 * of packets the FW sent out, so we must reconnect.
1167 */
1168 iwl_mvm_teardown_tdls_peers(mvm);
1169
Johannes Berg8ca151b2013-01-24 14:25:36 +01001170 mutex_unlock(&mvm->mutex);
1171}
1172
Eliad Peller088070a2014-10-20 18:42:58 +03001173static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1174{
1175 bool exit_now;
1176
1177 if (!iwl_mvm_is_d0i3_supported(mvm))
1178 return;
1179
1180 mutex_lock(&mvm->d0i3_suspend_mutex);
1181 __clear_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags);
1182 exit_now = __test_and_clear_bit(D0I3_PENDING_WAKEUP,
1183 &mvm->d0i3_suspend_flags);
1184 mutex_unlock(&mvm->d0i3_suspend_mutex);
1185
1186 if (exit_now) {
1187 IWL_DEBUG_RPM(mvm, "Run deferred d0i3 exit\n");
1188 _iwl_mvm_exit_d0i3(mvm);
1189 }
Eliad Peller67359432014-12-09 15:23:54 +02001190
1191 if (mvm->trans->d0i3_mode == IWL_D0I3_MODE_ON_SUSPEND)
1192 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
1193 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1194 &mvm->status),
1195 HZ))
1196 WARN_ONCE(1, "D0i3 exit on resume timed out\n");
Eliad Peller088070a2014-10-20 18:42:58 +03001197}
1198
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001199static void
1200iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1201 enum ieee80211_reconfig_type reconfig_type)
1202{
1203 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1204
1205 switch (reconfig_type) {
1206 case IEEE80211_RECONFIG_TYPE_RESTART:
1207 iwl_mvm_restart_complete(mvm);
1208 break;
1209 case IEEE80211_RECONFIG_TYPE_SUSPEND:
Eliad Peller088070a2014-10-20 18:42:58 +03001210 iwl_mvm_resume_complete(mvm);
Eliad Pellercf2c92d2014-11-04 11:43:54 +02001211 break;
1212 }
1213}
1214
Luciano Coelhoa0a092432014-09-04 12:29:15 +03001215void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001216{
Luciano Coelhoa0a092432014-09-04 12:29:15 +03001217 lockdep_assert_held(&mvm->mutex);
Eliad Peller7498cf42014-01-16 17:10:44 +02001218
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001219 /*
1220 * Disallow low power states when the FW is down by taking
1221 * the UCODE_DOWN ref. in case of ongoing hw restart the
1222 * ref is already taken, so don't take it again.
1223 */
1224 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1225 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
Eliad Peller7498cf42014-01-16 17:10:44 +02001226
Johannes Berg8ca151b2013-01-24 14:25:36 +01001227 /* async_handlers_wk is now blocked */
1228
1229 /*
1230 * The work item could be running or queued if the
1231 * ROC time event stops just as we get here.
1232 */
1233 cancel_work_sync(&mvm->roc_done_wk);
1234
1235 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001236
1237 iwl_mvm_async_handlers_purge(mvm);
1238 /* async_handlers_list is empty and will stay empty: HW is stopped */
1239
1240 /* the fw is stopped, the aux sta is dead: clean up driver state */
Johannes Berg712b24a2014-08-04 14:14:14 +02001241 iwl_mvm_del_aux_sta(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001242
Eliad Peller0a79a0c02014-12-04 10:27:20 +02001243 /*
1244 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1245 * won't be called in this case).
1246 */
1247 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1248
Luciano Coelhobc448862014-08-20 11:49:11 +03001249 mvm->ucode_loaded = false;
Luciano Coelhoa0a092432014-09-04 12:29:15 +03001250}
Luciano Coelhobc448862014-08-20 11:49:11 +03001251
Luciano Coelhoa0a092432014-09-04 12:29:15 +03001252static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1253{
1254 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1255
1256 flush_work(&mvm->d0i3_exit_work);
1257 flush_work(&mvm->async_handlers_wk);
Emmanuel Grumbach4bfa47f2014-09-11 16:19:43 +03001258 flush_work(&mvm->fw_error_dump_wk);
Luciano Coelhoa0a092432014-09-04 12:29:15 +03001259
1260 mutex_lock(&mvm->mutex);
1261 __iwl_mvm_mac_stop(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001262 mutex_unlock(&mvm->mutex);
1263
1264 /*
1265 * The worker might have been waiting for the mutex, let it run and
1266 * discover that its list is now empty.
1267 */
1268 cancel_work_sync(&mvm->async_handlers_wk);
1269}
1270
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001271static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1272{
1273 u16 i;
1274
1275 lockdep_assert_held(&mvm->mutex);
1276
1277 for (i = 0; i < NUM_PHY_CTX; i++)
1278 if (!mvm->phy_ctxts[i].ref)
1279 return &mvm->phy_ctxts[i];
1280
1281 IWL_ERR(mvm, "No available PHY context\n");
1282 return NULL;
1283}
1284
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +02001285static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1286 s8 tx_power)
1287{
1288 /* FW is in charge of regulatory enforcement */
1289 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
1290 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
1291 .pwr_restriction = cpu_to_le16(tx_power),
1292 };
1293
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001294 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +02001295 sizeof(reduce_txpwr_cmd),
1296 &reduce_txpwr_cmd);
1297}
1298
Johannes Berg8ca151b2013-01-24 14:25:36 +01001299static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1300 struct ieee80211_vif *vif)
1301{
1302 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1303 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1304 int ret;
1305
1306 /*
Gregory Greenmand40fc482014-06-25 14:08:50 +02001307 * make sure D0i3 exit is completed, otherwise a target access
1308 * during tx queue configuration could be done when still in
1309 * D0i3 state.
1310 */
1311 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1312 if (ret)
1313 return ret;
1314
1315 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001316 * Not much to do here. The stack will not allow interface
1317 * types or combinations that we didn't advertise, so we
1318 * don't really have to check the types.
1319 */
1320
1321 mutex_lock(&mvm->mutex);
1322
Eliad Pellere89044d2013-07-16 17:33:26 +03001323 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001324 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1325 if (ret)
1326 goto out_unlock;
1327
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001328 /* Counting number of interfaces is needed for legacy PM */
Ilan Peerea183d02013-07-23 14:41:53 +03001329 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1330 mvm->vif_count++;
Ilan Peerea183d02013-07-23 14:41:53 +03001331
1332 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001333 * The AP binding flow can be done only after the beacon
1334 * template is configured (which happens only in the mac80211
1335 * start_ap() flow), and adding the broadcast station can happen
1336 * only after the binding.
1337 * In addition, since modifying the MAC before adding a bcast
1338 * station is not allowed by the FW, delay the adding of MAC context to
1339 * the point where we can also add the bcast station.
1340 * In short: there's not much we can do at this point, other than
1341 * allocating resources :)
1342 */
Johannes Berg5023d962013-07-31 14:07:43 +02001343 if (vif->type == NL80211_IFTYPE_AP ||
1344 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg013290a2014-08-04 13:38:48 +02001345 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001346 if (ret) {
1347 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1348 goto out_release;
1349 }
1350
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +03001351 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001352 goto out_unlock;
1353 }
1354
Johannes Berg8ca151b2013-01-24 14:25:36 +01001355 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1356 if (ret)
1357 goto out_release;
1358
Arik Nemtsov999609f2014-05-15 17:31:51 +03001359 ret = iwl_mvm_power_update_mac(mvm);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001360 if (ret)
Luciano Coelhofd66fc12015-01-27 15:06:57 +02001361 goto out_remove_mac;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001362
Hila Gonen7df15b12012-12-12 11:16:19 +02001363 /* beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001364 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001365 if (ret)
1366 goto out_remove_mac;
1367
Hila Gonen7df15b12012-12-12 11:16:19 +02001368 if (!mvm->bf_allowed_vif &&
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +03001369 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001370 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001371 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1372 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +02001373 }
1374
Johannes Berg8ca151b2013-01-24 14:25:36 +01001375 /*
1376 * P2P_DEVICE interface does not have a channel context assigned to it,
1377 * so a dedicated PHY context is allocated to it and the corresponding
1378 * MAC context is bound to it at this stage.
1379 */
1380 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001381
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001382 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1383 if (!mvmvif->phy_ctxt) {
1384 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001385 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001386 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001387
Ilan Peer53a9d612013-04-28 11:55:08 +03001388 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001389 ret = iwl_mvm_binding_add_vif(mvm, vif);
1390 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +03001391 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001392
Johannes Berg013290a2014-08-04 13:38:48 +02001393 ret = iwl_mvm_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001394 if (ret)
1395 goto out_unbind;
1396
1397 /* Save a pointer to p2p device vif, so it can later be used to
1398 * update the p2p device MAC when a GO is started/stopped */
1399 mvm->p2p_device_vif = vif;
1400 }
1401
Johannes Berg63494372013-03-26 10:47:53 +01001402 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001403 goto out_unlock;
1404
1405 out_unbind:
1406 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +03001407 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001408 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001409 out_free_bf:
1410 if (mvm->bf_allowed_vif == mvmvif) {
1411 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001412 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1413 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001414 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001415 out_remove_mac:
1416 mvmvif->phy_ctxt = NULL;
1417 iwl_mvm_mac_ctxt_remove(mvm, vif);
1418 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001419 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1420 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001421
Johannes Berg8ca151b2013-01-24 14:25:36 +01001422 iwl_mvm_mac_ctxt_release(mvm, vif);
1423 out_unlock:
1424 mutex_unlock(&mvm->mutex);
1425
Gregory Greenmand40fc482014-06-25 14:08:50 +02001426 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1427
Johannes Berg8ca151b2013-01-24 14:25:36 +01001428 return ret;
1429}
1430
Johannes Berg38a12b52013-02-22 14:07:56 +01001431static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1432 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001433{
Arik Nemtsovd92b732e2014-09-21 19:00:42 +03001434 u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001435
1436 if (tfd_msk) {
1437 mutex_lock(&mvm->mutex);
1438 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
1439 mutex_unlock(&mvm->mutex);
1440 }
1441
1442 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1443 /*
1444 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1445 * We assume here that all the packets sent to the OFFCHANNEL
1446 * queue are sent in ROC session.
1447 */
1448 flush_work(&mvm->roc_done_wk);
1449 } else {
1450 /*
1451 * By now, all the AC queues are empty. The AGG queues are
1452 * empty too. We already got all the Tx responses for all the
1453 * packets in the queues. The drain work can have been
Emmanuel Grumbach0742a752013-06-10 14:10:33 +03001454 * triggered. Flush it.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001455 */
1456 flush_work(&mvm->sta_drained_wk);
1457 }
Johannes Berg38a12b52013-02-22 14:07:56 +01001458}
1459
1460static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1461 struct ieee80211_vif *vif)
1462{
1463 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1464 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1465
1466 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001467
1468 mutex_lock(&mvm->mutex);
1469
Hila Gonen7df15b12012-12-12 11:16:19 +02001470 if (mvm->bf_allowed_vif == mvmvif) {
1471 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001472 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1473 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +02001474 }
1475
Johannes Berg63494372013-03-26 10:47:53 +01001476 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1477
Johannes Berg8ca151b2013-01-24 14:25:36 +01001478 /*
1479 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +01001480 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001481 */
Johannes Berg5023d962013-07-31 14:07:43 +02001482 if (vif->type == NL80211_IFTYPE_AP ||
1483 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +03001484#ifdef CONFIG_NL80211_TESTMODE
1485 if (vif == mvm->noa_vif) {
1486 mvm->noa_vif = NULL;
1487 mvm->noa_duration = 0;
1488 }
1489#endif
Johannes Berg013290a2014-08-04 13:38:48 +02001490 iwl_mvm_dealloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001491 goto out_release;
1492 }
1493
1494 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1495 mvm->p2p_device_vif = NULL;
Johannes Berg013290a2014-08-04 13:38:48 +02001496 iwl_mvm_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001497 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001498 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001499 mvmvif->phy_ctxt = NULL;
1500 }
1501
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001502 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001503 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001504
Arik Nemtsov999609f2014-05-15 17:31:51 +03001505 iwl_mvm_power_update_mac(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001506 iwl_mvm_mac_ctxt_remove(mvm, vif);
1507
1508out_release:
1509 iwl_mvm_mac_ctxt_release(mvm, vif);
1510 mutex_unlock(&mvm->mutex);
1511}
1512
1513static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1514{
1515 return 0;
1516}
1517
Eliad Pellere59647e2013-11-28 14:08:50 +02001518struct iwl_mvm_mc_iter_data {
1519 struct iwl_mvm *mvm;
1520 int port_id;
1521};
1522
1523static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1524 struct ieee80211_vif *vif)
1525{
1526 struct iwl_mvm_mc_iter_data *data = _data;
1527 struct iwl_mvm *mvm = data->mvm;
1528 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1529 int ret, len;
1530
1531 /* if we don't have free ports, mcast frames will be dropped */
1532 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1533 return;
1534
1535 if (vif->type != NL80211_IFTYPE_STATION ||
1536 !vif->bss_conf.assoc)
1537 return;
1538
1539 cmd->port_id = data->port_id++;
1540 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1541 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1542
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001543 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
Eliad Pellere59647e2013-11-28 14:08:50 +02001544 if (ret)
1545 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1546}
1547
1548static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1549{
1550 struct iwl_mvm_mc_iter_data iter_data = {
1551 .mvm = mvm,
1552 };
1553
1554 lockdep_assert_held(&mvm->mutex);
1555
1556 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1557 return;
1558
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001559 ieee80211_iterate_active_interfaces_atomic(
Eliad Pellere59647e2013-11-28 14:08:50 +02001560 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1561 iwl_mvm_mc_iface_iterator, &iter_data);
1562}
1563
1564static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1565 struct netdev_hw_addr_list *mc_list)
1566{
1567 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1568 struct iwl_mcast_filter_cmd *cmd;
1569 struct netdev_hw_addr *addr;
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001570 int addr_count;
1571 bool pass_all;
Eliad Pellere59647e2013-11-28 14:08:50 +02001572 int len;
1573
Max Stepanovf3bd58f2014-08-04 13:55:01 +03001574 addr_count = netdev_hw_addr_list_count(mc_list);
1575 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1576 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1577 if (pass_all)
Eliad Pellere59647e2013-11-28 14:08:50 +02001578 addr_count = 0;
Eliad Pellere59647e2013-11-28 14:08:50 +02001579
1580 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1581 cmd = kzalloc(len, GFP_ATOMIC);
1582 if (!cmd)
1583 return 0;
1584
1585 if (pass_all) {
1586 cmd->pass_all = 1;
1587 return (u64)(unsigned long)cmd;
1588 }
1589
1590 netdev_hw_addr_list_for_each(addr, mc_list) {
1591 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1592 cmd->count, addr->addr);
1593 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1594 addr->addr, ETH_ALEN);
1595 cmd->count++;
1596 }
1597
1598 return (u64)(unsigned long)cmd;
1599}
1600
Johannes Berg8ca151b2013-01-24 14:25:36 +01001601static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1602 unsigned int changed_flags,
1603 unsigned int *total_flags,
1604 u64 multicast)
1605{
Eliad Pellere59647e2013-11-28 14:08:50 +02001606 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1607 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1608
1609 mutex_lock(&mvm->mutex);
1610
1611 /* replace previous configuration */
1612 kfree(mvm->mcast_filter_cmd);
1613 mvm->mcast_filter_cmd = cmd;
1614
1615 if (!cmd)
1616 goto out;
1617
1618 iwl_mvm_recalc_multicast(mvm);
1619out:
1620 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001621 *total_flags = 0;
1622}
1623
Eliad Pellerc87163b2014-01-08 10:11:11 +02001624#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1625struct iwl_bcast_iter_data {
1626 struct iwl_mvm *mvm;
1627 struct iwl_bcast_filter_cmd *cmd;
1628 u8 current_filter;
1629};
1630
1631static void
1632iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1633 const struct iwl_fw_bcast_filter *in_filter,
1634 struct iwl_fw_bcast_filter *out_filter)
1635{
1636 struct iwl_fw_bcast_filter_attr *attr;
1637 int i;
1638
1639 memcpy(out_filter, in_filter, sizeof(*out_filter));
1640
1641 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1642 attr = &out_filter->attrs[i];
1643
1644 if (!attr->mask)
1645 break;
1646
Eliad Peller2ee8f022014-01-13 19:07:09 +02001647 switch (attr->reserved1) {
1648 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1649 if (vif->bss_conf.arp_addr_cnt != 1) {
1650 attr->mask = 0;
1651 continue;
1652 }
1653
1654 attr->val = vif->bss_conf.arp_addr_list[0];
1655 break;
1656 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1657 attr->val = *(__be32 *)&vif->addr[2];
1658 break;
1659 default:
1660 break;
1661 }
1662 attr->reserved1 = 0;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001663 out_filter->num_attrs++;
1664 }
1665}
1666
1667static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1668 struct ieee80211_vif *vif)
1669{
1670 struct iwl_bcast_iter_data *data = _data;
1671 struct iwl_mvm *mvm = data->mvm;
1672 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1673 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1674 struct iwl_fw_bcast_mac *bcast_mac;
1675 int i;
1676
1677 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1678 return;
1679
1680 bcast_mac = &cmd->macs[mvmvif->id];
1681
Ilan Peere48393e2014-05-22 11:19:02 +03001682 /*
1683 * enable filtering only for associated stations, but not for P2P
1684 * Clients
1685 */
1686 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1687 !vif->bss_conf.assoc)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001688 return;
1689
1690 bcast_mac->default_discard = 1;
1691
1692 /* copy all configured filters */
1693 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1694 /*
1695 * Make sure we don't exceed our filters limit.
1696 * if there is still a valid filter to be configured,
1697 * be on the safe side and just allow bcast for this mac.
1698 */
1699 if (WARN_ON_ONCE(data->current_filter >=
1700 ARRAY_SIZE(cmd->filters))) {
1701 bcast_mac->default_discard = 0;
1702 bcast_mac->attached_filters = 0;
1703 break;
1704 }
1705
1706 iwl_mvm_set_bcast_filter(vif,
1707 &mvm->bcast_filters[i],
1708 &cmd->filters[data->current_filter]);
1709
1710 /* skip current filter if it contains no attributes */
1711 if (!cmd->filters[data->current_filter].num_attrs)
1712 continue;
1713
1714 /* attach the filter to current mac */
1715 bcast_mac->attached_filters |=
1716 cpu_to_le16(BIT(data->current_filter));
1717
1718 data->current_filter++;
1719 }
1720}
1721
Eliad Pellerde06a592014-01-08 10:11:12 +02001722bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1723 struct iwl_bcast_filter_cmd *cmd)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001724{
Eliad Pellerc87163b2014-01-08 10:11:11 +02001725 struct iwl_bcast_iter_data iter_data = {
1726 .mvm = mvm,
Eliad Pellerde06a592014-01-08 10:11:12 +02001727 .cmd = cmd,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001728 };
1729
Max Stepanov3b8983b2014-10-15 11:27:16 +03001730 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1731 return false;
1732
Eliad Pellerde06a592014-01-08 10:11:12 +02001733 memset(cmd, 0, sizeof(*cmd));
1734 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1735 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1736
1737#ifdef CONFIG_IWLWIFI_DEBUGFS
1738 /* use debugfs filters/macs if override is configured */
1739 if (mvm->dbgfs_bcast_filtering.override) {
1740 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1741 sizeof(cmd->filters));
1742 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1743 sizeof(cmd->macs));
1744 return true;
1745 }
1746#endif
Eliad Pellerc87163b2014-01-08 10:11:11 +02001747
1748 /* if no filters are configured, do nothing */
1749 if (!mvm->bcast_filters)
Eliad Pellerde06a592014-01-08 10:11:12 +02001750 return false;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001751
1752 /* configure and attach these filters for each associated sta vif */
1753 ieee80211_iterate_active_interfaces(
1754 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1755 iwl_mvm_bcast_filter_iterator, &iter_data);
1756
Eliad Pellerde06a592014-01-08 10:11:12 +02001757 return true;
1758}
1759static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1760 struct ieee80211_vif *vif)
1761{
1762 struct iwl_bcast_filter_cmd cmd;
1763
1764 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1765 return 0;
1766
1767 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1768 return 0;
1769
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001770 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001771 sizeof(cmd), &cmd);
1772}
1773#else
1774static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1775 struct ieee80211_vif *vif)
1776{
1777 return 0;
1778}
1779#endif
1780
Johannes Berg8ca151b2013-01-24 14:25:36 +01001781static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1782 struct ieee80211_vif *vif,
1783 struct ieee80211_bss_conf *bss_conf,
1784 u32 changes)
1785{
1786 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1787 int ret;
1788
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001789 /*
1790 * Re-calculate the tsf id, as the master-slave relations depend on the
1791 * beacon interval, which was not known when the station interface was
1792 * added.
1793 */
1794 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1795 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1796
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001797 /*
1798 * If we're not associated yet, take the (new) BSSID before associating
1799 * so the firmware knows. If we're already associated, then use the old
1800 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1801 * branch for disassociation below.
1802 */
1803 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1804 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1805
1806 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001807 if (ret)
1808 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1809
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001810 /* after sending it once, adopt mac80211 data */
1811 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1812 mvmvif->associated = bss_conf->assoc;
1813
Johannes Berg8ca151b2013-01-24 14:25:36 +01001814 if (changes & BSS_CHANGED_ASSOC) {
1815 if (bss_conf->assoc) {
1816 /* add quota for this interface */
Johannes Berg01662302014-06-06 15:18:45 +02001817 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001818 if (ret) {
1819 IWL_ERR(mvm, "failed to update quotas\n");
1820 return;
1821 }
Johannes Berg016d27e2013-05-03 11:16:15 +02001822
1823 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1824 &mvm->status)) {
1825 /*
1826 * If we're restarting then the firmware will
1827 * obviously have lost synchronisation with
1828 * the AP. It will attempt to synchronise by
1829 * itself, but we can make it more reliable by
1830 * scheduling a session protection time event.
1831 *
1832 * The firmware needs to receive a beacon to
1833 * catch up with synchronisation, use 110% of
1834 * the beacon interval.
1835 *
1836 * Set a large maximum delay to allow for more
1837 * than a single interface.
1838 */
1839 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1840 iwl_mvm_protect_session(mvm, vif, dur, dur,
Liad Kaufmand20d37b2014-07-06 17:14:39 +03001841 5 * dur, false);
Johannes Berg016d27e2013-05-03 11:16:15 +02001842 }
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001843
1844 iwl_mvm_sf_update(mvm, vif, false);
Alexander Bondar175a70b2013-04-14 20:59:37 +03001845 iwl_mvm_power_vif_assoc(mvm, vif);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001846 if (vif->p2p) {
Eliad Peller29a90a42013-11-05 14:06:29 +02001847 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001848 iwl_mvm_update_smps(mvm, vif,
1849 IWL_MVM_SMPS_REQ_PROT,
1850 IEEE80211_SMPS_DYNAMIC);
1851 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001852 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001853 /*
1854 * If update fails - SF might be running in associated
1855 * mode while disassociated - which is forbidden.
1856 */
1857 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1858 "Failed to update SF upon disassociation\n");
1859
Johannes Berg8ca151b2013-01-24 14:25:36 +01001860 /* remove AP station now that the MAC is unassoc */
1861 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1862 if (ret)
1863 IWL_ERR(mvm, "failed to remove AP station\n");
Eliad Peller37577fe2013-12-05 17:19:39 +02001864
1865 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1866 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001867 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1868 /* remove quota for this interface */
Johannes Berg01662302014-06-06 15:18:45 +02001869 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001870 if (ret)
1871 IWL_ERR(mvm, "failed to update quotas\n");
Eliad Peller29a90a42013-11-05 14:06:29 +02001872
1873 if (vif->p2p)
1874 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001875
1876 /* this will take the cleared BSSID from bss_conf */
1877 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1878 if (ret)
1879 IWL_ERR(mvm,
1880 "failed to update MAC %pM (clear after unassoc)\n",
1881 vif->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001882 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001883
Eliad Pellere59647e2013-11-28 14:08:50 +02001884 iwl_mvm_recalc_multicast(mvm);
Eliad Pellerc87163b2014-01-08 10:11:11 +02001885 iwl_mvm_configure_bcast_filter(mvm, vif);
Eliad Pellere59647e2013-11-28 14:08:50 +02001886
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001887 /* reset rssi values */
1888 mvmvif->bf_data.ave_beacon_signal = 0;
1889
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001890 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachf94045e2014-01-06 13:38:55 +02001891 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1892 IEEE80211_SMPS_AUTOMATIC);
Alexander Bondar989c6502013-05-16 17:34:17 +03001893 } else if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +01001894 /*
1895 * We received a beacon _after_ association so
1896 * remove the session protection.
1897 */
1898 iwl_mvm_remove_time_event(mvm, mvmvif,
1899 &mvmvif->time_event_data);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001900 }
Eran Hararycc87d322014-07-15 14:04:23 +03001901
1902 if (changes & BSS_CHANGED_BEACON_INFO) {
1903 iwl_mvm_sf_update(mvm, vif, false);
1904 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
1905 }
1906
Johannes Berg1bc10d32014-08-26 14:25:46 +02001907 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS)) {
1908 ret = iwl_mvm_power_update_mac(mvm);
1909 if (ret)
1910 IWL_ERR(mvm, "failed to update power mode\n");
1911 }
1912
Matti Gottlieb88f2fd72013-07-09 15:25:46 +03001913 if (changes & BSS_CHANGED_TXPOWER) {
1914 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1915 bss_conf->txpower);
1916 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1917 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001918
1919 if (changes & BSS_CHANGED_CQM) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02001920 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001921 /* reset cqm events tracking */
1922 mvmvif->bf_data.last_cqm_event = 0;
Avri Altmanfa7b2e72014-05-20 08:03:24 +03001923 if (mvmvif->bf_data.bf_enabled) {
1924 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1925 if (ret)
1926 IWL_ERR(mvm,
1927 "failed to update CQM thresholds\n");
1928 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001929 }
Eliad Peller2ee8f022014-01-13 19:07:09 +02001930
1931 if (changes & BSS_CHANGED_ARP_FILTER) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02001932 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
Eliad Peller2ee8f022014-01-13 19:07:09 +02001933 iwl_mvm_configure_bcast_filter(mvm, vif);
1934 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001935}
1936
Johannes Berg5023d962013-07-31 14:07:43 +02001937static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1938 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001939{
1940 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1941 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1942 int ret;
1943
Eliad Peller576eeee2014-07-01 18:38:38 +03001944 /*
1945 * iwl_mvm_mac_ctxt_add() might read directly from the device
1946 * (the system time), so make sure it is available.
1947 */
1948 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
1949 if (ret)
1950 return ret;
1951
Johannes Berg8ca151b2013-01-24 14:25:36 +01001952 mutex_lock(&mvm->mutex);
1953
1954 /* Send the beacon template */
1955 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1956 if (ret)
1957 goto out_unlock;
1958
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001959 /*
1960 * Re-calculate the tsf id, as the master-slave relations depend on the
1961 * beacon interval, which was not known when the AP interface was added.
1962 */
1963 if (vif->type == NL80211_IFTYPE_AP)
1964 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1965
Johannes Berg8ca151b2013-01-24 14:25:36 +01001966 /* Add the mac context */
1967 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1968 if (ret)
1969 goto out_unlock;
1970
1971 /* Perform the binding */
1972 ret = iwl_mvm_binding_add_vif(mvm, vif);
1973 if (ret)
1974 goto out_remove;
1975
Johannes Berg8ca151b2013-01-24 14:25:36 +01001976 /* Send the bcast station. At this stage the TBTT and DTIM time events
1977 * are added and applied to the scheduler */
Johannes Berg013290a2014-08-04 13:38:48 +02001978 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001979 if (ret)
1980 goto out_unbind;
1981
Ilan Peer5691e212013-12-31 21:05:50 +02001982 /* must be set before quota calculations */
1983 mvmvif->ap_ibss_active = true;
1984
Ilan Peera11e1442013-12-31 21:19:55 +02001985 /* power updated needs to be done before quotas */
Arik Nemtsov999609f2014-05-15 17:31:51 +03001986 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02001987
Johannes Berg01662302014-06-06 15:18:45 +02001988 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001989 if (ret)
Ilan Peera11e1442013-12-31 21:19:55 +02001990 goto out_quota_failed;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001991
Johannes Berg5023d962013-07-31 14:07:43 +02001992 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001993 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02001994 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001995
Eliad Peller29a90a42013-11-05 14:06:29 +02001996 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1997
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001998 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001999
Arik Nemtsovf6972672014-06-15 16:03:55 +03002000 /* we don't support TDLS during DCM */
2001 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2002 iwl_mvm_teardown_tdls_peers(mvm);
2003
Johannes Berg8ca151b2013-01-24 14:25:36 +01002004 mutex_unlock(&mvm->mutex);
2005 return 0;
2006
Ilan Peera11e1442013-12-31 21:19:55 +02002007out_quota_failed:
Arik Nemtsov999609f2014-05-15 17:31:51 +03002008 iwl_mvm_power_update_mac(mvm);
Ilan Peer5691e212013-12-31 21:05:50 +02002009 mvmvif->ap_ibss_active = false;
Johannes Berg013290a2014-08-04 13:38:48 +02002010 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002011out_unbind:
2012 iwl_mvm_binding_remove_vif(mvm, vif);
2013out_remove:
2014 iwl_mvm_mac_ctxt_remove(mvm, vif);
2015out_unlock:
2016 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002017 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002018 return ret;
2019}
2020
Johannes Berg5023d962013-07-31 14:07:43 +02002021static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2022 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002023{
2024 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2025 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2026
Johannes Berg38a12b52013-02-22 14:07:56 +01002027 iwl_mvm_prepare_mac_removal(mvm, vif);
2028
Johannes Berg8ca151b2013-01-24 14:25:36 +01002029 mutex_lock(&mvm->mutex);
2030
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002031 /* Handle AP stop while in CSA */
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03002032 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2033 iwl_mvm_remove_time_event(mvm, mvmvif,
2034 &mvmvif->time_event_data);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002035 RCU_INIT_POINTER(mvm->csa_vif, NULL);
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03002036 }
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002037
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03002038 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2039 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2040 mvm->csa_tx_block_bcn_timeout = 0;
2041 }
2042
Johannes Berg5023d962013-07-31 14:07:43 +02002043 mvmvif->ap_ibss_active = false;
David Spinadel1c87bba2014-02-27 16:41:52 +02002044 mvm->ap_last_beacon_gp2 = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002045
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002046 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03002047
Eliad Peller29a90a42013-11-05 14:06:29 +02002048 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2049
Johannes Berg5023d962013-07-31 14:07:43 +02002050 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002051 if (vif->p2p && mvm->p2p_device_vif)
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002052 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002053
Johannes Berg01662302014-06-06 15:18:45 +02002054 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg013290a2014-08-04 13:38:48 +02002055 iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002056 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02002057
Arik Nemtsov999609f2014-05-15 17:31:51 +03002058 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02002059
Johannes Berg8ca151b2013-01-24 14:25:36 +01002060 iwl_mvm_mac_ctxt_remove(mvm, vif);
2061
2062 mutex_unlock(&mvm->mutex);
2063}
2064
Johannes Berg5023d962013-07-31 14:07:43 +02002065static void
2066iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2067 struct ieee80211_vif *vif,
2068 struct ieee80211_bss_conf *bss_conf,
2069 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002070{
Ilan Peerbe2056f2013-12-04 16:47:14 +02002071 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman8a5e3662013-11-12 19:16:03 +02002072
Ilan Peerbe2056f2013-12-04 16:47:14 +02002073 /* Changes will be applied when the AP/IBSS is started */
2074 if (!mvmvif->ap_ibss_active)
2075 return;
2076
Johannes Berg863230da2013-12-04 17:08:40 +01002077 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
Johannes Bergf7d8b702014-09-09 15:49:19 +02002078 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002079 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
Johannes Berg863230da2013-12-04 17:08:40 +01002080 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
Avri Altman8a5e3662013-11-12 19:16:03 +02002081
Johannes Berg8ca151b2013-01-24 14:25:36 +01002082 /* Need to send a new beacon template to the FW */
Johannes Berg863230da2013-12-04 17:08:40 +01002083 if (changes & BSS_CHANGED_BEACON &&
2084 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2085 IWL_WARN(mvm, "Failed updating beacon data\n");
Haim Dreyfuss79b7a692014-09-14 12:40:00 +03002086
2087 if (changes & BSS_CHANGED_TXPOWER) {
2088 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2089 bss_conf->txpower);
2090 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2091 }
2092
Johannes Berg8ca151b2013-01-24 14:25:36 +01002093}
2094
2095static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2096 struct ieee80211_vif *vif,
2097 struct ieee80211_bss_conf *bss_conf,
2098 u32 changes)
2099{
2100 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2101
Eliad Peller576eeee2014-07-01 18:38:38 +03002102 /*
2103 * iwl_mvm_bss_info_changed_station() might call
2104 * iwl_mvm_protect_session(), which reads directly from
2105 * the device (the system time), so make sure it is available.
2106 */
2107 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2108 return;
2109
Johannes Berg8ca151b2013-01-24 14:25:36 +01002110 mutex_lock(&mvm->mutex);
2111
David Spinadel723f02e2014-04-27 09:54:54 +03002112 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
David Spinadelfb98be52014-05-04 12:51:10 +03002113 iwl_mvm_scan_offload_stop(mvm, true);
David Spinadel723f02e2014-04-27 09:54:54 +03002114
Johannes Berg8ca151b2013-01-24 14:25:36 +01002115 switch (vif->type) {
2116 case NL80211_IFTYPE_STATION:
2117 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2118 break;
2119 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02002120 case NL80211_IFTYPE_ADHOC:
2121 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002122 break;
2123 default:
2124 /* shouldn't happen */
2125 WARN_ON_ONCE(1);
2126 }
2127
2128 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002129 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002130}
2131
Eliad Peller4660dfb2014-06-22 18:15:59 +03002132static int iwl_mvm_cancel_scan_wait_notif(struct iwl_mvm *mvm,
2133 enum iwl_scan_status scan_type)
2134{
2135 int ret;
2136 bool wait_for_handlers = false;
2137
2138 mutex_lock(&mvm->mutex);
2139
2140 if (mvm->scan_status != scan_type) {
2141 ret = 0;
2142 /* make sure there are no pending notifications */
2143 wait_for_handlers = true;
2144 goto out;
2145 }
2146
2147 switch (scan_type) {
2148 case IWL_MVM_SCAN_SCHED:
2149 ret = iwl_mvm_scan_offload_stop(mvm, true);
2150 break;
2151 case IWL_MVM_SCAN_OS:
2152 ret = iwl_mvm_cancel_scan(mvm);
2153 break;
2154 case IWL_MVM_SCAN_NONE:
2155 default:
2156 WARN_ON_ONCE(1);
2157 ret = -EINVAL;
2158 break;
2159 }
2160 if (ret)
2161 goto out;
2162
2163 wait_for_handlers = true;
2164out:
2165 mutex_unlock(&mvm->mutex);
2166
2167 /* make sure we consume the completion notification */
2168 if (wait_for_handlers)
2169 iwl_mvm_wait_for_async_handlers(mvm);
2170
2171 return ret;
2172}
Johannes Berg8ca151b2013-01-24 14:25:36 +01002173static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2174 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02002175 struct ieee80211_scan_request *hw_req)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002176{
2177 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
David Spinadelc56ef672014-02-05 15:21:13 +02002178 struct cfg80211_scan_request *req = &hw_req->req;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002179 int ret;
2180
David Spinadel762533b2014-06-05 11:20:43 +03002181 if (req->n_channels == 0 ||
2182 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002183 return -EINVAL;
2184
David Spinadeld2496222014-05-20 12:46:37 +03002185 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2186 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_SCHED);
2187 if (ret)
2188 return ret;
2189 }
Eliad Peller4660dfb2014-06-22 18:15:59 +03002190
Johannes Berg8ca151b2013-01-24 14:25:36 +01002191 mutex_lock(&mvm->mutex);
2192
Eliad Peller4660dfb2014-06-22 18:15:59 +03002193 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002194 ret = -EBUSY;
Arik Nemtsov519e2022013-10-17 17:51:35 +03002195 goto out;
2196 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002197
Arik Nemtsov519e2022013-10-17 17:51:35 +03002198 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
2199
David Spinadelb975e552014-11-17 12:30:05 +02002200 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
David Spinadeld2496222014-05-20 12:46:37 +03002201 ret = iwl_mvm_scan_umac(mvm, vif, hw_req);
David Spinadelb975e552014-11-17 12:30:05 +02002202 else if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
2203 ret = iwl_mvm_unified_scan_lmac(mvm, vif, hw_req);
David Spinadelfb98be52014-05-04 12:51:10 +03002204 else
2205 ret = iwl_mvm_scan_request(mvm, vif, req);
2206
Arik Nemtsov519e2022013-10-17 17:51:35 +03002207 if (ret)
2208 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
2209out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002210 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002211 return ret;
2212}
2213
2214static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2215 struct ieee80211_vif *vif)
2216{
2217 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2218
2219 mutex_lock(&mvm->mutex);
2220
Luciano Coelhoe7d3aba2015-02-06 10:19:05 +02002221 /* Due to a race condition, it's possible that mac80211 asks
2222 * us to stop a hw_scan when it's already stopped. This can
2223 * happen, for instance, if we stopped the scan ourselves,
2224 * called ieee80211_scan_completed() and the userspace called
2225 * cancel scan scan before ieee80211_scan_work() could run.
2226 * To handle that, simply return if the scan is not running.
2227 */
2228 /* FIXME: for now, we ignore this race for UMAC scans, since
2229 * they don't set the scan_status.
2230 */
2231 if ((mvm->scan_status == IWL_MVM_SCAN_OS) ||
2232 (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2233 iwl_mvm_cancel_scan(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002234
2235 mutex_unlock(&mvm->mutex);
2236}
2237
2238static void
2239iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
Johannes Berg3e56ead2013-02-15 22:23:18 +01002240 struct ieee80211_sta *sta, u16 tids,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002241 int num_frames,
2242 enum ieee80211_frame_release_type reason,
2243 bool more_data)
2244{
2245 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002246
Johannes Berg3e56ead2013-02-15 22:23:18 +01002247 /* Called when we need to transmit (a) frame(s) from mac80211 */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002248
Johannes Berg3e56ead2013-02-15 22:23:18 +01002249 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2250 tids, more_data, false);
2251}
2252
2253static void
2254iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2255 struct ieee80211_sta *sta, u16 tids,
2256 int num_frames,
2257 enum ieee80211_frame_release_type reason,
2258 bool more_data)
2259{
2260 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2261
2262 /* Called when we need to transmit (a) frame(s) from agg queue */
2263
2264 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2265 tids, more_data, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002266}
2267
2268static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2269 struct ieee80211_vif *vif,
2270 enum sta_notify_cmd cmd,
2271 struct ieee80211_sta *sta)
2272{
2273 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01002274 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg3e56ead2013-02-15 22:23:18 +01002275 int tid;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002276
2277 switch (cmd) {
2278 case STA_NOTIFY_SLEEP:
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03002279 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002280 ieee80211_sta_block_awake(hw, sta, true);
Johannes Berg3e56ead2013-02-15 22:23:18 +01002281 spin_lock_bh(&mvmsta->lock);
2282 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2283 struct iwl_mvm_tid_data *tid_data;
2284
2285 tid_data = &mvmsta->tid_data[tid];
2286 if (tid_data->state != IWL_AGG_ON &&
2287 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
2288 continue;
2289 if (iwl_mvm_tid_queued(tid_data) == 0)
2290 continue;
2291 ieee80211_sta_set_buffered(sta, tid, true);
2292 }
2293 spin_unlock_bh(&mvmsta->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002294 /*
2295 * The fw updates the STA to be asleep. Tx packets on the Tx
2296 * queues to this station will not be transmitted. The fw will
2297 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2298 */
2299 break;
2300 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02002301 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01002302 break;
Johannes Berg9cc40712013-02-15 22:47:48 +01002303 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002304 break;
2305 default:
2306 break;
2307 }
2308}
2309
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002310static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2311 struct ieee80211_vif *vif,
2312 struct ieee80211_sta *sta)
2313{
2314 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01002315 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002316
2317 /*
2318 * This is called before mac80211 does RCU synchronisation,
2319 * so here we already invalidate our internal RCU-protected
2320 * station pointer. The rest of the code will thus no longer
2321 * be able to find the station this way, and we don't rely
2322 * on further RCU synchronisation after the sta_state()
2323 * callback deleted the station.
2324 */
2325 mutex_lock(&mvm->mutex);
2326 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2327 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2328 ERR_PTR(-ENOENT));
2329 mutex_unlock(&mvm->mutex);
2330}
2331
Johannes Bergbd1ba662014-11-13 20:53:45 +01002332static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2333 const u8 *bssid)
2334{
2335 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2336 return;
2337
2338 if (iwlwifi_mod_params.uapsd_disable) {
2339 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2340 return;
2341 }
2342
2343 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2344}
2345
Johannes Berg8ca151b2013-01-24 14:25:36 +01002346static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2347 struct ieee80211_vif *vif,
2348 struct ieee80211_sta *sta,
2349 enum ieee80211_sta_state old_state,
2350 enum ieee80211_sta_state new_state)
2351{
2352 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2353 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2354 int ret;
2355
2356 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2357 sta->addr, old_state, new_state);
2358
2359 /* this would be a mac80211 bug ... but don't crash */
2360 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2361 return -EINVAL;
2362
2363 /* if a STA is being removed, reuse its ID */
2364 flush_work(&mvm->sta_drained_wk);
2365
2366 mutex_lock(&mvm->mutex);
2367 if (old_state == IEEE80211_STA_NOTEXIST &&
2368 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02002369 /*
2370 * Firmware bug - it'll crash if the beacon interval is less
2371 * than 16. We can't avoid connecting at all, so refuse the
2372 * station state change, this will cause mac80211 to abandon
2373 * attempts to connect to this AP, and eventually wpa_s will
2374 * blacklist the AP...
2375 */
2376 if (vif->type == NL80211_IFTYPE_STATION &&
2377 vif->bss_conf.beacon_int < 16) {
2378 IWL_ERR(mvm,
2379 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2380 sta->addr, vif->bss_conf.beacon_int);
2381 ret = -EINVAL;
2382 goto out_unlock;
2383 }
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002384
2385 if (sta->tdls &&
2386 (vif->p2p ||
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002387 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2388 IWL_MVM_TDLS_STA_COUNT ||
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002389 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2390 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2391 ret = -EBUSY;
2392 goto out_unlock;
2393 }
2394
Johannes Berg8ca151b2013-01-24 14:25:36 +01002395 ret = iwl_mvm_add_sta(mvm, vif, sta);
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002396 if (sta->tdls && ret == 0)
2397 iwl_mvm_recalc_tdls_state(mvm, vif, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002398 } else if (old_state == IEEE80211_STA_NONE &&
2399 new_state == IEEE80211_STA_AUTH) {
Haim Dreyfusse820c2d2014-04-06 11:19:09 +03002400 /*
2401 * EBS may be disabled due to previous failures reported by FW.
2402 * Reset EBS status here assuming environment has been changed.
2403 */
2404 mvm->last_ebs_successful = true;
Johannes Bergbd1ba662014-11-13 20:53:45 +01002405 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002406 ret = 0;
2407 } else if (old_state == IEEE80211_STA_AUTH &&
2408 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01002409 ret = iwl_mvm_update_sta(mvm, vif, sta);
2410 if (ret == 0)
2411 iwl_mvm_rs_rate_init(mvm, sta,
Eyal Shapirab87c2172013-11-09 23:37:55 +02002412 mvmvif->phy_ctxt->channel->band,
2413 true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002414 } else if (old_state == IEEE80211_STA_ASSOC &&
2415 new_state == IEEE80211_STA_AUTHORIZED) {
Arik Nemtsovf59e0e3c2014-06-10 19:56:27 +03002416
2417 /* we don't support TDLS during DCM */
2418 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2419 iwl_mvm_teardown_tdls_peers(mvm);
2420
Hila Gonen7df15b12012-12-12 11:16:19 +02002421 /* enable beacon filtering */
Avri Altmanfa7b2e72014-05-20 08:03:24 +03002422 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002423 ret = 0;
2424 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2425 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02002426 /* disable beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002427 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002428 ret = 0;
2429 } else if (old_state == IEEE80211_STA_ASSOC &&
2430 new_state == IEEE80211_STA_AUTH) {
2431 ret = 0;
2432 } else if (old_state == IEEE80211_STA_AUTH &&
2433 new_state == IEEE80211_STA_NONE) {
2434 ret = 0;
2435 } else if (old_state == IEEE80211_STA_NONE &&
2436 new_state == IEEE80211_STA_NOTEXIST) {
2437 ret = iwl_mvm_rm_sta(mvm, vif, sta);
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002438 if (sta->tdls)
2439 iwl_mvm_recalc_tdls_state(mvm, vif, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002440 } else {
2441 ret = -EIO;
2442 }
Johannes Berg48bc1302013-07-04 15:55:29 +02002443 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002444 mutex_unlock(&mvm->mutex);
2445
Liad Kaufman9c126cd2014-10-06 19:08:56 +02002446 if (sta->tdls && ret == 0) {
2447 if (old_state == IEEE80211_STA_NOTEXIST &&
2448 new_state == IEEE80211_STA_NONE)
2449 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2450 else if (old_state == IEEE80211_STA_NONE &&
2451 new_state == IEEE80211_STA_NOTEXIST)
2452 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2453 }
2454
Johannes Berg8ca151b2013-01-24 14:25:36 +01002455 return ret;
2456}
2457
2458static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2459{
2460 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2461
2462 mvm->rts_threshold = value;
2463
2464 return 0;
2465}
2466
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002467static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2468 struct ieee80211_vif *vif,
2469 struct ieee80211_sta *sta, u32 changed)
2470{
2471 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2472
2473 if (vif->type == NL80211_IFTYPE_STATION &&
2474 changed & IEEE80211_RC_NSS_CHANGED)
2475 iwl_mvm_sf_update(mvm, vif, false);
2476}
2477
Johannes Berg8ca151b2013-01-24 14:25:36 +01002478static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2479 struct ieee80211_vif *vif, u16 ac,
2480 const struct ieee80211_tx_queue_params *params)
2481{
2482 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2483 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2484
2485 mvmvif->queue_params[ac] = *params;
2486
2487 /*
2488 * No need to update right away, we'll get BSS_CHANGED_QOS
2489 * The exception is P2P_DEVICE interface which needs immediate update.
2490 */
2491 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2492 int ret;
2493
2494 mutex_lock(&mvm->mutex);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02002495 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002496 mutex_unlock(&mvm->mutex);
2497 return ret;
2498 }
2499 return 0;
2500}
2501
2502static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2503 struct ieee80211_vif *vif)
2504{
2505 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2506 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
2507 200 + vif->bss_conf.beacon_int);
2508 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
2509 100 + vif->bss_conf.beacon_int);
2510
2511 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2512 return;
2513
Eliad Peller576eeee2014-07-01 18:38:38 +03002514 /*
2515 * iwl_mvm_protect_session() reads directly from the device
2516 * (the system time), so make sure it is available.
2517 */
2518 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2519 return;
2520
Johannes Berg8ca151b2013-01-24 14:25:36 +01002521 mutex_lock(&mvm->mutex);
2522 /* Try really hard to protect the session and hear a beacon */
Liad Kaufmand20d37b2014-07-06 17:14:39 +03002523 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002524 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002525
2526 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002527}
2528
David Spinadel35a000b2013-08-28 09:29:43 +03002529static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2530 struct ieee80211_vif *vif,
2531 struct cfg80211_sched_scan_request *req,
David Spinadel633e2712014-02-06 16:15:23 +02002532 struct ieee80211_scan_ies *ies)
David Spinadel35a000b2013-08-28 09:29:43 +03002533{
2534 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2535 int ret;
2536
David Spinadeld2496222014-05-20 12:46:37 +03002537 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2538 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_OS);
2539 if (ret)
2540 return ret;
2541 }
Eliad Peller4660dfb2014-06-22 18:15:59 +03002542
David Spinadel35a000b2013-08-28 09:29:43 +03002543 mutex_lock(&mvm->mutex);
2544
Alexander Bondar59ecb122014-07-30 17:40:28 +03002545 /* Newest FW fixes sched scan while connected on another interface */
2546 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) {
2547 if (!vif->bss_conf.idle) {
2548 ret = -EBUSY;
2549 goto out;
2550 }
2551 } else if (!iwl_mvm_is_idle(mvm)) {
David Spinadelbd5e4742014-04-24 13:15:29 +03002552 ret = -EBUSY;
2553 goto out;
2554 }
2555
Eliad Peller4660dfb2014-06-22 18:15:59 +03002556 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
David Spinadel35a000b2013-08-28 09:29:43 +03002557 ret = -EBUSY;
2558 goto out;
2559 }
2560
Luciano Coelhob141c232014-10-01 13:22:40 +03002561 ret = iwl_mvm_scan_offload_start(mvm, vif, req, ies);
David Spinadel35a000b2013-08-28 09:29:43 +03002562 if (ret)
Luciano Coelhob141c232014-10-01 13:22:40 +03002563 mvm->scan_status = IWL_MVM_SCAN_NONE;
David Spinadeld2496222014-05-20 12:46:37 +03002564
David Spinadel35a000b2013-08-28 09:29:43 +03002565out:
2566 mutex_unlock(&mvm->mutex);
2567 return ret;
2568}
2569
Johannes Berg37e33082014-02-17 10:48:17 +01002570static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2571 struct ieee80211_vif *vif)
David Spinadel35a000b2013-08-28 09:29:43 +03002572{
2573 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002574 int ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002575
2576 mutex_lock(&mvm->mutex);
Luciano Coelhoe7d3aba2015-02-06 10:19:05 +02002577
2578 /* Due to a race condition, it's possible that mac80211 asks
2579 * us to stop a sched_scan when it's already stopped. This
2580 * can happen, for instance, if we stopped the scan ourselves,
2581 * called ieee80211_sched_scan_stopped() and the userspace called
2582 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
2583 * could run. To handle this, simply return if the scan is
2584 * not running.
2585 */
2586 /* FIXME: for now, we ignore this race for UMAC scans, since
2587 * they don't set the scan_status.
2588 */
2589 if (mvm->scan_status != IWL_MVM_SCAN_SCHED &&
2590 !(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2591 mutex_unlock(&mvm->mutex);
2592 return 0;
2593 }
2594
David Spinadelfb98be52014-05-04 12:51:10 +03002595 ret = iwl_mvm_scan_offload_stop(mvm, false);
David Spinadel35a000b2013-08-28 09:29:43 +03002596 mutex_unlock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002597 iwl_mvm_wait_for_async_handlers(mvm);
Johannes Berg37e33082014-02-17 10:48:17 +01002598
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002599 return ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002600}
2601
Johannes Berg8ca151b2013-01-24 14:25:36 +01002602static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2603 enum set_key_cmd cmd,
2604 struct ieee80211_vif *vif,
2605 struct ieee80211_sta *sta,
2606 struct ieee80211_key_conf *key)
2607{
2608 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2609 int ret;
2610
2611 if (iwlwifi_mod_params.sw_crypto) {
2612 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2613 return -EOPNOTSUPP;
2614 }
2615
2616 switch (key->cipher) {
2617 case WLAN_CIPHER_SUITE_TKIP:
2618 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2619 /* fall-through */
2620 case WLAN_CIPHER_SUITE_CCMP:
2621 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2622 break;
2623 case WLAN_CIPHER_SUITE_AES_CMAC:
2624 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
2625 break;
2626 case WLAN_CIPHER_SUITE_WEP40:
2627 case WLAN_CIPHER_SUITE_WEP104:
Johannes Bergba3943b2014-11-12 23:54:48 +01002628 /* For non-client mode, only use WEP keys for TX as we probably
2629 * don't have a station yet anyway and would then have to keep
2630 * track of the keys, linking them to each of the clients/peers
2631 * as they appear. For now, don't do that, for performance WEP
2632 * offload doesn't really matter much, but we need it for some
2633 * other offload features in client mode.
Johannes Berg8ca151b2013-01-24 14:25:36 +01002634 */
Johannes Bergba3943b2014-11-12 23:54:48 +01002635 if (vif->type != NL80211_IFTYPE_STATION)
2636 return 0;
2637 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002638 default:
Max Stepanove36e5432013-08-27 19:56:13 +03002639 /* currently FW supports only one optional cipher scheme */
2640 if (hw->n_cipher_schemes &&
2641 hw->cipher_schemes->cipher == key->cipher)
2642 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2643 else
2644 return -EOPNOTSUPP;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002645 }
2646
2647 mutex_lock(&mvm->mutex);
2648
2649 switch (cmd) {
2650 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02002651 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2652 vif->type == NL80211_IFTYPE_AP) && !sta) {
2653 /*
2654 * GTK on AP interface is a TX-only key, return 0;
2655 * on IBSS they're per-station and because we're lazy
2656 * we don't support them for RX, so do the same.
2657 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002658 ret = 0;
2659 key->hw_key_idx = STA_KEY_IDX_INVALID;
2660 break;
2661 }
2662
Johannes Berg8ca151b2013-01-24 14:25:36 +01002663 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
2664 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
2665 if (ret) {
2666 IWL_WARN(mvm, "set key failed\n");
2667 /*
2668 * can't add key for RX, but we don't need it
2669 * in the device for TX so still return 0
2670 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002671 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002672 ret = 0;
2673 }
2674
2675 break;
2676 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01002677 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2678 ret = 0;
2679 break;
2680 }
2681
Johannes Berg8ca151b2013-01-24 14:25:36 +01002682 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
2683 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
2684 break;
2685 default:
2686 ret = -EINVAL;
2687 }
2688
2689 mutex_unlock(&mvm->mutex);
2690 return ret;
2691}
2692
2693static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2694 struct ieee80211_vif *vif,
2695 struct ieee80211_key_conf *keyconf,
2696 struct ieee80211_sta *sta,
2697 u32 iv32, u16 *phase1key)
2698{
2699 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2700
Johannes Berg5023d962013-07-31 14:07:43 +02002701 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2702 return;
2703
Johannes Berg8ca151b2013-01-24 14:25:36 +01002704 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2705}
2706
2707
Ariej Marjiehb1128892014-07-16 21:11:12 +03002708static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
2709 struct iwl_rx_packet *pkt, void *data)
2710{
2711 struct iwl_mvm *mvm =
2712 container_of(notif_wait, struct iwl_mvm, notif_wait);
2713 struct iwl_hs20_roc_res *resp;
2714 int resp_len = iwl_rx_packet_payload_len(pkt);
2715 struct iwl_mvm_time_event_data *te_data = data;
2716
2717 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
2718 return true;
2719
2720 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
2721 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
2722 return true;
2723 }
2724
2725 resp = (void *)pkt->data;
2726
2727 IWL_DEBUG_TE(mvm,
2728 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
2729 resp->status, resp->event_unique_id);
2730
2731 te_data->uid = le32_to_cpu(resp->event_unique_id);
2732 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
2733 te_data->uid);
2734
2735 spin_lock_bh(&mvm->time_event_lock);
2736 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
2737 spin_unlock_bh(&mvm->time_event_lock);
2738
2739 return true;
2740}
2741
2742#define AUX_ROC_MAX_DELAY_ON_CHANNEL 5000
2743static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
2744 struct ieee80211_channel *channel,
2745 struct ieee80211_vif *vif,
2746 int duration)
2747{
2748 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
2749 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2750 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
2751 static const u8 time_event_response[] = { HOT_SPOT_CMD };
2752 struct iwl_notification_wait wait_time_event;
2753 struct iwl_hs20_roc_req aux_roc_req = {
2754 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
2755 .id_and_color =
2756 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
2757 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
2758 /* Set the channel info data */
2759 .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ?
2760 PHY_BAND_24 : PHY_BAND_5,
2761 .channel_info.channel = channel->hw_value,
2762 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
2763 /* Set the time and duration */
2764 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
2765 .apply_time_max_delay =
2766 cpu_to_le32(MSEC_TO_TU(AUX_ROC_MAX_DELAY_ON_CHANNEL)),
2767 .duration = cpu_to_le32(MSEC_TO_TU(duration)),
2768 };
2769
2770 /* Set the node address */
2771 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
2772
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002773 lockdep_assert_held(&mvm->mutex);
2774
2775 spin_lock_bh(&mvm->time_event_lock);
2776
2777 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
2778 spin_unlock_bh(&mvm->time_event_lock);
2779 return -EIO;
2780 }
2781
Ariej Marjiehb1128892014-07-16 21:11:12 +03002782 te_data->vif = vif;
2783 te_data->duration = duration;
2784 te_data->id = HOT_SPOT_CMD;
2785
Ariej Marjiehb1128892014-07-16 21:11:12 +03002786 spin_unlock_bh(&mvm->time_event_lock);
2787
2788 /*
2789 * Use a notification wait, which really just processes the
2790 * command response and doesn't wait for anything, in order
2791 * to be able to process the response and get the UID inside
2792 * the RX path. Using CMD_WANT_SKB doesn't work because it
2793 * stores the buffer and then wakes up this thread, by which
2794 * time another notification (that the time event started)
2795 * might already be processed unsuccessfully.
2796 */
2797 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
2798 time_event_response,
2799 ARRAY_SIZE(time_event_response),
2800 iwl_mvm_rx_aux_roc, te_data);
2801
2802 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
2803 &aux_roc_req);
2804
2805 if (res) {
2806 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
2807 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
2808 goto out_clear_te;
2809 }
2810
2811 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
2812 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
2813 /* should never fail */
2814 WARN_ON_ONCE(res);
2815
2816 if (res) {
2817 out_clear_te:
2818 spin_lock_bh(&mvm->time_event_lock);
2819 iwl_mvm_te_clear_data(mvm, te_data);
2820 spin_unlock_bh(&mvm->time_event_lock);
2821 }
2822
2823 return res;
2824}
2825
Johannes Berg8ca151b2013-01-24 14:25:36 +01002826static int iwl_mvm_roc(struct ieee80211_hw *hw,
2827 struct ieee80211_vif *vif,
2828 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002829 int duration,
2830 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002831{
2832 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002833 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002834 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03002835 struct iwl_mvm_phy_ctxt *phy_ctxt;
2836 int ret, i;
2837
2838 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
2839 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002840
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002841 mutex_lock(&mvm->mutex);
2842
Ariej Marjiehb1128892014-07-16 21:11:12 +03002843 switch (vif->type) {
2844 case NL80211_IFTYPE_STATION:
Luciano Coelho5ac6c722014-10-21 16:12:18 +03002845 if (mvm->fw->ucode_capa.capa[0] &
2846 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT) {
2847 /* Use aux roc framework (HS20) */
2848 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
2849 vif, duration);
2850 goto out_unlock;
2851 }
2852 IWL_ERR(mvm, "hotspot not supported\n");
2853 ret = -EINVAL;
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002854 goto out_unlock;
Ariej Marjiehb1128892014-07-16 21:11:12 +03002855 case NL80211_IFTYPE_P2P_DEVICE:
2856 /* handle below */
2857 break;
2858 default:
2859 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
Matti Gottlieba6cc5162014-09-29 11:46:04 +03002860 ret = -EINVAL;
2861 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002862 }
2863
Ilan Peer31d385a2013-04-02 10:25:46 +03002864 for (i = 0; i < NUM_PHY_CTX; i++) {
2865 phy_ctxt = &mvm->phy_ctxts[i];
2866 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
2867 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002868
Ilan Peer31d385a2013-04-02 10:25:46 +03002869 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
2870 /*
2871 * Unbind the P2P_DEVICE from the current PHY context,
2872 * and if the PHY context is not used remove it.
2873 */
2874 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2875 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2876 goto out_unlock;
2877
2878 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2879
2880 /* Bind the P2P_DEVICE to the current PHY Context */
2881 mvmvif->phy_ctxt = phy_ctxt;
2882
2883 ret = iwl_mvm_binding_add_vif(mvm, vif);
2884 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2885 goto out_unlock;
2886
2887 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2888 goto schedule_time_event;
2889 }
2890 }
2891
2892 /* Need to update the PHY context only if the ROC channel changed */
2893 if (channel == mvmvif->phy_ctxt->channel)
2894 goto schedule_time_event;
2895
2896 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
2897
2898 /*
2899 * Change the PHY context configuration as it is currently referenced
2900 * only by the P2P Device MAC
2901 */
2902 if (mvmvif->phy_ctxt->ref == 1) {
2903 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2904 &chandef, 1, 1);
2905 if (ret)
2906 goto out_unlock;
2907 } else {
2908 /*
2909 * The PHY context is shared with other MACs. Need to remove the
2910 * P2P Device from the binding, allocate an new PHY context and
2911 * create a new binding
2912 */
2913 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2914 if (!phy_ctxt) {
2915 ret = -ENOSPC;
2916 goto out_unlock;
2917 }
2918
2919 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2920 1, 1);
2921 if (ret) {
2922 IWL_ERR(mvm, "Failed to change PHY context\n");
2923 goto out_unlock;
2924 }
2925
2926 /* Unbind the P2P_DEVICE from the current PHY context */
2927 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2928 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2929 goto out_unlock;
2930
2931 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2932
2933 /* Bind the P2P_DEVICE to the new allocated PHY context */
2934 mvmvif->phy_ctxt = phy_ctxt;
2935
2936 ret = iwl_mvm_binding_add_vif(mvm, vif);
2937 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2938 goto out_unlock;
2939
2940 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2941 }
2942
2943schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002944 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02002945 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002946
Ilan Peer31d385a2013-04-02 10:25:46 +03002947out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002948 mutex_unlock(&mvm->mutex);
2949 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01002950 return ret;
2951}
2952
2953static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
2954{
2955 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2956
2957 IWL_DEBUG_MAC80211(mvm, "enter\n");
2958
2959 mutex_lock(&mvm->mutex);
Matti Gottliebbf5da872014-11-16 10:25:12 +02002960 iwl_mvm_stop_roc(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002961 mutex_unlock(&mvm->mutex);
2962
2963 IWL_DEBUG_MAC80211(mvm, "leave\n");
2964 return 0;
2965}
2966
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002967static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
2968 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002969{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002970 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2971 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002972 int ret;
2973
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002974 lockdep_assert_held(&mvm->mutex);
2975
Ilan Peer53a9d612013-04-28 11:55:08 +03002976 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002977
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002978 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2979 if (!phy_ctxt) {
2980 ret = -ENOSPC;
2981 goto out;
2982 }
2983
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02002984 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Ilan Peer53a9d612013-04-28 11:55:08 +03002985 ctx->rx_chains_static,
2986 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002987 if (ret) {
2988 IWL_ERR(mvm, "Failed to add PHY context\n");
2989 goto out;
2990 }
2991
Ilan Peer53a9d612013-04-28 11:55:08 +03002992 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002993 *phy_ctxt_id = phy_ctxt->id;
2994out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002995 return ret;
2996}
2997
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002998static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2999 struct ieee80211_chanctx_conf *ctx)
3000{
3001 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3002 int ret;
3003
3004 mutex_lock(&mvm->mutex);
3005 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3006 mutex_unlock(&mvm->mutex);
3007
3008 return ret;
3009}
3010
3011static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3012 struct ieee80211_chanctx_conf *ctx)
3013{
3014 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3015 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3016
3017 lockdep_assert_held(&mvm->mutex);
3018
3019 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3020}
3021
Johannes Berg8ca151b2013-01-24 14:25:36 +01003022static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3023 struct ieee80211_chanctx_conf *ctx)
3024{
3025 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003026
3027 mutex_lock(&mvm->mutex);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003028 __iwl_mvm_remove_chanctx(mvm, ctx);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003029 mutex_unlock(&mvm->mutex);
3030}
3031
3032static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3033 struct ieee80211_chanctx_conf *ctx,
3034 u32 changed)
3035{
3036 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003037 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3038 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01003039
Ilan Peer31d385a2013-04-02 10:25:46 +03003040 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3041 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3042 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
Arik Nemtsov2dceeda2013-12-29 17:57:53 +02003043 IEEE80211_CHANCTX_CHANGE_RADAR |
3044 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
Ilan Peer31d385a2013-04-02 10:25:46 +03003045 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3046 phy_ctxt->ref, changed))
3047 return;
3048
Johannes Berg8ca151b2013-01-24 14:25:36 +01003049 mutex_lock(&mvm->mutex);
Emmanuel Grumbach4d664492014-04-30 18:09:59 +03003050 iwl_mvm_bt_coex_vif_change(mvm);
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02003051 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003052 ctx->rx_chains_static,
3053 ctx->rx_chains_dynamic);
3054 mutex_unlock(&mvm->mutex);
3055}
3056
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003057static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3058 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02003059 struct ieee80211_chanctx_conf *ctx,
3060 bool switching_chanctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003061{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003062 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3063 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01003064 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3065 int ret;
3066
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003067 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003068
Ilan Peerfe0f2de2013-03-21 10:23:52 +02003069 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003070
3071 switch (vif->type) {
3072 case NL80211_IFTYPE_AP:
Luciano Coelho4741dd02014-11-10 11:10:13 +02003073 /* only needed if we're switching chanctx (i.e. during CSA) */
3074 if (switching_chanctx) {
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003075 mvmvif->ap_ibss_active = true;
3076 break;
3077 }
Johannes Berg5023d962013-07-31 14:07:43 +02003078 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003079 /*
3080 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02003081 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01003082 */
3083 ret = 0;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003084 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003085 case NL80211_IFTYPE_STATION:
Luciano Coelho2533edc2014-08-08 19:50:46 +03003086 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003087 case NL80211_IFTYPE_MONITOR:
Luciano Coelho2533edc2014-08-08 19:50:46 +03003088 /* always disable PS when a monitor interface is active */
3089 mvmvif->ps_disabled = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003090 break;
3091 default:
3092 ret = -EINVAL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003093 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003094 }
3095
3096 ret = iwl_mvm_binding_add_vif(mvm, vif);
3097 if (ret)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003098 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003099
3100 /*
Alexander Bondar92d85562013-10-23 11:50:34 +02003101 * Power state must be updated before quotas,
3102 * otherwise fw will complain.
3103 */
Arik Nemtsov999609f2014-05-15 17:31:51 +03003104 iwl_mvm_power_update_mac(mvm);
Alexander Bondar92d85562013-10-23 11:50:34 +02003105
3106 /* Setting the quota at this stage is only required for monitor
Johannes Berg8ca151b2013-01-24 14:25:36 +01003107 * interfaces. For the other types, the bss_info changed flow
3108 * will handle quota settings.
3109 */
3110 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02003111 mvmvif->monitor_active = true;
Johannes Berg01662302014-06-06 15:18:45 +02003112 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003113 if (ret)
3114 goto out_remove_binding;
3115 }
3116
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003117 /* Handle binding during CSA */
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003118 if (vif->type == NL80211_IFTYPE_AP) {
Johannes Berg01662302014-06-06 15:18:45 +02003119 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg3dfd3a92014-08-11 21:37:30 +02003120 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003121 }
3122
Luciano Coelho4741dd02014-11-10 11:10:13 +02003123 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
Luciano Coelho686e7fe2014-11-10 11:10:21 +02003124 u32 duration = 2 * vif->bss_conf.beacon_int;
3125
3126 /* iwl_mvm_protect_session() reads directly from the
3127 * device (the system time), so make sure it is
3128 * available.
3129 */
3130 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3131 if (ret)
3132 goto out_remove_binding;
3133
3134 /* Protect the session to make sure we hear the first
3135 * beacon on the new channel.
3136 */
3137 iwl_mvm_protect_session(mvm, vif, duration, duration,
3138 vif->bss_conf.beacon_int / 2,
3139 true);
3140
3141 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3142
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003143 iwl_mvm_update_quotas(mvm, NULL);
Luciano Coelho0ce04ce2014-05-08 16:03:39 +03003144 }
3145
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003146 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003147
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003148out_remove_binding:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003149 iwl_mvm_binding_remove_vif(mvm, vif);
Arik Nemtsov999609f2014-05-15 17:31:51 +03003150 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003151out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01003152 if (ret)
3153 mvmvif->phy_ctxt = NULL;
3154 return ret;
3155}
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003156static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3157 struct ieee80211_vif *vif,
3158 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003159{
3160 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003161 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003162
3163 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003164 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003165 mutex_unlock(&mvm->mutex);
3166
3167 return ret;
3168}
3169
3170static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3171 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02003172 struct ieee80211_chanctx_conf *ctx,
3173 bool switching_chanctx)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003174{
3175 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003176 struct ieee80211_vif *disabled_vif = NULL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003177
3178 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003179
3180 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3181
Johannes Berg8ca151b2013-01-24 14:25:36 +01003182 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02003183 case NL80211_IFTYPE_ADHOC:
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003184 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003185 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02003186 mvmvif->monitor_active = false;
Luciano Coelho2533edc2014-08-08 19:50:46 +03003187 mvmvif->ps_disabled = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003188 break;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003189 case NL80211_IFTYPE_AP:
3190 /* This part is triggered only during CSA */
Luciano Coelho4741dd02014-11-10 11:10:13 +02003191 if (!switching_chanctx || !mvmvif->ap_ibss_active)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003192 goto out;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003193
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003194 mvmvif->csa_countdown = false;
3195
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03003196 /* Set CS bit on all the stations */
3197 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3198
3199 /* Save blocked iface, the timeout is set on the next beacon */
3200 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3201
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003202 mvmvif->ap_ibss_active = false;
Luciano Coelhof0c97782014-03-05 15:41:48 +02003203 break;
3204 case NL80211_IFTYPE_STATION:
3205 if (!switching_chanctx)
3206 break;
3207
3208 disabled_vif = vif;
3209
Johannes Berg3dfd3a92014-08-11 21:37:30 +02003210 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003211 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003212 default:
3213 break;
3214 }
3215
Luciano Coelhof0c97782014-03-05 15:41:48 +02003216 iwl_mvm_update_quotas(mvm, disabled_vif);
Ilan Peer1e1391c2013-03-13 14:52:04 +02003217 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03003218
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003219out:
Ilan Peera11e1442013-12-31 21:19:55 +02003220 mvmvif->phy_ctxt = NULL;
Arik Nemtsov999609f2014-05-15 17:31:51 +03003221 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003222}
3223
3224static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3225 struct ieee80211_vif *vif,
3226 struct ieee80211_chanctx_conf *ctx)
3227{
3228 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3229
3230 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003231 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003232 mutex_unlock(&mvm->mutex);
3233}
3234
Luciano Coelho50cc9572014-11-10 11:10:08 +02003235static int
3236iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3237 struct ieee80211_vif_chanctx_switch *vifs)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003238{
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003239 int ret;
3240
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003241 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02003242 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003243 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3244
3245 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3246 if (ret) {
3247 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3248 goto out_reassign;
3249 }
3250
Luciano Coelhof0c97782014-03-05 15:41:48 +02003251 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3252 true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003253 if (ret) {
3254 IWL_ERR(mvm,
3255 "failed to assign new_ctx during channel switch\n");
3256 goto out_remove;
3257 }
3258
Arik Nemtsovf6972672014-06-15 16:03:55 +03003259 /* we don't support TDLS during DCM - can be caused by channel switch */
3260 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3261 iwl_mvm_teardown_tdls_peers(mvm);
3262
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003263 goto out;
3264
3265out_remove:
3266 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3267
3268out_reassign:
Luciano Coelho6fd1fb62014-11-10 11:10:10 +02003269 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003270 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3271 goto out_restart;
3272 }
3273
Luciano Coelho6fd1fb62014-11-10 11:10:10 +02003274 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3275 true)) {
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003276 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3277 goto out_restart;
3278 }
3279
3280 goto out;
3281
3282out_restart:
3283 /* things keep failing, better restart the hw */
3284 iwl_mvm_nic_restart(mvm, false);
3285
3286out:
3287 mutex_unlock(&mvm->mutex);
Luciano Coelho50cc9572014-11-10 11:10:08 +02003288
3289 return ret;
3290}
3291
Luciano Coelho48a256e2014-11-10 11:10:09 +02003292static int
3293iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3294 struct ieee80211_vif_chanctx_switch *vifs)
3295{
3296 int ret;
3297
3298 mutex_lock(&mvm->mutex);
3299 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3300
3301 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3302 true);
3303 if (ret) {
3304 IWL_ERR(mvm,
3305 "failed to assign new_ctx during channel switch\n");
3306 goto out_reassign;
3307 }
3308
3309 goto out;
3310
3311out_reassign:
3312 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3313 true)) {
3314 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3315 goto out_restart;
3316 }
3317
3318 goto out;
3319
3320out_restart:
3321 /* things keep failing, better restart the hw */
3322 iwl_mvm_nic_restart(mvm, false);
3323
3324out:
3325 mutex_unlock(&mvm->mutex);
3326
3327 return ret;
3328}
3329
Luciano Coelho50cc9572014-11-10 11:10:08 +02003330static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3331 struct ieee80211_vif_chanctx_switch *vifs,
3332 int n_vifs,
3333 enum ieee80211_chanctx_switch_mode mode)
3334{
3335 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3336 int ret;
3337
3338 /* we only support a single-vif right now */
3339 if (n_vifs > 1)
3340 return -EOPNOTSUPP;
3341
3342 switch (mode) {
3343 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3344 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3345 break;
3346 case CHANCTX_SWMODE_REASSIGN_VIF:
Luciano Coelho48a256e2014-11-10 11:10:09 +02003347 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
Luciano Coelho50cc9572014-11-10 11:10:08 +02003348 break;
3349 default:
3350 ret = -EOPNOTSUPP;
3351 break;
3352 }
3353
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003354 return ret;
3355}
3356
Johannes Berg8ca151b2013-01-24 14:25:36 +01003357static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3358 struct ieee80211_sta *sta,
3359 bool set)
3360{
3361 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01003362 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003363
3364 if (!mvm_sta || !mvm_sta->vif) {
3365 IWL_ERR(mvm, "Station is not associated to a vif\n");
3366 return -EINVAL;
3367 }
3368
3369 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3370}
3371
David Spinadel507cadf2013-07-31 18:07:21 +03003372#ifdef CONFIG_NL80211_TESTMODE
3373static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3374 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3375 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad42013-08-01 14:17:15 +02003376 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03003377};
3378
3379static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3380 struct ieee80211_vif *vif,
3381 void *data, int len)
3382{
3383 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3384 int err;
3385 u32 noa_duration;
3386
3387 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
3388 if (err)
3389 return err;
3390
3391 if (!tb[IWL_MVM_TM_ATTR_CMD])
3392 return -EINVAL;
3393
3394 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3395 case IWL_MVM_TM_CMD_SET_NOA:
3396 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3397 !vif->bss_conf.enable_beacon ||
3398 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3399 return -EINVAL;
3400
3401 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3402 if (noa_duration >= vif->bss_conf.beacon_int)
3403 return -EINVAL;
3404
3405 mvm->noa_duration = noa_duration;
3406 mvm->noa_vif = vif;
3407
Johannes Berg01662302014-06-06 15:18:45 +02003408 return iwl_mvm_update_quotas(mvm, NULL);
Johannes Bergf6c6ad42013-08-01 14:17:15 +02003409 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3410 /* must be associated client vif - ignore authorized */
3411 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3412 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3413 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3414 return -EINVAL;
3415
3416 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03003417 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3418 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
David Spinadel507cadf2013-07-31 18:07:21 +03003419 }
3420
3421 return -EOPNOTSUPP;
3422}
3423
3424static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3425 struct ieee80211_vif *vif,
3426 void *data, int len)
3427{
3428 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3429 int err;
3430
3431 mutex_lock(&mvm->mutex);
3432 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3433 mutex_unlock(&mvm->mutex);
3434
3435 return err;
3436}
3437#endif
3438
Luciano Coelho622e3f92014-11-10 11:10:17 +02003439static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3440 struct ieee80211_vif *vif,
3441 struct ieee80211_channel_switch *chsw)
3442{
3443 /* By implementing this operation, we prevent mac80211 from
3444 * starting its own channel switch timer, so that we can call
3445 * ieee80211_chswitch_done() ourselves at the right time
3446 * (which is when the absence time event starts).
3447 */
3448
3449 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3450 "dummy channel switch op\n");
3451}
3452
Luciano Coelhof0289052014-11-10 11:10:06 +02003453static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3454 struct ieee80211_vif *vif,
3455 struct ieee80211_channel_switch *chsw)
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003456{
3457 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003458 struct ieee80211_vif *csa_vif;
Luciano Coelhof6c34822014-11-10 11:10:12 +02003459 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003460 u32 apply_time;
Luciano Coelhof0289052014-11-10 11:10:06 +02003461 int ret;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003462
3463 mutex_lock(&mvm->mutex);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03003464
Luciano Coelho6b20d772014-11-10 11:10:07 +02003465 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
Luciano Coelhof0289052014-11-10 11:10:06 +02003466 chsw->chandef.center_freq1);
Luciano Coelho6b20d772014-11-10 11:10:07 +02003467
3468 switch (vif->type) {
3469 case NL80211_IFTYPE_AP:
3470 csa_vif =
3471 rcu_dereference_protected(mvm->csa_vif,
3472 lockdep_is_held(&mvm->mutex));
3473 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3474 "Another CSA is already in progress")) {
3475 ret = -EBUSY;
3476 goto out_unlock;
3477 }
3478
3479 rcu_assign_pointer(mvm->csa_vif, vif);
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003480
Andrei Otcheretianski7ef0aab2014-11-10 11:10:11 +02003481 if (WARN_ONCE(mvmvif->csa_countdown,
3482 "Previous CSA countdown didn't complete")) {
3483 ret = -EBUSY;
3484 goto out_unlock;
3485 }
3486
Luciano Coelho6b20d772014-11-10 11:10:07 +02003487 break;
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003488 case NL80211_IFTYPE_STATION:
Luciano Coelho4500e132014-11-10 11:10:15 +02003489 /* Schedule the time event to a bit before beacon 1,
3490 * to make sure we're in the new channel when the
3491 * GO/AP arrives.
3492 */
3493 apply_time = chsw->device_timestamp +
3494 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3495 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003496
3497 if (chsw->block_tx)
3498 iwl_mvm_csa_client_absent(mvm, vif);
3499
Luciano Coelho4500e132014-11-10 11:10:15 +02003500 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003501 apply_time);
Luciano Coelhoc6e0a3e02014-11-10 11:10:18 +02003502 if (mvmvif->bf_data.bf_enabled) {
3503 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3504 if (ret)
3505 goto out_unlock;
3506 }
3507
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003508 break;
Luciano Coelho6b20d772014-11-10 11:10:07 +02003509 default:
3510 break;
3511 }
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003512
Luciano Coelhof6c34822014-11-10 11:10:12 +02003513 mvmvif->ps_disabled = true;
3514
3515 ret = iwl_mvm_power_update_ps(mvm);
3516 if (ret)
3517 goto out_unlock;
Luciano Coelhof0289052014-11-10 11:10:06 +02003518
Arik Nemtsove198f5e2014-09-14 19:13:54 +03003519 /* we won't be on this channel any longer */
3520 iwl_mvm_teardown_tdls_peers(mvm);
3521
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003522out_unlock:
3523 mutex_unlock(&mvm->mutex);
Luciano Coelhof0289052014-11-10 11:10:06 +02003524
3525 return ret;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003526}
3527
Luciano Coelhof6c34822014-11-10 11:10:12 +02003528static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
3529 struct ieee80211_vif *vif)
3530{
3531 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3532 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3533 int ret;
3534
3535 mutex_lock(&mvm->mutex);
3536
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003537 if (vif->type == NL80211_IFTYPE_STATION) {
3538 struct iwl_mvm_sta *mvmsta;
3539
3540 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
3541 mvmvif->ap_sta_id);
3542
3543 if (WARN_ON(!mvmsta)) {
3544 ret = -EIO;
3545 goto out_unlock;
3546 }
3547
3548 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
3549
3550 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Luciano Coelhoc6e0a3e02014-11-10 11:10:18 +02003551
3552 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3553 if (ret)
3554 goto out_unlock;
Luciano Coelho686e7fe2014-11-10 11:10:21 +02003555
3556 iwl_mvm_stop_session_protection(mvm, vif);
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003557 }
3558
Luciano Coelhof6c34822014-11-10 11:10:12 +02003559 mvmvif->ps_disabled = false;
3560
3561 ret = iwl_mvm_power_update_ps(mvm);
3562
Luciano Coelhoa57c6882014-11-10 11:10:16 +02003563out_unlock:
Luciano Coelhof6c34822014-11-10 11:10:12 +02003564 mutex_unlock(&mvm->mutex);
3565
3566 return ret;
3567}
3568
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003569static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
3570 struct ieee80211_vif *vif, u32 queues, bool drop)
3571{
3572 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3573 struct iwl_mvm_vif *mvmvif;
3574 struct iwl_mvm_sta *mvmsta;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03003575 struct ieee80211_sta *sta;
3576 int i;
3577 u32 msk = 0;
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003578
3579 if (!vif || vif->type != NL80211_IFTYPE_STATION)
3580 return;
3581
3582 mutex_lock(&mvm->mutex);
3583 mvmvif = iwl_mvm_vif_from_mac80211(vif);
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003584
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03003585 /* flush the AP-station and all TDLS peers */
3586 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
3587 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3588 lockdep_is_held(&mvm->mutex));
3589 if (IS_ERR_OR_NULL(sta))
3590 continue;
3591
3592 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3593 if (mvmsta->vif != vif)
3594 continue;
3595
3596 /* make sure only TDLS peers or the AP are flushed */
3597 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
3598
3599 msk |= mvmsta->tfd_queue_msk;
Johannes Berg480acbc2014-10-10 08:59:27 +02003600 }
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003601
Emmanuel Grumbach6d440b22015-01-20 09:25:19 +02003602 if (drop) {
3603 if (iwl_mvm_flush_tx_path(mvm, msk, true))
3604 IWL_ERR(mvm, "flush request fail\n");
3605 mutex_unlock(&mvm->mutex);
3606 } else {
3607 mutex_unlock(&mvm->mutex);
Johannes Berg480acbc2014-10-10 08:59:27 +02003608
Emmanuel Grumbach6d440b22015-01-20 09:25:19 +02003609 /* this can take a while, and we may need/want other operations
3610 * to succeed while doing this, so do it without the mutex held
3611 */
3612 iwl_trans_wait_tx_queue_empty(mvm->trans, msk);
3613 }
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003614}
3615
Johannes Berge5209262014-01-20 23:38:59 +01003616const struct ieee80211_ops iwl_mvm_hw_ops = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01003617 .tx = iwl_mvm_mac_tx,
3618 .ampdu_action = iwl_mvm_mac_ampdu_action,
3619 .start = iwl_mvm_mac_start,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02003620 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003621 .stop = iwl_mvm_mac_stop,
3622 .add_interface = iwl_mvm_mac_add_interface,
3623 .remove_interface = iwl_mvm_mac_remove_interface,
3624 .config = iwl_mvm_mac_config,
Eliad Pellere59647e2013-11-28 14:08:50 +02003625 .prepare_multicast = iwl_mvm_prepare_multicast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003626 .configure_filter = iwl_mvm_configure_filter,
3627 .bss_info_changed = iwl_mvm_bss_info_changed,
3628 .hw_scan = iwl_mvm_mac_hw_scan,
3629 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
Johannes Berg1ddbbb02013-12-04 22:39:17 +01003630 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003631 .sta_state = iwl_mvm_mac_sta_state,
3632 .sta_notify = iwl_mvm_mac_sta_notify,
3633 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
Johannes Berg3e56ead2013-02-15 22:23:18 +01003634 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003635 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02003636 .sta_rc_update = iwl_mvm_sta_rc_update,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003637 .conf_tx = iwl_mvm_mac_conf_tx,
3638 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
Arik Nemtsov07ecd892014-05-20 18:16:42 +03003639 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003640 .flush = iwl_mvm_mac_flush,
David Spinadel35a000b2013-08-28 09:29:43 +03003641 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
3642 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003643 .set_key = iwl_mvm_mac_set_key,
3644 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
3645 .remain_on_channel = iwl_mvm_roc,
3646 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003647 .add_chanctx = iwl_mvm_add_chanctx,
3648 .remove_chanctx = iwl_mvm_remove_chanctx,
3649 .change_chanctx = iwl_mvm_change_chanctx,
3650 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
3651 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003652 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003653
Johannes Berg5023d962013-07-31 14:07:43 +02003654 .start_ap = iwl_mvm_start_ap_ibss,
3655 .stop_ap = iwl_mvm_stop_ap_ibss,
3656 .join_ibss = iwl_mvm_start_ap_ibss,
3657 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003658
3659 .set_tim = iwl_mvm_set_tim,
3660
Luciano Coelho622e3f92014-11-10 11:10:17 +02003661 .channel_switch = iwl_mvm_channel_switch,
Luciano Coelhof0289052014-11-10 11:10:06 +02003662 .pre_channel_switch = iwl_mvm_pre_channel_switch,
Luciano Coelhof6c34822014-11-10 11:10:12 +02003663 .post_channel_switch = iwl_mvm_post_channel_switch,
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003664
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +03003665 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
3666 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
3667 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
3668
David Spinadel507cadf2013-07-31 18:07:21 +03003669 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
3670
Johannes Berg8ca151b2013-01-24 14:25:36 +01003671#ifdef CONFIG_PM_SLEEP
3672 /* look at d3.c */
3673 .suspend = iwl_mvm_suspend,
3674 .resume = iwl_mvm_resume,
3675 .set_wakeup = iwl_mvm_set_wakeup,
3676 .set_rekey_data = iwl_mvm_set_rekey_data,
3677#if IS_ENABLED(CONFIG_IPV6)
3678 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
3679#endif
3680 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
3681#endif
3682};