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