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