blob: c4557225f46ea3b6656ac052470b44598fddd0a3 [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
Emmanuel Grumbacha82dda62014-03-18 16:32:45 +0200298 if (0 && mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT) {
Alexander Bondare8e626a2013-10-16 00:21:34 +0200299 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) |
Emmanuel Grumbachc13b1722014-03-27 19:12:12 +0200312 BIT(NL80211_IFTYPE_P2P_DEVICE) |
313 BIT(NL80211_IFTYPE_ADHOC);
Johannes Berg5023d962013-07-31 14:07:43 +0200314
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +0100315 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
316 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
317 REGULATORY_DISABLE_BEACON_HINTS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100318
Johannes Berg3e56ead2013-02-15 22:23:18 +0100319 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
320 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
321
Johannes Berg8ca151b2013-01-24 14:25:36 +0100322 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
323 hw->wiphy->n_iface_combinations =
324 ARRAY_SIZE(iwl_mvm_iface_combinations);
325
Ilan Peerc451e6d2013-02-20 08:41:54 +0200326 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100327 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
328
329 /* Extract MAC address */
330 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
331 hw->wiphy->addresses = mvm->addresses;
332 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200333
334 /* Extract additional MAC addresses if available */
335 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
336 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
337
338 for (i = 1; i < num_mac; i++) {
339 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100340 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200341 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100342 hw->wiphy->n_addresses++;
343 }
344
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200345 iwl_mvm_reset_phy_ctxts(mvm);
346
David Spinadel20f1a5d2013-08-21 09:14:27 +0300347 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
348
Johannes Berg8ca151b2013-01-24 14:25:36 +0100349 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
350
351 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
352 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
353 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
354 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
355 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
356 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
357
358 hw->wiphy->hw_version = mvm->trans->hw_id;
359
Alexander Bondarade50652013-04-03 16:28:47 +0300360 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100361 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
362 else
363 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
364
Emmanuel Grumbach833df4a2014-03-16 08:51:47 +0200365 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) {
David Spinadel35a000b2013-08-28 09:29:43 +0300366 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
367 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
368 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
369 /* we create the 802.11 header and zero length SSID IE. */
370 hw->wiphy->max_sched_scan_ie_len =
371 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
372 }
373
Johannes Berg8ca151b2013-01-24 14:25:36 +0100374 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
Alexander Bondar8a110d92014-03-12 17:31:19 +0200375 NL80211_FEATURE_P2P_GO_OPPPS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100376
377 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
378
Max Stepanove36e5432013-08-27 19:56:13 +0300379 /* currently FW API supports only one optional cipher scheme */
Johannes Berg9ddca862014-01-06 09:29:40 +0100380 if (mvm->fw->cs[0].cipher) {
Max Stepanove36e5432013-08-27 19:56:13 +0300381 mvm->hw->n_cipher_schemes = 1;
Johannes Berg9ddca862014-01-06 09:29:40 +0100382 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
Max Stepanove36e5432013-08-27 19:56:13 +0300383 }
384
Johannes Berg8ca151b2013-01-24 14:25:36 +0100385#ifdef CONFIG_PM_SLEEP
386 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
387 mvm->trans->ops->d3_suspend &&
388 mvm->trans->ops->d3_resume &&
389 device_can_wakeup(mvm->trans->dev)) {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200390 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
391 WIPHY_WOWLAN_DISCONNECT |
392 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
393 WIPHY_WOWLAN_RFKILL_RELEASE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100394 if (!iwlwifi_mod_params.sw_crypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200395 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
396 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
397 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100398
Johannes Berg964dc9e2013-06-03 17:25:34 +0200399 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
400 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
401 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
402 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
403 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100404 }
405#endif
406
Eliad Peller77736922014-01-14 12:35:49 +0200407#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
408 /* assign default bcast filtering configuration */
409 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
410#endif
411
Johannes Berg8ca151b2013-01-24 14:25:36 +0100412 ret = iwl_mvm_leds_init(mvm);
413 if (ret)
414 return ret;
415
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300416 ret = ieee80211_register_hw(mvm->hw);
417 if (ret)
418 iwl_mvm_leds_exit(mvm);
419
420 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100421}
422
Arik Nemtsovb2492502014-03-13 12:21:50 +0200423static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
424 struct ieee80211_sta *sta,
425 struct sk_buff *skb)
426{
427 struct iwl_mvm_sta *mvmsta;
428 bool defer = false;
429
430 /*
431 * double check the IN_D0I3 flag both before and after
432 * taking the spinlock, in order to prevent taking
433 * the spinlock when not needed.
434 */
435 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
436 return false;
437
438 spin_lock(&mvm->d0i3_tx_lock);
439 /*
440 * testing the flag again ensures the skb dequeue
441 * loop (on d0i3 exit) hasn't run yet.
442 */
443 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
444 goto out;
445
446 mvmsta = iwl_mvm_sta_from_mac80211(sta);
447 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
448 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
449 goto out;
450
451 __skb_queue_tail(&mvm->d0i3_tx, skb);
452 ieee80211_stop_queues(mvm->hw);
453
454 /* trigger wakeup */
455 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
456 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
457
458 defer = true;
459out:
460 spin_unlock(&mvm->d0i3_tx_lock);
461 return defer;
462}
463
Johannes Berg8ca151b2013-01-24 14:25:36 +0100464static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
465 struct ieee80211_tx_control *control,
466 struct sk_buff *skb)
467{
468 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg3e56ead2013-02-15 22:23:18 +0100469 struct ieee80211_sta *sta = control->sta;
470 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
471 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100472
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300473 if (iwl_mvm_is_radio_killed(mvm)) {
474 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100475 goto drop;
476 }
477
Ilan Peer398e8c62013-03-13 15:20:35 +0200478 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100479 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
480 goto drop;
481
Johannes Berg3e56ead2013-02-15 22:23:18 +0100482 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
483 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
484 ieee80211_is_mgmt(hdr->frame_control) &&
485 !ieee80211_is_deauth(hdr->frame_control) &&
486 !ieee80211_is_disassoc(hdr->frame_control) &&
487 !ieee80211_is_action(hdr->frame_control)))
488 sta = NULL;
489
490 if (sta) {
Arik Nemtsovb2492502014-03-13 12:21:50 +0200491 if (iwl_mvm_defer_tx(mvm, sta, skb))
492 return;
Johannes Berg3e56ead2013-02-15 22:23:18 +0100493 if (iwl_mvm_tx_skb(mvm, skb, sta))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100494 goto drop;
495 return;
496 }
497
498 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
499 goto drop;
500 return;
501 drop:
502 ieee80211_free_txskb(hw, skb);
503}
504
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200505static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
506{
507 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
508 return false;
509 return true;
510}
511
512static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
513{
514 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
515 return false;
516 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
517 return true;
518
519 /* enabled by default */
520 return true;
521}
522
Johannes Berg8ca151b2013-01-24 14:25:36 +0100523static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
524 struct ieee80211_vif *vif,
525 enum ieee80211_ampdu_mlme_action action,
526 struct ieee80211_sta *sta, u16 tid,
527 u16 *ssn, u8 buf_size)
528{
529 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
530 int ret;
Arik Nemtsovb2492502014-03-13 12:21:50 +0200531 bool tx_agg_ref = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100532
533 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
534 sta->addr, tid, action);
535
536 if (!(mvm->nvm_data->sku_cap_11n_enable))
537 return -EACCES;
538
Arik Nemtsovb2492502014-03-13 12:21:50 +0200539 /* return from D0i3 before starting a new Tx aggregation */
540 if (action == IEEE80211_AMPDU_TX_START) {
541 iwl_mvm_ref(mvm, IWL_MVM_REF_TX_AGG);
542 tx_agg_ref = true;
543
544 /*
545 * wait synchronously until D0i3 exit to get the correct
546 * sequence number for the tid
547 */
548 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
549 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status), HZ)) {
550 WARN_ON_ONCE(1);
551 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
552 return -EIO;
553 }
554 }
555
Johannes Berg8ca151b2013-01-24 14:25:36 +0100556 mutex_lock(&mvm->mutex);
557
558 switch (action) {
559 case IEEE80211_AMPDU_RX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200560 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100561 ret = -EINVAL;
562 break;
563 }
564 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
565 break;
566 case IEEE80211_AMPDU_RX_STOP:
567 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
568 break;
569 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach205e2212014-02-12 15:15:05 +0200570 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200571 ret = -EINVAL;
572 break;
573 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100574 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
575 break;
576 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200577 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
578 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100579 case IEEE80211_AMPDU_TX_STOP_FLUSH:
580 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200581 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100582 break;
583 case IEEE80211_AMPDU_TX_OPERATIONAL:
584 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
585 break;
586 default:
587 WARN_ON_ONCE(1);
588 ret = -EINVAL;
589 break;
590 }
591 mutex_unlock(&mvm->mutex);
592
Arik Nemtsovb2492502014-03-13 12:21:50 +0200593 /*
594 * If the tid is marked as started, we won't use it for offloaded
595 * traffic on the next D0i3 entry. It's safe to unref.
596 */
597 if (tx_agg_ref)
598 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
599
Johannes Berg8ca151b2013-01-24 14:25:36 +0100600 return ret;
601}
602
603static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
604 struct ieee80211_vif *vif)
605{
606 struct iwl_mvm *mvm = data;
607 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
608
609 mvmvif->uploaded = false;
610 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
611
612 /* does this make sense at all? */
613 mvmvif->color++;
614
615 spin_lock_bh(&mvm->time_event_lock);
616 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
617 spin_unlock_bh(&mvm->time_event_lock);
618
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200619 mvmvif->phy_ctxt = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100620}
621
622static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
623{
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +0200624#ifdef CONFIG_IWLWIFI_DEBUGFS
625 static char *env[] = { "DRIVER=iwlwifi", "EVENT=error_dump", NULL };
626
627 iwl_mvm_fw_error_dump(mvm);
628
629 /* notify the userspace about the error we had */
630 kobject_uevent_env(&mvm->hw->wiphy->dev.kobj, KOBJ_CHANGE, env);
631#endif
632
Johannes Berg8ca151b2013-01-24 14:25:36 +0100633 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100634
635 mvm->scan_status = IWL_MVM_SCAN_NONE;
636
637 /* just in case one was running */
638 ieee80211_remain_on_channel_expired(mvm->hw);
639
640 ieee80211_iterate_active_interfaces_atomic(
641 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
642 iwl_mvm_cleanup_iterator, mvm);
643
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200644 mvm->p2p_device_vif = NULL;
Eliad Peller37577fe2013-12-05 17:19:39 +0200645 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200646
647 iwl_mvm_reset_phy_ctxts(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100648 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
649 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
650
651 ieee80211_wake_queues(mvm->hw);
652
Eliad Peller7498cf42014-01-16 17:10:44 +0200653 /* cleanup all stale references (scan, roc), but keep the
654 * ucode_down ref until reconfig is complete */
655 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
656
Johannes Berg8ca151b2013-01-24 14:25:36 +0100657 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +0300658 mvm->rx_ba_sessions = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100659}
660
661static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
662{
663 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
664 int ret;
665
666 mutex_lock(&mvm->mutex);
667
668 /* Clean up some internal and mac80211 state on restart */
669 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
670 iwl_mvm_restart_cleanup(mvm);
671
672 ret = iwl_mvm_up(mvm);
673 mutex_unlock(&mvm->mutex);
674
675 return ret;
676}
677
678static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
679{
680 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
681 int ret;
682
683 mutex_lock(&mvm->mutex);
684
685 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
Arik Nemtsovb2492502014-03-13 12:21:50 +0200686 iwl_mvm_d0i3_enable_tx(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100687 ret = iwl_mvm_update_quotas(mvm, NULL);
688 if (ret)
689 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
690 ret);
691
Eliad Peller7498cf42014-01-16 17:10:44 +0200692 /* allow transport/FW low power modes */
693 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
694
Johannes Berg8ca151b2013-01-24 14:25:36 +0100695 mutex_unlock(&mvm->mutex);
696}
697
698static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
699{
700 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
701
Eliad Peller37577fe2013-12-05 17:19:39 +0200702 flush_work(&mvm->d0i3_exit_work);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100703 flush_work(&mvm->async_handlers_wk);
704
705 mutex_lock(&mvm->mutex);
Eliad Peller7498cf42014-01-16 17:10:44 +0200706
707 /* disallow low power states when the FW is down */
708 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
709
Johannes Berg8ca151b2013-01-24 14:25:36 +0100710 /* async_handlers_wk is now blocked */
711
712 /*
713 * The work item could be running or queued if the
714 * ROC time event stops just as we get here.
715 */
716 cancel_work_sync(&mvm->roc_done_wk);
717
718 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100719
720 iwl_mvm_async_handlers_purge(mvm);
721 /* async_handlers_list is empty and will stay empty: HW is stopped */
722
723 /* the fw is stopped, the aux sta is dead: clean up driver state */
724 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
725
726 mutex_unlock(&mvm->mutex);
727
728 /*
729 * The worker might have been waiting for the mutex, let it run and
730 * discover that its list is now empty.
731 */
732 cancel_work_sync(&mvm->async_handlers_wk);
733}
734
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200735static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
736{
737 u16 i;
738
739 lockdep_assert_held(&mvm->mutex);
740
741 for (i = 0; i < NUM_PHY_CTX; i++)
742 if (!mvm->phy_ctxts[i].ref)
743 return &mvm->phy_ctxts[i];
744
745 IWL_ERR(mvm, "No available PHY context\n");
746 return NULL;
747}
748
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +0200749static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
750 s8 tx_power)
751{
752 /* FW is in charge of regulatory enforcement */
753 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
754 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
755 .pwr_restriction = cpu_to_le16(tx_power),
756 };
757
758 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
759 sizeof(reduce_txpwr_cmd),
760 &reduce_txpwr_cmd);
761}
762
Johannes Berg8ca151b2013-01-24 14:25:36 +0100763static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
764 struct ieee80211_vif *vif)
765{
766 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
767 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
768 int ret;
769
770 /*
771 * Not much to do here. The stack will not allow interface
772 * types or combinations that we didn't advertise, so we
773 * don't really have to check the types.
774 */
775
776 mutex_lock(&mvm->mutex);
777
Eliad Pellere89044d2013-07-16 17:33:26 +0300778 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100779 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
780 if (ret)
781 goto out_unlock;
782
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300783 /* Counting number of interfaces is needed for legacy PM */
Ilan Peerea183d02013-07-23 14:41:53 +0300784 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
785 mvm->vif_count++;
Ilan Peerea183d02013-07-23 14:41:53 +0300786
787 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +0100788 * The AP binding flow can be done only after the beacon
789 * template is configured (which happens only in the mac80211
790 * start_ap() flow), and adding the broadcast station can happen
791 * only after the binding.
792 * In addition, since modifying the MAC before adding a bcast
793 * station is not allowed by the FW, delay the adding of MAC context to
794 * the point where we can also add the bcast station.
795 * In short: there's not much we can do at this point, other than
796 * allocating resources :)
797 */
Johannes Berg5023d962013-07-31 14:07:43 +0200798 if (vif->type == NL80211_IFTYPE_AP ||
799 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100800 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
801 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
Eliad Pellerb92e6612014-01-23 17:58:23 +0200802 qmask,
803 ieee80211_vif_type_p2p(vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100804 if (ret) {
805 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
806 goto out_release;
807 }
808
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +0300809 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100810 goto out_unlock;
811 }
812
Johannes Berg8ca151b2013-01-24 14:25:36 +0100813 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
814 if (ret)
815 goto out_release;
816
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200817 ret = iwl_mvm_power_update_mac(mvm, vif);
818 if (ret)
819 goto out_release;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100820
Hila Gonen7df15b12012-12-12 11:16:19 +0200821 /* beacon filtering */
Eliad Peller3dd37d02014-01-07 14:00:24 +0200822 ret = iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300823 if (ret)
824 goto out_remove_mac;
825
Hila Gonen7df15b12012-12-12 11:16:19 +0200826 if (!mvm->bf_allowed_vif &&
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +0300827 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
Hila Gonen7df15b12012-12-12 11:16:19 +0200828 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300829 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
830 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +0200831 }
832
Johannes Berg8ca151b2013-01-24 14:25:36 +0100833 /*
834 * P2P_DEVICE interface does not have a channel context assigned to it,
835 * so a dedicated PHY context is allocated to it and the corresponding
836 * MAC context is bound to it at this stage.
837 */
838 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100839
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200840 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
841 if (!mvmvif->phy_ctxt) {
842 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300843 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200844 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100845
Ilan Peer53a9d612013-04-28 11:55:08 +0300846 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100847 ret = iwl_mvm_binding_add_vif(mvm, vif);
848 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +0300849 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100850
851 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
852 if (ret)
853 goto out_unbind;
854
855 /* Save a pointer to p2p device vif, so it can later be used to
856 * update the p2p device MAC when a GO is started/stopped */
857 mvm->p2p_device_vif = vif;
858 }
859
Johannes Berg63494372013-03-26 10:47:53 +0100860 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100861 goto out_unlock;
862
863 out_unbind:
864 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +0300865 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200866 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300867 out_free_bf:
868 if (mvm->bf_allowed_vif == mvmvif) {
869 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300870 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
871 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300872 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100873 out_remove_mac:
874 mvmvif->phy_ctxt = NULL;
875 iwl_mvm_mac_ctxt_remove(mvm, vif);
876 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200877 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
878 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300879
Johannes Berg8ca151b2013-01-24 14:25:36 +0100880 iwl_mvm_mac_ctxt_release(mvm, vif);
881 out_unlock:
882 mutex_unlock(&mvm->mutex);
883
884 return ret;
885}
886
Johannes Berg38a12b52013-02-22 14:07:56 +0100887static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
888 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100889{
Johannes Berg8ca151b2013-01-24 14:25:36 +0100890 u32 tfd_msk = 0, ac;
891
892 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
893 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
894 tfd_msk |= BIT(vif->hw_queue[ac]);
895
896 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
897 tfd_msk |= BIT(vif->cab_queue);
898
899 if (tfd_msk) {
900 mutex_lock(&mvm->mutex);
901 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
902 mutex_unlock(&mvm->mutex);
903 }
904
905 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
906 /*
907 * Flush the ROC worker which will flush the OFFCHANNEL queue.
908 * We assume here that all the packets sent to the OFFCHANNEL
909 * queue are sent in ROC session.
910 */
911 flush_work(&mvm->roc_done_wk);
912 } else {
913 /*
914 * By now, all the AC queues are empty. The AGG queues are
915 * empty too. We already got all the Tx responses for all the
916 * packets in the queues. The drain work can have been
Emmanuel Grumbach0742a752013-06-10 14:10:33 +0300917 * triggered. Flush it.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100918 */
919 flush_work(&mvm->sta_drained_wk);
920 }
Johannes Berg38a12b52013-02-22 14:07:56 +0100921}
922
923static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
924 struct ieee80211_vif *vif)
925{
926 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
927 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
928
929 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100930
931 mutex_lock(&mvm->mutex);
932
Hila Gonen7df15b12012-12-12 11:16:19 +0200933 if (mvm->bf_allowed_vif == mvmvif) {
934 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300935 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
936 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +0200937 }
938
Johannes Berg63494372013-03-26 10:47:53 +0100939 iwl_mvm_vif_dbgfs_clean(mvm, vif);
940
Johannes Berg8ca151b2013-01-24 14:25:36 +0100941 /*
942 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +0100943 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100944 */
Johannes Berg5023d962013-07-31 14:07:43 +0200945 if (vif->type == NL80211_IFTYPE_AP ||
946 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +0300947#ifdef CONFIG_NL80211_TESTMODE
948 if (vif == mvm->noa_vif) {
949 mvm->noa_vif = NULL;
950 mvm->noa_duration = 0;
951 }
952#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +0100953 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
954 goto out_release;
955 }
956
957 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
958 mvm->p2p_device_vif = NULL;
959 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
960 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200961 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100962 mvmvif->phy_ctxt = NULL;
963 }
964
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200965 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100966 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300967
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200968 iwl_mvm_power_update_mac(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100969 iwl_mvm_mac_ctxt_remove(mvm, vif);
970
971out_release:
972 iwl_mvm_mac_ctxt_release(mvm, vif);
973 mutex_unlock(&mvm->mutex);
974}
975
976static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
977{
978 return 0;
979}
980
Eliad Pellere59647e2013-11-28 14:08:50 +0200981struct iwl_mvm_mc_iter_data {
982 struct iwl_mvm *mvm;
983 int port_id;
984};
985
986static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
987 struct ieee80211_vif *vif)
988{
989 struct iwl_mvm_mc_iter_data *data = _data;
990 struct iwl_mvm *mvm = data->mvm;
991 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
992 int ret, len;
993
994 /* if we don't have free ports, mcast frames will be dropped */
995 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
996 return;
997
998 if (vif->type != NL80211_IFTYPE_STATION ||
999 !vif->bss_conf.assoc)
1000 return;
1001
1002 cmd->port_id = data->port_id++;
1003 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1004 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1005
1006 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC, len, cmd);
1007 if (ret)
1008 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1009}
1010
1011static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1012{
1013 struct iwl_mvm_mc_iter_data iter_data = {
1014 .mvm = mvm,
1015 };
1016
1017 lockdep_assert_held(&mvm->mutex);
1018
1019 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1020 return;
1021
1022 ieee80211_iterate_active_interfaces(
1023 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1024 iwl_mvm_mc_iface_iterator, &iter_data);
1025}
1026
1027static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1028 struct netdev_hw_addr_list *mc_list)
1029{
1030 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1031 struct iwl_mcast_filter_cmd *cmd;
1032 struct netdev_hw_addr *addr;
1033 int addr_count = netdev_hw_addr_list_count(mc_list);
1034 bool pass_all = false;
1035 int len;
1036
1037 if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) {
1038 pass_all = true;
1039 addr_count = 0;
1040 }
1041
1042 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1043 cmd = kzalloc(len, GFP_ATOMIC);
1044 if (!cmd)
1045 return 0;
1046
1047 if (pass_all) {
1048 cmd->pass_all = 1;
1049 return (u64)(unsigned long)cmd;
1050 }
1051
1052 netdev_hw_addr_list_for_each(addr, mc_list) {
1053 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1054 cmd->count, addr->addr);
1055 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1056 addr->addr, ETH_ALEN);
1057 cmd->count++;
1058 }
1059
1060 return (u64)(unsigned long)cmd;
1061}
1062
Johannes Berg8ca151b2013-01-24 14:25:36 +01001063static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1064 unsigned int changed_flags,
1065 unsigned int *total_flags,
1066 u64 multicast)
1067{
Eliad Pellere59647e2013-11-28 14:08:50 +02001068 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1069 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1070
1071 mutex_lock(&mvm->mutex);
1072
1073 /* replace previous configuration */
1074 kfree(mvm->mcast_filter_cmd);
1075 mvm->mcast_filter_cmd = cmd;
1076
1077 if (!cmd)
1078 goto out;
1079
1080 iwl_mvm_recalc_multicast(mvm);
1081out:
1082 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001083 *total_flags = 0;
1084}
1085
Eliad Pellerc87163b2014-01-08 10:11:11 +02001086#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1087struct iwl_bcast_iter_data {
1088 struct iwl_mvm *mvm;
1089 struct iwl_bcast_filter_cmd *cmd;
1090 u8 current_filter;
1091};
1092
1093static void
1094iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1095 const struct iwl_fw_bcast_filter *in_filter,
1096 struct iwl_fw_bcast_filter *out_filter)
1097{
1098 struct iwl_fw_bcast_filter_attr *attr;
1099 int i;
1100
1101 memcpy(out_filter, in_filter, sizeof(*out_filter));
1102
1103 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1104 attr = &out_filter->attrs[i];
1105
1106 if (!attr->mask)
1107 break;
1108
Eliad Peller2ee8f022014-01-13 19:07:09 +02001109 switch (attr->reserved1) {
1110 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1111 if (vif->bss_conf.arp_addr_cnt != 1) {
1112 attr->mask = 0;
1113 continue;
1114 }
1115
1116 attr->val = vif->bss_conf.arp_addr_list[0];
1117 break;
1118 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1119 attr->val = *(__be32 *)&vif->addr[2];
1120 break;
1121 default:
1122 break;
1123 }
1124 attr->reserved1 = 0;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001125 out_filter->num_attrs++;
1126 }
1127}
1128
1129static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1130 struct ieee80211_vif *vif)
1131{
1132 struct iwl_bcast_iter_data *data = _data;
1133 struct iwl_mvm *mvm = data->mvm;
1134 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1135 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1136 struct iwl_fw_bcast_mac *bcast_mac;
1137 int i;
1138
1139 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1140 return;
1141
1142 bcast_mac = &cmd->macs[mvmvif->id];
1143
1144 /* enable filtering only for associated stations */
1145 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
1146 return;
1147
1148 bcast_mac->default_discard = 1;
1149
1150 /* copy all configured filters */
1151 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1152 /*
1153 * Make sure we don't exceed our filters limit.
1154 * if there is still a valid filter to be configured,
1155 * be on the safe side and just allow bcast for this mac.
1156 */
1157 if (WARN_ON_ONCE(data->current_filter >=
1158 ARRAY_SIZE(cmd->filters))) {
1159 bcast_mac->default_discard = 0;
1160 bcast_mac->attached_filters = 0;
1161 break;
1162 }
1163
1164 iwl_mvm_set_bcast_filter(vif,
1165 &mvm->bcast_filters[i],
1166 &cmd->filters[data->current_filter]);
1167
1168 /* skip current filter if it contains no attributes */
1169 if (!cmd->filters[data->current_filter].num_attrs)
1170 continue;
1171
1172 /* attach the filter to current mac */
1173 bcast_mac->attached_filters |=
1174 cpu_to_le16(BIT(data->current_filter));
1175
1176 data->current_filter++;
1177 }
1178}
1179
Eliad Pellerde06a592014-01-08 10:11:12 +02001180bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1181 struct iwl_bcast_filter_cmd *cmd)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001182{
Eliad Pellerc87163b2014-01-08 10:11:11 +02001183 struct iwl_bcast_iter_data iter_data = {
1184 .mvm = mvm,
Eliad Pellerde06a592014-01-08 10:11:12 +02001185 .cmd = cmd,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001186 };
1187
Eliad Pellerde06a592014-01-08 10:11:12 +02001188 memset(cmd, 0, sizeof(*cmd));
1189 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1190 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1191
1192#ifdef CONFIG_IWLWIFI_DEBUGFS
1193 /* use debugfs filters/macs if override is configured */
1194 if (mvm->dbgfs_bcast_filtering.override) {
1195 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1196 sizeof(cmd->filters));
1197 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1198 sizeof(cmd->macs));
1199 return true;
1200 }
1201#endif
Eliad Pellerc87163b2014-01-08 10:11:11 +02001202
1203 /* if no filters are configured, do nothing */
1204 if (!mvm->bcast_filters)
Eliad Pellerde06a592014-01-08 10:11:12 +02001205 return false;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001206
1207 /* configure and attach these filters for each associated sta vif */
1208 ieee80211_iterate_active_interfaces(
1209 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1210 iwl_mvm_bcast_filter_iterator, &iter_data);
1211
Eliad Pellerde06a592014-01-08 10:11:12 +02001212 return true;
1213}
1214static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1215 struct ieee80211_vif *vif)
1216{
1217 struct iwl_bcast_filter_cmd cmd;
1218
1219 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1220 return 0;
1221
Emmanuel Grumbach003e3c42014-04-01 21:34:59 +03001222 /* bcast filtering isn't supported for P2P client */
1223 if (vif->p2p)
1224 return 0;
1225
Eliad Pellerde06a592014-01-08 10:11:12 +02001226 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1227 return 0;
1228
Eliad Pellerc87163b2014-01-08 10:11:11 +02001229 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, CMD_SYNC,
1230 sizeof(cmd), &cmd);
1231}
1232#else
1233static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1234 struct ieee80211_vif *vif)
1235{
1236 return 0;
1237}
1238#endif
1239
Johannes Berg8ca151b2013-01-24 14:25:36 +01001240static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1241 struct ieee80211_vif *vif,
1242 struct ieee80211_bss_conf *bss_conf,
1243 u32 changes)
1244{
1245 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1246 int ret;
1247
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001248 /*
1249 * Re-calculate the tsf id, as the master-slave relations depend on the
1250 * beacon interval, which was not known when the station interface was
1251 * added.
1252 */
1253 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1254 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1255
Johannes Berg8ca151b2013-01-24 14:25:36 +01001256 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1257 if (ret)
1258 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1259
1260 if (changes & BSS_CHANGED_ASSOC) {
1261 if (bss_conf->assoc) {
1262 /* add quota for this interface */
1263 ret = iwl_mvm_update_quotas(mvm, vif);
1264 if (ret) {
1265 IWL_ERR(mvm, "failed to update quotas\n");
1266 return;
1267 }
Johannes Berg016d27e2013-05-03 11:16:15 +02001268
1269 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1270 &mvm->status)) {
1271 /*
1272 * If we're restarting then the firmware will
1273 * obviously have lost synchronisation with
1274 * the AP. It will attempt to synchronise by
1275 * itself, but we can make it more reliable by
1276 * scheduling a session protection time event.
1277 *
1278 * The firmware needs to receive a beacon to
1279 * catch up with synchronisation, use 110% of
1280 * the beacon interval.
1281 *
1282 * Set a large maximum delay to allow for more
1283 * than a single interface.
1284 */
1285 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1286 iwl_mvm_protect_session(mvm, vif, dur, dur,
1287 5 * dur);
1288 }
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001289
1290 iwl_mvm_sf_update(mvm, vif, false);
Alexander Bondar175a70b2013-04-14 20:59:37 +03001291 iwl_mvm_power_vif_assoc(mvm, vif);
Eliad Peller29a90a42013-11-05 14:06:29 +02001292 if (vif->p2p)
1293 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001294 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001295 /*
1296 * If update fails - SF might be running in associated
1297 * mode while disassociated - which is forbidden.
1298 */
1299 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1300 "Failed to update SF upon disassociation\n");
1301
Johannes Berg8ca151b2013-01-24 14:25:36 +01001302 /* remove AP station now that the MAC is unassoc */
1303 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1304 if (ret)
1305 IWL_ERR(mvm, "failed to remove AP station\n");
Eliad Peller37577fe2013-12-05 17:19:39 +02001306
1307 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1308 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001309 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1310 /* remove quota for this interface */
1311 ret = iwl_mvm_update_quotas(mvm, NULL);
1312 if (ret)
1313 IWL_ERR(mvm, "failed to update quotas\n");
Eliad Peller29a90a42013-11-05 14:06:29 +02001314
1315 if (vif->p2p)
1316 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001317 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001318
Eliad Pellere59647e2013-11-28 14:08:50 +02001319 iwl_mvm_recalc_multicast(mvm);
Eliad Pellerc87163b2014-01-08 10:11:11 +02001320 iwl_mvm_configure_bcast_filter(mvm, vif);
Eliad Pellere59647e2013-11-28 14:08:50 +02001321
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001322 /* reset rssi values */
1323 mvmvif->bf_data.ave_beacon_signal = 0;
1324
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001325 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachf94045e2014-01-06 13:38:55 +02001326 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1327 IEEE80211_SMPS_AUTOMATIC);
Alexander Bondar989c6502013-05-16 17:34:17 +03001328 } else if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +01001329 /*
1330 * We received a beacon _after_ association so
1331 * remove the session protection.
1332 */
1333 iwl_mvm_remove_time_event(mvm, mvmvif,
1334 &mvmvif->time_event_data);
Alexander Bondarc63722c2014-03-10 22:02:26 +02001335 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, CMD_SYNC));
Alexander Bondar51498cf2013-09-02 17:10:14 +03001336 } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS |
1337 BSS_CHANGED_QOS)) {
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001338 ret = iwl_mvm_power_update_mac(mvm, vif);
Alexander Bondar4bf881f2013-05-29 10:19:50 +03001339 if (ret)
1340 IWL_ERR(mvm, "failed to update power mode\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001341 }
Matti Gottlieb88f2fd72013-07-09 15:25:46 +03001342 if (changes & BSS_CHANGED_TXPOWER) {
1343 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1344 bss_conf->txpower);
1345 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1346 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001347
1348 if (changes & BSS_CHANGED_CQM) {
1349 IWL_DEBUG_MAC80211(mvm, "cqm info_changed");
1350 /* reset cqm events tracking */
1351 mvmvif->bf_data.last_cqm_event = 0;
Eliad Peller3dd37d02014-01-07 14:00:24 +02001352 ret = iwl_mvm_update_beacon_filter(mvm, vif, false, CMD_SYNC);
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001353 if (ret)
1354 IWL_ERR(mvm, "failed to update CQM thresholds\n");
1355 }
Eliad Peller2ee8f022014-01-13 19:07:09 +02001356
1357 if (changes & BSS_CHANGED_ARP_FILTER) {
1358 IWL_DEBUG_MAC80211(mvm, "arp filter changed");
1359 iwl_mvm_configure_bcast_filter(mvm, vif);
1360 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001361}
1362
Johannes Berg5023d962013-07-31 14:07:43 +02001363static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1364 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001365{
1366 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1367 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1368 int ret;
1369
1370 mutex_lock(&mvm->mutex);
1371
1372 /* Send the beacon template */
1373 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1374 if (ret)
1375 goto out_unlock;
1376
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001377 /*
1378 * Re-calculate the tsf id, as the master-slave relations depend on the
1379 * beacon interval, which was not known when the AP interface was added.
1380 */
1381 if (vif->type == NL80211_IFTYPE_AP)
1382 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1383
Johannes Berg8ca151b2013-01-24 14:25:36 +01001384 /* Add the mac context */
1385 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1386 if (ret)
1387 goto out_unlock;
1388
1389 /* Perform the binding */
1390 ret = iwl_mvm_binding_add_vif(mvm, vif);
1391 if (ret)
1392 goto out_remove;
1393
Johannes Berg8ca151b2013-01-24 14:25:36 +01001394 /* Send the bcast station. At this stage the TBTT and DTIM time events
1395 * are added and applied to the scheduler */
1396 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
1397 if (ret)
1398 goto out_unbind;
1399
Ilan Peer5691e212013-12-31 21:05:50 +02001400 /* must be set before quota calculations */
1401 mvmvif->ap_ibss_active = true;
1402
Ilan Peera11e1442013-12-31 21:19:55 +02001403 /* power updated needs to be done before quotas */
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001404 iwl_mvm_power_update_mac(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02001405
Johannes Berg8ca151b2013-01-24 14:25:36 +01001406 ret = iwl_mvm_update_quotas(mvm, vif);
1407 if (ret)
Ilan Peera11e1442013-12-31 21:19:55 +02001408 goto out_quota_failed;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001409
Johannes Berg5023d962013-07-31 14:07:43 +02001410 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001411 if (vif->p2p && mvm->p2p_device_vif)
1412 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1413
Eliad Peller29a90a42013-11-05 14:06:29 +02001414 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1415
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001416 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001417
Johannes Berg8ca151b2013-01-24 14:25:36 +01001418 mutex_unlock(&mvm->mutex);
1419 return 0;
1420
Ilan Peera11e1442013-12-31 21:19:55 +02001421out_quota_failed:
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001422 iwl_mvm_power_update_mac(mvm, vif);
Ilan Peer5691e212013-12-31 21:05:50 +02001423 mvmvif->ap_ibss_active = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001424 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1425out_unbind:
1426 iwl_mvm_binding_remove_vif(mvm, vif);
1427out_remove:
1428 iwl_mvm_mac_ctxt_remove(mvm, vif);
1429out_unlock:
1430 mutex_unlock(&mvm->mutex);
1431 return ret;
1432}
1433
Johannes Berg5023d962013-07-31 14:07:43 +02001434static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
1435 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001436{
1437 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1438 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1439
Johannes Berg38a12b52013-02-22 14:07:56 +01001440 iwl_mvm_prepare_mac_removal(mvm, vif);
1441
Johannes Berg8ca151b2013-01-24 14:25:36 +01001442 mutex_lock(&mvm->mutex);
1443
Johannes Berg5023d962013-07-31 14:07:43 +02001444 mvmvif->ap_ibss_active = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001445
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001446 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001447
Eliad Peller29a90a42013-11-05 14:06:29 +02001448 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
1449
Johannes Berg5023d962013-07-31 14:07:43 +02001450 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001451 if (vif->p2p && mvm->p2p_device_vif)
1452 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1453
1454 iwl_mvm_update_quotas(mvm, NULL);
1455 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1456 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02001457
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001458 iwl_mvm_power_update_mac(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02001459
Johannes Berg8ca151b2013-01-24 14:25:36 +01001460 iwl_mvm_mac_ctxt_remove(mvm, vif);
1461
1462 mutex_unlock(&mvm->mutex);
1463}
1464
Johannes Berg5023d962013-07-31 14:07:43 +02001465static void
1466iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
1467 struct ieee80211_vif *vif,
1468 struct ieee80211_bss_conf *bss_conf,
1469 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001470{
Ilan Peerbe2056f2013-12-04 16:47:14 +02001471 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman8a5e3662013-11-12 19:16:03 +02001472
Ilan Peerbe2056f2013-12-04 16:47:14 +02001473 /* Changes will be applied when the AP/IBSS is started */
1474 if (!mvmvif->ap_ibss_active)
1475 return;
1476
Johannes Berg863230da2013-12-04 17:08:40 +01001477 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
1478 BSS_CHANGED_BANDWIDTH) &&
1479 iwl_mvm_mac_ctxt_changed(mvm, vif))
1480 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
Avri Altman8a5e3662013-11-12 19:16:03 +02001481
Johannes Berg8ca151b2013-01-24 14:25:36 +01001482 /* Need to send a new beacon template to the FW */
Johannes Berg863230da2013-12-04 17:08:40 +01001483 if (changes & BSS_CHANGED_BEACON &&
1484 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1485 IWL_WARN(mvm, "Failed updating beacon data\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001486}
1487
1488static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1489 struct ieee80211_vif *vif,
1490 struct ieee80211_bss_conf *bss_conf,
1491 u32 changes)
1492{
1493 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1494
1495 mutex_lock(&mvm->mutex);
1496
1497 switch (vif->type) {
1498 case NL80211_IFTYPE_STATION:
1499 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1500 break;
1501 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02001502 case NL80211_IFTYPE_ADHOC:
1503 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001504 break;
1505 default:
1506 /* shouldn't happen */
1507 WARN_ON_ONCE(1);
1508 }
1509
1510 mutex_unlock(&mvm->mutex);
1511}
1512
1513static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
1514 struct ieee80211_vif *vif,
1515 struct cfg80211_scan_request *req)
1516{
1517 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1518 int ret;
1519
1520 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
1521 return -EINVAL;
1522
1523 mutex_lock(&mvm->mutex);
1524
Johannes Berga6623e82014-01-27 15:40:53 +01001525 switch (mvm->scan_status) {
1526 case IWL_MVM_SCAN_SCHED:
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001527 ret = iwl_mvm_sched_scan_stop(mvm);
Johannes Berga6623e82014-01-27 15:40:53 +01001528 if (ret) {
1529 ret = -EBUSY;
1530 goto out;
1531 }
Johannes Berga6623e82014-01-27 15:40:53 +01001532 break;
1533 case IWL_MVM_SCAN_NONE:
1534 break;
1535 default:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001536 ret = -EBUSY;
Arik Nemtsov519e2022013-10-17 17:51:35 +03001537 goto out;
1538 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001539
Arik Nemtsov519e2022013-10-17 17:51:35 +03001540 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
1541
1542 ret = iwl_mvm_scan_request(mvm, vif, req);
1543 if (ret)
1544 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1545out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001546 mutex_unlock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001547 /* make sure to flush the Rx handler before the next scan arrives */
1548 iwl_mvm_wait_for_async_handlers(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001549 return ret;
1550}
1551
1552static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1553 struct ieee80211_vif *vif)
1554{
1555 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1556
1557 mutex_lock(&mvm->mutex);
1558
1559 iwl_mvm_cancel_scan(mvm);
1560
1561 mutex_unlock(&mvm->mutex);
1562}
1563
1564static void
1565iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
Johannes Berg3e56ead2013-02-15 22:23:18 +01001566 struct ieee80211_sta *sta, u16 tids,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001567 int num_frames,
1568 enum ieee80211_frame_release_type reason,
1569 bool more_data)
1570{
1571 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001572
Johannes Berg3e56ead2013-02-15 22:23:18 +01001573 /* Called when we need to transmit (a) frame(s) from mac80211 */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001574
Johannes Berg3e56ead2013-02-15 22:23:18 +01001575 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1576 tids, more_data, false);
1577}
1578
1579static void
1580iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
1581 struct ieee80211_sta *sta, u16 tids,
1582 int num_frames,
1583 enum ieee80211_frame_release_type reason,
1584 bool more_data)
1585{
1586 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1587
1588 /* Called when we need to transmit (a) frame(s) from agg queue */
1589
1590 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1591 tids, more_data, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001592}
1593
1594static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1595 struct ieee80211_vif *vif,
1596 enum sta_notify_cmd cmd,
1597 struct ieee80211_sta *sta)
1598{
1599 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01001600 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg3e56ead2013-02-15 22:23:18 +01001601 int tid;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001602
1603 switch (cmd) {
1604 case STA_NOTIFY_SLEEP:
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03001605 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001606 ieee80211_sta_block_awake(hw, sta, true);
Johannes Berg3e56ead2013-02-15 22:23:18 +01001607 spin_lock_bh(&mvmsta->lock);
1608 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
1609 struct iwl_mvm_tid_data *tid_data;
1610
1611 tid_data = &mvmsta->tid_data[tid];
1612 if (tid_data->state != IWL_AGG_ON &&
1613 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
1614 continue;
1615 if (iwl_mvm_tid_queued(tid_data) == 0)
1616 continue;
1617 ieee80211_sta_set_buffered(sta, tid, true);
1618 }
1619 spin_unlock_bh(&mvmsta->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001620 /*
1621 * The fw updates the STA to be asleep. Tx packets on the Tx
1622 * queues to this station will not be transmitted. The fw will
1623 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1624 */
1625 break;
1626 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02001627 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01001628 break;
Johannes Berg9cc40712013-02-15 22:47:48 +01001629 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001630 break;
1631 default:
1632 break;
1633 }
1634}
1635
Johannes Berg1ddbbb02013-12-04 22:39:17 +01001636static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
1637 struct ieee80211_vif *vif,
1638 struct ieee80211_sta *sta)
1639{
1640 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1641 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1642
1643 /*
1644 * This is called before mac80211 does RCU synchronisation,
1645 * so here we already invalidate our internal RCU-protected
1646 * station pointer. The rest of the code will thus no longer
1647 * be able to find the station this way, and we don't rely
1648 * on further RCU synchronisation after the sta_state()
1649 * callback deleted the station.
1650 */
1651 mutex_lock(&mvm->mutex);
1652 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
1653 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1654 ERR_PTR(-ENOENT));
1655 mutex_unlock(&mvm->mutex);
1656}
1657
Johannes Berg8ca151b2013-01-24 14:25:36 +01001658static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1659 struct ieee80211_vif *vif,
1660 struct ieee80211_sta *sta,
1661 enum ieee80211_sta_state old_state,
1662 enum ieee80211_sta_state new_state)
1663{
1664 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1665 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1666 int ret;
1667
1668 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1669 sta->addr, old_state, new_state);
1670
1671 /* this would be a mac80211 bug ... but don't crash */
1672 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1673 return -EINVAL;
1674
1675 /* if a STA is being removed, reuse its ID */
1676 flush_work(&mvm->sta_drained_wk);
1677
1678 mutex_lock(&mvm->mutex);
1679 if (old_state == IEEE80211_STA_NOTEXIST &&
1680 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02001681 /*
1682 * Firmware bug - it'll crash if the beacon interval is less
1683 * than 16. We can't avoid connecting at all, so refuse the
1684 * station state change, this will cause mac80211 to abandon
1685 * attempts to connect to this AP, and eventually wpa_s will
1686 * blacklist the AP...
1687 */
1688 if (vif->type == NL80211_IFTYPE_STATION &&
1689 vif->bss_conf.beacon_int < 16) {
1690 IWL_ERR(mvm,
1691 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1692 sta->addr, vif->bss_conf.beacon_int);
1693 ret = -EINVAL;
1694 goto out_unlock;
1695 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001696 ret = iwl_mvm_add_sta(mvm, vif, sta);
1697 } else if (old_state == IEEE80211_STA_NONE &&
1698 new_state == IEEE80211_STA_AUTH) {
1699 ret = 0;
1700 } else if (old_state == IEEE80211_STA_AUTH &&
1701 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01001702 ret = iwl_mvm_update_sta(mvm, vif, sta);
1703 if (ret == 0)
1704 iwl_mvm_rs_rate_init(mvm, sta,
Eyal Shapirab87c2172013-11-09 23:37:55 +02001705 mvmvif->phy_ctxt->channel->band,
1706 true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001707 } else if (old_state == IEEE80211_STA_ASSOC &&
1708 new_state == IEEE80211_STA_AUTHORIZED) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001709 /* enable beacon filtering */
Alexander Bondarc63722c2014-03-10 22:02:26 +02001710 if (vif->bss_conf.dtim_period)
1711 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif,
1712 CMD_SYNC));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001713 ret = 0;
1714 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1715 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001716 /* disable beacon filtering */
Eliad Peller3dd37d02014-01-07 14:00:24 +02001717 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001718 ret = 0;
1719 } else if (old_state == IEEE80211_STA_ASSOC &&
1720 new_state == IEEE80211_STA_AUTH) {
1721 ret = 0;
1722 } else if (old_state == IEEE80211_STA_AUTH &&
1723 new_state == IEEE80211_STA_NONE) {
1724 ret = 0;
1725 } else if (old_state == IEEE80211_STA_NONE &&
1726 new_state == IEEE80211_STA_NOTEXIST) {
1727 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1728 } else {
1729 ret = -EIO;
1730 }
Johannes Berg48bc1302013-07-04 15:55:29 +02001731 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001732 mutex_unlock(&mvm->mutex);
1733
1734 return ret;
1735}
1736
1737static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1738{
1739 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1740
1741 mvm->rts_threshold = value;
1742
1743 return 0;
1744}
1745
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001746static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
1747 struct ieee80211_vif *vif,
1748 struct ieee80211_sta *sta, u32 changed)
1749{
1750 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1751
1752 if (vif->type == NL80211_IFTYPE_STATION &&
1753 changed & IEEE80211_RC_NSS_CHANGED)
1754 iwl_mvm_sf_update(mvm, vif, false);
1755}
1756
Johannes Berg8ca151b2013-01-24 14:25:36 +01001757static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1758 struct ieee80211_vif *vif, u16 ac,
1759 const struct ieee80211_tx_queue_params *params)
1760{
1761 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1762 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1763
1764 mvmvif->queue_params[ac] = *params;
1765
1766 /*
1767 * No need to update right away, we'll get BSS_CHANGED_QOS
1768 * The exception is P2P_DEVICE interface which needs immediate update.
1769 */
1770 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1771 int ret;
1772
1773 mutex_lock(&mvm->mutex);
1774 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1775 mutex_unlock(&mvm->mutex);
1776 return ret;
1777 }
1778 return 0;
1779}
1780
1781static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1782 struct ieee80211_vif *vif)
1783{
1784 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1785 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1786 200 + vif->bss_conf.beacon_int);
1787 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1788 100 + vif->bss_conf.beacon_int);
1789
1790 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1791 return;
1792
1793 mutex_lock(&mvm->mutex);
1794 /* Try really hard to protect the session and hear a beacon */
Johannes Berg016d27e2013-05-03 11:16:15 +02001795 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001796 mutex_unlock(&mvm->mutex);
1797}
1798
David Spinadel35a000b2013-08-28 09:29:43 +03001799static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
1800 struct ieee80211_vif *vif,
1801 struct cfg80211_sched_scan_request *req,
1802 struct ieee80211_sched_scan_ies *ies)
1803{
1804 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1805 int ret;
1806
1807 mutex_lock(&mvm->mutex);
1808
Arik Nemtsov91b80252014-02-10 12:49:39 +02001809 switch (mvm->scan_status) {
1810 case IWL_MVM_SCAN_OS:
1811 IWL_DEBUG_SCAN(mvm, "Stopping previous scan for sched_scan\n");
1812 ret = iwl_mvm_cancel_scan(mvm);
1813 if (ret) {
1814 ret = -EBUSY;
1815 goto out;
1816 }
1817
1818 /*
1819 * iwl_mvm_rx_scan_complete() will be called soon but will
1820 * not reset the scan status as it won't be IWL_MVM_SCAN_OS
1821 * any more since we queue the next scan immediately (below).
1822 * We make sure it is called before the next scan starts by
1823 * flushing the async-handlers work.
1824 */
1825 break;
1826 case IWL_MVM_SCAN_NONE:
1827 break;
1828 default:
David Spinadel35a000b2013-08-28 09:29:43 +03001829 ret = -EBUSY;
1830 goto out;
1831 }
1832
1833 mvm->scan_status = IWL_MVM_SCAN_SCHED;
1834
1835 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
1836 if (ret)
1837 goto err;
1838
1839 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1840 if (ret)
1841 goto err;
1842
1843 ret = iwl_mvm_sched_scan_start(mvm, req);
1844 if (!ret)
1845 goto out;
1846err:
1847 mvm->scan_status = IWL_MVM_SCAN_NONE;
1848out:
1849 mutex_unlock(&mvm->mutex);
Arik Nemtsov91b80252014-02-10 12:49:39 +02001850 /* make sure to flush the Rx handler before the next scan arrives */
1851 iwl_mvm_wait_for_async_handlers(mvm);
David Spinadel35a000b2013-08-28 09:29:43 +03001852 return ret;
1853}
1854
Johannes Berg37e33082014-02-17 10:48:17 +01001855static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
1856 struct ieee80211_vif *vif)
David Spinadel35a000b2013-08-28 09:29:43 +03001857{
1858 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001859 int ret;
David Spinadel35a000b2013-08-28 09:29:43 +03001860
1861 mutex_lock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001862 ret = iwl_mvm_sched_scan_stop(mvm);
David Spinadel35a000b2013-08-28 09:29:43 +03001863 mutex_unlock(&mvm->mutex);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001864 iwl_mvm_wait_for_async_handlers(mvm);
Johannes Berg37e33082014-02-17 10:48:17 +01001865
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001866 return ret;
David Spinadel35a000b2013-08-28 09:29:43 +03001867}
1868
Johannes Berg8ca151b2013-01-24 14:25:36 +01001869static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1870 enum set_key_cmd cmd,
1871 struct ieee80211_vif *vif,
1872 struct ieee80211_sta *sta,
1873 struct ieee80211_key_conf *key)
1874{
1875 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1876 int ret;
1877
1878 if (iwlwifi_mod_params.sw_crypto) {
1879 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1880 return -EOPNOTSUPP;
1881 }
1882
1883 switch (key->cipher) {
1884 case WLAN_CIPHER_SUITE_TKIP:
1885 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1886 /* fall-through */
1887 case WLAN_CIPHER_SUITE_CCMP:
1888 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1889 break;
1890 case WLAN_CIPHER_SUITE_AES_CMAC:
1891 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1892 break;
1893 case WLAN_CIPHER_SUITE_WEP40:
1894 case WLAN_CIPHER_SUITE_WEP104:
1895 /*
1896 * Support for TX only, at least for now, so accept
1897 * the key and do nothing else. Then mac80211 will
1898 * pass it for TX but we don't have to use it for RX.
1899 */
1900 return 0;
1901 default:
Max Stepanove36e5432013-08-27 19:56:13 +03001902 /* currently FW supports only one optional cipher scheme */
1903 if (hw->n_cipher_schemes &&
1904 hw->cipher_schemes->cipher == key->cipher)
1905 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
1906 else
1907 return -EOPNOTSUPP;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001908 }
1909
1910 mutex_lock(&mvm->mutex);
1911
1912 switch (cmd) {
1913 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02001914 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1915 vif->type == NL80211_IFTYPE_AP) && !sta) {
1916 /*
1917 * GTK on AP interface is a TX-only key, return 0;
1918 * on IBSS they're per-station and because we're lazy
1919 * we don't support them for RX, so do the same.
1920 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001921 ret = 0;
1922 key->hw_key_idx = STA_KEY_IDX_INVALID;
1923 break;
1924 }
1925
Johannes Berg8ca151b2013-01-24 14:25:36 +01001926 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1927 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1928 if (ret) {
1929 IWL_WARN(mvm, "set key failed\n");
1930 /*
1931 * can't add key for RX, but we don't need it
1932 * in the device for TX so still return 0
1933 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001934 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001935 ret = 0;
1936 }
1937
1938 break;
1939 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01001940 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1941 ret = 0;
1942 break;
1943 }
1944
Johannes Berg8ca151b2013-01-24 14:25:36 +01001945 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1946 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1947 break;
1948 default:
1949 ret = -EINVAL;
1950 }
1951
1952 mutex_unlock(&mvm->mutex);
1953 return ret;
1954}
1955
1956static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1957 struct ieee80211_vif *vif,
1958 struct ieee80211_key_conf *keyconf,
1959 struct ieee80211_sta *sta,
1960 u32 iv32, u16 *phase1key)
1961{
1962 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1963
Johannes Berg5023d962013-07-31 14:07:43 +02001964 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
1965 return;
1966
Johannes Berg8ca151b2013-01-24 14:25:36 +01001967 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1968}
1969
1970
1971static int iwl_mvm_roc(struct ieee80211_hw *hw,
1972 struct ieee80211_vif *vif,
1973 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02001974 int duration,
1975 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001976{
1977 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001978 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001979 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03001980 struct iwl_mvm_phy_ctxt *phy_ctxt;
1981 int ret, i;
1982
1983 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1984 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001985
1986 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1987 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1988 return -EINVAL;
1989 }
1990
Johannes Berg8ca151b2013-01-24 14:25:36 +01001991 mutex_lock(&mvm->mutex);
1992
Ilan Peer31d385a2013-04-02 10:25:46 +03001993 for (i = 0; i < NUM_PHY_CTX; i++) {
1994 phy_ctxt = &mvm->phy_ctxts[i];
1995 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
1996 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001997
Ilan Peer31d385a2013-04-02 10:25:46 +03001998 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1999 /*
2000 * Unbind the P2P_DEVICE from the current PHY context,
2001 * and if the PHY context is not used remove it.
2002 */
2003 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2004 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2005 goto out_unlock;
2006
2007 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2008
2009 /* Bind the P2P_DEVICE to the current PHY Context */
2010 mvmvif->phy_ctxt = phy_ctxt;
2011
2012 ret = iwl_mvm_binding_add_vif(mvm, vif);
2013 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2014 goto out_unlock;
2015
2016 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2017 goto schedule_time_event;
2018 }
2019 }
2020
2021 /* Need to update the PHY context only if the ROC channel changed */
2022 if (channel == mvmvif->phy_ctxt->channel)
2023 goto schedule_time_event;
2024
2025 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
2026
2027 /*
2028 * Change the PHY context configuration as it is currently referenced
2029 * only by the P2P Device MAC
2030 */
2031 if (mvmvif->phy_ctxt->ref == 1) {
2032 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2033 &chandef, 1, 1);
2034 if (ret)
2035 goto out_unlock;
2036 } else {
2037 /*
2038 * The PHY context is shared with other MACs. Need to remove the
2039 * P2P Device from the binding, allocate an new PHY context and
2040 * create a new binding
2041 */
2042 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2043 if (!phy_ctxt) {
2044 ret = -ENOSPC;
2045 goto out_unlock;
2046 }
2047
2048 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2049 1, 1);
2050 if (ret) {
2051 IWL_ERR(mvm, "Failed to change PHY context\n");
2052 goto out_unlock;
2053 }
2054
2055 /* Unbind the P2P_DEVICE from the current PHY context */
2056 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2057 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2058 goto out_unlock;
2059
2060 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2061
2062 /* Bind the P2P_DEVICE to the new allocated PHY context */
2063 mvmvif->phy_ctxt = phy_ctxt;
2064
2065 ret = iwl_mvm_binding_add_vif(mvm, vif);
2066 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2067 goto out_unlock;
2068
2069 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2070 }
2071
2072schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002073 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02002074 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002075
Ilan Peer31d385a2013-04-02 10:25:46 +03002076out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002077 mutex_unlock(&mvm->mutex);
2078 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01002079 return ret;
2080}
2081
2082static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
2083{
2084 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2085
2086 IWL_DEBUG_MAC80211(mvm, "enter\n");
2087
2088 mutex_lock(&mvm->mutex);
2089 iwl_mvm_stop_p2p_roc(mvm);
2090 mutex_unlock(&mvm->mutex);
2091
2092 IWL_DEBUG_MAC80211(mvm, "leave\n");
2093 return 0;
2094}
2095
2096static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2097 struct ieee80211_chanctx_conf *ctx)
2098{
2099 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002100 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2101 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002102 int ret;
2103
Ilan Peer53a9d612013-04-28 11:55:08 +03002104 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002105
2106 mutex_lock(&mvm->mutex);
2107 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2108 if (!phy_ctxt) {
2109 ret = -ENOSPC;
2110 goto out;
2111 }
2112
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02002113 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Ilan Peer53a9d612013-04-28 11:55:08 +03002114 ctx->rx_chains_static,
2115 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002116 if (ret) {
2117 IWL_ERR(mvm, "Failed to add PHY context\n");
2118 goto out;
2119 }
2120
Ilan Peer53a9d612013-04-28 11:55:08 +03002121 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002122 *phy_ctxt_id = phy_ctxt->id;
2123out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002124 mutex_unlock(&mvm->mutex);
2125 return ret;
2126}
2127
2128static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2129 struct ieee80211_chanctx_conf *ctx)
2130{
2131 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002132 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2133 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002134
2135 mutex_lock(&mvm->mutex);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002136 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002137 mutex_unlock(&mvm->mutex);
2138}
2139
2140static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
2141 struct ieee80211_chanctx_conf *ctx,
2142 u32 changed)
2143{
2144 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002145 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2146 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002147
Ilan Peer31d385a2013-04-02 10:25:46 +03002148 if (WARN_ONCE((phy_ctxt->ref > 1) &&
2149 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
2150 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
Arik Nemtsov2dceeda2013-12-29 17:57:53 +02002151 IEEE80211_CHANCTX_CHANGE_RADAR |
2152 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
Ilan Peer31d385a2013-04-02 10:25:46 +03002153 "Cannot change PHY. Ref=%d, changed=0x%X\n",
2154 phy_ctxt->ref, changed))
2155 return;
2156
Johannes Berg8ca151b2013-01-24 14:25:36 +01002157 mutex_lock(&mvm->mutex);
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02002158 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002159 ctx->rx_chains_static,
2160 ctx->rx_chains_dynamic);
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002161 iwl_mvm_bt_coex_vif_change(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002162 mutex_unlock(&mvm->mutex);
2163}
2164
2165static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
2166 struct ieee80211_vif *vif,
2167 struct ieee80211_chanctx_conf *ctx)
2168{
2169 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002170 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2171 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002172 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2173 int ret;
2174
2175 mutex_lock(&mvm->mutex);
2176
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002177 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002178
2179 switch (vif->type) {
2180 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02002181 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002182 /*
2183 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02002184 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01002185 */
2186 ret = 0;
2187 goto out_unlock;
2188 case NL80211_IFTYPE_STATION:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002189 case NL80211_IFTYPE_MONITOR:
2190 break;
2191 default:
2192 ret = -EINVAL;
2193 goto out_unlock;
2194 }
2195
2196 ret = iwl_mvm_binding_add_vif(mvm, vif);
2197 if (ret)
2198 goto out_unlock;
2199
2200 /*
Alexander Bondar92d85562013-10-23 11:50:34 +02002201 * Power state must be updated before quotas,
2202 * otherwise fw will complain.
2203 */
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02002204 iwl_mvm_power_update_mac(mvm, vif);
Alexander Bondar92d85562013-10-23 11:50:34 +02002205
2206 /* Setting the quota at this stage is only required for monitor
Johannes Berg8ca151b2013-01-24 14:25:36 +01002207 * interfaces. For the other types, the bss_info changed flow
2208 * will handle quota settings.
2209 */
2210 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02002211 mvmvif->monitor_active = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002212 ret = iwl_mvm_update_quotas(mvm, vif);
2213 if (ret)
2214 goto out_remove_binding;
2215 }
2216
2217 goto out_unlock;
2218
2219 out_remove_binding:
2220 iwl_mvm_binding_remove_vif(mvm, vif);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02002221 iwl_mvm_power_update_mac(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002222 out_unlock:
2223 mutex_unlock(&mvm->mutex);
2224 if (ret)
2225 mvmvif->phy_ctxt = NULL;
2226 return ret;
2227}
2228
2229static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
2230 struct ieee80211_vif *vif,
2231 struct ieee80211_chanctx_conf *ctx)
2232{
2233 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2234 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2235
2236 mutex_lock(&mvm->mutex);
2237
2238 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
2239
Johannes Berg8ca151b2013-01-24 14:25:36 +01002240 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02002241 case NL80211_IFTYPE_AP:
2242 case NL80211_IFTYPE_ADHOC:
2243 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002244 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02002245 mvmvif->monitor_active = false;
2246 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002247 break;
2248 default:
2249 break;
2250 }
2251
Ilan Peer1e1391c2013-03-13 14:52:04 +02002252 iwl_mvm_binding_remove_vif(mvm, vif);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02002253 iwl_mvm_power_update_mac(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03002254
Ilan Peera11e1442013-12-31 21:19:55 +02002255out_unlock:
2256 mvmvif->phy_ctxt = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002257 mutex_unlock(&mvm->mutex);
2258}
2259
2260static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
2261 struct ieee80211_sta *sta,
2262 bool set)
2263{
2264 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2265 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
2266
2267 if (!mvm_sta || !mvm_sta->vif) {
2268 IWL_ERR(mvm, "Station is not associated to a vif\n");
2269 return -EINVAL;
2270 }
2271
2272 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
2273}
2274
David Spinadel507cadf2013-07-31 18:07:21 +03002275#ifdef CONFIG_NL80211_TESTMODE
2276static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
2277 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
2278 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad422013-08-01 14:17:15 +02002279 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03002280};
2281
2282static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
2283 struct ieee80211_vif *vif,
2284 void *data, int len)
2285{
2286 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
2287 int err;
2288 u32 noa_duration;
2289
2290 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
2291 if (err)
2292 return err;
2293
2294 if (!tb[IWL_MVM_TM_ATTR_CMD])
2295 return -EINVAL;
2296
2297 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
2298 case IWL_MVM_TM_CMD_SET_NOA:
2299 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
2300 !vif->bss_conf.enable_beacon ||
2301 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
2302 return -EINVAL;
2303
2304 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
2305 if (noa_duration >= vif->bss_conf.beacon_int)
2306 return -EINVAL;
2307
2308 mvm->noa_duration = noa_duration;
2309 mvm->noa_vif = vif;
2310
2311 return iwl_mvm_update_quotas(mvm, NULL);
Johannes Bergf6c6ad422013-08-01 14:17:15 +02002312 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
2313 /* must be associated client vif - ignore authorized */
2314 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
2315 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
2316 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
2317 return -EINVAL;
2318
2319 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
Eliad Peller3dd37d02014-01-07 14:00:24 +02002320 return iwl_mvm_enable_beacon_filter(mvm, vif,
2321 CMD_SYNC);
2322 return iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC);
David Spinadel507cadf2013-07-31 18:07:21 +03002323 }
2324
2325 return -EOPNOTSUPP;
2326}
2327
2328static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
2329 struct ieee80211_vif *vif,
2330 void *data, int len)
2331{
2332 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2333 int err;
2334
2335 mutex_lock(&mvm->mutex);
2336 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
2337 mutex_unlock(&mvm->mutex);
2338
2339 return err;
2340}
2341#endif
2342
Johannes Berge5209262014-01-20 23:38:59 +01002343const struct ieee80211_ops iwl_mvm_hw_ops = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002344 .tx = iwl_mvm_mac_tx,
2345 .ampdu_action = iwl_mvm_mac_ampdu_action,
2346 .start = iwl_mvm_mac_start,
2347 .restart_complete = iwl_mvm_mac_restart_complete,
2348 .stop = iwl_mvm_mac_stop,
2349 .add_interface = iwl_mvm_mac_add_interface,
2350 .remove_interface = iwl_mvm_mac_remove_interface,
2351 .config = iwl_mvm_mac_config,
Eliad Pellere59647e2013-11-28 14:08:50 +02002352 .prepare_multicast = iwl_mvm_prepare_multicast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002353 .configure_filter = iwl_mvm_configure_filter,
2354 .bss_info_changed = iwl_mvm_bss_info_changed,
2355 .hw_scan = iwl_mvm_mac_hw_scan,
2356 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002357 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002358 .sta_state = iwl_mvm_mac_sta_state,
2359 .sta_notify = iwl_mvm_mac_sta_notify,
2360 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
Johannes Berg3e56ead2013-02-15 22:23:18 +01002361 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002362 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002363 .sta_rc_update = iwl_mvm_sta_rc_update,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002364 .conf_tx = iwl_mvm_mac_conf_tx,
2365 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
David Spinadel35a000b2013-08-28 09:29:43 +03002366 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
2367 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002368 .set_key = iwl_mvm_mac_set_key,
2369 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
2370 .remain_on_channel = iwl_mvm_roc,
2371 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002372 .add_chanctx = iwl_mvm_add_chanctx,
2373 .remove_chanctx = iwl_mvm_remove_chanctx,
2374 .change_chanctx = iwl_mvm_change_chanctx,
2375 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
2376 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
2377
Johannes Berg5023d962013-07-31 14:07:43 +02002378 .start_ap = iwl_mvm_start_ap_ibss,
2379 .stop_ap = iwl_mvm_stop_ap_ibss,
2380 .join_ibss = iwl_mvm_start_ap_ibss,
2381 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002382
2383 .set_tim = iwl_mvm_set_tim,
2384
David Spinadel507cadf2013-07-31 18:07:21 +03002385 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
2386
Johannes Berg8ca151b2013-01-24 14:25:36 +01002387#ifdef CONFIG_PM_SLEEP
2388 /* look at d3.c */
2389 .suspend = iwl_mvm_suspend,
2390 .resume = iwl_mvm_resume,
2391 .set_wakeup = iwl_mvm_set_wakeup,
2392 .set_rekey_data = iwl_mvm_set_rekey_data,
2393#if IS_ENABLED(CONFIG_IPV6)
2394 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
2395#endif
2396 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
2397#endif
2398};