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