blob: 2a1b4b628e2f201a40cafeb1fe81e07d1c65f448 [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{
208 if (!mvm->trans->cfg->d0i3)
209 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{
218 if (!mvm->trans->cfg->d0i3)
219 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
231 if (!mvm->trans->cfg->d0i3)
232 return;
233
234 for_each_set_bit(i, mvm->ref_bitmap, IWL_MVM_REF_COUNT) {
235 if (ref == i)
236 continue;
237
238 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d\n", i);
239 clear_bit(i, mvm->ref_bitmap);
240 iwl_trans_unref(mvm->trans);
241 }
242}
243
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200244static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
245{
246 int i;
247
248 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
249 for (i = 0; i < NUM_PHY_CTX; i++) {
250 mvm->phy_ctxts[i].id = i;
251 mvm->phy_ctxts[i].ref = 0;
252 }
253}
254
David Spinadel20f1a5d2013-08-21 09:14:27 +0300255static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
256{
257 /* we create the 802.11 header and SSID element */
258 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID)
259 return mvm->fw->ucode_capa.max_probe_length - 24 - 2;
260 return mvm->fw->ucode_capa.max_probe_length - 24 - 34;
261}
262
Johannes Berg8ca151b2013-01-24 14:25:36 +0100263int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
264{
265 struct ieee80211_hw *hw = mvm->hw;
Ilan Peer831e85f2013-02-07 17:09:09 +0200266 int num_mac, ret, i;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100267
268 /* Tell mac80211 our characteristics */
269 hw->flags = IEEE80211_HW_SIGNAL_DBM |
270 IEEE80211_HW_SPECTRUM_MGMT |
271 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
272 IEEE80211_HW_QUEUE_CONTROL |
273 IEEE80211_HW_WANT_MONITOR_VIF |
Johannes Berg8ca151b2013-01-24 14:25:36 +0100274 IEEE80211_HW_SUPPORTS_PS |
275 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Johannes Bergd2931bb2013-02-05 18:10:04 +0100276 IEEE80211_HW_AMPDU_AGGREGATION |
Hila Gonend64048e2013-03-13 18:00:03 +0200277 IEEE80211_HW_TIMING_BEACON_ONLY |
Emmanuel Grumbach147fc9b2013-07-28 11:00:52 +0300278 IEEE80211_HW_CONNECTION_MONITOR |
279 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
Alexander Bondare8e626a2013-10-16 00:21:34 +0200280 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100281
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200282 hw->queues = mvm->first_agg_queue;
Ilan Peer398e8c62013-03-13 15:20:35 +0200283 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
Emmanuel Grumbach7b1dd042014-02-04 15:32:43 +0200284 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
285 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
286 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100287 hw->rate_control_algorithm = "iwl-mvm-rs";
288
289 /*
290 * Enable 11w if advertised by firmware and software crypto
291 * is not enabled (as the firmware will interpret some mgmt
292 * packets, so enabling it with software crypto isn't safe)
293 */
294 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
295 !iwlwifi_mod_params.sw_crypto)
296 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
297
Alexander Bondare8e626a2013-10-16 00:21:34 +0200298 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT) {
299 hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
300 hw->uapsd_queues = IWL_UAPSD_AC_INFO;
301 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
302 }
303
Johannes Berg8ca151b2013-01-24 14:25:36 +0100304 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
305 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200306 hw->chanctx_data_size = sizeof(u16);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100307
308 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Johannes Berg3c15a0f2013-05-31 10:17:19 +0200309 BIT(NL80211_IFTYPE_P2P_CLIENT) |
310 BIT(NL80211_IFTYPE_AP) |
311 BIT(NL80211_IFTYPE_P2P_GO) |
312 BIT(NL80211_IFTYPE_P2P_DEVICE);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100313
Johannes Berg5023d962013-07-31 14:07:43 +0200314 /* IBSS has bugs in older versions */
315 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 8)
316 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
317
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +0100318 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
319 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
320 REGULATORY_DISABLE_BEACON_HINTS;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100321
Johannes Berg3e56ead2013-02-15 22:23:18 +0100322 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
323 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
324
Johannes Berg8ca151b2013-01-24 14:25:36 +0100325 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
326 hw->wiphy->n_iface_combinations =
327 ARRAY_SIZE(iwl_mvm_iface_combinations);
328
Ilan Peerc451e6d2013-02-20 08:41:54 +0200329 hw->wiphy->max_remain_on_channel_duration = 10000;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100330 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
331
332 /* Extract MAC address */
333 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
334 hw->wiphy->addresses = mvm->addresses;
335 hw->wiphy->n_addresses = 1;
Ilan Peer831e85f2013-02-07 17:09:09 +0200336
337 /* Extract additional MAC addresses if available */
338 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
339 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
340
341 for (i = 1; i < num_mac; i++) {
342 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100343 ETH_ALEN);
Ilan Peer831e85f2013-02-07 17:09:09 +0200344 mvm->addresses[i].addr[5]++;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100345 hw->wiphy->n_addresses++;
346 }
347
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200348 iwl_mvm_reset_phy_ctxts(mvm);
349
David Spinadel20f1a5d2013-08-21 09:14:27 +0300350 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
351
Johannes Berg8ca151b2013-01-24 14:25:36 +0100352 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
353
354 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
355 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
356 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
357 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
358 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
359 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
360
361 hw->wiphy->hw_version = mvm->trans->hw_id;
362
Alexander Bondarade50652013-04-03 16:28:47 +0300363 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100364 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
365 else
366 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
367
David Spinadel35a000b2013-08-28 09:29:43 +0300368 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) {
369 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
370 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
371 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
372 /* we create the 802.11 header and zero length SSID IE. */
373 hw->wiphy->max_sched_scan_ie_len =
374 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
375 }
376
Johannes Berg8ca151b2013-01-24 14:25:36 +0100377 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200378 NL80211_FEATURE_P2P_GO_OPPPS |
379 NL80211_FEATURE_LOW_PRIORITY_SCAN;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100380
381 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
382
Max Stepanove36e5432013-08-27 19:56:13 +0300383 /* currently FW API supports only one optional cipher scheme */
Johannes Berg9ddca862014-01-06 09:29:40 +0100384 if (mvm->fw->cs[0].cipher) {
Max Stepanove36e5432013-08-27 19:56:13 +0300385 mvm->hw->n_cipher_schemes = 1;
Johannes Berg9ddca862014-01-06 09:29:40 +0100386 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
Max Stepanove36e5432013-08-27 19:56:13 +0300387 }
388
Johannes Berg8ca151b2013-01-24 14:25:36 +0100389#ifdef CONFIG_PM_SLEEP
390 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
391 mvm->trans->ops->d3_suspend &&
392 mvm->trans->ops->d3_resume &&
393 device_can_wakeup(mvm->trans->dev)) {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200394 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
395 WIPHY_WOWLAN_DISCONNECT |
396 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
397 WIPHY_WOWLAN_RFKILL_RELEASE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100398 if (!iwlwifi_mod_params.sw_crypto)
Johannes Berg964dc9e2013-06-03 17:25:34 +0200399 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
400 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
401 WIPHY_WOWLAN_4WAY_HANDSHAKE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100402
Johannes Berg964dc9e2013-06-03 17:25:34 +0200403 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
404 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
405 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
406 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
407 hw->wiphy->wowlan = &mvm->wowlan;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100408 }
409#endif
410
Eliad Peller77736922014-01-14 12:35:49 +0200411#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
412 /* assign default bcast filtering configuration */
413 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
414#endif
415
Johannes Berg8ca151b2013-01-24 14:25:36 +0100416 ret = iwl_mvm_leds_init(mvm);
417 if (ret)
418 return ret;
419
Emmanuel Grumbachb7327d82013-06-24 15:44:03 +0300420 ret = ieee80211_register_hw(mvm->hw);
421 if (ret)
422 iwl_mvm_leds_exit(mvm);
423
424 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100425}
426
427static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
428 struct ieee80211_tx_control *control,
429 struct sk_buff *skb)
430{
431 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg3e56ead2013-02-15 22:23:18 +0100432 struct ieee80211_sta *sta = control->sta;
433 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
434 struct ieee80211_hdr *hdr = (void *)skb->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100435
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300436 if (iwl_mvm_is_radio_killed(mvm)) {
437 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100438 goto drop;
439 }
440
Ilan Peer398e8c62013-03-13 15:20:35 +0200441 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
Johannes Berg8ca151b2013-01-24 14:25:36 +0100442 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
443 goto drop;
444
Johannes Berg3e56ead2013-02-15 22:23:18 +0100445 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
446 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
447 ieee80211_is_mgmt(hdr->frame_control) &&
448 !ieee80211_is_deauth(hdr->frame_control) &&
449 !ieee80211_is_disassoc(hdr->frame_control) &&
450 !ieee80211_is_action(hdr->frame_control)))
451 sta = NULL;
452
453 if (sta) {
454 if (iwl_mvm_tx_skb(mvm, skb, sta))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100455 goto drop;
456 return;
457 }
458
459 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
460 goto drop;
461 return;
462 drop:
463 ieee80211_free_txskb(hw, skb);
464}
465
466static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
467 struct ieee80211_vif *vif,
468 enum ieee80211_ampdu_mlme_action action,
469 struct ieee80211_sta *sta, u16 tid,
470 u16 *ssn, u8 buf_size)
471{
472 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
473 int ret;
474
475 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
476 sta->addr, tid, action);
477
478 if (!(mvm->nvm_data->sku_cap_11n_enable))
479 return -EACCES;
480
481 mutex_lock(&mvm->mutex);
482
483 switch (action) {
484 case IEEE80211_AMPDU_RX_START:
485 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
486 ret = -EINVAL;
487 break;
488 }
489 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
490 break;
491 case IEEE80211_AMPDU_RX_STOP:
492 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
493 break;
494 case IEEE80211_AMPDU_TX_START:
Emmanuel Grumbach5d158ef2013-02-19 14:39:58 +0200495 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
496 ret = -EINVAL;
497 break;
498 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100499 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
500 break;
501 case IEEE80211_AMPDU_TX_STOP_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200502 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
503 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100504 case IEEE80211_AMPDU_TX_STOP_FLUSH:
505 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +0200506 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100507 break;
508 case IEEE80211_AMPDU_TX_OPERATIONAL:
509 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
510 break;
511 default:
512 WARN_ON_ONCE(1);
513 ret = -EINVAL;
514 break;
515 }
516 mutex_unlock(&mvm->mutex);
517
518 return ret;
519}
520
521static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
522 struct ieee80211_vif *vif)
523{
524 struct iwl_mvm *mvm = data;
525 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
526
527 mvmvif->uploaded = false;
528 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
529
530 /* does this make sense at all? */
531 mvmvif->color++;
532
533 spin_lock_bh(&mvm->time_event_lock);
534 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
535 spin_unlock_bh(&mvm->time_event_lock);
536
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200537 mvmvif->phy_ctxt = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100538}
539
540static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
541{
542 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100543
544 mvm->scan_status = IWL_MVM_SCAN_NONE;
545
546 /* just in case one was running */
547 ieee80211_remain_on_channel_expired(mvm->hw);
548
549 ieee80211_iterate_active_interfaces_atomic(
550 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
551 iwl_mvm_cleanup_iterator, mvm);
552
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200553 mvm->p2p_device_vif = NULL;
Eliad Peller37577fe2013-12-05 17:19:39 +0200554 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200555
556 iwl_mvm_reset_phy_ctxts(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100557 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
558 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
559
560 ieee80211_wake_queues(mvm->hw);
561
Eliad Peller7498cf42014-01-16 17:10:44 +0200562 /* cleanup all stale references (scan, roc), but keep the
563 * ucode_down ref until reconfig is complete */
564 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
565
Johannes Berg8ca151b2013-01-24 14:25:36 +0100566 mvm->vif_count = 0;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +0300567 mvm->rx_ba_sessions = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100568}
569
570static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
571{
572 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
573 int ret;
574
575 mutex_lock(&mvm->mutex);
576
577 /* Clean up some internal and mac80211 state on restart */
578 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
579 iwl_mvm_restart_cleanup(mvm);
580
581 ret = iwl_mvm_up(mvm);
582 mutex_unlock(&mvm->mutex);
583
584 return ret;
585}
586
587static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
588{
589 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
590 int ret;
591
592 mutex_lock(&mvm->mutex);
593
594 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
595 ret = iwl_mvm_update_quotas(mvm, NULL);
596 if (ret)
597 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
598 ret);
599
Eliad Peller7498cf42014-01-16 17:10:44 +0200600 /* allow transport/FW low power modes */
601 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
602
Johannes Berg8ca151b2013-01-24 14:25:36 +0100603 mutex_unlock(&mvm->mutex);
604}
605
606static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
607{
608 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
609
Eliad Peller37577fe2013-12-05 17:19:39 +0200610 flush_work(&mvm->d0i3_exit_work);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100611 flush_work(&mvm->async_handlers_wk);
612
613 mutex_lock(&mvm->mutex);
Eliad Peller7498cf42014-01-16 17:10:44 +0200614
615 /* disallow low power states when the FW is down */
616 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
617
Johannes Berg8ca151b2013-01-24 14:25:36 +0100618 /* async_handlers_wk is now blocked */
619
620 /*
621 * The work item could be running or queued if the
622 * ROC time event stops just as we get here.
623 */
624 cancel_work_sync(&mvm->roc_done_wk);
625
626 iwl_trans_stop_device(mvm->trans);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100627
628 iwl_mvm_async_handlers_purge(mvm);
629 /* async_handlers_list is empty and will stay empty: HW is stopped */
630
631 /* the fw is stopped, the aux sta is dead: clean up driver state */
632 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
633
634 mutex_unlock(&mvm->mutex);
635
636 /*
637 * The worker might have been waiting for the mutex, let it run and
638 * discover that its list is now empty.
639 */
640 cancel_work_sync(&mvm->async_handlers_wk);
641}
642
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200643static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
644{
645 u16 i;
646
647 lockdep_assert_held(&mvm->mutex);
648
649 for (i = 0; i < NUM_PHY_CTX; i++)
650 if (!mvm->phy_ctxts[i].ref)
651 return &mvm->phy_ctxts[i];
652
653 IWL_ERR(mvm, "No available PHY context\n");
654 return NULL;
655}
656
Emmanuel Grumbachee9c6cb2013-12-04 13:53:39 +0200657static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
658 s8 tx_power)
659{
660 /* FW is in charge of regulatory enforcement */
661 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
662 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
663 .pwr_restriction = cpu_to_le16(tx_power),
664 };
665
666 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
667 sizeof(reduce_txpwr_cmd),
668 &reduce_txpwr_cmd);
669}
670
Johannes Berg8ca151b2013-01-24 14:25:36 +0100671static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
672 struct ieee80211_vif *vif)
673{
674 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
675 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
676 int ret;
677
678 /*
679 * Not much to do here. The stack will not allow interface
680 * types or combinations that we didn't advertise, so we
681 * don't really have to check the types.
682 */
683
684 mutex_lock(&mvm->mutex);
685
Eliad Pellere89044d2013-07-16 17:33:26 +0300686 /* Allocate resources for the MAC context, and add it to the fw */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100687 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
688 if (ret)
689 goto out_unlock;
690
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300691 /* Counting number of interfaces is needed for legacy PM */
Ilan Peerea183d02013-07-23 14:41:53 +0300692 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
693 mvm->vif_count++;
Ilan Peerea183d02013-07-23 14:41:53 +0300694
695 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +0100696 * The AP binding flow can be done only after the beacon
697 * template is configured (which happens only in the mac80211
698 * start_ap() flow), and adding the broadcast station can happen
699 * only after the binding.
700 * In addition, since modifying the MAC before adding a bcast
701 * station is not allowed by the FW, delay the adding of MAC context to
702 * the point where we can also add the bcast station.
703 * In short: there's not much we can do at this point, other than
704 * allocating resources :)
705 */
Johannes Berg5023d962013-07-31 14:07:43 +0200706 if (vif->type == NL80211_IFTYPE_AP ||
707 vif->type == NL80211_IFTYPE_ADHOC) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100708 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
709 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
Eliad Pellerb92e6612014-01-23 17:58:23 +0200710 qmask,
711 ieee80211_vif_type_p2p(vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100712 if (ret) {
713 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
714 goto out_release;
715 }
716
Emmanuel Grumbach77740cb2013-06-26 23:51:41 +0300717 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100718 goto out_unlock;
719 }
720
Johannes Berg8ca151b2013-01-24 14:25:36 +0100721 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
722 if (ret)
723 goto out_release;
724
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200725 ret = iwl_mvm_power_update_mac(mvm, vif);
726 if (ret)
727 goto out_release;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100728
Hila Gonen7df15b12012-12-12 11:16:19 +0200729 /* beacon filtering */
Eliad Peller3dd37d02014-01-07 14:00:24 +0200730 ret = iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300731 if (ret)
732 goto out_remove_mac;
733
Hila Gonen7df15b12012-12-12 11:16:19 +0200734 if (!mvm->bf_allowed_vif &&
Hila Gonen5dca7c22013-07-16 11:15:35 +0300735 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
736 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){
Hila Gonen7df15b12012-12-12 11:16:19 +0200737 mvm->bf_allowed_vif = mvmvif;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300738 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
739 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Hila Gonen7df15b12012-12-12 11:16:19 +0200740 }
741
Johannes Berg8ca151b2013-01-24 14:25:36 +0100742 /*
743 * P2P_DEVICE interface does not have a channel context assigned to it,
744 * so a dedicated PHY context is allocated to it and the corresponding
745 * MAC context is bound to it at this stage.
746 */
747 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100748
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200749 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
750 if (!mvmvif->phy_ctxt) {
751 ret = -ENOSPC;
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300752 goto out_free_bf;
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200753 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100754
Ilan Peer53a9d612013-04-28 11:55:08 +0300755 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100756 ret = iwl_mvm_binding_add_vif(mvm, vif);
757 if (ret)
Ilan Peer53a9d612013-04-28 11:55:08 +0300758 goto out_unref_phy;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100759
760 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
761 if (ret)
762 goto out_unbind;
763
764 /* Save a pointer to p2p device vif, so it can later be used to
765 * update the p2p device MAC when a GO is started/stopped */
766 mvm->p2p_device_vif = vif;
767 }
768
Johannes Berg63494372013-03-26 10:47:53 +0100769 iwl_mvm_vif_dbgfs_register(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100770 goto out_unlock;
771
772 out_unbind:
773 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peer53a9d612013-04-28 11:55:08 +0300774 out_unref_phy:
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200775 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300776 out_free_bf:
777 if (mvm->bf_allowed_vif == mvmvif) {
778 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300779 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
780 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Eliad Pellerbd3351b2013-07-16 17:50:17 +0300781 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100782 out_remove_mac:
783 mvmvif->phy_ctxt = NULL;
784 iwl_mvm_mac_ctxt_remove(mvm, vif);
785 out_release:
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200786 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
787 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300788
Johannes Berg8ca151b2013-01-24 14:25:36 +0100789 iwl_mvm_mac_ctxt_release(mvm, vif);
790 out_unlock:
791 mutex_unlock(&mvm->mutex);
792
793 return ret;
794}
795
Johannes Berg38a12b52013-02-22 14:07:56 +0100796static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
797 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100798{
Johannes Berg8ca151b2013-01-24 14:25:36 +0100799 u32 tfd_msk = 0, ac;
800
801 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
802 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
803 tfd_msk |= BIT(vif->hw_queue[ac]);
804
805 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
806 tfd_msk |= BIT(vif->cab_queue);
807
808 if (tfd_msk) {
809 mutex_lock(&mvm->mutex);
810 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
811 mutex_unlock(&mvm->mutex);
812 }
813
814 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
815 /*
816 * Flush the ROC worker which will flush the OFFCHANNEL queue.
817 * We assume here that all the packets sent to the OFFCHANNEL
818 * queue are sent in ROC session.
819 */
820 flush_work(&mvm->roc_done_wk);
821 } else {
822 /*
823 * By now, all the AC queues are empty. The AGG queues are
824 * empty too. We already got all the Tx responses for all the
825 * packets in the queues. The drain work can have been
Emmanuel Grumbach0742a752013-06-10 14:10:33 +0300826 * triggered. Flush it.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100827 */
828 flush_work(&mvm->sta_drained_wk);
829 }
Johannes Berg38a12b52013-02-22 14:07:56 +0100830}
831
832static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
833 struct ieee80211_vif *vif)
834{
835 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
836 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
837
838 iwl_mvm_prepare_mac_removal(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100839
840 mutex_lock(&mvm->mutex);
841
Hila Gonen7df15b12012-12-12 11:16:19 +0200842 if (mvm->bf_allowed_vif == mvmvif) {
843 mvm->bf_allowed_vif = NULL;
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300844 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
845 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
Hila Gonen7df15b12012-12-12 11:16:19 +0200846 }
847
Johannes Berg63494372013-03-26 10:47:53 +0100848 iwl_mvm_vif_dbgfs_clean(mvm, vif);
849
Johannes Berg8ca151b2013-01-24 14:25:36 +0100850 /*
851 * For AP/GO interface, the tear down of the resources allocated to the
Johannes Berg38a12b52013-02-22 14:07:56 +0100852 * interface is be handled as part of the stop_ap flow.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100853 */
Johannes Berg5023d962013-07-31 14:07:43 +0200854 if (vif->type == NL80211_IFTYPE_AP ||
855 vif->type == NL80211_IFTYPE_ADHOC) {
David Spinadel507cadf2013-07-31 18:07:21 +0300856#ifdef CONFIG_NL80211_TESTMODE
857 if (vif == mvm->noa_vif) {
858 mvm->noa_vif = NULL;
859 mvm->noa_duration = 0;
860 }
861#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +0100862 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
863 goto out_release;
864 }
865
866 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
867 mvm->p2p_device_vif = NULL;
868 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
869 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peerfe0f2de2013-03-21 10:23:52 +0200870 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100871 mvmvif->phy_ctxt = NULL;
872 }
873
Alexander Bondar5ee2b212013-03-05 10:16:40 +0200874 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100875 mvm->vif_count--;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300876
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200877 iwl_mvm_power_update_mac(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100878 iwl_mvm_mac_ctxt_remove(mvm, vif);
879
880out_release:
881 iwl_mvm_mac_ctxt_release(mvm, vif);
882 mutex_unlock(&mvm->mutex);
883}
884
885static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
886{
887 return 0;
888}
889
Eliad Pellere59647e2013-11-28 14:08:50 +0200890struct iwl_mvm_mc_iter_data {
891 struct iwl_mvm *mvm;
892 int port_id;
893};
894
895static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
896 struct ieee80211_vif *vif)
897{
898 struct iwl_mvm_mc_iter_data *data = _data;
899 struct iwl_mvm *mvm = data->mvm;
900 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
901 int ret, len;
902
903 /* if we don't have free ports, mcast frames will be dropped */
904 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
905 return;
906
907 if (vif->type != NL80211_IFTYPE_STATION ||
908 !vif->bss_conf.assoc)
909 return;
910
911 cmd->port_id = data->port_id++;
912 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
913 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
914
915 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC, len, cmd);
916 if (ret)
917 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
918}
919
920static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
921{
922 struct iwl_mvm_mc_iter_data iter_data = {
923 .mvm = mvm,
924 };
925
926 lockdep_assert_held(&mvm->mutex);
927
928 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
929 return;
930
931 ieee80211_iterate_active_interfaces(
932 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
933 iwl_mvm_mc_iface_iterator, &iter_data);
934}
935
936static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
937 struct netdev_hw_addr_list *mc_list)
938{
939 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
940 struct iwl_mcast_filter_cmd *cmd;
941 struct netdev_hw_addr *addr;
942 int addr_count = netdev_hw_addr_list_count(mc_list);
943 bool pass_all = false;
944 int len;
945
946 if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) {
947 pass_all = true;
948 addr_count = 0;
949 }
950
951 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
952 cmd = kzalloc(len, GFP_ATOMIC);
953 if (!cmd)
954 return 0;
955
956 if (pass_all) {
957 cmd->pass_all = 1;
958 return (u64)(unsigned long)cmd;
959 }
960
961 netdev_hw_addr_list_for_each(addr, mc_list) {
962 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
963 cmd->count, addr->addr);
964 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
965 addr->addr, ETH_ALEN);
966 cmd->count++;
967 }
968
969 return (u64)(unsigned long)cmd;
970}
971
Johannes Berg8ca151b2013-01-24 14:25:36 +0100972static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
973 unsigned int changed_flags,
974 unsigned int *total_flags,
975 u64 multicast)
976{
Eliad Pellere59647e2013-11-28 14:08:50 +0200977 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
978 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
979
980 mutex_lock(&mvm->mutex);
981
982 /* replace previous configuration */
983 kfree(mvm->mcast_filter_cmd);
984 mvm->mcast_filter_cmd = cmd;
985
986 if (!cmd)
987 goto out;
988
989 iwl_mvm_recalc_multicast(mvm);
990out:
991 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100992 *total_flags = 0;
993}
994
Eliad Pellerc87163b2014-01-08 10:11:11 +0200995#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
996struct iwl_bcast_iter_data {
997 struct iwl_mvm *mvm;
998 struct iwl_bcast_filter_cmd *cmd;
999 u8 current_filter;
1000};
1001
1002static void
1003iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1004 const struct iwl_fw_bcast_filter *in_filter,
1005 struct iwl_fw_bcast_filter *out_filter)
1006{
1007 struct iwl_fw_bcast_filter_attr *attr;
1008 int i;
1009
1010 memcpy(out_filter, in_filter, sizeof(*out_filter));
1011
1012 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1013 attr = &out_filter->attrs[i];
1014
1015 if (!attr->mask)
1016 break;
1017
Eliad Peller2ee8f022014-01-13 19:07:09 +02001018 switch (attr->reserved1) {
1019 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1020 if (vif->bss_conf.arp_addr_cnt != 1) {
1021 attr->mask = 0;
1022 continue;
1023 }
1024
1025 attr->val = vif->bss_conf.arp_addr_list[0];
1026 break;
1027 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1028 attr->val = *(__be32 *)&vif->addr[2];
1029 break;
1030 default:
1031 break;
1032 }
1033 attr->reserved1 = 0;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001034 out_filter->num_attrs++;
1035 }
1036}
1037
1038static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1039 struct ieee80211_vif *vif)
1040{
1041 struct iwl_bcast_iter_data *data = _data;
1042 struct iwl_mvm *mvm = data->mvm;
1043 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1044 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1045 struct iwl_fw_bcast_mac *bcast_mac;
1046 int i;
1047
1048 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1049 return;
1050
1051 bcast_mac = &cmd->macs[mvmvif->id];
1052
1053 /* enable filtering only for associated stations */
1054 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
1055 return;
1056
1057 bcast_mac->default_discard = 1;
1058
1059 /* copy all configured filters */
1060 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1061 /*
1062 * Make sure we don't exceed our filters limit.
1063 * if there is still a valid filter to be configured,
1064 * be on the safe side and just allow bcast for this mac.
1065 */
1066 if (WARN_ON_ONCE(data->current_filter >=
1067 ARRAY_SIZE(cmd->filters))) {
1068 bcast_mac->default_discard = 0;
1069 bcast_mac->attached_filters = 0;
1070 break;
1071 }
1072
1073 iwl_mvm_set_bcast_filter(vif,
1074 &mvm->bcast_filters[i],
1075 &cmd->filters[data->current_filter]);
1076
1077 /* skip current filter if it contains no attributes */
1078 if (!cmd->filters[data->current_filter].num_attrs)
1079 continue;
1080
1081 /* attach the filter to current mac */
1082 bcast_mac->attached_filters |=
1083 cpu_to_le16(BIT(data->current_filter));
1084
1085 data->current_filter++;
1086 }
1087}
1088
Eliad Pellerde06a592014-01-08 10:11:12 +02001089bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1090 struct iwl_bcast_filter_cmd *cmd)
Eliad Pellerc87163b2014-01-08 10:11:11 +02001091{
Eliad Pellerc87163b2014-01-08 10:11:11 +02001092 struct iwl_bcast_iter_data iter_data = {
1093 .mvm = mvm,
Eliad Pellerde06a592014-01-08 10:11:12 +02001094 .cmd = cmd,
Eliad Pellerc87163b2014-01-08 10:11:11 +02001095 };
1096
Eliad Pellerde06a592014-01-08 10:11:12 +02001097 memset(cmd, 0, sizeof(*cmd));
1098 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1099 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1100
1101#ifdef CONFIG_IWLWIFI_DEBUGFS
1102 /* use debugfs filters/macs if override is configured */
1103 if (mvm->dbgfs_bcast_filtering.override) {
1104 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1105 sizeof(cmd->filters));
1106 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1107 sizeof(cmd->macs));
1108 return true;
1109 }
1110#endif
Eliad Pellerc87163b2014-01-08 10:11:11 +02001111
1112 /* if no filters are configured, do nothing */
1113 if (!mvm->bcast_filters)
Eliad Pellerde06a592014-01-08 10:11:12 +02001114 return false;
Eliad Pellerc87163b2014-01-08 10:11:11 +02001115
1116 /* configure and attach these filters for each associated sta vif */
1117 ieee80211_iterate_active_interfaces(
1118 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1119 iwl_mvm_bcast_filter_iterator, &iter_data);
1120
Eliad Pellerde06a592014-01-08 10:11:12 +02001121 return true;
1122}
1123static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1124 struct ieee80211_vif *vif)
1125{
1126 struct iwl_bcast_filter_cmd cmd;
1127
1128 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1129 return 0;
1130
1131 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1132 return 0;
1133
Eliad Pellerc87163b2014-01-08 10:11:11 +02001134 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, CMD_SYNC,
1135 sizeof(cmd), &cmd);
1136}
1137#else
1138static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1139 struct ieee80211_vif *vif)
1140{
1141 return 0;
1142}
1143#endif
1144
Johannes Berg8ca151b2013-01-24 14:25:36 +01001145static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1146 struct ieee80211_vif *vif,
1147 struct ieee80211_bss_conf *bss_conf,
1148 u32 changes)
1149{
1150 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1151 int ret;
1152
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001153 /*
1154 * Re-calculate the tsf id, as the master-slave relations depend on the
1155 * beacon interval, which was not known when the station interface was
1156 * added.
1157 */
1158 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1159 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1160
Johannes Berg8ca151b2013-01-24 14:25:36 +01001161 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1162 if (ret)
1163 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1164
1165 if (changes & BSS_CHANGED_ASSOC) {
1166 if (bss_conf->assoc) {
1167 /* add quota for this interface */
1168 ret = iwl_mvm_update_quotas(mvm, vif);
1169 if (ret) {
1170 IWL_ERR(mvm, "failed to update quotas\n");
1171 return;
1172 }
Johannes Berg016d27e2013-05-03 11:16:15 +02001173
1174 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1175 &mvm->status)) {
1176 /*
1177 * If we're restarting then the firmware will
1178 * obviously have lost synchronisation with
1179 * the AP. It will attempt to synchronise by
1180 * itself, but we can make it more reliable by
1181 * scheduling a session protection time event.
1182 *
1183 * The firmware needs to receive a beacon to
1184 * catch up with synchronisation, use 110% of
1185 * the beacon interval.
1186 *
1187 * Set a large maximum delay to allow for more
1188 * than a single interface.
1189 */
1190 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1191 iwl_mvm_protect_session(mvm, vif, dur, dur,
1192 5 * dur);
1193 }
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001194
1195 iwl_mvm_sf_update(mvm, vif, false);
Alexander Bondar175a70b2013-04-14 20:59:37 +03001196 iwl_mvm_power_vif_assoc(mvm, vif);
Eliad Peller29a90a42013-11-05 14:06:29 +02001197 if (vif->p2p)
1198 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001199 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001200 /*
1201 * If update fails - SF might be running in associated
1202 * mode while disassociated - which is forbidden.
1203 */
1204 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1205 "Failed to update SF upon disassociation\n");
1206
Johannes Berg8ca151b2013-01-24 14:25:36 +01001207 /* remove AP station now that the MAC is unassoc */
1208 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1209 if (ret)
1210 IWL_ERR(mvm, "failed to remove AP station\n");
Eliad Peller37577fe2013-12-05 17:19:39 +02001211
1212 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1213 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001214 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1215 /* remove quota for this interface */
1216 ret = iwl_mvm_update_quotas(mvm, NULL);
1217 if (ret)
1218 IWL_ERR(mvm, "failed to update quotas\n");
Eliad Peller29a90a42013-11-05 14:06:29 +02001219
1220 if (vif->p2p)
1221 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001222 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001223
Eliad Pellere59647e2013-11-28 14:08:50 +02001224 iwl_mvm_recalc_multicast(mvm);
Eliad Pellerc87163b2014-01-08 10:11:11 +02001225 iwl_mvm_configure_bcast_filter(mvm, vif);
Eliad Pellere59647e2013-11-28 14:08:50 +02001226
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001227 /* reset rssi values */
1228 mvmvif->bf_data.ave_beacon_signal = 0;
1229
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001230 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachf94045e2014-01-06 13:38:55 +02001231 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1232 IEEE80211_SMPS_AUTOMATIC);
Alexander Bondar989c6502013-05-16 17:34:17 +03001233 } else if (changes & BSS_CHANGED_BEACON_INFO) {
Johannes Berg210a5442013-01-24 23:48:23 +01001234 /*
1235 * We received a beacon _after_ association so
1236 * remove the session protection.
1237 */
1238 iwl_mvm_remove_time_event(mvm, mvmvif,
1239 &mvmvif->time_event_data);
Alexander Bondar51498cf2013-09-02 17:10:14 +03001240 } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS |
1241 BSS_CHANGED_QOS)) {
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001242 ret = iwl_mvm_power_update_mac(mvm, vif);
Alexander Bondar4bf881f2013-05-29 10:19:50 +03001243 if (ret)
1244 IWL_ERR(mvm, "failed to update power mode\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001245 }
Matti Gottlieb88f2fd72013-07-09 15:25:46 +03001246 if (changes & BSS_CHANGED_TXPOWER) {
1247 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1248 bss_conf->txpower);
1249 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1250 }
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001251
1252 if (changes & BSS_CHANGED_CQM) {
1253 IWL_DEBUG_MAC80211(mvm, "cqm info_changed");
1254 /* reset cqm events tracking */
1255 mvmvif->bf_data.last_cqm_event = 0;
Eliad Peller3dd37d02014-01-07 14:00:24 +02001256 ret = iwl_mvm_update_beacon_filter(mvm, vif, false, CMD_SYNC);
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +03001257 if (ret)
1258 IWL_ERR(mvm, "failed to update CQM thresholds\n");
1259 }
Eliad Peller2ee8f022014-01-13 19:07:09 +02001260
1261 if (changes & BSS_CHANGED_ARP_FILTER) {
1262 IWL_DEBUG_MAC80211(mvm, "arp filter changed");
1263 iwl_mvm_configure_bcast_filter(mvm, vif);
1264 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001265}
1266
Johannes Berg5023d962013-07-31 14:07:43 +02001267static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1268 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001269{
1270 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1271 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1272 int ret;
1273
1274 mutex_lock(&mvm->mutex);
1275
1276 /* Send the beacon template */
1277 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1278 if (ret)
1279 goto out_unlock;
1280
Ilan Peer6e97b0d2013-12-23 22:18:02 +02001281 /*
1282 * Re-calculate the tsf id, as the master-slave relations depend on the
1283 * beacon interval, which was not known when the AP interface was added.
1284 */
1285 if (vif->type == NL80211_IFTYPE_AP)
1286 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1287
Johannes Berg8ca151b2013-01-24 14:25:36 +01001288 /* Add the mac context */
1289 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1290 if (ret)
1291 goto out_unlock;
1292
1293 /* Perform the binding */
1294 ret = iwl_mvm_binding_add_vif(mvm, vif);
1295 if (ret)
1296 goto out_remove;
1297
Johannes Berg8ca151b2013-01-24 14:25:36 +01001298 /* Send the bcast station. At this stage the TBTT and DTIM time events
1299 * are added and applied to the scheduler */
1300 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
1301 if (ret)
1302 goto out_unbind;
1303
Ilan Peer5691e212013-12-31 21:05:50 +02001304 /* must be set before quota calculations */
1305 mvmvif->ap_ibss_active = true;
1306
Ilan Peera11e1442013-12-31 21:19:55 +02001307 /* power updated needs to be done before quotas */
1308 mvm->bound_vif_cnt++;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001309 iwl_mvm_power_update_mac(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02001310
Johannes Berg8ca151b2013-01-24 14:25:36 +01001311 ret = iwl_mvm_update_quotas(mvm, vif);
1312 if (ret)
Ilan Peera11e1442013-12-31 21:19:55 +02001313 goto out_quota_failed;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001314
Johannes Berg5023d962013-07-31 14:07:43 +02001315 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001316 if (vif->p2p && mvm->p2p_device_vif)
1317 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1318
Eliad Peller29a90a42013-11-05 14:06:29 +02001319 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1320
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001321 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001322
Johannes Berg8ca151b2013-01-24 14:25:36 +01001323 mutex_unlock(&mvm->mutex);
1324 return 0;
1325
Ilan Peera11e1442013-12-31 21:19:55 +02001326out_quota_failed:
1327 mvm->bound_vif_cnt--;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001328 iwl_mvm_power_update_mac(mvm, vif);
Ilan Peer5691e212013-12-31 21:05:50 +02001329 mvmvif->ap_ibss_active = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001330 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1331out_unbind:
1332 iwl_mvm_binding_remove_vif(mvm, vif);
1333out_remove:
1334 iwl_mvm_mac_ctxt_remove(mvm, vif);
1335out_unlock:
1336 mutex_unlock(&mvm->mutex);
1337 return ret;
1338}
1339
Johannes Berg5023d962013-07-31 14:07:43 +02001340static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
1341 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001342{
1343 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1344 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1345
Johannes Berg38a12b52013-02-22 14:07:56 +01001346 iwl_mvm_prepare_mac_removal(mvm, vif);
1347
Johannes Berg8ca151b2013-01-24 14:25:36 +01001348 mutex_lock(&mvm->mutex);
1349
Johannes Berg5023d962013-07-31 14:07:43 +02001350 mvmvif->ap_ibss_active = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001351
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03001352 iwl_mvm_bt_coex_vif_change(mvm);
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +03001353
Eliad Peller29a90a42013-11-05 14:06:29 +02001354 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
1355
Johannes Berg5023d962013-07-31 14:07:43 +02001356 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001357 if (vif->p2p && mvm->p2p_device_vif)
1358 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1359
1360 iwl_mvm_update_quotas(mvm, NULL);
1361 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1362 iwl_mvm_binding_remove_vif(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02001363
1364 mvm->bound_vif_cnt--;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02001365 iwl_mvm_power_update_mac(mvm, vif);
Ilan Peera11e1442013-12-31 21:19:55 +02001366
Johannes Berg8ca151b2013-01-24 14:25:36 +01001367 iwl_mvm_mac_ctxt_remove(mvm, vif);
1368
1369 mutex_unlock(&mvm->mutex);
1370}
1371
Johannes Berg5023d962013-07-31 14:07:43 +02001372static void
1373iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
1374 struct ieee80211_vif *vif,
1375 struct ieee80211_bss_conf *bss_conf,
1376 u32 changes)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001377{
Ilan Peerbe2056f2013-12-04 16:47:14 +02001378 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman8a5e3662013-11-12 19:16:03 +02001379
Ilan Peerbe2056f2013-12-04 16:47:14 +02001380 /* Changes will be applied when the AP/IBSS is started */
1381 if (!mvmvif->ap_ibss_active)
1382 return;
1383
Johannes Berg863230da2013-12-04 17:08:40 +01001384 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
1385 BSS_CHANGED_BANDWIDTH) &&
1386 iwl_mvm_mac_ctxt_changed(mvm, vif))
1387 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
Avri Altman8a5e3662013-11-12 19:16:03 +02001388
Johannes Berg8ca151b2013-01-24 14:25:36 +01001389 /* Need to send a new beacon template to the FW */
Johannes Berg863230da2013-12-04 17:08:40 +01001390 if (changes & BSS_CHANGED_BEACON &&
1391 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1392 IWL_WARN(mvm, "Failed updating beacon data\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001393}
1394
1395static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1396 struct ieee80211_vif *vif,
1397 struct ieee80211_bss_conf *bss_conf,
1398 u32 changes)
1399{
1400 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1401
1402 mutex_lock(&mvm->mutex);
1403
1404 switch (vif->type) {
1405 case NL80211_IFTYPE_STATION:
1406 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1407 break;
1408 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02001409 case NL80211_IFTYPE_ADHOC:
1410 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001411 break;
1412 default:
1413 /* shouldn't happen */
1414 WARN_ON_ONCE(1);
1415 }
1416
1417 mutex_unlock(&mvm->mutex);
1418}
1419
1420static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
1421 struct ieee80211_vif *vif,
1422 struct cfg80211_scan_request *req)
1423{
1424 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berga6623e82014-01-27 15:40:53 +01001425 struct iwl_notification_wait wait_scan_done;
1426 static const u8 scan_done_notif[] = { SCAN_OFFLOAD_COMPLETE, };
Johannes Berg8ca151b2013-01-24 14:25:36 +01001427 int ret;
1428
1429 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
1430 return -EINVAL;
1431
1432 mutex_lock(&mvm->mutex);
1433
Johannes Berga6623e82014-01-27 15:40:53 +01001434 switch (mvm->scan_status) {
1435 case IWL_MVM_SCAN_SCHED:
1436 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
1437 scan_done_notif,
1438 ARRAY_SIZE(scan_done_notif),
1439 NULL, NULL);
1440 iwl_mvm_sched_scan_stop(mvm);
1441 ret = iwl_wait_notification(&mvm->notif_wait,
1442 &wait_scan_done, HZ);
1443 if (ret) {
1444 ret = -EBUSY;
1445 goto out;
1446 }
1447 /* iwl_mvm_rx_scan_offload_complete_notif() will be called
1448 * soon but will not reset the scan status as it won't be
1449 * IWL_MVM_SCAN_SCHED any more since we queue the next scan
1450 * immediately (below)
1451 */
1452 break;
1453 case IWL_MVM_SCAN_NONE:
1454 break;
1455 default:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001456 ret = -EBUSY;
Arik Nemtsov519e2022013-10-17 17:51:35 +03001457 goto out;
1458 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001459
Arik Nemtsov519e2022013-10-17 17:51:35 +03001460 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
1461
1462 ret = iwl_mvm_scan_request(mvm, vif, req);
1463 if (ret)
1464 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1465out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001466 mutex_unlock(&mvm->mutex);
1467
1468 return ret;
1469}
1470
1471static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1472 struct ieee80211_vif *vif)
1473{
1474 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1475
1476 mutex_lock(&mvm->mutex);
1477
1478 iwl_mvm_cancel_scan(mvm);
1479
1480 mutex_unlock(&mvm->mutex);
1481}
1482
1483static void
1484iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
Johannes Berg3e56ead2013-02-15 22:23:18 +01001485 struct ieee80211_sta *sta, u16 tids,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001486 int num_frames,
1487 enum ieee80211_frame_release_type reason,
1488 bool more_data)
1489{
1490 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001491
Johannes Berg3e56ead2013-02-15 22:23:18 +01001492 /* Called when we need to transmit (a) frame(s) from mac80211 */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001493
Johannes Berg3e56ead2013-02-15 22:23:18 +01001494 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1495 tids, more_data, false);
1496}
1497
1498static void
1499iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
1500 struct ieee80211_sta *sta, u16 tids,
1501 int num_frames,
1502 enum ieee80211_frame_release_type reason,
1503 bool more_data)
1504{
1505 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1506
1507 /* Called when we need to transmit (a) frame(s) from agg queue */
1508
1509 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1510 tids, more_data, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001511}
1512
1513static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1514 struct ieee80211_vif *vif,
1515 enum sta_notify_cmd cmd,
1516 struct ieee80211_sta *sta)
1517{
1518 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Johannes Berg5b577a92013-11-14 18:20:04 +01001519 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg3e56ead2013-02-15 22:23:18 +01001520 int tid;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001521
1522 switch (cmd) {
1523 case STA_NOTIFY_SLEEP:
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03001524 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001525 ieee80211_sta_block_awake(hw, sta, true);
Johannes Berg3e56ead2013-02-15 22:23:18 +01001526 spin_lock_bh(&mvmsta->lock);
1527 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
1528 struct iwl_mvm_tid_data *tid_data;
1529
1530 tid_data = &mvmsta->tid_data[tid];
1531 if (tid_data->state != IWL_AGG_ON &&
1532 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
1533 continue;
1534 if (iwl_mvm_tid_queued(tid_data) == 0)
1535 continue;
1536 ieee80211_sta_set_buffered(sta, tid, true);
1537 }
1538 spin_unlock_bh(&mvmsta->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001539 /*
1540 * The fw updates the STA to be asleep. Tx packets on the Tx
1541 * queues to this station will not be transmitted. The fw will
1542 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1543 */
1544 break;
1545 case STA_NOTIFY_AWAKE:
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02001546 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01001547 break;
Johannes Berg9cc40712013-02-15 22:47:48 +01001548 iwl_mvm_sta_modify_ps_wake(mvm, sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001549 break;
1550 default:
1551 break;
1552 }
1553}
1554
Johannes Berg1ddbbb02013-12-04 22:39:17 +01001555static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
1556 struct ieee80211_vif *vif,
1557 struct ieee80211_sta *sta)
1558{
1559 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1560 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1561
1562 /*
1563 * This is called before mac80211 does RCU synchronisation,
1564 * so here we already invalidate our internal RCU-protected
1565 * station pointer. The rest of the code will thus no longer
1566 * be able to find the station this way, and we don't rely
1567 * on further RCU synchronisation after the sta_state()
1568 * callback deleted the station.
1569 */
1570 mutex_lock(&mvm->mutex);
1571 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
1572 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1573 ERR_PTR(-ENOENT));
1574 mutex_unlock(&mvm->mutex);
1575}
1576
Johannes Berg8ca151b2013-01-24 14:25:36 +01001577static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1578 struct ieee80211_vif *vif,
1579 struct ieee80211_sta *sta,
1580 enum ieee80211_sta_state old_state,
1581 enum ieee80211_sta_state new_state)
1582{
1583 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1584 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1585 int ret;
1586
1587 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1588 sta->addr, old_state, new_state);
1589
1590 /* this would be a mac80211 bug ... but don't crash */
1591 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1592 return -EINVAL;
1593
1594 /* if a STA is being removed, reuse its ID */
1595 flush_work(&mvm->sta_drained_wk);
1596
1597 mutex_lock(&mvm->mutex);
1598 if (old_state == IEEE80211_STA_NOTEXIST &&
1599 new_state == IEEE80211_STA_NONE) {
Johannes Berg48bc1302013-07-04 15:55:29 +02001600 /*
1601 * Firmware bug - it'll crash if the beacon interval is less
1602 * than 16. We can't avoid connecting at all, so refuse the
1603 * station state change, this will cause mac80211 to abandon
1604 * attempts to connect to this AP, and eventually wpa_s will
1605 * blacklist the AP...
1606 */
1607 if (vif->type == NL80211_IFTYPE_STATION &&
1608 vif->bss_conf.beacon_int < 16) {
1609 IWL_ERR(mvm,
1610 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1611 sta->addr, vif->bss_conf.beacon_int);
1612 ret = -EINVAL;
1613 goto out_unlock;
1614 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001615 ret = iwl_mvm_add_sta(mvm, vif, sta);
1616 } else if (old_state == IEEE80211_STA_NONE &&
1617 new_state == IEEE80211_STA_AUTH) {
1618 ret = 0;
1619 } else if (old_state == IEEE80211_STA_AUTH &&
1620 new_state == IEEE80211_STA_ASSOC) {
Johannes Berg7a453972013-02-12 13:10:44 +01001621 ret = iwl_mvm_update_sta(mvm, vif, sta);
1622 if (ret == 0)
1623 iwl_mvm_rs_rate_init(mvm, sta,
Eyal Shapirab87c2172013-11-09 23:37:55 +02001624 mvmvif->phy_ctxt->channel->band,
1625 true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001626 } else if (old_state == IEEE80211_STA_ASSOC &&
1627 new_state == IEEE80211_STA_AUTHORIZED) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001628 /* enable beacon filtering */
Eliad Peller3dd37d02014-01-07 14:00:24 +02001629 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, CMD_SYNC));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001630 ret = 0;
1631 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1632 new_state == IEEE80211_STA_ASSOC) {
Hila Gonen7df15b12012-12-12 11:16:19 +02001633 /* disable beacon filtering */
Eliad Peller3dd37d02014-01-07 14:00:24 +02001634 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001635 ret = 0;
1636 } else if (old_state == IEEE80211_STA_ASSOC &&
1637 new_state == IEEE80211_STA_AUTH) {
1638 ret = 0;
1639 } else if (old_state == IEEE80211_STA_AUTH &&
1640 new_state == IEEE80211_STA_NONE) {
1641 ret = 0;
1642 } else if (old_state == IEEE80211_STA_NONE &&
1643 new_state == IEEE80211_STA_NOTEXIST) {
1644 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1645 } else {
1646 ret = -EIO;
1647 }
Johannes Berg48bc1302013-07-04 15:55:29 +02001648 out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001649 mutex_unlock(&mvm->mutex);
1650
1651 return ret;
1652}
1653
1654static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1655{
1656 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1657
1658 mvm->rts_threshold = value;
1659
1660 return 0;
1661}
1662
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001663static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
1664 struct ieee80211_vif *vif,
1665 struct ieee80211_sta *sta, u32 changed)
1666{
1667 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1668
1669 if (vif->type == NL80211_IFTYPE_STATION &&
1670 changed & IEEE80211_RC_NSS_CHANGED)
1671 iwl_mvm_sf_update(mvm, vif, false);
1672}
1673
Johannes Berg8ca151b2013-01-24 14:25:36 +01001674static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1675 struct ieee80211_vif *vif, u16 ac,
1676 const struct ieee80211_tx_queue_params *params)
1677{
1678 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1679 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1680
1681 mvmvif->queue_params[ac] = *params;
1682
1683 /*
1684 * No need to update right away, we'll get BSS_CHANGED_QOS
1685 * The exception is P2P_DEVICE interface which needs immediate update.
1686 */
1687 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1688 int ret;
1689
1690 mutex_lock(&mvm->mutex);
1691 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1692 mutex_unlock(&mvm->mutex);
1693 return ret;
1694 }
1695 return 0;
1696}
1697
1698static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1699 struct ieee80211_vif *vif)
1700{
1701 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1702 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1703 200 + vif->bss_conf.beacon_int);
1704 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1705 100 + vif->bss_conf.beacon_int);
1706
1707 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1708 return;
1709
1710 mutex_lock(&mvm->mutex);
1711 /* Try really hard to protect the session and hear a beacon */
Johannes Berg016d27e2013-05-03 11:16:15 +02001712 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001713 mutex_unlock(&mvm->mutex);
1714}
1715
David Spinadel35a000b2013-08-28 09:29:43 +03001716static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
1717 struct ieee80211_vif *vif,
1718 struct cfg80211_sched_scan_request *req,
1719 struct ieee80211_sched_scan_ies *ies)
1720{
1721 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1722 int ret;
1723
1724 mutex_lock(&mvm->mutex);
1725
1726 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
1727 IWL_DEBUG_SCAN(mvm,
1728 "SCHED SCAN request during internal scan - abort\n");
1729 ret = -EBUSY;
1730 goto out;
1731 }
1732
1733 mvm->scan_status = IWL_MVM_SCAN_SCHED;
1734
1735 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
1736 if (ret)
1737 goto err;
1738
1739 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1740 if (ret)
1741 goto err;
1742
1743 ret = iwl_mvm_sched_scan_start(mvm, req);
1744 if (!ret)
1745 goto out;
1746err:
1747 mvm->scan_status = IWL_MVM_SCAN_NONE;
1748out:
1749 mutex_unlock(&mvm->mutex);
1750 return ret;
1751}
1752
1753static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
1754 struct ieee80211_vif *vif)
1755{
1756 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1757
1758 mutex_lock(&mvm->mutex);
1759 iwl_mvm_sched_scan_stop(mvm);
1760 mutex_unlock(&mvm->mutex);
1761}
1762
Johannes Berg8ca151b2013-01-24 14:25:36 +01001763static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1764 enum set_key_cmd cmd,
1765 struct ieee80211_vif *vif,
1766 struct ieee80211_sta *sta,
1767 struct ieee80211_key_conf *key)
1768{
1769 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1770 int ret;
1771
1772 if (iwlwifi_mod_params.sw_crypto) {
1773 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1774 return -EOPNOTSUPP;
1775 }
1776
1777 switch (key->cipher) {
1778 case WLAN_CIPHER_SUITE_TKIP:
1779 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1780 /* fall-through */
1781 case WLAN_CIPHER_SUITE_CCMP:
1782 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1783 break;
1784 case WLAN_CIPHER_SUITE_AES_CMAC:
1785 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1786 break;
1787 case WLAN_CIPHER_SUITE_WEP40:
1788 case WLAN_CIPHER_SUITE_WEP104:
1789 /*
1790 * Support for TX only, at least for now, so accept
1791 * the key and do nothing else. Then mac80211 will
1792 * pass it for TX but we don't have to use it for RX.
1793 */
1794 return 0;
1795 default:
Max Stepanove36e5432013-08-27 19:56:13 +03001796 /* currently FW supports only one optional cipher scheme */
1797 if (hw->n_cipher_schemes &&
1798 hw->cipher_schemes->cipher == key->cipher)
1799 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
1800 else
1801 return -EOPNOTSUPP;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001802 }
1803
1804 mutex_lock(&mvm->mutex);
1805
1806 switch (cmd) {
1807 case SET_KEY:
Johannes Berg5023d962013-07-31 14:07:43 +02001808 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1809 vif->type == NL80211_IFTYPE_AP) && !sta) {
1810 /*
1811 * GTK on AP interface is a TX-only key, return 0;
1812 * on IBSS they're per-station and because we're lazy
1813 * we don't support them for RX, so do the same.
1814 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001815 ret = 0;
1816 key->hw_key_idx = STA_KEY_IDX_INVALID;
1817 break;
1818 }
1819
Johannes Berg8ca151b2013-01-24 14:25:36 +01001820 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1821 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1822 if (ret) {
1823 IWL_WARN(mvm, "set key failed\n");
1824 /*
1825 * can't add key for RX, but we don't need it
1826 * in the device for TX so still return 0
1827 */
Johannes Berg6caffd42013-03-06 13:15:21 +01001828 key->hw_key_idx = STA_KEY_IDX_INVALID;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001829 ret = 0;
1830 }
1831
1832 break;
1833 case DISABLE_KEY:
Johannes Berg6caffd42013-03-06 13:15:21 +01001834 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1835 ret = 0;
1836 break;
1837 }
1838
Johannes Berg8ca151b2013-01-24 14:25:36 +01001839 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1840 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1841 break;
1842 default:
1843 ret = -EINVAL;
1844 }
1845
1846 mutex_unlock(&mvm->mutex);
1847 return ret;
1848}
1849
1850static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1851 struct ieee80211_vif *vif,
1852 struct ieee80211_key_conf *keyconf,
1853 struct ieee80211_sta *sta,
1854 u32 iv32, u16 *phase1key)
1855{
1856 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1857
Johannes Berg5023d962013-07-31 14:07:43 +02001858 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
1859 return;
1860
Johannes Berg8ca151b2013-01-24 14:25:36 +01001861 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1862}
1863
1864
1865static int iwl_mvm_roc(struct ieee80211_hw *hw,
1866 struct ieee80211_vif *vif,
1867 struct ieee80211_channel *channel,
Ilan Peerd339d5c2013-02-12 09:34:13 +02001868 int duration,
1869 enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001870{
1871 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001872 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001873 struct cfg80211_chan_def chandef;
Ilan Peer31d385a2013-04-02 10:25:46 +03001874 struct iwl_mvm_phy_ctxt *phy_ctxt;
1875 int ret, i;
1876
1877 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1878 duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001879
1880 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1881 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1882 return -EINVAL;
1883 }
1884
Johannes Berg8ca151b2013-01-24 14:25:36 +01001885 mutex_lock(&mvm->mutex);
1886
Ilan Peer31d385a2013-04-02 10:25:46 +03001887 for (i = 0; i < NUM_PHY_CTX; i++) {
1888 phy_ctxt = &mvm->phy_ctxts[i];
1889 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
1890 continue;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001891
Ilan Peer31d385a2013-04-02 10:25:46 +03001892 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1893 /*
1894 * Unbind the P2P_DEVICE from the current PHY context,
1895 * and if the PHY context is not used remove it.
1896 */
1897 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1898 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1899 goto out_unlock;
1900
1901 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1902
1903 /* Bind the P2P_DEVICE to the current PHY Context */
1904 mvmvif->phy_ctxt = phy_ctxt;
1905
1906 ret = iwl_mvm_binding_add_vif(mvm, vif);
1907 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1908 goto out_unlock;
1909
1910 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1911 goto schedule_time_event;
1912 }
1913 }
1914
1915 /* Need to update the PHY context only if the ROC channel changed */
1916 if (channel == mvmvif->phy_ctxt->channel)
1917 goto schedule_time_event;
1918
1919 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
1920
1921 /*
1922 * Change the PHY context configuration as it is currently referenced
1923 * only by the P2P Device MAC
1924 */
1925 if (mvmvif->phy_ctxt->ref == 1) {
1926 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
1927 &chandef, 1, 1);
1928 if (ret)
1929 goto out_unlock;
1930 } else {
1931 /*
1932 * The PHY context is shared with other MACs. Need to remove the
1933 * P2P Device from the binding, allocate an new PHY context and
1934 * create a new binding
1935 */
1936 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1937 if (!phy_ctxt) {
1938 ret = -ENOSPC;
1939 goto out_unlock;
1940 }
1941
1942 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
1943 1, 1);
1944 if (ret) {
1945 IWL_ERR(mvm, "Failed to change PHY context\n");
1946 goto out_unlock;
1947 }
1948
1949 /* Unbind the P2P_DEVICE from the current PHY context */
1950 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1951 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1952 goto out_unlock;
1953
1954 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1955
1956 /* Bind the P2P_DEVICE to the new allocated PHY context */
1957 mvmvif->phy_ctxt = phy_ctxt;
1958
1959 ret = iwl_mvm_binding_add_vif(mvm, vif);
1960 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1961 goto out_unlock;
1962
1963 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1964 }
1965
1966schedule_time_event:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001967 /* Schedule the time events */
Ilan Peere635c792013-02-13 11:05:18 +02001968 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001969
Ilan Peer31d385a2013-04-02 10:25:46 +03001970out_unlock:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001971 mutex_unlock(&mvm->mutex);
1972 IWL_DEBUG_MAC80211(mvm, "leave\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001973 return ret;
1974}
1975
1976static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1977{
1978 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1979
1980 IWL_DEBUG_MAC80211(mvm, "enter\n");
1981
1982 mutex_lock(&mvm->mutex);
1983 iwl_mvm_stop_p2p_roc(mvm);
1984 mutex_unlock(&mvm->mutex);
1985
1986 IWL_DEBUG_MAC80211(mvm, "leave\n");
1987 return 0;
1988}
1989
1990static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1991 struct ieee80211_chanctx_conf *ctx)
1992{
1993 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001994 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1995 struct iwl_mvm_phy_ctxt *phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001996 int ret;
1997
Ilan Peer53a9d612013-04-28 11:55:08 +03001998 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
Ilan Peerfe0f2de2013-03-21 10:23:52 +02001999
2000 mutex_lock(&mvm->mutex);
2001 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2002 if (!phy_ctxt) {
2003 ret = -ENOSPC;
2004 goto out;
2005 }
2006
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02002007 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Ilan Peer53a9d612013-04-28 11:55:08 +03002008 ctx->rx_chains_static,
2009 ctx->rx_chains_dynamic);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002010 if (ret) {
2011 IWL_ERR(mvm, "Failed to add PHY context\n");
2012 goto out;
2013 }
2014
Ilan Peer53a9d612013-04-28 11:55:08 +03002015 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002016 *phy_ctxt_id = phy_ctxt->id;
2017out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002018 mutex_unlock(&mvm->mutex);
2019 return ret;
2020}
2021
2022static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2023 struct ieee80211_chanctx_conf *ctx)
2024{
2025 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002026 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2027 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002028
2029 mutex_lock(&mvm->mutex);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002030 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002031 mutex_unlock(&mvm->mutex);
2032}
2033
2034static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
2035 struct ieee80211_chanctx_conf *ctx,
2036 u32 changed)
2037{
2038 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002039 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2040 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002041
Ilan Peer31d385a2013-04-02 10:25:46 +03002042 if (WARN_ONCE((phy_ctxt->ref > 1) &&
2043 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
2044 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
Arik Nemtsov2dceeda2013-12-29 17:57:53 +02002045 IEEE80211_CHANCTX_CHANGE_RADAR |
2046 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
Ilan Peer31d385a2013-04-02 10:25:46 +03002047 "Cannot change PHY. Ref=%d, changed=0x%X\n",
2048 phy_ctxt->ref, changed))
2049 return;
2050
Johannes Berg8ca151b2013-01-24 14:25:36 +01002051 mutex_lock(&mvm->mutex);
Eliad Pellerdcbc3e12013-10-31 14:31:25 +02002052 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002053 ctx->rx_chains_static,
2054 ctx->rx_chains_dynamic);
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +03002055 iwl_mvm_bt_coex_vif_change(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002056 mutex_unlock(&mvm->mutex);
2057}
2058
2059static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
2060 struct ieee80211_vif *vif,
2061 struct ieee80211_chanctx_conf *ctx)
2062{
2063 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002064 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2065 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002066 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2067 int ret;
2068
2069 mutex_lock(&mvm->mutex);
2070
Ilan Peerfe0f2de2013-03-21 10:23:52 +02002071 mvmvif->phy_ctxt = phy_ctxt;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002072
2073 switch (vif->type) {
2074 case NL80211_IFTYPE_AP:
Johannes Berg5023d962013-07-31 14:07:43 +02002075 case NL80211_IFTYPE_ADHOC:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002076 /*
2077 * The AP binding flow is handled as part of the start_ap flow
Johannes Berg5023d962013-07-31 14:07:43 +02002078 * (in bss_info_changed), similarly for IBSS.
Johannes Berg8ca151b2013-01-24 14:25:36 +01002079 */
2080 ret = 0;
2081 goto out_unlock;
2082 case NL80211_IFTYPE_STATION:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002083 case NL80211_IFTYPE_MONITOR:
2084 break;
2085 default:
2086 ret = -EINVAL;
2087 goto out_unlock;
2088 }
2089
2090 ret = iwl_mvm_binding_add_vif(mvm, vif);
2091 if (ret)
2092 goto out_unlock;
2093
2094 /*
Alexander Bondar92d85562013-10-23 11:50:34 +02002095 * Power state must be updated before quotas,
2096 * otherwise fw will complain.
2097 */
2098 mvm->bound_vif_cnt++;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02002099 iwl_mvm_power_update_mac(mvm, vif);
Alexander Bondar92d85562013-10-23 11:50:34 +02002100
2101 /* Setting the quota at this stage is only required for monitor
Johannes Berg8ca151b2013-01-24 14:25:36 +01002102 * interfaces. For the other types, the bss_info changed flow
2103 * will handle quota settings.
2104 */
2105 if (vif->type == NL80211_IFTYPE_MONITOR) {
Ilan Peer1e1391c2013-03-13 14:52:04 +02002106 mvmvif->monitor_active = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002107 ret = iwl_mvm_update_quotas(mvm, vif);
2108 if (ret)
2109 goto out_remove_binding;
2110 }
2111
2112 goto out_unlock;
2113
2114 out_remove_binding:
2115 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar92d85562013-10-23 11:50:34 +02002116 mvm->bound_vif_cnt--;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02002117 iwl_mvm_power_update_mac(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002118 out_unlock:
2119 mutex_unlock(&mvm->mutex);
2120 if (ret)
2121 mvmvif->phy_ctxt = NULL;
2122 return ret;
2123}
2124
2125static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
2126 struct ieee80211_vif *vif,
2127 struct ieee80211_chanctx_conf *ctx)
2128{
2129 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2130 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2131
2132 mutex_lock(&mvm->mutex);
2133
2134 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
2135
Johannes Berg8ca151b2013-01-24 14:25:36 +01002136 switch (vif->type) {
Johannes Berg5023d962013-07-31 14:07:43 +02002137 case NL80211_IFTYPE_AP:
2138 case NL80211_IFTYPE_ADHOC:
2139 goto out_unlock;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002140 case NL80211_IFTYPE_MONITOR:
Ilan Peer1e1391c2013-03-13 14:52:04 +02002141 mvmvif->monitor_active = false;
2142 iwl_mvm_update_quotas(mvm, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002143 break;
2144 default:
2145 break;
2146 }
2147
Ilan Peer1e1391c2013-03-13 14:52:04 +02002148 iwl_mvm_binding_remove_vif(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03002149 mvm->bound_vif_cnt--;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +02002150 iwl_mvm_power_update_mac(mvm, vif);
Alexander Bondar1c2abf72013-08-27 20:31:48 +03002151
Ilan Peera11e1442013-12-31 21:19:55 +02002152out_unlock:
2153 mvmvif->phy_ctxt = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002154 mutex_unlock(&mvm->mutex);
2155}
2156
2157static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
2158 struct ieee80211_sta *sta,
2159 bool set)
2160{
2161 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2162 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
2163
2164 if (!mvm_sta || !mvm_sta->vif) {
2165 IWL_ERR(mvm, "Station is not associated to a vif\n");
2166 return -EINVAL;
2167 }
2168
2169 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
2170}
2171
David Spinadel507cadf2013-07-31 18:07:21 +03002172#ifdef CONFIG_NL80211_TESTMODE
2173static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
2174 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
2175 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
Johannes Bergf6c6ad42013-08-01 14:17:15 +02002176 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
David Spinadel507cadf2013-07-31 18:07:21 +03002177};
2178
2179static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
2180 struct ieee80211_vif *vif,
2181 void *data, int len)
2182{
2183 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
2184 int err;
2185 u32 noa_duration;
2186
2187 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
2188 if (err)
2189 return err;
2190
2191 if (!tb[IWL_MVM_TM_ATTR_CMD])
2192 return -EINVAL;
2193
2194 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
2195 case IWL_MVM_TM_CMD_SET_NOA:
2196 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
2197 !vif->bss_conf.enable_beacon ||
2198 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
2199 return -EINVAL;
2200
2201 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
2202 if (noa_duration >= vif->bss_conf.beacon_int)
2203 return -EINVAL;
2204
2205 mvm->noa_duration = noa_duration;
2206 mvm->noa_vif = vif;
2207
2208 return iwl_mvm_update_quotas(mvm, NULL);
Johannes Bergf6c6ad42013-08-01 14:17:15 +02002209 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
2210 /* must be associated client vif - ignore authorized */
2211 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
2212 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
2213 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
2214 return -EINVAL;
2215
2216 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
Eliad Peller3dd37d02014-01-07 14:00:24 +02002217 return iwl_mvm_enable_beacon_filter(mvm, vif,
2218 CMD_SYNC);
2219 return iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC);
David Spinadel507cadf2013-07-31 18:07:21 +03002220 }
2221
2222 return -EOPNOTSUPP;
2223}
2224
2225static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
2226 struct ieee80211_vif *vif,
2227 void *data, int len)
2228{
2229 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2230 int err;
2231
2232 mutex_lock(&mvm->mutex);
2233 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
2234 mutex_unlock(&mvm->mutex);
2235
2236 return err;
2237}
2238#endif
2239
Johannes Berge5209262014-01-20 23:38:59 +01002240const struct ieee80211_ops iwl_mvm_hw_ops = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002241 .tx = iwl_mvm_mac_tx,
2242 .ampdu_action = iwl_mvm_mac_ampdu_action,
2243 .start = iwl_mvm_mac_start,
2244 .restart_complete = iwl_mvm_mac_restart_complete,
2245 .stop = iwl_mvm_mac_stop,
2246 .add_interface = iwl_mvm_mac_add_interface,
2247 .remove_interface = iwl_mvm_mac_remove_interface,
2248 .config = iwl_mvm_mac_config,
Eliad Pellere59647e2013-11-28 14:08:50 +02002249 .prepare_multicast = iwl_mvm_prepare_multicast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002250 .configure_filter = iwl_mvm_configure_filter,
2251 .bss_info_changed = iwl_mvm_bss_info_changed,
2252 .hw_scan = iwl_mvm_mac_hw_scan,
2253 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
Johannes Berg1ddbbb02013-12-04 22:39:17 +01002254 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002255 .sta_state = iwl_mvm_mac_sta_state,
2256 .sta_notify = iwl_mvm_mac_sta_notify,
2257 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
Johannes Berg3e56ead2013-02-15 22:23:18 +01002258 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002259 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02002260 .sta_rc_update = iwl_mvm_sta_rc_update,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002261 .conf_tx = iwl_mvm_mac_conf_tx,
2262 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
David Spinadel35a000b2013-08-28 09:29:43 +03002263 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
2264 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002265 .set_key = iwl_mvm_mac_set_key,
2266 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
2267 .remain_on_channel = iwl_mvm_roc,
2268 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002269 .add_chanctx = iwl_mvm_add_chanctx,
2270 .remove_chanctx = iwl_mvm_remove_chanctx,
2271 .change_chanctx = iwl_mvm_change_chanctx,
2272 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
2273 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
2274
Johannes Berg5023d962013-07-31 14:07:43 +02002275 .start_ap = iwl_mvm_start_ap_ibss,
2276 .stop_ap = iwl_mvm_stop_ap_ibss,
2277 .join_ibss = iwl_mvm_start_ap_ibss,
2278 .leave_ibss = iwl_mvm_stop_ap_ibss,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002279
2280 .set_tim = iwl_mvm_set_tim,
2281
David Spinadel507cadf2013-07-31 18:07:21 +03002282 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
2283
Johannes Berg8ca151b2013-01-24 14:25:36 +01002284#ifdef CONFIG_PM_SLEEP
2285 /* look at d3.c */
2286 .suspend = iwl_mvm_suspend,
2287 .resume = iwl_mvm_resume,
2288 .set_wakeup = iwl_mvm_set_wakeup,
2289 .set_rekey_data = iwl_mvm_set_rekey_data,
2290#if IS_ENABLED(CONFIG_IPV6)
2291 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
2292#endif
2293 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
2294#endif
2295};