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