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