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