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