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. |
26d6c16b SS |
9 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
10 | * Copyright(c) 2016 - 2017 Intel Deutschland GmbH | |
c37763d2 | 11 | * Copyright(c) 2018 - 2019 Intel Corporation |
8ca151b5 JB |
12 | * |
13 | * This program is free software; you can redistribute it and/or modify | |
14 | * it under the terms of version 2 of the GNU General Public License as | |
15 | * published by the Free Software Foundation. | |
16 | * | |
17 | * This program is distributed in the hope that it will be useful, but | |
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | * General Public License for more details. | |
21 | * | |
8ca151b5 | 22 | * The full GNU General Public License is included in this distribution |
410dc5aa | 23 | * in the file called COPYING. |
8ca151b5 JB |
24 | * |
25 | * Contact Information: | |
cb2f8277 | 26 | * Intel Linux Wireless <linuxwifi@intel.com> |
8ca151b5 JB |
27 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
28 | * | |
29 | * BSD LICENSE | |
30 | * | |
51368bf7 | 31 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
26d6c16b SS |
32 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
33 | * Copyright(c) 2016 - 2017 Intel Deutschland GmbH | |
c37763d2 | 34 | * Copyright(c) 2018 - 2019 Intel Corporation |
8ca151b5 JB |
35 | * All rights reserved. |
36 | * | |
37 | * Redistribution and use in source and binary forms, with or without | |
38 | * modification, are permitted provided that the following conditions | |
39 | * are met: | |
40 | * | |
41 | * * Redistributions of source code must retain the above copyright | |
42 | * notice, this list of conditions and the following disclaimer. | |
43 | * * Redistributions in binary form must reproduce the above copyright | |
44 | * notice, this list of conditions and the following disclaimer in | |
45 | * the documentation and/or other materials provided with the | |
46 | * distribution. | |
47 | * * Neither the name Intel Corporation nor the names of its | |
48 | * contributors may be used to endorse or promote products derived | |
49 | * from this software without specific prior written permission. | |
50 | * | |
51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
52 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
53 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
54 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
55 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
56 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
57 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
58 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
59 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
60 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
61 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
62 | * | |
63 | *****************************************************************************/ | |
64 | #include <linux/kernel.h> | |
65 | #include <linux/slab.h> | |
66 | #include <linux/skbuff.h> | |
67 | #include <linux/netdevice.h> | |
68 | #include <linux/etherdevice.h> | |
f0c2646a | 69 | #include <linux/ip.h> |
2ee8f021 | 70 | #include <linux/if_arp.h> |
2f89a5d7 | 71 | #include <linux/time.h> |
8ca151b5 | 72 | #include <net/mac80211.h> |
7b1dd048 | 73 | #include <net/ieee80211_radiotap.h> |
f0c2646a | 74 | #include <net/tcp.h> |
8ca151b5 JB |
75 | |
76 | #include "iwl-op-mode.h" | |
77 | #include "iwl-io.h" | |
78 | #include "mvm.h" | |
79 | #include "sta.h" | |
80 | #include "time-event.h" | |
81 | #include "iwl-eeprom-parse.h" | |
8ca151b5 | 82 | #include "iwl-phy-db.h" |
507cadf2 | 83 | #include "testmode.h" |
d962f9b1 | 84 | #include "fw/error-dump.h" |
655e6d6d | 85 | #include "iwl-prph.h" |
88931cc9 | 86 | #include "iwl-nvm-parse.h" |
8ca151b5 JB |
87 | |
88 | static const struct ieee80211_iface_limit iwl_mvm_limits[] = { | |
89 | { | |
90 | .max = 1, | |
8eb38710 | 91 | .types = BIT(NL80211_IFTYPE_STATION), |
8ca151b5 | 92 | }, |
3c15a0fb JB |
93 | { |
94 | .max = 1, | |
8eb38710 IP |
95 | .types = BIT(NL80211_IFTYPE_AP) | |
96 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | |
3c15a0fb JB |
97 | BIT(NL80211_IFTYPE_P2P_GO), |
98 | }, | |
99 | { | |
100 | .max = 1, | |
101 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE), | |
102 | }, | |
8ca151b5 JB |
103 | }; |
104 | ||
105 | static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = { | |
106 | { | |
2624a5ca | 107 | .num_different_channels = 2, |
8ca151b5 JB |
108 | .max_interfaces = 3, |
109 | .limits = iwl_mvm_limits, | |
110 | .n_limits = ARRAY_SIZE(iwl_mvm_limits), | |
111 | }, | |
112 | }; | |
113 | ||
77736923 | 114 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
2ee8f021 EP |
115 | /* |
116 | * Use the reserved field to indicate magic values. | |
117 | * these values will only be used internally by the driver, | |
118 | * and won't make it to the fw (reserved will be 0). | |
119 | * BC_FILTER_MAGIC_IP - configure the val of this attribute to | |
120 | * be the vif's ip address. in case there is not a single | |
121 | * ip address (0, or more than 1), this attribute will | |
122 | * be skipped. | |
123 | * BC_FILTER_MAGIC_MAC - set the val of this attribute to | |
124 | * the LSB bytes of the vif's mac address | |
125 | */ | |
126 | enum { | |
127 | BC_FILTER_MAGIC_NONE = 0, | |
128 | BC_FILTER_MAGIC_IP, | |
129 | BC_FILTER_MAGIC_MAC, | |
130 | }; | |
131 | ||
77736923 EP |
132 | static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = { |
133 | { | |
134 | /* arp */ | |
135 | .discard = 0, | |
136 | .frame_type = BCAST_FILTER_FRAME_TYPE_ALL, | |
137 | .attrs = { | |
138 | { | |
139 | /* frame type - arp, hw type - ethernet */ | |
140 | .offset_type = | |
141 | BCAST_FILTER_OFFSET_PAYLOAD_START, | |
142 | .offset = sizeof(rfc1042_header), | |
143 | .val = cpu_to_be32(0x08060001), | |
144 | .mask = cpu_to_be32(0xffffffff), | |
145 | }, | |
2ee8f021 EP |
146 | { |
147 | /* arp dest ip */ | |
148 | .offset_type = | |
149 | BCAST_FILTER_OFFSET_PAYLOAD_START, | |
150 | .offset = sizeof(rfc1042_header) + 2 + | |
151 | sizeof(struct arphdr) + | |
152 | ETH_ALEN + sizeof(__be32) + | |
153 | ETH_ALEN, | |
154 | .mask = cpu_to_be32(0xffffffff), | |
155 | /* mark it as special field */ | |
156 | .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP), | |
157 | }, | |
158 | }, | |
159 | }, | |
160 | { | |
161 | /* dhcp offer bcast */ | |
162 | .discard = 0, | |
163 | .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4, | |
164 | .attrs = { | |
165 | { | |
166 | /* udp dest port - 68 (bootp client)*/ | |
167 | .offset_type = BCAST_FILTER_OFFSET_IP_END, | |
168 | .offset = offsetof(struct udphdr, dest), | |
169 | .val = cpu_to_be32(0x00440000), | |
170 | .mask = cpu_to_be32(0xffff0000), | |
171 | }, | |
172 | { | |
173 | /* dhcp - lsb bytes of client hw address */ | |
174 | .offset_type = BCAST_FILTER_OFFSET_IP_END, | |
175 | .offset = 38, | |
176 | .mask = cpu_to_be32(0xffffffff), | |
177 | /* mark it as special field */ | |
178 | .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC), | |
179 | }, | |
77736923 EP |
180 | }, |
181 | }, | |
182 | /* last filter must be empty */ | |
183 | {}, | |
184 | }; | |
185 | #endif | |
186 | ||
fc36ffda JB |
187 | static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa = { |
188 | .max_peers = IWL_MVM_TOF_MAX_APS, | |
189 | .report_ap_tsf = 1, | |
190 | .randomize_mac_addr = 1, | |
191 | ||
192 | .ftm = { | |
193 | .supported = 1, | |
194 | .asap = 1, | |
195 | .non_asap = 1, | |
196 | .request_lci = 1, | |
197 | .request_civicloc = 1, | |
198 | .max_bursts_exponent = -1, /* all supported */ | |
199 | .max_ftms_per_burst = 0, /* no limits */ | |
200 | .bandwidths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | | |
201 | BIT(NL80211_CHAN_WIDTH_20) | | |
202 | BIT(NL80211_CHAN_WIDTH_40) | | |
203 | BIT(NL80211_CHAN_WIDTH_80), | |
204 | .preambles = BIT(NL80211_PREAMBLE_LEGACY) | | |
205 | BIT(NL80211_PREAMBLE_HT) | | |
206 | BIT(NL80211_PREAMBLE_VHT), | |
207 | }, | |
208 | }; | |
209 | ||
c56e00a3 JB |
210 | static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, |
211 | enum set_key_cmd cmd, | |
212 | struct ieee80211_vif *vif, | |
213 | struct ieee80211_sta *sta, | |
214 | struct ieee80211_key_conf *key); | |
215 | ||
7498cf4c EP |
216 | void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type) |
217 | { | |
7bb426ea | 218 | if (!iwl_mvm_is_d0i3_supported(mvm)) |
7498cf4c EP |
219 | return; |
220 | ||
221 | IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type); | |
576eeee9 EP |
222 | spin_lock_bh(&mvm->refs_lock); |
223 | mvm->refs[ref_type]++; | |
224 | spin_unlock_bh(&mvm->refs_lock); | |
7498cf4c EP |
225 | iwl_trans_ref(mvm->trans); |
226 | } | |
227 | ||
228 | void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type) | |
229 | { | |
7bb426ea | 230 | if (!iwl_mvm_is_d0i3_supported(mvm)) |
7498cf4c EP |
231 | return; |
232 | ||
233 | IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type); | |
576eeee9 | 234 | spin_lock_bh(&mvm->refs_lock); |
16c45822 SS |
235 | if (WARN_ON(!mvm->refs[ref_type])) { |
236 | spin_unlock_bh(&mvm->refs_lock); | |
237 | return; | |
238 | } | |
239 | mvm->refs[ref_type]--; | |
576eeee9 | 240 | spin_unlock_bh(&mvm->refs_lock); |
7498cf4c EP |
241 | iwl_trans_unref(mvm->trans); |
242 | } | |
243 | ||
576eeee9 EP |
244 | static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm, |
245 | enum iwl_mvm_ref_type except_ref) | |
7498cf4c | 246 | { |
576eeee9 | 247 | int i, j; |
7498cf4c | 248 | |
7bb426ea | 249 | if (!iwl_mvm_is_d0i3_supported(mvm)) |
7498cf4c EP |
250 | return; |
251 | ||
576eeee9 EP |
252 | spin_lock_bh(&mvm->refs_lock); |
253 | for (i = 0; i < IWL_MVM_REF_COUNT; i++) { | |
254 | if (except_ref == i || !mvm->refs[i]) | |
7498cf4c EP |
255 | continue; |
256 | ||
576eeee9 EP |
257 | IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n", |
258 | i, mvm->refs[i]); | |
259 | for (j = 0; j < mvm->refs[i]; j++) | |
260 | iwl_trans_unref(mvm->trans); | |
261 | mvm->refs[i] = 0; | |
7498cf4c | 262 | } |
576eeee9 | 263 | spin_unlock_bh(&mvm->refs_lock); |
7498cf4c EP |
264 | } |
265 | ||
f4cf8680 EP |
266 | bool iwl_mvm_ref_taken(struct iwl_mvm *mvm) |
267 | { | |
268 | int i; | |
269 | bool taken = false; | |
270 | ||
271 | if (!iwl_mvm_is_d0i3_supported(mvm)) | |
272 | return true; | |
273 | ||
274 | spin_lock_bh(&mvm->refs_lock); | |
275 | for (i = 0; i < IWL_MVM_REF_COUNT; i++) { | |
276 | if (mvm->refs[i]) { | |
277 | taken = true; | |
278 | break; | |
279 | } | |
280 | } | |
281 | spin_unlock_bh(&mvm->refs_lock); | |
282 | ||
283 | return taken; | |
284 | } | |
285 | ||
576eeee9 | 286 | int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type) |
d40fc489 GG |
287 | { |
288 | iwl_mvm_ref(mvm, ref_type); | |
289 | ||
290 | if (!wait_event_timeout(mvm->d0i3_exit_waitq, | |
291 | !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status), | |
292 | HZ)) { | |
293 | WARN_ON_ONCE(1); | |
294 | iwl_mvm_unref(mvm, ref_type); | |
295 | return -EIO; | |
296 | } | |
297 | ||
298 | return 0; | |
299 | } | |
300 | ||
fe0f2de3 IP |
301 | static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm) |
302 | { | |
303 | int i; | |
304 | ||
305 | memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts)); | |
306 | for (i = 0; i < NUM_PHY_CTX; i++) { | |
307 | mvm->phy_ctxts[i].id = i; | |
308 | mvm->phy_ctxts[i].ref = 0; | |
309 | } | |
310 | } | |
311 | ||
88931cc9 | 312 | struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy, |
8ba2d7a1 | 313 | const char *alpha2, |
47c8b154 JD |
314 | enum iwl_mcc_source src_id, |
315 | bool *changed) | |
88931cc9 AN |
316 | { |
317 | struct ieee80211_regdomain *regd = NULL; | |
318 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); | |
319 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
320 | struct iwl_mcc_update_resp *resp; | |
321 | ||
322 | IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2); | |
323 | ||
8ba2d7a1 | 324 | lockdep_assert_held(&mvm->mutex); |
88931cc9 | 325 | |
8ba2d7a1 | 326 | resp = iwl_mvm_update_mcc(mvm, alpha2, src_id); |
88931cc9 AN |
327 | if (IS_ERR_OR_NULL(resp)) { |
328 | IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n", | |
b8c474d9 | 329 | PTR_ERR_OR_ZERO(resp)); |
8ba2d7a1 | 330 | goto out; |
88931cc9 AN |
331 | } |
332 | ||
82715ac7 EG |
333 | if (changed) { |
334 | u32 status = le32_to_cpu(resp->status); | |
335 | ||
336 | *changed = (status == MCC_RESP_NEW_CHAN_PROFILE || | |
337 | status == MCC_RESP_ILLEGAL); | |
338 | } | |
47c8b154 | 339 | |
162ee3c9 | 340 | regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg, |
88931cc9 AN |
341 | __le32_to_cpu(resp->n_channels), |
342 | resp->channels, | |
77e30e10 HD |
343 | __le16_to_cpu(resp->mcc), |
344 | __le16_to_cpu(resp->geo_info)); | |
8ba2d7a1 EH |
345 | /* Store the return source id */ |
346 | src_id = resp->source_id; | |
88931cc9 AN |
347 | kfree(resp); |
348 | if (IS_ERR_OR_NULL(regd)) { | |
349 | IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n", | |
b8c474d9 | 350 | PTR_ERR_OR_ZERO(regd)); |
8ba2d7a1 | 351 | goto out; |
88931cc9 AN |
352 | } |
353 | ||
8ba2d7a1 EH |
354 | IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n", |
355 | regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id); | |
88931cc9 | 356 | mvm->lar_regdom_set = true; |
8ba2d7a1 | 357 | mvm->mcc_src = src_id; |
88931cc9 | 358 | |
8ba2d7a1 | 359 | out: |
88931cc9 AN |
360 | return regd; |
361 | } | |
362 | ||
47c8b154 JD |
363 | void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm) |
364 | { | |
365 | bool changed; | |
366 | struct ieee80211_regdomain *regd; | |
367 | ||
368 | if (!iwl_mvm_is_lar_supported(mvm)) | |
369 | return; | |
370 | ||
371 | regd = iwl_mvm_get_current_regdomain(mvm, &changed); | |
372 | if (!IS_ERR_OR_NULL(regd)) { | |
373 | /* only update the regulatory core if changed */ | |
374 | if (changed) | |
375 | regulatory_set_wiphy_regd(mvm->hw->wiphy, regd); | |
376 | ||
377 | kfree(regd); | |
378 | } | |
379 | } | |
380 | ||
381 | struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm, | |
382 | bool *changed) | |
8ba2d7a1 EH |
383 | { |
384 | return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ", | |
385 | iwl_mvm_is_wifi_mcc_supported(mvm) ? | |
386 | MCC_SOURCE_GET_CURRENT : | |
47c8b154 | 387 | MCC_SOURCE_OLD_FW, changed); |
8ba2d7a1 EH |
388 | } |
389 | ||
390 | int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm) | |
391 | { | |
392 | enum iwl_mcc_source used_src; | |
393 | struct ieee80211_regdomain *regd; | |
b6e160ab AN |
394 | int ret; |
395 | bool changed; | |
8ba2d7a1 EH |
396 | const struct ieee80211_regdomain *r = |
397 | rtnl_dereference(mvm->hw->wiphy->regd); | |
398 | ||
399 | if (!r) | |
b6e160ab | 400 | return -ENOENT; |
8ba2d7a1 EH |
401 | |
402 | /* save the last source in case we overwrite it below */ | |
403 | used_src = mvm->mcc_src; | |
404 | if (iwl_mvm_is_wifi_mcc_supported(mvm)) { | |
405 | /* Notify the firmware we support wifi location updates */ | |
47c8b154 | 406 | regd = iwl_mvm_get_current_regdomain(mvm, NULL); |
8ba2d7a1 EH |
407 | if (!IS_ERR_OR_NULL(regd)) |
408 | kfree(regd); | |
409 | } | |
410 | ||
411 | /* Now set our last stored MCC and source */ | |
b6e160ab AN |
412 | regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src, |
413 | &changed); | |
8ba2d7a1 EH |
414 | if (IS_ERR_OR_NULL(regd)) |
415 | return -EIO; | |
416 | ||
b6e160ab AN |
417 | /* update cfg80211 if the regdomain was changed */ |
418 | if (changed) | |
419 | ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd); | |
420 | else | |
421 | ret = 0; | |
8ba2d7a1 | 422 | |
b6e160ab AN |
423 | kfree(regd); |
424 | return ret; | |
8ba2d7a1 EH |
425 | } |
426 | ||
7360f99e EG |
427 | const static u8 he_if_types_ext_capa_sta[] = { |
428 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
918cbf39 | 429 | [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, |
7360f99e EG |
430 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, |
431 | [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT, | |
432 | }; | |
433 | ||
434 | const static struct wiphy_iftype_ext_capab he_iftypes_ext_capa[] = { | |
435 | { | |
436 | .iftype = NL80211_IFTYPE_STATION, | |
437 | .extended_capabilities = he_if_types_ext_capa_sta, | |
438 | .extended_capabilities_mask = he_if_types_ext_capa_sta, | |
439 | .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta), | |
440 | }, | |
441 | }; | |
442 | ||
8ca151b5 JB |
443 | int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm) |
444 | { | |
445 | struct ieee80211_hw *hw = mvm->hw; | |
831e85f3 | 446 | int num_mac, ret, i; |
5f4c02e2 JB |
447 | static const u32 mvm_ciphers[] = { |
448 | WLAN_CIPHER_SUITE_WEP40, | |
449 | WLAN_CIPHER_SUITE_WEP104, | |
450 | WLAN_CIPHER_SUITE_TKIP, | |
451 | WLAN_CIPHER_SUITE_CCMP, | |
452 | }; | |
3f37c229 IY |
453 | #ifdef CONFIG_PM_SLEEP |
454 | bool unified = fw_has_capa(&mvm->fw->ucode_capa, | |
455 | IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); | |
456 | #endif | |
8ca151b5 JB |
457 | |
458 | /* Tell mac80211 our characteristics */ | |
30686bf7 JB |
459 | ieee80211_hw_set(hw, SIGNAL_DBM); |
460 | ieee80211_hw_set(hw, SPECTRUM_MGMT); | |
461 | ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); | |
30686bf7 JB |
462 | ieee80211_hw_set(hw, WANT_MONITOR_VIF); |
463 | ieee80211_hw_set(hw, SUPPORTS_PS); | |
464 | ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); | |
465 | ieee80211_hw_set(hw, AMPDU_AGGREGATION); | |
466 | ieee80211_hw_set(hw, TIMING_BEACON_ONLY); | |
467 | ieee80211_hw_set(hw, CONNECTION_MONITOR); | |
468 | ieee80211_hw_set(hw, CHANCTX_STA_CSA); | |
469 | ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); | |
470 | ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS); | |
909ddf0b | 471 | ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU); |
30433d3b | 472 | ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR); |
d270e7b8 | 473 | ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP); |
520229e4 | 474 | ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW); |
cfbc6c4c SS |
475 | ieee80211_hw_set(hw, BUFF_MMPDU_TXQ); |
476 | ieee80211_hw_set(hw, STA_MMPDU_TXQ); | |
438af969 SS |
477 | ieee80211_hw_set(hw, TX_AMSDU); |
478 | ieee80211_hw_set(hw, TX_FRAG_LIST); | |
ecaf71de | 479 | |
4243edb4 | 480 | if (iwl_mvm_has_tlc_offload(mvm)) { |
ecaf71de GG |
481 | ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW); |
482 | ieee80211_hw_set(hw, HAS_RATE_CONTROL); | |
483 | } | |
484 | ||
b915c101 SS |
485 | if (iwl_mvm_has_new_rx_api(mvm)) |
486 | ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER); | |
960f864b JB |
487 | |
488 | if (fw_has_capa(&mvm->fw->ucode_capa, | |
489 | IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) { | |
65e25482 | 490 | ieee80211_hw_set(hw, AP_LINK_PS); |
960f864b JB |
491 | } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) { |
492 | /* | |
493 | * we absolutely need this for the new TX API since that comes | |
494 | * with many more queues than the current code can deal with | |
495 | * for station powersave | |
496 | */ | |
497 | return -EINVAL; | |
498 | } | |
8ca151b5 | 499 | |
80938abc JB |
500 | if (mvm->trans->num_rx_queues > 1) |
501 | ieee80211_hw_set(hw, USES_RSS); | |
502 | ||
2d7cf549 JB |
503 | if (mvm->trans->max_skb_frags) |
504 | hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG; | |
505 | ||
c8f54701 | 506 | hw->queues = IEEE80211_MAX_QUEUES; |
398e8c6c | 507 | hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE; |
7b1dd048 EG |
508 | hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC | |
509 | IEEE80211_RADIOTAP_MCS_HAVE_STBC; | |
339b3086 ES |
510 | hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC | |
511 | IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED; | |
371a17ed JB |
512 | |
513 | hw->radiotap_timestamp.units_pos = | |
514 | IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US | | |
515 | IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ; | |
516 | /* this is the case for CCK frames, it's better (only 8) for OFDM */ | |
517 | hw->radiotap_timestamp.accuracy = 22; | |
518 | ||
4243edb4 | 519 | if (!iwl_mvm_has_tlc_offload(mvm)) |
9f66a397 GG |
520 | hw->rate_control_algorithm = RS_NAME; |
521 | ||
848955cc JB |
522 | hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES; |
523 | hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP; | |
438af969 | 524 | hw->max_tx_fragments = mvm->trans->max_skb_frags; |
8ca151b5 | 525 | |
8e160ab8 | 526 | BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6); |
5f4c02e2 JB |
527 | memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers)); |
528 | hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers); | |
529 | hw->wiphy->cipher_suites = mvm->ciphers; | |
530 | ||
2a53d166 AB |
531 | if (iwl_mvm_has_new_rx_api(mvm)) { |
532 | mvm->ciphers[hw->wiphy->n_cipher_suites] = | |
533 | WLAN_CIPHER_SUITE_GCMP; | |
534 | hw->wiphy->n_cipher_suites++; | |
535 | mvm->ciphers[hw->wiphy->n_cipher_suites] = | |
536 | WLAN_CIPHER_SUITE_GCMP_256; | |
537 | hw->wiphy->n_cipher_suites++; | |
538 | } | |
539 | ||
4b87e5af LC |
540 | /* Enable 11w if software crypto is not enabled (as the |
541 | * firmware will interpret some mgmt packets, so enabling it | |
542 | * with software crypto isn't safe). | |
8ca151b5 | 543 | */ |
3b37f4c9 | 544 | if (!iwlwifi_mod_params.swcrypto) { |
30686bf7 | 545 | ieee80211_hw_set(hw, MFP_CAPABLE); |
5f4c02e2 JB |
546 | mvm->ciphers[hw->wiphy->n_cipher_suites] = |
547 | WLAN_CIPHER_SUITE_AES_CMAC; | |
548 | hw->wiphy->n_cipher_suites++; | |
8e160ab8 AB |
549 | if (iwl_mvm_has_new_rx_api(mvm)) { |
550 | mvm->ciphers[hw->wiphy->n_cipher_suites] = | |
551 | WLAN_CIPHER_SUITE_BIP_GMAC_128; | |
552 | hw->wiphy->n_cipher_suites++; | |
553 | mvm->ciphers[hw->wiphy->n_cipher_suites] = | |
554 | WLAN_CIPHER_SUITE_BIP_GMAC_256; | |
555 | hw->wiphy->n_cipher_suites++; | |
556 | } | |
5f4c02e2 JB |
557 | } |
558 | ||
559 | /* currently FW API supports only one optional cipher scheme */ | |
560 | if (mvm->fw->cs[0].cipher) { | |
24ddddf3 JB |
561 | const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0]; |
562 | struct ieee80211_cipher_scheme *cs = &mvm->cs[0]; | |
563 | ||
5f4c02e2 | 564 | mvm->hw->n_cipher_schemes = 1; |
24ddddf3 JB |
565 | |
566 | cs->cipher = le32_to_cpu(fwcs->cipher); | |
567 | cs->iftype = BIT(NL80211_IFTYPE_STATION); | |
568 | cs->hdr_len = fwcs->hdr_len; | |
569 | cs->pn_len = fwcs->pn_len; | |
570 | cs->pn_off = fwcs->pn_off; | |
571 | cs->key_idx_off = fwcs->key_idx_off; | |
572 | cs->key_idx_mask = fwcs->key_idx_mask; | |
573 | cs->key_idx_shift = fwcs->key_idx_shift; | |
574 | cs->mic_len = fwcs->mic_len; | |
575 | ||
576 | mvm->hw->cipher_schemes = mvm->cs; | |
577 | mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher; | |
5f4c02e2 JB |
578 | hw->wiphy->n_cipher_suites++; |
579 | } | |
8ca151b5 | 580 | |
b73f9a4a | 581 | if (fw_has_capa(&mvm->fw->ucode_capa, |
fc36ffda | 582 | IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) { |
b73f9a4a JB |
583 | wiphy_ext_feature_set(hw->wiphy, |
584 | NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER); | |
fc36ffda JB |
585 | hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa; |
586 | } | |
b73f9a4a | 587 | |
30686bf7 | 588 | ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); |
1f940386 LC |
589 | hw->wiphy->features |= |
590 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | | |
3db93420 JB |
591 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR | |
592 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
fb98be5e | 593 | |
8ca151b5 JB |
594 | hw->sta_data_size = sizeof(struct iwl_mvm_sta); |
595 | hw->vif_data_size = sizeof(struct iwl_mvm_vif); | |
fe0f2de3 | 596 | hw->chanctx_data_size = sizeof(u16); |
cfbc6c4c | 597 | hw->txq_data_size = sizeof(struct iwl_mvm_txq); |
8ca151b5 JB |
598 | |
599 | hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | |
3c15a0fb JB |
600 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
601 | BIT(NL80211_IFTYPE_AP) | | |
602 | BIT(NL80211_IFTYPE_P2P_GO) | | |
c13b1725 EG |
603 | BIT(NL80211_IFTYPE_P2P_DEVICE) | |
604 | BIT(NL80211_IFTYPE_ADHOC); | |
5023d966 | 605 | |
a2f73b6c | 606 | hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
e47df5bd JB |
607 | wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS); |
608 | hw->wiphy->features |= NL80211_FEATURE_HT_IBSS; | |
609 | ||
8ba2d7a1 EH |
610 | hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR; |
611 | if (iwl_mvm_is_lar_supported(mvm)) | |
612 | hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED; | |
613 | else | |
614 | hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG | | |
615 | REGULATORY_DISABLE_BEACON_HINTS; | |
8ca151b5 | 616 | |
4b87e5af | 617 | hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; |
94bbed72 | 618 | hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
bd3398e2 | 619 | |
8ca151b5 JB |
620 | hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; |
621 | hw->wiphy->n_iface_combinations = | |
622 | ARRAY_SIZE(iwl_mvm_iface_combinations); | |
623 | ||
c451e6d4 | 624 | hw->wiphy->max_remain_on_channel_duration = 10000; |
8ca151b5 JB |
625 | hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; |
626 | ||
627 | /* Extract MAC address */ | |
628 | memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); | |
629 | hw->wiphy->addresses = mvm->addresses; | |
630 | hw->wiphy->n_addresses = 1; | |
831e85f3 IP |
631 | |
632 | /* Extract additional MAC addresses if available */ | |
633 | num_mac = (mvm->nvm_data->n_hw_addrs > 1) ? | |
634 | min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1; | |
635 | ||
636 | for (i = 1; i < num_mac; i++) { | |
637 | memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr, | |
8ca151b5 | 638 | ETH_ALEN); |
831e85f3 | 639 | mvm->addresses[i].addr[5]++; |
8ca151b5 JB |
640 | hw->wiphy->n_addresses++; |
641 | } | |
642 | ||
fe0f2de3 IP |
643 | iwl_mvm_reset_phy_ctxts(mvm); |
644 | ||
999d2568 | 645 | hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm); |
20f1a5de | 646 | |
8ca151b5 JB |
647 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; |
648 | ||
c7d42480 | 649 | BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK); |
507e4cda LC |
650 | BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) || |
651 | IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK)); | |
652 | ||
859d914c | 653 | if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) |
507e4cda LC |
654 | mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS; |
655 | else | |
656 | mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS; | |
657 | ||
57fbcce3 JB |
658 | if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels) |
659 | hw->wiphy->bands[NL80211_BAND_2GHZ] = | |
660 | &mvm->nvm_data->bands[NL80211_BAND_2GHZ]; | |
661 | if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) { | |
662 | hw->wiphy->bands[NL80211_BAND_5GHZ] = | |
663 | &mvm->nvm_data->bands[NL80211_BAND_5GHZ]; | |
8ca151b5 | 664 | |
859d914c JB |
665 | if (fw_has_capa(&mvm->fw->ucode_capa, |
666 | IWL_UCODE_TLV_CAPA_BEAMFORMER) && | |
667 | fw_has_api(&mvm->fw->ucode_capa, | |
668 | IWL_UCODE_TLV_API_LQ_SS_PARAMS)) | |
57fbcce3 | 669 | hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |= |
3d44eebf ES |
670 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE; |
671 | } | |
672 | ||
8ca151b5 JB |
673 | hw->wiphy->hw_version = mvm->trans->hw_id; |
674 | ||
ade50652 | 675 | if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) |
8ca151b5 JB |
676 | hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; |
677 | else | |
678 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; | |
679 | ||
ca986ad9 | 680 | hw->wiphy->max_sched_scan_reqs = 1; |
9954b37c EG |
681 | hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; |
682 | hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES; | |
683 | /* we create the 802.11 header and zero length SSID IE. */ | |
684 | hw->wiphy->max_sched_scan_ie_len = | |
685 | SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2; | |
cd55ccea AS |
686 | hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS; |
687 | hw->wiphy->max_sched_scan_plan_interval = U16_MAX; | |
688 | ||
689 | /* | |
690 | * the firmware uses u8 for num of iterations, but 0xff is saved for | |
691 | * infinite loop, so the maximum number of iterations is actually 254. | |
692 | */ | |
693 | hw->wiphy->max_sched_scan_plan_iterations = 254; | |
35a000b7 | 694 | |
8ca151b5 | 695 | hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | |
ab480030 | 696 | NL80211_FEATURE_LOW_PRIORITY_SCAN | |
0d8614b4 | 697 | NL80211_FEATURE_P2P_GO_OPPPS | |
a904a08b | 698 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | |
0d8614b4 | 699 | NL80211_FEATURE_DYNAMIC_SMPS | |
9b5452fd EG |
700 | NL80211_FEATURE_STATIC_SMPS | |
701 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION; | |
8ca151b5 | 702 | |
859d914c JB |
703 | if (fw_has_capa(&mvm->fw->ucode_capa, |
704 | IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)) | |
f1daa00e | 705 | hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION; |
859d914c JB |
706 | if (fw_has_capa(&mvm->fw->ucode_capa, |
707 | IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)) | |
226bcd48 | 708 | hw->wiphy->features |= NL80211_FEATURE_QUIET; |
f1daa00e | 709 | |
859d914c JB |
710 | if (fw_has_capa(&mvm->fw->ucode_capa, |
711 | IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)) | |
73897bd1 AO |
712 | hw->wiphy->features |= |
713 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES; | |
714 | ||
859d914c JB |
715 | if (fw_has_capa(&mvm->fw->ucode_capa, |
716 | IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)) | |
73897bd1 AO |
717 | hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES; |
718 | ||
aacf8f18 AS |
719 | if (fw_has_api(&mvm->fw->ucode_capa, |
720 | IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) { | |
721 | wiphy_ext_feature_set(hw->wiphy, | |
722 | NL80211_EXT_FEATURE_SCAN_START_TIME); | |
723 | wiphy_ext_feature_set(hw->wiphy, | |
724 | NL80211_EXT_FEATURE_BSS_PARENT_TSF); | |
725 | wiphy_ext_feature_set(hw->wiphy, | |
726 | NL80211_EXT_FEATURE_SET_SCAN_DWELL); | |
727 | } | |
728 | ||
8f691af9 ZR |
729 | if (iwl_mvm_is_oce_supported(mvm)) { |
730 | wiphy_ext_feature_set(hw->wiphy, | |
731 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP); | |
732 | wiphy_ext_feature_set(hw->wiphy, | |
733 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME); | |
734 | wiphy_ext_feature_set(hw->wiphy, | |
735 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION); | |
736 | wiphy_ext_feature_set(hw->wiphy, | |
737 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE); | |
738 | } | |
739 | ||
7360f99e EG |
740 | if (mvm->nvm_data->sku_cap_11ax_enable && |
741 | !iwlwifi_mod_params.disable_11ax) { | |
742 | hw->wiphy->iftype_ext_capab = he_iftypes_ext_capa; | |
743 | hw->wiphy->num_iftype_ext_capab = | |
744 | ARRAY_SIZE(he_iftypes_ext_capa); | |
918cbf39 SS |
745 | |
746 | ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID); | |
747 | ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID); | |
7360f99e EG |
748 | } |
749 | ||
8ca151b5 JB |
750 | mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
751 | ||
752 | #ifdef CONFIG_PM_SLEEP | |
d15a747f EP |
753 | if (iwl_mvm_is_d0i3_supported(mvm) && |
754 | device_can_wakeup(mvm->trans->dev)) { | |
755 | mvm->wowlan.flags = WIPHY_WOWLAN_ANY; | |
756 | hw->wiphy->wowlan = &mvm->wowlan; | |
91742449 EP |
757 | } |
758 | ||
3f37c229 | 759 | if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) && |
8ca151b5 JB |
760 | mvm->trans->ops->d3_suspend && |
761 | mvm->trans->ops->d3_resume && | |
762 | device_can_wakeup(mvm->trans->dev)) { | |
91742449 EP |
763 | mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT | |
764 | WIPHY_WOWLAN_DISCONNECT | | |
765 | WIPHY_WOWLAN_EAP_IDENTITY_REQ | | |
766 | WIPHY_WOWLAN_RFKILL_RELEASE | | |
767 | WIPHY_WOWLAN_NET_DETECT; | |
3b37f4c9 | 768 | if (!iwlwifi_mod_params.swcrypto) |
964dc9e2 JB |
769 | mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | |
770 | WIPHY_WOWLAN_GTK_REKEY_FAILURE | | |
771 | WIPHY_WOWLAN_4WAY_HANDSHAKE; | |
772 | ||
773 | mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; | |
774 | mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; | |
775 | mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; | |
c55385f5 | 776 | mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES; |
964dc9e2 | 777 | hw->wiphy->wowlan = &mvm->wowlan; |
8ca151b5 JB |
778 | } |
779 | #endif | |
780 | ||
77736923 EP |
781 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
782 | /* assign default bcast filtering configuration */ | |
783 | mvm->bcast_filters = iwl_mvm_default_bcast_filters; | |
784 | #endif | |
785 | ||
8ca151b5 JB |
786 | ret = iwl_mvm_leds_init(mvm); |
787 | if (ret) | |
788 | return ret; | |
789 | ||
859d914c JB |
790 | if (fw_has_capa(&mvm->fw->ucode_capa, |
791 | IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) { | |
d8f1c515 AN |
792 | IWL_DEBUG_TDLS(mvm, "TDLS supported\n"); |
793 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; | |
7c4f0843 | 794 | ieee80211_hw_set(hw, TDLS_WIDER_BW); |
d8f1c515 AN |
795 | } |
796 | ||
859d914c JB |
797 | if (fw_has_capa(&mvm->fw->ucode_capa, |
798 | IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) { | |
1d3c3f63 AN |
799 | IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n"); |
800 | hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH; | |
801 | } | |
802 | ||
93190fb0 | 803 | hw->netdev_features |= mvm->cfg->features; |
5e6a98dc SS |
804 | if (!iwl_mvm_is_csum_supported(mvm)) { |
805 | hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS | | |
806 | NETIF_F_RXCSUM); | |
807 | /* We may support SW TX CSUM */ | |
808 | if (IWL_MVM_SW_TX_CSUM_OFFLOAD) | |
809 | hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS; | |
810 | } | |
41837ca9 | 811 | |
91b08c2d AE |
812 | if (mvm->cfg->vht_mu_mimo_supported) |
813 | wiphy_ext_feature_set(hw->wiphy, | |
814 | NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER); | |
815 | ||
de645e89 JB |
816 | ret = ieee80211_register_hw(mvm->hw); |
817 | if (ret) { | |
818 | iwl_mvm_leds_exit(mvm); | |
de645e89 JB |
819 | } |
820 | ||
b7327d89 | 821 | return ret; |
8ca151b5 JB |
822 | } |
823 | ||
b2492501 AN |
824 | static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm, |
825 | struct ieee80211_sta *sta, | |
826 | struct sk_buff *skb) | |
827 | { | |
828 | struct iwl_mvm_sta *mvmsta; | |
829 | bool defer = false; | |
830 | ||
831 | /* | |
832 | * double check the IN_D0I3 flag both before and after | |
833 | * taking the spinlock, in order to prevent taking | |
834 | * the spinlock when not needed. | |
835 | */ | |
836 | if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))) | |
837 | return false; | |
838 | ||
839 | spin_lock(&mvm->d0i3_tx_lock); | |
840 | /* | |
841 | * testing the flag again ensures the skb dequeue | |
842 | * loop (on d0i3 exit) hasn't run yet. | |
843 | */ | |
844 | if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) | |
845 | goto out; | |
846 | ||
847 | mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
0ae98812 | 848 | if (mvmsta->sta_id == IWL_MVM_INVALID_STA || |
b2492501 AN |
849 | mvmsta->sta_id != mvm->d0i3_ap_sta_id) |
850 | goto out; | |
851 | ||
852 | __skb_queue_tail(&mvm->d0i3_tx, skb); | |
b2492501 AN |
853 | |
854 | /* trigger wakeup */ | |
855 | iwl_mvm_ref(mvm, IWL_MVM_REF_TX); | |
856 | iwl_mvm_unref(mvm, IWL_MVM_REF_TX); | |
857 | ||
858 | defer = true; | |
859 | out: | |
860 | spin_unlock(&mvm->d0i3_tx_lock); | |
861 | return defer; | |
862 | } | |
863 | ||
8ca151b5 JB |
864 | static void iwl_mvm_mac_tx(struct ieee80211_hw *hw, |
865 | struct ieee80211_tx_control *control, | |
866 | struct sk_buff *skb) | |
867 | { | |
868 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
3e56eadf JB |
869 | struct ieee80211_sta *sta = control->sta; |
870 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
871 | struct ieee80211_hdr *hdr = (void *)skb->data; | |
cfbc6c4c SS |
872 | bool offchannel = IEEE80211_SKB_CB(skb)->flags & |
873 | IEEE80211_TX_CTL_TX_OFFCHAN; | |
8ca151b5 | 874 | |
9ee718aa EL |
875 | if (iwl_mvm_is_radio_killed(mvm)) { |
876 | IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); | |
8ca151b5 JB |
877 | goto drop; |
878 | } | |
879 | ||
cfbc6c4c | 880 | if (offchannel && |
a6cc5163 MG |
881 | !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) && |
882 | !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status)) | |
8ca151b5 JB |
883 | goto drop; |
884 | ||
eb045e6e DS |
885 | /* treat non-bufferable MMPDUs on AP interfaces as broadcast */ |
886 | if ((info->control.vif->type == NL80211_IFTYPE_AP || | |
887 | info->control.vif->type == NL80211_IFTYPE_ADHOC) && | |
888 | ieee80211_is_mgmt(hdr->frame_control) && | |
889 | !ieee80211_is_bufferable_mmpdu(hdr->frame_control)) | |
3e56eadf JB |
890 | sta = NULL; |
891 | ||
dc1aca22 | 892 | /* If there is no sta, and it's not offchannel - send through AP */ |
cfbc6c4c SS |
893 | if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION && |
894 | !offchannel) { | |
dc1aca22 AO |
895 | struct iwl_mvm_vif *mvmvif = |
896 | iwl_mvm_vif_from_mac80211(info->control.vif); | |
897 | u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id); | |
898 | ||
899 | if (ap_sta_id < IWL_MVM_STATION_COUNT) { | |
900 | /* mac80211 holds rcu read lock */ | |
901 | sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]); | |
902 | if (IS_ERR_OR_NULL(sta)) | |
903 | goto drop; | |
904 | } | |
905 | } | |
906 | ||
3e56eadf | 907 | if (sta) { |
b2492501 AN |
908 | if (iwl_mvm_defer_tx(mvm, sta, skb)) |
909 | return; | |
3e56eadf | 910 | if (iwl_mvm_tx_skb(mvm, skb, sta)) |
8ca151b5 JB |
911 | goto drop; |
912 | return; | |
913 | } | |
914 | ||
915 | if (iwl_mvm_tx_skb_non_sta(mvm, skb)) | |
916 | goto drop; | |
917 | return; | |
918 | drop: | |
919 | ieee80211_free_txskb(hw, skb); | |
920 | } | |
921 | ||
cfbc6c4c | 922 | void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq) |
205e2210 | 923 | { |
cfbc6c4c SS |
924 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
925 | struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); | |
926 | struct sk_buff *skb = NULL; | |
927 | ||
fba8248e SS |
928 | /* |
929 | * No need for threads to be pending here, they can leave the first | |
930 | * taker all the work. | |
931 | * | |
932 | * mvmtxq->tx_request logic: | |
933 | * | |
934 | * If 0, no one is currently TXing, set to 1 to indicate current thread | |
935 | * will now start TX and other threads should quit. | |
936 | * | |
937 | * If 1, another thread is currently TXing, set to 2 to indicate to | |
938 | * that thread that there was another request. Since that request may | |
939 | * have raced with the check whether the queue is empty, the TXing | |
940 | * thread should check the queue's status one more time before leaving. | |
941 | * This check is done in order to not leave any TX hanging in the queue | |
942 | * until the next TX invocation (which may not even happen). | |
943 | * | |
944 | * If 2, another thread is currently TXing, and it will already double | |
945 | * check the queue, so do nothing. | |
946 | */ | |
947 | if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2)) | |
948 | return; | |
cfbc6c4c SS |
949 | |
950 | rcu_read_lock(); | |
fba8248e SS |
951 | do { |
952 | while (likely(!mvmtxq->stopped && | |
953 | (mvm->trans->system_pm_mode == | |
954 | IWL_PLAT_PM_MODE_DISABLED))) { | |
955 | skb = ieee80211_tx_dequeue(hw, txq); | |
956 | ||
f50d693b SS |
957 | if (!skb) { |
958 | if (txq->sta) | |
959 | IWL_DEBUG_TX(mvm, | |
960 | "TXQ of sta %pM tid %d is now empty\n", | |
961 | txq->sta->addr, | |
962 | txq->tid); | |
fba8248e | 963 | break; |
f50d693b | 964 | } |
fba8248e SS |
965 | |
966 | if (!txq->sta) | |
967 | iwl_mvm_tx_skb_non_sta(mvm, skb); | |
968 | else | |
969 | iwl_mvm_tx_skb(mvm, skb, txq->sta); | |
970 | } | |
971 | } while (atomic_dec_return(&mvmtxq->tx_request)); | |
cfbc6c4c | 972 | rcu_read_unlock(); |
205e2210 EG |
973 | } |
974 | ||
cfbc6c4c SS |
975 | static void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw, |
976 | struct ieee80211_txq *txq) | |
205e2210 | 977 | { |
cfbc6c4c SS |
978 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
979 | struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); | |
205e2210 | 980 | |
cfbc6c4c SS |
981 | /* |
982 | * Please note that racing is handled very carefully here: | |
983 | * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is | |
984 | * deleted afterwards. | |
985 | * This means that if: | |
986 | * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list): | |
987 | * queue is allocated and we can TX. | |
988 | * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list): | |
989 | * a race, should defer the frame. | |
990 | * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list): | |
991 | * need to allocate the queue and defer the frame. | |
992 | * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list): | |
993 | * queue is already scheduled for allocation, no need to allocate, | |
994 | * should defer the frame. | |
995 | */ | |
996 | ||
997 | /* If the queue is allocated TX and return. */ | |
998 | if (!txq->sta || mvmtxq->txq_id != IWL_MVM_INVALID_QUEUE) { | |
999 | /* | |
1000 | * Check that list is empty to avoid a race where txq_id is | |
1001 | * already updated, but the queue allocation work wasn't | |
1002 | * finished | |
1003 | */ | |
1004 | if (unlikely(txq->sta && !list_empty(&mvmtxq->list))) | |
1005 | return; | |
1006 | ||
1007 | iwl_mvm_mac_itxq_xmit(hw, txq); | |
1008 | return; | |
1009 | } | |
1010 | ||
1011 | /* The list is being deleted only after the queue is fully allocated. */ | |
1012 | if (!list_empty(&mvmtxq->list)) | |
1013 | return; | |
1014 | ||
1015 | list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs); | |
1016 | schedule_work(&mvm->add_stream_wk); | |
205e2210 EG |
1017 | } |
1018 | ||
7174beb6 JB |
1019 | #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \ |
1020 | do { \ | |
1021 | if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \ | |
1022 | break; \ | |
1023 | iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \ | |
4203263d EG |
1024 | } while (0) |
1025 | ||
1026 | static void | |
1027 | iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif, | |
1028 | struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn, | |
1029 | enum ieee80211_ampdu_mlme_action action) | |
1030 | { | |
1031 | struct iwl_fw_dbg_trigger_tlv *trig; | |
1032 | struct iwl_fw_dbg_trigger_ba *ba_trig; | |
1033 | ||
6c042d75 SS |
1034 | trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), |
1035 | FW_DBG_TRIGGER_BA); | |
1036 | if (!trig) | |
4203263d EG |
1037 | return; |
1038 | ||
4203263d EG |
1039 | ba_trig = (void *)trig->data; |
1040 | ||
4203263d EG |
1041 | switch (action) { |
1042 | case IEEE80211_AMPDU_TX_OPERATIONAL: { | |
1043 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
1044 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; | |
1045 | ||
1046 | CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid, | |
1047 | "TX AGG START: MAC %pM tid %d ssn %d\n", | |
1048 | sta->addr, tid, tid_data->ssn); | |
1049 | break; | |
1050 | } | |
1051 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
1052 | CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid, | |
1053 | "TX AGG STOP: MAC %pM tid %d\n", | |
1054 | sta->addr, tid); | |
1055 | break; | |
1056 | case IEEE80211_AMPDU_RX_START: | |
1057 | CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid, | |
1058 | "RX AGG START: MAC %pM tid %d ssn %d\n", | |
1059 | sta->addr, tid, rx_ba_ssn); | |
1060 | break; | |
1061 | case IEEE80211_AMPDU_RX_STOP: | |
1062 | CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid, | |
1063 | "RX AGG STOP: MAC %pM tid %d\n", | |
1064 | sta->addr, tid); | |
1065 | break; | |
1066 | default: | |
1067 | break; | |
1068 | } | |
1069 | } | |
1070 | ||
8ca151b5 JB |
1071 | static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, |
1072 | struct ieee80211_vif *vif, | |
50ea05ef | 1073 | struct ieee80211_ampdu_params *params) |
8ca151b5 JB |
1074 | { |
1075 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1076 | int ret; | |
b2492501 | 1077 | bool tx_agg_ref = false; |
50ea05ef SS |
1078 | struct ieee80211_sta *sta = params->sta; |
1079 | enum ieee80211_ampdu_mlme_action action = params->action; | |
1080 | u16 tid = params->tid; | |
1081 | u16 *ssn = ¶ms->ssn; | |
514c3069 | 1082 | u16 buf_size = params->buf_size; |
bb81bb68 | 1083 | bool amsdu = params->amsdu; |
10b2b201 | 1084 | u16 timeout = params->timeout; |
8ca151b5 JB |
1085 | |
1086 | IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", | |
1087 | sta->addr, tid, action); | |
1088 | ||
1089 | if (!(mvm->nvm_data->sku_cap_11n_enable)) | |
1090 | return -EACCES; | |
1091 | ||
b2492501 | 1092 | /* return from D0i3 before starting a new Tx aggregation */ |
9256c205 EP |
1093 | switch (action) { |
1094 | case IEEE80211_AMPDU_TX_START: | |
1095 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
1096 | case IEEE80211_AMPDU_TX_STOP_FLUSH: | |
1097 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
1098 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
b2492501 | 1099 | /* |
9256c205 EP |
1100 | * for tx start, wait synchronously until D0i3 exit to |
1101 | * get the correct sequence number for the tid. | |
1102 | * additionally, some other ampdu actions use direct | |
1103 | * target access, which is not handled automatically | |
1104 | * by the trans layer (unlike commands), so wait for | |
1105 | * d0i3 exit in these cases as well. | |
b2492501 | 1106 | */ |
d40fc489 GG |
1107 | ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG); |
1108 | if (ret) | |
1109 | return ret; | |
1110 | ||
1111 | tx_agg_ref = true; | |
9256c205 EP |
1112 | break; |
1113 | default: | |
1114 | break; | |
b2492501 AN |
1115 | } |
1116 | ||
8ca151b5 JB |
1117 | mutex_lock(&mvm->mutex); |
1118 | ||
1119 | switch (action) { | |
1120 | case IEEE80211_AMPDU_RX_START: | |
b0ffe455 JB |
1121 | if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id == |
1122 | iwl_mvm_sta_from_mac80211(sta)->sta_id) { | |
1123 | struct iwl_mvm_vif *mvmvif; | |
1124 | u16 macid = iwl_mvm_vif_from_mac80211(vif)->id; | |
1125 | struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid]; | |
1126 | ||
1127 | mdata->opened_rx_ba_sessions = true; | |
1128 | mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1129 | cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk); | |
1130 | } | |
e78da25e | 1131 | if (!iwl_enable_rx_ampdu()) { |
8ca151b5 JB |
1132 | ret = -EINVAL; |
1133 | break; | |
1134 | } | |
10b2b201 SS |
1135 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size, |
1136 | timeout); | |
8ca151b5 JB |
1137 | break; |
1138 | case IEEE80211_AMPDU_RX_STOP: | |
10b2b201 SS |
1139 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size, |
1140 | timeout); | |
8ca151b5 JB |
1141 | break; |
1142 | case IEEE80211_AMPDU_TX_START: | |
e78da25e | 1143 | if (!iwl_enable_tx_ampdu()) { |
5d158efa EG |
1144 | ret = -EINVAL; |
1145 | break; | |
1146 | } | |
8ca151b5 JB |
1147 | ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); |
1148 | break; | |
1149 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
e3d9e7ce EG |
1150 | ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); |
1151 | break; | |
8ca151b5 JB |
1152 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
1153 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
e3d9e7ce | 1154 | ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); |
8ca151b5 JB |
1155 | break; |
1156 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
bb81bb68 EG |
1157 | ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, |
1158 | buf_size, amsdu); | |
8ca151b5 JB |
1159 | break; |
1160 | default: | |
1161 | WARN_ON_ONCE(1); | |
1162 | ret = -EINVAL; | |
1163 | break; | |
1164 | } | |
4203263d EG |
1165 | |
1166 | if (!ret) { | |
1167 | u16 rx_ba_ssn = 0; | |
1168 | ||
1169 | if (action == IEEE80211_AMPDU_RX_START) | |
1170 | rx_ba_ssn = *ssn; | |
1171 | ||
1172 | iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid, | |
1173 | rx_ba_ssn, action); | |
1174 | } | |
8ca151b5 JB |
1175 | mutex_unlock(&mvm->mutex); |
1176 | ||
b2492501 AN |
1177 | /* |
1178 | * If the tid is marked as started, we won't use it for offloaded | |
1179 | * traffic on the next D0i3 entry. It's safe to unref. | |
1180 | */ | |
1181 | if (tx_agg_ref) | |
1182 | iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG); | |
1183 | ||
8ca151b5 JB |
1184 | return ret; |
1185 | } | |
1186 | ||
1187 | static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, | |
1188 | struct ieee80211_vif *vif) | |
1189 | { | |
1190 | struct iwl_mvm *mvm = data; | |
1191 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1192 | ||
1193 | mvmvif->uploaded = false; | |
0ae98812 | 1194 | mvmvif->ap_sta_id = IWL_MVM_INVALID_STA; |
8ca151b5 | 1195 | |
8ca151b5 JB |
1196 | spin_lock_bh(&mvm->time_event_lock); |
1197 | iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); | |
1198 | spin_unlock_bh(&mvm->time_event_lock); | |
1199 | ||
fe0f2de3 | 1200 | mvmvif->phy_ctxt = NULL; |
8a275bad | 1201 | memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data)); |
86e177d8 | 1202 | memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data)); |
8ca151b5 JB |
1203 | } |
1204 | ||
1205 | static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) | |
1206 | { | |
744cb695 EP |
1207 | /* cleanup all stale references (scan, roc), but keep the |
1208 | * ucode_down ref until reconfig is complete | |
1209 | */ | |
1210 | iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN); | |
1211 | ||
fcb6b92a | 1212 | iwl_mvm_stop_device(mvm); |
8ca151b5 | 1213 | |
9bf13bee JB |
1214 | mvm->cur_aid = 0; |
1215 | ||
9af91f46 | 1216 | mvm->scan_status = 0; |
b1873300 | 1217 | mvm->ps_disabled = false; |
b3500b47 | 1218 | mvm->rfkill_safe_init_done = false; |
8ca151b5 JB |
1219 | |
1220 | /* just in case one was running */ | |
305d236e | 1221 | iwl_mvm_cleanup_roc_te(mvm); |
8ca151b5 JB |
1222 | ieee80211_remain_on_channel_expired(mvm->hw); |
1223 | ||
fc36ffda JB |
1224 | iwl_mvm_ftm_restart(mvm); |
1225 | ||
737719fe AN |
1226 | /* |
1227 | * cleanup all interfaces, even inactive ones, as some might have | |
1228 | * gone down during the HW restart | |
1229 | */ | |
1230 | ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm); | |
8ca151b5 | 1231 | |
fe0f2de3 | 1232 | mvm->p2p_device_vif = NULL; |
0ae98812 | 1233 | mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA; |
fe0f2de3 IP |
1234 | |
1235 | iwl_mvm_reset_phy_ctxts(mvm); | |
9c3deeb5 | 1236 | memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); |
8a275bad | 1237 | memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); |
8a275bad | 1238 | memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd)); |
8ca151b5 JB |
1239 | |
1240 | ieee80211_wake_queues(mvm->hw); | |
1241 | ||
228670b2 EP |
1242 | /* clear any stale d0i3 state */ |
1243 | clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status); | |
1244 | ||
8ca151b5 | 1245 | mvm->vif_count = 0; |
113a0447 | 1246 | mvm->rx_ba_sessions = 0; |
7174beb6 | 1247 | mvm->fwrt.dump.conf = FW_DBG_INVALID; |
baf41bc3 | 1248 | mvm->monitor_on = false; |
91a8bcde JB |
1249 | |
1250 | /* keep statistics ticking */ | |
1251 | iwl_mvm_accu_radio_stats(mvm); | |
8ca151b5 JB |
1252 | } |
1253 | ||
a0a09243 | 1254 | int __iwl_mvm_mac_start(struct iwl_mvm *mvm) |
8ca151b5 | 1255 | { |
8ca151b5 JB |
1256 | int ret; |
1257 | ||
a0a09243 | 1258 | lockdep_assert_held(&mvm->mutex); |
8ca151b5 | 1259 | |
bf8b286f JB |
1260 | if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) { |
1261 | /* | |
1262 | * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART | |
1263 | * so later code will - from now on - see that we're doing it. | |
1264 | */ | |
1265 | set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); | |
1266 | clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status); | |
a42b2af3 | 1267 | /* Clean up some internal and mac80211 state on restart */ |
8ca151b5 | 1268 | iwl_mvm_restart_cleanup(mvm); |
a42b2af3 LC |
1269 | } else { |
1270 | /* Hold the reference to prevent runtime suspend while | |
1271 | * the start procedure runs. It's a bit confusing | |
1272 | * that the UCODE_DOWN reference is taken, but it just | |
1273 | * means "UCODE is not UP yet". ( TODO: rename this | |
1274 | * reference). | |
1275 | */ | |
1276 | iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN); | |
1277 | } | |
8ca151b5 | 1278 | ret = iwl_mvm_up(mvm); |
c47af22a | 1279 | |
da2eb669 SS |
1280 | iwl_fw_dbg_apply_point(&mvm->fwrt, IWL_FW_INI_APPLY_POST_INIT); |
1281 | ||
c47af22a JB |
1282 | if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
1283 | /* Something went wrong - we need to finish some cleanup | |
1284 | * that normally iwl_mvm_mac_restart_complete() below | |
1285 | * would do. | |
1286 | */ | |
1287 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); | |
a75b9b33 | 1288 | #ifdef CONFIG_PM |
c47af22a | 1289 | iwl_mvm_d0i3_enable_tx(mvm, NULL); |
a75b9b33 | 1290 | #endif |
c47af22a JB |
1291 | } |
1292 | ||
a0a09243 LC |
1293 | return ret; |
1294 | } | |
1295 | ||
1296 | static int iwl_mvm_mac_start(struct ieee80211_hw *hw) | |
1297 | { | |
1298 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1299 | int ret; | |
1300 | ||
37948fcf EP |
1301 | /* Some hw restart cleanups must not hold the mutex */ |
1302 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { | |
1303 | /* | |
1304 | * Make sure we are out of d0i3. This is needed | |
1305 | * to make sure the reference accounting is correct | |
1306 | * (and there is no stale d0i3_exit_work). | |
1307 | */ | |
1308 | wait_event_timeout(mvm->d0i3_exit_waitq, | |
1309 | !test_bit(IWL_MVM_STATUS_IN_D0I3, | |
1310 | &mvm->status), | |
1311 | HZ); | |
1312 | } | |
1313 | ||
a0a09243 LC |
1314 | mutex_lock(&mvm->mutex); |
1315 | ret = __iwl_mvm_mac_start(mvm); | |
8ca151b5 JB |
1316 | mutex_unlock(&mvm->mutex); |
1317 | ||
1318 | return ret; | |
1319 | } | |
1320 | ||
cf2c92d8 | 1321 | static void iwl_mvm_restart_complete(struct iwl_mvm *mvm) |
8ca151b5 | 1322 | { |
8ca151b5 JB |
1323 | int ret; |
1324 | ||
1325 | mutex_lock(&mvm->mutex); | |
1326 | ||
1327 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); | |
a75b9b33 | 1328 | #ifdef CONFIG_PM |
b2492501 | 1329 | iwl_mvm_d0i3_enable_tx(mvm, NULL); |
a75b9b33 | 1330 | #endif |
e7afe89f | 1331 | ret = iwl_mvm_update_quotas(mvm, true, NULL); |
8ca151b5 JB |
1332 | if (ret) |
1333 | IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", | |
1334 | ret); | |
1335 | ||
7498cf4c EP |
1336 | /* allow transport/FW low power modes */ |
1337 | iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN); | |
1338 | ||
f130bb75 MG |
1339 | iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY); |
1340 | ||
cbd2ae2d AN |
1341 | /* |
1342 | * If we have TDLS peers, remove them. We don't know the last seqno/PN | |
1343 | * of packets the FW sent out, so we must reconnect. | |
1344 | */ | |
1345 | iwl_mvm_teardown_tdls_peers(mvm); | |
1346 | ||
8ca151b5 JB |
1347 | mutex_unlock(&mvm->mutex); |
1348 | } | |
1349 | ||
088070a2 EP |
1350 | static void iwl_mvm_resume_complete(struct iwl_mvm *mvm) |
1351 | { | |
b7282643 LC |
1352 | if (iwl_mvm_is_d0i3_supported(mvm) && |
1353 | iwl_mvm_enter_d0i3_on_suspend(mvm)) | |
1354 | WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq, | |
1355 | !test_bit(IWL_MVM_STATUS_IN_D0I3, | |
1356 | &mvm->status), | |
1357 | HZ), | |
1358 | "D0i3 exit on resume timed out\n"); | |
088070a2 EP |
1359 | } |
1360 | ||
cf2c92d8 EP |
1361 | static void |
1362 | iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw, | |
1363 | enum ieee80211_reconfig_type reconfig_type) | |
1364 | { | |
1365 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1366 | ||
1367 | switch (reconfig_type) { | |
1368 | case IEEE80211_RECONFIG_TYPE_RESTART: | |
1369 | iwl_mvm_restart_complete(mvm); | |
1370 | break; | |
1371 | case IEEE80211_RECONFIG_TYPE_SUSPEND: | |
088070a2 | 1372 | iwl_mvm_resume_complete(mvm); |
cf2c92d8 EP |
1373 | break; |
1374 | } | |
1375 | } | |
1376 | ||
a0a09243 | 1377 | void __iwl_mvm_mac_stop(struct iwl_mvm *mvm) |
8ca151b5 | 1378 | { |
a0a09243 | 1379 | lockdep_assert_held(&mvm->mutex); |
7498cf4c | 1380 | |
91a8bcde JB |
1381 | /* firmware counters are obviously reset now, but we shouldn't |
1382 | * partially track so also clear the fw_reset_accu counters. | |
1383 | */ | |
1384 | memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats)); | |
1385 | ||
8ca151b5 JB |
1386 | /* async_handlers_wk is now blocked */ |
1387 | ||
1388 | /* | |
1389 | * The work item could be running or queued if the | |
1390 | * ROC time event stops just as we get here. | |
1391 | */ | |
c779273b | 1392 | flush_work(&mvm->roc_done_wk); |
8ca151b5 | 1393 | |
fcb6b92a | 1394 | iwl_mvm_stop_device(mvm); |
8ca151b5 JB |
1395 | |
1396 | iwl_mvm_async_handlers_purge(mvm); | |
1397 | /* async_handlers_list is empty and will stay empty: HW is stopped */ | |
1398 | ||
1399 | /* the fw is stopped, the aux sta is dead: clean up driver state */ | |
712b24ad | 1400 | iwl_mvm_del_aux_sta(mvm); |
8ca151b5 | 1401 | |
0a79a0c0 | 1402 | /* |
155f7e04 EG |
1403 | * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the |
1404 | * hw (as restart_complete() won't be called in this case) and mac80211 | |
1405 | * won't execute the restart. | |
8b2b9fbf AN |
1406 | * But make sure to cleanup interfaces that have gone down before/during |
1407 | * HW restart was requested. | |
0a79a0c0 | 1408 | */ |
155f7e04 EG |
1409 | if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) || |
1410 | test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, | |
1411 | &mvm->status)) | |
8b2b9fbf AN |
1412 | ieee80211_iterate_interfaces(mvm->hw, 0, |
1413 | iwl_mvm_cleanup_iterator, mvm); | |
0a79a0c0 | 1414 | |
963221be AB |
1415 | /* We shouldn't have any UIDs still set. Loop over all the UIDs to |
1416 | * make sure there's nothing left there and warn if any is found. | |
1417 | */ | |
859d914c | 1418 | if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { |
963221be AB |
1419 | int i; |
1420 | ||
507e4cda | 1421 | for (i = 0; i < mvm->max_scans; i++) { |
6185af2a LC |
1422 | if (WARN_ONCE(mvm->scan_uid_status[i], |
1423 | "UMAC scan UID %d status was not cleaned\n", | |
1424 | i)) | |
1425 | mvm->scan_uid_status[i] = 0; | |
963221be AB |
1426 | } |
1427 | } | |
a0a09243 | 1428 | } |
bc44886d | 1429 | |
a0a09243 LC |
1430 | static void iwl_mvm_mac_stop(struct ieee80211_hw *hw) |
1431 | { | |
1432 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1433 | ||
1434 | flush_work(&mvm->d0i3_exit_work); | |
1435 | flush_work(&mvm->async_handlers_wk); | |
24afba76 | 1436 | flush_work(&mvm->add_stream_wk); |
771147b0 JB |
1437 | |
1438 | /* | |
1439 | * Lock and clear the firmware running bit here already, so that | |
1440 | * new commands coming in elsewhere, e.g. from debugfs, will not | |
1441 | * be able to proceed. This is important here because one of those | |
7174beb6 | 1442 | * debugfs files causes the firmware dump to be triggered, and if we |
771147b0 JB |
1443 | * don't stop debugfs accesses before canceling that it could be |
1444 | * retriggered after we flush it but before we've cleared the bit. | |
1445 | */ | |
1446 | clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); | |
1447 | ||
c7ab138e | 1448 | iwl_fw_cancel_dumps(&mvm->fwrt); |
d3a108a4 | 1449 | cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork); |
69e04642 | 1450 | cancel_delayed_work_sync(&mvm->scan_timeout_dwork); |
7174beb6 | 1451 | iwl_fw_free_dump_desc(&mvm->fwrt); |
a0a09243 LC |
1452 | |
1453 | mutex_lock(&mvm->mutex); | |
1454 | __iwl_mvm_mac_stop(mvm); | |
8ca151b5 JB |
1455 | mutex_unlock(&mvm->mutex); |
1456 | ||
1457 | /* | |
1458 | * The worker might have been waiting for the mutex, let it run and | |
1459 | * discover that its list is now empty. | |
1460 | */ | |
1461 | cancel_work_sync(&mvm->async_handlers_wk); | |
1462 | } | |
1463 | ||
fe0f2de3 IP |
1464 | static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) |
1465 | { | |
1466 | u16 i; | |
1467 | ||
1468 | lockdep_assert_held(&mvm->mutex); | |
1469 | ||
1470 | for (i = 0; i < NUM_PHY_CTX; i++) | |
1471 | if (!mvm->phy_ctxts[i].ref) | |
1472 | return &mvm->phy_ctxts[i]; | |
1473 | ||
1474 | IWL_ERR(mvm, "No available PHY context\n"); | |
1475 | return NULL; | |
1476 | } | |
1477 | ||
d44c3fe6 AA |
1478 | static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
1479 | s16 tx_power) | |
1480 | { | |
0791c2fc HD |
1481 | int len; |
1482 | union { | |
1483 | struct iwl_dev_tx_power_cmd v5; | |
1484 | struct iwl_dev_tx_power_cmd_v4 v4; | |
1485 | } cmd = { | |
1486 | .v5.v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC), | |
1487 | .v5.v3.mac_context_id = | |
d44c3fe6 | 1488 | cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id), |
0791c2fc | 1489 | .v5.v3.pwr_restriction = cpu_to_le16(8 * tx_power), |
d44c3fe6 AA |
1490 | }; |
1491 | ||
d44c3fe6 | 1492 | if (tx_power == IWL_DEFAULT_MAX_TX_POWER) |
0791c2fc | 1493 | cmd.v5.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER); |
d44c3fe6 | 1494 | |
0791c2fc HD |
1495 | if (fw_has_api(&mvm->fw->ucode_capa, |
1496 | IWL_UCODE_TLV_API_REDUCE_TX_POWER)) | |
1497 | len = sizeof(cmd.v5); | |
1498 | else if (fw_has_capa(&mvm->fw->ucode_capa, | |
1499 | IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) | |
1500 | len = sizeof(cmd.v4); | |
1501 | else | |
1502 | len = sizeof(cmd.v4.v3); | |
da03f029 JB |
1503 | |
1504 | return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd); | |
d44c3fe6 AA |
1505 | } |
1506 | ||
f6780614 SS |
1507 | static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw, |
1508 | struct ieee80211_vif *vif) | |
1509 | { | |
1510 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1511 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1512 | int ret; | |
1513 | ||
1514 | mutex_lock(&mvm->mutex); | |
1515 | ||
1516 | if (mvmvif->csa_failed) { | |
1517 | mvmvif->csa_failed = false; | |
1518 | ret = -EIO; | |
1519 | goto out_unlock; | |
1520 | } | |
1521 | ||
1522 | if (vif->type == NL80211_IFTYPE_STATION) { | |
1523 | struct iwl_mvm_sta *mvmsta; | |
1524 | ||
1525 | mvmvif->csa_bcn_pending = false; | |
1526 | mvmsta = iwl_mvm_sta_from_staid_protected(mvm, | |
1527 | mvmvif->ap_sta_id); | |
1528 | ||
1529 | if (WARN_ON(!mvmsta)) { | |
1530 | ret = -EIO; | |
1531 | goto out_unlock; | |
1532 | } | |
1533 | ||
1534 | iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false); | |
1535 | ||
1536 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); | |
1537 | ||
1538 | ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); | |
1539 | if (ret) | |
1540 | goto out_unlock; | |
1541 | ||
1542 | iwl_mvm_stop_session_protection(mvm, vif); | |
1543 | } | |
1544 | ||
1545 | mvmvif->ps_disabled = false; | |
1546 | ||
1547 | ret = iwl_mvm_power_update_ps(mvm); | |
1548 | ||
1549 | out_unlock: | |
1550 | mutex_unlock(&mvm->mutex); | |
1551 | ||
1552 | return ret; | |
1553 | } | |
1554 | ||
1555 | static void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw, | |
1556 | struct ieee80211_vif *vif) | |
1557 | { | |
1558 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1559 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1560 | struct iwl_chan_switch_te_cmd cmd = { | |
1561 | .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, | |
1562 | mvmvif->color)), | |
1563 | .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE), | |
1564 | }; | |
1565 | ||
1566 | IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id); | |
1567 | ||
1568 | mutex_lock(&mvm->mutex); | |
1569 | WARN_ON(iwl_mvm_send_cmd_pdu(mvm, | |
1570 | WIDE_ID(MAC_CONF_GROUP, | |
1571 | CHANNEL_SWITCH_TIME_EVENT_CMD), | |
1572 | 0, sizeof(cmd), &cmd)); | |
1573 | mutex_unlock(&mvm->mutex); | |
1574 | ||
1575 | WARN_ON(iwl_mvm_post_channel_switch(hw, vif)); | |
1576 | } | |
1577 | ||
1578 | static void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk) | |
1579 | { | |
1580 | struct iwl_mvm *mvm; | |
1581 | struct iwl_mvm_vif *mvmvif; | |
1582 | struct ieee80211_vif *vif; | |
1583 | ||
1584 | mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work); | |
1585 | vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv); | |
1586 | mvm = mvmvif->mvm; | |
1587 | ||
1588 | iwl_mvm_abort_channel_switch(mvm->hw, vif); | |
1589 | ieee80211_chswitch_done(vif, false); | |
1590 | } | |
1591 | ||
8ca151b5 JB |
1592 | static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, |
1593 | struct ieee80211_vif *vif) | |
1594 | { | |
1595 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1596 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1597 | int ret; | |
1598 | ||
aa5e1832 | 1599 | mvmvif->mvm = mvm; |
86e177d8 | 1600 | RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL); |
aa5e1832 | 1601 | |
d40fc489 GG |
1602 | /* |
1603 | * make sure D0i3 exit is completed, otherwise a target access | |
1604 | * during tx queue configuration could be done when still in | |
1605 | * D0i3 state. | |
1606 | */ | |
1607 | ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF); | |
1608 | if (ret) | |
1609 | return ret; | |
1610 | ||
8ca151b5 JB |
1611 | /* |
1612 | * Not much to do here. The stack will not allow interface | |
1613 | * types or combinations that we didn't advertise, so we | |
1614 | * don't really have to check the types. | |
1615 | */ | |
1616 | ||
1617 | mutex_lock(&mvm->mutex); | |
1618 | ||
33cef925 JB |
1619 | /* make sure that beacon statistics don't go backwards with FW reset */ |
1620 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) | |
1621 | mvmvif->beacon_stats.accu_num_beacons += | |
1622 | mvmvif->beacon_stats.num_beacons; | |
1623 | ||
e89044d7 | 1624 | /* Allocate resources for the MAC context, and add it to the fw */ |
8ca151b5 JB |
1625 | ret = iwl_mvm_mac_ctxt_init(mvm, vif); |
1626 | if (ret) | |
1627 | goto out_unlock; | |
1628 | ||
698478c4 SS |
1629 | rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif); |
1630 | ||
1c2abf72 | 1631 | /* Counting number of interfaces is needed for legacy PM */ |
ea183d02 IP |
1632 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) |
1633 | mvm->vif_count++; | |
ea183d02 | 1634 | |
8ca151b5 JB |
1635 | /* |
1636 | * The AP binding flow can be done only after the beacon | |
1637 | * template is configured (which happens only in the mac80211 | |
1638 | * start_ap() flow), and adding the broadcast station can happen | |
1639 | * only after the binding. | |
1640 | * In addition, since modifying the MAC before adding a bcast | |
1641 | * station is not allowed by the FW, delay the adding of MAC context to | |
1642 | * the point where we can also add the bcast station. | |
1643 | * In short: there's not much we can do at this point, other than | |
1644 | * allocating resources :) | |
1645 | */ | |
5023d966 JB |
1646 | if (vif->type == NL80211_IFTYPE_AP || |
1647 | vif->type == NL80211_IFTYPE_ADHOC) { | |
013290aa | 1648 | ret = iwl_mvm_alloc_bcast_sta(mvm, vif); |
8ca151b5 JB |
1649 | if (ret) { |
1650 | IWL_ERR(mvm, "Failed to allocate bcast sta\n"); | |
1651 | goto out_release; | |
1652 | } | |
1653 | ||
c8f54701 JB |
1654 | /* |
1655 | * Only queue for this station is the mcast queue, | |
1656 | * which shouldn't be in TFD mask anyway | |
1657 | */ | |
1658 | ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta, | |
1659 | 0, vif->type, | |
1660 | IWL_STA_MULTICAST); | |
1661 | if (ret) | |
1662 | goto out_release; | |
26d6c16b | 1663 | |
77740cb4 | 1664 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
8ca151b5 JB |
1665 | goto out_unlock; |
1666 | } | |
1667 | ||
93190fb0 AA |
1668 | mvmvif->features |= hw->netdev_features; |
1669 | ||
8ca151b5 JB |
1670 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
1671 | if (ret) | |
1672 | goto out_release; | |
1673 | ||
999609f1 | 1674 | ret = iwl_mvm_power_update_mac(mvm); |
e5e7aa8e | 1675 | if (ret) |
fd66fc1c | 1676 | goto out_remove_mac; |
8ca151b5 | 1677 | |
7df15b1e | 1678 | /* beacon filtering */ |
a1022927 | 1679 | ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); |
bd3351ba EP |
1680 | if (ret) |
1681 | goto out_remove_mac; | |
1682 | ||
7df15b1e | 1683 | if (!mvm->bf_allowed_vif && |
73e5f2c5 | 1684 | vif->type == NL80211_IFTYPE_STATION && !vif->p2p) { |
7df15b1e | 1685 | mvm->bf_allowed_vif = mvmvif; |
a20fd398 AO |
1686 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | |
1687 | IEEE80211_VIF_SUPPORTS_CQM_RSSI; | |
7df15b1e HG |
1688 | } |
1689 | ||
8ca151b5 JB |
1690 | /* |
1691 | * P2P_DEVICE interface does not have a channel context assigned to it, | |
1692 | * so a dedicated PHY context is allocated to it and the corresponding | |
1693 | * MAC context is bound to it at this stage. | |
1694 | */ | |
1695 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
8ca151b5 | 1696 | |
fe0f2de3 IP |
1697 | mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
1698 | if (!mvmvif->phy_ctxt) { | |
1699 | ret = -ENOSPC; | |
bd3351ba | 1700 | goto out_free_bf; |
fe0f2de3 | 1701 | } |
8ca151b5 | 1702 | |
53a9d61e | 1703 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
8ca151b5 JB |
1704 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
1705 | if (ret) | |
53a9d61e | 1706 | goto out_unref_phy; |
8ca151b5 | 1707 | |
d197358b | 1708 | ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif); |
8ca151b5 JB |
1709 | if (ret) |
1710 | goto out_unbind; | |
1711 | ||
1712 | /* Save a pointer to p2p device vif, so it can later be used to | |
1713 | * update the p2p device MAC when a GO is started/stopped */ | |
1714 | mvm->p2p_device_vif = vif; | |
1715 | } | |
1716 | ||
b0ffe455 | 1717 | iwl_mvm_tcm_add_vif(mvm, vif); |
f6780614 SS |
1718 | INIT_DELAYED_WORK(&mvmvif->csa_work, |
1719 | iwl_mvm_channel_switch_disconnect_wk); | |
b0ffe455 | 1720 | |
baf41bc3 ST |
1721 | if (vif->type == NL80211_IFTYPE_MONITOR) |
1722 | mvm->monitor_on = true; | |
1723 | ||
63494374 | 1724 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
8ca151b5 JB |
1725 | goto out_unlock; |
1726 | ||
1727 | out_unbind: | |
1728 | iwl_mvm_binding_remove_vif(mvm, vif); | |
53a9d61e | 1729 | out_unref_phy: |
fe0f2de3 | 1730 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
bd3351ba EP |
1731 | out_free_bf: |
1732 | if (mvm->bf_allowed_vif == mvmvif) { | |
1733 | mvm->bf_allowed_vif = NULL; | |
a20fd398 AO |
1734 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
1735 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); | |
bd3351ba | 1736 | } |
8ca151b5 JB |
1737 | out_remove_mac: |
1738 | mvmvif->phy_ctxt = NULL; | |
1739 | iwl_mvm_mac_ctxt_remove(mvm, vif); | |
1740 | out_release: | |
5ee2b215 AB |
1741 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) |
1742 | mvm->vif_count--; | |
8ca151b5 JB |
1743 | out_unlock: |
1744 | mutex_unlock(&mvm->mutex); | |
1745 | ||
d40fc489 GG |
1746 | iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF); |
1747 | ||
8ca151b5 JB |
1748 | return ret; |
1749 | } | |
1750 | ||
38a12b5b JB |
1751 | static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, |
1752 | struct ieee80211_vif *vif) | |
8ca151b5 | 1753 | { |
8ca151b5 JB |
1754 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
1755 | /* | |
1756 | * Flush the ROC worker which will flush the OFFCHANNEL queue. | |
1757 | * We assume here that all the packets sent to the OFFCHANNEL | |
1758 | * queue are sent in ROC session. | |
1759 | */ | |
1760 | flush_work(&mvm->roc_done_wk); | |
8ca151b5 | 1761 | } |
38a12b5b JB |
1762 | } |
1763 | ||
1764 | static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, | |
1765 | struct ieee80211_vif *vif) | |
1766 | { | |
1767 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1768 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
86e177d8 | 1769 | struct iwl_probe_resp_data *probe_data; |
38a12b5b JB |
1770 | |
1771 | iwl_mvm_prepare_mac_removal(mvm, vif); | |
8ca151b5 | 1772 | |
b0ffe455 JB |
1773 | if (!(vif->type == NL80211_IFTYPE_AP || |
1774 | vif->type == NL80211_IFTYPE_ADHOC)) | |
1775 | iwl_mvm_tcm_rm_vif(mvm, vif); | |
1776 | ||
8ca151b5 JB |
1777 | mutex_lock(&mvm->mutex); |
1778 | ||
86e177d8 GG |
1779 | probe_data = rcu_dereference_protected(mvmvif->probe_resp_data, |
1780 | lockdep_is_held(&mvm->mutex)); | |
1781 | RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL); | |
1782 | if (probe_data) | |
1783 | kfree_rcu(probe_data, rcu_head); | |
1784 | ||
7df15b1e HG |
1785 | if (mvm->bf_allowed_vif == mvmvif) { |
1786 | mvm->bf_allowed_vif = NULL; | |
a20fd398 AO |
1787 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
1788 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); | |
7df15b1e HG |
1789 | } |
1790 | ||
b73f9a4a JB |
1791 | if (vif->bss_conf.ftm_responder) |
1792 | memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats)); | |
1793 | ||
63494374 JB |
1794 | iwl_mvm_vif_dbgfs_clean(mvm, vif); |
1795 | ||
8ca151b5 JB |
1796 | /* |
1797 | * For AP/GO interface, the tear down of the resources allocated to the | |
38a12b5b | 1798 | * interface is be handled as part of the stop_ap flow. |
8ca151b5 | 1799 | */ |
5023d966 JB |
1800 | if (vif->type == NL80211_IFTYPE_AP || |
1801 | vif->type == NL80211_IFTYPE_ADHOC) { | |
507cadf2 DS |
1802 | #ifdef CONFIG_NL80211_TESTMODE |
1803 | if (vif == mvm->noa_vif) { | |
1804 | mvm->noa_vif = NULL; | |
1805 | mvm->noa_duration = 0; | |
1806 | } | |
1807 | #endif | |
26d6c16b | 1808 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta); |
013290aa | 1809 | iwl_mvm_dealloc_bcast_sta(mvm, vif); |
8ca151b5 JB |
1810 | goto out_release; |
1811 | } | |
1812 | ||
1813 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
1814 | mvm->p2p_device_vif = NULL; | |
d197358b | 1815 | iwl_mvm_rm_p2p_bcast_sta(mvm, vif); |
8ca151b5 | 1816 | iwl_mvm_binding_remove_vif(mvm, vif); |
fe0f2de3 | 1817 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
8ca151b5 JB |
1818 | mvmvif->phy_ctxt = NULL; |
1819 | } | |
1820 | ||
5ee2b215 | 1821 | if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE) |
8ca151b5 | 1822 | mvm->vif_count--; |
1c2abf72 | 1823 | |
999609f1 | 1824 | iwl_mvm_power_update_mac(mvm); |
8ca151b5 JB |
1825 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
1826 | ||
698478c4 SS |
1827 | RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL); |
1828 | ||
baf41bc3 ST |
1829 | if (vif->type == NL80211_IFTYPE_MONITOR) |
1830 | mvm->monitor_on = false; | |
1831 | ||
8ca151b5 | 1832 | out_release: |
8ca151b5 JB |
1833 | mutex_unlock(&mvm->mutex); |
1834 | } | |
1835 | ||
1836 | static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed) | |
88f2fd73 | 1837 | { |
8ca151b5 JB |
1838 | return 0; |
1839 | } | |
1840 | ||
e59647ea EP |
1841 | struct iwl_mvm_mc_iter_data { |
1842 | struct iwl_mvm *mvm; | |
1843 | int port_id; | |
1844 | }; | |
1845 | ||
1846 | static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac, | |
1847 | struct ieee80211_vif *vif) | |
1848 | { | |
1849 | struct iwl_mvm_mc_iter_data *data = _data; | |
1850 | struct iwl_mvm *mvm = data->mvm; | |
1851 | struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd; | |
97bce57b LC |
1852 | struct iwl_host_cmd hcmd = { |
1853 | .id = MCAST_FILTER_CMD, | |
1854 | .flags = CMD_ASYNC, | |
1855 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, | |
1856 | }; | |
e59647ea EP |
1857 | int ret, len; |
1858 | ||
1859 | /* if we don't have free ports, mcast frames will be dropped */ | |
1860 | if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM)) | |
1861 | return; | |
1862 | ||
1863 | if (vif->type != NL80211_IFTYPE_STATION || | |
1864 | !vif->bss_conf.assoc) | |
1865 | return; | |
1866 | ||
1867 | cmd->port_id = data->port_id++; | |
1868 | memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); | |
1869 | len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); | |
1870 | ||
97bce57b LC |
1871 | hcmd.len[0] = len; |
1872 | hcmd.data[0] = cmd; | |
1873 | ||
1874 | ret = iwl_mvm_send_cmd(mvm, &hcmd); | |
e59647ea EP |
1875 | if (ret) |
1876 | IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret); | |
1877 | } | |
1878 | ||
1879 | static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm) | |
1880 | { | |
1881 | struct iwl_mvm_mc_iter_data iter_data = { | |
1882 | .mvm = mvm, | |
88f2fd73 MG |
1883 | }; |
1884 | ||
e59647ea EP |
1885 | lockdep_assert_held(&mvm->mutex); |
1886 | ||
1887 | if (WARN_ON_ONCE(!mvm->mcast_filter_cmd)) | |
1888 | return; | |
1889 | ||
1c4abec0 | 1890 | ieee80211_iterate_active_interfaces_atomic( |
e59647ea EP |
1891 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
1892 | iwl_mvm_mc_iface_iterator, &iter_data); | |
88f2fd73 MG |
1893 | } |
1894 | ||
e59647ea EP |
1895 | static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw, |
1896 | struct netdev_hw_addr_list *mc_list) | |
8ca151b5 | 1897 | { |
e59647ea EP |
1898 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
1899 | struct iwl_mcast_filter_cmd *cmd; | |
1900 | struct netdev_hw_addr *addr; | |
f3bd58f4 MS |
1901 | int addr_count; |
1902 | bool pass_all; | |
e59647ea EP |
1903 | int len; |
1904 | ||
f3bd58f4 MS |
1905 | addr_count = netdev_hw_addr_list_count(mc_list); |
1906 | pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES || | |
1907 | IWL_MVM_FW_MCAST_FILTER_PASS_ALL; | |
1908 | if (pass_all) | |
e59647ea | 1909 | addr_count = 0; |
e59647ea EP |
1910 | |
1911 | len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); | |
1912 | cmd = kzalloc(len, GFP_ATOMIC); | |
1913 | if (!cmd) | |
1914 | return 0; | |
1915 | ||
1916 | if (pass_all) { | |
1917 | cmd->pass_all = 1; | |
1918 | return (u64)(unsigned long)cmd; | |
1919 | } | |
1920 | ||
1921 | netdev_hw_addr_list_for_each(addr, mc_list) { | |
1922 | IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n", | |
1923 | cmd->count, addr->addr); | |
1924 | memcpy(&cmd->addr_list[cmd->count * ETH_ALEN], | |
1925 | addr->addr, ETH_ALEN); | |
1926 | cmd->count++; | |
1927 | } | |
1928 | ||
1929 | return (u64)(unsigned long)cmd; | |
8ca151b5 JB |
1930 | } |
1931 | ||
1932 | static void iwl_mvm_configure_filter(struct ieee80211_hw *hw, | |
1933 | unsigned int changed_flags, | |
1934 | unsigned int *total_flags, | |
1935 | u64 multicast) | |
1936 | { | |
e59647ea EP |
1937 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
1938 | struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; | |
8ca151b5 | 1939 | |
e59647ea | 1940 | mutex_lock(&mvm->mutex); |
51b6b9e0 | 1941 | |
e59647ea EP |
1942 | /* replace previous configuration */ |
1943 | kfree(mvm->mcast_filter_cmd); | |
1944 | mvm->mcast_filter_cmd = cmd; | |
51b6b9e0 | 1945 | |
e59647ea EP |
1946 | if (!cmd) |
1947 | goto out; | |
51b6b9e0 | 1948 | |
61e7d91b LC |
1949 | if (changed_flags & FIF_ALLMULTI) |
1950 | cmd->pass_all = !!(*total_flags & FIF_ALLMULTI); | |
1951 | ||
1952 | if (cmd->pass_all) | |
1953 | cmd->count = 0; | |
1954 | ||
e59647ea EP |
1955 | iwl_mvm_recalc_multicast(mvm); |
1956 | out: | |
1957 | mutex_unlock(&mvm->mutex); | |
1958 | *total_flags = 0; | |
51b6b9e0 EG |
1959 | } |
1960 | ||
effd1929 AO |
1961 | static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw, |
1962 | struct ieee80211_vif *vif, | |
1963 | unsigned int filter_flags, | |
1964 | unsigned int changed_flags) | |
1965 | { | |
1966 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1967 | ||
1968 | /* We support only filter for probe requests */ | |
1969 | if (!(changed_flags & FIF_PROBE_REQ)) | |
1970 | return; | |
1971 | ||
1972 | /* Supported only for p2p client interfaces */ | |
1973 | if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc || | |
1974 | !vif->p2p) | |
1975 | return; | |
1976 | ||
1977 | mutex_lock(&mvm->mutex); | |
1978 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); | |
1979 | mutex_unlock(&mvm->mutex); | |
1980 | } | |
1981 | ||
c87163b9 EP |
1982 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
1983 | struct iwl_bcast_iter_data { | |
1984 | struct iwl_mvm *mvm; | |
1985 | struct iwl_bcast_filter_cmd *cmd; | |
1986 | u8 current_filter; | |
1987 | }; | |
1988 | ||
1989 | static void | |
1990 | iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif, | |
1991 | const struct iwl_fw_bcast_filter *in_filter, | |
1992 | struct iwl_fw_bcast_filter *out_filter) | |
1993 | { | |
1994 | struct iwl_fw_bcast_filter_attr *attr; | |
1995 | int i; | |
1996 | ||
1997 | memcpy(out_filter, in_filter, sizeof(*out_filter)); | |
1998 | ||
1999 | for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) { | |
2000 | attr = &out_filter->attrs[i]; | |
2001 | ||
2002 | if (!attr->mask) | |
2003 | break; | |
2004 | ||
2ee8f021 EP |
2005 | switch (attr->reserved1) { |
2006 | case cpu_to_le16(BC_FILTER_MAGIC_IP): | |
2007 | if (vif->bss_conf.arp_addr_cnt != 1) { | |
2008 | attr->mask = 0; | |
2009 | continue; | |
2010 | } | |
2011 | ||
2012 | attr->val = vif->bss_conf.arp_addr_list[0]; | |
2013 | break; | |
2014 | case cpu_to_le16(BC_FILTER_MAGIC_MAC): | |
2015 | attr->val = *(__be32 *)&vif->addr[2]; | |
2016 | break; | |
2017 | default: | |
2018 | break; | |
2019 | } | |
2020 | attr->reserved1 = 0; | |
c87163b9 EP |
2021 | out_filter->num_attrs++; |
2022 | } | |
2023 | } | |
2024 | ||
2025 | static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac, | |
2026 | struct ieee80211_vif *vif) | |
2027 | { | |
2028 | struct iwl_bcast_iter_data *data = _data; | |
2029 | struct iwl_mvm *mvm = data->mvm; | |
2030 | struct iwl_bcast_filter_cmd *cmd = data->cmd; | |
2031 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
2032 | struct iwl_fw_bcast_mac *bcast_mac; | |
2033 | int i; | |
2034 | ||
2035 | if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs))) | |
2036 | return; | |
2037 | ||
2038 | bcast_mac = &cmd->macs[mvmvif->id]; | |
2039 | ||
e48393e8 IP |
2040 | /* |
2041 | * enable filtering only for associated stations, but not for P2P | |
2042 | * Clients | |
2043 | */ | |
2044 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p || | |
2045 | !vif->bss_conf.assoc) | |
c87163b9 EP |
2046 | return; |
2047 | ||
2048 | bcast_mac->default_discard = 1; | |
2049 | ||
2050 | /* copy all configured filters */ | |
2051 | for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) { | |
2052 | /* | |
2053 | * Make sure we don't exceed our filters limit. | |
2054 | * if there is still a valid filter to be configured, | |
2055 | * be on the safe side and just allow bcast for this mac. | |
2056 | */ | |
2057 | if (WARN_ON_ONCE(data->current_filter >= | |
2058 | ARRAY_SIZE(cmd->filters))) { | |
2059 | bcast_mac->default_discard = 0; | |
2060 | bcast_mac->attached_filters = 0; | |
2061 | break; | |
2062 | } | |
2063 | ||
2064 | iwl_mvm_set_bcast_filter(vif, | |
2065 | &mvm->bcast_filters[i], | |
2066 | &cmd->filters[data->current_filter]); | |
2067 | ||
2068 | /* skip current filter if it contains no attributes */ | |
2069 | if (!cmd->filters[data->current_filter].num_attrs) | |
2070 | continue; | |
2071 | ||
2072 | /* attach the filter to current mac */ | |
2073 | bcast_mac->attached_filters |= | |
2074 | cpu_to_le16(BIT(data->current_filter)); | |
2075 | ||
2076 | data->current_filter++; | |
2077 | } | |
2078 | } | |
2079 | ||
de06a59e EP |
2080 | bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm, |
2081 | struct iwl_bcast_filter_cmd *cmd) | |
c87163b9 | 2082 | { |
c87163b9 EP |
2083 | struct iwl_bcast_iter_data iter_data = { |
2084 | .mvm = mvm, | |
de06a59e | 2085 | .cmd = cmd, |
c87163b9 EP |
2086 | }; |
2087 | ||
3b8983b1 MS |
2088 | if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL) |
2089 | return false; | |
2090 | ||
de06a59e EP |
2091 | memset(cmd, 0, sizeof(*cmd)); |
2092 | cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters); | |
2093 | cmd->max_macs = ARRAY_SIZE(cmd->macs); | |
2094 | ||
2095 | #ifdef CONFIG_IWLWIFI_DEBUGFS | |
2096 | /* use debugfs filters/macs if override is configured */ | |
2097 | if (mvm->dbgfs_bcast_filtering.override) { | |
2098 | memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters, | |
2099 | sizeof(cmd->filters)); | |
2100 | memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs, | |
2101 | sizeof(cmd->macs)); | |
2102 | return true; | |
2103 | } | |
2104 | #endif | |
c87163b9 EP |
2105 | |
2106 | /* if no filters are configured, do nothing */ | |
2107 | if (!mvm->bcast_filters) | |
de06a59e | 2108 | return false; |
c87163b9 EP |
2109 | |
2110 | /* configure and attach these filters for each associated sta vif */ | |
2111 | ieee80211_iterate_active_interfaces( | |
2112 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
2113 | iwl_mvm_bcast_filter_iterator, &iter_data); | |
2114 | ||
de06a59e EP |
2115 | return true; |
2116 | } | |
34672bb3 EP |
2117 | |
2118 | static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm) | |
de06a59e EP |
2119 | { |
2120 | struct iwl_bcast_filter_cmd cmd; | |
2121 | ||
2122 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING)) | |
2123 | return 0; | |
2124 | ||
2125 | if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) | |
2126 | return 0; | |
2127 | ||
a1022927 | 2128 | return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0, |
c87163b9 EP |
2129 | sizeof(cmd), &cmd); |
2130 | } | |
2131 | #else | |
34672bb3 | 2132 | static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm) |
c87163b9 EP |
2133 | { |
2134 | return 0; | |
2135 | } | |
2136 | #endif | |
2137 | ||
a07a8f37 SS |
2138 | static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm, |
2139 | struct ieee80211_vif *vif) | |
2140 | { | |
2141 | struct iwl_mu_group_mgmt_cmd cmd = {}; | |
2142 | ||
2143 | memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership, | |
2144 | WLAN_MEMBERSHIP_LEN); | |
2145 | memcpy(cmd.user_position, vif->bss_conf.mu_group.position, | |
2146 | WLAN_USER_POSITION_LEN); | |
2147 | ||
2148 | return iwl_mvm_send_cmd_pdu(mvm, | |
2149 | WIDE_ID(DATA_PATH_GROUP, | |
2150 | UPDATE_MU_GROUPS_CMD), | |
2151 | 0, sizeof(cmd), &cmd); | |
2152 | } | |
2153 | ||
f92659a1 SS |
2154 | static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac, |
2155 | struct ieee80211_vif *vif) | |
2156 | { | |
2157 | if (vif->mu_mimo_owner) { | |
2158 | struct iwl_mu_group_mgmt_notif *notif = _data; | |
2159 | ||
2160 | /* | |
2161 | * MU-MIMO Group Id action frame is little endian. We treat | |
2162 | * the data received from firmware as if it came from the | |
2163 | * action frame, so no conversion is needed. | |
2164 | */ | |
2165 | ieee80211_update_mu_groups(vif, | |
2166 | (u8 *)¬if->membership_status, | |
2167 | (u8 *)¬if->user_position); | |
2168 | } | |
2169 | } | |
2170 | ||
2171 | void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm, | |
2172 | struct iwl_rx_cmd_buffer *rxb) | |
2173 | { | |
2174 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
2175 | struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data; | |
2176 | ||
2177 | ieee80211_iterate_active_interfaces_atomic( | |
2178 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
2179 | iwl_mvm_mu_mimo_iface_iterator, notif); | |
2180 | } | |
2181 | ||
514c3069 LC |
2182 | static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit) |
2183 | { | |
2184 | u8 byte_num = ppe_pos_bit / 8; | |
2185 | u8 bit_num = ppe_pos_bit % 8; | |
2186 | u8 residue_bits; | |
2187 | u8 res; | |
2188 | ||
2189 | if (bit_num <= 5) | |
2190 | return (ppe[byte_num] >> bit_num) & | |
2191 | (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1); | |
2192 | ||
2193 | /* | |
2194 | * If bit_num > 5, we have to combine bits with next byte. | |
2195 | * Calculate how many bits we need to take from current byte (called | |
2196 | * here "residue_bits"), and add them to bits from next byte. | |
2197 | */ | |
2198 | ||
2199 | residue_bits = 8 - bit_num; | |
2200 | ||
2201 | res = (ppe[byte_num + 1] & | |
2202 | (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) << | |
2203 | residue_bits; | |
2204 | res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1); | |
2205 | ||
2206 | return res; | |
2207 | } | |
2208 | ||
2209 | static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm, | |
2210 | struct ieee80211_vif *vif, u8 sta_id) | |
2211 | { | |
2212 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
2213 | struct iwl_he_sta_context_cmd sta_ctxt_cmd = { | |
2214 | .sta_id = sta_id, | |
2215 | .tid_limit = IWL_MAX_TID_COUNT, | |
2216 | .bss_color = vif->bss_conf.bss_color, | |
2217 | .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext, | |
2218 | .frame_time_rts_th = | |
2219 | cpu_to_le16(vif->bss_conf.frame_time_rts_th), | |
2220 | }; | |
d14ae796 SS |
2221 | int size = fw_has_api(&mvm->fw->ucode_capa, |
2222 | IWL_UCODE_TLV_API_MBSSID_HE) ? | |
2223 | sizeof(sta_ctxt_cmd) : | |
2224 | sizeof(struct iwl_he_sta_context_cmd_v1); | |
514c3069 LC |
2225 | struct ieee80211_sta *sta; |
2226 | u32 flags; | |
2227 | int i; | |
2228 | ||
2229 | rcu_read_lock(); | |
2230 | ||
2231 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]); | |
2232 | if (IS_ERR(sta)) { | |
2233 | rcu_read_unlock(); | |
2234 | WARN(1, "Can't find STA to configure HE\n"); | |
2235 | return; | |
2236 | } | |
2237 | ||
2238 | if (!sta->he_cap.has_he) { | |
2239 | rcu_read_unlock(); | |
2240 | return; | |
2241 | } | |
2242 | ||
2243 | flags = 0; | |
2244 | ||
2245 | /* HTC flags */ | |
2246 | if (sta->he_cap.he_cap_elem.mac_cap_info[0] & | |
2247 | IEEE80211_HE_MAC_CAP0_HTC_HE) | |
2248 | sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT); | |
2249 | if ((sta->he_cap.he_cap_elem.mac_cap_info[1] & | |
2250 | IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) || | |
2251 | (sta->he_cap.he_cap_elem.mac_cap_info[2] & | |
2252 | IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) { | |
2253 | u8 link_adap = | |
2254 | ((sta->he_cap.he_cap_elem.mac_cap_info[2] & | |
2255 | IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) + | |
2256 | (sta->he_cap.he_cap_elem.mac_cap_info[1] & | |
2257 | IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION); | |
2258 | ||
2259 | if (link_adap == 2) | |
2260 | sta_ctxt_cmd.htc_flags |= | |
2261 | cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED); | |
2262 | else if (link_adap == 3) | |
2263 | sta_ctxt_cmd.htc_flags |= | |
2264 | cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH); | |
2265 | } | |
514c3069 LC |
2266 | if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR) |
2267 | sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP); | |
2268 | if (sta->he_cap.he_cap_elem.mac_cap_info[3] & | |
2269 | IEEE80211_HE_MAC_CAP3_OMI_CONTROL) | |
2270 | sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP); | |
2271 | if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR) | |
2272 | sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP); | |
2273 | ||
189b8d44 NG |
2274 | /* |
2275 | * Initialize the PPE thresholds to "None" (7), as described in Table | |
2276 | * 9-262ac of 80211.ax/D3.0. | |
2277 | */ | |
2278 | memset(&sta_ctxt_cmd.pkt_ext, 7, sizeof(sta_ctxt_cmd.pkt_ext)); | |
2279 | ||
2280 | /* If PPE Thresholds exist, parse them into a FW-familiar format. */ | |
514c3069 LC |
2281 | if (sta->he_cap.he_cap_elem.phy_cap_info[6] & |
2282 | IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { | |
2283 | u8 nss = (sta->he_cap.ppe_thres[0] & | |
2284 | IEEE80211_PPE_THRES_NSS_MASK) + 1; | |
2285 | u8 ru_index_bitmap = | |
2286 | (sta->he_cap.ppe_thres[0] & | |
2287 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >> | |
2288 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS; | |
2289 | u8 *ppe = &sta->he_cap.ppe_thres[0]; | |
2290 | u8 ppe_pos_bit = 7; /* Starting after PPE header */ | |
2291 | ||
2292 | /* | |
2293 | * FW currently supports only nss == MAX_HE_SUPP_NSS | |
2294 | * | |
2295 | * If nss > MAX: we can ignore values we don't support | |
2296 | * If nss < MAX: we can set zeros in other streams | |
2297 | */ | |
2298 | if (nss > MAX_HE_SUPP_NSS) { | |
2299 | IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss, | |
2300 | MAX_HE_SUPP_NSS); | |
2301 | nss = MAX_HE_SUPP_NSS; | |
2302 | } | |
2303 | ||
2304 | for (i = 0; i < nss; i++) { | |
2305 | u8 ru_index_tmp = ru_index_bitmap << 1; | |
2306 | u8 bw; | |
2307 | ||
2308 | for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) { | |
2309 | ru_index_tmp >>= 1; | |
2310 | if (!(ru_index_tmp & 1)) | |
2311 | continue; | |
2312 | ||
2313 | sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] = | |
2314 | iwl_mvm_he_get_ppe_val(ppe, | |
2315 | ppe_pos_bit); | |
2316 | ppe_pos_bit += | |
2317 | IEEE80211_PPE_THRES_INFO_PPET_SIZE; | |
2318 | sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] = | |
2319 | iwl_mvm_he_get_ppe_val(ppe, | |
2320 | ppe_pos_bit); | |
2321 | ppe_pos_bit += | |
2322 | IEEE80211_PPE_THRES_INFO_PPET_SIZE; | |
2323 | } | |
2324 | } | |
2325 | ||
2326 | flags |= STA_CTXT_HE_PACKET_EXT; | |
77ff2c6b LK |
2327 | } else if ((sta->he_cap.he_cap_elem.phy_cap_info[9] & |
2328 | IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) != | |
2329 | IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_RESERVED) { | |
2330 | int low_th = -1; | |
2331 | int high_th = -1; | |
2332 | ||
2333 | /* Take the PPE thresholds from the nominal padding info */ | |
2334 | switch (sta->he_cap.he_cap_elem.phy_cap_info[9] & | |
2335 | IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) { | |
2336 | case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_0US: | |
2337 | low_th = IWL_HE_PKT_EXT_NONE; | |
2338 | high_th = IWL_HE_PKT_EXT_NONE; | |
2339 | break; | |
2340 | case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_8US: | |
2341 | low_th = IWL_HE_PKT_EXT_BPSK; | |
2342 | high_th = IWL_HE_PKT_EXT_NONE; | |
2343 | break; | |
2344 | case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_16US: | |
2345 | low_th = IWL_HE_PKT_EXT_NONE; | |
2346 | high_th = IWL_HE_PKT_EXT_BPSK; | |
2347 | break; | |
2348 | } | |
2349 | ||
2350 | /* Set the PPE thresholds accordingly */ | |
2351 | if (low_th >= 0 && high_th >= 0) { | |
0bfefe2f LK |
2352 | struct iwl_he_pkt_ext *pkt_ext = |
2353 | (struct iwl_he_pkt_ext *)&sta_ctxt_cmd.pkt_ext; | |
77ff2c6b LK |
2354 | |
2355 | for (i = 0; i < MAX_HE_SUPP_NSS; i++) { | |
2356 | u8 bw; | |
2357 | ||
2358 | for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; | |
2359 | bw++) { | |
0bfefe2f LK |
2360 | pkt_ext->pkt_ext_qam_th[i][bw][0] = |
2361 | low_th; | |
2362 | pkt_ext->pkt_ext_qam_th[i][bw][1] = | |
2363 | high_th; | |
77ff2c6b LK |
2364 | } |
2365 | } | |
2366 | ||
2367 | flags |= STA_CTXT_HE_PACKET_EXT; | |
2368 | } | |
514c3069 LC |
2369 | } |
2370 | rcu_read_unlock(); | |
2371 | ||
2372 | /* Mark MU EDCA as enabled, unless none detected on some AC */ | |
2373 | flags |= STA_CTXT_HE_MU_EDCA_CW; | |
5cc74f65 | 2374 | for (i = 0; i < IEEE80211_NUM_ACS; i++) { |
514c3069 LC |
2375 | struct ieee80211_he_mu_edca_param_ac_rec *mu_edca = |
2376 | &mvmvif->queue_params[i].mu_edca_param_rec; | |
5cc74f65 | 2377 | u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i); |
514c3069 LC |
2378 | |
2379 | if (!mvmvif->queue_params[i].mu_edca) { | |
2380 | flags &= ~STA_CTXT_HE_MU_EDCA_CW; | |
2381 | break; | |
2382 | } | |
2383 | ||
5cc74f65 | 2384 | sta_ctxt_cmd.trig_based_txf[ac].cwmin = |
514c3069 | 2385 | cpu_to_le16(mu_edca->ecw_min_max & 0xf); |
5cc74f65 | 2386 | sta_ctxt_cmd.trig_based_txf[ac].cwmax = |
514c3069 | 2387 | cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4); |
5cc74f65 | 2388 | sta_ctxt_cmd.trig_based_txf[ac].aifsn = |
514c3069 | 2389 | cpu_to_le16(mu_edca->aifsn); |
5cc74f65 | 2390 | sta_ctxt_cmd.trig_based_txf[ac].mu_time = |
514c3069 LC |
2391 | cpu_to_le16(mu_edca->mu_edca_timer); |
2392 | } | |
2393 | ||
2394 | if (vif->bss_conf.multi_sta_back_32bit) | |
2395 | flags |= STA_CTXT_HE_32BIT_BA_BITMAP; | |
2396 | ||
2397 | if (vif->bss_conf.ack_enabled) | |
2398 | flags |= STA_CTXT_HE_ACK_ENABLED; | |
2399 | ||
2400 | if (vif->bss_conf.uora_exists) { | |
2401 | flags |= STA_CTXT_HE_TRIG_RND_ALLOC; | |
2402 | ||
2403 | sta_ctxt_cmd.rand_alloc_ecwmin = | |
2404 | vif->bss_conf.uora_ocw_range & 0x7; | |
2405 | sta_ctxt_cmd.rand_alloc_ecwmax = | |
2406 | (vif->bss_conf.uora_ocw_range >> 3) & 0x7; | |
2407 | } | |
2408 | ||
918cbf39 SS |
2409 | if (vif->bss_conf.nontransmitted) { |
2410 | flags |= STA_CTXT_HE_REF_BSSID_VALID; | |
2411 | ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr, | |
2412 | vif->bss_conf.transmitter_bssid); | |
d14ae796 SS |
2413 | sta_ctxt_cmd.max_bssid_indicator = |
2414 | vif->bss_conf.bssid_indicator; | |
2415 | sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index; | |
2416 | sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap; | |
2417 | sta_ctxt_cmd.profile_periodicity = | |
2418 | vif->bss_conf.profile_periodicity; | |
918cbf39 | 2419 | } |
514c3069 LC |
2420 | |
2421 | sta_ctxt_cmd.flags = cpu_to_le32(flags); | |
2422 | ||
2423 | if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD, | |
2424 | DATA_PATH_GROUP, 0), | |
d14ae796 | 2425 | 0, size, &sta_ctxt_cmd)) |
514c3069 LC |
2426 | IWL_ERR(mvm, "Failed to config FW to work HE!\n"); |
2427 | } | |
2428 | ||
8ca151b5 JB |
2429 | static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, |
2430 | struct ieee80211_vif *vif, | |
2431 | struct ieee80211_bss_conf *bss_conf, | |
2432 | u32 changes) | |
2433 | { | |
2434 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
2435 | int ret; | |
2436 | ||
6e97b0d2 IP |
2437 | /* |
2438 | * Re-calculate the tsf id, as the master-slave relations depend on the | |
2439 | * beacon interval, which was not known when the station interface was | |
2440 | * added. | |
2441 | */ | |
514c3069 | 2442 | if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) { |
230ba6c5 LC |
2443 | if (vif->bss_conf.he_support && |
2444 | !iwlwifi_mod_params.disable_11ax) | |
514c3069 LC |
2445 | iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id); |
2446 | ||
6e97b0d2 | 2447 | iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); |
514c3069 | 2448 | } |
6e97b0d2 | 2449 | |
40ecdd01 ST |
2450 | /* Update MU EDCA params */ |
2451 | if (changes & BSS_CHANGED_QOS && mvmvif->associated && | |
2452 | bss_conf->assoc && vif->bss_conf.he_support && | |
2453 | !iwlwifi_mod_params.disable_11ax) | |
2454 | iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id); | |
2455 | ||
3dfd3a97 JB |
2456 | /* |
2457 | * If we're not associated yet, take the (new) BSSID before associating | |
2458 | * so the firmware knows. If we're already associated, then use the old | |
2459 | * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC | |
2460 | * branch for disassociation below. | |
2461 | */ | |
2462 | if (changes & BSS_CHANGED_BSSID && !mvmvif->associated) | |
2463 | memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN); | |
2464 | ||
2465 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid); | |
8ca151b5 JB |
2466 | if (ret) |
2467 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); | |
2468 | ||
3dfd3a97 JB |
2469 | /* after sending it once, adopt mac80211 data */ |
2470 | memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN); | |
2471 | mvmvif->associated = bss_conf->assoc; | |
2472 | ||
8ca151b5 JB |
2473 | if (changes & BSS_CHANGED_ASSOC) { |
2474 | if (bss_conf->assoc) { | |
33cef925 JB |
2475 | /* clear statistics to get clean beacon counter */ |
2476 | iwl_mvm_request_statistics(mvm, true); | |
2477 | memset(&mvmvif->beacon_stats, 0, | |
2478 | sizeof(mvmvif->beacon_stats)); | |
2479 | ||
8ca151b5 | 2480 | /* add quota for this interface */ |
7754ae79 | 2481 | ret = iwl_mvm_update_quotas(mvm, true, NULL); |
8ca151b5 JB |
2482 | if (ret) { |
2483 | IWL_ERR(mvm, "failed to update quotas\n"); | |
2484 | return; | |
2485 | } | |
016d27e1 JB |
2486 | |
2487 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, | |
2488 | &mvm->status)) { | |
2489 | /* | |
2490 | * If we're restarting then the firmware will | |
2491 | * obviously have lost synchronisation with | |
2492 | * the AP. It will attempt to synchronise by | |
2493 | * itself, but we can make it more reliable by | |
2494 | * scheduling a session protection time event. | |
2495 | * | |
2496 | * The firmware needs to receive a beacon to | |
2497 | * catch up with synchronisation, use 110% of | |
2498 | * the beacon interval. | |
2499 | * | |
2500 | * Set a large maximum delay to allow for more | |
2501 | * than a single interface. | |
2502 | */ | |
2503 | u32 dur = (11 * vif->bss_conf.beacon_int) / 10; | |
2504 | iwl_mvm_protect_session(mvm, vif, dur, dur, | |
d20d37bc | 2505 | 5 * dur, false); |
016d27e1 | 2506 | } |
1f3b0ff8 LE |
2507 | |
2508 | iwl_mvm_sf_update(mvm, vif, false); | |
175a70b7 | 2509 | iwl_mvm_power_vif_assoc(mvm, vif); |
697162a1 | 2510 | if (vif->p2p) { |
29a90a49 | 2511 | iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT); |
697162a1 EG |
2512 | iwl_mvm_update_smps(mvm, vif, |
2513 | IWL_MVM_SMPS_REQ_PROT, | |
2514 | IEEE80211_SMPS_DYNAMIC); | |
2515 | } | |
0ae98812 | 2516 | } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) { |
1f3b0ff8 LE |
2517 | /* |
2518 | * If update fails - SF might be running in associated | |
2519 | * mode while disassociated - which is forbidden. | |
2520 | */ | |
69e508b4 IP |
2521 | ret = iwl_mvm_sf_update(mvm, vif, false); |
2522 | WARN_ONCE(ret && | |
2523 | !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, | |
2524 | &mvm->status), | |
1f3b0ff8 LE |
2525 | "Failed to update SF upon disassociation\n"); |
2526 | ||
6b28f978 EG |
2527 | /* |
2528 | * If we get an assert during the connection (after the | |
2529 | * station has been added, but before the vif is set | |
2530 | * to associated), mac80211 will re-add the station and | |
2531 | * then configure the vif. Since the vif is not | |
2532 | * associated, we would remove the station here and | |
2533 | * this would fail the recovery. | |
2534 | */ | |
2535 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, | |
2536 | &mvm->status)) { | |
2537 | /* | |
2538 | * Remove AP station now that | |
2539 | * the MAC is unassoc | |
2540 | */ | |
2541 | ret = iwl_mvm_rm_sta_id(mvm, vif, | |
2542 | mvmvif->ap_sta_id); | |
2543 | if (ret) | |
2544 | IWL_ERR(mvm, | |
2545 | "failed to remove AP station\n"); | |
2546 | ||
2547 | if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id) | |
2548 | mvm->d0i3_ap_sta_id = | |
2549 | IWL_MVM_INVALID_STA; | |
2550 | mvmvif->ap_sta_id = IWL_MVM_INVALID_STA; | |
2551 | } | |
37577fe2 | 2552 | |
8ca151b5 | 2553 | /* remove quota for this interface */ |
7754ae79 | 2554 | ret = iwl_mvm_update_quotas(mvm, false, NULL); |
8ca151b5 JB |
2555 | if (ret) |
2556 | IWL_ERR(mvm, "failed to update quotas\n"); | |
29a90a49 EP |
2557 | |
2558 | if (vif->p2p) | |
2559 | iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT); | |
3dfd3a97 JB |
2560 | |
2561 | /* this will take the cleared BSSID from bss_conf */ | |
2562 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); | |
2563 | if (ret) | |
2564 | IWL_ERR(mvm, | |
2565 | "failed to update MAC %pM (clear after unassoc)\n", | |
2566 | vif->addr); | |
8ca151b5 | 2567 | } |
a20fd398 | 2568 | |
a07a8f37 SS |
2569 | /* |
2570 | * The firmware tracks the MU-MIMO group on its own. | |
f92659a1 | 2571 | * However, on HW restart we should restore this data. |
a07a8f37 SS |
2572 | */ |
2573 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && | |
f92659a1 | 2574 | (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) { |
a07a8f37 SS |
2575 | ret = iwl_mvm_update_mu_groups(mvm, vif); |
2576 | if (ret) | |
2577 | IWL_ERR(mvm, | |
2578 | "failed to update VHT MU_MIMO groups\n"); | |
2579 | } | |
2580 | ||
e59647ea | 2581 | iwl_mvm_recalc_multicast(mvm); |
34672bb3 | 2582 | iwl_mvm_configure_bcast_filter(mvm); |
e59647ea | 2583 | |
a20fd398 AO |
2584 | /* reset rssi values */ |
2585 | mvmvif->bf_data.ave_beacon_signal = 0; | |
2586 | ||
8e484f0b | 2587 | iwl_mvm_bt_coex_vif_change(mvm); |
f94045ed EG |
2588 | iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, |
2589 | IEEE80211_SMPS_AUTOMATIC); | |
355346ba AS |
2590 | if (fw_has_capa(&mvm->fw->ucode_capa, |
2591 | IWL_UCODE_TLV_CAPA_UMAC_SCAN)) | |
2592 | iwl_mvm_config_scan(mvm); | |
b45242c9 AS |
2593 | } |
2594 | ||
2595 | if (changes & BSS_CHANGED_BEACON_INFO) { | |
210a544e | 2596 | /* |
b45242c9 | 2597 | * We received a beacon from the associated AP so |
210a544e JB |
2598 | * remove the session protection. |
2599 | */ | |
3edfb5f4 | 2600 | iwl_mvm_stop_session_protection(mvm, vif); |
cc87d322 | 2601 | |
cc87d322 EH |
2602 | iwl_mvm_sf_update(mvm, vif, false); |
2603 | WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); | |
2604 | } | |
2605 | ||
283115fb AA |
2606 | if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS | |
2607 | /* | |
2608 | * Send power command on every beacon change, | |
2609 | * because we may have not enabled beacon abort yet. | |
2610 | */ | |
2611 | BSS_CHANGED_BEACON_INFO)) { | |
1bc10d3b JB |
2612 | ret = iwl_mvm_power_update_mac(mvm); |
2613 | if (ret) | |
2614 | IWL_ERR(mvm, "failed to update power mode\n"); | |
2615 | } | |
2616 | ||
88f2fd73 MG |
2617 | if (changes & BSS_CHANGED_TXPOWER) { |
2618 | IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n", | |
2619 | bss_conf->txpower); | |
2620 | iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); | |
2621 | } | |
a20fd398 AO |
2622 | |
2623 | if (changes & BSS_CHANGED_CQM) { | |
3c6acb61 | 2624 | IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n"); |
a20fd398 AO |
2625 | /* reset cqm events tracking */ |
2626 | mvmvif->bf_data.last_cqm_event = 0; | |
fa7b2e7f AA |
2627 | if (mvmvif->bf_data.bf_enabled) { |
2628 | ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); | |
2629 | if (ret) | |
2630 | IWL_ERR(mvm, | |
2631 | "failed to update CQM thresholds\n"); | |
2632 | } | |
a20fd398 | 2633 | } |
2ee8f021 EP |
2634 | |
2635 | if (changes & BSS_CHANGED_ARP_FILTER) { | |
3c6acb61 | 2636 | IWL_DEBUG_MAC80211(mvm, "arp filter changed\n"); |
34672bb3 | 2637 | iwl_mvm_configure_bcast_filter(mvm); |
2ee8f021 | 2638 | } |
8ca151b5 JB |
2639 | } |
2640 | ||
5023d966 JB |
2641 | static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, |
2642 | struct ieee80211_vif *vif) | |
8ca151b5 JB |
2643 | { |
2644 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
2645 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
c56e00a3 | 2646 | int ret, i; |
8ca151b5 | 2647 | |
576eeee9 EP |
2648 | /* |
2649 | * iwl_mvm_mac_ctxt_add() might read directly from the device | |
2650 | * (the system time), so make sure it is available. | |
2651 | */ | |
2652 | ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP); | |
2653 | if (ret) | |
2654 | return ret; | |
2655 | ||
8ca151b5 JB |
2656 | mutex_lock(&mvm->mutex); |
2657 | ||
2658 | /* Send the beacon template */ | |
2659 | ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif); | |
2660 | if (ret) | |
2661 | goto out_unlock; | |
2662 | ||
6e97b0d2 IP |
2663 | /* |
2664 | * Re-calculate the tsf id, as the master-slave relations depend on the | |
2665 | * beacon interval, which was not known when the AP interface was added. | |
2666 | */ | |
2667 | if (vif->type == NL80211_IFTYPE_AP) | |
2668 | iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); | |
2669 | ||
94939080 GG |
2670 | mvmvif->ap_assoc_sta_count = 0; |
2671 | ||
8ca151b5 JB |
2672 | /* Add the mac context */ |
2673 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); | |
2674 | if (ret) | |
2675 | goto out_unlock; | |
2676 | ||
2677 | /* Perform the binding */ | |
2678 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
2679 | if (ret) | |
2680 | goto out_remove; | |
2681 | ||
63dd5d02 SS |
2682 | /* |
2683 | * This is not very nice, but the simplest: | |
2684 | * For older FWs adding the mcast sta before the bcast station may | |
2685 | * cause assert 0x2b00. | |
2686 | * This is fixed in later FW so make the order of removal depend on | |
2687 | * the TLV | |
2688 | */ | |
2689 | if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) { | |
2690 | ret = iwl_mvm_add_mcast_sta(mvm, vif); | |
2691 | if (ret) | |
2692 | goto out_unbind; | |
2693 | /* | |
2694 | * Send the bcast station. At this stage the TBTT and DTIM time | |
2695 | * events are added and applied to the scheduler | |
2696 | */ | |
2697 | ret = iwl_mvm_send_add_bcast_sta(mvm, vif); | |
2698 | if (ret) { | |
2699 | iwl_mvm_rm_mcast_sta(mvm, vif); | |
2700 | goto out_unbind; | |
2701 | } | |
2702 | } else { | |
2703 | /* | |
2704 | * Send the bcast station. At this stage the TBTT and DTIM time | |
2705 | * events are added and applied to the scheduler | |
2706 | */ | |
75fd4fec | 2707 | ret = iwl_mvm_send_add_bcast_sta(mvm, vif); |
63dd5d02 SS |
2708 | if (ret) |
2709 | goto out_unbind; | |
75fd4fec | 2710 | ret = iwl_mvm_add_mcast_sta(mvm, vif); |
63dd5d02 SS |
2711 | if (ret) { |
2712 | iwl_mvm_send_rm_bcast_sta(mvm, vif); | |
2713 | goto out_unbind; | |
2714 | } | |
2715 | } | |
26d6c16b | 2716 | |
5691e218 IP |
2717 | /* must be set before quota calculations */ |
2718 | mvmvif->ap_ibss_active = true; | |
2719 | ||
c56e00a3 JB |
2720 | /* send all the early keys to the device now */ |
2721 | for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { | |
2722 | struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i]; | |
2723 | ||
2724 | if (!key) | |
2725 | continue; | |
2726 | ||
2727 | mvmvif->ap_early_keys[i] = NULL; | |
2728 | ||
2729 | ret = iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key); | |
2730 | if (ret) | |
2731 | goto out_quota_failed; | |
2732 | } | |
2733 | ||
47242744 TM |
2734 | if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { |
2735 | iwl_mvm_vif_set_low_latency(mvmvif, true, | |
2736 | LOW_LATENCY_VIF_TYPE); | |
2737 | iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id); | |
2738 | } | |
2739 | ||
a11e144e | 2740 | /* power updated needs to be done before quotas */ |
999609f1 | 2741 | iwl_mvm_power_update_mac(mvm); |
a11e144e | 2742 | |
7754ae79 | 2743 | ret = iwl_mvm_update_quotas(mvm, false, NULL); |
8ca151b5 | 2744 | if (ret) |
a11e144e | 2745 | goto out_quota_failed; |
8ca151b5 | 2746 | |
5023d966 | 2747 | /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ |
8ca151b5 | 2748 | if (vif->p2p && mvm->p2p_device_vif) |
3dfd3a97 | 2749 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); |
8ca151b5 | 2750 | |
29a90a49 EP |
2751 | iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS); |
2752 | ||
8e484f0b | 2753 | iwl_mvm_bt_coex_vif_change(mvm); |
dac94da8 | 2754 | |
f697267f AN |
2755 | /* we don't support TDLS during DCM */ |
2756 | if (iwl_mvm_phy_ctx_count(mvm) > 1) | |
2757 | iwl_mvm_teardown_tdls_peers(mvm); | |
2758 | ||
b73f9a4a JB |
2759 | iwl_mvm_ftm_restart_responder(mvm, vif); |
2760 | ||
939e4904 | 2761 | goto out_unlock; |
8ca151b5 | 2762 | |
a11e144e | 2763 | out_quota_failed: |
999609f1 | 2764 | iwl_mvm_power_update_mac(mvm); |
5691e218 | 2765 | mvmvif->ap_ibss_active = false; |
013290aa | 2766 | iwl_mvm_send_rm_bcast_sta(mvm, vif); |
ced19f26 | 2767 | iwl_mvm_rm_mcast_sta(mvm, vif); |
8ca151b5 JB |
2768 | out_unbind: |
2769 | iwl_mvm_binding_remove_vif(mvm, vif); | |
2770 | out_remove: | |
2771 | iwl_mvm_mac_ctxt_remove(mvm, vif); | |
2772 | out_unlock: | |
2773 | mutex_unlock(&mvm->mutex); | |
576eeee9 | 2774 | iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP); |
8ca151b5 JB |
2775 | return ret; |
2776 | } | |
2777 | ||
5023d966 JB |
2778 | static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, |
2779 | struct ieee80211_vif *vif) | |
8ca151b5 JB |
2780 | { |
2781 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
2782 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
2783 | ||
38a12b5b JB |
2784 | iwl_mvm_prepare_mac_removal(mvm, vif); |
2785 | ||
8ca151b5 JB |
2786 | mutex_lock(&mvm->mutex); |
2787 | ||
664322fa | 2788 | /* Handle AP stop while in CSA */ |
7f0a7c67 AO |
2789 | if (rcu_access_pointer(mvm->csa_vif) == vif) { |
2790 | iwl_mvm_remove_time_event(mvm, mvmvif, | |
2791 | &mvmvif->time_event_data); | |
664322fa | 2792 | RCU_INIT_POINTER(mvm->csa_vif, NULL); |
e9cb0327 | 2793 | mvmvif->csa_countdown = false; |
7f0a7c67 | 2794 | } |
664322fa | 2795 | |
003e5236 AO |
2796 | if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) { |
2797 | RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); | |
2798 | mvm->csa_tx_block_bcn_timeout = 0; | |
2799 | } | |
2800 | ||
5023d966 | 2801 | mvmvif->ap_ibss_active = false; |
1c87bbad | 2802 | mvm->ap_last_beacon_gp2 = 0; |
8ca151b5 | 2803 | |
47242744 TM |
2804 | if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { |
2805 | iwl_mvm_vif_set_low_latency(mvmvif, false, | |
2806 | LOW_LATENCY_VIF_TYPE); | |
2807 | iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id); | |
2808 | } | |
2809 | ||
8e484f0b | 2810 | iwl_mvm_bt_coex_vif_change(mvm); |
dac94da8 | 2811 | |
29a90a49 EP |
2812 | iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS); |
2813 | ||
5023d966 | 2814 | /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ |
8ca151b5 | 2815 | if (vif->p2p && mvm->p2p_device_vif) |
3dfd3a97 | 2816 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); |
8ca151b5 | 2817 | |
7754ae79 | 2818 | iwl_mvm_update_quotas(mvm, false, NULL); |
ced19f26 SS |
2819 | |
2820 | /* | |
2821 | * This is not very nice, but the simplest: | |
2822 | * For older FWs removing the mcast sta before the bcast station may | |
2823 | * cause assert 0x2b00. | |
2824 | * This is fixed in later FW (which will stop beaconing when removing | |
2825 | * bcast station). | |
2826 | * So make the order of removal depend on the TLV | |
2827 | */ | |
2828 | if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) | |
2829 | iwl_mvm_rm_mcast_sta(mvm, vif); | |
013290aa | 2830 | iwl_mvm_send_rm_bcast_sta(mvm, vif); |
ced19f26 SS |
2831 | if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) |
2832 | iwl_mvm_rm_mcast_sta(mvm, vif); | |
8ca151b5 | 2833 | iwl_mvm_binding_remove_vif(mvm, vif); |
a11e144e | 2834 | |
999609f1 | 2835 | iwl_mvm_power_update_mac(mvm); |
a11e144e | 2836 | |
8ca151b5 JB |
2837 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
2838 | ||
2839 | mutex_unlock(&mvm->mutex); | |
2840 | } | |
2841 | ||
5023d966 JB |
2842 | static void |
2843 | iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, | |
2844 | struct ieee80211_vif *vif, | |
2845 | struct ieee80211_bss_conf *bss_conf, | |
2846 | u32 changes) | |
8ca151b5 | 2847 | { |
be2056fc | 2848 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
8a5e3660 | 2849 | |
be2056fc IP |
2850 | /* Changes will be applied when the AP/IBSS is started */ |
2851 | if (!mvmvif->ap_ibss_active) | |
2852 | return; | |
2853 | ||
863230da | 2854 | if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT | |
f7d8b702 | 2855 | BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) && |
3dfd3a97 | 2856 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL)) |
863230da | 2857 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); |
8a5e3660 | 2858 | |
8ca151b5 | 2859 | /* Need to send a new beacon template to the FW */ |
863230da JB |
2860 | if (changes & BSS_CHANGED_BEACON && |
2861 | iwl_mvm_mac_ctxt_beacon_changed(mvm, vif)) | |
2862 | IWL_WARN(mvm, "Failed updating beacon data\n"); | |
79b7a69d HD |
2863 | |
2864 | if (changes & BSS_CHANGED_TXPOWER) { | |
2865 | IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n", | |
2866 | bss_conf->txpower); | |
2867 | iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); | |
2868 | } | |
b73f9a4a JB |
2869 | |
2870 | if (changes & BSS_CHANGED_FTM_RESPONDER) { | |
2871 | int ret = iwl_mvm_ftm_start_responder(mvm, vif); | |
2872 | ||
2873 | if (ret) | |
2874 | IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n", | |
2875 | ret); | |
2876 | } | |
2877 | ||
8ca151b5 JB |
2878 | } |
2879 | ||
2880 | static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, | |
2881 | struct ieee80211_vif *vif, | |
2882 | struct ieee80211_bss_conf *bss_conf, | |
2883 | u32 changes) | |
2884 | { | |
2885 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
2886 | ||
576eeee9 EP |
2887 | /* |
2888 | * iwl_mvm_bss_info_changed_station() might call | |
2889 | * iwl_mvm_protect_session(), which reads directly from | |
2890 | * the device (the system time), so make sure it is available. | |
2891 | */ | |
2892 | if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED)) | |
2893 | return; | |
2894 | ||
8ca151b5 JB |
2895 | mutex_lock(&mvm->mutex); |
2896 | ||
723f02ed | 2897 | if (changes & BSS_CHANGED_IDLE && !bss_conf->idle) |
c7d42480 | 2898 | iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true); |
723f02ed | 2899 | |
8ca151b5 JB |
2900 | switch (vif->type) { |
2901 | case NL80211_IFTYPE_STATION: | |
2902 | iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); | |
2903 | break; | |
2904 | case NL80211_IFTYPE_AP: | |
5023d966 JB |
2905 | case NL80211_IFTYPE_ADHOC: |
2906 | iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes); | |
8ca151b5 | 2907 | break; |
91b08c2d AE |
2908 | case NL80211_IFTYPE_MONITOR: |
2909 | if (changes & BSS_CHANGED_MU_GROUPS) | |
2910 | iwl_mvm_update_mu_groups(mvm, vif); | |
2911 | break; | |
8ca151b5 JB |
2912 | default: |
2913 | /* shouldn't happen */ | |
2914 | WARN_ON_ONCE(1); | |
2915 | } | |
2916 | ||
2917 | mutex_unlock(&mvm->mutex); | |
576eeee9 | 2918 | iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED); |
8ca151b5 JB |
2919 | } |
2920 | ||
2921 | static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, | |
2922 | struct ieee80211_vif *vif, | |
c56ef672 | 2923 | struct ieee80211_scan_request *hw_req) |
8ca151b5 JB |
2924 | { |
2925 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
2926 | int ret; | |
2927 | ||
6749dd80 LC |
2928 | if (hw_req->req.n_channels == 0 || |
2929 | hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels) | |
8ca151b5 JB |
2930 | return -EINVAL; |
2931 | ||
2932 | mutex_lock(&mvm->mutex); | |
6749dd80 | 2933 | ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies); |
8ca151b5 | 2934 | mutex_unlock(&mvm->mutex); |
6749dd80 | 2935 | |
8ca151b5 JB |
2936 | return ret; |
2937 | } | |
2938 | ||
2939 | static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, | |
2940 | struct ieee80211_vif *vif) | |
2941 | { | |
2942 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
2943 | ||
2944 | mutex_lock(&mvm->mutex); | |
2945 | ||
e7d3abab LC |
2946 | /* Due to a race condition, it's possible that mac80211 asks |
2947 | * us to stop a hw_scan when it's already stopped. This can | |
2948 | * happen, for instance, if we stopped the scan ourselves, | |
2949 | * called ieee80211_scan_completed() and the userspace called | |
2950 | * cancel scan scan before ieee80211_scan_work() could run. | |
2951 | * To handle that, simply return if the scan is not running. | |
2952 | */ | |
262888fc | 2953 | if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) |
c7d42480 | 2954 | iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true); |
8ca151b5 JB |
2955 | |
2956 | mutex_unlock(&mvm->mutex); | |
2957 | } | |
2958 | ||
2959 | static void | |
2960 | iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, | |
3e56eadf | 2961 | struct ieee80211_sta *sta, u16 tids, |
8ca151b5 JB |
2962 | int num_frames, |
2963 | enum ieee80211_frame_release_type reason, | |
2964 | bool more_data) | |
2965 | { | |
2966 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
8ca151b5 | 2967 | |
3e56eadf | 2968 | /* Called when we need to transmit (a) frame(s) from mac80211 */ |
8ca151b5 | 2969 | |
3e56eadf JB |
2970 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, |
2971 | tids, more_data, false); | |
2972 | } | |
2973 | ||
2974 | static void | |
2975 | iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw, | |
2976 | struct ieee80211_sta *sta, u16 tids, | |
2977 | int num_frames, | |
2978 | enum ieee80211_frame_release_type reason, | |
2979 | bool more_data) | |
2980 | { | |
2981 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
2982 | ||
9a3fcf91 | 2983 | /* Called when we need to transmit (a) frame(s) from agg or dqa queue */ |
3e56eadf JB |
2984 | |
2985 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, | |
2986 | tids, more_data, true); | |
8ca151b5 JB |
2987 | } |
2988 | ||
65e25482 JB |
2989 | static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, |
2990 | enum sta_notify_cmd cmd, | |
2991 | struct ieee80211_sta *sta) | |
8ca151b5 JB |
2992 | { |
2993 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5b577a90 | 2994 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
c22b0ff5 | 2995 | unsigned long txqs = 0, tids = 0; |
3e56eadf | 2996 | int tid; |
8ca151b5 | 2997 | |
960f864b JB |
2998 | /* |
2999 | * If we have TVQM then we get too high queue numbers - luckily | |
3000 | * we really shouldn't get here with that because such hardware | |
3001 | * should have firmware supporting buffer station offload. | |
3002 | */ | |
3003 | if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) | |
3004 | return; | |
3005 | ||
c22b0ff5 | 3006 | spin_lock_bh(&mvmsta->lock); |
311590a3 | 3007 | for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) { |
c22b0ff5 EG |
3008 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
3009 | ||
6862fcee | 3010 | if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE) |
1c17627b SS |
3011 | continue; |
3012 | ||
c22b0ff5 EG |
3013 | __set_bit(tid_data->txq_id, &txqs); |
3014 | ||
dd32162d | 3015 | if (iwl_mvm_tid_queued(mvm, tid_data) == 0) |
c22b0ff5 EG |
3016 | continue; |
3017 | ||
3018 | __set_bit(tid, &tids); | |
3019 | } | |
3020 | ||
8ca151b5 JB |
3021 | switch (cmd) { |
3022 | case STA_NOTIFY_SLEEP: | |
c22b0ff5 | 3023 | for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT) |
3e56eadf | 3024 | ieee80211_sta_set_buffered(sta, tid, true); |
c22b0ff5 EG |
3025 | |
3026 | if (txqs) | |
3027 | iwl_trans_freeze_txq_timer(mvm->trans, txqs, true); | |
8ca151b5 JB |
3028 | /* |
3029 | * The fw updates the STA to be asleep. Tx packets on the Tx | |
3030 | * queues to this station will not be transmitted. The fw will | |
3031 | * send a Tx response with TX_STATUS_FAIL_DEST_PS. | |
3032 | */ | |
3033 | break; | |
3034 | case STA_NOTIFY_AWAKE: | |
0ae98812 | 3035 | if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA)) |
8ca151b5 | 3036 | break; |
c22b0ff5 EG |
3037 | |
3038 | if (txqs) | |
3039 | iwl_trans_freeze_txq_timer(mvm->trans, txqs, false); | |
9cc40712 | 3040 | iwl_mvm_sta_modify_ps_wake(mvm, sta); |
8ca151b5 JB |
3041 | break; |
3042 | default: | |
3043 | break; | |
3044 | } | |
c22b0ff5 | 3045 | spin_unlock_bh(&mvmsta->lock); |
8ca151b5 JB |
3046 | } |
3047 | ||
65e25482 JB |
3048 | static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, |
3049 | struct ieee80211_vif *vif, | |
3050 | enum sta_notify_cmd cmd, | |
3051 | struct ieee80211_sta *sta) | |
3052 | { | |
3053 | __iwl_mvm_mac_sta_notify(hw, cmd, sta); | |
3054 | } | |
3055 | ||
3056 | void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) | |
3057 | { | |
3058 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
3059 | struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data; | |
3060 | struct ieee80211_sta *sta; | |
3061 | struct iwl_mvm_sta *mvmsta; | |
3062 | bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE); | |
3063 | ||
3064 | if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id))) | |
3065 | return; | |
3066 | ||
3067 | rcu_read_lock(); | |
a9560029 | 3068 | sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]); |
65e25482 JB |
3069 | if (WARN_ON(IS_ERR_OR_NULL(sta))) { |
3070 | rcu_read_unlock(); | |
3071 | return; | |
3072 | } | |
3073 | ||
3074 | mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
3075 | ||
3076 | if (!mvmsta->vif || | |
3077 | mvmsta->vif->type != NL80211_IFTYPE_AP) { | |
3078 | rcu_read_unlock(); | |
3079 | return; | |
3080 | } | |
3081 | ||
3082 | if (mvmsta->sleeping != sleeping) { | |
3083 | mvmsta->sleeping = sleeping; | |
3084 | __iwl_mvm_mac_sta_notify(mvm->hw, | |
3085 | sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE, | |
3086 | sta); | |
3087 | ieee80211_sta_ps_transition(sta, sleeping); | |
3088 | } | |
3089 | ||
3090 | if (sleeping) { | |
3091 | switch (notif->type) { | |
3092 | case IWL_MVM_PM_EVENT_AWAKE: | |
3093 | case IWL_MVM_PM_EVENT_ASLEEP: | |
3094 | break; | |
3095 | case IWL_MVM_PM_EVENT_UAPSD: | |
3096 | ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS); | |
3097 | break; | |
3098 | case IWL_MVM_PM_EVENT_PS_POLL: | |
3099 | ieee80211_sta_pspoll(sta); | |
3100 | break; | |
3101 | default: | |
3102 | break; | |
3103 | } | |
3104 | } | |
3105 | ||
3106 | rcu_read_unlock(); | |
3107 | } | |
3108 | ||
1ddbbb0c JB |
3109 | static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw, |
3110 | struct ieee80211_vif *vif, | |
3111 | struct ieee80211_sta *sta) | |
3112 | { | |
3113 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
9d8ce6af | 3114 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
1ddbbb0c JB |
3115 | |
3116 | /* | |
3117 | * This is called before mac80211 does RCU synchronisation, | |
3118 | * so here we already invalidate our internal RCU-protected | |
3119 | * station pointer. The rest of the code will thus no longer | |
3120 | * be able to find the station this way, and we don't rely | |
3121 | * on further RCU synchronisation after the sta_state() | |
3122 | * callback deleted the station. | |
3123 | */ | |
3124 | mutex_lock(&mvm->mutex); | |
3125 | if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id])) | |
3126 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], | |
3127 | ERR_PTR(-ENOENT)); | |
94939080 | 3128 | |
1ddbbb0c JB |
3129 | mutex_unlock(&mvm->mutex); |
3130 | } | |
3131 | ||
bd1ba664 JB |
3132 | static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
3133 | const u8 *bssid) | |
3134 | { | |
b0ffe455 JB |
3135 | int i; |
3136 | ||
3137 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { | |
3138 | struct iwl_mvm_tcm_mac *mdata; | |
3139 | ||
3140 | mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id]; | |
3141 | ewma_rate_init(&mdata->uapsd_nonagg_detect.rate); | |
3142 | mdata->opened_rx_ba_sessions = false; | |
3143 | } | |
3144 | ||
bd1ba664 JB |
3145 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT)) |
3146 | return; | |
3147 | ||
c5241b0c | 3148 | if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) { |
cee5a882 AA |
3149 | vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; |
3150 | return; | |
3151 | } | |
3152 | ||
11dee0b4 EG |
3153 | if (!vif->p2p && |
3154 | (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) { | |
bd1ba664 JB |
3155 | vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; |
3156 | return; | |
3157 | } | |
3158 | ||
b0ffe455 JB |
3159 | for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) { |
3160 | if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) { | |
3161 | vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; | |
3162 | return; | |
3163 | } | |
3164 | } | |
3165 | ||
bd1ba664 JB |
3166 | vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; |
3167 | } | |
3168 | ||
1e8f1329 GBA |
3169 | static void |
3170 | iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm, | |
3171 | struct ieee80211_vif *vif, u8 *peer_addr, | |
3172 | enum nl80211_tdls_operation action) | |
3173 | { | |
3174 | struct iwl_fw_dbg_trigger_tlv *trig; | |
3175 | struct iwl_fw_dbg_trigger_tdls *tdls_trig; | |
3176 | ||
6c042d75 SS |
3177 | trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), |
3178 | FW_DBG_TRIGGER_TDLS); | |
3179 | if (!trig) | |
1e8f1329 GBA |
3180 | return; |
3181 | ||
1e8f1329 | 3182 | tdls_trig = (void *)trig->data; |
1e8f1329 GBA |
3183 | |
3184 | if (!(tdls_trig->action_bitmap & BIT(action))) | |
3185 | return; | |
3186 | ||
3187 | if (tdls_trig->peer_mode && | |
3188 | memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0) | |
3189 | return; | |
3190 | ||
7174beb6 JB |
3191 | iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, |
3192 | "TDLS event occurred, peer %pM, action %d", | |
3193 | peer_addr, action); | |
1e8f1329 GBA |
3194 | } |
3195 | ||
8ca151b5 JB |
3196 | static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, |
3197 | struct ieee80211_vif *vif, | |
3198 | struct ieee80211_sta *sta, | |
3199 | enum ieee80211_sta_state old_state, | |
3200 | enum ieee80211_sta_state new_state) | |
3201 | { | |
3202 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
3203 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
6ea29ce5 | 3204 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
3205 | int ret; |
3206 | ||
3207 | IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", | |
3208 | sta->addr, old_state, new_state); | |
3209 | ||
3210 | /* this would be a mac80211 bug ... but don't crash */ | |
3211 | if (WARN_ON_ONCE(!mvmvif->phy_ctxt)) | |
3212 | return -EINVAL; | |
3213 | ||
24afba76 LK |
3214 | /* |
3215 | * If we are in a STA removal flow and in DQA mode: | |
3216 | * | |
3217 | * This is after the sync_rcu part, so the queues have already been | |
3218 | * flushed. No more TXs on their way in mac80211's path, and no more in | |
3219 | * the queues. | |
3220 | * Also, we won't be getting any new TX frames for this station. | |
3221 | * What we might have are deferred TX frames that need to be taken care | |
3222 | * of. | |
3223 | * | |
3224 | * Drop any still-queued deferred-frame before removing the STA, and | |
3225 | * make sure the worker is no longer handling frames for this STA. | |
3226 | */ | |
3227 | if (old_state == IEEE80211_STA_NONE && | |
c8f54701 | 3228 | new_state == IEEE80211_STA_NOTEXIST) { |
24afba76 LK |
3229 | flush_work(&mvm->add_stream_wk); |
3230 | ||
3231 | /* | |
3232 | * No need to make sure deferred TX indication is off since the | |
3233 | * worker will already remove it if it was on | |
3234 | */ | |
3235 | } | |
3236 | ||
8ca151b5 | 3237 | mutex_lock(&mvm->mutex); |
6ea29ce5 | 3238 | /* track whether or not the station is associated */ |
d94c5a82 | 3239 | mvm_sta->sta_state = new_state; |
6ea29ce5 | 3240 | |
8ca151b5 JB |
3241 | if (old_state == IEEE80211_STA_NOTEXIST && |
3242 | new_state == IEEE80211_STA_NONE) { | |
48bc1307 JB |
3243 | /* |
3244 | * Firmware bug - it'll crash if the beacon interval is less | |
3245 | * than 16. We can't avoid connecting at all, so refuse the | |
3246 | * station state change, this will cause mac80211 to abandon | |
3247 | * attempts to connect to this AP, and eventually wpa_s will | |
3248 | * blacklist the AP... | |
3249 | */ | |
3250 | if (vif->type == NL80211_IFTYPE_STATION && | |
3251 | vif->bss_conf.beacon_int < 16) { | |
3252 | IWL_ERR(mvm, | |
3253 | "AP %pM beacon interval is %d, refusing due to firmware bug!\n", | |
3254 | sta->addr, vif->bss_conf.beacon_int); | |
3255 | ret = -EINVAL; | |
3256 | goto out_unlock; | |
3257 | } | |
cf7b491d AN |
3258 | |
3259 | if (sta->tdls && | |
3260 | (vif->p2p || | |
fa3d07e4 AN |
3261 | iwl_mvm_tdls_sta_count(mvm, NULL) == |
3262 | IWL_MVM_TDLS_STA_COUNT || | |
cf7b491d AN |
3263 | iwl_mvm_phy_ctx_count(mvm) > 1)) { |
3264 | IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n"); | |
3265 | ret = -EBUSY; | |
3266 | goto out_unlock; | |
3267 | } | |
3268 | ||
8ca151b5 | 3269 | ret = iwl_mvm_add_sta(mvm, vif, sta); |
1e8f1329 | 3270 | if (sta->tdls && ret == 0) { |
fa3d07e4 | 3271 | iwl_mvm_recalc_tdls_state(mvm, vif, true); |
1e8f1329 GBA |
3272 | iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, |
3273 | NL80211_TDLS_SETUP); | |
3274 | } | |
438af969 SS |
3275 | |
3276 | sta->max_rc_amsdu_len = 1; | |
8ca151b5 JB |
3277 | } else if (old_state == IEEE80211_STA_NONE && |
3278 | new_state == IEEE80211_STA_AUTH) { | |
e820c2da HD |
3279 | /* |
3280 | * EBS may be disabled due to previous failures reported by FW. | |
3281 | * Reset EBS status here assuming environment has been changed. | |
3282 | */ | |
3283 | mvm->last_ebs_successful = true; | |
bd1ba664 | 3284 | iwl_mvm_check_uapsd(mvm, vif, sta->addr); |
8ca151b5 JB |
3285 | ret = 0; |
3286 | } else if (old_state == IEEE80211_STA_AUTH && | |
3287 | new_state == IEEE80211_STA_ASSOC) { | |
8be30c13 | 3288 | if (vif->type == NL80211_IFTYPE_AP) { |
9394662a | 3289 | vif->bss_conf.he_support = sta->he_cap.has_he; |
8be30c13 AB |
3290 | mvmvif->ap_assoc_sta_count++; |
3291 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); | |
02221a81 ST |
3292 | if (vif->bss_conf.he_support && |
3293 | !iwlwifi_mod_params.disable_11ax) | |
3294 | iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id); | |
9394662a LK |
3295 | } else if (vif->type == NL80211_IFTYPE_STATION) { |
3296 | vif->bss_conf.he_support = sta->he_cap.has_he; | |
3297 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); | |
8be30c13 | 3298 | } |
735a0045 | 3299 | |
3baf7528 AS |
3300 | iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, |
3301 | false); | |
7a453973 | 3302 | ret = iwl_mvm_update_sta(mvm, vif, sta); |
8ca151b5 JB |
3303 | } else if (old_state == IEEE80211_STA_ASSOC && |
3304 | new_state == IEEE80211_STA_AUTHORIZED) { | |
475c6bde | 3305 | ret = 0; |
f59e0e3c AN |
3306 | |
3307 | /* we don't support TDLS during DCM */ | |
3308 | if (iwl_mvm_phy_ctx_count(mvm) > 1) | |
3309 | iwl_mvm_teardown_tdls_peers(mvm); | |
3310 | ||
1e8f1329 GBA |
3311 | if (sta->tdls) |
3312 | iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, | |
3313 | NL80211_TDLS_ENABLE_LINK); | |
3314 | ||
7df15b1e | 3315 | /* enable beacon filtering */ |
fa7b2e7f | 3316 | WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); |
6b7a5aea | 3317 | |
3baf7528 AS |
3318 | iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, |
3319 | true); | |
8ca151b5 JB |
3320 | } else if (old_state == IEEE80211_STA_AUTHORIZED && |
3321 | new_state == IEEE80211_STA_ASSOC) { | |
7df15b1e | 3322 | /* disable beacon filtering */ |
69e508b4 IP |
3323 | ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); |
3324 | WARN_ON(ret && | |
3325 | !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, | |
3326 | &mvm->status)); | |
8ca151b5 JB |
3327 | ret = 0; |
3328 | } else if (old_state == IEEE80211_STA_ASSOC && | |
3329 | new_state == IEEE80211_STA_AUTH) { | |
8be30c13 AB |
3330 | if (vif->type == NL80211_IFTYPE_AP) { |
3331 | mvmvif->ap_assoc_sta_count--; | |
3332 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); | |
3333 | } | |
8ca151b5 JB |
3334 | ret = 0; |
3335 | } else if (old_state == IEEE80211_STA_AUTH && | |
3336 | new_state == IEEE80211_STA_NONE) { | |
3337 | ret = 0; | |
3338 | } else if (old_state == IEEE80211_STA_NONE && | |
3339 | new_state == IEEE80211_STA_NOTEXIST) { | |
3340 | ret = iwl_mvm_rm_sta(mvm, vif, sta); | |
1e8f1329 | 3341 | if (sta->tdls) { |
fa3d07e4 | 3342 | iwl_mvm_recalc_tdls_state(mvm, vif, false); |
1e8f1329 GBA |
3343 | iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, |
3344 | NL80211_TDLS_DISABLE_LINK); | |
3345 | } | |
34a880d8 | 3346 | |
44135b7c IP |
3347 | if (unlikely(ret && |
3348 | test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, | |
3349 | &mvm->status))) | |
3350 | ret = 0; | |
8ca151b5 JB |
3351 | } else { |
3352 | ret = -EIO; | |
3353 | } | |
48bc1307 | 3354 | out_unlock: |
8ca151b5 JB |
3355 | mutex_unlock(&mvm->mutex); |
3356 | ||
9c126cd6 LK |
3357 | if (sta->tdls && ret == 0) { |
3358 | if (old_state == IEEE80211_STA_NOTEXIST && | |
3359 | new_state == IEEE80211_STA_NONE) | |
3360 | ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID); | |
3361 | else if (old_state == IEEE80211_STA_NONE && | |
3362 | new_state == IEEE80211_STA_NOTEXIST) | |
3363 | ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID); | |
3364 | } | |
3365 | ||
8ca151b5 JB |
3366 | return ret; |
3367 | } | |
3368 | ||
3369 | static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) | |
3370 | { | |
3371 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
3372 | ||
3373 | mvm->rts_threshold = value; | |
3374 | ||
3375 | return 0; | |
3376 | } | |
3377 | ||
1f3b0ff8 LE |
3378 | static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, |
3379 | struct ieee80211_vif *vif, | |
3380 | struct ieee80211_sta *sta, u32 changed) | |
3381 | { | |
3382 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
dcfe3b10 JB |
3383 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
3384 | ||
3385 | if (changed & (IEEE80211_RC_BW_CHANGED | | |
3386 | IEEE80211_RC_SUPP_RATES_CHANGED | | |
3387 | IEEE80211_RC_NSS_CHANGED)) | |
3388 | iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, | |
3389 | true); | |
1f3b0ff8 LE |
3390 | |
3391 | if (vif->type == NL80211_IFTYPE_STATION && | |
3392 | changed & IEEE80211_RC_NSS_CHANGED) | |
3393 | iwl_mvm_sf_update(mvm, vif, false); | |
3394 | } | |
3395 | ||
8ca151b5 JB |
3396 | static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, |
3397 | struct ieee80211_vif *vif, u16 ac, | |
3398 | const struct ieee80211_tx_queue_params *params) | |
3399 | { | |
3400 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
3401 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
3402 | ||
3403 | mvmvif->queue_params[ac] = *params; | |
3404 | ||
3405 | /* | |
3406 | * No need to update right away, we'll get BSS_CHANGED_QOS | |
3407 | * The exception is P2P_DEVICE interface which needs immediate update. | |
3408 | */ | |
3409 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
3410 | int ret; | |
3411 | ||
3412 | mutex_lock(&mvm->mutex); | |
3dfd3a97 | 3413 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); |
8ca151b5 JB |
3414 | mutex_unlock(&mvm->mutex); |
3415 | return ret; | |
3416 | } | |
3417 | return 0; | |
3418 | } | |
3419 | ||
3420 | static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, | |
d4e36e55 IP |
3421 | struct ieee80211_vif *vif, |
3422 | u16 req_duration) | |
8ca151b5 JB |
3423 | { |
3424 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
7c70fee5 SS |
3425 | u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS; |
3426 | u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS; | |
8ca151b5 | 3427 | |
576eeee9 EP |
3428 | /* |
3429 | * iwl_mvm_protect_session() reads directly from the device | |
3430 | * (the system time), so make sure it is available. | |
3431 | */ | |
3432 | if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX)) | |
3433 | return; | |
3434 | ||
d4e36e55 IP |
3435 | if (req_duration > duration) |
3436 | duration = req_duration; | |
3437 | ||
8ca151b5 JB |
3438 | mutex_lock(&mvm->mutex); |
3439 | /* Try really hard to protect the session and hear a beacon */ | |
d20d37bc | 3440 | iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false); |
8ca151b5 | 3441 | mutex_unlock(&mvm->mutex); |
576eeee9 EP |
3442 | |
3443 | iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX); | |
8ca151b5 JB |
3444 | } |
3445 | ||
35a000b7 DS |
3446 | static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, |
3447 | struct ieee80211_vif *vif, | |
3448 | struct cfg80211_sched_scan_request *req, | |
633e2713 | 3449 | struct ieee80211_scan_ies *ies) |
35a000b7 DS |
3450 | { |
3451 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
35a000b7 | 3452 | |
35a000b7 | 3453 | int ret; |
4660dfbb | 3454 | |
35a000b7 DS |
3455 | mutex_lock(&mvm->mutex); |
3456 | ||
1f940386 | 3457 | if (!vif->bss_conf.idle) { |
bd5e4744 DS |
3458 | ret = -EBUSY; |
3459 | goto out; | |
3460 | } | |
3461 | ||
19945dfb | 3462 | ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED); |
d2496221 | 3463 | |
35a000b7 DS |
3464 | out: |
3465 | mutex_unlock(&mvm->mutex); | |
3466 | return ret; | |
3467 | } | |
3468 | ||
37e3308c JB |
3469 | static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, |
3470 | struct ieee80211_vif *vif) | |
35a000b7 DS |
3471 | { |
3472 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
33ea27f6 | 3473 | int ret; |
35a000b7 DS |
3474 | |
3475 | mutex_lock(&mvm->mutex); | |
e7d3abab LC |
3476 | |
3477 | /* Due to a race condition, it's possible that mac80211 asks | |
3478 | * us to stop a sched_scan when it's already stopped. This | |
3479 | * can happen, for instance, if we stopped the scan ourselves, | |
3480 | * called ieee80211_sched_scan_stopped() and the userspace called | |
3481 | * stop sched scan scan before ieee80211_sched_scan_stopped_work() | |
3482 | * could run. To handle this, simply return if the scan is | |
3483 | * not running. | |
3484 | */ | |
262888fc | 3485 | if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) { |
e7d3abab LC |
3486 | mutex_unlock(&mvm->mutex); |
3487 | return 0; | |
3488 | } | |
3489 | ||
c7d42480 | 3490 | ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false); |
35a000b7 | 3491 | mutex_unlock(&mvm->mutex); |
33ea27f6 | 3492 | iwl_mvm_wait_for_async_handlers(mvm); |
37e3308c | 3493 | |
33ea27f6 | 3494 | return ret; |
35a000b7 DS |
3495 | } |
3496 | ||
8ca151b5 JB |
3497 | static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, |
3498 | enum set_key_cmd cmd, | |
3499 | struct ieee80211_vif *vif, | |
3500 | struct ieee80211_sta *sta, | |
3501 | struct ieee80211_key_conf *key) | |
3502 | { | |
c56e00a3 | 3503 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
8ca151b5 | 3504 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
f5e28eac JB |
3505 | struct iwl_mvm_sta *mvmsta; |
3506 | struct iwl_mvm_key_pn *ptk_pn; | |
3507 | int keyidx = key->keyidx; | |
c56e00a3 | 3508 | int ret, i; |
d6ee54a9 | 3509 | u8 key_offset; |
8ca151b5 | 3510 | |
3b37f4c9 | 3511 | if (iwlwifi_mod_params.swcrypto) { |
8ca151b5 JB |
3512 | IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n"); |
3513 | return -EOPNOTSUPP; | |
3514 | } | |
3515 | ||
3516 | switch (key->cipher) { | |
3517 | case WLAN_CIPHER_SUITE_TKIP: | |
7f768ad5 DS |
3518 | if (!mvm->trans->cfg->gen2) { |
3519 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; | |
3520 | key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; | |
3521 | } else if (vif->type == NL80211_IFTYPE_STATION) { | |
3522 | key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE; | |
3523 | } else { | |
3524 | IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n"); | |
3525 | return -EOPNOTSUPP; | |
3526 | } | |
8ca151b5 | 3527 | break; |
ca8c0f4b | 3528 | case WLAN_CIPHER_SUITE_CCMP: |
2a53d166 AB |
3529 | case WLAN_CIPHER_SUITE_GCMP: |
3530 | case WLAN_CIPHER_SUITE_GCMP_256: | |
85aeb58c DS |
3531 | if (!iwl_mvm_has_new_tx_api(mvm)) |
3532 | key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; | |
ca8c0f4b | 3533 | break; |
8ca151b5 | 3534 | case WLAN_CIPHER_SUITE_AES_CMAC: |
8e160ab8 AB |
3535 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
3536 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: | |
30686bf7 | 3537 | WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE)); |
8ca151b5 JB |
3538 | break; |
3539 | case WLAN_CIPHER_SUITE_WEP40: | |
3540 | case WLAN_CIPHER_SUITE_WEP104: | |
475c6bde JB |
3541 | if (vif->type == NL80211_IFTYPE_STATION) |
3542 | break; | |
3543 | if (iwl_mvm_has_new_tx_api(mvm)) | |
3544 | return -EOPNOTSUPP; | |
3545 | /* support HW crypto on TX */ | |
3546 | return 0; | |
8ca151b5 | 3547 | default: |
e36e5433 MS |
3548 | /* currently FW supports only one optional cipher scheme */ |
3549 | if (hw->n_cipher_schemes && | |
3550 | hw->cipher_schemes->cipher == key->cipher) | |
3551 | key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; | |
3552 | else | |
3553 | return -EOPNOTSUPP; | |
8ca151b5 JB |
3554 | } |
3555 | ||
3556 | mutex_lock(&mvm->mutex); | |
3557 | ||
3558 | switch (cmd) { | |
3559 | case SET_KEY: | |
5023d966 JB |
3560 | if ((vif->type == NL80211_IFTYPE_ADHOC || |
3561 | vif->type == NL80211_IFTYPE_AP) && !sta) { | |
3562 | /* | |
3563 | * GTK on AP interface is a TX-only key, return 0; | |
3564 | * on IBSS they're per-station and because we're lazy | |
3565 | * we don't support them for RX, so do the same. | |
8e160ab8 | 3566 | * CMAC/GMAC in AP/IBSS modes must be done in software. |
5023d966 | 3567 | */ |
8e160ab8 AB |
3568 | if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || |
3569 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || | |
3570 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) | |
81279c49 JB |
3571 | ret = -EOPNOTSUPP; |
3572 | else | |
3573 | ret = 0; | |
85aeb58c DS |
3574 | |
3575 | if (key->cipher != WLAN_CIPHER_SUITE_GCMP && | |
3576 | key->cipher != WLAN_CIPHER_SUITE_GCMP_256 && | |
3577 | !iwl_mvm_has_new_tx_api(mvm)) { | |
3578 | key->hw_key_idx = STA_KEY_IDX_INVALID; | |
3579 | break; | |
3580 | } | |
c56e00a3 JB |
3581 | |
3582 | if (!mvmvif->ap_ibss_active) { | |
3583 | for (i = 0; | |
3584 | i < ARRAY_SIZE(mvmvif->ap_early_keys); | |
3585 | i++) { | |
3586 | if (!mvmvif->ap_early_keys[i]) { | |
3587 | mvmvif->ap_early_keys[i] = key; | |
3588 | break; | |
3589 | } | |
3590 | } | |
3591 | ||
3592 | if (i >= ARRAY_SIZE(mvmvif->ap_early_keys)) | |
3593 | ret = -ENOSPC; | |
3594 | ||
3595 | break; | |
3596 | } | |
6caffd4f JB |
3597 | } |
3598 | ||
b546dcd6 JB |
3599 | /* During FW restart, in order to restore the state as it was, |
3600 | * don't try to reprogram keys we previously failed for. | |
3601 | */ | |
3602 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && | |
3603 | key->hw_key_idx == STA_KEY_IDX_INVALID) { | |
3604 | IWL_DEBUG_MAC80211(mvm, | |
3605 | "skip invalid idx key programming during restart\n"); | |
3606 | ret = 0; | |
3607 | break; | |
3608 | } | |
3609 | ||
f5e28eac JB |
3610 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && |
3611 | sta && iwl_mvm_has_new_rx_api(mvm) && | |
3612 | key->flags & IEEE80211_KEY_FLAG_PAIRWISE && | |
3613 | (key->cipher == WLAN_CIPHER_SUITE_CCMP || | |
2a53d166 AB |
3614 | key->cipher == WLAN_CIPHER_SUITE_GCMP || |
3615 | key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { | |
f5e28eac JB |
3616 | struct ieee80211_key_seq seq; |
3617 | int tid, q; | |
3618 | ||
3619 | mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
3620 | WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx])); | |
acafe7e3 KC |
3621 | ptk_pn = kzalloc(struct_size(ptk_pn, q, |
3622 | mvm->trans->num_rx_queues), | |
f5e28eac JB |
3623 | GFP_KERNEL); |
3624 | if (!ptk_pn) { | |
3625 | ret = -ENOMEM; | |
3626 | break; | |
3627 | } | |
3628 | ||
3629 | for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { | |
3630 | ieee80211_get_key_rx_seq(key, tid, &seq); | |
3631 | for (q = 0; q < mvm->trans->num_rx_queues; q++) | |
3632 | memcpy(ptk_pn->q[q].pn[tid], | |
3633 | seq.ccmp.pn, | |
3634 | IEEE80211_CCMP_PN_LEN); | |
3635 | } | |
3636 | ||
3637 | rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn); | |
3638 | } | |
3639 | ||
d6ee54a9 LC |
3640 | /* in HW restart reuse the index, otherwise request a new one */ |
3641 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) | |
3642 | key_offset = key->hw_key_idx; | |
3643 | else | |
3644 | key_offset = STA_KEY_IDX_INVALID; | |
3645 | ||
8ca151b5 | 3646 | IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n"); |
d6ee54a9 | 3647 | ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset); |
8ca151b5 JB |
3648 | if (ret) { |
3649 | IWL_WARN(mvm, "set key failed\n"); | |
475c6bde | 3650 | key->hw_key_idx = STA_KEY_IDX_INVALID; |
8ca151b5 JB |
3651 | /* |
3652 | * can't add key for RX, but we don't need it | |
475c6bde JB |
3653 | * in the device for TX so still return 0, |
3654 | * unless we have new TX API where we cannot | |
3655 | * put key material into the TX_CMD | |
8ca151b5 | 3656 | */ |
475c6bde JB |
3657 | if (iwl_mvm_has_new_tx_api(mvm)) |
3658 | ret = -EOPNOTSUPP; | |
3659 | else | |
3660 | ret = 0; | |
8ca151b5 JB |
3661 | } |
3662 | ||
3663 | break; | |
3664 | case DISABLE_KEY: | |
c56e00a3 JB |
3665 | ret = -ENOENT; |
3666 | for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { | |
3667 | if (mvmvif->ap_early_keys[i] == key) { | |
3668 | mvmvif->ap_early_keys[i] = NULL; | |
3669 | ret = 0; | |
3670 | } | |
3671 | } | |
3672 | ||
3673 | /* found in pending list - don't do anything else */ | |
3674 | if (ret == 0) | |
3675 | break; | |
3676 | ||
6caffd4f JB |
3677 | if (key->hw_key_idx == STA_KEY_IDX_INVALID) { |
3678 | ret = 0; | |
3679 | break; | |
3680 | } | |
3681 | ||
f5e28eac JB |
3682 | if (sta && iwl_mvm_has_new_rx_api(mvm) && |
3683 | key->flags & IEEE80211_KEY_FLAG_PAIRWISE && | |
3684 | (key->cipher == WLAN_CIPHER_SUITE_CCMP || | |
2a53d166 AB |
3685 | key->cipher == WLAN_CIPHER_SUITE_GCMP || |
3686 | key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { | |
f5e28eac JB |
3687 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
3688 | ptk_pn = rcu_dereference_protected( | |
3689 | mvmsta->ptk_pn[keyidx], | |
3690 | lockdep_is_held(&mvm->mutex)); | |
3691 | RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL); | |
3692 | if (ptk_pn) | |
3693 | kfree_rcu(ptk_pn, rcu_head); | |
3694 | } | |
3695 | ||
8ca151b5 JB |
3696 | IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); |
3697 | ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); | |
3698 | break; | |
3699 | default: | |
3700 | ret = -EINVAL; | |
3701 | } | |
3702 | ||
3703 | mutex_unlock(&mvm->mutex); | |
3704 | return ret; | |
3705 | } | |
3706 | ||
3707 | static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, | |
3708 | struct ieee80211_vif *vif, | |
3709 | struct ieee80211_key_conf *keyconf, | |
3710 | struct ieee80211_sta *sta, | |
3711 | u32 iv32, u16 *phase1key) | |
3712 | { | |
3713 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
3714 | ||
5023d966 JB |
3715 | if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) |
3716 | return; | |
3717 | ||
8ca151b5 JB |
3718 | iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); |
3719 | } | |
3720 | ||
3721 | ||
b112889c AM |
3722 | static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait, |
3723 | struct iwl_rx_packet *pkt, void *data) | |
3724 | { | |
3725 | struct iwl_mvm *mvm = | |
3726 | container_of(notif_wait, struct iwl_mvm, notif_wait); | |
3727 | struct iwl_hs20_roc_res *resp; | |
3728 | int resp_len = iwl_rx_packet_payload_len(pkt); | |
3729 | struct iwl_mvm_time_event_data *te_data = data; | |
3730 | ||
3731 | if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD)) | |
3732 | return true; | |
3733 | ||
3734 | if (WARN_ON_ONCE(resp_len != sizeof(*resp))) { | |
3735 | IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n"); | |
3736 | return true; | |
3737 | } | |
3738 | ||
3739 | resp = (void *)pkt->data; | |
3740 | ||
3741 | IWL_DEBUG_TE(mvm, | |
b71a9c35 | 3742 | "Aux ROC: Received response from ucode: status=%d uid=%d\n", |
b112889c AM |
3743 | resp->status, resp->event_unique_id); |
3744 | ||
3745 | te_data->uid = le32_to_cpu(resp->event_unique_id); | |
3746 | IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n", | |
3747 | te_data->uid); | |
3748 | ||
3749 | spin_lock_bh(&mvm->time_event_lock); | |
3750 | list_add_tail(&te_data->list, &mvm->aux_roc_te_list); | |
3751 | spin_unlock_bh(&mvm->time_event_lock); | |
3752 | ||
3753 | return true; | |
3754 | } | |
3755 | ||
dc28e12f MG |
3756 | #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100) |
3757 | #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200) | |
3758 | #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600) | |
3759 | #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20) | |
3760 | #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10) | |
b112889c AM |
3761 | static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm, |
3762 | struct ieee80211_channel *channel, | |
3763 | struct ieee80211_vif *vif, | |
3764 | int duration) | |
3765 | { | |
afc1e3b4 | 3766 | int res; |
b112889c AM |
3767 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
3768 | struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data; | |
6eb031d2 | 3769 | static const u16 time_event_response[] = { HOT_SPOT_CMD }; |
b112889c | 3770 | struct iwl_notification_wait wait_time_event; |
dc28e12f MG |
3771 | u32 dtim_interval = vif->bss_conf.dtim_period * |
3772 | vif->bss_conf.beacon_int; | |
3773 | u32 req_dur, delay; | |
b112889c AM |
3774 | struct iwl_hs20_roc_req aux_roc_req = { |
3775 | .action = cpu_to_le32(FW_CTXT_ACTION_ADD), | |
3776 | .id_and_color = | |
3777 | cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)), | |
3778 | .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id), | |
57e861d9 DS |
3779 | }; |
3780 | struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm, | |
3781 | &aux_roc_req.channel_info); | |
3782 | u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm); | |
3783 | ||
3784 | /* Set the channel info data */ | |
3785 | iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value, | |
3786 | (channel->band == NL80211_BAND_2GHZ) ? | |
3787 | PHY_BAND_24 : PHY_BAND_5, | |
3788 | PHY_VHT_CHANNEL_MODE20, | |
3789 | 0); | |
3790 | ||
3791 | /* Set the time and duration */ | |
afc1e3b4 | 3792 | tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm)); |
b112889c | 3793 | |
dc28e12f MG |
3794 | delay = AUX_ROC_MIN_DELAY; |
3795 | req_dur = MSEC_TO_TU(duration); | |
3796 | ||
3797 | /* | |
3798 | * If we are associated we want the delay time to be at least one | |
3799 | * dtim interval so that the FW can wait until after the DTIM and | |
3800 | * then start the time event, this will potentially allow us to | |
3801 | * remain off-channel for the max duration. | |
3802 | * Since we want to use almost a whole dtim interval we would also | |
3803 | * like the delay to be for 2-3 dtim intervals, in case there are | |
3804 | * other time events with higher priority. | |
3805 | */ | |
3806 | if (vif->bss_conf.assoc) { | |
3807 | delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY); | |
3808 | /* We cannot remain off-channel longer than the DTIM interval */ | |
3809 | if (dtim_interval <= req_dur) { | |
3810 | req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER; | |
3811 | if (req_dur <= AUX_ROC_MIN_DURATION) | |
3812 | req_dur = dtim_interval - | |
3813 | AUX_ROC_MIN_SAFETY_BUFFER; | |
3814 | } | |
3815 | } | |
3816 | ||
57e861d9 DS |
3817 | tail->duration = cpu_to_le32(req_dur); |
3818 | tail->apply_time_max_delay = cpu_to_le32(delay); | |
dc28e12f MG |
3819 | |
3820 | IWL_DEBUG_TE(mvm, | |
3821 | "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n", | |
3822 | channel->hw_value, req_dur, duration, delay, | |
3823 | dtim_interval); | |
b112889c | 3824 | /* Set the node address */ |
57e861d9 | 3825 | memcpy(tail->node_addr, vif->addr, ETH_ALEN); |
b112889c | 3826 | |
a6cc5163 MG |
3827 | lockdep_assert_held(&mvm->mutex); |
3828 | ||
3829 | spin_lock_bh(&mvm->time_event_lock); | |
3830 | ||
3831 | if (WARN_ON(te_data->id == HOT_SPOT_CMD)) { | |
3832 | spin_unlock_bh(&mvm->time_event_lock); | |
3833 | return -EIO; | |
3834 | } | |
3835 | ||
b112889c AM |
3836 | te_data->vif = vif; |
3837 | te_data->duration = duration; | |
3838 | te_data->id = HOT_SPOT_CMD; | |
3839 | ||
b112889c AM |
3840 | spin_unlock_bh(&mvm->time_event_lock); |
3841 | ||
3842 | /* | |
3843 | * Use a notification wait, which really just processes the | |
3844 | * command response and doesn't wait for anything, in order | |
3845 | * to be able to process the response and get the UID inside | |
3846 | * the RX path. Using CMD_WANT_SKB doesn't work because it | |
3847 | * stores the buffer and then wakes up this thread, by which | |
3848 | * time another notification (that the time event started) | |
3849 | * might already be processed unsuccessfully. | |
3850 | */ | |
3851 | iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event, | |
3852 | time_event_response, | |
3853 | ARRAY_SIZE(time_event_response), | |
3854 | iwl_mvm_rx_aux_roc, te_data); | |
3855 | ||
57e861d9 | 3856 | res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len, |
b112889c AM |
3857 | &aux_roc_req); |
3858 | ||
3859 | if (res) { | |
3860 | IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res); | |
3861 | iwl_remove_notification(&mvm->notif_wait, &wait_time_event); | |
3862 | goto out_clear_te; | |
3863 | } | |
3864 | ||
3865 | /* No need to wait for anything, so just pass 1 (0 isn't valid) */ | |
3866 | res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1); | |
3867 | /* should never fail */ | |
3868 | WARN_ON_ONCE(res); | |
3869 | ||
3870 | if (res) { | |
3871 | out_clear_te: | |
3872 | spin_lock_bh(&mvm->time_event_lock); | |
3873 | iwl_mvm_te_clear_data(mvm, te_data); | |
3874 | spin_unlock_bh(&mvm->time_event_lock); | |
3875 | } | |
3876 | ||
3877 | return res; | |
3878 | } | |
3879 | ||
8ca151b5 JB |
3880 | static int iwl_mvm_roc(struct ieee80211_hw *hw, |
3881 | struct ieee80211_vif *vif, | |
3882 | struct ieee80211_channel *channel, | |
d339d5ca IP |
3883 | int duration, |
3884 | enum ieee80211_roc_type type) | |
8ca151b5 JB |
3885 | { |
3886 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
fe0f2de3 | 3887 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
8ca151b5 | 3888 | struct cfg80211_chan_def chandef; |
31d385ae IP |
3889 | struct iwl_mvm_phy_ctxt *phy_ctxt; |
3890 | int ret, i; | |
3891 | ||
3892 | IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, | |
3893 | duration, type); | |
8ca151b5 | 3894 | |
9834781c JB |
3895 | /* |
3896 | * Flush the done work, just in case it's still pending, so that | |
3897 | * the work it does can complete and we can accept new frames. | |
3898 | */ | |
6ed13164 MG |
3899 | flush_work(&mvm->roc_done_wk); |
3900 | ||
a6cc5163 MG |
3901 | mutex_lock(&mvm->mutex); |
3902 | ||
b112889c AM |
3903 | switch (vif->type) { |
3904 | case NL80211_IFTYPE_STATION: | |
859d914c JB |
3905 | if (fw_has_capa(&mvm->fw->ucode_capa, |
3906 | IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) { | |
5ac6c72e LC |
3907 | /* Use aux roc framework (HS20) */ |
3908 | ret = iwl_mvm_send_aux_roc_cmd(mvm, channel, | |
3909 | vif, duration); | |
3910 | goto out_unlock; | |
3911 | } | |
3912 | IWL_ERR(mvm, "hotspot not supported\n"); | |
3913 | ret = -EINVAL; | |
a6cc5163 | 3914 | goto out_unlock; |
b112889c AM |
3915 | case NL80211_IFTYPE_P2P_DEVICE: |
3916 | /* handle below */ | |
3917 | break; | |
3918 | default: | |
3919 | IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type); | |
a6cc5163 MG |
3920 | ret = -EINVAL; |
3921 | goto out_unlock; | |
8ca151b5 JB |
3922 | } |
3923 | ||
31d385ae IP |
3924 | for (i = 0; i < NUM_PHY_CTX; i++) { |
3925 | phy_ctxt = &mvm->phy_ctxts[i]; | |
3926 | if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt) | |
3927 | continue; | |
3928 | ||
3929 | if (phy_ctxt->ref && channel == phy_ctxt->channel) { | |
3930 | /* | |
3931 | * Unbind the P2P_DEVICE from the current PHY context, | |
3932 | * and if the PHY context is not used remove it. | |
3933 | */ | |
3934 | ret = iwl_mvm_binding_remove_vif(mvm, vif); | |
3935 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) | |
3936 | goto out_unlock; | |
3937 | ||
3938 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); | |
3939 | ||
3940 | /* Bind the P2P_DEVICE to the current PHY Context */ | |
3941 | mvmvif->phy_ctxt = phy_ctxt; | |
3942 | ||
3943 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
3944 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) | |
3945 | goto out_unlock; | |
3946 | ||
3947 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); | |
3948 | goto schedule_time_event; | |
3949 | } | |
3950 | } | |
3951 | ||
3952 | /* Need to update the PHY context only if the ROC channel changed */ | |
3953 | if (channel == mvmvif->phy_ctxt->channel) | |
3954 | goto schedule_time_event; | |
3955 | ||
8ca151b5 | 3956 | cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); |
8ca151b5 | 3957 | |
31d385ae IP |
3958 | /* |
3959 | * Change the PHY context configuration as it is currently referenced | |
3960 | * only by the P2P Device MAC | |
3961 | */ | |
3962 | if (mvmvif->phy_ctxt->ref == 1) { | |
3963 | ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt, | |
3964 | &chandef, 1, 1); | |
3965 | if (ret) | |
3966 | goto out_unlock; | |
3967 | } else { | |
3968 | /* | |
3969 | * The PHY context is shared with other MACs. Need to remove the | |
3970 | * P2P Device from the binding, allocate an new PHY context and | |
3971 | * create a new binding | |
3972 | */ | |
3973 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); | |
3974 | if (!phy_ctxt) { | |
3975 | ret = -ENOSPC; | |
3976 | goto out_unlock; | |
3977 | } | |
3978 | ||
3979 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef, | |
3980 | 1, 1); | |
3981 | if (ret) { | |
3982 | IWL_ERR(mvm, "Failed to change PHY context\n"); | |
3983 | goto out_unlock; | |
3984 | } | |
3985 | ||
3986 | /* Unbind the P2P_DEVICE from the current PHY context */ | |
3987 | ret = iwl_mvm_binding_remove_vif(mvm, vif); | |
3988 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) | |
3989 | goto out_unlock; | |
3990 | ||
3991 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); | |
3992 | ||
3993 | /* Bind the P2P_DEVICE to the new allocated PHY context */ | |
3994 | mvmvif->phy_ctxt = phy_ctxt; | |
3995 | ||
3996 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
3997 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) | |
3998 | goto out_unlock; | |
3999 | ||
4000 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); | |
4001 | } | |
4002 | ||
4003 | schedule_time_event: | |
8ca151b5 | 4004 | /* Schedule the time events */ |
e635c797 | 4005 | ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); |
8ca151b5 | 4006 | |
31d385ae | 4007 | out_unlock: |
8ca151b5 JB |
4008 | mutex_unlock(&mvm->mutex); |
4009 | IWL_DEBUG_MAC80211(mvm, "leave\n"); | |
8ca151b5 JB |
4010 | return ret; |
4011 | } | |
4012 | ||
4013 | static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw) | |
4014 | { | |
4015 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4016 | ||
4017 | IWL_DEBUG_MAC80211(mvm, "enter\n"); | |
4018 | ||
4019 | mutex_lock(&mvm->mutex); | |
bf5da87f | 4020 | iwl_mvm_stop_roc(mvm); |
8ca151b5 JB |
4021 | mutex_unlock(&mvm->mutex); |
4022 | ||
4023 | IWL_DEBUG_MAC80211(mvm, "leave\n"); | |
4024 | return 0; | |
4025 | } | |
4026 | ||
b73f9a4a JB |
4027 | struct iwl_mvm_ftm_responder_iter_data { |
4028 | bool responder; | |
4029 | struct ieee80211_chanctx_conf *ctx; | |
4030 | }; | |
4031 | ||
4032 | static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac, | |
4033 | struct ieee80211_vif *vif) | |
4034 | { | |
4035 | struct iwl_mvm_ftm_responder_iter_data *data = _data; | |
4036 | ||
4037 | if (rcu_access_pointer(vif->chanctx_conf) == data->ctx && | |
4038 | vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params) | |
4039 | data->responder = true; | |
4040 | } | |
4041 | ||
4042 | static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm, | |
4043 | struct ieee80211_chanctx_conf *ctx) | |
4044 | { | |
4045 | struct iwl_mvm_ftm_responder_iter_data data = { | |
4046 | .responder = false, | |
4047 | .ctx = ctx, | |
4048 | }; | |
4049 | ||
4050 | ieee80211_iterate_active_interfaces_atomic(mvm->hw, | |
4051 | IEEE80211_IFACE_ITER_NORMAL, | |
4052 | iwl_mvm_ftm_responder_chanctx_iter, | |
4053 | &data); | |
4054 | return data.responder; | |
4055 | } | |
4056 | ||
b08c1d97 LC |
4057 | static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm, |
4058 | struct ieee80211_chanctx_conf *ctx) | |
8ca151b5 | 4059 | { |
fe0f2de3 IP |
4060 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
4061 | struct iwl_mvm_phy_ctxt *phy_ctxt; | |
b73f9a4a JB |
4062 | bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx); |
4063 | struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def; | |
8ca151b5 JB |
4064 | int ret; |
4065 | ||
b08c1d97 LC |
4066 | lockdep_assert_held(&mvm->mutex); |
4067 | ||
53a9d61e | 4068 | IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); |
fe0f2de3 | 4069 | |
fe0f2de3 IP |
4070 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
4071 | if (!phy_ctxt) { | |
4072 | ret = -ENOSPC; | |
4073 | goto out; | |
4074 | } | |
8ca151b5 | 4075 | |
b73f9a4a | 4076 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def, |
53a9d61e IP |
4077 | ctx->rx_chains_static, |
4078 | ctx->rx_chains_dynamic); | |
fe0f2de3 IP |
4079 | if (ret) { |
4080 | IWL_ERR(mvm, "Failed to add PHY context\n"); | |
4081 | goto out; | |
4082 | } | |
4083 | ||
53a9d61e | 4084 | iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt); |
fe0f2de3 IP |
4085 | *phy_ctxt_id = phy_ctxt->id; |
4086 | out: | |
b08c1d97 LC |
4087 | return ret; |
4088 | } | |
4089 | ||
4090 | static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, | |
4091 | struct ieee80211_chanctx_conf *ctx) | |
4092 | { | |
4093 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4094 | int ret; | |
4095 | ||
4096 | mutex_lock(&mvm->mutex); | |
4097 | ret = __iwl_mvm_add_chanctx(mvm, ctx); | |
8ca151b5 | 4098 | mutex_unlock(&mvm->mutex); |
b08c1d97 | 4099 | |
8ca151b5 JB |
4100 | return ret; |
4101 | } | |
4102 | ||
b08c1d97 LC |
4103 | static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm, |
4104 | struct ieee80211_chanctx_conf *ctx) | |
4105 | { | |
4106 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; | |
4107 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; | |
4108 | ||
4109 | lockdep_assert_held(&mvm->mutex); | |
4110 | ||
4111 | iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); | |
4112 | } | |
4113 | ||
8ca151b5 JB |
4114 | static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, |
4115 | struct ieee80211_chanctx_conf *ctx) | |
4116 | { | |
4117 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
8ca151b5 JB |
4118 | |
4119 | mutex_lock(&mvm->mutex); | |
b08c1d97 | 4120 | __iwl_mvm_remove_chanctx(mvm, ctx); |
8ca151b5 JB |
4121 | mutex_unlock(&mvm->mutex); |
4122 | } | |
4123 | ||
4124 | static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, | |
4125 | struct ieee80211_chanctx_conf *ctx, | |
4126 | u32 changed) | |
4127 | { | |
4128 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
fe0f2de3 IP |
4129 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
4130 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; | |
b73f9a4a JB |
4131 | bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx); |
4132 | struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def; | |
8ca151b5 | 4133 | |
31d385ae IP |
4134 | if (WARN_ONCE((phy_ctxt->ref > 1) && |
4135 | (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | | |
4136 | IEEE80211_CHANCTX_CHANGE_RX_CHAINS | | |
2dceedae AN |
4137 | IEEE80211_CHANCTX_CHANGE_RADAR | |
4138 | IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)), | |
31d385ae IP |
4139 | "Cannot change PHY. Ref=%d, changed=0x%X\n", |
4140 | phy_ctxt->ref, changed)) | |
4141 | return; | |
4142 | ||
8ca151b5 | 4143 | mutex_lock(&mvm->mutex); |
7a20bcce EG |
4144 | |
4145 | /* we are only changing the min_width, may be a noop */ | |
4146 | if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) { | |
b73f9a4a | 4147 | if (phy_ctxt->width == def->width) |
7a20bcce EG |
4148 | goto out_unlock; |
4149 | ||
4150 | /* we are just toggling between 20_NOHT and 20 */ | |
4151 | if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 && | |
b73f9a4a | 4152 | def->width <= NL80211_CHAN_WIDTH_20) |
7a20bcce EG |
4153 | goto out_unlock; |
4154 | } | |
4155 | ||
4d66449a | 4156 | iwl_mvm_bt_coex_vif_change(mvm); |
b73f9a4a | 4157 | iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def, |
8ca151b5 JB |
4158 | ctx->rx_chains_static, |
4159 | ctx->rx_chains_dynamic); | |
7a20bcce EG |
4160 | |
4161 | out_unlock: | |
8ca151b5 JB |
4162 | mutex_unlock(&mvm->mutex); |
4163 | } | |
4164 | ||
b08c1d97 LC |
4165 | static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm, |
4166 | struct ieee80211_vif *vif, | |
f0c97783 LC |
4167 | struct ieee80211_chanctx_conf *ctx, |
4168 | bool switching_chanctx) | |
8ca151b5 | 4169 | { |
fe0f2de3 IP |
4170 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
4171 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; | |
8ca151b5 JB |
4172 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
4173 | int ret; | |
4174 | ||
b08c1d97 | 4175 | lockdep_assert_held(&mvm->mutex); |
8ca151b5 | 4176 | |
fe0f2de3 | 4177 | mvmvif->phy_ctxt = phy_ctxt; |
8ca151b5 JB |
4178 | |
4179 | switch (vif->type) { | |
4180 | case NL80211_IFTYPE_AP: | |
4741dd04 LC |
4181 | /* only needed if we're switching chanctx (i.e. during CSA) */ |
4182 | if (switching_chanctx) { | |
bd3398e2 AO |
4183 | mvmvif->ap_ibss_active = true; |
4184 | break; | |
4185 | } | |
244726ec | 4186 | /* fall through */ |
5023d966 | 4187 | case NL80211_IFTYPE_ADHOC: |
8ca151b5 JB |
4188 | /* |
4189 | * The AP binding flow is handled as part of the start_ap flow | |
5023d966 | 4190 | * (in bss_info_changed), similarly for IBSS. |
8ca151b5 JB |
4191 | */ |
4192 | ret = 0; | |
b08c1d97 | 4193 | goto out; |
8ca151b5 | 4194 | case NL80211_IFTYPE_STATION: |
19125cb0 | 4195 | mvmvif->csa_bcn_pending = false; |
2533edce | 4196 | break; |
8ca151b5 | 4197 | case NL80211_IFTYPE_MONITOR: |
2533edce LC |
4198 | /* always disable PS when a monitor interface is active */ |
4199 | mvmvif->ps_disabled = true; | |
8ca151b5 JB |
4200 | break; |
4201 | default: | |
4202 | ret = -EINVAL; | |
b08c1d97 | 4203 | goto out; |
8ca151b5 JB |
4204 | } |
4205 | ||
4206 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
4207 | if (ret) | |
b08c1d97 | 4208 | goto out; |
8ca151b5 JB |
4209 | |
4210 | /* | |
92d85562 AB |
4211 | * Power state must be updated before quotas, |
4212 | * otherwise fw will complain. | |
4213 | */ | |
999609f1 | 4214 | iwl_mvm_power_update_mac(mvm); |
92d85562 AB |
4215 | |
4216 | /* Setting the quota at this stage is only required for monitor | |
8ca151b5 JB |
4217 | * interfaces. For the other types, the bss_info changed flow |
4218 | * will handle quota settings. | |
4219 | */ | |
4220 | if (vif->type == NL80211_IFTYPE_MONITOR) { | |
1e1391ca | 4221 | mvmvif->monitor_active = true; |
7754ae79 | 4222 | ret = iwl_mvm_update_quotas(mvm, false, NULL); |
8ca151b5 JB |
4223 | if (ret) |
4224 | goto out_remove_binding; | |
0e39eb03 CRI |
4225 | |
4226 | ret = iwl_mvm_add_snif_sta(mvm, vif); | |
4227 | if (ret) | |
4228 | goto out_remove_binding; | |
4229 | ||
8ca151b5 JB |
4230 | } |
4231 | ||
bd3398e2 | 4232 | /* Handle binding during CSA */ |
a57c688d | 4233 | if (vif->type == NL80211_IFTYPE_AP) { |
7754ae79 | 4234 | iwl_mvm_update_quotas(mvm, false, NULL); |
3dfd3a97 | 4235 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); |
bd3398e2 AO |
4236 | } |
4237 | ||
4741dd04 | 4238 | if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) { |
74a10252 | 4239 | mvmvif->csa_bcn_pending = true; |
686e7fe1 | 4240 | |
74a10252 SS |
4241 | if (!fw_has_capa(&mvm->fw->ucode_capa, |
4242 | IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { | |
4243 | u32 duration = 3 * vif->bss_conf.beacon_int; | |
686e7fe1 | 4244 | |
686e7fe1 | 4245 | |
74a10252 SS |
4246 | /* iwl_mvm_protect_session() reads directly from the |
4247 | * device (the system time), so make sure it is | |
4248 | * available. | |
4249 | */ | |
4250 | ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA); | |
4251 | if (ret) | |
4252 | goto out_remove_binding; | |
4253 | ||
4254 | /* Protect the session to make sure we hear the first | |
4255 | * beacon on the new channel. | |
4256 | */ | |
4257 | iwl_mvm_protect_session(mvm, vif, duration, duration, | |
4258 | vif->bss_conf.beacon_int / 2, | |
4259 | true); | |
4260 | ||
4261 | iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA); | |
4262 | } | |
686e7fe1 | 4263 | |
7754ae79 | 4264 | iwl_mvm_update_quotas(mvm, false, NULL); |
0ce04ce7 LC |
4265 | } |
4266 | ||
b08c1d97 | 4267 | goto out; |
8ca151b5 | 4268 | |
b08c1d97 | 4269 | out_remove_binding: |
8ca151b5 | 4270 | iwl_mvm_binding_remove_vif(mvm, vif); |
999609f1 | 4271 | iwl_mvm_power_update_mac(mvm); |
b08c1d97 | 4272 | out: |
8ca151b5 JB |
4273 | if (ret) |
4274 | mvmvif->phy_ctxt = NULL; | |
4275 | return ret; | |
4276 | } | |
b08c1d97 LC |
4277 | static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, |
4278 | struct ieee80211_vif *vif, | |
4279 | struct ieee80211_chanctx_conf *ctx) | |
8ca151b5 JB |
4280 | { |
4281 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
b08c1d97 | 4282 | int ret; |
8ca151b5 JB |
4283 | |
4284 | mutex_lock(&mvm->mutex); | |
f0c97783 | 4285 | ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false); |
b08c1d97 LC |
4286 | mutex_unlock(&mvm->mutex); |
4287 | ||
4288 | return ret; | |
4289 | } | |
4290 | ||
4291 | static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm, | |
4292 | struct ieee80211_vif *vif, | |
f0c97783 LC |
4293 | struct ieee80211_chanctx_conf *ctx, |
4294 | bool switching_chanctx) | |
b08c1d97 LC |
4295 | { |
4296 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
f0c97783 | 4297 | struct ieee80211_vif *disabled_vif = NULL; |
b08c1d97 LC |
4298 | |
4299 | lockdep_assert_held(&mvm->mutex); | |
8ca151b5 JB |
4300 | |
4301 | iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data); | |
4302 | ||
8ca151b5 | 4303 | switch (vif->type) { |
5023d966 | 4304 | case NL80211_IFTYPE_ADHOC: |
b08c1d97 | 4305 | goto out; |
8ca151b5 | 4306 | case NL80211_IFTYPE_MONITOR: |
1e1391ca | 4307 | mvmvif->monitor_active = false; |
2533edce | 4308 | mvmvif->ps_disabled = false; |
0e39eb03 | 4309 | iwl_mvm_rm_snif_sta(mvm, vif); |
8ca151b5 | 4310 | break; |
bd3398e2 AO |
4311 | case NL80211_IFTYPE_AP: |
4312 | /* This part is triggered only during CSA */ | |
4741dd04 | 4313 | if (!switching_chanctx || !mvmvif->ap_ibss_active) |
b08c1d97 | 4314 | goto out; |
bd3398e2 | 4315 | |
7ef0aab6 AO |
4316 | mvmvif->csa_countdown = false; |
4317 | ||
003e5236 AO |
4318 | /* Set CS bit on all the stations */ |
4319 | iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true); | |
4320 | ||
4321 | /* Save blocked iface, the timeout is set on the next beacon */ | |
4322 | rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif); | |
4323 | ||
bd3398e2 | 4324 | mvmvif->ap_ibss_active = false; |
f0c97783 LC |
4325 | break; |
4326 | case NL80211_IFTYPE_STATION: | |
4327 | if (!switching_chanctx) | |
4328 | break; | |
4329 | ||
4330 | disabled_vif = vif; | |
4331 | ||
74a10252 SS |
4332 | if (!fw_has_capa(&mvm->fw->ucode_capa, |
4333 | IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) | |
4334 | iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL); | |
f0c97783 | 4335 | break; |
8ca151b5 JB |
4336 | default: |
4337 | break; | |
4338 | } | |
4339 | ||
7754ae79 | 4340 | iwl_mvm_update_quotas(mvm, false, disabled_vif); |
1e1391ca | 4341 | iwl_mvm_binding_remove_vif(mvm, vif); |
1c2abf72 | 4342 | |
b08c1d97 | 4343 | out: |
a11e144e | 4344 | mvmvif->phy_ctxt = NULL; |
999609f1 | 4345 | iwl_mvm_power_update_mac(mvm); |
b08c1d97 LC |
4346 | } |
4347 | ||
4348 | static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, | |
4349 | struct ieee80211_vif *vif, | |
4350 | struct ieee80211_chanctx_conf *ctx) | |
4351 | { | |
4352 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4353 | ||
4354 | mutex_lock(&mvm->mutex); | |
f0c97783 | 4355 | __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false); |
8ca151b5 JB |
4356 | mutex_unlock(&mvm->mutex); |
4357 | } | |
4358 | ||
50cc9574 LC |
4359 | static int |
4360 | iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm, | |
4361 | struct ieee80211_vif_chanctx_switch *vifs) | |
b08c1d97 | 4362 | { |
b08c1d97 LC |
4363 | int ret; |
4364 | ||
b08c1d97 | 4365 | mutex_lock(&mvm->mutex); |
f0c97783 | 4366 | __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); |
b08c1d97 LC |
4367 | __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx); |
4368 | ||
4369 | ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx); | |
4370 | if (ret) { | |
4371 | IWL_ERR(mvm, "failed to add new_ctx during channel switch\n"); | |
4372 | goto out_reassign; | |
4373 | } | |
4374 | ||
f0c97783 LC |
4375 | ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, |
4376 | true); | |
b08c1d97 LC |
4377 | if (ret) { |
4378 | IWL_ERR(mvm, | |
4379 | "failed to assign new_ctx during channel switch\n"); | |
4380 | goto out_remove; | |
4381 | } | |
4382 | ||
f697267f AN |
4383 | /* we don't support TDLS during DCM - can be caused by channel switch */ |
4384 | if (iwl_mvm_phy_ctx_count(mvm) > 1) | |
4385 | iwl_mvm_teardown_tdls_peers(mvm); | |
4386 | ||
b08c1d97 LC |
4387 | goto out; |
4388 | ||
4389 | out_remove: | |
4390 | __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx); | |
4391 | ||
4392 | out_reassign: | |
6fd1fb63 | 4393 | if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) { |
b08c1d97 LC |
4394 | IWL_ERR(mvm, "failed to add old_ctx back after failure.\n"); |
4395 | goto out_restart; | |
4396 | } | |
4397 | ||
6fd1fb63 LC |
4398 | if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, |
4399 | true)) { | |
b08c1d97 LC |
4400 | IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); |
4401 | goto out_restart; | |
4402 | } | |
4403 | ||
4404 | goto out; | |
4405 | ||
4406 | out_restart: | |
4407 | /* things keep failing, better restart the hw */ | |
4408 | iwl_mvm_nic_restart(mvm, false); | |
4409 | ||
4410 | out: | |
4411 | mutex_unlock(&mvm->mutex); | |
50cc9574 LC |
4412 | |
4413 | return ret; | |
4414 | } | |
4415 | ||
48a256e8 LC |
4416 | static int |
4417 | iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm, | |
4418 | struct ieee80211_vif_chanctx_switch *vifs) | |
4419 | { | |
4420 | int ret; | |
4421 | ||
4422 | mutex_lock(&mvm->mutex); | |
4423 | __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); | |
4424 | ||
4425 | ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, | |
4426 | true); | |
4427 | if (ret) { | |
4428 | IWL_ERR(mvm, | |
4429 | "failed to assign new_ctx during channel switch\n"); | |
4430 | goto out_reassign; | |
4431 | } | |
4432 | ||
4433 | goto out; | |
4434 | ||
4435 | out_reassign: | |
4436 | if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, | |
4437 | true)) { | |
4438 | IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); | |
4439 | goto out_restart; | |
4440 | } | |
4441 | ||
4442 | goto out; | |
4443 | ||
4444 | out_restart: | |
4445 | /* things keep failing, better restart the hw */ | |
4446 | iwl_mvm_nic_restart(mvm, false); | |
4447 | ||
4448 | out: | |
4449 | mutex_unlock(&mvm->mutex); | |
4450 | ||
4451 | return ret; | |
4452 | } | |
4453 | ||
50cc9574 LC |
4454 | static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw, |
4455 | struct ieee80211_vif_chanctx_switch *vifs, | |
4456 | int n_vifs, | |
4457 | enum ieee80211_chanctx_switch_mode mode) | |
4458 | { | |
4459 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4460 | int ret; | |
4461 | ||
4462 | /* we only support a single-vif right now */ | |
4463 | if (n_vifs > 1) | |
4464 | return -EOPNOTSUPP; | |
4465 | ||
4466 | switch (mode) { | |
4467 | case CHANCTX_SWMODE_SWAP_CONTEXTS: | |
4468 | ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs); | |
4469 | break; | |
4470 | case CHANCTX_SWMODE_REASSIGN_VIF: | |
48a256e8 | 4471 | ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs); |
50cc9574 LC |
4472 | break; |
4473 | default: | |
4474 | ret = -EOPNOTSUPP; | |
4475 | break; | |
4476 | } | |
4477 | ||
b08c1d97 LC |
4478 | return ret; |
4479 | } | |
4480 | ||
2f0282db JB |
4481 | static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw) |
4482 | { | |
4483 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4484 | ||
4485 | return mvm->ibss_manager; | |
4486 | } | |
4487 | ||
8ca151b5 JB |
4488 | static int iwl_mvm_set_tim(struct ieee80211_hw *hw, |
4489 | struct ieee80211_sta *sta, | |
4490 | bool set) | |
4491 | { | |
4492 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
9d8ce6af | 4493 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
4494 | |
4495 | if (!mvm_sta || !mvm_sta->vif) { | |
4496 | IWL_ERR(mvm, "Station is not associated to a vif\n"); | |
4497 | return -EINVAL; | |
4498 | } | |
4499 | ||
4500 | return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif); | |
4501 | } | |
4502 | ||
507cadf2 DS |
4503 | #ifdef CONFIG_NL80211_TESTMODE |
4504 | static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { | |
4505 | [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, | |
4506 | [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, | |
f6c6ad42 | 4507 | [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, |
507cadf2 DS |
4508 | }; |
4509 | ||
4510 | static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, | |
4511 | struct ieee80211_vif *vif, | |
4512 | void *data, int len) | |
4513 | { | |
4514 | struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; | |
4515 | int err; | |
4516 | u32 noa_duration; | |
4517 | ||
8cb08174 JB |
4518 | err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len, |
4519 | iwl_mvm_tm_policy, NULL); | |
507cadf2 DS |
4520 | if (err) |
4521 | return err; | |
4522 | ||
4523 | if (!tb[IWL_MVM_TM_ATTR_CMD]) | |
4524 | return -EINVAL; | |
4525 | ||
4526 | switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { | |
4527 | case IWL_MVM_TM_CMD_SET_NOA: | |
4528 | if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || | |
4529 | !vif->bss_conf.enable_beacon || | |
4530 | !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) | |
4531 | return -EINVAL; | |
4532 | ||
4533 | noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); | |
4534 | if (noa_duration >= vif->bss_conf.beacon_int) | |
4535 | return -EINVAL; | |
4536 | ||
4537 | mvm->noa_duration = noa_duration; | |
4538 | mvm->noa_vif = vif; | |
4539 | ||
22b21041 | 4540 | return iwl_mvm_update_quotas(mvm, true, NULL); |
f6c6ad42 JB |
4541 | case IWL_MVM_TM_CMD_SET_BEACON_FILTER: |
4542 | /* must be associated client vif - ignore authorized */ | |
4543 | if (!vif || vif->type != NL80211_IFTYPE_STATION || | |
4544 | !vif->bss_conf.assoc || !vif->bss_conf.dtim_period || | |
4545 | !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) | |
4546 | return -EINVAL; | |
4547 | ||
4548 | if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) | |
a1022927 EG |
4549 | return iwl_mvm_enable_beacon_filter(mvm, vif, 0); |
4550 | return iwl_mvm_disable_beacon_filter(mvm, vif, 0); | |
507cadf2 DS |
4551 | } |
4552 | ||
4553 | return -EOPNOTSUPP; | |
4554 | } | |
4555 | ||
4556 | static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, | |
4557 | struct ieee80211_vif *vif, | |
4558 | void *data, int len) | |
4559 | { | |
4560 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4561 | int err; | |
4562 | ||
4563 | mutex_lock(&mvm->mutex); | |
4564 | err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); | |
4565 | mutex_unlock(&mvm->mutex); | |
4566 | ||
4567 | return err; | |
4568 | } | |
4569 | #endif | |
4570 | ||
622e3f9b LC |
4571 | static void iwl_mvm_channel_switch(struct ieee80211_hw *hw, |
4572 | struct ieee80211_vif *vif, | |
4573 | struct ieee80211_channel_switch *chsw) | |
4574 | { | |
4575 | /* By implementing this operation, we prevent mac80211 from | |
4576 | * starting its own channel switch timer, so that we can call | |
4577 | * ieee80211_chswitch_done() ourselves at the right time | |
4578 | * (which is when the absence time event starts). | |
4579 | */ | |
4580 | ||
4581 | IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw), | |
4582 | "dummy channel switch op\n"); | |
4583 | } | |
4584 | ||
74a10252 SS |
4585 | static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm, |
4586 | struct ieee80211_vif *vif, | |
4587 | struct ieee80211_channel_switch *chsw) | |
4588 | { | |
4589 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
4590 | struct iwl_chan_switch_te_cmd cmd = { | |
4591 | .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, | |
4592 | mvmvif->color)), | |
4593 | .action = cpu_to_le32(FW_CTXT_ACTION_ADD), | |
4594 | .tsf = cpu_to_le32(chsw->timestamp), | |
4595 | .cs_count = chsw->count, | |
77738865 | 4596 | .cs_mode = chsw->block_tx, |
74a10252 SS |
4597 | }; |
4598 | ||
4599 | lockdep_assert_held(&mvm->mutex); | |
4600 | ||
9cfcf71c SS |
4601 | if (chsw->delay) |
4602 | cmd.cs_delayed_bcn_count = | |
4603 | DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int); | |
4604 | ||
74a10252 SS |
4605 | return iwl_mvm_send_cmd_pdu(mvm, |
4606 | WIDE_ID(MAC_CONF_GROUP, | |
4607 | CHANNEL_SWITCH_TIME_EVENT_CMD), | |
4608 | 0, sizeof(cmd), &cmd); | |
4609 | } | |
4610 | ||
f6780614 | 4611 | #define IWL_MAX_CSA_BLOCK_TX 1500 |
f028905c LC |
4612 | static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw, |
4613 | struct ieee80211_vif *vif, | |
4614 | struct ieee80211_channel_switch *chsw) | |
bd3398e2 AO |
4615 | { |
4616 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
664322fa | 4617 | struct ieee80211_vif *csa_vif; |
f6c34820 | 4618 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
dc88b4ba | 4619 | u32 apply_time; |
f028905c | 4620 | int ret; |
bd3398e2 AO |
4621 | |
4622 | mutex_lock(&mvm->mutex); | |
664322fa | 4623 | |
81d62d5a JB |
4624 | mvmvif->csa_failed = false; |
4625 | ||
6b20d774 | 4626 | IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n", |
f028905c | 4627 | chsw->chandef.center_freq1); |
6b20d774 | 4628 | |
7174beb6 JB |
4629 | iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt, |
4630 | ieee80211_vif_to_wdev(vif), | |
4631 | FW_DBG_TRIGGER_CHANNEL_SWITCH); | |
f35d9c55 | 4632 | |
6b20d774 LC |
4633 | switch (vif->type) { |
4634 | case NL80211_IFTYPE_AP: | |
4635 | csa_vif = | |
4636 | rcu_dereference_protected(mvm->csa_vif, | |
4637 | lockdep_is_held(&mvm->mutex)); | |
4638 | if (WARN_ONCE(csa_vif && csa_vif->csa_active, | |
4639 | "Another CSA is already in progress")) { | |
4640 | ret = -EBUSY; | |
4641 | goto out_unlock; | |
4642 | } | |
4643 | ||
d3a108a4 AO |
4644 | /* we still didn't unblock tx. prevent new CS meanwhile */ |
4645 | if (rcu_dereference_protected(mvm->csa_tx_blocked_vif, | |
4646 | lockdep_is_held(&mvm->mutex))) { | |
4647 | ret = -EBUSY; | |
4648 | goto out_unlock; | |
4649 | } | |
4650 | ||
6b20d774 | 4651 | rcu_assign_pointer(mvm->csa_vif, vif); |
7ef0aab6 | 4652 | |
7ef0aab6 AO |
4653 | if (WARN_ONCE(mvmvif->csa_countdown, |
4654 | "Previous CSA countdown didn't complete")) { | |
4655 | ret = -EBUSY; | |
4656 | goto out_unlock; | |
4657 | } | |
4658 | ||
d3a108a4 AO |
4659 | mvmvif->csa_target_freq = chsw->chandef.chan->center_freq; |
4660 | ||
6b20d774 | 4661 | break; |
dc88b4ba | 4662 | case NL80211_IFTYPE_STATION: |
4500e133 LC |
4663 | /* Schedule the time event to a bit before beacon 1, |
4664 | * to make sure we're in the new channel when the | |
f5d8f50f IP |
4665 | * GO/AP arrives. In case count <= 1 immediately schedule the |
4666 | * TE (this might result with some packet loss or connection | |
4667 | * loss). | |
4500e133 | 4668 | */ |
f5d8f50f IP |
4669 | if (chsw->count <= 1) |
4670 | apply_time = 0; | |
4671 | else | |
4672 | apply_time = chsw->device_timestamp + | |
4673 | ((vif->bss_conf.beacon_int * (chsw->count - 1) - | |
4674 | IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024); | |
dc88b4ba | 4675 | |
f6780614 | 4676 | if (chsw->block_tx) { |
dc88b4ba | 4677 | iwl_mvm_csa_client_absent(mvm, vif); |
f6780614 SS |
4678 | /* |
4679 | * In case of undetermined / long time with immediate | |
4680 | * quiet monitor status to gracefully disconnect | |
4681 | */ | |
4682 | if (!chsw->count || | |
4683 | chsw->count * vif->bss_conf.beacon_int > | |
4684 | IWL_MAX_CSA_BLOCK_TX) | |
4685 | schedule_delayed_work(&mvmvif->csa_work, | |
4686 | msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX)); | |
4687 | } | |
dc88b4ba | 4688 | |
c6e0a3e0 LC |
4689 | if (mvmvif->bf_data.bf_enabled) { |
4690 | ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); | |
4691 | if (ret) | |
4692 | goto out_unlock; | |
4693 | } | |
4694 | ||
74a10252 SS |
4695 | if (fw_has_capa(&mvm->fw->ucode_capa, |
4696 | IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) | |
4697 | iwl_mvm_schedule_client_csa(mvm, vif, chsw); | |
4698 | else | |
4699 | iwl_mvm_schedule_csa_period(mvm, vif, | |
4700 | vif->bss_conf.beacon_int, | |
4701 | apply_time); | |
81b4e44e SS |
4702 | |
4703 | mvmvif->csa_count = chsw->count; | |
4704 | mvmvif->csa_misbehave = false; | |
dc88b4ba | 4705 | break; |
6b20d774 LC |
4706 | default: |
4707 | break; | |
4708 | } | |
bd3398e2 | 4709 | |
f6c34820 LC |
4710 | mvmvif->ps_disabled = true; |
4711 | ||
4712 | ret = iwl_mvm_power_update_ps(mvm); | |
4713 | if (ret) | |
4714 | goto out_unlock; | |
f028905c | 4715 | |
e198f5e7 AN |
4716 | /* we won't be on this channel any longer */ |
4717 | iwl_mvm_teardown_tdls_peers(mvm); | |
4718 | ||
bd3398e2 AO |
4719 | out_unlock: |
4720 | mutex_unlock(&mvm->mutex); | |
f028905c LC |
4721 | |
4722 | return ret; | |
bd3398e2 AO |
4723 | } |
4724 | ||
c37763d2 SS |
4725 | static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw, |
4726 | struct ieee80211_vif *vif, | |
4727 | struct ieee80211_channel_switch *chsw) | |
f6c34820 | 4728 | { |
f6c34820 | 4729 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
c37763d2 SS |
4730 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
4731 | struct iwl_chan_switch_te_cmd cmd = { | |
4732 | .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, | |
4733 | mvmvif->color)), | |
4734 | .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY), | |
4735 | .tsf = cpu_to_le32(chsw->timestamp), | |
4736 | .cs_count = chsw->count, | |
77738865 | 4737 | .cs_mode = chsw->block_tx, |
c37763d2 | 4738 | }; |
a57c688d | 4739 | |
c37763d2 SS |
4740 | if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY)) |
4741 | return; | |
a57c688d | 4742 | |
81b4e44e SS |
4743 | if (chsw->count >= mvmvif->csa_count && chsw->block_tx) { |
4744 | if (mvmvif->csa_misbehave) { | |
4745 | /* Second time, give up on this AP*/ | |
4746 | iwl_mvm_abort_channel_switch(hw, vif); | |
4747 | ieee80211_chswitch_done(vif, false); | |
4748 | mvmvif->csa_misbehave = false; | |
4749 | return; | |
a57c688d | 4750 | } |
81b4e44e | 4751 | mvmvif->csa_misbehave = true; |
a57c688d | 4752 | } |
81b4e44e | 4753 | mvmvif->csa_count = chsw->count; |
a57c688d | 4754 | |
c37763d2 | 4755 | IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d\n", mvmvif->id); |
f6c34820 | 4756 | |
c37763d2 SS |
4757 | WARN_ON(iwl_mvm_send_cmd_pdu(mvm, |
4758 | WIDE_ID(MAC_CONF_GROUP, | |
4759 | CHANNEL_SWITCH_TIME_EVENT_CMD), | |
4760 | CMD_ASYNC, sizeof(cmd), &cmd)); | |
f6c34820 LC |
4761 | } |
4762 | ||
6110d9e5 DS |
4763 | static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop) |
4764 | { | |
435d0827 SS |
4765 | int i; |
4766 | ||
06195639 | 4767 | if (!iwl_mvm_has_new_tx_api(mvm)) { |
309c4848 LC |
4768 | if (drop) { |
4769 | mutex_lock(&mvm->mutex); | |
6110d9e5 | 4770 | iwl_mvm_flush_tx_path(mvm, |
435d0827 | 4771 | iwl_mvm_flushable_queues(mvm) & queues, 0); |
309c4848 LC |
4772 | mutex_unlock(&mvm->mutex); |
4773 | } else { | |
06195639 | 4774 | iwl_trans_wait_tx_queues_empty(mvm->trans, queues); |
309c4848 | 4775 | } |
435d0827 SS |
4776 | return; |
4777 | } | |
6110d9e5 | 4778 | |
435d0827 SS |
4779 | mutex_lock(&mvm->mutex); |
4780 | for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) { | |
4781 | struct ieee80211_sta *sta; | |
6110d9e5 | 4782 | |
435d0827 SS |
4783 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
4784 | lockdep_is_held(&mvm->mutex)); | |
4785 | if (IS_ERR_OR_NULL(sta)) | |
4786 | continue; | |
6110d9e5 | 4787 | |
06195639 SS |
4788 | if (drop) |
4789 | iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0); | |
4790 | else | |
4791 | iwl_mvm_wait_sta_queues_empty(mvm, | |
4792 | iwl_mvm_sta_from_mac80211(sta)); | |
6110d9e5 | 4793 | } |
435d0827 | 4794 | mutex_unlock(&mvm->mutex); |
6110d9e5 DS |
4795 | } |
4796 | ||
c5b0e7c0 EG |
4797 | static void iwl_mvm_mac_flush(struct ieee80211_hw *hw, |
4798 | struct ieee80211_vif *vif, u32 queues, bool drop) | |
4799 | { | |
4800 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4801 | struct iwl_mvm_vif *mvmvif; | |
4802 | struct iwl_mvm_sta *mvmsta; | |
a0f6bf2a AN |
4803 | struct ieee80211_sta *sta; |
4804 | int i; | |
4805 | u32 msk = 0; | |
c5b0e7c0 | 4806 | |
6110d9e5 DS |
4807 | if (!vif) { |
4808 | iwl_mvm_flush_no_vif(mvm, queues, drop); | |
4809 | return; | |
4810 | } | |
4811 | ||
4812 | if (vif->type != NL80211_IFTYPE_STATION) | |
c5b0e7c0 EG |
4813 | return; |
4814 | ||
24afba76 | 4815 | /* Make sure we're done with the deferred traffic before flushing */ |
c8f54701 | 4816 | flush_work(&mvm->add_stream_wk); |
24afba76 | 4817 | |
c5b0e7c0 EG |
4818 | mutex_lock(&mvm->mutex); |
4819 | mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
c5b0e7c0 | 4820 | |
a0f6bf2a | 4821 | /* flush the AP-station and all TDLS peers */ |
0ae98812 | 4822 | for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) { |
a0f6bf2a AN |
4823 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
4824 | lockdep_is_held(&mvm->mutex)); | |
4825 | if (IS_ERR_OR_NULL(sta)) | |
4826 | continue; | |
4827 | ||
4828 | mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
4829 | if (mvmsta->vif != vif) | |
4830 | continue; | |
4831 | ||
4832 | /* make sure only TDLS peers or the AP are flushed */ | |
4833 | WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls); | |
4834 | ||
d49394a1 SS |
4835 | if (drop) { |
4836 | if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0)) | |
4837 | IWL_ERR(mvm, "flush request fail\n"); | |
4838 | } else { | |
4839 | msk |= mvmsta->tfd_queue_msk; | |
d6d517b7 SS |
4840 | if (iwl_mvm_has_new_tx_api(mvm)) |
4841 | iwl_mvm_wait_sta_queues_empty(mvm, mvmsta); | |
d49394a1 | 4842 | } |
480acbce | 4843 | } |
c5b0e7c0 | 4844 | |
d49394a1 | 4845 | mutex_unlock(&mvm->mutex); |
4e6c48e0 | 4846 | |
d49394a1 SS |
4847 | /* this can take a while, and we may need/want other operations |
4848 | * to succeed while doing this, so do it without the mutex held | |
4849 | */ | |
d6d517b7 | 4850 | if (!drop && !iwl_mvm_has_new_tx_api(mvm)) |
a1a57877 | 4851 | iwl_trans_wait_tx_queues_empty(mvm->trans, msk); |
c5b0e7c0 EG |
4852 | } |
4853 | ||
91a8bcde JB |
4854 | static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx, |
4855 | struct survey_info *survey) | |
4856 | { | |
4857 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4858 | int ret; | |
4859 | ||
4860 | memset(survey, 0, sizeof(*survey)); | |
4861 | ||
4862 | /* only support global statistics right now */ | |
4863 | if (idx != 0) | |
4864 | return -ENOENT; | |
4865 | ||
280a3efa JB |
4866 | if (!fw_has_capa(&mvm->fw->ucode_capa, |
4867 | IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) | |
91a8bcde JB |
4868 | return -ENOENT; |
4869 | ||
4870 | mutex_lock(&mvm->mutex); | |
4871 | ||
aab6930d | 4872 | if (iwl_mvm_firmware_running(mvm)) { |
33cef925 | 4873 | ret = iwl_mvm_request_statistics(mvm, false); |
91a8bcde JB |
4874 | if (ret) |
4875 | goto out; | |
4876 | } | |
4877 | ||
4878 | survey->filled = SURVEY_INFO_TIME | | |
4879 | SURVEY_INFO_TIME_RX | | |
4880 | SURVEY_INFO_TIME_TX | | |
4881 | SURVEY_INFO_TIME_SCAN; | |
4882 | survey->time = mvm->accu_radio_stats.on_time_rf + | |
4883 | mvm->radio_stats.on_time_rf; | |
4884 | do_div(survey->time, USEC_PER_MSEC); | |
4885 | ||
4886 | survey->time_rx = mvm->accu_radio_stats.rx_time + | |
4887 | mvm->radio_stats.rx_time; | |
4888 | do_div(survey->time_rx, USEC_PER_MSEC); | |
4889 | ||
4890 | survey->time_tx = mvm->accu_radio_stats.tx_time + | |
4891 | mvm->radio_stats.tx_time; | |
4892 | do_div(survey->time_tx, USEC_PER_MSEC); | |
4893 | ||
4894 | survey->time_scan = mvm->accu_radio_stats.on_time_scan + | |
4895 | mvm->radio_stats.on_time_scan; | |
4896 | do_div(survey->time_scan, USEC_PER_MSEC); | |
4897 | ||
10a7c028 | 4898 | ret = 0; |
91a8bcde JB |
4899 | out: |
4900 | mutex_unlock(&mvm->mutex); | |
4901 | return ret; | |
4902 | } | |
4903 | ||
33cef925 JB |
4904 | static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw, |
4905 | struct ieee80211_vif *vif, | |
4906 | struct ieee80211_sta *sta, | |
4907 | struct station_info *sinfo) | |
4908 | { | |
4909 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4910 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
4911 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
4912 | ||
988b5968 SS |
4913 | if (mvmsta->avg_energy) { |
4914 | sinfo->signal_avg = mvmsta->avg_energy; | |
22d0d2fa | 4915 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG); |
988b5968 SS |
4916 | } |
4917 | ||
33cef925 JB |
4918 | /* if beacon filtering isn't on mac80211 does it anyway */ |
4919 | if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)) | |
4920 | return; | |
4921 | ||
4922 | if (!vif->bss_conf.assoc) | |
4923 | return; | |
4924 | ||
4925 | mutex_lock(&mvm->mutex); | |
4926 | ||
4927 | if (mvmvif->ap_sta_id != mvmsta->sta_id) | |
4928 | goto unlock; | |
4929 | ||
4930 | if (iwl_mvm_request_statistics(mvm, false)) | |
4931 | goto unlock; | |
4932 | ||
4933 | sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons + | |
4934 | mvmvif->beacon_stats.accu_num_beacons; | |
22d0d2fa | 4935 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX); |
33cef925 JB |
4936 | if (mvmvif->beacon_stats.avg_signal) { |
4937 | /* firmware only reports a value after RXing a few beacons */ | |
4938 | sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal; | |
22d0d2fa | 4939 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG); |
33cef925 JB |
4940 | } |
4941 | unlock: | |
4942 | mutex_unlock(&mvm->mutex); | |
4943 | } | |
4944 | ||
4203263d EG |
4945 | static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm, |
4946 | struct ieee80211_vif *vif, | |
4947 | const struct ieee80211_event *event) | |
d42f5350 | 4948 | { |
7174beb6 JB |
4949 | #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \ |
4950 | do { \ | |
4951 | if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \ | |
4952 | break; \ | |
4953 | iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \ | |
d42f5350 EG |
4954 | } while (0) |
4955 | ||
d42f5350 EG |
4956 | struct iwl_fw_dbg_trigger_tlv *trig; |
4957 | struct iwl_fw_dbg_trigger_mlme *trig_mlme; | |
d42f5350 | 4958 | |
6c042d75 SS |
4959 | trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), |
4960 | FW_DBG_TRIGGER_MLME); | |
4961 | if (!trig) | |
d42f5350 EG |
4962 | return; |
4963 | ||
d42f5350 | 4964 | trig_mlme = (void *)trig->data; |
d42f5350 | 4965 | |
d42f5350 EG |
4966 | if (event->u.mlme.data == ASSOC_EVENT) { |
4967 | if (event->u.mlme.status == MLME_DENIED) | |
4c324a51 | 4968 | CHECK_MLME_TRIGGER(stop_assoc_denied, |
d42f5350 EG |
4969 | "DENIED ASSOC: reason %d", |
4970 | event->u.mlme.reason); | |
4971 | else if (event->u.mlme.status == MLME_TIMEOUT) | |
4c324a51 | 4972 | CHECK_MLME_TRIGGER(stop_assoc_timeout, |
d42f5350 EG |
4973 | "ASSOC TIMEOUT"); |
4974 | } else if (event->u.mlme.data == AUTH_EVENT) { | |
4975 | if (event->u.mlme.status == MLME_DENIED) | |
4c324a51 | 4976 | CHECK_MLME_TRIGGER(stop_auth_denied, |
d42f5350 EG |
4977 | "DENIED AUTH: reason %d", |
4978 | event->u.mlme.reason); | |
4979 | else if (event->u.mlme.status == MLME_TIMEOUT) | |
4c324a51 | 4980 | CHECK_MLME_TRIGGER(stop_auth_timeout, |
d42f5350 EG |
4981 | "AUTH TIMEOUT"); |
4982 | } else if (event->u.mlme.data == DEAUTH_RX_EVENT) { | |
4c324a51 | 4983 | CHECK_MLME_TRIGGER(stop_rx_deauth, |
d42f5350 EG |
4984 | "DEAUTH RX %d", event->u.mlme.reason); |
4985 | } else if (event->u.mlme.data == DEAUTH_TX_EVENT) { | |
4c324a51 | 4986 | CHECK_MLME_TRIGGER(stop_tx_deauth, |
d42f5350 EG |
4987 | "DEAUTH TX %d", event->u.mlme.reason); |
4988 | } | |
4989 | #undef CHECK_MLME_TRIGGER | |
4990 | } | |
4991 | ||
4203263d EG |
4992 | static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm, |
4993 | struct ieee80211_vif *vif, | |
4994 | const struct ieee80211_event *event) | |
4995 | { | |
4996 | struct iwl_fw_dbg_trigger_tlv *trig; | |
4997 | struct iwl_fw_dbg_trigger_ba *ba_trig; | |
4998 | ||
6c042d75 SS |
4999 | trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), |
5000 | FW_DBG_TRIGGER_BA); | |
5001 | if (!trig) | |
4203263d EG |
5002 | return; |
5003 | ||
4203263d | 5004 | ba_trig = (void *)trig->data; |
4203263d EG |
5005 | |
5006 | if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid))) | |
5007 | return; | |
5008 | ||
7174beb6 JB |
5009 | iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, |
5010 | "BAR received from %pM, tid %d, ssn %d", | |
5011 | event->u.ba.sta->addr, event->u.ba.tid, | |
5012 | event->u.ba.ssn); | |
4203263d EG |
5013 | } |
5014 | ||
4203263d EG |
5015 | static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw, |
5016 | struct ieee80211_vif *vif, | |
5017 | const struct ieee80211_event *event) | |
5018 | { | |
5019 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5020 | ||
5021 | switch (event->type) { | |
5022 | case MLME_EVENT: | |
5023 | iwl_mvm_event_mlme_callback(mvm, vif, event); | |
5024 | break; | |
5025 | case BAR_RX_EVENT: | |
5026 | iwl_mvm_event_bar_rx_callback(mvm, vif, event); | |
5027 | break; | |
5028 | case BA_FRAME_TIMEOUT: | |
528a542a EG |
5029 | iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta, |
5030 | event->u.ba.tid); | |
4203263d EG |
5031 | break; |
5032 | default: | |
5033 | break; | |
5034 | } | |
5035 | } | |
5036 | ||
d0ff5d22 SS |
5037 | void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm, |
5038 | struct iwl_mvm_internal_rxq_notif *notif, | |
5039 | u32 size) | |
0636b938 | 5040 | { |
0636b938 SS |
5041 | u32 qmask = BIT(mvm->trans->num_rx_queues) - 1; |
5042 | int ret; | |
5043 | ||
5044 | lockdep_assert_held(&mvm->mutex); | |
5045 | ||
cb8550e1 | 5046 | if (!iwl_mvm_has_new_rx_api(mvm)) |
0636b938 SS |
5047 | return; |
5048 | ||
d0ff5d22 SS |
5049 | notif->cookie = mvm->queue_sync_cookie; |
5050 | ||
5051 | if (notif->sync) | |
5052 | atomic_set(&mvm->queue_sync_counter, | |
5053 | mvm->trans->num_rx_queues); | |
0636b938 | 5054 | |
d0ff5d22 | 5055 | ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size); |
0636b938 SS |
5056 | if (ret) { |
5057 | IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret); | |
5058 | goto out; | |
5059 | } | |
d0ff5d22 | 5060 | |
6ad04359 | 5061 | if (notif->sync) { |
3a732c65 | 5062 | ret = wait_event_timeout(mvm->rx_sync_waitq, |
6ad04359 JB |
5063 | atomic_read(&mvm->queue_sync_counter) == 0 || |
5064 | iwl_mvm_is_radio_killed(mvm), | |
d0ff5d22 | 5065 | HZ); |
6ad04359 JB |
5066 | WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm)); |
5067 | } | |
0636b938 SS |
5068 | |
5069 | out: | |
5070 | atomic_set(&mvm->queue_sync_counter, 0); | |
5071 | mvm->queue_sync_cookie++; | |
5072 | } | |
5073 | ||
5074 | static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw) | |
5075 | { | |
5076 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
d0ff5d22 SS |
5077 | struct iwl_mvm_internal_rxq_notif data = { |
5078 | .type = IWL_MVM_RXQ_EMPTY, | |
5079 | .sync = 1, | |
5080 | }; | |
0636b938 SS |
5081 | |
5082 | mutex_lock(&mvm->mutex); | |
d0ff5d22 | 5083 | iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data)); |
0636b938 SS |
5084 | mutex_unlock(&mvm->mutex); |
5085 | } | |
5086 | ||
b73f9a4a JB |
5087 | static int |
5088 | iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw, | |
5089 | struct ieee80211_vif *vif, | |
5090 | struct cfg80211_ftm_responder_stats *stats) | |
5091 | { | |
5092 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5093 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
5094 | ||
5095 | if (vif->p2p || vif->type != NL80211_IFTYPE_AP || | |
5096 | !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder) | |
5097 | return -EINVAL; | |
5098 | ||
5099 | mutex_lock(&mvm->mutex); | |
5100 | *stats = mvm->ftm_resp_stats; | |
5101 | mutex_unlock(&mvm->mutex); | |
5102 | ||
5103 | stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) | | |
5104 | BIT(NL80211_FTM_STATS_PARTIAL_NUM) | | |
5105 | BIT(NL80211_FTM_STATS_FAILED_NUM) | | |
5106 | BIT(NL80211_FTM_STATS_ASAP_NUM) | | |
5107 | BIT(NL80211_FTM_STATS_NON_ASAP_NUM) | | |
5108 | BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) | | |
5109 | BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) | | |
5110 | BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) | | |
5111 | BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM); | |
5112 | ||
5113 | return 0; | |
5114 | } | |
5115 | ||
fc36ffda JB |
5116 | static int iwl_mvm_start_pmsr(struct ieee80211_hw *hw, |
5117 | struct ieee80211_vif *vif, | |
5118 | struct cfg80211_pmsr_request *request) | |
5119 | { | |
5120 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5121 | int ret; | |
5122 | ||
5123 | mutex_lock(&mvm->mutex); | |
5124 | ret = iwl_mvm_ftm_start(mvm, vif, request); | |
5125 | mutex_unlock(&mvm->mutex); | |
5126 | ||
5127 | return ret; | |
5128 | } | |
5129 | ||
5130 | static void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw, | |
5131 | struct ieee80211_vif *vif, | |
5132 | struct cfg80211_pmsr_request *request) | |
5133 | { | |
5134 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5135 | ||
5136 | mutex_lock(&mvm->mutex); | |
5137 | iwl_mvm_ftm_abort(mvm, request); | |
5138 | mutex_unlock(&mvm->mutex); | |
5139 | } | |
5140 | ||
438af969 SS |
5141 | static bool iwl_mvm_can_hw_csum(struct sk_buff *skb) |
5142 | { | |
5143 | u8 protocol = ip_hdr(skb)->protocol; | |
5144 | ||
5145 | if (!IS_ENABLED(CONFIG_INET)) | |
5146 | return false; | |
5147 | ||
5148 | return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP; | |
5149 | } | |
5150 | ||
5151 | static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw, | |
5152 | struct sk_buff *head, | |
5153 | struct sk_buff *skb) | |
5154 | { | |
5155 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5156 | ||
5157 | /* For now don't aggregate IPv6 in AMSDU */ | |
5158 | if (skb->protocol != htons(ETH_P_IP)) | |
5159 | return false; | |
5160 | ||
5161 | if (!iwl_mvm_is_csum_supported(mvm)) | |
5162 | return true; | |
5163 | ||
5164 | return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head); | |
5165 | } | |
5166 | ||
e5209263 | 5167 | const struct ieee80211_ops iwl_mvm_hw_ops = { |
8ca151b5 | 5168 | .tx = iwl_mvm_mac_tx, |
cfbc6c4c | 5169 | .wake_tx_queue = iwl_mvm_mac_wake_tx_queue, |
8ca151b5 JB |
5170 | .ampdu_action = iwl_mvm_mac_ampdu_action, |
5171 | .start = iwl_mvm_mac_start, | |
cf2c92d8 | 5172 | .reconfig_complete = iwl_mvm_mac_reconfig_complete, |
8ca151b5 JB |
5173 | .stop = iwl_mvm_mac_stop, |
5174 | .add_interface = iwl_mvm_mac_add_interface, | |
5175 | .remove_interface = iwl_mvm_mac_remove_interface, | |
5176 | .config = iwl_mvm_mac_config, | |
e59647ea | 5177 | .prepare_multicast = iwl_mvm_prepare_multicast, |
8ca151b5 | 5178 | .configure_filter = iwl_mvm_configure_filter, |
effd1929 | 5179 | .config_iface_filter = iwl_mvm_config_iface_filter, |
8ca151b5 JB |
5180 | .bss_info_changed = iwl_mvm_bss_info_changed, |
5181 | .hw_scan = iwl_mvm_mac_hw_scan, | |
5182 | .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, | |
1ddbbb0c | 5183 | .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, |
8ca151b5 JB |
5184 | .sta_state = iwl_mvm_mac_sta_state, |
5185 | .sta_notify = iwl_mvm_mac_sta_notify, | |
5186 | .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, | |
3e56eadf | 5187 | .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, |
8ca151b5 | 5188 | .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, |
1f3b0ff8 | 5189 | .sta_rc_update = iwl_mvm_sta_rc_update, |
8ca151b5 JB |
5190 | .conf_tx = iwl_mvm_mac_conf_tx, |
5191 | .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, | |
07ecd897 | 5192 | .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover, |
c5b0e7c0 | 5193 | .flush = iwl_mvm_mac_flush, |
35a000b7 DS |
5194 | .sched_scan_start = iwl_mvm_mac_sched_scan_start, |
5195 | .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, | |
8ca151b5 JB |
5196 | .set_key = iwl_mvm_mac_set_key, |
5197 | .update_tkip_key = iwl_mvm_mac_update_tkip_key, | |
5198 | .remain_on_channel = iwl_mvm_roc, | |
5199 | .cancel_remain_on_channel = iwl_mvm_cancel_roc, | |
8ca151b5 JB |
5200 | .add_chanctx = iwl_mvm_add_chanctx, |
5201 | .remove_chanctx = iwl_mvm_remove_chanctx, | |
5202 | .change_chanctx = iwl_mvm_change_chanctx, | |
5203 | .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, | |
5204 | .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, | |
b08c1d97 | 5205 | .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx, |
8ca151b5 | 5206 | |
5023d966 JB |
5207 | .start_ap = iwl_mvm_start_ap_ibss, |
5208 | .stop_ap = iwl_mvm_stop_ap_ibss, | |
5209 | .join_ibss = iwl_mvm_start_ap_ibss, | |
5210 | .leave_ibss = iwl_mvm_stop_ap_ibss, | |
8ca151b5 | 5211 | |
2f0282db JB |
5212 | .tx_last_beacon = iwl_mvm_tx_last_beacon, |
5213 | ||
8ca151b5 JB |
5214 | .set_tim = iwl_mvm_set_tim, |
5215 | ||
622e3f9b | 5216 | .channel_switch = iwl_mvm_channel_switch, |
f028905c | 5217 | .pre_channel_switch = iwl_mvm_pre_channel_switch, |
f6c34820 | 5218 | .post_channel_switch = iwl_mvm_post_channel_switch, |
79221126 | 5219 | .abort_channel_switch = iwl_mvm_abort_channel_switch, |
c37763d2 | 5220 | .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon, |
bd3398e2 | 5221 | |
1d3c3f63 AN |
5222 | .tdls_channel_switch = iwl_mvm_tdls_channel_switch, |
5223 | .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch, | |
5224 | .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch, | |
5225 | ||
d42f5350 EG |
5226 | .event_callback = iwl_mvm_mac_event_callback, |
5227 | ||
0636b938 SS |
5228 | .sync_rx_queues = iwl_mvm_sync_rx_queues, |
5229 | ||
507cadf2 DS |
5230 | CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) |
5231 | ||
8ca151b5 JB |
5232 | #ifdef CONFIG_PM_SLEEP |
5233 | /* look at d3.c */ | |
5234 | .suspend = iwl_mvm_suspend, | |
5235 | .resume = iwl_mvm_resume, | |
5236 | .set_wakeup = iwl_mvm_set_wakeup, | |
5237 | .set_rekey_data = iwl_mvm_set_rekey_data, | |
5238 | #if IS_ENABLED(CONFIG_IPV6) | |
5239 | .ipv6_addr_change = iwl_mvm_ipv6_addr_change, | |
5240 | #endif | |
5241 | .set_default_unicast_key = iwl_mvm_set_default_unicast_key, | |
5242 | #endif | |
91a8bcde | 5243 | .get_survey = iwl_mvm_mac_get_survey, |
33cef925 | 5244 | .sta_statistics = iwl_mvm_mac_sta_statistics, |
b73f9a4a | 5245 | .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats, |
fc36ffda JB |
5246 | .start_pmsr = iwl_mvm_start_pmsr, |
5247 | .abort_pmsr = iwl_mvm_abort_pmsr, | |
b73f9a4a | 5248 | |
438af969 | 5249 | .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate, |
177a11cf GG |
5250 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
5251 | .sta_add_debugfs = iwl_mvm_sta_add_debugfs, | |
5252 | #endif | |
8ca151b5 | 5253 | }; |