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