]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/net/wireless/iwlwifi/mvm/mac80211.c
iwlwifi: mvm: add bcast_filtering debugfs entries
[mirror_ubuntu-bionic-kernel.git] / drivers / net / wireless / iwlwifi / mvm / mac80211.c
CommitLineData
8ca151b5
JB
1/******************************************************************************
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 *
51368bf7 8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8ca151b5
JB
9 *
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
410dc5aa 25 * in the file called COPYING.
8ca151b5
JB
26 *
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 *
51368bf7 33 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8ca151b5
JB
34 * 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>
f0c2646a 68#include <linux/ip.h>
2ee8f021 69#include <linux/if_arp.h>
8ca151b5 70#include <net/mac80211.h>
f0c2646a 71#include <net/tcp.h>
8ca151b5
JB
72
73#include "iwl-op-mode.h"
74#include "iwl-io.h"
75#include "mvm.h"
76#include "sta.h"
77#include "time-event.h"
78#include "iwl-eeprom-parse.h"
79#include "fw-api-scan.h"
80#include "iwl-phy-db.h"
507cadf2 81#include "testmode.h"
8ca151b5
JB
82
83static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
84 {
85 .max = 1,
8eb38710 86 .types = BIT(NL80211_IFTYPE_STATION),
8ca151b5 87 },
3c15a0fb
JB
88 {
89 .max = 1,
8eb38710
IP
90 .types = BIT(NL80211_IFTYPE_AP) |
91 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3c15a0fb
JB
92 BIT(NL80211_IFTYPE_P2P_GO),
93 },
94 {
95 .max = 1,
96 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
97 },
8ca151b5
JB
98};
99
100static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
101 {
102 .num_different_channels = 1,
103 .max_interfaces = 3,
104 .limits = iwl_mvm_limits,
105 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
106 },
107};
108
f0c2646a
JB
109#ifdef CONFIG_PM_SLEEP
110static const struct nl80211_wowlan_tcp_data_token_feature
111iwl_mvm_wowlan_tcp_token_feature = {
112 .min_len = 0,
113 .max_len = 255,
114 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
115};
116
117static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
118 .tok = &iwl_mvm_wowlan_tcp_token_feature,
119 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
120 sizeof(struct ethhdr) -
121 sizeof(struct iphdr) -
122 sizeof(struct tcphdr),
123 .data_interval_max = 65535, /* __le16 in API */
124 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
125 sizeof(struct ethhdr) -
126 sizeof(struct iphdr) -
127 sizeof(struct tcphdr),
128 .seq = true,
129};
130#endif
131
77736923 132#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
2ee8f021
EP
133/*
134 * Use the reserved field to indicate magic values.
135 * these values will only be used internally by the driver,
136 * and won't make it to the fw (reserved will be 0).
137 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
138 * be the vif's ip address. in case there is not a single
139 * ip address (0, or more than 1), this attribute will
140 * be skipped.
141 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
142 * the LSB bytes of the vif's mac address
143 */
144enum {
145 BC_FILTER_MAGIC_NONE = 0,
146 BC_FILTER_MAGIC_IP,
147 BC_FILTER_MAGIC_MAC,
148};
149
77736923
EP
150static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
151 {
152 /* arp */
153 .discard = 0,
154 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
155 .attrs = {
156 {
157 /* frame type - arp, hw type - ethernet */
158 .offset_type =
159 BCAST_FILTER_OFFSET_PAYLOAD_START,
160 .offset = sizeof(rfc1042_header),
161 .val = cpu_to_be32(0x08060001),
162 .mask = cpu_to_be32(0xffffffff),
163 },
2ee8f021
EP
164 {
165 /* arp dest ip */
166 .offset_type =
167 BCAST_FILTER_OFFSET_PAYLOAD_START,
168 .offset = sizeof(rfc1042_header) + 2 +
169 sizeof(struct arphdr) +
170 ETH_ALEN + sizeof(__be32) +
171 ETH_ALEN,
172 .mask = cpu_to_be32(0xffffffff),
173 /* mark it as special field */
174 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
175 },
176 },
177 },
178 {
179 /* dhcp offer bcast */
180 .discard = 0,
181 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
182 .attrs = {
183 {
184 /* udp dest port - 68 (bootp client)*/
185 .offset_type = BCAST_FILTER_OFFSET_IP_END,
186 .offset = offsetof(struct udphdr, dest),
187 .val = cpu_to_be32(0x00440000),
188 .mask = cpu_to_be32(0xffff0000),
189 },
190 {
191 /* dhcp - lsb bytes of client hw address */
192 .offset_type = BCAST_FILTER_OFFSET_IP_END,
193 .offset = 38,
194 .mask = cpu_to_be32(0xffffffff),
195 /* mark it as special field */
196 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
197 },
77736923
EP
198 },
199 },
200 /* last filter must be empty */
201 {},
202};
203#endif
204
fe0f2de3
IP
205static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
206{
207 int i;
208
209 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
210 for (i = 0; i < NUM_PHY_CTX; i++) {
211 mvm->phy_ctxts[i].id = i;
212 mvm->phy_ctxts[i].ref = 0;
213 }
214}
215
20f1a5de
DS
216static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
217{
218 /* we create the 802.11 header and SSID element */
219 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID)
220 return mvm->fw->ucode_capa.max_probe_length - 24 - 2;
221 return mvm->fw->ucode_capa.max_probe_length - 24 - 34;
222}
223
8ca151b5
JB
224int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
225{
226 struct ieee80211_hw *hw = mvm->hw;
831e85f3 227 int num_mac, ret, i;
8ca151b5
JB
228
229 /* Tell mac80211 our characteristics */
230 hw->flags = IEEE80211_HW_SIGNAL_DBM |
231 IEEE80211_HW_SPECTRUM_MGMT |
232 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
233 IEEE80211_HW_QUEUE_CONTROL |
234 IEEE80211_HW_WANT_MONITOR_VIF |
8ca151b5
JB
235 IEEE80211_HW_SUPPORTS_PS |
236 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
d2931bbd 237 IEEE80211_HW_AMPDU_AGGREGATION |
d64048ed 238 IEEE80211_HW_TIMING_BEACON_ONLY |
147fc9be
EG
239 IEEE80211_HW_CONNECTION_MONITOR |
240 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
e8e626ad 241 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
8ca151b5 242
19e737c9 243 hw->queues = mvm->first_agg_queue;
398e8c6c 244 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
8ca151b5
JB
245 hw->rate_control_algorithm = "iwl-mvm-rs";
246
247 /*
248 * Enable 11w if advertised by firmware and software crypto
249 * is not enabled (as the firmware will interpret some mgmt
250 * packets, so enabling it with software crypto isn't safe)
251 */
252 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
253 !iwlwifi_mod_params.sw_crypto)
254 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
255
e8e626ad
AB
256 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT) {
257 hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
258 hw->uapsd_queues = IWL_UAPSD_AC_INFO;
259 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
260 }
261
8ca151b5
JB
262 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
263 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
fe0f2de3 264 hw->chanctx_data_size = sizeof(u16);
8ca151b5
JB
265
266 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
3c15a0fb
JB
267 BIT(NL80211_IFTYPE_P2P_CLIENT) |
268 BIT(NL80211_IFTYPE_AP) |
269 BIT(NL80211_IFTYPE_P2P_GO) |
270 BIT(NL80211_IFTYPE_P2P_DEVICE);
8ca151b5 271
5023d966
JB
272 /* IBSS has bugs in older versions */
273 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 8)
274 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
275
a2f73b6c
LR
276 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
277 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
278 REGULATORY_DISABLE_BEACON_HINTS;
8ca151b5 279
3e56eadf
JB
280 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
281 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
282
8ca151b5
JB
283 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
284 hw->wiphy->n_iface_combinations =
285 ARRAY_SIZE(iwl_mvm_iface_combinations);
286
c451e6d4 287 hw->wiphy->max_remain_on_channel_duration = 10000;
8ca151b5
JB
288 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
289
290 /* Extract MAC address */
291 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
292 hw->wiphy->addresses = mvm->addresses;
293 hw->wiphy->n_addresses = 1;
831e85f3
IP
294
295 /* Extract additional MAC addresses if available */
296 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
297 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
298
299 for (i = 1; i < num_mac; i++) {
300 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
8ca151b5 301 ETH_ALEN);
831e85f3 302 mvm->addresses[i].addr[5]++;
8ca151b5
JB
303 hw->wiphy->n_addresses++;
304 }
305
fe0f2de3
IP
306 iwl_mvm_reset_phy_ctxts(mvm);
307
20f1a5de
DS
308 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
309
8ca151b5
JB
310 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
311
312 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
313 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
314 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
315 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
316 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
317 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
318
319 hw->wiphy->hw_version = mvm->trans->hw_id;
320
ade50652 321 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
8ca151b5
JB
322 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
323 else
324 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
325
35a000b7
DS
326 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) {
327 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
328 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
329 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
330 /* we create the 802.11 header and zero length SSID IE. */
331 hw->wiphy->max_sched_scan_ie_len =
332 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
333 }
334
8ca151b5 335 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
61f6325d
HD
336 NL80211_FEATURE_P2P_GO_OPPPS |
337 NL80211_FEATURE_LOW_PRIORITY_SCAN;
8ca151b5
JB
338
339 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
340
e36e5433 341 /* currently FW API supports only one optional cipher scheme */
9ddca860 342 if (mvm->fw->cs[0].cipher) {
e36e5433 343 mvm->hw->n_cipher_schemes = 1;
9ddca860 344 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
e36e5433
MS
345 }
346
8ca151b5
JB
347#ifdef CONFIG_PM_SLEEP
348 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
349 mvm->trans->ops->d3_suspend &&
350 mvm->trans->ops->d3_resume &&
351 device_can_wakeup(mvm->trans->dev)) {
964dc9e2
JB
352 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
353 WIPHY_WOWLAN_DISCONNECT |
354 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
355 WIPHY_WOWLAN_RFKILL_RELEASE;
8ca151b5 356 if (!iwlwifi_mod_params.sw_crypto)
964dc9e2
JB
357 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
358 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
359 WIPHY_WOWLAN_4WAY_HANDSHAKE;
360
361 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
362 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
363 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
364 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
365 hw->wiphy->wowlan = &mvm->wowlan;
8ca151b5
JB
366 }
367#endif
368
77736923
EP
369#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
370 /* assign default bcast filtering configuration */
371 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
372#endif
373
8ca151b5
JB
374 ret = iwl_mvm_leds_init(mvm);
375 if (ret)
376 return ret;
377
b7327d89
EG
378 ret = ieee80211_register_hw(mvm->hw);
379 if (ret)
380 iwl_mvm_leds_exit(mvm);
381
382 return ret;
8ca151b5
JB
383}
384
385static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
386 struct ieee80211_tx_control *control,
387 struct sk_buff *skb)
388{
389 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3e56eadf
JB
390 struct ieee80211_sta *sta = control->sta;
391 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
392 struct ieee80211_hdr *hdr = (void *)skb->data;
8ca151b5 393
9ee718aa
EL
394 if (iwl_mvm_is_radio_killed(mvm)) {
395 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
8ca151b5
JB
396 goto drop;
397 }
398
398e8c6c 399 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
8ca151b5
JB
400 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
401 goto drop;
402
3e56eadf
JB
403 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
404 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
405 ieee80211_is_mgmt(hdr->frame_control) &&
406 !ieee80211_is_deauth(hdr->frame_control) &&
407 !ieee80211_is_disassoc(hdr->frame_control) &&
408 !ieee80211_is_action(hdr->frame_control)))
409 sta = NULL;
410
411 if (sta) {
412 if (iwl_mvm_tx_skb(mvm, skb, sta))
8ca151b5
JB
413 goto drop;
414 return;
415 }
416
417 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
418 goto drop;
419 return;
420 drop:
421 ieee80211_free_txskb(hw, skb);
422}
423
424static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
425 struct ieee80211_vif *vif,
426 enum ieee80211_ampdu_mlme_action action,
427 struct ieee80211_sta *sta, u16 tid,
428 u16 *ssn, u8 buf_size)
429{
430 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
431 int ret;
432
433 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
434 sta->addr, tid, action);
435
436 if (!(mvm->nvm_data->sku_cap_11n_enable))
437 return -EACCES;
438
439 mutex_lock(&mvm->mutex);
440
441 switch (action) {
442 case IEEE80211_AMPDU_RX_START:
443 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
444 ret = -EINVAL;
445 break;
446 }
447 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
448 break;
449 case IEEE80211_AMPDU_RX_STOP:
450 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
451 break;
452 case IEEE80211_AMPDU_TX_START:
5d158efa
EG
453 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
454 ret = -EINVAL;
455 break;
456 }
8ca151b5
JB
457 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
458 break;
459 case IEEE80211_AMPDU_TX_STOP_CONT:
e3d9e7ce
EG
460 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
461 break;
8ca151b5
JB
462 case IEEE80211_AMPDU_TX_STOP_FLUSH:
463 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
e3d9e7ce 464 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
8ca151b5
JB
465 break;
466 case IEEE80211_AMPDU_TX_OPERATIONAL:
467 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
468 break;
469 default:
470 WARN_ON_ONCE(1);
471 ret = -EINVAL;
472 break;
473 }
474 mutex_unlock(&mvm->mutex);
475
476 return ret;
477}
478
479static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
480 struct ieee80211_vif *vif)
481{
482 struct iwl_mvm *mvm = data;
483 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
484
485 mvmvif->uploaded = false;
486 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
487
488 /* does this make sense at all? */
489 mvmvif->color++;
490
491 spin_lock_bh(&mvm->time_event_lock);
492 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
493 spin_unlock_bh(&mvm->time_event_lock);
494
fe0f2de3 495 mvmvif->phy_ctxt = NULL;
8ca151b5
JB
496}
497
498static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
499{
500 iwl_trans_stop_device(mvm->trans);
8ca151b5
JB
501
502 mvm->scan_status = IWL_MVM_SCAN_NONE;
503
504 /* just in case one was running */
505 ieee80211_remain_on_channel_expired(mvm->hw);
506
507 ieee80211_iterate_active_interfaces_atomic(
508 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
509 iwl_mvm_cleanup_iterator, mvm);
510
fe0f2de3
IP
511 mvm->p2p_device_vif = NULL;
512
513 iwl_mvm_reset_phy_ctxts(mvm);
8ca151b5
JB
514 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
515 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
516
517 ieee80211_wake_queues(mvm->hw);
518
519 mvm->vif_count = 0;
113a0447 520 mvm->rx_ba_sessions = 0;
8ca151b5
JB
521}
522
523static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
524{
525 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
526 int ret;
527
528 mutex_lock(&mvm->mutex);
529
530 /* Clean up some internal and mac80211 state on restart */
531 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
532 iwl_mvm_restart_cleanup(mvm);
533
534 ret = iwl_mvm_up(mvm);
535 mutex_unlock(&mvm->mutex);
536
537 return ret;
538}
539
540static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
541{
542 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
543 int ret;
544
545 mutex_lock(&mvm->mutex);
546
547 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
548 ret = iwl_mvm_update_quotas(mvm, NULL);
549 if (ret)
550 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
551 ret);
552
553 mutex_unlock(&mvm->mutex);
554}
555
556static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
557{
558 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
559
560 flush_work(&mvm->async_handlers_wk);
561
562 mutex_lock(&mvm->mutex);
563 /* async_handlers_wk is now blocked */
564
565 /*
566 * The work item could be running or queued if the
567 * ROC time event stops just as we get here.
568 */
569 cancel_work_sync(&mvm->roc_done_wk);
570
571 iwl_trans_stop_device(mvm->trans);
8ca151b5
JB
572
573 iwl_mvm_async_handlers_purge(mvm);
574 /* async_handlers_list is empty and will stay empty: HW is stopped */
575
576 /* the fw is stopped, the aux sta is dead: clean up driver state */
577 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
578
579 mutex_unlock(&mvm->mutex);
580
581 /*
582 * The worker might have been waiting for the mutex, let it run and
583 * discover that its list is now empty.
584 */
585 cancel_work_sync(&mvm->async_handlers_wk);
586}
587
8ca151b5
JB
588static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
589 struct ieee80211_vif *vif)
590{
591 struct iwl_mvm *mvm = data;
592
593 iwl_mvm_power_update_mode(mvm, vif);
594}
595
fe0f2de3
IP
596static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
597{
598 u16 i;
599
600 lockdep_assert_held(&mvm->mutex);
601
602 for (i = 0; i < NUM_PHY_CTX; i++)
603 if (!mvm->phy_ctxts[i].ref)
604 return &mvm->phy_ctxts[i];
605
606 IWL_ERR(mvm, "No available PHY context\n");
607 return NULL;
608}
609
ee9c6cb0
EG
610static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
611 s8 tx_power)
612{
613 /* FW is in charge of regulatory enforcement */
614 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
615 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
616 .pwr_restriction = cpu_to_le16(tx_power),
617 };
618
619 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
620 sizeof(reduce_txpwr_cmd),
621 &reduce_txpwr_cmd);
622}
623
8ca151b5
JB
624static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
625 struct ieee80211_vif *vif)
626{
627 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
628 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
629 int ret;
630
631 /*
632 * Not much to do here. The stack will not allow interface
633 * types or combinations that we didn't advertise, so we
634 * don't really have to check the types.
635 */
636
637 mutex_lock(&mvm->mutex);
638
e89044d7 639 /* Allocate resources for the MAC context, and add it to the fw */
8ca151b5
JB
640 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
641 if (ret)
642 goto out_unlock;
643
1c2abf72 644 /* Counting number of interfaces is needed for legacy PM */
ea183d02
IP
645 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
646 mvm->vif_count++;
ea183d02 647
8ca151b5
JB
648 /*
649 * The AP binding flow can be done only after the beacon
650 * template is configured (which happens only in the mac80211
651 * start_ap() flow), and adding the broadcast station can happen
652 * only after the binding.
653 * In addition, since modifying the MAC before adding a bcast
654 * station is not allowed by the FW, delay the adding of MAC context to
655 * the point where we can also add the bcast station.
656 * In short: there's not much we can do at this point, other than
657 * allocating resources :)
658 */
5023d966
JB
659 if (vif->type == NL80211_IFTYPE_AP ||
660 vif->type == NL80211_IFTYPE_ADHOC) {
8ca151b5
JB
661 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
662 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
663 qmask);
664 if (ret) {
665 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
666 goto out_release;
667 }
668
77740cb4 669 iwl_mvm_vif_dbgfs_register(mvm, vif);
8ca151b5
JB
670 goto out_unlock;
671 }
672
8ca151b5
JB
673 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
674 if (ret)
675 goto out_release;
676
1c2abf72 677 iwl_mvm_power_disable(mvm, vif);
8ca151b5 678
7df15b1e 679 /* beacon filtering */
bd3351ba
EP
680 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
681 if (ret)
682 goto out_remove_mac;
683
7df15b1e 684 if (!mvm->bf_allowed_vif &&
5dca7c24
HG
685 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
686 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){
7df15b1e 687 mvm->bf_allowed_vif = mvmvif;
a20fd398
AO
688 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
689 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
7df15b1e
HG
690 }
691
8ca151b5
JB
692 /*
693 * P2P_DEVICE interface does not have a channel context assigned to it,
694 * so a dedicated PHY context is allocated to it and the corresponding
695 * MAC context is bound to it at this stage.
696 */
697 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
8ca151b5 698
fe0f2de3
IP
699 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
700 if (!mvmvif->phy_ctxt) {
701 ret = -ENOSPC;
bd3351ba 702 goto out_free_bf;
fe0f2de3 703 }
8ca151b5 704
53a9d61e 705 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
8ca151b5
JB
706 ret = iwl_mvm_binding_add_vif(mvm, vif);
707 if (ret)
53a9d61e 708 goto out_unref_phy;
8ca151b5
JB
709
710 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
711 if (ret)
712 goto out_unbind;
713
714 /* Save a pointer to p2p device vif, so it can later be used to
715 * update the p2p device MAC when a GO is started/stopped */
716 mvm->p2p_device_vif = vif;
717 }
718
63494374 719 iwl_mvm_vif_dbgfs_register(mvm, vif);
8ca151b5
JB
720 goto out_unlock;
721
722 out_unbind:
723 iwl_mvm_binding_remove_vif(mvm, vif);
53a9d61e 724 out_unref_phy:
fe0f2de3 725 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
bd3351ba
EP
726 out_free_bf:
727 if (mvm->bf_allowed_vif == mvmvif) {
728 mvm->bf_allowed_vif = NULL;
a20fd398
AO
729 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
730 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
bd3351ba 731 }
8ca151b5
JB
732 out_remove_mac:
733 mvmvif->phy_ctxt = NULL;
734 iwl_mvm_mac_ctxt_remove(mvm, vif);
735 out_release:
5ee2b215
AB
736 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
737 mvm->vif_count--;
1c2abf72
AB
738
739 /* TODO: remove this when legacy PM will be discarded */
4bf881f5
AB
740 ieee80211_iterate_active_interfaces(
741 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
742 iwl_mvm_power_update_iterator, mvm);
1c2abf72 743
8ca151b5
JB
744 iwl_mvm_mac_ctxt_release(mvm, vif);
745 out_unlock:
746 mutex_unlock(&mvm->mutex);
747
748 return ret;
749}
750
38a12b5b
JB
751static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
752 struct ieee80211_vif *vif)
8ca151b5 753{
8ca151b5
JB
754 u32 tfd_msk = 0, ac;
755
756 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
757 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
758 tfd_msk |= BIT(vif->hw_queue[ac]);
759
760 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
761 tfd_msk |= BIT(vif->cab_queue);
762
763 if (tfd_msk) {
764 mutex_lock(&mvm->mutex);
765 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
766 mutex_unlock(&mvm->mutex);
767 }
768
769 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
770 /*
771 * Flush the ROC worker which will flush the OFFCHANNEL queue.
772 * We assume here that all the packets sent to the OFFCHANNEL
773 * queue are sent in ROC session.
774 */
775 flush_work(&mvm->roc_done_wk);
776 } else {
777 /*
778 * By now, all the AC queues are empty. The AGG queues are
779 * empty too. We already got all the Tx responses for all the
780 * packets in the queues. The drain work can have been
0742a75a 781 * triggered. Flush it.
8ca151b5
JB
782 */
783 flush_work(&mvm->sta_drained_wk);
784 }
38a12b5b
JB
785}
786
787static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
788 struct ieee80211_vif *vif)
789{
790 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
791 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
792
793 iwl_mvm_prepare_mac_removal(mvm, vif);
8ca151b5
JB
794
795 mutex_lock(&mvm->mutex);
796
7df15b1e
HG
797 if (mvm->bf_allowed_vif == mvmvif) {
798 mvm->bf_allowed_vif = NULL;
a20fd398
AO
799 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
800 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
7df15b1e
HG
801 }
802
63494374
JB
803 iwl_mvm_vif_dbgfs_clean(mvm, vif);
804
8ca151b5
JB
805 /*
806 * For AP/GO interface, the tear down of the resources allocated to the
38a12b5b 807 * interface is be handled as part of the stop_ap flow.
8ca151b5 808 */
5023d966
JB
809 if (vif->type == NL80211_IFTYPE_AP ||
810 vif->type == NL80211_IFTYPE_ADHOC) {
507cadf2
DS
811#ifdef CONFIG_NL80211_TESTMODE
812 if (vif == mvm->noa_vif) {
813 mvm->noa_vif = NULL;
814 mvm->noa_duration = 0;
815 }
816#endif
8ca151b5
JB
817 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
818 goto out_release;
819 }
820
821 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
822 mvm->p2p_device_vif = NULL;
823 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
824 iwl_mvm_binding_remove_vif(mvm, vif);
fe0f2de3 825 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
8ca151b5
JB
826 mvmvif->phy_ctxt = NULL;
827 }
828
5ee2b215 829 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
8ca151b5 830 mvm->vif_count--;
1c2abf72
AB
831
832 /* TODO: remove this when legacy PM will be discarded */
833 ieee80211_iterate_active_interfaces(
834 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
835 iwl_mvm_power_update_iterator, mvm);
8ca151b5
JB
836
837 iwl_mvm_mac_ctxt_remove(mvm, vif);
838
839out_release:
840 iwl_mvm_mac_ctxt_release(mvm, vif);
841 mutex_unlock(&mvm->mutex);
842}
843
844static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
88f2fd73 845{
8ca151b5
JB
846 return 0;
847}
848
e59647ea
EP
849struct iwl_mvm_mc_iter_data {
850 struct iwl_mvm *mvm;
851 int port_id;
852};
853
854static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
855 struct ieee80211_vif *vif)
856{
857 struct iwl_mvm_mc_iter_data *data = _data;
858 struct iwl_mvm *mvm = data->mvm;
859 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
860 int ret, len;
861
862 /* if we don't have free ports, mcast frames will be dropped */
863 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
864 return;
865
866 if (vif->type != NL80211_IFTYPE_STATION ||
867 !vif->bss_conf.assoc)
868 return;
869
870 cmd->port_id = data->port_id++;
871 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
872 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
873
874 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC, len, cmd);
875 if (ret)
876 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
877}
878
879static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
880{
881 struct iwl_mvm_mc_iter_data iter_data = {
882 .mvm = mvm,
88f2fd73
MG
883 };
884
e59647ea
EP
885 lockdep_assert_held(&mvm->mutex);
886
887 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
888 return;
889
890 ieee80211_iterate_active_interfaces(
891 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
892 iwl_mvm_mc_iface_iterator, &iter_data);
88f2fd73
MG
893}
894
e59647ea
EP
895static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
896 struct netdev_hw_addr_list *mc_list)
8ca151b5 897{
e59647ea
EP
898 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
899 struct iwl_mcast_filter_cmd *cmd;
900 struct netdev_hw_addr *addr;
901 int addr_count = netdev_hw_addr_list_count(mc_list);
902 bool pass_all = false;
903 int len;
904
905 if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) {
906 pass_all = true;
907 addr_count = 0;
908 }
909
910 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
911 cmd = kzalloc(len, GFP_ATOMIC);
912 if (!cmd)
913 return 0;
914
915 if (pass_all) {
916 cmd->pass_all = 1;
917 return (u64)(unsigned long)cmd;
918 }
919
920 netdev_hw_addr_list_for_each(addr, mc_list) {
921 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
922 cmd->count, addr->addr);
923 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
924 addr->addr, ETH_ALEN);
925 cmd->count++;
926 }
927
928 return (u64)(unsigned long)cmd;
8ca151b5
JB
929}
930
931static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
932 unsigned int changed_flags,
933 unsigned int *total_flags,
934 u64 multicast)
935{
e59647ea
EP
936 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
937 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
8ca151b5 938
e59647ea 939 mutex_lock(&mvm->mutex);
51b6b9e0 940
e59647ea
EP
941 /* replace previous configuration */
942 kfree(mvm->mcast_filter_cmd);
943 mvm->mcast_filter_cmd = cmd;
51b6b9e0 944
e59647ea
EP
945 if (!cmd)
946 goto out;
51b6b9e0 947
e59647ea
EP
948 iwl_mvm_recalc_multicast(mvm);
949out:
950 mutex_unlock(&mvm->mutex);
951 *total_flags = 0;
51b6b9e0
EG
952}
953
c87163b9
EP
954#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
955struct iwl_bcast_iter_data {
956 struct iwl_mvm *mvm;
957 struct iwl_bcast_filter_cmd *cmd;
958 u8 current_filter;
959};
960
961static void
962iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
963 const struct iwl_fw_bcast_filter *in_filter,
964 struct iwl_fw_bcast_filter *out_filter)
965{
966 struct iwl_fw_bcast_filter_attr *attr;
967 int i;
968
969 memcpy(out_filter, in_filter, sizeof(*out_filter));
970
971 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
972 attr = &out_filter->attrs[i];
973
974 if (!attr->mask)
975 break;
976
2ee8f021
EP
977 switch (attr->reserved1) {
978 case cpu_to_le16(BC_FILTER_MAGIC_IP):
979 if (vif->bss_conf.arp_addr_cnt != 1) {
980 attr->mask = 0;
981 continue;
982 }
983
984 attr->val = vif->bss_conf.arp_addr_list[0];
985 break;
986 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
987 attr->val = *(__be32 *)&vif->addr[2];
988 break;
989 default:
990 break;
991 }
992 attr->reserved1 = 0;
c87163b9
EP
993 out_filter->num_attrs++;
994 }
995}
996
997static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
998 struct ieee80211_vif *vif)
999{
1000 struct iwl_bcast_iter_data *data = _data;
1001 struct iwl_mvm *mvm = data->mvm;
1002 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1003 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1004 struct iwl_fw_bcast_mac *bcast_mac;
1005 int i;
1006
1007 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1008 return;
1009
1010 bcast_mac = &cmd->macs[mvmvif->id];
1011
1012 /* enable filtering only for associated stations */
1013 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
1014 return;
1015
1016 bcast_mac->default_discard = 1;
1017
1018 /* copy all configured filters */
1019 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1020 /*
1021 * Make sure we don't exceed our filters limit.
1022 * if there is still a valid filter to be configured,
1023 * be on the safe side and just allow bcast for this mac.
1024 */
1025 if (WARN_ON_ONCE(data->current_filter >=
1026 ARRAY_SIZE(cmd->filters))) {
1027 bcast_mac->default_discard = 0;
1028 bcast_mac->attached_filters = 0;
1029 break;
1030 }
1031
1032 iwl_mvm_set_bcast_filter(vif,
1033 &mvm->bcast_filters[i],
1034 &cmd->filters[data->current_filter]);
1035
1036 /* skip current filter if it contains no attributes */
1037 if (!cmd->filters[data->current_filter].num_attrs)
1038 continue;
1039
1040 /* attach the filter to current mac */
1041 bcast_mac->attached_filters |=
1042 cpu_to_le16(BIT(data->current_filter));
1043
1044 data->current_filter++;
1045 }
1046}
1047
de06a59e
EP
1048bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1049 struct iwl_bcast_filter_cmd *cmd)
c87163b9 1050{
c87163b9
EP
1051 struct iwl_bcast_iter_data iter_data = {
1052 .mvm = mvm,
de06a59e 1053 .cmd = cmd,
c87163b9
EP
1054 };
1055
de06a59e
EP
1056 memset(cmd, 0, sizeof(*cmd));
1057 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1058 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1059
1060#ifdef CONFIG_IWLWIFI_DEBUGFS
1061 /* use debugfs filters/macs if override is configured */
1062 if (mvm->dbgfs_bcast_filtering.override) {
1063 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1064 sizeof(cmd->filters));
1065 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1066 sizeof(cmd->macs));
1067 return true;
1068 }
1069#endif
c87163b9
EP
1070
1071 /* if no filters are configured, do nothing */
1072 if (!mvm->bcast_filters)
de06a59e 1073 return false;
c87163b9
EP
1074
1075 /* configure and attach these filters for each associated sta vif */
1076 ieee80211_iterate_active_interfaces(
1077 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1078 iwl_mvm_bcast_filter_iterator, &iter_data);
1079
de06a59e
EP
1080 return true;
1081}
1082static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1083 struct ieee80211_vif *vif)
1084{
1085 struct iwl_bcast_filter_cmd cmd;
1086
1087 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1088 return 0;
1089
1090 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1091 return 0;
1092
c87163b9
EP
1093 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, CMD_SYNC,
1094 sizeof(cmd), &cmd);
1095}
1096#else
1097static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1098 struct ieee80211_vif *vif)
1099{
1100 return 0;
1101}
1102#endif
1103
8ca151b5
JB
1104static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1105 struct ieee80211_vif *vif,
1106 struct ieee80211_bss_conf *bss_conf,
1107 u32 changes)
1108{
1109 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1110 int ret;
1111
6e97b0d2
IP
1112 /*
1113 * Re-calculate the tsf id, as the master-slave relations depend on the
1114 * beacon interval, which was not known when the station interface was
1115 * added.
1116 */
1117 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1118 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1119
8ca151b5
JB
1120 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1121 if (ret)
1122 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1123
1124 if (changes & BSS_CHANGED_ASSOC) {
1125 if (bss_conf->assoc) {
1126 /* add quota for this interface */
1127 ret = iwl_mvm_update_quotas(mvm, vif);
1128 if (ret) {
1129 IWL_ERR(mvm, "failed to update quotas\n");
1130 return;
1131 }
016d27e1
JB
1132
1133 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1134 &mvm->status)) {
1135 /*
1136 * If we're restarting then the firmware will
1137 * obviously have lost synchronisation with
1138 * the AP. It will attempt to synchronise by
1139 * itself, but we can make it more reliable by
1140 * scheduling a session protection time event.
1141 *
1142 * The firmware needs to receive a beacon to
1143 * catch up with synchronisation, use 110% of
1144 * the beacon interval.
1145 *
1146 * Set a large maximum delay to allow for more
1147 * than a single interface.
1148 */
1149 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1150 iwl_mvm_protect_session(mvm, vif, dur, dur,
1151 5 * dur);
1152 }
1f3b0ff8
LE
1153
1154 iwl_mvm_sf_update(mvm, vif, false);
175a70b7 1155 iwl_mvm_power_vif_assoc(mvm, vif);
8ca151b5 1156 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1f3b0ff8
LE
1157 /*
1158 * If update fails - SF might be running in associated
1159 * mode while disassociated - which is forbidden.
1160 */
1161 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1162 "Failed to update SF upon disassociation\n");
1163
8ca151b5
JB
1164 /* remove AP station now that the MAC is unassoc */
1165 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1166 if (ret)
1167 IWL_ERR(mvm, "failed to remove AP station\n");
1168 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1169 /* remove quota for this interface */
1170 ret = iwl_mvm_update_quotas(mvm, NULL);
1171 if (ret)
1172 IWL_ERR(mvm, "failed to update quotas\n");
1173 }
a20fd398 1174
e59647ea 1175 iwl_mvm_recalc_multicast(mvm);
c87163b9 1176 iwl_mvm_configure_bcast_filter(mvm, vif);
e59647ea 1177
a20fd398
AO
1178 /* reset rssi values */
1179 mvmvif->bf_data.ave_beacon_signal = 0;
1180
e8e626ad
AB
1181 if (!(mvm->fw->ucode_capa.flags &
1182 IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT)) {
e811ada7
AB
1183 /* Workaround for FW bug, otherwise FW disables device
1184 * power save upon disassociation
1185 */
1186 ret = iwl_mvm_power_update_mode(mvm, vif);
1187 if (ret)
1188 IWL_ERR(mvm, "failed to update power mode\n");
1189 }
8e484f0b 1190 iwl_mvm_bt_coex_vif_change(mvm);
f94045ed
EG
1191 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1192 IEEE80211_SMPS_AUTOMATIC);
989c6505 1193 } else if (changes & BSS_CHANGED_BEACON_INFO) {
210a544e
JB
1194 /*
1195 * We received a beacon _after_ association so
1196 * remove the session protection.
1197 */
1198 iwl_mvm_remove_time_event(mvm, mvmvif,
1199 &mvmvif->time_event_data);
51498cf6
AB
1200 } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS |
1201 BSS_CHANGED_QOS)) {
4bf881f5
AB
1202 ret = iwl_mvm_power_update_mode(mvm, vif);
1203 if (ret)
1204 IWL_ERR(mvm, "failed to update power mode\n");
8ca151b5 1205 }
88f2fd73
MG
1206 if (changes & BSS_CHANGED_TXPOWER) {
1207 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1208 bss_conf->txpower);
1209 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1210 }
a20fd398
AO
1211
1212 if (changes & BSS_CHANGED_CQM) {
1213 IWL_DEBUG_MAC80211(mvm, "cqm info_changed");
1214 /* reset cqm events tracking */
1215 mvmvif->bf_data.last_cqm_event = 0;
1216 ret = iwl_mvm_update_beacon_filter(mvm, vif);
1217 if (ret)
1218 IWL_ERR(mvm, "failed to update CQM thresholds\n");
1219 }
2ee8f021
EP
1220
1221 if (changes & BSS_CHANGED_ARP_FILTER) {
1222 IWL_DEBUG_MAC80211(mvm, "arp filter changed");
1223 iwl_mvm_configure_bcast_filter(mvm, vif);
1224 }
8ca151b5
JB
1225}
1226
5023d966
JB
1227static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1228 struct ieee80211_vif *vif)
8ca151b5
JB
1229{
1230 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1231 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1232 int ret;
1233
1234 mutex_lock(&mvm->mutex);
1235
1236 /* Send the beacon template */
1237 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1238 if (ret)
1239 goto out_unlock;
1240
6e97b0d2
IP
1241 /*
1242 * Re-calculate the tsf id, as the master-slave relations depend on the
1243 * beacon interval, which was not known when the AP interface was added.
1244 */
1245 if (vif->type == NL80211_IFTYPE_AP)
1246 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1247
8ca151b5
JB
1248 /* Add the mac context */
1249 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1250 if (ret)
1251 goto out_unlock;
1252
1253 /* Perform the binding */
1254 ret = iwl_mvm_binding_add_vif(mvm, vif);
1255 if (ret)
1256 goto out_remove;
1257
5023d966 1258 mvmvif->ap_ibss_active = true;
8ca151b5
JB
1259
1260 /* Send the bcast station. At this stage the TBTT and DTIM time events
1261 * are added and applied to the scheduler */
1262 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
1263 if (ret)
1264 goto out_unbind;
1265
5691e218
IP
1266 /* must be set before quota calculations */
1267 mvmvif->ap_ibss_active = true;
1268
a11e144e
IP
1269 /* power updated needs to be done before quotas */
1270 mvm->bound_vif_cnt++;
1271 iwl_mvm_power_update_binding(mvm, vif, true);
1272
8ca151b5
JB
1273 ret = iwl_mvm_update_quotas(mvm, vif);
1274 if (ret)
a11e144e 1275 goto out_quota_failed;
8ca151b5 1276
5023d966 1277 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
8ca151b5
JB
1278 if (vif->p2p && mvm->p2p_device_vif)
1279 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1280
8e484f0b 1281 iwl_mvm_bt_coex_vif_change(mvm);
dac94da8 1282
8ca151b5
JB
1283 mutex_unlock(&mvm->mutex);
1284 return 0;
1285
a11e144e
IP
1286out_quota_failed:
1287 mvm->bound_vif_cnt--;
1288 iwl_mvm_power_update_binding(mvm, vif, false);
5691e218 1289 mvmvif->ap_ibss_active = false;
8ca151b5
JB
1290 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1291out_unbind:
1292 iwl_mvm_binding_remove_vif(mvm, vif);
1293out_remove:
1294 iwl_mvm_mac_ctxt_remove(mvm, vif);
1295out_unlock:
1296 mutex_unlock(&mvm->mutex);
1297 return ret;
1298}
1299
5023d966
JB
1300static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
1301 struct ieee80211_vif *vif)
8ca151b5
JB
1302{
1303 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1304 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1305
38a12b5b
JB
1306 iwl_mvm_prepare_mac_removal(mvm, vif);
1307
8ca151b5
JB
1308 mutex_lock(&mvm->mutex);
1309
5023d966 1310 mvmvif->ap_ibss_active = false;
8ca151b5 1311
8e484f0b 1312 iwl_mvm_bt_coex_vif_change(mvm);
dac94da8 1313
5023d966 1314 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
8ca151b5
JB
1315 if (vif->p2p && mvm->p2p_device_vif)
1316 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1317
1318 iwl_mvm_update_quotas(mvm, NULL);
1319 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1320 iwl_mvm_binding_remove_vif(mvm, vif);
a11e144e
IP
1321
1322 mvm->bound_vif_cnt--;
1323 iwl_mvm_power_update_binding(mvm, vif, false);
1324
8ca151b5
JB
1325 iwl_mvm_mac_ctxt_remove(mvm, vif);
1326
1327 mutex_unlock(&mvm->mutex);
1328}
1329
5023d966
JB
1330static void
1331iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
1332 struct ieee80211_vif *vif,
1333 struct ieee80211_bss_conf *bss_conf,
1334 u32 changes)
8ca151b5 1335{
be2056fc 1336 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8a5e3660
AA
1337 enum ieee80211_bss_change ht_change = BSS_CHANGED_ERP_CTS_PROT |
1338 BSS_CHANGED_HT |
1339 BSS_CHANGED_BANDWIDTH;
1340 int ret;
1341
be2056fc
IP
1342 /* Changes will be applied when the AP/IBSS is started */
1343 if (!mvmvif->ap_ibss_active)
1344 return;
1345
8a5e3660
AA
1346 if (changes & ht_change) {
1347 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1348 if (ret)
1349 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1350 }
1351
8ca151b5
JB
1352 /* Need to send a new beacon template to the FW */
1353 if (changes & BSS_CHANGED_BEACON) {
1354 if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1355 IWL_WARN(mvm, "Failed updating beacon data\n");
1356 }
1357}
1358
1359static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1360 struct ieee80211_vif *vif,
1361 struct ieee80211_bss_conf *bss_conf,
1362 u32 changes)
1363{
1364 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1365
1366 mutex_lock(&mvm->mutex);
1367
1368 switch (vif->type) {
1369 case NL80211_IFTYPE_STATION:
1370 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1371 break;
1372 case NL80211_IFTYPE_AP:
5023d966
JB
1373 case NL80211_IFTYPE_ADHOC:
1374 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
8ca151b5
JB
1375 break;
1376 default:
1377 /* shouldn't happen */
1378 WARN_ON_ONCE(1);
1379 }
1380
1381 mutex_unlock(&mvm->mutex);
1382}
1383
1384static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
1385 struct ieee80211_vif *vif,
1386 struct cfg80211_scan_request *req)
1387{
1388 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1389 int ret;
1390
1391 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
1392 return -EINVAL;
1393
1394 mutex_lock(&mvm->mutex);
1395
1396 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
1397 ret = iwl_mvm_scan_request(mvm, vif, req);
1398 else
1399 ret = -EBUSY;
1400
1401 mutex_unlock(&mvm->mutex);
1402
1403 return ret;
1404}
1405
1406static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1407 struct ieee80211_vif *vif)
1408{
1409 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1410
1411 mutex_lock(&mvm->mutex);
1412
1413 iwl_mvm_cancel_scan(mvm);
1414
1415 mutex_unlock(&mvm->mutex);
1416}
1417
1418static void
1419iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
3e56eadf 1420 struct ieee80211_sta *sta, u16 tids,
8ca151b5
JB
1421 int num_frames,
1422 enum ieee80211_frame_release_type reason,
1423 bool more_data)
1424{
1425 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
8ca151b5 1426
3e56eadf 1427 /* Called when we need to transmit (a) frame(s) from mac80211 */
8ca151b5 1428
3e56eadf
JB
1429 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1430 tids, more_data, false);
1431}
1432
1433static void
1434iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
1435 struct ieee80211_sta *sta, u16 tids,
1436 int num_frames,
1437 enum ieee80211_frame_release_type reason,
1438 bool more_data)
1439{
1440 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1441
1442 /* Called when we need to transmit (a) frame(s) from agg queue */
1443
1444 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1445 tids, more_data, true);
8ca151b5
JB
1446}
1447
1448static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1449 struct ieee80211_vif *vif,
1450 enum sta_notify_cmd cmd,
1451 struct ieee80211_sta *sta)
1452{
1453 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5b577a90 1454 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3e56eadf 1455 int tid;
8ca151b5
JB
1456
1457 switch (cmd) {
1458 case STA_NOTIFY_SLEEP:
e3d4bc8c 1459 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
8ca151b5 1460 ieee80211_sta_block_awake(hw, sta, true);
3e56eadf
JB
1461 spin_lock_bh(&mvmsta->lock);
1462 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
1463 struct iwl_mvm_tid_data *tid_data;
1464
1465 tid_data = &mvmsta->tid_data[tid];
1466 if (tid_data->state != IWL_AGG_ON &&
1467 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
1468 continue;
1469 if (iwl_mvm_tid_queued(tid_data) == 0)
1470 continue;
1471 ieee80211_sta_set_buffered(sta, tid, true);
1472 }
1473 spin_unlock_bh(&mvmsta->lock);
8ca151b5
JB
1474 /*
1475 * The fw updates the STA to be asleep. Tx packets on the Tx
1476 * queues to this station will not be transmitted. The fw will
1477 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1478 */
1479 break;
1480 case STA_NOTIFY_AWAKE:
881acd89 1481 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
8ca151b5 1482 break;
9cc40712 1483 iwl_mvm_sta_modify_ps_wake(mvm, sta);
8ca151b5
JB
1484 break;
1485 default:
1486 break;
1487 }
1488}
1489
1ddbbb0c
JB
1490static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
1491 struct ieee80211_vif *vif,
1492 struct ieee80211_sta *sta)
1493{
1494 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1495 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1496
1497 /*
1498 * This is called before mac80211 does RCU synchronisation,
1499 * so here we already invalidate our internal RCU-protected
1500 * station pointer. The rest of the code will thus no longer
1501 * be able to find the station this way, and we don't rely
1502 * on further RCU synchronisation after the sta_state()
1503 * callback deleted the station.
1504 */
1505 mutex_lock(&mvm->mutex);
1506 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
1507 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1508 ERR_PTR(-ENOENT));
1509 mutex_unlock(&mvm->mutex);
1510}
1511
8ca151b5
JB
1512static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1513 struct ieee80211_vif *vif,
1514 struct ieee80211_sta *sta,
1515 enum ieee80211_sta_state old_state,
1516 enum ieee80211_sta_state new_state)
1517{
1518 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1519 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1520 int ret;
1521
1522 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1523 sta->addr, old_state, new_state);
1524
1525 /* this would be a mac80211 bug ... but don't crash */
1526 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1527 return -EINVAL;
1528
1529 /* if a STA is being removed, reuse its ID */
1530 flush_work(&mvm->sta_drained_wk);
1531
1532 mutex_lock(&mvm->mutex);
1533 if (old_state == IEEE80211_STA_NOTEXIST &&
1534 new_state == IEEE80211_STA_NONE) {
48bc1307
JB
1535 /*
1536 * Firmware bug - it'll crash if the beacon interval is less
1537 * than 16. We can't avoid connecting at all, so refuse the
1538 * station state change, this will cause mac80211 to abandon
1539 * attempts to connect to this AP, and eventually wpa_s will
1540 * blacklist the AP...
1541 */
1542 if (vif->type == NL80211_IFTYPE_STATION &&
1543 vif->bss_conf.beacon_int < 16) {
1544 IWL_ERR(mvm,
1545 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1546 sta->addr, vif->bss_conf.beacon_int);
1547 ret = -EINVAL;
1548 goto out_unlock;
1549 }
8ca151b5
JB
1550 ret = iwl_mvm_add_sta(mvm, vif, sta);
1551 } else if (old_state == IEEE80211_STA_NONE &&
1552 new_state == IEEE80211_STA_AUTH) {
1553 ret = 0;
1554 } else if (old_state == IEEE80211_STA_AUTH &&
1555 new_state == IEEE80211_STA_ASSOC) {
7a453973
JB
1556 ret = iwl_mvm_update_sta(mvm, vif, sta);
1557 if (ret == 0)
1558 iwl_mvm_rs_rate_init(mvm, sta,
b87c2179
ES
1559 mvmvif->phy_ctxt->channel->band,
1560 true);
8ca151b5
JB
1561 } else if (old_state == IEEE80211_STA_ASSOC &&
1562 new_state == IEEE80211_STA_AUTHORIZED) {
7df15b1e
HG
1563 /* enable beacon filtering */
1564 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
8ca151b5
JB
1565 ret = 0;
1566 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1567 new_state == IEEE80211_STA_ASSOC) {
7df15b1e
HG
1568 /* disable beacon filtering */
1569 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
8ca151b5
JB
1570 ret = 0;
1571 } else if (old_state == IEEE80211_STA_ASSOC &&
1572 new_state == IEEE80211_STA_AUTH) {
1573 ret = 0;
1574 } else if (old_state == IEEE80211_STA_AUTH &&
1575 new_state == IEEE80211_STA_NONE) {
1576 ret = 0;
1577 } else if (old_state == IEEE80211_STA_NONE &&
1578 new_state == IEEE80211_STA_NOTEXIST) {
1579 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1580 } else {
1581 ret = -EIO;
1582 }
48bc1307 1583 out_unlock:
8ca151b5
JB
1584 mutex_unlock(&mvm->mutex);
1585
1586 return ret;
1587}
1588
1589static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1590{
1591 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1592
1593 mvm->rts_threshold = value;
1594
1595 return 0;
1596}
1597
1f3b0ff8
LE
1598static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
1599 struct ieee80211_vif *vif,
1600 struct ieee80211_sta *sta, u32 changed)
1601{
1602 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1603
1604 if (vif->type == NL80211_IFTYPE_STATION &&
1605 changed & IEEE80211_RC_NSS_CHANGED)
1606 iwl_mvm_sf_update(mvm, vif, false);
1607}
1608
8ca151b5
JB
1609static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1610 struct ieee80211_vif *vif, u16 ac,
1611 const struct ieee80211_tx_queue_params *params)
1612{
1613 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1614 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1615
1616 mvmvif->queue_params[ac] = *params;
1617
1618 /*
1619 * No need to update right away, we'll get BSS_CHANGED_QOS
1620 * The exception is P2P_DEVICE interface which needs immediate update.
1621 */
1622 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1623 int ret;
1624
1625 mutex_lock(&mvm->mutex);
1626 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1627 mutex_unlock(&mvm->mutex);
1628 return ret;
1629 }
1630 return 0;
1631}
1632
1633static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1634 struct ieee80211_vif *vif)
1635{
1636 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1637 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1638 200 + vif->bss_conf.beacon_int);
1639 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1640 100 + vif->bss_conf.beacon_int);
1641
1642 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1643 return;
1644
1645 mutex_lock(&mvm->mutex);
1646 /* Try really hard to protect the session and hear a beacon */
016d27e1 1647 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
8ca151b5
JB
1648 mutex_unlock(&mvm->mutex);
1649}
1650
35a000b7
DS
1651static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
1652 struct ieee80211_vif *vif,
1653 struct cfg80211_sched_scan_request *req,
1654 struct ieee80211_sched_scan_ies *ies)
1655{
1656 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1657 int ret;
1658
1659 mutex_lock(&mvm->mutex);
1660
1661 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
1662 IWL_DEBUG_SCAN(mvm,
1663 "SCHED SCAN request during internal scan - abort\n");
1664 ret = -EBUSY;
1665 goto out;
1666 }
1667
1668 mvm->scan_status = IWL_MVM_SCAN_SCHED;
1669
1670 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
1671 if (ret)
1672 goto err;
1673
1674 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1675 if (ret)
1676 goto err;
1677
1678 ret = iwl_mvm_sched_scan_start(mvm, req);
1679 if (!ret)
1680 goto out;
1681err:
1682 mvm->scan_status = IWL_MVM_SCAN_NONE;
1683out:
1684 mutex_unlock(&mvm->mutex);
1685 return ret;
1686}
1687
1688static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
1689 struct ieee80211_vif *vif)
1690{
1691 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1692
1693 mutex_lock(&mvm->mutex);
1694 iwl_mvm_sched_scan_stop(mvm);
1695 mutex_unlock(&mvm->mutex);
1696}
1697
8ca151b5
JB
1698static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1699 enum set_key_cmd cmd,
1700 struct ieee80211_vif *vif,
1701 struct ieee80211_sta *sta,
1702 struct ieee80211_key_conf *key)
1703{
1704 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1705 int ret;
1706
1707 if (iwlwifi_mod_params.sw_crypto) {
1708 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1709 return -EOPNOTSUPP;
1710 }
1711
1712 switch (key->cipher) {
1713 case WLAN_CIPHER_SUITE_TKIP:
1714 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1715 /* fall-through */
1716 case WLAN_CIPHER_SUITE_CCMP:
1717 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1718 break;
1719 case WLAN_CIPHER_SUITE_AES_CMAC:
1720 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1721 break;
1722 case WLAN_CIPHER_SUITE_WEP40:
1723 case WLAN_CIPHER_SUITE_WEP104:
1724 /*
1725 * Support for TX only, at least for now, so accept
1726 * the key and do nothing else. Then mac80211 will
1727 * pass it for TX but we don't have to use it for RX.
1728 */
1729 return 0;
1730 default:
e36e5433
MS
1731 /* currently FW supports only one optional cipher scheme */
1732 if (hw->n_cipher_schemes &&
1733 hw->cipher_schemes->cipher == key->cipher)
1734 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
1735 else
1736 return -EOPNOTSUPP;
8ca151b5
JB
1737 }
1738
1739 mutex_lock(&mvm->mutex);
1740
1741 switch (cmd) {
1742 case SET_KEY:
5023d966
JB
1743 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1744 vif->type == NL80211_IFTYPE_AP) && !sta) {
1745 /*
1746 * GTK on AP interface is a TX-only key, return 0;
1747 * on IBSS they're per-station and because we're lazy
1748 * we don't support them for RX, so do the same.
1749 */
6caffd4f
JB
1750 ret = 0;
1751 key->hw_key_idx = STA_KEY_IDX_INVALID;
1752 break;
1753 }
1754
8ca151b5
JB
1755 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1756 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1757 if (ret) {
1758 IWL_WARN(mvm, "set key failed\n");
1759 /*
1760 * can't add key for RX, but we don't need it
1761 * in the device for TX so still return 0
1762 */
6caffd4f 1763 key->hw_key_idx = STA_KEY_IDX_INVALID;
8ca151b5
JB
1764 ret = 0;
1765 }
1766
1767 break;
1768 case DISABLE_KEY:
6caffd4f
JB
1769 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1770 ret = 0;
1771 break;
1772 }
1773
8ca151b5
JB
1774 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1775 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1776 break;
1777 default:
1778 ret = -EINVAL;
1779 }
1780
1781 mutex_unlock(&mvm->mutex);
1782 return ret;
1783}
1784
1785static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1786 struct ieee80211_vif *vif,
1787 struct ieee80211_key_conf *keyconf,
1788 struct ieee80211_sta *sta,
1789 u32 iv32, u16 *phase1key)
1790{
1791 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1792
5023d966
JB
1793 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
1794 return;
1795
8ca151b5
JB
1796 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1797}
1798
1799
1800static int iwl_mvm_roc(struct ieee80211_hw *hw,
1801 struct ieee80211_vif *vif,
1802 struct ieee80211_channel *channel,
d339d5ca
IP
1803 int duration,
1804 enum ieee80211_roc_type type)
8ca151b5
JB
1805{
1806 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3 1807 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8ca151b5 1808 struct cfg80211_chan_def chandef;
31d385ae
IP
1809 struct iwl_mvm_phy_ctxt *phy_ctxt;
1810 int ret, i;
1811
1812 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1813 duration, type);
8ca151b5
JB
1814
1815 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1816 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1817 return -EINVAL;
1818 }
1819
8ca151b5
JB
1820 mutex_lock(&mvm->mutex);
1821
31d385ae
IP
1822 for (i = 0; i < NUM_PHY_CTX; i++) {
1823 phy_ctxt = &mvm->phy_ctxts[i];
1824 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
1825 continue;
1826
1827 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1828 /*
1829 * Unbind the P2P_DEVICE from the current PHY context,
1830 * and if the PHY context is not used remove it.
1831 */
1832 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1833 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1834 goto out_unlock;
1835
1836 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1837
1838 /* Bind the P2P_DEVICE to the current PHY Context */
1839 mvmvif->phy_ctxt = phy_ctxt;
1840
1841 ret = iwl_mvm_binding_add_vif(mvm, vif);
1842 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1843 goto out_unlock;
1844
1845 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1846 goto schedule_time_event;
1847 }
1848 }
1849
1850 /* Need to update the PHY context only if the ROC channel changed */
1851 if (channel == mvmvif->phy_ctxt->channel)
1852 goto schedule_time_event;
1853
8ca151b5 1854 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
8ca151b5 1855
31d385ae
IP
1856 /*
1857 * Change the PHY context configuration as it is currently referenced
1858 * only by the P2P Device MAC
1859 */
1860 if (mvmvif->phy_ctxt->ref == 1) {
1861 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
1862 &chandef, 1, 1);
1863 if (ret)
1864 goto out_unlock;
1865 } else {
1866 /*
1867 * The PHY context is shared with other MACs. Need to remove the
1868 * P2P Device from the binding, allocate an new PHY context and
1869 * create a new binding
1870 */
1871 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1872 if (!phy_ctxt) {
1873 ret = -ENOSPC;
1874 goto out_unlock;
1875 }
1876
1877 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
1878 1, 1);
1879 if (ret) {
1880 IWL_ERR(mvm, "Failed to change PHY context\n");
1881 goto out_unlock;
1882 }
1883
1884 /* Unbind the P2P_DEVICE from the current PHY context */
1885 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1886 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1887 goto out_unlock;
1888
1889 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1890
1891 /* Bind the P2P_DEVICE to the new allocated PHY context */
1892 mvmvif->phy_ctxt = phy_ctxt;
1893
1894 ret = iwl_mvm_binding_add_vif(mvm, vif);
1895 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1896 goto out_unlock;
1897
1898 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1899 }
1900
1901schedule_time_event:
8ca151b5 1902 /* Schedule the time events */
e635c797 1903 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
8ca151b5 1904
31d385ae 1905out_unlock:
8ca151b5
JB
1906 mutex_unlock(&mvm->mutex);
1907 IWL_DEBUG_MAC80211(mvm, "leave\n");
8ca151b5
JB
1908 return ret;
1909}
1910
1911static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1912{
1913 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1914
1915 IWL_DEBUG_MAC80211(mvm, "enter\n");
1916
1917 mutex_lock(&mvm->mutex);
1918 iwl_mvm_stop_p2p_roc(mvm);
1919 mutex_unlock(&mvm->mutex);
1920
1921 IWL_DEBUG_MAC80211(mvm, "leave\n");
1922 return 0;
1923}
1924
1925static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1926 struct ieee80211_chanctx_conf *ctx)
1927{
1928 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3
IP
1929 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1930 struct iwl_mvm_phy_ctxt *phy_ctxt;
8ca151b5
JB
1931 int ret;
1932
53a9d61e 1933 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
fe0f2de3 1934
8ca151b5 1935 mutex_lock(&mvm->mutex);
fe0f2de3
IP
1936 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1937 if (!phy_ctxt) {
1938 ret = -ENOSPC;
1939 goto out;
1940 }
8ca151b5 1941
dcbc3e1a 1942 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
53a9d61e
IP
1943 ctx->rx_chains_static,
1944 ctx->rx_chains_dynamic);
fe0f2de3
IP
1945 if (ret) {
1946 IWL_ERR(mvm, "Failed to add PHY context\n");
1947 goto out;
1948 }
1949
53a9d61e 1950 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
fe0f2de3
IP
1951 *phy_ctxt_id = phy_ctxt->id;
1952out:
8ca151b5
JB
1953 mutex_unlock(&mvm->mutex);
1954 return ret;
1955}
1956
1957static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
1958 struct ieee80211_chanctx_conf *ctx)
1959{
1960 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3
IP
1961 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1962 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
8ca151b5
JB
1963
1964 mutex_lock(&mvm->mutex);
fe0f2de3 1965 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
8ca151b5
JB
1966 mutex_unlock(&mvm->mutex);
1967}
1968
1969static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
1970 struct ieee80211_chanctx_conf *ctx,
1971 u32 changed)
1972{
1973 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3
IP
1974 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1975 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
8ca151b5 1976
31d385ae
IP
1977 if (WARN_ONCE((phy_ctxt->ref > 1) &&
1978 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
1979 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
2dceedae
AN
1980 IEEE80211_CHANCTX_CHANGE_RADAR |
1981 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
31d385ae
IP
1982 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1983 phy_ctxt->ref, changed))
1984 return;
1985
8ca151b5 1986 mutex_lock(&mvm->mutex);
dcbc3e1a 1987 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
8ca151b5
JB
1988 ctx->rx_chains_static,
1989 ctx->rx_chains_dynamic);
8e484f0b 1990 iwl_mvm_bt_coex_vif_change(mvm);
8ca151b5
JB
1991 mutex_unlock(&mvm->mutex);
1992}
1993
1994static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
1995 struct ieee80211_vif *vif,
1996 struct ieee80211_chanctx_conf *ctx)
1997{
1998 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3
IP
1999 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2000 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
8ca151b5
JB
2001 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2002 int ret;
2003
2004 mutex_lock(&mvm->mutex);
2005
fe0f2de3 2006 mvmvif->phy_ctxt = phy_ctxt;
8ca151b5
JB
2007
2008 switch (vif->type) {
2009 case NL80211_IFTYPE_AP:
5023d966 2010 case NL80211_IFTYPE_ADHOC:
8ca151b5
JB
2011 /*
2012 * The AP binding flow is handled as part of the start_ap flow
5023d966 2013 * (in bss_info_changed), similarly for IBSS.
8ca151b5
JB
2014 */
2015 ret = 0;
2016 goto out_unlock;
2017 case NL80211_IFTYPE_STATION:
8ca151b5
JB
2018 case NL80211_IFTYPE_MONITOR:
2019 break;
2020 default:
2021 ret = -EINVAL;
2022 goto out_unlock;
2023 }
2024
2025 ret = iwl_mvm_binding_add_vif(mvm, vif);
2026 if (ret)
2027 goto out_unlock;
2028
2029 /*
92d85562
AB
2030 * Power state must be updated before quotas,
2031 * otherwise fw will complain.
2032 */
2033 mvm->bound_vif_cnt++;
2034 iwl_mvm_power_update_binding(mvm, vif, true);
2035
2036 /* Setting the quota at this stage is only required for monitor
8ca151b5
JB
2037 * interfaces. For the other types, the bss_info changed flow
2038 * will handle quota settings.
2039 */
2040 if (vif->type == NL80211_IFTYPE_MONITOR) {
1e1391ca 2041 mvmvif->monitor_active = true;
8ca151b5
JB
2042 ret = iwl_mvm_update_quotas(mvm, vif);
2043 if (ret)
2044 goto out_remove_binding;
2045 }
2046
2047 goto out_unlock;
2048
2049 out_remove_binding:
2050 iwl_mvm_binding_remove_vif(mvm, vif);
92d85562
AB
2051 mvm->bound_vif_cnt--;
2052 iwl_mvm_power_update_binding(mvm, vif, false);
8ca151b5
JB
2053 out_unlock:
2054 mutex_unlock(&mvm->mutex);
2055 if (ret)
2056 mvmvif->phy_ctxt = NULL;
2057 return ret;
2058}
2059
2060static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
2061 struct ieee80211_vif *vif,
2062 struct ieee80211_chanctx_conf *ctx)
2063{
2064 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2065 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2066
2067 mutex_lock(&mvm->mutex);
2068
2069 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
2070
8ca151b5 2071 switch (vif->type) {
5023d966
JB
2072 case NL80211_IFTYPE_AP:
2073 case NL80211_IFTYPE_ADHOC:
2074 goto out_unlock;
8ca151b5 2075 case NL80211_IFTYPE_MONITOR:
1e1391ca
IP
2076 mvmvif->monitor_active = false;
2077 iwl_mvm_update_quotas(mvm, NULL);
8ca151b5
JB
2078 break;
2079 default:
2080 break;
2081 }
2082
1e1391ca 2083 iwl_mvm_binding_remove_vif(mvm, vif);
1c2abf72 2084 mvm->bound_vif_cnt--;
92d85562 2085 iwl_mvm_power_update_binding(mvm, vif, false);
1c2abf72 2086
a11e144e
IP
2087out_unlock:
2088 mvmvif->phy_ctxt = NULL;
8ca151b5
JB
2089 mutex_unlock(&mvm->mutex);
2090}
2091
2092static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
2093 struct ieee80211_sta *sta,
2094 bool set)
2095{
2096 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2097 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
2098
2099 if (!mvm_sta || !mvm_sta->vif) {
2100 IWL_ERR(mvm, "Station is not associated to a vif\n");
2101 return -EINVAL;
2102 }
2103
2104 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
2105}
2106
507cadf2
DS
2107#ifdef CONFIG_NL80211_TESTMODE
2108static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
2109 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
2110 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
f6c6ad42 2111 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
507cadf2
DS
2112};
2113
2114static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
2115 struct ieee80211_vif *vif,
2116 void *data, int len)
2117{
2118 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
2119 int err;
2120 u32 noa_duration;
2121
2122 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
2123 if (err)
2124 return err;
2125
2126 if (!tb[IWL_MVM_TM_ATTR_CMD])
2127 return -EINVAL;
2128
2129 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
2130 case IWL_MVM_TM_CMD_SET_NOA:
2131 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
2132 !vif->bss_conf.enable_beacon ||
2133 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
2134 return -EINVAL;
2135
2136 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
2137 if (noa_duration >= vif->bss_conf.beacon_int)
2138 return -EINVAL;
2139
2140 mvm->noa_duration = noa_duration;
2141 mvm->noa_vif = vif;
2142
2143 return iwl_mvm_update_quotas(mvm, NULL);
f6c6ad42
JB
2144 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
2145 /* must be associated client vif - ignore authorized */
2146 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
2147 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
2148 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
2149 return -EINVAL;
2150
2151 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
2152 return iwl_mvm_enable_beacon_filter(mvm, vif);
2153 return iwl_mvm_disable_beacon_filter(mvm, vif);
507cadf2
DS
2154 }
2155
2156 return -EOPNOTSUPP;
2157}
2158
2159static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
2160 struct ieee80211_vif *vif,
2161 void *data, int len)
2162{
2163 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2164 int err;
2165
2166 mutex_lock(&mvm->mutex);
2167 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
2168 mutex_unlock(&mvm->mutex);
2169
2170 return err;
2171}
2172#endif
2173
8ca151b5
JB
2174struct ieee80211_ops iwl_mvm_hw_ops = {
2175 .tx = iwl_mvm_mac_tx,
2176 .ampdu_action = iwl_mvm_mac_ampdu_action,
2177 .start = iwl_mvm_mac_start,
2178 .restart_complete = iwl_mvm_mac_restart_complete,
2179 .stop = iwl_mvm_mac_stop,
2180 .add_interface = iwl_mvm_mac_add_interface,
2181 .remove_interface = iwl_mvm_mac_remove_interface,
2182 .config = iwl_mvm_mac_config,
e59647ea 2183 .prepare_multicast = iwl_mvm_prepare_multicast,
8ca151b5
JB
2184 .configure_filter = iwl_mvm_configure_filter,
2185 .bss_info_changed = iwl_mvm_bss_info_changed,
2186 .hw_scan = iwl_mvm_mac_hw_scan,
2187 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1ddbbb0c 2188 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
8ca151b5
JB
2189 .sta_state = iwl_mvm_mac_sta_state,
2190 .sta_notify = iwl_mvm_mac_sta_notify,
2191 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
3e56eadf 2192 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
8ca151b5 2193 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1f3b0ff8 2194 .sta_rc_update = iwl_mvm_sta_rc_update,
8ca151b5
JB
2195 .conf_tx = iwl_mvm_mac_conf_tx,
2196 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
35a000b7
DS
2197 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
2198 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
8ca151b5
JB
2199 .set_key = iwl_mvm_mac_set_key,
2200 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
2201 .remain_on_channel = iwl_mvm_roc,
2202 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
8ca151b5
JB
2203 .add_chanctx = iwl_mvm_add_chanctx,
2204 .remove_chanctx = iwl_mvm_remove_chanctx,
2205 .change_chanctx = iwl_mvm_change_chanctx,
2206 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
2207 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
2208
5023d966
JB
2209 .start_ap = iwl_mvm_start_ap_ibss,
2210 .stop_ap = iwl_mvm_stop_ap_ibss,
2211 .join_ibss = iwl_mvm_start_ap_ibss,
2212 .leave_ibss = iwl_mvm_stop_ap_ibss,
8ca151b5
JB
2213
2214 .set_tim = iwl_mvm_set_tim,
2215
507cadf2
DS
2216 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
2217
8ca151b5
JB
2218#ifdef CONFIG_PM_SLEEP
2219 /* look at d3.c */
2220 .suspend = iwl_mvm_suspend,
2221 .resume = iwl_mvm_resume,
2222 .set_wakeup = iwl_mvm_set_wakeup,
2223 .set_rekey_data = iwl_mvm_set_rekey_data,
2224#if IS_ENABLED(CONFIG_IPV6)
2225 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
2226#endif
2227 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
2228#endif
2229};