blob: 8414c031e274bb459b81cafd82a2441ae46b0e4d [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"
Johannes Berg8ca151b2013-01-24 14:25:36 +010083
84static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
85 {
86 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030087 .types = BIT(NL80211_IFTYPE_STATION),
Johannes Berg8ca151b2013-01-24 14:25:36 +010088 },
Johannes Berg3c15a0f2013-05-31 10:17:19 +020089 {
90 .max = 1,
Ilan Peer8eb38712013-06-01 20:17:18 +030091 .types = BIT(NL80211_IFTYPE_AP) |
92 BIT(NL80211_IFTYPE_P2P_CLIENT) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +020093 BIT(NL80211_IFTYPE_P2P_GO),
94 },
95 {
96 .max = 1,
97 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
98 },
Johannes Berg8ca151b2013-01-24 14:25:36 +010099};
100
101static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
102 {
103 .num_different_channels = 1,
104 .max_interfaces = 3,
105 .limits = iwl_mvm_limits,
106 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
107 },
108};
109
Johannes Bergf0c26462013-01-22 20:41:58 +0100110#ifdef CONFIG_PM_SLEEP
111static const struct nl80211_wowlan_tcp_data_token_feature
112iwl_mvm_wowlan_tcp_token_feature = {
113 .min_len = 0,
114 .max_len = 255,
115 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
116};
117
118static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
119 .tok = &iwl_mvm_wowlan_tcp_token_feature,
120 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
121 sizeof(struct ethhdr) -
122 sizeof(struct iphdr) -
123 sizeof(struct tcphdr),
124 .data_interval_max = 65535, /* __le16 in API */
125 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
126 sizeof(struct ethhdr) -
127 sizeof(struct iphdr) -
128 sizeof(struct tcphdr),
129 .seq = true,
130};
131#endif
132
Eliad Peller77736922014-01-14 12:35:49 +0200133#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
Eliad Peller2ee8f022014-01-13 19:07:09 +0200134/*
135 * Use the reserved field to indicate magic values.
136 * these values will only be used internally by the driver,
137 * and won't make it to the fw (reserved will be 0).
138 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
139 * be the vif's ip address. in case there is not a single
140 * ip address (0, or more than 1), this attribute will
141 * be skipped.
142 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
143 * the LSB bytes of the vif's mac address
144 */
145enum {
146 BC_FILTER_MAGIC_NONE = 0,
147 BC_FILTER_MAGIC_IP,
148 BC_FILTER_MAGIC_MAC,
149};
150
Eliad Peller77736922014-01-14 12:35:49 +0200151static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
152 {
153 /* arp */
154 .discard = 0,
155 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
156 .attrs = {
157 {
158 /* frame type - arp, hw type - ethernet */
159 .offset_type =
160 BCAST_FILTER_OFFSET_PAYLOAD_START,
161 .offset = sizeof(rfc1042_header),
162 .val = cpu_to_be32(0x08060001),
163 .mask = cpu_to_be32(0xffffffff),
164 },
Eliad Peller2ee8f022014-01-13 19:07:09 +0200165 {
166 /* arp dest ip */
167 .offset_type =
168 BCAST_FILTER_OFFSET_PAYLOAD_START,
169 .offset = sizeof(rfc1042_header) + 2 +
170 sizeof(struct arphdr) +
171 ETH_ALEN + sizeof(__be32) +
172 ETH_ALEN,
173 .mask = cpu_to_be32(0xffffffff),
174 /* mark it as special field */
175 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
176 },
177 },
178 },
179 {
180 /* dhcp offer bcast */
181 .discard = 0,
182 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
183 .attrs = {
184 {
185 /* udp dest port - 68 (bootp client)*/
186 .offset_type = BCAST_FILTER_OFFSET_IP_END,
187 .offset = offsetof(struct udphdr, dest),
188 .val = cpu_to_be32(0x00440000),
189 .mask = cpu_to_be32(0xffff0000),
190 },
191 {
192 /* dhcp - lsb bytes of client hw address */
193 .offset_type = BCAST_FILTER_OFFSET_IP_END,
194 .offset = 38,
195 .mask = cpu_to_be32(0xffffffff),
196 /* mark it as special field */
197 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
198 },
Eliad Peller77736922014-01-14 12:35:49 +0200199 },
200 },
201 /* last filter must be empty */
202 {},
203};
204#endif
205
Eliad Peller7498cf42014-01-16 17:10:44 +0200206void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
207{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200208 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200209 return;
210
211 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
212 WARN_ON(test_and_set_bit(ref_type, mvm->ref_bitmap));
213 iwl_trans_ref(mvm->trans);
214}
215
216void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
217{
Eliad Peller7bb426e2014-02-24 12:54:37 +0200218 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200219 return;
220
221 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
222 WARN_ON(!test_and_clear_bit(ref_type, mvm->ref_bitmap));
223 iwl_trans_unref(mvm->trans);
224}
225
226static void
227iwl_mvm_unref_all_except(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref)
228{
229 int i;
230
Eliad Peller7bb426e2014-02-24 12:54:37 +0200231 if (!iwl_mvm_is_d0i3_supported(mvm))
Eliad Peller7498cf42014-01-16 17:10:44 +0200232 return;
233
234 for_each_set_bit(i, mvm->ref_bitmap, IWL_MVM_REF_COUNT) {
235 if (ref == i)
236 continue;
237
238 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d\n", i);
239 clear_bit(i, mvm->ref_bitmap);
240 iwl_trans_unref(mvm->trans);
241 }
242}
243
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200244static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
245{
246 int i;
247
248 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
249 for (i = 0; i < NUM_PHY_CTX; i++) {
250 mvm->phy_ctxts[i].id = i;
251 mvm->phy_ctxts[i].ref = 0;
252 }
253}
254
David Spinadel20f1a5d2013-08-21 09:14:27 +0300255static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
256{
257 /* we create the 802.11 header and SSID element */
258 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID)
259 return mvm->fw->ucode_capa.max_probe_length - 24 - 2;
260 return mvm->fw->ucode_capa.max_probe_length - 24 - 34;
261}
262
Johannes Berg8ca151b2013-01-24 14:25:36 +0100263int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
264{
265 struct ieee80211_hw *hw = mvm->hw;
Ilan Peer831e85f2013-02-07 17:09:09 +0200266 int num_mac, ret, i;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100267
268 /* Tell mac80211 our characteristics */
269 hw->flags = IEEE80211_HW_SIGNAL_DBM |
270 IEEE80211_HW_SPECTRUM_MGMT |
271 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
272 IEEE80211_HW_QUEUE_CONTROL |
273 IEEE80211_HW_WANT_MONITOR_VIF |
Johannes Berg8ca151b2013-01-24 14:25:36 +0100274 IEEE80211_HW_SUPPORTS_PS |
275 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Johannes Bergd2931bb2013-02-05 18:10:04 +0100276 IEEE80211_HW_AMPDU_AGGREGATION |
Hila Gonend64048e2013-03-13 18:00:03 +0200277 IEEE80211_HW_TIMING_BEACON_ONLY |
Emmanuel Grumbach147fc9b2013-07-28 11:00:52 +0300278 IEEE80211_HW_CONNECTION_MONITOR |
279 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
Alexander Bondare8e626a2013-10-16 00:21:34 +0200280 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100281
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200282 hw->queues = mvm->first_agg_queue;
Ilan Peer398e8c62013-03-13 15:20:35 +0200283 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +0200284 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
285 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
286 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100287 hw->rate_control_algorithm = "iwl-mvm-rs";
288
289 /*
290 * Enable 11w if advertised by firmware and software crypto
291 * is not enabled (as the firmware will interpret some mgmt
292 * packets, so enabling it with software crypto isn't safe)
293 */
294 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
295 !iwlwifi_mod_params.sw_crypto)
296 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
297
Alexander Bondare8e626a2013-10-16 00:21:34 +0200298 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT) {
299 hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
300 hw->uapsd_queues = IWL_UAPSD_AC_INFO;
301 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
302 }
303
Johannes Berg8ca151b2013-01-24 14:25:36 +0100304 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
305 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200306 hw->chanctx_data_size = sizeof(u16);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100307
308 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200309 BIT(NL80211_IFTYPE_P2P_CLIENT) |
310 BIT(NL80211_IFTYPE_AP) |
311 BIT(NL80211_IFTYPE_P2P_GO) |
312 BIT(NL80211_IFTYPE_P2P_DEVICE);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100313
Johannes Berg5023d962013-07-31 14:07:43 +0200314 /* IBSS has bugs in older versions */
315 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 8)
316 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
317
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +0100318 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
319 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
320 REGULATORY_DISABLE_BEACON_HINTS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100321
Johannes Berg3e56ead2013-02-15 22:23:18 +0100322 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
323 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
324
Johannes Berg8ca151b2013-01-24 14:25:36 +0100325 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
326 hw->wiphy->n_iface_combinations =
327 ARRAY_SIZE(iwl_mvm_iface_combinations);
328
Ilan Peerc451e6d2013-02-20 08:41:54 +0200329 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100330 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
331
332 /* Extract MAC address */
333 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
334 hw->wiphy->addresses = mvm->addresses;
335 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200336
337 /* Extract additional MAC addresses if available */
338 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
339 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
340
341 for (i = 1; i < num_mac; i++) {
342 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100343 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200344 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100345 hw->wiphy->n_addresses++;
346 }
347
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200348 iwl_mvm_reset_phy_ctxts(mvm);
349
David Spinadel20f1a5d2013-08-21 09:14:27 +0300350 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
351
Johannes Berg8ca151b2013-01-24 14:25:36 +0100352 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
353
354 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
355 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
356 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
357 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
358 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
359 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
360
361 hw->wiphy->hw_version = mvm->trans->hw_id;
362
Alexander Bondarade50652013-04-03 16:28:47 +0300363 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100364 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
365 else
366 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
367
Emmanuel Grumbach833df4a2014-03-16 08:51:47 +0200368 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) {
David Spinadel35a000b2013-08-28 09:29:43 +0300369 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
370 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
371 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
372 /* we create the 802.11 header and zero length SSID IE. */
373 hw->wiphy->max_sched_scan_ie_len =
374 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
375 }
376
Johannes Berg8ca151b2013-01-24 14:25:36 +0100377 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200378 NL80211_FEATURE_P2P_GO_OPPPS |
379 NL80211_FEATURE_LOW_PRIORITY_SCAN;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100380
381 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
382
Max Stepanove36e5432013-08-27 19:56:13 +0300383 /* currently FW API supports only one optional cipher scheme */
Johannes Berg9ddca862014-01-06 09:29:40 +0100384 if (mvm->fw->cs[0].cipher) {
Max Stepanove36e5432013-08-27 19:56:13 +0300385 mvm->hw->n_cipher_schemes = 1;
Johannes Berg9ddca862014-01-06 09:29:40 +0100386 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
Max Stepanove36e5432013-08-27 19:56:13 +0300387 }
388
Johannes Berg8ca151b2013-01-24 14:25:36 +0100389#ifdef CONFIG_PM_SLEEP
390 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
391 mvm->trans->ops->d3_suspend &&
392 mvm->trans->ops->d3_resume &&
393 device_can_wakeup(mvm->trans->dev)) {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200394 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
395 WIPHY_WOWLAN_DISCONNECT |
396 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
397 WIPHY_WOWLAN_RFKILL_RELEASE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100398 if (!iwlwifi_mod_params.sw_crypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200399 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
400 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
401 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100402
Johannes Berg964dc9e2013-06-03 17:25:34 +0200403 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
404 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
405 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
406 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
407 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100408 }
409#endif
410
Eliad Peller77736922014-01-14 12:35:49 +0200411#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
412 /* assign default bcast filtering configuration */
413 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
414#endif
415
Johannes Berg8ca151b2013-01-24 14:25:36 +0100416 ret = iwl_mvm_leds_init(mvm);
417 if (ret)
418 return ret;
419
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300420 ret = ieee80211_register_hw(mvm->hw);
421 if (ret)
422 iwl_mvm_leds_exit(mvm);
423
424 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100425}
426
Arik Nemtsovb2492502014-03-13 12:21:50 +0200427static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
428 struct ieee80211_sta *sta,
429 struct sk_buff *skb)
430{
431 struct iwl_mvm_sta *mvmsta;
432 bool defer = false;
433
434 /*
435 * double check the IN_D0I3 flag both before and after
436 * taking the spinlock, in order to prevent taking
437 * the spinlock when not needed.
438 */
439 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
440 return false;
441
442 spin_lock(&mvm->d0i3_tx_lock);
443 /*
444 * testing the flag again ensures the skb dequeue
445 * loop (on d0i3 exit) hasn't run yet.
446 */
447 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
448 goto out;
449
450 mvmsta = iwl_mvm_sta_from_mac80211(sta);
451 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
452 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
453 goto out;
454
455 __skb_queue_tail(&mvm->d0i3_tx, skb);
456 ieee80211_stop_queues(mvm->hw);
457
458 /* trigger wakeup */
459 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
460 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
461
462 defer = true;
463out:
464 spin_unlock(&mvm->d0i3_tx_lock);
465 return defer;
466}
467
Johannes Berg8ca151b2013-01-24 14:25:36 +0100468static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
469 struct ieee80211_tx_control *control,
470 struct sk_buff *skb)
471{
472 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg3e56ead2013-02-15 22:23:18 +0100473 struct ieee80211_sta *sta = control->sta;
474 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
475 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100476
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300477 if (iwl_mvm_is_radio_killed(mvm)) {
478 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100479 goto drop;
480 }
481
Ilan Peer398e8c62013-03-13 15:20:35 +0200482 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100483 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
484 goto drop;
485
Johannes Berg3e56ead2013-02-15 22:23:18 +0100486 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
487 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
488 ieee80211_is_mgmt(hdr->frame_control) &&
489 !ieee80211_is_deauth(hdr->frame_control) &&
490 !ieee80211_is_disassoc(hdr->frame_control) &&
491 !ieee80211_is_action(hdr->frame_control)))
492 sta = NULL;
493
494 if (sta) {
Arik Nemtsovb2492502014-03-13 12:21:50 +0200495 if (iwl_mvm_defer_tx(mvm, sta, skb))
496 return;
Johannes Berg3e56ead2013-02-15 22:23:18 +0100497 if (iwl_mvm_tx_skb(mvm, skb, sta))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100498 goto drop;
499 return;
500 }
501
502 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
503 goto drop;
504 return;
505 drop:
506 ieee80211_free_txskb(hw, skb);
507}
508
509static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
510 struct ieee80211_vif *vif,
511 enum ieee80211_ampdu_mlme_action action,
512 struct ieee80211_sta *sta, u16 tid,
513 u16 *ssn, u8 buf_size)
514{
515 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
516 int ret;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200517 bool tx_agg_ref = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100518
519 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
520 sta->addr, tid, action);
521
522 if (!(mvm->nvm_data->sku_cap_11n_enable))
523 return -EACCES;
524
Arik Nemtsovb2492502014-03-13 12:21:50 +0200525 /* return from D0i3 before starting a new Tx aggregation */
526 if (action == IEEE80211_AMPDU_TX_START) {
527 iwl_mvm_ref(mvm, IWL_MVM_REF_TX_AGG);
528 tx_agg_ref = true;
529
530 /*
531 * wait synchronously until D0i3 exit to get the correct
532 * sequence number for the tid
533 */
534 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
535 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status), HZ)) {
536 WARN_ON_ONCE(1);
537 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
538 return -EIO;
539 }
540 }
541
Johannes Berg8ca151b2013-01-24 14:25:36 +0100542 mutex_lock(&mvm->mutex);
543
544 switch (action) {
545 case IEEE80211_AMPDU_RX_START:
546 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
547 ret = -EINVAL;
548 break;
549 }
550 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
551 break;
552 case IEEE80211_AMPDU_RX_STOP:
553 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
554 break;
555 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200556 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
557 ret = -EINVAL;
558 break;
559 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100560 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
561 break;
562 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200563 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
564 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100565 case IEEE80211_AMPDU_TX_STOP_FLUSH:
566 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200567 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100568 break;
569 case IEEE80211_AMPDU_TX_OPERATIONAL:
570 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
571 break;
572 default:
573 WARN_ON_ONCE(1);
574 ret = -EINVAL;
575 break;
576 }
577 mutex_unlock(&mvm->mutex);
578
Arik Nemtsovb2492502014-03-13 12:21:50 +0200579 /*
580 * If the tid is marked as started, we won't use it for offloaded
581 * traffic on the next D0i3 entry. It's safe to unref.
582 */
583 if (tx_agg_ref)
584 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
585
Johannes Berg8ca151b2013-01-24 14:25:36 +0100586 return ret;
587}
588
589static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
590 struct ieee80211_vif *vif)
591{
592 struct iwl_mvm *mvm = data;
593 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
594
595 mvmvif->uploaded = false;
596 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
597
598 /* does this make sense at all? */
599 mvmvif->color++;
600
601 spin_lock_bh(&mvm->time_event_lock);
602 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
603 spin_unlock_bh(&mvm->time_event_lock);
604
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200605 mvmvif->phy_ctxt = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100606}
607
608static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
609{
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +0200610#ifdef CONFIG_IWLWIFI_DEBUGFS
611 static char *env[] = { "DRIVER=iwlwifi", "EVENT=error_dump", NULL };
612
613 iwl_mvm_fw_error_dump(mvm);
614
615 /* notify the userspace about the error we had */
616 kobject_uevent_env(&mvm->hw->wiphy->dev.kobj, KOBJ_CHANGE, env);
617#endif
618
Johannes Berg8ca151b2013-01-24 14:25:36 +0100619 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100620
621 mvm->scan_status = IWL_MVM_SCAN_NONE;
622
623 /* just in case one was running */
624 ieee80211_remain_on_channel_expired(mvm->hw);
625
626 ieee80211_iterate_active_interfaces_atomic(
627 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
628 iwl_mvm_cleanup_iterator, mvm);
629
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200630 mvm->p2p_device_vif = NULL;
Eliad Peller37577fe2013-12-05 17:19:39 +0200631 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200632
633 iwl_mvm_reset_phy_ctxts(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100634 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
635 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
636
637 ieee80211_wake_queues(mvm->hw);
638
Eliad Peller7498cf42014-01-16 17:10:44 +0200639 /* cleanup all stale references (scan, roc), but keep the
640 * ucode_down ref until reconfig is complete */
641 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
642
Johannes Berg8ca151b2013-01-24 14:25:36 +0100643 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +0300644 mvm->rx_ba_sessions = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100645}
646
647static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
648{
649 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
650 int ret;
651
652 mutex_lock(&mvm->mutex);
653
654 /* Clean up some internal and mac80211 state on restart */
655 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
656 iwl_mvm_restart_cleanup(mvm);
657
658 ret = iwl_mvm_up(mvm);
659 mutex_unlock(&mvm->mutex);
660
661 return ret;
662}
663
664static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
665{
666 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
667 int ret;
668
669 mutex_lock(&mvm->mutex);
670
671 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
Arik Nemtsovb2492502014-03-13 12:21:50 +0200672 iwl_mvm_d0i3_enable_tx(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100673 ret = iwl_mvm_update_quotas(mvm, NULL);
674 if (ret)
675 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
676 ret);
677
Eliad Peller7498cf42014-01-16 17:10:44 +0200678 /* allow transport/FW low power modes */
679 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
680
Johannes Berg8ca151b2013-01-24 14:25:36 +0100681 mutex_unlock(&mvm->mutex);
682}
683
684static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
685{
686 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
687
Eliad Peller37577fe2013-12-05 17:19:39 +0200688 flush_work(&mvm->d0i3_exit_work);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100689 flush_work(&mvm->async_handlers_wk);
690
691 mutex_lock(&mvm->mutex);
Eliad Peller7498cf42014-01-16 17:10:44 +0200692
693 /* disallow low power states when the FW is down */
694 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
695
Johannes Berg8ca151b2013-01-24 14:25:36 +0100696 /* async_handlers_wk is now blocked */
697
698 /*
699 * The work item could be running or queued if the
700 * ROC time event stops just as we get here.
701 */
702 cancel_work_sync(&mvm->roc_done_wk);
703
704 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100705
706 iwl_mvm_async_handlers_purge(mvm);
707 /* async_handlers_list is empty and will stay empty: HW is stopped */
708
709 /* the fw is stopped, the aux sta is dead: clean up driver state */
710 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
711
712 mutex_unlock(&mvm->mutex);
713
714 /*
715 * The worker might have been waiting for the mutex, let it run and
716 * discover that its list is now empty.
717 */
718 cancel_work_sync(&mvm->async_handlers_wk);
719}
720
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200721static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
722{
723 u16 i;
724
725 lockdep_assert_held(&mvm->mutex);
726
727 for (i = 0; i < NUM_PHY_CTX; i++)
728 if (!mvm->phy_ctxts[i].ref)
729 return &mvm->phy_ctxts[i];
730
731 IWL_ERR(mvm, "No available PHY context\n");
732 return NULL;
733}
734
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +0200735static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
736 s8 tx_power)
737{
738 /* FW is in charge of regulatory enforcement */
739 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
740 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
741 .pwr_restriction = cpu_to_le16(tx_power),
742 };
743
744 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
745 sizeof(reduce_txpwr_cmd),
746 &reduce_txpwr_cmd);
747}
748
Johannes Berg8ca151b2013-01-24 14:25:36 +0100749static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
750 struct ieee80211_vif *vif)
751{
752 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
753 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
754 int ret;
755
756 /*
757 * Not much to do here. The stack will not allow interface
758 * types or combinations that we didn't advertise, so we
759 * don't really have to check the types.
760 */
761
762 mutex_lock(&mvm->mutex);
763
Eliad Pellere89044d2013-07-16 17:33:26 +0300764 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100765 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
766 if (ret)
767 goto out_unlock;
768
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300769 /* Counting number of interfaces is needed for legacy PM */
Ilan Peerea183d02013-07-23 14:41:53 +0300770 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
771 mvm->vif_count++;
Ilan Peerea183d02013-07-23 14:41:53 +0300772
773 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +0100774 * The AP binding flow can be done only after the beacon
775 * template is configured (which happens only in the mac80211
776 * start_ap() flow), and adding the broadcast station can happen
777 * only after the binding.
778 * In addition, since modifying the MAC before adding a bcast
779 * station is not allowed by the FW, delay the adding of MAC context to
780 * the point where we can also add the bcast station.
781 * In short: there's not much we can do at this point, other than
782 * allocating resources :)
783 */
Johannes Berg5023d962013-07-31 14:07:43 +0200784 if (vif->type == NL80211_IFTYPE_AP ||
785 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100786 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
787 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
Eliad Pellerb92e6612014-01-23 17:58:23 +0200788 qmask,
789 ieee80211_vif_type_p2p(vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100790 if (ret) {
791 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
792 goto out_release;
793 }
794
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +0300795 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100796 goto out_unlock;
797 }
798
Johannes Berg8ca151b2013-01-24 14:25:36 +0100799 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
800 if (ret)
801 goto out_release;
802
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200803 ret = iwl_mvm_power_update_mac(mvm, vif);
804 if (ret)
805 goto out_release;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100806
Hila Gonen7df15b12012-12-12 11:16:19 +0200807 /* beacon filtering */
Eliad Peller3dd37d02014-01-07 14:00:24 +0200808 ret = iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300809 if (ret)
810 goto out_remove_mac;
811
Hila Gonen7df15b12012-12-12 11:16:19 +0200812 if (!mvm->bf_allowed_vif &&
Hila Gonen5dca7c22013-07-16 11:15:35 +0300813 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
814 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){
Hila Gonen7df15b12012-12-12 11:16:19 +0200815 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300816 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
817 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +0200818 }
819
Johannes Berg8ca151b2013-01-24 14:25:36 +0100820 /*
821 * P2P_DEVICE interface does not have a channel context assigned to it,
822 * so a dedicated PHY context is allocated to it and the corresponding
823 * MAC context is bound to it at this stage.
824 */
825 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100826
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200827 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
828 if (!mvmvif->phy_ctxt) {
829 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300830 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200831 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100832
Ilan Peer53a9d612013-04-28 11:55:08 +0300833 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100834 ret = iwl_mvm_binding_add_vif(mvm, vif);
835 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +0300836 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100837
838 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
839 if (ret)
840 goto out_unbind;
841
842 /* Save a pointer to p2p device vif, so it can later be used to
843 * update the p2p device MAC when a GO is started/stopped */
844 mvm->p2p_device_vif = vif;
845 }
846
Johannes Berg63494372013-03-26 10:47:53 +0100847 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100848 goto out_unlock;
849
850 out_unbind:
851 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +0300852 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200853 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300854 out_free_bf:
855 if (mvm->bf_allowed_vif == mvmvif) {
856 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300857 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
858 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300859 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100860 out_remove_mac:
861 mvmvif->phy_ctxt = NULL;
862 iwl_mvm_mac_ctxt_remove(mvm, vif);
863 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200864 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
865 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300866
Johannes Berg8ca151b2013-01-24 14:25:36 +0100867 iwl_mvm_mac_ctxt_release(mvm, vif);
868 out_unlock:
869 mutex_unlock(&mvm->mutex);
870
871 return ret;
872}
873
Johannes Berg38a12b52013-02-22 14:07:56 +0100874static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
875 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100876{
Johannes Berg8ca151b2013-01-24 14:25:36 +0100877 u32 tfd_msk = 0, ac;
878
879 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
880 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
881 tfd_msk |= BIT(vif->hw_queue[ac]);
882
883 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
884 tfd_msk |= BIT(vif->cab_queue);
885
886 if (tfd_msk) {
887 mutex_lock(&mvm->mutex);
888 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
889 mutex_unlock(&mvm->mutex);
890 }
891
892 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
893 /*
894 * Flush the ROC worker which will flush the OFFCHANNEL queue.
895 * We assume here that all the packets sent to the OFFCHANNEL
896 * queue are sent in ROC session.
897 */
898 flush_work(&mvm->roc_done_wk);
899 } else {
900 /*
901 * By now, all the AC queues are empty. The AGG queues are
902 * empty too. We already got all the Tx responses for all the
903 * packets in the queues. The drain work can have been
Emmanuel Grumbach0742a752013-06-10 14:10:33 +0300904 * triggered. Flush it.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100905 */
906 flush_work(&mvm->sta_drained_wk);
907 }
Johannes Berg38a12b52013-02-22 14:07:56 +0100908}
909
910static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
911 struct ieee80211_vif *vif)
912{
913 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
914 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
915
916 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100917
918 mutex_lock(&mvm->mutex);
919
Hila Gonen7df15b12012-12-12 11:16:19 +0200920 if (mvm->bf_allowed_vif == mvmvif) {
921 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300922 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
923 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +0200924 }
925
Johannes Berg63494372013-03-26 10:47:53 +0100926 iwl_mvm_vif_dbgfs_clean(mvm, vif);
927
Johannes Berg8ca151b2013-01-24 14:25:36 +0100928 /*
929 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +0100930 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100931 */
Johannes Berg5023d962013-07-31 14:07:43 +0200932 if (vif->type == NL80211_IFTYPE_AP ||
933 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +0300934#ifdef CONFIG_NL80211_TESTMODE
935 if (vif == mvm->noa_vif) {
936 mvm->noa_vif = NULL;
937 mvm->noa_duration = 0;
938 }
939#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +0100940 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
941 goto out_release;
942 }
943
944 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
945 mvm->p2p_device_vif = NULL;
946 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
947 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200948 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100949 mvmvif->phy_ctxt = NULL;
950 }
951
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200952 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100953 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300954
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200955 iwl_mvm_power_update_mac(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100956 iwl_mvm_mac_ctxt_remove(mvm, vif);
957
958out_release:
959 iwl_mvm_mac_ctxt_release(mvm, vif);
960 mutex_unlock(&mvm->mutex);
961}
962
963static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
964{
965 return 0;
966}
967
Eliad Pellere59647e2013-11-28 14:08:50 +0200968struct iwl_mvm_mc_iter_data {
969 struct iwl_mvm *mvm;
970 int port_id;
971};
972
973static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
974 struct ieee80211_vif *vif)
975{
976 struct iwl_mvm_mc_iter_data *data = _data;
977 struct iwl_mvm *mvm = data->mvm;
978 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
979 int ret, len;
980
981 /* if we don't have free ports, mcast frames will be dropped */
982 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
983 return;
984
985 if (vif->type != NL80211_IFTYPE_STATION ||
986 !vif->bss_conf.assoc)
987 return;
988
989 cmd->port_id = data->port_id++;
990 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
991 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
992
993 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC, len, cmd);
994 if (ret)
995 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
996}
997
998static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
999{
1000 struct iwl_mvm_mc_iter_data iter_data = {
1001 .mvm = mvm,
1002 };
1003
1004 lockdep_assert_held(&mvm->mutex);
1005
1006 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1007 return;
1008
1009 ieee80211_iterate_active_interfaces(
1010 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1011 iwl_mvm_mc_iface_iterator, &iter_data);
1012}
1013
1014static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1015 struct netdev_hw_addr_list *mc_list)
1016{
1017 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1018 struct iwl_mcast_filter_cmd *cmd;
1019 struct netdev_hw_addr *addr;
1020 int addr_count = netdev_hw_addr_list_count(mc_list);
1021 bool pass_all = false;
1022 int len;
1023
1024 if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) {
1025 pass_all = true;
1026 addr_count = 0;
1027 }
1028
1029 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1030 cmd = kzalloc(len, GFP_ATOMIC);
1031 if (!cmd)
1032 return 0;
1033
1034 if (pass_all) {
1035 cmd->pass_all = 1;
1036 return (u64)(unsigned long)cmd;
1037 }
1038
1039 netdev_hw_addr_list_for_each(addr, mc_list) {
1040 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1041 cmd->count, addr->addr);
1042 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1043 addr->addr, ETH_ALEN);
1044 cmd->count++;
1045 }
1046
1047 return (u64)(unsigned long)cmd;
1048}
1049
Johannes Berg8ca151b2013-01-24 14:25:36 +01001050static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1051 unsigned int changed_flags,
1052 unsigned int *total_flags,
1053 u64 multicast)
1054{
Eliad Pellere59647e2013-11-28 14:08:50 +02001055 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1056 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1057
1058 mutex_lock(&mvm->mutex);
1059
1060 /* replace previous configuration */
1061 kfree(mvm->mcast_filter_cmd);
1062 mvm->mcast_filter_cmd = cmd;
1063
1064 if (!cmd)
1065 goto out;
1066
1067 iwl_mvm_recalc_multicast(mvm);
1068out:
1069 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001070 *total_flags = 0;
1071}
1072
Eliad Pellerc87163b2014-01-08 10:11:11 +02001073#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1074struct iwl_bcast_iter_data {
1075 struct iwl_mvm *mvm;
1076 struct iwl_bcast_filter_cmd *cmd;
1077 u8 current_filter;
1078};
1079
1080static void
1081iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1082 const struct iwl_fw_bcast_filter *in_filter,
1083 struct iwl_fw_bcast_filter *out_filter)
1084{
1085 struct iwl_fw_bcast_filter_attr *attr;
1086 int i;
1087
1088 memcpy(out_filter, in_filter, sizeof(*out_filter));
1089
1090 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1091 attr = &out_filter->attrs[i];
1092
1093 if (!attr->mask)
1094 break;
1095
Eliad Peller2ee8f022014-01-13 19:07:09 +02001096 switch (attr->reserved1) {
1097 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1098 if (vif->bss_conf.arp_addr_cnt != 1) {
1099 attr->mask = 0;
1100 continue;
1101 }
1102
1103 attr->val = vif->bss_conf.arp_addr_list[0];
1104 break;
1105 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1106 attr->val = *(__be32 *)&vif->addr[2];
1107 break;
1108 default:
1109 break;
1110 }
1111 attr->reserved1 = 0;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001112 out_filter->num_attrs++;
1113 }
1114}
1115
1116static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1117 struct ieee80211_vif *vif)
1118{
1119 struct iwl_bcast_iter_data *data = _data;
1120 struct iwl_mvm *mvm = data->mvm;
1121 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1122 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1123 struct iwl_fw_bcast_mac *bcast_mac;
1124 int i;
1125
1126 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1127 return;
1128
1129 bcast_mac = &cmd->macs[mvmvif->id];
1130
1131 /* enable filtering only for associated stations */
1132 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
1133 return;
1134
1135 bcast_mac->default_discard = 1;
1136
1137 /* copy all configured filters */
1138 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1139 /*
1140 * Make sure we don't exceed our filters limit.
1141 * if there is still a valid filter to be configured,
1142 * be on the safe side and just allow bcast for this mac.
1143 */
1144 if (WARN_ON_ONCE(data->current_filter >=
1145 ARRAY_SIZE(cmd->filters))) {
1146 bcast_mac->default_discard = 0;
1147 bcast_mac->attached_filters = 0;
1148 break;
1149 }
1150
1151 iwl_mvm_set_bcast_filter(vif,
1152 &mvm->bcast_filters[i],
1153 &cmd->filters[data->current_filter]);
1154
1155 /* skip current filter if it contains no attributes */
1156 if (!cmd->filters[data->current_filter].num_attrs)
1157 continue;
1158
1159 /* attach the filter to current mac */
1160 bcast_mac->attached_filters |=
1161 cpu_to_le16(BIT(data->current_filter));
1162
1163 data->current_filter++;
1164 }
1165}
1166
Eliad Pellerde06a592014-01-08 10:11:12 +02001167bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1168 struct iwl_bcast_filter_cmd *cmd)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001169{
Eliad Pellerc87163b2014-01-08 10:11:11 +02001170 struct iwl_bcast_iter_data iter_data = {
1171 .mvm = mvm,
Eliad Pellerde06a592014-01-08 10:11:12 +02001172 .cmd = cmd,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001173 };
1174
Eliad Pellerde06a592014-01-08 10:11:12 +02001175 memset(cmd, 0, sizeof(*cmd));
1176 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1177 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1178
1179#ifdef CONFIG_IWLWIFI_DEBUGFS
1180 /* use debugfs filters/macs if override is configured */
1181 if (mvm->dbgfs_bcast_filtering.override) {
1182 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1183 sizeof(cmd->filters));
1184 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1185 sizeof(cmd->macs));
1186 return true;
1187 }
1188#endif
Eliad Pellerc87163b2014-01-08 10:11:11 +02001189
1190 /* if no filters are configured, do nothing */
1191 if (!mvm->bcast_filters)
Eliad Pellerde06a592014-01-08 10:11:12 +02001192 return false;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001193
1194 /* configure and attach these filters for each associated sta vif */
1195 ieee80211_iterate_active_interfaces(
1196 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1197 iwl_mvm_bcast_filter_iterator, &iter_data);
1198
Eliad Pellerde06a592014-01-08 10:11:12 +02001199 return true;
1200}
1201static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1202 struct ieee80211_vif *vif)
1203{
1204 struct iwl_bcast_filter_cmd cmd;
1205
1206 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1207 return 0;
1208
1209 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1210 return 0;
1211
Eliad Pellerc87163b2014-01-08 10:11:11 +02001212 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, CMD_SYNC,
1213 sizeof(cmd), &cmd);
1214}
1215#else
1216static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1217 struct ieee80211_vif *vif)
1218{
1219 return 0;
1220}
1221#endif
1222
Johannes Berg8ca151b2013-01-24 14:25:36 +01001223static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1224 struct ieee80211_vif *vif,
1225 struct ieee80211_bss_conf *bss_conf,
1226 u32 changes)
1227{
1228 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1229 int ret;
1230
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001231 /*
1232 * Re-calculate the tsf id, as the master-slave relations depend on the
1233 * beacon interval, which was not known when the station interface was
1234 * added.
1235 */
1236 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1237 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1238
Johannes Berg8ca151b2013-01-24 14:25:36 +01001239 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1240 if (ret)
1241 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1242
1243 if (changes & BSS_CHANGED_ASSOC) {
1244 if (bss_conf->assoc) {
1245 /* add quota for this interface */
1246 ret = iwl_mvm_update_quotas(mvm, vif);
1247 if (ret) {
1248 IWL_ERR(mvm, "failed to update quotas\n");
1249 return;
1250 }
Johannes Berg016d27e2013-05-03 11:16:15 +02001251
1252 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1253 &mvm->status)) {
1254 /*
1255 * If we're restarting then the firmware will
1256 * obviously have lost synchronisation with
1257 * the AP. It will attempt to synchronise by
1258 * itself, but we can make it more reliable by
1259 * scheduling a session protection time event.
1260 *
1261 * The firmware needs to receive a beacon to
1262 * catch up with synchronisation, use 110% of
1263 * the beacon interval.
1264 *
1265 * Set a large maximum delay to allow for more
1266 * than a single interface.
1267 */
1268 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1269 iwl_mvm_protect_session(mvm, vif, dur, dur,
1270 5 * dur);
1271 }
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001272
1273 iwl_mvm_sf_update(mvm, vif, false);
Alexander Bondar175a70b2013-04-14 20:59:37 +03001274 iwl_mvm_power_vif_assoc(mvm, vif);
Eliad Peller29a90a42013-11-05 14:06:29 +02001275 if (vif->p2p)
1276 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001277 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001278 /*
1279 * If update fails - SF might be running in associated
1280 * mode while disassociated - which is forbidden.
1281 */
1282 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1283 "Failed to update SF upon disassociation\n");
1284
Johannes Berg8ca151b2013-01-24 14:25:36 +01001285 /* remove AP station now that the MAC is unassoc */
1286 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1287 if (ret)
1288 IWL_ERR(mvm, "failed to remove AP station\n");
Eliad Peller37577fe2013-12-05 17:19:39 +02001289
1290 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1291 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001292 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1293 /* remove quota for this interface */
1294 ret = iwl_mvm_update_quotas(mvm, NULL);
1295 if (ret)
1296 IWL_ERR(mvm, "failed to update quotas\n");
Eliad Peller29a90a42013-11-05 14:06:29 +02001297
1298 if (vif->p2p)
1299 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001300 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001301
Eliad Pellere59647e2013-11-28 14:08:50 +02001302 iwl_mvm_recalc_multicast(mvm);
Eliad Pellerc87163b2014-01-08 10:11:11 +02001303 iwl_mvm_configure_bcast_filter(mvm, vif);
Eliad Pellere59647e2013-11-28 14:08:50 +02001304
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001305 /* reset rssi values */
1306 mvmvif->bf_data.ave_beacon_signal = 0;
1307
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001308 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachf94045e2014-01-06 13:38:55 +02001309 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1310 IEEE80211_SMPS_AUTOMATIC);
Alexander Bondar989c6502013-05-16 17:34:17 +03001311 } else if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +01001312 /*
1313 * We received a beacon _after_ association so
1314 * remove the session protection.
1315 */
1316 iwl_mvm_remove_time_event(mvm, mvmvif,
1317 &mvmvif->time_event_data);
Alexander Bondarc63722c2014-03-10 22:02:26 +02001318 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, CMD_SYNC));
Alexander Bondar51498cf2013-09-02 17:10:14 +03001319 } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS |
1320 BSS_CHANGED_QOS)) {
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001321 ret = iwl_mvm_power_update_mac(mvm, vif);
Alexander Bondar4bf881f2013-05-29 10:19:50 +03001322 if (ret)
1323 IWL_ERR(mvm, "failed to update power mode\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001324 }
Matti Gottlieb88f2fd72013-07-09 15:25:46 +03001325 if (changes & BSS_CHANGED_TXPOWER) {
1326 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1327 bss_conf->txpower);
1328 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1329 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001330
1331 if (changes & BSS_CHANGED_CQM) {
1332 IWL_DEBUG_MAC80211(mvm, "cqm info_changed");
1333 /* reset cqm events tracking */
1334 mvmvif->bf_data.last_cqm_event = 0;
Eliad Peller3dd37d02014-01-07 14:00:24 +02001335 ret = iwl_mvm_update_beacon_filter(mvm, vif, false, CMD_SYNC);
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001336 if (ret)
1337 IWL_ERR(mvm, "failed to update CQM thresholds\n");
1338 }
Eliad Peller2ee8f022014-01-13 19:07:09 +02001339
1340 if (changes & BSS_CHANGED_ARP_FILTER) {
1341 IWL_DEBUG_MAC80211(mvm, "arp filter changed");
1342 iwl_mvm_configure_bcast_filter(mvm, vif);
1343 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001344}
1345
Johannes Berg5023d962013-07-31 14:07:43 +02001346static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1347 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001348{
1349 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1350 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1351 int ret;
1352
1353 mutex_lock(&mvm->mutex);
1354
1355 /* Send the beacon template */
1356 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1357 if (ret)
1358 goto out_unlock;
1359
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001360 /*
1361 * Re-calculate the tsf id, as the master-slave relations depend on the
1362 * beacon interval, which was not known when the AP interface was added.
1363 */
1364 if (vif->type == NL80211_IFTYPE_AP)
1365 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1366
Johannes Berg8ca151b2013-01-24 14:25:36 +01001367 /* Add the mac context */
1368 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1369 if (ret)
1370 goto out_unlock;
1371
1372 /* Perform the binding */
1373 ret = iwl_mvm_binding_add_vif(mvm, vif);
1374 if (ret)
1375 goto out_remove;
1376
Johannes Berg8ca151b2013-01-24 14:25:36 +01001377 /* Send the bcast station. At this stage the TBTT and DTIM time events
1378 * are added and applied to the scheduler */
1379 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
1380 if (ret)
1381 goto out_unbind;
1382
Ilan Peer5691e212013-12-31 21:05:50 +02001383 /* must be set before quota calculations */
1384 mvmvif->ap_ibss_active = true;
1385
Ilan Peera11e1442013-12-31 21:19:55 +02001386 /* power updated needs to be done before quotas */
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001387 iwl_mvm_power_update_mac(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02001388
Johannes Berg8ca151b2013-01-24 14:25:36 +01001389 ret = iwl_mvm_update_quotas(mvm, vif);
1390 if (ret)
Ilan Peera11e1442013-12-31 21:19:55 +02001391 goto out_quota_failed;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001392
Johannes Berg5023d962013-07-31 14:07:43 +02001393 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001394 if (vif->p2p && mvm->p2p_device_vif)
1395 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1396
Eliad Peller29a90a42013-11-05 14:06:29 +02001397 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1398
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001399 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001400
Johannes Berg8ca151b2013-01-24 14:25:36 +01001401 mutex_unlock(&mvm->mutex);
1402 return 0;
1403
Ilan Peera11e1442013-12-31 21:19:55 +02001404out_quota_failed:
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001405 iwl_mvm_power_update_mac(mvm, vif);
Ilan Peer5691e212013-12-31 21:05:50 +02001406 mvmvif->ap_ibss_active = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001407 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1408out_unbind:
1409 iwl_mvm_binding_remove_vif(mvm, vif);
1410out_remove:
1411 iwl_mvm_mac_ctxt_remove(mvm, vif);
1412out_unlock:
1413 mutex_unlock(&mvm->mutex);
1414 return ret;
1415}
1416
Johannes Berg5023d962013-07-31 14:07:43 +02001417static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
1418 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001419{
1420 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1421 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1422
Johannes Berg38a12b52013-02-22 14:07:56 +01001423 iwl_mvm_prepare_mac_removal(mvm, vif);
1424
Johannes Berg8ca151b2013-01-24 14:25:36 +01001425 mutex_lock(&mvm->mutex);
1426
Johannes Berg5023d962013-07-31 14:07:43 +02001427 mvmvif->ap_ibss_active = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001428
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001429 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001430
Eliad Peller29a90a42013-11-05 14:06:29 +02001431 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
1432
Johannes Berg5023d962013-07-31 14:07:43 +02001433 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001434 if (vif->p2p && mvm->p2p_device_vif)
1435 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1436
1437 iwl_mvm_update_quotas(mvm, NULL);
1438 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1439 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02001440
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001441 iwl_mvm_power_update_mac(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02001442
Johannes Berg8ca151b2013-01-24 14:25:36 +01001443 iwl_mvm_mac_ctxt_remove(mvm, vif);
1444
1445 mutex_unlock(&mvm->mutex);
1446}
1447
Johannes Berg5023d962013-07-31 14:07:43 +02001448static void
1449iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
1450 struct ieee80211_vif *vif,
1451 struct ieee80211_bss_conf *bss_conf,
1452 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001453{
Ilan Peerbe2056f2013-12-04 16:47:14 +02001454 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman8a5e3662013-11-12 19:16:03 +02001455
Ilan Peerbe2056f2013-12-04 16:47:14 +02001456 /* Changes will be applied when the AP/IBSS is started */
1457 if (!mvmvif->ap_ibss_active)
1458 return;
1459
Johannes Berg863230da2013-12-04 17:08:40 +01001460 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
1461 BSS_CHANGED_BANDWIDTH) &&
1462 iwl_mvm_mac_ctxt_changed(mvm, vif))
1463 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
Avri Altman8a5e3662013-11-12 19:16:03 +02001464
Johannes Berg8ca151b2013-01-24 14:25:36 +01001465 /* Need to send a new beacon template to the FW */
Johannes Berg863230da2013-12-04 17:08:40 +01001466 if (changes & BSS_CHANGED_BEACON &&
1467 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1468 IWL_WARN(mvm, "Failed updating beacon data\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001469}
1470
1471static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1472 struct ieee80211_vif *vif,
1473 struct ieee80211_bss_conf *bss_conf,
1474 u32 changes)
1475{
1476 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1477
1478 mutex_lock(&mvm->mutex);
1479
1480 switch (vif->type) {
1481 case NL80211_IFTYPE_STATION:
1482 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1483 break;
1484 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02001485 case NL80211_IFTYPE_ADHOC:
1486 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001487 break;
1488 default:
1489 /* shouldn't happen */
1490 WARN_ON_ONCE(1);
1491 }
1492
1493 mutex_unlock(&mvm->mutex);
1494}
1495
1496static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
1497 struct ieee80211_vif *vif,
1498 struct cfg80211_scan_request *req)
1499{
1500 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1501 int ret;
1502
1503 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
1504 return -EINVAL;
1505
1506 mutex_lock(&mvm->mutex);
1507
Johannes Berga6623e82014-01-27 15:40:53 +01001508 switch (mvm->scan_status) {
1509 case IWL_MVM_SCAN_SCHED:
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001510 ret = iwl_mvm_sched_scan_stop(mvm);
Johannes Berga6623e82014-01-27 15:40:53 +01001511 if (ret) {
1512 ret = -EBUSY;
1513 goto out;
1514 }
Johannes Berga6623e82014-01-27 15:40:53 +01001515 break;
1516 case IWL_MVM_SCAN_NONE:
1517 break;
1518 default:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001519 ret = -EBUSY;
Arik Nemtsov519e2022013-10-17 17:51:35 +03001520 goto out;
1521 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001522
Arik Nemtsov519e2022013-10-17 17:51:35 +03001523 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
1524
1525 ret = iwl_mvm_scan_request(mvm, vif, req);
1526 if (ret)
1527 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1528out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001529 mutex_unlock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001530 /* make sure to flush the Rx handler before the next scan arrives */
1531 iwl_mvm_wait_for_async_handlers(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001532 return ret;
1533}
1534
1535static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1536 struct ieee80211_vif *vif)
1537{
1538 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1539
1540 mutex_lock(&mvm->mutex);
1541
1542 iwl_mvm_cancel_scan(mvm);
1543
1544 mutex_unlock(&mvm->mutex);
1545}
1546
1547static void
1548iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
Johannes Berg3e56ead2013-02-15 22:23:18 +01001549 struct ieee80211_sta *sta, u16 tids,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001550 int num_frames,
1551 enum ieee80211_frame_release_type reason,
1552 bool more_data)
1553{
1554 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001555
Johannes Berg3e56ead2013-02-15 22:23:18 +01001556 /* Called when we need to transmit (a) frame(s) from mac80211 */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001557
Johannes Berg3e56ead2013-02-15 22:23:18 +01001558 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1559 tids, more_data, false);
1560}
1561
1562static void
1563iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
1564 struct ieee80211_sta *sta, u16 tids,
1565 int num_frames,
1566 enum ieee80211_frame_release_type reason,
1567 bool more_data)
1568{
1569 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1570
1571 /* Called when we need to transmit (a) frame(s) from agg queue */
1572
1573 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1574 tids, more_data, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001575}
1576
1577static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1578 struct ieee80211_vif *vif,
1579 enum sta_notify_cmd cmd,
1580 struct ieee80211_sta *sta)
1581{
1582 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01001583 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg3e56ead2013-02-15 22:23:18 +01001584 int tid;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001585
1586 switch (cmd) {
1587 case STA_NOTIFY_SLEEP:
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03001588 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001589 ieee80211_sta_block_awake(hw, sta, true);
Johannes Berg3e56ead2013-02-15 22:23:18 +01001590 spin_lock_bh(&mvmsta->lock);
1591 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
1592 struct iwl_mvm_tid_data *tid_data;
1593
1594 tid_data = &mvmsta->tid_data[tid];
1595 if (tid_data->state != IWL_AGG_ON &&
1596 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
1597 continue;
1598 if (iwl_mvm_tid_queued(tid_data) == 0)
1599 continue;
1600 ieee80211_sta_set_buffered(sta, tid, true);
1601 }
1602 spin_unlock_bh(&mvmsta->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001603 /*
1604 * The fw updates the STA to be asleep. Tx packets on the Tx
1605 * queues to this station will not be transmitted. The fw will
1606 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1607 */
1608 break;
1609 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02001610 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01001611 break;
Johannes Berg9cc40712013-02-15 22:47:48 +01001612 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001613 break;
1614 default:
1615 break;
1616 }
1617}
1618
Johannes Berg1ddbbb02013-12-04 22:39:17 +01001619static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
1620 struct ieee80211_vif *vif,
1621 struct ieee80211_sta *sta)
1622{
1623 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1624 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1625
1626 /*
1627 * This is called before mac80211 does RCU synchronisation,
1628 * so here we already invalidate our internal RCU-protected
1629 * station pointer. The rest of the code will thus no longer
1630 * be able to find the station this way, and we don't rely
1631 * on further RCU synchronisation after the sta_state()
1632 * callback deleted the station.
1633 */
1634 mutex_lock(&mvm->mutex);
1635 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
1636 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1637 ERR_PTR(-ENOENT));
1638 mutex_unlock(&mvm->mutex);
1639}
1640
Johannes Berg8ca151b2013-01-24 14:25:36 +01001641static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1642 struct ieee80211_vif *vif,
1643 struct ieee80211_sta *sta,
1644 enum ieee80211_sta_state old_state,
1645 enum ieee80211_sta_state new_state)
1646{
1647 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1648 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1649 int ret;
1650
1651 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1652 sta->addr, old_state, new_state);
1653
1654 /* this would be a mac80211 bug ... but don't crash */
1655 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1656 return -EINVAL;
1657
1658 /* if a STA is being removed, reuse its ID */
1659 flush_work(&mvm->sta_drained_wk);
1660
1661 mutex_lock(&mvm->mutex);
1662 if (old_state == IEEE80211_STA_NOTEXIST &&
1663 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02001664 /*
1665 * Firmware bug - it'll crash if the beacon interval is less
1666 * than 16. We can't avoid connecting at all, so refuse the
1667 * station state change, this will cause mac80211 to abandon
1668 * attempts to connect to this AP, and eventually wpa_s will
1669 * blacklist the AP...
1670 */
1671 if (vif->type == NL80211_IFTYPE_STATION &&
1672 vif->bss_conf.beacon_int < 16) {
1673 IWL_ERR(mvm,
1674 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1675 sta->addr, vif->bss_conf.beacon_int);
1676 ret = -EINVAL;
1677 goto out_unlock;
1678 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001679 ret = iwl_mvm_add_sta(mvm, vif, sta);
1680 } else if (old_state == IEEE80211_STA_NONE &&
1681 new_state == IEEE80211_STA_AUTH) {
1682 ret = 0;
1683 } else if (old_state == IEEE80211_STA_AUTH &&
1684 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01001685 ret = iwl_mvm_update_sta(mvm, vif, sta);
1686 if (ret == 0)
1687 iwl_mvm_rs_rate_init(mvm, sta,
Eyal Shapirab87c2172013-11-09 23:37:55 +02001688 mvmvif->phy_ctxt->channel->band,
1689 true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001690 } else if (old_state == IEEE80211_STA_ASSOC &&
1691 new_state == IEEE80211_STA_AUTHORIZED) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001692 /* enable beacon filtering */
Alexander Bondarc63722c2014-03-10 22:02:26 +02001693 if (vif->bss_conf.dtim_period)
1694 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif,
1695 CMD_SYNC));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001696 ret = 0;
1697 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1698 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001699 /* disable beacon filtering */
Eliad Peller3dd37d02014-01-07 14:00:24 +02001700 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001701 ret = 0;
1702 } else if (old_state == IEEE80211_STA_ASSOC &&
1703 new_state == IEEE80211_STA_AUTH) {
1704 ret = 0;
1705 } else if (old_state == IEEE80211_STA_AUTH &&
1706 new_state == IEEE80211_STA_NONE) {
1707 ret = 0;
1708 } else if (old_state == IEEE80211_STA_NONE &&
1709 new_state == IEEE80211_STA_NOTEXIST) {
1710 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1711 } else {
1712 ret = -EIO;
1713 }
Johannes Berg48bc1302013-07-04 15:55:29 +02001714 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001715 mutex_unlock(&mvm->mutex);
1716
1717 return ret;
1718}
1719
1720static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1721{
1722 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1723
1724 mvm->rts_threshold = value;
1725
1726 return 0;
1727}
1728
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001729static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
1730 struct ieee80211_vif *vif,
1731 struct ieee80211_sta *sta, u32 changed)
1732{
1733 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1734
1735 if (vif->type == NL80211_IFTYPE_STATION &&
1736 changed & IEEE80211_RC_NSS_CHANGED)
1737 iwl_mvm_sf_update(mvm, vif, false);
1738}
1739
Johannes Berg8ca151b2013-01-24 14:25:36 +01001740static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1741 struct ieee80211_vif *vif, u16 ac,
1742 const struct ieee80211_tx_queue_params *params)
1743{
1744 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1745 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1746
1747 mvmvif->queue_params[ac] = *params;
1748
1749 /*
1750 * No need to update right away, we'll get BSS_CHANGED_QOS
1751 * The exception is P2P_DEVICE interface which needs immediate update.
1752 */
1753 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1754 int ret;
1755
1756 mutex_lock(&mvm->mutex);
1757 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1758 mutex_unlock(&mvm->mutex);
1759 return ret;
1760 }
1761 return 0;
1762}
1763
1764static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1765 struct ieee80211_vif *vif)
1766{
1767 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1768 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1769 200 + vif->bss_conf.beacon_int);
1770 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1771 100 + vif->bss_conf.beacon_int);
1772
1773 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1774 return;
1775
1776 mutex_lock(&mvm->mutex);
1777 /* Try really hard to protect the session and hear a beacon */
Johannes Berg016d27e2013-05-03 11:16:15 +02001778 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001779 mutex_unlock(&mvm->mutex);
1780}
1781
David Spinadel35a000b2013-08-28 09:29:43 +03001782static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
1783 struct ieee80211_vif *vif,
1784 struct cfg80211_sched_scan_request *req,
1785 struct ieee80211_sched_scan_ies *ies)
1786{
1787 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1788 int ret;
1789
1790 mutex_lock(&mvm->mutex);
1791
Arik Nemtsov91b80252014-02-10 12:49:39 +02001792 switch (mvm->scan_status) {
1793 case IWL_MVM_SCAN_OS:
1794 IWL_DEBUG_SCAN(mvm, "Stopping previous scan for sched_scan\n");
1795 ret = iwl_mvm_cancel_scan(mvm);
1796 if (ret) {
1797 ret = -EBUSY;
1798 goto out;
1799 }
1800
1801 /*
1802 * iwl_mvm_rx_scan_complete() will be called soon but will
1803 * not reset the scan status as it won't be IWL_MVM_SCAN_OS
1804 * any more since we queue the next scan immediately (below).
1805 * We make sure it is called before the next scan starts by
1806 * flushing the async-handlers work.
1807 */
1808 break;
1809 case IWL_MVM_SCAN_NONE:
1810 break;
1811 default:
David Spinadel35a000b2013-08-28 09:29:43 +03001812 ret = -EBUSY;
1813 goto out;
1814 }
1815
1816 mvm->scan_status = IWL_MVM_SCAN_SCHED;
1817
1818 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
1819 if (ret)
1820 goto err;
1821
1822 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1823 if (ret)
1824 goto err;
1825
1826 ret = iwl_mvm_sched_scan_start(mvm, req);
1827 if (!ret)
1828 goto out;
1829err:
1830 mvm->scan_status = IWL_MVM_SCAN_NONE;
1831out:
1832 mutex_unlock(&mvm->mutex);
Arik Nemtsov91b80252014-02-10 12:49:39 +02001833 /* make sure to flush the Rx handler before the next scan arrives */
1834 iwl_mvm_wait_for_async_handlers(mvm);
David Spinadel35a000b2013-08-28 09:29:43 +03001835 return ret;
1836}
1837
Johannes Berg37e33082014-02-17 10:48:17 +01001838static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
1839 struct ieee80211_vif *vif)
David Spinadel35a000b2013-08-28 09:29:43 +03001840{
1841 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001842 int ret;
David Spinadel35a000b2013-08-28 09:29:43 +03001843
1844 mutex_lock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001845 ret = iwl_mvm_sched_scan_stop(mvm);
David Spinadel35a000b2013-08-28 09:29:43 +03001846 mutex_unlock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001847 iwl_mvm_wait_for_async_handlers(mvm);
Johannes Berg37e33082014-02-17 10:48:17 +01001848
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001849 return ret;
David Spinadel35a000b2013-08-28 09:29:43 +03001850}
1851
Johannes Berg8ca151b2013-01-24 14:25:36 +01001852static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1853 enum set_key_cmd cmd,
1854 struct ieee80211_vif *vif,
1855 struct ieee80211_sta *sta,
1856 struct ieee80211_key_conf *key)
1857{
1858 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1859 int ret;
1860
1861 if (iwlwifi_mod_params.sw_crypto) {
1862 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1863 return -EOPNOTSUPP;
1864 }
1865
1866 switch (key->cipher) {
1867 case WLAN_CIPHER_SUITE_TKIP:
1868 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1869 /* fall-through */
1870 case WLAN_CIPHER_SUITE_CCMP:
1871 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1872 break;
1873 case WLAN_CIPHER_SUITE_AES_CMAC:
1874 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1875 break;
1876 case WLAN_CIPHER_SUITE_WEP40:
1877 case WLAN_CIPHER_SUITE_WEP104:
1878 /*
1879 * Support for TX only, at least for now, so accept
1880 * the key and do nothing else. Then mac80211 will
1881 * pass it for TX but we don't have to use it for RX.
1882 */
1883 return 0;
1884 default:
Max Stepanove36e5432013-08-27 19:56:13 +03001885 /* currently FW supports only one optional cipher scheme */
1886 if (hw->n_cipher_schemes &&
1887 hw->cipher_schemes->cipher == key->cipher)
1888 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
1889 else
1890 return -EOPNOTSUPP;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001891 }
1892
1893 mutex_lock(&mvm->mutex);
1894
1895 switch (cmd) {
1896 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02001897 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1898 vif->type == NL80211_IFTYPE_AP) && !sta) {
1899 /*
1900 * GTK on AP interface is a TX-only key, return 0;
1901 * on IBSS they're per-station and because we're lazy
1902 * we don't support them for RX, so do the same.
1903 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001904 ret = 0;
1905 key->hw_key_idx = STA_KEY_IDX_INVALID;
1906 break;
1907 }
1908
Johannes Berg8ca151b2013-01-24 14:25:36 +01001909 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1910 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1911 if (ret) {
1912 IWL_WARN(mvm, "set key failed\n");
1913 /*
1914 * can't add key for RX, but we don't need it
1915 * in the device for TX so still return 0
1916 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001917 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001918 ret = 0;
1919 }
1920
1921 break;
1922 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01001923 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1924 ret = 0;
1925 break;
1926 }
1927
Johannes Berg8ca151b2013-01-24 14:25:36 +01001928 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1929 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1930 break;
1931 default:
1932 ret = -EINVAL;
1933 }
1934
1935 mutex_unlock(&mvm->mutex);
1936 return ret;
1937}
1938
1939static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1940 struct ieee80211_vif *vif,
1941 struct ieee80211_key_conf *keyconf,
1942 struct ieee80211_sta *sta,
1943 u32 iv32, u16 *phase1key)
1944{
1945 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1946
Johannes Berg5023d962013-07-31 14:07:43 +02001947 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
1948 return;
1949
Johannes Berg8ca151b2013-01-24 14:25:36 +01001950 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1951}
1952
1953
1954static int iwl_mvm_roc(struct ieee80211_hw *hw,
1955 struct ieee80211_vif *vif,
1956 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02001957 int duration,
1958 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001959{
1960 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001961 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001962 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03001963 struct iwl_mvm_phy_ctxt *phy_ctxt;
1964 int ret, i;
1965
1966 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1967 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001968
1969 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1970 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1971 return -EINVAL;
1972 }
1973
Johannes Berg8ca151b2013-01-24 14:25:36 +01001974 mutex_lock(&mvm->mutex);
1975
Ilan Peer31d385a2013-04-02 10:25:46 +03001976 for (i = 0; i < NUM_PHY_CTX; i++) {
1977 phy_ctxt = &mvm->phy_ctxts[i];
1978 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
1979 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001980
Ilan Peer31d385a2013-04-02 10:25:46 +03001981 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1982 /*
1983 * Unbind the P2P_DEVICE from the current PHY context,
1984 * and if the PHY context is not used remove it.
1985 */
1986 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1987 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1988 goto out_unlock;
1989
1990 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1991
1992 /* Bind the P2P_DEVICE to the current PHY Context */
1993 mvmvif->phy_ctxt = phy_ctxt;
1994
1995 ret = iwl_mvm_binding_add_vif(mvm, vif);
1996 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1997 goto out_unlock;
1998
1999 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2000 goto schedule_time_event;
2001 }
2002 }
2003
2004 /* Need to update the PHY context only if the ROC channel changed */
2005 if (channel == mvmvif->phy_ctxt->channel)
2006 goto schedule_time_event;
2007
2008 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
2009
2010 /*
2011 * Change the PHY context configuration as it is currently referenced
2012 * only by the P2P Device MAC
2013 */
2014 if (mvmvif->phy_ctxt->ref == 1) {
2015 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2016 &chandef, 1, 1);
2017 if (ret)
2018 goto out_unlock;
2019 } else {
2020 /*
2021 * The PHY context is shared with other MACs. Need to remove the
2022 * P2P Device from the binding, allocate an new PHY context and
2023 * create a new binding
2024 */
2025 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2026 if (!phy_ctxt) {
2027 ret = -ENOSPC;
2028 goto out_unlock;
2029 }
2030
2031 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2032 1, 1);
2033 if (ret) {
2034 IWL_ERR(mvm, "Failed to change PHY context\n");
2035 goto out_unlock;
2036 }
2037
2038 /* Unbind the P2P_DEVICE from the current PHY context */
2039 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2040 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2041 goto out_unlock;
2042
2043 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2044
2045 /* Bind the P2P_DEVICE to the new allocated PHY context */
2046 mvmvif->phy_ctxt = phy_ctxt;
2047
2048 ret = iwl_mvm_binding_add_vif(mvm, vif);
2049 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2050 goto out_unlock;
2051
2052 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2053 }
2054
2055schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002056 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02002057 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002058
Ilan Peer31d385a2013-04-02 10:25:46 +03002059out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002060 mutex_unlock(&mvm->mutex);
2061 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01002062 return ret;
2063}
2064
2065static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
2066{
2067 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2068
2069 IWL_DEBUG_MAC80211(mvm, "enter\n");
2070
2071 mutex_lock(&mvm->mutex);
2072 iwl_mvm_stop_p2p_roc(mvm);
2073 mutex_unlock(&mvm->mutex);
2074
2075 IWL_DEBUG_MAC80211(mvm, "leave\n");
2076 return 0;
2077}
2078
2079static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2080 struct ieee80211_chanctx_conf *ctx)
2081{
2082 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002083 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2084 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002085 int ret;
2086
Ilan Peer53a9d612013-04-28 11:55:08 +03002087 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002088
2089 mutex_lock(&mvm->mutex);
2090 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2091 if (!phy_ctxt) {
2092 ret = -ENOSPC;
2093 goto out;
2094 }
2095
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02002096 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Ilan Peer53a9d612013-04-28 11:55:08 +03002097 ctx->rx_chains_static,
2098 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002099 if (ret) {
2100 IWL_ERR(mvm, "Failed to add PHY context\n");
2101 goto out;
2102 }
2103
Ilan Peer53a9d612013-04-28 11:55:08 +03002104 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002105 *phy_ctxt_id = phy_ctxt->id;
2106out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002107 mutex_unlock(&mvm->mutex);
2108 return ret;
2109}
2110
2111static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2112 struct ieee80211_chanctx_conf *ctx)
2113{
2114 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002115 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2116 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002117
2118 mutex_lock(&mvm->mutex);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002119 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002120 mutex_unlock(&mvm->mutex);
2121}
2122
2123static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
2124 struct ieee80211_chanctx_conf *ctx,
2125 u32 changed)
2126{
2127 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002128 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2129 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002130
Ilan Peer31d385a2013-04-02 10:25:46 +03002131 if (WARN_ONCE((phy_ctxt->ref > 1) &&
2132 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
2133 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
Arik Nemtsov2dceeda2013-12-29 17:57:53 +02002134 IEEE80211_CHANCTX_CHANGE_RADAR |
2135 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
Ilan Peer31d385a2013-04-02 10:25:46 +03002136 "Cannot change PHY. Ref=%d, changed=0x%X\n",
2137 phy_ctxt->ref, changed))
2138 return;
2139
Johannes Berg8ca151b2013-01-24 14:25:36 +01002140 mutex_lock(&mvm->mutex);
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02002141 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002142 ctx->rx_chains_static,
2143 ctx->rx_chains_dynamic);
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002144 iwl_mvm_bt_coex_vif_change(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002145 mutex_unlock(&mvm->mutex);
2146}
2147
2148static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
2149 struct ieee80211_vif *vif,
2150 struct ieee80211_chanctx_conf *ctx)
2151{
2152 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002153 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2154 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002155 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2156 int ret;
2157
2158 mutex_lock(&mvm->mutex);
2159
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002160 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002161
2162 switch (vif->type) {
2163 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02002164 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002165 /*
2166 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02002167 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01002168 */
2169 ret = 0;
2170 goto out_unlock;
2171 case NL80211_IFTYPE_STATION:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002172 case NL80211_IFTYPE_MONITOR:
2173 break;
2174 default:
2175 ret = -EINVAL;
2176 goto out_unlock;
2177 }
2178
2179 ret = iwl_mvm_binding_add_vif(mvm, vif);
2180 if (ret)
2181 goto out_unlock;
2182
2183 /*
Alexander Bondar92d85562013-10-23 11:50:34 +02002184 * Power state must be updated before quotas,
2185 * otherwise fw will complain.
2186 */
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02002187 iwl_mvm_power_update_mac(mvm, vif);
Alexander Bondar92d85562013-10-23 11:50:34 +02002188
2189 /* Setting the quota at this stage is only required for monitor
Johannes Berg8ca151b2013-01-24 14:25:36 +01002190 * interfaces. For the other types, the bss_info changed flow
2191 * will handle quota settings.
2192 */
2193 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02002194 mvmvif->monitor_active = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002195 ret = iwl_mvm_update_quotas(mvm, vif);
2196 if (ret)
2197 goto out_remove_binding;
2198 }
2199
2200 goto out_unlock;
2201
2202 out_remove_binding:
2203 iwl_mvm_binding_remove_vif(mvm, vif);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02002204 iwl_mvm_power_update_mac(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002205 out_unlock:
2206 mutex_unlock(&mvm->mutex);
2207 if (ret)
2208 mvmvif->phy_ctxt = NULL;
2209 return ret;
2210}
2211
2212static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
2213 struct ieee80211_vif *vif,
2214 struct ieee80211_chanctx_conf *ctx)
2215{
2216 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2217 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2218
2219 mutex_lock(&mvm->mutex);
2220
2221 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
2222
Johannes Berg8ca151b2013-01-24 14:25:36 +01002223 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02002224 case NL80211_IFTYPE_AP:
2225 case NL80211_IFTYPE_ADHOC:
2226 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002227 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02002228 mvmvif->monitor_active = false;
2229 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002230 break;
2231 default:
2232 break;
2233 }
2234
Ilan Peer1e1391c2013-03-13 14:52:04 +02002235 iwl_mvm_binding_remove_vif(mvm, vif);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02002236 iwl_mvm_power_update_mac(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03002237
Ilan Peera11e1442013-12-31 21:19:55 +02002238out_unlock:
2239 mvmvif->phy_ctxt = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002240 mutex_unlock(&mvm->mutex);
2241}
2242
2243static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
2244 struct ieee80211_sta *sta,
2245 bool set)
2246{
2247 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2248 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
2249
2250 if (!mvm_sta || !mvm_sta->vif) {
2251 IWL_ERR(mvm, "Station is not associated to a vif\n");
2252 return -EINVAL;
2253 }
2254
2255 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
2256}
2257
David Spinadel507cadf2013-07-31 18:07:21 +03002258#ifdef CONFIG_NL80211_TESTMODE
2259static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
2260 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
2261 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad42013-08-01 14:17:15 +02002262 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03002263};
2264
2265static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
2266 struct ieee80211_vif *vif,
2267 void *data, int len)
2268{
2269 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
2270 int err;
2271 u32 noa_duration;
2272
2273 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
2274 if (err)
2275 return err;
2276
2277 if (!tb[IWL_MVM_TM_ATTR_CMD])
2278 return -EINVAL;
2279
2280 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
2281 case IWL_MVM_TM_CMD_SET_NOA:
2282 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
2283 !vif->bss_conf.enable_beacon ||
2284 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
2285 return -EINVAL;
2286
2287 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
2288 if (noa_duration >= vif->bss_conf.beacon_int)
2289 return -EINVAL;
2290
2291 mvm->noa_duration = noa_duration;
2292 mvm->noa_vif = vif;
2293
2294 return iwl_mvm_update_quotas(mvm, NULL);
Johannes Bergf6c6ad42013-08-01 14:17:15 +02002295 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
2296 /* must be associated client vif - ignore authorized */
2297 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
2298 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
2299 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
2300 return -EINVAL;
2301
2302 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
Eliad Peller3dd37d02014-01-07 14:00:24 +02002303 return iwl_mvm_enable_beacon_filter(mvm, vif,
2304 CMD_SYNC);
2305 return iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC);
David Spinadel507cadf2013-07-31 18:07:21 +03002306 }
2307
2308 return -EOPNOTSUPP;
2309}
2310
2311static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
2312 struct ieee80211_vif *vif,
2313 void *data, int len)
2314{
2315 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2316 int err;
2317
2318 mutex_lock(&mvm->mutex);
2319 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
2320 mutex_unlock(&mvm->mutex);
2321
2322 return err;
2323}
2324#endif
2325
Johannes Berge5209262014-01-20 23:38:59 +01002326const struct ieee80211_ops iwl_mvm_hw_ops = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002327 .tx = iwl_mvm_mac_tx,
2328 .ampdu_action = iwl_mvm_mac_ampdu_action,
2329 .start = iwl_mvm_mac_start,
2330 .restart_complete = iwl_mvm_mac_restart_complete,
2331 .stop = iwl_mvm_mac_stop,
2332 .add_interface = iwl_mvm_mac_add_interface,
2333 .remove_interface = iwl_mvm_mac_remove_interface,
2334 .config = iwl_mvm_mac_config,
Eliad Pellere59647e2013-11-28 14:08:50 +02002335 .prepare_multicast = iwl_mvm_prepare_multicast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002336 .configure_filter = iwl_mvm_configure_filter,
2337 .bss_info_changed = iwl_mvm_bss_info_changed,
2338 .hw_scan = iwl_mvm_mac_hw_scan,
2339 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002340 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002341 .sta_state = iwl_mvm_mac_sta_state,
2342 .sta_notify = iwl_mvm_mac_sta_notify,
2343 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
Johannes Berg3e56ead2013-02-15 22:23:18 +01002344 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002345 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002346 .sta_rc_update = iwl_mvm_sta_rc_update,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002347 .conf_tx = iwl_mvm_mac_conf_tx,
2348 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
David Spinadel35a000b2013-08-28 09:29:43 +03002349 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
2350 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002351 .set_key = iwl_mvm_mac_set_key,
2352 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
2353 .remain_on_channel = iwl_mvm_roc,
2354 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002355 .add_chanctx = iwl_mvm_add_chanctx,
2356 .remove_chanctx = iwl_mvm_remove_chanctx,
2357 .change_chanctx = iwl_mvm_change_chanctx,
2358 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
2359 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
2360
Johannes Berg5023d962013-07-31 14:07:43 +02002361 .start_ap = iwl_mvm_start_ap_ibss,
2362 .stop_ap = iwl_mvm_stop_ap_ibss,
2363 .join_ibss = iwl_mvm_start_ap_ibss,
2364 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002365
2366 .set_tim = iwl_mvm_set_tim,
2367
David Spinadel507cadf2013-07-31 18:07:21 +03002368 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
2369
Johannes Berg8ca151b2013-01-24 14:25:36 +01002370#ifdef CONFIG_PM_SLEEP
2371 /* look at d3.c */
2372 .suspend = iwl_mvm_suspend,
2373 .resume = iwl_mvm_resume,
2374 .set_wakeup = iwl_mvm_set_wakeup,
2375 .set_rekey_data = iwl_mvm_set_rekey_data,
2376#if IS_ENABLED(CONFIG_IPV6)
2377 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
2378#endif
2379 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
2380#endif
2381};