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