]>
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: | |
e3d9e7ce EG |
287 | ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); |
288 | break; | |
8ca151b5 JB |
289 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
290 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
e3d9e7ce | 291 | ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); |
8ca151b5 JB |
292 | break; |
293 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
294 | ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size); | |
295 | break; | |
296 | default: | |
297 | WARN_ON_ONCE(1); | |
298 | ret = -EINVAL; | |
299 | break; | |
300 | } | |
301 | mutex_unlock(&mvm->mutex); | |
302 | ||
303 | return ret; | |
304 | } | |
305 | ||
306 | static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, | |
307 | struct ieee80211_vif *vif) | |
308 | { | |
309 | struct iwl_mvm *mvm = data; | |
310 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
311 | ||
312 | mvmvif->uploaded = false; | |
313 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; | |
314 | ||
315 | /* does this make sense at all? */ | |
316 | mvmvif->color++; | |
317 | ||
318 | spin_lock_bh(&mvm->time_event_lock); | |
319 | iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); | |
320 | spin_unlock_bh(&mvm->time_event_lock); | |
321 | ||
322 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) | |
323 | mvmvif->phy_ctxt = NULL; | |
324 | } | |
325 | ||
326 | static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) | |
327 | { | |
328 | iwl_trans_stop_device(mvm->trans); | |
329 | iwl_trans_stop_hw(mvm->trans, false); | |
330 | ||
331 | mvm->scan_status = IWL_MVM_SCAN_NONE; | |
332 | ||
333 | /* just in case one was running */ | |
334 | ieee80211_remain_on_channel_expired(mvm->hw); | |
335 | ||
336 | ieee80211_iterate_active_interfaces_atomic( | |
337 | mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL, | |
338 | iwl_mvm_cleanup_iterator, mvm); | |
339 | ||
340 | memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); | |
341 | memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained)); | |
342 | ||
343 | ieee80211_wake_queues(mvm->hw); | |
344 | ||
345 | mvm->vif_count = 0; | |
346 | } | |
347 | ||
348 | static int iwl_mvm_mac_start(struct ieee80211_hw *hw) | |
349 | { | |
350 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
351 | int ret; | |
352 | ||
353 | mutex_lock(&mvm->mutex); | |
354 | ||
355 | /* Clean up some internal and mac80211 state on restart */ | |
356 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) | |
357 | iwl_mvm_restart_cleanup(mvm); | |
358 | ||
359 | ret = iwl_mvm_up(mvm); | |
360 | mutex_unlock(&mvm->mutex); | |
361 | ||
362 | return ret; | |
363 | } | |
364 | ||
365 | static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw) | |
366 | { | |
367 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
368 | int ret; | |
369 | ||
370 | mutex_lock(&mvm->mutex); | |
371 | ||
372 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); | |
373 | ret = iwl_mvm_update_quotas(mvm, NULL); | |
374 | if (ret) | |
375 | IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", | |
376 | ret); | |
377 | ||
378 | mutex_unlock(&mvm->mutex); | |
379 | } | |
380 | ||
381 | static void iwl_mvm_mac_stop(struct ieee80211_hw *hw) | |
382 | { | |
383 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
384 | ||
385 | flush_work(&mvm->async_handlers_wk); | |
386 | ||
387 | mutex_lock(&mvm->mutex); | |
388 | /* async_handlers_wk is now blocked */ | |
389 | ||
390 | /* | |
391 | * The work item could be running or queued if the | |
392 | * ROC time event stops just as we get here. | |
393 | */ | |
394 | cancel_work_sync(&mvm->roc_done_wk); | |
395 | ||
396 | iwl_trans_stop_device(mvm->trans); | |
397 | iwl_trans_stop_hw(mvm->trans, false); | |
398 | ||
399 | iwl_mvm_async_handlers_purge(mvm); | |
400 | /* async_handlers_list is empty and will stay empty: HW is stopped */ | |
401 | ||
402 | /* the fw is stopped, the aux sta is dead: clean up driver state */ | |
403 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); | |
404 | ||
405 | mutex_unlock(&mvm->mutex); | |
406 | ||
407 | /* | |
408 | * The worker might have been waiting for the mutex, let it run and | |
409 | * discover that its list is now empty. | |
410 | */ | |
411 | cancel_work_sync(&mvm->async_handlers_wk); | |
412 | } | |
413 | ||
414 | static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac, | |
415 | struct ieee80211_vif *vif) | |
416 | { | |
417 | struct iwl_mvm *mvm = data; | |
418 | int ret; | |
419 | ||
420 | ret = iwl_mvm_power_disable(mvm, vif); | |
421 | if (ret) | |
422 | IWL_ERR(mvm, "failed to disable power management\n"); | |
423 | } | |
424 | ||
425 | static void iwl_mvm_power_update_iterator(void *data, u8 *mac, | |
426 | struct ieee80211_vif *vif) | |
427 | { | |
428 | struct iwl_mvm *mvm = data; | |
429 | ||
430 | iwl_mvm_power_update_mode(mvm, vif); | |
431 | } | |
432 | ||
433 | static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, | |
434 | struct ieee80211_vif *vif) | |
435 | { | |
436 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
437 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
438 | int ret; | |
439 | ||
440 | /* | |
441 | * Not much to do here. The stack will not allow interface | |
442 | * types or combinations that we didn't advertise, so we | |
443 | * don't really have to check the types. | |
444 | */ | |
445 | ||
446 | mutex_lock(&mvm->mutex); | |
447 | ||
448 | /* Allocate resources for the MAC context, and add it the the fw */ | |
449 | ret = iwl_mvm_mac_ctxt_init(mvm, vif); | |
450 | if (ret) | |
451 | goto out_unlock; | |
452 | ||
453 | /* | |
454 | * The AP binding flow can be done only after the beacon | |
455 | * template is configured (which happens only in the mac80211 | |
456 | * start_ap() flow), and adding the broadcast station can happen | |
457 | * only after the binding. | |
458 | * In addition, since modifying the MAC before adding a bcast | |
459 | * station is not allowed by the FW, delay the adding of MAC context to | |
460 | * the point where we can also add the bcast station. | |
461 | * In short: there's not much we can do at this point, other than | |
462 | * allocating resources :) | |
463 | */ | |
464 | if (vif->type == NL80211_IFTYPE_AP) { | |
465 | u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif); | |
466 | ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, | |
467 | qmask); | |
468 | if (ret) { | |
469 | IWL_ERR(mvm, "Failed to allocate bcast sta\n"); | |
470 | goto out_release; | |
471 | } | |
472 | ||
473 | goto out_unlock; | |
474 | } | |
475 | ||
476 | /* | |
477 | * TODO: remove this temporary code. | |
478 | * Currently MVM FW supports power management only on single MAC. | |
479 | * Iterate and disable PM on all active interfaces. | |
480 | * Note: the method below does not count the new interface being added | |
481 | * at this moment. | |
482 | */ | |
483 | mvm->vif_count++; | |
484 | if (mvm->vif_count > 1) { | |
485 | IWL_DEBUG_MAC80211(mvm, | |
486 | "Disable power on existing interfaces\n"); | |
5360cfb2 | 487 | ieee80211_iterate_active_interfaces_atomic( |
8ca151b5 JB |
488 | mvm->hw, |
489 | IEEE80211_IFACE_ITER_NORMAL, | |
490 | iwl_mvm_pm_disable_iterator, mvm); | |
491 | } | |
492 | ||
493 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); | |
494 | if (ret) | |
495 | goto out_release; | |
496 | ||
497 | /* | |
498 | * Update power state on the new interface. Admittedly, based on | |
499 | * mac80211 logics this power update will disable power management | |
500 | */ | |
501 | iwl_mvm_power_update_mode(mvm, vif); | |
502 | ||
503 | /* | |
504 | * P2P_DEVICE interface does not have a channel context assigned to it, | |
505 | * so a dedicated PHY context is allocated to it and the corresponding | |
506 | * MAC context is bound to it at this stage. | |
507 | */ | |
508 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
509 | struct ieee80211_channel *chan; | |
510 | struct cfg80211_chan_def chandef; | |
511 | ||
512 | mvmvif->phy_ctxt = &mvm->phy_ctxt_roc; | |
513 | ||
514 | /* | |
515 | * The channel used here isn't relevant as it's | |
516 | * going to be overwritten as part of the ROC flow. | |
517 | * For now use the first channel we have. | |
518 | */ | |
519 | chan = &mvm->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels[0]; | |
520 | cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT); | |
521 | ret = iwl_mvm_phy_ctxt_add(mvm, mvmvif->phy_ctxt, | |
522 | &chandef, 1, 1); | |
523 | if (ret) | |
524 | goto out_remove_mac; | |
525 | ||
526 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
527 | if (ret) | |
528 | goto out_remove_phy; | |
529 | ||
530 | ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta); | |
531 | if (ret) | |
532 | goto out_unbind; | |
533 | ||
534 | /* Save a pointer to p2p device vif, so it can later be used to | |
535 | * update the p2p device MAC when a GO is started/stopped */ | |
536 | mvm->p2p_device_vif = vif; | |
537 | } | |
538 | ||
539 | goto out_unlock; | |
540 | ||
541 | out_unbind: | |
542 | iwl_mvm_binding_remove_vif(mvm, vif); | |
543 | out_remove_phy: | |
544 | iwl_mvm_phy_ctxt_remove(mvm, mvmvif->phy_ctxt); | |
545 | out_remove_mac: | |
546 | mvmvif->phy_ctxt = NULL; | |
547 | iwl_mvm_mac_ctxt_remove(mvm, vif); | |
548 | out_release: | |
549 | /* | |
550 | * TODO: remove this temporary code. | |
551 | * Currently MVM FW supports power management only on single MAC. | |
552 | * Check if only one additional interface remains after rereasing | |
553 | * current one. Update power mode on the remaining interface. | |
554 | */ | |
555 | mvm->vif_count--; | |
556 | IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n", | |
557 | mvm->vif_count); | |
558 | if (mvm->vif_count == 1) { | |
559 | ieee80211_iterate_active_interfaces( | |
560 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
561 | iwl_mvm_power_update_iterator, mvm); | |
562 | } | |
563 | iwl_mvm_mac_ctxt_release(mvm, vif); | |
564 | out_unlock: | |
565 | mutex_unlock(&mvm->mutex); | |
566 | ||
567 | return ret; | |
568 | } | |
569 | ||
38a12b5b JB |
570 | static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, |
571 | struct ieee80211_vif *vif) | |
8ca151b5 | 572 | { |
8ca151b5 JB |
573 | u32 tfd_msk = 0, ac; |
574 | ||
575 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) | |
576 | if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE) | |
577 | tfd_msk |= BIT(vif->hw_queue[ac]); | |
578 | ||
579 | if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE) | |
580 | tfd_msk |= BIT(vif->cab_queue); | |
581 | ||
582 | if (tfd_msk) { | |
583 | mutex_lock(&mvm->mutex); | |
584 | iwl_mvm_flush_tx_path(mvm, tfd_msk, true); | |
585 | mutex_unlock(&mvm->mutex); | |
586 | } | |
587 | ||
588 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
589 | /* | |
590 | * Flush the ROC worker which will flush the OFFCHANNEL queue. | |
591 | * We assume here that all the packets sent to the OFFCHANNEL | |
592 | * queue are sent in ROC session. | |
593 | */ | |
594 | flush_work(&mvm->roc_done_wk); | |
595 | } else { | |
596 | /* | |
597 | * By now, all the AC queues are empty. The AGG queues are | |
598 | * empty too. We already got all the Tx responses for all the | |
599 | * packets in the queues. The drain work can have been | |
600 | * triggered. Flush it. This work item takes the mutex, so kill | |
601 | * it before we take it. | |
602 | */ | |
603 | flush_work(&mvm->sta_drained_wk); | |
604 | } | |
38a12b5b JB |
605 | } |
606 | ||
607 | static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, | |
608 | struct ieee80211_vif *vif) | |
609 | { | |
610 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
611 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
612 | ||
613 | iwl_mvm_prepare_mac_removal(mvm, vif); | |
8ca151b5 JB |
614 | |
615 | mutex_lock(&mvm->mutex); | |
616 | ||
617 | /* | |
618 | * For AP/GO interface, the tear down of the resources allocated to the | |
38a12b5b | 619 | * interface is be handled as part of the stop_ap flow. |
8ca151b5 JB |
620 | */ |
621 | if (vif->type == NL80211_IFTYPE_AP) { | |
622 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); | |
623 | goto out_release; | |
624 | } | |
625 | ||
626 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
627 | mvm->p2p_device_vif = NULL; | |
628 | iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta); | |
629 | iwl_mvm_binding_remove_vif(mvm, vif); | |
630 | iwl_mvm_phy_ctxt_remove(mvm, mvmvif->phy_ctxt); | |
631 | mvmvif->phy_ctxt = NULL; | |
632 | } | |
633 | ||
634 | /* | |
635 | * TODO: remove this temporary code. | |
636 | * Currently MVM FW supports power management only on single MAC. | |
637 | * Check if only one additional interface remains after removing | |
638 | * current one. Update power mode on the remaining interface. | |
639 | */ | |
640 | if (mvm->vif_count) | |
641 | mvm->vif_count--; | |
642 | IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n", | |
643 | mvm->vif_count); | |
644 | if (mvm->vif_count == 1) { | |
645 | ieee80211_iterate_active_interfaces( | |
646 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
647 | iwl_mvm_power_update_iterator, mvm); | |
648 | } | |
649 | ||
650 | iwl_mvm_mac_ctxt_remove(mvm, vif); | |
651 | ||
652 | out_release: | |
653 | iwl_mvm_mac_ctxt_release(mvm, vif); | |
654 | mutex_unlock(&mvm->mutex); | |
655 | } | |
656 | ||
657 | static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed) | |
658 | { | |
659 | return 0; | |
660 | } | |
661 | ||
662 | static void iwl_mvm_configure_filter(struct ieee80211_hw *hw, | |
663 | unsigned int changed_flags, | |
664 | unsigned int *total_flags, | |
665 | u64 multicast) | |
666 | { | |
667 | *total_flags = 0; | |
668 | } | |
669 | ||
670 | static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, | |
671 | struct ieee80211_vif *vif, | |
672 | struct ieee80211_bss_conf *bss_conf, | |
673 | u32 changes) | |
674 | { | |
675 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
676 | int ret; | |
677 | ||
678 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); | |
679 | if (ret) | |
680 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); | |
681 | ||
682 | if (changes & BSS_CHANGED_ASSOC) { | |
683 | if (bss_conf->assoc) { | |
684 | /* add quota for this interface */ | |
685 | ret = iwl_mvm_update_quotas(mvm, vif); | |
686 | if (ret) { | |
687 | IWL_ERR(mvm, "failed to update quotas\n"); | |
688 | return; | |
689 | } | |
8ca151b5 JB |
690 | } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
691 | /* remove AP station now that the MAC is unassoc */ | |
692 | ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id); | |
693 | if (ret) | |
694 | IWL_ERR(mvm, "failed to remove AP station\n"); | |
695 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; | |
696 | /* remove quota for this interface */ | |
697 | ret = iwl_mvm_update_quotas(mvm, NULL); | |
698 | if (ret) | |
699 | IWL_ERR(mvm, "failed to update quotas\n"); | |
700 | } | |
210a544e JB |
701 | } else if (changes & BSS_CHANGED_DTIM_PERIOD) { |
702 | /* | |
703 | * We received a beacon _after_ association so | |
704 | * remove the session protection. | |
705 | */ | |
706 | iwl_mvm_remove_time_event(mvm, mvmvif, | |
707 | &mvmvif->time_event_data); | |
8ca151b5 JB |
708 | } else if (changes & BSS_CHANGED_PS) { |
709 | /* | |
710 | * TODO: remove this temporary code. | |
711 | * Currently MVM FW supports power management only on single | |
712 | * MAC. Avoid power mode update if more than one interface | |
713 | * is active. | |
714 | */ | |
715 | IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n", | |
716 | mvm->vif_count); | |
717 | if (mvm->vif_count == 1) { | |
718 | ret = iwl_mvm_power_update_mode(mvm, vif); | |
719 | if (ret) | |
720 | IWL_ERR(mvm, "failed to update power mode\n"); | |
721 | } | |
722 | } | |
723 | } | |
724 | ||
725 | static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif) | |
726 | { | |
727 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
728 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
729 | int ret; | |
730 | ||
731 | mutex_lock(&mvm->mutex); | |
732 | ||
733 | /* Send the beacon template */ | |
734 | ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif); | |
735 | if (ret) | |
736 | goto out_unlock; | |
737 | ||
738 | /* Add the mac context */ | |
739 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); | |
740 | if (ret) | |
741 | goto out_unlock; | |
742 | ||
743 | /* Perform the binding */ | |
744 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
745 | if (ret) | |
746 | goto out_remove; | |
747 | ||
748 | mvmvif->ap_active = true; | |
749 | ||
750 | /* Send the bcast station. At this stage the TBTT and DTIM time events | |
751 | * are added and applied to the scheduler */ | |
752 | ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta); | |
753 | if (ret) | |
754 | goto out_unbind; | |
755 | ||
756 | ret = iwl_mvm_update_quotas(mvm, vif); | |
757 | if (ret) | |
758 | goto out_rm_bcast; | |
759 | ||
760 | /* Need to update the P2P Device MAC */ | |
761 | if (vif->p2p && mvm->p2p_device_vif) | |
762 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif); | |
763 | ||
764 | mutex_unlock(&mvm->mutex); | |
765 | return 0; | |
766 | ||
767 | out_rm_bcast: | |
768 | iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta); | |
769 | out_unbind: | |
770 | iwl_mvm_binding_remove_vif(mvm, vif); | |
771 | out_remove: | |
772 | iwl_mvm_mac_ctxt_remove(mvm, vif); | |
773 | out_unlock: | |
774 | mutex_unlock(&mvm->mutex); | |
775 | return ret; | |
776 | } | |
777 | ||
778 | static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif) | |
779 | { | |
780 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
781 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
782 | ||
38a12b5b JB |
783 | iwl_mvm_prepare_mac_removal(mvm, vif); |
784 | ||
8ca151b5 JB |
785 | mutex_lock(&mvm->mutex); |
786 | ||
787 | mvmvif->ap_active = false; | |
788 | ||
789 | /* Need to update the P2P Device MAC */ | |
790 | if (vif->p2p && mvm->p2p_device_vif) | |
791 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif); | |
792 | ||
793 | iwl_mvm_update_quotas(mvm, NULL); | |
794 | iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta); | |
795 | iwl_mvm_binding_remove_vif(mvm, vif); | |
796 | iwl_mvm_mac_ctxt_remove(mvm, vif); | |
797 | ||
798 | mutex_unlock(&mvm->mutex); | |
799 | } | |
800 | ||
801 | static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm, | |
802 | struct ieee80211_vif *vif, | |
803 | struct ieee80211_bss_conf *bss_conf, | |
804 | u32 changes) | |
805 | { | |
806 | /* Need to send a new beacon template to the FW */ | |
807 | if (changes & BSS_CHANGED_BEACON) { | |
808 | if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif)) | |
809 | IWL_WARN(mvm, "Failed updating beacon data\n"); | |
810 | } | |
811 | } | |
812 | ||
813 | static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, | |
814 | struct ieee80211_vif *vif, | |
815 | struct ieee80211_bss_conf *bss_conf, | |
816 | u32 changes) | |
817 | { | |
818 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
819 | ||
820 | mutex_lock(&mvm->mutex); | |
821 | ||
822 | switch (vif->type) { | |
823 | case NL80211_IFTYPE_STATION: | |
824 | iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); | |
825 | break; | |
826 | case NL80211_IFTYPE_AP: | |
827 | iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes); | |
828 | break; | |
829 | default: | |
830 | /* shouldn't happen */ | |
831 | WARN_ON_ONCE(1); | |
832 | } | |
833 | ||
834 | mutex_unlock(&mvm->mutex); | |
835 | } | |
836 | ||
837 | static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, | |
838 | struct ieee80211_vif *vif, | |
839 | struct cfg80211_scan_request *req) | |
840 | { | |
841 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
842 | int ret; | |
843 | ||
844 | if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS) | |
845 | return -EINVAL; | |
846 | ||
847 | mutex_lock(&mvm->mutex); | |
848 | ||
849 | if (mvm->scan_status == IWL_MVM_SCAN_NONE) | |
850 | ret = iwl_mvm_scan_request(mvm, vif, req); | |
851 | else | |
852 | ret = -EBUSY; | |
853 | ||
854 | mutex_unlock(&mvm->mutex); | |
855 | ||
856 | return ret; | |
857 | } | |
858 | ||
859 | static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, | |
860 | struct ieee80211_vif *vif) | |
861 | { | |
862 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
863 | ||
864 | mutex_lock(&mvm->mutex); | |
865 | ||
866 | iwl_mvm_cancel_scan(mvm); | |
867 | ||
868 | mutex_unlock(&mvm->mutex); | |
869 | } | |
870 | ||
871 | static void | |
872 | iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, | |
873 | struct ieee80211_sta *sta, u16 tid, | |
874 | int num_frames, | |
875 | enum ieee80211_frame_release_type reason, | |
876 | bool more_data) | |
877 | { | |
878 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
8ca151b5 JB |
879 | |
880 | /* TODO: how do we tell the fw to send frames for a specific TID */ | |
881 | ||
882 | /* | |
883 | * The fw will send EOSP notification when the last frame will be | |
884 | * transmitted. | |
885 | */ | |
9cc40712 | 886 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames); |
8ca151b5 JB |
887 | } |
888 | ||
889 | static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, | |
890 | struct ieee80211_vif *vif, | |
891 | enum sta_notify_cmd cmd, | |
892 | struct ieee80211_sta *sta) | |
893 | { | |
894 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
895 | struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv; | |
896 | ||
897 | switch (cmd) { | |
898 | case STA_NOTIFY_SLEEP: | |
899 | if (atomic_read(&mvmsta->pending_frames) > 0) | |
900 | ieee80211_sta_block_awake(hw, sta, true); | |
901 | /* | |
902 | * The fw updates the STA to be asleep. Tx packets on the Tx | |
903 | * queues to this station will not be transmitted. The fw will | |
904 | * send a Tx response with TX_STATUS_FAIL_DEST_PS. | |
905 | */ | |
906 | break; | |
907 | case STA_NOTIFY_AWAKE: | |
908 | if (WARN_ON(mvmsta->sta_id == IWL_INVALID_STATION)) | |
909 | break; | |
9cc40712 | 910 | iwl_mvm_sta_modify_ps_wake(mvm, sta); |
8ca151b5 JB |
911 | break; |
912 | default: | |
913 | break; | |
914 | } | |
915 | } | |
916 | ||
917 | static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, | |
918 | struct ieee80211_vif *vif, | |
919 | struct ieee80211_sta *sta, | |
920 | enum ieee80211_sta_state old_state, | |
921 | enum ieee80211_sta_state new_state) | |
922 | { | |
923 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
924 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
925 | int ret; | |
926 | ||
927 | IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", | |
928 | sta->addr, old_state, new_state); | |
929 | ||
930 | /* this would be a mac80211 bug ... but don't crash */ | |
931 | if (WARN_ON_ONCE(!mvmvif->phy_ctxt)) | |
932 | return -EINVAL; | |
933 | ||
934 | /* if a STA is being removed, reuse its ID */ | |
935 | flush_work(&mvm->sta_drained_wk); | |
936 | ||
937 | mutex_lock(&mvm->mutex); | |
938 | if (old_state == IEEE80211_STA_NOTEXIST && | |
939 | new_state == IEEE80211_STA_NONE) { | |
940 | ret = iwl_mvm_add_sta(mvm, vif, sta); | |
941 | } else if (old_state == IEEE80211_STA_NONE && | |
942 | new_state == IEEE80211_STA_AUTH) { | |
943 | ret = 0; | |
944 | } else if (old_state == IEEE80211_STA_AUTH && | |
945 | new_state == IEEE80211_STA_ASSOC) { | |
7a453973 JB |
946 | ret = iwl_mvm_update_sta(mvm, vif, sta); |
947 | if (ret == 0) | |
948 | iwl_mvm_rs_rate_init(mvm, sta, | |
949 | mvmvif->phy_ctxt->channel->band); | |
8ca151b5 JB |
950 | } else if (old_state == IEEE80211_STA_ASSOC && |
951 | new_state == IEEE80211_STA_AUTHORIZED) { | |
952 | ret = 0; | |
953 | } else if (old_state == IEEE80211_STA_AUTHORIZED && | |
954 | new_state == IEEE80211_STA_ASSOC) { | |
955 | ret = 0; | |
956 | } else if (old_state == IEEE80211_STA_ASSOC && | |
957 | new_state == IEEE80211_STA_AUTH) { | |
958 | ret = 0; | |
959 | } else if (old_state == IEEE80211_STA_AUTH && | |
960 | new_state == IEEE80211_STA_NONE) { | |
961 | ret = 0; | |
962 | } else if (old_state == IEEE80211_STA_NONE && | |
963 | new_state == IEEE80211_STA_NOTEXIST) { | |
964 | ret = iwl_mvm_rm_sta(mvm, vif, sta); | |
965 | } else { | |
966 | ret = -EIO; | |
967 | } | |
968 | mutex_unlock(&mvm->mutex); | |
969 | ||
970 | return ret; | |
971 | } | |
972 | ||
973 | static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) | |
974 | { | |
975 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
976 | ||
977 | mvm->rts_threshold = value; | |
978 | ||
979 | return 0; | |
980 | } | |
981 | ||
982 | static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, | |
983 | struct ieee80211_vif *vif, u16 ac, | |
984 | const struct ieee80211_tx_queue_params *params) | |
985 | { | |
986 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
987 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
988 | ||
989 | mvmvif->queue_params[ac] = *params; | |
990 | ||
991 | /* | |
992 | * No need to update right away, we'll get BSS_CHANGED_QOS | |
993 | * The exception is P2P_DEVICE interface which needs immediate update. | |
994 | */ | |
995 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
996 | int ret; | |
997 | ||
998 | mutex_lock(&mvm->mutex); | |
999 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); | |
1000 | mutex_unlock(&mvm->mutex); | |
1001 | return ret; | |
1002 | } | |
1003 | return 0; | |
1004 | } | |
1005 | ||
1006 | static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, | |
1007 | struct ieee80211_vif *vif) | |
1008 | { | |
1009 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1010 | u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS, | |
1011 | 200 + vif->bss_conf.beacon_int); | |
1012 | u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS, | |
1013 | 100 + vif->bss_conf.beacon_int); | |
1014 | ||
1015 | if (WARN_ON_ONCE(vif->bss_conf.assoc)) | |
1016 | return; | |
1017 | ||
1018 | mutex_lock(&mvm->mutex); | |
1019 | /* Try really hard to protect the session and hear a beacon */ | |
1020 | iwl_mvm_protect_session(mvm, vif, duration, min_duration); | |
1021 | mutex_unlock(&mvm->mutex); | |
1022 | } | |
1023 | ||
1024 | static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, | |
1025 | enum set_key_cmd cmd, | |
1026 | struct ieee80211_vif *vif, | |
1027 | struct ieee80211_sta *sta, | |
1028 | struct ieee80211_key_conf *key) | |
1029 | { | |
1030 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1031 | int ret; | |
1032 | ||
1033 | if (iwlwifi_mod_params.sw_crypto) { | |
1034 | IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n"); | |
1035 | return -EOPNOTSUPP; | |
1036 | } | |
1037 | ||
1038 | switch (key->cipher) { | |
1039 | case WLAN_CIPHER_SUITE_TKIP: | |
1040 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; | |
1041 | /* fall-through */ | |
1042 | case WLAN_CIPHER_SUITE_CCMP: | |
1043 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
1044 | break; | |
1045 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
1046 | WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE)); | |
1047 | break; | |
1048 | case WLAN_CIPHER_SUITE_WEP40: | |
1049 | case WLAN_CIPHER_SUITE_WEP104: | |
1050 | /* | |
1051 | * Support for TX only, at least for now, so accept | |
1052 | * the key and do nothing else. Then mac80211 will | |
1053 | * pass it for TX but we don't have to use it for RX. | |
1054 | */ | |
1055 | return 0; | |
1056 | default: | |
1057 | return -EOPNOTSUPP; | |
1058 | } | |
1059 | ||
1060 | mutex_lock(&mvm->mutex); | |
1061 | ||
1062 | switch (cmd) { | |
1063 | case SET_KEY: | |
1064 | IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n"); | |
1065 | ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false); | |
1066 | if (ret) { | |
1067 | IWL_WARN(mvm, "set key failed\n"); | |
1068 | /* | |
1069 | * can't add key for RX, but we don't need it | |
1070 | * in the device for TX so still return 0 | |
1071 | */ | |
1072 | ret = 0; | |
1073 | } | |
1074 | ||
1075 | break; | |
1076 | case DISABLE_KEY: | |
1077 | IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); | |
1078 | ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); | |
1079 | break; | |
1080 | default: | |
1081 | ret = -EINVAL; | |
1082 | } | |
1083 | ||
1084 | mutex_unlock(&mvm->mutex); | |
1085 | return ret; | |
1086 | } | |
1087 | ||
1088 | static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, | |
1089 | struct ieee80211_vif *vif, | |
1090 | struct ieee80211_key_conf *keyconf, | |
1091 | struct ieee80211_sta *sta, | |
1092 | u32 iv32, u16 *phase1key) | |
1093 | { | |
1094 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1095 | ||
1096 | iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); | |
1097 | } | |
1098 | ||
1099 | ||
1100 | static int iwl_mvm_roc(struct ieee80211_hw *hw, | |
1101 | struct ieee80211_vif *vif, | |
1102 | struct ieee80211_channel *channel, | |
1103 | int duration) | |
1104 | { | |
1105 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1106 | struct cfg80211_chan_def chandef; | |
1107 | int ret; | |
1108 | ||
1109 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) { | |
1110 | IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type); | |
1111 | return -EINVAL; | |
1112 | } | |
1113 | ||
1114 | IWL_DEBUG_MAC80211(mvm, "enter (%d, %d)\n", channel->hw_value, | |
1115 | duration); | |
1116 | ||
1117 | mutex_lock(&mvm->mutex); | |
1118 | ||
1119 | cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); | |
1120 | ret = iwl_mvm_phy_ctxt_changed(mvm, &mvm->phy_ctxt_roc, | |
1121 | &chandef, 1, 1); | |
1122 | ||
1123 | /* Schedule the time events */ | |
1124 | ret = iwl_mvm_start_p2p_roc(mvm, vif, duration); | |
1125 | ||
1126 | mutex_unlock(&mvm->mutex); | |
1127 | IWL_DEBUG_MAC80211(mvm, "leave\n"); | |
1128 | ||
1129 | return ret; | |
1130 | } | |
1131 | ||
1132 | static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw) | |
1133 | { | |
1134 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1135 | ||
1136 | IWL_DEBUG_MAC80211(mvm, "enter\n"); | |
1137 | ||
1138 | mutex_lock(&mvm->mutex); | |
1139 | iwl_mvm_stop_p2p_roc(mvm); | |
1140 | mutex_unlock(&mvm->mutex); | |
1141 | ||
1142 | IWL_DEBUG_MAC80211(mvm, "leave\n"); | |
1143 | return 0; | |
1144 | } | |
1145 | ||
1146 | static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, | |
1147 | struct ieee80211_chanctx_conf *ctx) | |
1148 | { | |
1149 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1150 | struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv; | |
1151 | int ret; | |
1152 | ||
1153 | mutex_lock(&mvm->mutex); | |
1154 | ||
1155 | IWL_DEBUG_MAC80211(mvm, "Add PHY context\n"); | |
1156 | ret = iwl_mvm_phy_ctxt_add(mvm, phy_ctxt, &ctx->def, | |
1157 | ctx->rx_chains_static, | |
1158 | ctx->rx_chains_dynamic); | |
1159 | mutex_unlock(&mvm->mutex); | |
1160 | return ret; | |
1161 | } | |
1162 | ||
1163 | static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, | |
1164 | struct ieee80211_chanctx_conf *ctx) | |
1165 | { | |
1166 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1167 | struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv; | |
1168 | ||
1169 | mutex_lock(&mvm->mutex); | |
1170 | iwl_mvm_phy_ctxt_remove(mvm, phy_ctxt); | |
1171 | mutex_unlock(&mvm->mutex); | |
1172 | } | |
1173 | ||
1174 | static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, | |
1175 | struct ieee80211_chanctx_conf *ctx, | |
1176 | u32 changed) | |
1177 | { | |
1178 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1179 | struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv; | |
1180 | ||
1181 | mutex_lock(&mvm->mutex); | |
1182 | iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def, | |
1183 | ctx->rx_chains_static, | |
1184 | ctx->rx_chains_dynamic); | |
1185 | mutex_unlock(&mvm->mutex); | |
1186 | } | |
1187 | ||
1188 | static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, | |
1189 | struct ieee80211_vif *vif, | |
1190 | struct ieee80211_chanctx_conf *ctx) | |
1191 | { | |
1192 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1193 | struct iwl_mvm_phy_ctxt *phyctx = (void *)ctx->drv_priv; | |
1194 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1195 | int ret; | |
1196 | ||
1197 | mutex_lock(&mvm->mutex); | |
1198 | ||
1199 | mvmvif->phy_ctxt = phyctx; | |
1200 | ||
1201 | switch (vif->type) { | |
1202 | case NL80211_IFTYPE_AP: | |
1203 | /* | |
1204 | * The AP binding flow is handled as part of the start_ap flow | |
1205 | * (in bss_info_changed). | |
1206 | */ | |
1207 | ret = 0; | |
1208 | goto out_unlock; | |
1209 | case NL80211_IFTYPE_STATION: | |
1210 | case NL80211_IFTYPE_ADHOC: | |
1211 | case NL80211_IFTYPE_MONITOR: | |
1212 | break; | |
1213 | default: | |
1214 | ret = -EINVAL; | |
1215 | goto out_unlock; | |
1216 | } | |
1217 | ||
1218 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
1219 | if (ret) | |
1220 | goto out_unlock; | |
1221 | ||
1222 | /* | |
1223 | * Setting the quota at this stage is only required for monitor | |
1224 | * interfaces. For the other types, the bss_info changed flow | |
1225 | * will handle quota settings. | |
1226 | */ | |
1227 | if (vif->type == NL80211_IFTYPE_MONITOR) { | |
1228 | ret = iwl_mvm_update_quotas(mvm, vif); | |
1229 | if (ret) | |
1230 | goto out_remove_binding; | |
1231 | } | |
1232 | ||
1233 | goto out_unlock; | |
1234 | ||
1235 | out_remove_binding: | |
1236 | iwl_mvm_binding_remove_vif(mvm, vif); | |
1237 | out_unlock: | |
1238 | mutex_unlock(&mvm->mutex); | |
1239 | if (ret) | |
1240 | mvmvif->phy_ctxt = NULL; | |
1241 | return ret; | |
1242 | } | |
1243 | ||
1244 | static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, | |
1245 | struct ieee80211_vif *vif, | |
1246 | struct ieee80211_chanctx_conf *ctx) | |
1247 | { | |
1248 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1249 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1250 | ||
1251 | mutex_lock(&mvm->mutex); | |
1252 | ||
1253 | iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data); | |
1254 | ||
1255 | if (vif->type == NL80211_IFTYPE_AP) | |
1256 | goto out_unlock; | |
1257 | ||
1258 | iwl_mvm_binding_remove_vif(mvm, vif); | |
1259 | switch (vif->type) { | |
1260 | case NL80211_IFTYPE_MONITOR: | |
1261 | iwl_mvm_update_quotas(mvm, vif); | |
1262 | break; | |
1263 | default: | |
1264 | break; | |
1265 | } | |
1266 | ||
1267 | out_unlock: | |
1268 | mvmvif->phy_ctxt = NULL; | |
1269 | mutex_unlock(&mvm->mutex); | |
1270 | } | |
1271 | ||
1272 | static int iwl_mvm_set_tim(struct ieee80211_hw *hw, | |
1273 | struct ieee80211_sta *sta, | |
1274 | bool set) | |
1275 | { | |
1276 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1277 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; | |
1278 | ||
1279 | if (!mvm_sta || !mvm_sta->vif) { | |
1280 | IWL_ERR(mvm, "Station is not associated to a vif\n"); | |
1281 | return -EINVAL; | |
1282 | } | |
1283 | ||
1284 | return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif); | |
1285 | } | |
1286 | ||
1287 | struct ieee80211_ops iwl_mvm_hw_ops = { | |
1288 | .tx = iwl_mvm_mac_tx, | |
1289 | .ampdu_action = iwl_mvm_mac_ampdu_action, | |
1290 | .start = iwl_mvm_mac_start, | |
1291 | .restart_complete = iwl_mvm_mac_restart_complete, | |
1292 | .stop = iwl_mvm_mac_stop, | |
1293 | .add_interface = iwl_mvm_mac_add_interface, | |
1294 | .remove_interface = iwl_mvm_mac_remove_interface, | |
1295 | .config = iwl_mvm_mac_config, | |
1296 | .configure_filter = iwl_mvm_configure_filter, | |
1297 | .bss_info_changed = iwl_mvm_bss_info_changed, | |
1298 | .hw_scan = iwl_mvm_mac_hw_scan, | |
1299 | .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, | |
1300 | .sta_state = iwl_mvm_mac_sta_state, | |
1301 | .sta_notify = iwl_mvm_mac_sta_notify, | |
1302 | .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, | |
1303 | .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, | |
1304 | .conf_tx = iwl_mvm_mac_conf_tx, | |
1305 | .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, | |
1306 | .set_key = iwl_mvm_mac_set_key, | |
1307 | .update_tkip_key = iwl_mvm_mac_update_tkip_key, | |
1308 | .remain_on_channel = iwl_mvm_roc, | |
1309 | .cancel_remain_on_channel = iwl_mvm_cancel_roc, | |
1310 | ||
1311 | .add_chanctx = iwl_mvm_add_chanctx, | |
1312 | .remove_chanctx = iwl_mvm_remove_chanctx, | |
1313 | .change_chanctx = iwl_mvm_change_chanctx, | |
1314 | .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, | |
1315 | .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, | |
1316 | ||
1317 | .start_ap = iwl_mvm_start_ap, | |
1318 | .stop_ap = iwl_mvm_stop_ap, | |
1319 | ||
1320 | .set_tim = iwl_mvm_set_tim, | |
1321 | ||
1322 | #ifdef CONFIG_PM_SLEEP | |
1323 | /* look at d3.c */ | |
1324 | .suspend = iwl_mvm_suspend, | |
1325 | .resume = iwl_mvm_resume, | |
1326 | .set_wakeup = iwl_mvm_set_wakeup, | |
1327 | .set_rekey_data = iwl_mvm_set_rekey_data, | |
1328 | #if IS_ENABLED(CONFIG_IPV6) | |
1329 | .ipv6_addr_change = iwl_mvm_ipv6_addr_change, | |
1330 | #endif | |
1331 | .set_default_unicast_key = iwl_mvm_set_default_unicast_key, | |
1332 | #endif | |
1333 | }; |