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