Merge branch 'for-john' of git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac802...
[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
81 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
82 {
83 .max = 1,
84 .types = BIT(NL80211_IFTYPE_STATION) |
85 BIT(NL80211_IFTYPE_AP),
86 },
87 };
88
89 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
90 {
91 .num_different_channels = 1,
92 .max_interfaces = 3,
93 .limits = iwl_mvm_limits,
94 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
95 },
96 };
97
98 #ifdef CONFIG_PM_SLEEP
99 static const struct nl80211_wowlan_tcp_data_token_feature
100 iwl_mvm_wowlan_tcp_token_feature = {
101 .min_len = 0,
102 .max_len = 255,
103 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
104 };
105
106 static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
107 .tok = &iwl_mvm_wowlan_tcp_token_feature,
108 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
109 sizeof(struct ethhdr) -
110 sizeof(struct iphdr) -
111 sizeof(struct tcphdr),
112 .data_interval_max = 65535, /* __le16 in API */
113 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
114 sizeof(struct ethhdr) -
115 sizeof(struct iphdr) -
116 sizeof(struct tcphdr),
117 .seq = true,
118 };
119 #endif
120
121 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
122 {
123 int i;
124
125 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
126 for (i = 0; i < NUM_PHY_CTX; i++) {
127 mvm->phy_ctxts[i].id = i;
128 mvm->phy_ctxts[i].ref = 0;
129 }
130 }
131
132 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
133 {
134 struct ieee80211_hw *hw = mvm->hw;
135 int num_mac, ret, i;
136
137 /* Tell mac80211 our characteristics */
138 hw->flags = IEEE80211_HW_SIGNAL_DBM |
139 IEEE80211_HW_SPECTRUM_MGMT |
140 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
141 IEEE80211_HW_QUEUE_CONTROL |
142 IEEE80211_HW_WANT_MONITOR_VIF |
143 IEEE80211_HW_SUPPORTS_PS |
144 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
145 IEEE80211_HW_AMPDU_AGGREGATION |
146 IEEE80211_HW_TIMING_BEACON_ONLY |
147 IEEE80211_HW_CONNECTION_MONITOR;
148
149 hw->queues = IWL_MVM_FIRST_AGG_QUEUE;
150 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
151 hw->rate_control_algorithm = "iwl-mvm-rs";
152
153 /*
154 * Enable 11w if advertised by firmware and software crypto
155 * is not enabled (as the firmware will interpret some mgmt
156 * packets, so enabling it with software crypto isn't safe)
157 */
158 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
159 !iwlwifi_mod_params.sw_crypto)
160 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
161
162 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
163 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
164 hw->chanctx_data_size = sizeof(u16);
165
166 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
167 BIT(NL80211_IFTYPE_AP);
168
169 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
170 WIPHY_FLAG_DISABLE_BEACON_HINTS |
171 WIPHY_FLAG_IBSS_RSN;
172
173 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
174 hw->wiphy->n_iface_combinations =
175 ARRAY_SIZE(iwl_mvm_iface_combinations);
176
177 hw->wiphy->max_remain_on_channel_duration = 10000;
178 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
179
180 /* Extract MAC address */
181 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
182 hw->wiphy->addresses = mvm->addresses;
183 hw->wiphy->n_addresses = 1;
184
185 /* Extract additional MAC addresses if available */
186 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
187 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
188
189 for (i = 1; i < num_mac; i++) {
190 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
191 ETH_ALEN);
192 mvm->addresses[i].addr[5]++;
193 hw->wiphy->n_addresses++;
194 }
195
196 iwl_mvm_reset_phy_ctxts(mvm);
197
198 /* we create the 802.11 header and a max-length SSID element */
199 hw->wiphy->max_scan_ie_len =
200 mvm->fw->ucode_capa.max_probe_length - 24 - 34;
201 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
202
203 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
204 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
205 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
206 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
207 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
208 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
209
210 hw->wiphy->hw_version = mvm->trans->hw_id;
211
212 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
213 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
214 else
215 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
216
217 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
218 NL80211_FEATURE_P2P_GO_OPPPS;
219
220 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
221
222 #ifdef CONFIG_PM_SLEEP
223 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
224 mvm->trans->ops->d3_suspend &&
225 mvm->trans->ops->d3_resume &&
226 device_can_wakeup(mvm->trans->dev)) {
227 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
228 WIPHY_WOWLAN_DISCONNECT |
229 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
230 WIPHY_WOWLAN_RFKILL_RELEASE;
231 if (!iwlwifi_mod_params.sw_crypto)
232 hw->wiphy->wowlan.flags |=
233 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
234 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
235 WIPHY_WOWLAN_4WAY_HANDSHAKE;
236
237 hw->wiphy->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
238 hw->wiphy->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
239 hw->wiphy->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
240 hw->wiphy->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
241 }
242 #endif
243
244 ret = iwl_mvm_leds_init(mvm);
245 if (ret)
246 return ret;
247
248 return ieee80211_register_hw(mvm->hw);
249 }
250
251 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
252 struct ieee80211_tx_control *control,
253 struct sk_buff *skb)
254 {
255 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
256
257 if (iwl_mvm_is_radio_killed(mvm)) {
258 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
259 goto drop;
260 }
261
262 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
263 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
264 goto drop;
265
266 if (control->sta) {
267 if (iwl_mvm_tx_skb(mvm, skb, control->sta))
268 goto drop;
269 return;
270 }
271
272 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
273 goto drop;
274 return;
275 drop:
276 ieee80211_free_txskb(hw, skb);
277 }
278
279 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
280 struct ieee80211_vif *vif,
281 enum ieee80211_ampdu_mlme_action action,
282 struct ieee80211_sta *sta, u16 tid,
283 u16 *ssn, u8 buf_size)
284 {
285 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
286 int ret;
287
288 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
289 sta->addr, tid, action);
290
291 if (!(mvm->nvm_data->sku_cap_11n_enable))
292 return -EACCES;
293
294 mutex_lock(&mvm->mutex);
295
296 switch (action) {
297 case IEEE80211_AMPDU_RX_START:
298 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
299 ret = -EINVAL;
300 break;
301 }
302 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
303 break;
304 case IEEE80211_AMPDU_RX_STOP:
305 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
306 break;
307 case IEEE80211_AMPDU_TX_START:
308 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
309 ret = -EINVAL;
310 break;
311 }
312 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
313 break;
314 case IEEE80211_AMPDU_TX_STOP_CONT:
315 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
316 break;
317 case IEEE80211_AMPDU_TX_STOP_FLUSH:
318 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
319 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
320 break;
321 case IEEE80211_AMPDU_TX_OPERATIONAL:
322 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
323 break;
324 default:
325 WARN_ON_ONCE(1);
326 ret = -EINVAL;
327 break;
328 }
329 mutex_unlock(&mvm->mutex);
330
331 return ret;
332 }
333
334 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
335 struct ieee80211_vif *vif)
336 {
337 struct iwl_mvm *mvm = data;
338 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
339
340 mvmvif->uploaded = false;
341 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
342
343 /* does this make sense at all? */
344 mvmvif->color++;
345
346 spin_lock_bh(&mvm->time_event_lock);
347 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
348 spin_unlock_bh(&mvm->time_event_lock);
349
350 mvmvif->phy_ctxt = NULL;
351 }
352
353 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
354 {
355 iwl_trans_stop_device(mvm->trans);
356 iwl_trans_stop_hw(mvm->trans, false);
357
358 mvm->scan_status = IWL_MVM_SCAN_NONE;
359
360 /* just in case one was running */
361 ieee80211_remain_on_channel_expired(mvm->hw);
362
363 ieee80211_iterate_active_interfaces_atomic(
364 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
365 iwl_mvm_cleanup_iterator, mvm);
366
367 mvm->p2p_device_vif = NULL;
368
369 iwl_mvm_reset_phy_ctxts(mvm);
370 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
371 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
372
373 ieee80211_wake_queues(mvm->hw);
374
375 mvm->vif_count = 0;
376 }
377
378 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
379 {
380 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
381 int ret;
382
383 mutex_lock(&mvm->mutex);
384
385 /* Clean up some internal and mac80211 state on restart */
386 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
387 iwl_mvm_restart_cleanup(mvm);
388
389 ret = iwl_mvm_up(mvm);
390 mutex_unlock(&mvm->mutex);
391
392 return ret;
393 }
394
395 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
396 {
397 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
398 int ret;
399
400 mutex_lock(&mvm->mutex);
401
402 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
403 ret = iwl_mvm_update_quotas(mvm, NULL);
404 if (ret)
405 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
406 ret);
407
408 mutex_unlock(&mvm->mutex);
409 }
410
411 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
412 {
413 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
414
415 flush_work(&mvm->async_handlers_wk);
416
417 mutex_lock(&mvm->mutex);
418 /* async_handlers_wk is now blocked */
419
420 /*
421 * The work item could be running or queued if the
422 * ROC time event stops just as we get here.
423 */
424 cancel_work_sync(&mvm->roc_done_wk);
425
426 iwl_trans_stop_device(mvm->trans);
427 iwl_trans_stop_hw(mvm->trans, false);
428
429 iwl_mvm_async_handlers_purge(mvm);
430 /* async_handlers_list is empty and will stay empty: HW is stopped */
431
432 /* the fw is stopped, the aux sta is dead: clean up driver state */
433 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
434
435 mutex_unlock(&mvm->mutex);
436
437 /*
438 * The worker might have been waiting for the mutex, let it run and
439 * discover that its list is now empty.
440 */
441 cancel_work_sync(&mvm->async_handlers_wk);
442 }
443
444 static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac,
445 struct ieee80211_vif *vif)
446 {
447 struct iwl_mvm *mvm = data;
448 int ret;
449
450 ret = iwl_mvm_power_disable(mvm, vif);
451 if (ret)
452 IWL_ERR(mvm, "failed to disable power management\n");
453 }
454
455 static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
456 struct ieee80211_vif *vif)
457 {
458 struct iwl_mvm *mvm = data;
459
460 iwl_mvm_power_update_mode(mvm, vif);
461 }
462
463 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
464 {
465 u16 i;
466
467 lockdep_assert_held(&mvm->mutex);
468
469 for (i = 0; i < NUM_PHY_CTX; i++)
470 if (!mvm->phy_ctxts[i].ref)
471 return &mvm->phy_ctxts[i];
472
473 IWL_ERR(mvm, "No available PHY context\n");
474 return NULL;
475 }
476
477 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
478 struct ieee80211_vif *vif)
479 {
480 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
481 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
482 int ret;
483
484 /*
485 * Not much to do here. The stack will not allow interface
486 * types or combinations that we didn't advertise, so we
487 * don't really have to check the types.
488 */
489
490 mutex_lock(&mvm->mutex);
491
492 /* Allocate resources for the MAC context, and add it the the fw */
493 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
494 if (ret)
495 goto out_unlock;
496
497 /*
498 * The AP binding flow can be done only after the beacon
499 * template is configured (which happens only in the mac80211
500 * start_ap() flow), and adding the broadcast station can happen
501 * only after the binding.
502 * In addition, since modifying the MAC before adding a bcast
503 * station is not allowed by the FW, delay the adding of MAC context to
504 * the point where we can also add the bcast station.
505 * In short: there's not much we can do at this point, other than
506 * allocating resources :)
507 */
508 if (vif->type == NL80211_IFTYPE_AP) {
509 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
510 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
511 qmask);
512 if (ret) {
513 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
514 goto out_release;
515 }
516
517 goto out_unlock;
518 }
519
520 /*
521 * TODO: remove this temporary code.
522 * Currently MVM FW supports power management only on single MAC.
523 * If new interface added, disable PM on existing interface.
524 * P2P device is a special case, since it is handled by FW similary to
525 * scan. If P2P deviced is added, PM remains enabled on existing
526 * interface.
527 * Note: the method below does not count the new interface being added
528 * at this moment.
529 */
530 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
531 mvm->vif_count++;
532 if (mvm->vif_count > 1) {
533 IWL_DEBUG_MAC80211(mvm,
534 "Disable power on existing interfaces\n");
535 ieee80211_iterate_active_interfaces_atomic(
536 mvm->hw,
537 IEEE80211_IFACE_ITER_NORMAL,
538 iwl_mvm_pm_disable_iterator, mvm);
539 }
540
541 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
542 if (ret)
543 goto out_release;
544
545 /*
546 * Update power state on the new interface. Admittedly, based on
547 * mac80211 logics this power update will disable power management
548 */
549 iwl_mvm_power_update_mode(mvm, vif);
550
551 /* beacon filtering */
552 if (!mvm->bf_allowed_vif &&
553 vif->type == NL80211_IFTYPE_STATION && !vif->p2p){
554 mvm->bf_allowed_vif = mvmvif;
555 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
556 }
557
558 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
559 if (ret)
560 goto out_release;
561
562 /*
563 * P2P_DEVICE interface does not have a channel context assigned to it,
564 * so a dedicated PHY context is allocated to it and the corresponding
565 * MAC context is bound to it at this stage.
566 */
567 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
568
569 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
570 if (!mvmvif->phy_ctxt) {
571 ret = -ENOSPC;
572 goto out_remove_mac;
573 }
574
575 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
576 ret = iwl_mvm_binding_add_vif(mvm, vif);
577 if (ret)
578 goto out_unref_phy;
579
580 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
581 if (ret)
582 goto out_unbind;
583
584 /* Save a pointer to p2p device vif, so it can later be used to
585 * update the p2p device MAC when a GO is started/stopped */
586 mvm->p2p_device_vif = vif;
587 }
588
589 iwl_mvm_vif_dbgfs_register(mvm, vif);
590 goto out_unlock;
591
592 out_unbind:
593 iwl_mvm_binding_remove_vif(mvm, vif);
594 out_unref_phy:
595 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
596 out_remove_mac:
597 mvmvif->phy_ctxt = NULL;
598 iwl_mvm_mac_ctxt_remove(mvm, vif);
599 out_release:
600 /*
601 * TODO: remove this temporary code.
602 * Currently MVM FW supports power management only on single MAC.
603 * Check if only one additional interface remains after releasing
604 * current one. Update power mode on the remaining interface.
605 */
606 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
607 mvm->vif_count--;
608 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
609 mvm->vif_count);
610 if (mvm->vif_count == 1) {
611 ieee80211_iterate_active_interfaces(
612 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
613 iwl_mvm_power_update_iterator, mvm);
614 }
615 iwl_mvm_mac_ctxt_release(mvm, vif);
616 out_unlock:
617 mutex_unlock(&mvm->mutex);
618
619 return ret;
620 }
621
622 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
623 struct ieee80211_vif *vif)
624 {
625 u32 tfd_msk = 0, ac;
626
627 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
628 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
629 tfd_msk |= BIT(vif->hw_queue[ac]);
630
631 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
632 tfd_msk |= BIT(vif->cab_queue);
633
634 if (tfd_msk) {
635 mutex_lock(&mvm->mutex);
636 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
637 mutex_unlock(&mvm->mutex);
638 }
639
640 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
641 /*
642 * Flush the ROC worker which will flush the OFFCHANNEL queue.
643 * We assume here that all the packets sent to the OFFCHANNEL
644 * queue are sent in ROC session.
645 */
646 flush_work(&mvm->roc_done_wk);
647 } else {
648 /*
649 * By now, all the AC queues are empty. The AGG queues are
650 * empty too. We already got all the Tx responses for all the
651 * packets in the queues. The drain work can have been
652 * triggered. Flush it. This work item takes the mutex, so kill
653 * it before we take it.
654 */
655 flush_work(&mvm->sta_drained_wk);
656 }
657 }
658
659 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
660 struct ieee80211_vif *vif)
661 {
662 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
663 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
664
665 iwl_mvm_prepare_mac_removal(mvm, vif);
666
667 mutex_lock(&mvm->mutex);
668
669 if (mvm->bf_allowed_vif == mvmvif) {
670 mvm->bf_allowed_vif = NULL;
671 vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
672 }
673
674 iwl_mvm_vif_dbgfs_clean(mvm, vif);
675
676 /*
677 * For AP/GO interface, the tear down of the resources allocated to the
678 * interface is be handled as part of the stop_ap flow.
679 */
680 if (vif->type == NL80211_IFTYPE_AP) {
681 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
682 goto out_release;
683 }
684
685 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
686 mvm->p2p_device_vif = NULL;
687 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
688 iwl_mvm_binding_remove_vif(mvm, vif);
689 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
690 mvmvif->phy_ctxt = NULL;
691 }
692
693 /*
694 * TODO: remove this temporary code.
695 * Currently MVM FW supports power management only on single MAC.
696 * Check if only one additional interface remains after removing
697 * current one. Update power mode on the remaining interface.
698 */
699 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
700 mvm->vif_count--;
701 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
702 mvm->vif_count);
703 if (mvm->vif_count == 1) {
704 ieee80211_iterate_active_interfaces(
705 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
706 iwl_mvm_power_update_iterator, mvm);
707 }
708
709 iwl_mvm_mac_ctxt_remove(mvm, vif);
710
711 out_release:
712 iwl_mvm_mac_ctxt_release(mvm, vif);
713 mutex_unlock(&mvm->mutex);
714 }
715
716 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
717 {
718 return 0;
719 }
720
721 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
722 unsigned int changed_flags,
723 unsigned int *total_flags,
724 u64 multicast)
725 {
726 *total_flags = 0;
727 }
728
729 static int iwl_mvm_configure_mcast_filter(struct iwl_mvm *mvm,
730 struct ieee80211_vif *vif)
731 {
732 struct iwl_mcast_filter_cmd mcast_filter_cmd = {
733 .pass_all = 1,
734 };
735
736 memcpy(mcast_filter_cmd.bssid, vif->bss_conf.bssid, ETH_ALEN);
737
738 return iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC,
739 sizeof(mcast_filter_cmd),
740 &mcast_filter_cmd);
741 }
742
743 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
744 struct ieee80211_vif *vif,
745 struct ieee80211_bss_conf *bss_conf,
746 u32 changes)
747 {
748 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
749 int ret;
750
751 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
752 if (ret)
753 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
754
755 if (changes & BSS_CHANGED_ASSOC) {
756 if (bss_conf->assoc) {
757 /* add quota for this interface */
758 ret = iwl_mvm_update_quotas(mvm, vif);
759 if (ret) {
760 IWL_ERR(mvm, "failed to update quotas\n");
761 return;
762 }
763 iwl_mvm_bt_coex_vif_assoc(mvm, vif);
764 iwl_mvm_configure_mcast_filter(mvm, vif);
765 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
766 /* remove AP station now that the MAC is unassoc */
767 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
768 if (ret)
769 IWL_ERR(mvm, "failed to remove AP station\n");
770 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
771 /* remove quota for this interface */
772 ret = iwl_mvm_update_quotas(mvm, NULL);
773 if (ret)
774 IWL_ERR(mvm, "failed to update quotas\n");
775 }
776 } else if (changes & BSS_CHANGED_DTIM_PERIOD) {
777 /*
778 * We received a beacon _after_ association so
779 * remove the session protection.
780 */
781 iwl_mvm_remove_time_event(mvm, mvmvif,
782 &mvmvif->time_event_data);
783 } else if (changes & BSS_CHANGED_PS) {
784 /*
785 * TODO: remove this temporary code.
786 * Currently MVM FW supports power management only on single
787 * MAC. Avoid power mode update if more than one interface
788 * is active.
789 */
790 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
791 mvm->vif_count);
792 if (mvm->vif_count == 1) {
793 ret = iwl_mvm_power_update_mode(mvm, vif);
794 if (ret)
795 IWL_ERR(mvm, "failed to update power mode\n");
796 }
797 }
798 }
799
800 static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
801 {
802 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
803 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
804 int ret;
805
806 mutex_lock(&mvm->mutex);
807
808 /* Send the beacon template */
809 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
810 if (ret)
811 goto out_unlock;
812
813 /* Add the mac context */
814 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
815 if (ret)
816 goto out_unlock;
817
818 /* Perform the binding */
819 ret = iwl_mvm_binding_add_vif(mvm, vif);
820 if (ret)
821 goto out_remove;
822
823 mvmvif->ap_active = true;
824
825 /* Send the bcast station. At this stage the TBTT and DTIM time events
826 * are added and applied to the scheduler */
827 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
828 if (ret)
829 goto out_unbind;
830
831 ret = iwl_mvm_update_quotas(mvm, vif);
832 if (ret)
833 goto out_rm_bcast;
834
835 /* Need to update the P2P Device MAC */
836 if (vif->p2p && mvm->p2p_device_vif)
837 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
838
839 mutex_unlock(&mvm->mutex);
840 return 0;
841
842 out_rm_bcast:
843 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
844 out_unbind:
845 iwl_mvm_binding_remove_vif(mvm, vif);
846 out_remove:
847 iwl_mvm_mac_ctxt_remove(mvm, vif);
848 out_unlock:
849 mutex_unlock(&mvm->mutex);
850 return ret;
851 }
852
853 static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
854 {
855 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
856 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
857
858 iwl_mvm_prepare_mac_removal(mvm, vif);
859
860 mutex_lock(&mvm->mutex);
861
862 mvmvif->ap_active = false;
863
864 /* Need to update the P2P Device MAC */
865 if (vif->p2p && mvm->p2p_device_vif)
866 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
867
868 iwl_mvm_update_quotas(mvm, NULL);
869 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
870 iwl_mvm_binding_remove_vif(mvm, vif);
871 iwl_mvm_mac_ctxt_remove(mvm, vif);
872
873 mutex_unlock(&mvm->mutex);
874 }
875
876 static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm,
877 struct ieee80211_vif *vif,
878 struct ieee80211_bss_conf *bss_conf,
879 u32 changes)
880 {
881 /* Need to send a new beacon template to the FW */
882 if (changes & BSS_CHANGED_BEACON) {
883 if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
884 IWL_WARN(mvm, "Failed updating beacon data\n");
885 }
886 }
887
888 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
889 struct ieee80211_vif *vif,
890 struct ieee80211_bss_conf *bss_conf,
891 u32 changes)
892 {
893 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
894
895 mutex_lock(&mvm->mutex);
896
897 switch (vif->type) {
898 case NL80211_IFTYPE_STATION:
899 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
900 break;
901 case NL80211_IFTYPE_AP:
902 iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes);
903 break;
904 default:
905 /* shouldn't happen */
906 WARN_ON_ONCE(1);
907 }
908
909 mutex_unlock(&mvm->mutex);
910 }
911
912 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
913 struct ieee80211_vif *vif,
914 struct cfg80211_scan_request *req)
915 {
916 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
917 int ret;
918
919 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
920 return -EINVAL;
921
922 mutex_lock(&mvm->mutex);
923
924 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
925 ret = iwl_mvm_scan_request(mvm, vif, req);
926 else
927 ret = -EBUSY;
928
929 mutex_unlock(&mvm->mutex);
930
931 return ret;
932 }
933
934 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
935 struct ieee80211_vif *vif)
936 {
937 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
938
939 mutex_lock(&mvm->mutex);
940
941 iwl_mvm_cancel_scan(mvm);
942
943 mutex_unlock(&mvm->mutex);
944 }
945
946 static void
947 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
948 struct ieee80211_sta *sta, u16 tid,
949 int num_frames,
950 enum ieee80211_frame_release_type reason,
951 bool more_data)
952 {
953 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
954
955 /* TODO: how do we tell the fw to send frames for a specific TID */
956
957 /*
958 * The fw will send EOSP notification when the last frame will be
959 * transmitted.
960 */
961 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
962 }
963
964 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
965 struct ieee80211_vif *vif,
966 enum sta_notify_cmd cmd,
967 struct ieee80211_sta *sta)
968 {
969 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
970 struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv;
971
972 switch (cmd) {
973 case STA_NOTIFY_SLEEP:
974 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
975 ieee80211_sta_block_awake(hw, sta, true);
976 /*
977 * The fw updates the STA to be asleep. Tx packets on the Tx
978 * queues to this station will not be transmitted. The fw will
979 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
980 */
981 break;
982 case STA_NOTIFY_AWAKE:
983 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
984 break;
985 iwl_mvm_sta_modify_ps_wake(mvm, sta);
986 break;
987 default:
988 break;
989 }
990 }
991
992 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
993 struct ieee80211_vif *vif,
994 struct ieee80211_sta *sta,
995 enum ieee80211_sta_state old_state,
996 enum ieee80211_sta_state new_state)
997 {
998 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
999 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1000 int ret;
1001
1002 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1003 sta->addr, old_state, new_state);
1004
1005 /* this would be a mac80211 bug ... but don't crash */
1006 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1007 return -EINVAL;
1008
1009 /* if a STA is being removed, reuse its ID */
1010 flush_work(&mvm->sta_drained_wk);
1011
1012 mutex_lock(&mvm->mutex);
1013 if (old_state == IEEE80211_STA_NOTEXIST &&
1014 new_state == IEEE80211_STA_NONE) {
1015 ret = iwl_mvm_add_sta(mvm, vif, sta);
1016 } else if (old_state == IEEE80211_STA_NONE &&
1017 new_state == IEEE80211_STA_AUTH) {
1018 ret = 0;
1019 } else if (old_state == IEEE80211_STA_AUTH &&
1020 new_state == IEEE80211_STA_ASSOC) {
1021 ret = iwl_mvm_update_sta(mvm, vif, sta);
1022 if (ret == 0)
1023 iwl_mvm_rs_rate_init(mvm, sta,
1024 mvmvif->phy_ctxt->channel->band);
1025 } else if (old_state == IEEE80211_STA_ASSOC &&
1026 new_state == IEEE80211_STA_AUTHORIZED) {
1027 /* enable beacon filtering */
1028 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
1029 ret = 0;
1030 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1031 new_state == IEEE80211_STA_ASSOC) {
1032 /* disable beacon filtering */
1033 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
1034 ret = 0;
1035 } else if (old_state == IEEE80211_STA_ASSOC &&
1036 new_state == IEEE80211_STA_AUTH) {
1037 ret = 0;
1038 } else if (old_state == IEEE80211_STA_AUTH &&
1039 new_state == IEEE80211_STA_NONE) {
1040 ret = 0;
1041 } else if (old_state == IEEE80211_STA_NONE &&
1042 new_state == IEEE80211_STA_NOTEXIST) {
1043 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1044 } else {
1045 ret = -EIO;
1046 }
1047 mutex_unlock(&mvm->mutex);
1048
1049 return ret;
1050 }
1051
1052 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1053 {
1054 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1055
1056 mvm->rts_threshold = value;
1057
1058 return 0;
1059 }
1060
1061 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1062 struct ieee80211_vif *vif, u16 ac,
1063 const struct ieee80211_tx_queue_params *params)
1064 {
1065 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1066 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1067
1068 mvmvif->queue_params[ac] = *params;
1069
1070 /*
1071 * No need to update right away, we'll get BSS_CHANGED_QOS
1072 * The exception is P2P_DEVICE interface which needs immediate update.
1073 */
1074 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1075 int ret;
1076
1077 mutex_lock(&mvm->mutex);
1078 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1079 mutex_unlock(&mvm->mutex);
1080 return ret;
1081 }
1082 return 0;
1083 }
1084
1085 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1086 struct ieee80211_vif *vif)
1087 {
1088 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1089 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1090 200 + vif->bss_conf.beacon_int);
1091 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1092 100 + vif->bss_conf.beacon_int);
1093
1094 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1095 return;
1096
1097 mutex_lock(&mvm->mutex);
1098 /* Try really hard to protect the session and hear a beacon */
1099 iwl_mvm_protect_session(mvm, vif, duration, min_duration);
1100 mutex_unlock(&mvm->mutex);
1101 }
1102
1103 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1104 enum set_key_cmd cmd,
1105 struct ieee80211_vif *vif,
1106 struct ieee80211_sta *sta,
1107 struct ieee80211_key_conf *key)
1108 {
1109 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1110 int ret;
1111
1112 if (iwlwifi_mod_params.sw_crypto) {
1113 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1114 return -EOPNOTSUPP;
1115 }
1116
1117 switch (key->cipher) {
1118 case WLAN_CIPHER_SUITE_TKIP:
1119 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1120 /* fall-through */
1121 case WLAN_CIPHER_SUITE_CCMP:
1122 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1123 break;
1124 case WLAN_CIPHER_SUITE_AES_CMAC:
1125 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1126 break;
1127 case WLAN_CIPHER_SUITE_WEP40:
1128 case WLAN_CIPHER_SUITE_WEP104:
1129 /*
1130 * Support for TX only, at least for now, so accept
1131 * the key and do nothing else. Then mac80211 will
1132 * pass it for TX but we don't have to use it for RX.
1133 */
1134 return 0;
1135 default:
1136 return -EOPNOTSUPP;
1137 }
1138
1139 mutex_lock(&mvm->mutex);
1140
1141 switch (cmd) {
1142 case SET_KEY:
1143 if (vif->type == NL80211_IFTYPE_AP && !sta) {
1144 /* GTK on AP interface is a TX-only key, return 0 */
1145 ret = 0;
1146 key->hw_key_idx = STA_KEY_IDX_INVALID;
1147 break;
1148 }
1149
1150 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1151 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1152 if (ret) {
1153 IWL_WARN(mvm, "set key failed\n");
1154 /*
1155 * can't add key for RX, but we don't need it
1156 * in the device for TX so still return 0
1157 */
1158 key->hw_key_idx = STA_KEY_IDX_INVALID;
1159 ret = 0;
1160 }
1161
1162 break;
1163 case DISABLE_KEY:
1164 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1165 ret = 0;
1166 break;
1167 }
1168
1169 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1170 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1171 break;
1172 default:
1173 ret = -EINVAL;
1174 }
1175
1176 mutex_unlock(&mvm->mutex);
1177 return ret;
1178 }
1179
1180 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1181 struct ieee80211_vif *vif,
1182 struct ieee80211_key_conf *keyconf,
1183 struct ieee80211_sta *sta,
1184 u32 iv32, u16 *phase1key)
1185 {
1186 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1187
1188 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1189 }
1190
1191
1192 static int iwl_mvm_roc(struct ieee80211_hw *hw,
1193 struct ieee80211_vif *vif,
1194 struct ieee80211_channel *channel,
1195 int duration,
1196 enum ieee80211_roc_type type)
1197 {
1198 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1199 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1200 struct cfg80211_chan_def chandef;
1201 struct iwl_mvm_phy_ctxt *phy_ctxt;
1202 int ret, i;
1203
1204 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1205 duration, type);
1206
1207 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1208 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1209 return -EINVAL;
1210 }
1211
1212 mutex_lock(&mvm->mutex);
1213
1214 for (i = 0; i < NUM_PHY_CTX; i++) {
1215 phy_ctxt = &mvm->phy_ctxts[i];
1216 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
1217 continue;
1218
1219 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1220 /*
1221 * Unbind the P2P_DEVICE from the current PHY context,
1222 * and if the PHY context is not used remove it.
1223 */
1224 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1225 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1226 goto out_unlock;
1227
1228 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1229
1230 /* Bind the P2P_DEVICE to the current PHY Context */
1231 mvmvif->phy_ctxt = phy_ctxt;
1232
1233 ret = iwl_mvm_binding_add_vif(mvm, vif);
1234 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1235 goto out_unlock;
1236
1237 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1238 goto schedule_time_event;
1239 }
1240 }
1241
1242 /* Need to update the PHY context only if the ROC channel changed */
1243 if (channel == mvmvif->phy_ctxt->channel)
1244 goto schedule_time_event;
1245
1246 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
1247
1248 /*
1249 * Change the PHY context configuration as it is currently referenced
1250 * only by the P2P Device MAC
1251 */
1252 if (mvmvif->phy_ctxt->ref == 1) {
1253 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
1254 &chandef, 1, 1);
1255 if (ret)
1256 goto out_unlock;
1257 } else {
1258 /*
1259 * The PHY context is shared with other MACs. Need to remove the
1260 * P2P Device from the binding, allocate an new PHY context and
1261 * create a new binding
1262 */
1263 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1264 if (!phy_ctxt) {
1265 ret = -ENOSPC;
1266 goto out_unlock;
1267 }
1268
1269 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
1270 1, 1);
1271 if (ret) {
1272 IWL_ERR(mvm, "Failed to change PHY context\n");
1273 goto out_unlock;
1274 }
1275
1276 /* Unbind the P2P_DEVICE from the current PHY context */
1277 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1278 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1279 goto out_unlock;
1280
1281 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1282
1283 /* Bind the P2P_DEVICE to the new allocated PHY context */
1284 mvmvif->phy_ctxt = phy_ctxt;
1285
1286 ret = iwl_mvm_binding_add_vif(mvm, vif);
1287 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1288 goto out_unlock;
1289
1290 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1291 }
1292
1293 schedule_time_event:
1294 /* Schedule the time events */
1295 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
1296
1297 out_unlock:
1298 mutex_unlock(&mvm->mutex);
1299 IWL_DEBUG_MAC80211(mvm, "leave\n");
1300 return ret;
1301 }
1302
1303 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1304 {
1305 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1306
1307 IWL_DEBUG_MAC80211(mvm, "enter\n");
1308
1309 mutex_lock(&mvm->mutex);
1310 iwl_mvm_stop_p2p_roc(mvm);
1311 mutex_unlock(&mvm->mutex);
1312
1313 IWL_DEBUG_MAC80211(mvm, "leave\n");
1314 return 0;
1315 }
1316
1317 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1318 struct ieee80211_chanctx_conf *ctx)
1319 {
1320 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1321 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1322 struct iwl_mvm_phy_ctxt *phy_ctxt;
1323 int ret;
1324
1325 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
1326
1327 mutex_lock(&mvm->mutex);
1328 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1329 if (!phy_ctxt) {
1330 ret = -ENOSPC;
1331 goto out;
1332 }
1333
1334 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1335 ctx->rx_chains_static,
1336 ctx->rx_chains_dynamic);
1337 if (ret) {
1338 IWL_ERR(mvm, "Failed to add PHY context\n");
1339 goto out;
1340 }
1341
1342 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
1343 *phy_ctxt_id = phy_ctxt->id;
1344 out:
1345 mutex_unlock(&mvm->mutex);
1346 return ret;
1347 }
1348
1349 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
1350 struct ieee80211_chanctx_conf *ctx)
1351 {
1352 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1353 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1354 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
1355
1356 mutex_lock(&mvm->mutex);
1357 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
1358 mutex_unlock(&mvm->mutex);
1359 }
1360
1361 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
1362 struct ieee80211_chanctx_conf *ctx,
1363 u32 changed)
1364 {
1365 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1366 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1367 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
1368
1369 if (WARN_ONCE((phy_ctxt->ref > 1) &&
1370 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
1371 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
1372 IEEE80211_CHANCTX_CHANGE_RADAR)),
1373 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1374 phy_ctxt->ref, changed))
1375 return;
1376
1377 mutex_lock(&mvm->mutex);
1378 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1379 ctx->rx_chains_static,
1380 ctx->rx_chains_dynamic);
1381 mutex_unlock(&mvm->mutex);
1382 }
1383
1384 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
1385 struct ieee80211_vif *vif,
1386 struct ieee80211_chanctx_conf *ctx)
1387 {
1388 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1389 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1390 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
1391 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1392 int ret;
1393
1394 mutex_lock(&mvm->mutex);
1395
1396 mvmvif->phy_ctxt = phy_ctxt;
1397
1398 switch (vif->type) {
1399 case NL80211_IFTYPE_AP:
1400 /*
1401 * The AP binding flow is handled as part of the start_ap flow
1402 * (in bss_info_changed).
1403 */
1404 ret = 0;
1405 goto out_unlock;
1406 case NL80211_IFTYPE_STATION:
1407 case NL80211_IFTYPE_ADHOC:
1408 case NL80211_IFTYPE_MONITOR:
1409 break;
1410 default:
1411 ret = -EINVAL;
1412 goto out_unlock;
1413 }
1414
1415 ret = iwl_mvm_binding_add_vif(mvm, vif);
1416 if (ret)
1417 goto out_unlock;
1418
1419 /*
1420 * Setting the quota at this stage is only required for monitor
1421 * interfaces. For the other types, the bss_info changed flow
1422 * will handle quota settings.
1423 */
1424 if (vif->type == NL80211_IFTYPE_MONITOR) {
1425 mvmvif->monitor_active = true;
1426 ret = iwl_mvm_update_quotas(mvm, vif);
1427 if (ret)
1428 goto out_remove_binding;
1429 }
1430
1431 goto out_unlock;
1432
1433 out_remove_binding:
1434 iwl_mvm_binding_remove_vif(mvm, vif);
1435 out_unlock:
1436 mutex_unlock(&mvm->mutex);
1437 if (ret)
1438 mvmvif->phy_ctxt = NULL;
1439 return ret;
1440 }
1441
1442 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
1443 struct ieee80211_vif *vif,
1444 struct ieee80211_chanctx_conf *ctx)
1445 {
1446 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1447 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1448
1449 mutex_lock(&mvm->mutex);
1450
1451 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
1452
1453 if (vif->type == NL80211_IFTYPE_AP)
1454 goto out_unlock;
1455
1456 switch (vif->type) {
1457 case NL80211_IFTYPE_MONITOR:
1458 mvmvif->monitor_active = false;
1459 iwl_mvm_update_quotas(mvm, NULL);
1460 break;
1461 default:
1462 break;
1463 }
1464
1465 iwl_mvm_binding_remove_vif(mvm, vif);
1466 out_unlock:
1467 mvmvif->phy_ctxt = NULL;
1468 mutex_unlock(&mvm->mutex);
1469 }
1470
1471 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
1472 struct ieee80211_sta *sta,
1473 bool set)
1474 {
1475 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1476 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1477
1478 if (!mvm_sta || !mvm_sta->vif) {
1479 IWL_ERR(mvm, "Station is not associated to a vif\n");
1480 return -EINVAL;
1481 }
1482
1483 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
1484 }
1485
1486 static void iwl_mvm_mac_rssi_callback(struct ieee80211_hw *hw,
1487 struct ieee80211_vif *vif,
1488 enum ieee80211_rssi_event rssi_event)
1489 {
1490 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1491
1492 iwl_mvm_bt_rssi_event(mvm, vif, rssi_event);
1493 }
1494
1495 struct ieee80211_ops iwl_mvm_hw_ops = {
1496 .tx = iwl_mvm_mac_tx,
1497 .ampdu_action = iwl_mvm_mac_ampdu_action,
1498 .start = iwl_mvm_mac_start,
1499 .restart_complete = iwl_mvm_mac_restart_complete,
1500 .stop = iwl_mvm_mac_stop,
1501 .add_interface = iwl_mvm_mac_add_interface,
1502 .remove_interface = iwl_mvm_mac_remove_interface,
1503 .config = iwl_mvm_mac_config,
1504 .configure_filter = iwl_mvm_configure_filter,
1505 .bss_info_changed = iwl_mvm_bss_info_changed,
1506 .hw_scan = iwl_mvm_mac_hw_scan,
1507 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1508 .sta_state = iwl_mvm_mac_sta_state,
1509 .sta_notify = iwl_mvm_mac_sta_notify,
1510 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
1511 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1512 .conf_tx = iwl_mvm_mac_conf_tx,
1513 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
1514 .set_key = iwl_mvm_mac_set_key,
1515 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
1516 .remain_on_channel = iwl_mvm_roc,
1517 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
1518 .rssi_callback = iwl_mvm_mac_rssi_callback,
1519
1520 .add_chanctx = iwl_mvm_add_chanctx,
1521 .remove_chanctx = iwl_mvm_remove_chanctx,
1522 .change_chanctx = iwl_mvm_change_chanctx,
1523 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
1524 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
1525
1526 .start_ap = iwl_mvm_start_ap,
1527 .stop_ap = iwl_mvm_stop_ap,
1528
1529 .set_tim = iwl_mvm_set_tim,
1530
1531 #ifdef CONFIG_PM_SLEEP
1532 /* look at d3.c */
1533 .suspend = iwl_mvm_suspend,
1534 .resume = iwl_mvm_resume,
1535 .set_wakeup = iwl_mvm_set_wakeup,
1536 .set_rekey_data = iwl_mvm_set_rekey_data,
1537 #if IS_ENABLED(CONFIG_IPV6)
1538 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
1539 #endif
1540 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
1541 #endif
1542 };
This page took 0.082292 seconds and 6 git commands to generate.