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