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