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