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