]>
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 | * | |
8 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. | |
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 | * | |
33 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. | |
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> |
8ca151b5 | 69 | #include <net/mac80211.h> |
f0c2646a | 70 | #include <net/tcp.h> |
8ca151b5 JB |
71 | |
72 | #include "iwl-op-mode.h" | |
73 | #include "iwl-io.h" | |
74 | #include "mvm.h" | |
75 | #include "sta.h" | |
76 | #include "time-event.h" | |
77 | #include "iwl-eeprom-parse.h" | |
78 | #include "fw-api-scan.h" | |
79 | #include "iwl-phy-db.h" | |
507cadf2 | 80 | #include "testmode.h" |
8ca151b5 JB |
81 | |
82 | static const struct ieee80211_iface_limit iwl_mvm_limits[] = { | |
83 | { | |
84 | .max = 1, | |
8eb38710 | 85 | .types = BIT(NL80211_IFTYPE_STATION), |
8ca151b5 | 86 | }, |
3c15a0fb JB |
87 | { |
88 | .max = 1, | |
8eb38710 IP |
89 | .types = BIT(NL80211_IFTYPE_AP) | |
90 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | |
3c15a0fb JB |
91 | BIT(NL80211_IFTYPE_P2P_GO), |
92 | }, | |
93 | { | |
94 | .max = 1, | |
95 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE), | |
96 | }, | |
8ca151b5 JB |
97 | }; |
98 | ||
99 | static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = { | |
100 | { | |
101 | .num_different_channels = 1, | |
102 | .max_interfaces = 3, | |
103 | .limits = iwl_mvm_limits, | |
104 | .n_limits = ARRAY_SIZE(iwl_mvm_limits), | |
105 | }, | |
106 | }; | |
107 | ||
f0c2646a JB |
108 | #ifdef CONFIG_PM_SLEEP |
109 | static const struct nl80211_wowlan_tcp_data_token_feature | |
110 | iwl_mvm_wowlan_tcp_token_feature = { | |
111 | .min_len = 0, | |
112 | .max_len = 255, | |
113 | .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS, | |
114 | }; | |
115 | ||
116 | static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = { | |
117 | .tok = &iwl_mvm_wowlan_tcp_token_feature, | |
118 | .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN - | |
119 | sizeof(struct ethhdr) - | |
120 | sizeof(struct iphdr) - | |
121 | sizeof(struct tcphdr), | |
122 | .data_interval_max = 65535, /* __le16 in API */ | |
123 | .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN - | |
124 | sizeof(struct ethhdr) - | |
125 | sizeof(struct iphdr) - | |
126 | sizeof(struct tcphdr), | |
127 | .seq = true, | |
128 | }; | |
129 | #endif | |
130 | ||
fe0f2de3 IP |
131 | static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm) |
132 | { | |
133 | int i; | |
134 | ||
135 | memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts)); | |
136 | for (i = 0; i < NUM_PHY_CTX; i++) { | |
137 | mvm->phy_ctxts[i].id = i; | |
138 | mvm->phy_ctxts[i].ref = 0; | |
139 | } | |
140 | } | |
141 | ||
20f1a5de DS |
142 | static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm) |
143 | { | |
144 | /* we create the 802.11 header and SSID element */ | |
145 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID) | |
146 | return mvm->fw->ucode_capa.max_probe_length - 24 - 2; | |
147 | return mvm->fw->ucode_capa.max_probe_length - 24 - 34; | |
148 | } | |
149 | ||
8ca151b5 JB |
150 | int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm) |
151 | { | |
152 | struct ieee80211_hw *hw = mvm->hw; | |
831e85f3 | 153 | int num_mac, ret, i; |
8ca151b5 JB |
154 | |
155 | /* Tell mac80211 our characteristics */ | |
156 | hw->flags = IEEE80211_HW_SIGNAL_DBM | | |
157 | IEEE80211_HW_SPECTRUM_MGMT | | |
158 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | | |
159 | IEEE80211_HW_QUEUE_CONTROL | | |
160 | IEEE80211_HW_WANT_MONITOR_VIF | | |
8ca151b5 JB |
161 | IEEE80211_HW_SUPPORTS_PS | |
162 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | | |
d2931bbd | 163 | IEEE80211_HW_AMPDU_AGGREGATION | |
d64048ed | 164 | IEEE80211_HW_TIMING_BEACON_ONLY | |
147fc9be EG |
165 | IEEE80211_HW_CONNECTION_MONITOR | |
166 | IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS | | |
e8e626ad | 167 | IEEE80211_HW_SUPPORTS_STATIC_SMPS; |
8ca151b5 | 168 | |
19e737c9 | 169 | hw->queues = mvm->first_agg_queue; |
398e8c6c | 170 | hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE; |
8ca151b5 JB |
171 | hw->rate_control_algorithm = "iwl-mvm-rs"; |
172 | ||
173 | /* | |
174 | * Enable 11w if advertised by firmware and software crypto | |
175 | * is not enabled (as the firmware will interpret some mgmt | |
176 | * packets, so enabling it with software crypto isn't safe) | |
177 | */ | |
178 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP && | |
179 | !iwlwifi_mod_params.sw_crypto) | |
180 | hw->flags |= IEEE80211_HW_MFP_CAPABLE; | |
181 | ||
e8e626ad AB |
182 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT) { |
183 | hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD; | |
184 | hw->uapsd_queues = IWL_UAPSD_AC_INFO; | |
185 | hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP; | |
186 | } | |
187 | ||
8ca151b5 JB |
188 | hw->sta_data_size = sizeof(struct iwl_mvm_sta); |
189 | hw->vif_data_size = sizeof(struct iwl_mvm_vif); | |
fe0f2de3 | 190 | hw->chanctx_data_size = sizeof(u16); |
8ca151b5 JB |
191 | |
192 | hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | |
3c15a0fb JB |
193 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
194 | BIT(NL80211_IFTYPE_AP) | | |
195 | BIT(NL80211_IFTYPE_P2P_GO) | | |
196 | BIT(NL80211_IFTYPE_P2P_DEVICE); | |
8ca151b5 | 197 | |
5023d966 JB |
198 | /* IBSS has bugs in older versions */ |
199 | if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 8) | |
200 | hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC); | |
201 | ||
a2f73b6c LR |
202 | hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
203 | hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG | | |
204 | REGULATORY_DISABLE_BEACON_HINTS; | |
8ca151b5 JB |
205 | |
206 | hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; | |
207 | hw->wiphy->n_iface_combinations = | |
208 | ARRAY_SIZE(iwl_mvm_iface_combinations); | |
209 | ||
c451e6d4 | 210 | hw->wiphy->max_remain_on_channel_duration = 10000; |
8ca151b5 JB |
211 | hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; |
212 | ||
213 | /* Extract MAC address */ | |
214 | memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); | |
215 | hw->wiphy->addresses = mvm->addresses; | |
216 | hw->wiphy->n_addresses = 1; | |
831e85f3 IP |
217 | |
218 | /* Extract additional MAC addresses if available */ | |
219 | num_mac = (mvm->nvm_data->n_hw_addrs > 1) ? | |
220 | min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1; | |
221 | ||
222 | for (i = 1; i < num_mac; i++) { | |
223 | memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr, | |
8ca151b5 | 224 | ETH_ALEN); |
831e85f3 | 225 | mvm->addresses[i].addr[5]++; |
8ca151b5 JB |
226 | hw->wiphy->n_addresses++; |
227 | } | |
228 | ||
fe0f2de3 IP |
229 | iwl_mvm_reset_phy_ctxts(mvm); |
230 | ||
20f1a5de DS |
231 | hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm); |
232 | ||
8ca151b5 JB |
233 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; |
234 | ||
235 | if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels) | |
236 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = | |
237 | &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ]; | |
238 | if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) | |
239 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = | |
240 | &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ]; | |
241 | ||
242 | hw->wiphy->hw_version = mvm->trans->hw_id; | |
243 | ||
ade50652 | 244 | if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) |
8ca151b5 JB |
245 | hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; |
246 | else | |
247 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; | |
248 | ||
35a000b7 DS |
249 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) { |
250 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; | |
251 | hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; | |
252 | hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES; | |
253 | /* we create the 802.11 header and zero length SSID IE. */ | |
254 | hw->wiphy->max_sched_scan_ie_len = | |
255 | SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2; | |
256 | } | |
257 | ||
8ca151b5 | 258 | hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | |
61f6325d HD |
259 | NL80211_FEATURE_P2P_GO_OPPPS | |
260 | NL80211_FEATURE_LOW_PRIORITY_SCAN; | |
8ca151b5 JB |
261 | |
262 | mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; | |
263 | ||
264 | #ifdef CONFIG_PM_SLEEP | |
265 | if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len && | |
266 | mvm->trans->ops->d3_suspend && | |
267 | mvm->trans->ops->d3_resume && | |
268 | device_can_wakeup(mvm->trans->dev)) { | |
964dc9e2 JB |
269 | mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT | |
270 | WIPHY_WOWLAN_DISCONNECT | | |
271 | WIPHY_WOWLAN_EAP_IDENTITY_REQ | | |
272 | WIPHY_WOWLAN_RFKILL_RELEASE; | |
8ca151b5 | 273 | if (!iwlwifi_mod_params.sw_crypto) |
964dc9e2 JB |
274 | mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | |
275 | WIPHY_WOWLAN_GTK_REKEY_FAILURE | | |
276 | WIPHY_WOWLAN_4WAY_HANDSHAKE; | |
277 | ||
278 | mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; | |
279 | mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; | |
280 | mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; | |
281 | mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support; | |
282 | hw->wiphy->wowlan = &mvm->wowlan; | |
8ca151b5 JB |
283 | } |
284 | #endif | |
285 | ||
286 | ret = iwl_mvm_leds_init(mvm); | |
287 | if (ret) | |
288 | return ret; | |
289 | ||
b7327d89 EG |
290 | ret = ieee80211_register_hw(mvm->hw); |
291 | if (ret) | |
292 | iwl_mvm_leds_exit(mvm); | |
293 | ||
294 | return ret; | |
8ca151b5 JB |
295 | } |
296 | ||
297 | static void iwl_mvm_mac_tx(struct ieee80211_hw *hw, | |
298 | struct ieee80211_tx_control *control, | |
299 | struct sk_buff *skb) | |
300 | { | |
301 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
302 | ||
9ee718aa EL |
303 | if (iwl_mvm_is_radio_killed(mvm)) { |
304 | IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); | |
8ca151b5 JB |
305 | goto drop; |
306 | } | |
307 | ||
398e8c6c | 308 | if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE && |
8ca151b5 JB |
309 | !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status)) |
310 | goto drop; | |
311 | ||
312 | if (control->sta) { | |
313 | if (iwl_mvm_tx_skb(mvm, skb, control->sta)) | |
314 | goto drop; | |
315 | return; | |
316 | } | |
317 | ||
318 | if (iwl_mvm_tx_skb_non_sta(mvm, skb)) | |
319 | goto drop; | |
320 | return; | |
321 | drop: | |
322 | ieee80211_free_txskb(hw, skb); | |
323 | } | |
324 | ||
325 | static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, | |
326 | struct ieee80211_vif *vif, | |
327 | enum ieee80211_ampdu_mlme_action action, | |
328 | struct ieee80211_sta *sta, u16 tid, | |
329 | u16 *ssn, u8 buf_size) | |
330 | { | |
331 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
332 | int ret; | |
333 | ||
334 | IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", | |
335 | sta->addr, tid, action); | |
336 | ||
337 | if (!(mvm->nvm_data->sku_cap_11n_enable)) | |
338 | return -EACCES; | |
339 | ||
340 | mutex_lock(&mvm->mutex); | |
341 | ||
342 | switch (action) { | |
343 | case IEEE80211_AMPDU_RX_START: | |
344 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) { | |
345 | ret = -EINVAL; | |
346 | break; | |
347 | } | |
348 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true); | |
349 | break; | |
350 | case IEEE80211_AMPDU_RX_STOP: | |
351 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false); | |
352 | break; | |
353 | case IEEE80211_AMPDU_TX_START: | |
5d158efa EG |
354 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) { |
355 | ret = -EINVAL; | |
356 | break; | |
357 | } | |
8ca151b5 JB |
358 | ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); |
359 | break; | |
360 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
e3d9e7ce EG |
361 | ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); |
362 | break; | |
8ca151b5 JB |
363 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
364 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
e3d9e7ce | 365 | ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); |
8ca151b5 JB |
366 | break; |
367 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
368 | ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size); | |
369 | break; | |
370 | default: | |
371 | WARN_ON_ONCE(1); | |
372 | ret = -EINVAL; | |
373 | break; | |
374 | } | |
375 | mutex_unlock(&mvm->mutex); | |
376 | ||
377 | return ret; | |
378 | } | |
379 | ||
380 | static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, | |
381 | struct ieee80211_vif *vif) | |
382 | { | |
383 | struct iwl_mvm *mvm = data; | |
384 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
385 | ||
386 | mvmvif->uploaded = false; | |
387 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; | |
388 | ||
389 | /* does this make sense at all? */ | |
390 | mvmvif->color++; | |
391 | ||
392 | spin_lock_bh(&mvm->time_event_lock); | |
393 | iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); | |
394 | spin_unlock_bh(&mvm->time_event_lock); | |
395 | ||
fe0f2de3 | 396 | mvmvif->phy_ctxt = NULL; |
8ca151b5 JB |
397 | } |
398 | ||
399 | static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) | |
400 | { | |
401 | iwl_trans_stop_device(mvm->trans); | |
402 | iwl_trans_stop_hw(mvm->trans, false); | |
403 | ||
404 | mvm->scan_status = IWL_MVM_SCAN_NONE; | |
405 | ||
406 | /* just in case one was running */ | |
407 | ieee80211_remain_on_channel_expired(mvm->hw); | |
408 | ||
409 | ieee80211_iterate_active_interfaces_atomic( | |
410 | mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL, | |
411 | iwl_mvm_cleanup_iterator, mvm); | |
412 | ||
fe0f2de3 IP |
413 | mvm->p2p_device_vif = NULL; |
414 | ||
415 | iwl_mvm_reset_phy_ctxts(mvm); | |
8ca151b5 JB |
416 | memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); |
417 | memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained)); | |
418 | ||
419 | ieee80211_wake_queues(mvm->hw); | |
420 | ||
421 | mvm->vif_count = 0; | |
113a0447 | 422 | mvm->rx_ba_sessions = 0; |
8ca151b5 JB |
423 | } |
424 | ||
425 | static int iwl_mvm_mac_start(struct ieee80211_hw *hw) | |
426 | { | |
427 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
428 | int ret; | |
429 | ||
430 | mutex_lock(&mvm->mutex); | |
431 | ||
432 | /* Clean up some internal and mac80211 state on restart */ | |
433 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) | |
434 | iwl_mvm_restart_cleanup(mvm); | |
435 | ||
436 | ret = iwl_mvm_up(mvm); | |
437 | mutex_unlock(&mvm->mutex); | |
438 | ||
439 | return ret; | |
440 | } | |
441 | ||
442 | static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw) | |
443 | { | |
444 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
445 | int ret; | |
446 | ||
447 | mutex_lock(&mvm->mutex); | |
448 | ||
449 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); | |
450 | ret = iwl_mvm_update_quotas(mvm, NULL); | |
451 | if (ret) | |
452 | IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", | |
453 | ret); | |
454 | ||
455 | mutex_unlock(&mvm->mutex); | |
456 | } | |
457 | ||
458 | static void iwl_mvm_mac_stop(struct ieee80211_hw *hw) | |
459 | { | |
460 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
461 | ||
462 | flush_work(&mvm->async_handlers_wk); | |
463 | ||
464 | mutex_lock(&mvm->mutex); | |
465 | /* async_handlers_wk is now blocked */ | |
466 | ||
467 | /* | |
468 | * The work item could be running or queued if the | |
469 | * ROC time event stops just as we get here. | |
470 | */ | |
471 | cancel_work_sync(&mvm->roc_done_wk); | |
472 | ||
473 | iwl_trans_stop_device(mvm->trans); | |
474 | iwl_trans_stop_hw(mvm->trans, false); | |
475 | ||
476 | iwl_mvm_async_handlers_purge(mvm); | |
477 | /* async_handlers_list is empty and will stay empty: HW is stopped */ | |
478 | ||
479 | /* the fw is stopped, the aux sta is dead: clean up driver state */ | |
480 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); | |
481 | ||
482 | mutex_unlock(&mvm->mutex); | |
483 | ||
484 | /* | |
485 | * The worker might have been waiting for the mutex, let it run and | |
486 | * discover that its list is now empty. | |
487 | */ | |
488 | cancel_work_sync(&mvm->async_handlers_wk); | |
489 | } | |
490 | ||
491 | static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac, | |
492 | struct ieee80211_vif *vif) | |
493 | { | |
494 | struct iwl_mvm *mvm = data; | |
495 | int ret; | |
496 | ||
497 | ret = iwl_mvm_power_disable(mvm, vif); | |
498 | if (ret) | |
499 | IWL_ERR(mvm, "failed to disable power management\n"); | |
500 | } | |
501 | ||
502 | static void iwl_mvm_power_update_iterator(void *data, u8 *mac, | |
503 | struct ieee80211_vif *vif) | |
504 | { | |
505 | struct iwl_mvm *mvm = data; | |
506 | ||
507 | iwl_mvm_power_update_mode(mvm, vif); | |
508 | } | |
509 | ||
fe0f2de3 IP |
510 | static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) |
511 | { | |
512 | u16 i; | |
513 | ||
514 | lockdep_assert_held(&mvm->mutex); | |
515 | ||
516 | for (i = 0; i < NUM_PHY_CTX; i++) | |
517 | if (!mvm->phy_ctxts[i].ref) | |
518 | return &mvm->phy_ctxts[i]; | |
519 | ||
520 | IWL_ERR(mvm, "No available PHY context\n"); | |
521 | return NULL; | |
522 | } | |
523 | ||
8ca151b5 JB |
524 | static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, |
525 | struct ieee80211_vif *vif) | |
526 | { | |
527 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
528 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
529 | int ret; | |
530 | ||
531 | /* | |
532 | * Not much to do here. The stack will not allow interface | |
533 | * types or combinations that we didn't advertise, so we | |
534 | * don't really have to check the types. | |
535 | */ | |
536 | ||
537 | mutex_lock(&mvm->mutex); | |
538 | ||
e89044d7 | 539 | /* Allocate resources for the MAC context, and add it to the fw */ |
8ca151b5 JB |
540 | ret = iwl_mvm_mac_ctxt_init(mvm, vif); |
541 | if (ret) | |
542 | goto out_unlock; | |
543 | ||
ea183d02 IP |
544 | /* |
545 | * TODO: remove this temporary code. | |
546 | * Currently MVM FW supports power management only on single MAC. | |
547 | * If new interface added, disable PM on existing interface. | |
548 | * P2P device is a special case, since it is handled by FW similary to | |
549 | * scan. If P2P deviced is added, PM remains enabled on existing | |
550 | * interface. | |
551 | * Note: the method below does not count the new interface being added | |
552 | * at this moment. | |
553 | */ | |
554 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) | |
555 | mvm->vif_count++; | |
556 | if (mvm->vif_count > 1) { | |
557 | IWL_DEBUG_MAC80211(mvm, | |
558 | "Disable power on existing interfaces\n"); | |
559 | ieee80211_iterate_active_interfaces_atomic( | |
560 | mvm->hw, | |
561 | IEEE80211_IFACE_ITER_NORMAL, | |
562 | iwl_mvm_pm_disable_iterator, mvm); | |
563 | } | |
564 | ||
8ca151b5 JB |
565 | /* |
566 | * The AP binding flow can be done only after the beacon | |
567 | * template is configured (which happens only in the mac80211 | |
568 | * start_ap() flow), and adding the broadcast station can happen | |
569 | * only after the binding. | |
570 | * In addition, since modifying the MAC before adding a bcast | |
571 | * station is not allowed by the FW, delay the adding of MAC context to | |
572 | * the point where we can also add the bcast station. | |
573 | * In short: there's not much we can do at this point, other than | |
574 | * allocating resources :) | |
575 | */ | |
5023d966 JB |
576 | if (vif->type == NL80211_IFTYPE_AP || |
577 | vif->type == NL80211_IFTYPE_ADHOC) { | |
8ca151b5 JB |
578 | u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif); |
579 | ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, | |
580 | qmask); | |
581 | if (ret) { | |
582 | IWL_ERR(mvm, "Failed to allocate bcast sta\n"); | |
583 | goto out_release; | |
584 | } | |
585 | ||
77740cb4 | 586 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
8ca151b5 JB |
587 | goto out_unlock; |
588 | } | |
589 | ||
8ca151b5 JB |
590 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
591 | if (ret) | |
592 | goto out_release; | |
593 | ||
594 | /* | |
595 | * Update power state on the new interface. Admittedly, based on | |
596 | * mac80211 logics this power update will disable power management | |
597 | */ | |
598 | iwl_mvm_power_update_mode(mvm, vif); | |
599 | ||
7df15b1e | 600 | /* beacon filtering */ |
bd3351ba EP |
601 | ret = iwl_mvm_disable_beacon_filter(mvm, vif); |
602 | if (ret) | |
603 | goto out_remove_mac; | |
604 | ||
7df15b1e | 605 | if (!mvm->bf_allowed_vif && |
5dca7c24 HG |
606 | vif->type == NL80211_IFTYPE_STATION && !vif->p2p && |
607 | mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){ | |
7df15b1e | 608 | mvm->bf_allowed_vif = mvmvif; |
a20fd398 AO |
609 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | |
610 | IEEE80211_VIF_SUPPORTS_CQM_RSSI; | |
7df15b1e HG |
611 | } |
612 | ||
8ca151b5 JB |
613 | /* |
614 | * P2P_DEVICE interface does not have a channel context assigned to it, | |
615 | * so a dedicated PHY context is allocated to it and the corresponding | |
616 | * MAC context is bound to it at this stage. | |
617 | */ | |
618 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
8ca151b5 | 619 | |
fe0f2de3 IP |
620 | mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
621 | if (!mvmvif->phy_ctxt) { | |
622 | ret = -ENOSPC; | |
bd3351ba | 623 | goto out_free_bf; |
fe0f2de3 | 624 | } |
8ca151b5 | 625 | |
53a9d61e | 626 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
8ca151b5 JB |
627 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
628 | if (ret) | |
53a9d61e | 629 | goto out_unref_phy; |
8ca151b5 JB |
630 | |
631 | ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta); | |
632 | if (ret) | |
633 | goto out_unbind; | |
634 | ||
635 | /* Save a pointer to p2p device vif, so it can later be used to | |
636 | * update the p2p device MAC when a GO is started/stopped */ | |
637 | mvm->p2p_device_vif = vif; | |
638 | } | |
639 | ||
63494374 | 640 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
8ca151b5 JB |
641 | goto out_unlock; |
642 | ||
643 | out_unbind: | |
644 | iwl_mvm_binding_remove_vif(mvm, vif); | |
53a9d61e | 645 | out_unref_phy: |
fe0f2de3 | 646 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
bd3351ba EP |
647 | out_free_bf: |
648 | if (mvm->bf_allowed_vif == mvmvif) { | |
649 | mvm->bf_allowed_vif = NULL; | |
a20fd398 AO |
650 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
651 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); | |
bd3351ba | 652 | } |
8ca151b5 JB |
653 | out_remove_mac: |
654 | mvmvif->phy_ctxt = NULL; | |
655 | iwl_mvm_mac_ctxt_remove(mvm, vif); | |
656 | out_release: | |
5ee2b215 AB |
657 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) |
658 | mvm->vif_count--; | |
4bf881f5 AB |
659 | ieee80211_iterate_active_interfaces( |
660 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
661 | iwl_mvm_power_update_iterator, mvm); | |
8ca151b5 JB |
662 | iwl_mvm_mac_ctxt_release(mvm, vif); |
663 | out_unlock: | |
664 | mutex_unlock(&mvm->mutex); | |
665 | ||
666 | return ret; | |
667 | } | |
668 | ||
38a12b5b JB |
669 | static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, |
670 | struct ieee80211_vif *vif) | |
8ca151b5 | 671 | { |
8ca151b5 JB |
672 | u32 tfd_msk = 0, ac; |
673 | ||
674 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) | |
675 | if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE) | |
676 | tfd_msk |= BIT(vif->hw_queue[ac]); | |
677 | ||
678 | if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE) | |
679 | tfd_msk |= BIT(vif->cab_queue); | |
680 | ||
681 | if (tfd_msk) { | |
682 | mutex_lock(&mvm->mutex); | |
683 | iwl_mvm_flush_tx_path(mvm, tfd_msk, true); | |
684 | mutex_unlock(&mvm->mutex); | |
685 | } | |
686 | ||
687 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
688 | /* | |
689 | * Flush the ROC worker which will flush the OFFCHANNEL queue. | |
690 | * We assume here that all the packets sent to the OFFCHANNEL | |
691 | * queue are sent in ROC session. | |
692 | */ | |
693 | flush_work(&mvm->roc_done_wk); | |
694 | } else { | |
695 | /* | |
696 | * By now, all the AC queues are empty. The AGG queues are | |
697 | * empty too. We already got all the Tx responses for all the | |
698 | * packets in the queues. The drain work can have been | |
0742a75a | 699 | * triggered. Flush it. |
8ca151b5 JB |
700 | */ |
701 | flush_work(&mvm->sta_drained_wk); | |
702 | } | |
38a12b5b JB |
703 | } |
704 | ||
705 | static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, | |
706 | struct ieee80211_vif *vif) | |
707 | { | |
708 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
709 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
710 | ||
711 | iwl_mvm_prepare_mac_removal(mvm, vif); | |
8ca151b5 JB |
712 | |
713 | mutex_lock(&mvm->mutex); | |
714 | ||
7df15b1e HG |
715 | if (mvm->bf_allowed_vif == mvmvif) { |
716 | mvm->bf_allowed_vif = NULL; | |
a20fd398 AO |
717 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
718 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); | |
7df15b1e HG |
719 | } |
720 | ||
63494374 JB |
721 | iwl_mvm_vif_dbgfs_clean(mvm, vif); |
722 | ||
8ca151b5 JB |
723 | /* |
724 | * For AP/GO interface, the tear down of the resources allocated to the | |
38a12b5b | 725 | * interface is be handled as part of the stop_ap flow. |
8ca151b5 | 726 | */ |
5023d966 JB |
727 | if (vif->type == NL80211_IFTYPE_AP || |
728 | vif->type == NL80211_IFTYPE_ADHOC) { | |
507cadf2 DS |
729 | #ifdef CONFIG_NL80211_TESTMODE |
730 | if (vif == mvm->noa_vif) { | |
731 | mvm->noa_vif = NULL; | |
732 | mvm->noa_duration = 0; | |
733 | } | |
734 | #endif | |
8ca151b5 JB |
735 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); |
736 | goto out_release; | |
737 | } | |
738 | ||
739 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
740 | mvm->p2p_device_vif = NULL; | |
741 | iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta); | |
742 | iwl_mvm_binding_remove_vif(mvm, vif); | |
fe0f2de3 | 743 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
8ca151b5 JB |
744 | mvmvif->phy_ctxt = NULL; |
745 | } | |
746 | ||
747 | /* | |
748 | * TODO: remove this temporary code. | |
749 | * Currently MVM FW supports power management only on single MAC. | |
750 | * Check if only one additional interface remains after removing | |
751 | * current one. Update power mode on the remaining interface. | |
752 | */ | |
5ee2b215 | 753 | if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE) |
8ca151b5 JB |
754 | mvm->vif_count--; |
755 | IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n", | |
756 | mvm->vif_count); | |
757 | if (mvm->vif_count == 1) { | |
758 | ieee80211_iterate_active_interfaces( | |
759 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
760 | iwl_mvm_power_update_iterator, mvm); | |
761 | } | |
762 | ||
763 | iwl_mvm_mac_ctxt_remove(mvm, vif); | |
764 | ||
765 | out_release: | |
766 | iwl_mvm_mac_ctxt_release(mvm, vif); | |
767 | mutex_unlock(&mvm->mutex); | |
768 | } | |
769 | ||
88f2fd73 MG |
770 | static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
771 | s8 tx_power) | |
772 | { | |
773 | /* FW is in charge of regulatory enforcement */ | |
774 | struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = { | |
775 | .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id, | |
776 | .pwr_restriction = cpu_to_le16(tx_power), | |
777 | }; | |
778 | ||
779 | return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC, | |
780 | sizeof(reduce_txpwr_cmd), | |
781 | &reduce_txpwr_cmd); | |
782 | } | |
783 | ||
8ca151b5 JB |
784 | static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed) |
785 | { | |
786 | return 0; | |
787 | } | |
788 | ||
789 | static void iwl_mvm_configure_filter(struct ieee80211_hw *hw, | |
790 | unsigned int changed_flags, | |
791 | unsigned int *total_flags, | |
792 | u64 multicast) | |
793 | { | |
794 | *total_flags = 0; | |
795 | } | |
796 | ||
51b6b9e0 EG |
797 | static int iwl_mvm_configure_mcast_filter(struct iwl_mvm *mvm, |
798 | struct ieee80211_vif *vif) | |
799 | { | |
800 | struct iwl_mcast_filter_cmd mcast_filter_cmd = { | |
801 | .pass_all = 1, | |
802 | }; | |
803 | ||
804 | memcpy(mcast_filter_cmd.bssid, vif->bss_conf.bssid, ETH_ALEN); | |
805 | ||
806 | return iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC, | |
807 | sizeof(mcast_filter_cmd), | |
808 | &mcast_filter_cmd); | |
809 | } | |
810 | ||
8ca151b5 JB |
811 | static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, |
812 | struct ieee80211_vif *vif, | |
813 | struct ieee80211_bss_conf *bss_conf, | |
814 | u32 changes) | |
815 | { | |
816 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
817 | int ret; | |
818 | ||
819 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); | |
820 | if (ret) | |
821 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); | |
822 | ||
823 | if (changes & BSS_CHANGED_ASSOC) { | |
824 | if (bss_conf->assoc) { | |
825 | /* add quota for this interface */ | |
826 | ret = iwl_mvm_update_quotas(mvm, vif); | |
827 | if (ret) { | |
828 | IWL_ERR(mvm, "failed to update quotas\n"); | |
829 | return; | |
830 | } | |
51b6b9e0 | 831 | iwl_mvm_configure_mcast_filter(mvm, vif); |
016d27e1 JB |
832 | |
833 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, | |
834 | &mvm->status)) { | |
835 | /* | |
836 | * If we're restarting then the firmware will | |
837 | * obviously have lost synchronisation with | |
838 | * the AP. It will attempt to synchronise by | |
839 | * itself, but we can make it more reliable by | |
840 | * scheduling a session protection time event. | |
841 | * | |
842 | * The firmware needs to receive a beacon to | |
843 | * catch up with synchronisation, use 110% of | |
844 | * the beacon interval. | |
845 | * | |
846 | * Set a large maximum delay to allow for more | |
847 | * than a single interface. | |
848 | */ | |
849 | u32 dur = (11 * vif->bss_conf.beacon_int) / 10; | |
850 | iwl_mvm_protect_session(mvm, vif, dur, dur, | |
851 | 5 * dur); | |
852 | } | |
8ca151b5 JB |
853 | } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
854 | /* remove AP station now that the MAC is unassoc */ | |
855 | ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id); | |
856 | if (ret) | |
857 | IWL_ERR(mvm, "failed to remove AP station\n"); | |
858 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; | |
859 | /* remove quota for this interface */ | |
860 | ret = iwl_mvm_update_quotas(mvm, NULL); | |
861 | if (ret) | |
862 | IWL_ERR(mvm, "failed to update quotas\n"); | |
863 | } | |
a20fd398 AO |
864 | |
865 | /* reset rssi values */ | |
866 | mvmvif->bf_data.ave_beacon_signal = 0; | |
867 | ||
e8e626ad AB |
868 | if (!(mvm->fw->ucode_capa.flags & |
869 | IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT)) { | |
e811ada7 AB |
870 | /* Workaround for FW bug, otherwise FW disables device |
871 | * power save upon disassociation | |
872 | */ | |
873 | ret = iwl_mvm_power_update_mode(mvm, vif); | |
874 | if (ret) | |
875 | IWL_ERR(mvm, "failed to update power mode\n"); | |
876 | } | |
8e484f0b | 877 | iwl_mvm_bt_coex_vif_change(mvm); |
989c6505 | 878 | } else if (changes & BSS_CHANGED_BEACON_INFO) { |
210a544e JB |
879 | /* |
880 | * We received a beacon _after_ association so | |
881 | * remove the session protection. | |
882 | */ | |
883 | iwl_mvm_remove_time_event(mvm, mvmvif, | |
884 | &mvmvif->time_event_data); | |
e3c588ec | 885 | } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_QOS)) { |
4bf881f5 AB |
886 | ret = iwl_mvm_power_update_mode(mvm, vif); |
887 | if (ret) | |
888 | IWL_ERR(mvm, "failed to update power mode\n"); | |
8ca151b5 | 889 | } |
88f2fd73 MG |
890 | if (changes & BSS_CHANGED_TXPOWER) { |
891 | IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n", | |
892 | bss_conf->txpower); | |
893 | iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); | |
894 | } | |
a20fd398 AO |
895 | |
896 | if (changes & BSS_CHANGED_CQM) { | |
897 | IWL_DEBUG_MAC80211(mvm, "cqm info_changed"); | |
898 | /* reset cqm events tracking */ | |
899 | mvmvif->bf_data.last_cqm_event = 0; | |
900 | ret = iwl_mvm_update_beacon_filter(mvm, vif); | |
901 | if (ret) | |
902 | IWL_ERR(mvm, "failed to update CQM thresholds\n"); | |
903 | } | |
8ca151b5 JB |
904 | } |
905 | ||
5023d966 JB |
906 | static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, |
907 | struct ieee80211_vif *vif) | |
8ca151b5 JB |
908 | { |
909 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
910 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
911 | int ret; | |
912 | ||
913 | mutex_lock(&mvm->mutex); | |
914 | ||
915 | /* Send the beacon template */ | |
916 | ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif); | |
917 | if (ret) | |
918 | goto out_unlock; | |
919 | ||
920 | /* Add the mac context */ | |
921 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); | |
922 | if (ret) | |
923 | goto out_unlock; | |
924 | ||
925 | /* Perform the binding */ | |
926 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
927 | if (ret) | |
928 | goto out_remove; | |
929 | ||
5023d966 | 930 | mvmvif->ap_ibss_active = true; |
8ca151b5 JB |
931 | |
932 | /* Send the bcast station. At this stage the TBTT and DTIM time events | |
933 | * are added and applied to the scheduler */ | |
934 | ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta); | |
935 | if (ret) | |
936 | goto out_unbind; | |
937 | ||
938 | ret = iwl_mvm_update_quotas(mvm, vif); | |
939 | if (ret) | |
940 | goto out_rm_bcast; | |
941 | ||
5023d966 | 942 | /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ |
8ca151b5 JB |
943 | if (vif->p2p && mvm->p2p_device_vif) |
944 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif); | |
945 | ||
8e484f0b | 946 | iwl_mvm_bt_coex_vif_change(mvm); |
dac94da8 | 947 | |
8ca151b5 JB |
948 | mutex_unlock(&mvm->mutex); |
949 | return 0; | |
950 | ||
951 | out_rm_bcast: | |
952 | iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta); | |
953 | out_unbind: | |
954 | iwl_mvm_binding_remove_vif(mvm, vif); | |
955 | out_remove: | |
956 | iwl_mvm_mac_ctxt_remove(mvm, vif); | |
957 | out_unlock: | |
958 | mutex_unlock(&mvm->mutex); | |
959 | return ret; | |
960 | } | |
961 | ||
5023d966 JB |
962 | static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, |
963 | struct ieee80211_vif *vif) | |
8ca151b5 JB |
964 | { |
965 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
966 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
967 | ||
38a12b5b JB |
968 | iwl_mvm_prepare_mac_removal(mvm, vif); |
969 | ||
8ca151b5 JB |
970 | mutex_lock(&mvm->mutex); |
971 | ||
5023d966 | 972 | mvmvif->ap_ibss_active = false; |
8ca151b5 | 973 | |
8e484f0b | 974 | iwl_mvm_bt_coex_vif_change(mvm); |
dac94da8 | 975 | |
5023d966 | 976 | /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ |
8ca151b5 JB |
977 | if (vif->p2p && mvm->p2p_device_vif) |
978 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif); | |
979 | ||
980 | iwl_mvm_update_quotas(mvm, NULL); | |
981 | iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta); | |
982 | iwl_mvm_binding_remove_vif(mvm, vif); | |
983 | iwl_mvm_mac_ctxt_remove(mvm, vif); | |
984 | ||
985 | mutex_unlock(&mvm->mutex); | |
986 | } | |
987 | ||
5023d966 JB |
988 | static void |
989 | iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, | |
990 | struct ieee80211_vif *vif, | |
991 | struct ieee80211_bss_conf *bss_conf, | |
992 | u32 changes) | |
8ca151b5 | 993 | { |
8a5e3660 AA |
994 | enum ieee80211_bss_change ht_change = BSS_CHANGED_ERP_CTS_PROT | |
995 | BSS_CHANGED_HT | | |
996 | BSS_CHANGED_BANDWIDTH; | |
997 | int ret; | |
998 | ||
999 | if (changes & ht_change) { | |
1000 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); | |
1001 | if (ret) | |
1002 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); | |
1003 | } | |
1004 | ||
8ca151b5 JB |
1005 | /* Need to send a new beacon template to the FW */ |
1006 | if (changes & BSS_CHANGED_BEACON) { | |
1007 | if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif)) | |
1008 | IWL_WARN(mvm, "Failed updating beacon data\n"); | |
1009 | } | |
1010 | } | |
1011 | ||
1012 | static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, | |
1013 | struct ieee80211_vif *vif, | |
1014 | struct ieee80211_bss_conf *bss_conf, | |
1015 | u32 changes) | |
1016 | { | |
1017 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1018 | ||
1019 | mutex_lock(&mvm->mutex); | |
1020 | ||
1021 | switch (vif->type) { | |
1022 | case NL80211_IFTYPE_STATION: | |
1023 | iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); | |
1024 | break; | |
1025 | case NL80211_IFTYPE_AP: | |
5023d966 JB |
1026 | case NL80211_IFTYPE_ADHOC: |
1027 | iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes); | |
8ca151b5 JB |
1028 | break; |
1029 | default: | |
1030 | /* shouldn't happen */ | |
1031 | WARN_ON_ONCE(1); | |
1032 | } | |
1033 | ||
1034 | mutex_unlock(&mvm->mutex); | |
1035 | } | |
1036 | ||
1037 | static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, | |
1038 | struct ieee80211_vif *vif, | |
1039 | struct cfg80211_scan_request *req) | |
1040 | { | |
1041 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1042 | int ret; | |
1043 | ||
1044 | if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS) | |
1045 | return -EINVAL; | |
1046 | ||
1047 | mutex_lock(&mvm->mutex); | |
1048 | ||
1049 | if (mvm->scan_status == IWL_MVM_SCAN_NONE) | |
1050 | ret = iwl_mvm_scan_request(mvm, vif, req); | |
1051 | else | |
1052 | ret = -EBUSY; | |
1053 | ||
1054 | mutex_unlock(&mvm->mutex); | |
1055 | ||
1056 | return ret; | |
1057 | } | |
1058 | ||
1059 | static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, | |
1060 | struct ieee80211_vif *vif) | |
1061 | { | |
1062 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1063 | ||
1064 | mutex_lock(&mvm->mutex); | |
1065 | ||
1066 | iwl_mvm_cancel_scan(mvm); | |
1067 | ||
1068 | mutex_unlock(&mvm->mutex); | |
1069 | } | |
1070 | ||
1071 | static void | |
1072 | iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, | |
1073 | struct ieee80211_sta *sta, u16 tid, | |
1074 | int num_frames, | |
1075 | enum ieee80211_frame_release_type reason, | |
1076 | bool more_data) | |
1077 | { | |
1078 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
8ca151b5 JB |
1079 | |
1080 | /* TODO: how do we tell the fw to send frames for a specific TID */ | |
1081 | ||
1082 | /* | |
1083 | * The fw will send EOSP notification when the last frame will be | |
1084 | * transmitted. | |
1085 | */ | |
9cc40712 | 1086 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames); |
8ca151b5 JB |
1087 | } |
1088 | ||
1089 | static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, | |
1090 | struct ieee80211_vif *vif, | |
1091 | enum sta_notify_cmd cmd, | |
1092 | struct ieee80211_sta *sta) | |
1093 | { | |
1094 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5b577a90 | 1095 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
1096 | |
1097 | switch (cmd) { | |
1098 | case STA_NOTIFY_SLEEP: | |
e3d4bc8c | 1099 | if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0) |
8ca151b5 JB |
1100 | ieee80211_sta_block_awake(hw, sta, true); |
1101 | /* | |
1102 | * The fw updates the STA to be asleep. Tx packets on the Tx | |
1103 | * queues to this station will not be transmitted. The fw will | |
1104 | * send a Tx response with TX_STATUS_FAIL_DEST_PS. | |
1105 | */ | |
1106 | break; | |
1107 | case STA_NOTIFY_AWAKE: | |
881acd89 | 1108 | if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT)) |
8ca151b5 | 1109 | break; |
9cc40712 | 1110 | iwl_mvm_sta_modify_ps_wake(mvm, sta); |
8ca151b5 JB |
1111 | break; |
1112 | default: | |
1113 | break; | |
1114 | } | |
1115 | } | |
1116 | ||
1117 | static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, | |
1118 | struct ieee80211_vif *vif, | |
1119 | struct ieee80211_sta *sta, | |
1120 | enum ieee80211_sta_state old_state, | |
1121 | enum ieee80211_sta_state new_state) | |
1122 | { | |
1123 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1124 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1125 | int ret; | |
1126 | ||
1127 | IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", | |
1128 | sta->addr, old_state, new_state); | |
1129 | ||
1130 | /* this would be a mac80211 bug ... but don't crash */ | |
1131 | if (WARN_ON_ONCE(!mvmvif->phy_ctxt)) | |
1132 | return -EINVAL; | |
1133 | ||
1134 | /* if a STA is being removed, reuse its ID */ | |
1135 | flush_work(&mvm->sta_drained_wk); | |
1136 | ||
1137 | mutex_lock(&mvm->mutex); | |
1138 | if (old_state == IEEE80211_STA_NOTEXIST && | |
1139 | new_state == IEEE80211_STA_NONE) { | |
48bc1307 JB |
1140 | /* |
1141 | * Firmware bug - it'll crash if the beacon interval is less | |
1142 | * than 16. We can't avoid connecting at all, so refuse the | |
1143 | * station state change, this will cause mac80211 to abandon | |
1144 | * attempts to connect to this AP, and eventually wpa_s will | |
1145 | * blacklist the AP... | |
1146 | */ | |
1147 | if (vif->type == NL80211_IFTYPE_STATION && | |
1148 | vif->bss_conf.beacon_int < 16) { | |
1149 | IWL_ERR(mvm, | |
1150 | "AP %pM beacon interval is %d, refusing due to firmware bug!\n", | |
1151 | sta->addr, vif->bss_conf.beacon_int); | |
1152 | ret = -EINVAL; | |
1153 | goto out_unlock; | |
1154 | } | |
8ca151b5 JB |
1155 | ret = iwl_mvm_add_sta(mvm, vif, sta); |
1156 | } else if (old_state == IEEE80211_STA_NONE && | |
1157 | new_state == IEEE80211_STA_AUTH) { | |
1158 | ret = 0; | |
1159 | } else if (old_state == IEEE80211_STA_AUTH && | |
1160 | new_state == IEEE80211_STA_ASSOC) { | |
7a453973 JB |
1161 | ret = iwl_mvm_update_sta(mvm, vif, sta); |
1162 | if (ret == 0) | |
1163 | iwl_mvm_rs_rate_init(mvm, sta, | |
b87c2179 ES |
1164 | mvmvif->phy_ctxt->channel->band, |
1165 | true); | |
8ca151b5 JB |
1166 | } else if (old_state == IEEE80211_STA_ASSOC && |
1167 | new_state == IEEE80211_STA_AUTHORIZED) { | |
7df15b1e HG |
1168 | /* enable beacon filtering */ |
1169 | WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif)); | |
8ca151b5 JB |
1170 | ret = 0; |
1171 | } else if (old_state == IEEE80211_STA_AUTHORIZED && | |
1172 | new_state == IEEE80211_STA_ASSOC) { | |
7df15b1e HG |
1173 | /* disable beacon filtering */ |
1174 | WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif)); | |
8ca151b5 JB |
1175 | ret = 0; |
1176 | } else if (old_state == IEEE80211_STA_ASSOC && | |
1177 | new_state == IEEE80211_STA_AUTH) { | |
1178 | ret = 0; | |
1179 | } else if (old_state == IEEE80211_STA_AUTH && | |
1180 | new_state == IEEE80211_STA_NONE) { | |
1181 | ret = 0; | |
1182 | } else if (old_state == IEEE80211_STA_NONE && | |
1183 | new_state == IEEE80211_STA_NOTEXIST) { | |
1184 | ret = iwl_mvm_rm_sta(mvm, vif, sta); | |
1185 | } else { | |
1186 | ret = -EIO; | |
1187 | } | |
48bc1307 | 1188 | out_unlock: |
8ca151b5 JB |
1189 | mutex_unlock(&mvm->mutex); |
1190 | ||
1191 | return ret; | |
1192 | } | |
1193 | ||
1194 | static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) | |
1195 | { | |
1196 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1197 | ||
1198 | mvm->rts_threshold = value; | |
1199 | ||
1200 | return 0; | |
1201 | } | |
1202 | ||
1203 | static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, | |
1204 | struct ieee80211_vif *vif, u16 ac, | |
1205 | const struct ieee80211_tx_queue_params *params) | |
1206 | { | |
1207 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1208 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1209 | ||
1210 | mvmvif->queue_params[ac] = *params; | |
1211 | ||
1212 | /* | |
1213 | * No need to update right away, we'll get BSS_CHANGED_QOS | |
1214 | * The exception is P2P_DEVICE interface which needs immediate update. | |
1215 | */ | |
1216 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
1217 | int ret; | |
1218 | ||
1219 | mutex_lock(&mvm->mutex); | |
1220 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); | |
1221 | mutex_unlock(&mvm->mutex); | |
1222 | return ret; | |
1223 | } | |
1224 | return 0; | |
1225 | } | |
1226 | ||
1227 | static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, | |
1228 | struct ieee80211_vif *vif) | |
1229 | { | |
1230 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1231 | u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS, | |
1232 | 200 + vif->bss_conf.beacon_int); | |
1233 | u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS, | |
1234 | 100 + vif->bss_conf.beacon_int); | |
1235 | ||
1236 | if (WARN_ON_ONCE(vif->bss_conf.assoc)) | |
1237 | return; | |
1238 | ||
1239 | mutex_lock(&mvm->mutex); | |
1240 | /* Try really hard to protect the session and hear a beacon */ | |
016d27e1 | 1241 | iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500); |
8ca151b5 JB |
1242 | mutex_unlock(&mvm->mutex); |
1243 | } | |
1244 | ||
35a000b7 DS |
1245 | static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, |
1246 | struct ieee80211_vif *vif, | |
1247 | struct cfg80211_sched_scan_request *req, | |
1248 | struct ieee80211_sched_scan_ies *ies) | |
1249 | { | |
1250 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1251 | int ret; | |
1252 | ||
1253 | mutex_lock(&mvm->mutex); | |
1254 | ||
1255 | if (mvm->scan_status != IWL_MVM_SCAN_NONE) { | |
1256 | IWL_DEBUG_SCAN(mvm, | |
1257 | "SCHED SCAN request during internal scan - abort\n"); | |
1258 | ret = -EBUSY; | |
1259 | goto out; | |
1260 | } | |
1261 | ||
1262 | mvm->scan_status = IWL_MVM_SCAN_SCHED; | |
1263 | ||
1264 | ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies); | |
1265 | if (ret) | |
1266 | goto err; | |
1267 | ||
1268 | ret = iwl_mvm_config_sched_scan_profiles(mvm, req); | |
1269 | if (ret) | |
1270 | goto err; | |
1271 | ||
1272 | ret = iwl_mvm_sched_scan_start(mvm, req); | |
1273 | if (!ret) | |
1274 | goto out; | |
1275 | err: | |
1276 | mvm->scan_status = IWL_MVM_SCAN_NONE; | |
1277 | out: | |
1278 | mutex_unlock(&mvm->mutex); | |
1279 | return ret; | |
1280 | } | |
1281 | ||
1282 | static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, | |
1283 | struct ieee80211_vif *vif) | |
1284 | { | |
1285 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1286 | ||
1287 | mutex_lock(&mvm->mutex); | |
1288 | iwl_mvm_sched_scan_stop(mvm); | |
1289 | mutex_unlock(&mvm->mutex); | |
1290 | } | |
1291 | ||
8ca151b5 JB |
1292 | static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, |
1293 | enum set_key_cmd cmd, | |
1294 | struct ieee80211_vif *vif, | |
1295 | struct ieee80211_sta *sta, | |
1296 | struct ieee80211_key_conf *key) | |
1297 | { | |
1298 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1299 | int ret; | |
1300 | ||
1301 | if (iwlwifi_mod_params.sw_crypto) { | |
1302 | IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n"); | |
1303 | return -EOPNOTSUPP; | |
1304 | } | |
1305 | ||
1306 | switch (key->cipher) { | |
1307 | case WLAN_CIPHER_SUITE_TKIP: | |
1308 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; | |
1309 | /* fall-through */ | |
1310 | case WLAN_CIPHER_SUITE_CCMP: | |
1311 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
1312 | break; | |
1313 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
1314 | WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE)); | |
1315 | break; | |
1316 | case WLAN_CIPHER_SUITE_WEP40: | |
1317 | case WLAN_CIPHER_SUITE_WEP104: | |
1318 | /* | |
1319 | * Support for TX only, at least for now, so accept | |
1320 | * the key and do nothing else. Then mac80211 will | |
1321 | * pass it for TX but we don't have to use it for RX. | |
1322 | */ | |
1323 | return 0; | |
1324 | default: | |
1325 | return -EOPNOTSUPP; | |
1326 | } | |
1327 | ||
1328 | mutex_lock(&mvm->mutex); | |
1329 | ||
1330 | switch (cmd) { | |
1331 | case SET_KEY: | |
5023d966 JB |
1332 | if ((vif->type == NL80211_IFTYPE_ADHOC || |
1333 | vif->type == NL80211_IFTYPE_AP) && !sta) { | |
1334 | /* | |
1335 | * GTK on AP interface is a TX-only key, return 0; | |
1336 | * on IBSS they're per-station and because we're lazy | |
1337 | * we don't support them for RX, so do the same. | |
1338 | */ | |
6caffd4f JB |
1339 | ret = 0; |
1340 | key->hw_key_idx = STA_KEY_IDX_INVALID; | |
1341 | break; | |
1342 | } | |
1343 | ||
8ca151b5 JB |
1344 | IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n"); |
1345 | ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false); | |
1346 | if (ret) { | |
1347 | IWL_WARN(mvm, "set key failed\n"); | |
1348 | /* | |
1349 | * can't add key for RX, but we don't need it | |
1350 | * in the device for TX so still return 0 | |
1351 | */ | |
6caffd4f | 1352 | key->hw_key_idx = STA_KEY_IDX_INVALID; |
8ca151b5 JB |
1353 | ret = 0; |
1354 | } | |
1355 | ||
1356 | break; | |
1357 | case DISABLE_KEY: | |
6caffd4f JB |
1358 | if (key->hw_key_idx == STA_KEY_IDX_INVALID) { |
1359 | ret = 0; | |
1360 | break; | |
1361 | } | |
1362 | ||
8ca151b5 JB |
1363 | IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); |
1364 | ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); | |
1365 | break; | |
1366 | default: | |
1367 | ret = -EINVAL; | |
1368 | } | |
1369 | ||
1370 | mutex_unlock(&mvm->mutex); | |
1371 | return ret; | |
1372 | } | |
1373 | ||
1374 | static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, | |
1375 | struct ieee80211_vif *vif, | |
1376 | struct ieee80211_key_conf *keyconf, | |
1377 | struct ieee80211_sta *sta, | |
1378 | u32 iv32, u16 *phase1key) | |
1379 | { | |
1380 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1381 | ||
5023d966 JB |
1382 | if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) |
1383 | return; | |
1384 | ||
8ca151b5 JB |
1385 | iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); |
1386 | } | |
1387 | ||
1388 | ||
1389 | static int iwl_mvm_roc(struct ieee80211_hw *hw, | |
1390 | struct ieee80211_vif *vif, | |
1391 | struct ieee80211_channel *channel, | |
d339d5ca IP |
1392 | int duration, |
1393 | enum ieee80211_roc_type type) | |
8ca151b5 JB |
1394 | { |
1395 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
fe0f2de3 | 1396 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
8ca151b5 | 1397 | struct cfg80211_chan_def chandef; |
31d385ae IP |
1398 | struct iwl_mvm_phy_ctxt *phy_ctxt; |
1399 | int ret, i; | |
1400 | ||
1401 | IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, | |
1402 | duration, type); | |
8ca151b5 JB |
1403 | |
1404 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) { | |
1405 | IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type); | |
1406 | return -EINVAL; | |
1407 | } | |
1408 | ||
8ca151b5 JB |
1409 | mutex_lock(&mvm->mutex); |
1410 | ||
31d385ae IP |
1411 | for (i = 0; i < NUM_PHY_CTX; i++) { |
1412 | phy_ctxt = &mvm->phy_ctxts[i]; | |
1413 | if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt) | |
1414 | continue; | |
1415 | ||
1416 | if (phy_ctxt->ref && channel == phy_ctxt->channel) { | |
1417 | /* | |
1418 | * Unbind the P2P_DEVICE from the current PHY context, | |
1419 | * and if the PHY context is not used remove it. | |
1420 | */ | |
1421 | ret = iwl_mvm_binding_remove_vif(mvm, vif); | |
1422 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) | |
1423 | goto out_unlock; | |
1424 | ||
1425 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); | |
1426 | ||
1427 | /* Bind the P2P_DEVICE to the current PHY Context */ | |
1428 | mvmvif->phy_ctxt = phy_ctxt; | |
1429 | ||
1430 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
1431 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) | |
1432 | goto out_unlock; | |
1433 | ||
1434 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); | |
1435 | goto schedule_time_event; | |
1436 | } | |
1437 | } | |
1438 | ||
1439 | /* Need to update the PHY context only if the ROC channel changed */ | |
1440 | if (channel == mvmvif->phy_ctxt->channel) | |
1441 | goto schedule_time_event; | |
1442 | ||
8ca151b5 | 1443 | cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); |
8ca151b5 | 1444 | |
31d385ae IP |
1445 | /* |
1446 | * Change the PHY context configuration as it is currently referenced | |
1447 | * only by the P2P Device MAC | |
1448 | */ | |
1449 | if (mvmvif->phy_ctxt->ref == 1) { | |
1450 | ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt, | |
1451 | &chandef, 1, 1); | |
1452 | if (ret) | |
1453 | goto out_unlock; | |
1454 | } else { | |
1455 | /* | |
1456 | * The PHY context is shared with other MACs. Need to remove the | |
1457 | * P2P Device from the binding, allocate an new PHY context and | |
1458 | * create a new binding | |
1459 | */ | |
1460 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); | |
1461 | if (!phy_ctxt) { | |
1462 | ret = -ENOSPC; | |
1463 | goto out_unlock; | |
1464 | } | |
1465 | ||
1466 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef, | |
1467 | 1, 1); | |
1468 | if (ret) { | |
1469 | IWL_ERR(mvm, "Failed to change PHY context\n"); | |
1470 | goto out_unlock; | |
1471 | } | |
1472 | ||
1473 | /* Unbind the P2P_DEVICE from the current PHY context */ | |
1474 | ret = iwl_mvm_binding_remove_vif(mvm, vif); | |
1475 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) | |
1476 | goto out_unlock; | |
1477 | ||
1478 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); | |
1479 | ||
1480 | /* Bind the P2P_DEVICE to the new allocated PHY context */ | |
1481 | mvmvif->phy_ctxt = phy_ctxt; | |
1482 | ||
1483 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
1484 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) | |
1485 | goto out_unlock; | |
1486 | ||
1487 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); | |
1488 | } | |
1489 | ||
1490 | schedule_time_event: | |
8ca151b5 | 1491 | /* Schedule the time events */ |
e635c797 | 1492 | ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); |
8ca151b5 | 1493 | |
31d385ae | 1494 | out_unlock: |
8ca151b5 JB |
1495 | mutex_unlock(&mvm->mutex); |
1496 | IWL_DEBUG_MAC80211(mvm, "leave\n"); | |
8ca151b5 JB |
1497 | return ret; |
1498 | } | |
1499 | ||
1500 | static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw) | |
1501 | { | |
1502 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1503 | ||
1504 | IWL_DEBUG_MAC80211(mvm, "enter\n"); | |
1505 | ||
1506 | mutex_lock(&mvm->mutex); | |
1507 | iwl_mvm_stop_p2p_roc(mvm); | |
1508 | mutex_unlock(&mvm->mutex); | |
1509 | ||
1510 | IWL_DEBUG_MAC80211(mvm, "leave\n"); | |
1511 | return 0; | |
1512 | } | |
1513 | ||
1514 | static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, | |
1515 | struct ieee80211_chanctx_conf *ctx) | |
1516 | { | |
1517 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
fe0f2de3 IP |
1518 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
1519 | struct iwl_mvm_phy_ctxt *phy_ctxt; | |
8ca151b5 JB |
1520 | int ret; |
1521 | ||
53a9d61e | 1522 | IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); |
fe0f2de3 | 1523 | |
8ca151b5 | 1524 | mutex_lock(&mvm->mutex); |
fe0f2de3 IP |
1525 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
1526 | if (!phy_ctxt) { | |
1527 | ret = -ENOSPC; | |
1528 | goto out; | |
1529 | } | |
8ca151b5 | 1530 | |
53a9d61e IP |
1531 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def, |
1532 | ctx->rx_chains_static, | |
1533 | ctx->rx_chains_dynamic); | |
fe0f2de3 IP |
1534 | if (ret) { |
1535 | IWL_ERR(mvm, "Failed to add PHY context\n"); | |
1536 | goto out; | |
1537 | } | |
1538 | ||
53a9d61e | 1539 | iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt); |
fe0f2de3 IP |
1540 | *phy_ctxt_id = phy_ctxt->id; |
1541 | out: | |
8ca151b5 JB |
1542 | mutex_unlock(&mvm->mutex); |
1543 | return ret; | |
1544 | } | |
1545 | ||
1546 | static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, | |
1547 | struct ieee80211_chanctx_conf *ctx) | |
1548 | { | |
1549 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
fe0f2de3 IP |
1550 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
1551 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; | |
8ca151b5 JB |
1552 | |
1553 | mutex_lock(&mvm->mutex); | |
fe0f2de3 | 1554 | iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); |
8ca151b5 JB |
1555 | mutex_unlock(&mvm->mutex); |
1556 | } | |
1557 | ||
1558 | static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, | |
1559 | struct ieee80211_chanctx_conf *ctx, | |
1560 | u32 changed) | |
1561 | { | |
1562 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
fe0f2de3 IP |
1563 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
1564 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; | |
8ca151b5 | 1565 | |
31d385ae IP |
1566 | if (WARN_ONCE((phy_ctxt->ref > 1) && |
1567 | (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | | |
1568 | IEEE80211_CHANCTX_CHANGE_RX_CHAINS | | |
1569 | IEEE80211_CHANCTX_CHANGE_RADAR)), | |
1570 | "Cannot change PHY. Ref=%d, changed=0x%X\n", | |
1571 | phy_ctxt->ref, changed)) | |
1572 | return; | |
1573 | ||
8ca151b5 JB |
1574 | mutex_lock(&mvm->mutex); |
1575 | iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def, | |
1576 | ctx->rx_chains_static, | |
1577 | ctx->rx_chains_dynamic); | |
8e484f0b | 1578 | iwl_mvm_bt_coex_vif_change(mvm); |
8ca151b5 JB |
1579 | mutex_unlock(&mvm->mutex); |
1580 | } | |
1581 | ||
1582 | static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, | |
1583 | struct ieee80211_vif *vif, | |
1584 | struct ieee80211_chanctx_conf *ctx) | |
1585 | { | |
1586 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
fe0f2de3 IP |
1587 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
1588 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; | |
8ca151b5 JB |
1589 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
1590 | int ret; | |
1591 | ||
1592 | mutex_lock(&mvm->mutex); | |
1593 | ||
fe0f2de3 | 1594 | mvmvif->phy_ctxt = phy_ctxt; |
8ca151b5 JB |
1595 | |
1596 | switch (vif->type) { | |
1597 | case NL80211_IFTYPE_AP: | |
5023d966 | 1598 | case NL80211_IFTYPE_ADHOC: |
8ca151b5 JB |
1599 | /* |
1600 | * The AP binding flow is handled as part of the start_ap flow | |
5023d966 | 1601 | * (in bss_info_changed), similarly for IBSS. |
8ca151b5 JB |
1602 | */ |
1603 | ret = 0; | |
1604 | goto out_unlock; | |
1605 | case NL80211_IFTYPE_STATION: | |
8ca151b5 JB |
1606 | case NL80211_IFTYPE_MONITOR: |
1607 | break; | |
1608 | default: | |
1609 | ret = -EINVAL; | |
1610 | goto out_unlock; | |
1611 | } | |
1612 | ||
1613 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
1614 | if (ret) | |
1615 | goto out_unlock; | |
1616 | ||
1617 | /* | |
1618 | * Setting the quota at this stage is only required for monitor | |
1619 | * interfaces. For the other types, the bss_info changed flow | |
1620 | * will handle quota settings. | |
1621 | */ | |
1622 | if (vif->type == NL80211_IFTYPE_MONITOR) { | |
1e1391ca | 1623 | mvmvif->monitor_active = true; |
8ca151b5 JB |
1624 | ret = iwl_mvm_update_quotas(mvm, vif); |
1625 | if (ret) | |
1626 | goto out_remove_binding; | |
1627 | } | |
1628 | ||
1629 | goto out_unlock; | |
1630 | ||
1631 | out_remove_binding: | |
1632 | iwl_mvm_binding_remove_vif(mvm, vif); | |
1633 | out_unlock: | |
1634 | mutex_unlock(&mvm->mutex); | |
1635 | if (ret) | |
1636 | mvmvif->phy_ctxt = NULL; | |
1637 | return ret; | |
1638 | } | |
1639 | ||
1640 | static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, | |
1641 | struct ieee80211_vif *vif, | |
1642 | struct ieee80211_chanctx_conf *ctx) | |
1643 | { | |
1644 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1645 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1646 | ||
1647 | mutex_lock(&mvm->mutex); | |
1648 | ||
1649 | iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data); | |
1650 | ||
8ca151b5 | 1651 | switch (vif->type) { |
5023d966 JB |
1652 | case NL80211_IFTYPE_AP: |
1653 | case NL80211_IFTYPE_ADHOC: | |
1654 | goto out_unlock; | |
8ca151b5 | 1655 | case NL80211_IFTYPE_MONITOR: |
1e1391ca IP |
1656 | mvmvif->monitor_active = false; |
1657 | iwl_mvm_update_quotas(mvm, NULL); | |
8ca151b5 JB |
1658 | break; |
1659 | default: | |
1660 | break; | |
1661 | } | |
1662 | ||
1e1391ca | 1663 | iwl_mvm_binding_remove_vif(mvm, vif); |
8ca151b5 JB |
1664 | out_unlock: |
1665 | mvmvif->phy_ctxt = NULL; | |
1666 | mutex_unlock(&mvm->mutex); | |
1667 | } | |
1668 | ||
1669 | static int iwl_mvm_set_tim(struct ieee80211_hw *hw, | |
1670 | struct ieee80211_sta *sta, | |
1671 | bool set) | |
1672 | { | |
1673 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1674 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; | |
1675 | ||
1676 | if (!mvm_sta || !mvm_sta->vif) { | |
1677 | IWL_ERR(mvm, "Station is not associated to a vif\n"); | |
1678 | return -EINVAL; | |
1679 | } | |
1680 | ||
1681 | return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif); | |
1682 | } | |
1683 | ||
507cadf2 DS |
1684 | #ifdef CONFIG_NL80211_TESTMODE |
1685 | static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { | |
1686 | [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, | |
1687 | [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, | |
f6c6ad42 | 1688 | [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, |
507cadf2 DS |
1689 | }; |
1690 | ||
1691 | static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, | |
1692 | struct ieee80211_vif *vif, | |
1693 | void *data, int len) | |
1694 | { | |
1695 | struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; | |
1696 | int err; | |
1697 | u32 noa_duration; | |
1698 | ||
1699 | err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy); | |
1700 | if (err) | |
1701 | return err; | |
1702 | ||
1703 | if (!tb[IWL_MVM_TM_ATTR_CMD]) | |
1704 | return -EINVAL; | |
1705 | ||
1706 | switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { | |
1707 | case IWL_MVM_TM_CMD_SET_NOA: | |
1708 | if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || | |
1709 | !vif->bss_conf.enable_beacon || | |
1710 | !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) | |
1711 | return -EINVAL; | |
1712 | ||
1713 | noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); | |
1714 | if (noa_duration >= vif->bss_conf.beacon_int) | |
1715 | return -EINVAL; | |
1716 | ||
1717 | mvm->noa_duration = noa_duration; | |
1718 | mvm->noa_vif = vif; | |
1719 | ||
1720 | return iwl_mvm_update_quotas(mvm, NULL); | |
f6c6ad42 JB |
1721 | case IWL_MVM_TM_CMD_SET_BEACON_FILTER: |
1722 | /* must be associated client vif - ignore authorized */ | |
1723 | if (!vif || vif->type != NL80211_IFTYPE_STATION || | |
1724 | !vif->bss_conf.assoc || !vif->bss_conf.dtim_period || | |
1725 | !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) | |
1726 | return -EINVAL; | |
1727 | ||
1728 | if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) | |
1729 | return iwl_mvm_enable_beacon_filter(mvm, vif); | |
1730 | return iwl_mvm_disable_beacon_filter(mvm, vif); | |
507cadf2 DS |
1731 | } |
1732 | ||
1733 | return -EOPNOTSUPP; | |
1734 | } | |
1735 | ||
1736 | static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, | |
1737 | struct ieee80211_vif *vif, | |
1738 | void *data, int len) | |
1739 | { | |
1740 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1741 | int err; | |
1742 | ||
1743 | mutex_lock(&mvm->mutex); | |
1744 | err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); | |
1745 | mutex_unlock(&mvm->mutex); | |
1746 | ||
1747 | return err; | |
1748 | } | |
1749 | #endif | |
1750 | ||
8ca151b5 JB |
1751 | struct ieee80211_ops iwl_mvm_hw_ops = { |
1752 | .tx = iwl_mvm_mac_tx, | |
1753 | .ampdu_action = iwl_mvm_mac_ampdu_action, | |
1754 | .start = iwl_mvm_mac_start, | |
1755 | .restart_complete = iwl_mvm_mac_restart_complete, | |
1756 | .stop = iwl_mvm_mac_stop, | |
1757 | .add_interface = iwl_mvm_mac_add_interface, | |
1758 | .remove_interface = iwl_mvm_mac_remove_interface, | |
1759 | .config = iwl_mvm_mac_config, | |
1760 | .configure_filter = iwl_mvm_configure_filter, | |
1761 | .bss_info_changed = iwl_mvm_bss_info_changed, | |
1762 | .hw_scan = iwl_mvm_mac_hw_scan, | |
1763 | .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, | |
1764 | .sta_state = iwl_mvm_mac_sta_state, | |
1765 | .sta_notify = iwl_mvm_mac_sta_notify, | |
1766 | .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, | |
1767 | .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, | |
1768 | .conf_tx = iwl_mvm_mac_conf_tx, | |
1769 | .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, | |
35a000b7 DS |
1770 | .sched_scan_start = iwl_mvm_mac_sched_scan_start, |
1771 | .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, | |
8ca151b5 JB |
1772 | .set_key = iwl_mvm_mac_set_key, |
1773 | .update_tkip_key = iwl_mvm_mac_update_tkip_key, | |
1774 | .remain_on_channel = iwl_mvm_roc, | |
1775 | .cancel_remain_on_channel = iwl_mvm_cancel_roc, | |
8ca151b5 JB |
1776 | .add_chanctx = iwl_mvm_add_chanctx, |
1777 | .remove_chanctx = iwl_mvm_remove_chanctx, | |
1778 | .change_chanctx = iwl_mvm_change_chanctx, | |
1779 | .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, | |
1780 | .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, | |
1781 | ||
5023d966 JB |
1782 | .start_ap = iwl_mvm_start_ap_ibss, |
1783 | .stop_ap = iwl_mvm_stop_ap_ibss, | |
1784 | .join_ibss = iwl_mvm_start_ap_ibss, | |
1785 | .leave_ibss = iwl_mvm_stop_ap_ibss, | |
8ca151b5 JB |
1786 | |
1787 | .set_tim = iwl_mvm_set_tim, | |
1788 | ||
507cadf2 DS |
1789 | CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) |
1790 | ||
8ca151b5 JB |
1791 | #ifdef CONFIG_PM_SLEEP |
1792 | /* look at d3.c */ | |
1793 | .suspend = iwl_mvm_suspend, | |
1794 | .resume = iwl_mvm_resume, | |
1795 | .set_wakeup = iwl_mvm_set_wakeup, | |
1796 | .set_rekey_data = iwl_mvm_set_rekey_data, | |
1797 | #if IS_ENABLED(CONFIG_IPV6) | |
1798 | .ipv6_addr_change = iwl_mvm_ipv6_addr_change, | |
1799 | #endif | |
1800 | .set_default_unicast_key = iwl_mvm_set_default_unicast_key, | |
1801 | #endif | |
1802 | }; |