blob: 98e14f9c6fbe5f54cef5fdf7d84915adcba3d0f1 [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 Berg8ca151b2013-01-24 14:25:36 +01009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020025 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010026 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020033 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8ca151b2013-01-24 14:25:36 +010034 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63#include <linux/kernel.h>
64#include <linux/slab.h>
65#include <linux/skbuff.h>
66#include <linux/netdevice.h>
67#include <linux/etherdevice.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010068#include <linux/ip.h>
Eliad Peller2ee8f022014-01-13 19:07:09 +020069#include <linux/if_arp.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010070#include <net/mac80211.h>
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +020071#include <net/ieee80211_radiotap.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010072#include <net/tcp.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010073
74#include "iwl-op-mode.h"
75#include "iwl-io.h"
76#include "mvm.h"
77#include "sta.h"
78#include "time-event.h"
79#include "iwl-eeprom-parse.h"
80#include "fw-api-scan.h"
81#include "iwl-phy-db.h"
David Spinadel507cadf2013-07-31 18:07:21 +030082#include "testmode.h"
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +030083#include "iwl-fw-error-dump.h"
84#include "iwl-prph.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010085
86static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
87 {
88 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030089 .types = BIT(NL80211_IFTYPE_STATION),
Johannes Berg8ca151b2013-01-24 14:25:36 +010090 },
Johannes Berg3c15a0f2013-05-31 10:17:19 +020091 {
92 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030093 .types = BIT(NL80211_IFTYPE_AP) |
94 BIT(NL80211_IFTYPE_P2P_CLIENT) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +020095 BIT(NL80211_IFTYPE_P2P_GO),
96 },
97 {
98 .max = 1,
99 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
100 },
Johannes Berg8ca151b2013-01-24 14:25:36 +0100101};
102
103static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
104 {
105 .num_different_channels = 1,
106 .max_interfaces = 3,
107 .limits = iwl_mvm_limits,
108 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
109 },
110};
111
Johannes Bergf0c26462013-01-22 20:41:58 +0100112#ifdef CONFIG_PM_SLEEP
113static const struct nl80211_wowlan_tcp_data_token_feature
114iwl_mvm_wowlan_tcp_token_feature = {
115 .min_len = 0,
116 .max_len = 255,
117 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
118};
119
120static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
121 .tok = &iwl_mvm_wowlan_tcp_token_feature,
122 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
123 sizeof(struct ethhdr) -
124 sizeof(struct iphdr) -
125 sizeof(struct tcphdr),
126 .data_interval_max = 65535, /* __le16 in API */
127 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
128 sizeof(struct ethhdr) -
129 sizeof(struct iphdr) -
130 sizeof(struct tcphdr),
131 .seq = true,
132};
133#endif
134
Eliad Peller77736922014-01-14 12:35:49 +0200135#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
Eliad Peller2ee8f022014-01-13 19:07:09 +0200136/*
137 * Use the reserved field to indicate magic values.
138 * these values will only be used internally by the driver,
139 * and won't make it to the fw (reserved will be 0).
140 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
141 * be the vif's ip address. in case there is not a single
142 * ip address (0, or more than 1), this attribute will
143 * be skipped.
144 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
145 * the LSB bytes of the vif's mac address
146 */
147enum {
148 BC_FILTER_MAGIC_NONE = 0,
149 BC_FILTER_MAGIC_IP,
150 BC_FILTER_MAGIC_MAC,
151};
152
Eliad Peller77736922014-01-14 12:35:49 +0200153static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
154 {
155 /* arp */
156 .discard = 0,
157 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
158 .attrs = {
159 {
160 /* frame type - arp, hw type - ethernet */
161 .offset_type =
162 BCAST_FILTER_OFFSET_PAYLOAD_START,
163 .offset = sizeof(rfc1042_header),
164 .val = cpu_to_be32(0x08060001),
165 .mask = cpu_to_be32(0xffffffff),
166 },
Eliad Peller2ee8f022014-01-13 19:07:09 +0200167 {
168 /* arp dest ip */
169 .offset_type =
170 BCAST_FILTER_OFFSET_PAYLOAD_START,
171 .offset = sizeof(rfc1042_header) + 2 +
172 sizeof(struct arphdr) +
173 ETH_ALEN + sizeof(__be32) +
174 ETH_ALEN,
175 .mask = cpu_to_be32(0xffffffff),
176 /* mark it as special field */
177 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
178 },
179 },
180 },
181 {
182 /* dhcp offer bcast */
183 .discard = 0,
184 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
185 .attrs = {
186 {
187 /* udp dest port - 68 (bootp client)*/
188 .offset_type = BCAST_FILTER_OFFSET_IP_END,
189 .offset = offsetof(struct udphdr, dest),
190 .val = cpu_to_be32(0x00440000),
191 .mask = cpu_to_be32(0xffff0000),
192 },
193 {
194 /* dhcp - lsb bytes of client hw address */
195 .offset_type = BCAST_FILTER_OFFSET_IP_END,
196 .offset = 38,
197 .mask = cpu_to_be32(0xffffffff),
198 /* mark it as special field */
199 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
200 },
Eliad Peller77736922014-01-14 12:35:49 +0200201 },
202 },
203 /* last filter must be empty */
204 {},
205};
206#endif
207
Eliad Peller7498cf42014-01-16 17:10:44 +0200208void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
209{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200210 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200211 return;
212
213 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
Eliad Peller576eeee2014-07-01 18:38:38 +0300214 spin_lock_bh(&mvm->refs_lock);
215 mvm->refs[ref_type]++;
216 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200217 iwl_trans_ref(mvm->trans);
218}
219
220void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
221{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200222 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200223 return;
224
225 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
Eliad Peller576eeee2014-07-01 18:38:38 +0300226 spin_lock_bh(&mvm->refs_lock);
227 WARN_ON(!mvm->refs[ref_type]--);
228 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200229 iwl_trans_unref(mvm->trans);
230}
231
Eliad Peller576eeee2014-07-01 18:38:38 +0300232static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
233 enum iwl_mvm_ref_type except_ref)
Eliad Peller7498cf42014-01-16 17:10:44 +0200234{
Eliad Peller576eeee2014-07-01 18:38:38 +0300235 int i, j;
Eliad Peller7498cf42014-01-16 17:10:44 +0200236
Eliad Peller7bb426e2014-02-24 12:54:37 +0200237 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200238 return;
239
Eliad Peller576eeee2014-07-01 18:38:38 +0300240 spin_lock_bh(&mvm->refs_lock);
241 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
242 if (except_ref == i || !mvm->refs[i])
Eliad Peller7498cf42014-01-16 17:10:44 +0200243 continue;
244
Eliad Peller576eeee2014-07-01 18:38:38 +0300245 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
246 i, mvm->refs[i]);
247 for (j = 0; j < mvm->refs[i]; j++)
248 iwl_trans_unref(mvm->trans);
249 mvm->refs[i] = 0;
Eliad Peller7498cf42014-01-16 17:10:44 +0200250 }
Eliad Peller576eeee2014-07-01 18:38:38 +0300251 spin_unlock_bh(&mvm->refs_lock);
Eliad Peller7498cf42014-01-16 17:10:44 +0200252}
253
Eliad Peller576eeee2014-07-01 18:38:38 +0300254int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
Gregory Greenmand40fc482014-06-25 14:08:50 +0200255{
256 iwl_mvm_ref(mvm, ref_type);
257
258 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
259 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
260 HZ)) {
261 WARN_ON_ONCE(1);
262 iwl_mvm_unref(mvm, ref_type);
263 return -EIO;
264 }
265
266 return 0;
267}
268
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200269static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
270{
271 int i;
272
273 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
274 for (i = 0; i < NUM_PHY_CTX; i++) {
275 mvm->phy_ctxts[i].id = i;
276 mvm->phy_ctxts[i].ref = 0;
277 }
278}
279
David Spinadel20f1a5d2013-08-21 09:14:27 +0300280static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
281{
282 /* we create the 802.11 header and SSID element */
283 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID)
284 return mvm->fw->ucode_capa.max_probe_length - 24 - 2;
285 return mvm->fw->ucode_capa.max_probe_length - 24 - 34;
286}
287
Johannes Berg8ca151b2013-01-24 14:25:36 +0100288int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
289{
290 struct ieee80211_hw *hw = mvm->hw;
Ilan Peer831e85f2013-02-07 17:09:09 +0200291 int num_mac, ret, i;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100292
293 /* Tell mac80211 our characteristics */
294 hw->flags = IEEE80211_HW_SIGNAL_DBM |
295 IEEE80211_HW_SPECTRUM_MGMT |
296 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
297 IEEE80211_HW_QUEUE_CONTROL |
298 IEEE80211_HW_WANT_MONITOR_VIF |
Johannes Berg8ca151b2013-01-24 14:25:36 +0100299 IEEE80211_HW_SUPPORTS_PS |
300 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Johannes Bergd2931bb2013-02-05 18:10:04 +0100301 IEEE80211_HW_AMPDU_AGGREGATION |
Hila Gonend64048e2013-03-13 18:00:03 +0200302 IEEE80211_HW_TIMING_BEACON_ONLY |
Emmanuel Grumbach147fc9b2013-07-28 11:00:52 +0300303 IEEE80211_HW_CONNECTION_MONITOR |
Luciano Coelhof0c97782014-03-05 15:41:48 +0200304 IEEE80211_HW_CHANCTX_STA_CSA |
Emmanuel Grumbach147fc9b2013-07-28 11:00:52 +0300305 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
Alexander Bondare8e626a2013-10-16 00:21:34 +0200306 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100307
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200308 hw->queues = mvm->first_agg_queue;
Ilan Peer398e8c62013-03-13 15:20:35 +0200309 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +0200310 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
311 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
312 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100313 hw->rate_control_algorithm = "iwl-mvm-rs";
314
315 /*
316 * Enable 11w if advertised by firmware and software crypto
317 * is not enabled (as the firmware will interpret some mgmt
318 * packets, so enabling it with software crypto isn't safe)
319 */
320 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
321 !iwlwifi_mod_params.sw_crypto)
322 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
323
Matt Chen1504f482014-04-24 18:43:18 +0800324 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT &&
325 IWL_UCODE_API(mvm->fw->ucode_ver) >= 9 &&
326 !iwlwifi_mod_params.uapsd_disable) {
327 hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
328 hw->uapsd_queues = IWL_UAPSD_AC_INFO;
329 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
330 }
Alexander Bondare8e626a2013-10-16 00:21:34 +0200331
David Spinadelfb98be52014-05-04 12:51:10 +0300332 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
333 hw->flags |= IEEE80211_SINGLE_HW_SCAN_ON_ALL_BANDS;
334
Johannes Berg8ca151b2013-01-24 14:25:36 +0100335 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
336 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200337 hw->chanctx_data_size = sizeof(u16);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100338
339 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200340 BIT(NL80211_IFTYPE_P2P_CLIENT) |
341 BIT(NL80211_IFTYPE_AP) |
342 BIT(NL80211_IFTYPE_P2P_GO) |
Emmanuel Grumbachc13b1722014-03-27 19:12:12 +0200343 BIT(NL80211_IFTYPE_P2P_DEVICE) |
344 BIT(NL80211_IFTYPE_ADHOC);
Johannes Berg5023d962013-07-31 14:07:43 +0200345
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +0100346 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
347 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
348 REGULATORY_DISABLE_BEACON_HINTS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100349
Johannes Berg3e56ead2013-02-15 22:23:18 +0100350 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
351 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
352
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +0200353 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_CSA_FLOW)
354 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
355
Johannes Berg8ca151b2013-01-24 14:25:36 +0100356 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
357 hw->wiphy->n_iface_combinations =
358 ARRAY_SIZE(iwl_mvm_iface_combinations);
359
Ilan Peerc451e6d2013-02-20 08:41:54 +0200360 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100361 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
362
363 /* Extract MAC address */
364 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
365 hw->wiphy->addresses = mvm->addresses;
366 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200367
368 /* Extract additional MAC addresses if available */
369 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
370 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
371
372 for (i = 1; i < num_mac; i++) {
373 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100374 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200375 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100376 hw->wiphy->n_addresses++;
377 }
378
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200379 iwl_mvm_reset_phy_ctxts(mvm);
380
David Spinadel20f1a5d2013-08-21 09:14:27 +0300381 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
382
Johannes Berg8ca151b2013-01-24 14:25:36 +0100383 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
384
385 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
386 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
387 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
388 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
389 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
390 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
391
392 hw->wiphy->hw_version = mvm->trans->hw_id;
393
Alexander Bondarade50652013-04-03 16:28:47 +0300394 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100395 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
396 else
397 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
398
Emmanuel Grumbach77b2f282014-08-14 19:32:16 +0300399 /* TODO: enable that only for firmwares that don't crash */
400 /* hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; */
Emmanuel Grumbach536a3ee2014-03-30 09:11:44 +0300401 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
402 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
403 /* we create the 802.11 header and zero length SSID IE. */
404 hw->wiphy->max_sched_scan_ie_len = SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
David Spinadel35a000b2013-08-28 09:29:43 +0300405
Johannes Berg8ca151b2013-01-24 14:25:36 +0100406 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
Johannes Bergab480032014-06-04 10:13:50 +0200407 NL80211_FEATURE_LOW_PRIORITY_SCAN |
Alexander Bondar8a110d92014-03-12 17:31:19 +0200408 NL80211_FEATURE_P2P_GO_OPPPS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100409
410 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
411
Max Stepanove36e5432013-08-27 19:56:13 +0300412 /* currently FW API supports only one optional cipher scheme */
Johannes Berg9ddca862014-01-06 09:29:40 +0100413 if (mvm->fw->cs[0].cipher) {
Max Stepanove36e5432013-08-27 19:56:13 +0300414 mvm->hw->n_cipher_schemes = 1;
Johannes Berg9ddca862014-01-06 09:29:40 +0100415 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
Max Stepanove36e5432013-08-27 19:56:13 +0300416 }
417
Johannes Berg8ca151b2013-01-24 14:25:36 +0100418#ifdef CONFIG_PM_SLEEP
Eliad Pellerd15a7472014-03-27 18:53:12 +0200419 if (iwl_mvm_is_d0i3_supported(mvm) &&
420 device_can_wakeup(mvm->trans->dev)) {
421 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
422 hw->wiphy->wowlan = &mvm->wowlan;
423 } else if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100424 mvm->trans->ops->d3_suspend &&
425 mvm->trans->ops->d3_resume &&
426 device_can_wakeup(mvm->trans->dev)) {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200427 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
428 WIPHY_WOWLAN_DISCONNECT |
429 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
430 WIPHY_WOWLAN_RFKILL_RELEASE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100431 if (!iwlwifi_mod_params.sw_crypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200432 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
433 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
434 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100435
Johannes Berg964dc9e2013-06-03 17:25:34 +0200436 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
437 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
438 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
439 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
440 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100441 }
442#endif
443
Eliad Peller77736922014-01-14 12:35:49 +0200444#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
445 /* assign default bcast filtering configuration */
446 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
447#endif
448
Johannes Berg8ca151b2013-01-24 14:25:36 +0100449 ret = iwl_mvm_leds_init(mvm);
450 if (ret)
451 return ret;
452
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300453 ret = ieee80211_register_hw(mvm->hw);
454 if (ret)
455 iwl_mvm_leds_exit(mvm);
456
457 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100458}
459
Arik Nemtsovb2492502014-03-13 12:21:50 +0200460static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
461 struct ieee80211_sta *sta,
462 struct sk_buff *skb)
463{
464 struct iwl_mvm_sta *mvmsta;
465 bool defer = false;
466
467 /*
468 * double check the IN_D0I3 flag both before and after
469 * taking the spinlock, in order to prevent taking
470 * the spinlock when not needed.
471 */
472 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
473 return false;
474
475 spin_lock(&mvm->d0i3_tx_lock);
476 /*
477 * testing the flag again ensures the skb dequeue
478 * loop (on d0i3 exit) hasn't run yet.
479 */
480 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
481 goto out;
482
483 mvmsta = iwl_mvm_sta_from_mac80211(sta);
484 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
485 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
486 goto out;
487
488 __skb_queue_tail(&mvm->d0i3_tx, skb);
489 ieee80211_stop_queues(mvm->hw);
490
491 /* trigger wakeup */
492 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
493 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
494
495 defer = true;
496out:
497 spin_unlock(&mvm->d0i3_tx_lock);
498 return defer;
499}
500
Johannes Berg8ca151b2013-01-24 14:25:36 +0100501static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
502 struct ieee80211_tx_control *control,
503 struct sk_buff *skb)
504{
505 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg3e56ead2013-02-15 22:23:18 +0100506 struct ieee80211_sta *sta = control->sta;
507 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
508 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100509
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300510 if (iwl_mvm_is_radio_killed(mvm)) {
511 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100512 goto drop;
513 }
514
Ilan Peer398e8c62013-03-13 15:20:35 +0200515 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100516 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
517 goto drop;
518
Johannes Berg3e56ead2013-02-15 22:23:18 +0100519 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
520 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
521 ieee80211_is_mgmt(hdr->frame_control) &&
522 !ieee80211_is_deauth(hdr->frame_control) &&
523 !ieee80211_is_disassoc(hdr->frame_control) &&
524 !ieee80211_is_action(hdr->frame_control)))
525 sta = NULL;
526
527 if (sta) {
Arik Nemtsovb2492502014-03-13 12:21:50 +0200528 if (iwl_mvm_defer_tx(mvm, sta, skb))
529 return;
Johannes Berg3e56ead2013-02-15 22:23:18 +0100530 if (iwl_mvm_tx_skb(mvm, skb, sta))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100531 goto drop;
532 return;
533 }
534
535 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
536 goto drop;
537 return;
538 drop:
539 ieee80211_free_txskb(hw, skb);
540}
541
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200542static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
543{
544 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
545 return false;
546 return true;
547}
548
549static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
550{
551 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
552 return false;
553 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
554 return true;
555
556 /* enabled by default */
557 return true;
558}
559
Johannes Berg8ca151b2013-01-24 14:25:36 +0100560static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
561 struct ieee80211_vif *vif,
562 enum ieee80211_ampdu_mlme_action action,
563 struct ieee80211_sta *sta, u16 tid,
564 u16 *ssn, u8 buf_size)
565{
566 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
567 int ret;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200568 bool tx_agg_ref = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100569
570 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
571 sta->addr, tid, action);
572
573 if (!(mvm->nvm_data->sku_cap_11n_enable))
574 return -EACCES;
575
Arik Nemtsovb2492502014-03-13 12:21:50 +0200576 /* return from D0i3 before starting a new Tx aggregation */
Eliad Peller9256c202014-04-22 13:33:29 +0300577 switch (action) {
578 case IEEE80211_AMPDU_TX_START:
579 case IEEE80211_AMPDU_TX_STOP_CONT:
580 case IEEE80211_AMPDU_TX_STOP_FLUSH:
581 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
582 case IEEE80211_AMPDU_TX_OPERATIONAL:
Arik Nemtsovb2492502014-03-13 12:21:50 +0200583 /*
Eliad Peller9256c202014-04-22 13:33:29 +0300584 * for tx start, wait synchronously until D0i3 exit to
585 * get the correct sequence number for the tid.
586 * additionally, some other ampdu actions use direct
587 * target access, which is not handled automatically
588 * by the trans layer (unlike commands), so wait for
589 * d0i3 exit in these cases as well.
Arik Nemtsovb2492502014-03-13 12:21:50 +0200590 */
Gregory Greenmand40fc482014-06-25 14:08:50 +0200591 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
592 if (ret)
593 return ret;
594
595 tx_agg_ref = true;
Eliad Peller9256c202014-04-22 13:33:29 +0300596 break;
597 default:
598 break;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200599 }
600
Johannes Berg8ca151b2013-01-24 14:25:36 +0100601 mutex_lock(&mvm->mutex);
602
603 switch (action) {
604 case IEEE80211_AMPDU_RX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200605 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100606 ret = -EINVAL;
607 break;
608 }
609 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
610 break;
611 case IEEE80211_AMPDU_RX_STOP:
612 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
613 break;
614 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200615 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200616 ret = -EINVAL;
617 break;
618 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100619 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
620 break;
621 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200622 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
623 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100624 case IEEE80211_AMPDU_TX_STOP_FLUSH:
625 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200626 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100627 break;
628 case IEEE80211_AMPDU_TX_OPERATIONAL:
629 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
630 break;
631 default:
632 WARN_ON_ONCE(1);
633 ret = -EINVAL;
634 break;
635 }
636 mutex_unlock(&mvm->mutex);
637
Arik Nemtsovb2492502014-03-13 12:21:50 +0200638 /*
639 * If the tid is marked as started, we won't use it for offloaded
640 * traffic on the next D0i3 entry. It's safe to unref.
641 */
642 if (tx_agg_ref)
643 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
644
Johannes Berg8ca151b2013-01-24 14:25:36 +0100645 return ret;
646}
647
648static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
649 struct ieee80211_vif *vif)
650{
651 struct iwl_mvm *mvm = data;
652 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
653
654 mvmvif->uploaded = false;
655 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
656
657 /* does this make sense at all? */
658 mvmvif->color++;
659
660 spin_lock_bh(&mvm->time_event_lock);
661 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
662 spin_unlock_bh(&mvm->time_event_lock);
663
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200664 mvmvif->phy_ctxt = NULL;
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +0300665 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100666}
667
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300668#ifdef CONFIG_IWLWIFI_DEBUGFS
669static void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
670{
671 struct iwl_fw_error_dump_file *dump_file;
672 struct iwl_fw_error_dump_data *dump_data;
673 struct iwl_fw_error_dump_info *dump_info;
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300674 struct iwl_mvm_dump_ptrs *fw_error_dump;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300675 const struct fw_img *img;
676 u32 sram_len, sram_ofs;
677 u32 file_len, rxf_len;
678 unsigned long flags;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300679 int reg_val;
680
681 lockdep_assert_held(&mvm->mutex);
682
683 if (mvm->fw_error_dump)
684 return;
685
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300686 fw_error_dump = kzalloc(sizeof(*mvm->fw_error_dump), GFP_KERNEL);
687 if (!fw_error_dump)
688 return;
689
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300690 img = &mvm->fw->img[mvm->cur_ucode];
691 sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
692 sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
693
694 /* reading buffer size */
695 reg_val = iwl_trans_read_prph(mvm->trans, RXF_SIZE_ADDR);
696 rxf_len = (reg_val & RXF_SIZE_BYTE_CNT_MSK) >> RXF_SIZE_BYTE_CND_POS;
697
698 /* the register holds the value divided by 128 */
699 rxf_len = rxf_len << 7;
700
701 file_len = sizeof(*dump_file) +
702 sizeof(*dump_data) * 3 +
703 sram_len +
704 rxf_len +
705 sizeof(*dump_info);
706
Emmanuel Grumbach5bfe6f52014-06-25 16:21:43 +0300707 dump_file = vzalloc(file_len);
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300708 if (!dump_file) {
709 kfree(fw_error_dump);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300710 return;
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300711 }
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300712
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300713 fw_error_dump->op_mode_ptr = dump_file;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300714
715 dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300716 dump_data = (void *)dump_file->data;
717
718 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
719 dump_data->len = cpu_to_le32(sizeof(*dump_info));
720 dump_info = (void *) dump_data->data;
721 dump_info->device_family =
722 mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
723 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
724 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
725 memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
726 sizeof(dump_info->fw_human_readable));
727 strncpy(dump_info->dev_human_readable, mvm->cfg->name,
728 sizeof(dump_info->dev_human_readable));
729 strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
730 sizeof(dump_info->bus_human_readable));
731
732 dump_data = iwl_fw_error_next_data(dump_data);
733 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
734 dump_data->len = cpu_to_le32(rxf_len);
735
736 if (iwl_trans_grab_nic_access(mvm->trans, false, &flags)) {
737 u32 *rxf = (void *)dump_data->data;
738 int i;
739
740 for (i = 0; i < (rxf_len / sizeof(u32)); i++) {
741 iwl_trans_write_prph(mvm->trans,
742 RXF_LD_FENCE_OFFSET_ADDR,
743 i * sizeof(u32));
744 rxf[i] = iwl_trans_read_prph(mvm->trans,
745 RXF_FIFO_RD_FENCE_ADDR);
746 }
747 iwl_trans_release_nic_access(mvm->trans, &flags);
748 }
749
750 dump_data = iwl_fw_error_next_data(dump_data);
751 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_SRAM);
752 dump_data->len = cpu_to_le32(sram_len);
753 iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_data->data,
754 sram_len);
755
Emmanuel Grumbach48eb7b32014-07-08 19:45:17 +0300756 fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans);
757 fw_error_dump->op_mode_len = file_len;
758 if (fw_error_dump->trans_ptr)
759 file_len += fw_error_dump->trans_ptr->len;
760 dump_file->file_len = cpu_to_le32(file_len);
761 mvm->fw_error_dump = fw_error_dump;
Emmanuel Grumbach655e6d62014-06-25 14:08:58 +0300762}
763#endif
764
Johannes Berg8ca151b2013-01-24 14:25:36 +0100765static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
766{
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +0200767#ifdef CONFIG_IWLWIFI_DEBUGFS
768 static char *env[] = { "DRIVER=iwlwifi", "EVENT=error_dump", NULL };
769
770 iwl_mvm_fw_error_dump(mvm);
771
772 /* notify the userspace about the error we had */
773 kobject_uevent_env(&mvm->hw->wiphy->dev.kobj, KOBJ_CHANGE, env);
774#endif
775
Johannes Berg8ca151b2013-01-24 14:25:36 +0100776 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100777
778 mvm->scan_status = IWL_MVM_SCAN_NONE;
Luciano Coelhob1873302014-08-08 17:12:07 +0300779 mvm->ps_disabled = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100780
781 /* just in case one was running */
782 ieee80211_remain_on_channel_expired(mvm->hw);
783
784 ieee80211_iterate_active_interfaces_atomic(
785 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
786 iwl_mvm_cleanup_iterator, mvm);
787
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200788 mvm->p2p_device_vif = NULL;
Eliad Peller37577fe2013-12-05 17:19:39 +0200789 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200790
791 iwl_mvm_reset_phy_ctxts(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100792 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
793 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
Emmanuel Grumbach8a275ba2014-07-13 09:12:11 +0300794 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
795 memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
796 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
797 memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
798 memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk));
799 memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100800
801 ieee80211_wake_queues(mvm->hw);
802
Eliad Peller7498cf42014-01-16 17:10:44 +0200803 /* cleanup all stale references (scan, roc), but keep the
804 * ucode_down ref until reconfig is complete */
805 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
806
Eliad Peller228670b2014-08-10 17:00:15 +0300807 /* clear any stale d0i3 state */
808 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
809
Johannes Berg8ca151b2013-01-24 14:25:36 +0100810 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +0300811 mvm->rx_ba_sessions = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100812}
813
814static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
815{
816 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
817 int ret;
818
819 mutex_lock(&mvm->mutex);
820
821 /* Clean up some internal and mac80211 state on restart */
822 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
823 iwl_mvm_restart_cleanup(mvm);
824
825 ret = iwl_mvm_up(mvm);
Johannes Bergc47af222014-04-30 16:34:45 +0200826
827 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
828 /* Something went wrong - we need to finish some cleanup
829 * that normally iwl_mvm_mac_restart_complete() below
830 * would do.
831 */
832 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
833 iwl_mvm_d0i3_enable_tx(mvm, NULL);
834 }
835
Johannes Berg8ca151b2013-01-24 14:25:36 +0100836 mutex_unlock(&mvm->mutex);
837
838 return ret;
839}
840
841static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
842{
843 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
844 int ret;
845
846 mutex_lock(&mvm->mutex);
847
848 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
Arik Nemtsovb2492502014-03-13 12:21:50 +0200849 iwl_mvm_d0i3_enable_tx(mvm, NULL);
Johannes Berg01662302014-06-06 15:18:45 +0200850 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100851 if (ret)
852 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
853 ret);
854
Eliad Peller7498cf42014-01-16 17:10:44 +0200855 /* allow transport/FW low power modes */
856 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
857
Johannes Berg8ca151b2013-01-24 14:25:36 +0100858 mutex_unlock(&mvm->mutex);
859}
860
861static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
862{
863 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
864
Eliad Peller37577fe2013-12-05 17:19:39 +0200865 flush_work(&mvm->d0i3_exit_work);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100866 flush_work(&mvm->async_handlers_wk);
867
868 mutex_lock(&mvm->mutex);
Eliad Peller7498cf42014-01-16 17:10:44 +0200869
870 /* disallow low power states when the FW is down */
871 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
872
Johannes Berg8ca151b2013-01-24 14:25:36 +0100873 /* async_handlers_wk is now blocked */
874
875 /*
876 * The work item could be running or queued if the
877 * ROC time event stops just as we get here.
878 */
879 cancel_work_sync(&mvm->roc_done_wk);
880
881 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100882
883 iwl_mvm_async_handlers_purge(mvm);
884 /* async_handlers_list is empty and will stay empty: HW is stopped */
885
886 /* the fw is stopped, the aux sta is dead: clean up driver state */
887 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
888
889 mutex_unlock(&mvm->mutex);
890
891 /*
892 * The worker might have been waiting for the mutex, let it run and
893 * discover that its list is now empty.
894 */
895 cancel_work_sync(&mvm->async_handlers_wk);
896}
897
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200898static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
899{
900 u16 i;
901
902 lockdep_assert_held(&mvm->mutex);
903
904 for (i = 0; i < NUM_PHY_CTX; i++)
905 if (!mvm->phy_ctxts[i].ref)
906 return &mvm->phy_ctxts[i];
907
908 IWL_ERR(mvm, "No available PHY context\n");
909 return NULL;
910}
911
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +0200912static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
913 s8 tx_power)
914{
915 /* FW is in charge of regulatory enforcement */
916 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
917 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
918 .pwr_restriction = cpu_to_le16(tx_power),
919 };
920
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300921 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +0200922 sizeof(reduce_txpwr_cmd),
923 &reduce_txpwr_cmd);
924}
925
Johannes Berg8ca151b2013-01-24 14:25:36 +0100926static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
927 struct ieee80211_vif *vif)
928{
929 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
930 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
931 int ret;
932
933 /*
Gregory Greenmand40fc482014-06-25 14:08:50 +0200934 * make sure D0i3 exit is completed, otherwise a target access
935 * during tx queue configuration could be done when still in
936 * D0i3 state.
937 */
938 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
939 if (ret)
940 return ret;
941
942 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +0100943 * Not much to do here. The stack will not allow interface
944 * types or combinations that we didn't advertise, so we
945 * don't really have to check the types.
946 */
947
948 mutex_lock(&mvm->mutex);
949
Eliad Pellere89044d2013-07-16 17:33:26 +0300950 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100951 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
952 if (ret)
953 goto out_unlock;
954
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300955 /* Counting number of interfaces is needed for legacy PM */
Ilan Peerea183d02013-07-23 14:41:53 +0300956 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
957 mvm->vif_count++;
Ilan Peerea183d02013-07-23 14:41:53 +0300958
959 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +0100960 * The AP binding flow can be done only after the beacon
961 * template is configured (which happens only in the mac80211
962 * start_ap() flow), and adding the broadcast station can happen
963 * only after the binding.
964 * In addition, since modifying the MAC before adding a bcast
965 * station is not allowed by the FW, delay the adding of MAC context to
966 * the point where we can also add the bcast station.
967 * In short: there's not much we can do at this point, other than
968 * allocating resources :)
969 */
Johannes Berg5023d962013-07-31 14:07:43 +0200970 if (vif->type == NL80211_IFTYPE_AP ||
971 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100972 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
973 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
Eliad Pellerb92e6612014-01-23 17:58:23 +0200974 qmask,
975 ieee80211_vif_type_p2p(vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100976 if (ret) {
977 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
978 goto out_release;
979 }
980
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +0300981 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100982 goto out_unlock;
983 }
984
Johannes Berg8ca151b2013-01-24 14:25:36 +0100985 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
986 if (ret)
987 goto out_release;
988
Arik Nemtsov999609f2014-05-15 17:31:51 +0300989 ret = iwl_mvm_power_update_mac(mvm);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200990 if (ret)
991 goto out_release;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100992
Hila Gonen7df15b12012-12-12 11:16:19 +0200993 /* beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300994 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300995 if (ret)
996 goto out_remove_mac;
997
Hila Gonen7df15b12012-12-12 11:16:19 +0200998 if (!mvm->bf_allowed_vif &&
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +0300999 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001000 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001001 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1002 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +02001003 }
1004
Johannes Berg8ca151b2013-01-24 14:25:36 +01001005 /*
1006 * P2P_DEVICE interface does not have a channel context assigned to it,
1007 * so a dedicated PHY context is allocated to it and the corresponding
1008 * MAC context is bound to it at this stage.
1009 */
1010 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001011
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001012 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1013 if (!mvmvif->phy_ctxt) {
1014 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001015 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001016 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001017
Ilan Peer53a9d612013-04-28 11:55:08 +03001018 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001019 ret = iwl_mvm_binding_add_vif(mvm, vif);
1020 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +03001021 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001022
1023 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
1024 if (ret)
1025 goto out_unbind;
1026
1027 /* Save a pointer to p2p device vif, so it can later be used to
1028 * update the p2p device MAC when a GO is started/stopped */
1029 mvm->p2p_device_vif = vif;
1030 }
1031
Johannes Berg63494372013-03-26 10:47:53 +01001032 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001033 goto out_unlock;
1034
1035 out_unbind:
1036 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +03001037 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001038 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001039 out_free_bf:
1040 if (mvm->bf_allowed_vif == mvmvif) {
1041 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001042 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1043 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +03001044 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001045 out_remove_mac:
1046 mvmvif->phy_ctxt = NULL;
1047 iwl_mvm_mac_ctxt_remove(mvm, vif);
1048 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001049 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1050 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001051
Johannes Berg8ca151b2013-01-24 14:25:36 +01001052 iwl_mvm_mac_ctxt_release(mvm, vif);
1053 out_unlock:
1054 mutex_unlock(&mvm->mutex);
1055
Gregory Greenmand40fc482014-06-25 14:08:50 +02001056 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1057
Johannes Berg8ca151b2013-01-24 14:25:36 +01001058 return ret;
1059}
1060
Johannes Berg38a12b52013-02-22 14:07:56 +01001061static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1062 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001063{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001064 u32 tfd_msk = 0, ac;
1065
1066 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
1067 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
1068 tfd_msk |= BIT(vif->hw_queue[ac]);
1069
1070 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
1071 tfd_msk |= BIT(vif->cab_queue);
1072
1073 if (tfd_msk) {
1074 mutex_lock(&mvm->mutex);
1075 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
1076 mutex_unlock(&mvm->mutex);
1077 }
1078
1079 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1080 /*
1081 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1082 * We assume here that all the packets sent to the OFFCHANNEL
1083 * queue are sent in ROC session.
1084 */
1085 flush_work(&mvm->roc_done_wk);
1086 } else {
1087 /*
1088 * By now, all the AC queues are empty. The AGG queues are
1089 * empty too. We already got all the Tx responses for all the
1090 * packets in the queues. The drain work can have been
Emmanuel Grumbach0742a752013-06-10 14:10:33 +03001091 * triggered. Flush it.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001092 */
1093 flush_work(&mvm->sta_drained_wk);
1094 }
Johannes Berg38a12b52013-02-22 14:07:56 +01001095}
1096
1097static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1098 struct ieee80211_vif *vif)
1099{
1100 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1101 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1102
1103 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001104
1105 mutex_lock(&mvm->mutex);
1106
Hila Gonen7df15b12012-12-12 11:16:19 +02001107 if (mvm->bf_allowed_vif == mvmvif) {
1108 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001109 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1110 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +02001111 }
1112
Johannes Berg63494372013-03-26 10:47:53 +01001113 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1114
Johannes Berg8ca151b2013-01-24 14:25:36 +01001115 /*
1116 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +01001117 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +01001118 */
Johannes Berg5023d962013-07-31 14:07:43 +02001119 if (vif->type == NL80211_IFTYPE_AP ||
1120 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +03001121#ifdef CONFIG_NL80211_TESTMODE
1122 if (vif == mvm->noa_vif) {
1123 mvm->noa_vif = NULL;
1124 mvm->noa_duration = 0;
1125 }
1126#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001127 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
1128 goto out_release;
1129 }
1130
1131 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1132 mvm->p2p_device_vif = NULL;
1133 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1134 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001135 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001136 mvmvif->phy_ctxt = NULL;
1137 }
1138
Alexander Bondar5ee2b212013-03-05 10:16:40 +02001139 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001140 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +03001141
Arik Nemtsov999609f2014-05-15 17:31:51 +03001142 iwl_mvm_power_update_mac(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001143 iwl_mvm_mac_ctxt_remove(mvm, vif);
1144
1145out_release:
1146 iwl_mvm_mac_ctxt_release(mvm, vif);
1147 mutex_unlock(&mvm->mutex);
1148}
1149
1150static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1151{
1152 return 0;
1153}
1154
Eliad Pellere59647e2013-11-28 14:08:50 +02001155struct iwl_mvm_mc_iter_data {
1156 struct iwl_mvm *mvm;
1157 int port_id;
1158};
1159
1160static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1161 struct ieee80211_vif *vif)
1162{
1163 struct iwl_mvm_mc_iter_data *data = _data;
1164 struct iwl_mvm *mvm = data->mvm;
1165 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1166 int ret, len;
1167
1168 /* if we don't have free ports, mcast frames will be dropped */
1169 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1170 return;
1171
1172 if (vif->type != NL80211_IFTYPE_STATION ||
1173 !vif->bss_conf.assoc)
1174 return;
1175
1176 cmd->port_id = data->port_id++;
1177 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1178 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1179
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001180 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
Eliad Pellere59647e2013-11-28 14:08:50 +02001181 if (ret)
1182 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1183}
1184
1185static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1186{
1187 struct iwl_mvm_mc_iter_data iter_data = {
1188 .mvm = mvm,
1189 };
1190
1191 lockdep_assert_held(&mvm->mutex);
1192
1193 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1194 return;
1195
Emmanuel Grumbach1c4abec2014-05-08 09:48:10 +03001196 ieee80211_iterate_active_interfaces_atomic(
Eliad Pellere59647e2013-11-28 14:08:50 +02001197 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1198 iwl_mvm_mc_iface_iterator, &iter_data);
1199}
1200
1201static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1202 struct netdev_hw_addr_list *mc_list)
1203{
1204 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1205 struct iwl_mcast_filter_cmd *cmd;
1206 struct netdev_hw_addr *addr;
1207 int addr_count = netdev_hw_addr_list_count(mc_list);
1208 bool pass_all = false;
1209 int len;
1210
1211 if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) {
1212 pass_all = true;
1213 addr_count = 0;
1214 }
1215
1216 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1217 cmd = kzalloc(len, GFP_ATOMIC);
1218 if (!cmd)
1219 return 0;
1220
1221 if (pass_all) {
1222 cmd->pass_all = 1;
1223 return (u64)(unsigned long)cmd;
1224 }
1225
1226 netdev_hw_addr_list_for_each(addr, mc_list) {
1227 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1228 cmd->count, addr->addr);
1229 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1230 addr->addr, ETH_ALEN);
1231 cmd->count++;
1232 }
1233
1234 return (u64)(unsigned long)cmd;
1235}
1236
Johannes Berg8ca151b2013-01-24 14:25:36 +01001237static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1238 unsigned int changed_flags,
1239 unsigned int *total_flags,
1240 u64 multicast)
1241{
Eliad Pellere59647e2013-11-28 14:08:50 +02001242 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1243 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1244
1245 mutex_lock(&mvm->mutex);
1246
1247 /* replace previous configuration */
1248 kfree(mvm->mcast_filter_cmd);
1249 mvm->mcast_filter_cmd = cmd;
1250
1251 if (!cmd)
1252 goto out;
1253
1254 iwl_mvm_recalc_multicast(mvm);
1255out:
1256 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001257 *total_flags = 0;
1258}
1259
Eliad Pellerc87163b2014-01-08 10:11:11 +02001260#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1261struct iwl_bcast_iter_data {
1262 struct iwl_mvm *mvm;
1263 struct iwl_bcast_filter_cmd *cmd;
1264 u8 current_filter;
1265};
1266
1267static void
1268iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1269 const struct iwl_fw_bcast_filter *in_filter,
1270 struct iwl_fw_bcast_filter *out_filter)
1271{
1272 struct iwl_fw_bcast_filter_attr *attr;
1273 int i;
1274
1275 memcpy(out_filter, in_filter, sizeof(*out_filter));
1276
1277 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1278 attr = &out_filter->attrs[i];
1279
1280 if (!attr->mask)
1281 break;
1282
Eliad Peller2ee8f022014-01-13 19:07:09 +02001283 switch (attr->reserved1) {
1284 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1285 if (vif->bss_conf.arp_addr_cnt != 1) {
1286 attr->mask = 0;
1287 continue;
1288 }
1289
1290 attr->val = vif->bss_conf.arp_addr_list[0];
1291 break;
1292 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1293 attr->val = *(__be32 *)&vif->addr[2];
1294 break;
1295 default:
1296 break;
1297 }
1298 attr->reserved1 = 0;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001299 out_filter->num_attrs++;
1300 }
1301}
1302
1303static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1304 struct ieee80211_vif *vif)
1305{
1306 struct iwl_bcast_iter_data *data = _data;
1307 struct iwl_mvm *mvm = data->mvm;
1308 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1309 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1310 struct iwl_fw_bcast_mac *bcast_mac;
1311 int i;
1312
1313 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1314 return;
1315
1316 bcast_mac = &cmd->macs[mvmvif->id];
1317
Ilan Peere48393e2014-05-22 11:19:02 +03001318 /*
1319 * enable filtering only for associated stations, but not for P2P
1320 * Clients
1321 */
1322 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1323 !vif->bss_conf.assoc)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001324 return;
1325
1326 bcast_mac->default_discard = 1;
1327
1328 /* copy all configured filters */
1329 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1330 /*
1331 * Make sure we don't exceed our filters limit.
1332 * if there is still a valid filter to be configured,
1333 * be on the safe side and just allow bcast for this mac.
1334 */
1335 if (WARN_ON_ONCE(data->current_filter >=
1336 ARRAY_SIZE(cmd->filters))) {
1337 bcast_mac->default_discard = 0;
1338 bcast_mac->attached_filters = 0;
1339 break;
1340 }
1341
1342 iwl_mvm_set_bcast_filter(vif,
1343 &mvm->bcast_filters[i],
1344 &cmd->filters[data->current_filter]);
1345
1346 /* skip current filter if it contains no attributes */
1347 if (!cmd->filters[data->current_filter].num_attrs)
1348 continue;
1349
1350 /* attach the filter to current mac */
1351 bcast_mac->attached_filters |=
1352 cpu_to_le16(BIT(data->current_filter));
1353
1354 data->current_filter++;
1355 }
1356}
1357
Eliad Pellerde06a592014-01-08 10:11:12 +02001358bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1359 struct iwl_bcast_filter_cmd *cmd)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001360{
Eliad Pellerc87163b2014-01-08 10:11:11 +02001361 struct iwl_bcast_iter_data iter_data = {
1362 .mvm = mvm,
Eliad Pellerde06a592014-01-08 10:11:12 +02001363 .cmd = cmd,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001364 };
1365
Eliad Pellerde06a592014-01-08 10:11:12 +02001366 memset(cmd, 0, sizeof(*cmd));
1367 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1368 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1369
1370#ifdef CONFIG_IWLWIFI_DEBUGFS
1371 /* use debugfs filters/macs if override is configured */
1372 if (mvm->dbgfs_bcast_filtering.override) {
1373 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1374 sizeof(cmd->filters));
1375 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1376 sizeof(cmd->macs));
1377 return true;
1378 }
1379#endif
Eliad Pellerc87163b2014-01-08 10:11:11 +02001380
1381 /* if no filters are configured, do nothing */
1382 if (!mvm->bcast_filters)
Eliad Pellerde06a592014-01-08 10:11:12 +02001383 return false;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001384
1385 /* configure and attach these filters for each associated sta vif */
1386 ieee80211_iterate_active_interfaces(
1387 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1388 iwl_mvm_bcast_filter_iterator, &iter_data);
1389
Eliad Pellerde06a592014-01-08 10:11:12 +02001390 return true;
1391}
1392static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1393 struct ieee80211_vif *vif)
1394{
1395 struct iwl_bcast_filter_cmd cmd;
1396
1397 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1398 return 0;
1399
1400 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1401 return 0;
1402
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001403 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001404 sizeof(cmd), &cmd);
1405}
1406#else
1407static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1408 struct ieee80211_vif *vif)
1409{
1410 return 0;
1411}
1412#endif
1413
Arik Nemtsovf6972672014-06-15 16:03:55 +03001414static void iwl_mvm_teardown_tdls_peers(struct iwl_mvm *mvm)
1415{
1416 struct ieee80211_sta *sta;
1417 struct iwl_mvm_sta *mvmsta;
1418 int i;
1419
1420 lockdep_assert_held(&mvm->mutex);
1421
1422 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
1423 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
1424 lockdep_is_held(&mvm->mutex));
1425 if (!sta || IS_ERR(sta) || !sta->tdls)
1426 continue;
1427
1428 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1429 ieee80211_tdls_oper_request(mvmsta->vif, sta->addr,
1430 NL80211_TDLS_TEARDOWN,
1431 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED,
1432 GFP_KERNEL);
1433 }
1434}
1435
Johannes Berg8ca151b2013-01-24 14:25:36 +01001436static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1437 struct ieee80211_vif *vif,
1438 struct ieee80211_bss_conf *bss_conf,
1439 u32 changes)
1440{
1441 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1442 int ret;
1443
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001444 /*
1445 * Re-calculate the tsf id, as the master-slave relations depend on the
1446 * beacon interval, which was not known when the station interface was
1447 * added.
1448 */
1449 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1450 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1451
Luciano Coelhobca49d92014-05-13 17:33:38 +03001452 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001453 if (ret)
1454 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1455
1456 if (changes & BSS_CHANGED_ASSOC) {
1457 if (bss_conf->assoc) {
1458 /* add quota for this interface */
Johannes Berg01662302014-06-06 15:18:45 +02001459 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001460 if (ret) {
1461 IWL_ERR(mvm, "failed to update quotas\n");
1462 return;
1463 }
Johannes Berg016d27e2013-05-03 11:16:15 +02001464
1465 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1466 &mvm->status)) {
1467 /*
1468 * If we're restarting then the firmware will
1469 * obviously have lost synchronisation with
1470 * the AP. It will attempt to synchronise by
1471 * itself, but we can make it more reliable by
1472 * scheduling a session protection time event.
1473 *
1474 * The firmware needs to receive a beacon to
1475 * catch up with synchronisation, use 110% of
1476 * the beacon interval.
1477 *
1478 * Set a large maximum delay to allow for more
1479 * than a single interface.
1480 */
1481 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1482 iwl_mvm_protect_session(mvm, vif, dur, dur,
1483 5 * dur);
1484 }
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001485
1486 iwl_mvm_sf_update(mvm, vif, false);
Alexander Bondar175a70b2013-04-14 20:59:37 +03001487 iwl_mvm_power_vif_assoc(mvm, vif);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001488 if (vif->p2p) {
Eliad Peller29a90a42013-11-05 14:06:29 +02001489 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
Emmanuel Grumbach697162a2014-07-30 15:56:42 +03001490 iwl_mvm_update_smps(mvm, vif,
1491 IWL_MVM_SMPS_REQ_PROT,
1492 IEEE80211_SMPS_DYNAMIC);
1493 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001494 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001495 /*
1496 * If update fails - SF might be running in associated
1497 * mode while disassociated - which is forbidden.
1498 */
1499 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1500 "Failed to update SF upon disassociation\n");
1501
Johannes Berg8ca151b2013-01-24 14:25:36 +01001502 /* remove AP station now that the MAC is unassoc */
1503 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1504 if (ret)
1505 IWL_ERR(mvm, "failed to remove AP station\n");
Eliad Peller37577fe2013-12-05 17:19:39 +02001506
1507 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1508 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001509 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1510 /* remove quota for this interface */
Johannes Berg01662302014-06-06 15:18:45 +02001511 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001512 if (ret)
1513 IWL_ERR(mvm, "failed to update quotas\n");
Eliad Peller29a90a42013-11-05 14:06:29 +02001514
1515 if (vif->p2p)
1516 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001517 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001518
Eliad Pellere59647e2013-11-28 14:08:50 +02001519 iwl_mvm_recalc_multicast(mvm);
Eliad Pellerc87163b2014-01-08 10:11:11 +02001520 iwl_mvm_configure_bcast_filter(mvm, vif);
Eliad Pellere59647e2013-11-28 14:08:50 +02001521
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001522 /* reset rssi values */
1523 mvmvif->bf_data.ave_beacon_signal = 0;
1524
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001525 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachf94045e2014-01-06 13:38:55 +02001526 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1527 IEEE80211_SMPS_AUTOMATIC);
Alexander Bondar989c6502013-05-16 17:34:17 +03001528 } else if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +01001529 /*
1530 * We received a beacon _after_ association so
1531 * remove the session protection.
1532 */
1533 iwl_mvm_remove_time_event(mvm, mvmvif,
1534 &mvmvif->time_event_data);
Alexander Bondar51498cf62013-09-02 17:10:14 +03001535 } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS |
1536 BSS_CHANGED_QOS)) {
Arik Nemtsov999609f2014-05-15 17:31:51 +03001537 ret = iwl_mvm_power_update_mac(mvm);
Alexander Bondar4bf881f2013-05-29 10:19:50 +03001538 if (ret)
1539 IWL_ERR(mvm, "failed to update power mode\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001540 }
Eran Hararycc87d322014-07-15 14:04:23 +03001541
1542 if (changes & BSS_CHANGED_BEACON_INFO) {
1543 iwl_mvm_sf_update(mvm, vif, false);
1544 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
1545 }
1546
Matti Gottlieb88f2fd72013-07-09 15:25:46 +03001547 if (changes & BSS_CHANGED_TXPOWER) {
1548 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1549 bss_conf->txpower);
1550 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1551 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001552
1553 if (changes & BSS_CHANGED_CQM) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02001554 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001555 /* reset cqm events tracking */
1556 mvmvif->bf_data.last_cqm_event = 0;
Avri Altmanfa7b2e72014-05-20 08:03:24 +03001557 if (mvmvif->bf_data.bf_enabled) {
1558 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1559 if (ret)
1560 IWL_ERR(mvm,
1561 "failed to update CQM thresholds\n");
1562 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001563 }
Eliad Peller2ee8f022014-01-13 19:07:09 +02001564
1565 if (changes & BSS_CHANGED_ARP_FILTER) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02001566 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
Eliad Peller2ee8f022014-01-13 19:07:09 +02001567 iwl_mvm_configure_bcast_filter(mvm, vif);
1568 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001569}
1570
Johannes Berg5023d962013-07-31 14:07:43 +02001571static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1572 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001573{
1574 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1575 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1576 int ret;
1577
Eliad Peller576eeee2014-07-01 18:38:38 +03001578 /*
1579 * iwl_mvm_mac_ctxt_add() might read directly from the device
1580 * (the system time), so make sure it is available.
1581 */
1582 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
1583 if (ret)
1584 return ret;
1585
Johannes Berg8ca151b2013-01-24 14:25:36 +01001586 mutex_lock(&mvm->mutex);
1587
1588 /* Send the beacon template */
1589 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1590 if (ret)
1591 goto out_unlock;
1592
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001593 /*
1594 * Re-calculate the tsf id, as the master-slave relations depend on the
1595 * beacon interval, which was not known when the AP interface was added.
1596 */
1597 if (vif->type == NL80211_IFTYPE_AP)
1598 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1599
Johannes Berg8ca151b2013-01-24 14:25:36 +01001600 /* Add the mac context */
1601 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1602 if (ret)
1603 goto out_unlock;
1604
1605 /* Perform the binding */
1606 ret = iwl_mvm_binding_add_vif(mvm, vif);
1607 if (ret)
1608 goto out_remove;
1609
Johannes Berg8ca151b2013-01-24 14:25:36 +01001610 /* Send the bcast station. At this stage the TBTT and DTIM time events
1611 * are added and applied to the scheduler */
1612 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
1613 if (ret)
1614 goto out_unbind;
1615
Ilan Peer5691e212013-12-31 21:05:50 +02001616 /* must be set before quota calculations */
1617 mvmvif->ap_ibss_active = true;
1618
Ilan Peera11e1442013-12-31 21:19:55 +02001619 /* power updated needs to be done before quotas */
Arik Nemtsov999609f2014-05-15 17:31:51 +03001620 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02001621
Johannes Berg01662302014-06-06 15:18:45 +02001622 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001623 if (ret)
Ilan Peera11e1442013-12-31 21:19:55 +02001624 goto out_quota_failed;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001625
Johannes Berg5023d962013-07-31 14:07:43 +02001626 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001627 if (vif->p2p && mvm->p2p_device_vif)
Luciano Coelhobca49d92014-05-13 17:33:38 +03001628 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001629
Eliad Peller29a90a42013-11-05 14:06:29 +02001630 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1631
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001632 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001633
Arik Nemtsovf6972672014-06-15 16:03:55 +03001634 /* we don't support TDLS during DCM */
1635 if (iwl_mvm_phy_ctx_count(mvm) > 1)
1636 iwl_mvm_teardown_tdls_peers(mvm);
1637
Johannes Berg8ca151b2013-01-24 14:25:36 +01001638 mutex_unlock(&mvm->mutex);
1639 return 0;
1640
Ilan Peera11e1442013-12-31 21:19:55 +02001641out_quota_failed:
Arik Nemtsov999609f2014-05-15 17:31:51 +03001642 iwl_mvm_power_update_mac(mvm);
Ilan Peer5691e212013-12-31 21:05:50 +02001643 mvmvif->ap_ibss_active = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001644 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1645out_unbind:
1646 iwl_mvm_binding_remove_vif(mvm, vif);
1647out_remove:
1648 iwl_mvm_mac_ctxt_remove(mvm, vif);
1649out_unlock:
1650 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03001651 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001652 return ret;
1653}
1654
Johannes Berg5023d962013-07-31 14:07:43 +02001655static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
1656 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001657{
1658 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1659 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1660
Johannes Berg38a12b52013-02-22 14:07:56 +01001661 iwl_mvm_prepare_mac_removal(mvm, vif);
1662
Johannes Berg8ca151b2013-01-24 14:25:36 +01001663 mutex_lock(&mvm->mutex);
1664
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03001665 /* Handle AP stop while in CSA */
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03001666 if (rcu_access_pointer(mvm->csa_vif) == vif) {
1667 iwl_mvm_remove_time_event(mvm, mvmvif,
1668 &mvmvif->time_event_data);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03001669 RCU_INIT_POINTER(mvm->csa_vif, NULL);
Andrei Otcheretianski7f0a7c62014-05-04 11:48:12 +03001670 }
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03001671
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03001672 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
1673 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
1674 mvm->csa_tx_block_bcn_timeout = 0;
1675 }
1676
Johannes Berg5023d962013-07-31 14:07:43 +02001677 mvmvif->ap_ibss_active = false;
David Spinadel1c87bba2014-02-27 16:41:52 +02001678 mvm->ap_last_beacon_gp2 = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001679
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001680 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001681
Eliad Peller29a90a42013-11-05 14:06:29 +02001682 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
1683
Johannes Berg5023d962013-07-31 14:07:43 +02001684 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001685 if (vif->p2p && mvm->p2p_device_vif)
Luciano Coelhobca49d92014-05-13 17:33:38 +03001686 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001687
Johannes Berg01662302014-06-06 15:18:45 +02001688 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001689 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1690 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02001691
Arik Nemtsov999609f2014-05-15 17:31:51 +03001692 iwl_mvm_power_update_mac(mvm);
Ilan Peera11e1442013-12-31 21:19:55 +02001693
Johannes Berg8ca151b2013-01-24 14:25:36 +01001694 iwl_mvm_mac_ctxt_remove(mvm, vif);
1695
1696 mutex_unlock(&mvm->mutex);
1697}
1698
Johannes Berg5023d962013-07-31 14:07:43 +02001699static void
1700iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
1701 struct ieee80211_vif *vif,
1702 struct ieee80211_bss_conf *bss_conf,
1703 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001704{
Ilan Peerbe2056f2013-12-04 16:47:14 +02001705 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman8a5e3662013-11-12 19:16:03 +02001706
Ilan Peerbe2056f2013-12-04 16:47:14 +02001707 /* Changes will be applied when the AP/IBSS is started */
1708 if (!mvmvif->ap_ibss_active)
1709 return;
1710
Johannes Berg863230da2013-12-04 17:08:40 +01001711 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
1712 BSS_CHANGED_BANDWIDTH) &&
Luciano Coelhobca49d92014-05-13 17:33:38 +03001713 iwl_mvm_mac_ctxt_changed(mvm, vif, false))
Johannes Berg863230da2013-12-04 17:08:40 +01001714 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
Avri Altman8a5e3662013-11-12 19:16:03 +02001715
Johannes Berg8ca151b2013-01-24 14:25:36 +01001716 /* Need to send a new beacon template to the FW */
Johannes Berg863230da2013-12-04 17:08:40 +01001717 if (changes & BSS_CHANGED_BEACON &&
1718 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1719 IWL_WARN(mvm, "Failed updating beacon data\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001720}
1721
1722static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1723 struct ieee80211_vif *vif,
1724 struct ieee80211_bss_conf *bss_conf,
1725 u32 changes)
1726{
1727 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1728
Eliad Peller576eeee2014-07-01 18:38:38 +03001729 /*
1730 * iwl_mvm_bss_info_changed_station() might call
1731 * iwl_mvm_protect_session(), which reads directly from
1732 * the device (the system time), so make sure it is available.
1733 */
1734 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
1735 return;
1736
Johannes Berg8ca151b2013-01-24 14:25:36 +01001737 mutex_lock(&mvm->mutex);
1738
David Spinadel723f02e2014-04-27 09:54:54 +03001739 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
David Spinadelfb98be52014-05-04 12:51:10 +03001740 iwl_mvm_scan_offload_stop(mvm, true);
David Spinadel723f02e2014-04-27 09:54:54 +03001741
Johannes Berg8ca151b2013-01-24 14:25:36 +01001742 switch (vif->type) {
1743 case NL80211_IFTYPE_STATION:
1744 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1745 break;
1746 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02001747 case NL80211_IFTYPE_ADHOC:
1748 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001749 break;
1750 default:
1751 /* shouldn't happen */
1752 WARN_ON_ONCE(1);
1753 }
1754
1755 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03001756 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001757}
1758
Eliad Peller4660dfb2014-06-22 18:15:59 +03001759static int iwl_mvm_cancel_scan_wait_notif(struct iwl_mvm *mvm,
1760 enum iwl_scan_status scan_type)
1761{
1762 int ret;
1763 bool wait_for_handlers = false;
1764
1765 mutex_lock(&mvm->mutex);
1766
1767 if (mvm->scan_status != scan_type) {
1768 ret = 0;
1769 /* make sure there are no pending notifications */
1770 wait_for_handlers = true;
1771 goto out;
1772 }
1773
1774 switch (scan_type) {
1775 case IWL_MVM_SCAN_SCHED:
1776 ret = iwl_mvm_scan_offload_stop(mvm, true);
1777 break;
1778 case IWL_MVM_SCAN_OS:
1779 ret = iwl_mvm_cancel_scan(mvm);
1780 break;
1781 case IWL_MVM_SCAN_NONE:
1782 default:
1783 WARN_ON_ONCE(1);
1784 ret = -EINVAL;
1785 break;
1786 }
1787 if (ret)
1788 goto out;
1789
1790 wait_for_handlers = true;
1791out:
1792 mutex_unlock(&mvm->mutex);
1793
1794 /* make sure we consume the completion notification */
1795 if (wait_for_handlers)
1796 iwl_mvm_wait_for_async_handlers(mvm);
1797
1798 return ret;
1799}
Johannes Berg8ca151b2013-01-24 14:25:36 +01001800static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
1801 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02001802 struct ieee80211_scan_request *hw_req)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001803{
1804 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
David Spinadelc56ef672014-02-05 15:21:13 +02001805 struct cfg80211_scan_request *req = &hw_req->req;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001806 int ret;
1807
David Spinadel762533b2014-06-05 11:20:43 +03001808 if (req->n_channels == 0 ||
1809 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001810 return -EINVAL;
1811
Eliad Peller4660dfb2014-06-22 18:15:59 +03001812 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_SCHED);
1813 if (ret)
1814 return ret;
1815
Johannes Berg8ca151b2013-01-24 14:25:36 +01001816 mutex_lock(&mvm->mutex);
1817
Eliad Peller4660dfb2014-06-22 18:15:59 +03001818 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001819 ret = -EBUSY;
Arik Nemtsov519e2022013-10-17 17:51:35 +03001820 goto out;
1821 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001822
Arik Nemtsov519e2022013-10-17 17:51:35 +03001823 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
1824
David Spinadelfb98be52014-05-04 12:51:10 +03001825 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
1826 ret = iwl_mvm_unified_scan_lmac(mvm, vif, hw_req);
1827 else
1828 ret = iwl_mvm_scan_request(mvm, vif, req);
1829
Arik Nemtsov519e2022013-10-17 17:51:35 +03001830 if (ret)
1831 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1832out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001833 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001834 return ret;
1835}
1836
1837static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1838 struct ieee80211_vif *vif)
1839{
1840 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1841
1842 mutex_lock(&mvm->mutex);
1843
1844 iwl_mvm_cancel_scan(mvm);
1845
1846 mutex_unlock(&mvm->mutex);
1847}
1848
1849static void
1850iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
Johannes Berg3e56ead2013-02-15 22:23:18 +01001851 struct ieee80211_sta *sta, u16 tids,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001852 int num_frames,
1853 enum ieee80211_frame_release_type reason,
1854 bool more_data)
1855{
1856 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001857
Johannes Berg3e56ead2013-02-15 22:23:18 +01001858 /* Called when we need to transmit (a) frame(s) from mac80211 */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001859
Johannes Berg3e56ead2013-02-15 22:23:18 +01001860 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1861 tids, more_data, false);
1862}
1863
1864static void
1865iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
1866 struct ieee80211_sta *sta, u16 tids,
1867 int num_frames,
1868 enum ieee80211_frame_release_type reason,
1869 bool more_data)
1870{
1871 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1872
1873 /* Called when we need to transmit (a) frame(s) from agg queue */
1874
1875 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1876 tids, more_data, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001877}
1878
1879static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1880 struct ieee80211_vif *vif,
1881 enum sta_notify_cmd cmd,
1882 struct ieee80211_sta *sta)
1883{
1884 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01001885 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg3e56ead2013-02-15 22:23:18 +01001886 int tid;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001887
1888 switch (cmd) {
1889 case STA_NOTIFY_SLEEP:
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03001890 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001891 ieee80211_sta_block_awake(hw, sta, true);
Johannes Berg3e56ead2013-02-15 22:23:18 +01001892 spin_lock_bh(&mvmsta->lock);
1893 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
1894 struct iwl_mvm_tid_data *tid_data;
1895
1896 tid_data = &mvmsta->tid_data[tid];
1897 if (tid_data->state != IWL_AGG_ON &&
1898 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
1899 continue;
1900 if (iwl_mvm_tid_queued(tid_data) == 0)
1901 continue;
1902 ieee80211_sta_set_buffered(sta, tid, true);
1903 }
1904 spin_unlock_bh(&mvmsta->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001905 /*
1906 * The fw updates the STA to be asleep. Tx packets on the Tx
1907 * queues to this station will not be transmitted. The fw will
1908 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1909 */
1910 break;
1911 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02001912 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01001913 break;
Johannes Berg9cc40712013-02-15 22:47:48 +01001914 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001915 break;
1916 default:
1917 break;
1918 }
1919}
1920
Johannes Berg1ddbbb02013-12-04 22:39:17 +01001921static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
1922 struct ieee80211_vif *vif,
1923 struct ieee80211_sta *sta)
1924{
1925 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1926 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1927
1928 /*
1929 * This is called before mac80211 does RCU synchronisation,
1930 * so here we already invalidate our internal RCU-protected
1931 * station pointer. The rest of the code will thus no longer
1932 * be able to find the station this way, and we don't rely
1933 * on further RCU synchronisation after the sta_state()
1934 * callback deleted the station.
1935 */
1936 mutex_lock(&mvm->mutex);
1937 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
1938 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1939 ERR_PTR(-ENOENT));
1940 mutex_unlock(&mvm->mutex);
1941}
1942
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03001943int iwl_mvm_tdls_sta_count(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03001944{
1945 struct ieee80211_sta *sta;
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03001946 struct iwl_mvm_sta *mvmsta;
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03001947 int count = 0;
1948 int i;
1949
1950 lockdep_assert_held(&mvm->mutex);
1951
1952 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
1953 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
1954 lockdep_is_held(&mvm->mutex));
1955 if (!sta || IS_ERR(sta) || !sta->tdls)
1956 continue;
1957
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03001958 if (vif) {
1959 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1960 if (mvmsta->vif != vif)
1961 continue;
1962 }
1963
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03001964 count++;
1965 }
1966
1967 return count;
1968}
1969
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03001970static void iwl_mvm_recalc_tdls_state(struct iwl_mvm *mvm,
1971 struct ieee80211_vif *vif,
1972 bool sta_added)
1973{
1974 int tdls_sta_cnt = iwl_mvm_tdls_sta_count(mvm, vif);
1975
1976 /*
1977 * Disable ps when the first TDLS sta is added and re-enable it
1978 * when the last TDLS sta is removed
1979 */
1980 if ((tdls_sta_cnt == 1 && sta_added) ||
1981 (tdls_sta_cnt == 0 && !sta_added))
1982 iwl_mvm_power_update_mac(mvm);
1983}
1984
Johannes Berg8ca151b2013-01-24 14:25:36 +01001985static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1986 struct ieee80211_vif *vif,
1987 struct ieee80211_sta *sta,
1988 enum ieee80211_sta_state old_state,
1989 enum ieee80211_sta_state new_state)
1990{
1991 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1992 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1993 int ret;
1994
1995 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1996 sta->addr, old_state, new_state);
1997
1998 /* this would be a mac80211 bug ... but don't crash */
1999 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2000 return -EINVAL;
2001
2002 /* if a STA is being removed, reuse its ID */
2003 flush_work(&mvm->sta_drained_wk);
2004
2005 mutex_lock(&mvm->mutex);
2006 if (old_state == IEEE80211_STA_NOTEXIST &&
2007 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02002008 /*
2009 * Firmware bug - it'll crash if the beacon interval is less
2010 * than 16. We can't avoid connecting at all, so refuse the
2011 * station state change, this will cause mac80211 to abandon
2012 * attempts to connect to this AP, and eventually wpa_s will
2013 * blacklist the AP...
2014 */
2015 if (vif->type == NL80211_IFTYPE_STATION &&
2016 vif->bss_conf.beacon_int < 16) {
2017 IWL_ERR(mvm,
2018 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2019 sta->addr, vif->bss_conf.beacon_int);
2020 ret = -EINVAL;
2021 goto out_unlock;
2022 }
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002023
2024 if (sta->tdls &&
2025 (vif->p2p ||
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002026 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2027 IWL_MVM_TDLS_STA_COUNT ||
Arik Nemtsovcf7b4912014-05-15 11:44:40 +03002028 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2029 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2030 ret = -EBUSY;
2031 goto out_unlock;
2032 }
2033
Johannes Berg8ca151b2013-01-24 14:25:36 +01002034 ret = iwl_mvm_add_sta(mvm, vif, sta);
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002035 if (sta->tdls && ret == 0)
2036 iwl_mvm_recalc_tdls_state(mvm, vif, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002037 } else if (old_state == IEEE80211_STA_NONE &&
2038 new_state == IEEE80211_STA_AUTH) {
Haim Dreyfusse820c2d2014-04-06 11:19:09 +03002039 /*
2040 * EBS may be disabled due to previous failures reported by FW.
2041 * Reset EBS status here assuming environment has been changed.
2042 */
2043 mvm->last_ebs_successful = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002044 ret = 0;
2045 } else if (old_state == IEEE80211_STA_AUTH &&
2046 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01002047 ret = iwl_mvm_update_sta(mvm, vif, sta);
2048 if (ret == 0)
2049 iwl_mvm_rs_rate_init(mvm, sta,
Eyal Shapirab87c2172013-11-09 23:37:55 +02002050 mvmvif->phy_ctxt->channel->band,
2051 true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002052 } else if (old_state == IEEE80211_STA_ASSOC &&
2053 new_state == IEEE80211_STA_AUTHORIZED) {
Arik Nemtsovf59e0e3c2014-06-10 19:56:27 +03002054
2055 /* we don't support TDLS during DCM */
2056 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2057 iwl_mvm_teardown_tdls_peers(mvm);
2058
Hila Gonen7df15b12012-12-12 11:16:19 +02002059 /* enable beacon filtering */
Avri Altmanfa7b2e72014-05-20 08:03:24 +03002060 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002061 ret = 0;
2062 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2063 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02002064 /* disable beacon filtering */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002065 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
Johannes Berg8ca151b2013-01-24 14:25:36 +01002066 ret = 0;
2067 } else if (old_state == IEEE80211_STA_ASSOC &&
2068 new_state == IEEE80211_STA_AUTH) {
2069 ret = 0;
2070 } else if (old_state == IEEE80211_STA_AUTH &&
2071 new_state == IEEE80211_STA_NONE) {
2072 ret = 0;
2073 } else if (old_state == IEEE80211_STA_NONE &&
2074 new_state == IEEE80211_STA_NOTEXIST) {
2075 ret = iwl_mvm_rm_sta(mvm, vif, sta);
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +03002076 if (sta->tdls)
2077 iwl_mvm_recalc_tdls_state(mvm, vif, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002078 } else {
2079 ret = -EIO;
2080 }
Johannes Berg48bc1302013-07-04 15:55:29 +02002081 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002082 mutex_unlock(&mvm->mutex);
2083
2084 return ret;
2085}
2086
2087static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2088{
2089 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2090
2091 mvm->rts_threshold = value;
2092
2093 return 0;
2094}
2095
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002096static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2097 struct ieee80211_vif *vif,
2098 struct ieee80211_sta *sta, u32 changed)
2099{
2100 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2101
2102 if (vif->type == NL80211_IFTYPE_STATION &&
2103 changed & IEEE80211_RC_NSS_CHANGED)
2104 iwl_mvm_sf_update(mvm, vif, false);
2105}
2106
Johannes Berg8ca151b2013-01-24 14:25:36 +01002107static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2108 struct ieee80211_vif *vif, u16 ac,
2109 const struct ieee80211_tx_queue_params *params)
2110{
2111 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2112 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2113
2114 mvmvif->queue_params[ac] = *params;
2115
2116 /*
2117 * No need to update right away, we'll get BSS_CHANGED_QOS
2118 * The exception is P2P_DEVICE interface which needs immediate update.
2119 */
2120 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2121 int ret;
2122
2123 mutex_lock(&mvm->mutex);
Luciano Coelhobca49d92014-05-13 17:33:38 +03002124 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002125 mutex_unlock(&mvm->mutex);
2126 return ret;
2127 }
2128 return 0;
2129}
2130
2131static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2132 struct ieee80211_vif *vif)
2133{
2134 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2135 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
2136 200 + vif->bss_conf.beacon_int);
2137 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
2138 100 + vif->bss_conf.beacon_int);
2139
2140 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2141 return;
2142
Eliad Peller576eeee2014-07-01 18:38:38 +03002143 /*
2144 * iwl_mvm_protect_session() reads directly from the device
2145 * (the system time), so make sure it is available.
2146 */
2147 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2148 return;
2149
Johannes Berg8ca151b2013-01-24 14:25:36 +01002150 mutex_lock(&mvm->mutex);
2151 /* Try really hard to protect the session and hear a beacon */
Johannes Berg016d27e2013-05-03 11:16:15 +02002152 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002153 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002154
2155 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002156}
2157
Arik Nemtsov07ecd892014-05-20 18:16:42 +03002158static void iwl_mvm_mac_mgd_protect_tdls_discover(struct ieee80211_hw *hw,
2159 struct ieee80211_vif *vif)
2160{
2161 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2162 u32 duration = 2 * vif->bss_conf.dtim_period * vif->bss_conf.beacon_int;
2163
Eliad Peller576eeee2014-07-01 18:38:38 +03002164 /*
2165 * iwl_mvm_protect_session() reads directly from the device
2166 * (the system time), so make sure it is available.
2167 */
2168 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_TDLS))
2169 return;
2170
Arik Nemtsov07ecd892014-05-20 18:16:42 +03002171 mutex_lock(&mvm->mutex);
2172 /* Protect the session to hear the TDLS setup response on the channel */
2173 iwl_mvm_protect_session(mvm, vif, duration, duration, 100);
2174 mutex_unlock(&mvm->mutex);
Eliad Peller576eeee2014-07-01 18:38:38 +03002175
2176 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_TDLS);
Arik Nemtsov07ecd892014-05-20 18:16:42 +03002177}
2178
David Spinadel35a000b2013-08-28 09:29:43 +03002179static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2180 struct ieee80211_vif *vif,
2181 struct cfg80211_sched_scan_request *req,
David Spinadel633e2712014-02-06 16:15:23 +02002182 struct ieee80211_scan_ies *ies)
David Spinadel35a000b2013-08-28 09:29:43 +03002183{
2184 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2185 int ret;
2186
Eliad Peller4660dfb2014-06-22 18:15:59 +03002187 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_OS);
2188 if (ret)
2189 return ret;
2190
David Spinadel35a000b2013-08-28 09:29:43 +03002191 mutex_lock(&mvm->mutex);
2192
David Spinadelb538b8c2014-05-13 14:29:36 +03002193 if (!iwl_mvm_is_idle(mvm)) {
David Spinadelbd5e4742014-04-24 13:15:29 +03002194 ret = -EBUSY;
2195 goto out;
2196 }
2197
Eliad Peller4660dfb2014-06-22 18:15:59 +03002198 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
David Spinadel35a000b2013-08-28 09:29:43 +03002199 ret = -EBUSY;
2200 goto out;
2201 }
2202
2203 mvm->scan_status = IWL_MVM_SCAN_SCHED;
2204
David Spinadelfb98be52014-05-04 12:51:10 +03002205 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)) {
2206 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
2207 if (ret)
2208 goto err;
2209 }
David Spinadel35a000b2013-08-28 09:29:43 +03002210
2211 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
2212 if (ret)
2213 goto err;
2214
David Spinadelfb98be52014-05-04 12:51:10 +03002215 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
2216 ret = iwl_mvm_unified_sched_scan_lmac(mvm, vif, req, ies);
2217 else
2218 ret = iwl_mvm_sched_scan_start(mvm, req);
2219
David Spinadel35a000b2013-08-28 09:29:43 +03002220 if (!ret)
2221 goto out;
2222err:
2223 mvm->scan_status = IWL_MVM_SCAN_NONE;
2224out:
2225 mutex_unlock(&mvm->mutex);
2226 return ret;
2227}
2228
Johannes Berg37e33082014-02-17 10:48:17 +01002229static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2230 struct ieee80211_vif *vif)
David Spinadel35a000b2013-08-28 09:29:43 +03002231{
2232 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002233 int ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002234
2235 mutex_lock(&mvm->mutex);
David Spinadelfb98be52014-05-04 12:51:10 +03002236 ret = iwl_mvm_scan_offload_stop(mvm, false);
David Spinadel35a000b2013-08-28 09:29:43 +03002237 mutex_unlock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002238 iwl_mvm_wait_for_async_handlers(mvm);
Johannes Berg37e33082014-02-17 10:48:17 +01002239
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02002240 return ret;
David Spinadel35a000b2013-08-28 09:29:43 +03002241}
2242
Johannes Berg8ca151b2013-01-24 14:25:36 +01002243static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2244 enum set_key_cmd cmd,
2245 struct ieee80211_vif *vif,
2246 struct ieee80211_sta *sta,
2247 struct ieee80211_key_conf *key)
2248{
2249 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2250 int ret;
2251
2252 if (iwlwifi_mod_params.sw_crypto) {
2253 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2254 return -EOPNOTSUPP;
2255 }
2256
2257 switch (key->cipher) {
2258 case WLAN_CIPHER_SUITE_TKIP:
2259 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2260 /* fall-through */
2261 case WLAN_CIPHER_SUITE_CCMP:
2262 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2263 break;
2264 case WLAN_CIPHER_SUITE_AES_CMAC:
2265 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
2266 break;
2267 case WLAN_CIPHER_SUITE_WEP40:
2268 case WLAN_CIPHER_SUITE_WEP104:
2269 /*
2270 * Support for TX only, at least for now, so accept
2271 * the key and do nothing else. Then mac80211 will
2272 * pass it for TX but we don't have to use it for RX.
2273 */
2274 return 0;
2275 default:
Max Stepanove36e5432013-08-27 19:56:13 +03002276 /* currently FW supports only one optional cipher scheme */
2277 if (hw->n_cipher_schemes &&
2278 hw->cipher_schemes->cipher == key->cipher)
2279 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2280 else
2281 return -EOPNOTSUPP;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002282 }
2283
2284 mutex_lock(&mvm->mutex);
2285
2286 switch (cmd) {
2287 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02002288 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2289 vif->type == NL80211_IFTYPE_AP) && !sta) {
2290 /*
2291 * GTK on AP interface is a TX-only key, return 0;
2292 * on IBSS they're per-station and because we're lazy
2293 * we don't support them for RX, so do the same.
2294 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002295 ret = 0;
2296 key->hw_key_idx = STA_KEY_IDX_INVALID;
2297 break;
2298 }
2299
Johannes Berg8ca151b2013-01-24 14:25:36 +01002300 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
2301 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
2302 if (ret) {
2303 IWL_WARN(mvm, "set key failed\n");
2304 /*
2305 * can't add key for RX, but we don't need it
2306 * in the device for TX so still return 0
2307 */
Johannes Berg6caffd42013-03-06 13:15:21 +01002308 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002309 ret = 0;
2310 }
2311
2312 break;
2313 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01002314 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2315 ret = 0;
2316 break;
2317 }
2318
Johannes Berg8ca151b2013-01-24 14:25:36 +01002319 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
2320 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
2321 break;
2322 default:
2323 ret = -EINVAL;
2324 }
2325
2326 mutex_unlock(&mvm->mutex);
2327 return ret;
2328}
2329
2330static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2331 struct ieee80211_vif *vif,
2332 struct ieee80211_key_conf *keyconf,
2333 struct ieee80211_sta *sta,
2334 u32 iv32, u16 *phase1key)
2335{
2336 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2337
Johannes Berg5023d962013-07-31 14:07:43 +02002338 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2339 return;
2340
Johannes Berg8ca151b2013-01-24 14:25:36 +01002341 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2342}
2343
2344
Ariej Marjiehb1128892014-07-16 21:11:12 +03002345static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
2346 struct iwl_rx_packet *pkt, void *data)
2347{
2348 struct iwl_mvm *mvm =
2349 container_of(notif_wait, struct iwl_mvm, notif_wait);
2350 struct iwl_hs20_roc_res *resp;
2351 int resp_len = iwl_rx_packet_payload_len(pkt);
2352 struct iwl_mvm_time_event_data *te_data = data;
2353
2354 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
2355 return true;
2356
2357 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
2358 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
2359 return true;
2360 }
2361
2362 resp = (void *)pkt->data;
2363
2364 IWL_DEBUG_TE(mvm,
2365 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
2366 resp->status, resp->event_unique_id);
2367
2368 te_data->uid = le32_to_cpu(resp->event_unique_id);
2369 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
2370 te_data->uid);
2371
2372 spin_lock_bh(&mvm->time_event_lock);
2373 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
2374 spin_unlock_bh(&mvm->time_event_lock);
2375
2376 return true;
2377}
2378
2379#define AUX_ROC_MAX_DELAY_ON_CHANNEL 5000
2380static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
2381 struct ieee80211_channel *channel,
2382 struct ieee80211_vif *vif,
2383 int duration)
2384{
2385 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
2386 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2387 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
2388 static const u8 time_event_response[] = { HOT_SPOT_CMD };
2389 struct iwl_notification_wait wait_time_event;
2390 struct iwl_hs20_roc_req aux_roc_req = {
2391 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
2392 .id_and_color =
2393 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
2394 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
2395 /* Set the channel info data */
2396 .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ?
2397 PHY_BAND_24 : PHY_BAND_5,
2398 .channel_info.channel = channel->hw_value,
2399 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
2400 /* Set the time and duration */
2401 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
2402 .apply_time_max_delay =
2403 cpu_to_le32(MSEC_TO_TU(AUX_ROC_MAX_DELAY_ON_CHANNEL)),
2404 .duration = cpu_to_le32(MSEC_TO_TU(duration)),
2405 };
2406
2407 /* Set the node address */
2408 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
2409
2410 te_data->vif = vif;
2411 te_data->duration = duration;
2412 te_data->id = HOT_SPOT_CMD;
2413
2414 lockdep_assert_held(&mvm->mutex);
2415
2416 spin_lock_bh(&mvm->time_event_lock);
2417 list_add_tail(&te_data->list, &mvm->time_event_list);
2418 spin_unlock_bh(&mvm->time_event_lock);
2419
2420 /*
2421 * Use a notification wait, which really just processes the
2422 * command response and doesn't wait for anything, in order
2423 * to be able to process the response and get the UID inside
2424 * the RX path. Using CMD_WANT_SKB doesn't work because it
2425 * stores the buffer and then wakes up this thread, by which
2426 * time another notification (that the time event started)
2427 * might already be processed unsuccessfully.
2428 */
2429 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
2430 time_event_response,
2431 ARRAY_SIZE(time_event_response),
2432 iwl_mvm_rx_aux_roc, te_data);
2433
2434 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
2435 &aux_roc_req);
2436
2437 if (res) {
2438 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
2439 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
2440 goto out_clear_te;
2441 }
2442
2443 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
2444 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
2445 /* should never fail */
2446 WARN_ON_ONCE(res);
2447
2448 if (res) {
2449 out_clear_te:
2450 spin_lock_bh(&mvm->time_event_lock);
2451 iwl_mvm_te_clear_data(mvm, te_data);
2452 spin_unlock_bh(&mvm->time_event_lock);
2453 }
2454
2455 return res;
2456}
2457
Johannes Berg8ca151b2013-01-24 14:25:36 +01002458static int iwl_mvm_roc(struct ieee80211_hw *hw,
2459 struct ieee80211_vif *vif,
2460 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002461 int duration,
2462 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002463{
2464 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002465 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002466 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03002467 struct iwl_mvm_phy_ctxt *phy_ctxt;
2468 int ret, i;
2469
2470 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
2471 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002472
Ariej Marjiehb1128892014-07-16 21:11:12 +03002473 switch (vif->type) {
2474 case NL80211_IFTYPE_STATION:
2475 /* Use aux roc framework (HS20) */
2476 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
2477 vif, duration);
2478 return ret;
2479 case NL80211_IFTYPE_P2P_DEVICE:
2480 /* handle below */
2481 break;
2482 default:
2483 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002484 return -EINVAL;
2485 }
2486
Johannes Berg8ca151b2013-01-24 14:25:36 +01002487 mutex_lock(&mvm->mutex);
2488
Ilan Peer31d385a2013-04-02 10:25:46 +03002489 for (i = 0; i < NUM_PHY_CTX; i++) {
2490 phy_ctxt = &mvm->phy_ctxts[i];
2491 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
2492 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002493
Ilan Peer31d385a2013-04-02 10:25:46 +03002494 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
2495 /*
2496 * Unbind the P2P_DEVICE from the current PHY context,
2497 * and if the PHY context is not used remove it.
2498 */
2499 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2500 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2501 goto out_unlock;
2502
2503 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2504
2505 /* Bind the P2P_DEVICE to the current PHY Context */
2506 mvmvif->phy_ctxt = phy_ctxt;
2507
2508 ret = iwl_mvm_binding_add_vif(mvm, vif);
2509 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2510 goto out_unlock;
2511
2512 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2513 goto schedule_time_event;
2514 }
2515 }
2516
2517 /* Need to update the PHY context only if the ROC channel changed */
2518 if (channel == mvmvif->phy_ctxt->channel)
2519 goto schedule_time_event;
2520
2521 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
2522
2523 /*
2524 * Change the PHY context configuration as it is currently referenced
2525 * only by the P2P Device MAC
2526 */
2527 if (mvmvif->phy_ctxt->ref == 1) {
2528 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2529 &chandef, 1, 1);
2530 if (ret)
2531 goto out_unlock;
2532 } else {
2533 /*
2534 * The PHY context is shared with other MACs. Need to remove the
2535 * P2P Device from the binding, allocate an new PHY context and
2536 * create a new binding
2537 */
2538 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2539 if (!phy_ctxt) {
2540 ret = -ENOSPC;
2541 goto out_unlock;
2542 }
2543
2544 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2545 1, 1);
2546 if (ret) {
2547 IWL_ERR(mvm, "Failed to change PHY context\n");
2548 goto out_unlock;
2549 }
2550
2551 /* Unbind the P2P_DEVICE from the current PHY context */
2552 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2553 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2554 goto out_unlock;
2555
2556 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2557
2558 /* Bind the P2P_DEVICE to the new allocated PHY context */
2559 mvmvif->phy_ctxt = phy_ctxt;
2560
2561 ret = iwl_mvm_binding_add_vif(mvm, vif);
2562 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2563 goto out_unlock;
2564
2565 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2566 }
2567
2568schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002569 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02002570 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002571
Ilan Peer31d385a2013-04-02 10:25:46 +03002572out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002573 mutex_unlock(&mvm->mutex);
2574 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01002575 return ret;
2576}
2577
2578static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
2579{
2580 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2581
2582 IWL_DEBUG_MAC80211(mvm, "enter\n");
2583
2584 mutex_lock(&mvm->mutex);
2585 iwl_mvm_stop_p2p_roc(mvm);
2586 mutex_unlock(&mvm->mutex);
2587
2588 IWL_DEBUG_MAC80211(mvm, "leave\n");
2589 return 0;
2590}
2591
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002592static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
2593 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002594{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002595 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2596 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002597 int ret;
2598
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002599 lockdep_assert_held(&mvm->mutex);
2600
Ilan Peer53a9d612013-04-28 11:55:08 +03002601 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002602
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002603 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2604 if (!phy_ctxt) {
2605 ret = -ENOSPC;
2606 goto out;
2607 }
2608
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02002609 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Ilan Peer53a9d612013-04-28 11:55:08 +03002610 ctx->rx_chains_static,
2611 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002612 if (ret) {
2613 IWL_ERR(mvm, "Failed to add PHY context\n");
2614 goto out;
2615 }
2616
Ilan Peer53a9d612013-04-28 11:55:08 +03002617 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002618 *phy_ctxt_id = phy_ctxt->id;
2619out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002620 return ret;
2621}
2622
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002623static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2624 struct ieee80211_chanctx_conf *ctx)
2625{
2626 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2627 int ret;
2628
2629 mutex_lock(&mvm->mutex);
2630 ret = __iwl_mvm_add_chanctx(mvm, ctx);
2631 mutex_unlock(&mvm->mutex);
2632
2633 return ret;
2634}
2635
2636static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
2637 struct ieee80211_chanctx_conf *ctx)
2638{
2639 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2640 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2641
2642 lockdep_assert_held(&mvm->mutex);
2643
2644 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
2645}
2646
Johannes Berg8ca151b2013-01-24 14:25:36 +01002647static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2648 struct ieee80211_chanctx_conf *ctx)
2649{
2650 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002651
2652 mutex_lock(&mvm->mutex);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002653 __iwl_mvm_remove_chanctx(mvm, ctx);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002654 mutex_unlock(&mvm->mutex);
2655}
2656
2657static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
2658 struct ieee80211_chanctx_conf *ctx,
2659 u32 changed)
2660{
2661 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002662 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2663 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002664
Ilan Peer31d385a2013-04-02 10:25:46 +03002665 if (WARN_ONCE((phy_ctxt->ref > 1) &&
2666 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
2667 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
Arik Nemtsov2dceeda2013-12-29 17:57:53 +02002668 IEEE80211_CHANCTX_CHANGE_RADAR |
2669 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
Ilan Peer31d385a2013-04-02 10:25:46 +03002670 "Cannot change PHY. Ref=%d, changed=0x%X\n",
2671 phy_ctxt->ref, changed))
2672 return;
2673
Johannes Berg8ca151b2013-01-24 14:25:36 +01002674 mutex_lock(&mvm->mutex);
Emmanuel Grumbach4d664492014-04-30 18:09:59 +03002675 iwl_mvm_bt_coex_vif_change(mvm);
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02002676 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002677 ctx->rx_chains_static,
2678 ctx->rx_chains_dynamic);
2679 mutex_unlock(&mvm->mutex);
2680}
2681
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002682static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
2683 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02002684 struct ieee80211_chanctx_conf *ctx,
2685 bool switching_chanctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002686{
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002687 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2688 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002689 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2690 int ret;
2691
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002692 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002693
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002694 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002695
2696 switch (vif->type) {
2697 case NL80211_IFTYPE_AP:
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002698 /* Unless it's a CSA flow we have nothing to do here */
2699 if (vif->csa_active) {
2700 mvmvif->ap_ibss_active = true;
2701 break;
2702 }
Johannes Berg5023d962013-07-31 14:07:43 +02002703 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002704 /*
2705 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02002706 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01002707 */
2708 ret = 0;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002709 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002710 case NL80211_IFTYPE_STATION:
Luciano Coelho2533edc2014-08-08 19:50:46 +03002711 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002712 case NL80211_IFTYPE_MONITOR:
Luciano Coelho2533edc2014-08-08 19:50:46 +03002713 /* always disable PS when a monitor interface is active */
2714 mvmvif->ps_disabled = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002715 break;
2716 default:
2717 ret = -EINVAL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002718 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002719 }
2720
2721 ret = iwl_mvm_binding_add_vif(mvm, vif);
2722 if (ret)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002723 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002724
2725 /*
Alexander Bondar92d85562013-10-23 11:50:34 +02002726 * Power state must be updated before quotas,
2727 * otherwise fw will complain.
2728 */
Arik Nemtsov999609f2014-05-15 17:31:51 +03002729 iwl_mvm_power_update_mac(mvm);
Alexander Bondar92d85562013-10-23 11:50:34 +02002730
2731 /* Setting the quota at this stage is only required for monitor
Johannes Berg8ca151b2013-01-24 14:25:36 +01002732 * interfaces. For the other types, the bss_info changed flow
2733 * will handle quota settings.
2734 */
2735 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02002736 mvmvif->monitor_active = true;
Johannes Berg01662302014-06-06 15:18:45 +02002737 ret = iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002738 if (ret)
2739 goto out_remove_binding;
2740 }
2741
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002742 /* Handle binding during CSA */
Luciano Coelhof0c97782014-03-05 15:41:48 +02002743 if ((vif->type == NL80211_IFTYPE_AP) ||
2744 (switching_chanctx && (vif->type == NL80211_IFTYPE_STATION))) {
Johannes Berg01662302014-06-06 15:18:45 +02002745 iwl_mvm_update_quotas(mvm, NULL);
Luciano Coelhobca49d92014-05-13 17:33:38 +03002746 iwl_mvm_mac_ctxt_changed(mvm, vif, false);
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002747 }
2748
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002749 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002750
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002751out_remove_binding:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002752 iwl_mvm_binding_remove_vif(mvm, vif);
Arik Nemtsov999609f2014-05-15 17:31:51 +03002753 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002754out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002755 if (ret)
2756 mvmvif->phy_ctxt = NULL;
2757 return ret;
2758}
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002759static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
2760 struct ieee80211_vif *vif,
2761 struct ieee80211_chanctx_conf *ctx)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002762{
2763 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002764 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002765
2766 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02002767 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002768 mutex_unlock(&mvm->mutex);
2769
2770 return ret;
2771}
2772
2773static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
2774 struct ieee80211_vif *vif,
Luciano Coelhof0c97782014-03-05 15:41:48 +02002775 struct ieee80211_chanctx_conf *ctx,
2776 bool switching_chanctx)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002777{
2778 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Luciano Coelhof0c97782014-03-05 15:41:48 +02002779 struct ieee80211_vif *disabled_vif = NULL;
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002780
2781 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002782
2783 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
2784
Johannes Berg8ca151b2013-01-24 14:25:36 +01002785 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02002786 case NL80211_IFTYPE_ADHOC:
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002787 goto out;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002788 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02002789 mvmvif->monitor_active = false;
Luciano Coelho2533edc2014-08-08 19:50:46 +03002790 mvmvif->ps_disabled = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002791 break;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002792 case NL80211_IFTYPE_AP:
2793 /* This part is triggered only during CSA */
2794 if (!vif->csa_active || !mvmvif->ap_ibss_active)
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002795 goto out;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002796
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03002797 /* Set CS bit on all the stations */
2798 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
2799
2800 /* Save blocked iface, the timeout is set on the next beacon */
2801 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
2802
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002803 mvmvif->ap_ibss_active = false;
Luciano Coelhof0c97782014-03-05 15:41:48 +02002804 break;
2805 case NL80211_IFTYPE_STATION:
2806 if (!switching_chanctx)
2807 break;
2808
2809 disabled_vif = vif;
2810
2811 iwl_mvm_mac_ctxt_changed(mvm, vif, true);
2812 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002813 default:
2814 break;
2815 }
2816
Luciano Coelhof0c97782014-03-05 15:41:48 +02002817 iwl_mvm_update_quotas(mvm, disabled_vif);
Ilan Peer1e1391c2013-03-13 14:52:04 +02002818 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03002819
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002820out:
Ilan Peera11e1442013-12-31 21:19:55 +02002821 mvmvif->phy_ctxt = NULL;
Arik Nemtsov999609f2014-05-15 17:31:51 +03002822 iwl_mvm_power_update_mac(mvm);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002823}
2824
2825static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
2826 struct ieee80211_vif *vif,
2827 struct ieee80211_chanctx_conf *ctx)
2828{
2829 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2830
2831 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02002832 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002833 mutex_unlock(&mvm->mutex);
2834}
2835
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002836static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
2837 struct ieee80211_vif_chanctx_switch *vifs,
2838 int n_vifs,
2839 enum ieee80211_chanctx_switch_mode mode)
2840{
2841 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2842 int ret;
2843
2844 /* we only support SWAP_CONTEXTS and with a single-vif right now */
2845 if (mode != CHANCTX_SWMODE_SWAP_CONTEXTS || n_vifs > 1)
2846 return -EOPNOTSUPP;
2847
2848 mutex_lock(&mvm->mutex);
Luciano Coelhof0c97782014-03-05 15:41:48 +02002849 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002850 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
2851
2852 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
2853 if (ret) {
2854 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
2855 goto out_reassign;
2856 }
2857
Luciano Coelhof0c97782014-03-05 15:41:48 +02002858 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
2859 true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002860 if (ret) {
2861 IWL_ERR(mvm,
2862 "failed to assign new_ctx during channel switch\n");
2863 goto out_remove;
2864 }
2865
Arik Nemtsovf6972672014-06-15 16:03:55 +03002866 /* we don't support TDLS during DCM - can be caused by channel switch */
2867 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2868 iwl_mvm_teardown_tdls_peers(mvm);
2869
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002870 goto out;
2871
2872out_remove:
2873 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
2874
2875out_reassign:
2876 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx);
2877 if (ret) {
2878 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
2879 goto out_restart;
2880 }
2881
Luciano Coelhof0c97782014-03-05 15:41:48 +02002882 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
2883 true);
Luciano Coelhob08c1d92014-05-20 23:31:05 +03002884 if (ret) {
2885 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
2886 goto out_restart;
2887 }
2888
2889 goto out;
2890
2891out_restart:
2892 /* things keep failing, better restart the hw */
2893 iwl_mvm_nic_restart(mvm, false);
2894
2895out:
2896 mutex_unlock(&mvm->mutex);
2897 return ret;
2898}
2899
Johannes Berg8ca151b2013-01-24 14:25:36 +01002900static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
2901 struct ieee80211_sta *sta,
2902 bool set)
2903{
2904 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2905 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
2906
2907 if (!mvm_sta || !mvm_sta->vif) {
2908 IWL_ERR(mvm, "Station is not associated to a vif\n");
2909 return -EINVAL;
2910 }
2911
2912 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
2913}
2914
David Spinadel507cadf2013-07-31 18:07:21 +03002915#ifdef CONFIG_NL80211_TESTMODE
2916static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
2917 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
2918 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad422013-08-01 14:17:15 +02002919 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03002920};
2921
2922static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
2923 struct ieee80211_vif *vif,
2924 void *data, int len)
2925{
2926 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
2927 int err;
2928 u32 noa_duration;
2929
2930 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
2931 if (err)
2932 return err;
2933
2934 if (!tb[IWL_MVM_TM_ATTR_CMD])
2935 return -EINVAL;
2936
2937 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
2938 case IWL_MVM_TM_CMD_SET_NOA:
2939 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
2940 !vif->bss_conf.enable_beacon ||
2941 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
2942 return -EINVAL;
2943
2944 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
2945 if (noa_duration >= vif->bss_conf.beacon_int)
2946 return -EINVAL;
2947
2948 mvm->noa_duration = noa_duration;
2949 mvm->noa_vif = vif;
2950
Johannes Berg01662302014-06-06 15:18:45 +02002951 return iwl_mvm_update_quotas(mvm, NULL);
Johannes Bergf6c6ad422013-08-01 14:17:15 +02002952 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
2953 /* must be associated client vif - ignore authorized */
2954 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
2955 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
2956 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
2957 return -EINVAL;
2958
2959 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002960 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2961 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
David Spinadel507cadf2013-07-31 18:07:21 +03002962 }
2963
2964 return -EOPNOTSUPP;
2965}
2966
2967static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
2968 struct ieee80211_vif *vif,
2969 void *data, int len)
2970{
2971 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2972 int err;
2973
2974 mutex_lock(&mvm->mutex);
2975 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
2976 mutex_unlock(&mvm->mutex);
2977
2978 return err;
2979}
2980#endif
2981
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002982static void iwl_mvm_channel_switch_beacon(struct ieee80211_hw *hw,
2983 struct ieee80211_vif *vif,
2984 struct cfg80211_chan_def *chandef)
2985{
2986 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002987 struct ieee80211_vif *csa_vif;
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002988
2989 mutex_lock(&mvm->mutex);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002990
2991 csa_vif = rcu_dereference_protected(mvm->csa_vif,
2992 lockdep_is_held(&mvm->mutex));
2993 if (WARN(csa_vif && csa_vif->csa_active,
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02002994 "Another CSA is already in progress"))
2995 goto out_unlock;
2996
2997 IWL_DEBUG_MAC80211(mvm, "CSA started to freq %d\n",
2998 chandef->center_freq1);
Andrei Otcheretianski664322f2014-06-05 16:40:36 +03002999 rcu_assign_pointer(mvm->csa_vif, vif);
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003000
3001out_unlock:
3002 mutex_unlock(&mvm->mutex);
3003}
3004
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003005static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
3006 struct ieee80211_vif *vif, u32 queues, bool drop)
3007{
3008 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3009 struct iwl_mvm_vif *mvmvif;
3010 struct iwl_mvm_sta *mvmsta;
3011
3012 if (!vif || vif->type != NL80211_IFTYPE_STATION)
3013 return;
3014
3015 mutex_lock(&mvm->mutex);
3016 mvmvif = iwl_mvm_vif_from_mac80211(vif);
3017 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, mvmvif->ap_sta_id);
3018
3019 if (WARN_ON_ONCE(!mvmsta))
3020 goto done;
3021
3022 if (drop) {
3023 if (iwl_mvm_flush_tx_path(mvm, mvmsta->tfd_queue_msk, true))
3024 IWL_ERR(mvm, "flush request fail\n");
3025 } else {
3026 iwl_trans_wait_tx_queue_empty(mvm->trans,
3027 mvmsta->tfd_queue_msk);
3028 }
3029done:
3030 mutex_unlock(&mvm->mutex);
3031}
3032
Johannes Berge5209262014-01-20 23:38:59 +01003033const struct ieee80211_ops iwl_mvm_hw_ops = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01003034 .tx = iwl_mvm_mac_tx,
3035 .ampdu_action = iwl_mvm_mac_ampdu_action,
3036 .start = iwl_mvm_mac_start,
3037 .restart_complete = iwl_mvm_mac_restart_complete,
3038 .stop = iwl_mvm_mac_stop,
3039 .add_interface = iwl_mvm_mac_add_interface,
3040 .remove_interface = iwl_mvm_mac_remove_interface,
3041 .config = iwl_mvm_mac_config,
Eliad Pellere59647e2013-11-28 14:08:50 +02003042 .prepare_multicast = iwl_mvm_prepare_multicast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003043 .configure_filter = iwl_mvm_configure_filter,
3044 .bss_info_changed = iwl_mvm_bss_info_changed,
3045 .hw_scan = iwl_mvm_mac_hw_scan,
3046 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
Johannes Berg1ddbbb02013-12-04 22:39:17 +01003047 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003048 .sta_state = iwl_mvm_mac_sta_state,
3049 .sta_notify = iwl_mvm_mac_sta_notify,
3050 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
Johannes Berg3e56ead2013-02-15 22:23:18 +01003051 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003052 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02003053 .sta_rc_update = iwl_mvm_sta_rc_update,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003054 .conf_tx = iwl_mvm_mac_conf_tx,
3055 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
Arik Nemtsov07ecd892014-05-20 18:16:42 +03003056 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
Emmanuel Grumbachc5b0e7c2014-03-24 12:08:53 +02003057 .flush = iwl_mvm_mac_flush,
David Spinadel35a000b2013-08-28 09:29:43 +03003058 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
3059 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003060 .set_key = iwl_mvm_mac_set_key,
3061 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
3062 .remain_on_channel = iwl_mvm_roc,
3063 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003064 .add_chanctx = iwl_mvm_add_chanctx,
3065 .remove_chanctx = iwl_mvm_remove_chanctx,
3066 .change_chanctx = iwl_mvm_change_chanctx,
3067 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
3068 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
Luciano Coelhob08c1d92014-05-20 23:31:05 +03003069 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003070
Johannes Berg5023d962013-07-31 14:07:43 +02003071 .start_ap = iwl_mvm_start_ap_ibss,
3072 .stop_ap = iwl_mvm_stop_ap_ibss,
3073 .join_ibss = iwl_mvm_start_ap_ibss,
3074 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003075
3076 .set_tim = iwl_mvm_set_tim,
3077
Andrei Otcheretianskibd3398e2013-10-22 05:01:12 +02003078 .channel_switch_beacon = iwl_mvm_channel_switch_beacon,
3079
David Spinadel507cadf2013-07-31 18:07:21 +03003080 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
3081
Johannes Berg8ca151b2013-01-24 14:25:36 +01003082#ifdef CONFIG_PM_SLEEP
3083 /* look at d3.c */
3084 .suspend = iwl_mvm_suspend,
3085 .resume = iwl_mvm_resume,
3086 .set_wakeup = iwl_mvm_set_wakeup,
3087 .set_rekey_data = iwl_mvm_set_rekey_data,
3088#if IS_ENABLED(CONFIG_IPV6)
3089 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
3090#endif
3091 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
3092#endif
3093};