]>
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> |
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 | 205 | |
3e56eadf JB |
206 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD) |
207 | hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; | |
208 | ||
8ca151b5 JB |
209 | hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; |
210 | hw->wiphy->n_iface_combinations = | |
211 | ARRAY_SIZE(iwl_mvm_iface_combinations); | |
212 | ||
c451e6d4 | 213 | hw->wiphy->max_remain_on_channel_duration = 10000; |
8ca151b5 JB |
214 | hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; |
215 | ||
216 | /* Extract MAC address */ | |
217 | memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); | |
218 | hw->wiphy->addresses = mvm->addresses; | |
219 | hw->wiphy->n_addresses = 1; | |
831e85f3 IP |
220 | |
221 | /* Extract additional MAC addresses if available */ | |
222 | num_mac = (mvm->nvm_data->n_hw_addrs > 1) ? | |
223 | min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1; | |
224 | ||
225 | for (i = 1; i < num_mac; i++) { | |
226 | memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr, | |
8ca151b5 | 227 | ETH_ALEN); |
831e85f3 | 228 | mvm->addresses[i].addr[5]++; |
8ca151b5 JB |
229 | hw->wiphy->n_addresses++; |
230 | } | |
231 | ||
fe0f2de3 IP |
232 | iwl_mvm_reset_phy_ctxts(mvm); |
233 | ||
20f1a5de DS |
234 | hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm); |
235 | ||
8ca151b5 JB |
236 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; |
237 | ||
238 | if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels) | |
239 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = | |
240 | &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ]; | |
241 | if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) | |
242 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = | |
243 | &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ]; | |
244 | ||
245 | hw->wiphy->hw_version = mvm->trans->hw_id; | |
246 | ||
ade50652 | 247 | if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) |
8ca151b5 JB |
248 | hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; |
249 | else | |
250 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; | |
251 | ||
35a000b7 DS |
252 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) { |
253 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; | |
254 | hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; | |
255 | hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES; | |
256 | /* we create the 802.11 header and zero length SSID IE. */ | |
257 | hw->wiphy->max_sched_scan_ie_len = | |
258 | SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2; | |
259 | } | |
260 | ||
8ca151b5 | 261 | hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | |
61f6325d HD |
262 | NL80211_FEATURE_P2P_GO_OPPPS | |
263 | NL80211_FEATURE_LOW_PRIORITY_SCAN; | |
8ca151b5 JB |
264 | |
265 | mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; | |
266 | ||
e36e5433 | 267 | /* currently FW API supports only one optional cipher scheme */ |
9ddca860 | 268 | if (mvm->fw->cs[0].cipher) { |
e36e5433 | 269 | mvm->hw->n_cipher_schemes = 1; |
9ddca860 | 270 | mvm->hw->cipher_schemes = &mvm->fw->cs[0]; |
e36e5433 MS |
271 | } |
272 | ||
8ca151b5 JB |
273 | #ifdef CONFIG_PM_SLEEP |
274 | if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len && | |
275 | mvm->trans->ops->d3_suspend && | |
276 | mvm->trans->ops->d3_resume && | |
277 | device_can_wakeup(mvm->trans->dev)) { | |
964dc9e2 JB |
278 | mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT | |
279 | WIPHY_WOWLAN_DISCONNECT | | |
280 | WIPHY_WOWLAN_EAP_IDENTITY_REQ | | |
281 | WIPHY_WOWLAN_RFKILL_RELEASE; | |
8ca151b5 | 282 | if (!iwlwifi_mod_params.sw_crypto) |
964dc9e2 JB |
283 | mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | |
284 | WIPHY_WOWLAN_GTK_REKEY_FAILURE | | |
285 | WIPHY_WOWLAN_4WAY_HANDSHAKE; | |
286 | ||
287 | mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; | |
288 | mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; | |
289 | mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; | |
290 | mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support; | |
291 | hw->wiphy->wowlan = &mvm->wowlan; | |
8ca151b5 JB |
292 | } |
293 | #endif | |
294 | ||
295 | ret = iwl_mvm_leds_init(mvm); | |
296 | if (ret) | |
297 | return ret; | |
298 | ||
b7327d89 EG |
299 | ret = ieee80211_register_hw(mvm->hw); |
300 | if (ret) | |
301 | iwl_mvm_leds_exit(mvm); | |
302 | ||
303 | return ret; | |
8ca151b5 JB |
304 | } |
305 | ||
306 | static void iwl_mvm_mac_tx(struct ieee80211_hw *hw, | |
307 | struct ieee80211_tx_control *control, | |
308 | struct sk_buff *skb) | |
309 | { | |
310 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
3e56eadf JB |
311 | struct ieee80211_sta *sta = control->sta; |
312 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
313 | struct ieee80211_hdr *hdr = (void *)skb->data; | |
8ca151b5 | 314 | |
9ee718aa EL |
315 | if (iwl_mvm_is_radio_killed(mvm)) { |
316 | IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); | |
8ca151b5 JB |
317 | goto drop; |
318 | } | |
319 | ||
398e8c6c | 320 | if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE && |
8ca151b5 JB |
321 | !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status)) |
322 | goto drop; | |
323 | ||
3e56eadf JB |
324 | /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */ |
325 | if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER && | |
326 | ieee80211_is_mgmt(hdr->frame_control) && | |
327 | !ieee80211_is_deauth(hdr->frame_control) && | |
328 | !ieee80211_is_disassoc(hdr->frame_control) && | |
329 | !ieee80211_is_action(hdr->frame_control))) | |
330 | sta = NULL; | |
331 | ||
332 | if (sta) { | |
333 | if (iwl_mvm_tx_skb(mvm, skb, sta)) | |
8ca151b5 JB |
334 | goto drop; |
335 | return; | |
336 | } | |
337 | ||
338 | if (iwl_mvm_tx_skb_non_sta(mvm, skb)) | |
339 | goto drop; | |
340 | return; | |
341 | drop: | |
342 | ieee80211_free_txskb(hw, skb); | |
343 | } | |
344 | ||
345 | static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, | |
346 | struct ieee80211_vif *vif, | |
347 | enum ieee80211_ampdu_mlme_action action, | |
348 | struct ieee80211_sta *sta, u16 tid, | |
349 | u16 *ssn, u8 buf_size) | |
350 | { | |
351 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
352 | int ret; | |
353 | ||
354 | IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", | |
355 | sta->addr, tid, action); | |
356 | ||
357 | if (!(mvm->nvm_data->sku_cap_11n_enable)) | |
358 | return -EACCES; | |
359 | ||
360 | mutex_lock(&mvm->mutex); | |
361 | ||
362 | switch (action) { | |
363 | case IEEE80211_AMPDU_RX_START: | |
364 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) { | |
365 | ret = -EINVAL; | |
366 | break; | |
367 | } | |
368 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true); | |
369 | break; | |
370 | case IEEE80211_AMPDU_RX_STOP: | |
371 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false); | |
372 | break; | |
373 | case IEEE80211_AMPDU_TX_START: | |
5d158efa EG |
374 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) { |
375 | ret = -EINVAL; | |
376 | break; | |
377 | } | |
8ca151b5 JB |
378 | ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); |
379 | break; | |
380 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
e3d9e7ce EG |
381 | ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); |
382 | break; | |
8ca151b5 JB |
383 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
384 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
e3d9e7ce | 385 | ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); |
8ca151b5 JB |
386 | break; |
387 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
388 | ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size); | |
389 | break; | |
390 | default: | |
391 | WARN_ON_ONCE(1); | |
392 | ret = -EINVAL; | |
393 | break; | |
394 | } | |
395 | mutex_unlock(&mvm->mutex); | |
396 | ||
397 | return ret; | |
398 | } | |
399 | ||
400 | static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, | |
401 | struct ieee80211_vif *vif) | |
402 | { | |
403 | struct iwl_mvm *mvm = data; | |
404 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
405 | ||
406 | mvmvif->uploaded = false; | |
407 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; | |
408 | ||
409 | /* does this make sense at all? */ | |
410 | mvmvif->color++; | |
411 | ||
412 | spin_lock_bh(&mvm->time_event_lock); | |
413 | iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); | |
414 | spin_unlock_bh(&mvm->time_event_lock); | |
415 | ||
fe0f2de3 | 416 | mvmvif->phy_ctxt = NULL; |
8ca151b5 JB |
417 | } |
418 | ||
419 | static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) | |
420 | { | |
421 | iwl_trans_stop_device(mvm->trans); | |
8ca151b5 JB |
422 | |
423 | mvm->scan_status = IWL_MVM_SCAN_NONE; | |
424 | ||
425 | /* just in case one was running */ | |
426 | ieee80211_remain_on_channel_expired(mvm->hw); | |
427 | ||
428 | ieee80211_iterate_active_interfaces_atomic( | |
429 | mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL, | |
430 | iwl_mvm_cleanup_iterator, mvm); | |
431 | ||
fe0f2de3 IP |
432 | mvm->p2p_device_vif = NULL; |
433 | ||
434 | iwl_mvm_reset_phy_ctxts(mvm); | |
8ca151b5 JB |
435 | memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); |
436 | memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained)); | |
437 | ||
438 | ieee80211_wake_queues(mvm->hw); | |
439 | ||
440 | mvm->vif_count = 0; | |
113a0447 | 441 | mvm->rx_ba_sessions = 0; |
8ca151b5 JB |
442 | } |
443 | ||
444 | static int iwl_mvm_mac_start(struct ieee80211_hw *hw) | |
445 | { | |
446 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
447 | int ret; | |
448 | ||
449 | mutex_lock(&mvm->mutex); | |
450 | ||
451 | /* Clean up some internal and mac80211 state on restart */ | |
452 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) | |
453 | iwl_mvm_restart_cleanup(mvm); | |
454 | ||
455 | ret = iwl_mvm_up(mvm); | |
456 | mutex_unlock(&mvm->mutex); | |
457 | ||
458 | return ret; | |
459 | } | |
460 | ||
461 | static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw) | |
462 | { | |
463 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
464 | int ret; | |
465 | ||
466 | mutex_lock(&mvm->mutex); | |
467 | ||
468 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); | |
469 | ret = iwl_mvm_update_quotas(mvm, NULL); | |
470 | if (ret) | |
471 | IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", | |
472 | ret); | |
473 | ||
474 | mutex_unlock(&mvm->mutex); | |
475 | } | |
476 | ||
477 | static void iwl_mvm_mac_stop(struct ieee80211_hw *hw) | |
478 | { | |
479 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
480 | ||
481 | flush_work(&mvm->async_handlers_wk); | |
482 | ||
483 | mutex_lock(&mvm->mutex); | |
484 | /* async_handlers_wk is now blocked */ | |
485 | ||
486 | /* | |
487 | * The work item could be running or queued if the | |
488 | * ROC time event stops just as we get here. | |
489 | */ | |
490 | cancel_work_sync(&mvm->roc_done_wk); | |
491 | ||
492 | iwl_trans_stop_device(mvm->trans); | |
8ca151b5 JB |
493 | |
494 | iwl_mvm_async_handlers_purge(mvm); | |
495 | /* async_handlers_list is empty and will stay empty: HW is stopped */ | |
496 | ||
497 | /* the fw is stopped, the aux sta is dead: clean up driver state */ | |
498 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); | |
499 | ||
500 | mutex_unlock(&mvm->mutex); | |
501 | ||
502 | /* | |
503 | * The worker might have been waiting for the mutex, let it run and | |
504 | * discover that its list is now empty. | |
505 | */ | |
506 | cancel_work_sync(&mvm->async_handlers_wk); | |
507 | } | |
508 | ||
8ca151b5 JB |
509 | static void iwl_mvm_power_update_iterator(void *data, u8 *mac, |
510 | struct ieee80211_vif *vif) | |
511 | { | |
512 | struct iwl_mvm *mvm = data; | |
513 | ||
514 | iwl_mvm_power_update_mode(mvm, vif); | |
515 | } | |
516 | ||
fe0f2de3 IP |
517 | static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) |
518 | { | |
519 | u16 i; | |
520 | ||
521 | lockdep_assert_held(&mvm->mutex); | |
522 | ||
523 | for (i = 0; i < NUM_PHY_CTX; i++) | |
524 | if (!mvm->phy_ctxts[i].ref) | |
525 | return &mvm->phy_ctxts[i]; | |
526 | ||
527 | IWL_ERR(mvm, "No available PHY context\n"); | |
528 | return NULL; | |
529 | } | |
530 | ||
ee9c6cb0 EG |
531 | static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
532 | s8 tx_power) | |
533 | { | |
534 | /* FW is in charge of regulatory enforcement */ | |
535 | struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = { | |
536 | .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id, | |
537 | .pwr_restriction = cpu_to_le16(tx_power), | |
538 | }; | |
539 | ||
540 | return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC, | |
541 | sizeof(reduce_txpwr_cmd), | |
542 | &reduce_txpwr_cmd); | |
543 | } | |
544 | ||
8ca151b5 JB |
545 | static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, |
546 | struct ieee80211_vif *vif) | |
547 | { | |
548 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
549 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
550 | int ret; | |
551 | ||
552 | /* | |
553 | * Not much to do here. The stack will not allow interface | |
554 | * types or combinations that we didn't advertise, so we | |
555 | * don't really have to check the types. | |
556 | */ | |
557 | ||
558 | mutex_lock(&mvm->mutex); | |
559 | ||
e89044d7 | 560 | /* Allocate resources for the MAC context, and add it to the fw */ |
8ca151b5 JB |
561 | ret = iwl_mvm_mac_ctxt_init(mvm, vif); |
562 | if (ret) | |
563 | goto out_unlock; | |
564 | ||
1c2abf72 | 565 | /* Counting number of interfaces is needed for legacy PM */ |
ea183d02 IP |
566 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) |
567 | mvm->vif_count++; | |
ea183d02 | 568 | |
8ca151b5 JB |
569 | /* |
570 | * The AP binding flow can be done only after the beacon | |
571 | * template is configured (which happens only in the mac80211 | |
572 | * start_ap() flow), and adding the broadcast station can happen | |
573 | * only after the binding. | |
574 | * In addition, since modifying the MAC before adding a bcast | |
575 | * station is not allowed by the FW, delay the adding of MAC context to | |
576 | * the point where we can also add the bcast station. | |
577 | * In short: there's not much we can do at this point, other than | |
578 | * allocating resources :) | |
579 | */ | |
5023d966 JB |
580 | if (vif->type == NL80211_IFTYPE_AP || |
581 | vif->type == NL80211_IFTYPE_ADHOC) { | |
8ca151b5 JB |
582 | u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif); |
583 | ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, | |
584 | qmask); | |
585 | if (ret) { | |
586 | IWL_ERR(mvm, "Failed to allocate bcast sta\n"); | |
587 | goto out_release; | |
588 | } | |
589 | ||
77740cb4 | 590 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
8ca151b5 JB |
591 | goto out_unlock; |
592 | } | |
593 | ||
8ca151b5 JB |
594 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
595 | if (ret) | |
596 | goto out_release; | |
597 | ||
1c2abf72 | 598 | iwl_mvm_power_disable(mvm, vif); |
8ca151b5 | 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--; | |
1c2abf72 AB |
659 | |
660 | /* TODO: remove this when legacy PM will be discarded */ | |
4bf881f5 AB |
661 | ieee80211_iterate_active_interfaces( |
662 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
663 | iwl_mvm_power_update_iterator, mvm); | |
1c2abf72 | 664 | |
8ca151b5 JB |
665 | iwl_mvm_mac_ctxt_release(mvm, vif); |
666 | out_unlock: | |
667 | mutex_unlock(&mvm->mutex); | |
668 | ||
669 | return ret; | |
670 | } | |
671 | ||
38a12b5b JB |
672 | static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, |
673 | struct ieee80211_vif *vif) | |
8ca151b5 | 674 | { |
8ca151b5 JB |
675 | u32 tfd_msk = 0, ac; |
676 | ||
677 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) | |
678 | if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE) | |
679 | tfd_msk |= BIT(vif->hw_queue[ac]); | |
680 | ||
681 | if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE) | |
682 | tfd_msk |= BIT(vif->cab_queue); | |
683 | ||
684 | if (tfd_msk) { | |
685 | mutex_lock(&mvm->mutex); | |
686 | iwl_mvm_flush_tx_path(mvm, tfd_msk, true); | |
687 | mutex_unlock(&mvm->mutex); | |
688 | } | |
689 | ||
690 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
691 | /* | |
692 | * Flush the ROC worker which will flush the OFFCHANNEL queue. | |
693 | * We assume here that all the packets sent to the OFFCHANNEL | |
694 | * queue are sent in ROC session. | |
695 | */ | |
696 | flush_work(&mvm->roc_done_wk); | |
697 | } else { | |
698 | /* | |
699 | * By now, all the AC queues are empty. The AGG queues are | |
700 | * empty too. We already got all the Tx responses for all the | |
701 | * packets in the queues. The drain work can have been | |
0742a75a | 702 | * triggered. Flush it. |
8ca151b5 JB |
703 | */ |
704 | flush_work(&mvm->sta_drained_wk); | |
705 | } | |
38a12b5b JB |
706 | } |
707 | ||
708 | static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, | |
709 | struct ieee80211_vif *vif) | |
710 | { | |
711 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
712 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
713 | ||
714 | iwl_mvm_prepare_mac_removal(mvm, vif); | |
8ca151b5 JB |
715 | |
716 | mutex_lock(&mvm->mutex); | |
717 | ||
7df15b1e HG |
718 | if (mvm->bf_allowed_vif == mvmvif) { |
719 | mvm->bf_allowed_vif = NULL; | |
a20fd398 AO |
720 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
721 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); | |
7df15b1e HG |
722 | } |
723 | ||
63494374 JB |
724 | iwl_mvm_vif_dbgfs_clean(mvm, vif); |
725 | ||
8ca151b5 JB |
726 | /* |
727 | * For AP/GO interface, the tear down of the resources allocated to the | |
38a12b5b | 728 | * interface is be handled as part of the stop_ap flow. |
8ca151b5 | 729 | */ |
5023d966 JB |
730 | if (vif->type == NL80211_IFTYPE_AP || |
731 | vif->type == NL80211_IFTYPE_ADHOC) { | |
507cadf2 DS |
732 | #ifdef CONFIG_NL80211_TESTMODE |
733 | if (vif == mvm->noa_vif) { | |
734 | mvm->noa_vif = NULL; | |
735 | mvm->noa_duration = 0; | |
736 | } | |
737 | #endif | |
8ca151b5 JB |
738 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); |
739 | goto out_release; | |
740 | } | |
741 | ||
742 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
743 | mvm->p2p_device_vif = NULL; | |
744 | iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta); | |
745 | iwl_mvm_binding_remove_vif(mvm, vif); | |
fe0f2de3 | 746 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
8ca151b5 JB |
747 | mvmvif->phy_ctxt = NULL; |
748 | } | |
749 | ||
5ee2b215 | 750 | if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE) |
8ca151b5 | 751 | mvm->vif_count--; |
1c2abf72 AB |
752 | |
753 | /* TODO: remove this when legacy PM will be discarded */ | |
754 | ieee80211_iterate_active_interfaces( | |
755 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
756 | iwl_mvm_power_update_iterator, mvm); | |
8ca151b5 JB |
757 | |
758 | iwl_mvm_mac_ctxt_remove(mvm, vif); | |
759 | ||
760 | out_release: | |
761 | iwl_mvm_mac_ctxt_release(mvm, vif); | |
762 | mutex_unlock(&mvm->mutex); | |
763 | } | |
764 | ||
765 | static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed) | |
88f2fd73 | 766 | { |
8ca151b5 JB |
767 | return 0; |
768 | } | |
769 | ||
e59647ea EP |
770 | struct iwl_mvm_mc_iter_data { |
771 | struct iwl_mvm *mvm; | |
772 | int port_id; | |
773 | }; | |
774 | ||
775 | static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac, | |
776 | struct ieee80211_vif *vif) | |
777 | { | |
778 | struct iwl_mvm_mc_iter_data *data = _data; | |
779 | struct iwl_mvm *mvm = data->mvm; | |
780 | struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd; | |
781 | int ret, len; | |
782 | ||
783 | /* if we don't have free ports, mcast frames will be dropped */ | |
784 | if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM)) | |
785 | return; | |
786 | ||
787 | if (vif->type != NL80211_IFTYPE_STATION || | |
788 | !vif->bss_conf.assoc) | |
789 | return; | |
790 | ||
791 | cmd->port_id = data->port_id++; | |
792 | memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); | |
793 | len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); | |
794 | ||
795 | ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC, len, cmd); | |
796 | if (ret) | |
797 | IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret); | |
798 | } | |
799 | ||
800 | static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm) | |
801 | { | |
802 | struct iwl_mvm_mc_iter_data iter_data = { | |
803 | .mvm = mvm, | |
88f2fd73 MG |
804 | }; |
805 | ||
e59647ea EP |
806 | lockdep_assert_held(&mvm->mutex); |
807 | ||
808 | if (WARN_ON_ONCE(!mvm->mcast_filter_cmd)) | |
809 | return; | |
810 | ||
811 | ieee80211_iterate_active_interfaces( | |
812 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
813 | iwl_mvm_mc_iface_iterator, &iter_data); | |
88f2fd73 MG |
814 | } |
815 | ||
e59647ea EP |
816 | static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw, |
817 | struct netdev_hw_addr_list *mc_list) | |
8ca151b5 | 818 | { |
e59647ea EP |
819 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
820 | struct iwl_mcast_filter_cmd *cmd; | |
821 | struct netdev_hw_addr *addr; | |
822 | int addr_count = netdev_hw_addr_list_count(mc_list); | |
823 | bool pass_all = false; | |
824 | int len; | |
825 | ||
826 | if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) { | |
827 | pass_all = true; | |
828 | addr_count = 0; | |
829 | } | |
830 | ||
831 | len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); | |
832 | cmd = kzalloc(len, GFP_ATOMIC); | |
833 | if (!cmd) | |
834 | return 0; | |
835 | ||
836 | if (pass_all) { | |
837 | cmd->pass_all = 1; | |
838 | return (u64)(unsigned long)cmd; | |
839 | } | |
840 | ||
841 | netdev_hw_addr_list_for_each(addr, mc_list) { | |
842 | IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n", | |
843 | cmd->count, addr->addr); | |
844 | memcpy(&cmd->addr_list[cmd->count * ETH_ALEN], | |
845 | addr->addr, ETH_ALEN); | |
846 | cmd->count++; | |
847 | } | |
848 | ||
849 | return (u64)(unsigned long)cmd; | |
8ca151b5 JB |
850 | } |
851 | ||
852 | static void iwl_mvm_configure_filter(struct ieee80211_hw *hw, | |
853 | unsigned int changed_flags, | |
854 | unsigned int *total_flags, | |
855 | u64 multicast) | |
856 | { | |
e59647ea EP |
857 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
858 | struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; | |
8ca151b5 | 859 | |
e59647ea | 860 | mutex_lock(&mvm->mutex); |
51b6b9e0 | 861 | |
e59647ea EP |
862 | /* replace previous configuration */ |
863 | kfree(mvm->mcast_filter_cmd); | |
864 | mvm->mcast_filter_cmd = cmd; | |
51b6b9e0 | 865 | |
e59647ea EP |
866 | if (!cmd) |
867 | goto out; | |
51b6b9e0 | 868 | |
e59647ea EP |
869 | iwl_mvm_recalc_multicast(mvm); |
870 | out: | |
871 | mutex_unlock(&mvm->mutex); | |
872 | *total_flags = 0; | |
51b6b9e0 EG |
873 | } |
874 | ||
c87163b9 EP |
875 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
876 | struct iwl_bcast_iter_data { | |
877 | struct iwl_mvm *mvm; | |
878 | struct iwl_bcast_filter_cmd *cmd; | |
879 | u8 current_filter; | |
880 | }; | |
881 | ||
882 | static void | |
883 | iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif, | |
884 | const struct iwl_fw_bcast_filter *in_filter, | |
885 | struct iwl_fw_bcast_filter *out_filter) | |
886 | { | |
887 | struct iwl_fw_bcast_filter_attr *attr; | |
888 | int i; | |
889 | ||
890 | memcpy(out_filter, in_filter, sizeof(*out_filter)); | |
891 | ||
892 | for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) { | |
893 | attr = &out_filter->attrs[i]; | |
894 | ||
895 | if (!attr->mask) | |
896 | break; | |
897 | ||
898 | out_filter->num_attrs++; | |
899 | } | |
900 | } | |
901 | ||
902 | static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac, | |
903 | struct ieee80211_vif *vif) | |
904 | { | |
905 | struct iwl_bcast_iter_data *data = _data; | |
906 | struct iwl_mvm *mvm = data->mvm; | |
907 | struct iwl_bcast_filter_cmd *cmd = data->cmd; | |
908 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
909 | struct iwl_fw_bcast_mac *bcast_mac; | |
910 | int i; | |
911 | ||
912 | if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs))) | |
913 | return; | |
914 | ||
915 | bcast_mac = &cmd->macs[mvmvif->id]; | |
916 | ||
917 | /* enable filtering only for associated stations */ | |
918 | if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc) | |
919 | return; | |
920 | ||
921 | bcast_mac->default_discard = 1; | |
922 | ||
923 | /* copy all configured filters */ | |
924 | for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) { | |
925 | /* | |
926 | * Make sure we don't exceed our filters limit. | |
927 | * if there is still a valid filter to be configured, | |
928 | * be on the safe side and just allow bcast for this mac. | |
929 | */ | |
930 | if (WARN_ON_ONCE(data->current_filter >= | |
931 | ARRAY_SIZE(cmd->filters))) { | |
932 | bcast_mac->default_discard = 0; | |
933 | bcast_mac->attached_filters = 0; | |
934 | break; | |
935 | } | |
936 | ||
937 | iwl_mvm_set_bcast_filter(vif, | |
938 | &mvm->bcast_filters[i], | |
939 | &cmd->filters[data->current_filter]); | |
940 | ||
941 | /* skip current filter if it contains no attributes */ | |
942 | if (!cmd->filters[data->current_filter].num_attrs) | |
943 | continue; | |
944 | ||
945 | /* attach the filter to current mac */ | |
946 | bcast_mac->attached_filters |= | |
947 | cpu_to_le16(BIT(data->current_filter)); | |
948 | ||
949 | data->current_filter++; | |
950 | } | |
951 | } | |
952 | ||
953 | static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm, | |
954 | struct ieee80211_vif *vif) | |
955 | { | |
956 | /* initialize cmd to pass broadcasts on all vifs */ | |
957 | struct iwl_bcast_filter_cmd cmd = { | |
958 | .disable = 0, | |
959 | .max_bcast_filters = ARRAY_SIZE(cmd.filters), | |
960 | .max_macs = ARRAY_SIZE(cmd.macs), | |
961 | }; | |
962 | struct iwl_bcast_iter_data iter_data = { | |
963 | .mvm = mvm, | |
964 | .cmd = &cmd, | |
965 | }; | |
966 | ||
967 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING)) | |
968 | return 0; | |
969 | ||
970 | /* if no filters are configured, do nothing */ | |
971 | if (!mvm->bcast_filters) | |
972 | return 0; | |
973 | ||
974 | /* configure and attach these filters for each associated sta vif */ | |
975 | ieee80211_iterate_active_interfaces( | |
976 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
977 | iwl_mvm_bcast_filter_iterator, &iter_data); | |
978 | ||
979 | return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, CMD_SYNC, | |
980 | sizeof(cmd), &cmd); | |
981 | } | |
982 | #else | |
983 | static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm, | |
984 | struct ieee80211_vif *vif) | |
985 | { | |
986 | return 0; | |
987 | } | |
988 | #endif | |
989 | ||
8ca151b5 JB |
990 | static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, |
991 | struct ieee80211_vif *vif, | |
992 | struct ieee80211_bss_conf *bss_conf, | |
993 | u32 changes) | |
994 | { | |
995 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
996 | int ret; | |
997 | ||
6e97b0d2 IP |
998 | /* |
999 | * Re-calculate the tsf id, as the master-slave relations depend on the | |
1000 | * beacon interval, which was not known when the station interface was | |
1001 | * added. | |
1002 | */ | |
1003 | if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) | |
1004 | iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); | |
1005 | ||
8ca151b5 JB |
1006 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); |
1007 | if (ret) | |
1008 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); | |
1009 | ||
1010 | if (changes & BSS_CHANGED_ASSOC) { | |
1011 | if (bss_conf->assoc) { | |
1012 | /* add quota for this interface */ | |
1013 | ret = iwl_mvm_update_quotas(mvm, vif); | |
1014 | if (ret) { | |
1015 | IWL_ERR(mvm, "failed to update quotas\n"); | |
1016 | return; | |
1017 | } | |
016d27e1 JB |
1018 | |
1019 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, | |
1020 | &mvm->status)) { | |
1021 | /* | |
1022 | * If we're restarting then the firmware will | |
1023 | * obviously have lost synchronisation with | |
1024 | * the AP. It will attempt to synchronise by | |
1025 | * itself, but we can make it more reliable by | |
1026 | * scheduling a session protection time event. | |
1027 | * | |
1028 | * The firmware needs to receive a beacon to | |
1029 | * catch up with synchronisation, use 110% of | |
1030 | * the beacon interval. | |
1031 | * | |
1032 | * Set a large maximum delay to allow for more | |
1033 | * than a single interface. | |
1034 | */ | |
1035 | u32 dur = (11 * vif->bss_conf.beacon_int) / 10; | |
1036 | iwl_mvm_protect_session(mvm, vif, dur, dur, | |
1037 | 5 * dur); | |
1038 | } | |
1f3b0ff8 LE |
1039 | |
1040 | iwl_mvm_sf_update(mvm, vif, false); | |
175a70b7 | 1041 | iwl_mvm_power_vif_assoc(mvm, vif); |
8ca151b5 | 1042 | } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
1f3b0ff8 LE |
1043 | /* |
1044 | * If update fails - SF might be running in associated | |
1045 | * mode while disassociated - which is forbidden. | |
1046 | */ | |
1047 | WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false), | |
1048 | "Failed to update SF upon disassociation\n"); | |
1049 | ||
8ca151b5 JB |
1050 | /* remove AP station now that the MAC is unassoc */ |
1051 | ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id); | |
1052 | if (ret) | |
1053 | IWL_ERR(mvm, "failed to remove AP station\n"); | |
1054 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; | |
1055 | /* remove quota for this interface */ | |
1056 | ret = iwl_mvm_update_quotas(mvm, NULL); | |
1057 | if (ret) | |
1058 | IWL_ERR(mvm, "failed to update quotas\n"); | |
1059 | } | |
a20fd398 | 1060 | |
e59647ea | 1061 | iwl_mvm_recalc_multicast(mvm); |
c87163b9 | 1062 | iwl_mvm_configure_bcast_filter(mvm, vif); |
e59647ea | 1063 | |
a20fd398 AO |
1064 | /* reset rssi values */ |
1065 | mvmvif->bf_data.ave_beacon_signal = 0; | |
1066 | ||
e8e626ad AB |
1067 | if (!(mvm->fw->ucode_capa.flags & |
1068 | IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT)) { | |
e811ada7 AB |
1069 | /* Workaround for FW bug, otherwise FW disables device |
1070 | * power save upon disassociation | |
1071 | */ | |
1072 | ret = iwl_mvm_power_update_mode(mvm, vif); | |
1073 | if (ret) | |
1074 | IWL_ERR(mvm, "failed to update power mode\n"); | |
1075 | } | |
8e484f0b | 1076 | iwl_mvm_bt_coex_vif_change(mvm); |
f94045ed EG |
1077 | iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, |
1078 | IEEE80211_SMPS_AUTOMATIC); | |
989c6505 | 1079 | } else if (changes & BSS_CHANGED_BEACON_INFO) { |
210a544e JB |
1080 | /* |
1081 | * We received a beacon _after_ association so | |
1082 | * remove the session protection. | |
1083 | */ | |
1084 | iwl_mvm_remove_time_event(mvm, mvmvif, | |
1085 | &mvmvif->time_event_data); | |
51498cf6 AB |
1086 | } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | |
1087 | BSS_CHANGED_QOS)) { | |
4bf881f5 AB |
1088 | ret = iwl_mvm_power_update_mode(mvm, vif); |
1089 | if (ret) | |
1090 | IWL_ERR(mvm, "failed to update power mode\n"); | |
8ca151b5 | 1091 | } |
88f2fd73 MG |
1092 | if (changes & BSS_CHANGED_TXPOWER) { |
1093 | IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n", | |
1094 | bss_conf->txpower); | |
1095 | iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); | |
1096 | } | |
a20fd398 AO |
1097 | |
1098 | if (changes & BSS_CHANGED_CQM) { | |
1099 | IWL_DEBUG_MAC80211(mvm, "cqm info_changed"); | |
1100 | /* reset cqm events tracking */ | |
1101 | mvmvif->bf_data.last_cqm_event = 0; | |
1102 | ret = iwl_mvm_update_beacon_filter(mvm, vif); | |
1103 | if (ret) | |
1104 | IWL_ERR(mvm, "failed to update CQM thresholds\n"); | |
1105 | } | |
8ca151b5 JB |
1106 | } |
1107 | ||
5023d966 JB |
1108 | static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, |
1109 | struct ieee80211_vif *vif) | |
8ca151b5 JB |
1110 | { |
1111 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1112 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1113 | int ret; | |
1114 | ||
1115 | mutex_lock(&mvm->mutex); | |
1116 | ||
1117 | /* Send the beacon template */ | |
1118 | ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif); | |
1119 | if (ret) | |
1120 | goto out_unlock; | |
1121 | ||
6e97b0d2 IP |
1122 | /* |
1123 | * Re-calculate the tsf id, as the master-slave relations depend on the | |
1124 | * beacon interval, which was not known when the AP interface was added. | |
1125 | */ | |
1126 | if (vif->type == NL80211_IFTYPE_AP) | |
1127 | iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); | |
1128 | ||
8ca151b5 JB |
1129 | /* Add the mac context */ |
1130 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); | |
1131 | if (ret) | |
1132 | goto out_unlock; | |
1133 | ||
1134 | /* Perform the binding */ | |
1135 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
1136 | if (ret) | |
1137 | goto out_remove; | |
1138 | ||
5023d966 | 1139 | mvmvif->ap_ibss_active = true; |
8ca151b5 JB |
1140 | |
1141 | /* Send the bcast station. At this stage the TBTT and DTIM time events | |
1142 | * are added and applied to the scheduler */ | |
1143 | ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta); | |
1144 | if (ret) | |
1145 | goto out_unbind; | |
1146 | ||
5691e218 IP |
1147 | /* must be set before quota calculations */ |
1148 | mvmvif->ap_ibss_active = true; | |
1149 | ||
a11e144e IP |
1150 | /* power updated needs to be done before quotas */ |
1151 | mvm->bound_vif_cnt++; | |
1152 | iwl_mvm_power_update_binding(mvm, vif, true); | |
1153 | ||
8ca151b5 JB |
1154 | ret = iwl_mvm_update_quotas(mvm, vif); |
1155 | if (ret) | |
a11e144e | 1156 | goto out_quota_failed; |
8ca151b5 | 1157 | |
5023d966 | 1158 | /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ |
8ca151b5 JB |
1159 | if (vif->p2p && mvm->p2p_device_vif) |
1160 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif); | |
1161 | ||
8e484f0b | 1162 | iwl_mvm_bt_coex_vif_change(mvm); |
dac94da8 | 1163 | |
8ca151b5 JB |
1164 | mutex_unlock(&mvm->mutex); |
1165 | return 0; | |
1166 | ||
a11e144e IP |
1167 | out_quota_failed: |
1168 | mvm->bound_vif_cnt--; | |
1169 | iwl_mvm_power_update_binding(mvm, vif, false); | |
5691e218 | 1170 | mvmvif->ap_ibss_active = false; |
8ca151b5 JB |
1171 | iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta); |
1172 | out_unbind: | |
1173 | iwl_mvm_binding_remove_vif(mvm, vif); | |
1174 | out_remove: | |
1175 | iwl_mvm_mac_ctxt_remove(mvm, vif); | |
1176 | out_unlock: | |
1177 | mutex_unlock(&mvm->mutex); | |
1178 | return ret; | |
1179 | } | |
1180 | ||
5023d966 JB |
1181 | static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, |
1182 | struct ieee80211_vif *vif) | |
8ca151b5 JB |
1183 | { |
1184 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1185 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1186 | ||
38a12b5b JB |
1187 | iwl_mvm_prepare_mac_removal(mvm, vif); |
1188 | ||
8ca151b5 JB |
1189 | mutex_lock(&mvm->mutex); |
1190 | ||
5023d966 | 1191 | mvmvif->ap_ibss_active = false; |
8ca151b5 | 1192 | |
8e484f0b | 1193 | iwl_mvm_bt_coex_vif_change(mvm); |
dac94da8 | 1194 | |
5023d966 | 1195 | /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ |
8ca151b5 JB |
1196 | if (vif->p2p && mvm->p2p_device_vif) |
1197 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif); | |
1198 | ||
1199 | iwl_mvm_update_quotas(mvm, NULL); | |
1200 | iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta); | |
1201 | iwl_mvm_binding_remove_vif(mvm, vif); | |
a11e144e IP |
1202 | |
1203 | mvm->bound_vif_cnt--; | |
1204 | iwl_mvm_power_update_binding(mvm, vif, false); | |
1205 | ||
8ca151b5 JB |
1206 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
1207 | ||
1208 | mutex_unlock(&mvm->mutex); | |
1209 | } | |
1210 | ||
5023d966 JB |
1211 | static void |
1212 | iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, | |
1213 | struct ieee80211_vif *vif, | |
1214 | struct ieee80211_bss_conf *bss_conf, | |
1215 | u32 changes) | |
8ca151b5 | 1216 | { |
be2056fc | 1217 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
8a5e3660 AA |
1218 | enum ieee80211_bss_change ht_change = BSS_CHANGED_ERP_CTS_PROT | |
1219 | BSS_CHANGED_HT | | |
1220 | BSS_CHANGED_BANDWIDTH; | |
1221 | int ret; | |
1222 | ||
be2056fc IP |
1223 | /* Changes will be applied when the AP/IBSS is started */ |
1224 | if (!mvmvif->ap_ibss_active) | |
1225 | return; | |
1226 | ||
8a5e3660 AA |
1227 | if (changes & ht_change) { |
1228 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); | |
1229 | if (ret) | |
1230 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); | |
1231 | } | |
1232 | ||
8ca151b5 JB |
1233 | /* Need to send a new beacon template to the FW */ |
1234 | if (changes & BSS_CHANGED_BEACON) { | |
1235 | if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif)) | |
1236 | IWL_WARN(mvm, "Failed updating beacon data\n"); | |
1237 | } | |
1238 | } | |
1239 | ||
1240 | static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, | |
1241 | struct ieee80211_vif *vif, | |
1242 | struct ieee80211_bss_conf *bss_conf, | |
1243 | u32 changes) | |
1244 | { | |
1245 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1246 | ||
1247 | mutex_lock(&mvm->mutex); | |
1248 | ||
1249 | switch (vif->type) { | |
1250 | case NL80211_IFTYPE_STATION: | |
1251 | iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); | |
1252 | break; | |
1253 | case NL80211_IFTYPE_AP: | |
5023d966 JB |
1254 | case NL80211_IFTYPE_ADHOC: |
1255 | iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes); | |
8ca151b5 JB |
1256 | break; |
1257 | default: | |
1258 | /* shouldn't happen */ | |
1259 | WARN_ON_ONCE(1); | |
1260 | } | |
1261 | ||
1262 | mutex_unlock(&mvm->mutex); | |
1263 | } | |
1264 | ||
1265 | static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, | |
1266 | struct ieee80211_vif *vif, | |
1267 | struct cfg80211_scan_request *req) | |
1268 | { | |
1269 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1270 | int ret; | |
1271 | ||
1272 | if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS) | |
1273 | return -EINVAL; | |
1274 | ||
1275 | mutex_lock(&mvm->mutex); | |
1276 | ||
1277 | if (mvm->scan_status == IWL_MVM_SCAN_NONE) | |
1278 | ret = iwl_mvm_scan_request(mvm, vif, req); | |
1279 | else | |
1280 | ret = -EBUSY; | |
1281 | ||
1282 | mutex_unlock(&mvm->mutex); | |
1283 | ||
1284 | return ret; | |
1285 | } | |
1286 | ||
1287 | static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, | |
1288 | struct ieee80211_vif *vif) | |
1289 | { | |
1290 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1291 | ||
1292 | mutex_lock(&mvm->mutex); | |
1293 | ||
1294 | iwl_mvm_cancel_scan(mvm); | |
1295 | ||
1296 | mutex_unlock(&mvm->mutex); | |
1297 | } | |
1298 | ||
1299 | static void | |
1300 | iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, | |
3e56eadf | 1301 | struct ieee80211_sta *sta, u16 tids, |
8ca151b5 JB |
1302 | int num_frames, |
1303 | enum ieee80211_frame_release_type reason, | |
1304 | bool more_data) | |
1305 | { | |
1306 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
8ca151b5 | 1307 | |
3e56eadf | 1308 | /* Called when we need to transmit (a) frame(s) from mac80211 */ |
8ca151b5 | 1309 | |
3e56eadf JB |
1310 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, |
1311 | tids, more_data, false); | |
1312 | } | |
1313 | ||
1314 | static void | |
1315 | iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw, | |
1316 | struct ieee80211_sta *sta, u16 tids, | |
1317 | int num_frames, | |
1318 | enum ieee80211_frame_release_type reason, | |
1319 | bool more_data) | |
1320 | { | |
1321 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1322 | ||
1323 | /* Called when we need to transmit (a) frame(s) from agg queue */ | |
1324 | ||
1325 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, | |
1326 | tids, more_data, true); | |
8ca151b5 JB |
1327 | } |
1328 | ||
1329 | static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, | |
1330 | struct ieee80211_vif *vif, | |
1331 | enum sta_notify_cmd cmd, | |
1332 | struct ieee80211_sta *sta) | |
1333 | { | |
1334 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5b577a90 | 1335 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
3e56eadf | 1336 | int tid; |
8ca151b5 JB |
1337 | |
1338 | switch (cmd) { | |
1339 | case STA_NOTIFY_SLEEP: | |
e3d4bc8c | 1340 | if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0) |
8ca151b5 | 1341 | ieee80211_sta_block_awake(hw, sta, true); |
3e56eadf JB |
1342 | spin_lock_bh(&mvmsta->lock); |
1343 | for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { | |
1344 | struct iwl_mvm_tid_data *tid_data; | |
1345 | ||
1346 | tid_data = &mvmsta->tid_data[tid]; | |
1347 | if (tid_data->state != IWL_AGG_ON && | |
1348 | tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA) | |
1349 | continue; | |
1350 | if (iwl_mvm_tid_queued(tid_data) == 0) | |
1351 | continue; | |
1352 | ieee80211_sta_set_buffered(sta, tid, true); | |
1353 | } | |
1354 | spin_unlock_bh(&mvmsta->lock); | |
8ca151b5 JB |
1355 | /* |
1356 | * The fw updates the STA to be asleep. Tx packets on the Tx | |
1357 | * queues to this station will not be transmitted. The fw will | |
1358 | * send a Tx response with TX_STATUS_FAIL_DEST_PS. | |
1359 | */ | |
1360 | break; | |
1361 | case STA_NOTIFY_AWAKE: | |
881acd89 | 1362 | if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT)) |
8ca151b5 | 1363 | break; |
9cc40712 | 1364 | iwl_mvm_sta_modify_ps_wake(mvm, sta); |
8ca151b5 JB |
1365 | break; |
1366 | default: | |
1367 | break; | |
1368 | } | |
1369 | } | |
1370 | ||
1ddbbb0c JB |
1371 | static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw, |
1372 | struct ieee80211_vif *vif, | |
1373 | struct ieee80211_sta *sta) | |
1374 | { | |
1375 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1376 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; | |
1377 | ||
1378 | /* | |
1379 | * This is called before mac80211 does RCU synchronisation, | |
1380 | * so here we already invalidate our internal RCU-protected | |
1381 | * station pointer. The rest of the code will thus no longer | |
1382 | * be able to find the station this way, and we don't rely | |
1383 | * on further RCU synchronisation after the sta_state() | |
1384 | * callback deleted the station. | |
1385 | */ | |
1386 | mutex_lock(&mvm->mutex); | |
1387 | if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id])) | |
1388 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], | |
1389 | ERR_PTR(-ENOENT)); | |
1390 | mutex_unlock(&mvm->mutex); | |
1391 | } | |
1392 | ||
8ca151b5 JB |
1393 | static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, |
1394 | struct ieee80211_vif *vif, | |
1395 | struct ieee80211_sta *sta, | |
1396 | enum ieee80211_sta_state old_state, | |
1397 | enum ieee80211_sta_state new_state) | |
1398 | { | |
1399 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1400 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1401 | int ret; | |
1402 | ||
1403 | IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", | |
1404 | sta->addr, old_state, new_state); | |
1405 | ||
1406 | /* this would be a mac80211 bug ... but don't crash */ | |
1407 | if (WARN_ON_ONCE(!mvmvif->phy_ctxt)) | |
1408 | return -EINVAL; | |
1409 | ||
1410 | /* if a STA is being removed, reuse its ID */ | |
1411 | flush_work(&mvm->sta_drained_wk); | |
1412 | ||
1413 | mutex_lock(&mvm->mutex); | |
1414 | if (old_state == IEEE80211_STA_NOTEXIST && | |
1415 | new_state == IEEE80211_STA_NONE) { | |
48bc1307 JB |
1416 | /* |
1417 | * Firmware bug - it'll crash if the beacon interval is less | |
1418 | * than 16. We can't avoid connecting at all, so refuse the | |
1419 | * station state change, this will cause mac80211 to abandon | |
1420 | * attempts to connect to this AP, and eventually wpa_s will | |
1421 | * blacklist the AP... | |
1422 | */ | |
1423 | if (vif->type == NL80211_IFTYPE_STATION && | |
1424 | vif->bss_conf.beacon_int < 16) { | |
1425 | IWL_ERR(mvm, | |
1426 | "AP %pM beacon interval is %d, refusing due to firmware bug!\n", | |
1427 | sta->addr, vif->bss_conf.beacon_int); | |
1428 | ret = -EINVAL; | |
1429 | goto out_unlock; | |
1430 | } | |
8ca151b5 JB |
1431 | ret = iwl_mvm_add_sta(mvm, vif, sta); |
1432 | } else if (old_state == IEEE80211_STA_NONE && | |
1433 | new_state == IEEE80211_STA_AUTH) { | |
1434 | ret = 0; | |
1435 | } else if (old_state == IEEE80211_STA_AUTH && | |
1436 | new_state == IEEE80211_STA_ASSOC) { | |
7a453973 JB |
1437 | ret = iwl_mvm_update_sta(mvm, vif, sta); |
1438 | if (ret == 0) | |
1439 | iwl_mvm_rs_rate_init(mvm, sta, | |
b87c2179 ES |
1440 | mvmvif->phy_ctxt->channel->band, |
1441 | true); | |
8ca151b5 JB |
1442 | } else if (old_state == IEEE80211_STA_ASSOC && |
1443 | new_state == IEEE80211_STA_AUTHORIZED) { | |
7df15b1e HG |
1444 | /* enable beacon filtering */ |
1445 | WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif)); | |
8ca151b5 JB |
1446 | ret = 0; |
1447 | } else if (old_state == IEEE80211_STA_AUTHORIZED && | |
1448 | new_state == IEEE80211_STA_ASSOC) { | |
7df15b1e HG |
1449 | /* disable beacon filtering */ |
1450 | WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif)); | |
8ca151b5 JB |
1451 | ret = 0; |
1452 | } else if (old_state == IEEE80211_STA_ASSOC && | |
1453 | new_state == IEEE80211_STA_AUTH) { | |
1454 | ret = 0; | |
1455 | } else if (old_state == IEEE80211_STA_AUTH && | |
1456 | new_state == IEEE80211_STA_NONE) { | |
1457 | ret = 0; | |
1458 | } else if (old_state == IEEE80211_STA_NONE && | |
1459 | new_state == IEEE80211_STA_NOTEXIST) { | |
1460 | ret = iwl_mvm_rm_sta(mvm, vif, sta); | |
1461 | } else { | |
1462 | ret = -EIO; | |
1463 | } | |
48bc1307 | 1464 | out_unlock: |
8ca151b5 JB |
1465 | mutex_unlock(&mvm->mutex); |
1466 | ||
1467 | return ret; | |
1468 | } | |
1469 | ||
1470 | static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) | |
1471 | { | |
1472 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1473 | ||
1474 | mvm->rts_threshold = value; | |
1475 | ||
1476 | return 0; | |
1477 | } | |
1478 | ||
1f3b0ff8 LE |
1479 | static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, |
1480 | struct ieee80211_vif *vif, | |
1481 | struct ieee80211_sta *sta, u32 changed) | |
1482 | { | |
1483 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1484 | ||
1485 | if (vif->type == NL80211_IFTYPE_STATION && | |
1486 | changed & IEEE80211_RC_NSS_CHANGED) | |
1487 | iwl_mvm_sf_update(mvm, vif, false); | |
1488 | } | |
1489 | ||
8ca151b5 JB |
1490 | static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, |
1491 | struct ieee80211_vif *vif, u16 ac, | |
1492 | const struct ieee80211_tx_queue_params *params) | |
1493 | { | |
1494 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1495 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1496 | ||
1497 | mvmvif->queue_params[ac] = *params; | |
1498 | ||
1499 | /* | |
1500 | * No need to update right away, we'll get BSS_CHANGED_QOS | |
1501 | * The exception is P2P_DEVICE interface which needs immediate update. | |
1502 | */ | |
1503 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
1504 | int ret; | |
1505 | ||
1506 | mutex_lock(&mvm->mutex); | |
1507 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); | |
1508 | mutex_unlock(&mvm->mutex); | |
1509 | return ret; | |
1510 | } | |
1511 | return 0; | |
1512 | } | |
1513 | ||
1514 | static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, | |
1515 | struct ieee80211_vif *vif) | |
1516 | { | |
1517 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1518 | u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS, | |
1519 | 200 + vif->bss_conf.beacon_int); | |
1520 | u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS, | |
1521 | 100 + vif->bss_conf.beacon_int); | |
1522 | ||
1523 | if (WARN_ON_ONCE(vif->bss_conf.assoc)) | |
1524 | return; | |
1525 | ||
1526 | mutex_lock(&mvm->mutex); | |
1527 | /* Try really hard to protect the session and hear a beacon */ | |
016d27e1 | 1528 | iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500); |
8ca151b5 JB |
1529 | mutex_unlock(&mvm->mutex); |
1530 | } | |
1531 | ||
35a000b7 DS |
1532 | static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, |
1533 | struct ieee80211_vif *vif, | |
1534 | struct cfg80211_sched_scan_request *req, | |
1535 | struct ieee80211_sched_scan_ies *ies) | |
1536 | { | |
1537 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1538 | int ret; | |
1539 | ||
1540 | mutex_lock(&mvm->mutex); | |
1541 | ||
1542 | if (mvm->scan_status != IWL_MVM_SCAN_NONE) { | |
1543 | IWL_DEBUG_SCAN(mvm, | |
1544 | "SCHED SCAN request during internal scan - abort\n"); | |
1545 | ret = -EBUSY; | |
1546 | goto out; | |
1547 | } | |
1548 | ||
1549 | mvm->scan_status = IWL_MVM_SCAN_SCHED; | |
1550 | ||
1551 | ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies); | |
1552 | if (ret) | |
1553 | goto err; | |
1554 | ||
1555 | ret = iwl_mvm_config_sched_scan_profiles(mvm, req); | |
1556 | if (ret) | |
1557 | goto err; | |
1558 | ||
1559 | ret = iwl_mvm_sched_scan_start(mvm, req); | |
1560 | if (!ret) | |
1561 | goto out; | |
1562 | err: | |
1563 | mvm->scan_status = IWL_MVM_SCAN_NONE; | |
1564 | out: | |
1565 | mutex_unlock(&mvm->mutex); | |
1566 | return ret; | |
1567 | } | |
1568 | ||
1569 | static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, | |
1570 | struct ieee80211_vif *vif) | |
1571 | { | |
1572 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1573 | ||
1574 | mutex_lock(&mvm->mutex); | |
1575 | iwl_mvm_sched_scan_stop(mvm); | |
1576 | mutex_unlock(&mvm->mutex); | |
1577 | } | |
1578 | ||
8ca151b5 JB |
1579 | static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, |
1580 | enum set_key_cmd cmd, | |
1581 | struct ieee80211_vif *vif, | |
1582 | struct ieee80211_sta *sta, | |
1583 | struct ieee80211_key_conf *key) | |
1584 | { | |
1585 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1586 | int ret; | |
1587 | ||
1588 | if (iwlwifi_mod_params.sw_crypto) { | |
1589 | IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n"); | |
1590 | return -EOPNOTSUPP; | |
1591 | } | |
1592 | ||
1593 | switch (key->cipher) { | |
1594 | case WLAN_CIPHER_SUITE_TKIP: | |
1595 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; | |
1596 | /* fall-through */ | |
1597 | case WLAN_CIPHER_SUITE_CCMP: | |
1598 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
1599 | break; | |
1600 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
1601 | WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE)); | |
1602 | break; | |
1603 | case WLAN_CIPHER_SUITE_WEP40: | |
1604 | case WLAN_CIPHER_SUITE_WEP104: | |
1605 | /* | |
1606 | * Support for TX only, at least for now, so accept | |
1607 | * the key and do nothing else. Then mac80211 will | |
1608 | * pass it for TX but we don't have to use it for RX. | |
1609 | */ | |
1610 | return 0; | |
1611 | default: | |
e36e5433 MS |
1612 | /* currently FW supports only one optional cipher scheme */ |
1613 | if (hw->n_cipher_schemes && | |
1614 | hw->cipher_schemes->cipher == key->cipher) | |
1615 | key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; | |
1616 | else | |
1617 | return -EOPNOTSUPP; | |
8ca151b5 JB |
1618 | } |
1619 | ||
1620 | mutex_lock(&mvm->mutex); | |
1621 | ||
1622 | switch (cmd) { | |
1623 | case SET_KEY: | |
5023d966 JB |
1624 | if ((vif->type == NL80211_IFTYPE_ADHOC || |
1625 | vif->type == NL80211_IFTYPE_AP) && !sta) { | |
1626 | /* | |
1627 | * GTK on AP interface is a TX-only key, return 0; | |
1628 | * on IBSS they're per-station and because we're lazy | |
1629 | * we don't support them for RX, so do the same. | |
1630 | */ | |
6caffd4f JB |
1631 | ret = 0; |
1632 | key->hw_key_idx = STA_KEY_IDX_INVALID; | |
1633 | break; | |
1634 | } | |
1635 | ||
8ca151b5 JB |
1636 | IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n"); |
1637 | ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false); | |
1638 | if (ret) { | |
1639 | IWL_WARN(mvm, "set key failed\n"); | |
1640 | /* | |
1641 | * can't add key for RX, but we don't need it | |
1642 | * in the device for TX so still return 0 | |
1643 | */ | |
6caffd4f | 1644 | key->hw_key_idx = STA_KEY_IDX_INVALID; |
8ca151b5 JB |
1645 | ret = 0; |
1646 | } | |
1647 | ||
1648 | break; | |
1649 | case DISABLE_KEY: | |
6caffd4f JB |
1650 | if (key->hw_key_idx == STA_KEY_IDX_INVALID) { |
1651 | ret = 0; | |
1652 | break; | |
1653 | } | |
1654 | ||
8ca151b5 JB |
1655 | IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); |
1656 | ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); | |
1657 | break; | |
1658 | default: | |
1659 | ret = -EINVAL; | |
1660 | } | |
1661 | ||
1662 | mutex_unlock(&mvm->mutex); | |
1663 | return ret; | |
1664 | } | |
1665 | ||
1666 | static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, | |
1667 | struct ieee80211_vif *vif, | |
1668 | struct ieee80211_key_conf *keyconf, | |
1669 | struct ieee80211_sta *sta, | |
1670 | u32 iv32, u16 *phase1key) | |
1671 | { | |
1672 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1673 | ||
5023d966 JB |
1674 | if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) |
1675 | return; | |
1676 | ||
8ca151b5 JB |
1677 | iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); |
1678 | } | |
1679 | ||
1680 | ||
1681 | static int iwl_mvm_roc(struct ieee80211_hw *hw, | |
1682 | struct ieee80211_vif *vif, | |
1683 | struct ieee80211_channel *channel, | |
d339d5ca IP |
1684 | int duration, |
1685 | enum ieee80211_roc_type type) | |
8ca151b5 JB |
1686 | { |
1687 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
fe0f2de3 | 1688 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
8ca151b5 | 1689 | struct cfg80211_chan_def chandef; |
31d385ae IP |
1690 | struct iwl_mvm_phy_ctxt *phy_ctxt; |
1691 | int ret, i; | |
1692 | ||
1693 | IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, | |
1694 | duration, type); | |
8ca151b5 JB |
1695 | |
1696 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE) { | |
1697 | IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type); | |
1698 | return -EINVAL; | |
1699 | } | |
1700 | ||
8ca151b5 JB |
1701 | mutex_lock(&mvm->mutex); |
1702 | ||
31d385ae IP |
1703 | for (i = 0; i < NUM_PHY_CTX; i++) { |
1704 | phy_ctxt = &mvm->phy_ctxts[i]; | |
1705 | if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt) | |
1706 | continue; | |
1707 | ||
1708 | if (phy_ctxt->ref && channel == phy_ctxt->channel) { | |
1709 | /* | |
1710 | * Unbind the P2P_DEVICE from the current PHY context, | |
1711 | * and if the PHY context is not used remove it. | |
1712 | */ | |
1713 | ret = iwl_mvm_binding_remove_vif(mvm, vif); | |
1714 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) | |
1715 | goto out_unlock; | |
1716 | ||
1717 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); | |
1718 | ||
1719 | /* Bind the P2P_DEVICE to the current PHY Context */ | |
1720 | mvmvif->phy_ctxt = phy_ctxt; | |
1721 | ||
1722 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
1723 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) | |
1724 | goto out_unlock; | |
1725 | ||
1726 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); | |
1727 | goto schedule_time_event; | |
1728 | } | |
1729 | } | |
1730 | ||
1731 | /* Need to update the PHY context only if the ROC channel changed */ | |
1732 | if (channel == mvmvif->phy_ctxt->channel) | |
1733 | goto schedule_time_event; | |
1734 | ||
8ca151b5 | 1735 | cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); |
8ca151b5 | 1736 | |
31d385ae IP |
1737 | /* |
1738 | * Change the PHY context configuration as it is currently referenced | |
1739 | * only by the P2P Device MAC | |
1740 | */ | |
1741 | if (mvmvif->phy_ctxt->ref == 1) { | |
1742 | ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt, | |
1743 | &chandef, 1, 1); | |
1744 | if (ret) | |
1745 | goto out_unlock; | |
1746 | } else { | |
1747 | /* | |
1748 | * The PHY context is shared with other MACs. Need to remove the | |
1749 | * P2P Device from the binding, allocate an new PHY context and | |
1750 | * create a new binding | |
1751 | */ | |
1752 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); | |
1753 | if (!phy_ctxt) { | |
1754 | ret = -ENOSPC; | |
1755 | goto out_unlock; | |
1756 | } | |
1757 | ||
1758 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef, | |
1759 | 1, 1); | |
1760 | if (ret) { | |
1761 | IWL_ERR(mvm, "Failed to change PHY context\n"); | |
1762 | goto out_unlock; | |
1763 | } | |
1764 | ||
1765 | /* Unbind the P2P_DEVICE from the current PHY context */ | |
1766 | ret = iwl_mvm_binding_remove_vif(mvm, vif); | |
1767 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) | |
1768 | goto out_unlock; | |
1769 | ||
1770 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); | |
1771 | ||
1772 | /* Bind the P2P_DEVICE to the new allocated PHY context */ | |
1773 | mvmvif->phy_ctxt = phy_ctxt; | |
1774 | ||
1775 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
1776 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) | |
1777 | goto out_unlock; | |
1778 | ||
1779 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); | |
1780 | } | |
1781 | ||
1782 | schedule_time_event: | |
8ca151b5 | 1783 | /* Schedule the time events */ |
e635c797 | 1784 | ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); |
8ca151b5 | 1785 | |
31d385ae | 1786 | out_unlock: |
8ca151b5 JB |
1787 | mutex_unlock(&mvm->mutex); |
1788 | IWL_DEBUG_MAC80211(mvm, "leave\n"); | |
8ca151b5 JB |
1789 | return ret; |
1790 | } | |
1791 | ||
1792 | static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw) | |
1793 | { | |
1794 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1795 | ||
1796 | IWL_DEBUG_MAC80211(mvm, "enter\n"); | |
1797 | ||
1798 | mutex_lock(&mvm->mutex); | |
1799 | iwl_mvm_stop_p2p_roc(mvm); | |
1800 | mutex_unlock(&mvm->mutex); | |
1801 | ||
1802 | IWL_DEBUG_MAC80211(mvm, "leave\n"); | |
1803 | return 0; | |
1804 | } | |
1805 | ||
1806 | static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, | |
1807 | struct ieee80211_chanctx_conf *ctx) | |
1808 | { | |
1809 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
fe0f2de3 IP |
1810 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
1811 | struct iwl_mvm_phy_ctxt *phy_ctxt; | |
8ca151b5 JB |
1812 | int ret; |
1813 | ||
53a9d61e | 1814 | IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); |
fe0f2de3 | 1815 | |
8ca151b5 | 1816 | mutex_lock(&mvm->mutex); |
fe0f2de3 IP |
1817 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
1818 | if (!phy_ctxt) { | |
1819 | ret = -ENOSPC; | |
1820 | goto out; | |
1821 | } | |
8ca151b5 | 1822 | |
dcbc3e1a | 1823 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def, |
53a9d61e IP |
1824 | ctx->rx_chains_static, |
1825 | ctx->rx_chains_dynamic); | |
fe0f2de3 IP |
1826 | if (ret) { |
1827 | IWL_ERR(mvm, "Failed to add PHY context\n"); | |
1828 | goto out; | |
1829 | } | |
1830 | ||
53a9d61e | 1831 | iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt); |
fe0f2de3 IP |
1832 | *phy_ctxt_id = phy_ctxt->id; |
1833 | out: | |
8ca151b5 JB |
1834 | mutex_unlock(&mvm->mutex); |
1835 | return ret; | |
1836 | } | |
1837 | ||
1838 | static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, | |
1839 | struct ieee80211_chanctx_conf *ctx) | |
1840 | { | |
1841 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
fe0f2de3 IP |
1842 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
1843 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; | |
8ca151b5 JB |
1844 | |
1845 | mutex_lock(&mvm->mutex); | |
fe0f2de3 | 1846 | iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); |
8ca151b5 JB |
1847 | mutex_unlock(&mvm->mutex); |
1848 | } | |
1849 | ||
1850 | static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, | |
1851 | struct ieee80211_chanctx_conf *ctx, | |
1852 | u32 changed) | |
1853 | { | |
1854 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
fe0f2de3 IP |
1855 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
1856 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; | |
8ca151b5 | 1857 | |
31d385ae IP |
1858 | if (WARN_ONCE((phy_ctxt->ref > 1) && |
1859 | (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | | |
1860 | IEEE80211_CHANCTX_CHANGE_RX_CHAINS | | |
2dceedae AN |
1861 | IEEE80211_CHANCTX_CHANGE_RADAR | |
1862 | IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)), | |
31d385ae IP |
1863 | "Cannot change PHY. Ref=%d, changed=0x%X\n", |
1864 | phy_ctxt->ref, changed)) | |
1865 | return; | |
1866 | ||
8ca151b5 | 1867 | mutex_lock(&mvm->mutex); |
dcbc3e1a | 1868 | iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def, |
8ca151b5 JB |
1869 | ctx->rx_chains_static, |
1870 | ctx->rx_chains_dynamic); | |
8e484f0b | 1871 | iwl_mvm_bt_coex_vif_change(mvm); |
8ca151b5 JB |
1872 | mutex_unlock(&mvm->mutex); |
1873 | } | |
1874 | ||
1875 | static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, | |
1876 | struct ieee80211_vif *vif, | |
1877 | struct ieee80211_chanctx_conf *ctx) | |
1878 | { | |
1879 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
fe0f2de3 IP |
1880 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
1881 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; | |
8ca151b5 JB |
1882 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
1883 | int ret; | |
1884 | ||
1885 | mutex_lock(&mvm->mutex); | |
1886 | ||
fe0f2de3 | 1887 | mvmvif->phy_ctxt = phy_ctxt; |
8ca151b5 JB |
1888 | |
1889 | switch (vif->type) { | |
1890 | case NL80211_IFTYPE_AP: | |
5023d966 | 1891 | case NL80211_IFTYPE_ADHOC: |
8ca151b5 JB |
1892 | /* |
1893 | * The AP binding flow is handled as part of the start_ap flow | |
5023d966 | 1894 | * (in bss_info_changed), similarly for IBSS. |
8ca151b5 JB |
1895 | */ |
1896 | ret = 0; | |
1897 | goto out_unlock; | |
1898 | case NL80211_IFTYPE_STATION: | |
8ca151b5 JB |
1899 | case NL80211_IFTYPE_MONITOR: |
1900 | break; | |
1901 | default: | |
1902 | ret = -EINVAL; | |
1903 | goto out_unlock; | |
1904 | } | |
1905 | ||
1906 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
1907 | if (ret) | |
1908 | goto out_unlock; | |
1909 | ||
1910 | /* | |
92d85562 AB |
1911 | * Power state must be updated before quotas, |
1912 | * otherwise fw will complain. | |
1913 | */ | |
1914 | mvm->bound_vif_cnt++; | |
1915 | iwl_mvm_power_update_binding(mvm, vif, true); | |
1916 | ||
1917 | /* Setting the quota at this stage is only required for monitor | |
8ca151b5 JB |
1918 | * interfaces. For the other types, the bss_info changed flow |
1919 | * will handle quota settings. | |
1920 | */ | |
1921 | if (vif->type == NL80211_IFTYPE_MONITOR) { | |
1e1391ca | 1922 | mvmvif->monitor_active = true; |
8ca151b5 JB |
1923 | ret = iwl_mvm_update_quotas(mvm, vif); |
1924 | if (ret) | |
1925 | goto out_remove_binding; | |
1926 | } | |
1927 | ||
1928 | goto out_unlock; | |
1929 | ||
1930 | out_remove_binding: | |
1931 | iwl_mvm_binding_remove_vif(mvm, vif); | |
92d85562 AB |
1932 | mvm->bound_vif_cnt--; |
1933 | iwl_mvm_power_update_binding(mvm, vif, false); | |
8ca151b5 JB |
1934 | out_unlock: |
1935 | mutex_unlock(&mvm->mutex); | |
1936 | if (ret) | |
1937 | mvmvif->phy_ctxt = NULL; | |
1938 | return ret; | |
1939 | } | |
1940 | ||
1941 | static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, | |
1942 | struct ieee80211_vif *vif, | |
1943 | struct ieee80211_chanctx_conf *ctx) | |
1944 | { | |
1945 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1946 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1947 | ||
1948 | mutex_lock(&mvm->mutex); | |
1949 | ||
1950 | iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data); | |
1951 | ||
8ca151b5 | 1952 | switch (vif->type) { |
5023d966 JB |
1953 | case NL80211_IFTYPE_AP: |
1954 | case NL80211_IFTYPE_ADHOC: | |
1955 | goto out_unlock; | |
8ca151b5 | 1956 | case NL80211_IFTYPE_MONITOR: |
1e1391ca IP |
1957 | mvmvif->monitor_active = false; |
1958 | iwl_mvm_update_quotas(mvm, NULL); | |
8ca151b5 JB |
1959 | break; |
1960 | default: | |
1961 | break; | |
1962 | } | |
1963 | ||
1e1391ca | 1964 | iwl_mvm_binding_remove_vif(mvm, vif); |
1c2abf72 | 1965 | mvm->bound_vif_cnt--; |
92d85562 | 1966 | iwl_mvm_power_update_binding(mvm, vif, false); |
1c2abf72 | 1967 | |
a11e144e IP |
1968 | out_unlock: |
1969 | mvmvif->phy_ctxt = NULL; | |
8ca151b5 JB |
1970 | mutex_unlock(&mvm->mutex); |
1971 | } | |
1972 | ||
1973 | static int iwl_mvm_set_tim(struct ieee80211_hw *hw, | |
1974 | struct ieee80211_sta *sta, | |
1975 | bool set) | |
1976 | { | |
1977 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1978 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; | |
1979 | ||
1980 | if (!mvm_sta || !mvm_sta->vif) { | |
1981 | IWL_ERR(mvm, "Station is not associated to a vif\n"); | |
1982 | return -EINVAL; | |
1983 | } | |
1984 | ||
1985 | return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif); | |
1986 | } | |
1987 | ||
507cadf2 DS |
1988 | #ifdef CONFIG_NL80211_TESTMODE |
1989 | static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { | |
1990 | [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, | |
1991 | [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, | |
f6c6ad42 | 1992 | [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, |
507cadf2 DS |
1993 | }; |
1994 | ||
1995 | static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, | |
1996 | struct ieee80211_vif *vif, | |
1997 | void *data, int len) | |
1998 | { | |
1999 | struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; | |
2000 | int err; | |
2001 | u32 noa_duration; | |
2002 | ||
2003 | err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy); | |
2004 | if (err) | |
2005 | return err; | |
2006 | ||
2007 | if (!tb[IWL_MVM_TM_ATTR_CMD]) | |
2008 | return -EINVAL; | |
2009 | ||
2010 | switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { | |
2011 | case IWL_MVM_TM_CMD_SET_NOA: | |
2012 | if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || | |
2013 | !vif->bss_conf.enable_beacon || | |
2014 | !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) | |
2015 | return -EINVAL; | |
2016 | ||
2017 | noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); | |
2018 | if (noa_duration >= vif->bss_conf.beacon_int) | |
2019 | return -EINVAL; | |
2020 | ||
2021 | mvm->noa_duration = noa_duration; | |
2022 | mvm->noa_vif = vif; | |
2023 | ||
2024 | return iwl_mvm_update_quotas(mvm, NULL); | |
f6c6ad42 JB |
2025 | case IWL_MVM_TM_CMD_SET_BEACON_FILTER: |
2026 | /* must be associated client vif - ignore authorized */ | |
2027 | if (!vif || vif->type != NL80211_IFTYPE_STATION || | |
2028 | !vif->bss_conf.assoc || !vif->bss_conf.dtim_period || | |
2029 | !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) | |
2030 | return -EINVAL; | |
2031 | ||
2032 | if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) | |
2033 | return iwl_mvm_enable_beacon_filter(mvm, vif); | |
2034 | return iwl_mvm_disable_beacon_filter(mvm, vif); | |
507cadf2 DS |
2035 | } |
2036 | ||
2037 | return -EOPNOTSUPP; | |
2038 | } | |
2039 | ||
2040 | static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, | |
2041 | struct ieee80211_vif *vif, | |
2042 | void *data, int len) | |
2043 | { | |
2044 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
2045 | int err; | |
2046 | ||
2047 | mutex_lock(&mvm->mutex); | |
2048 | err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); | |
2049 | mutex_unlock(&mvm->mutex); | |
2050 | ||
2051 | return err; | |
2052 | } | |
2053 | #endif | |
2054 | ||
8ca151b5 JB |
2055 | struct ieee80211_ops iwl_mvm_hw_ops = { |
2056 | .tx = iwl_mvm_mac_tx, | |
2057 | .ampdu_action = iwl_mvm_mac_ampdu_action, | |
2058 | .start = iwl_mvm_mac_start, | |
2059 | .restart_complete = iwl_mvm_mac_restart_complete, | |
2060 | .stop = iwl_mvm_mac_stop, | |
2061 | .add_interface = iwl_mvm_mac_add_interface, | |
2062 | .remove_interface = iwl_mvm_mac_remove_interface, | |
2063 | .config = iwl_mvm_mac_config, | |
e59647ea | 2064 | .prepare_multicast = iwl_mvm_prepare_multicast, |
8ca151b5 JB |
2065 | .configure_filter = iwl_mvm_configure_filter, |
2066 | .bss_info_changed = iwl_mvm_bss_info_changed, | |
2067 | .hw_scan = iwl_mvm_mac_hw_scan, | |
2068 | .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, | |
1ddbbb0c | 2069 | .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, |
8ca151b5 JB |
2070 | .sta_state = iwl_mvm_mac_sta_state, |
2071 | .sta_notify = iwl_mvm_mac_sta_notify, | |
2072 | .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, | |
3e56eadf | 2073 | .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, |
8ca151b5 | 2074 | .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, |
1f3b0ff8 | 2075 | .sta_rc_update = iwl_mvm_sta_rc_update, |
8ca151b5 JB |
2076 | .conf_tx = iwl_mvm_mac_conf_tx, |
2077 | .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, | |
35a000b7 DS |
2078 | .sched_scan_start = iwl_mvm_mac_sched_scan_start, |
2079 | .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, | |
8ca151b5 JB |
2080 | .set_key = iwl_mvm_mac_set_key, |
2081 | .update_tkip_key = iwl_mvm_mac_update_tkip_key, | |
2082 | .remain_on_channel = iwl_mvm_roc, | |
2083 | .cancel_remain_on_channel = iwl_mvm_cancel_roc, | |
8ca151b5 JB |
2084 | .add_chanctx = iwl_mvm_add_chanctx, |
2085 | .remove_chanctx = iwl_mvm_remove_chanctx, | |
2086 | .change_chanctx = iwl_mvm_change_chanctx, | |
2087 | .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, | |
2088 | .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, | |
2089 | ||
5023d966 JB |
2090 | .start_ap = iwl_mvm_start_ap_ibss, |
2091 | .stop_ap = iwl_mvm_stop_ap_ibss, | |
2092 | .join_ibss = iwl_mvm_start_ap_ibss, | |
2093 | .leave_ibss = iwl_mvm_stop_ap_ibss, | |
8ca151b5 JB |
2094 | |
2095 | .set_tim = iwl_mvm_set_tim, | |
2096 | ||
507cadf2 DS |
2097 | CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) |
2098 | ||
8ca151b5 JB |
2099 | #ifdef CONFIG_PM_SLEEP |
2100 | /* look at d3.c */ | |
2101 | .suspend = iwl_mvm_suspend, | |
2102 | .resume = iwl_mvm_resume, | |
2103 | .set_wakeup = iwl_mvm_set_wakeup, | |
2104 | .set_rekey_data = iwl_mvm_set_rekey_data, | |
2105 | #if IS_ENABLED(CONFIG_IPV6) | |
2106 | .ipv6_addr_change = iwl_mvm_ipv6_addr_change, | |
2107 | #endif | |
2108 | .set_default_unicast_key = iwl_mvm_set_default_unicast_key, | |
2109 | #endif | |
2110 | }; |