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