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