Commit | Line | Data |
---|---|---|
8e99ea8d JB |
1 | // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause |
2 | /* | |
091296d3 | 3 | * Copyright (C) 2012-2014, 2018-2022 Intel Corporation |
8e99ea8d JB |
4 | * Copyright (C) 2013-2015 Intel Mobile Communications GmbH |
5 | * Copyright (C) 2016-2017 Intel Deutschland GmbH | |
6 | */ | |
8ca151b5 JB |
7 | #include <linux/kernel.h> |
8 | #include <linux/slab.h> | |
9 | #include <linux/skbuff.h> | |
10 | #include <linux/netdevice.h> | |
11 | #include <linux/etherdevice.h> | |
f0c2646a | 12 | #include <linux/ip.h> |
2ee8f021 | 13 | #include <linux/if_arp.h> |
2f89a5d7 | 14 | #include <linux/time.h> |
8ca151b5 | 15 | #include <net/mac80211.h> |
7b1dd048 | 16 | #include <net/ieee80211_radiotap.h> |
f0c2646a | 17 | #include <net/tcp.h> |
8ca151b5 | 18 | |
5283dd67 | 19 | #include "iwl-drv.h" |
8ca151b5 JB |
20 | #include "iwl-op-mode.h" |
21 | #include "iwl-io.h" | |
22 | #include "mvm.h" | |
23 | #include "sta.h" | |
24 | #include "time-event.h" | |
25 | #include "iwl-eeprom-parse.h" | |
8ca151b5 | 26 | #include "iwl-phy-db.h" |
507cadf2 | 27 | #include "testmode.h" |
d962f9b1 | 28 | #include "fw/error-dump.h" |
655e6d6d | 29 | #include "iwl-prph.h" |
88931cc9 | 30 | #include "iwl-nvm-parse.h" |
8ca151b5 JB |
31 | |
32 | static const struct ieee80211_iface_limit iwl_mvm_limits[] = { | |
33 | { | |
34 | .max = 1, | |
8eb38710 | 35 | .types = BIT(NL80211_IFTYPE_STATION), |
8ca151b5 | 36 | }, |
3c15a0fb JB |
37 | { |
38 | .max = 1, | |
8eb38710 IP |
39 | .types = BIT(NL80211_IFTYPE_AP) | |
40 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | |
3c15a0fb JB |
41 | BIT(NL80211_IFTYPE_P2P_GO), |
42 | }, | |
43 | { | |
44 | .max = 1, | |
45 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE), | |
46 | }, | |
8ca151b5 JB |
47 | }; |
48 | ||
49 | static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = { | |
50 | { | |
2624a5ca | 51 | .num_different_channels = 2, |
8ca151b5 JB |
52 | .max_interfaces = 3, |
53 | .limits = iwl_mvm_limits, | |
54 | .n_limits = ARRAY_SIZE(iwl_mvm_limits), | |
55 | }, | |
56 | }; | |
57 | ||
fc36ffda JB |
58 | static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa = { |
59 | .max_peers = IWL_MVM_TOF_MAX_APS, | |
60 | .report_ap_tsf = 1, | |
61 | .randomize_mac_addr = 1, | |
62 | ||
63 | .ftm = { | |
64 | .supported = 1, | |
65 | .asap = 1, | |
66 | .non_asap = 1, | |
67 | .request_lci = 1, | |
68 | .request_civicloc = 1, | |
6815e3d0 AS |
69 | .trigger_based = 1, |
70 | .non_trigger_based = 1, | |
fc36ffda JB |
71 | .max_bursts_exponent = -1, /* all supported */ |
72 | .max_ftms_per_burst = 0, /* no limits */ | |
73 | .bandwidths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | | |
74 | BIT(NL80211_CHAN_WIDTH_20) | | |
75 | BIT(NL80211_CHAN_WIDTH_40) | | |
8a2c1516 AS |
76 | BIT(NL80211_CHAN_WIDTH_80) | |
77 | BIT(NL80211_CHAN_WIDTH_160), | |
fc36ffda JB |
78 | .preambles = BIT(NL80211_PREAMBLE_LEGACY) | |
79 | BIT(NL80211_PREAMBLE_HT) | | |
6815e3d0 AS |
80 | BIT(NL80211_PREAMBLE_VHT) | |
81 | BIT(NL80211_PREAMBLE_HE), | |
fc36ffda JB |
82 | }, |
83 | }; | |
84 | ||
6569e7d3 JB |
85 | static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw, |
86 | enum set_key_cmd cmd, | |
87 | struct ieee80211_vif *vif, | |
88 | struct ieee80211_sta *sta, | |
89 | struct ieee80211_key_conf *key); | |
c56e00a3 | 90 | |
fe0f2de3 IP |
91 | static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm) |
92 | { | |
93 | int i; | |
94 | ||
95 | memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts)); | |
96 | for (i = 0; i < NUM_PHY_CTX; i++) { | |
97 | mvm->phy_ctxts[i].id = i; | |
98 | mvm->phy_ctxts[i].ref = 0; | |
99 | } | |
100 | } | |
101 | ||
88931cc9 | 102 | struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy, |
8ba2d7a1 | 103 | const char *alpha2, |
47c8b154 JD |
104 | enum iwl_mcc_source src_id, |
105 | bool *changed) | |
88931cc9 AN |
106 | { |
107 | struct ieee80211_regdomain *regd = NULL; | |
108 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); | |
109 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
110 | struct iwl_mcc_update_resp *resp; | |
e27c506a | 111 | u8 resp_ver; |
88931cc9 AN |
112 | |
113 | IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2); | |
114 | ||
8ba2d7a1 | 115 | lockdep_assert_held(&mvm->mutex); |
88931cc9 | 116 | |
8ba2d7a1 | 117 | resp = iwl_mvm_update_mcc(mvm, alpha2, src_id); |
88931cc9 AN |
118 | if (IS_ERR_OR_NULL(resp)) { |
119 | IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n", | |
b8c474d9 | 120 | PTR_ERR_OR_ZERO(resp)); |
6d19a5eb | 121 | resp = NULL; |
8ba2d7a1 | 122 | goto out; |
88931cc9 AN |
123 | } |
124 | ||
82715ac7 EG |
125 | if (changed) { |
126 | u32 status = le32_to_cpu(resp->status); | |
127 | ||
128 | *changed = (status == MCC_RESP_NEW_CHAN_PROFILE || | |
129 | status == MCC_RESP_ILLEGAL); | |
130 | } | |
e27c506a GA |
131 | resp_ver = iwl_fw_lookup_notif_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP, |
132 | MCC_UPDATE_CMD, 0); | |
133 | IWL_DEBUG_LAR(mvm, "MCC update response version: %d\n", resp_ver); | |
47c8b154 | 134 | |
162ee3c9 | 135 | regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg, |
88931cc9 AN |
136 | __le32_to_cpu(resp->n_channels), |
137 | resp->channels, | |
77e30e10 | 138 | __le16_to_cpu(resp->mcc), |
2763bba6 | 139 | __le16_to_cpu(resp->geo_info), |
e27c506a | 140 | __le16_to_cpu(resp->cap), resp_ver); |
8ba2d7a1 EH |
141 | /* Store the return source id */ |
142 | src_id = resp->source_id; | |
88931cc9 AN |
143 | if (IS_ERR_OR_NULL(regd)) { |
144 | IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n", | |
b8c474d9 | 145 | PTR_ERR_OR_ZERO(regd)); |
8ba2d7a1 | 146 | goto out; |
88931cc9 AN |
147 | } |
148 | ||
8ba2d7a1 EH |
149 | IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n", |
150 | regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id); | |
88931cc9 | 151 | mvm->lar_regdom_set = true; |
8ba2d7a1 | 152 | mvm->mcc_src = src_id; |
88931cc9 | 153 | |
6d19a5eb EG |
154 | iwl_mei_set_country_code(__le16_to_cpu(resp->mcc)); |
155 | ||
8ba2d7a1 | 156 | out: |
6d19a5eb | 157 | kfree(resp); |
88931cc9 AN |
158 | return regd; |
159 | } | |
160 | ||
47c8b154 JD |
161 | void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm) |
162 | { | |
163 | bool changed; | |
164 | struct ieee80211_regdomain *regd; | |
165 | ||
166 | if (!iwl_mvm_is_lar_supported(mvm)) | |
167 | return; | |
168 | ||
169 | regd = iwl_mvm_get_current_regdomain(mvm, &changed); | |
170 | if (!IS_ERR_OR_NULL(regd)) { | |
171 | /* only update the regulatory core if changed */ | |
172 | if (changed) | |
173 | regulatory_set_wiphy_regd(mvm->hw->wiphy, regd); | |
174 | ||
175 | kfree(regd); | |
176 | } | |
177 | } | |
178 | ||
179 | struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm, | |
180 | bool *changed) | |
8ba2d7a1 EH |
181 | { |
182 | return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ", | |
183 | iwl_mvm_is_wifi_mcc_supported(mvm) ? | |
184 | MCC_SOURCE_GET_CURRENT : | |
47c8b154 | 185 | MCC_SOURCE_OLD_FW, changed); |
8ba2d7a1 EH |
186 | } |
187 | ||
188 | int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm) | |
189 | { | |
190 | enum iwl_mcc_source used_src; | |
191 | struct ieee80211_regdomain *regd; | |
b6e160ab AN |
192 | int ret; |
193 | bool changed; | |
8ba2d7a1 | 194 | const struct ieee80211_regdomain *r = |
a05829a7 | 195 | wiphy_dereference(mvm->hw->wiphy, mvm->hw->wiphy->regd); |
8ba2d7a1 EH |
196 | |
197 | if (!r) | |
b6e160ab | 198 | return -ENOENT; |
8ba2d7a1 EH |
199 | |
200 | /* save the last source in case we overwrite it below */ | |
201 | used_src = mvm->mcc_src; | |
202 | if (iwl_mvm_is_wifi_mcc_supported(mvm)) { | |
203 | /* Notify the firmware we support wifi location updates */ | |
47c8b154 | 204 | regd = iwl_mvm_get_current_regdomain(mvm, NULL); |
8ba2d7a1 EH |
205 | if (!IS_ERR_OR_NULL(regd)) |
206 | kfree(regd); | |
207 | } | |
208 | ||
209 | /* Now set our last stored MCC and source */ | |
b6e160ab AN |
210 | regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src, |
211 | &changed); | |
8ba2d7a1 EH |
212 | if (IS_ERR_OR_NULL(regd)) |
213 | return -EIO; | |
214 | ||
b6e160ab AN |
215 | /* update cfg80211 if the regdomain was changed */ |
216 | if (changed) | |
a05829a7 | 217 | ret = regulatory_set_wiphy_regd_sync(mvm->hw->wiphy, regd); |
b6e160ab AN |
218 | else |
219 | ret = 0; | |
8ba2d7a1 | 220 | |
b6e160ab AN |
221 | kfree(regd); |
222 | return ret; | |
8ba2d7a1 EH |
223 | } |
224 | ||
8e33f046 | 225 | /* Each capability added here should also be add to tm_if_types_ext_capa_sta */ |
7f2ea521 | 226 | static const u8 he_if_types_ext_capa_sta[] = { |
7360f99e | 227 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, |
918cbf39 | 228 | [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, |
7360f99e | 229 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, |
7360f99e EG |
230 | }; |
231 | ||
8e33f046 KP |
232 | static const u8 tm_if_types_ext_capa_sta[] = { |
233 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
234 | [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT | | |
235 | WLAN_EXT_CAPA3_TIMING_MEASUREMENT_SUPPORT, | |
236 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, | |
237 | [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT, | |
238 | }; | |
239 | ||
240 | /* Additional interface types for which extended capabilities are | |
241 | * specified separately | |
242 | */ | |
243 | static const struct wiphy_iftype_ext_capab add_iftypes_ext_capa[] = { | |
7360f99e EG |
244 | { |
245 | .iftype = NL80211_IFTYPE_STATION, | |
246 | .extended_capabilities = he_if_types_ext_capa_sta, | |
247 | .extended_capabilities_mask = he_if_types_ext_capa_sta, | |
248 | .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta), | |
249 | }, | |
8e33f046 KP |
250 | { |
251 | .iftype = NL80211_IFTYPE_STATION, | |
252 | .extended_capabilities = tm_if_types_ext_capa_sta, | |
253 | .extended_capabilities_mask = tm_if_types_ext_capa_sta, | |
254 | .extended_capabilities_len = sizeof(tm_if_types_ext_capa_sta), | |
255 | /* relevant only if EHT is supported */ | |
256 | .eml_capabilities = IEEE80211_EML_CAP_EMLSR_SUPP, | |
257 | }, | |
7360f99e EG |
258 | }; |
259 | ||
e8503aec BG |
260 | static int |
261 | iwl_mvm_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) | |
262 | { | |
263 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
264 | *tx_ant = iwl_mvm_get_valid_tx_ant(mvm); | |
265 | *rx_ant = iwl_mvm_get_valid_rx_ant(mvm); | |
266 | return 0; | |
267 | } | |
268 | ||
8ca151b5 JB |
269 | int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm) |
270 | { | |
271 | struct ieee80211_hw *hw = mvm->hw; | |
831e85f3 | 272 | int num_mac, ret, i; |
5f4c02e2 JB |
273 | static const u32 mvm_ciphers[] = { |
274 | WLAN_CIPHER_SUITE_WEP40, | |
275 | WLAN_CIPHER_SUITE_WEP104, | |
276 | WLAN_CIPHER_SUITE_TKIP, | |
277 | WLAN_CIPHER_SUITE_CCMP, | |
278 | }; | |
3f37c229 IY |
279 | #ifdef CONFIG_PM_SLEEP |
280 | bool unified = fw_has_capa(&mvm->fw->ucode_capa, | |
281 | IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); | |
282 | #endif | |
a5de7de7 JB |
283 | u32 sec_key_id = WIDE_ID(DATA_PATH_GROUP, SEC_KEY_CMD); |
284 | u8 sec_key_ver = iwl_fw_lookup_cmd_ver(mvm->fw, sec_key_id, 0); | |
8ca151b5 JB |
285 | |
286 | /* Tell mac80211 our characteristics */ | |
30686bf7 JB |
287 | ieee80211_hw_set(hw, SIGNAL_DBM); |
288 | ieee80211_hw_set(hw, SPECTRUM_MGMT); | |
289 | ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); | |
30686bf7 JB |
290 | ieee80211_hw_set(hw, WANT_MONITOR_VIF); |
291 | ieee80211_hw_set(hw, SUPPORTS_PS); | |
292 | ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); | |
293 | ieee80211_hw_set(hw, AMPDU_AGGREGATION); | |
294 | ieee80211_hw_set(hw, TIMING_BEACON_ONLY); | |
295 | ieee80211_hw_set(hw, CONNECTION_MONITOR); | |
296 | ieee80211_hw_set(hw, CHANCTX_STA_CSA); | |
297 | ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); | |
298 | ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS); | |
909ddf0b | 299 | ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU); |
30433d3b | 300 | ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR); |
d270e7b8 | 301 | ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP); |
520229e4 | 302 | ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW); |
cfbc6c4c SS |
303 | ieee80211_hw_set(hw, BUFF_MMPDU_TXQ); |
304 | ieee80211_hw_set(hw, STA_MMPDU_TXQ); | |
cfb21b11 JB |
305 | /* |
306 | * On older devices, enabling TX A-MSDU occasionally leads to | |
307 | * something getting messed up, the command read from the FIFO | |
308 | * gets out of sync and isn't a TX command, so that we have an | |
309 | * assert EDC. | |
310 | * | |
311 | * It's not clear where the bug is, but since we didn't used to | |
312 | * support A-MSDU until moving the mac80211 iTXQs, just leave it | |
313 | * for older devices. We also don't see this issue on any newer | |
314 | * devices. | |
315 | */ | |
7d34a7d7 | 316 | if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_9000) |
cfb21b11 | 317 | ieee80211_hw_set(hw, TX_AMSDU); |
438af969 | 318 | ieee80211_hw_set(hw, TX_FRAG_LIST); |
ecaf71de | 319 | |
4243edb4 | 320 | if (iwl_mvm_has_tlc_offload(mvm)) { |
ecaf71de GG |
321 | ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW); |
322 | ieee80211_hw_set(hw, HAS_RATE_CONTROL); | |
323 | } | |
324 | ||
b915c101 SS |
325 | if (iwl_mvm_has_new_rx_api(mvm)) |
326 | ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER); | |
960f864b JB |
327 | |
328 | if (fw_has_capa(&mvm->fw->ucode_capa, | |
329 | IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) { | |
65e25482 | 330 | ieee80211_hw_set(hw, AP_LINK_PS); |
960f864b JB |
331 | } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) { |
332 | /* | |
333 | * we absolutely need this for the new TX API since that comes | |
334 | * with many more queues than the current code can deal with | |
335 | * for station powersave | |
336 | */ | |
337 | return -EINVAL; | |
338 | } | |
8ca151b5 | 339 | |
80938abc JB |
340 | if (mvm->trans->num_rx_queues > 1) |
341 | ieee80211_hw_set(hw, USES_RSS); | |
342 | ||
2d7cf549 JB |
343 | if (mvm->trans->max_skb_frags) |
344 | hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG; | |
345 | ||
366fc672 | 346 | hw->queues = IEEE80211_NUM_ACS; |
398e8c6c | 347 | hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE; |
7b1dd048 EG |
348 | hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC | |
349 | IEEE80211_RADIOTAP_MCS_HAVE_STBC; | |
339b3086 ES |
350 | hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC | |
351 | IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED; | |
371a17ed JB |
352 | |
353 | hw->radiotap_timestamp.units_pos = | |
354 | IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US | | |
355 | IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ; | |
356 | /* this is the case for CCK frames, it's better (only 8) for OFDM */ | |
357 | hw->radiotap_timestamp.accuracy = 22; | |
358 | ||
4243edb4 | 359 | if (!iwl_mvm_has_tlc_offload(mvm)) |
9f66a397 GG |
360 | hw->rate_control_algorithm = RS_NAME; |
361 | ||
848955cc JB |
362 | hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES; |
363 | hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP; | |
438af969 | 364 | hw->max_tx_fragments = mvm->trans->max_skb_frags; |
8ca151b5 | 365 | |
8e160ab8 | 366 | BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6); |
5f4c02e2 JB |
367 | memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers)); |
368 | hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers); | |
369 | hw->wiphy->cipher_suites = mvm->ciphers; | |
370 | ||
2a53d166 AB |
371 | if (iwl_mvm_has_new_rx_api(mvm)) { |
372 | mvm->ciphers[hw->wiphy->n_cipher_suites] = | |
373 | WLAN_CIPHER_SUITE_GCMP; | |
374 | hw->wiphy->n_cipher_suites++; | |
375 | mvm->ciphers[hw->wiphy->n_cipher_suites] = | |
376 | WLAN_CIPHER_SUITE_GCMP_256; | |
377 | hw->wiphy->n_cipher_suites++; | |
378 | } | |
379 | ||
f4bfdc5e EG |
380 | if (iwlwifi_mod_params.swcrypto) |
381 | IWL_ERR(mvm, | |
382 | "iwlmvm doesn't allow to disable HW crypto, check swcrypto module parameter\n"); | |
383 | if (!iwlwifi_mod_params.bt_coex_active) | |
384 | IWL_ERR(mvm, | |
385 | "iwlmvm doesn't allow to disable BT Coex, check bt_coex_active module parameter\n"); | |
386 | ||
387 | ieee80211_hw_set(hw, MFP_CAPABLE); | |
388 | mvm->ciphers[hw->wiphy->n_cipher_suites] = WLAN_CIPHER_SUITE_AES_CMAC; | |
389 | hw->wiphy->n_cipher_suites++; | |
390 | if (iwl_mvm_has_new_rx_api(mvm)) { | |
5f4c02e2 | 391 | mvm->ciphers[hw->wiphy->n_cipher_suites] = |
f4bfdc5e EG |
392 | WLAN_CIPHER_SUITE_BIP_GMAC_128; |
393 | hw->wiphy->n_cipher_suites++; | |
394 | mvm->ciphers[hw->wiphy->n_cipher_suites] = | |
395 | WLAN_CIPHER_SUITE_BIP_GMAC_256; | |
5f4c02e2 JB |
396 | hw->wiphy->n_cipher_suites++; |
397 | } | |
398 | ||
ef2e7a51 IP |
399 | wiphy_ext_feature_set(hw->wiphy, |
400 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY); | |
401 | ||
b73f9a4a | 402 | if (fw_has_capa(&mvm->fw->ucode_capa, |
fc36ffda | 403 | IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) { |
b73f9a4a JB |
404 | wiphy_ext_feature_set(hw->wiphy, |
405 | NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER); | |
fc36ffda JB |
406 | hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa; |
407 | } | |
b73f9a4a | 408 | |
a5de7de7 JB |
409 | if (sec_key_ver && |
410 | fw_has_capa(&mvm->fw->ucode_capa, | |
411 | IWL_UCODE_TLV_CAPA_BIGTK_TX_SUPPORT)) | |
412 | wiphy_ext_feature_set(hw->wiphy, | |
413 | NL80211_EXT_FEATURE_BEACON_PROTECTION); | |
414 | else if (fw_has_capa(&mvm->fw->ucode_capa, | |
415 | IWL_UCODE_TLV_CAPA_BIGTK_SUPPORT)) | |
b1fdc250 JB |
416 | wiphy_ext_feature_set(hw->wiphy, |
417 | NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT); | |
418 | ||
30686bf7 | 419 | ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); |
1f940386 LC |
420 | hw->wiphy->features |= |
421 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | | |
3db93420 JB |
422 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR | |
423 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
fb98be5e | 424 | |
8ca151b5 JB |
425 | hw->sta_data_size = sizeof(struct iwl_mvm_sta); |
426 | hw->vif_data_size = sizeof(struct iwl_mvm_vif); | |
fe0f2de3 | 427 | hw->chanctx_data_size = sizeof(u16); |
cfbc6c4c | 428 | hw->txq_data_size = sizeof(struct iwl_mvm_txq); |
8ca151b5 JB |
429 | |
430 | hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | |
3c15a0fb JB |
431 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
432 | BIT(NL80211_IFTYPE_AP) | | |
433 | BIT(NL80211_IFTYPE_P2P_GO) | | |
c13b1725 EG |
434 | BIT(NL80211_IFTYPE_P2P_DEVICE) | |
435 | BIT(NL80211_IFTYPE_ADHOC); | |
5023d966 | 436 | |
a2f73b6c | 437 | hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
e47df5bd | 438 | wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS); |
33e3fd99 AW |
439 | |
440 | /* The new Tx API does not allow to pass the key or keyid of a MPDU to | |
441 | * the hw, preventing us to control which key(id) to use per MPDU. | |
442 | * Till that's fixed we can't use Extended Key ID for the newer cards. | |
443 | */ | |
444 | if (!iwl_mvm_has_new_tx_api(mvm)) | |
445 | wiphy_ext_feature_set(hw->wiphy, | |
446 | NL80211_EXT_FEATURE_EXT_KEY_ID); | |
e47df5bd JB |
447 | hw->wiphy->features |= NL80211_FEATURE_HT_IBSS; |
448 | ||
8ba2d7a1 EH |
449 | hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR; |
450 | if (iwl_mvm_is_lar_supported(mvm)) | |
451 | hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED; | |
452 | else | |
453 | hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG | | |
454 | REGULATORY_DISABLE_BEACON_HINTS; | |
8ca151b5 | 455 | |
4b87e5af | 456 | hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; |
94bbed72 | 457 | hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
eae94cf8 | 458 | hw->wiphy->flags |= WIPHY_FLAG_SPLIT_SCAN_6GHZ; |
bd3398e2 | 459 | |
8ca151b5 JB |
460 | hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; |
461 | hw->wiphy->n_iface_combinations = | |
462 | ARRAY_SIZE(iwl_mvm_iface_combinations); | |
463 | ||
c451e6d4 | 464 | hw->wiphy->max_remain_on_channel_duration = 10000; |
8ca151b5 JB |
465 | hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; |
466 | ||
467 | /* Extract MAC address */ | |
468 | memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); | |
469 | hw->wiphy->addresses = mvm->addresses; | |
470 | hw->wiphy->n_addresses = 1; | |
831e85f3 IP |
471 | |
472 | /* Extract additional MAC addresses if available */ | |
473 | num_mac = (mvm->nvm_data->n_hw_addrs > 1) ? | |
474 | min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1; | |
475 | ||
476 | for (i = 1; i < num_mac; i++) { | |
477 | memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr, | |
8ca151b5 | 478 | ETH_ALEN); |
831e85f3 | 479 | mvm->addresses[i].addr[5]++; |
8ca151b5 JB |
480 | hw->wiphy->n_addresses++; |
481 | } | |
482 | ||
fe0f2de3 IP |
483 | iwl_mvm_reset_phy_ctxts(mvm); |
484 | ||
999d2568 | 485 | hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm); |
20f1a5de | 486 | |
8ca151b5 JB |
487 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; |
488 | ||
c7d42480 | 489 | BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK); |
507e4cda LC |
490 | BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) || |
491 | IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK)); | |
492 | ||
859d914c | 493 | if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) |
507e4cda LC |
494 | mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS; |
495 | else | |
496 | mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS; | |
497 | ||
57fbcce3 JB |
498 | if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels) |
499 | hw->wiphy->bands[NL80211_BAND_2GHZ] = | |
500 | &mvm->nvm_data->bands[NL80211_BAND_2GHZ]; | |
501 | if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) { | |
502 | hw->wiphy->bands[NL80211_BAND_5GHZ] = | |
503 | &mvm->nvm_data->bands[NL80211_BAND_5GHZ]; | |
8ca151b5 | 504 | |
859d914c JB |
505 | if (fw_has_capa(&mvm->fw->ucode_capa, |
506 | IWL_UCODE_TLV_CAPA_BEAMFORMER) && | |
507 | fw_has_api(&mvm->fw->ucode_capa, | |
508 | IWL_UCODE_TLV_API_LQ_SS_PARAMS)) | |
57fbcce3 | 509 | hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |= |
3d44eebf ES |
510 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE; |
511 | } | |
eae94cf8 LC |
512 | if (fw_has_capa(&mvm->fw->ucode_capa, |
513 | IWL_UCODE_TLV_CAPA_PSC_CHAN_SUPPORT) && | |
514 | mvm->nvm_data->bands[NL80211_BAND_6GHZ].n_channels) | |
515 | hw->wiphy->bands[NL80211_BAND_6GHZ] = | |
516 | &mvm->nvm_data->bands[NL80211_BAND_6GHZ]; | |
3d44eebf | 517 | |
8ca151b5 JB |
518 | hw->wiphy->hw_version = mvm->trans->hw_id; |
519 | ||
ade50652 | 520 | if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) |
8ca151b5 JB |
521 | hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; |
522 | else | |
523 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; | |
524 | ||
ca986ad9 | 525 | hw->wiphy->max_sched_scan_reqs = 1; |
9954b37c | 526 | hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; |
5d1234ba | 527 | hw->wiphy->max_match_sets = iwl_umac_scan_get_max_profiles(mvm->fw); |
9954b37c EG |
528 | /* we create the 802.11 header and zero length SSID IE. */ |
529 | hw->wiphy->max_sched_scan_ie_len = | |
530 | SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2; | |
cd55ccea AS |
531 | hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS; |
532 | hw->wiphy->max_sched_scan_plan_interval = U16_MAX; | |
533 | ||
534 | /* | |
535 | * the firmware uses u8 for num of iterations, but 0xff is saved for | |
536 | * infinite loop, so the maximum number of iterations is actually 254. | |
537 | */ | |
538 | hw->wiphy->max_sched_scan_plan_iterations = 254; | |
35a000b7 | 539 | |
8ca151b5 | 540 | hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | |
ab480030 | 541 | NL80211_FEATURE_LOW_PRIORITY_SCAN | |
0d8614b4 | 542 | NL80211_FEATURE_P2P_GO_OPPPS | |
a904a08b | 543 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | |
0d8614b4 | 544 | NL80211_FEATURE_DYNAMIC_SMPS | |
9b5452fd EG |
545 | NL80211_FEATURE_STATIC_SMPS | |
546 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION; | |
8ca151b5 | 547 | |
859d914c JB |
548 | if (fw_has_capa(&mvm->fw->ucode_capa, |
549 | IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)) | |
f1daa00e | 550 | hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION; |
859d914c JB |
551 | if (fw_has_capa(&mvm->fw->ucode_capa, |
552 | IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)) | |
226bcd48 | 553 | hw->wiphy->features |= NL80211_FEATURE_QUIET; |
f1daa00e | 554 | |
859d914c JB |
555 | if (fw_has_capa(&mvm->fw->ucode_capa, |
556 | IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)) | |
73897bd1 AO |
557 | hw->wiphy->features |= |
558 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES; | |
559 | ||
859d914c JB |
560 | if (fw_has_capa(&mvm->fw->ucode_capa, |
561 | IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)) | |
73897bd1 AO |
562 | hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES; |
563 | ||
971cbe50 | 564 | if (iwl_fw_lookup_cmd_ver(mvm->fw, WOWLAN_KEK_KCK_MATERIAL, |
2a42aea7 NE |
565 | IWL_FW_CMD_VER_UNKNOWN) == 3) |
566 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK; | |
567 | ||
aacf8f18 AS |
568 | if (fw_has_api(&mvm->fw->ucode_capa, |
569 | IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) { | |
570 | wiphy_ext_feature_set(hw->wiphy, | |
571 | NL80211_EXT_FEATURE_SCAN_START_TIME); | |
572 | wiphy_ext_feature_set(hw->wiphy, | |
573 | NL80211_EXT_FEATURE_BSS_PARENT_TSF); | |
aacf8f18 AS |
574 | } |
575 | ||
8f691af9 | 576 | if (iwl_mvm_is_oce_supported(mvm)) { |
971cbe50 | 577 | u8 scan_ver = iwl_fw_lookup_cmd_ver(mvm->fw, SCAN_REQ_UMAC, 0); |
773a042f | 578 | |
8f691af9 ZR |
579 | wiphy_ext_feature_set(hw->wiphy, |
580 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP); | |
581 | wiphy_ext_feature_set(hw->wiphy, | |
582 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME); | |
8f691af9 ZR |
583 | wiphy_ext_feature_set(hw->wiphy, |
584 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE); | |
773a042f AS |
585 | |
586 | /* Old firmware also supports probe deferral and suppression */ | |
587 | if (scan_ver < 15) | |
588 | wiphy_ext_feature_set(hw->wiphy, | |
589 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION); | |
8f691af9 ZR |
590 | } |
591 | ||
8e33f046 KP |
592 | hw->wiphy->iftype_ext_capab = NULL; |
593 | hw->wiphy->num_iftype_ext_capab = 0; | |
594 | ||
7360f99e EG |
595 | if (mvm->nvm_data->sku_cap_11ax_enable && |
596 | !iwlwifi_mod_params.disable_11ax) { | |
8e33f046 | 597 | hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa; |
7360f99e | 598 | hw->wiphy->num_iftype_ext_capab = |
8e33f046 | 599 | ARRAY_SIZE(add_iftypes_ext_capa) - 1; |
918cbf39 SS |
600 | |
601 | ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID); | |
602 | ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID); | |
7360f99e EG |
603 | } |
604 | ||
8e33f046 KP |
605 | if (iwl_fw_lookup_cmd_ver(mvm->fw, |
606 | WIDE_ID(DATA_PATH_GROUP, | |
607 | WNM_80211V_TIMING_MEASUREMENT_CONFIG_CMD), | |
608 | IWL_FW_CMD_VER_UNKNOWN) >= 1) { | |
609 | IWL_DEBUG_INFO(mvm->trans, "Timing measurement supported\n"); | |
610 | ||
611 | if (!hw->wiphy->iftype_ext_capab) { | |
612 | hw->wiphy->num_iftype_ext_capab = 1; | |
613 | hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa + | |
614 | ARRAY_SIZE(add_iftypes_ext_capa) - 1; | |
615 | } else { | |
616 | hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa + 1; | |
617 | } | |
618 | } | |
619 | ||
8ca151b5 JB |
620 | mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
621 | ||
622 | #ifdef CONFIG_PM_SLEEP | |
3f37c229 | 623 | if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) && |
8ca151b5 JB |
624 | mvm->trans->ops->d3_suspend && |
625 | mvm->trans->ops->d3_resume && | |
626 | device_can_wakeup(mvm->trans->dev)) { | |
91742449 EP |
627 | mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT | |
628 | WIPHY_WOWLAN_DISCONNECT | | |
629 | WIPHY_WOWLAN_EAP_IDENTITY_REQ | | |
630 | WIPHY_WOWLAN_RFKILL_RELEASE | | |
631 | WIPHY_WOWLAN_NET_DETECT; | |
f4bfdc5e EG |
632 | mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | |
633 | WIPHY_WOWLAN_GTK_REKEY_FAILURE | | |
634 | WIPHY_WOWLAN_4WAY_HANDSHAKE; | |
964dc9e2 JB |
635 | |
636 | mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; | |
637 | mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; | |
638 | mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; | |
5d1234ba TM |
639 | mvm->wowlan.max_nd_match_sets = |
640 | iwl_umac_scan_get_max_profiles(mvm->fw); | |
964dc9e2 | 641 | hw->wiphy->wowlan = &mvm->wowlan; |
8ca151b5 JB |
642 | } |
643 | #endif | |
644 | ||
645 | ret = iwl_mvm_leds_init(mvm); | |
646 | if (ret) | |
647 | return ret; | |
648 | ||
859d914c JB |
649 | if (fw_has_capa(&mvm->fw->ucode_capa, |
650 | IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) { | |
d8f1c515 AN |
651 | IWL_DEBUG_TDLS(mvm, "TDLS supported\n"); |
652 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; | |
7c4f0843 | 653 | ieee80211_hw_set(hw, TDLS_WIDER_BW); |
d8f1c515 AN |
654 | } |
655 | ||
859d914c JB |
656 | if (fw_has_capa(&mvm->fw->ucode_capa, |
657 | IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) { | |
1d3c3f63 AN |
658 | IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n"); |
659 | hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH; | |
660 | } | |
661 | ||
93190fb0 | 662 | hw->netdev_features |= mvm->cfg->features; |
59fa61f3 | 663 | if (!iwl_mvm_is_csum_supported(mvm)) |
6772aab7 | 664 | hw->netdev_features &= ~IWL_CSUM_NETIF_FLAGS_MASK; |
41837ca9 | 665 | |
91b08c2d AE |
666 | if (mvm->cfg->vht_mu_mimo_supported) |
667 | wiphy_ext_feature_set(hw->wiphy, | |
668 | NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER); | |
669 | ||
9c11d8a9 ST |
670 | if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT)) |
671 | wiphy_ext_feature_set(hw->wiphy, | |
672 | NL80211_EXT_FEATURE_PROTECTED_TWT); | |
673 | ||
bfcfdb59 EG |
674 | iwl_mvm_vendor_cmds_register(mvm); |
675 | ||
e8503aec BG |
676 | hw->wiphy->available_antennas_tx = iwl_mvm_get_valid_tx_ant(mvm); |
677 | hw->wiphy->available_antennas_rx = iwl_mvm_get_valid_rx_ant(mvm); | |
678 | ||
de645e89 JB |
679 | ret = ieee80211_register_hw(mvm->hw); |
680 | if (ret) { | |
681 | iwl_mvm_leds_exit(mvm); | |
de645e89 JB |
682 | } |
683 | ||
b7327d89 | 684 | return ret; |
8ca151b5 JB |
685 | } |
686 | ||
df2378ab JB |
687 | static void iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb, |
688 | struct ieee80211_sta *sta) | |
689 | { | |
690 | if (likely(sta)) { | |
691 | if (likely(iwl_mvm_tx_skb_sta(mvm, skb, sta) == 0)) | |
692 | return; | |
693 | } else { | |
694 | if (likely(iwl_mvm_tx_skb_non_sta(mvm, skb) == 0)) | |
695 | return; | |
696 | } | |
697 | ||
698 | ieee80211_free_txskb(mvm->hw, skb); | |
699 | } | |
700 | ||
8ca151b5 JB |
701 | static void iwl_mvm_mac_tx(struct ieee80211_hw *hw, |
702 | struct ieee80211_tx_control *control, | |
703 | struct sk_buff *skb) | |
704 | { | |
705 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
3e56eadf JB |
706 | struct ieee80211_sta *sta = control->sta; |
707 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
708 | struct ieee80211_hdr *hdr = (void *)skb->data; | |
cfbc6c4c SS |
709 | bool offchannel = IEEE80211_SKB_CB(skb)->flags & |
710 | IEEE80211_TX_CTL_TX_OFFCHAN; | |
8ca151b5 | 711 | |
9ee718aa EL |
712 | if (iwl_mvm_is_radio_killed(mvm)) { |
713 | IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); | |
8ca151b5 JB |
714 | goto drop; |
715 | } | |
716 | ||
cfbc6c4c | 717 | if (offchannel && |
a6cc5163 MG |
718 | !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) && |
719 | !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status)) | |
8ca151b5 JB |
720 | goto drop; |
721 | ||
10516783 JB |
722 | /* |
723 | * bufferable MMPDUs or MMPDUs on STA interfaces come via TXQs | |
724 | * so we treat the others as broadcast | |
725 | */ | |
726 | if (ieee80211_is_mgmt(hdr->frame_control)) | |
3e56eadf JB |
727 | sta = NULL; |
728 | ||
dc1aca22 | 729 | /* If there is no sta, and it's not offchannel - send through AP */ |
cfbc6c4c SS |
730 | if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION && |
731 | !offchannel) { | |
dc1aca22 AO |
732 | struct iwl_mvm_vif *mvmvif = |
733 | iwl_mvm_vif_from_mac80211(info->control.vif); | |
734 | u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id); | |
735 | ||
be9ae34e | 736 | if (ap_sta_id < mvm->fw->ucode_capa.num_stations) { |
dc1aca22 AO |
737 | /* mac80211 holds rcu read lock */ |
738 | sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]); | |
739 | if (IS_ERR_OR_NULL(sta)) | |
740 | goto drop; | |
741 | } | |
742 | } | |
743 | ||
df2378ab | 744 | iwl_mvm_tx_skb(mvm, skb, sta); |
8ca151b5 JB |
745 | return; |
746 | drop: | |
747 | ieee80211_free_txskb(hw, skb); | |
748 | } | |
749 | ||
cfbc6c4c | 750 | void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq) |
205e2210 | 751 | { |
cfbc6c4c SS |
752 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
753 | struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); | |
754 | struct sk_buff *skb = NULL; | |
755 | ||
fba8248e SS |
756 | /* |
757 | * No need for threads to be pending here, they can leave the first | |
758 | * taker all the work. | |
759 | * | |
760 | * mvmtxq->tx_request logic: | |
761 | * | |
762 | * If 0, no one is currently TXing, set to 1 to indicate current thread | |
763 | * will now start TX and other threads should quit. | |
764 | * | |
765 | * If 1, another thread is currently TXing, set to 2 to indicate to | |
766 | * that thread that there was another request. Since that request may | |
767 | * have raced with the check whether the queue is empty, the TXing | |
768 | * thread should check the queue's status one more time before leaving. | |
769 | * This check is done in order to not leave any TX hanging in the queue | |
770 | * until the next TX invocation (which may not even happen). | |
771 | * | |
772 | * If 2, another thread is currently TXing, and it will already double | |
773 | * check the queue, so do nothing. | |
774 | */ | |
775 | if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2)) | |
776 | return; | |
cfbc6c4c SS |
777 | |
778 | rcu_read_lock(); | |
fba8248e SS |
779 | do { |
780 | while (likely(!mvmtxq->stopped && | |
00520b7a | 781 | !test_bit(IWL_MVM_STATUS_IN_D3, &mvm->status))) { |
fba8248e SS |
782 | skb = ieee80211_tx_dequeue(hw, txq); |
783 | ||
f50d693b SS |
784 | if (!skb) { |
785 | if (txq->sta) | |
786 | IWL_DEBUG_TX(mvm, | |
787 | "TXQ of sta %pM tid %d is now empty\n", | |
788 | txq->sta->addr, | |
789 | txq->tid); | |
fba8248e | 790 | break; |
f50d693b | 791 | } |
fba8248e | 792 | |
df2378ab | 793 | iwl_mvm_tx_skb(mvm, skb, txq->sta); |
fba8248e SS |
794 | } |
795 | } while (atomic_dec_return(&mvmtxq->tx_request)); | |
cfbc6c4c | 796 | rcu_read_unlock(); |
205e2210 EG |
797 | } |
798 | ||
cfbc6c4c SS |
799 | static void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw, |
800 | struct ieee80211_txq *txq) | |
205e2210 | 801 | { |
cfbc6c4c SS |
802 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
803 | struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); | |
205e2210 | 804 | |
cfbc6c4c SS |
805 | /* |
806 | * Please note that racing is handled very carefully here: | |
807 | * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is | |
808 | * deleted afterwards. | |
809 | * This means that if: | |
810 | * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list): | |
811 | * queue is allocated and we can TX. | |
812 | * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list): | |
813 | * a race, should defer the frame. | |
814 | * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list): | |
815 | * need to allocate the queue and defer the frame. | |
816 | * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list): | |
817 | * queue is already scheduled for allocation, no need to allocate, | |
818 | * should defer the frame. | |
819 | */ | |
820 | ||
821 | /* If the queue is allocated TX and return. */ | |
822 | if (!txq->sta || mvmtxq->txq_id != IWL_MVM_INVALID_QUEUE) { | |
823 | /* | |
824 | * Check that list is empty to avoid a race where txq_id is | |
825 | * already updated, but the queue allocation work wasn't | |
826 | * finished | |
827 | */ | |
828 | if (unlikely(txq->sta && !list_empty(&mvmtxq->list))) | |
829 | return; | |
830 | ||
831 | iwl_mvm_mac_itxq_xmit(hw, txq); | |
832 | return; | |
833 | } | |
834 | ||
835 | /* The list is being deleted only after the queue is fully allocated. */ | |
836 | if (!list_empty(&mvmtxq->list)) | |
837 | return; | |
838 | ||
839 | list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs); | |
840 | schedule_work(&mvm->add_stream_wk); | |
205e2210 EG |
841 | } |
842 | ||
7174beb6 JB |
843 | #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \ |
844 | do { \ | |
845 | if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \ | |
846 | break; \ | |
847 | iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \ | |
4203263d EG |
848 | } while (0) |
849 | ||
850 | static void | |
851 | iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif, | |
852 | struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn, | |
853 | enum ieee80211_ampdu_mlme_action action) | |
854 | { | |
855 | struct iwl_fw_dbg_trigger_tlv *trig; | |
856 | struct iwl_fw_dbg_trigger_ba *ba_trig; | |
857 | ||
6c042d75 SS |
858 | trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), |
859 | FW_DBG_TRIGGER_BA); | |
860 | if (!trig) | |
4203263d EG |
861 | return; |
862 | ||
4203263d EG |
863 | ba_trig = (void *)trig->data; |
864 | ||
4203263d EG |
865 | switch (action) { |
866 | case IEEE80211_AMPDU_TX_OPERATIONAL: { | |
867 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
868 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; | |
869 | ||
870 | CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid, | |
871 | "TX AGG START: MAC %pM tid %d ssn %d\n", | |
872 | sta->addr, tid, tid_data->ssn); | |
873 | break; | |
874 | } | |
875 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
876 | CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid, | |
877 | "TX AGG STOP: MAC %pM tid %d\n", | |
878 | sta->addr, tid); | |
879 | break; | |
880 | case IEEE80211_AMPDU_RX_START: | |
881 | CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid, | |
882 | "RX AGG START: MAC %pM tid %d ssn %d\n", | |
883 | sta->addr, tid, rx_ba_ssn); | |
884 | break; | |
885 | case IEEE80211_AMPDU_RX_STOP: | |
886 | CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid, | |
887 | "RX AGG STOP: MAC %pM tid %d\n", | |
888 | sta->addr, tid); | |
889 | break; | |
890 | default: | |
891 | break; | |
892 | } | |
893 | } | |
894 | ||
8ca151b5 JB |
895 | static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, |
896 | struct ieee80211_vif *vif, | |
50ea05ef | 897 | struct ieee80211_ampdu_params *params) |
8ca151b5 JB |
898 | { |
899 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
900 | int ret; | |
50ea05ef SS |
901 | struct ieee80211_sta *sta = params->sta; |
902 | enum ieee80211_ampdu_mlme_action action = params->action; | |
903 | u16 tid = params->tid; | |
904 | u16 *ssn = ¶ms->ssn; | |
514c3069 | 905 | u16 buf_size = params->buf_size; |
bb81bb68 | 906 | bool amsdu = params->amsdu; |
10b2b201 | 907 | u16 timeout = params->timeout; |
8ca151b5 JB |
908 | |
909 | IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", | |
910 | sta->addr, tid, action); | |
911 | ||
912 | if (!(mvm->nvm_data->sku_cap_11n_enable)) | |
913 | return -EACCES; | |
914 | ||
915 | mutex_lock(&mvm->mutex); | |
916 | ||
917 | switch (action) { | |
918 | case IEEE80211_AMPDU_RX_START: | |
b0ffe455 JB |
919 | if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id == |
920 | iwl_mvm_sta_from_mac80211(sta)->sta_id) { | |
921 | struct iwl_mvm_vif *mvmvif; | |
922 | u16 macid = iwl_mvm_vif_from_mac80211(vif)->id; | |
923 | struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid]; | |
924 | ||
925 | mdata->opened_rx_ba_sessions = true; | |
926 | mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
927 | cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk); | |
928 | } | |
e78da25e | 929 | if (!iwl_enable_rx_ampdu()) { |
8ca151b5 JB |
930 | ret = -EINVAL; |
931 | break; | |
932 | } | |
10b2b201 SS |
933 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size, |
934 | timeout); | |
8ca151b5 JB |
935 | break; |
936 | case IEEE80211_AMPDU_RX_STOP: | |
10b2b201 SS |
937 | ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size, |
938 | timeout); | |
8ca151b5 JB |
939 | break; |
940 | case IEEE80211_AMPDU_TX_START: | |
e78da25e | 941 | if (!iwl_enable_tx_ampdu()) { |
5d158efa EG |
942 | ret = -EINVAL; |
943 | break; | |
944 | } | |
8ca151b5 JB |
945 | ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); |
946 | break; | |
947 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
e3d9e7ce EG |
948 | ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); |
949 | break; | |
8ca151b5 JB |
950 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
951 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
e3d9e7ce | 952 | ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); |
8ca151b5 JB |
953 | break; |
954 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
bb81bb68 EG |
955 | ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, |
956 | buf_size, amsdu); | |
8ca151b5 JB |
957 | break; |
958 | default: | |
959 | WARN_ON_ONCE(1); | |
960 | ret = -EINVAL; | |
961 | break; | |
962 | } | |
4203263d EG |
963 | |
964 | if (!ret) { | |
965 | u16 rx_ba_ssn = 0; | |
966 | ||
967 | if (action == IEEE80211_AMPDU_RX_START) | |
968 | rx_ba_ssn = *ssn; | |
969 | ||
970 | iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid, | |
971 | rx_ba_ssn, action); | |
972 | } | |
8ca151b5 JB |
973 | mutex_unlock(&mvm->mutex); |
974 | ||
975 | return ret; | |
976 | } | |
977 | ||
978 | static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, | |
979 | struct ieee80211_vif *vif) | |
980 | { | |
981 | struct iwl_mvm *mvm = data; | |
982 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
983 | ||
984 | mvmvif->uploaded = false; | |
0ae98812 | 985 | mvmvif->ap_sta_id = IWL_MVM_INVALID_STA; |
8ca151b5 | 986 | |
8ca151b5 JB |
987 | spin_lock_bh(&mvm->time_event_lock); |
988 | iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); | |
989 | spin_unlock_bh(&mvm->time_event_lock); | |
990 | ||
fe0f2de3 | 991 | mvmvif->phy_ctxt = NULL; |
8a275bad | 992 | memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data)); |
86e177d8 | 993 | memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data)); |
8ca151b5 JB |
994 | } |
995 | ||
996 | static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) | |
997 | { | |
fcb6b92a | 998 | iwl_mvm_stop_device(mvm); |
8ca151b5 | 999 | |
9bf13bee JB |
1000 | mvm->cur_aid = 0; |
1001 | ||
9af91f46 | 1002 | mvm->scan_status = 0; |
b1873300 | 1003 | mvm->ps_disabled = false; |
b3500b47 | 1004 | mvm->rfkill_safe_init_done = false; |
8ca151b5 JB |
1005 | |
1006 | /* just in case one was running */ | |
305d236e | 1007 | iwl_mvm_cleanup_roc_te(mvm); |
8ca151b5 JB |
1008 | ieee80211_remain_on_channel_expired(mvm->hw); |
1009 | ||
fc36ffda JB |
1010 | iwl_mvm_ftm_restart(mvm); |
1011 | ||
737719fe AN |
1012 | /* |
1013 | * cleanup all interfaces, even inactive ones, as some might have | |
1014 | * gone down during the HW restart | |
1015 | */ | |
1016 | ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm); | |
8ca151b5 | 1017 | |
fe0f2de3 IP |
1018 | mvm->p2p_device_vif = NULL; |
1019 | ||
1020 | iwl_mvm_reset_phy_ctxts(mvm); | |
9c3deeb5 | 1021 | memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); |
8a275bad | 1022 | memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); |
8a275bad | 1023 | memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd)); |
8ca151b5 JB |
1024 | |
1025 | ieee80211_wake_queues(mvm->hw); | |
1026 | ||
113a0447 | 1027 | mvm->rx_ba_sessions = 0; |
7174beb6 | 1028 | mvm->fwrt.dump.conf = FW_DBG_INVALID; |
baf41bc3 | 1029 | mvm->monitor_on = false; |
91a8bcde JB |
1030 | |
1031 | /* keep statistics ticking */ | |
1032 | iwl_mvm_accu_radio_stats(mvm); | |
8ca151b5 JB |
1033 | } |
1034 | ||
a0a09243 | 1035 | int __iwl_mvm_mac_start(struct iwl_mvm *mvm) |
8ca151b5 | 1036 | { |
8ca151b5 JB |
1037 | int ret; |
1038 | ||
a0a09243 | 1039 | lockdep_assert_held(&mvm->mutex); |
8ca151b5 | 1040 | |
6d19a5eb EG |
1041 | ret = iwl_mvm_mei_get_ownership(mvm); |
1042 | if (ret) | |
1043 | return ret; | |
1044 | ||
1045 | if (mvm->mei_nvm_data) { | |
1046 | /* We got the NIC, we can now free the MEI NVM data */ | |
1047 | kfree(mvm->mei_nvm_data); | |
1048 | mvm->mei_nvm_data = NULL; | |
1049 | ||
1050 | /* | |
1051 | * We can't free the nvm_data we allocated based on the SAP | |
1052 | * data because we registered to cfg80211 with the channels | |
1053 | * allocated on mvm->nvm_data. Keep a pointer in temp_nvm_data | |
1054 | * just in order to be able free it later. | |
1055 | * NULLify nvm_data so that we will read the NVM from the | |
1056 | * firmware this time. | |
1057 | */ | |
1058 | mvm->temp_nvm_data = mvm->nvm_data; | |
1059 | mvm->nvm_data = NULL; | |
1060 | } | |
1061 | ||
bf8b286f JB |
1062 | if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) { |
1063 | /* | |
1064 | * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART | |
1065 | * so later code will - from now on - see that we're doing it. | |
1066 | */ | |
1067 | set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); | |
1068 | clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status); | |
a42b2af3 | 1069 | /* Clean up some internal and mac80211 state on restart */ |
8ca151b5 | 1070 | iwl_mvm_restart_cleanup(mvm); |
a42b2af3 | 1071 | } |
8ca151b5 | 1072 | ret = iwl_mvm_up(mvm); |
c47af22a | 1073 | |
b108d8c7 SM |
1074 | iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT, |
1075 | NULL); | |
1076 | iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC, | |
1077 | NULL); | |
da2eb669 | 1078 | |
e8fe3b41 IP |
1079 | mvm->last_reset_or_resume_time_jiffies = jiffies; |
1080 | ||
c47af22a JB |
1081 | if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
1082 | /* Something went wrong - we need to finish some cleanup | |
1083 | * that normally iwl_mvm_mac_restart_complete() below | |
1084 | * would do. | |
1085 | */ | |
1086 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); | |
c47af22a JB |
1087 | } |
1088 | ||
a0a09243 LC |
1089 | return ret; |
1090 | } | |
1091 | ||
1092 | static int iwl_mvm_mac_start(struct ieee80211_hw *hw) | |
1093 | { | |
1094 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1095 | int ret; | |
5283dd67 | 1096 | int retry, max_retry = 0; |
a0a09243 LC |
1097 | |
1098 | mutex_lock(&mvm->mutex); | |
5283dd67 MG |
1099 | |
1100 | /* we are starting the mac not in error flow, and restart is enabled */ | |
1101 | if (!test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) && | |
1102 | iwlwifi_mod_params.fw_restart) { | |
1103 | max_retry = IWL_MAX_INIT_RETRY; | |
1104 | /* | |
1105 | * This will prevent mac80211 recovery flows to trigger during | |
1106 | * init failures | |
1107 | */ | |
1108 | set_bit(IWL_MVM_STATUS_STARTING, &mvm->status); | |
1109 | } | |
1110 | ||
1111 | for (retry = 0; retry <= max_retry; retry++) { | |
1112 | ret = __iwl_mvm_mac_start(mvm); | |
1113 | if (!ret) | |
1114 | break; | |
1115 | ||
b8133439 AS |
1116 | /* |
1117 | * In PLDR sync PCI re-enumeration is needed. no point to retry | |
1118 | * mac start before that. | |
1119 | */ | |
1120 | if (mvm->pldr_sync) { | |
1121 | iwl_mei_alive_notif(false); | |
1122 | iwl_trans_pcie_remove(mvm->trans, true); | |
1123 | break; | |
1124 | } | |
1125 | ||
5283dd67 MG |
1126 | IWL_ERR(mvm, "mac start retry %d\n", retry); |
1127 | } | |
1128 | clear_bit(IWL_MVM_STATUS_STARTING, &mvm->status); | |
1129 | ||
8ca151b5 JB |
1130 | mutex_unlock(&mvm->mutex); |
1131 | ||
7ce1f215 EG |
1132 | iwl_mvm_mei_set_sw_rfkill_state(mvm); |
1133 | ||
8ca151b5 JB |
1134 | return ret; |
1135 | } | |
1136 | ||
cf2c92d8 | 1137 | static void iwl_mvm_restart_complete(struct iwl_mvm *mvm) |
8ca151b5 | 1138 | { |
8ca151b5 JB |
1139 | int ret; |
1140 | ||
1141 | mutex_lock(&mvm->mutex); | |
1142 | ||
1143 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); | |
4d4183c4 | 1144 | |
e7afe89f | 1145 | ret = iwl_mvm_update_quotas(mvm, true, NULL); |
8ca151b5 JB |
1146 | if (ret) |
1147 | IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", | |
1148 | ret); | |
1149 | ||
f130bb75 MG |
1150 | iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY); |
1151 | ||
cbd2ae2d AN |
1152 | /* |
1153 | * If we have TDLS peers, remove them. We don't know the last seqno/PN | |
1154 | * of packets the FW sent out, so we must reconnect. | |
1155 | */ | |
1156 | iwl_mvm_teardown_tdls_peers(mvm); | |
1157 | ||
8ca151b5 JB |
1158 | mutex_unlock(&mvm->mutex); |
1159 | } | |
1160 | ||
cf2c92d8 EP |
1161 | static void |
1162 | iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw, | |
1163 | enum ieee80211_reconfig_type reconfig_type) | |
1164 | { | |
1165 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1166 | ||
1167 | switch (reconfig_type) { | |
1168 | case IEEE80211_RECONFIG_TYPE_RESTART: | |
1169 | iwl_mvm_restart_complete(mvm); | |
1170 | break; | |
1171 | case IEEE80211_RECONFIG_TYPE_SUSPEND: | |
1172 | break; | |
1173 | } | |
1174 | } | |
1175 | ||
a0a09243 | 1176 | void __iwl_mvm_mac_stop(struct iwl_mvm *mvm) |
8ca151b5 | 1177 | { |
a0a09243 | 1178 | lockdep_assert_held(&mvm->mutex); |
7498cf4c | 1179 | |
b68bd2e3 IP |
1180 | iwl_mvm_ftm_initiator_smooth_stop(mvm); |
1181 | ||
91a8bcde JB |
1182 | /* firmware counters are obviously reset now, but we shouldn't |
1183 | * partially track so also clear the fw_reset_accu counters. | |
1184 | */ | |
1185 | memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats)); | |
1186 | ||
8ca151b5 JB |
1187 | /* async_handlers_wk is now blocked */ |
1188 | ||
971cbe50 | 1189 | if (iwl_fw_lookup_cmd_ver(mvm->fw, ADD_STA, 0) < 12) |
2c2c3647 | 1190 | iwl_mvm_rm_aux_sta(mvm); |
f327236d | 1191 | |
fcb6b92a | 1192 | iwl_mvm_stop_device(mvm); |
8ca151b5 JB |
1193 | |
1194 | iwl_mvm_async_handlers_purge(mvm); | |
1195 | /* async_handlers_list is empty and will stay empty: HW is stopped */ | |
1196 | ||
0a79a0c0 | 1197 | /* |
155f7e04 EG |
1198 | * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the |
1199 | * hw (as restart_complete() won't be called in this case) and mac80211 | |
1200 | * won't execute the restart. | |
8b2b9fbf AN |
1201 | * But make sure to cleanup interfaces that have gone down before/during |
1202 | * HW restart was requested. | |
0a79a0c0 | 1203 | */ |
155f7e04 EG |
1204 | if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) || |
1205 | test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, | |
1206 | &mvm->status)) | |
8b2b9fbf AN |
1207 | ieee80211_iterate_interfaces(mvm->hw, 0, |
1208 | iwl_mvm_cleanup_iterator, mvm); | |
0a79a0c0 | 1209 | |
963221be AB |
1210 | /* We shouldn't have any UIDs still set. Loop over all the UIDs to |
1211 | * make sure there's nothing left there and warn if any is found. | |
1212 | */ | |
859d914c | 1213 | if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { |
963221be AB |
1214 | int i; |
1215 | ||
507e4cda | 1216 | for (i = 0; i < mvm->max_scans; i++) { |
6185af2a LC |
1217 | if (WARN_ONCE(mvm->scan_uid_status[i], |
1218 | "UMAC scan UID %d status was not cleaned\n", | |
1219 | i)) | |
1220 | mvm->scan_uid_status[i] = 0; | |
963221be AB |
1221 | } |
1222 | } | |
a0a09243 | 1223 | } |
bc44886d | 1224 | |
a0a09243 LC |
1225 | static void iwl_mvm_mac_stop(struct ieee80211_hw *hw) |
1226 | { | |
1227 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1228 | ||
a0a09243 | 1229 | flush_work(&mvm->async_handlers_wk); |
24afba76 | 1230 | flush_work(&mvm->add_stream_wk); |
771147b0 JB |
1231 | |
1232 | /* | |
1233 | * Lock and clear the firmware running bit here already, so that | |
1234 | * new commands coming in elsewhere, e.g. from debugfs, will not | |
1235 | * be able to proceed. This is important here because one of those | |
7174beb6 | 1236 | * debugfs files causes the firmware dump to be triggered, and if we |
771147b0 JB |
1237 | * don't stop debugfs accesses before canceling that it could be |
1238 | * retriggered after we flush it but before we've cleared the bit. | |
1239 | */ | |
1240 | clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); | |
1241 | ||
d3a108a4 | 1242 | cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork); |
69e04642 | 1243 | cancel_delayed_work_sync(&mvm->scan_timeout_dwork); |
a0a09243 | 1244 | |
f9084775 NE |
1245 | /* |
1246 | * The work item could be running or queued if the | |
1247 | * ROC time event stops just as we get here. | |
1248 | */ | |
1249 | flush_work(&mvm->roc_done_wk); | |
1250 | ||
7ce1f215 EG |
1251 | iwl_mvm_mei_set_sw_rfkill_state(mvm); |
1252 | ||
a0a09243 LC |
1253 | mutex_lock(&mvm->mutex); |
1254 | __iwl_mvm_mac_stop(mvm); | |
8ca151b5 JB |
1255 | mutex_unlock(&mvm->mutex); |
1256 | ||
1257 | /* | |
1258 | * The worker might have been waiting for the mutex, let it run and | |
1259 | * discover that its list is now empty. | |
1260 | */ | |
1261 | cancel_work_sync(&mvm->async_handlers_wk); | |
1262 | } | |
1263 | ||
1ab26632 | 1264 | struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) |
fe0f2de3 IP |
1265 | { |
1266 | u16 i; | |
1267 | ||
1268 | lockdep_assert_held(&mvm->mutex); | |
1269 | ||
1270 | for (i = 0; i < NUM_PHY_CTX; i++) | |
1271 | if (!mvm->phy_ctxts[i].ref) | |
1272 | return &mvm->phy_ctxts[i]; | |
1273 | ||
1274 | IWL_ERR(mvm, "No available PHY context\n"); | |
1275 | return NULL; | |
1276 | } | |
1277 | ||
d44c3fe6 AA |
1278 | static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
1279 | s16 tx_power) | |
1280 | { | |
971cbe50 | 1281 | u32 cmd_id = REDUCE_TX_POWER_CMD; |
0791c2fc | 1282 | int len; |
216cdfb5 LC |
1283 | struct iwl_dev_tx_power_cmd cmd = { |
1284 | .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC), | |
1285 | .common.mac_context_id = | |
d44c3fe6 | 1286 | cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id), |
216cdfb5 | 1287 | .common.pwr_restriction = cpu_to_le16(8 * tx_power), |
d44c3fe6 | 1288 | }; |
971cbe50 | 1289 | u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, |
e80bfd11 | 1290 | IWL_FW_CMD_VER_UNKNOWN); |
d44c3fe6 | 1291 | |
d44c3fe6 | 1292 | if (tx_power == IWL_DEFAULT_MAX_TX_POWER) |
216cdfb5 | 1293 | cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER); |
d44c3fe6 | 1294 | |
b0aa02b3 AB |
1295 | if (cmd_ver == 7) |
1296 | len = sizeof(cmd.v7); | |
1297 | else if (cmd_ver == 6) | |
fbb7957d LC |
1298 | len = sizeof(cmd.v6); |
1299 | else if (fw_has_api(&mvm->fw->ucode_capa, | |
1300 | IWL_UCODE_TLV_API_REDUCE_TX_POWER)) | |
0791c2fc HD |
1301 | len = sizeof(cmd.v5); |
1302 | else if (fw_has_capa(&mvm->fw->ucode_capa, | |
1303 | IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) | |
1304 | len = sizeof(cmd.v4); | |
1305 | else | |
216cdfb5 LC |
1306 | len = sizeof(cmd.v3); |
1307 | ||
1308 | /* all structs have the same common part, add it */ | |
1309 | len += sizeof(cmd.common); | |
da03f029 | 1310 | |
971cbe50 | 1311 | return iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, len, &cmd); |
d44c3fe6 AA |
1312 | } |
1313 | ||
f6780614 SS |
1314 | static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw, |
1315 | struct ieee80211_vif *vif) | |
1316 | { | |
1317 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1318 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1319 | int ret; | |
1320 | ||
1321 | mutex_lock(&mvm->mutex); | |
1322 | ||
f6780614 SS |
1323 | if (vif->type == NL80211_IFTYPE_STATION) { |
1324 | struct iwl_mvm_sta *mvmsta; | |
1325 | ||
1326 | mvmvif->csa_bcn_pending = false; | |
1327 | mvmsta = iwl_mvm_sta_from_staid_protected(mvm, | |
1328 | mvmvif->ap_sta_id); | |
1329 | ||
1330 | if (WARN_ON(!mvmsta)) { | |
1331 | ret = -EIO; | |
1332 | goto out_unlock; | |
1333 | } | |
1334 | ||
df720373 | 1335 | iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false); |
f6780614 SS |
1336 | |
1337 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); | |
1338 | ||
0202bcf0 EG |
1339 | if (!fw_has_capa(&mvm->fw->ucode_capa, |
1340 | IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { | |
1341 | ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); | |
1342 | if (ret) | |
1343 | goto out_unlock; | |
f6780614 | 1344 | |
0202bcf0 EG |
1345 | iwl_mvm_stop_session_protection(mvm, vif); |
1346 | } | |
f6780614 SS |
1347 | } |
1348 | ||
1349 | mvmvif->ps_disabled = false; | |
1350 | ||
1351 | ret = iwl_mvm_power_update_ps(mvm); | |
1352 | ||
1353 | out_unlock: | |
caf46377 SS |
1354 | if (mvmvif->csa_failed) |
1355 | ret = -EIO; | |
f6780614 SS |
1356 | mutex_unlock(&mvm->mutex); |
1357 | ||
1358 | return ret; | |
1359 | } | |
1360 | ||
1361 | static void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw, | |
1362 | struct ieee80211_vif *vif) | |
1363 | { | |
1364 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1365 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1366 | struct iwl_chan_switch_te_cmd cmd = { | |
1367 | .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, | |
1368 | mvmvif->color)), | |
1369 | .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE), | |
1370 | }; | |
1371 | ||
ad12b231 NE |
1372 | /* |
1373 | * In the new flow since FW is in charge of the timing, | |
1374 | * if driver has canceled the channel switch he will receive the | |
1375 | * CHANNEL_SWITCH_START_NOTIF notification from FW and then cancel it | |
1376 | */ | |
1377 | if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, | |
1378 | CHANNEL_SWITCH_ERROR_NOTIF, 0)) | |
1379 | return; | |
1380 | ||
f6780614 SS |
1381 | IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id); |
1382 | ||
1383 | mutex_lock(&mvm->mutex); | |
58ddd9b6 EG |
1384 | if (!fw_has_capa(&mvm->fw->ucode_capa, |
1385 | IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) | |
1386 | iwl_mvm_remove_csa_period(mvm, vif); | |
1387 | else | |
1388 | WARN_ON(iwl_mvm_send_cmd_pdu(mvm, | |
1389 | WIDE_ID(MAC_CONF_GROUP, | |
1390 | CHANNEL_SWITCH_TIME_EVENT_CMD), | |
1391 | 0, sizeof(cmd), &cmd)); | |
caf46377 | 1392 | mvmvif->csa_failed = true; |
f6780614 SS |
1393 | mutex_unlock(&mvm->mutex); |
1394 | ||
caf46377 | 1395 | iwl_mvm_post_channel_switch(hw, vif); |
f6780614 SS |
1396 | } |
1397 | ||
1ab26632 | 1398 | void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk) |
f6780614 | 1399 | { |
f6780614 SS |
1400 | struct iwl_mvm_vif *mvmvif; |
1401 | struct ieee80211_vif *vif; | |
1402 | ||
1403 | mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work); | |
1404 | vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv); | |
f6780614 | 1405 | |
70162580 | 1406 | /* Trigger disconnect (should clear the CSA state) */ |
f6780614 SS |
1407 | ieee80211_chswitch_done(vif, false); |
1408 | } | |
1409 | ||
5abf3154 MG |
1410 | static u8 |
1411 | iwl_mvm_chandef_get_primary_80(struct cfg80211_chan_def *chandef) | |
1412 | { | |
1413 | int data_start; | |
1414 | int control_start; | |
1415 | int bw; | |
1416 | ||
1417 | if (chandef->width == NL80211_CHAN_WIDTH_320) | |
1418 | bw = 320; | |
1419 | else if (chandef->width == NL80211_CHAN_WIDTH_160) | |
1420 | bw = 160; | |
1421 | else | |
1422 | return 0; | |
1423 | ||
1424 | /* data is bw wide so the start is half the width */ | |
1425 | data_start = chandef->center_freq1 - bw / 2; | |
1426 | /* control is 20Mhz width */ | |
1427 | control_start = chandef->chan->center_freq - 10; | |
1428 | ||
1429 | return (control_start - data_start) / 80; | |
1430 | } | |
1431 | ||
1ab26632 MK |
1432 | /* |
1433 | * Returns true if addding the interface is done | |
1434 | * (either with success or failure) | |
1435 | */ | |
1436 | bool iwl_mvm_mac_add_interface_common(struct iwl_mvm *mvm, | |
1437 | struct ieee80211_hw *hw, | |
1438 | struct ieee80211_vif *vif, int *ret) | |
8ca151b5 | 1439 | { |
8ca151b5 | 1440 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
1ab26632 MK |
1441 | |
1442 | lockdep_assert_held(&mvm->mutex); | |
8ca151b5 | 1443 | |
aa5e1832 | 1444 | mvmvif->mvm = mvm; |
86e177d8 | 1445 | RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL); |
aa5e1832 | 1446 | |
8ca151b5 JB |
1447 | /* |
1448 | * Not much to do here. The stack will not allow interface | |
1449 | * types or combinations that we didn't advertise, so we | |
1450 | * don't really have to check the types. | |
1451 | */ | |
1452 | ||
33cef925 JB |
1453 | /* make sure that beacon statistics don't go backwards with FW reset */ |
1454 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) | |
1455 | mvmvif->beacon_stats.accu_num_beacons += | |
1456 | mvmvif->beacon_stats.num_beacons; | |
1457 | ||
e89044d7 | 1458 | /* Allocate resources for the MAC context, and add it to the fw */ |
1ab26632 MK |
1459 | *ret = iwl_mvm_mac_ctxt_init(mvm, vif); |
1460 | if (*ret) | |
1461 | return true; | |
8ca151b5 | 1462 | |
698478c4 SS |
1463 | rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif); |
1464 | ||
8ca151b5 JB |
1465 | /* |
1466 | * The AP binding flow can be done only after the beacon | |
1467 | * template is configured (which happens only in the mac80211 | |
1468 | * start_ap() flow), and adding the broadcast station can happen | |
1469 | * only after the binding. | |
1470 | * In addition, since modifying the MAC before adding a bcast | |
1471 | * station is not allowed by the FW, delay the adding of MAC context to | |
1472 | * the point where we can also add the bcast station. | |
1473 | * In short: there's not much we can do at this point, other than | |
1474 | * allocating resources :) | |
1475 | */ | |
5023d966 JB |
1476 | if (vif->type == NL80211_IFTYPE_AP || |
1477 | vif->type == NL80211_IFTYPE_ADHOC) { | |
77740cb4 | 1478 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
1ab26632 | 1479 | return true; |
8ca151b5 JB |
1480 | } |
1481 | ||
93190fb0 | 1482 | mvmvif->features |= hw->netdev_features; |
1ab26632 MK |
1483 | return false; |
1484 | } | |
1485 | ||
1486 | static int iwl_mvm_alloc_bcast_mcast_sta(struct iwl_mvm *mvm, | |
1487 | struct ieee80211_vif *vif) | |
1488 | { | |
1489 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1490 | int ret; | |
1491 | ||
1492 | lockdep_assert_held(&mvm->mutex); | |
1493 | ||
1494 | ret = iwl_mvm_alloc_bcast_sta(mvm, vif); | |
1495 | if (ret) { | |
1496 | IWL_ERR(mvm, "Failed to allocate bcast sta\n"); | |
1497 | return ret; | |
1498 | } | |
1499 | ||
1500 | /* | |
1501 | * Only queue for this station is the mcast queue, | |
1502 | * which shouldn't be in TFD mask anyway | |
1503 | */ | |
1504 | return iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta, 0, vif->type, | |
1505 | IWL_STA_MULTICAST); | |
1506 | } | |
1507 | ||
1508 | static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, | |
1509 | struct ieee80211_vif *vif) | |
1510 | { | |
1511 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1512 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1513 | int ret; | |
1514 | ||
1515 | mutex_lock(&mvm->mutex); | |
1516 | ||
1517 | /* Common for MLD and non-MLD API */ | |
1518 | if (iwl_mvm_mac_add_interface_common(mvm, hw, vif, &ret)) | |
1519 | goto out; | |
93190fb0 | 1520 | |
8ca151b5 JB |
1521 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
1522 | if (ret) | |
98c0de7b | 1523 | goto out_unlock; |
8ca151b5 | 1524 | |
999609f1 | 1525 | ret = iwl_mvm_power_update_mac(mvm); |
e5e7aa8e | 1526 | if (ret) |
fd66fc1c | 1527 | goto out_remove_mac; |
8ca151b5 | 1528 | |
7df15b1e | 1529 | /* beacon filtering */ |
a1022927 | 1530 | ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); |
bd3351ba EP |
1531 | if (ret) |
1532 | goto out_remove_mac; | |
1533 | ||
7df15b1e | 1534 | if (!mvm->bf_allowed_vif && |
73e5f2c5 | 1535 | vif->type == NL80211_IFTYPE_STATION && !vif->p2p) { |
7df15b1e | 1536 | mvm->bf_allowed_vif = mvmvif; |
a20fd398 AO |
1537 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | |
1538 | IEEE80211_VIF_SUPPORTS_CQM_RSSI; | |
7df15b1e HG |
1539 | } |
1540 | ||
8ca151b5 JB |
1541 | /* |
1542 | * P2P_DEVICE interface does not have a channel context assigned to it, | |
1543 | * so a dedicated PHY context is allocated to it and the corresponding | |
1544 | * MAC context is bound to it at this stage. | |
1545 | */ | |
1546 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
8ca151b5 | 1547 | |
fe0f2de3 IP |
1548 | mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
1549 | if (!mvmvif->phy_ctxt) { | |
1550 | ret = -ENOSPC; | |
bd3351ba | 1551 | goto out_free_bf; |
fe0f2de3 | 1552 | } |
8ca151b5 | 1553 | |
53a9d61e | 1554 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); |
8ca151b5 JB |
1555 | ret = iwl_mvm_binding_add_vif(mvm, vif); |
1556 | if (ret) | |
53a9d61e | 1557 | goto out_unref_phy; |
8ca151b5 | 1558 | |
d197358b | 1559 | ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif); |
8ca151b5 JB |
1560 | if (ret) |
1561 | goto out_unbind; | |
1562 | ||
1563 | /* Save a pointer to p2p device vif, so it can later be used to | |
1564 | * update the p2p device MAC when a GO is started/stopped */ | |
1565 | mvm->p2p_device_vif = vif; | |
1566 | } | |
1567 | ||
b0ffe455 | 1568 | iwl_mvm_tcm_add_vif(mvm, vif); |
f6780614 SS |
1569 | INIT_DELAYED_WORK(&mvmvif->csa_work, |
1570 | iwl_mvm_channel_switch_disconnect_wk); | |
b0ffe455 | 1571 | |
5abf3154 | 1572 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
baf41bc3 | 1573 | mvm->monitor_on = true; |
5abf3154 MG |
1574 | mvm->monitor_p80 = |
1575 | iwl_mvm_chandef_get_primary_80(&vif->bss_conf.chandef); | |
1576 | } | |
baf41bc3 | 1577 | |
63494374 | 1578 | iwl_mvm_vif_dbgfs_register(mvm, vif); |
6d19a5eb EG |
1579 | |
1580 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && | |
1581 | vif->type == NL80211_IFTYPE_STATION && !vif->p2p && | |
1582 | !mvm->csme_vif && mvm->mei_registered) { | |
1583 | iwl_mei_set_nic_info(vif->addr, mvm->nvm_data->hw_addr); | |
1584 | iwl_mei_set_netdev(ieee80211_vif_to_wdev(vif)->netdev); | |
1585 | mvm->csme_vif = vif; | |
1586 | } | |
1587 | ||
1ab26632 MK |
1588 | out: |
1589 | if (!ret && (vif->type == NL80211_IFTYPE_AP || | |
1590 | vif->type == NL80211_IFTYPE_ADHOC)) | |
1591 | ret = iwl_mvm_alloc_bcast_mcast_sta(mvm, vif); | |
1592 | ||
8ca151b5 JB |
1593 | goto out_unlock; |
1594 | ||
1595 | out_unbind: | |
1596 | iwl_mvm_binding_remove_vif(mvm, vif); | |
53a9d61e | 1597 | out_unref_phy: |
fe0f2de3 | 1598 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
bd3351ba EP |
1599 | out_free_bf: |
1600 | if (mvm->bf_allowed_vif == mvmvif) { | |
1601 | mvm->bf_allowed_vif = NULL; | |
a20fd398 AO |
1602 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
1603 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); | |
bd3351ba | 1604 | } |
8ca151b5 JB |
1605 | out_remove_mac: |
1606 | mvmvif->phy_ctxt = NULL; | |
1607 | iwl_mvm_mac_ctxt_remove(mvm, vif); | |
8ca151b5 JB |
1608 | out_unlock: |
1609 | mutex_unlock(&mvm->mutex); | |
1610 | ||
1611 | return ret; | |
1612 | } | |
1613 | ||
38a12b5b JB |
1614 | static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, |
1615 | struct ieee80211_vif *vif) | |
8ca151b5 | 1616 | { |
8ca151b5 JB |
1617 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
1618 | /* | |
1619 | * Flush the ROC worker which will flush the OFFCHANNEL queue. | |
1620 | * We assume here that all the packets sent to the OFFCHANNEL | |
1621 | * queue are sent in ROC session. | |
1622 | */ | |
1623 | flush_work(&mvm->roc_done_wk); | |
8ca151b5 | 1624 | } |
38a12b5b JB |
1625 | } |
1626 | ||
60efeca1 MK |
1627 | /* This function is doing the common part of removing the interface for |
1628 | * both - MLD and non-MLD modes. Returns true if removing the interface | |
1629 | * is done | |
1630 | */ | |
1631 | bool iwl_mvm_mac_remove_interface_common(struct ieee80211_hw *hw, | |
38a12b5b JB |
1632 | struct ieee80211_vif *vif) |
1633 | { | |
1634 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1635 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
86e177d8 | 1636 | struct iwl_probe_resp_data *probe_data; |
38a12b5b JB |
1637 | |
1638 | iwl_mvm_prepare_mac_removal(mvm, vif); | |
8ca151b5 | 1639 | |
b0ffe455 JB |
1640 | if (!(vif->type == NL80211_IFTYPE_AP || |
1641 | vif->type == NL80211_IFTYPE_ADHOC)) | |
1642 | iwl_mvm_tcm_rm_vif(mvm, vif); | |
1643 | ||
8ca151b5 JB |
1644 | mutex_lock(&mvm->mutex); |
1645 | ||
6d19a5eb EG |
1646 | if (vif == mvm->csme_vif) { |
1647 | iwl_mei_set_netdev(NULL); | |
1648 | mvm->csme_vif = NULL; | |
1649 | } | |
1650 | ||
86e177d8 GG |
1651 | probe_data = rcu_dereference_protected(mvmvif->probe_resp_data, |
1652 | lockdep_is_held(&mvm->mutex)); | |
1653 | RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL); | |
1654 | if (probe_data) | |
1655 | kfree_rcu(probe_data, rcu_head); | |
1656 | ||
7df15b1e HG |
1657 | if (mvm->bf_allowed_vif == mvmvif) { |
1658 | mvm->bf_allowed_vif = NULL; | |
a20fd398 AO |
1659 | vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | |
1660 | IEEE80211_VIF_SUPPORTS_CQM_RSSI); | |
7df15b1e HG |
1661 | } |
1662 | ||
b73f9a4a JB |
1663 | if (vif->bss_conf.ftm_responder) |
1664 | memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats)); | |
1665 | ||
63494374 JB |
1666 | iwl_mvm_vif_dbgfs_clean(mvm, vif); |
1667 | ||
8ca151b5 JB |
1668 | /* |
1669 | * For AP/GO interface, the tear down of the resources allocated to the | |
38a12b5b | 1670 | * interface is be handled as part of the stop_ap flow. |
8ca151b5 | 1671 | */ |
5023d966 JB |
1672 | if (vif->type == NL80211_IFTYPE_AP || |
1673 | vif->type == NL80211_IFTYPE_ADHOC) { | |
507cadf2 DS |
1674 | #ifdef CONFIG_NL80211_TESTMODE |
1675 | if (vif == mvm->noa_vif) { | |
1676 | mvm->noa_vif = NULL; | |
1677 | mvm->noa_duration = 0; | |
1678 | } | |
1679 | #endif | |
60efeca1 | 1680 | return true; |
8ca151b5 JB |
1681 | } |
1682 | ||
60efeca1 MK |
1683 | iwl_mvm_power_update_mac(mvm); |
1684 | return false; | |
1685 | } | |
1686 | ||
1687 | static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, | |
1688 | struct ieee80211_vif *vif) | |
1689 | { | |
1690 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1691 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1692 | ||
1693 | if (iwl_mvm_mac_remove_interface_common(hw, vif)) | |
1694 | goto out; | |
1695 | ||
8ca151b5 JB |
1696 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
1697 | mvm->p2p_device_vif = NULL; | |
d197358b | 1698 | iwl_mvm_rm_p2p_bcast_sta(mvm, vif); |
8ca151b5 | 1699 | iwl_mvm_binding_remove_vif(mvm, vif); |
fe0f2de3 | 1700 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); |
8ca151b5 JB |
1701 | mvmvif->phy_ctxt = NULL; |
1702 | } | |
1703 | ||
8ca151b5 JB |
1704 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
1705 | ||
698478c4 SS |
1706 | RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL); |
1707 | ||
baf41bc3 ST |
1708 | if (vif->type == NL80211_IFTYPE_MONITOR) |
1709 | mvm->monitor_on = false; | |
1710 | ||
60efeca1 MK |
1711 | out: |
1712 | if (vif->type == NL80211_IFTYPE_AP || | |
1713 | vif->type == NL80211_IFTYPE_ADHOC) { | |
1714 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta); | |
1715 | iwl_mvm_dealloc_bcast_sta(mvm, vif); | |
1716 | } | |
1717 | ||
8ca151b5 JB |
1718 | mutex_unlock(&mvm->mutex); |
1719 | } | |
1720 | ||
1721 | static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed) | |
88f2fd73 | 1722 | { |
8ca151b5 JB |
1723 | return 0; |
1724 | } | |
1725 | ||
e59647ea EP |
1726 | struct iwl_mvm_mc_iter_data { |
1727 | struct iwl_mvm *mvm; | |
1728 | int port_id; | |
1729 | }; | |
1730 | ||
1731 | static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac, | |
1732 | struct ieee80211_vif *vif) | |
1733 | { | |
1734 | struct iwl_mvm_mc_iter_data *data = _data; | |
1735 | struct iwl_mvm *mvm = data->mvm; | |
1736 | struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd; | |
97bce57b LC |
1737 | struct iwl_host_cmd hcmd = { |
1738 | .id = MCAST_FILTER_CMD, | |
1739 | .flags = CMD_ASYNC, | |
1740 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, | |
1741 | }; | |
e59647ea EP |
1742 | int ret, len; |
1743 | ||
1744 | /* if we don't have free ports, mcast frames will be dropped */ | |
1745 | if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM)) | |
1746 | return; | |
1747 | ||
1748 | if (vif->type != NL80211_IFTYPE_STATION || | |
f276e20b | 1749 | !vif->cfg.assoc) |
e59647ea EP |
1750 | return; |
1751 | ||
1752 | cmd->port_id = data->port_id++; | |
1753 | memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); | |
1754 | len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); | |
1755 | ||
97bce57b LC |
1756 | hcmd.len[0] = len; |
1757 | hcmd.data[0] = cmd; | |
1758 | ||
1759 | ret = iwl_mvm_send_cmd(mvm, &hcmd); | |
e59647ea EP |
1760 | if (ret) |
1761 | IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret); | |
1762 | } | |
1763 | ||
1764 | static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm) | |
1765 | { | |
1766 | struct iwl_mvm_mc_iter_data iter_data = { | |
1767 | .mvm = mvm, | |
88f2fd73 | 1768 | }; |
db66abee | 1769 | int ret; |
88f2fd73 | 1770 | |
e59647ea EP |
1771 | lockdep_assert_held(&mvm->mutex); |
1772 | ||
1773 | if (WARN_ON_ONCE(!mvm->mcast_filter_cmd)) | |
1774 | return; | |
1775 | ||
1c4abec0 | 1776 | ieee80211_iterate_active_interfaces_atomic( |
e59647ea EP |
1777 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
1778 | iwl_mvm_mc_iface_iterator, &iter_data); | |
db66abee JB |
1779 | |
1780 | /* | |
1781 | * Send a (synchronous) ech command so that we wait for the | |
1782 | * multiple asynchronous MCAST_FILTER_CMD commands sent by | |
1783 | * the interface iterator. Otherwise, we might get here over | |
1784 | * and over again (by userspace just sending a lot of these) | |
1785 | * and the CPU can send them faster than the firmware can | |
1786 | * process them. | |
1787 | * Note that the CPU is still faster - but with this we'll | |
1788 | * actually send fewer commands overall because the CPU will | |
1789 | * not schedule the work in mac80211 as frequently if it's | |
1790 | * still running when rescheduled (possibly multiple times). | |
1791 | */ | |
1792 | ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL); | |
1793 | if (ret) | |
1794 | IWL_ERR(mvm, "Failed to synchronize multicast groups update\n"); | |
88f2fd73 MG |
1795 | } |
1796 | ||
e59647ea EP |
1797 | static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw, |
1798 | struct netdev_hw_addr_list *mc_list) | |
8ca151b5 | 1799 | { |
e59647ea EP |
1800 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
1801 | struct iwl_mcast_filter_cmd *cmd; | |
1802 | struct netdev_hw_addr *addr; | |
f3bd58f4 MS |
1803 | int addr_count; |
1804 | bool pass_all; | |
e59647ea EP |
1805 | int len; |
1806 | ||
f3bd58f4 MS |
1807 | addr_count = netdev_hw_addr_list_count(mc_list); |
1808 | pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES || | |
1809 | IWL_MVM_FW_MCAST_FILTER_PASS_ALL; | |
1810 | if (pass_all) | |
e59647ea | 1811 | addr_count = 0; |
e59647ea EP |
1812 | |
1813 | len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); | |
1814 | cmd = kzalloc(len, GFP_ATOMIC); | |
1815 | if (!cmd) | |
1816 | return 0; | |
1817 | ||
1818 | if (pass_all) { | |
1819 | cmd->pass_all = 1; | |
1820 | return (u64)(unsigned long)cmd; | |
1821 | } | |
1822 | ||
1823 | netdev_hw_addr_list_for_each(addr, mc_list) { | |
1824 | IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n", | |
1825 | cmd->count, addr->addr); | |
1826 | memcpy(&cmd->addr_list[cmd->count * ETH_ALEN], | |
1827 | addr->addr, ETH_ALEN); | |
1828 | cmd->count++; | |
1829 | } | |
1830 | ||
1831 | return (u64)(unsigned long)cmd; | |
8ca151b5 JB |
1832 | } |
1833 | ||
1834 | static void iwl_mvm_configure_filter(struct ieee80211_hw *hw, | |
1835 | unsigned int changed_flags, | |
1836 | unsigned int *total_flags, | |
1837 | u64 multicast) | |
1838 | { | |
e59647ea EP |
1839 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
1840 | struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; | |
8ca151b5 | 1841 | |
e59647ea | 1842 | mutex_lock(&mvm->mutex); |
51b6b9e0 | 1843 | |
e59647ea EP |
1844 | /* replace previous configuration */ |
1845 | kfree(mvm->mcast_filter_cmd); | |
1846 | mvm->mcast_filter_cmd = cmd; | |
51b6b9e0 | 1847 | |
e59647ea EP |
1848 | if (!cmd) |
1849 | goto out; | |
51b6b9e0 | 1850 | |
61e7d91b LC |
1851 | if (changed_flags & FIF_ALLMULTI) |
1852 | cmd->pass_all = !!(*total_flags & FIF_ALLMULTI); | |
1853 | ||
1854 | if (cmd->pass_all) | |
1855 | cmd->count = 0; | |
1856 | ||
e59647ea EP |
1857 | iwl_mvm_recalc_multicast(mvm); |
1858 | out: | |
1859 | mutex_unlock(&mvm->mutex); | |
1860 | *total_flags = 0; | |
51b6b9e0 EG |
1861 | } |
1862 | ||
effd1929 AO |
1863 | static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw, |
1864 | struct ieee80211_vif *vif, | |
1865 | unsigned int filter_flags, | |
1866 | unsigned int changed_flags) | |
1867 | { | |
1868 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1869 | ||
1870 | /* We support only filter for probe requests */ | |
1871 | if (!(changed_flags & FIF_PROBE_REQ)) | |
1872 | return; | |
1873 | ||
1874 | /* Supported only for p2p client interfaces */ | |
f276e20b | 1875 | if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc || |
effd1929 AO |
1876 | !vif->p2p) |
1877 | return; | |
1878 | ||
1879 | mutex_lock(&mvm->mutex); | |
1880 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); | |
1881 | mutex_unlock(&mvm->mutex); | |
1882 | } | |
1883 | ||
a07a8f37 SS |
1884 | static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm, |
1885 | struct ieee80211_vif *vif) | |
1886 | { | |
1887 | struct iwl_mu_group_mgmt_cmd cmd = {}; | |
1888 | ||
1889 | memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership, | |
1890 | WLAN_MEMBERSHIP_LEN); | |
1891 | memcpy(cmd.user_position, vif->bss_conf.mu_group.position, | |
1892 | WLAN_USER_POSITION_LEN); | |
1893 | ||
1894 | return iwl_mvm_send_cmd_pdu(mvm, | |
1895 | WIDE_ID(DATA_PATH_GROUP, | |
1896 | UPDATE_MU_GROUPS_CMD), | |
1897 | 0, sizeof(cmd), &cmd); | |
1898 | } | |
1899 | ||
f92659a1 SS |
1900 | static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac, |
1901 | struct ieee80211_vif *vif) | |
1902 | { | |
d0a9123e | 1903 | if (vif->bss_conf.mu_mimo_owner) { |
f92659a1 SS |
1904 | struct iwl_mu_group_mgmt_notif *notif = _data; |
1905 | ||
1906 | /* | |
1907 | * MU-MIMO Group Id action frame is little endian. We treat | |
1908 | * the data received from firmware as if it came from the | |
1909 | * action frame, so no conversion is needed. | |
1910 | */ | |
afe0d181 | 1911 | ieee80211_update_mu_groups(vif, 0, |
f92659a1 SS |
1912 | (u8 *)¬if->membership_status, |
1913 | (u8 *)¬if->user_position); | |
1914 | } | |
1915 | } | |
1916 | ||
1917 | void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm, | |
1918 | struct iwl_rx_cmd_buffer *rxb) | |
1919 | { | |
1920 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
1921 | struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data; | |
1922 | ||
1923 | ieee80211_iterate_active_interfaces_atomic( | |
1924 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
1925 | iwl_mvm_mu_mimo_iface_iterator, notif); | |
1926 | } | |
1927 | ||
514c3069 LC |
1928 | static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit) |
1929 | { | |
1930 | u8 byte_num = ppe_pos_bit / 8; | |
1931 | u8 bit_num = ppe_pos_bit % 8; | |
1932 | u8 residue_bits; | |
1933 | u8 res; | |
1934 | ||
1935 | if (bit_num <= 5) | |
1936 | return (ppe[byte_num] >> bit_num) & | |
1937 | (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1); | |
1938 | ||
1939 | /* | |
1940 | * If bit_num > 5, we have to combine bits with next byte. | |
1941 | * Calculate how many bits we need to take from current byte (called | |
1942 | * here "residue_bits"), and add them to bits from next byte. | |
1943 | */ | |
1944 | ||
1945 | residue_bits = 8 - bit_num; | |
1946 | ||
1947 | res = (ppe[byte_num + 1] & | |
1948 | (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) << | |
1949 | residue_bits; | |
1950 | res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1); | |
1951 | ||
1952 | return res; | |
1953 | } | |
1954 | ||
091296d3 MK |
1955 | static void iwl_mvm_parse_ppe(struct iwl_mvm *mvm, |
1956 | struct iwl_he_pkt_ext_v2 *pkt_ext, u8 nss, | |
cb63eb43 MK |
1957 | u8 ru_index_bitmap, u8 *ppe, u8 ppe_pos_bit, |
1958 | bool inheritance) | |
091296d3 MK |
1959 | { |
1960 | int i; | |
1961 | ||
1962 | /* | |
1963 | * FW currently supports only nss == MAX_HE_SUPP_NSS | |
1964 | * | |
1965 | * If nss > MAX: we can ignore values we don't support | |
1966 | * If nss < MAX: we can set zeros in other streams | |
1967 | */ | |
1968 | if (nss > MAX_HE_SUPP_NSS) { | |
4d8421f2 JD |
1969 | IWL_DEBUG_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss, |
1970 | MAX_HE_SUPP_NSS); | |
091296d3 MK |
1971 | nss = MAX_HE_SUPP_NSS; |
1972 | } | |
1973 | ||
1974 | for (i = 0; i < nss; i++) { | |
1975 | u8 ru_index_tmp = ru_index_bitmap << 1; | |
1976 | u8 low_th = IWL_HE_PKT_EXT_NONE, high_th = IWL_HE_PKT_EXT_NONE; | |
1977 | u8 bw; | |
1978 | ||
1979 | for (bw = 0; | |
1980 | bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); | |
1981 | bw++) { | |
1982 | ru_index_tmp >>= 1; | |
1983 | ||
cb63eb43 MK |
1984 | /* |
1985 | * According to the 11be spec, if for a specific BW the PPE Thresholds | |
1986 | * isn't present - it should inherit the thresholds from the last | |
1987 | * BW for which we had PPE Thresholds. In 11ax though, we don't have | |
1988 | * this inheritance - continue in this case | |
1989 | */ | |
1990 | if (!(ru_index_tmp & 1)) { | |
1991 | if (inheritance) | |
1992 | goto set_thresholds; | |
1993 | else | |
1994 | continue; | |
1995 | } | |
091296d3 MK |
1996 | |
1997 | high_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit); | |
1998 | ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE; | |
1999 | low_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit); | |
2000 | ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE; | |
2001 | ||
cb63eb43 | 2002 | set_thresholds: |
091296d3 MK |
2003 | pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th; |
2004 | pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th; | |
2005 | } | |
2006 | } | |
2007 | } | |
2008 | ||
2009 | static void iwl_mvm_set_pkt_ext_from_he_ppe(struct iwl_mvm *mvm, | |
2010 | struct ieee80211_sta *sta, | |
cb63eb43 MK |
2011 | struct iwl_he_pkt_ext_v2 *pkt_ext, |
2012 | bool inheritance) | |
091296d3 | 2013 | { |
046d2e7c S |
2014 | u8 nss = (sta->deflink.he_cap.ppe_thres[0] & IEEE80211_PPE_THRES_NSS_MASK) + 1; |
2015 | u8 *ppe = &sta->deflink.he_cap.ppe_thres[0]; | |
091296d3 MK |
2016 | u8 ru_index_bitmap = |
2017 | u8_get_bits(*ppe, | |
2018 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK); | |
2019 | /* Starting after PPE header */ | |
2020 | u8 ppe_pos_bit = IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE; | |
2021 | ||
cb63eb43 MK |
2022 | iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, ppe, ppe_pos_bit, |
2023 | inheritance); | |
091296d3 MK |
2024 | } |
2025 | ||
4df6a075 MK |
2026 | static int |
2027 | iwl_mvm_set_pkt_ext_from_nominal_padding(struct iwl_he_pkt_ext_v2 *pkt_ext, | |
2028 | u8 nominal_padding) | |
091296d3 MK |
2029 | { |
2030 | int low_th = -1; | |
2031 | int high_th = -1; | |
2032 | int i; | |
2033 | ||
cb63eb43 | 2034 | /* all the macros are the same for EHT and HE */ |
091296d3 | 2035 | switch (nominal_padding) { |
cb63eb43 | 2036 | case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_0US: |
091296d3 MK |
2037 | low_th = IWL_HE_PKT_EXT_NONE; |
2038 | high_th = IWL_HE_PKT_EXT_NONE; | |
2039 | break; | |
cb63eb43 | 2040 | case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US: |
091296d3 MK |
2041 | low_th = IWL_HE_PKT_EXT_BPSK; |
2042 | high_th = IWL_HE_PKT_EXT_NONE; | |
2043 | break; | |
cb63eb43 MK |
2044 | case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US: |
2045 | case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_20US: | |
091296d3 MK |
2046 | low_th = IWL_HE_PKT_EXT_NONE; |
2047 | high_th = IWL_HE_PKT_EXT_BPSK; | |
2048 | break; | |
2049 | } | |
2050 | ||
4df6a075 MK |
2051 | if (low_th < 0 || high_th < 0) |
2052 | return -EINVAL; | |
2053 | ||
091296d3 | 2054 | /* Set the PPE thresholds accordingly */ |
4df6a075 MK |
2055 | for (i = 0; i < MAX_HE_SUPP_NSS; i++) { |
2056 | u8 bw; | |
091296d3 | 2057 | |
4df6a075 MK |
2058 | for (bw = 0; |
2059 | bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); | |
2060 | bw++) { | |
2061 | pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th; | |
2062 | pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th; | |
2063 | } | |
091296d3 | 2064 | } |
4df6a075 MK |
2065 | |
2066 | return 0; | |
091296d3 MK |
2067 | } |
2068 | ||
cb63eb43 MK |
2069 | static void iwl_mvm_get_optimal_ppe_info(struct iwl_he_pkt_ext_v2 *pkt_ext, |
2070 | u8 nominal_padding) | |
2071 | { | |
2072 | int i; | |
2073 | ||
2074 | for (i = 0; i < MAX_HE_SUPP_NSS; i++) { | |
2075 | u8 bw; | |
2076 | ||
2077 | for (bw = 0; bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); | |
2078 | bw++) { | |
2079 | u8 *qam_th = &pkt_ext->pkt_ext_qam_th[i][bw][0]; | |
2080 | ||
2081 | if (nominal_padding > | |
2082 | IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US && | |
2083 | qam_th[1] == IWL_HE_PKT_EXT_NONE) | |
2084 | qam_th[1] = IWL_HE_PKT_EXT_4096QAM; | |
2085 | else if (nominal_padding == | |
2086 | IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US && | |
2087 | qam_th[0] == IWL_HE_PKT_EXT_NONE && | |
2088 | qam_th[1] == IWL_HE_PKT_EXT_NONE) | |
2089 | qam_th[0] = IWL_HE_PKT_EXT_4096QAM; | |
2090 | } | |
2091 | } | |
2092 | } | |
2093 | ||
4df6a075 MK |
2094 | /* Set the pkt_ext field according to PPE Thresholds element */ |
2095 | static int iwl_mvm_set_sta_pkt_ext(struct iwl_mvm *mvm, | |
2096 | struct ieee80211_sta *sta, | |
2097 | struct iwl_he_pkt_ext_v2 *pkt_ext) | |
2098 | { | |
2099 | u8 nominal_padding; | |
2100 | int i, ret = 0; | |
2101 | ||
2102 | /* Initialize the PPE thresholds to "None" (7), as described in Table | |
2103 | * 9-262ac of 80211.ax/D3.0. | |
2104 | */ | |
2105 | memset(pkt_ext, IWL_HE_PKT_EXT_NONE, | |
2106 | sizeof(struct iwl_he_pkt_ext_v2)); | |
2107 | ||
2108 | if (sta->deflink.eht_cap.has_eht) { | |
2109 | nominal_padding = | |
2110 | u8_get_bits(sta->deflink.eht_cap.eht_cap_elem.phy_cap_info[5], | |
2111 | IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK); | |
2112 | ||
2113 | /* If PPE Thresholds exists, parse them into a FW-familiar | |
2114 | * format. | |
2115 | */ | |
2116 | if (sta->deflink.eht_cap.eht_cap_elem.phy_cap_info[5] & | |
2117 | IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) { | |
2118 | u8 nss = (sta->deflink.eht_cap.eht_ppe_thres[0] & | |
2119 | IEEE80211_EHT_PPE_THRES_NSS_MASK) + 1; | |
2120 | u8 *ppe = &sta->deflink.eht_cap.eht_ppe_thres[0]; | |
2121 | u8 ru_index_bitmap = | |
2122 | u16_get_bits(*ppe, | |
2123 | IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); | |
2124 | /* Starting after PPE header */ | |
2125 | u8 ppe_pos_bit = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE; | |
2126 | ||
2127 | iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, | |
2128 | ppe, ppe_pos_bit, true); | |
2129 | /* EHT PPE Thresholds doesn't exist - set the API according | |
2130 | * to HE PPE Tresholds | |
2131 | */ | |
2132 | } else if (sta->deflink.he_cap.he_cap_elem.phy_cap_info[6] & | |
2133 | IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { | |
2134 | /* Even though HE Capabilities IE doesn't contain PPE | |
2135 | * Thresholds for BW 320Mhz, thresholds for this BW will | |
2136 | * be filled in with the same values as 160Mhz, due to | |
2137 | * the inheritance, as required. | |
2138 | */ | |
2139 | iwl_mvm_set_pkt_ext_from_he_ppe(mvm, sta, pkt_ext, | |
2140 | true); | |
2141 | ||
2142 | /* According to the requirements, for MCSs 12-13 the | |
2143 | * maximum value between HE PPE Threshold and Common | |
2144 | * Nominal Packet Padding needs to be taken | |
2145 | */ | |
2146 | iwl_mvm_get_optimal_ppe_info(pkt_ext, nominal_padding); | |
2147 | ||
2148 | /* if PPE Thresholds doesn't present in both EHT IE and HE IE - | |
2149 | * take the Thresholds from Common Nominal Packet Padding field | |
2150 | */ | |
2151 | } else { | |
2152 | ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext, | |
2153 | nominal_padding); | |
2154 | } | |
2155 | } else if (sta->deflink.he_cap.has_he) { | |
2156 | /* If PPE Thresholds exist, parse them into a FW-familiar format. */ | |
2157 | if (sta->deflink.he_cap.he_cap_elem.phy_cap_info[6] & | |
2158 | IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { | |
2159 | iwl_mvm_set_pkt_ext_from_he_ppe(mvm, sta, pkt_ext, | |
2160 | false); | |
2161 | /* PPE Thresholds doesn't exist - set the API PPE values | |
2162 | * according to Common Nominal Packet Padding field. | |
2163 | */ | |
2164 | } else { | |
2165 | nominal_padding = | |
2166 | u8_get_bits(sta->deflink.he_cap.he_cap_elem.phy_cap_info[9], | |
2167 | IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK); | |
2168 | if (nominal_padding != IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_RESERVED) | |
2169 | ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext, | |
2170 | nominal_padding); | |
2171 | } | |
2172 | } | |
2173 | ||
2174 | for (i = 0; i < MAX_HE_SUPP_NSS; i++) { | |
2175 | int bw; | |
2176 | ||
2177 | for (bw = 0; | |
2178 | bw < ARRAY_SIZE(*pkt_ext->pkt_ext_qam_th[i]); | |
2179 | bw++) { | |
2180 | u8 *qam_th = | |
2181 | &pkt_ext->pkt_ext_qam_th[i][bw][0]; | |
2182 | ||
2183 | IWL_DEBUG_HT(mvm, | |
2184 | "PPE table: nss[%d] bw[%d] PPET8 = %d, PPET16 = %d\n", | |
2185 | i, bw, qam_th[0], qam_th[1]); | |
2186 | } | |
2187 | } | |
2188 | return ret; | |
2189 | } | |
2190 | ||
9c4f15ca MK |
2191 | /* |
2192 | * This function sets the MU EDCA parameters ans returns whether MU EDCA | |
2193 | * is enabled or not | |
2194 | */ | |
55eb1c5f MK |
2195 | bool iwl_mvm_set_fw_mu_edca_params(struct iwl_mvm *mvm, |
2196 | struct iwl_mvm_vif *mvmvif, | |
2197 | struct iwl_he_backoff_conf *trig_based_txf) | |
9c4f15ca MK |
2198 | { |
2199 | int i; | |
2200 | /* Mark MU EDCA as enabled, unless none detected on some AC */ | |
2201 | bool mu_edca_enabled = true; | |
2202 | ||
2203 | for (i = 0; i < IEEE80211_NUM_ACS; i++) { | |
2204 | struct ieee80211_he_mu_edca_param_ac_rec *mu_edca = | |
2205 | &mvmvif->queue_params[i].mu_edca_param_rec; | |
2206 | u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i); | |
2207 | ||
2208 | if (!mvmvif->queue_params[i].mu_edca) { | |
2209 | mu_edca_enabled = false; | |
2210 | break; | |
2211 | } | |
2212 | ||
2213 | trig_based_txf[ac].cwmin = | |
2214 | cpu_to_le16(mu_edca->ecw_min_max & 0xf); | |
2215 | trig_based_txf[ac].cwmax = | |
2216 | cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4); | |
2217 | trig_based_txf[ac].aifsn = | |
2218 | cpu_to_le16(mu_edca->aifsn & 0xf); | |
2219 | trig_based_txf[ac].mu_time = | |
2220 | cpu_to_le16(mu_edca->mu_edca_timer); | |
2221 | } | |
2222 | ||
2223 | return mu_edca_enabled; | |
2224 | } | |
2225 | ||
9be162a7 | 2226 | bool iwl_mvm_is_nic_ack_enabled(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
9c4f15ca MK |
2227 | { |
2228 | const struct ieee80211_supported_band *sband; | |
2229 | const struct ieee80211_sta_he_cap *own_he_cap = NULL; | |
2230 | ||
2231 | /* This capability is the same for all bands, | |
2232 | * so take it from one of them. | |
2233 | */ | |
2234 | sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]; | |
2235 | own_he_cap = ieee80211_get_he_iftype_cap(sband, | |
2236 | ieee80211_vif_type_p2p(vif)); | |
2237 | ||
2238 | return (own_he_cap && (own_he_cap->he_cap_elem.mac_cap_info[2] & | |
2239 | IEEE80211_HE_MAC_CAP2_ACK_EN)); | |
2240 | } | |
2241 | ||
4df6a075 MK |
2242 | static __le32 iwl_mvm_get_sta_htc_flags(struct ieee80211_sta *sta) |
2243 | { | |
2244 | u8 *mac_cap_info = &sta->deflink.he_cap.he_cap_elem.mac_cap_info[0]; | |
2245 | __le32 htc_flags = 0; | |
2246 | ||
2247 | if (mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_HTC_HE) | |
2248 | htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT); | |
2249 | if ((mac_cap_info[1] & IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) || | |
2250 | (mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) { | |
2251 | u8 link_adap = | |
2252 | ((mac_cap_info[2] & | |
2253 | IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) + | |
2254 | (mac_cap_info[1] & | |
2255 | IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION); | |
2256 | ||
2257 | if (link_adap == 2) | |
2258 | htc_flags |= | |
2259 | cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED); | |
2260 | else if (link_adap == 3) | |
2261 | htc_flags |= cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH); | |
2262 | } | |
2263 | if (mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR) | |
2264 | htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP); | |
2265 | if (mac_cap_info[3] & IEEE80211_HE_MAC_CAP3_OMI_CONTROL) | |
2266 | htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP); | |
2267 | if (mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR) | |
2268 | htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP); | |
2269 | ||
2270 | return htc_flags; | |
2271 | } | |
2272 | ||
514c3069 LC |
2273 | static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm, |
2274 | struct ieee80211_vif *vif, u8 sta_id) | |
2275 | { | |
2276 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
42506dd2 | 2277 | struct iwl_he_sta_context_cmd_v3 sta_ctxt_cmd = { |
514c3069 LC |
2278 | .sta_id = sta_id, |
2279 | .tid_limit = IWL_MAX_TID_COUNT, | |
dd56e902 | 2280 | .bss_color = vif->bss_conf.he_bss_color.color, |
514c3069 LC |
2281 | .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext, |
2282 | .frame_time_rts_th = | |
2283 | cpu_to_le16(vif->bss_conf.frame_time_rts_th), | |
2284 | }; | |
42506dd2 JB |
2285 | struct iwl_he_sta_context_cmd_v2 sta_ctxt_cmd_v2 = {}; |
2286 | u32 cmd_id = WIDE_ID(DATA_PATH_GROUP, STA_HE_CTXT_CMD); | |
2287 | u8 ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 2); | |
2288 | int size; | |
514c3069 LC |
2289 | struct ieee80211_sta *sta; |
2290 | u32 flags; | |
2291 | int i; | |
42506dd2 JB |
2292 | void *cmd; |
2293 | ||
2294 | if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_MBSSID_HE)) | |
2295 | ver = 1; | |
2296 | ||
2297 | switch (ver) { | |
2298 | case 1: | |
2299 | /* same layout as v2 except some data at the end */ | |
2300 | cmd = &sta_ctxt_cmd_v2; | |
2301 | size = sizeof(struct iwl_he_sta_context_cmd_v1); | |
2302 | break; | |
2303 | case 2: | |
2304 | cmd = &sta_ctxt_cmd_v2; | |
2305 | size = sizeof(struct iwl_he_sta_context_cmd_v2); | |
2306 | break; | |
2307 | case 3: | |
2308 | cmd = &sta_ctxt_cmd; | |
2309 | size = sizeof(struct iwl_he_sta_context_cmd_v3); | |
2310 | break; | |
2311 | default: | |
2312 | IWL_ERR(mvm, "bad STA_HE_CTXT_CMD version %d\n", ver); | |
2313 | return; | |
2314 | } | |
514c3069 LC |
2315 | |
2316 | rcu_read_lock(); | |
2317 | ||
2318 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]); | |
12d47f0e | 2319 | if (IS_ERR_OR_NULL(sta)) { |
514c3069 LC |
2320 | rcu_read_unlock(); |
2321 | WARN(1, "Can't find STA to configure HE\n"); | |
2322 | return; | |
2323 | } | |
2324 | ||
046d2e7c | 2325 | if (!sta->deflink.he_cap.has_he) { |
514c3069 LC |
2326 | rcu_read_unlock(); |
2327 | return; | |
2328 | } | |
2329 | ||
2330 | flags = 0; | |
2331 | ||
4f58121d IP |
2332 | /* Block 26-tone RU OFDMA transmissions */ |
2333 | if (mvmvif->he_ru_2mhz_block) | |
2334 | flags |= STA_CTXT_HE_RU_2MHZ_BLOCK; | |
2335 | ||
514c3069 | 2336 | /* HTC flags */ |
4df6a075 | 2337 | sta_ctxt_cmd.htc_flags = iwl_mvm_get_sta_htc_flags(sta); |
514c3069 | 2338 | |
4df6a075 MK |
2339 | /* PPE Thresholds */ |
2340 | if (!iwl_mvm_set_sta_pkt_ext(mvm, sta, &sta_ctxt_cmd.pkt_ext)) | |
2341 | flags |= STA_CTXT_HE_PACKET_EXT; | |
73f23d91 | 2342 | |
046d2e7c | 2343 | if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & |
73f23d91 ST |
2344 | IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP) |
2345 | flags |= STA_CTXT_HE_32BIT_BA_BITMAP; | |
2346 | ||
046d2e7c | 2347 | if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & |
73f23d91 ST |
2348 | IEEE80211_HE_MAC_CAP2_ACK_EN) |
2349 | flags |= STA_CTXT_HE_ACK_ENABLED; | |
2350 | ||
514c3069 LC |
2351 | rcu_read_unlock(); |
2352 | ||
9c4f15ca MK |
2353 | if (iwl_mvm_set_fw_mu_edca_params(mvm, mvmvif, |
2354 | &sta_ctxt_cmd.trig_based_txf[0])) | |
2355 | flags |= STA_CTXT_HE_MU_EDCA_CW; | |
514c3069 LC |
2356 | |
2357 | if (vif->bss_conf.uora_exists) { | |
2358 | flags |= STA_CTXT_HE_TRIG_RND_ALLOC; | |
2359 | ||
2360 | sta_ctxt_cmd.rand_alloc_ecwmin = | |
2361 | vif->bss_conf.uora_ocw_range & 0x7; | |
2362 | sta_ctxt_cmd.rand_alloc_ecwmax = | |
2363 | (vif->bss_conf.uora_ocw_range >> 3) & 0x7; | |
2364 | } | |
2365 | ||
9c4f15ca | 2366 | if (!iwl_mvm_is_nic_ack_enabled(mvm, vif)) |
ee1a02d7 ST |
2367 | flags |= STA_CTXT_HE_NIC_NOT_ACK_ENABLED; |
2368 | ||
918cbf39 SS |
2369 | if (vif->bss_conf.nontransmitted) { |
2370 | flags |= STA_CTXT_HE_REF_BSSID_VALID; | |
2371 | ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr, | |
2372 | vif->bss_conf.transmitter_bssid); | |
d14ae796 SS |
2373 | sta_ctxt_cmd.max_bssid_indicator = |
2374 | vif->bss_conf.bssid_indicator; | |
2375 | sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index; | |
2376 | sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap; | |
2377 | sta_ctxt_cmd.profile_periodicity = | |
2378 | vif->bss_conf.profile_periodicity; | |
918cbf39 | 2379 | } |
514c3069 LC |
2380 | |
2381 | sta_ctxt_cmd.flags = cpu_to_le32(flags); | |
2382 | ||
42506dd2 JB |
2383 | if (ver < 3) { |
2384 | /* fields before pkt_ext */ | |
2385 | BUILD_BUG_ON(offsetof(typeof(sta_ctxt_cmd), pkt_ext) != | |
2386 | offsetof(typeof(sta_ctxt_cmd_v2), pkt_ext)); | |
2387 | memcpy(&sta_ctxt_cmd_v2, &sta_ctxt_cmd, | |
2388 | offsetof(typeof(sta_ctxt_cmd), pkt_ext)); | |
2389 | ||
2390 | /* pkt_ext */ | |
2391 | for (i = 0; | |
2392 | i < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th); | |
2393 | i++) { | |
2394 | u8 bw; | |
2395 | ||
2396 | for (bw = 0; | |
2397 | bw < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i]); | |
2398 | bw++) { | |
2399 | BUILD_BUG_ON(sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw]) != | |
2400 | sizeof(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw])); | |
2401 | ||
2402 | memcpy(&sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw], | |
2403 | &sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw], | |
2404 | sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw])); | |
2405 | } | |
2406 | } | |
2407 | ||
2408 | /* fields after pkt_ext */ | |
2409 | BUILD_BUG_ON(sizeof(sta_ctxt_cmd) - | |
2410 | offsetofend(typeof(sta_ctxt_cmd), pkt_ext) != | |
2411 | sizeof(sta_ctxt_cmd_v2) - | |
2412 | offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext)); | |
2413 | memcpy((u8 *)&sta_ctxt_cmd_v2 + | |
2414 | offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext), | |
2415 | (u8 *)&sta_ctxt_cmd + | |
2416 | offsetofend(typeof(sta_ctxt_cmd), pkt_ext), | |
2417 | sizeof(sta_ctxt_cmd) - | |
2418 | offsetofend(typeof(sta_ctxt_cmd), pkt_ext)); | |
2419 | sta_ctxt_cmd_v2.reserved3 = 0; | |
2420 | } | |
2421 | ||
2422 | if (iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, size, cmd)) | |
514c3069 LC |
2423 | IWL_ERR(mvm, "Failed to config FW to work HE!\n"); |
2424 | } | |
2425 | ||
af84ac57 JB |
2426 | static void iwl_mvm_protect_assoc(struct iwl_mvm *mvm, |
2427 | struct ieee80211_vif *vif, | |
2428 | u32 duration_override) | |
2429 | { | |
2430 | u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS; | |
2431 | u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS; | |
2432 | ||
2433 | if (duration_override > duration) | |
2434 | duration = duration_override; | |
2435 | ||
2436 | /* Try really hard to protect the session and hear a beacon | |
2437 | * The new session protection command allows us to protect the | |
2438 | * session for a much longer time since the firmware will internally | |
2439 | * create two events: a 300TU one with a very high priority that | |
2440 | * won't be fragmented which should be enough for 99% of the cases, | |
2441 | * and another one (which we configure here to be 900TU long) which | |
2442 | * will have a slightly lower priority, but more importantly, can be | |
2443 | * fragmented so that it'll allow other activities to run. | |
2444 | */ | |
2445 | if (fw_has_capa(&mvm->fw->ucode_capa, | |
2446 | IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) | |
2447 | iwl_mvm_schedule_session_protection(mvm, vif, 900, | |
2448 | min_duration, false); | |
2449 | else | |
2450 | iwl_mvm_protect_session(mvm, vif, duration, | |
2451 | min_duration, 500, false); | |
2452 | } | |
2453 | ||
8ca151b5 JB |
2454 | static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, |
2455 | struct ieee80211_vif *vif, | |
2456 | struct ieee80211_bss_conf *bss_conf, | |
7b7090b4 | 2457 | u64 changes) |
8ca151b5 JB |
2458 | { |
2459 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
2460 | int ret; | |
2461 | ||
6e97b0d2 | 2462 | /* |
cdaba917 EG |
2463 | * Re-calculate the tsf id, as the leader-follower relations depend |
2464 | * on the beacon interval, which was not known when the station | |
2465 | * interface was added. | |
6e97b0d2 | 2466 | */ |
f276e20b | 2467 | if (changes & BSS_CHANGED_ASSOC && vif->cfg.assoc) { |
cb63eb43 MK |
2468 | if ((vif->bss_conf.he_support && |
2469 | !iwlwifi_mod_params.disable_11ax) || | |
2470 | (vif->bss_conf.eht_support && | |
2471 | !iwlwifi_mod_params.disable_11be)) | |
514c3069 LC |
2472 | iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id); |
2473 | ||
6e97b0d2 | 2474 | iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); |
514c3069 | 2475 | } |
6e97b0d2 | 2476 | |
40ecdd01 ST |
2477 | /* Update MU EDCA params */ |
2478 | if (changes & BSS_CHANGED_QOS && mvmvif->associated && | |
cb63eb43 MK |
2479 | vif->cfg.assoc && |
2480 | ((vif->bss_conf.he_support && | |
2481 | !iwlwifi_mod_params.disable_11ax) || | |
2482 | (vif->bss_conf.eht_support && | |
2483 | !iwlwifi_mod_params.disable_11be))) | |
40ecdd01 ST |
2484 | iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id); |
2485 | ||
3dfd3a97 JB |
2486 | /* |
2487 | * If we're not associated yet, take the (new) BSSID before associating | |
2488 | * so the firmware knows. If we're already associated, then use the old | |
2489 | * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC | |
2490 | * branch for disassociation below. | |
2491 | */ | |
2492 | if (changes & BSS_CHANGED_BSSID && !mvmvif->associated) | |
2493 | memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN); | |
2494 | ||
2495 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid); | |
8ca151b5 JB |
2496 | if (ret) |
2497 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); | |
2498 | ||
3dfd3a97 JB |
2499 | /* after sending it once, adopt mac80211 data */ |
2500 | memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN); | |
f276e20b | 2501 | mvmvif->associated = vif->cfg.assoc; |
3dfd3a97 | 2502 | |
8ca151b5 | 2503 | if (changes & BSS_CHANGED_ASSOC) { |
f276e20b | 2504 | if (vif->cfg.assoc) { |
33cef925 JB |
2505 | /* clear statistics to get clean beacon counter */ |
2506 | iwl_mvm_request_statistics(mvm, true); | |
2507 | memset(&mvmvif->beacon_stats, 0, | |
2508 | sizeof(mvmvif->beacon_stats)); | |
2509 | ||
8ca151b5 | 2510 | /* add quota for this interface */ |
7754ae79 | 2511 | ret = iwl_mvm_update_quotas(mvm, true, NULL); |
8ca151b5 JB |
2512 | if (ret) { |
2513 | IWL_ERR(mvm, "failed to update quotas\n"); | |
2514 | return; | |
2515 | } | |
016d27e1 JB |
2516 | |
2517 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, | |
fe959c7b EG |
2518 | &mvm->status) && |
2519 | !fw_has_capa(&mvm->fw->ucode_capa, | |
2520 | IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) { | |
016d27e1 JB |
2521 | /* |
2522 | * If we're restarting then the firmware will | |
2523 | * obviously have lost synchronisation with | |
2524 | * the AP. It will attempt to synchronise by | |
2525 | * itself, but we can make it more reliable by | |
2526 | * scheduling a session protection time event. | |
2527 | * | |
2528 | * The firmware needs to receive a beacon to | |
2529 | * catch up with synchronisation, use 110% of | |
2530 | * the beacon interval. | |
2531 | * | |
2532 | * Set a large maximum delay to allow for more | |
2533 | * than a single interface. | |
fe959c7b EG |
2534 | * |
2535 | * For new firmware versions, rely on the | |
2536 | * firmware. This is relevant for DCM scenarios | |
2537 | * only anyway. | |
016d27e1 JB |
2538 | */ |
2539 | u32 dur = (11 * vif->bss_conf.beacon_int) / 10; | |
2540 | iwl_mvm_protect_session(mvm, vif, dur, dur, | |
d20d37bc | 2541 | 5 * dur, false); |
af84ac57 JB |
2542 | } else if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, |
2543 | &mvm->status) && | |
2544 | !vif->bss_conf.dtim_period) { | |
2545 | /* | |
2546 | * If we're not restarting and still haven't | |
2547 | * heard a beacon (dtim period unknown) then | |
2548 | * make sure we still have enough minimum time | |
2549 | * remaining in the time event, since the auth | |
2550 | * might actually have taken quite a while | |
2551 | * (especially for SAE) and so the remaining | |
2552 | * time could be small without us having heard | |
2553 | * a beacon yet. | |
2554 | */ | |
2555 | iwl_mvm_protect_assoc(mvm, vif, 0); | |
016d27e1 | 2556 | } |
1f3b0ff8 LE |
2557 | |
2558 | iwl_mvm_sf_update(mvm, vif, false); | |
175a70b7 | 2559 | iwl_mvm_power_vif_assoc(mvm, vif); |
697162a1 | 2560 | if (vif->p2p) { |
697162a1 EG |
2561 | iwl_mvm_update_smps(mvm, vif, |
2562 | IWL_MVM_SMPS_REQ_PROT, | |
2563 | IEEE80211_SMPS_DYNAMIC); | |
2564 | } | |
0ae98812 | 2565 | } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) { |
6d19a5eb | 2566 | iwl_mvm_mei_host_disassociated(mvm); |
1f3b0ff8 LE |
2567 | /* |
2568 | * If update fails - SF might be running in associated | |
2569 | * mode while disassociated - which is forbidden. | |
2570 | */ | |
69e508b4 IP |
2571 | ret = iwl_mvm_sf_update(mvm, vif, false); |
2572 | WARN_ONCE(ret && | |
2573 | !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, | |
2574 | &mvm->status), | |
1f3b0ff8 LE |
2575 | "Failed to update SF upon disassociation\n"); |
2576 | ||
6b28f978 EG |
2577 | /* |
2578 | * If we get an assert during the connection (after the | |
2579 | * station has been added, but before the vif is set | |
2580 | * to associated), mac80211 will re-add the station and | |
2581 | * then configure the vif. Since the vif is not | |
2582 | * associated, we would remove the station here and | |
2583 | * this would fail the recovery. | |
2584 | */ | |
2585 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, | |
2586 | &mvm->status)) { | |
5c75a208 JB |
2587 | /* first remove remaining keys */ |
2588 | iwl_mvm_sec_key_remove_ap(mvm, vif); | |
2589 | ||
6b28f978 EG |
2590 | /* |
2591 | * Remove AP station now that | |
2592 | * the MAC is unassoc | |
2593 | */ | |
2594 | ret = iwl_mvm_rm_sta_id(mvm, vif, | |
2595 | mvmvif->ap_sta_id); | |
2596 | if (ret) | |
2597 | IWL_ERR(mvm, | |
2598 | "failed to remove AP station\n"); | |
2599 | ||
6b28f978 EG |
2600 | mvmvif->ap_sta_id = IWL_MVM_INVALID_STA; |
2601 | } | |
37577fe2 | 2602 | |
8ca151b5 | 2603 | /* remove quota for this interface */ |
7754ae79 | 2604 | ret = iwl_mvm_update_quotas(mvm, false, NULL); |
8ca151b5 JB |
2605 | if (ret) |
2606 | IWL_ERR(mvm, "failed to update quotas\n"); | |
29a90a49 | 2607 | |
3dfd3a97 JB |
2608 | /* this will take the cleared BSSID from bss_conf */ |
2609 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); | |
2610 | if (ret) | |
2611 | IWL_ERR(mvm, | |
2612 | "failed to update MAC %pM (clear after unassoc)\n", | |
2613 | vif->addr); | |
8ca151b5 | 2614 | } |
a20fd398 | 2615 | |
a07a8f37 SS |
2616 | /* |
2617 | * The firmware tracks the MU-MIMO group on its own. | |
f92659a1 | 2618 | * However, on HW restart we should restore this data. |
a07a8f37 SS |
2619 | */ |
2620 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && | |
d0a9123e | 2621 | (changes & BSS_CHANGED_MU_GROUPS) && vif->bss_conf.mu_mimo_owner) { |
a07a8f37 SS |
2622 | ret = iwl_mvm_update_mu_groups(mvm, vif); |
2623 | if (ret) | |
2624 | IWL_ERR(mvm, | |
2625 | "failed to update VHT MU_MIMO groups\n"); | |
2626 | } | |
2627 | ||
e59647ea EP |
2628 | iwl_mvm_recalc_multicast(mvm); |
2629 | ||
a20fd398 AO |
2630 | /* reset rssi values */ |
2631 | mvmvif->bf_data.ave_beacon_signal = 0; | |
2632 | ||
8e484f0b | 2633 | iwl_mvm_bt_coex_vif_change(mvm); |
f94045ed EG |
2634 | iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, |
2635 | IEEE80211_SMPS_AUTOMATIC); | |
355346ba AS |
2636 | if (fw_has_capa(&mvm->fw->ucode_capa, |
2637 | IWL_UCODE_TLV_CAPA_UMAC_SCAN)) | |
2638 | iwl_mvm_config_scan(mvm); | |
b45242c9 AS |
2639 | } |
2640 | ||
2641 | if (changes & BSS_CHANGED_BEACON_INFO) { | |
210a544e | 2642 | /* |
b45242c9 | 2643 | * We received a beacon from the associated AP so |
210a544e JB |
2644 | * remove the session protection. |
2645 | */ | |
25246d2e | 2646 | iwl_mvm_stop_session_protection(mvm, vif); |
cc87d322 | 2647 | |
cc87d322 EH |
2648 | iwl_mvm_sf_update(mvm, vif, false); |
2649 | WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); | |
2650 | } | |
2651 | ||
283115fb AA |
2652 | if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS | |
2653 | /* | |
2654 | * Send power command on every beacon change, | |
2655 | * because we may have not enabled beacon abort yet. | |
2656 | */ | |
2657 | BSS_CHANGED_BEACON_INFO)) { | |
1bc10d3b JB |
2658 | ret = iwl_mvm_power_update_mac(mvm); |
2659 | if (ret) | |
2660 | IWL_ERR(mvm, "failed to update power mode\n"); | |
2661 | } | |
2662 | ||
a20fd398 | 2663 | if (changes & BSS_CHANGED_CQM) { |
3c6acb61 | 2664 | IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n"); |
a20fd398 AO |
2665 | /* reset cqm events tracking */ |
2666 | mvmvif->bf_data.last_cqm_event = 0; | |
fa7b2e7f AA |
2667 | if (mvmvif->bf_data.bf_enabled) { |
2668 | ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); | |
2669 | if (ret) | |
2670 | IWL_ERR(mvm, | |
2671 | "failed to update CQM thresholds\n"); | |
2672 | } | |
a20fd398 | 2673 | } |
2ee8f021 | 2674 | |
de34d1c1 JB |
2675 | if (changes & BSS_CHANGED_BANDWIDTH) |
2676 | iwl_mvm_apply_fw_smps_request(vif); | |
8ca151b5 JB |
2677 | } |
2678 | ||
f947b62c MK |
2679 | bool iwl_mvm_start_ap_ibss_common(struct ieee80211_hw *hw, |
2680 | struct ieee80211_vif *vif, | |
2681 | int *ret) | |
2682 | { | |
2683 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
2684 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
2685 | int i; | |
2686 | ||
2687 | lockdep_assert_held(&mvm->mutex); | |
2688 | ||
2689 | mvmvif->ap_assoc_sta_count = 0; | |
2690 | ||
2691 | /* must be set before quota calculations */ | |
2692 | mvmvif->ap_ibss_active = true; | |
2693 | ||
2694 | /* send all the early keys to the device now */ | |
2695 | for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { | |
2696 | struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i]; | |
2697 | ||
2698 | if (!key) | |
2699 | continue; | |
2700 | ||
2701 | mvmvif->ap_early_keys[i] = NULL; | |
2702 | ||
2703 | *ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key); | |
2704 | if (*ret) | |
2705 | return true; | |
2706 | } | |
2707 | ||
2708 | if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { | |
2709 | iwl_mvm_vif_set_low_latency(mvmvif, true, | |
2710 | LOW_LATENCY_VIF_TYPE); | |
2711 | iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id); | |
2712 | } | |
2713 | ||
2714 | /* power updated needs to be done before quotas */ | |
2715 | iwl_mvm_power_update_mac(mvm); | |
2716 | ||
2717 | return false; | |
2718 | } | |
2719 | ||
5023d966 | 2720 | static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, |
ae7ba17b | 2721 | struct ieee80211_vif *vif, |
b327c84c | 2722 | struct ieee80211_bss_conf *link_conf) |
8ca151b5 JB |
2723 | { |
2724 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
2725 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
f947b62c | 2726 | int ret; |
8ca151b5 JB |
2727 | |
2728 | mutex_lock(&mvm->mutex); | |
2729 | ||
2730 | /* Send the beacon template */ | |
2731 | ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif); | |
2732 | if (ret) | |
2733 | goto out_unlock; | |
2734 | ||
6e97b0d2 | 2735 | /* |
cdaba917 EG |
2736 | * Re-calculate the tsf id, as the leader-follower relations depend on |
2737 | * the beacon interval, which was not known when the AP interface | |
2738 | * was added. | |
6e97b0d2 IP |
2739 | */ |
2740 | if (vif->type == NL80211_IFTYPE_AP) | |
2741 | iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); | |
2742 | ||
8ca151b5 JB |
2743 | /* Add the mac context */ |
2744 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); | |
2745 | if (ret) | |
2746 | goto out_unlock; | |
2747 | ||
2748 | /* Perform the binding */ | |
2749 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
2750 | if (ret) | |
2751 | goto out_remove; | |
2752 | ||
63dd5d02 SS |
2753 | /* |
2754 | * This is not very nice, but the simplest: | |
2755 | * For older FWs adding the mcast sta before the bcast station may | |
2756 | * cause assert 0x2b00. | |
2757 | * This is fixed in later FW so make the order of removal depend on | |
2758 | * the TLV | |
2759 | */ | |
2760 | if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) { | |
2761 | ret = iwl_mvm_add_mcast_sta(mvm, vif); | |
2762 | if (ret) | |
2763 | goto out_unbind; | |
2764 | /* | |
2765 | * Send the bcast station. At this stage the TBTT and DTIM time | |
2766 | * events are added and applied to the scheduler | |
2767 | */ | |
2768 | ret = iwl_mvm_send_add_bcast_sta(mvm, vif); | |
2769 | if (ret) { | |
2770 | iwl_mvm_rm_mcast_sta(mvm, vif); | |
2771 | goto out_unbind; | |
2772 | } | |
2773 | } else { | |
2774 | /* | |
2775 | * Send the bcast station. At this stage the TBTT and DTIM time | |
2776 | * events are added and applied to the scheduler | |
2777 | */ | |
75fd4fec | 2778 | ret = iwl_mvm_send_add_bcast_sta(mvm, vif); |
63dd5d02 SS |
2779 | if (ret) |
2780 | goto out_unbind; | |
75fd4fec | 2781 | ret = iwl_mvm_add_mcast_sta(mvm, vif); |
63dd5d02 SS |
2782 | if (ret) { |
2783 | iwl_mvm_send_rm_bcast_sta(mvm, vif); | |
2784 | goto out_unbind; | |
2785 | } | |
2786 | } | |
26d6c16b | 2787 | |
f947b62c MK |
2788 | if (iwl_mvm_start_ap_ibss_common(hw, vif, &ret)) |
2789 | goto out_failed; | |
a11e144e | 2790 | |
7754ae79 | 2791 | ret = iwl_mvm_update_quotas(mvm, false, NULL); |
8ca151b5 | 2792 | if (ret) |
f947b62c | 2793 | goto out_failed; |
8ca151b5 | 2794 | |
5023d966 | 2795 | /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ |
8ca151b5 | 2796 | if (vif->p2p && mvm->p2p_device_vif) |
3dfd3a97 | 2797 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); |
8ca151b5 | 2798 | |
8e484f0b | 2799 | iwl_mvm_bt_coex_vif_change(mvm); |
dac94da8 | 2800 | |
f697267f AN |
2801 | /* we don't support TDLS during DCM */ |
2802 | if (iwl_mvm_phy_ctx_count(mvm) > 1) | |
2803 | iwl_mvm_teardown_tdls_peers(mvm); | |
2804 | ||
b73f9a4a JB |
2805 | iwl_mvm_ftm_restart_responder(mvm, vif); |
2806 | ||
939e4904 | 2807 | goto out_unlock; |
8ca151b5 | 2808 | |
f947b62c | 2809 | out_failed: |
999609f1 | 2810 | iwl_mvm_power_update_mac(mvm); |
5691e218 | 2811 | mvmvif->ap_ibss_active = false; |
013290aa | 2812 | iwl_mvm_send_rm_bcast_sta(mvm, vif); |
ced19f26 | 2813 | iwl_mvm_rm_mcast_sta(mvm, vif); |
8ca151b5 JB |
2814 | out_unbind: |
2815 | iwl_mvm_binding_remove_vif(mvm, vif); | |
2816 | out_remove: | |
2817 | iwl_mvm_mac_ctxt_remove(mvm, vif); | |
2818 | out_unlock: | |
2819 | mutex_unlock(&mvm->mutex); | |
2820 | return ret; | |
2821 | } | |
2822 | ||
ae7ba17b ST |
2823 | static int iwl_mvm_start_ap(struct ieee80211_hw *hw, |
2824 | struct ieee80211_vif *vif, | |
b327c84c | 2825 | struct ieee80211_bss_conf *link_conf) |
ae7ba17b | 2826 | { |
b327c84c | 2827 | return iwl_mvm_start_ap_ibss(hw, vif, link_conf); |
ae7ba17b ST |
2828 | } |
2829 | ||
2830 | static int iwl_mvm_start_ibss(struct ieee80211_hw *hw, | |
2831 | struct ieee80211_vif *vif) | |
2832 | { | |
b327c84c | 2833 | return iwl_mvm_start_ap_ibss(hw, vif, &vif->bss_conf); |
ae7ba17b ST |
2834 | } |
2835 | ||
fd1a54c1 MK |
2836 | /* Common part for MLD and non-MLD ops */ |
2837 | void iwl_mvm_stop_ap_ibss_common(struct iwl_mvm *mvm, | |
2838 | struct ieee80211_vif *vif) | |
8ca151b5 | 2839 | { |
8ca151b5 JB |
2840 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
2841 | ||
fd1a54c1 | 2842 | lockdep_assert_held(&mvm->mutex); |
38a12b5b | 2843 | |
fd1a54c1 | 2844 | iwl_mvm_prepare_mac_removal(mvm, vif); |
8ca151b5 | 2845 | |
664322fa | 2846 | /* Handle AP stop while in CSA */ |
7f0a7c67 AO |
2847 | if (rcu_access_pointer(mvm->csa_vif) == vif) { |
2848 | iwl_mvm_remove_time_event(mvm, mvmvif, | |
2849 | &mvmvif->time_event_data); | |
664322fa | 2850 | RCU_INIT_POINTER(mvm->csa_vif, NULL); |
e9cb0327 | 2851 | mvmvif->csa_countdown = false; |
7f0a7c67 | 2852 | } |
664322fa | 2853 | |
003e5236 AO |
2854 | if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) { |
2855 | RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); | |
2856 | mvm->csa_tx_block_bcn_timeout = 0; | |
2857 | } | |
2858 | ||
5023d966 | 2859 | mvmvif->ap_ibss_active = false; |
1c87bbad | 2860 | mvm->ap_last_beacon_gp2 = 0; |
8ca151b5 | 2861 | |
47242744 TM |
2862 | if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { |
2863 | iwl_mvm_vif_set_low_latency(mvmvif, false, | |
2864 | LOW_LATENCY_VIF_TYPE); | |
2865 | iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id); | |
2866 | } | |
2867 | ||
8e484f0b | 2868 | iwl_mvm_bt_coex_vif_change(mvm); |
fd1a54c1 MK |
2869 | } |
2870 | ||
2871 | static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, | |
2872 | struct ieee80211_vif *vif, | |
2873 | struct ieee80211_bss_conf *link_conf) | |
2874 | { | |
2875 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
2876 | ||
2877 | mutex_lock(&mvm->mutex); | |
2878 | ||
2879 | iwl_mvm_stop_ap_ibss_common(mvm, vif); | |
dac94da8 | 2880 | |
5023d966 | 2881 | /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ |
8ca151b5 | 2882 | if (vif->p2p && mvm->p2p_device_vif) |
3dfd3a97 | 2883 | iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); |
8ca151b5 | 2884 | |
7754ae79 | 2885 | iwl_mvm_update_quotas(mvm, false, NULL); |
ced19f26 | 2886 | |
be82ecd3 AS |
2887 | iwl_mvm_ftm_responder_clear(mvm, vif); |
2888 | ||
ced19f26 SS |
2889 | /* |
2890 | * This is not very nice, but the simplest: | |
2891 | * For older FWs removing the mcast sta before the bcast station may | |
2892 | * cause assert 0x2b00. | |
2893 | * This is fixed in later FW (which will stop beaconing when removing | |
2894 | * bcast station). | |
2895 | * So make the order of removal depend on the TLV | |
2896 | */ | |
2897 | if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) | |
2898 | iwl_mvm_rm_mcast_sta(mvm, vif); | |
013290aa | 2899 | iwl_mvm_send_rm_bcast_sta(mvm, vif); |
ced19f26 SS |
2900 | if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) |
2901 | iwl_mvm_rm_mcast_sta(mvm, vif); | |
8ca151b5 | 2902 | iwl_mvm_binding_remove_vif(mvm, vif); |
a11e144e | 2903 | |
999609f1 | 2904 | iwl_mvm_power_update_mac(mvm); |
a11e144e | 2905 | |
8ca151b5 JB |
2906 | iwl_mvm_mac_ctxt_remove(mvm, vif); |
2907 | ||
2908 | mutex_unlock(&mvm->mutex); | |
2909 | } | |
2910 | ||
ae7ba17b ST |
2911 | static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, |
2912 | struct ieee80211_vif *vif, | |
b327c84c | 2913 | struct ieee80211_bss_conf *link_conf) |
ae7ba17b | 2914 | { |
b327c84c | 2915 | iwl_mvm_stop_ap_ibss(hw, vif, link_conf); |
ae7ba17b ST |
2916 | } |
2917 | ||
2918 | static void iwl_mvm_stop_ibss(struct ieee80211_hw *hw, | |
2919 | struct ieee80211_vif *vif) | |
2920 | { | |
b327c84c | 2921 | iwl_mvm_stop_ap_ibss(hw, vif, &vif->bss_conf); |
ae7ba17b ST |
2922 | } |
2923 | ||
5023d966 JB |
2924 | static void |
2925 | iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, | |
2926 | struct ieee80211_vif *vif, | |
2927 | struct ieee80211_bss_conf *bss_conf, | |
7b7090b4 | 2928 | u64 changes) |
8ca151b5 | 2929 | { |
be2056fc | 2930 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
8a5e3660 | 2931 | |
be2056fc IP |
2932 | /* Changes will be applied when the AP/IBSS is started */ |
2933 | if (!mvmvif->ap_ibss_active) | |
2934 | return; | |
2935 | ||
863230da | 2936 | if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT | |
f7d8b702 | 2937 | BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) && |
3dfd3a97 | 2938 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL)) |
863230da | 2939 | IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); |
8a5e3660 | 2940 | |
8ca151b5 | 2941 | /* Need to send a new beacon template to the FW */ |
863230da JB |
2942 | if (changes & BSS_CHANGED_BEACON && |
2943 | iwl_mvm_mac_ctxt_beacon_changed(mvm, vif)) | |
2944 | IWL_WARN(mvm, "Failed updating beacon data\n"); | |
79b7a69d | 2945 | |
b73f9a4a JB |
2946 | if (changes & BSS_CHANGED_FTM_RESPONDER) { |
2947 | int ret = iwl_mvm_ftm_start_responder(mvm, vif); | |
2948 | ||
2949 | if (ret) | |
2950 | IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n", | |
2951 | ret); | |
2952 | } | |
2953 | ||
8ca151b5 JB |
2954 | } |
2955 | ||
2956 | static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, | |
2957 | struct ieee80211_vif *vif, | |
2958 | struct ieee80211_bss_conf *bss_conf, | |
7b7090b4 | 2959 | u64 changes) |
8ca151b5 JB |
2960 | { |
2961 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
2962 | ||
2963 | mutex_lock(&mvm->mutex); | |
2964 | ||
f276e20b | 2965 | if (changes & BSS_CHANGED_IDLE && !vif->cfg.idle) |
c7d42480 | 2966 | iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true); |
723f02ed | 2967 | |
8ca151b5 JB |
2968 | switch (vif->type) { |
2969 | case NL80211_IFTYPE_STATION: | |
2970 | iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); | |
2971 | break; | |
2972 | case NL80211_IFTYPE_AP: | |
5023d966 JB |
2973 | case NL80211_IFTYPE_ADHOC: |
2974 | iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes); | |
8ca151b5 | 2975 | break; |
91b08c2d AE |
2976 | case NL80211_IFTYPE_MONITOR: |
2977 | if (changes & BSS_CHANGED_MU_GROUPS) | |
2978 | iwl_mvm_update_mu_groups(mvm, vif); | |
2979 | break; | |
8ca151b5 JB |
2980 | default: |
2981 | /* shouldn't happen */ | |
2982 | WARN_ON_ONCE(1); | |
2983 | } | |
2984 | ||
9aae43a4 JB |
2985 | if (changes & BSS_CHANGED_TXPOWER) { |
2986 | IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n", | |
2987 | bss_conf->txpower); | |
2988 | iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); | |
2989 | } | |
2990 | ||
8ca151b5 JB |
2991 | mutex_unlock(&mvm->mutex); |
2992 | } | |
2993 | ||
2994 | static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, | |
2995 | struct ieee80211_vif *vif, | |
c56ef672 | 2996 | struct ieee80211_scan_request *hw_req) |
8ca151b5 JB |
2997 | { |
2998 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
2999 | int ret; | |
3000 | ||
6749dd80 LC |
3001 | if (hw_req->req.n_channels == 0 || |
3002 | hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels) | |
8ca151b5 JB |
3003 | return -EINVAL; |
3004 | ||
3005 | mutex_lock(&mvm->mutex); | |
6749dd80 | 3006 | ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies); |
8ca151b5 | 3007 | mutex_unlock(&mvm->mutex); |
6749dd80 | 3008 | |
8ca151b5 JB |
3009 | return ret; |
3010 | } | |
3011 | ||
3012 | static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, | |
3013 | struct ieee80211_vif *vif) | |
3014 | { | |
3015 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
3016 | ||
3017 | mutex_lock(&mvm->mutex); | |
3018 | ||
e7d3abab LC |
3019 | /* Due to a race condition, it's possible that mac80211 asks |
3020 | * us to stop a hw_scan when it's already stopped. This can | |
3021 | * happen, for instance, if we stopped the scan ourselves, | |
3022 | * called ieee80211_scan_completed() and the userspace called | |
3023 | * cancel scan scan before ieee80211_scan_work() could run. | |
3024 | * To handle that, simply return if the scan is not running. | |
3025 | */ | |
262888fc | 3026 | if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) |
c7d42480 | 3027 | iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true); |
8ca151b5 JB |
3028 | |
3029 | mutex_unlock(&mvm->mutex); | |
3030 | } | |
3031 | ||
3032 | static void | |
3033 | iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, | |
3e56eadf | 3034 | struct ieee80211_sta *sta, u16 tids, |
8ca151b5 JB |
3035 | int num_frames, |
3036 | enum ieee80211_frame_release_type reason, | |
3037 | bool more_data) | |
3038 | { | |
3039 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
8ca151b5 | 3040 | |
3e56eadf | 3041 | /* Called when we need to transmit (a) frame(s) from mac80211 */ |
8ca151b5 | 3042 | |
3e56eadf JB |
3043 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, |
3044 | tids, more_data, false); | |
3045 | } | |
3046 | ||
3047 | static void | |
3048 | iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw, | |
3049 | struct ieee80211_sta *sta, u16 tids, | |
3050 | int num_frames, | |
3051 | enum ieee80211_frame_release_type reason, | |
3052 | bool more_data) | |
3053 | { | |
3054 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
3055 | ||
9a3fcf91 | 3056 | /* Called when we need to transmit (a) frame(s) from agg or dqa queue */ |
3e56eadf JB |
3057 | |
3058 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, | |
3059 | tids, more_data, true); | |
8ca151b5 JB |
3060 | } |
3061 | ||
65e25482 JB |
3062 | static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, |
3063 | enum sta_notify_cmd cmd, | |
3064 | struct ieee80211_sta *sta) | |
8ca151b5 JB |
3065 | { |
3066 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5b577a90 | 3067 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
c22b0ff5 | 3068 | unsigned long txqs = 0, tids = 0; |
3e56eadf | 3069 | int tid; |
8ca151b5 | 3070 | |
960f864b JB |
3071 | /* |
3072 | * If we have TVQM then we get too high queue numbers - luckily | |
3073 | * we really shouldn't get here with that because such hardware | |
3074 | * should have firmware supporting buffer station offload. | |
3075 | */ | |
3076 | if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) | |
3077 | return; | |
3078 | ||
c22b0ff5 | 3079 | spin_lock_bh(&mvmsta->lock); |
311590a3 | 3080 | for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) { |
c22b0ff5 EG |
3081 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
3082 | ||
6862fcee | 3083 | if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE) |
1c17627b SS |
3084 | continue; |
3085 | ||
c22b0ff5 EG |
3086 | __set_bit(tid_data->txq_id, &txqs); |
3087 | ||
dd32162d | 3088 | if (iwl_mvm_tid_queued(mvm, tid_data) == 0) |
c22b0ff5 EG |
3089 | continue; |
3090 | ||
3091 | __set_bit(tid, &tids); | |
3092 | } | |
3093 | ||
8ca151b5 JB |
3094 | switch (cmd) { |
3095 | case STA_NOTIFY_SLEEP: | |
c22b0ff5 | 3096 | for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT) |
3e56eadf | 3097 | ieee80211_sta_set_buffered(sta, tid, true); |
c22b0ff5 EG |
3098 | |
3099 | if (txqs) | |
3100 | iwl_trans_freeze_txq_timer(mvm->trans, txqs, true); | |
8ca151b5 JB |
3101 | /* |
3102 | * The fw updates the STA to be asleep. Tx packets on the Tx | |
3103 | * queues to this station will not be transmitted. The fw will | |
3104 | * send a Tx response with TX_STATUS_FAIL_DEST_PS. | |
3105 | */ | |
3106 | break; | |
3107 | case STA_NOTIFY_AWAKE: | |
0ae98812 | 3108 | if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA)) |
8ca151b5 | 3109 | break; |
c22b0ff5 EG |
3110 | |
3111 | if (txqs) | |
3112 | iwl_trans_freeze_txq_timer(mvm->trans, txqs, false); | |
9cc40712 | 3113 | iwl_mvm_sta_modify_ps_wake(mvm, sta); |
8ca151b5 JB |
3114 | break; |
3115 | default: | |
3116 | break; | |
3117 | } | |
c22b0ff5 | 3118 | spin_unlock_bh(&mvmsta->lock); |
8ca151b5 JB |
3119 | } |
3120 | ||
65e25482 JB |
3121 | static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, |
3122 | struct ieee80211_vif *vif, | |
3123 | enum sta_notify_cmd cmd, | |
3124 | struct ieee80211_sta *sta) | |
3125 | { | |
3126 | __iwl_mvm_mac_sta_notify(hw, cmd, sta); | |
3127 | } | |
3128 | ||
3129 | void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) | |
3130 | { | |
3131 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
3132 | struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data; | |
3133 | struct ieee80211_sta *sta; | |
3134 | struct iwl_mvm_sta *mvmsta; | |
3135 | bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE); | |
3136 | ||
be9ae34e | 3137 | if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations)) |
65e25482 JB |
3138 | return; |
3139 | ||
3140 | rcu_read_lock(); | |
a9560029 | 3141 | sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]); |
65e25482 JB |
3142 | if (WARN_ON(IS_ERR_OR_NULL(sta))) { |
3143 | rcu_read_unlock(); | |
3144 | return; | |
3145 | } | |
3146 | ||
3147 | mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
3148 | ||
3149 | if (!mvmsta->vif || | |
3150 | mvmsta->vif->type != NL80211_IFTYPE_AP) { | |
3151 | rcu_read_unlock(); | |
3152 | return; | |
3153 | } | |
3154 | ||
3155 | if (mvmsta->sleeping != sleeping) { | |
3156 | mvmsta->sleeping = sleeping; | |
3157 | __iwl_mvm_mac_sta_notify(mvm->hw, | |
3158 | sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE, | |
3159 | sta); | |
3160 | ieee80211_sta_ps_transition(sta, sleeping); | |
3161 | } | |
3162 | ||
3163 | if (sleeping) { | |
3164 | switch (notif->type) { | |
3165 | case IWL_MVM_PM_EVENT_AWAKE: | |
3166 | case IWL_MVM_PM_EVENT_ASLEEP: | |
3167 | break; | |
3168 | case IWL_MVM_PM_EVENT_UAPSD: | |
3169 | ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS); | |
3170 | break; | |
3171 | case IWL_MVM_PM_EVENT_PS_POLL: | |
3172 | ieee80211_sta_pspoll(sta); | |
3173 | break; | |
3174 | default: | |
3175 | break; | |
3176 | } | |
3177 | } | |
3178 | ||
3179 | rcu_read_unlock(); | |
3180 | } | |
3181 | ||
1ddbbb0c JB |
3182 | static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw, |
3183 | struct ieee80211_vif *vif, | |
3184 | struct ieee80211_sta *sta) | |
3185 | { | |
3186 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
9d8ce6af | 3187 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
1ddbbb0c JB |
3188 | |
3189 | /* | |
3190 | * This is called before mac80211 does RCU synchronisation, | |
3191 | * so here we already invalidate our internal RCU-protected | |
3192 | * station pointer. The rest of the code will thus no longer | |
3193 | * be able to find the station this way, and we don't rely | |
3194 | * on further RCU synchronisation after the sta_state() | |
3195 | * callback deleted the station. | |
3196 | */ | |
3197 | mutex_lock(&mvm->mutex); | |
3198 | if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id])) | |
3199 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], | |
3200 | ERR_PTR(-ENOENT)); | |
94939080 | 3201 | |
1ddbbb0c JB |
3202 | mutex_unlock(&mvm->mutex); |
3203 | } | |
3204 | ||
bd1ba664 JB |
3205 | static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
3206 | const u8 *bssid) | |
3207 | { | |
b0ffe455 JB |
3208 | int i; |
3209 | ||
3210 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { | |
3211 | struct iwl_mvm_tcm_mac *mdata; | |
3212 | ||
3213 | mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id]; | |
3214 | ewma_rate_init(&mdata->uapsd_nonagg_detect.rate); | |
3215 | mdata->opened_rx_ba_sessions = false; | |
3216 | } | |
3217 | ||
bd1ba664 JB |
3218 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT)) |
3219 | return; | |
3220 | ||
c5241b0c | 3221 | if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) { |
cee5a882 AA |
3222 | vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; |
3223 | return; | |
3224 | } | |
3225 | ||
11dee0b4 EG |
3226 | if (!vif->p2p && |
3227 | (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) { | |
bd1ba664 JB |
3228 | vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; |
3229 | return; | |
3230 | } | |
3231 | ||
b0ffe455 JB |
3232 | for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) { |
3233 | if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) { | |
3234 | vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; | |
3235 | return; | |
3236 | } | |
3237 | } | |
3238 | ||
bd1ba664 JB |
3239 | vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; |
3240 | } | |
3241 | ||
1e8f1329 GBA |
3242 | static void |
3243 | iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm, | |
3244 | struct ieee80211_vif *vif, u8 *peer_addr, | |
3245 | enum nl80211_tdls_operation action) | |
3246 | { | |
3247 | struct iwl_fw_dbg_trigger_tlv *trig; | |
3248 | struct iwl_fw_dbg_trigger_tdls *tdls_trig; | |
3249 | ||
6c042d75 SS |
3250 | trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), |
3251 | FW_DBG_TRIGGER_TDLS); | |
3252 | if (!trig) | |
1e8f1329 GBA |
3253 | return; |
3254 | ||
1e8f1329 | 3255 | tdls_trig = (void *)trig->data; |
1e8f1329 GBA |
3256 | |
3257 | if (!(tdls_trig->action_bitmap & BIT(action))) | |
3258 | return; | |
3259 | ||
3260 | if (tdls_trig->peer_mode && | |
3261 | memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0) | |
3262 | return; | |
3263 | ||
7174beb6 JB |
3264 | iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, |
3265 | "TDLS event occurred, peer %pM, action %d", | |
3266 | peer_addr, action); | |
1e8f1329 GBA |
3267 | } |
3268 | ||
4f58121d IP |
3269 | struct iwl_mvm_he_obss_narrow_bw_ru_data { |
3270 | bool tolerated; | |
3271 | }; | |
3272 | ||
3273 | static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy, | |
3274 | struct cfg80211_bss *bss, | |
3275 | void *_data) | |
3276 | { | |
3277 | struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data; | |
6c608cd6 | 3278 | const struct cfg80211_bss_ies *ies; |
4f58121d IP |
3279 | const struct element *elem; |
3280 | ||
6c608cd6 JB |
3281 | rcu_read_lock(); |
3282 | ies = rcu_dereference(bss->ies); | |
3283 | elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data, | |
3284 | ies->len); | |
4f58121d IP |
3285 | |
3286 | if (!elem || elem->datalen < 10 || | |
3287 | !(elem->data[10] & | |
3288 | WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) { | |
3289 | data->tolerated = false; | |
3290 | } | |
6c608cd6 | 3291 | rcu_read_unlock(); |
4f58121d IP |
3292 | } |
3293 | ||
3294 | static void iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw, | |
3295 | struct ieee80211_vif *vif) | |
3296 | { | |
3297 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
3298 | struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = { | |
3299 | .tolerated = true, | |
3300 | }; | |
3301 | ||
3302 | if (!(vif->bss_conf.chandef.chan->flags & IEEE80211_CHAN_RADAR)) { | |
3303 | mvmvif->he_ru_2mhz_block = false; | |
3304 | return; | |
3305 | } | |
3306 | ||
3307 | cfg80211_bss_iter(hw->wiphy, &vif->bss_conf.chandef, | |
3308 | iwl_mvm_check_he_obss_narrow_bw_ru_iter, | |
3309 | &iter_data); | |
3310 | ||
3311 | /* | |
3312 | * If there is at least one AP on radar channel that cannot | |
3313 | * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU. | |
3314 | */ | |
3315 | mvmvif->he_ru_2mhz_block = !iter_data.tolerated; | |
3316 | } | |
3317 | ||
f7d6ef33 JB |
3318 | static void iwl_mvm_reset_cca_40mhz_workaround(struct iwl_mvm *mvm, |
3319 | struct ieee80211_vif *vif) | |
3320 | { | |
3321 | struct ieee80211_supported_band *sband; | |
3322 | const struct ieee80211_sta_he_cap *he_cap; | |
3323 | ||
3324 | if (vif->type != NL80211_IFTYPE_STATION) | |
3325 | return; | |
3326 | ||
3327 | if (!mvm->cca_40mhz_workaround) | |
3328 | return; | |
3329 | ||
3330 | /* decrement and check that we reached zero */ | |
3331 | mvm->cca_40mhz_workaround--; | |
3332 | if (mvm->cca_40mhz_workaround) | |
3333 | return; | |
3334 | ||
3335 | sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]; | |
3336 | ||
3337 | sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
3338 | ||
3339 | he_cap = ieee80211_get_he_iftype_cap(sband, | |
3340 | ieee80211_vif_type_p2p(vif)); | |
3341 | ||
3342 | if (he_cap) { | |
3343 | /* we know that ours is writable */ | |
0301bcd5 | 3344 | struct ieee80211_sta_he_cap *he = (void *)(uintptr_t)he_cap; |
f7d6ef33 JB |
3345 | |
3346 | he->he_cap_elem.phy_cap_info[0] |= | |
3347 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G; | |
3348 | } | |
3349 | } | |
3350 | ||
6d19a5eb EG |
3351 | static void iwl_mvm_mei_host_associated(struct iwl_mvm *mvm, |
3352 | struct ieee80211_vif *vif, | |
3353 | struct iwl_mvm_sta *mvm_sta) | |
3354 | { | |
3355 | #if IS_ENABLED(CONFIG_IWLMEI) | |
3356 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
3357 | struct iwl_mei_conn_info conn_info = { | |
f276e20b | 3358 | .ssid_len = vif->cfg.ssid_len, |
6d19a5eb EG |
3359 | .channel = vif->bss_conf.chandef.chan->hw_value, |
3360 | }; | |
3361 | ||
3362 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) | |
3363 | return; | |
3364 | ||
3365 | if (!mvm->mei_registered) | |
3366 | return; | |
3367 | ||
3368 | switch (mvm_sta->pairwise_cipher) { | |
e5d3a64e AS |
3369 | case WLAN_CIPHER_SUITE_TKIP: |
3370 | conn_info.pairwise_cipher = IWL_MEI_CIPHER_TKIP; | |
3371 | break; | |
6d19a5eb EG |
3372 | case WLAN_CIPHER_SUITE_CCMP: |
3373 | conn_info.pairwise_cipher = IWL_MEI_CIPHER_CCMP; | |
3374 | break; | |
3375 | case WLAN_CIPHER_SUITE_GCMP: | |
3376 | conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP; | |
3377 | break; | |
3378 | case WLAN_CIPHER_SUITE_GCMP_256: | |
3379 | conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP_256; | |
3380 | break; | |
3381 | case 0: | |
3382 | /* open profile */ | |
3383 | break; | |
3384 | default: | |
3385 | /* cipher not supported, don't send anything to iwlmei */ | |
3386 | return; | |
3387 | } | |
3388 | ||
3389 | switch (mvmvif->rekey_data.akm) { | |
3390 | case WLAN_AKM_SUITE_SAE & 0xff: | |
3391 | conn_info.auth_mode = IWL_MEI_AKM_AUTH_SAE; | |
3392 | break; | |
3393 | case WLAN_AKM_SUITE_PSK & 0xff: | |
3394 | conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA_PSK; | |
3395 | break; | |
3396 | case WLAN_AKM_SUITE_8021X & 0xff: | |
3397 | conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA; | |
3398 | break; | |
3399 | case 0: | |
3400 | /* open profile */ | |
3401 | conn_info.auth_mode = IWL_MEI_AKM_AUTH_OPEN; | |
3402 | break; | |
3403 | default: | |
3404 | /* auth method / AKM not supported */ | |
3405 | /* TODO: All the FT vesions of these? */ | |
3406 | return; | |
3407 | } | |
3408 | ||
f276e20b | 3409 | memcpy(conn_info.ssid, vif->cfg.ssid, vif->cfg.ssid_len); |
6d19a5eb EG |
3410 | memcpy(conn_info.bssid, vif->bss_conf.bssid, ETH_ALEN); |
3411 | ||
3412 | /* TODO: add support for collocated AP data */ | |
3413 | iwl_mei_host_associated(&conn_info, NULL); | |
3414 | #endif | |
3415 | } | |
3416 | ||
8ca151b5 JB |
3417 | static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, |
3418 | struct ieee80211_vif *vif, | |
3419 | struct ieee80211_sta *sta, | |
3420 | enum ieee80211_sta_state old_state, | |
3421 | enum ieee80211_sta_state new_state) | |
3422 | { | |
3423 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
3424 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
6ea29ce5 | 3425 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
3426 | int ret; |
3427 | ||
3428 | IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", | |
3429 | sta->addr, old_state, new_state); | |
3430 | ||
3431 | /* this would be a mac80211 bug ... but don't crash */ | |
3432 | if (WARN_ON_ONCE(!mvmvif->phy_ctxt)) | |
fe56d05e | 3433 | return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) ? 0 : -EINVAL; |
8ca151b5 | 3434 | |
24afba76 LK |
3435 | /* |
3436 | * If we are in a STA removal flow and in DQA mode: | |
3437 | * | |
3438 | * This is after the sync_rcu part, so the queues have already been | |
3439 | * flushed. No more TXs on their way in mac80211's path, and no more in | |
3440 | * the queues. | |
3441 | * Also, we won't be getting any new TX frames for this station. | |
3442 | * What we might have are deferred TX frames that need to be taken care | |
3443 | * of. | |
3444 | * | |
3445 | * Drop any still-queued deferred-frame before removing the STA, and | |
3446 | * make sure the worker is no longer handling frames for this STA. | |
3447 | */ | |
3448 | if (old_state == IEEE80211_STA_NONE && | |
c8f54701 | 3449 | new_state == IEEE80211_STA_NOTEXIST) { |
24afba76 LK |
3450 | flush_work(&mvm->add_stream_wk); |
3451 | ||
3452 | /* | |
3453 | * No need to make sure deferred TX indication is off since the | |
3454 | * worker will already remove it if it was on | |
3455 | */ | |
f7d6ef33 JB |
3456 | |
3457 | /* | |
3458 | * Additionally, reset the 40 MHz capability if we disconnected | |
3459 | * from the AP now. | |
3460 | */ | |
3461 | iwl_mvm_reset_cca_40mhz_workaround(mvm, vif); | |
24afba76 LK |
3462 | } |
3463 | ||
8ca151b5 | 3464 | mutex_lock(&mvm->mutex); |
6ea29ce5 | 3465 | /* track whether or not the station is associated */ |
d94c5a82 | 3466 | mvm_sta->sta_state = new_state; |
6ea29ce5 | 3467 | |
8ca151b5 JB |
3468 | if (old_state == IEEE80211_STA_NOTEXIST && |
3469 | new_state == IEEE80211_STA_NONE) { | |
48bc1307 JB |
3470 | /* |
3471 | * Firmware bug - it'll crash if the beacon interval is less | |
3472 | * than 16. We can't avoid connecting at all, so refuse the | |
3473 | * station state change, this will cause mac80211 to abandon | |
3474 | * attempts to connect to this AP, and eventually wpa_s will | |
cdaba917 | 3475 | * blocklist the AP... |
48bc1307 JB |
3476 | */ |
3477 | if (vif->type == NL80211_IFTYPE_STATION && | |
3478 | vif->bss_conf.beacon_int < 16) { | |
3479 | IWL_ERR(mvm, | |
3480 | "AP %pM beacon interval is %d, refusing due to firmware bug!\n", | |
3481 | sta->addr, vif->bss_conf.beacon_int); | |
3482 | ret = -EINVAL; | |
3483 | goto out_unlock; | |
3484 | } | |
cf7b491d | 3485 | |
97cc1694 | 3486 | if (vif->type == NL80211_IFTYPE_STATION) |
046d2e7c | 3487 | vif->bss_conf.he_support = sta->deflink.he_cap.has_he; |
97cc1694 | 3488 | |
cf7b491d AN |
3489 | if (sta->tdls && |
3490 | (vif->p2p || | |
fa3d07e4 AN |
3491 | iwl_mvm_tdls_sta_count(mvm, NULL) == |
3492 | IWL_MVM_TDLS_STA_COUNT || | |
cf7b491d AN |
3493 | iwl_mvm_phy_ctx_count(mvm) > 1)) { |
3494 | IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n"); | |
3495 | ret = -EBUSY; | |
3496 | goto out_unlock; | |
3497 | } | |
3498 | ||
8ca151b5 | 3499 | ret = iwl_mvm_add_sta(mvm, vif, sta); |
1e8f1329 | 3500 | if (sta->tdls && ret == 0) { |
fa3d07e4 | 3501 | iwl_mvm_recalc_tdls_state(mvm, vif, true); |
1e8f1329 GBA |
3502 | iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, |
3503 | NL80211_TDLS_SETUP); | |
3504 | } | |
438af969 | 3505 | |
4c51541d | 3506 | sta->deflink.agg.max_rc_amsdu_len = 1; |
8ca151b5 JB |
3507 | } else if (old_state == IEEE80211_STA_NONE && |
3508 | new_state == IEEE80211_STA_AUTH) { | |
e820c2da HD |
3509 | /* |
3510 | * EBS may be disabled due to previous failures reported by FW. | |
3511 | * Reset EBS status here assuming environment has been changed. | |
3512 | */ | |
3513 | mvm->last_ebs_successful = true; | |
bd1ba664 | 3514 | iwl_mvm_check_uapsd(mvm, vif, sta->addr); |
8ca151b5 JB |
3515 | ret = 0; |
3516 | } else if (old_state == IEEE80211_STA_AUTH && | |
3517 | new_state == IEEE80211_STA_ASSOC) { | |
8be30c13 | 3518 | if (vif->type == NL80211_IFTYPE_AP) { |
046d2e7c | 3519 | vif->bss_conf.he_support = sta->deflink.he_cap.has_he; |
8be30c13 AB |
3520 | mvmvif->ap_assoc_sta_count++; |
3521 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); | |
cb63eb43 MK |
3522 | if ((vif->bss_conf.he_support && |
3523 | !iwlwifi_mod_params.disable_11ax) || | |
3524 | (vif->bss_conf.eht_support && | |
3525 | !iwlwifi_mod_params.disable_11be)) | |
02221a81 | 3526 | iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id); |
9394662a | 3527 | } else if (vif->type == NL80211_IFTYPE_STATION) { |
046d2e7c | 3528 | vif->bss_conf.he_support = sta->deflink.he_cap.has_he; |
4f58121d IP |
3529 | |
3530 | mvmvif->he_ru_2mhz_block = false; | |
046d2e7c | 3531 | if (sta->deflink.he_cap.has_he) |
4f58121d IP |
3532 | iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif); |
3533 | ||
9394662a | 3534 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); |
8be30c13 | 3535 | } |
735a0045 | 3536 | |
3baf7528 AS |
3537 | iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, |
3538 | false); | |
7a453973 | 3539 | ret = iwl_mvm_update_sta(mvm, vif, sta); |
8ca151b5 JB |
3540 | } else if (old_state == IEEE80211_STA_ASSOC && |
3541 | new_state == IEEE80211_STA_AUTHORIZED) { | |
475c6bde | 3542 | ret = 0; |
f59e0e3c AN |
3543 | |
3544 | /* we don't support TDLS during DCM */ | |
3545 | if (iwl_mvm_phy_ctx_count(mvm) > 1) | |
3546 | iwl_mvm_teardown_tdls_peers(mvm); | |
3547 | ||
4634b176 | 3548 | if (sta->tdls) { |
1e8f1329 GBA |
3549 | iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, |
3550 | NL80211_TDLS_ENABLE_LINK); | |
4634b176 JB |
3551 | } else { |
3552 | /* enable beacon filtering */ | |
3553 | WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); | |
1e8f1329 | 3554 | |
8b75858c JB |
3555 | mvmvif->authorized = 1; |
3556 | ||
4634b176 | 3557 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); |
6d19a5eb | 3558 | iwl_mvm_mei_host_associated(mvm, vif, mvm_sta); |
4634b176 | 3559 | } |
50f56044 | 3560 | |
3baf7528 AS |
3561 | iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, |
3562 | true); | |
8ca151b5 JB |
3563 | } else if (old_state == IEEE80211_STA_AUTHORIZED && |
3564 | new_state == IEEE80211_STA_ASSOC) { | |
d9e95e35 MG |
3565 | /* once we move into assoc state, need to update rate scale to |
3566 | * disable using wide bandwidth | |
3567 | */ | |
3568 | iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, | |
3569 | false); | |
4634b176 | 3570 | if (!sta->tdls) { |
8b75858c | 3571 | /* |
f5034bcf MK |
3572 | * Set this but don't call iwl_mvm_mac_ctxt_changed() |
3573 | * yet to avoid sending high prio again for a little | |
3574 | * time. | |
8b75858c JB |
3575 | */ |
3576 | mvmvif->authorized = 0; | |
3577 | ||
4634b176 JB |
3578 | /* disable beacon filtering */ |
3579 | ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); | |
3580 | WARN_ON(ret && | |
3581 | !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, | |
3582 | &mvm->status)); | |
3583 | } | |
8ca151b5 JB |
3584 | ret = 0; |
3585 | } else if (old_state == IEEE80211_STA_ASSOC && | |
3586 | new_state == IEEE80211_STA_AUTH) { | |
8be30c13 AB |
3587 | if (vif->type == NL80211_IFTYPE_AP) { |
3588 | mvmvif->ap_assoc_sta_count--; | |
3589 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); | |
d5d8ee52 | 3590 | } else if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) |
cf7a7457 | 3591 | iwl_mvm_stop_session_protection(mvm, vif); |
8ca151b5 JB |
3592 | ret = 0; |
3593 | } else if (old_state == IEEE80211_STA_AUTH && | |
3594 | new_state == IEEE80211_STA_NONE) { | |
3595 | ret = 0; | |
3596 | } else if (old_state == IEEE80211_STA_NONE && | |
3597 | new_state == IEEE80211_STA_NOTEXIST) { | |
d5d8ee52 EG |
3598 | if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) |
3599 | iwl_mvm_stop_session_protection(mvm, vif); | |
8ca151b5 | 3600 | ret = iwl_mvm_rm_sta(mvm, vif, sta); |
1e8f1329 | 3601 | if (sta->tdls) { |
fa3d07e4 | 3602 | iwl_mvm_recalc_tdls_state(mvm, vif, false); |
1e8f1329 GBA |
3603 | iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, |
3604 | NL80211_TDLS_DISABLE_LINK); | |
3605 | } | |
34a880d8 | 3606 | |
44135b7c IP |
3607 | if (unlikely(ret && |
3608 | test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, | |
3609 | &mvm->status))) | |
3610 | ret = 0; | |
8ca151b5 JB |
3611 | } else { |
3612 | ret = -EIO; | |
3613 | } | |
48bc1307 | 3614 | out_unlock: |
8ca151b5 JB |
3615 | mutex_unlock(&mvm->mutex); |
3616 | ||
9c126cd6 LK |
3617 | if (sta->tdls && ret == 0) { |
3618 | if (old_state == IEEE80211_STA_NOTEXIST && | |
3619 | new_state == IEEE80211_STA_NONE) | |
3620 | ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID); | |
3621 | else if (old_state == IEEE80211_STA_NONE && | |
3622 | new_state == IEEE80211_STA_NOTEXIST) | |
3623 | ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID); | |
3624 | } | |
3625 | ||
8ca151b5 JB |
3626 | return ret; |
3627 | } | |
3628 | ||
3629 | static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) | |
3630 | { | |
3631 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
3632 | ||
3633 | mvm->rts_threshold = value; | |
3634 | ||
3635 | return 0; | |
3636 | } | |
3637 | ||
1f3b0ff8 LE |
3638 | static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, |
3639 | struct ieee80211_vif *vif, | |
3640 | struct ieee80211_sta *sta, u32 changed) | |
3641 | { | |
3642 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
dcfe3b10 JB |
3643 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
3644 | ||
3645 | if (changed & (IEEE80211_RC_BW_CHANGED | | |
3646 | IEEE80211_RC_SUPP_RATES_CHANGED | | |
3647 | IEEE80211_RC_NSS_CHANGED)) | |
3648 | iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, | |
3649 | true); | |
1f3b0ff8 LE |
3650 | |
3651 | if (vif->type == NL80211_IFTYPE_STATION && | |
3652 | changed & IEEE80211_RC_NSS_CHANGED) | |
3653 | iwl_mvm_sf_update(mvm, vif, false); | |
3654 | } | |
3655 | ||
8ca151b5 | 3656 | static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, |
b3e2130b JB |
3657 | struct ieee80211_vif *vif, |
3658 | unsigned int link_id, u16 ac, | |
8ca151b5 JB |
3659 | const struct ieee80211_tx_queue_params *params) |
3660 | { | |
3661 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
3662 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
3663 | ||
3664 | mvmvif->queue_params[ac] = *params; | |
3665 | ||
3666 | /* | |
3667 | * No need to update right away, we'll get BSS_CHANGED_QOS | |
3668 | * The exception is P2P_DEVICE interface which needs immediate update. | |
3669 | */ | |
3670 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
3671 | int ret; | |
3672 | ||
3673 | mutex_lock(&mvm->mutex); | |
3dfd3a97 | 3674 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); |
8ca151b5 JB |
3675 | mutex_unlock(&mvm->mutex); |
3676 | return ret; | |
3677 | } | |
3678 | return 0; | |
3679 | } | |
3680 | ||
3681 | static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, | |
d4e36e55 | 3682 | struct ieee80211_vif *vif, |
15fae341 | 3683 | struct ieee80211_prep_tx_info *info) |
8ca151b5 JB |
3684 | { |
3685 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
d4e36e55 | 3686 | |
8ca151b5 | 3687 | mutex_lock(&mvm->mutex); |
af84ac57 | 3688 | iwl_mvm_protect_assoc(mvm, vif, info->duration); |
8ca151b5 JB |
3689 | mutex_unlock(&mvm->mutex); |
3690 | } | |
3691 | ||
6b1259d1 JB |
3692 | static void iwl_mvm_mac_mgd_complete_tx(struct ieee80211_hw *hw, |
3693 | struct ieee80211_vif *vif, | |
3694 | struct ieee80211_prep_tx_info *info) | |
3695 | { | |
3696 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
3697 | ||
3698 | /* for successful cases (auth/assoc), don't cancel session protection */ | |
3699 | if (info->success) | |
3700 | return; | |
3701 | ||
3702 | mutex_lock(&mvm->mutex); | |
3703 | iwl_mvm_stop_session_protection(mvm, vif); | |
3704 | mutex_unlock(&mvm->mutex); | |
3705 | } | |
3706 | ||
35a000b7 DS |
3707 | static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, |
3708 | struct ieee80211_vif *vif, | |
3709 | struct cfg80211_sched_scan_request *req, | |
633e2713 | 3710 | struct ieee80211_scan_ies *ies) |
35a000b7 DS |
3711 | { |
3712 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
35a000b7 | 3713 | |
35a000b7 | 3714 | int ret; |
4660dfbb | 3715 | |
35a000b7 DS |
3716 | mutex_lock(&mvm->mutex); |
3717 | ||
f276e20b | 3718 | if (!vif->cfg.idle) { |
bd5e4744 DS |
3719 | ret = -EBUSY; |
3720 | goto out; | |
3721 | } | |
3722 | ||
19945dfb | 3723 | ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED); |
d2496221 | 3724 | |
35a000b7 DS |
3725 | out: |
3726 | mutex_unlock(&mvm->mutex); | |
3727 | return ret; | |
3728 | } | |
3729 | ||
37e3308c JB |
3730 | static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, |
3731 | struct ieee80211_vif *vif) | |
35a000b7 DS |
3732 | { |
3733 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
33ea27f6 | 3734 | int ret; |
35a000b7 DS |
3735 | |
3736 | mutex_lock(&mvm->mutex); | |
e7d3abab LC |
3737 | |
3738 | /* Due to a race condition, it's possible that mac80211 asks | |
3739 | * us to stop a sched_scan when it's already stopped. This | |
3740 | * can happen, for instance, if we stopped the scan ourselves, | |
3741 | * called ieee80211_sched_scan_stopped() and the userspace called | |
3742 | * stop sched scan scan before ieee80211_sched_scan_stopped_work() | |
3743 | * could run. To handle this, simply return if the scan is | |
3744 | * not running. | |
3745 | */ | |
262888fc | 3746 | if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) { |
e7d3abab LC |
3747 | mutex_unlock(&mvm->mutex); |
3748 | return 0; | |
3749 | } | |
3750 | ||
c7d42480 | 3751 | ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false); |
35a000b7 | 3752 | mutex_unlock(&mvm->mutex); |
33ea27f6 | 3753 | iwl_mvm_wait_for_async_handlers(mvm); |
37e3308c | 3754 | |
33ea27f6 | 3755 | return ret; |
35a000b7 DS |
3756 | } |
3757 | ||
6569e7d3 JB |
3758 | static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw, |
3759 | enum set_key_cmd cmd, | |
3760 | struct ieee80211_vif *vif, | |
3761 | struct ieee80211_sta *sta, | |
3762 | struct ieee80211_key_conf *key) | |
8ca151b5 | 3763 | { |
c56e00a3 | 3764 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
8ca151b5 | 3765 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
46c7b05a | 3766 | struct iwl_mvm_sta *mvmsta = NULL; |
f5e28eac JB |
3767 | struct iwl_mvm_key_pn *ptk_pn; |
3768 | int keyidx = key->keyidx; | |
5c75a208 JB |
3769 | u32 sec_key_id = WIDE_ID(DATA_PATH_GROUP, SEC_KEY_CMD); |
3770 | u8 sec_key_ver = iwl_fw_lookup_cmd_ver(mvm->fw, sec_key_id, 0); | |
c56e00a3 | 3771 | int ret, i; |
d6ee54a9 | 3772 | u8 key_offset; |
8ca151b5 | 3773 | |
46c7b05a EG |
3774 | if (sta) |
3775 | mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
6d19a5eb | 3776 | |
8ca151b5 JB |
3777 | switch (key->cipher) { |
3778 | case WLAN_CIPHER_SUITE_TKIP: | |
286ca8eb | 3779 | if (!mvm->trans->trans_cfg->gen2) { |
7f768ad5 DS |
3780 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
3781 | key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; | |
3782 | } else if (vif->type == NL80211_IFTYPE_STATION) { | |
3783 | key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE; | |
3784 | } else { | |
3785 | IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n"); | |
3786 | return -EOPNOTSUPP; | |
3787 | } | |
8ca151b5 | 3788 | break; |
ca8c0f4b | 3789 | case WLAN_CIPHER_SUITE_CCMP: |
2a53d166 AB |
3790 | case WLAN_CIPHER_SUITE_GCMP: |
3791 | case WLAN_CIPHER_SUITE_GCMP_256: | |
85aeb58c DS |
3792 | if (!iwl_mvm_has_new_tx_api(mvm)) |
3793 | key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; | |
ca8c0f4b | 3794 | break; |
8ca151b5 | 3795 | case WLAN_CIPHER_SUITE_AES_CMAC: |
8e160ab8 AB |
3796 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
3797 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: | |
30686bf7 | 3798 | WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE)); |
8ca151b5 JB |
3799 | break; |
3800 | case WLAN_CIPHER_SUITE_WEP40: | |
3801 | case WLAN_CIPHER_SUITE_WEP104: | |
475c6bde JB |
3802 | if (vif->type == NL80211_IFTYPE_STATION) |
3803 | break; | |
3804 | if (iwl_mvm_has_new_tx_api(mvm)) | |
3805 | return -EOPNOTSUPP; | |
3806 | /* support HW crypto on TX */ | |
3807 | return 0; | |
8ca151b5 | 3808 | default: |
8b3d2c48 | 3809 | return -EOPNOTSUPP; |
8ca151b5 JB |
3810 | } |
3811 | ||
8ca151b5 JB |
3812 | switch (cmd) { |
3813 | case SET_KEY: | |
a5de7de7 JB |
3814 | if (vif->type == NL80211_IFTYPE_STATION && |
3815 | (keyidx == 6 || keyidx == 7)) | |
b1fdc250 JB |
3816 | rcu_assign_pointer(mvmvif->bcn_prot.keys[keyidx - 6], |
3817 | key); | |
3818 | ||
5023d966 JB |
3819 | if ((vif->type == NL80211_IFTYPE_ADHOC || |
3820 | vif->type == NL80211_IFTYPE_AP) && !sta) { | |
3821 | /* | |
3822 | * GTK on AP interface is a TX-only key, return 0; | |
3823 | * on IBSS they're per-station and because we're lazy | |
3824 | * we don't support them for RX, so do the same. | |
8e160ab8 | 3825 | * CMAC/GMAC in AP/IBSS modes must be done in software. |
a5de7de7 JB |
3826 | * |
3827 | * Except, of course, beacon protection - it must be | |
3828 | * offloaded since we just set a beacon template. | |
5023d966 | 3829 | */ |
a5de7de7 JB |
3830 | if (keyidx < 6 && |
3831 | (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || | |
3832 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || | |
3833 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)) { | |
81279c49 | 3834 | ret = -EOPNOTSUPP; |
a1c2ff30 AO |
3835 | break; |
3836 | } | |
85aeb58c DS |
3837 | |
3838 | if (key->cipher != WLAN_CIPHER_SUITE_GCMP && | |
3839 | key->cipher != WLAN_CIPHER_SUITE_GCMP_256 && | |
3840 | !iwl_mvm_has_new_tx_api(mvm)) { | |
3841 | key->hw_key_idx = STA_KEY_IDX_INVALID; | |
a1c2ff30 | 3842 | ret = 0; |
85aeb58c DS |
3843 | break; |
3844 | } | |
c56e00a3 JB |
3845 | |
3846 | if (!mvmvif->ap_ibss_active) { | |
3847 | for (i = 0; | |
3848 | i < ARRAY_SIZE(mvmvif->ap_early_keys); | |
3849 | i++) { | |
3850 | if (!mvmvif->ap_early_keys[i]) { | |
3851 | mvmvif->ap_early_keys[i] = key; | |
3852 | break; | |
3853 | } | |
3854 | } | |
3855 | ||
3856 | if (i >= ARRAY_SIZE(mvmvif->ap_early_keys)) | |
3857 | ret = -ENOSPC; | |
a1c2ff30 AO |
3858 | else |
3859 | ret = 0; | |
c56e00a3 JB |
3860 | |
3861 | break; | |
3862 | } | |
6caffd4f JB |
3863 | } |
3864 | ||
b546dcd6 JB |
3865 | /* During FW restart, in order to restore the state as it was, |
3866 | * don't try to reprogram keys we previously failed for. | |
3867 | */ | |
3868 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && | |
3869 | key->hw_key_idx == STA_KEY_IDX_INVALID) { | |
3870 | IWL_DEBUG_MAC80211(mvm, | |
3871 | "skip invalid idx key programming during restart\n"); | |
3872 | ret = 0; | |
3873 | break; | |
3874 | } | |
3875 | ||
f5e28eac | 3876 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && |
46c7b05a | 3877 | mvmsta && iwl_mvm_has_new_rx_api(mvm) && |
f5e28eac JB |
3878 | key->flags & IEEE80211_KEY_FLAG_PAIRWISE && |
3879 | (key->cipher == WLAN_CIPHER_SUITE_CCMP || | |
2a53d166 AB |
3880 | key->cipher == WLAN_CIPHER_SUITE_GCMP || |
3881 | key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { | |
f5e28eac JB |
3882 | struct ieee80211_key_seq seq; |
3883 | int tid, q; | |
3884 | ||
f5e28eac | 3885 | WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx])); |
acafe7e3 KC |
3886 | ptk_pn = kzalloc(struct_size(ptk_pn, q, |
3887 | mvm->trans->num_rx_queues), | |
f5e28eac JB |
3888 | GFP_KERNEL); |
3889 | if (!ptk_pn) { | |
3890 | ret = -ENOMEM; | |
3891 | break; | |
3892 | } | |
3893 | ||
3894 | for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { | |
3895 | ieee80211_get_key_rx_seq(key, tid, &seq); | |
3896 | for (q = 0; q < mvm->trans->num_rx_queues; q++) | |
3897 | memcpy(ptk_pn->q[q].pn[tid], | |
3898 | seq.ccmp.pn, | |
3899 | IEEE80211_CCMP_PN_LEN); | |
3900 | } | |
3901 | ||
3902 | rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn); | |
3903 | } | |
3904 | ||
d6ee54a9 LC |
3905 | /* in HW restart reuse the index, otherwise request a new one */ |
3906 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) | |
3907 | key_offset = key->hw_key_idx; | |
3908 | else | |
3909 | key_offset = STA_KEY_IDX_INVALID; | |
3910 | ||
46c7b05a | 3911 | if (mvmsta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
6d19a5eb EG |
3912 | mvmsta->pairwise_cipher = key->cipher; |
3913 | ||
a5de7de7 JB |
3914 | IWL_DEBUG_MAC80211(mvm, "set hwcrypto key (sta:%pM, id:%d)\n", |
3915 | sta ? sta->addr : NULL, key->keyidx); | |
5c75a208 JB |
3916 | |
3917 | if (sec_key_ver) | |
3918 | ret = iwl_mvm_sec_key_add(mvm, vif, sta, key); | |
3919 | else | |
3920 | ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset); | |
3921 | ||
8ca151b5 JB |
3922 | if (ret) { |
3923 | IWL_WARN(mvm, "set key failed\n"); | |
475c6bde | 3924 | key->hw_key_idx = STA_KEY_IDX_INVALID; |
8ca151b5 JB |
3925 | /* |
3926 | * can't add key for RX, but we don't need it | |
475c6bde JB |
3927 | * in the device for TX so still return 0, |
3928 | * unless we have new TX API where we cannot | |
3929 | * put key material into the TX_CMD | |
8ca151b5 | 3930 | */ |
475c6bde JB |
3931 | if (iwl_mvm_has_new_tx_api(mvm)) |
3932 | ret = -EOPNOTSUPP; | |
3933 | else | |
3934 | ret = 0; | |
8ca151b5 JB |
3935 | } |
3936 | ||
3937 | break; | |
3938 | case DISABLE_KEY: | |
a5de7de7 JB |
3939 | if (vif->type == NL80211_IFTYPE_STATION && |
3940 | (keyidx == 6 || keyidx == 7)) | |
b1fdc250 JB |
3941 | RCU_INIT_POINTER(mvmvif->bcn_prot.keys[keyidx - 6], |
3942 | NULL); | |
3943 | ||
c56e00a3 JB |
3944 | ret = -ENOENT; |
3945 | for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { | |
3946 | if (mvmvif->ap_early_keys[i] == key) { | |
3947 | mvmvif->ap_early_keys[i] = NULL; | |
3948 | ret = 0; | |
3949 | } | |
3950 | } | |
3951 | ||
3952 | /* found in pending list - don't do anything else */ | |
3953 | if (ret == 0) | |
3954 | break; | |
3955 | ||
6caffd4f JB |
3956 | if (key->hw_key_idx == STA_KEY_IDX_INVALID) { |
3957 | ret = 0; | |
3958 | break; | |
3959 | } | |
3960 | ||
46c7b05a | 3961 | if (mvmsta && iwl_mvm_has_new_rx_api(mvm) && |
f5e28eac JB |
3962 | key->flags & IEEE80211_KEY_FLAG_PAIRWISE && |
3963 | (key->cipher == WLAN_CIPHER_SUITE_CCMP || | |
2a53d166 AB |
3964 | key->cipher == WLAN_CIPHER_SUITE_GCMP || |
3965 | key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { | |
f5e28eac JB |
3966 | ptk_pn = rcu_dereference_protected( |
3967 | mvmsta->ptk_pn[keyidx], | |
3968 | lockdep_is_held(&mvm->mutex)); | |
3969 | RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL); | |
3970 | if (ptk_pn) | |
3971 | kfree_rcu(ptk_pn, rcu_head); | |
3972 | } | |
3973 | ||
8ca151b5 | 3974 | IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); |
5c75a208 JB |
3975 | if (sec_key_ver) |
3976 | ret = iwl_mvm_sec_key_del(mvm, vif, sta, key); | |
3977 | else | |
3978 | ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); | |
8ca151b5 JB |
3979 | break; |
3980 | default: | |
3981 | ret = -EINVAL; | |
3982 | } | |
3983 | ||
6569e7d3 JB |
3984 | return ret; |
3985 | } | |
3986 | ||
3987 | static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, | |
3988 | enum set_key_cmd cmd, | |
3989 | struct ieee80211_vif *vif, | |
3990 | struct ieee80211_sta *sta, | |
3991 | struct ieee80211_key_conf *key) | |
3992 | { | |
3993 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
3994 | int ret; | |
3995 | ||
3996 | mutex_lock(&mvm->mutex); | |
3997 | ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key); | |
8ca151b5 | 3998 | mutex_unlock(&mvm->mutex); |
6569e7d3 | 3999 | |
8ca151b5 JB |
4000 | return ret; |
4001 | } | |
4002 | ||
4003 | static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, | |
4004 | struct ieee80211_vif *vif, | |
4005 | struct ieee80211_key_conf *keyconf, | |
4006 | struct ieee80211_sta *sta, | |
4007 | u32 iv32, u16 *phase1key) | |
4008 | { | |
4009 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4010 | ||
5023d966 JB |
4011 | if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) |
4012 | return; | |
4013 | ||
8ca151b5 JB |
4014 | iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); |
4015 | } | |
4016 | ||
4017 | ||
b112889c AM |
4018 | static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait, |
4019 | struct iwl_rx_packet *pkt, void *data) | |
4020 | { | |
4021 | struct iwl_mvm *mvm = | |
4022 | container_of(notif_wait, struct iwl_mvm, notif_wait); | |
4023 | struct iwl_hs20_roc_res *resp; | |
4024 | int resp_len = iwl_rx_packet_payload_len(pkt); | |
4025 | struct iwl_mvm_time_event_data *te_data = data; | |
4026 | ||
4027 | if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD)) | |
4028 | return true; | |
4029 | ||
4030 | if (WARN_ON_ONCE(resp_len != sizeof(*resp))) { | |
4031 | IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n"); | |
4032 | return true; | |
4033 | } | |
4034 | ||
4035 | resp = (void *)pkt->data; | |
4036 | ||
4037 | IWL_DEBUG_TE(mvm, | |
b71a9c35 | 4038 | "Aux ROC: Received response from ucode: status=%d uid=%d\n", |
b112889c AM |
4039 | resp->status, resp->event_unique_id); |
4040 | ||
4041 | te_data->uid = le32_to_cpu(resp->event_unique_id); | |
4042 | IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n", | |
4043 | te_data->uid); | |
4044 | ||
4045 | spin_lock_bh(&mvm->time_event_lock); | |
4046 | list_add_tail(&te_data->list, &mvm->aux_roc_te_list); | |
4047 | spin_unlock_bh(&mvm->time_event_lock); | |
4048 | ||
4049 | return true; | |
4050 | } | |
4051 | ||
dc28e12f MG |
4052 | #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100) |
4053 | #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200) | |
4054 | #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600) | |
4055 | #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20) | |
4056 | #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10) | |
b112889c AM |
4057 | static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm, |
4058 | struct ieee80211_channel *channel, | |
4059 | struct ieee80211_vif *vif, | |
4060 | int duration) | |
4061 | { | |
afc1e3b4 | 4062 | int res; |
b112889c AM |
4063 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
4064 | struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data; | |
6eb031d2 | 4065 | static const u16 time_event_response[] = { HOT_SPOT_CMD }; |
b112889c | 4066 | struct iwl_notification_wait wait_time_event; |
dc28e12f MG |
4067 | u32 dtim_interval = vif->bss_conf.dtim_period * |
4068 | vif->bss_conf.beacon_int; | |
4069 | u32 req_dur, delay; | |
b112889c AM |
4070 | struct iwl_hs20_roc_req aux_roc_req = { |
4071 | .action = cpu_to_le32(FW_CTXT_ACTION_ADD), | |
4072 | .id_and_color = | |
4073 | cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)), | |
4074 | .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id), | |
57e861d9 DS |
4075 | }; |
4076 | struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm, | |
4077 | &aux_roc_req.channel_info); | |
4078 | u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm); | |
4079 | ||
4080 | /* Set the channel info data */ | |
4081 | iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value, | |
3717f91a | 4082 | iwl_mvm_phy_band_from_nl80211(channel->band), |
7ac87575 | 4083 | IWL_PHY_CHANNEL_MODE20, |
57e861d9 DS |
4084 | 0); |
4085 | ||
4086 | /* Set the time and duration */ | |
afc1e3b4 | 4087 | tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm)); |
b112889c | 4088 | |
dc28e12f MG |
4089 | delay = AUX_ROC_MIN_DELAY; |
4090 | req_dur = MSEC_TO_TU(duration); | |
4091 | ||
4092 | /* | |
4093 | * If we are associated we want the delay time to be at least one | |
4094 | * dtim interval so that the FW can wait until after the DTIM and | |
4095 | * then start the time event, this will potentially allow us to | |
4096 | * remain off-channel for the max duration. | |
4097 | * Since we want to use almost a whole dtim interval we would also | |
4098 | * like the delay to be for 2-3 dtim intervals, in case there are | |
4099 | * other time events with higher priority. | |
4100 | */ | |
f276e20b | 4101 | if (vif->cfg.assoc) { |
dc28e12f MG |
4102 | delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY); |
4103 | /* We cannot remain off-channel longer than the DTIM interval */ | |
4104 | if (dtim_interval <= req_dur) { | |
4105 | req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER; | |
4106 | if (req_dur <= AUX_ROC_MIN_DURATION) | |
4107 | req_dur = dtim_interval - | |
4108 | AUX_ROC_MIN_SAFETY_BUFFER; | |
4109 | } | |
4110 | } | |
4111 | ||
57e861d9 DS |
4112 | tail->duration = cpu_to_le32(req_dur); |
4113 | tail->apply_time_max_delay = cpu_to_le32(delay); | |
dc28e12f MG |
4114 | |
4115 | IWL_DEBUG_TE(mvm, | |
903b3f9b EG |
4116 | "ROC: Requesting to remain on channel %u for %ums\n", |
4117 | channel->hw_value, req_dur); | |
4118 | IWL_DEBUG_TE(mvm, | |
4119 | "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n", | |
4120 | duration, delay, dtim_interval); | |
4121 | ||
b112889c | 4122 | /* Set the node address */ |
57e861d9 | 4123 | memcpy(tail->node_addr, vif->addr, ETH_ALEN); |
b112889c | 4124 | |
a6cc5163 MG |
4125 | lockdep_assert_held(&mvm->mutex); |
4126 | ||
4127 | spin_lock_bh(&mvm->time_event_lock); | |
4128 | ||
4129 | if (WARN_ON(te_data->id == HOT_SPOT_CMD)) { | |
4130 | spin_unlock_bh(&mvm->time_event_lock); | |
4131 | return -EIO; | |
4132 | } | |
4133 | ||
b112889c AM |
4134 | te_data->vif = vif; |
4135 | te_data->duration = duration; | |
4136 | te_data->id = HOT_SPOT_CMD; | |
4137 | ||
b112889c AM |
4138 | spin_unlock_bh(&mvm->time_event_lock); |
4139 | ||
4140 | /* | |
4141 | * Use a notification wait, which really just processes the | |
4142 | * command response and doesn't wait for anything, in order | |
4143 | * to be able to process the response and get the UID inside | |
4144 | * the RX path. Using CMD_WANT_SKB doesn't work because it | |
4145 | * stores the buffer and then wakes up this thread, by which | |
4146 | * time another notification (that the time event started) | |
4147 | * might already be processed unsuccessfully. | |
4148 | */ | |
4149 | iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event, | |
4150 | time_event_response, | |
4151 | ARRAY_SIZE(time_event_response), | |
4152 | iwl_mvm_rx_aux_roc, te_data); | |
4153 | ||
57e861d9 | 4154 | res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len, |
b112889c AM |
4155 | &aux_roc_req); |
4156 | ||
4157 | if (res) { | |
4158 | IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res); | |
4159 | iwl_remove_notification(&mvm->notif_wait, &wait_time_event); | |
4160 | goto out_clear_te; | |
4161 | } | |
4162 | ||
4163 | /* No need to wait for anything, so just pass 1 (0 isn't valid) */ | |
4164 | res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1); | |
4165 | /* should never fail */ | |
4166 | WARN_ON_ONCE(res); | |
4167 | ||
4168 | if (res) { | |
4169 | out_clear_te: | |
4170 | spin_lock_bh(&mvm->time_event_lock); | |
4171 | iwl_mvm_te_clear_data(mvm, te_data); | |
4172 | spin_unlock_bh(&mvm->time_event_lock); | |
4173 | } | |
4174 | ||
4175 | return res; | |
4176 | } | |
4177 | ||
8ca151b5 JB |
4178 | static int iwl_mvm_roc(struct ieee80211_hw *hw, |
4179 | struct ieee80211_vif *vif, | |
4180 | struct ieee80211_channel *channel, | |
d339d5ca IP |
4181 | int duration, |
4182 | enum ieee80211_roc_type type) | |
8ca151b5 JB |
4183 | { |
4184 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
fe0f2de3 | 4185 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
8ca151b5 | 4186 | struct cfg80211_chan_def chandef; |
31d385ae | 4187 | struct iwl_mvm_phy_ctxt *phy_ctxt; |
8835a64f | 4188 | bool band_change_removal; |
31d385ae IP |
4189 | int ret, i; |
4190 | ||
4191 | IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, | |
4192 | duration, type); | |
8ca151b5 | 4193 | |
9834781c JB |
4194 | /* |
4195 | * Flush the done work, just in case it's still pending, so that | |
4196 | * the work it does can complete and we can accept new frames. | |
4197 | */ | |
6ed13164 MG |
4198 | flush_work(&mvm->roc_done_wk); |
4199 | ||
a6cc5163 MG |
4200 | mutex_lock(&mvm->mutex); |
4201 | ||
b112889c AM |
4202 | switch (vif->type) { |
4203 | case NL80211_IFTYPE_STATION: | |
859d914c JB |
4204 | if (fw_has_capa(&mvm->fw->ucode_capa, |
4205 | IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) { | |
5ac6c72e | 4206 | /* Use aux roc framework (HS20) */ |
971cbe50 | 4207 | if (iwl_fw_lookup_cmd_ver(mvm->fw, ADD_STA, 0) >= 12) { |
2c2c3647 NE |
4208 | u32 lmac_id; |
4209 | ||
4210 | lmac_id = iwl_mvm_get_lmac_id(mvm->fw, | |
4211 | channel->band); | |
4212 | ret = iwl_mvm_add_aux_sta(mvm, lmac_id); | |
4213 | if (WARN(ret, | |
4214 | "Failed to allocate aux station")) | |
4215 | goto out_unlock; | |
4216 | } | |
5ac6c72e LC |
4217 | ret = iwl_mvm_send_aux_roc_cmd(mvm, channel, |
4218 | vif, duration); | |
4219 | goto out_unlock; | |
4220 | } | |
4221 | IWL_ERR(mvm, "hotspot not supported\n"); | |
4222 | ret = -EINVAL; | |
a6cc5163 | 4223 | goto out_unlock; |
b112889c AM |
4224 | case NL80211_IFTYPE_P2P_DEVICE: |
4225 | /* handle below */ | |
4226 | break; | |
4227 | default: | |
4228 | IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type); | |
a6cc5163 MG |
4229 | ret = -EINVAL; |
4230 | goto out_unlock; | |
8ca151b5 JB |
4231 | } |
4232 | ||
31d385ae IP |
4233 | for (i = 0; i < NUM_PHY_CTX; i++) { |
4234 | phy_ctxt = &mvm->phy_ctxts[i]; | |
4235 | if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt) | |
4236 | continue; | |
4237 | ||
4238 | if (phy_ctxt->ref && channel == phy_ctxt->channel) { | |
4239 | /* | |
4240 | * Unbind the P2P_DEVICE from the current PHY context, | |
4241 | * and if the PHY context is not used remove it. | |
4242 | */ | |
4243 | ret = iwl_mvm_binding_remove_vif(mvm, vif); | |
4244 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) | |
4245 | goto out_unlock; | |
4246 | ||
4247 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); | |
4248 | ||
4249 | /* Bind the P2P_DEVICE to the current PHY Context */ | |
4250 | mvmvif->phy_ctxt = phy_ctxt; | |
4251 | ||
4252 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
4253 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) | |
4254 | goto out_unlock; | |
4255 | ||
4256 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); | |
4257 | goto schedule_time_event; | |
4258 | } | |
4259 | } | |
4260 | ||
4261 | /* Need to update the PHY context only if the ROC channel changed */ | |
4262 | if (channel == mvmvif->phy_ctxt->channel) | |
4263 | goto schedule_time_event; | |
4264 | ||
8ca151b5 | 4265 | cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); |
8ca151b5 | 4266 | |
31d385ae | 4267 | /* |
8835a64f JB |
4268 | * Check if the remain-on-channel is on a different band and that |
4269 | * requires context removal, see iwl_mvm_phy_ctxt_changed(). If | |
4270 | * so, we'll need to release and then re-configure here, since we | |
4271 | * must not remove a PHY context that's part of a binding. | |
31d385ae | 4272 | */ |
8835a64f JB |
4273 | band_change_removal = |
4274 | fw_has_capa(&mvm->fw->ucode_capa, | |
4275 | IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT) && | |
4276 | mvmvif->phy_ctxt->channel->band != chandef.chan->band; | |
4277 | ||
4278 | if (mvmvif->phy_ctxt->ref == 1 && !band_change_removal) { | |
4279 | /* | |
4280 | * Change the PHY context configuration as it is currently | |
4281 | * referenced only by the P2P Device MAC (and we can modify it) | |
4282 | */ | |
31d385ae IP |
4283 | ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt, |
4284 | &chandef, 1, 1); | |
4285 | if (ret) | |
4286 | goto out_unlock; | |
4287 | } else { | |
4288 | /* | |
8835a64f JB |
4289 | * The PHY context is shared with other MACs (or we're trying to |
4290 | * switch bands), so remove the P2P Device from the binding, | |
4291 | * allocate an new PHY context and create a new binding. | |
31d385ae IP |
4292 | */ |
4293 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); | |
4294 | if (!phy_ctxt) { | |
4295 | ret = -ENOSPC; | |
4296 | goto out_unlock; | |
4297 | } | |
4298 | ||
4299 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef, | |
4300 | 1, 1); | |
4301 | if (ret) { | |
4302 | IWL_ERR(mvm, "Failed to change PHY context\n"); | |
4303 | goto out_unlock; | |
4304 | } | |
4305 | ||
4306 | /* Unbind the P2P_DEVICE from the current PHY context */ | |
4307 | ret = iwl_mvm_binding_remove_vif(mvm, vif); | |
4308 | if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) | |
4309 | goto out_unlock; | |
4310 | ||
4311 | iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); | |
4312 | ||
4313 | /* Bind the P2P_DEVICE to the new allocated PHY context */ | |
4314 | mvmvif->phy_ctxt = phy_ctxt; | |
4315 | ||
4316 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
4317 | if (WARN(ret, "Failed binding P2P_DEVICE\n")) | |
4318 | goto out_unlock; | |
4319 | ||
4320 | iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); | |
4321 | } | |
4322 | ||
4323 | schedule_time_event: | |
8ca151b5 | 4324 | /* Schedule the time events */ |
e635c797 | 4325 | ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); |
8ca151b5 | 4326 | |
31d385ae | 4327 | out_unlock: |
8ca151b5 JB |
4328 | mutex_unlock(&mvm->mutex); |
4329 | IWL_DEBUG_MAC80211(mvm, "leave\n"); | |
8ca151b5 JB |
4330 | return ret; |
4331 | } | |
4332 | ||
5db4c4b9 EG |
4333 | static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw, |
4334 | struct ieee80211_vif *vif) | |
8ca151b5 JB |
4335 | { |
4336 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4337 | ||
4338 | IWL_DEBUG_MAC80211(mvm, "enter\n"); | |
4339 | ||
4340 | mutex_lock(&mvm->mutex); | |
fe959c7b | 4341 | iwl_mvm_stop_roc(mvm, vif); |
8ca151b5 JB |
4342 | mutex_unlock(&mvm->mutex); |
4343 | ||
4344 | IWL_DEBUG_MAC80211(mvm, "leave\n"); | |
4345 | return 0; | |
4346 | } | |
4347 | ||
b73f9a4a JB |
4348 | struct iwl_mvm_ftm_responder_iter_data { |
4349 | bool responder; | |
4350 | struct ieee80211_chanctx_conf *ctx; | |
4351 | }; | |
4352 | ||
4353 | static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac, | |
4354 | struct ieee80211_vif *vif) | |
4355 | { | |
4356 | struct iwl_mvm_ftm_responder_iter_data *data = _data; | |
4357 | ||
d0a9123e | 4358 | if (rcu_access_pointer(vif->bss_conf.chanctx_conf) == data->ctx && |
b73f9a4a JB |
4359 | vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params) |
4360 | data->responder = true; | |
4361 | } | |
4362 | ||
4363 | static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm, | |
4364 | struct ieee80211_chanctx_conf *ctx) | |
4365 | { | |
4366 | struct iwl_mvm_ftm_responder_iter_data data = { | |
4367 | .responder = false, | |
4368 | .ctx = ctx, | |
4369 | }; | |
4370 | ||
4371 | ieee80211_iterate_active_interfaces_atomic(mvm->hw, | |
4372 | IEEE80211_IFACE_ITER_NORMAL, | |
4373 | iwl_mvm_ftm_responder_chanctx_iter, | |
4374 | &data); | |
4375 | return data.responder; | |
4376 | } | |
4377 | ||
b08c1d97 LC |
4378 | static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm, |
4379 | struct ieee80211_chanctx_conf *ctx) | |
8ca151b5 | 4380 | { |
fe0f2de3 IP |
4381 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
4382 | struct iwl_mvm_phy_ctxt *phy_ctxt; | |
b73f9a4a JB |
4383 | bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx); |
4384 | struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def; | |
8ca151b5 JB |
4385 | int ret; |
4386 | ||
b08c1d97 LC |
4387 | lockdep_assert_held(&mvm->mutex); |
4388 | ||
53a9d61e | 4389 | IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); |
fe0f2de3 | 4390 | |
fe0f2de3 IP |
4391 | phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); |
4392 | if (!phy_ctxt) { | |
4393 | ret = -ENOSPC; | |
4394 | goto out; | |
4395 | } | |
8ca151b5 | 4396 | |
b73f9a4a | 4397 | ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def, |
53a9d61e IP |
4398 | ctx->rx_chains_static, |
4399 | ctx->rx_chains_dynamic); | |
fe0f2de3 IP |
4400 | if (ret) { |
4401 | IWL_ERR(mvm, "Failed to add PHY context\n"); | |
4402 | goto out; | |
4403 | } | |
4404 | ||
53a9d61e | 4405 | iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt); |
fe0f2de3 IP |
4406 | *phy_ctxt_id = phy_ctxt->id; |
4407 | out: | |
b08c1d97 LC |
4408 | return ret; |
4409 | } | |
4410 | ||
4411 | static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, | |
4412 | struct ieee80211_chanctx_conf *ctx) | |
4413 | { | |
4414 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4415 | int ret; | |
4416 | ||
4417 | mutex_lock(&mvm->mutex); | |
4418 | ret = __iwl_mvm_add_chanctx(mvm, ctx); | |
8ca151b5 | 4419 | mutex_unlock(&mvm->mutex); |
b08c1d97 | 4420 | |
8ca151b5 JB |
4421 | return ret; |
4422 | } | |
4423 | ||
b08c1d97 LC |
4424 | static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm, |
4425 | struct ieee80211_chanctx_conf *ctx) | |
4426 | { | |
4427 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; | |
4428 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; | |
4429 | ||
4430 | lockdep_assert_held(&mvm->mutex); | |
4431 | ||
4432 | iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); | |
4433 | } | |
4434 | ||
8ca151b5 JB |
4435 | static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, |
4436 | struct ieee80211_chanctx_conf *ctx) | |
4437 | { | |
4438 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
8ca151b5 JB |
4439 | |
4440 | mutex_lock(&mvm->mutex); | |
b08c1d97 | 4441 | __iwl_mvm_remove_chanctx(mvm, ctx); |
8ca151b5 JB |
4442 | mutex_unlock(&mvm->mutex); |
4443 | } | |
4444 | ||
4445 | static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, | |
4446 | struct ieee80211_chanctx_conf *ctx, | |
4447 | u32 changed) | |
4448 | { | |
4449 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
fe0f2de3 IP |
4450 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
4451 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; | |
b73f9a4a JB |
4452 | bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx); |
4453 | struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def; | |
8ca151b5 | 4454 | |
31d385ae IP |
4455 | if (WARN_ONCE((phy_ctxt->ref > 1) && |
4456 | (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | | |
4457 | IEEE80211_CHANCTX_CHANGE_RX_CHAINS | | |
2dceedae AN |
4458 | IEEE80211_CHANCTX_CHANGE_RADAR | |
4459 | IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)), | |
31d385ae IP |
4460 | "Cannot change PHY. Ref=%d, changed=0x%X\n", |
4461 | phy_ctxt->ref, changed)) | |
4462 | return; | |
4463 | ||
8ca151b5 | 4464 | mutex_lock(&mvm->mutex); |
7a20bcce EG |
4465 | |
4466 | /* we are only changing the min_width, may be a noop */ | |
4467 | if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) { | |
b73f9a4a | 4468 | if (phy_ctxt->width == def->width) |
7a20bcce EG |
4469 | goto out_unlock; |
4470 | ||
4471 | /* we are just toggling between 20_NOHT and 20 */ | |
4472 | if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 && | |
b73f9a4a | 4473 | def->width <= NL80211_CHAN_WIDTH_20) |
7a20bcce EG |
4474 | goto out_unlock; |
4475 | } | |
4476 | ||
4d66449a | 4477 | iwl_mvm_bt_coex_vif_change(mvm); |
b73f9a4a | 4478 | iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def, |
8ca151b5 JB |
4479 | ctx->rx_chains_static, |
4480 | ctx->rx_chains_dynamic); | |
7a20bcce EG |
4481 | |
4482 | out_unlock: | |
8ca151b5 JB |
4483 | mutex_unlock(&mvm->mutex); |
4484 | } | |
4485 | ||
8a919a78 MK |
4486 | /* |
4487 | * This function executes the common part for MLD and non-MLD modes. | |
4488 | * | |
4489 | * Returns true if we're done assigning the chanctx | |
4490 | * (either on failure or success) | |
4491 | */ | |
50e81437 MK |
4492 | bool __iwl_mvm_assign_vif_chanctx_common(struct iwl_mvm *mvm, |
4493 | struct ieee80211_vif *vif, | |
4494 | struct ieee80211_chanctx_conf *ctx, | |
4495 | bool switching_chanctx, int *ret) | |
8ca151b5 | 4496 | { |
fe0f2de3 IP |
4497 | u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; |
4498 | struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; | |
8ca151b5 | 4499 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
8ca151b5 | 4500 | |
b08c1d97 | 4501 | lockdep_assert_held(&mvm->mutex); |
8ca151b5 | 4502 | |
fe0f2de3 | 4503 | mvmvif->phy_ctxt = phy_ctxt; |
8ca151b5 JB |
4504 | |
4505 | switch (vif->type) { | |
4506 | case NL80211_IFTYPE_AP: | |
4741dd04 LC |
4507 | /* only needed if we're switching chanctx (i.e. during CSA) */ |
4508 | if (switching_chanctx) { | |
bd3398e2 AO |
4509 | mvmvif->ap_ibss_active = true; |
4510 | break; | |
4511 | } | |
5a2abdca | 4512 | fallthrough; |
5023d966 | 4513 | case NL80211_IFTYPE_ADHOC: |
8ca151b5 JB |
4514 | /* |
4515 | * The AP binding flow is handled as part of the start_ap flow | |
5023d966 | 4516 | * (in bss_info_changed), similarly for IBSS. |
8ca151b5 | 4517 | */ |
8a919a78 MK |
4518 | *ret = 0; |
4519 | return true; | |
8ca151b5 | 4520 | case NL80211_IFTYPE_STATION: |
2533edce | 4521 | break; |
8ca151b5 | 4522 | case NL80211_IFTYPE_MONITOR: |
2533edce LC |
4523 | /* always disable PS when a monitor interface is active */ |
4524 | mvmvif->ps_disabled = true; | |
8ca151b5 JB |
4525 | break; |
4526 | default: | |
8a919a78 MK |
4527 | *ret = -EINVAL; |
4528 | return true; | |
8ca151b5 | 4529 | } |
8a919a78 MK |
4530 | return false; |
4531 | } | |
4532 | ||
4533 | static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm, | |
4534 | struct ieee80211_vif *vif, | |
4535 | struct ieee80211_chanctx_conf *ctx, | |
4536 | bool switching_chanctx) | |
4537 | { | |
4538 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
4539 | int ret; | |
4540 | ||
4541 | if (__iwl_mvm_assign_vif_chanctx_common(mvm, vif, ctx, | |
4542 | switching_chanctx, &ret)) | |
4543 | goto out; | |
8ca151b5 JB |
4544 | |
4545 | ret = iwl_mvm_binding_add_vif(mvm, vif); | |
4546 | if (ret) | |
b08c1d97 | 4547 | goto out; |
8ca151b5 JB |
4548 | |
4549 | /* | |
92d85562 AB |
4550 | * Power state must be updated before quotas, |
4551 | * otherwise fw will complain. | |
4552 | */ | |
999609f1 | 4553 | iwl_mvm_power_update_mac(mvm); |
92d85562 AB |
4554 | |
4555 | /* Setting the quota at this stage is only required for monitor | |
8ca151b5 JB |
4556 | * interfaces. For the other types, the bss_info changed flow |
4557 | * will handle quota settings. | |
4558 | */ | |
4559 | if (vif->type == NL80211_IFTYPE_MONITOR) { | |
1e1391ca | 4560 | mvmvif->monitor_active = true; |
7754ae79 | 4561 | ret = iwl_mvm_update_quotas(mvm, false, NULL); |
8ca151b5 JB |
4562 | if (ret) |
4563 | goto out_remove_binding; | |
0e39eb03 CRI |
4564 | |
4565 | ret = iwl_mvm_add_snif_sta(mvm, vif); | |
4566 | if (ret) | |
4567 | goto out_remove_binding; | |
4568 | ||
8ca151b5 JB |
4569 | } |
4570 | ||
bd3398e2 | 4571 | /* Handle binding during CSA */ |
a57c688d | 4572 | if (vif->type == NL80211_IFTYPE_AP) { |
7754ae79 | 4573 | iwl_mvm_update_quotas(mvm, false, NULL); |
3dfd3a97 | 4574 | iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); |
bd3398e2 AO |
4575 | } |
4576 | ||
8a919a78 MK |
4577 | if (vif->type == NL80211_IFTYPE_STATION) { |
4578 | if (!switching_chanctx) { | |
4579 | mvmvif->csa_bcn_pending = false; | |
4580 | goto out; | |
4581 | } | |
4582 | ||
74a10252 | 4583 | mvmvif->csa_bcn_pending = true; |
686e7fe1 | 4584 | |
74a10252 SS |
4585 | if (!fw_has_capa(&mvm->fw->ucode_capa, |
4586 | IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { | |
4587 | u32 duration = 3 * vif->bss_conf.beacon_int; | |
686e7fe1 | 4588 | |
74a10252 SS |
4589 | /* Protect the session to make sure we hear the first |
4590 | * beacon on the new channel. | |
4591 | */ | |
4592 | iwl_mvm_protect_session(mvm, vif, duration, duration, | |
4593 | vif->bss_conf.beacon_int / 2, | |
4594 | true); | |
74a10252 | 4595 | } |
686e7fe1 | 4596 | |
7754ae79 | 4597 | iwl_mvm_update_quotas(mvm, false, NULL); |
0ce04ce7 LC |
4598 | } |
4599 | ||
b08c1d97 | 4600 | goto out; |
8ca151b5 | 4601 | |
b08c1d97 | 4602 | out_remove_binding: |
8ca151b5 | 4603 | iwl_mvm_binding_remove_vif(mvm, vif); |
999609f1 | 4604 | iwl_mvm_power_update_mac(mvm); |
b08c1d97 | 4605 | out: |
8ca151b5 JB |
4606 | if (ret) |
4607 | mvmvif->phy_ctxt = NULL; | |
4608 | return ret; | |
4609 | } | |
8a919a78 | 4610 | |
b08c1d97 LC |
4611 | static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, |
4612 | struct ieee80211_vif *vif, | |
727eff4d | 4613 | struct ieee80211_bss_conf *link_conf, |
b08c1d97 | 4614 | struct ieee80211_chanctx_conf *ctx) |
8ca151b5 JB |
4615 | { |
4616 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
b08c1d97 | 4617 | int ret; |
8ca151b5 JB |
4618 | |
4619 | mutex_lock(&mvm->mutex); | |
f0c97783 | 4620 | ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false); |
b08c1d97 LC |
4621 | mutex_unlock(&mvm->mutex); |
4622 | ||
4623 | return ret; | |
4624 | } | |
4625 | ||
daddfae5 MK |
4626 | /* |
4627 | * This function executes the common part for MLD and non-MLD modes. | |
4628 | * | |
4629 | * Returns if chanctx unassign chanctx is done | |
4630 | * (either on failure or success) | |
4631 | */ | |
6f71e90e MK |
4632 | bool __iwl_mvm_unassign_vif_chanctx_common(struct iwl_mvm *mvm, |
4633 | struct ieee80211_vif *vif, | |
4634 | bool switching_chanctx) | |
b08c1d97 LC |
4635 | { |
4636 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
4637 | ||
4638 | lockdep_assert_held(&mvm->mutex); | |
8ca151b5 JB |
4639 | iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data); |
4640 | ||
8ca151b5 | 4641 | switch (vif->type) { |
5023d966 | 4642 | case NL80211_IFTYPE_ADHOC: |
daddfae5 | 4643 | return true; |
8ca151b5 | 4644 | case NL80211_IFTYPE_MONITOR: |
1e1391ca | 4645 | mvmvif->monitor_active = false; |
2533edce | 4646 | mvmvif->ps_disabled = false; |
8ca151b5 | 4647 | break; |
bd3398e2 AO |
4648 | case NL80211_IFTYPE_AP: |
4649 | /* This part is triggered only during CSA */ | |
4741dd04 | 4650 | if (!switching_chanctx || !mvmvif->ap_ibss_active) |
daddfae5 | 4651 | return true; |
bd3398e2 | 4652 | |
7ef0aab6 AO |
4653 | mvmvif->csa_countdown = false; |
4654 | ||
003e5236 AO |
4655 | /* Save blocked iface, the timeout is set on the next beacon */ |
4656 | rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif); | |
4657 | ||
bd3398e2 | 4658 | mvmvif->ap_ibss_active = false; |
f0c97783 | 4659 | break; |
daddfae5 MK |
4660 | default: |
4661 | break; | |
4662 | } | |
4663 | return false; | |
4664 | } | |
f0c97783 | 4665 | |
daddfae5 MK |
4666 | static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm, |
4667 | struct ieee80211_vif *vif, | |
4668 | struct ieee80211_chanctx_conf *ctx, | |
4669 | bool switching_chanctx) | |
4670 | { | |
4671 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
4672 | struct ieee80211_vif *disabled_vif = NULL; | |
4673 | ||
4674 | if (__iwl_mvm_unassign_vif_chanctx_common(mvm, vif, switching_chanctx)) | |
4675 | goto out; | |
f0c97783 | 4676 | |
daddfae5 MK |
4677 | if (vif->type == NL80211_IFTYPE_MONITOR) |
4678 | iwl_mvm_rm_snif_sta(mvm, vif); | |
4679 | ||
4680 | if (vif->type == NL80211_IFTYPE_AP) | |
4681 | /* Set CS bit on all the stations */ | |
4682 | iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true); | |
4683 | ||
4684 | if (vif->type == NL80211_IFTYPE_STATION && switching_chanctx) { | |
4685 | disabled_vif = vif; | |
74a10252 SS |
4686 | if (!fw_has_capa(&mvm->fw->ucode_capa, |
4687 | IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) | |
4688 | iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL); | |
8ca151b5 JB |
4689 | } |
4690 | ||
7754ae79 | 4691 | iwl_mvm_update_quotas(mvm, false, disabled_vif); |
1e1391ca | 4692 | iwl_mvm_binding_remove_vif(mvm, vif); |
1c2abf72 | 4693 | |
b08c1d97 | 4694 | out: |
bf544e9a SS |
4695 | if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD) && |
4696 | switching_chanctx) | |
4697 | return; | |
a11e144e | 4698 | mvmvif->phy_ctxt = NULL; |
999609f1 | 4699 | iwl_mvm_power_update_mac(mvm); |
b08c1d97 LC |
4700 | } |
4701 | ||
4702 | static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, | |
4703 | struct ieee80211_vif *vif, | |
727eff4d | 4704 | struct ieee80211_bss_conf *link_conf, |
b08c1d97 LC |
4705 | struct ieee80211_chanctx_conf *ctx) |
4706 | { | |
4707 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4708 | ||
4709 | mutex_lock(&mvm->mutex); | |
f0c97783 | 4710 | __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false); |
8ca151b5 JB |
4711 | mutex_unlock(&mvm->mutex); |
4712 | } | |
4713 | ||
50cc9574 LC |
4714 | static int |
4715 | iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm, | |
4716 | struct ieee80211_vif_chanctx_switch *vifs) | |
b08c1d97 | 4717 | { |
b08c1d97 LC |
4718 | int ret; |
4719 | ||
b08c1d97 | 4720 | mutex_lock(&mvm->mutex); |
f0c97783 | 4721 | __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); |
b08c1d97 LC |
4722 | __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx); |
4723 | ||
4724 | ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx); | |
4725 | if (ret) { | |
4726 | IWL_ERR(mvm, "failed to add new_ctx during channel switch\n"); | |
4727 | goto out_reassign; | |
4728 | } | |
4729 | ||
f0c97783 LC |
4730 | ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, |
4731 | true); | |
b08c1d97 LC |
4732 | if (ret) { |
4733 | IWL_ERR(mvm, | |
4734 | "failed to assign new_ctx during channel switch\n"); | |
4735 | goto out_remove; | |
4736 | } | |
4737 | ||
f697267f AN |
4738 | /* we don't support TDLS during DCM - can be caused by channel switch */ |
4739 | if (iwl_mvm_phy_ctx_count(mvm) > 1) | |
4740 | iwl_mvm_teardown_tdls_peers(mvm); | |
4741 | ||
b08c1d97 LC |
4742 | goto out; |
4743 | ||
4744 | out_remove: | |
4745 | __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx); | |
4746 | ||
4747 | out_reassign: | |
6fd1fb63 | 4748 | if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) { |
b08c1d97 LC |
4749 | IWL_ERR(mvm, "failed to add old_ctx back after failure.\n"); |
4750 | goto out_restart; | |
4751 | } | |
4752 | ||
6fd1fb63 LC |
4753 | if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, |
4754 | true)) { | |
b08c1d97 LC |
4755 | IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); |
4756 | goto out_restart; | |
4757 | } | |
4758 | ||
4759 | goto out; | |
4760 | ||
4761 | out_restart: | |
4762 | /* things keep failing, better restart the hw */ | |
4763 | iwl_mvm_nic_restart(mvm, false); | |
4764 | ||
4765 | out: | |
4766 | mutex_unlock(&mvm->mutex); | |
50cc9574 LC |
4767 | |
4768 | return ret; | |
4769 | } | |
4770 | ||
48a256e8 LC |
4771 | static int |
4772 | iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm, | |
4773 | struct ieee80211_vif_chanctx_switch *vifs) | |
4774 | { | |
4775 | int ret; | |
4776 | ||
4777 | mutex_lock(&mvm->mutex); | |
4778 | __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); | |
4779 | ||
4780 | ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, | |
4781 | true); | |
4782 | if (ret) { | |
4783 | IWL_ERR(mvm, | |
4784 | "failed to assign new_ctx during channel switch\n"); | |
4785 | goto out_reassign; | |
4786 | } | |
4787 | ||
4788 | goto out; | |
4789 | ||
4790 | out_reassign: | |
4791 | if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, | |
4792 | true)) { | |
4793 | IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); | |
4794 | goto out_restart; | |
4795 | } | |
4796 | ||
4797 | goto out; | |
4798 | ||
4799 | out_restart: | |
4800 | /* things keep failing, better restart the hw */ | |
4801 | iwl_mvm_nic_restart(mvm, false); | |
4802 | ||
4803 | out: | |
4804 | mutex_unlock(&mvm->mutex); | |
4805 | ||
4806 | return ret; | |
4807 | } | |
4808 | ||
50cc9574 LC |
4809 | static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw, |
4810 | struct ieee80211_vif_chanctx_switch *vifs, | |
4811 | int n_vifs, | |
4812 | enum ieee80211_chanctx_switch_mode mode) | |
4813 | { | |
4814 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4815 | int ret; | |
4816 | ||
4817 | /* we only support a single-vif right now */ | |
4818 | if (n_vifs > 1) | |
4819 | return -EOPNOTSUPP; | |
4820 | ||
4821 | switch (mode) { | |
4822 | case CHANCTX_SWMODE_SWAP_CONTEXTS: | |
4823 | ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs); | |
4824 | break; | |
4825 | case CHANCTX_SWMODE_REASSIGN_VIF: | |
48a256e8 | 4826 | ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs); |
50cc9574 LC |
4827 | break; |
4828 | default: | |
4829 | ret = -EOPNOTSUPP; | |
4830 | break; | |
4831 | } | |
4832 | ||
b08c1d97 LC |
4833 | return ret; |
4834 | } | |
4835 | ||
2f0282db JB |
4836 | static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw) |
4837 | { | |
4838 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4839 | ||
4840 | return mvm->ibss_manager; | |
4841 | } | |
4842 | ||
8ca151b5 JB |
4843 | static int iwl_mvm_set_tim(struct ieee80211_hw *hw, |
4844 | struct ieee80211_sta *sta, | |
4845 | bool set) | |
4846 | { | |
4847 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
9d8ce6af | 4848 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
4849 | |
4850 | if (!mvm_sta || !mvm_sta->vif) { | |
4851 | IWL_ERR(mvm, "Station is not associated to a vif\n"); | |
4852 | return -EINVAL; | |
4853 | } | |
4854 | ||
4855 | return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif); | |
4856 | } | |
4857 | ||
507cadf2 DS |
4858 | #ifdef CONFIG_NL80211_TESTMODE |
4859 | static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { | |
4860 | [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, | |
4861 | [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, | |
f6c6ad42 | 4862 | [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, |
507cadf2 DS |
4863 | }; |
4864 | ||
4865 | static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, | |
4866 | struct ieee80211_vif *vif, | |
4867 | void *data, int len) | |
4868 | { | |
4869 | struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; | |
4870 | int err; | |
4871 | u32 noa_duration; | |
4872 | ||
8cb08174 JB |
4873 | err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len, |
4874 | iwl_mvm_tm_policy, NULL); | |
507cadf2 DS |
4875 | if (err) |
4876 | return err; | |
4877 | ||
4878 | if (!tb[IWL_MVM_TM_ATTR_CMD]) | |
4879 | return -EINVAL; | |
4880 | ||
4881 | switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { | |
4882 | case IWL_MVM_TM_CMD_SET_NOA: | |
4883 | if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || | |
4884 | !vif->bss_conf.enable_beacon || | |
4885 | !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) | |
4886 | return -EINVAL; | |
4887 | ||
4888 | noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); | |
4889 | if (noa_duration >= vif->bss_conf.beacon_int) | |
4890 | return -EINVAL; | |
4891 | ||
4892 | mvm->noa_duration = noa_duration; | |
4893 | mvm->noa_vif = vif; | |
4894 | ||
22b21041 | 4895 | return iwl_mvm_update_quotas(mvm, true, NULL); |
f6c6ad42 JB |
4896 | case IWL_MVM_TM_CMD_SET_BEACON_FILTER: |
4897 | /* must be associated client vif - ignore authorized */ | |
4898 | if (!vif || vif->type != NL80211_IFTYPE_STATION || | |
f276e20b | 4899 | !vif->cfg.assoc || !vif->bss_conf.dtim_period || |
f6c6ad42 JB |
4900 | !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) |
4901 | return -EINVAL; | |
4902 | ||
4903 | if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) | |
a1022927 EG |
4904 | return iwl_mvm_enable_beacon_filter(mvm, vif, 0); |
4905 | return iwl_mvm_disable_beacon_filter(mvm, vif, 0); | |
507cadf2 DS |
4906 | } |
4907 | ||
4908 | return -EOPNOTSUPP; | |
4909 | } | |
4910 | ||
4911 | static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, | |
4912 | struct ieee80211_vif *vif, | |
4913 | void *data, int len) | |
4914 | { | |
4915 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
4916 | int err; | |
4917 | ||
4918 | mutex_lock(&mvm->mutex); | |
4919 | err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); | |
4920 | mutex_unlock(&mvm->mutex); | |
4921 | ||
4922 | return err; | |
4923 | } | |
4924 | #endif | |
4925 | ||
622e3f9b LC |
4926 | static void iwl_mvm_channel_switch(struct ieee80211_hw *hw, |
4927 | struct ieee80211_vif *vif, | |
4928 | struct ieee80211_channel_switch *chsw) | |
4929 | { | |
4930 | /* By implementing this operation, we prevent mac80211 from | |
4931 | * starting its own channel switch timer, so that we can call | |
4932 | * ieee80211_chswitch_done() ourselves at the right time | |
4933 | * (which is when the absence time event starts). | |
4934 | */ | |
4935 | ||
4936 | IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw), | |
4937 | "dummy channel switch op\n"); | |
4938 | } | |
4939 | ||
74a10252 SS |
4940 | static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm, |
4941 | struct ieee80211_vif *vif, | |
4942 | struct ieee80211_channel_switch *chsw) | |
4943 | { | |
4944 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
4945 | struct iwl_chan_switch_te_cmd cmd = { | |
4946 | .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, | |
4947 | mvmvif->color)), | |
4948 | .action = cpu_to_le32(FW_CTXT_ACTION_ADD), | |
4949 | .tsf = cpu_to_le32(chsw->timestamp), | |
4950 | .cs_count = chsw->count, | |
77738865 | 4951 | .cs_mode = chsw->block_tx, |
74a10252 SS |
4952 | }; |
4953 | ||
4954 | lockdep_assert_held(&mvm->mutex); | |
4955 | ||
9cfcf71c SS |
4956 | if (chsw->delay) |
4957 | cmd.cs_delayed_bcn_count = | |
4958 | DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int); | |
4959 | ||
74a10252 SS |
4960 | return iwl_mvm_send_cmd_pdu(mvm, |
4961 | WIDE_ID(MAC_CONF_GROUP, | |
4962 | CHANNEL_SWITCH_TIME_EVENT_CMD), | |
4963 | 0, sizeof(cmd), &cmd); | |
4964 | } | |
4965 | ||
0202bcf0 EG |
4966 | static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm, |
4967 | struct ieee80211_vif *vif, | |
4968 | struct ieee80211_channel_switch *chsw) | |
4969 | { | |
4970 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
4971 | u32 apply_time; | |
4972 | ||
4973 | /* Schedule the time event to a bit before beacon 1, | |
4974 | * to make sure we're in the new channel when the | |
4975 | * GO/AP arrives. In case count <= 1 immediately schedule the | |
4976 | * TE (this might result with some packet loss or connection | |
4977 | * loss). | |
4978 | */ | |
4979 | if (chsw->count <= 1) | |
4980 | apply_time = 0; | |
4981 | else | |
4982 | apply_time = chsw->device_timestamp + | |
4983 | ((vif->bss_conf.beacon_int * (chsw->count - 1) - | |
4984 | IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024); | |
4985 | ||
4986 | if (chsw->block_tx) | |
4987 | iwl_mvm_csa_client_absent(mvm, vif); | |
4988 | ||
4989 | if (mvmvif->bf_data.bf_enabled) { | |
4990 | int ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); | |
4991 | ||
4992 | if (ret) | |
4993 | return ret; | |
4994 | } | |
4995 | ||
4996 | iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int, | |
4997 | apply_time); | |
4998 | ||
4999 | return 0; | |
5000 | } | |
5001 | ||
f6780614 | 5002 | #define IWL_MAX_CSA_BLOCK_TX 1500 |
f028905c LC |
5003 | static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw, |
5004 | struct ieee80211_vif *vif, | |
5005 | struct ieee80211_channel_switch *chsw) | |
bd3398e2 AO |
5006 | { |
5007 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
664322fa | 5008 | struct ieee80211_vif *csa_vif; |
f6c34820 | 5009 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
f028905c | 5010 | int ret; |
bd3398e2 AO |
5011 | |
5012 | mutex_lock(&mvm->mutex); | |
664322fa | 5013 | |
81d62d5a JB |
5014 | mvmvif->csa_failed = false; |
5015 | ||
6b20d774 | 5016 | IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n", |
f028905c | 5017 | chsw->chandef.center_freq1); |
6b20d774 | 5018 | |
7174beb6 JB |
5019 | iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt, |
5020 | ieee80211_vif_to_wdev(vif), | |
5021 | FW_DBG_TRIGGER_CHANNEL_SWITCH); | |
f35d9c55 | 5022 | |
6b20d774 LC |
5023 | switch (vif->type) { |
5024 | case NL80211_IFTYPE_AP: | |
5025 | csa_vif = | |
5026 | rcu_dereference_protected(mvm->csa_vif, | |
5027 | lockdep_is_held(&mvm->mutex)); | |
d0a9123e | 5028 | if (WARN_ONCE(csa_vif && csa_vif->bss_conf.csa_active, |
6b20d774 LC |
5029 | "Another CSA is already in progress")) { |
5030 | ret = -EBUSY; | |
5031 | goto out_unlock; | |
5032 | } | |
5033 | ||
d3a108a4 AO |
5034 | /* we still didn't unblock tx. prevent new CS meanwhile */ |
5035 | if (rcu_dereference_protected(mvm->csa_tx_blocked_vif, | |
5036 | lockdep_is_held(&mvm->mutex))) { | |
5037 | ret = -EBUSY; | |
5038 | goto out_unlock; | |
5039 | } | |
5040 | ||
6b20d774 | 5041 | rcu_assign_pointer(mvm->csa_vif, vif); |
7ef0aab6 | 5042 | |
7ef0aab6 AO |
5043 | if (WARN_ONCE(mvmvif->csa_countdown, |
5044 | "Previous CSA countdown didn't complete")) { | |
5045 | ret = -EBUSY; | |
5046 | goto out_unlock; | |
5047 | } | |
5048 | ||
d3a108a4 AO |
5049 | mvmvif->csa_target_freq = chsw->chandef.chan->center_freq; |
5050 | ||
6b20d774 | 5051 | break; |
dc88b4ba | 5052 | case NL80211_IFTYPE_STATION: |
ad12b231 NE |
5053 | /* |
5054 | * In the new flow FW is in charge of timing the switch so there | |
5055 | * is no need for all of this | |
5056 | */ | |
5057 | if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, | |
5058 | CHANNEL_SWITCH_ERROR_NOTIF, | |
5059 | 0)) | |
5060 | break; | |
5061 | ||
2360acbd EG |
5062 | /* |
5063 | * We haven't configured the firmware to be associated yet since | |
5064 | * we don't know the dtim period. In this case, the firmware can't | |
5065 | * track the beacons. | |
5066 | */ | |
f276e20b | 5067 | if (!vif->cfg.assoc || !vif->bss_conf.dtim_period) { |
2360acbd EG |
5068 | ret = -EBUSY; |
5069 | goto out_unlock; | |
5070 | } | |
5071 | ||
87d9564e JB |
5072 | if (chsw->delay > IWL_MAX_CSA_BLOCK_TX) |
5073 | schedule_delayed_work(&mvmvif->csa_work, 0); | |
5074 | ||
f6780614 | 5075 | if (chsw->block_tx) { |
f6780614 SS |
5076 | /* |
5077 | * In case of undetermined / long time with immediate | |
5078 | * quiet monitor status to gracefully disconnect | |
5079 | */ | |
5080 | if (!chsw->count || | |
5081 | chsw->count * vif->bss_conf.beacon_int > | |
5082 | IWL_MAX_CSA_BLOCK_TX) | |
5083 | schedule_delayed_work(&mvmvif->csa_work, | |
5084 | msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX)); | |
5085 | } | |
dc88b4ba | 5086 | |
0202bcf0 EG |
5087 | if (!fw_has_capa(&mvm->fw->ucode_capa, |
5088 | IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { | |
5089 | ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw); | |
c6e0a3e0 LC |
5090 | if (ret) |
5091 | goto out_unlock; | |
0202bcf0 | 5092 | } else { |
74a10252 | 5093 | iwl_mvm_schedule_client_csa(mvm, vif, chsw); |
0202bcf0 | 5094 | } |
81b4e44e SS |
5095 | |
5096 | mvmvif->csa_count = chsw->count; | |
5097 | mvmvif->csa_misbehave = false; | |
dc88b4ba | 5098 | break; |
6b20d774 LC |
5099 | default: |
5100 | break; | |
5101 | } | |
bd3398e2 | 5102 | |
f6c34820 LC |
5103 | mvmvif->ps_disabled = true; |
5104 | ||
5105 | ret = iwl_mvm_power_update_ps(mvm); | |
5106 | if (ret) | |
5107 | goto out_unlock; | |
f028905c | 5108 | |
e198f5e7 AN |
5109 | /* we won't be on this channel any longer */ |
5110 | iwl_mvm_teardown_tdls_peers(mvm); | |
5111 | ||
bd3398e2 AO |
5112 | out_unlock: |
5113 | mutex_unlock(&mvm->mutex); | |
f028905c LC |
5114 | |
5115 | return ret; | |
bd3398e2 AO |
5116 | } |
5117 | ||
c37763d2 SS |
5118 | static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw, |
5119 | struct ieee80211_vif *vif, | |
5120 | struct ieee80211_channel_switch *chsw) | |
f6c34820 | 5121 | { |
f6c34820 | 5122 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
c37763d2 SS |
5123 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
5124 | struct iwl_chan_switch_te_cmd cmd = { | |
5125 | .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, | |
5126 | mvmvif->color)), | |
5127 | .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY), | |
5128 | .tsf = cpu_to_le32(chsw->timestamp), | |
5129 | .cs_count = chsw->count, | |
77738865 | 5130 | .cs_mode = chsw->block_tx, |
c37763d2 | 5131 | }; |
a57c688d | 5132 | |
ad12b231 NE |
5133 | /* |
5134 | * In the new flow FW is in charge of timing the switch so there is no | |
5135 | * need for all of this | |
5136 | */ | |
5137 | if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, | |
5138 | CHANNEL_SWITCH_ERROR_NOTIF, 0)) | |
5139 | return; | |
5140 | ||
c37763d2 SS |
5141 | if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY)) |
5142 | return; | |
a57c688d | 5143 | |
c3eae059 GG |
5144 | IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d count = %d (old %d) mode = %d\n", |
5145 | mvmvif->id, chsw->count, mvmvif->csa_count, chsw->block_tx); | |
5146 | ||
81b4e44e SS |
5147 | if (chsw->count >= mvmvif->csa_count && chsw->block_tx) { |
5148 | if (mvmvif->csa_misbehave) { | |
5149 | /* Second time, give up on this AP*/ | |
5150 | iwl_mvm_abort_channel_switch(hw, vif); | |
5151 | ieee80211_chswitch_done(vif, false); | |
5152 | mvmvif->csa_misbehave = false; | |
5153 | return; | |
a57c688d | 5154 | } |
81b4e44e | 5155 | mvmvif->csa_misbehave = true; |
a57c688d | 5156 | } |
81b4e44e | 5157 | mvmvif->csa_count = chsw->count; |
a57c688d | 5158 | |
caf46377 SS |
5159 | mutex_lock(&mvm->mutex); |
5160 | if (mvmvif->csa_failed) | |
5161 | goto out_unlock; | |
f6c34820 | 5162 | |
c37763d2 SS |
5163 | WARN_ON(iwl_mvm_send_cmd_pdu(mvm, |
5164 | WIDE_ID(MAC_CONF_GROUP, | |
5165 | CHANNEL_SWITCH_TIME_EVENT_CMD), | |
caf46377 SS |
5166 | 0, sizeof(cmd), &cmd)); |
5167 | out_unlock: | |
5168 | mutex_unlock(&mvm->mutex); | |
f6c34820 LC |
5169 | } |
5170 | ||
6110d9e5 DS |
5171 | static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop) |
5172 | { | |
435d0827 SS |
5173 | int i; |
5174 | ||
06195639 | 5175 | if (!iwl_mvm_has_new_tx_api(mvm)) { |
309c4848 LC |
5176 | if (drop) { |
5177 | mutex_lock(&mvm->mutex); | |
6110d9e5 | 5178 | iwl_mvm_flush_tx_path(mvm, |
d4e3a341 | 5179 | iwl_mvm_flushable_queues(mvm) & queues); |
309c4848 LC |
5180 | mutex_unlock(&mvm->mutex); |
5181 | } else { | |
06195639 | 5182 | iwl_trans_wait_tx_queues_empty(mvm->trans, queues); |
309c4848 | 5183 | } |
435d0827 SS |
5184 | return; |
5185 | } | |
6110d9e5 | 5186 | |
435d0827 | 5187 | mutex_lock(&mvm->mutex); |
be9ae34e | 5188 | for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { |
435d0827 | 5189 | struct ieee80211_sta *sta; |
6110d9e5 | 5190 | |
435d0827 SS |
5191 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
5192 | lockdep_is_held(&mvm->mutex)); | |
5193 | if (IS_ERR_OR_NULL(sta)) | |
5194 | continue; | |
6110d9e5 | 5195 | |
06195639 | 5196 | if (drop) |
d4e3a341 | 5197 | iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF); |
06195639 SS |
5198 | else |
5199 | iwl_mvm_wait_sta_queues_empty(mvm, | |
5200 | iwl_mvm_sta_from_mac80211(sta)); | |
6110d9e5 | 5201 | } |
435d0827 | 5202 | mutex_unlock(&mvm->mutex); |
6110d9e5 DS |
5203 | } |
5204 | ||
c5b0e7c0 EG |
5205 | static void iwl_mvm_mac_flush(struct ieee80211_hw *hw, |
5206 | struct ieee80211_vif *vif, u32 queues, bool drop) | |
5207 | { | |
5208 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5209 | struct iwl_mvm_vif *mvmvif; | |
5210 | struct iwl_mvm_sta *mvmsta; | |
a0f6bf2a AN |
5211 | struct ieee80211_sta *sta; |
5212 | int i; | |
5213 | u32 msk = 0; | |
c5b0e7c0 | 5214 | |
6110d9e5 DS |
5215 | if (!vif) { |
5216 | iwl_mvm_flush_no_vif(mvm, queues, drop); | |
5217 | return; | |
5218 | } | |
5219 | ||
5220 | if (vif->type != NL80211_IFTYPE_STATION) | |
c5b0e7c0 EG |
5221 | return; |
5222 | ||
24afba76 | 5223 | /* Make sure we're done with the deferred traffic before flushing */ |
c8f54701 | 5224 | flush_work(&mvm->add_stream_wk); |
24afba76 | 5225 | |
c5b0e7c0 EG |
5226 | mutex_lock(&mvm->mutex); |
5227 | mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
c5b0e7c0 | 5228 | |
a0f6bf2a | 5229 | /* flush the AP-station and all TDLS peers */ |
be9ae34e | 5230 | for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { |
a0f6bf2a AN |
5231 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
5232 | lockdep_is_held(&mvm->mutex)); | |
5233 | if (IS_ERR_OR_NULL(sta)) | |
5234 | continue; | |
5235 | ||
5236 | mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
5237 | if (mvmsta->vif != vif) | |
5238 | continue; | |
5239 | ||
5240 | /* make sure only TDLS peers or the AP are flushed */ | |
5241 | WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls); | |
5242 | ||
d49394a1 | 5243 | if (drop) { |
f9084775 | 5244 | if (iwl_mvm_flush_sta(mvm, mvmsta, false)) |
d49394a1 SS |
5245 | IWL_ERR(mvm, "flush request fail\n"); |
5246 | } else { | |
d6d517b7 SS |
5247 | if (iwl_mvm_has_new_tx_api(mvm)) |
5248 | iwl_mvm_wait_sta_queues_empty(mvm, mvmsta); | |
f7bd883b JB |
5249 | else /* only used for !iwl_mvm_has_new_tx_api() below */ |
5250 | msk |= mvmsta->tfd_queue_msk; | |
d49394a1 | 5251 | } |
480acbce | 5252 | } |
c5b0e7c0 | 5253 | |
d49394a1 | 5254 | mutex_unlock(&mvm->mutex); |
4e6c48e0 | 5255 | |
d49394a1 SS |
5256 | /* this can take a while, and we may need/want other operations |
5257 | * to succeed while doing this, so do it without the mutex held | |
5258 | */ | |
d6d517b7 | 5259 | if (!drop && !iwl_mvm_has_new_tx_api(mvm)) |
a1a57877 | 5260 | iwl_trans_wait_tx_queues_empty(mvm->trans, msk); |
c5b0e7c0 EG |
5261 | } |
5262 | ||
91a8bcde JB |
5263 | static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx, |
5264 | struct survey_info *survey) | |
5265 | { | |
5266 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5267 | int ret; | |
5268 | ||
5269 | memset(survey, 0, sizeof(*survey)); | |
5270 | ||
5271 | /* only support global statistics right now */ | |
5272 | if (idx != 0) | |
5273 | return -ENOENT; | |
5274 | ||
280a3efa JB |
5275 | if (!fw_has_capa(&mvm->fw->ucode_capa, |
5276 | IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) | |
91a8bcde JB |
5277 | return -ENOENT; |
5278 | ||
5279 | mutex_lock(&mvm->mutex); | |
5280 | ||
aab6930d | 5281 | if (iwl_mvm_firmware_running(mvm)) { |
33cef925 | 5282 | ret = iwl_mvm_request_statistics(mvm, false); |
91a8bcde JB |
5283 | if (ret) |
5284 | goto out; | |
5285 | } | |
5286 | ||
5287 | survey->filled = SURVEY_INFO_TIME | | |
5288 | SURVEY_INFO_TIME_RX | | |
5289 | SURVEY_INFO_TIME_TX | | |
5290 | SURVEY_INFO_TIME_SCAN; | |
5291 | survey->time = mvm->accu_radio_stats.on_time_rf + | |
5292 | mvm->radio_stats.on_time_rf; | |
5293 | do_div(survey->time, USEC_PER_MSEC); | |
5294 | ||
5295 | survey->time_rx = mvm->accu_radio_stats.rx_time + | |
5296 | mvm->radio_stats.rx_time; | |
5297 | do_div(survey->time_rx, USEC_PER_MSEC); | |
5298 | ||
5299 | survey->time_tx = mvm->accu_radio_stats.tx_time + | |
5300 | mvm->radio_stats.tx_time; | |
5301 | do_div(survey->time_tx, USEC_PER_MSEC); | |
5302 | ||
5303 | survey->time_scan = mvm->accu_radio_stats.on_time_scan + | |
5304 | mvm->radio_stats.on_time_scan; | |
5305 | do_div(survey->time_scan, USEC_PER_MSEC); | |
5306 | ||
10a7c028 | 5307 | ret = 0; |
91a8bcde JB |
5308 | out: |
5309 | mutex_unlock(&mvm->mutex); | |
5310 | return ret; | |
5311 | } | |
5312 | ||
ed780545 JB |
5313 | static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo) |
5314 | { | |
82cdbd11 | 5315 | u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK; |
7138763e | 5316 | u32 gi_ltf; |
82cdbd11 MK |
5317 | |
5318 | switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { | |
ed780545 JB |
5319 | case RATE_MCS_CHAN_WIDTH_20: |
5320 | rinfo->bw = RATE_INFO_BW_20; | |
5321 | break; | |
5322 | case RATE_MCS_CHAN_WIDTH_40: | |
5323 | rinfo->bw = RATE_INFO_BW_40; | |
5324 | break; | |
5325 | case RATE_MCS_CHAN_WIDTH_80: | |
5326 | rinfo->bw = RATE_INFO_BW_80; | |
5327 | break; | |
5328 | case RATE_MCS_CHAN_WIDTH_160: | |
5329 | rinfo->bw = RATE_INFO_BW_160; | |
5330 | break; | |
23dcee94 JB |
5331 | case RATE_MCS_CHAN_WIDTH_320: |
5332 | rinfo->bw = RATE_INFO_BW_320; | |
5333 | break; | |
ed780545 JB |
5334 | } |
5335 | ||
82cdbd11 MK |
5336 | if (format == RATE_MCS_CCK_MSK || |
5337 | format == RATE_MCS_LEGACY_OFDM_MSK) { | |
5338 | int rate = u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK); | |
5339 | ||
5340 | /* add the offset needed to get to the legacy ofdm indices */ | |
5341 | if (format == RATE_MCS_LEGACY_OFDM_MSK) | |
5342 | rate += IWL_FIRST_OFDM_RATE; | |
5343 | ||
5344 | switch (rate) { | |
5345 | case IWL_RATE_1M_INDEX: | |
5346 | rinfo->legacy = 10; | |
5347 | break; | |
5348 | case IWL_RATE_2M_INDEX: | |
5349 | rinfo->legacy = 20; | |
5350 | break; | |
5351 | case IWL_RATE_5M_INDEX: | |
5352 | rinfo->legacy = 55; | |
5353 | break; | |
5354 | case IWL_RATE_11M_INDEX: | |
5355 | rinfo->legacy = 110; | |
5356 | break; | |
5357 | case IWL_RATE_6M_INDEX: | |
5358 | rinfo->legacy = 60; | |
5359 | break; | |
5360 | case IWL_RATE_9M_INDEX: | |
5361 | rinfo->legacy = 90; | |
5362 | break; | |
5363 | case IWL_RATE_12M_INDEX: | |
5364 | rinfo->legacy = 120; | |
5365 | break; | |
5366 | case IWL_RATE_18M_INDEX: | |
5367 | rinfo->legacy = 180; | |
5368 | break; | |
5369 | case IWL_RATE_24M_INDEX: | |
5370 | rinfo->legacy = 240; | |
5371 | break; | |
5372 | case IWL_RATE_36M_INDEX: | |
5373 | rinfo->legacy = 360; | |
5374 | break; | |
5375 | case IWL_RATE_48M_INDEX: | |
5376 | rinfo->legacy = 480; | |
5377 | break; | |
5378 | case IWL_RATE_54M_INDEX: | |
5379 | rinfo->legacy = 540; | |
5380 | } | |
5381 | return; | |
5382 | } | |
5383 | ||
5384 | rinfo->nss = u32_get_bits(rate_n_flags, | |
5385 | RATE_MCS_NSS_MSK) + 1; | |
5386 | rinfo->mcs = format == RATE_MCS_HT_MSK ? | |
5387 | RATE_HT_MCS_INDEX(rate_n_flags) : | |
5388 | u32_get_bits(rate_n_flags, RATE_MCS_CODE_MSK); | |
5389 | ||
7138763e JB |
5390 | if (rate_n_flags & RATE_MCS_SGI_MSK) |
5391 | rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI; | |
5392 | ||
5393 | switch (format) { | |
23dcee94 JB |
5394 | case RATE_MCS_EHT_MSK: |
5395 | /* TODO: GI/LTF/RU. How does the firmware encode them? */ | |
5396 | rinfo->flags |= RATE_INFO_FLAGS_EHT_MCS; | |
5397 | break; | |
7138763e JB |
5398 | case RATE_MCS_HE_MSK: |
5399 | gi_ltf = u32_get_bits(rate_n_flags, RATE_MCS_HE_GI_LTF_MSK); | |
ed780545 JB |
5400 | |
5401 | rinfo->flags |= RATE_INFO_FLAGS_HE_MCS; | |
ed780545 | 5402 | |
82cdbd11 | 5403 | if (rate_n_flags & RATE_MCS_HE_106T_MSK) { |
ed780545 JB |
5404 | rinfo->bw = RATE_INFO_BW_HE_RU; |
5405 | rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106; | |
5406 | } | |
5407 | ||
82cdbd11 MK |
5408 | switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) { |
5409 | case RATE_MCS_HE_TYPE_SU: | |
5410 | case RATE_MCS_HE_TYPE_EXT_SU: | |
ed780545 JB |
5411 | if (gi_ltf == 0 || gi_ltf == 1) |
5412 | rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; | |
5413 | else if (gi_ltf == 2) | |
5414 | rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; | |
82cdbd11 | 5415 | else if (gi_ltf == 3) |
ed780545 | 5416 | rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; |
82cdbd11 MK |
5417 | else |
5418 | rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; | |
ed780545 | 5419 | break; |
82cdbd11 | 5420 | case RATE_MCS_HE_TYPE_MU: |
ed780545 JB |
5421 | if (gi_ltf == 0 || gi_ltf == 1) |
5422 | rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; | |
5423 | else if (gi_ltf == 2) | |
5424 | rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; | |
5425 | else | |
5426 | rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; | |
5427 | break; | |
82cdbd11 | 5428 | case RATE_MCS_HE_TYPE_TRIG: |
ed780545 JB |
5429 | if (gi_ltf == 0 || gi_ltf == 1) |
5430 | rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; | |
5431 | else | |
5432 | rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; | |
5433 | break; | |
5434 | } | |
5435 | ||
5436 | if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK) | |
5437 | rinfo->he_dcm = 1; | |
7138763e JB |
5438 | break; |
5439 | case RATE_MCS_HT_MSK: | |
82cdbd11 | 5440 | rinfo->flags |= RATE_INFO_FLAGS_MCS; |
7138763e JB |
5441 | break; |
5442 | case RATE_MCS_VHT_MSK: | |
82cdbd11 | 5443 | rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS; |
7138763e | 5444 | break; |
ed780545 JB |
5445 | } |
5446 | } | |
5447 | ||
33cef925 JB |
5448 | static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw, |
5449 | struct ieee80211_vif *vif, | |
5450 | struct ieee80211_sta *sta, | |
5451 | struct station_info *sinfo) | |
5452 | { | |
5453 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5454 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
5455 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
5456 | ||
988b5968 | 5457 | if (mvmsta->avg_energy) { |
88ad368a | 5458 | sinfo->signal_avg = -(s8)mvmsta->avg_energy; |
22d0d2fa | 5459 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG); |
988b5968 SS |
5460 | } |
5461 | ||
ed780545 JB |
5462 | if (iwl_mvm_has_tlc_offload(mvm)) { |
5463 | struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw; | |
5464 | ||
5465 | iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate); | |
5466 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); | |
5467 | } | |
5468 | ||
33cef925 JB |
5469 | /* if beacon filtering isn't on mac80211 does it anyway */ |
5470 | if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)) | |
5471 | return; | |
5472 | ||
f276e20b | 5473 | if (!vif->cfg.assoc) |
33cef925 JB |
5474 | return; |
5475 | ||
5476 | mutex_lock(&mvm->mutex); | |
5477 | ||
5478 | if (mvmvif->ap_sta_id != mvmsta->sta_id) | |
5479 | goto unlock; | |
5480 | ||
5481 | if (iwl_mvm_request_statistics(mvm, false)) | |
5482 | goto unlock; | |
5483 | ||
5484 | sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons + | |
5485 | mvmvif->beacon_stats.accu_num_beacons; | |
22d0d2fa | 5486 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX); |
33cef925 JB |
5487 | if (mvmvif->beacon_stats.avg_signal) { |
5488 | /* firmware only reports a value after RXing a few beacons */ | |
5489 | sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal; | |
22d0d2fa | 5490 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG); |
33cef925 JB |
5491 | } |
5492 | unlock: | |
5493 | mutex_unlock(&mvm->mutex); | |
5494 | } | |
5495 | ||
119c2a13 MG |
5496 | static void iwl_mvm_event_mlme_callback_ini(struct iwl_mvm *mvm, |
5497 | struct ieee80211_vif *vif, | |
5498 | const struct ieee80211_mlme_event *mlme) | |
5499 | { | |
1a81bddf MG |
5500 | if ((mlme->data == ASSOC_EVENT || mlme->data == AUTH_EVENT) && |
5501 | (mlme->status == MLME_DENIED || mlme->status == MLME_TIMEOUT)) { | |
119c2a13 MG |
5502 | iwl_dbg_tlv_time_point(&mvm->fwrt, |
5503 | IWL_FW_INI_TIME_POINT_ASSOC_FAILED, | |
5504 | NULL); | |
5505 | return; | |
5506 | } | |
5507 | ||
119c2a13 MG |
5508 | if (mlme->data == DEAUTH_RX_EVENT || mlme->data == DEAUTH_TX_EVENT) { |
5509 | iwl_dbg_tlv_time_point(&mvm->fwrt, | |
5510 | IWL_FW_INI_TIME_POINT_DEASSOC, | |
5511 | NULL); | |
5512 | return; | |
5513 | } | |
5514 | } | |
5515 | ||
4203263d EG |
5516 | static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm, |
5517 | struct ieee80211_vif *vif, | |
5518 | const struct ieee80211_event *event) | |
d42f5350 | 5519 | { |
7174beb6 JB |
5520 | #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \ |
5521 | do { \ | |
5522 | if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \ | |
5523 | break; \ | |
5524 | iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \ | |
d42f5350 EG |
5525 | } while (0) |
5526 | ||
d42f5350 EG |
5527 | struct iwl_fw_dbg_trigger_tlv *trig; |
5528 | struct iwl_fw_dbg_trigger_mlme *trig_mlme; | |
d42f5350 | 5529 | |
119c2a13 MG |
5530 | if (iwl_trans_dbg_ini_valid(mvm->trans)) { |
5531 | iwl_mvm_event_mlme_callback_ini(mvm, vif, &event->u.mlme); | |
5532 | return; | |
5533 | } | |
5534 | ||
6c042d75 SS |
5535 | trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), |
5536 | FW_DBG_TRIGGER_MLME); | |
5537 | if (!trig) | |
d42f5350 EG |
5538 | return; |
5539 | ||
d42f5350 | 5540 | trig_mlme = (void *)trig->data; |
d42f5350 | 5541 | |
d42f5350 EG |
5542 | if (event->u.mlme.data == ASSOC_EVENT) { |
5543 | if (event->u.mlme.status == MLME_DENIED) | |
4c324a51 | 5544 | CHECK_MLME_TRIGGER(stop_assoc_denied, |
d42f5350 EG |
5545 | "DENIED ASSOC: reason %d", |
5546 | event->u.mlme.reason); | |
5547 | else if (event->u.mlme.status == MLME_TIMEOUT) | |
4c324a51 | 5548 | CHECK_MLME_TRIGGER(stop_assoc_timeout, |
d42f5350 EG |
5549 | "ASSOC TIMEOUT"); |
5550 | } else if (event->u.mlme.data == AUTH_EVENT) { | |
5551 | if (event->u.mlme.status == MLME_DENIED) | |
4c324a51 | 5552 | CHECK_MLME_TRIGGER(stop_auth_denied, |
d42f5350 EG |
5553 | "DENIED AUTH: reason %d", |
5554 | event->u.mlme.reason); | |
5555 | else if (event->u.mlme.status == MLME_TIMEOUT) | |
4c324a51 | 5556 | CHECK_MLME_TRIGGER(stop_auth_timeout, |
d42f5350 EG |
5557 | "AUTH TIMEOUT"); |
5558 | } else if (event->u.mlme.data == DEAUTH_RX_EVENT) { | |
4c324a51 | 5559 | CHECK_MLME_TRIGGER(stop_rx_deauth, |
d42f5350 EG |
5560 | "DEAUTH RX %d", event->u.mlme.reason); |
5561 | } else if (event->u.mlme.data == DEAUTH_TX_EVENT) { | |
4c324a51 | 5562 | CHECK_MLME_TRIGGER(stop_tx_deauth, |
d42f5350 EG |
5563 | "DEAUTH TX %d", event->u.mlme.reason); |
5564 | } | |
5565 | #undef CHECK_MLME_TRIGGER | |
5566 | } | |
5567 | ||
4203263d EG |
5568 | static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm, |
5569 | struct ieee80211_vif *vif, | |
5570 | const struct ieee80211_event *event) | |
5571 | { | |
5572 | struct iwl_fw_dbg_trigger_tlv *trig; | |
5573 | struct iwl_fw_dbg_trigger_ba *ba_trig; | |
5574 | ||
6c042d75 SS |
5575 | trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), |
5576 | FW_DBG_TRIGGER_BA); | |
5577 | if (!trig) | |
4203263d EG |
5578 | return; |
5579 | ||
4203263d | 5580 | ba_trig = (void *)trig->data; |
4203263d EG |
5581 | |
5582 | if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid))) | |
5583 | return; | |
5584 | ||
7174beb6 JB |
5585 | iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, |
5586 | "BAR received from %pM, tid %d, ssn %d", | |
5587 | event->u.ba.sta->addr, event->u.ba.tid, | |
5588 | event->u.ba.ssn); | |
4203263d EG |
5589 | } |
5590 | ||
4203263d EG |
5591 | static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw, |
5592 | struct ieee80211_vif *vif, | |
5593 | const struct ieee80211_event *event) | |
5594 | { | |
5595 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5596 | ||
5597 | switch (event->type) { | |
5598 | case MLME_EVENT: | |
5599 | iwl_mvm_event_mlme_callback(mvm, vif, event); | |
5600 | break; | |
5601 | case BAR_RX_EVENT: | |
5602 | iwl_mvm_event_bar_rx_callback(mvm, vif, event); | |
5603 | break; | |
5604 | case BA_FRAME_TIMEOUT: | |
528a542a EG |
5605 | iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta, |
5606 | event->u.ba.tid); | |
4203263d EG |
5607 | break; |
5608 | default: | |
5609 | break; | |
5610 | } | |
5611 | } | |
5612 | ||
d0ff5d22 | 5613 | void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm, |
5e1688ce JB |
5614 | enum iwl_mvm_rxq_notif_type type, |
5615 | bool sync, | |
5616 | const void *data, u32 size) | |
0636b938 | 5617 | { |
5e1688ce JB |
5618 | struct { |
5619 | struct iwl_rxq_sync_cmd cmd; | |
5620 | struct iwl_mvm_internal_rxq_notif notif; | |
5621 | } __packed cmd = { | |
5622 | .cmd.rxq_mask = cpu_to_le32(BIT(mvm->trans->num_rx_queues) - 1), | |
5623 | .cmd.count = | |
5624 | cpu_to_le32(sizeof(struct iwl_mvm_internal_rxq_notif) + | |
5625 | size), | |
5626 | .notif.type = type, | |
5627 | .notif.sync = sync, | |
5628 | }; | |
5629 | struct iwl_host_cmd hcmd = { | |
5630 | .id = WIDE_ID(DATA_PATH_GROUP, TRIGGER_RX_QUEUES_NOTIF_CMD), | |
5631 | .data[0] = &cmd, | |
5632 | .len[0] = sizeof(cmd), | |
5633 | .data[1] = data, | |
5634 | .len[1] = size, | |
5635 | .flags = sync ? 0 : CMD_ASYNC, | |
5636 | }; | |
0636b938 SS |
5637 | int ret; |
5638 | ||
5e1688ce JB |
5639 | /* size must be a multiple of DWORD */ |
5640 | if (WARN_ON(cmd.cmd.count & cpu_to_le32(3))) | |
5641 | return; | |
0636b938 | 5642 | |
cb8550e1 | 5643 | if (!iwl_mvm_has_new_rx_api(mvm)) |
0636b938 SS |
5644 | return; |
5645 | ||
5e1688ce JB |
5646 | if (sync) { |
5647 | cmd.notif.cookie = mvm->queue_sync_cookie; | |
2f7a04c7 | 5648 | mvm->queue_sync_state = (1 << mvm->trans->num_rx_queues) - 1; |
a2113cc4 | 5649 | } |
0636b938 | 5650 | |
5e1688ce | 5651 | ret = iwl_mvm_send_cmd(mvm, &hcmd); |
0636b938 SS |
5652 | if (ret) { |
5653 | IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret); | |
5654 | goto out; | |
5655 | } | |
d0ff5d22 | 5656 | |
5e1688ce | 5657 | if (sync) { |
3c514bf8 | 5658 | lockdep_assert_held(&mvm->mutex); |
3a732c65 | 5659 | ret = wait_event_timeout(mvm->rx_sync_waitq, |
2f7a04c7 | 5660 | READ_ONCE(mvm->queue_sync_state) == 0 || |
6ad04359 | 5661 | iwl_mvm_is_radio_killed(mvm), |
d0ff5d22 | 5662 | HZ); |
2f7a04c7 JB |
5663 | WARN_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm), |
5664 | "queue sync: failed to sync, state is 0x%lx\n", | |
5665 | mvm->queue_sync_state); | |
6ad04359 | 5666 | } |
0636b938 SS |
5667 | |
5668 | out: | |
5e1688ce | 5669 | if (sync) { |
5f8a3561 | 5670 | mvm->queue_sync_state = 0; |
a2113cc4 | 5671 | mvm->queue_sync_cookie++; |
5f8a3561 | 5672 | } |
0636b938 SS |
5673 | } |
5674 | ||
5675 | static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw) | |
5676 | { | |
5677 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5678 | ||
5679 | mutex_lock(&mvm->mutex); | |
5e1688ce | 5680 | iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_EMPTY, true, NULL, 0); |
0636b938 SS |
5681 | mutex_unlock(&mvm->mutex); |
5682 | } | |
5683 | ||
b73f9a4a JB |
5684 | static int |
5685 | iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw, | |
5686 | struct ieee80211_vif *vif, | |
5687 | struct cfg80211_ftm_responder_stats *stats) | |
5688 | { | |
5689 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5690 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
5691 | ||
5692 | if (vif->p2p || vif->type != NL80211_IFTYPE_AP || | |
5693 | !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder) | |
5694 | return -EINVAL; | |
5695 | ||
5696 | mutex_lock(&mvm->mutex); | |
5697 | *stats = mvm->ftm_resp_stats; | |
5698 | mutex_unlock(&mvm->mutex); | |
5699 | ||
5700 | stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) | | |
5701 | BIT(NL80211_FTM_STATS_PARTIAL_NUM) | | |
5702 | BIT(NL80211_FTM_STATS_FAILED_NUM) | | |
5703 | BIT(NL80211_FTM_STATS_ASAP_NUM) | | |
5704 | BIT(NL80211_FTM_STATS_NON_ASAP_NUM) | | |
5705 | BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) | | |
5706 | BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) | | |
5707 | BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) | | |
5708 | BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM); | |
5709 | ||
5710 | return 0; | |
5711 | } | |
5712 | ||
fc36ffda JB |
5713 | static int iwl_mvm_start_pmsr(struct ieee80211_hw *hw, |
5714 | struct ieee80211_vif *vif, | |
5715 | struct cfg80211_pmsr_request *request) | |
5716 | { | |
5717 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5718 | int ret; | |
5719 | ||
5720 | mutex_lock(&mvm->mutex); | |
5721 | ret = iwl_mvm_ftm_start(mvm, vif, request); | |
5722 | mutex_unlock(&mvm->mutex); | |
5723 | ||
5724 | return ret; | |
5725 | } | |
5726 | ||
5727 | static void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw, | |
5728 | struct ieee80211_vif *vif, | |
5729 | struct cfg80211_pmsr_request *request) | |
5730 | { | |
5731 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5732 | ||
5733 | mutex_lock(&mvm->mutex); | |
5734 | iwl_mvm_ftm_abort(mvm, request); | |
5735 | mutex_unlock(&mvm->mutex); | |
5736 | } | |
5737 | ||
438af969 SS |
5738 | static bool iwl_mvm_can_hw_csum(struct sk_buff *skb) |
5739 | { | |
5740 | u8 protocol = ip_hdr(skb)->protocol; | |
5741 | ||
5742 | if (!IS_ENABLED(CONFIG_INET)) | |
5743 | return false; | |
5744 | ||
5745 | return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP; | |
5746 | } | |
5747 | ||
5748 | static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw, | |
5749 | struct sk_buff *head, | |
5750 | struct sk_buff *skb) | |
5751 | { | |
5752 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
5753 | ||
0792df68 JB |
5754 | if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) |
5755 | return iwl_mvm_tx_csum_bz(mvm, head, true) == | |
5756 | iwl_mvm_tx_csum_bz(mvm, skb, true); | |
5757 | ||
438af969 SS |
5758 | /* For now don't aggregate IPv6 in AMSDU */ |
5759 | if (skb->protocol != htons(ETH_P_IP)) | |
5760 | return false; | |
5761 | ||
5762 | if (!iwl_mvm_is_csum_supported(mvm)) | |
5763 | return true; | |
5764 | ||
5765 | return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head); | |
5766 | } | |
5767 | ||
e5209263 | 5768 | const struct ieee80211_ops iwl_mvm_hw_ops = { |
8ca151b5 | 5769 | .tx = iwl_mvm_mac_tx, |
cfbc6c4c | 5770 | .wake_tx_queue = iwl_mvm_mac_wake_tx_queue, |
8ca151b5 | 5771 | .ampdu_action = iwl_mvm_mac_ampdu_action, |
e8503aec | 5772 | .get_antenna = iwl_mvm_op_get_antenna, |
8ca151b5 | 5773 | .start = iwl_mvm_mac_start, |
cf2c92d8 | 5774 | .reconfig_complete = iwl_mvm_mac_reconfig_complete, |
8ca151b5 JB |
5775 | .stop = iwl_mvm_mac_stop, |
5776 | .add_interface = iwl_mvm_mac_add_interface, | |
5777 | .remove_interface = iwl_mvm_mac_remove_interface, | |
5778 | .config = iwl_mvm_mac_config, | |
e59647ea | 5779 | .prepare_multicast = iwl_mvm_prepare_multicast, |
8ca151b5 | 5780 | .configure_filter = iwl_mvm_configure_filter, |
effd1929 | 5781 | .config_iface_filter = iwl_mvm_config_iface_filter, |
8ca151b5 JB |
5782 | .bss_info_changed = iwl_mvm_bss_info_changed, |
5783 | .hw_scan = iwl_mvm_mac_hw_scan, | |
5784 | .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, | |
1ddbbb0c | 5785 | .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, |
8ca151b5 JB |
5786 | .sta_state = iwl_mvm_mac_sta_state, |
5787 | .sta_notify = iwl_mvm_mac_sta_notify, | |
5788 | .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, | |
3e56eadf | 5789 | .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, |
8ca151b5 | 5790 | .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, |
1f3b0ff8 | 5791 | .sta_rc_update = iwl_mvm_sta_rc_update, |
8ca151b5 JB |
5792 | .conf_tx = iwl_mvm_mac_conf_tx, |
5793 | .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, | |
6b1259d1 | 5794 | .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx, |
07ecd897 | 5795 | .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover, |
c5b0e7c0 | 5796 | .flush = iwl_mvm_mac_flush, |
35a000b7 DS |
5797 | .sched_scan_start = iwl_mvm_mac_sched_scan_start, |
5798 | .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, | |
8ca151b5 JB |
5799 | .set_key = iwl_mvm_mac_set_key, |
5800 | .update_tkip_key = iwl_mvm_mac_update_tkip_key, | |
5801 | .remain_on_channel = iwl_mvm_roc, | |
5802 | .cancel_remain_on_channel = iwl_mvm_cancel_roc, | |
8ca151b5 JB |
5803 | .add_chanctx = iwl_mvm_add_chanctx, |
5804 | .remove_chanctx = iwl_mvm_remove_chanctx, | |
5805 | .change_chanctx = iwl_mvm_change_chanctx, | |
5806 | .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, | |
5807 | .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, | |
b08c1d97 | 5808 | .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx, |
8ca151b5 | 5809 | |
ae7ba17b ST |
5810 | .start_ap = iwl_mvm_start_ap, |
5811 | .stop_ap = iwl_mvm_stop_ap, | |
5812 | .join_ibss = iwl_mvm_start_ibss, | |
5813 | .leave_ibss = iwl_mvm_stop_ibss, | |
8ca151b5 | 5814 | |
2f0282db JB |
5815 | .tx_last_beacon = iwl_mvm_tx_last_beacon, |
5816 | ||
8ca151b5 JB |
5817 | .set_tim = iwl_mvm_set_tim, |
5818 | ||
622e3f9b | 5819 | .channel_switch = iwl_mvm_channel_switch, |
f028905c | 5820 | .pre_channel_switch = iwl_mvm_pre_channel_switch, |
f6c34820 | 5821 | .post_channel_switch = iwl_mvm_post_channel_switch, |
79221126 | 5822 | .abort_channel_switch = iwl_mvm_abort_channel_switch, |
c37763d2 | 5823 | .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon, |
bd3398e2 | 5824 | |
1d3c3f63 AN |
5825 | .tdls_channel_switch = iwl_mvm_tdls_channel_switch, |
5826 | .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch, | |
5827 | .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch, | |
5828 | ||
d42f5350 EG |
5829 | .event_callback = iwl_mvm_mac_event_callback, |
5830 | ||
0636b938 SS |
5831 | .sync_rx_queues = iwl_mvm_sync_rx_queues, |
5832 | ||
507cadf2 DS |
5833 | CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) |
5834 | ||
8ca151b5 JB |
5835 | #ifdef CONFIG_PM_SLEEP |
5836 | /* look at d3.c */ | |
5837 | .suspend = iwl_mvm_suspend, | |
5838 | .resume = iwl_mvm_resume, | |
5839 | .set_wakeup = iwl_mvm_set_wakeup, | |
5840 | .set_rekey_data = iwl_mvm_set_rekey_data, | |
5841 | #if IS_ENABLED(CONFIG_IPV6) | |
5842 | .ipv6_addr_change = iwl_mvm_ipv6_addr_change, | |
5843 | #endif | |
5844 | .set_default_unicast_key = iwl_mvm_set_default_unicast_key, | |
5845 | #endif | |
91a8bcde | 5846 | .get_survey = iwl_mvm_mac_get_survey, |
33cef925 | 5847 | .sta_statistics = iwl_mvm_mac_sta_statistics, |
b73f9a4a | 5848 | .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats, |
fc36ffda JB |
5849 | .start_pmsr = iwl_mvm_start_pmsr, |
5850 | .abort_pmsr = iwl_mvm_abort_pmsr, | |
b73f9a4a | 5851 | |
438af969 | 5852 | .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate, |
177a11cf GG |
5853 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
5854 | .sta_add_debugfs = iwl_mvm_sta_add_debugfs, | |
5855 | #endif | |
8ca151b5 | 5856 | }; |