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