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