Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/iwlwif...
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / mvm / mac80211.c
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 *
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
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
25 * in the file called COPYING.
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 *
33 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
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>
68 #include <linux/ip.h>
69 #include <linux/if_arp.h>
70 #include <net/mac80211.h>
71 #include <net/ieee80211_radiotap.h>
72 #include <net/tcp.h>
73
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"
82 #include "testmode.h"
83
84 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
85 {
86 .max = 1,
87 .types = BIT(NL80211_IFTYPE_STATION),
88 },
89 {
90 .max = 1,
91 .types = BIT(NL80211_IFTYPE_AP) |
92 BIT(NL80211_IFTYPE_P2P_CLIENT) |
93 BIT(NL80211_IFTYPE_P2P_GO),
94 },
95 {
96 .max = 1,
97 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
98 },
99 };
100
101 static 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
110 #ifdef CONFIG_PM_SLEEP
111 static const struct nl80211_wowlan_tcp_data_token_feature
112 iwl_mvm_wowlan_tcp_token_feature = {
113 .min_len = 0,
114 .max_len = 255,
115 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
116 };
117
118 static 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
133 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
134 /*
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 */
145 enum {
146 BC_FILTER_MAGIC_NONE = 0,
147 BC_FILTER_MAGIC_IP,
148 BC_FILTER_MAGIC_MAC,
149 };
150
151 static 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 },
165 {
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 },
199 },
200 },
201 /* last filter must be empty */
202 {},
203 };
204 #endif
205
206 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
207 {
208 if (!iwl_mvm_is_d0i3_supported(mvm))
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
216 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
217 {
218 if (!iwl_mvm_is_d0i3_supported(mvm))
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
226 static void
227 iwl_mvm_unref_all_except(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref)
228 {
229 int i;
230
231 if (!iwl_mvm_is_d0i3_supported(mvm))
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
244 static 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
255 static 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
263 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
264 {
265 struct ieee80211_hw *hw = mvm->hw;
266 int num_mac, ret, i;
267
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 |
274 IEEE80211_HW_SUPPORTS_PS |
275 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
276 IEEE80211_HW_AMPDU_AGGREGATION |
277 IEEE80211_HW_TIMING_BEACON_ONLY |
278 IEEE80211_HW_CONNECTION_MONITOR |
279 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
280 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
281
282 hw->queues = mvm->first_agg_queue;
283 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
284 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;
287 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
298 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT &&
299 IWL_UCODE_API(mvm->fw->ucode_ver) >= 9 &&
300 !iwlwifi_mod_params.uapsd_disable) {
301 hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
302 hw->uapsd_queues = IWL_UAPSD_AC_INFO;
303 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
304 }
305
306 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
307 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
308 hw->chanctx_data_size = sizeof(u16);
309
310 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
311 BIT(NL80211_IFTYPE_P2P_CLIENT) |
312 BIT(NL80211_IFTYPE_AP) |
313 BIT(NL80211_IFTYPE_P2P_GO) |
314 BIT(NL80211_IFTYPE_P2P_DEVICE) |
315 BIT(NL80211_IFTYPE_ADHOC);
316
317 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
318 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
319 REGULATORY_DISABLE_BEACON_HINTS;
320
321 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
322 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
323
324 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_CSA_FLOW)
325 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
326
327 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
328 hw->wiphy->n_iface_combinations =
329 ARRAY_SIZE(iwl_mvm_iface_combinations);
330
331 hw->wiphy->max_remain_on_channel_duration = 10000;
332 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
333
334 /* Extract MAC address */
335 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
336 hw->wiphy->addresses = mvm->addresses;
337 hw->wiphy->n_addresses = 1;
338
339 /* Extract additional MAC addresses if available */
340 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
341 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
342
343 for (i = 1; i < num_mac; i++) {
344 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
345 ETH_ALEN);
346 mvm->addresses[i].addr[5]++;
347 hw->wiphy->n_addresses++;
348 }
349
350 iwl_mvm_reset_phy_ctxts(mvm);
351
352 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
353
354 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
355
356 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
357 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
358 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
359 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
360 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
361 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
362
363 hw->wiphy->hw_version = mvm->trans->hw_id;
364
365 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
366 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
367 else
368 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
369
370 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
371 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
372 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
373 /* we create the 802.11 header and zero length SSID IE. */
374 hw->wiphy->max_sched_scan_ie_len = SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
375
376 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
377 NL80211_FEATURE_LOW_PRIORITY_SCAN |
378 NL80211_FEATURE_P2P_GO_OPPPS;
379
380 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
381
382 /* currently FW API supports only one optional cipher scheme */
383 if (mvm->fw->cs[0].cipher) {
384 mvm->hw->n_cipher_schemes = 1;
385 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
386 }
387
388 #ifdef CONFIG_PM_SLEEP
389 if (iwl_mvm_is_d0i3_supported(mvm) &&
390 device_can_wakeup(mvm->trans->dev)) {
391 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
392 hw->wiphy->wowlan = &mvm->wowlan;
393 } else if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
394 mvm->trans->ops->d3_suspend &&
395 mvm->trans->ops->d3_resume &&
396 device_can_wakeup(mvm->trans->dev)) {
397 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
398 WIPHY_WOWLAN_DISCONNECT |
399 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
400 WIPHY_WOWLAN_RFKILL_RELEASE;
401 if (!iwlwifi_mod_params.sw_crypto)
402 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
403 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
404 WIPHY_WOWLAN_4WAY_HANDSHAKE;
405
406 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
407 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
408 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
409 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
410 hw->wiphy->wowlan = &mvm->wowlan;
411 }
412 #endif
413
414 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
415 /* assign default bcast filtering configuration */
416 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
417 #endif
418
419 ret = iwl_mvm_leds_init(mvm);
420 if (ret)
421 return ret;
422
423 ret = ieee80211_register_hw(mvm->hw);
424 if (ret)
425 iwl_mvm_leds_exit(mvm);
426
427 return ret;
428 }
429
430 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
431 struct ieee80211_sta *sta,
432 struct sk_buff *skb)
433 {
434 struct iwl_mvm_sta *mvmsta;
435 bool defer = false;
436
437 /*
438 * double check the IN_D0I3 flag both before and after
439 * taking the spinlock, in order to prevent taking
440 * the spinlock when not needed.
441 */
442 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
443 return false;
444
445 spin_lock(&mvm->d0i3_tx_lock);
446 /*
447 * testing the flag again ensures the skb dequeue
448 * loop (on d0i3 exit) hasn't run yet.
449 */
450 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
451 goto out;
452
453 mvmsta = iwl_mvm_sta_from_mac80211(sta);
454 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
455 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
456 goto out;
457
458 __skb_queue_tail(&mvm->d0i3_tx, skb);
459 ieee80211_stop_queues(mvm->hw);
460
461 /* trigger wakeup */
462 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
463 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
464
465 defer = true;
466 out:
467 spin_unlock(&mvm->d0i3_tx_lock);
468 return defer;
469 }
470
471 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
472 struct ieee80211_tx_control *control,
473 struct sk_buff *skb)
474 {
475 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
476 struct ieee80211_sta *sta = control->sta;
477 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
478 struct ieee80211_hdr *hdr = (void *)skb->data;
479
480 if (iwl_mvm_is_radio_killed(mvm)) {
481 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
482 goto drop;
483 }
484
485 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
486 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
487 goto drop;
488
489 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
490 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
491 ieee80211_is_mgmt(hdr->frame_control) &&
492 !ieee80211_is_deauth(hdr->frame_control) &&
493 !ieee80211_is_disassoc(hdr->frame_control) &&
494 !ieee80211_is_action(hdr->frame_control)))
495 sta = NULL;
496
497 if (sta) {
498 if (iwl_mvm_defer_tx(mvm, sta, skb))
499 return;
500 if (iwl_mvm_tx_skb(mvm, skb, sta))
501 goto drop;
502 return;
503 }
504
505 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
506 goto drop;
507 return;
508 drop:
509 ieee80211_free_txskb(hw, skb);
510 }
511
512 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
513 {
514 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
515 return false;
516 return true;
517 }
518
519 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
520 {
521 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
522 return false;
523 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
524 return true;
525
526 /* enabled by default */
527 return true;
528 }
529
530 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
531 struct ieee80211_vif *vif,
532 enum ieee80211_ampdu_mlme_action action,
533 struct ieee80211_sta *sta, u16 tid,
534 u16 *ssn, u8 buf_size)
535 {
536 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
537 int ret;
538 bool tx_agg_ref = false;
539
540 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
541 sta->addr, tid, action);
542
543 if (!(mvm->nvm_data->sku_cap_11n_enable))
544 return -EACCES;
545
546 /* return from D0i3 before starting a new Tx aggregation */
547 switch (action) {
548 case IEEE80211_AMPDU_TX_START:
549 case IEEE80211_AMPDU_TX_STOP_CONT:
550 case IEEE80211_AMPDU_TX_STOP_FLUSH:
551 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
552 case IEEE80211_AMPDU_TX_OPERATIONAL:
553 iwl_mvm_ref(mvm, IWL_MVM_REF_TX_AGG);
554 tx_agg_ref = true;
555
556 /*
557 * for tx start, wait synchronously until D0i3 exit to
558 * get the correct sequence number for the tid.
559 * additionally, some other ampdu actions use direct
560 * target access, which is not handled automatically
561 * by the trans layer (unlike commands), so wait for
562 * d0i3 exit in these cases as well.
563 */
564 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
565 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status), HZ)) {
566 WARN_ON_ONCE(1);
567 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
568 return -EIO;
569 }
570 break;
571 default:
572 break;
573 }
574
575 mutex_lock(&mvm->mutex);
576
577 switch (action) {
578 case IEEE80211_AMPDU_RX_START:
579 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
580 ret = -EINVAL;
581 break;
582 }
583 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
584 break;
585 case IEEE80211_AMPDU_RX_STOP:
586 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
587 break;
588 case IEEE80211_AMPDU_TX_START:
589 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
590 ret = -EINVAL;
591 break;
592 }
593 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
594 break;
595 case IEEE80211_AMPDU_TX_STOP_CONT:
596 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
597 break;
598 case IEEE80211_AMPDU_TX_STOP_FLUSH:
599 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
600 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
601 break;
602 case IEEE80211_AMPDU_TX_OPERATIONAL:
603 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
604 break;
605 default:
606 WARN_ON_ONCE(1);
607 ret = -EINVAL;
608 break;
609 }
610 mutex_unlock(&mvm->mutex);
611
612 /*
613 * If the tid is marked as started, we won't use it for offloaded
614 * traffic on the next D0i3 entry. It's safe to unref.
615 */
616 if (tx_agg_ref)
617 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
618
619 return ret;
620 }
621
622 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
623 struct ieee80211_vif *vif)
624 {
625 struct iwl_mvm *mvm = data;
626 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
627
628 mvmvif->uploaded = false;
629 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
630
631 /* does this make sense at all? */
632 mvmvif->color++;
633
634 spin_lock_bh(&mvm->time_event_lock);
635 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
636 spin_unlock_bh(&mvm->time_event_lock);
637
638 mvmvif->phy_ctxt = NULL;
639 }
640
641 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
642 {
643 #ifdef CONFIG_IWLWIFI_DEBUGFS
644 static char *env[] = { "DRIVER=iwlwifi", "EVENT=error_dump", NULL };
645
646 iwl_mvm_fw_error_dump(mvm);
647
648 /* notify the userspace about the error we had */
649 kobject_uevent_env(&mvm->hw->wiphy->dev.kobj, KOBJ_CHANGE, env);
650 #endif
651
652 iwl_trans_stop_device(mvm->trans);
653
654 mvm->scan_status = IWL_MVM_SCAN_NONE;
655
656 /* just in case one was running */
657 ieee80211_remain_on_channel_expired(mvm->hw);
658
659 ieee80211_iterate_active_interfaces_atomic(
660 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
661 iwl_mvm_cleanup_iterator, mvm);
662
663 mvm->p2p_device_vif = NULL;
664 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
665
666 iwl_mvm_reset_phy_ctxts(mvm);
667 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
668 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
669
670 ieee80211_wake_queues(mvm->hw);
671
672 /* cleanup all stale references (scan, roc), but keep the
673 * ucode_down ref until reconfig is complete */
674 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
675
676 mvm->vif_count = 0;
677 mvm->rx_ba_sessions = 0;
678 }
679
680 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
681 {
682 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
683 int ret;
684
685 mutex_lock(&mvm->mutex);
686
687 /* Clean up some internal and mac80211 state on restart */
688 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
689 iwl_mvm_restart_cleanup(mvm);
690
691 ret = iwl_mvm_up(mvm);
692
693 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
694 /* Something went wrong - we need to finish some cleanup
695 * that normally iwl_mvm_mac_restart_complete() below
696 * would do.
697 */
698 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
699 iwl_mvm_d0i3_enable_tx(mvm, NULL);
700 }
701
702 mutex_unlock(&mvm->mutex);
703
704 return ret;
705 }
706
707 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
708 {
709 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
710 int ret;
711
712 mutex_lock(&mvm->mutex);
713
714 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
715 iwl_mvm_d0i3_enable_tx(mvm, NULL);
716 ret = iwl_mvm_update_quotas(mvm, NULL);
717 if (ret)
718 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
719 ret);
720
721 /* allow transport/FW low power modes */
722 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
723
724 mutex_unlock(&mvm->mutex);
725 }
726
727 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
728 {
729 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
730
731 flush_work(&mvm->d0i3_exit_work);
732 flush_work(&mvm->async_handlers_wk);
733
734 mutex_lock(&mvm->mutex);
735
736 /* disallow low power states when the FW is down */
737 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
738
739 /* async_handlers_wk is now blocked */
740
741 /*
742 * The work item could be running or queued if the
743 * ROC time event stops just as we get here.
744 */
745 cancel_work_sync(&mvm->roc_done_wk);
746
747 iwl_trans_stop_device(mvm->trans);
748
749 iwl_mvm_async_handlers_purge(mvm);
750 /* async_handlers_list is empty and will stay empty: HW is stopped */
751
752 /* the fw is stopped, the aux sta is dead: clean up driver state */
753 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
754
755 mutex_unlock(&mvm->mutex);
756
757 /*
758 * The worker might have been waiting for the mutex, let it run and
759 * discover that its list is now empty.
760 */
761 cancel_work_sync(&mvm->async_handlers_wk);
762 }
763
764 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
765 {
766 u16 i;
767
768 lockdep_assert_held(&mvm->mutex);
769
770 for (i = 0; i < NUM_PHY_CTX; i++)
771 if (!mvm->phy_ctxts[i].ref)
772 return &mvm->phy_ctxts[i];
773
774 IWL_ERR(mvm, "No available PHY context\n");
775 return NULL;
776 }
777
778 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
779 s8 tx_power)
780 {
781 /* FW is in charge of regulatory enforcement */
782 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
783 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
784 .pwr_restriction = cpu_to_le16(tx_power),
785 };
786
787 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
788 sizeof(reduce_txpwr_cmd),
789 &reduce_txpwr_cmd);
790 }
791
792 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
793 struct ieee80211_vif *vif)
794 {
795 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
796 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
797 int ret;
798
799 /*
800 * Not much to do here. The stack will not allow interface
801 * types or combinations that we didn't advertise, so we
802 * don't really have to check the types.
803 */
804
805 mutex_lock(&mvm->mutex);
806
807 /* Allocate resources for the MAC context, and add it to the fw */
808 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
809 if (ret)
810 goto out_unlock;
811
812 /* Counting number of interfaces is needed for legacy PM */
813 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
814 mvm->vif_count++;
815
816 /*
817 * The AP binding flow can be done only after the beacon
818 * template is configured (which happens only in the mac80211
819 * start_ap() flow), and adding the broadcast station can happen
820 * only after the binding.
821 * In addition, since modifying the MAC before adding a bcast
822 * station is not allowed by the FW, delay the adding of MAC context to
823 * the point where we can also add the bcast station.
824 * In short: there's not much we can do at this point, other than
825 * allocating resources :)
826 */
827 if (vif->type == NL80211_IFTYPE_AP ||
828 vif->type == NL80211_IFTYPE_ADHOC) {
829 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
830 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
831 qmask,
832 ieee80211_vif_type_p2p(vif));
833 if (ret) {
834 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
835 goto out_release;
836 }
837
838 iwl_mvm_vif_dbgfs_register(mvm, vif);
839 goto out_unlock;
840 }
841
842 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
843 if (ret)
844 goto out_release;
845
846 ret = iwl_mvm_power_update_mac(mvm);
847 if (ret)
848 goto out_release;
849
850 /* beacon filtering */
851 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
852 if (ret)
853 goto out_remove_mac;
854
855 if (!mvm->bf_allowed_vif &&
856 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
857 mvm->bf_allowed_vif = mvmvif;
858 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
859 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
860 }
861
862 /*
863 * P2P_DEVICE interface does not have a channel context assigned to it,
864 * so a dedicated PHY context is allocated to it and the corresponding
865 * MAC context is bound to it at this stage.
866 */
867 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
868
869 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
870 if (!mvmvif->phy_ctxt) {
871 ret = -ENOSPC;
872 goto out_free_bf;
873 }
874
875 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
876 ret = iwl_mvm_binding_add_vif(mvm, vif);
877 if (ret)
878 goto out_unref_phy;
879
880 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
881 if (ret)
882 goto out_unbind;
883
884 /* Save a pointer to p2p device vif, so it can later be used to
885 * update the p2p device MAC when a GO is started/stopped */
886 mvm->p2p_device_vif = vif;
887 }
888
889 iwl_mvm_vif_dbgfs_register(mvm, vif);
890 goto out_unlock;
891
892 out_unbind:
893 iwl_mvm_binding_remove_vif(mvm, vif);
894 out_unref_phy:
895 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
896 out_free_bf:
897 if (mvm->bf_allowed_vif == mvmvif) {
898 mvm->bf_allowed_vif = NULL;
899 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
900 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
901 }
902 out_remove_mac:
903 mvmvif->phy_ctxt = NULL;
904 iwl_mvm_mac_ctxt_remove(mvm, vif);
905 out_release:
906 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
907 mvm->vif_count--;
908
909 iwl_mvm_mac_ctxt_release(mvm, vif);
910 out_unlock:
911 mutex_unlock(&mvm->mutex);
912
913 return ret;
914 }
915
916 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
917 struct ieee80211_vif *vif)
918 {
919 u32 tfd_msk = 0, ac;
920
921 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
922 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
923 tfd_msk |= BIT(vif->hw_queue[ac]);
924
925 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
926 tfd_msk |= BIT(vif->cab_queue);
927
928 if (tfd_msk) {
929 mutex_lock(&mvm->mutex);
930 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
931 mutex_unlock(&mvm->mutex);
932 }
933
934 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
935 /*
936 * Flush the ROC worker which will flush the OFFCHANNEL queue.
937 * We assume here that all the packets sent to the OFFCHANNEL
938 * queue are sent in ROC session.
939 */
940 flush_work(&mvm->roc_done_wk);
941 } else {
942 /*
943 * By now, all the AC queues are empty. The AGG queues are
944 * empty too. We already got all the Tx responses for all the
945 * packets in the queues. The drain work can have been
946 * triggered. Flush it.
947 */
948 flush_work(&mvm->sta_drained_wk);
949 }
950 }
951
952 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
953 struct ieee80211_vif *vif)
954 {
955 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
956 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
957
958 iwl_mvm_prepare_mac_removal(mvm, vif);
959
960 mutex_lock(&mvm->mutex);
961
962 if (mvm->bf_allowed_vif == mvmvif) {
963 mvm->bf_allowed_vif = NULL;
964 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
965 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
966 }
967
968 iwl_mvm_vif_dbgfs_clean(mvm, vif);
969
970 /*
971 * For AP/GO interface, the tear down of the resources allocated to the
972 * interface is be handled as part of the stop_ap flow.
973 */
974 if (vif->type == NL80211_IFTYPE_AP ||
975 vif->type == NL80211_IFTYPE_ADHOC) {
976 #ifdef CONFIG_NL80211_TESTMODE
977 if (vif == mvm->noa_vif) {
978 mvm->noa_vif = NULL;
979 mvm->noa_duration = 0;
980 }
981 #endif
982 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
983 goto out_release;
984 }
985
986 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
987 mvm->p2p_device_vif = NULL;
988 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
989 iwl_mvm_binding_remove_vif(mvm, vif);
990 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
991 mvmvif->phy_ctxt = NULL;
992 }
993
994 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
995 mvm->vif_count--;
996
997 iwl_mvm_power_update_mac(mvm);
998 iwl_mvm_mac_ctxt_remove(mvm, vif);
999
1000 out_release:
1001 iwl_mvm_mac_ctxt_release(mvm, vif);
1002 mutex_unlock(&mvm->mutex);
1003 }
1004
1005 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1006 {
1007 return 0;
1008 }
1009
1010 struct iwl_mvm_mc_iter_data {
1011 struct iwl_mvm *mvm;
1012 int port_id;
1013 };
1014
1015 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1016 struct ieee80211_vif *vif)
1017 {
1018 struct iwl_mvm_mc_iter_data *data = _data;
1019 struct iwl_mvm *mvm = data->mvm;
1020 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1021 int ret, len;
1022
1023 /* if we don't have free ports, mcast frames will be dropped */
1024 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1025 return;
1026
1027 if (vif->type != NL80211_IFTYPE_STATION ||
1028 !vif->bss_conf.assoc)
1029 return;
1030
1031 cmd->port_id = data->port_id++;
1032 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1033 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1034
1035 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
1036 if (ret)
1037 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1038 }
1039
1040 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1041 {
1042 struct iwl_mvm_mc_iter_data iter_data = {
1043 .mvm = mvm,
1044 };
1045
1046 lockdep_assert_held(&mvm->mutex);
1047
1048 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1049 return;
1050
1051 ieee80211_iterate_active_interfaces_atomic(
1052 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1053 iwl_mvm_mc_iface_iterator, &iter_data);
1054 }
1055
1056 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1057 struct netdev_hw_addr_list *mc_list)
1058 {
1059 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1060 struct iwl_mcast_filter_cmd *cmd;
1061 struct netdev_hw_addr *addr;
1062 int addr_count = netdev_hw_addr_list_count(mc_list);
1063 bool pass_all = false;
1064 int len;
1065
1066 if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) {
1067 pass_all = true;
1068 addr_count = 0;
1069 }
1070
1071 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1072 cmd = kzalloc(len, GFP_ATOMIC);
1073 if (!cmd)
1074 return 0;
1075
1076 if (pass_all) {
1077 cmd->pass_all = 1;
1078 return (u64)(unsigned long)cmd;
1079 }
1080
1081 netdev_hw_addr_list_for_each(addr, mc_list) {
1082 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1083 cmd->count, addr->addr);
1084 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1085 addr->addr, ETH_ALEN);
1086 cmd->count++;
1087 }
1088
1089 return (u64)(unsigned long)cmd;
1090 }
1091
1092 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1093 unsigned int changed_flags,
1094 unsigned int *total_flags,
1095 u64 multicast)
1096 {
1097 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1098 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1099
1100 mutex_lock(&mvm->mutex);
1101
1102 /* replace previous configuration */
1103 kfree(mvm->mcast_filter_cmd);
1104 mvm->mcast_filter_cmd = cmd;
1105
1106 if (!cmd)
1107 goto out;
1108
1109 iwl_mvm_recalc_multicast(mvm);
1110 out:
1111 mutex_unlock(&mvm->mutex);
1112 *total_flags = 0;
1113 }
1114
1115 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1116 struct iwl_bcast_iter_data {
1117 struct iwl_mvm *mvm;
1118 struct iwl_bcast_filter_cmd *cmd;
1119 u8 current_filter;
1120 };
1121
1122 static void
1123 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1124 const struct iwl_fw_bcast_filter *in_filter,
1125 struct iwl_fw_bcast_filter *out_filter)
1126 {
1127 struct iwl_fw_bcast_filter_attr *attr;
1128 int i;
1129
1130 memcpy(out_filter, in_filter, sizeof(*out_filter));
1131
1132 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1133 attr = &out_filter->attrs[i];
1134
1135 if (!attr->mask)
1136 break;
1137
1138 switch (attr->reserved1) {
1139 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1140 if (vif->bss_conf.arp_addr_cnt != 1) {
1141 attr->mask = 0;
1142 continue;
1143 }
1144
1145 attr->val = vif->bss_conf.arp_addr_list[0];
1146 break;
1147 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1148 attr->val = *(__be32 *)&vif->addr[2];
1149 break;
1150 default:
1151 break;
1152 }
1153 attr->reserved1 = 0;
1154 out_filter->num_attrs++;
1155 }
1156 }
1157
1158 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1159 struct ieee80211_vif *vif)
1160 {
1161 struct iwl_bcast_iter_data *data = _data;
1162 struct iwl_mvm *mvm = data->mvm;
1163 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1164 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1165 struct iwl_fw_bcast_mac *bcast_mac;
1166 int i;
1167
1168 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1169 return;
1170
1171 bcast_mac = &cmd->macs[mvmvif->id];
1172
1173 /* enable filtering only for associated stations */
1174 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
1175 return;
1176
1177 bcast_mac->default_discard = 1;
1178
1179 /* copy all configured filters */
1180 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1181 /*
1182 * Make sure we don't exceed our filters limit.
1183 * if there is still a valid filter to be configured,
1184 * be on the safe side and just allow bcast for this mac.
1185 */
1186 if (WARN_ON_ONCE(data->current_filter >=
1187 ARRAY_SIZE(cmd->filters))) {
1188 bcast_mac->default_discard = 0;
1189 bcast_mac->attached_filters = 0;
1190 break;
1191 }
1192
1193 iwl_mvm_set_bcast_filter(vif,
1194 &mvm->bcast_filters[i],
1195 &cmd->filters[data->current_filter]);
1196
1197 /* skip current filter if it contains no attributes */
1198 if (!cmd->filters[data->current_filter].num_attrs)
1199 continue;
1200
1201 /* attach the filter to current mac */
1202 bcast_mac->attached_filters |=
1203 cpu_to_le16(BIT(data->current_filter));
1204
1205 data->current_filter++;
1206 }
1207 }
1208
1209 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1210 struct iwl_bcast_filter_cmd *cmd)
1211 {
1212 struct iwl_bcast_iter_data iter_data = {
1213 .mvm = mvm,
1214 .cmd = cmd,
1215 };
1216
1217 memset(cmd, 0, sizeof(*cmd));
1218 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1219 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1220
1221 #ifdef CONFIG_IWLWIFI_DEBUGFS
1222 /* use debugfs filters/macs if override is configured */
1223 if (mvm->dbgfs_bcast_filtering.override) {
1224 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1225 sizeof(cmd->filters));
1226 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1227 sizeof(cmd->macs));
1228 return true;
1229 }
1230 #endif
1231
1232 /* if no filters are configured, do nothing */
1233 if (!mvm->bcast_filters)
1234 return false;
1235
1236 /* configure and attach these filters for each associated sta vif */
1237 ieee80211_iterate_active_interfaces(
1238 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1239 iwl_mvm_bcast_filter_iterator, &iter_data);
1240
1241 return true;
1242 }
1243 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1244 struct ieee80211_vif *vif)
1245 {
1246 struct iwl_bcast_filter_cmd cmd;
1247
1248 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1249 return 0;
1250
1251 /* bcast filtering isn't supported for P2P client */
1252 if (vif->p2p)
1253 return 0;
1254
1255 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1256 return 0;
1257
1258 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1259 sizeof(cmd), &cmd);
1260 }
1261 #else
1262 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1263 struct ieee80211_vif *vif)
1264 {
1265 return 0;
1266 }
1267 #endif
1268
1269 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1270 struct ieee80211_vif *vif,
1271 struct ieee80211_bss_conf *bss_conf,
1272 u32 changes)
1273 {
1274 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1275 int ret;
1276
1277 /*
1278 * Re-calculate the tsf id, as the master-slave relations depend on the
1279 * beacon interval, which was not known when the station interface was
1280 * added.
1281 */
1282 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1283 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1284
1285 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false);
1286 if (ret)
1287 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1288
1289 if (changes & BSS_CHANGED_ASSOC) {
1290 if (bss_conf->assoc) {
1291 /* add quota for this interface */
1292 ret = iwl_mvm_update_quotas(mvm, vif);
1293 if (ret) {
1294 IWL_ERR(mvm, "failed to update quotas\n");
1295 return;
1296 }
1297
1298 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1299 &mvm->status)) {
1300 /*
1301 * If we're restarting then the firmware will
1302 * obviously have lost synchronisation with
1303 * the AP. It will attempt to synchronise by
1304 * itself, but we can make it more reliable by
1305 * scheduling a session protection time event.
1306 *
1307 * The firmware needs to receive a beacon to
1308 * catch up with synchronisation, use 110% of
1309 * the beacon interval.
1310 *
1311 * Set a large maximum delay to allow for more
1312 * than a single interface.
1313 */
1314 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1315 iwl_mvm_protect_session(mvm, vif, dur, dur,
1316 5 * dur);
1317 }
1318
1319 iwl_mvm_sf_update(mvm, vif, false);
1320 iwl_mvm_power_vif_assoc(mvm, vif);
1321 if (vif->p2p)
1322 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
1323 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1324 /*
1325 * If update fails - SF might be running in associated
1326 * mode while disassociated - which is forbidden.
1327 */
1328 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1329 "Failed to update SF upon disassociation\n");
1330
1331 /* remove AP station now that the MAC is unassoc */
1332 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1333 if (ret)
1334 IWL_ERR(mvm, "failed to remove AP station\n");
1335
1336 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1337 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
1338 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1339 /* remove quota for this interface */
1340 ret = iwl_mvm_update_quotas(mvm, NULL);
1341 if (ret)
1342 IWL_ERR(mvm, "failed to update quotas\n");
1343
1344 if (vif->p2p)
1345 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
1346 }
1347
1348 iwl_mvm_recalc_multicast(mvm);
1349 iwl_mvm_configure_bcast_filter(mvm, vif);
1350
1351 /* reset rssi values */
1352 mvmvif->bf_data.ave_beacon_signal = 0;
1353
1354 iwl_mvm_bt_coex_vif_change(mvm);
1355 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1356 IEEE80211_SMPS_AUTOMATIC);
1357 } else if (changes & BSS_CHANGED_BEACON_INFO) {
1358 /*
1359 * We received a beacon _after_ association so
1360 * remove the session protection.
1361 */
1362 iwl_mvm_remove_time_event(mvm, mvmvif,
1363 &mvmvif->time_event_data);
1364 iwl_mvm_sf_update(mvm, vif, false);
1365 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
1366 } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS |
1367 BSS_CHANGED_QOS)) {
1368 ret = iwl_mvm_power_update_mac(mvm);
1369 if (ret)
1370 IWL_ERR(mvm, "failed to update power mode\n");
1371 }
1372 if (changes & BSS_CHANGED_TXPOWER) {
1373 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1374 bss_conf->txpower);
1375 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1376 }
1377
1378 if (changes & BSS_CHANGED_CQM) {
1379 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
1380 /* reset cqm events tracking */
1381 mvmvif->bf_data.last_cqm_event = 0;
1382 if (mvmvif->bf_data.bf_enabled) {
1383 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1384 if (ret)
1385 IWL_ERR(mvm,
1386 "failed to update CQM thresholds\n");
1387 }
1388 }
1389
1390 if (changes & BSS_CHANGED_ARP_FILTER) {
1391 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
1392 iwl_mvm_configure_bcast_filter(mvm, vif);
1393 }
1394 }
1395
1396 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1397 struct ieee80211_vif *vif)
1398 {
1399 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1400 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1401 int ret;
1402
1403 mutex_lock(&mvm->mutex);
1404
1405 /* Send the beacon template */
1406 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1407 if (ret)
1408 goto out_unlock;
1409
1410 /*
1411 * Re-calculate the tsf id, as the master-slave relations depend on the
1412 * beacon interval, which was not known when the AP interface was added.
1413 */
1414 if (vif->type == NL80211_IFTYPE_AP)
1415 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1416
1417 /* Add the mac context */
1418 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1419 if (ret)
1420 goto out_unlock;
1421
1422 /* Perform the binding */
1423 ret = iwl_mvm_binding_add_vif(mvm, vif);
1424 if (ret)
1425 goto out_remove;
1426
1427 /* Send the bcast station. At this stage the TBTT and DTIM time events
1428 * are added and applied to the scheduler */
1429 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
1430 if (ret)
1431 goto out_unbind;
1432
1433 /* must be set before quota calculations */
1434 mvmvif->ap_ibss_active = true;
1435
1436 /* power updated needs to be done before quotas */
1437 iwl_mvm_power_update_mac(mvm);
1438
1439 ret = iwl_mvm_update_quotas(mvm, vif);
1440 if (ret)
1441 goto out_quota_failed;
1442
1443 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1444 if (vif->p2p && mvm->p2p_device_vif)
1445 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false);
1446
1447 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1448
1449 iwl_mvm_bt_coex_vif_change(mvm);
1450
1451 mutex_unlock(&mvm->mutex);
1452 return 0;
1453
1454 out_quota_failed:
1455 iwl_mvm_power_update_mac(mvm);
1456 mvmvif->ap_ibss_active = false;
1457 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1458 out_unbind:
1459 iwl_mvm_binding_remove_vif(mvm, vif);
1460 out_remove:
1461 iwl_mvm_mac_ctxt_remove(mvm, vif);
1462 out_unlock:
1463 mutex_unlock(&mvm->mutex);
1464 return ret;
1465 }
1466
1467 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
1468 struct ieee80211_vif *vif)
1469 {
1470 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1471 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1472
1473 iwl_mvm_prepare_mac_removal(mvm, vif);
1474
1475 mutex_lock(&mvm->mutex);
1476
1477 mvmvif->ap_ibss_active = false;
1478 mvm->ap_last_beacon_gp2 = 0;
1479
1480 iwl_mvm_bt_coex_vif_change(mvm);
1481
1482 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
1483
1484 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1485 if (vif->p2p && mvm->p2p_device_vif)
1486 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false);
1487
1488 iwl_mvm_update_quotas(mvm, NULL);
1489 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1490 iwl_mvm_binding_remove_vif(mvm, vif);
1491
1492 iwl_mvm_power_update_mac(mvm);
1493
1494 iwl_mvm_mac_ctxt_remove(mvm, vif);
1495
1496 mutex_unlock(&mvm->mutex);
1497 }
1498
1499 static void
1500 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
1501 struct ieee80211_vif *vif,
1502 struct ieee80211_bss_conf *bss_conf,
1503 u32 changes)
1504 {
1505 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1506
1507 /* Changes will be applied when the AP/IBSS is started */
1508 if (!mvmvif->ap_ibss_active)
1509 return;
1510
1511 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
1512 BSS_CHANGED_BANDWIDTH) &&
1513 iwl_mvm_mac_ctxt_changed(mvm, vif, false))
1514 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1515
1516 /* Need to send a new beacon template to the FW */
1517 if (changes & BSS_CHANGED_BEACON &&
1518 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1519 IWL_WARN(mvm, "Failed updating beacon data\n");
1520 }
1521
1522 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1523 struct ieee80211_vif *vif,
1524 struct ieee80211_bss_conf *bss_conf,
1525 u32 changes)
1526 {
1527 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1528
1529 mutex_lock(&mvm->mutex);
1530
1531 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
1532 iwl_mvm_sched_scan_stop(mvm, true);
1533
1534 switch (vif->type) {
1535 case NL80211_IFTYPE_STATION:
1536 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1537 break;
1538 case NL80211_IFTYPE_AP:
1539 case NL80211_IFTYPE_ADHOC:
1540 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
1541 break;
1542 default:
1543 /* shouldn't happen */
1544 WARN_ON_ONCE(1);
1545 }
1546
1547 mutex_unlock(&mvm->mutex);
1548 }
1549
1550 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
1551 struct ieee80211_vif *vif,
1552 struct ieee80211_scan_request *hw_req)
1553 {
1554 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1555 struct cfg80211_scan_request *req = &hw_req->req;
1556 int ret;
1557
1558 if (req->n_channels == 0 ||
1559 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
1560 return -EINVAL;
1561
1562 mutex_lock(&mvm->mutex);
1563
1564 switch (mvm->scan_status) {
1565 case IWL_MVM_SCAN_SCHED:
1566 ret = iwl_mvm_sched_scan_stop(mvm, true);
1567 if (ret) {
1568 ret = -EBUSY;
1569 goto out;
1570 }
1571 break;
1572 case IWL_MVM_SCAN_NONE:
1573 break;
1574 default:
1575 ret = -EBUSY;
1576 goto out;
1577 }
1578
1579 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
1580
1581 ret = iwl_mvm_scan_request(mvm, vif, req);
1582 if (ret)
1583 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1584 out:
1585 mutex_unlock(&mvm->mutex);
1586 /* make sure to flush the Rx handler before the next scan arrives */
1587 iwl_mvm_wait_for_async_handlers(mvm);
1588 return ret;
1589 }
1590
1591 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1592 struct ieee80211_vif *vif)
1593 {
1594 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1595
1596 mutex_lock(&mvm->mutex);
1597
1598 iwl_mvm_cancel_scan(mvm);
1599
1600 mutex_unlock(&mvm->mutex);
1601 }
1602
1603 static void
1604 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
1605 struct ieee80211_sta *sta, u16 tids,
1606 int num_frames,
1607 enum ieee80211_frame_release_type reason,
1608 bool more_data)
1609 {
1610 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1611
1612 /* Called when we need to transmit (a) frame(s) from mac80211 */
1613
1614 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1615 tids, more_data, false);
1616 }
1617
1618 static void
1619 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
1620 struct ieee80211_sta *sta, u16 tids,
1621 int num_frames,
1622 enum ieee80211_frame_release_type reason,
1623 bool more_data)
1624 {
1625 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1626
1627 /* Called when we need to transmit (a) frame(s) from agg queue */
1628
1629 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1630 tids, more_data, true);
1631 }
1632
1633 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1634 struct ieee80211_vif *vif,
1635 enum sta_notify_cmd cmd,
1636 struct ieee80211_sta *sta)
1637 {
1638 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1639 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1640 int tid;
1641
1642 switch (cmd) {
1643 case STA_NOTIFY_SLEEP:
1644 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
1645 ieee80211_sta_block_awake(hw, sta, true);
1646 spin_lock_bh(&mvmsta->lock);
1647 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
1648 struct iwl_mvm_tid_data *tid_data;
1649
1650 tid_data = &mvmsta->tid_data[tid];
1651 if (tid_data->state != IWL_AGG_ON &&
1652 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
1653 continue;
1654 if (iwl_mvm_tid_queued(tid_data) == 0)
1655 continue;
1656 ieee80211_sta_set_buffered(sta, tid, true);
1657 }
1658 spin_unlock_bh(&mvmsta->lock);
1659 /*
1660 * The fw updates the STA to be asleep. Tx packets on the Tx
1661 * queues to this station will not be transmitted. The fw will
1662 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1663 */
1664 break;
1665 case STA_NOTIFY_AWAKE:
1666 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
1667 break;
1668 iwl_mvm_sta_modify_ps_wake(mvm, sta);
1669 break;
1670 default:
1671 break;
1672 }
1673 }
1674
1675 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
1676 struct ieee80211_vif *vif,
1677 struct ieee80211_sta *sta)
1678 {
1679 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1680 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1681
1682 /*
1683 * This is called before mac80211 does RCU synchronisation,
1684 * so here we already invalidate our internal RCU-protected
1685 * station pointer. The rest of the code will thus no longer
1686 * be able to find the station this way, and we don't rely
1687 * on further RCU synchronisation after the sta_state()
1688 * callback deleted the station.
1689 */
1690 mutex_lock(&mvm->mutex);
1691 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
1692 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1693 ERR_PTR(-ENOENT));
1694 mutex_unlock(&mvm->mutex);
1695 }
1696
1697 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1698 struct ieee80211_vif *vif,
1699 struct ieee80211_sta *sta,
1700 enum ieee80211_sta_state old_state,
1701 enum ieee80211_sta_state new_state)
1702 {
1703 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1704 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1705 int ret;
1706
1707 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1708 sta->addr, old_state, new_state);
1709
1710 /* this would be a mac80211 bug ... but don't crash */
1711 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1712 return -EINVAL;
1713
1714 /* if a STA is being removed, reuse its ID */
1715 flush_work(&mvm->sta_drained_wk);
1716
1717 mutex_lock(&mvm->mutex);
1718 if (old_state == IEEE80211_STA_NOTEXIST &&
1719 new_state == IEEE80211_STA_NONE) {
1720 /*
1721 * Firmware bug - it'll crash if the beacon interval is less
1722 * than 16. We can't avoid connecting at all, so refuse the
1723 * station state change, this will cause mac80211 to abandon
1724 * attempts to connect to this AP, and eventually wpa_s will
1725 * blacklist the AP...
1726 */
1727 if (vif->type == NL80211_IFTYPE_STATION &&
1728 vif->bss_conf.beacon_int < 16) {
1729 IWL_ERR(mvm,
1730 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1731 sta->addr, vif->bss_conf.beacon_int);
1732 ret = -EINVAL;
1733 goto out_unlock;
1734 }
1735 ret = iwl_mvm_add_sta(mvm, vif, sta);
1736 } else if (old_state == IEEE80211_STA_NONE &&
1737 new_state == IEEE80211_STA_AUTH) {
1738 /*
1739 * EBS may be disabled due to previous failures reported by FW.
1740 * Reset EBS status here assuming environment has been changed.
1741 */
1742 mvm->last_ebs_successful = true;
1743 ret = 0;
1744 } else if (old_state == IEEE80211_STA_AUTH &&
1745 new_state == IEEE80211_STA_ASSOC) {
1746 ret = iwl_mvm_update_sta(mvm, vif, sta);
1747 if (ret == 0)
1748 iwl_mvm_rs_rate_init(mvm, sta,
1749 mvmvif->phy_ctxt->channel->band,
1750 true);
1751 } else if (old_state == IEEE80211_STA_ASSOC &&
1752 new_state == IEEE80211_STA_AUTHORIZED) {
1753 /* enable beacon filtering */
1754 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
1755 ret = 0;
1756 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1757 new_state == IEEE80211_STA_ASSOC) {
1758 /* disable beacon filtering */
1759 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
1760 ret = 0;
1761 } else if (old_state == IEEE80211_STA_ASSOC &&
1762 new_state == IEEE80211_STA_AUTH) {
1763 ret = 0;
1764 } else if (old_state == IEEE80211_STA_AUTH &&
1765 new_state == IEEE80211_STA_NONE) {
1766 ret = 0;
1767 } else if (old_state == IEEE80211_STA_NONE &&
1768 new_state == IEEE80211_STA_NOTEXIST) {
1769 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1770 } else {
1771 ret = -EIO;
1772 }
1773 out_unlock:
1774 mutex_unlock(&mvm->mutex);
1775
1776 return ret;
1777 }
1778
1779 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1780 {
1781 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1782
1783 mvm->rts_threshold = value;
1784
1785 return 0;
1786 }
1787
1788 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
1789 struct ieee80211_vif *vif,
1790 struct ieee80211_sta *sta, u32 changed)
1791 {
1792 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1793
1794 if (vif->type == NL80211_IFTYPE_STATION &&
1795 changed & IEEE80211_RC_NSS_CHANGED)
1796 iwl_mvm_sf_update(mvm, vif, false);
1797 }
1798
1799 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1800 struct ieee80211_vif *vif, u16 ac,
1801 const struct ieee80211_tx_queue_params *params)
1802 {
1803 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1804 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1805
1806 mvmvif->queue_params[ac] = *params;
1807
1808 /*
1809 * No need to update right away, we'll get BSS_CHANGED_QOS
1810 * The exception is P2P_DEVICE interface which needs immediate update.
1811 */
1812 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1813 int ret;
1814
1815 mutex_lock(&mvm->mutex);
1816 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false);
1817 mutex_unlock(&mvm->mutex);
1818 return ret;
1819 }
1820 return 0;
1821 }
1822
1823 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1824 struct ieee80211_vif *vif)
1825 {
1826 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1827 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1828 200 + vif->bss_conf.beacon_int);
1829 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1830 100 + vif->bss_conf.beacon_int);
1831
1832 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1833 return;
1834
1835 mutex_lock(&mvm->mutex);
1836 /* Try really hard to protect the session and hear a beacon */
1837 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
1838 mutex_unlock(&mvm->mutex);
1839 }
1840
1841 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
1842 struct ieee80211_vif *vif,
1843 struct cfg80211_sched_scan_request *req,
1844 struct ieee80211_scan_ies *ies)
1845 {
1846 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1847 int ret;
1848
1849 mutex_lock(&mvm->mutex);
1850
1851 if (!iwl_mvm_is_idle(mvm)) {
1852 ret = -EBUSY;
1853 goto out;
1854 }
1855
1856 switch (mvm->scan_status) {
1857 case IWL_MVM_SCAN_OS:
1858 IWL_DEBUG_SCAN(mvm, "Stopping previous scan for sched_scan\n");
1859 ret = iwl_mvm_cancel_scan(mvm);
1860 if (ret) {
1861 ret = -EBUSY;
1862 goto out;
1863 }
1864
1865 /*
1866 * iwl_mvm_rx_scan_complete() will be called soon but will
1867 * not reset the scan status as it won't be IWL_MVM_SCAN_OS
1868 * any more since we queue the next scan immediately (below).
1869 * We make sure it is called before the next scan starts by
1870 * flushing the async-handlers work.
1871 */
1872 break;
1873 case IWL_MVM_SCAN_NONE:
1874 break;
1875 default:
1876 ret = -EBUSY;
1877 goto out;
1878 }
1879
1880 mvm->scan_status = IWL_MVM_SCAN_SCHED;
1881
1882 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
1883 if (ret)
1884 goto err;
1885
1886 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1887 if (ret)
1888 goto err;
1889
1890 ret = iwl_mvm_sched_scan_start(mvm, req);
1891 if (!ret)
1892 goto out;
1893 err:
1894 mvm->scan_status = IWL_MVM_SCAN_NONE;
1895 out:
1896 mutex_unlock(&mvm->mutex);
1897 /* make sure to flush the Rx handler before the next scan arrives */
1898 iwl_mvm_wait_for_async_handlers(mvm);
1899 return ret;
1900 }
1901
1902 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
1903 struct ieee80211_vif *vif)
1904 {
1905 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1906 int ret;
1907
1908 mutex_lock(&mvm->mutex);
1909 ret = iwl_mvm_sched_scan_stop(mvm, false);
1910 mutex_unlock(&mvm->mutex);
1911 iwl_mvm_wait_for_async_handlers(mvm);
1912
1913 return ret;
1914 }
1915
1916 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1917 enum set_key_cmd cmd,
1918 struct ieee80211_vif *vif,
1919 struct ieee80211_sta *sta,
1920 struct ieee80211_key_conf *key)
1921 {
1922 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1923 int ret;
1924
1925 if (iwlwifi_mod_params.sw_crypto) {
1926 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1927 return -EOPNOTSUPP;
1928 }
1929
1930 switch (key->cipher) {
1931 case WLAN_CIPHER_SUITE_TKIP:
1932 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1933 /* fall-through */
1934 case WLAN_CIPHER_SUITE_CCMP:
1935 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1936 break;
1937 case WLAN_CIPHER_SUITE_AES_CMAC:
1938 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1939 break;
1940 case WLAN_CIPHER_SUITE_WEP40:
1941 case WLAN_CIPHER_SUITE_WEP104:
1942 /*
1943 * Support for TX only, at least for now, so accept
1944 * the key and do nothing else. Then mac80211 will
1945 * pass it for TX but we don't have to use it for RX.
1946 */
1947 return 0;
1948 default:
1949 /* currently FW supports only one optional cipher scheme */
1950 if (hw->n_cipher_schemes &&
1951 hw->cipher_schemes->cipher == key->cipher)
1952 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
1953 else
1954 return -EOPNOTSUPP;
1955 }
1956
1957 mutex_lock(&mvm->mutex);
1958
1959 switch (cmd) {
1960 case SET_KEY:
1961 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1962 vif->type == NL80211_IFTYPE_AP) && !sta) {
1963 /*
1964 * GTK on AP interface is a TX-only key, return 0;
1965 * on IBSS they're per-station and because we're lazy
1966 * we don't support them for RX, so do the same.
1967 */
1968 ret = 0;
1969 key->hw_key_idx = STA_KEY_IDX_INVALID;
1970 break;
1971 }
1972
1973 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1974 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1975 if (ret) {
1976 IWL_WARN(mvm, "set key failed\n");
1977 /*
1978 * can't add key for RX, but we don't need it
1979 * in the device for TX so still return 0
1980 */
1981 key->hw_key_idx = STA_KEY_IDX_INVALID;
1982 ret = 0;
1983 }
1984
1985 break;
1986 case DISABLE_KEY:
1987 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1988 ret = 0;
1989 break;
1990 }
1991
1992 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1993 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1994 break;
1995 default:
1996 ret = -EINVAL;
1997 }
1998
1999 mutex_unlock(&mvm->mutex);
2000 return ret;
2001 }
2002
2003 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2004 struct ieee80211_vif *vif,
2005 struct ieee80211_key_conf *keyconf,
2006 struct ieee80211_sta *sta,
2007 u32 iv32, u16 *phase1key)
2008 {
2009 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2010
2011 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2012 return;
2013
2014 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2015 }
2016
2017
2018 static int iwl_mvm_roc(struct ieee80211_hw *hw,
2019 struct ieee80211_vif *vif,
2020 struct ieee80211_channel *channel,
2021 int duration,
2022 enum ieee80211_roc_type type)
2023 {
2024 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2025 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2026 struct cfg80211_chan_def chandef;
2027 struct iwl_mvm_phy_ctxt *phy_ctxt;
2028 int ret, i;
2029
2030 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
2031 duration, type);
2032
2033 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
2034 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
2035 return -EINVAL;
2036 }
2037
2038 mutex_lock(&mvm->mutex);
2039
2040 for (i = 0; i < NUM_PHY_CTX; i++) {
2041 phy_ctxt = &mvm->phy_ctxts[i];
2042 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
2043 continue;
2044
2045 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
2046 /*
2047 * Unbind the P2P_DEVICE from the current PHY context,
2048 * and if the PHY context is not used remove it.
2049 */
2050 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2051 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2052 goto out_unlock;
2053
2054 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2055
2056 /* Bind the P2P_DEVICE to the current PHY Context */
2057 mvmvif->phy_ctxt = phy_ctxt;
2058
2059 ret = iwl_mvm_binding_add_vif(mvm, vif);
2060 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2061 goto out_unlock;
2062
2063 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2064 goto schedule_time_event;
2065 }
2066 }
2067
2068 /* Need to update the PHY context only if the ROC channel changed */
2069 if (channel == mvmvif->phy_ctxt->channel)
2070 goto schedule_time_event;
2071
2072 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
2073
2074 /*
2075 * Change the PHY context configuration as it is currently referenced
2076 * only by the P2P Device MAC
2077 */
2078 if (mvmvif->phy_ctxt->ref == 1) {
2079 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2080 &chandef, 1, 1);
2081 if (ret)
2082 goto out_unlock;
2083 } else {
2084 /*
2085 * The PHY context is shared with other MACs. Need to remove the
2086 * P2P Device from the binding, allocate an new PHY context and
2087 * create a new binding
2088 */
2089 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2090 if (!phy_ctxt) {
2091 ret = -ENOSPC;
2092 goto out_unlock;
2093 }
2094
2095 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2096 1, 1);
2097 if (ret) {
2098 IWL_ERR(mvm, "Failed to change PHY context\n");
2099 goto out_unlock;
2100 }
2101
2102 /* Unbind the P2P_DEVICE from the current PHY context */
2103 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2104 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2105 goto out_unlock;
2106
2107 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2108
2109 /* Bind the P2P_DEVICE to the new allocated PHY context */
2110 mvmvif->phy_ctxt = phy_ctxt;
2111
2112 ret = iwl_mvm_binding_add_vif(mvm, vif);
2113 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2114 goto out_unlock;
2115
2116 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2117 }
2118
2119 schedule_time_event:
2120 /* Schedule the time events */
2121 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
2122
2123 out_unlock:
2124 mutex_unlock(&mvm->mutex);
2125 IWL_DEBUG_MAC80211(mvm, "leave\n");
2126 return ret;
2127 }
2128
2129 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
2130 {
2131 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2132
2133 IWL_DEBUG_MAC80211(mvm, "enter\n");
2134
2135 mutex_lock(&mvm->mutex);
2136 iwl_mvm_stop_p2p_roc(mvm);
2137 mutex_unlock(&mvm->mutex);
2138
2139 IWL_DEBUG_MAC80211(mvm, "leave\n");
2140 return 0;
2141 }
2142
2143 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2144 struct ieee80211_chanctx_conf *ctx)
2145 {
2146 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2147 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2148 struct iwl_mvm_phy_ctxt *phy_ctxt;
2149 int ret;
2150
2151 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
2152
2153 mutex_lock(&mvm->mutex);
2154 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2155 if (!phy_ctxt) {
2156 ret = -ENOSPC;
2157 goto out;
2158 }
2159
2160 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
2161 ctx->rx_chains_static,
2162 ctx->rx_chains_dynamic);
2163 if (ret) {
2164 IWL_ERR(mvm, "Failed to add PHY context\n");
2165 goto out;
2166 }
2167
2168 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
2169 *phy_ctxt_id = phy_ctxt->id;
2170 out:
2171 mutex_unlock(&mvm->mutex);
2172 return ret;
2173 }
2174
2175 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2176 struct ieee80211_chanctx_conf *ctx)
2177 {
2178 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2179 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2180 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2181
2182 mutex_lock(&mvm->mutex);
2183 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
2184 mutex_unlock(&mvm->mutex);
2185 }
2186
2187 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
2188 struct ieee80211_chanctx_conf *ctx,
2189 u32 changed)
2190 {
2191 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2192 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2193 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2194
2195 if (WARN_ONCE((phy_ctxt->ref > 1) &&
2196 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
2197 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
2198 IEEE80211_CHANCTX_CHANGE_RADAR |
2199 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
2200 "Cannot change PHY. Ref=%d, changed=0x%X\n",
2201 phy_ctxt->ref, changed))
2202 return;
2203
2204 mutex_lock(&mvm->mutex);
2205 iwl_mvm_bt_coex_vif_change(mvm);
2206 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
2207 ctx->rx_chains_static,
2208 ctx->rx_chains_dynamic);
2209 mutex_unlock(&mvm->mutex);
2210 }
2211
2212 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
2213 struct ieee80211_vif *vif,
2214 struct ieee80211_chanctx_conf *ctx)
2215 {
2216 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2217 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2218 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2219 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2220 int ret;
2221
2222 mutex_lock(&mvm->mutex);
2223
2224 mvmvif->phy_ctxt = phy_ctxt;
2225
2226 switch (vif->type) {
2227 case NL80211_IFTYPE_AP:
2228 /* Unless it's a CSA flow we have nothing to do here */
2229 if (vif->csa_active) {
2230 mvmvif->ap_ibss_active = true;
2231 break;
2232 }
2233 case NL80211_IFTYPE_ADHOC:
2234 /*
2235 * The AP binding flow is handled as part of the start_ap flow
2236 * (in bss_info_changed), similarly for IBSS.
2237 */
2238 ret = 0;
2239 goto out_unlock;
2240 case NL80211_IFTYPE_STATION:
2241 case NL80211_IFTYPE_MONITOR:
2242 break;
2243 default:
2244 ret = -EINVAL;
2245 goto out_unlock;
2246 }
2247
2248 ret = iwl_mvm_binding_add_vif(mvm, vif);
2249 if (ret)
2250 goto out_unlock;
2251
2252 /*
2253 * Power state must be updated before quotas,
2254 * otherwise fw will complain.
2255 */
2256 iwl_mvm_power_update_mac(mvm);
2257
2258 /* Setting the quota at this stage is only required for monitor
2259 * interfaces. For the other types, the bss_info changed flow
2260 * will handle quota settings.
2261 */
2262 if (vif->type == NL80211_IFTYPE_MONITOR) {
2263 mvmvif->monitor_active = true;
2264 ret = iwl_mvm_update_quotas(mvm, vif);
2265 if (ret)
2266 goto out_remove_binding;
2267 }
2268
2269 /* Handle binding during CSA */
2270 if (vif->type == NL80211_IFTYPE_AP) {
2271 iwl_mvm_update_quotas(mvm, vif);
2272 iwl_mvm_mac_ctxt_changed(mvm, vif, false);
2273 }
2274
2275 goto out_unlock;
2276
2277 out_remove_binding:
2278 iwl_mvm_binding_remove_vif(mvm, vif);
2279 iwl_mvm_power_update_mac(mvm);
2280 out_unlock:
2281 mutex_unlock(&mvm->mutex);
2282 if (ret)
2283 mvmvif->phy_ctxt = NULL;
2284 return ret;
2285 }
2286
2287 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
2288 struct ieee80211_vif *vif,
2289 struct ieee80211_chanctx_conf *ctx)
2290 {
2291 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2292 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2293
2294 mutex_lock(&mvm->mutex);
2295
2296 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
2297
2298 switch (vif->type) {
2299 case NL80211_IFTYPE_ADHOC:
2300 goto out_unlock;
2301 case NL80211_IFTYPE_MONITOR:
2302 mvmvif->monitor_active = false;
2303 iwl_mvm_update_quotas(mvm, NULL);
2304 break;
2305 case NL80211_IFTYPE_AP:
2306 /* This part is triggered only during CSA */
2307 if (!vif->csa_active || !mvmvif->ap_ibss_active)
2308 goto out_unlock;
2309
2310 mvmvif->ap_ibss_active = false;
2311 iwl_mvm_update_quotas(mvm, NULL);
2312 /*TODO: bt_coex notification here? */
2313 default:
2314 break;
2315 }
2316
2317 iwl_mvm_binding_remove_vif(mvm, vif);
2318
2319 out_unlock:
2320 mvmvif->phy_ctxt = NULL;
2321 iwl_mvm_power_update_mac(mvm);
2322 mutex_unlock(&mvm->mutex);
2323 }
2324
2325 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
2326 struct ieee80211_sta *sta,
2327 bool set)
2328 {
2329 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2330 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
2331
2332 if (!mvm_sta || !mvm_sta->vif) {
2333 IWL_ERR(mvm, "Station is not associated to a vif\n");
2334 return -EINVAL;
2335 }
2336
2337 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
2338 }
2339
2340 #ifdef CONFIG_NL80211_TESTMODE
2341 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
2342 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
2343 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
2344 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
2345 };
2346
2347 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
2348 struct ieee80211_vif *vif,
2349 void *data, int len)
2350 {
2351 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
2352 int err;
2353 u32 noa_duration;
2354
2355 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
2356 if (err)
2357 return err;
2358
2359 if (!tb[IWL_MVM_TM_ATTR_CMD])
2360 return -EINVAL;
2361
2362 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
2363 case IWL_MVM_TM_CMD_SET_NOA:
2364 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
2365 !vif->bss_conf.enable_beacon ||
2366 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
2367 return -EINVAL;
2368
2369 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
2370 if (noa_duration >= vif->bss_conf.beacon_int)
2371 return -EINVAL;
2372
2373 mvm->noa_duration = noa_duration;
2374 mvm->noa_vif = vif;
2375
2376 return iwl_mvm_update_quotas(mvm, NULL);
2377 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
2378 /* must be associated client vif - ignore authorized */
2379 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
2380 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
2381 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
2382 return -EINVAL;
2383
2384 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
2385 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2386 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
2387 }
2388
2389 return -EOPNOTSUPP;
2390 }
2391
2392 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
2393 struct ieee80211_vif *vif,
2394 void *data, int len)
2395 {
2396 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2397 int err;
2398
2399 mutex_lock(&mvm->mutex);
2400 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
2401 mutex_unlock(&mvm->mutex);
2402
2403 return err;
2404 }
2405 #endif
2406
2407 static void iwl_mvm_channel_switch_beacon(struct ieee80211_hw *hw,
2408 struct ieee80211_vif *vif,
2409 struct cfg80211_chan_def *chandef)
2410 {
2411 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2412
2413 mutex_lock(&mvm->mutex);
2414 if (WARN(mvm->csa_vif && mvm->csa_vif->csa_active,
2415 "Another CSA is already in progress"))
2416 goto out_unlock;
2417
2418 IWL_DEBUG_MAC80211(mvm, "CSA started to freq %d\n",
2419 chandef->center_freq1);
2420 mvm->csa_vif = vif;
2421
2422 out_unlock:
2423 mutex_unlock(&mvm->mutex);
2424 }
2425
2426 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
2427 struct ieee80211_vif *vif, u32 queues, bool drop)
2428 {
2429 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2430 struct iwl_mvm_vif *mvmvif;
2431 struct iwl_mvm_sta *mvmsta;
2432
2433 if (!vif || vif->type != NL80211_IFTYPE_STATION)
2434 return;
2435
2436 mutex_lock(&mvm->mutex);
2437 mvmvif = iwl_mvm_vif_from_mac80211(vif);
2438 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, mvmvif->ap_sta_id);
2439
2440 if (WARN_ON_ONCE(!mvmsta))
2441 goto done;
2442
2443 if (drop) {
2444 if (iwl_mvm_flush_tx_path(mvm, mvmsta->tfd_queue_msk, true))
2445 IWL_ERR(mvm, "flush request fail\n");
2446 } else {
2447 iwl_trans_wait_tx_queue_empty(mvm->trans,
2448 mvmsta->tfd_queue_msk);
2449 }
2450 done:
2451 mutex_unlock(&mvm->mutex);
2452 }
2453
2454 const struct ieee80211_ops iwl_mvm_hw_ops = {
2455 .tx = iwl_mvm_mac_tx,
2456 .ampdu_action = iwl_mvm_mac_ampdu_action,
2457 .start = iwl_mvm_mac_start,
2458 .restart_complete = iwl_mvm_mac_restart_complete,
2459 .stop = iwl_mvm_mac_stop,
2460 .add_interface = iwl_mvm_mac_add_interface,
2461 .remove_interface = iwl_mvm_mac_remove_interface,
2462 .config = iwl_mvm_mac_config,
2463 .prepare_multicast = iwl_mvm_prepare_multicast,
2464 .configure_filter = iwl_mvm_configure_filter,
2465 .bss_info_changed = iwl_mvm_bss_info_changed,
2466 .hw_scan = iwl_mvm_mac_hw_scan,
2467 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
2468 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
2469 .sta_state = iwl_mvm_mac_sta_state,
2470 .sta_notify = iwl_mvm_mac_sta_notify,
2471 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
2472 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
2473 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
2474 .sta_rc_update = iwl_mvm_sta_rc_update,
2475 .conf_tx = iwl_mvm_mac_conf_tx,
2476 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
2477 .flush = iwl_mvm_mac_flush,
2478 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
2479 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
2480 .set_key = iwl_mvm_mac_set_key,
2481 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
2482 .remain_on_channel = iwl_mvm_roc,
2483 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
2484 .add_chanctx = iwl_mvm_add_chanctx,
2485 .remove_chanctx = iwl_mvm_remove_chanctx,
2486 .change_chanctx = iwl_mvm_change_chanctx,
2487 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
2488 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
2489
2490 .start_ap = iwl_mvm_start_ap_ibss,
2491 .stop_ap = iwl_mvm_stop_ap_ibss,
2492 .join_ibss = iwl_mvm_start_ap_ibss,
2493 .leave_ibss = iwl_mvm_stop_ap_ibss,
2494
2495 .set_tim = iwl_mvm_set_tim,
2496
2497 .channel_switch_beacon = iwl_mvm_channel_switch_beacon,
2498
2499 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
2500
2501 #ifdef CONFIG_PM_SLEEP
2502 /* look at d3.c */
2503 .suspend = iwl_mvm_suspend,
2504 .resume = iwl_mvm_resume,
2505 .set_wakeup = iwl_mvm_set_wakeup,
2506 .set_rekey_data = iwl_mvm_set_rekey_data,
2507 #if IS_ENABLED(CONFIG_IPV6)
2508 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
2509 #endif
2510 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
2511 #endif
2512 };
This page took 0.08156 seconds and 6 git commands to generate.