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