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