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