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