1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
9 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
10 * Copyright(c) 2012 - 2014, 2018 - 2020 Intel Corporation
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * The full GNU General Public License is included in this distribution
22 * in the file called COPYING.
24 * Contact Information:
25 * Intel Linux Wireless <linuxwifi@intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
31 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
32 * Copyright(c) 2012 - 2014, 2018 - 2020 Intel Corporation
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
39 * * Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * * Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in
43 * the documentation and/or other materials provided with the
45 * * Neither the name Intel Corporation nor the names of its
46 * contributors may be used to endorse or promote products derived
47 * from this software without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
62 #include <linux/kernel.h>
63 #include <linux/slab.h>
64 #include <linux/skbuff.h>
65 #include <linux/netdevice.h>
66 #include <linux/etherdevice.h>
68 #include <linux/if_arp.h>
69 #include <linux/time.h>
70 #include <net/mac80211.h>
71 #include <net/ieee80211_radiotap.h>
74 #include "iwl-op-mode.h"
78 #include "time-event.h"
79 #include "iwl-eeprom-parse.h"
80 #include "iwl-phy-db.h"
82 #include "fw/error-dump.h"
84 #include "iwl-nvm-parse.h"
86 static const struct ieee80211_iface_limit iwl_mvm_limits
[] = {
89 .types
= BIT(NL80211_IFTYPE_STATION
),
93 .types
= BIT(NL80211_IFTYPE_AP
) |
94 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
95 BIT(NL80211_IFTYPE_P2P_GO
),
99 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
103 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations
[] = {
105 .num_different_channels
= 2,
107 .limits
= iwl_mvm_limits
,
108 .n_limits
= ARRAY_SIZE(iwl_mvm_limits
),
112 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
114 * Use the reserved field to indicate magic values.
115 * these values will only be used internally by the driver,
116 * and won't make it to the fw (reserved will be 0).
117 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
118 * be the vif's ip address. in case there is not a single
119 * ip address (0, or more than 1), this attribute will
121 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
122 * the LSB bytes of the vif's mac address
125 BC_FILTER_MAGIC_NONE
= 0,
130 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters
[] = {
134 .frame_type
= BCAST_FILTER_FRAME_TYPE_ALL
,
137 /* frame type - arp, hw type - ethernet */
139 BCAST_FILTER_OFFSET_PAYLOAD_START
,
140 .offset
= sizeof(rfc1042_header
),
141 .val
= cpu_to_be32(0x08060001),
142 .mask
= cpu_to_be32(0xffffffff),
147 BCAST_FILTER_OFFSET_PAYLOAD_START
,
148 .offset
= sizeof(rfc1042_header
) + 2 +
149 sizeof(struct arphdr
) +
150 ETH_ALEN
+ sizeof(__be32
) +
152 .mask
= cpu_to_be32(0xffffffff),
153 /* mark it as special field */
154 .reserved1
= cpu_to_le16(BC_FILTER_MAGIC_IP
),
159 /* dhcp offer bcast */
161 .frame_type
= BCAST_FILTER_FRAME_TYPE_IPV4
,
164 /* udp dest port - 68 (bootp client)*/
165 .offset_type
= BCAST_FILTER_OFFSET_IP_END
,
166 .offset
= offsetof(struct udphdr
, dest
),
167 .val
= cpu_to_be32(0x00440000),
168 .mask
= cpu_to_be32(0xffff0000),
171 /* dhcp - lsb bytes of client hw address */
172 .offset_type
= BCAST_FILTER_OFFSET_IP_END
,
174 .mask
= cpu_to_be32(0xffffffff),
175 /* mark it as special field */
176 .reserved1
= cpu_to_le16(BC_FILTER_MAGIC_MAC
),
180 /* last filter must be empty */
185 static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa
= {
186 .max_peers
= IWL_MVM_TOF_MAX_APS
,
188 .randomize_mac_addr
= 1,
195 .request_civicloc
= 1,
197 .non_trigger_based
= 1,
198 .max_bursts_exponent
= -1, /* all supported */
199 .max_ftms_per_burst
= 0, /* no limits */
200 .bandwidths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
201 BIT(NL80211_CHAN_WIDTH_20
) |
202 BIT(NL80211_CHAN_WIDTH_40
) |
203 BIT(NL80211_CHAN_WIDTH_80
),
204 .preambles
= BIT(NL80211_PREAMBLE_LEGACY
) |
205 BIT(NL80211_PREAMBLE_HT
) |
206 BIT(NL80211_PREAMBLE_VHT
) |
207 BIT(NL80211_PREAMBLE_HE
),
211 static int __iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
212 enum set_key_cmd cmd
,
213 struct ieee80211_vif
*vif
,
214 struct ieee80211_sta
*sta
,
215 struct ieee80211_key_conf
*key
);
217 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm
*mvm
)
221 memset(mvm
->phy_ctxts
, 0, sizeof(mvm
->phy_ctxts
));
222 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
223 mvm
->phy_ctxts
[i
].id
= i
;
224 mvm
->phy_ctxts
[i
].ref
= 0;
228 struct ieee80211_regdomain
*iwl_mvm_get_regdomain(struct wiphy
*wiphy
,
230 enum iwl_mcc_source src_id
,
233 struct ieee80211_regdomain
*regd
= NULL
;
234 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
235 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
236 struct iwl_mcc_update_resp
*resp
;
238 IWL_DEBUG_LAR(mvm
, "Getting regdomain data for %s from FW\n", alpha2
);
240 lockdep_assert_held(&mvm
->mutex
);
242 resp
= iwl_mvm_update_mcc(mvm
, alpha2
, src_id
);
243 if (IS_ERR_OR_NULL(resp
)) {
244 IWL_DEBUG_LAR(mvm
, "Could not get update from FW %d\n",
245 PTR_ERR_OR_ZERO(resp
));
250 u32 status
= le32_to_cpu(resp
->status
);
252 *changed
= (status
== MCC_RESP_NEW_CHAN_PROFILE
||
253 status
== MCC_RESP_ILLEGAL
);
256 regd
= iwl_parse_nvm_mcc_info(mvm
->trans
->dev
, mvm
->cfg
,
257 __le32_to_cpu(resp
->n_channels
),
259 __le16_to_cpu(resp
->mcc
),
260 __le16_to_cpu(resp
->geo_info
),
261 __le16_to_cpu(resp
->cap
));
262 /* Store the return source id */
263 src_id
= resp
->source_id
;
265 if (IS_ERR_OR_NULL(regd
)) {
266 IWL_DEBUG_LAR(mvm
, "Could not get parse update from FW %d\n",
267 PTR_ERR_OR_ZERO(regd
));
271 IWL_DEBUG_LAR(mvm
, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
272 regd
->alpha2
, regd
->alpha2
[0], regd
->alpha2
[1], src_id
);
273 mvm
->lar_regdom_set
= true;
274 mvm
->mcc_src
= src_id
;
280 void iwl_mvm_update_changed_regdom(struct iwl_mvm
*mvm
)
283 struct ieee80211_regdomain
*regd
;
285 if (!iwl_mvm_is_lar_supported(mvm
))
288 regd
= iwl_mvm_get_current_regdomain(mvm
, &changed
);
289 if (!IS_ERR_OR_NULL(regd
)) {
290 /* only update the regulatory core if changed */
292 regulatory_set_wiphy_regd(mvm
->hw
->wiphy
, regd
);
298 struct ieee80211_regdomain
*iwl_mvm_get_current_regdomain(struct iwl_mvm
*mvm
,
301 return iwl_mvm_get_regdomain(mvm
->hw
->wiphy
, "ZZ",
302 iwl_mvm_is_wifi_mcc_supported(mvm
) ?
303 MCC_SOURCE_GET_CURRENT
:
304 MCC_SOURCE_OLD_FW
, changed
);
307 int iwl_mvm_init_fw_regd(struct iwl_mvm
*mvm
)
309 enum iwl_mcc_source used_src
;
310 struct ieee80211_regdomain
*regd
;
313 const struct ieee80211_regdomain
*r
=
314 rtnl_dereference(mvm
->hw
->wiphy
->regd
);
319 /* save the last source in case we overwrite it below */
320 used_src
= mvm
->mcc_src
;
321 if (iwl_mvm_is_wifi_mcc_supported(mvm
)) {
322 /* Notify the firmware we support wifi location updates */
323 regd
= iwl_mvm_get_current_regdomain(mvm
, NULL
);
324 if (!IS_ERR_OR_NULL(regd
))
328 /* Now set our last stored MCC and source */
329 regd
= iwl_mvm_get_regdomain(mvm
->hw
->wiphy
, r
->alpha2
, used_src
,
331 if (IS_ERR_OR_NULL(regd
))
334 /* update cfg80211 if the regdomain was changed */
336 ret
= regulatory_set_wiphy_regd_sync_rtnl(mvm
->hw
->wiphy
, regd
);
344 static const u8 he_if_types_ext_capa_sta
[] = {
345 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING
,
346 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT
,
347 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF
,
348 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT
,
351 static const struct wiphy_iftype_ext_capab he_iftypes_ext_capa
[] = {
353 .iftype
= NL80211_IFTYPE_STATION
,
354 .extended_capabilities
= he_if_types_ext_capa_sta
,
355 .extended_capabilities_mask
= he_if_types_ext_capa_sta
,
356 .extended_capabilities_len
= sizeof(he_if_types_ext_capa_sta
),
361 iwl_mvm_op_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
363 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
364 *tx_ant
= iwl_mvm_get_valid_tx_ant(mvm
);
365 *rx_ant
= iwl_mvm_get_valid_rx_ant(mvm
);
369 int iwl_mvm_mac_setup_register(struct iwl_mvm
*mvm
)
371 struct ieee80211_hw
*hw
= mvm
->hw
;
373 static const u32 mvm_ciphers
[] = {
374 WLAN_CIPHER_SUITE_WEP40
,
375 WLAN_CIPHER_SUITE_WEP104
,
376 WLAN_CIPHER_SUITE_TKIP
,
377 WLAN_CIPHER_SUITE_CCMP
,
379 #ifdef CONFIG_PM_SLEEP
380 bool unified
= fw_has_capa(&mvm
->fw
->ucode_capa
,
381 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG
);
384 /* Tell mac80211 our characteristics */
385 ieee80211_hw_set(hw
, SIGNAL_DBM
);
386 ieee80211_hw_set(hw
, SPECTRUM_MGMT
);
387 ieee80211_hw_set(hw
, REPORTS_TX_ACK_STATUS
);
388 ieee80211_hw_set(hw
, WANT_MONITOR_VIF
);
389 ieee80211_hw_set(hw
, SUPPORTS_PS
);
390 ieee80211_hw_set(hw
, SUPPORTS_DYNAMIC_PS
);
391 ieee80211_hw_set(hw
, AMPDU_AGGREGATION
);
392 ieee80211_hw_set(hw
, TIMING_BEACON_ONLY
);
393 ieee80211_hw_set(hw
, CONNECTION_MONITOR
);
394 ieee80211_hw_set(hw
, CHANCTX_STA_CSA
);
395 ieee80211_hw_set(hw
, SUPPORT_FAST_XMIT
);
396 ieee80211_hw_set(hw
, SUPPORTS_CLONED_SKBS
);
397 ieee80211_hw_set(hw
, SUPPORTS_AMSDU_IN_AMPDU
);
398 ieee80211_hw_set(hw
, NEEDS_UNIQUE_STA_ADDR
);
399 ieee80211_hw_set(hw
, DEAUTH_NEED_MGD_TX_PREP
);
400 ieee80211_hw_set(hw
, SUPPORTS_VHT_EXT_NSS_BW
);
401 ieee80211_hw_set(hw
, BUFF_MMPDU_TXQ
);
402 ieee80211_hw_set(hw
, STA_MMPDU_TXQ
);
404 * On older devices, enabling TX A-MSDU occasionally leads to
405 * something getting messed up, the command read from the FIFO
406 * gets out of sync and isn't a TX command, so that we have an
409 * It's not clear where the bug is, but since we didn't used to
410 * support A-MSDU until moving the mac80211 iTXQs, just leave it
411 * for older devices. We also don't see this issue on any newer
414 if (mvm
->trans
->trans_cfg
->device_family
>= IWL_DEVICE_FAMILY_9000
)
415 ieee80211_hw_set(hw
, TX_AMSDU
);
416 ieee80211_hw_set(hw
, TX_FRAG_LIST
);
418 if (iwl_mvm_has_tlc_offload(mvm
)) {
419 ieee80211_hw_set(hw
, TX_AMPDU_SETUP_IN_HW
);
420 ieee80211_hw_set(hw
, HAS_RATE_CONTROL
);
423 if (iwl_mvm_has_new_rx_api(mvm
))
424 ieee80211_hw_set(hw
, SUPPORTS_REORDERING_BUFFER
);
426 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
427 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF
)) {
428 ieee80211_hw_set(hw
, AP_LINK_PS
);
429 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm
))) {
431 * we absolutely need this for the new TX API since that comes
432 * with many more queues than the current code can deal with
433 * for station powersave
438 if (mvm
->trans
->num_rx_queues
> 1)
439 ieee80211_hw_set(hw
, USES_RSS
);
441 if (mvm
->trans
->max_skb_frags
)
442 hw
->netdev_features
= NETIF_F_HIGHDMA
| NETIF_F_SG
;
444 hw
->queues
= IEEE80211_MAX_QUEUES
;
445 hw
->offchannel_tx_hw_queue
= IWL_MVM_OFFCHANNEL_QUEUE
;
446 hw
->radiotap_mcs_details
|= IEEE80211_RADIOTAP_MCS_HAVE_FEC
|
447 IEEE80211_RADIOTAP_MCS_HAVE_STBC
;
448 hw
->radiotap_vht_details
|= IEEE80211_RADIOTAP_VHT_KNOWN_STBC
|
449 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED
;
451 hw
->radiotap_timestamp
.units_pos
=
452 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US
|
453 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ
;
454 /* this is the case for CCK frames, it's better (only 8) for OFDM */
455 hw
->radiotap_timestamp
.accuracy
= 22;
457 if (!iwl_mvm_has_tlc_offload(mvm
))
458 hw
->rate_control_algorithm
= RS_NAME
;
460 hw
->uapsd_queues
= IWL_MVM_UAPSD_QUEUES
;
461 hw
->uapsd_max_sp_len
= IWL_UAPSD_MAX_SP
;
462 hw
->max_tx_fragments
= mvm
->trans
->max_skb_frags
;
464 BUILD_BUG_ON(ARRAY_SIZE(mvm
->ciphers
) < ARRAY_SIZE(mvm_ciphers
) + 6);
465 memcpy(mvm
->ciphers
, mvm_ciphers
, sizeof(mvm_ciphers
));
466 hw
->wiphy
->n_cipher_suites
= ARRAY_SIZE(mvm_ciphers
);
467 hw
->wiphy
->cipher_suites
= mvm
->ciphers
;
469 if (iwl_mvm_has_new_rx_api(mvm
)) {
470 mvm
->ciphers
[hw
->wiphy
->n_cipher_suites
] =
471 WLAN_CIPHER_SUITE_GCMP
;
472 hw
->wiphy
->n_cipher_suites
++;
473 mvm
->ciphers
[hw
->wiphy
->n_cipher_suites
] =
474 WLAN_CIPHER_SUITE_GCMP_256
;
475 hw
->wiphy
->n_cipher_suites
++;
478 /* Enable 11w if software crypto is not enabled (as the
479 * firmware will interpret some mgmt packets, so enabling it
480 * with software crypto isn't safe).
482 if (!iwlwifi_mod_params
.swcrypto
) {
483 ieee80211_hw_set(hw
, MFP_CAPABLE
);
484 mvm
->ciphers
[hw
->wiphy
->n_cipher_suites
] =
485 WLAN_CIPHER_SUITE_AES_CMAC
;
486 hw
->wiphy
->n_cipher_suites
++;
487 if (iwl_mvm_has_new_rx_api(mvm
)) {
488 mvm
->ciphers
[hw
->wiphy
->n_cipher_suites
] =
489 WLAN_CIPHER_SUITE_BIP_GMAC_128
;
490 hw
->wiphy
->n_cipher_suites
++;
491 mvm
->ciphers
[hw
->wiphy
->n_cipher_suites
] =
492 WLAN_CIPHER_SUITE_BIP_GMAC_256
;
493 hw
->wiphy
->n_cipher_suites
++;
497 /* currently FW API supports only one optional cipher scheme */
498 if (mvm
->fw
->cs
[0].cipher
) {
499 const struct iwl_fw_cipher_scheme
*fwcs
= &mvm
->fw
->cs
[0];
500 struct ieee80211_cipher_scheme
*cs
= &mvm
->cs
[0];
502 mvm
->hw
->n_cipher_schemes
= 1;
504 cs
->cipher
= le32_to_cpu(fwcs
->cipher
);
505 cs
->iftype
= BIT(NL80211_IFTYPE_STATION
);
506 cs
->hdr_len
= fwcs
->hdr_len
;
507 cs
->pn_len
= fwcs
->pn_len
;
508 cs
->pn_off
= fwcs
->pn_off
;
509 cs
->key_idx_off
= fwcs
->key_idx_off
;
510 cs
->key_idx_mask
= fwcs
->key_idx_mask
;
511 cs
->key_idx_shift
= fwcs
->key_idx_shift
;
512 cs
->mic_len
= fwcs
->mic_len
;
514 mvm
->hw
->cipher_schemes
= mvm
->cs
;
515 mvm
->ciphers
[hw
->wiphy
->n_cipher_suites
] = cs
->cipher
;
516 hw
->wiphy
->n_cipher_suites
++;
519 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
520 IWL_UCODE_TLV_CAPA_FTM_CALIBRATED
)) {
521 wiphy_ext_feature_set(hw
->wiphy
,
522 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER
);
523 hw
->wiphy
->pmsr_capa
= &iwl_mvm_pmsr_capa
;
526 ieee80211_hw_set(hw
, SINGLE_SCAN_ON_ALL_BANDS
);
527 hw
->wiphy
->features
|=
528 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR
|
529 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
|
530 NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
532 hw
->sta_data_size
= sizeof(struct iwl_mvm_sta
);
533 hw
->vif_data_size
= sizeof(struct iwl_mvm_vif
);
534 hw
->chanctx_data_size
= sizeof(u16
);
535 hw
->txq_data_size
= sizeof(struct iwl_mvm_txq
);
537 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
538 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
539 BIT(NL80211_IFTYPE_AP
) |
540 BIT(NL80211_IFTYPE_P2P_GO
) |
541 BIT(NL80211_IFTYPE_P2P_DEVICE
) |
542 BIT(NL80211_IFTYPE_ADHOC
);
544 hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
545 wiphy_ext_feature_set(hw
->wiphy
, NL80211_EXT_FEATURE_VHT_IBSS
);
546 hw
->wiphy
->features
|= NL80211_FEATURE_HT_IBSS
;
548 hw
->wiphy
->regulatory_flags
|= REGULATORY_ENABLE_RELAX_NO_IR
;
549 if (iwl_mvm_is_lar_supported(mvm
))
550 hw
->wiphy
->regulatory_flags
|= REGULATORY_WIPHY_SELF_MANAGED
;
552 hw
->wiphy
->regulatory_flags
|= REGULATORY_CUSTOM_REG
|
553 REGULATORY_DISABLE_BEACON_HINTS
;
555 hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
556 hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
558 hw
->wiphy
->iface_combinations
= iwl_mvm_iface_combinations
;
559 hw
->wiphy
->n_iface_combinations
=
560 ARRAY_SIZE(iwl_mvm_iface_combinations
);
562 hw
->wiphy
->max_remain_on_channel_duration
= 10000;
563 hw
->max_listen_interval
= IWL_CONN_MAX_LISTEN_INTERVAL
;
565 /* Extract MAC address */
566 memcpy(mvm
->addresses
[0].addr
, mvm
->nvm_data
->hw_addr
, ETH_ALEN
);
567 hw
->wiphy
->addresses
= mvm
->addresses
;
568 hw
->wiphy
->n_addresses
= 1;
570 /* Extract additional MAC addresses if available */
571 num_mac
= (mvm
->nvm_data
->n_hw_addrs
> 1) ?
572 min(IWL_MVM_MAX_ADDRESSES
, mvm
->nvm_data
->n_hw_addrs
) : 1;
574 for (i
= 1; i
< num_mac
; i
++) {
575 memcpy(mvm
->addresses
[i
].addr
, mvm
->addresses
[i
-1].addr
,
577 mvm
->addresses
[i
].addr
[5]++;
578 hw
->wiphy
->n_addresses
++;
581 iwl_mvm_reset_phy_ctxts(mvm
);
583 hw
->wiphy
->max_scan_ie_len
= iwl_mvm_max_scan_ie_len(mvm
);
585 hw
->wiphy
->max_scan_ssids
= PROBE_OPTION_MAX
;
587 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK
& IWL_MVM_SCAN_MASK
);
588 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS
> HWEIGHT32(IWL_MVM_SCAN_MASK
) ||
589 IWL_MVM_MAX_LMAC_SCANS
> HWEIGHT32(IWL_MVM_SCAN_MASK
));
591 if (fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_UMAC_SCAN
))
592 mvm
->max_scans
= IWL_MVM_MAX_UMAC_SCANS
;
594 mvm
->max_scans
= IWL_MVM_MAX_LMAC_SCANS
;
596 if (mvm
->nvm_data
->bands
[NL80211_BAND_2GHZ
].n_channels
)
597 hw
->wiphy
->bands
[NL80211_BAND_2GHZ
] =
598 &mvm
->nvm_data
->bands
[NL80211_BAND_2GHZ
];
599 if (mvm
->nvm_data
->bands
[NL80211_BAND_5GHZ
].n_channels
) {
600 hw
->wiphy
->bands
[NL80211_BAND_5GHZ
] =
601 &mvm
->nvm_data
->bands
[NL80211_BAND_5GHZ
];
603 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
604 IWL_UCODE_TLV_CAPA_BEAMFORMER
) &&
605 fw_has_api(&mvm
->fw
->ucode_capa
,
606 IWL_UCODE_TLV_API_LQ_SS_PARAMS
))
607 hw
->wiphy
->bands
[NL80211_BAND_5GHZ
]->vht_cap
.cap
|=
608 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
;
611 hw
->wiphy
->hw_version
= mvm
->trans
->hw_id
;
613 if (iwlmvm_mod_params
.power_scheme
!= IWL_POWER_SCHEME_CAM
)
614 hw
->wiphy
->flags
|= WIPHY_FLAG_PS_ON_BY_DEFAULT
;
616 hw
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
618 hw
->wiphy
->max_sched_scan_reqs
= 1;
619 hw
->wiphy
->max_sched_scan_ssids
= PROBE_OPTION_MAX
;
620 hw
->wiphy
->max_match_sets
= iwl_umac_scan_get_max_profiles(mvm
->fw
);
621 /* we create the 802.11 header and zero length SSID IE. */
622 hw
->wiphy
->max_sched_scan_ie_len
=
623 SCAN_OFFLOAD_PROBE_REQ_SIZE
- 24 - 2;
624 hw
->wiphy
->max_sched_scan_plans
= IWL_MAX_SCHED_SCAN_PLANS
;
625 hw
->wiphy
->max_sched_scan_plan_interval
= U16_MAX
;
628 * the firmware uses u8 for num of iterations, but 0xff is saved for
629 * infinite loop, so the maximum number of iterations is actually 254.
631 hw
->wiphy
->max_sched_scan_plan_iterations
= 254;
633 hw
->wiphy
->features
|= NL80211_FEATURE_P2P_GO_CTWIN
|
634 NL80211_FEATURE_LOW_PRIORITY_SCAN
|
635 NL80211_FEATURE_P2P_GO_OPPPS
|
636 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
|
637 NL80211_FEATURE_DYNAMIC_SMPS
|
638 NL80211_FEATURE_STATIC_SMPS
|
639 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
;
641 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
642 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT
))
643 hw
->wiphy
->features
|= NL80211_FEATURE_TX_POWER_INSERTION
;
644 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
645 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT
))
646 hw
->wiphy
->features
|= NL80211_FEATURE_QUIET
;
648 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
649 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT
))
650 hw
->wiphy
->features
|=
651 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
;
653 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
654 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT
))
655 hw
->wiphy
->features
|= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES
;
657 if (fw_has_api(&mvm
->fw
->ucode_capa
,
658 IWL_UCODE_TLV_API_SCAN_TSF_REPORT
)) {
659 wiphy_ext_feature_set(hw
->wiphy
,
660 NL80211_EXT_FEATURE_SCAN_START_TIME
);
661 wiphy_ext_feature_set(hw
->wiphy
,
662 NL80211_EXT_FEATURE_BSS_PARENT_TSF
);
663 wiphy_ext_feature_set(hw
->wiphy
,
664 NL80211_EXT_FEATURE_SET_SCAN_DWELL
);
667 if (iwl_mvm_is_oce_supported(mvm
)) {
668 wiphy_ext_feature_set(hw
->wiphy
,
669 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP
);
670 wiphy_ext_feature_set(hw
->wiphy
,
671 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME
);
672 wiphy_ext_feature_set(hw
->wiphy
,
673 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION
);
674 wiphy_ext_feature_set(hw
->wiphy
,
675 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE
);
678 if (mvm
->nvm_data
->sku_cap_11ax_enable
&&
679 !iwlwifi_mod_params
.disable_11ax
) {
680 hw
->wiphy
->iftype_ext_capab
= he_iftypes_ext_capa
;
681 hw
->wiphy
->num_iftype_ext_capab
=
682 ARRAY_SIZE(he_iftypes_ext_capa
);
684 ieee80211_hw_set(hw
, SUPPORTS_MULTI_BSSID
);
685 ieee80211_hw_set(hw
, SUPPORTS_ONLY_HE_MULTI_BSSID
);
688 mvm
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
690 #ifdef CONFIG_PM_SLEEP
691 if ((unified
|| mvm
->fw
->img
[IWL_UCODE_WOWLAN
].num_sec
) &&
692 mvm
->trans
->ops
->d3_suspend
&&
693 mvm
->trans
->ops
->d3_resume
&&
694 device_can_wakeup(mvm
->trans
->dev
)) {
695 mvm
->wowlan
.flags
|= WIPHY_WOWLAN_MAGIC_PKT
|
696 WIPHY_WOWLAN_DISCONNECT
|
697 WIPHY_WOWLAN_EAP_IDENTITY_REQ
|
698 WIPHY_WOWLAN_RFKILL_RELEASE
|
699 WIPHY_WOWLAN_NET_DETECT
;
700 if (!iwlwifi_mod_params
.swcrypto
)
701 mvm
->wowlan
.flags
|= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
|
702 WIPHY_WOWLAN_GTK_REKEY_FAILURE
|
703 WIPHY_WOWLAN_4WAY_HANDSHAKE
;
705 mvm
->wowlan
.n_patterns
= IWL_WOWLAN_MAX_PATTERNS
;
706 mvm
->wowlan
.pattern_min_len
= IWL_WOWLAN_MIN_PATTERN_LEN
;
707 mvm
->wowlan
.pattern_max_len
= IWL_WOWLAN_MAX_PATTERN_LEN
;
708 mvm
->wowlan
.max_nd_match_sets
=
709 iwl_umac_scan_get_max_profiles(mvm
->fw
);
710 hw
->wiphy
->wowlan
= &mvm
->wowlan
;
714 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
715 /* assign default bcast filtering configuration */
716 mvm
->bcast_filters
= iwl_mvm_default_bcast_filters
;
719 ret
= iwl_mvm_leds_init(mvm
);
723 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
724 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT
)) {
725 IWL_DEBUG_TDLS(mvm
, "TDLS supported\n");
726 hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_TDLS
;
727 ieee80211_hw_set(hw
, TDLS_WIDER_BW
);
730 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
731 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH
)) {
732 IWL_DEBUG_TDLS(mvm
, "TDLS channel switch supported\n");
733 hw
->wiphy
->features
|= NL80211_FEATURE_TDLS_CHANNEL_SWITCH
;
736 hw
->netdev_features
|= mvm
->cfg
->features
;
737 if (!iwl_mvm_is_csum_supported(mvm
)) {
738 hw
->netdev_features
&= ~(IWL_TX_CSUM_NETIF_FLAGS
|
740 /* We may support SW TX CSUM */
741 if (IWL_MVM_SW_TX_CSUM_OFFLOAD
)
742 hw
->netdev_features
|= IWL_TX_CSUM_NETIF_FLAGS
;
745 if (mvm
->cfg
->vht_mu_mimo_supported
)
746 wiphy_ext_feature_set(hw
->wiphy
,
747 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
);
749 hw
->wiphy
->available_antennas_tx
= iwl_mvm_get_valid_tx_ant(mvm
);
750 hw
->wiphy
->available_antennas_rx
= iwl_mvm_get_valid_rx_ant(mvm
);
752 ret
= ieee80211_register_hw(mvm
->hw
);
754 iwl_mvm_leds_exit(mvm
);
760 static void iwl_mvm_tx_skb(struct iwl_mvm
*mvm
, struct sk_buff
*skb
,
761 struct ieee80211_sta
*sta
)
764 if (likely(iwl_mvm_tx_skb_sta(mvm
, skb
, sta
) == 0))
767 if (likely(iwl_mvm_tx_skb_non_sta(mvm
, skb
) == 0))
771 ieee80211_free_txskb(mvm
->hw
, skb
);
774 static void iwl_mvm_mac_tx(struct ieee80211_hw
*hw
,
775 struct ieee80211_tx_control
*control
,
778 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
779 struct ieee80211_sta
*sta
= control
->sta
;
780 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
781 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
782 bool offchannel
= IEEE80211_SKB_CB(skb
)->flags
&
783 IEEE80211_TX_CTL_TX_OFFCHAN
;
785 if (iwl_mvm_is_radio_killed(mvm
)) {
786 IWL_DEBUG_DROP(mvm
, "Dropping - RF/CT KILL\n");
791 !test_bit(IWL_MVM_STATUS_ROC_RUNNING
, &mvm
->status
) &&
792 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING
, &mvm
->status
))
795 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
796 if ((info
->control
.vif
->type
== NL80211_IFTYPE_AP
||
797 info
->control
.vif
->type
== NL80211_IFTYPE_ADHOC
) &&
798 ieee80211_is_mgmt(hdr
->frame_control
) &&
799 !ieee80211_is_bufferable_mmpdu(hdr
->frame_control
))
802 /* If there is no sta, and it's not offchannel - send through AP */
803 if (!sta
&& info
->control
.vif
->type
== NL80211_IFTYPE_STATION
&&
805 struct iwl_mvm_vif
*mvmvif
=
806 iwl_mvm_vif_from_mac80211(info
->control
.vif
);
807 u8 ap_sta_id
= READ_ONCE(mvmvif
->ap_sta_id
);
809 if (ap_sta_id
< IWL_MVM_STATION_COUNT
) {
810 /* mac80211 holds rcu read lock */
811 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[ap_sta_id
]);
812 if (IS_ERR_OR_NULL(sta
))
817 iwl_mvm_tx_skb(mvm
, skb
, sta
);
820 ieee80211_free_txskb(hw
, skb
);
823 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw
*hw
, struct ieee80211_txq
*txq
)
825 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
826 struct iwl_mvm_txq
*mvmtxq
= iwl_mvm_txq_from_mac80211(txq
);
827 struct sk_buff
*skb
= NULL
;
830 * No need for threads to be pending here, they can leave the first
831 * taker all the work.
833 * mvmtxq->tx_request logic:
835 * If 0, no one is currently TXing, set to 1 to indicate current thread
836 * will now start TX and other threads should quit.
838 * If 1, another thread is currently TXing, set to 2 to indicate to
839 * that thread that there was another request. Since that request may
840 * have raced with the check whether the queue is empty, the TXing
841 * thread should check the queue's status one more time before leaving.
842 * This check is done in order to not leave any TX hanging in the queue
843 * until the next TX invocation (which may not even happen).
845 * If 2, another thread is currently TXing, and it will already double
846 * check the queue, so do nothing.
848 if (atomic_fetch_add_unless(&mvmtxq
->tx_request
, 1, 2))
853 while (likely(!mvmtxq
->stopped
&&
854 (mvm
->trans
->system_pm_mode
==
855 IWL_PLAT_PM_MODE_DISABLED
))) {
856 skb
= ieee80211_tx_dequeue(hw
, txq
);
861 "TXQ of sta %pM tid %d is now empty\n",
867 iwl_mvm_tx_skb(mvm
, skb
, txq
->sta
);
869 } while (atomic_dec_return(&mvmtxq
->tx_request
));
873 static void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw
*hw
,
874 struct ieee80211_txq
*txq
)
876 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
877 struct iwl_mvm_txq
*mvmtxq
= iwl_mvm_txq_from_mac80211(txq
);
880 * Please note that racing is handled very carefully here:
881 * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is
882 * deleted afterwards.
883 * This means that if:
884 * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list):
885 * queue is allocated and we can TX.
886 * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list):
887 * a race, should defer the frame.
888 * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list):
889 * need to allocate the queue and defer the frame.
890 * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list):
891 * queue is already scheduled for allocation, no need to allocate,
892 * should defer the frame.
895 /* If the queue is allocated TX and return. */
896 if (!txq
->sta
|| mvmtxq
->txq_id
!= IWL_MVM_INVALID_QUEUE
) {
898 * Check that list is empty to avoid a race where txq_id is
899 * already updated, but the queue allocation work wasn't
902 if (unlikely(txq
->sta
&& !list_empty(&mvmtxq
->list
)))
905 iwl_mvm_mac_itxq_xmit(hw
, txq
);
909 /* The list is being deleted only after the queue is fully allocated. */
910 if (!list_empty(&mvmtxq
->list
))
913 list_add_tail(&mvmtxq
->list
, &mvm
->add_stream_txqs
);
914 schedule_work(&mvm
->add_stream_wk
);
917 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
919 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
921 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
925 iwl_mvm_ampdu_check_trigger(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
926 struct ieee80211_sta
*sta
, u16 tid
, u16 rx_ba_ssn
,
927 enum ieee80211_ampdu_mlme_action action
)
929 struct iwl_fw_dbg_trigger_tlv
*trig
;
930 struct iwl_fw_dbg_trigger_ba
*ba_trig
;
932 trig
= iwl_fw_dbg_trigger_on(&mvm
->fwrt
, ieee80211_vif_to_wdev(vif
),
937 ba_trig
= (void *)trig
->data
;
940 case IEEE80211_AMPDU_TX_OPERATIONAL
: {
941 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
942 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
944 CHECK_BA_TRIGGER(mvm
, trig
, ba_trig
->tx_ba_start
, tid
,
945 "TX AGG START: MAC %pM tid %d ssn %d\n",
946 sta
->addr
, tid
, tid_data
->ssn
);
949 case IEEE80211_AMPDU_TX_STOP_CONT
:
950 CHECK_BA_TRIGGER(mvm
, trig
, ba_trig
->tx_ba_stop
, tid
,
951 "TX AGG STOP: MAC %pM tid %d\n",
954 case IEEE80211_AMPDU_RX_START
:
955 CHECK_BA_TRIGGER(mvm
, trig
, ba_trig
->rx_ba_start
, tid
,
956 "RX AGG START: MAC %pM tid %d ssn %d\n",
957 sta
->addr
, tid
, rx_ba_ssn
);
959 case IEEE80211_AMPDU_RX_STOP
:
960 CHECK_BA_TRIGGER(mvm
, trig
, ba_trig
->rx_ba_stop
, tid
,
961 "RX AGG STOP: MAC %pM tid %d\n",
969 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw
*hw
,
970 struct ieee80211_vif
*vif
,
971 struct ieee80211_ampdu_params
*params
)
973 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
975 struct ieee80211_sta
*sta
= params
->sta
;
976 enum ieee80211_ampdu_mlme_action action
= params
->action
;
977 u16 tid
= params
->tid
;
978 u16
*ssn
= ¶ms
->ssn
;
979 u16 buf_size
= params
->buf_size
;
980 bool amsdu
= params
->amsdu
;
981 u16 timeout
= params
->timeout
;
983 IWL_DEBUG_HT(mvm
, "A-MPDU action on addr %pM tid %d: action %d\n",
984 sta
->addr
, tid
, action
);
986 if (!(mvm
->nvm_data
->sku_cap_11n_enable
))
989 mutex_lock(&mvm
->mutex
);
992 case IEEE80211_AMPDU_RX_START
:
993 if (iwl_mvm_vif_from_mac80211(vif
)->ap_sta_id
==
994 iwl_mvm_sta_from_mac80211(sta
)->sta_id
) {
995 struct iwl_mvm_vif
*mvmvif
;
996 u16 macid
= iwl_mvm_vif_from_mac80211(vif
)->id
;
997 struct iwl_mvm_tcm_mac
*mdata
= &mvm
->tcm
.data
[macid
];
999 mdata
->opened_rx_ba_sessions
= true;
1000 mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1001 cancel_delayed_work(&mvmvif
->uapsd_nonagg_detected_wk
);
1003 if (!iwl_enable_rx_ampdu()) {
1007 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, *ssn
, true, buf_size
,
1010 case IEEE80211_AMPDU_RX_STOP
:
1011 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, 0, false, buf_size
,
1014 case IEEE80211_AMPDU_TX_START
:
1015 if (!iwl_enable_tx_ampdu()) {
1019 ret
= iwl_mvm_sta_tx_agg_start(mvm
, vif
, sta
, tid
, ssn
);
1021 case IEEE80211_AMPDU_TX_STOP_CONT
:
1022 ret
= iwl_mvm_sta_tx_agg_stop(mvm
, vif
, sta
, tid
);
1024 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
1025 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
1026 ret
= iwl_mvm_sta_tx_agg_flush(mvm
, vif
, sta
, tid
);
1028 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1029 ret
= iwl_mvm_sta_tx_agg_oper(mvm
, vif
, sta
, tid
,
1041 if (action
== IEEE80211_AMPDU_RX_START
)
1044 iwl_mvm_ampdu_check_trigger(mvm
, vif
, sta
, tid
,
1047 mutex_unlock(&mvm
->mutex
);
1052 static void iwl_mvm_cleanup_iterator(void *data
, u8
*mac
,
1053 struct ieee80211_vif
*vif
)
1055 struct iwl_mvm
*mvm
= data
;
1056 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1058 mvmvif
->uploaded
= false;
1059 mvmvif
->ap_sta_id
= IWL_MVM_INVALID_STA
;
1061 spin_lock_bh(&mvm
->time_event_lock
);
1062 iwl_mvm_te_clear_data(mvm
, &mvmvif
->time_event_data
);
1063 spin_unlock_bh(&mvm
->time_event_lock
);
1065 mvmvif
->phy_ctxt
= NULL
;
1066 memset(&mvmvif
->bf_data
, 0, sizeof(mvmvif
->bf_data
));
1067 memset(&mvmvif
->probe_resp_data
, 0, sizeof(mvmvif
->probe_resp_data
));
1070 static void iwl_mvm_restart_cleanup(struct iwl_mvm
*mvm
)
1072 iwl_mvm_stop_device(mvm
);
1076 mvm
->scan_status
= 0;
1077 mvm
->ps_disabled
= false;
1078 mvm
->rfkill_safe_init_done
= false;
1080 /* just in case one was running */
1081 iwl_mvm_cleanup_roc_te(mvm
);
1082 ieee80211_remain_on_channel_expired(mvm
->hw
);
1084 iwl_mvm_ftm_restart(mvm
);
1087 * cleanup all interfaces, even inactive ones, as some might have
1088 * gone down during the HW restart
1090 ieee80211_iterate_interfaces(mvm
->hw
, 0, iwl_mvm_cleanup_iterator
, mvm
);
1092 mvm
->p2p_device_vif
= NULL
;
1094 iwl_mvm_reset_phy_ctxts(mvm
);
1095 memset(mvm
->fw_key_table
, 0, sizeof(mvm
->fw_key_table
));
1096 memset(&mvm
->last_bt_notif
, 0, sizeof(mvm
->last_bt_notif
));
1097 memset(&mvm
->last_bt_ci_cmd
, 0, sizeof(mvm
->last_bt_ci_cmd
));
1099 ieee80211_wake_queues(mvm
->hw
);
1102 mvm
->rx_ba_sessions
= 0;
1103 mvm
->fwrt
.dump
.conf
= FW_DBG_INVALID
;
1104 mvm
->monitor_on
= false;
1106 /* keep statistics ticking */
1107 iwl_mvm_accu_radio_stats(mvm
);
1110 int __iwl_mvm_mac_start(struct iwl_mvm
*mvm
)
1114 lockdep_assert_held(&mvm
->mutex
);
1116 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED
, &mvm
->status
)) {
1118 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1119 * so later code will - from now on - see that we're doing it.
1121 set_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
1122 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED
, &mvm
->status
);
1123 /* Clean up some internal and mac80211 state on restart */
1124 iwl_mvm_restart_cleanup(mvm
);
1126 ret
= iwl_mvm_up(mvm
);
1128 iwl_dbg_tlv_time_point(&mvm
->fwrt
, IWL_FW_INI_TIME_POINT_POST_INIT
,
1130 iwl_dbg_tlv_time_point(&mvm
->fwrt
, IWL_FW_INI_TIME_POINT_PERIODIC
,
1133 if (ret
&& test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
1134 /* Something went wrong - we need to finish some cleanup
1135 * that normally iwl_mvm_mac_restart_complete() below
1138 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
1144 static int iwl_mvm_mac_start(struct ieee80211_hw
*hw
)
1146 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1149 mutex_lock(&mvm
->mutex
);
1150 ret
= __iwl_mvm_mac_start(mvm
);
1151 mutex_unlock(&mvm
->mutex
);
1156 static void iwl_mvm_restart_complete(struct iwl_mvm
*mvm
)
1160 mutex_lock(&mvm
->mutex
);
1162 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
1164 ret
= iwl_mvm_update_quotas(mvm
, true, NULL
);
1166 IWL_ERR(mvm
, "Failed to update quotas after restart (%d)\n",
1169 iwl_mvm_send_recovery_cmd(mvm
, ERROR_RECOVERY_END_OF_RECOVERY
);
1172 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1173 * of packets the FW sent out, so we must reconnect.
1175 iwl_mvm_teardown_tdls_peers(mvm
);
1177 mutex_unlock(&mvm
->mutex
);
1181 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw
*hw
,
1182 enum ieee80211_reconfig_type reconfig_type
)
1184 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1186 switch (reconfig_type
) {
1187 case IEEE80211_RECONFIG_TYPE_RESTART
:
1188 iwl_mvm_restart_complete(mvm
);
1190 case IEEE80211_RECONFIG_TYPE_SUSPEND
:
1195 void __iwl_mvm_mac_stop(struct iwl_mvm
*mvm
)
1197 lockdep_assert_held(&mvm
->mutex
);
1199 /* firmware counters are obviously reset now, but we shouldn't
1200 * partially track so also clear the fw_reset_accu counters.
1202 memset(&mvm
->accu_radio_stats
, 0, sizeof(mvm
->accu_radio_stats
));
1204 /* async_handlers_wk is now blocked */
1207 * The work item could be running or queued if the
1208 * ROC time event stops just as we get here.
1210 flush_work(&mvm
->roc_done_wk
);
1212 iwl_mvm_stop_device(mvm
);
1214 iwl_mvm_async_handlers_purge(mvm
);
1215 /* async_handlers_list is empty and will stay empty: HW is stopped */
1217 /* the fw is stopped, the aux sta is dead: clean up driver state */
1218 iwl_mvm_del_aux_sta(mvm
);
1221 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1222 * hw (as restart_complete() won't be called in this case) and mac80211
1223 * won't execute the restart.
1224 * But make sure to cleanup interfaces that have gone down before/during
1225 * HW restart was requested.
1227 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
) ||
1228 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED
,
1230 ieee80211_iterate_interfaces(mvm
->hw
, 0,
1231 iwl_mvm_cleanup_iterator
, mvm
);
1233 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1234 * make sure there's nothing left there and warn if any is found.
1236 if (fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_UMAC_SCAN
)) {
1239 for (i
= 0; i
< mvm
->max_scans
; i
++) {
1240 if (WARN_ONCE(mvm
->scan_uid_status
[i
],
1241 "UMAC scan UID %d status was not cleaned\n",
1243 mvm
->scan_uid_status
[i
] = 0;
1248 static void iwl_mvm_mac_stop(struct ieee80211_hw
*hw
)
1250 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1252 flush_work(&mvm
->async_handlers_wk
);
1253 flush_work(&mvm
->add_stream_wk
);
1256 * Lock and clear the firmware running bit here already, so that
1257 * new commands coming in elsewhere, e.g. from debugfs, will not
1258 * be able to proceed. This is important here because one of those
1259 * debugfs files causes the firmware dump to be triggered, and if we
1260 * don't stop debugfs accesses before canceling that it could be
1261 * retriggered after we flush it but before we've cleared the bit.
1263 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING
, &mvm
->status
);
1265 cancel_delayed_work_sync(&mvm
->cs_tx_unblock_dwork
);
1266 cancel_delayed_work_sync(&mvm
->scan_timeout_dwork
);
1267 iwl_fw_free_dump_desc(&mvm
->fwrt
);
1269 mutex_lock(&mvm
->mutex
);
1270 __iwl_mvm_mac_stop(mvm
);
1271 mutex_unlock(&mvm
->mutex
);
1274 * The worker might have been waiting for the mutex, let it run and
1275 * discover that its list is now empty.
1277 cancel_work_sync(&mvm
->async_handlers_wk
);
1280 static struct iwl_mvm_phy_ctxt
*iwl_mvm_get_free_phy_ctxt(struct iwl_mvm
*mvm
)
1284 lockdep_assert_held(&mvm
->mutex
);
1286 for (i
= 0; i
< NUM_PHY_CTX
; i
++)
1287 if (!mvm
->phy_ctxts
[i
].ref
)
1288 return &mvm
->phy_ctxts
[i
];
1290 IWL_ERR(mvm
, "No available PHY context\n");
1294 static int iwl_mvm_set_tx_power(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1299 struct iwl_dev_tx_power_cmd v5
;
1300 struct iwl_dev_tx_power_cmd_v4 v4
;
1302 .v5
.v3
.set_mode
= cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC
),
1303 .v5
.v3
.mac_context_id
=
1304 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif
)->id
),
1305 .v5
.v3
.pwr_restriction
= cpu_to_le16(8 * tx_power
),
1308 if (tx_power
== IWL_DEFAULT_MAX_TX_POWER
)
1309 cmd
.v5
.v3
.pwr_restriction
= cpu_to_le16(IWL_DEV_MAX_TX_POWER
);
1311 if (fw_has_api(&mvm
->fw
->ucode_capa
,
1312 IWL_UCODE_TLV_API_REDUCE_TX_POWER
))
1313 len
= sizeof(cmd
.v5
);
1314 else if (fw_has_capa(&mvm
->fw
->ucode_capa
,
1315 IWL_UCODE_TLV_CAPA_TX_POWER_ACK
))
1316 len
= sizeof(cmd
.v4
);
1318 len
= sizeof(cmd
.v4
.v3
);
1320 return iwl_mvm_send_cmd_pdu(mvm
, REDUCE_TX_POWER_CMD
, 0, len
, &cmd
);
1323 static int iwl_mvm_post_channel_switch(struct ieee80211_hw
*hw
,
1324 struct ieee80211_vif
*vif
)
1326 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1327 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1330 mutex_lock(&mvm
->mutex
);
1332 if (mvmvif
->csa_failed
) {
1333 mvmvif
->csa_failed
= false;
1338 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1339 struct iwl_mvm_sta
*mvmsta
;
1341 mvmvif
->csa_bcn_pending
= false;
1342 mvmsta
= iwl_mvm_sta_from_staid_protected(mvm
,
1345 if (WARN_ON(!mvmsta
)) {
1350 if (!fw_has_capa(&mvm
->fw
->ucode_capa
,
1351 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD
))
1352 iwl_mvm_sta_modify_disable_tx(mvm
, mvmsta
, false);
1354 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
1356 if (!fw_has_capa(&mvm
->fw
->ucode_capa
,
1357 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD
)) {
1358 ret
= iwl_mvm_enable_beacon_filter(mvm
, vif
, 0);
1362 iwl_mvm_stop_session_protection(mvm
, vif
);
1366 mvmvif
->ps_disabled
= false;
1368 ret
= iwl_mvm_power_update_ps(mvm
);
1371 mutex_unlock(&mvm
->mutex
);
1376 static void iwl_mvm_abort_channel_switch(struct ieee80211_hw
*hw
,
1377 struct ieee80211_vif
*vif
)
1379 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1380 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1381 struct iwl_chan_switch_te_cmd cmd
= {
1382 .mac_id
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->id
,
1384 .action
= cpu_to_le32(FW_CTXT_ACTION_REMOVE
),
1387 IWL_DEBUG_MAC80211(mvm
, "Abort CSA on mac %d\n", mvmvif
->id
);
1389 mutex_lock(&mvm
->mutex
);
1390 WARN_ON(iwl_mvm_send_cmd_pdu(mvm
,
1391 WIDE_ID(MAC_CONF_GROUP
,
1392 CHANNEL_SWITCH_TIME_EVENT_CMD
),
1393 0, sizeof(cmd
), &cmd
));
1394 mutex_unlock(&mvm
->mutex
);
1396 WARN_ON(iwl_mvm_post_channel_switch(hw
, vif
));
1399 static void iwl_mvm_channel_switch_disconnect_wk(struct work_struct
*wk
)
1401 struct iwl_mvm
*mvm
;
1402 struct iwl_mvm_vif
*mvmvif
;
1403 struct ieee80211_vif
*vif
;
1405 mvmvif
= container_of(wk
, struct iwl_mvm_vif
, csa_work
.work
);
1406 vif
= container_of((void *)mvmvif
, struct ieee80211_vif
, drv_priv
);
1409 iwl_mvm_abort_channel_switch(mvm
->hw
, vif
);
1410 ieee80211_chswitch_done(vif
, false);
1413 static int iwl_mvm_mac_add_interface(struct ieee80211_hw
*hw
,
1414 struct ieee80211_vif
*vif
)
1416 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1417 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1421 RCU_INIT_POINTER(mvmvif
->probe_resp_data
, NULL
);
1424 * Not much to do here. The stack will not allow interface
1425 * types or combinations that we didn't advertise, so we
1426 * don't really have to check the types.
1429 mutex_lock(&mvm
->mutex
);
1431 /* make sure that beacon statistics don't go backwards with FW reset */
1432 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
1433 mvmvif
->beacon_stats
.accu_num_beacons
+=
1434 mvmvif
->beacon_stats
.num_beacons
;
1436 /* Allocate resources for the MAC context, and add it to the fw */
1437 ret
= iwl_mvm_mac_ctxt_init(mvm
, vif
);
1441 rcu_assign_pointer(mvm
->vif_id_to_mac
[mvmvif
->id
], vif
);
1443 /* Counting number of interfaces is needed for legacy PM */
1444 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
1448 * The AP binding flow can be done only after the beacon
1449 * template is configured (which happens only in the mac80211
1450 * start_ap() flow), and adding the broadcast station can happen
1451 * only after the binding.
1452 * In addition, since modifying the MAC before adding a bcast
1453 * station is not allowed by the FW, delay the adding of MAC context to
1454 * the point where we can also add the bcast station.
1455 * In short: there's not much we can do at this point, other than
1456 * allocating resources :)
1458 if (vif
->type
== NL80211_IFTYPE_AP
||
1459 vif
->type
== NL80211_IFTYPE_ADHOC
) {
1460 ret
= iwl_mvm_alloc_bcast_sta(mvm
, vif
);
1462 IWL_ERR(mvm
, "Failed to allocate bcast sta\n");
1467 * Only queue for this station is the mcast queue,
1468 * which shouldn't be in TFD mask anyway
1470 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->mcast_sta
,
1476 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
1480 mvmvif
->features
|= hw
->netdev_features
;
1482 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
1486 ret
= iwl_mvm_power_update_mac(mvm
);
1488 goto out_remove_mac
;
1490 /* beacon filtering */
1491 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
, 0);
1493 goto out_remove_mac
;
1495 if (!mvm
->bf_allowed_vif
&&
1496 vif
->type
== NL80211_IFTYPE_STATION
&& !vif
->p2p
) {
1497 mvm
->bf_allowed_vif
= mvmvif
;
1498 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
|
1499 IEEE80211_VIF_SUPPORTS_CQM_RSSI
;
1503 * P2P_DEVICE interface does not have a channel context assigned to it,
1504 * so a dedicated PHY context is allocated to it and the corresponding
1505 * MAC context is bound to it at this stage.
1507 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1509 mvmvif
->phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1510 if (!mvmvif
->phy_ctxt
) {
1515 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1516 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1520 ret
= iwl_mvm_add_p2p_bcast_sta(mvm
, vif
);
1524 /* Save a pointer to p2p device vif, so it can later be used to
1525 * update the p2p device MAC when a GO is started/stopped */
1526 mvm
->p2p_device_vif
= vif
;
1529 iwl_mvm_tcm_add_vif(mvm
, vif
);
1530 INIT_DELAYED_WORK(&mvmvif
->csa_work
,
1531 iwl_mvm_channel_switch_disconnect_wk
);
1533 if (vif
->type
== NL80211_IFTYPE_MONITOR
)
1534 mvm
->monitor_on
= true;
1536 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
1540 iwl_mvm_binding_remove_vif(mvm
, vif
);
1542 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1544 if (mvm
->bf_allowed_vif
== mvmvif
) {
1545 mvm
->bf_allowed_vif
= NULL
;
1546 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
1547 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
1550 mvmvif
->phy_ctxt
= NULL
;
1551 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
1553 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
1556 mutex_unlock(&mvm
->mutex
);
1561 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm
*mvm
,
1562 struct ieee80211_vif
*vif
)
1564 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1566 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1567 * We assume here that all the packets sent to the OFFCHANNEL
1568 * queue are sent in ROC session.
1570 flush_work(&mvm
->roc_done_wk
);
1574 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw
*hw
,
1575 struct ieee80211_vif
*vif
)
1577 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1578 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1579 struct iwl_probe_resp_data
*probe_data
;
1581 iwl_mvm_prepare_mac_removal(mvm
, vif
);
1583 if (!(vif
->type
== NL80211_IFTYPE_AP
||
1584 vif
->type
== NL80211_IFTYPE_ADHOC
))
1585 iwl_mvm_tcm_rm_vif(mvm
, vif
);
1587 mutex_lock(&mvm
->mutex
);
1589 probe_data
= rcu_dereference_protected(mvmvif
->probe_resp_data
,
1590 lockdep_is_held(&mvm
->mutex
));
1591 RCU_INIT_POINTER(mvmvif
->probe_resp_data
, NULL
);
1593 kfree_rcu(probe_data
, rcu_head
);
1595 if (mvm
->bf_allowed_vif
== mvmvif
) {
1596 mvm
->bf_allowed_vif
= NULL
;
1597 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
1598 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
1601 if (vif
->bss_conf
.ftm_responder
)
1602 memset(&mvm
->ftm_resp_stats
, 0, sizeof(mvm
->ftm_resp_stats
));
1604 iwl_mvm_vif_dbgfs_clean(mvm
, vif
);
1607 * For AP/GO interface, the tear down of the resources allocated to the
1608 * interface is be handled as part of the stop_ap flow.
1610 if (vif
->type
== NL80211_IFTYPE_AP
||
1611 vif
->type
== NL80211_IFTYPE_ADHOC
) {
1612 #ifdef CONFIG_NL80211_TESTMODE
1613 if (vif
== mvm
->noa_vif
) {
1614 mvm
->noa_vif
= NULL
;
1615 mvm
->noa_duration
= 0;
1618 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->mcast_sta
);
1619 iwl_mvm_dealloc_bcast_sta(mvm
, vif
);
1623 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1624 mvm
->p2p_device_vif
= NULL
;
1625 iwl_mvm_rm_p2p_bcast_sta(mvm
, vif
);
1626 iwl_mvm_binding_remove_vif(mvm
, vif
);
1627 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1628 mvmvif
->phy_ctxt
= NULL
;
1631 if (mvm
->vif_count
&& vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
1634 iwl_mvm_power_update_mac(mvm
);
1635 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
1637 RCU_INIT_POINTER(mvm
->vif_id_to_mac
[mvmvif
->id
], NULL
);
1639 if (vif
->type
== NL80211_IFTYPE_MONITOR
)
1640 mvm
->monitor_on
= false;
1643 mutex_unlock(&mvm
->mutex
);
1646 static int iwl_mvm_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
1651 struct iwl_mvm_mc_iter_data
{
1652 struct iwl_mvm
*mvm
;
1656 static void iwl_mvm_mc_iface_iterator(void *_data
, u8
*mac
,
1657 struct ieee80211_vif
*vif
)
1659 struct iwl_mvm_mc_iter_data
*data
= _data
;
1660 struct iwl_mvm
*mvm
= data
->mvm
;
1661 struct iwl_mcast_filter_cmd
*cmd
= mvm
->mcast_filter_cmd
;
1662 struct iwl_host_cmd hcmd
= {
1663 .id
= MCAST_FILTER_CMD
,
1665 .dataflags
[0] = IWL_HCMD_DFL_NOCOPY
,
1669 /* if we don't have free ports, mcast frames will be dropped */
1670 if (WARN_ON_ONCE(data
->port_id
>= MAX_PORT_ID_NUM
))
1673 if (vif
->type
!= NL80211_IFTYPE_STATION
||
1674 !vif
->bss_conf
.assoc
)
1677 cmd
->port_id
= data
->port_id
++;
1678 memcpy(cmd
->bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1679 len
= roundup(sizeof(*cmd
) + cmd
->count
* ETH_ALEN
, 4);
1684 ret
= iwl_mvm_send_cmd(mvm
, &hcmd
);
1686 IWL_ERR(mvm
, "mcast filter cmd error. ret=%d\n", ret
);
1689 static void iwl_mvm_recalc_multicast(struct iwl_mvm
*mvm
)
1691 struct iwl_mvm_mc_iter_data iter_data
= {
1695 lockdep_assert_held(&mvm
->mutex
);
1697 if (WARN_ON_ONCE(!mvm
->mcast_filter_cmd
))
1700 ieee80211_iterate_active_interfaces_atomic(
1701 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1702 iwl_mvm_mc_iface_iterator
, &iter_data
);
1705 static u64
iwl_mvm_prepare_multicast(struct ieee80211_hw
*hw
,
1706 struct netdev_hw_addr_list
*mc_list
)
1708 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1709 struct iwl_mcast_filter_cmd
*cmd
;
1710 struct netdev_hw_addr
*addr
;
1715 addr_count
= netdev_hw_addr_list_count(mc_list
);
1716 pass_all
= addr_count
> MAX_MCAST_FILTERING_ADDRESSES
||
1717 IWL_MVM_FW_MCAST_FILTER_PASS_ALL
;
1721 len
= roundup(sizeof(*cmd
) + addr_count
* ETH_ALEN
, 4);
1722 cmd
= kzalloc(len
, GFP_ATOMIC
);
1728 return (u64
)(unsigned long)cmd
;
1731 netdev_hw_addr_list_for_each(addr
, mc_list
) {
1732 IWL_DEBUG_MAC80211(mvm
, "mcast addr (%d): %pM\n",
1733 cmd
->count
, addr
->addr
);
1734 memcpy(&cmd
->addr_list
[cmd
->count
* ETH_ALEN
],
1735 addr
->addr
, ETH_ALEN
);
1739 return (u64
)(unsigned long)cmd
;
1742 static void iwl_mvm_configure_filter(struct ieee80211_hw
*hw
,
1743 unsigned int changed_flags
,
1744 unsigned int *total_flags
,
1747 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1748 struct iwl_mcast_filter_cmd
*cmd
= (void *)(unsigned long)multicast
;
1750 mutex_lock(&mvm
->mutex
);
1752 /* replace previous configuration */
1753 kfree(mvm
->mcast_filter_cmd
);
1754 mvm
->mcast_filter_cmd
= cmd
;
1759 if (changed_flags
& FIF_ALLMULTI
)
1760 cmd
->pass_all
= !!(*total_flags
& FIF_ALLMULTI
);
1765 iwl_mvm_recalc_multicast(mvm
);
1767 mutex_unlock(&mvm
->mutex
);
1771 static void iwl_mvm_config_iface_filter(struct ieee80211_hw
*hw
,
1772 struct ieee80211_vif
*vif
,
1773 unsigned int filter_flags
,
1774 unsigned int changed_flags
)
1776 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1778 /* We support only filter for probe requests */
1779 if (!(changed_flags
& FIF_PROBE_REQ
))
1782 /* Supported only for p2p client interfaces */
1783 if (vif
->type
!= NL80211_IFTYPE_STATION
|| !vif
->bss_conf
.assoc
||
1787 mutex_lock(&mvm
->mutex
);
1788 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
1789 mutex_unlock(&mvm
->mutex
);
1792 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1793 struct iwl_bcast_iter_data
{
1794 struct iwl_mvm
*mvm
;
1795 struct iwl_bcast_filter_cmd
*cmd
;
1800 iwl_mvm_set_bcast_filter(struct ieee80211_vif
*vif
,
1801 const struct iwl_fw_bcast_filter
*in_filter
,
1802 struct iwl_fw_bcast_filter
*out_filter
)
1804 struct iwl_fw_bcast_filter_attr
*attr
;
1807 memcpy(out_filter
, in_filter
, sizeof(*out_filter
));
1809 for (i
= 0; i
< ARRAY_SIZE(out_filter
->attrs
); i
++) {
1810 attr
= &out_filter
->attrs
[i
];
1815 switch (attr
->reserved1
) {
1816 case cpu_to_le16(BC_FILTER_MAGIC_IP
):
1817 if (vif
->bss_conf
.arp_addr_cnt
!= 1) {
1822 attr
->val
= vif
->bss_conf
.arp_addr_list
[0];
1824 case cpu_to_le16(BC_FILTER_MAGIC_MAC
):
1825 attr
->val
= *(__be32
*)&vif
->addr
[2];
1830 attr
->reserved1
= 0;
1831 out_filter
->num_attrs
++;
1835 static void iwl_mvm_bcast_filter_iterator(void *_data
, u8
*mac
,
1836 struct ieee80211_vif
*vif
)
1838 struct iwl_bcast_iter_data
*data
= _data
;
1839 struct iwl_mvm
*mvm
= data
->mvm
;
1840 struct iwl_bcast_filter_cmd
*cmd
= data
->cmd
;
1841 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1842 struct iwl_fw_bcast_mac
*bcast_mac
;
1845 if (WARN_ON(mvmvif
->id
>= ARRAY_SIZE(cmd
->macs
)))
1848 bcast_mac
= &cmd
->macs
[mvmvif
->id
];
1851 * enable filtering only for associated stations, but not for P2P
1854 if (vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
||
1855 !vif
->bss_conf
.assoc
)
1858 bcast_mac
->default_discard
= 1;
1860 /* copy all configured filters */
1861 for (i
= 0; mvm
->bcast_filters
[i
].attrs
[0].mask
; i
++) {
1863 * Make sure we don't exceed our filters limit.
1864 * if there is still a valid filter to be configured,
1865 * be on the safe side and just allow bcast for this mac.
1867 if (WARN_ON_ONCE(data
->current_filter
>=
1868 ARRAY_SIZE(cmd
->filters
))) {
1869 bcast_mac
->default_discard
= 0;
1870 bcast_mac
->attached_filters
= 0;
1874 iwl_mvm_set_bcast_filter(vif
,
1875 &mvm
->bcast_filters
[i
],
1876 &cmd
->filters
[data
->current_filter
]);
1878 /* skip current filter if it contains no attributes */
1879 if (!cmd
->filters
[data
->current_filter
].num_attrs
)
1882 /* attach the filter to current mac */
1883 bcast_mac
->attached_filters
|=
1884 cpu_to_le16(BIT(data
->current_filter
));
1886 data
->current_filter
++;
1890 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm
*mvm
,
1891 struct iwl_bcast_filter_cmd
*cmd
)
1893 struct iwl_bcast_iter_data iter_data
= {
1898 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL
)
1901 memset(cmd
, 0, sizeof(*cmd
));
1902 cmd
->max_bcast_filters
= ARRAY_SIZE(cmd
->filters
);
1903 cmd
->max_macs
= ARRAY_SIZE(cmd
->macs
);
1905 #ifdef CONFIG_IWLWIFI_DEBUGFS
1906 /* use debugfs filters/macs if override is configured */
1907 if (mvm
->dbgfs_bcast_filtering
.override
) {
1908 memcpy(cmd
->filters
, &mvm
->dbgfs_bcast_filtering
.cmd
.filters
,
1909 sizeof(cmd
->filters
));
1910 memcpy(cmd
->macs
, &mvm
->dbgfs_bcast_filtering
.cmd
.macs
,
1916 /* if no filters are configured, do nothing */
1917 if (!mvm
->bcast_filters
)
1920 /* configure and attach these filters for each associated sta vif */
1921 ieee80211_iterate_active_interfaces(
1922 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1923 iwl_mvm_bcast_filter_iterator
, &iter_data
);
1928 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm
*mvm
)
1930 struct iwl_bcast_filter_cmd cmd
;
1932 if (!(mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BCAST_FILTERING
))
1935 if (!iwl_mvm_bcast_filter_build_cmd(mvm
, &cmd
))
1938 return iwl_mvm_send_cmd_pdu(mvm
, BCAST_FILTER_CMD
, 0,
1942 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm
*mvm
)
1948 static int iwl_mvm_update_mu_groups(struct iwl_mvm
*mvm
,
1949 struct ieee80211_vif
*vif
)
1951 struct iwl_mu_group_mgmt_cmd cmd
= {};
1953 memcpy(cmd
.membership_status
, vif
->bss_conf
.mu_group
.membership
,
1954 WLAN_MEMBERSHIP_LEN
);
1955 memcpy(cmd
.user_position
, vif
->bss_conf
.mu_group
.position
,
1956 WLAN_USER_POSITION_LEN
);
1958 return iwl_mvm_send_cmd_pdu(mvm
,
1959 WIDE_ID(DATA_PATH_GROUP
,
1960 UPDATE_MU_GROUPS_CMD
),
1961 0, sizeof(cmd
), &cmd
);
1964 static void iwl_mvm_mu_mimo_iface_iterator(void *_data
, u8
*mac
,
1965 struct ieee80211_vif
*vif
)
1967 if (vif
->mu_mimo_owner
) {
1968 struct iwl_mu_group_mgmt_notif
*notif
= _data
;
1971 * MU-MIMO Group Id action frame is little endian. We treat
1972 * the data received from firmware as if it came from the
1973 * action frame, so no conversion is needed.
1975 ieee80211_update_mu_groups(vif
,
1976 (u8
*)¬if
->membership_status
,
1977 (u8
*)¬if
->user_position
);
1981 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm
*mvm
,
1982 struct iwl_rx_cmd_buffer
*rxb
)
1984 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1985 struct iwl_mu_group_mgmt_notif
*notif
= (void *)pkt
->data
;
1987 ieee80211_iterate_active_interfaces_atomic(
1988 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1989 iwl_mvm_mu_mimo_iface_iterator
, notif
);
1992 static u8
iwl_mvm_he_get_ppe_val(u8
*ppe
, u8 ppe_pos_bit
)
1994 u8 byte_num
= ppe_pos_bit
/ 8;
1995 u8 bit_num
= ppe_pos_bit
% 8;
2000 return (ppe
[byte_num
] >> bit_num
) &
2001 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE
) - 1);
2004 * If bit_num > 5, we have to combine bits with next byte.
2005 * Calculate how many bits we need to take from current byte (called
2006 * here "residue_bits"), and add them to bits from next byte.
2009 residue_bits
= 8 - bit_num
;
2011 res
= (ppe
[byte_num
+ 1] &
2012 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE
- residue_bits
) - 1)) <<
2014 res
+= (ppe
[byte_num
] >> bit_num
) & (BIT(residue_bits
) - 1);
2019 static void iwl_mvm_cfg_he_sta(struct iwl_mvm
*mvm
,
2020 struct ieee80211_vif
*vif
, u8 sta_id
)
2022 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2023 struct iwl_he_sta_context_cmd sta_ctxt_cmd
= {
2025 .tid_limit
= IWL_MAX_TID_COUNT
,
2026 .bss_color
= vif
->bss_conf
.he_bss_color
.color
,
2027 .htc_trig_based_pkt_ext
= vif
->bss_conf
.htc_trig_based_pkt_ext
,
2028 .frame_time_rts_th
=
2029 cpu_to_le16(vif
->bss_conf
.frame_time_rts_th
),
2031 int size
= fw_has_api(&mvm
->fw
->ucode_capa
,
2032 IWL_UCODE_TLV_API_MBSSID_HE
) ?
2033 sizeof(sta_ctxt_cmd
) :
2034 sizeof(struct iwl_he_sta_context_cmd_v1
);
2035 struct ieee80211_sta
*sta
;
2041 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_ctxt_cmd
.sta_id
]);
2042 if (IS_ERR_OR_NULL(sta
)) {
2044 WARN(1, "Can't find STA to configure HE\n");
2048 if (!sta
->he_cap
.has_he
) {
2055 /* Block 26-tone RU OFDMA transmissions */
2056 if (mvmvif
->he_ru_2mhz_block
)
2057 flags
|= STA_CTXT_HE_RU_2MHZ_BLOCK
;
2060 if (sta
->he_cap
.he_cap_elem
.mac_cap_info
[0] &
2061 IEEE80211_HE_MAC_CAP0_HTC_HE
)
2062 sta_ctxt_cmd
.htc_flags
|= cpu_to_le32(IWL_HE_HTC_SUPPORT
);
2063 if ((sta
->he_cap
.he_cap_elem
.mac_cap_info
[1] &
2064 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION
) ||
2065 (sta
->he_cap
.he_cap_elem
.mac_cap_info
[2] &
2066 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION
)) {
2068 ((sta
->he_cap
.he_cap_elem
.mac_cap_info
[2] &
2069 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION
) << 1) +
2070 (sta
->he_cap
.he_cap_elem
.mac_cap_info
[1] &
2071 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION
);
2074 sta_ctxt_cmd
.htc_flags
|=
2075 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED
);
2076 else if (link_adap
== 3)
2077 sta_ctxt_cmd
.htc_flags
|=
2078 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH
);
2080 if (sta
->he_cap
.he_cap_elem
.mac_cap_info
[2] & IEEE80211_HE_MAC_CAP2_BSR
)
2081 sta_ctxt_cmd
.htc_flags
|= cpu_to_le32(IWL_HE_HTC_BSR_SUPP
);
2082 if (sta
->he_cap
.he_cap_elem
.mac_cap_info
[3] &
2083 IEEE80211_HE_MAC_CAP3_OMI_CONTROL
)
2084 sta_ctxt_cmd
.htc_flags
|= cpu_to_le32(IWL_HE_HTC_OMI_SUPP
);
2085 if (sta
->he_cap
.he_cap_elem
.mac_cap_info
[4] & IEEE80211_HE_MAC_CAP4_BQR
)
2086 sta_ctxt_cmd
.htc_flags
|= cpu_to_le32(IWL_HE_HTC_BQR_SUPP
);
2089 * Initialize the PPE thresholds to "None" (7), as described in Table
2090 * 9-262ac of 80211.ax/D3.0.
2092 memset(&sta_ctxt_cmd
.pkt_ext
, 7, sizeof(sta_ctxt_cmd
.pkt_ext
));
2094 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2095 if (sta
->he_cap
.he_cap_elem
.phy_cap_info
[6] &
2096 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT
) {
2097 u8 nss
= (sta
->he_cap
.ppe_thres
[0] &
2098 IEEE80211_PPE_THRES_NSS_MASK
) + 1;
2099 u8 ru_index_bitmap
=
2100 (sta
->he_cap
.ppe_thres
[0] &
2101 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK
) >>
2102 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS
;
2103 u8
*ppe
= &sta
->he_cap
.ppe_thres
[0];
2104 u8 ppe_pos_bit
= 7; /* Starting after PPE header */
2107 * FW currently supports only nss == MAX_HE_SUPP_NSS
2109 * If nss > MAX: we can ignore values we don't support
2110 * If nss < MAX: we can set zeros in other streams
2112 if (nss
> MAX_HE_SUPP_NSS
) {
2113 IWL_INFO(mvm
, "Got NSS = %d - trimming to %d\n", nss
,
2115 nss
= MAX_HE_SUPP_NSS
;
2118 for (i
= 0; i
< nss
; i
++) {
2119 u8 ru_index_tmp
= ru_index_bitmap
<< 1;
2122 for (bw
= 0; bw
< MAX_HE_CHANNEL_BW_INDX
; bw
++) {
2124 if (!(ru_index_tmp
& 1))
2127 sta_ctxt_cmd
.pkt_ext
.pkt_ext_qam_th
[i
][bw
][1] =
2128 iwl_mvm_he_get_ppe_val(ppe
,
2131 IEEE80211_PPE_THRES_INFO_PPET_SIZE
;
2132 sta_ctxt_cmd
.pkt_ext
.pkt_ext_qam_th
[i
][bw
][0] =
2133 iwl_mvm_he_get_ppe_val(ppe
,
2136 IEEE80211_PPE_THRES_INFO_PPET_SIZE
;
2140 flags
|= STA_CTXT_HE_PACKET_EXT
;
2141 } else if ((sta
->he_cap
.he_cap_elem
.phy_cap_info
[9] &
2142 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK
) !=
2143 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_RESERVED
) {
2147 /* Take the PPE thresholds from the nominal padding info */
2148 switch (sta
->he_cap
.he_cap_elem
.phy_cap_info
[9] &
2149 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK
) {
2150 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_0US
:
2151 low_th
= IWL_HE_PKT_EXT_NONE
;
2152 high_th
= IWL_HE_PKT_EXT_NONE
;
2154 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_8US
:
2155 low_th
= IWL_HE_PKT_EXT_BPSK
;
2156 high_th
= IWL_HE_PKT_EXT_NONE
;
2158 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_16US
:
2159 low_th
= IWL_HE_PKT_EXT_NONE
;
2160 high_th
= IWL_HE_PKT_EXT_BPSK
;
2164 /* Set the PPE thresholds accordingly */
2165 if (low_th
>= 0 && high_th
>= 0) {
2166 struct iwl_he_pkt_ext
*pkt_ext
=
2167 (struct iwl_he_pkt_ext
*)&sta_ctxt_cmd
.pkt_ext
;
2169 for (i
= 0; i
< MAX_HE_SUPP_NSS
; i
++) {
2172 for (bw
= 0; bw
< MAX_HE_CHANNEL_BW_INDX
;
2174 pkt_ext
->pkt_ext_qam_th
[i
][bw
][0] =
2176 pkt_ext
->pkt_ext_qam_th
[i
][bw
][1] =
2181 flags
|= STA_CTXT_HE_PACKET_EXT
;
2186 /* Mark MU EDCA as enabled, unless none detected on some AC */
2187 flags
|= STA_CTXT_HE_MU_EDCA_CW
;
2188 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++) {
2189 struct ieee80211_he_mu_edca_param_ac_rec
*mu_edca
=
2190 &mvmvif
->queue_params
[i
].mu_edca_param_rec
;
2191 u8 ac
= iwl_mvm_mac80211_ac_to_ucode_ac(i
);
2193 if (!mvmvif
->queue_params
[i
].mu_edca
) {
2194 flags
&= ~STA_CTXT_HE_MU_EDCA_CW
;
2198 sta_ctxt_cmd
.trig_based_txf
[ac
].cwmin
=
2199 cpu_to_le16(mu_edca
->ecw_min_max
& 0xf);
2200 sta_ctxt_cmd
.trig_based_txf
[ac
].cwmax
=
2201 cpu_to_le16((mu_edca
->ecw_min_max
& 0xf0) >> 4);
2202 sta_ctxt_cmd
.trig_based_txf
[ac
].aifsn
=
2203 cpu_to_le16(mu_edca
->aifsn
);
2204 sta_ctxt_cmd
.trig_based_txf
[ac
].mu_time
=
2205 cpu_to_le16(mu_edca
->mu_edca_timer
);
2208 if (vif
->bss_conf
.multi_sta_back_32bit
)
2209 flags
|= STA_CTXT_HE_32BIT_BA_BITMAP
;
2211 if (vif
->bss_conf
.ack_enabled
)
2212 flags
|= STA_CTXT_HE_ACK_ENABLED
;
2214 if (vif
->bss_conf
.uora_exists
) {
2215 flags
|= STA_CTXT_HE_TRIG_RND_ALLOC
;
2217 sta_ctxt_cmd
.rand_alloc_ecwmin
=
2218 vif
->bss_conf
.uora_ocw_range
& 0x7;
2219 sta_ctxt_cmd
.rand_alloc_ecwmax
=
2220 (vif
->bss_conf
.uora_ocw_range
>> 3) & 0x7;
2223 if (vif
->bss_conf
.nontransmitted
) {
2224 flags
|= STA_CTXT_HE_REF_BSSID_VALID
;
2225 ether_addr_copy(sta_ctxt_cmd
.ref_bssid_addr
,
2226 vif
->bss_conf
.transmitter_bssid
);
2227 sta_ctxt_cmd
.max_bssid_indicator
=
2228 vif
->bss_conf
.bssid_indicator
;
2229 sta_ctxt_cmd
.bssid_index
= vif
->bss_conf
.bssid_index
;
2230 sta_ctxt_cmd
.ema_ap
= vif
->bss_conf
.ema_ap
;
2231 sta_ctxt_cmd
.profile_periodicity
=
2232 vif
->bss_conf
.profile_periodicity
;
2235 sta_ctxt_cmd
.flags
= cpu_to_le32(flags
);
2237 if (iwl_mvm_send_cmd_pdu(mvm
, iwl_cmd_id(STA_HE_CTXT_CMD
,
2238 DATA_PATH_GROUP
, 0),
2239 0, size
, &sta_ctxt_cmd
))
2240 IWL_ERR(mvm
, "Failed to config FW to work HE!\n");
2243 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm
*mvm
,
2244 struct ieee80211_vif
*vif
,
2245 struct ieee80211_bss_conf
*bss_conf
,
2248 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2252 * Re-calculate the tsf id, as the master-slave relations depend on the
2253 * beacon interval, which was not known when the station interface was
2256 if (changes
& BSS_CHANGED_ASSOC
&& bss_conf
->assoc
) {
2257 if (vif
->bss_conf
.he_support
&&
2258 !iwlwifi_mod_params
.disable_11ax
)
2259 iwl_mvm_cfg_he_sta(mvm
, vif
, mvmvif
->ap_sta_id
);
2261 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm
, vif
);
2264 /* Update MU EDCA params */
2265 if (changes
& BSS_CHANGED_QOS
&& mvmvif
->associated
&&
2266 bss_conf
->assoc
&& vif
->bss_conf
.he_support
&&
2267 !iwlwifi_mod_params
.disable_11ax
)
2268 iwl_mvm_cfg_he_sta(mvm
, vif
, mvmvif
->ap_sta_id
);
2271 * If we're not associated yet, take the (new) BSSID before associating
2272 * so the firmware knows. If we're already associated, then use the old
2273 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2274 * branch for disassociation below.
2276 if (changes
& BSS_CHANGED_BSSID
&& !mvmvif
->associated
)
2277 memcpy(mvmvif
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
2279 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, mvmvif
->bssid
);
2281 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
2283 /* after sending it once, adopt mac80211 data */
2284 memcpy(mvmvif
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
2285 mvmvif
->associated
= bss_conf
->assoc
;
2287 if (changes
& BSS_CHANGED_ASSOC
) {
2288 if (bss_conf
->assoc
) {
2289 /* clear statistics to get clean beacon counter */
2290 iwl_mvm_request_statistics(mvm
, true);
2291 memset(&mvmvif
->beacon_stats
, 0,
2292 sizeof(mvmvif
->beacon_stats
));
2294 /* add quota for this interface */
2295 ret
= iwl_mvm_update_quotas(mvm
, true, NULL
);
2297 IWL_ERR(mvm
, "failed to update quotas\n");
2301 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
,
2303 !fw_has_capa(&mvm
->fw
->ucode_capa
,
2304 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD
)) {
2306 * If we're restarting then the firmware will
2307 * obviously have lost synchronisation with
2308 * the AP. It will attempt to synchronise by
2309 * itself, but we can make it more reliable by
2310 * scheduling a session protection time event.
2312 * The firmware needs to receive a beacon to
2313 * catch up with synchronisation, use 110% of
2314 * the beacon interval.
2316 * Set a large maximum delay to allow for more
2317 * than a single interface.
2319 * For new firmware versions, rely on the
2320 * firmware. This is relevant for DCM scenarios
2323 u32 dur
= (11 * vif
->bss_conf
.beacon_int
) / 10;
2324 iwl_mvm_protect_session(mvm
, vif
, dur
, dur
,
2328 iwl_mvm_sf_update(mvm
, vif
, false);
2329 iwl_mvm_power_vif_assoc(mvm
, vif
);
2331 iwl_mvm_update_smps(mvm
, vif
,
2332 IWL_MVM_SMPS_REQ_PROT
,
2333 IEEE80211_SMPS_DYNAMIC
);
2335 } else if (mvmvif
->ap_sta_id
!= IWL_MVM_INVALID_STA
) {
2337 * If update fails - SF might be running in associated
2338 * mode while disassociated - which is forbidden.
2340 ret
= iwl_mvm_sf_update(mvm
, vif
, false);
2342 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED
,
2344 "Failed to update SF upon disassociation\n");
2347 * If we get an assert during the connection (after the
2348 * station has been added, but before the vif is set
2349 * to associated), mac80211 will re-add the station and
2350 * then configure the vif. Since the vif is not
2351 * associated, we would remove the station here and
2352 * this would fail the recovery.
2354 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
,
2357 * Remove AP station now that
2358 * the MAC is unassoc
2360 ret
= iwl_mvm_rm_sta_id(mvm
, vif
,
2364 "failed to remove AP station\n");
2366 mvmvif
->ap_sta_id
= IWL_MVM_INVALID_STA
;
2369 /* remove quota for this interface */
2370 ret
= iwl_mvm_update_quotas(mvm
, false, NULL
);
2372 IWL_ERR(mvm
, "failed to update quotas\n");
2374 /* this will take the cleared BSSID from bss_conf */
2375 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
2378 "failed to update MAC %pM (clear after unassoc)\n",
2383 * The firmware tracks the MU-MIMO group on its own.
2384 * However, on HW restart we should restore this data.
2386 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
) &&
2387 (changes
& BSS_CHANGED_MU_GROUPS
) && vif
->mu_mimo_owner
) {
2388 ret
= iwl_mvm_update_mu_groups(mvm
, vif
);
2391 "failed to update VHT MU_MIMO groups\n");
2394 iwl_mvm_recalc_multicast(mvm
);
2395 iwl_mvm_configure_bcast_filter(mvm
);
2397 /* reset rssi values */
2398 mvmvif
->bf_data
.ave_beacon_signal
= 0;
2400 iwl_mvm_bt_coex_vif_change(mvm
);
2401 iwl_mvm_update_smps(mvm
, vif
, IWL_MVM_SMPS_REQ_TT
,
2402 IEEE80211_SMPS_AUTOMATIC
);
2403 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
2404 IWL_UCODE_TLV_CAPA_UMAC_SCAN
))
2405 iwl_mvm_config_scan(mvm
);
2408 if (changes
& BSS_CHANGED_BEACON_INFO
) {
2410 * We received a beacon from the associated AP so
2411 * remove the session protection.
2412 * A firmware with the new API will remove it automatically.
2414 if (!fw_has_capa(&mvm
->fw
->ucode_capa
,
2415 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD
))
2416 iwl_mvm_stop_session_protection(mvm
, vif
);
2418 iwl_mvm_sf_update(mvm
, vif
, false);
2419 WARN_ON(iwl_mvm_enable_beacon_filter(mvm
, vif
, 0));
2422 if (changes
& (BSS_CHANGED_PS
| BSS_CHANGED_P2P_PS
| BSS_CHANGED_QOS
|
2424 * Send power command on every beacon change,
2425 * because we may have not enabled beacon abort yet.
2427 BSS_CHANGED_BEACON_INFO
)) {
2428 ret
= iwl_mvm_power_update_mac(mvm
);
2430 IWL_ERR(mvm
, "failed to update power mode\n");
2433 if (changes
& BSS_CHANGED_TXPOWER
) {
2434 IWL_DEBUG_CALIB(mvm
, "Changing TX Power to %d\n",
2436 iwl_mvm_set_tx_power(mvm
, vif
, bss_conf
->txpower
);
2439 if (changes
& BSS_CHANGED_CQM
) {
2440 IWL_DEBUG_MAC80211(mvm
, "cqm info_changed\n");
2441 /* reset cqm events tracking */
2442 mvmvif
->bf_data
.last_cqm_event
= 0;
2443 if (mvmvif
->bf_data
.bf_enabled
) {
2444 ret
= iwl_mvm_enable_beacon_filter(mvm
, vif
, 0);
2447 "failed to update CQM thresholds\n");
2451 if (changes
& BSS_CHANGED_ARP_FILTER
) {
2452 IWL_DEBUG_MAC80211(mvm
, "arp filter changed\n");
2453 iwl_mvm_configure_bcast_filter(mvm
);
2457 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw
*hw
,
2458 struct ieee80211_vif
*vif
)
2460 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2461 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2464 mutex_lock(&mvm
->mutex
);
2466 /* Send the beacon template */
2467 ret
= iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
);
2472 * Re-calculate the tsf id, as the master-slave relations depend on the
2473 * beacon interval, which was not known when the AP interface was added.
2475 if (vif
->type
== NL80211_IFTYPE_AP
)
2476 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm
, vif
);
2478 mvmvif
->ap_assoc_sta_count
= 0;
2480 /* Add the mac context */
2481 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
2485 /* Perform the binding */
2486 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
2491 * This is not very nice, but the simplest:
2492 * For older FWs adding the mcast sta before the bcast station may
2493 * cause assert 0x2b00.
2494 * This is fixed in later FW so make the order of removal depend on
2497 if (fw_has_api(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_API_STA_TYPE
)) {
2498 ret
= iwl_mvm_add_mcast_sta(mvm
, vif
);
2502 * Send the bcast station. At this stage the TBTT and DTIM time
2503 * events are added and applied to the scheduler
2505 ret
= iwl_mvm_send_add_bcast_sta(mvm
, vif
);
2507 iwl_mvm_rm_mcast_sta(mvm
, vif
);
2512 * Send the bcast station. At this stage the TBTT and DTIM time
2513 * events are added and applied to the scheduler
2515 ret
= iwl_mvm_send_add_bcast_sta(mvm
, vif
);
2518 ret
= iwl_mvm_add_mcast_sta(mvm
, vif
);
2520 iwl_mvm_send_rm_bcast_sta(mvm
, vif
);
2525 /* must be set before quota calculations */
2526 mvmvif
->ap_ibss_active
= true;
2528 /* send all the early keys to the device now */
2529 for (i
= 0; i
< ARRAY_SIZE(mvmvif
->ap_early_keys
); i
++) {
2530 struct ieee80211_key_conf
*key
= mvmvif
->ap_early_keys
[i
];
2535 mvmvif
->ap_early_keys
[i
] = NULL
;
2537 ret
= __iwl_mvm_mac_set_key(hw
, SET_KEY
, vif
, NULL
, key
);
2539 goto out_quota_failed
;
2542 if (vif
->type
== NL80211_IFTYPE_AP
&& !vif
->p2p
) {
2543 iwl_mvm_vif_set_low_latency(mvmvif
, true,
2544 LOW_LATENCY_VIF_TYPE
);
2545 iwl_mvm_send_low_latency_cmd(mvm
, true, mvmvif
->id
);
2548 /* power updated needs to be done before quotas */
2549 iwl_mvm_power_update_mac(mvm
);
2551 ret
= iwl_mvm_update_quotas(mvm
, false, NULL
);
2553 goto out_quota_failed
;
2555 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2556 if (vif
->p2p
&& mvm
->p2p_device_vif
)
2557 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
, false, NULL
);
2559 iwl_mvm_bt_coex_vif_change(mvm
);
2561 /* we don't support TDLS during DCM */
2562 if (iwl_mvm_phy_ctx_count(mvm
) > 1)
2563 iwl_mvm_teardown_tdls_peers(mvm
);
2565 iwl_mvm_ftm_restart_responder(mvm
, vif
);
2570 iwl_mvm_power_update_mac(mvm
);
2571 mvmvif
->ap_ibss_active
= false;
2572 iwl_mvm_send_rm_bcast_sta(mvm
, vif
);
2573 iwl_mvm_rm_mcast_sta(mvm
, vif
);
2575 iwl_mvm_binding_remove_vif(mvm
, vif
);
2577 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
2579 mutex_unlock(&mvm
->mutex
);
2583 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw
*hw
,
2584 struct ieee80211_vif
*vif
)
2586 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2587 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2589 iwl_mvm_prepare_mac_removal(mvm
, vif
);
2591 mutex_lock(&mvm
->mutex
);
2593 /* Handle AP stop while in CSA */
2594 if (rcu_access_pointer(mvm
->csa_vif
) == vif
) {
2595 iwl_mvm_remove_time_event(mvm
, mvmvif
,
2596 &mvmvif
->time_event_data
);
2597 RCU_INIT_POINTER(mvm
->csa_vif
, NULL
);
2598 mvmvif
->csa_countdown
= false;
2601 if (rcu_access_pointer(mvm
->csa_tx_blocked_vif
) == vif
) {
2602 RCU_INIT_POINTER(mvm
->csa_tx_blocked_vif
, NULL
);
2603 mvm
->csa_tx_block_bcn_timeout
= 0;
2606 mvmvif
->ap_ibss_active
= false;
2607 mvm
->ap_last_beacon_gp2
= 0;
2609 if (vif
->type
== NL80211_IFTYPE_AP
&& !vif
->p2p
) {
2610 iwl_mvm_vif_set_low_latency(mvmvif
, false,
2611 LOW_LATENCY_VIF_TYPE
);
2612 iwl_mvm_send_low_latency_cmd(mvm
, false, mvmvif
->id
);
2615 iwl_mvm_bt_coex_vif_change(mvm
);
2617 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2618 if (vif
->p2p
&& mvm
->p2p_device_vif
)
2619 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
, false, NULL
);
2621 iwl_mvm_update_quotas(mvm
, false, NULL
);
2624 * This is not very nice, but the simplest:
2625 * For older FWs removing the mcast sta before the bcast station may
2626 * cause assert 0x2b00.
2627 * This is fixed in later FW (which will stop beaconing when removing
2629 * So make the order of removal depend on the TLV
2631 if (!fw_has_api(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_API_STA_TYPE
))
2632 iwl_mvm_rm_mcast_sta(mvm
, vif
);
2633 iwl_mvm_send_rm_bcast_sta(mvm
, vif
);
2634 if (fw_has_api(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_API_STA_TYPE
))
2635 iwl_mvm_rm_mcast_sta(mvm
, vif
);
2636 iwl_mvm_binding_remove_vif(mvm
, vif
);
2638 iwl_mvm_power_update_mac(mvm
);
2640 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
2642 mutex_unlock(&mvm
->mutex
);
2646 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm
*mvm
,
2647 struct ieee80211_vif
*vif
,
2648 struct ieee80211_bss_conf
*bss_conf
,
2651 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2653 /* Changes will be applied when the AP/IBSS is started */
2654 if (!mvmvif
->ap_ibss_active
)
2657 if (changes
& (BSS_CHANGED_ERP_CTS_PROT
| BSS_CHANGED_HT
|
2658 BSS_CHANGED_BANDWIDTH
| BSS_CHANGED_QOS
) &&
2659 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
))
2660 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
2662 /* Need to send a new beacon template to the FW */
2663 if (changes
& BSS_CHANGED_BEACON
&&
2664 iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
))
2665 IWL_WARN(mvm
, "Failed updating beacon data\n");
2667 if (changes
& BSS_CHANGED_TXPOWER
) {
2668 IWL_DEBUG_CALIB(mvm
, "Changing TX Power to %d\n",
2670 iwl_mvm_set_tx_power(mvm
, vif
, bss_conf
->txpower
);
2673 if (changes
& BSS_CHANGED_FTM_RESPONDER
) {
2674 int ret
= iwl_mvm_ftm_start_responder(mvm
, vif
);
2677 IWL_WARN(mvm
, "Failed to enable FTM responder (%d)\n",
2683 static void iwl_mvm_bss_info_changed(struct ieee80211_hw
*hw
,
2684 struct ieee80211_vif
*vif
,
2685 struct ieee80211_bss_conf
*bss_conf
,
2688 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2690 mutex_lock(&mvm
->mutex
);
2692 if (changes
& BSS_CHANGED_IDLE
&& !bss_conf
->idle
)
2693 iwl_mvm_scan_stop(mvm
, IWL_MVM_SCAN_SCHED
, true);
2695 switch (vif
->type
) {
2696 case NL80211_IFTYPE_STATION
:
2697 iwl_mvm_bss_info_changed_station(mvm
, vif
, bss_conf
, changes
);
2699 case NL80211_IFTYPE_AP
:
2700 case NL80211_IFTYPE_ADHOC
:
2701 iwl_mvm_bss_info_changed_ap_ibss(mvm
, vif
, bss_conf
, changes
);
2703 case NL80211_IFTYPE_MONITOR
:
2704 if (changes
& BSS_CHANGED_MU_GROUPS
)
2705 iwl_mvm_update_mu_groups(mvm
, vif
);
2708 /* shouldn't happen */
2712 mutex_unlock(&mvm
->mutex
);
2715 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw
*hw
,
2716 struct ieee80211_vif
*vif
,
2717 struct ieee80211_scan_request
*hw_req
)
2719 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2722 if (hw_req
->req
.n_channels
== 0 ||
2723 hw_req
->req
.n_channels
> mvm
->fw
->ucode_capa
.n_scan_channels
)
2726 mutex_lock(&mvm
->mutex
);
2727 ret
= iwl_mvm_reg_scan_start(mvm
, vif
, &hw_req
->req
, &hw_req
->ies
);
2728 mutex_unlock(&mvm
->mutex
);
2733 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw
*hw
,
2734 struct ieee80211_vif
*vif
)
2736 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2738 mutex_lock(&mvm
->mutex
);
2740 /* Due to a race condition, it's possible that mac80211 asks
2741 * us to stop a hw_scan when it's already stopped. This can
2742 * happen, for instance, if we stopped the scan ourselves,
2743 * called ieee80211_scan_completed() and the userspace called
2744 * cancel scan scan before ieee80211_scan_work() could run.
2745 * To handle that, simply return if the scan is not running.
2747 if (mvm
->scan_status
& IWL_MVM_SCAN_REGULAR
)
2748 iwl_mvm_scan_stop(mvm
, IWL_MVM_SCAN_REGULAR
, true);
2750 mutex_unlock(&mvm
->mutex
);
2754 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw
*hw
,
2755 struct ieee80211_sta
*sta
, u16 tids
,
2757 enum ieee80211_frame_release_type reason
,
2760 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2762 /* Called when we need to transmit (a) frame(s) from mac80211 */
2764 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
,
2765 tids
, more_data
, false);
2769 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw
*hw
,
2770 struct ieee80211_sta
*sta
, u16 tids
,
2772 enum ieee80211_frame_release_type reason
,
2775 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2777 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2779 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
,
2780 tids
, more_data
, true);
2783 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw
*hw
,
2784 enum sta_notify_cmd cmd
,
2785 struct ieee80211_sta
*sta
)
2787 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2788 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
2789 unsigned long txqs
= 0, tids
= 0;
2793 * If we have TVQM then we get too high queue numbers - luckily
2794 * we really shouldn't get here with that because such hardware
2795 * should have firmware supporting buffer station offload.
2797 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm
)))
2800 spin_lock_bh(&mvmsta
->lock
);
2801 for (tid
= 0; tid
< ARRAY_SIZE(mvmsta
->tid_data
); tid
++) {
2802 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
2804 if (tid_data
->txq_id
== IWL_MVM_INVALID_QUEUE
)
2807 __set_bit(tid_data
->txq_id
, &txqs
);
2809 if (iwl_mvm_tid_queued(mvm
, tid_data
) == 0)
2812 __set_bit(tid
, &tids
);
2816 case STA_NOTIFY_SLEEP
:
2817 for_each_set_bit(tid
, &tids
, IWL_MAX_TID_COUNT
)
2818 ieee80211_sta_set_buffered(sta
, tid
, true);
2821 iwl_trans_freeze_txq_timer(mvm
->trans
, txqs
, true);
2823 * The fw updates the STA to be asleep. Tx packets on the Tx
2824 * queues to this station will not be transmitted. The fw will
2825 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2828 case STA_NOTIFY_AWAKE
:
2829 if (WARN_ON(mvmsta
->sta_id
== IWL_MVM_INVALID_STA
))
2833 iwl_trans_freeze_txq_timer(mvm
->trans
, txqs
, false);
2834 iwl_mvm_sta_modify_ps_wake(mvm
, sta
);
2839 spin_unlock_bh(&mvmsta
->lock
);
2842 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw
*hw
,
2843 struct ieee80211_vif
*vif
,
2844 enum sta_notify_cmd cmd
,
2845 struct ieee80211_sta
*sta
)
2847 __iwl_mvm_mac_sta_notify(hw
, cmd
, sta
);
2850 void iwl_mvm_sta_pm_notif(struct iwl_mvm
*mvm
, struct iwl_rx_cmd_buffer
*rxb
)
2852 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
2853 struct iwl_mvm_pm_state_notification
*notif
= (void *)pkt
->data
;
2854 struct ieee80211_sta
*sta
;
2855 struct iwl_mvm_sta
*mvmsta
;
2856 bool sleeping
= (notif
->type
!= IWL_MVM_PM_EVENT_AWAKE
);
2858 if (WARN_ON(notif
->sta_id
>= ARRAY_SIZE(mvm
->fw_id_to_mac_id
)))
2862 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[notif
->sta_id
]);
2863 if (WARN_ON(IS_ERR_OR_NULL(sta
))) {
2868 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
2871 mvmsta
->vif
->type
!= NL80211_IFTYPE_AP
) {
2876 if (mvmsta
->sleeping
!= sleeping
) {
2877 mvmsta
->sleeping
= sleeping
;
2878 __iwl_mvm_mac_sta_notify(mvm
->hw
,
2879 sleeping
? STA_NOTIFY_SLEEP
: STA_NOTIFY_AWAKE
,
2881 ieee80211_sta_ps_transition(sta
, sleeping
);
2885 switch (notif
->type
) {
2886 case IWL_MVM_PM_EVENT_AWAKE
:
2887 case IWL_MVM_PM_EVENT_ASLEEP
:
2889 case IWL_MVM_PM_EVENT_UAPSD
:
2890 ieee80211_sta_uapsd_trigger(sta
, IEEE80211_NUM_TIDS
);
2892 case IWL_MVM_PM_EVENT_PS_POLL
:
2893 ieee80211_sta_pspoll(sta
);
2903 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw
*hw
,
2904 struct ieee80211_vif
*vif
,
2905 struct ieee80211_sta
*sta
)
2907 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2908 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
2911 * This is called before mac80211 does RCU synchronisation,
2912 * so here we already invalidate our internal RCU-protected
2913 * station pointer. The rest of the code will thus no longer
2914 * be able to find the station this way, and we don't rely
2915 * on further RCU synchronisation after the sta_state()
2916 * callback deleted the station.
2918 mutex_lock(&mvm
->mutex
);
2919 if (sta
== rcu_access_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
]))
2920 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
],
2923 mutex_unlock(&mvm
->mutex
);
2926 static void iwl_mvm_check_uapsd(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
2931 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
2932 struct iwl_mvm_tcm_mac
*mdata
;
2934 mdata
= &mvm
->tcm
.data
[iwl_mvm_vif_from_mac80211(vif
)->id
];
2935 ewma_rate_init(&mdata
->uapsd_nonagg_detect
.rate
);
2936 mdata
->opened_rx_ba_sessions
= false;
2939 if (!(mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT
))
2942 if (vif
->p2p
&& !iwl_mvm_is_p2p_scm_uapsd_supported(mvm
)) {
2943 vif
->driver_flags
&= ~IEEE80211_VIF_SUPPORTS_UAPSD
;
2948 (iwlwifi_mod_params
.uapsd_disable
& IWL_DISABLE_UAPSD_BSS
)) {
2949 vif
->driver_flags
&= ~IEEE80211_VIF_SUPPORTS_UAPSD
;
2953 for (i
= 0; i
< IWL_MVM_UAPSD_NOAGG_LIST_LEN
; i
++) {
2954 if (ether_addr_equal(mvm
->uapsd_noagg_bssids
[i
].addr
, bssid
)) {
2955 vif
->driver_flags
&= ~IEEE80211_VIF_SUPPORTS_UAPSD
;
2960 vif
->driver_flags
|= IEEE80211_VIF_SUPPORTS_UAPSD
;
2964 iwl_mvm_tdls_check_trigger(struct iwl_mvm
*mvm
,
2965 struct ieee80211_vif
*vif
, u8
*peer_addr
,
2966 enum nl80211_tdls_operation action
)
2968 struct iwl_fw_dbg_trigger_tlv
*trig
;
2969 struct iwl_fw_dbg_trigger_tdls
*tdls_trig
;
2971 trig
= iwl_fw_dbg_trigger_on(&mvm
->fwrt
, ieee80211_vif_to_wdev(vif
),
2972 FW_DBG_TRIGGER_TDLS
);
2976 tdls_trig
= (void *)trig
->data
;
2978 if (!(tdls_trig
->action_bitmap
& BIT(action
)))
2981 if (tdls_trig
->peer_mode
&&
2982 memcmp(tdls_trig
->peer
, peer_addr
, ETH_ALEN
) != 0)
2985 iwl_fw_dbg_collect_trig(&mvm
->fwrt
, trig
,
2986 "TDLS event occurred, peer %pM, action %d",
2990 struct iwl_mvm_he_obss_narrow_bw_ru_data
{
2994 static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy
*wiphy
,
2995 struct cfg80211_bss
*bss
,
2998 struct iwl_mvm_he_obss_narrow_bw_ru_data
*data
= _data
;
2999 const struct element
*elem
;
3001 elem
= cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY
, bss
->ies
->data
,
3004 if (!elem
|| elem
->datalen
< 10 ||
3006 WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT
)) {
3007 data
->tolerated
= false;
3011 static void iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw
*hw
,
3012 struct ieee80211_vif
*vif
)
3014 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3015 struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data
= {
3019 if (!(vif
->bss_conf
.chandef
.chan
->flags
& IEEE80211_CHAN_RADAR
)) {
3020 mvmvif
->he_ru_2mhz_block
= false;
3024 cfg80211_bss_iter(hw
->wiphy
, &vif
->bss_conf
.chandef
,
3025 iwl_mvm_check_he_obss_narrow_bw_ru_iter
,
3029 * If there is at least one AP on radar channel that cannot
3030 * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU.
3032 mvmvif
->he_ru_2mhz_block
= !iter_data
.tolerated
;
3035 static int iwl_mvm_mac_sta_state(struct ieee80211_hw
*hw
,
3036 struct ieee80211_vif
*vif
,
3037 struct ieee80211_sta
*sta
,
3038 enum ieee80211_sta_state old_state
,
3039 enum ieee80211_sta_state new_state
)
3041 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3042 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3043 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
3046 IWL_DEBUG_MAC80211(mvm
, "station %pM state change %d->%d\n",
3047 sta
->addr
, old_state
, new_state
);
3049 /* this would be a mac80211 bug ... but don't crash */
3050 if (WARN_ON_ONCE(!mvmvif
->phy_ctxt
))
3054 * If we are in a STA removal flow and in DQA mode:
3056 * This is after the sync_rcu part, so the queues have already been
3057 * flushed. No more TXs on their way in mac80211's path, and no more in
3059 * Also, we won't be getting any new TX frames for this station.
3060 * What we might have are deferred TX frames that need to be taken care
3063 * Drop any still-queued deferred-frame before removing the STA, and
3064 * make sure the worker is no longer handling frames for this STA.
3066 if (old_state
== IEEE80211_STA_NONE
&&
3067 new_state
== IEEE80211_STA_NOTEXIST
) {
3068 flush_work(&mvm
->add_stream_wk
);
3071 * No need to make sure deferred TX indication is off since the
3072 * worker will already remove it if it was on
3076 mutex_lock(&mvm
->mutex
);
3077 /* track whether or not the station is associated */
3078 mvm_sta
->sta_state
= new_state
;
3080 if (old_state
== IEEE80211_STA_NOTEXIST
&&
3081 new_state
== IEEE80211_STA_NONE
) {
3083 * Firmware bug - it'll crash if the beacon interval is less
3084 * than 16. We can't avoid connecting at all, so refuse the
3085 * station state change, this will cause mac80211 to abandon
3086 * attempts to connect to this AP, and eventually wpa_s will
3087 * blacklist the AP...
3089 if (vif
->type
== NL80211_IFTYPE_STATION
&&
3090 vif
->bss_conf
.beacon_int
< 16) {
3092 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
3093 sta
->addr
, vif
->bss_conf
.beacon_int
);
3100 iwl_mvm_tdls_sta_count(mvm
, NULL
) ==
3101 IWL_MVM_TDLS_STA_COUNT
||
3102 iwl_mvm_phy_ctx_count(mvm
) > 1)) {
3103 IWL_DEBUG_MAC80211(mvm
, "refusing TDLS sta\n");
3108 ret
= iwl_mvm_add_sta(mvm
, vif
, sta
);
3109 if (sta
->tdls
&& ret
== 0) {
3110 iwl_mvm_recalc_tdls_state(mvm
, vif
, true);
3111 iwl_mvm_tdls_check_trigger(mvm
, vif
, sta
->addr
,
3112 NL80211_TDLS_SETUP
);
3115 sta
->max_rc_amsdu_len
= 1;
3116 } else if (old_state
== IEEE80211_STA_NONE
&&
3117 new_state
== IEEE80211_STA_AUTH
) {
3119 * EBS may be disabled due to previous failures reported by FW.
3120 * Reset EBS status here assuming environment has been changed.
3122 mvm
->last_ebs_successful
= true;
3123 iwl_mvm_check_uapsd(mvm
, vif
, sta
->addr
);
3125 } else if (old_state
== IEEE80211_STA_AUTH
&&
3126 new_state
== IEEE80211_STA_ASSOC
) {
3127 if (vif
->type
== NL80211_IFTYPE_AP
) {
3128 vif
->bss_conf
.he_support
= sta
->he_cap
.has_he
;
3129 mvmvif
->ap_assoc_sta_count
++;
3130 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
3131 if (vif
->bss_conf
.he_support
&&
3132 !iwlwifi_mod_params
.disable_11ax
)
3133 iwl_mvm_cfg_he_sta(mvm
, vif
, mvm_sta
->sta_id
);
3134 } else if (vif
->type
== NL80211_IFTYPE_STATION
) {
3135 vif
->bss_conf
.he_support
= sta
->he_cap
.has_he
;
3137 mvmvif
->he_ru_2mhz_block
= false;
3138 if (sta
->he_cap
.has_he
)
3139 iwl_mvm_check_he_obss_narrow_bw_ru(hw
, vif
);
3141 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
3144 iwl_mvm_rs_rate_init(mvm
, sta
, mvmvif
->phy_ctxt
->channel
->band
,
3146 ret
= iwl_mvm_update_sta(mvm
, vif
, sta
);
3147 } else if (old_state
== IEEE80211_STA_ASSOC
&&
3148 new_state
== IEEE80211_STA_AUTHORIZED
) {
3151 /* we don't support TDLS during DCM */
3152 if (iwl_mvm_phy_ctx_count(mvm
) > 1)
3153 iwl_mvm_teardown_tdls_peers(mvm
);
3156 iwl_mvm_tdls_check_trigger(mvm
, vif
, sta
->addr
,
3157 NL80211_TDLS_ENABLE_LINK
);
3159 /* enable beacon filtering */
3160 WARN_ON(iwl_mvm_enable_beacon_filter(mvm
, vif
, 0));
3163 * Now that the station is authorized, i.e., keys were already
3164 * installed, need to indicate to the FW that
3165 * multicast data frames can be forwarded to the driver
3167 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
3169 iwl_mvm_rs_rate_init(mvm
, sta
, mvmvif
->phy_ctxt
->channel
->band
,
3171 } else if (old_state
== IEEE80211_STA_AUTHORIZED
&&
3172 new_state
== IEEE80211_STA_ASSOC
) {
3173 /* Multicast data frames are no longer allowed */
3174 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
3176 /* disable beacon filtering */
3177 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
, 0);
3179 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED
,
3182 } else if (old_state
== IEEE80211_STA_ASSOC
&&
3183 new_state
== IEEE80211_STA_AUTH
) {
3184 if (vif
->type
== NL80211_IFTYPE_AP
) {
3185 mvmvif
->ap_assoc_sta_count
--;
3186 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
3189 } else if (old_state
== IEEE80211_STA_AUTH
&&
3190 new_state
== IEEE80211_STA_NONE
) {
3192 } else if (old_state
== IEEE80211_STA_NONE
&&
3193 new_state
== IEEE80211_STA_NOTEXIST
) {
3194 ret
= iwl_mvm_rm_sta(mvm
, vif
, sta
);
3196 iwl_mvm_recalc_tdls_state(mvm
, vif
, false);
3197 iwl_mvm_tdls_check_trigger(mvm
, vif
, sta
->addr
,
3198 NL80211_TDLS_DISABLE_LINK
);
3202 test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED
,
3209 mutex_unlock(&mvm
->mutex
);
3211 if (sta
->tdls
&& ret
== 0) {
3212 if (old_state
== IEEE80211_STA_NOTEXIST
&&
3213 new_state
== IEEE80211_STA_NONE
)
3214 ieee80211_reserve_tid(sta
, IWL_MVM_TDLS_FW_TID
);
3215 else if (old_state
== IEEE80211_STA_NONE
&&
3216 new_state
== IEEE80211_STA_NOTEXIST
)
3217 ieee80211_unreserve_tid(sta
, IWL_MVM_TDLS_FW_TID
);
3223 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3225 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3227 mvm
->rts_threshold
= value
;
3232 static void iwl_mvm_sta_rc_update(struct ieee80211_hw
*hw
,
3233 struct ieee80211_vif
*vif
,
3234 struct ieee80211_sta
*sta
, u32 changed
)
3236 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3237 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3239 if (changed
& (IEEE80211_RC_BW_CHANGED
|
3240 IEEE80211_RC_SUPP_RATES_CHANGED
|
3241 IEEE80211_RC_NSS_CHANGED
))
3242 iwl_mvm_rs_rate_init(mvm
, sta
, mvmvif
->phy_ctxt
->channel
->band
,
3245 if (vif
->type
== NL80211_IFTYPE_STATION
&&
3246 changed
& IEEE80211_RC_NSS_CHANGED
)
3247 iwl_mvm_sf_update(mvm
, vif
, false);
3250 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw
*hw
,
3251 struct ieee80211_vif
*vif
, u16 ac
,
3252 const struct ieee80211_tx_queue_params
*params
)
3254 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3255 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3257 mvmvif
->queue_params
[ac
] = *params
;
3260 * No need to update right away, we'll get BSS_CHANGED_QOS
3261 * The exception is P2P_DEVICE interface which needs immediate update.
3263 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
3266 mutex_lock(&mvm
->mutex
);
3267 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
3268 mutex_unlock(&mvm
->mutex
);
3274 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw
*hw
,
3275 struct ieee80211_vif
*vif
,
3278 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3279 u32 duration
= IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS
;
3280 u32 min_duration
= IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS
;
3282 if (req_duration
> duration
)
3283 duration
= req_duration
;
3285 mutex_lock(&mvm
->mutex
);
3286 /* Try really hard to protect the session and hear a beacon
3287 * The new session protection command allows us to protect the
3288 * session for a much longer time since the firmware will internally
3289 * create two events: a 300TU one with a very high priority that
3290 * won't be fragmented which should be enough for 99% of the cases,
3291 * and another one (which we configure here to be 900TU long) which
3292 * will have a slightly lower priority, but more importantly, can be
3293 * fragmented so that it'll allow other activities to run.
3295 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
3296 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD
))
3297 iwl_mvm_schedule_session_protection(mvm
, vif
, 900,
3298 min_duration
, false);
3300 iwl_mvm_protect_session(mvm
, vif
, duration
,
3301 min_duration
, 500, false);
3302 mutex_unlock(&mvm
->mutex
);
3305 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw
*hw
,
3306 struct ieee80211_vif
*vif
,
3307 struct cfg80211_sched_scan_request
*req
,
3308 struct ieee80211_scan_ies
*ies
)
3310 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3314 mutex_lock(&mvm
->mutex
);
3316 if (!vif
->bss_conf
.idle
) {
3321 ret
= iwl_mvm_sched_scan_start(mvm
, vif
, req
, ies
, IWL_MVM_SCAN_SCHED
);
3324 mutex_unlock(&mvm
->mutex
);
3328 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw
*hw
,
3329 struct ieee80211_vif
*vif
)
3331 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3334 mutex_lock(&mvm
->mutex
);
3336 /* Due to a race condition, it's possible that mac80211 asks
3337 * us to stop a sched_scan when it's already stopped. This
3338 * can happen, for instance, if we stopped the scan ourselves,
3339 * called ieee80211_sched_scan_stopped() and the userspace called
3340 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3341 * could run. To handle this, simply return if the scan is
3344 if (!(mvm
->scan_status
& IWL_MVM_SCAN_SCHED
)) {
3345 mutex_unlock(&mvm
->mutex
);
3349 ret
= iwl_mvm_scan_stop(mvm
, IWL_MVM_SCAN_SCHED
, false);
3350 mutex_unlock(&mvm
->mutex
);
3351 iwl_mvm_wait_for_async_handlers(mvm
);
3356 static int __iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
3357 enum set_key_cmd cmd
,
3358 struct ieee80211_vif
*vif
,
3359 struct ieee80211_sta
*sta
,
3360 struct ieee80211_key_conf
*key
)
3362 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3363 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3364 struct iwl_mvm_sta
*mvmsta
;
3365 struct iwl_mvm_key_pn
*ptk_pn
;
3366 int keyidx
= key
->keyidx
;
3370 if (iwlwifi_mod_params
.swcrypto
) {
3371 IWL_DEBUG_MAC80211(mvm
, "leave - hwcrypto disabled\n");
3375 switch (key
->cipher
) {
3376 case WLAN_CIPHER_SUITE_TKIP
:
3377 if (!mvm
->trans
->trans_cfg
->gen2
) {
3378 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
3379 key
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
3380 } else if (vif
->type
== NL80211_IFTYPE_STATION
) {
3381 key
->flags
|= IEEE80211_KEY_FLAG_PUT_MIC_SPACE
;
3383 IWL_DEBUG_MAC80211(mvm
, "Use SW encryption for TKIP\n");
3387 case WLAN_CIPHER_SUITE_CCMP
:
3388 case WLAN_CIPHER_SUITE_GCMP
:
3389 case WLAN_CIPHER_SUITE_GCMP_256
:
3390 if (!iwl_mvm_has_new_tx_api(mvm
))
3391 key
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
3393 case WLAN_CIPHER_SUITE_AES_CMAC
:
3394 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
3395 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
3396 WARN_ON_ONCE(!ieee80211_hw_check(hw
, MFP_CAPABLE
));
3398 case WLAN_CIPHER_SUITE_WEP40
:
3399 case WLAN_CIPHER_SUITE_WEP104
:
3400 if (vif
->type
== NL80211_IFTYPE_STATION
)
3402 if (iwl_mvm_has_new_tx_api(mvm
))
3404 /* support HW crypto on TX */
3407 /* currently FW supports only one optional cipher scheme */
3408 if (hw
->n_cipher_schemes
&&
3409 hw
->cipher_schemes
->cipher
== key
->cipher
)
3410 key
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
3417 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
3418 vif
->type
== NL80211_IFTYPE_AP
) && !sta
) {
3420 * GTK on AP interface is a TX-only key, return 0;
3421 * on IBSS they're per-station and because we're lazy
3422 * we don't support them for RX, so do the same.
3423 * CMAC/GMAC in AP/IBSS modes must be done in software.
3425 if (key
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
||
3426 key
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_128
||
3427 key
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_256
)
3432 if (key
->cipher
!= WLAN_CIPHER_SUITE_GCMP
&&
3433 key
->cipher
!= WLAN_CIPHER_SUITE_GCMP_256
&&
3434 !iwl_mvm_has_new_tx_api(mvm
)) {
3435 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
3439 if (!mvmvif
->ap_ibss_active
) {
3441 i
< ARRAY_SIZE(mvmvif
->ap_early_keys
);
3443 if (!mvmvif
->ap_early_keys
[i
]) {
3444 mvmvif
->ap_early_keys
[i
] = key
;
3449 if (i
>= ARRAY_SIZE(mvmvif
->ap_early_keys
))
3456 /* During FW restart, in order to restore the state as it was,
3457 * don't try to reprogram keys we previously failed for.
3459 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
) &&
3460 key
->hw_key_idx
== STA_KEY_IDX_INVALID
) {
3461 IWL_DEBUG_MAC80211(mvm
,
3462 "skip invalid idx key programming during restart\n");
3467 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
) &&
3468 sta
&& iwl_mvm_has_new_rx_api(mvm
) &&
3469 key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
&&
3470 (key
->cipher
== WLAN_CIPHER_SUITE_CCMP
||
3471 key
->cipher
== WLAN_CIPHER_SUITE_GCMP
||
3472 key
->cipher
== WLAN_CIPHER_SUITE_GCMP_256
)) {
3473 struct ieee80211_key_seq seq
;
3476 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
3477 WARN_ON(rcu_access_pointer(mvmsta
->ptk_pn
[keyidx
]));
3478 ptk_pn
= kzalloc(struct_size(ptk_pn
, q
,
3479 mvm
->trans
->num_rx_queues
),
3486 for (tid
= 0; tid
< IWL_MAX_TID_COUNT
; tid
++) {
3487 ieee80211_get_key_rx_seq(key
, tid
, &seq
);
3488 for (q
= 0; q
< mvm
->trans
->num_rx_queues
; q
++)
3489 memcpy(ptk_pn
->q
[q
].pn
[tid
],
3491 IEEE80211_CCMP_PN_LEN
);
3494 rcu_assign_pointer(mvmsta
->ptk_pn
[keyidx
], ptk_pn
);
3497 /* in HW restart reuse the index, otherwise request a new one */
3498 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
3499 key_offset
= key
->hw_key_idx
;
3501 key_offset
= STA_KEY_IDX_INVALID
;
3503 IWL_DEBUG_MAC80211(mvm
, "set hwcrypto key\n");
3504 ret
= iwl_mvm_set_sta_key(mvm
, vif
, sta
, key
, key_offset
);
3506 IWL_WARN(mvm
, "set key failed\n");
3507 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
3509 * can't add key for RX, but we don't need it
3510 * in the device for TX so still return 0,
3511 * unless we have new TX API where we cannot
3512 * put key material into the TX_CMD
3514 if (iwl_mvm_has_new_tx_api(mvm
))
3523 for (i
= 0; i
< ARRAY_SIZE(mvmvif
->ap_early_keys
); i
++) {
3524 if (mvmvif
->ap_early_keys
[i
] == key
) {
3525 mvmvif
->ap_early_keys
[i
] = NULL
;
3530 /* found in pending list - don't do anything else */
3534 if (key
->hw_key_idx
== STA_KEY_IDX_INVALID
) {
3539 if (sta
&& iwl_mvm_has_new_rx_api(mvm
) &&
3540 key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
&&
3541 (key
->cipher
== WLAN_CIPHER_SUITE_CCMP
||
3542 key
->cipher
== WLAN_CIPHER_SUITE_GCMP
||
3543 key
->cipher
== WLAN_CIPHER_SUITE_GCMP_256
)) {
3544 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
3545 ptk_pn
= rcu_dereference_protected(
3546 mvmsta
->ptk_pn
[keyidx
],
3547 lockdep_is_held(&mvm
->mutex
));
3548 RCU_INIT_POINTER(mvmsta
->ptk_pn
[keyidx
], NULL
);
3550 kfree_rcu(ptk_pn
, rcu_head
);
3553 IWL_DEBUG_MAC80211(mvm
, "disable hwcrypto key\n");
3554 ret
= iwl_mvm_remove_sta_key(mvm
, vif
, sta
, key
);
3563 static int iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
3564 enum set_key_cmd cmd
,
3565 struct ieee80211_vif
*vif
,
3566 struct ieee80211_sta
*sta
,
3567 struct ieee80211_key_conf
*key
)
3569 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3572 mutex_lock(&mvm
->mutex
);
3573 ret
= __iwl_mvm_mac_set_key(hw
, cmd
, vif
, sta
, key
);
3574 mutex_unlock(&mvm
->mutex
);
3579 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw
*hw
,
3580 struct ieee80211_vif
*vif
,
3581 struct ieee80211_key_conf
*keyconf
,
3582 struct ieee80211_sta
*sta
,
3583 u32 iv32
, u16
*phase1key
)
3585 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3587 if (keyconf
->hw_key_idx
== STA_KEY_IDX_INVALID
)
3590 iwl_mvm_update_tkip_key(mvm
, vif
, keyconf
, sta
, iv32
, phase1key
);
3594 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data
*notif_wait
,
3595 struct iwl_rx_packet
*pkt
, void *data
)
3597 struct iwl_mvm
*mvm
=
3598 container_of(notif_wait
, struct iwl_mvm
, notif_wait
);
3599 struct iwl_hs20_roc_res
*resp
;
3600 int resp_len
= iwl_rx_packet_payload_len(pkt
);
3601 struct iwl_mvm_time_event_data
*te_data
= data
;
3603 if (WARN_ON(pkt
->hdr
.cmd
!= HOT_SPOT_CMD
))
3606 if (WARN_ON_ONCE(resp_len
!= sizeof(*resp
))) {
3607 IWL_ERR(mvm
, "Invalid HOT_SPOT_CMD response\n");
3611 resp
= (void *)pkt
->data
;
3614 "Aux ROC: Received response from ucode: status=%d uid=%d\n",
3615 resp
->status
, resp
->event_unique_id
);
3617 te_data
->uid
= le32_to_cpu(resp
->event_unique_id
);
3618 IWL_DEBUG_TE(mvm
, "TIME_EVENT_CMD response - UID = 0x%x\n",
3621 spin_lock_bh(&mvm
->time_event_lock
);
3622 list_add_tail(&te_data
->list
, &mvm
->aux_roc_te_list
);
3623 spin_unlock_bh(&mvm
->time_event_lock
);
3628 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3629 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3630 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3631 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3632 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3633 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm
*mvm
,
3634 struct ieee80211_channel
*channel
,
3635 struct ieee80211_vif
*vif
,
3639 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3640 struct iwl_mvm_time_event_data
*te_data
= &mvmvif
->hs_time_event_data
;
3641 static const u16 time_event_response
[] = { HOT_SPOT_CMD
};
3642 struct iwl_notification_wait wait_time_event
;
3643 u32 dtim_interval
= vif
->bss_conf
.dtim_period
*
3644 vif
->bss_conf
.beacon_int
;
3646 struct iwl_hs20_roc_req aux_roc_req
= {
3647 .action
= cpu_to_le32(FW_CTXT_ACTION_ADD
),
3649 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX
, 0)),
3650 .sta_id_and_color
= cpu_to_le32(mvm
->aux_sta
.sta_id
),
3652 struct iwl_hs20_roc_req_tail
*tail
= iwl_mvm_chan_info_cmd_tail(mvm
,
3653 &aux_roc_req
.channel_info
);
3654 u16 len
= sizeof(aux_roc_req
) - iwl_mvm_chan_info_padding(mvm
);
3656 /* Set the channel info data */
3657 iwl_mvm_set_chan_info(mvm
, &aux_roc_req
.channel_info
, channel
->hw_value
,
3658 iwl_mvm_phy_band_from_nl80211(channel
->band
),
3659 PHY_VHT_CHANNEL_MODE20
,
3662 /* Set the time and duration */
3663 tail
->apply_time
= cpu_to_le32(iwl_mvm_get_systime(mvm
));
3665 delay
= AUX_ROC_MIN_DELAY
;
3666 req_dur
= MSEC_TO_TU(duration
);
3669 * If we are associated we want the delay time to be at least one
3670 * dtim interval so that the FW can wait until after the DTIM and
3671 * then start the time event, this will potentially allow us to
3672 * remain off-channel for the max duration.
3673 * Since we want to use almost a whole dtim interval we would also
3674 * like the delay to be for 2-3 dtim intervals, in case there are
3675 * other time events with higher priority.
3677 if (vif
->bss_conf
.assoc
) {
3678 delay
= min_t(u32
, dtim_interval
* 3, AUX_ROC_MAX_DELAY
);
3679 /* We cannot remain off-channel longer than the DTIM interval */
3680 if (dtim_interval
<= req_dur
) {
3681 req_dur
= dtim_interval
- AUX_ROC_SAFETY_BUFFER
;
3682 if (req_dur
<= AUX_ROC_MIN_DURATION
)
3683 req_dur
= dtim_interval
-
3684 AUX_ROC_MIN_SAFETY_BUFFER
;
3688 tail
->duration
= cpu_to_le32(req_dur
);
3689 tail
->apply_time_max_delay
= cpu_to_le32(delay
);
3692 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3693 channel
->hw_value
, req_dur
, duration
, delay
,
3695 /* Set the node address */
3696 memcpy(tail
->node_addr
, vif
->addr
, ETH_ALEN
);
3698 lockdep_assert_held(&mvm
->mutex
);
3700 spin_lock_bh(&mvm
->time_event_lock
);
3702 if (WARN_ON(te_data
->id
== HOT_SPOT_CMD
)) {
3703 spin_unlock_bh(&mvm
->time_event_lock
);
3708 te_data
->duration
= duration
;
3709 te_data
->id
= HOT_SPOT_CMD
;
3711 spin_unlock_bh(&mvm
->time_event_lock
);
3714 * Use a notification wait, which really just processes the
3715 * command response and doesn't wait for anything, in order
3716 * to be able to process the response and get the UID inside
3717 * the RX path. Using CMD_WANT_SKB doesn't work because it
3718 * stores the buffer and then wakes up this thread, by which
3719 * time another notification (that the time event started)
3720 * might already be processed unsuccessfully.
3722 iwl_init_notification_wait(&mvm
->notif_wait
, &wait_time_event
,
3723 time_event_response
,
3724 ARRAY_SIZE(time_event_response
),
3725 iwl_mvm_rx_aux_roc
, te_data
);
3727 res
= iwl_mvm_send_cmd_pdu(mvm
, HOT_SPOT_CMD
, 0, len
,
3731 IWL_ERR(mvm
, "Couldn't send HOT_SPOT_CMD: %d\n", res
);
3732 iwl_remove_notification(&mvm
->notif_wait
, &wait_time_event
);
3736 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3737 res
= iwl_wait_notification(&mvm
->notif_wait
, &wait_time_event
, 1);
3738 /* should never fail */
3743 spin_lock_bh(&mvm
->time_event_lock
);
3744 iwl_mvm_te_clear_data(mvm
, te_data
);
3745 spin_unlock_bh(&mvm
->time_event_lock
);
3751 static int iwl_mvm_roc(struct ieee80211_hw
*hw
,
3752 struct ieee80211_vif
*vif
,
3753 struct ieee80211_channel
*channel
,
3755 enum ieee80211_roc_type type
)
3757 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3758 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3759 struct cfg80211_chan_def chandef
;
3760 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
3763 IWL_DEBUG_MAC80211(mvm
, "enter (%d, %d, %d)\n", channel
->hw_value
,
3767 * Flush the done work, just in case it's still pending, so that
3768 * the work it does can complete and we can accept new frames.
3770 flush_work(&mvm
->roc_done_wk
);
3772 mutex_lock(&mvm
->mutex
);
3774 switch (vif
->type
) {
3775 case NL80211_IFTYPE_STATION
:
3776 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
3777 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT
)) {
3778 /* Use aux roc framework (HS20) */
3779 ret
= iwl_mvm_send_aux_roc_cmd(mvm
, channel
,
3783 IWL_ERR(mvm
, "hotspot not supported\n");
3786 case NL80211_IFTYPE_P2P_DEVICE
:
3790 IWL_ERR(mvm
, "vif isn't P2P_DEVICE: %d\n", vif
->type
);
3795 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
3796 phy_ctxt
= &mvm
->phy_ctxts
[i
];
3797 if (phy_ctxt
->ref
== 0 || mvmvif
->phy_ctxt
== phy_ctxt
)
3800 if (phy_ctxt
->ref
&& channel
== phy_ctxt
->channel
) {
3802 * Unbind the P2P_DEVICE from the current PHY context,
3803 * and if the PHY context is not used remove it.
3805 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
3806 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
3809 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
3811 /* Bind the P2P_DEVICE to the current PHY Context */
3812 mvmvif
->phy_ctxt
= phy_ctxt
;
3814 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
3815 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
3818 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
3819 goto schedule_time_event
;
3823 /* Need to update the PHY context only if the ROC channel changed */
3824 if (channel
== mvmvif
->phy_ctxt
->channel
)
3825 goto schedule_time_event
;
3827 cfg80211_chandef_create(&chandef
, channel
, NL80211_CHAN_NO_HT
);
3830 * Change the PHY context configuration as it is currently referenced
3831 * only by the P2P Device MAC
3833 if (mvmvif
->phy_ctxt
->ref
== 1) {
3834 ret
= iwl_mvm_phy_ctxt_changed(mvm
, mvmvif
->phy_ctxt
,
3840 * The PHY context is shared with other MACs. Need to remove the
3841 * P2P Device from the binding, allocate an new PHY context and
3842 * create a new binding
3844 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
3850 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &chandef
,
3853 IWL_ERR(mvm
, "Failed to change PHY context\n");
3857 /* Unbind the P2P_DEVICE from the current PHY context */
3858 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
3859 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
3862 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
3864 /* Bind the P2P_DEVICE to the new allocated PHY context */
3865 mvmvif
->phy_ctxt
= phy_ctxt
;
3867 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
3868 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
3871 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
3874 schedule_time_event
:
3875 /* Schedule the time events */
3876 ret
= iwl_mvm_start_p2p_roc(mvm
, vif
, duration
, type
);
3879 mutex_unlock(&mvm
->mutex
);
3880 IWL_DEBUG_MAC80211(mvm
, "leave\n");
3884 static int iwl_mvm_cancel_roc(struct ieee80211_hw
*hw
,
3885 struct ieee80211_vif
*vif
)
3887 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3889 IWL_DEBUG_MAC80211(mvm
, "enter\n");
3891 mutex_lock(&mvm
->mutex
);
3892 iwl_mvm_stop_roc(mvm
, vif
);
3893 mutex_unlock(&mvm
->mutex
);
3895 IWL_DEBUG_MAC80211(mvm
, "leave\n");
3899 struct iwl_mvm_ftm_responder_iter_data
{
3901 struct ieee80211_chanctx_conf
*ctx
;
3904 static void iwl_mvm_ftm_responder_chanctx_iter(void *_data
, u8
*mac
,
3905 struct ieee80211_vif
*vif
)
3907 struct iwl_mvm_ftm_responder_iter_data
*data
= _data
;
3909 if (rcu_access_pointer(vif
->chanctx_conf
) == data
->ctx
&&
3910 vif
->type
== NL80211_IFTYPE_AP
&& vif
->bss_conf
.ftmr_params
)
3911 data
->responder
= true;
3914 static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm
*mvm
,
3915 struct ieee80211_chanctx_conf
*ctx
)
3917 struct iwl_mvm_ftm_responder_iter_data data
= {
3922 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
3923 IEEE80211_IFACE_ITER_NORMAL
,
3924 iwl_mvm_ftm_responder_chanctx_iter
,
3926 return data
.responder
;
3929 static int __iwl_mvm_add_chanctx(struct iwl_mvm
*mvm
,
3930 struct ieee80211_chanctx_conf
*ctx
)
3932 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
3933 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
3934 bool responder
= iwl_mvm_is_ftm_responder_chanctx(mvm
, ctx
);
3935 struct cfg80211_chan_def
*def
= responder
? &ctx
->def
: &ctx
->min_def
;
3938 lockdep_assert_held(&mvm
->mutex
);
3940 IWL_DEBUG_MAC80211(mvm
, "Add channel context\n");
3942 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
3948 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, def
,
3949 ctx
->rx_chains_static
,
3950 ctx
->rx_chains_dynamic
);
3952 IWL_ERR(mvm
, "Failed to add PHY context\n");
3956 iwl_mvm_phy_ctxt_ref(mvm
, phy_ctxt
);
3957 *phy_ctxt_id
= phy_ctxt
->id
;
3962 static int iwl_mvm_add_chanctx(struct ieee80211_hw
*hw
,
3963 struct ieee80211_chanctx_conf
*ctx
)
3965 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3968 mutex_lock(&mvm
->mutex
);
3969 ret
= __iwl_mvm_add_chanctx(mvm
, ctx
);
3970 mutex_unlock(&mvm
->mutex
);
3975 static void __iwl_mvm_remove_chanctx(struct iwl_mvm
*mvm
,
3976 struct ieee80211_chanctx_conf
*ctx
)
3978 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
3979 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
3981 lockdep_assert_held(&mvm
->mutex
);
3983 iwl_mvm_phy_ctxt_unref(mvm
, phy_ctxt
);
3986 static void iwl_mvm_remove_chanctx(struct ieee80211_hw
*hw
,
3987 struct ieee80211_chanctx_conf
*ctx
)
3989 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3991 mutex_lock(&mvm
->mutex
);
3992 __iwl_mvm_remove_chanctx(mvm
, ctx
);
3993 mutex_unlock(&mvm
->mutex
);
3996 static void iwl_mvm_change_chanctx(struct ieee80211_hw
*hw
,
3997 struct ieee80211_chanctx_conf
*ctx
,
4000 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4001 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
4002 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
4003 bool responder
= iwl_mvm_is_ftm_responder_chanctx(mvm
, ctx
);
4004 struct cfg80211_chan_def
*def
= responder
? &ctx
->def
: &ctx
->min_def
;
4006 if (WARN_ONCE((phy_ctxt
->ref
> 1) &&
4007 (changed
& ~(IEEE80211_CHANCTX_CHANGE_WIDTH
|
4008 IEEE80211_CHANCTX_CHANGE_RX_CHAINS
|
4009 IEEE80211_CHANCTX_CHANGE_RADAR
|
4010 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH
)),
4011 "Cannot change PHY. Ref=%d, changed=0x%X\n",
4012 phy_ctxt
->ref
, changed
))
4015 mutex_lock(&mvm
->mutex
);
4017 /* we are only changing the min_width, may be a noop */
4018 if (changed
== IEEE80211_CHANCTX_CHANGE_MIN_WIDTH
) {
4019 if (phy_ctxt
->width
== def
->width
)
4022 /* we are just toggling between 20_NOHT and 20 */
4023 if (phy_ctxt
->width
<= NL80211_CHAN_WIDTH_20
&&
4024 def
->width
<= NL80211_CHAN_WIDTH_20
)
4028 iwl_mvm_bt_coex_vif_change(mvm
);
4029 iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, def
,
4030 ctx
->rx_chains_static
,
4031 ctx
->rx_chains_dynamic
);
4034 mutex_unlock(&mvm
->mutex
);
4037 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm
*mvm
,
4038 struct ieee80211_vif
*vif
,
4039 struct ieee80211_chanctx_conf
*ctx
,
4040 bool switching_chanctx
)
4042 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
4043 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
4044 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4047 lockdep_assert_held(&mvm
->mutex
);
4049 mvmvif
->phy_ctxt
= phy_ctxt
;
4051 switch (vif
->type
) {
4052 case NL80211_IFTYPE_AP
:
4053 /* only needed if we're switching chanctx (i.e. during CSA) */
4054 if (switching_chanctx
) {
4055 mvmvif
->ap_ibss_active
= true;
4059 case NL80211_IFTYPE_ADHOC
:
4061 * The AP binding flow is handled as part of the start_ap flow
4062 * (in bss_info_changed), similarly for IBSS.
4066 case NL80211_IFTYPE_STATION
:
4067 mvmvif
->csa_bcn_pending
= false;
4069 case NL80211_IFTYPE_MONITOR
:
4070 /* always disable PS when a monitor interface is active */
4071 mvmvif
->ps_disabled
= true;
4078 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
4083 * Power state must be updated before quotas,
4084 * otherwise fw will complain.
4086 iwl_mvm_power_update_mac(mvm
);
4088 /* Setting the quota at this stage is only required for monitor
4089 * interfaces. For the other types, the bss_info changed flow
4090 * will handle quota settings.
4092 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
4093 mvmvif
->monitor_active
= true;
4094 ret
= iwl_mvm_update_quotas(mvm
, false, NULL
);
4096 goto out_remove_binding
;
4098 ret
= iwl_mvm_add_snif_sta(mvm
, vif
);
4100 goto out_remove_binding
;
4104 /* Handle binding during CSA */
4105 if (vif
->type
== NL80211_IFTYPE_AP
) {
4106 iwl_mvm_update_quotas(mvm
, false, NULL
);
4107 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
4110 if (switching_chanctx
&& vif
->type
== NL80211_IFTYPE_STATION
) {
4111 mvmvif
->csa_bcn_pending
= true;
4113 if (!fw_has_capa(&mvm
->fw
->ucode_capa
,
4114 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD
)) {
4115 u32 duration
= 3 * vif
->bss_conf
.beacon_int
;
4117 /* Protect the session to make sure we hear the first
4118 * beacon on the new channel.
4120 iwl_mvm_protect_session(mvm
, vif
, duration
, duration
,
4121 vif
->bss_conf
.beacon_int
/ 2,
4125 iwl_mvm_update_quotas(mvm
, false, NULL
);
4131 iwl_mvm_binding_remove_vif(mvm
, vif
);
4132 iwl_mvm_power_update_mac(mvm
);
4135 mvmvif
->phy_ctxt
= NULL
;
4138 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw
*hw
,
4139 struct ieee80211_vif
*vif
,
4140 struct ieee80211_chanctx_conf
*ctx
)
4142 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4145 mutex_lock(&mvm
->mutex
);
4146 ret
= __iwl_mvm_assign_vif_chanctx(mvm
, vif
, ctx
, false);
4147 mutex_unlock(&mvm
->mutex
);
4152 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm
*mvm
,
4153 struct ieee80211_vif
*vif
,
4154 struct ieee80211_chanctx_conf
*ctx
,
4155 bool switching_chanctx
)
4157 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4158 struct ieee80211_vif
*disabled_vif
= NULL
;
4160 lockdep_assert_held(&mvm
->mutex
);
4162 iwl_mvm_remove_time_event(mvm
, mvmvif
, &mvmvif
->time_event_data
);
4164 switch (vif
->type
) {
4165 case NL80211_IFTYPE_ADHOC
:
4167 case NL80211_IFTYPE_MONITOR
:
4168 mvmvif
->monitor_active
= false;
4169 mvmvif
->ps_disabled
= false;
4170 iwl_mvm_rm_snif_sta(mvm
, vif
);
4172 case NL80211_IFTYPE_AP
:
4173 /* This part is triggered only during CSA */
4174 if (!switching_chanctx
|| !mvmvif
->ap_ibss_active
)
4177 mvmvif
->csa_countdown
= false;
4179 /* Set CS bit on all the stations */
4180 iwl_mvm_modify_all_sta_disable_tx(mvm
, mvmvif
, true);
4182 /* Save blocked iface, the timeout is set on the next beacon */
4183 rcu_assign_pointer(mvm
->csa_tx_blocked_vif
, vif
);
4185 mvmvif
->ap_ibss_active
= false;
4187 case NL80211_IFTYPE_STATION
:
4188 if (!switching_chanctx
)
4193 if (!fw_has_capa(&mvm
->fw
->ucode_capa
,
4194 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD
))
4195 iwl_mvm_mac_ctxt_changed(mvm
, vif
, true, NULL
);
4201 iwl_mvm_update_quotas(mvm
, false, disabled_vif
);
4202 iwl_mvm_binding_remove_vif(mvm
, vif
);
4205 mvmvif
->phy_ctxt
= NULL
;
4206 iwl_mvm_power_update_mac(mvm
);
4209 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
4210 struct ieee80211_vif
*vif
,
4211 struct ieee80211_chanctx_conf
*ctx
)
4213 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4215 mutex_lock(&mvm
->mutex
);
4216 __iwl_mvm_unassign_vif_chanctx(mvm
, vif
, ctx
, false);
4217 mutex_unlock(&mvm
->mutex
);
4221 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm
*mvm
,
4222 struct ieee80211_vif_chanctx_switch
*vifs
)
4226 mutex_lock(&mvm
->mutex
);
4227 __iwl_mvm_unassign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].old_ctx
, true);
4228 __iwl_mvm_remove_chanctx(mvm
, vifs
[0].old_ctx
);
4230 ret
= __iwl_mvm_add_chanctx(mvm
, vifs
[0].new_ctx
);
4232 IWL_ERR(mvm
, "failed to add new_ctx during channel switch\n");
4236 ret
= __iwl_mvm_assign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].new_ctx
,
4240 "failed to assign new_ctx during channel switch\n");
4244 /* we don't support TDLS during DCM - can be caused by channel switch */
4245 if (iwl_mvm_phy_ctx_count(mvm
) > 1)
4246 iwl_mvm_teardown_tdls_peers(mvm
);
4251 __iwl_mvm_remove_chanctx(mvm
, vifs
[0].new_ctx
);
4254 if (__iwl_mvm_add_chanctx(mvm
, vifs
[0].old_ctx
)) {
4255 IWL_ERR(mvm
, "failed to add old_ctx back after failure.\n");
4259 if (__iwl_mvm_assign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].old_ctx
,
4261 IWL_ERR(mvm
, "failed to reassign old_ctx after failure.\n");
4268 /* things keep failing, better restart the hw */
4269 iwl_mvm_nic_restart(mvm
, false);
4272 mutex_unlock(&mvm
->mutex
);
4278 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm
*mvm
,
4279 struct ieee80211_vif_chanctx_switch
*vifs
)
4283 mutex_lock(&mvm
->mutex
);
4284 __iwl_mvm_unassign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].old_ctx
, true);
4286 ret
= __iwl_mvm_assign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].new_ctx
,
4290 "failed to assign new_ctx during channel switch\n");
4297 if (__iwl_mvm_assign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].old_ctx
,
4299 IWL_ERR(mvm
, "failed to reassign old_ctx after failure.\n");
4306 /* things keep failing, better restart the hw */
4307 iwl_mvm_nic_restart(mvm
, false);
4310 mutex_unlock(&mvm
->mutex
);
4315 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw
*hw
,
4316 struct ieee80211_vif_chanctx_switch
*vifs
,
4318 enum ieee80211_chanctx_switch_mode mode
)
4320 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4323 /* we only support a single-vif right now */
4328 case CHANCTX_SWMODE_SWAP_CONTEXTS
:
4329 ret
= iwl_mvm_switch_vif_chanctx_swap(mvm
, vifs
);
4331 case CHANCTX_SWMODE_REASSIGN_VIF
:
4332 ret
= iwl_mvm_switch_vif_chanctx_reassign(mvm
, vifs
);
4342 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw
*hw
)
4344 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4346 return mvm
->ibss_manager
;
4349 static int iwl_mvm_set_tim(struct ieee80211_hw
*hw
,
4350 struct ieee80211_sta
*sta
,
4353 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4354 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
4356 if (!mvm_sta
|| !mvm_sta
->vif
) {
4357 IWL_ERR(mvm
, "Station is not associated to a vif\n");
4361 return iwl_mvm_mac_ctxt_beacon_changed(mvm
, mvm_sta
->vif
);
4364 #ifdef CONFIG_NL80211_TESTMODE
4365 static const struct nla_policy iwl_mvm_tm_policy
[IWL_MVM_TM_ATTR_MAX
+ 1] = {
4366 [IWL_MVM_TM_ATTR_CMD
] = { .type
= NLA_U32
},
4367 [IWL_MVM_TM_ATTR_NOA_DURATION
] = { .type
= NLA_U32
},
4368 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
] = { .type
= NLA_U32
},
4371 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm
*mvm
,
4372 struct ieee80211_vif
*vif
,
4373 void *data
, int len
)
4375 struct nlattr
*tb
[IWL_MVM_TM_ATTR_MAX
+ 1];
4379 err
= nla_parse_deprecated(tb
, IWL_MVM_TM_ATTR_MAX
, data
, len
,
4380 iwl_mvm_tm_policy
, NULL
);
4384 if (!tb
[IWL_MVM_TM_ATTR_CMD
])
4387 switch (nla_get_u32(tb
[IWL_MVM_TM_ATTR_CMD
])) {
4388 case IWL_MVM_TM_CMD_SET_NOA
:
4389 if (!vif
|| vif
->type
!= NL80211_IFTYPE_AP
|| !vif
->p2p
||
4390 !vif
->bss_conf
.enable_beacon
||
4391 !tb
[IWL_MVM_TM_ATTR_NOA_DURATION
])
4394 noa_duration
= nla_get_u32(tb
[IWL_MVM_TM_ATTR_NOA_DURATION
]);
4395 if (noa_duration
>= vif
->bss_conf
.beacon_int
)
4398 mvm
->noa_duration
= noa_duration
;
4401 return iwl_mvm_update_quotas(mvm
, true, NULL
);
4402 case IWL_MVM_TM_CMD_SET_BEACON_FILTER
:
4403 /* must be associated client vif - ignore authorized */
4404 if (!vif
|| vif
->type
!= NL80211_IFTYPE_STATION
||
4405 !vif
->bss_conf
.assoc
|| !vif
->bss_conf
.dtim_period
||
4406 !tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
])
4409 if (nla_get_u32(tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
]))
4410 return iwl_mvm_enable_beacon_filter(mvm
, vif
, 0);
4411 return iwl_mvm_disable_beacon_filter(mvm
, vif
, 0);
4417 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw
*hw
,
4418 struct ieee80211_vif
*vif
,
4419 void *data
, int len
)
4421 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4424 mutex_lock(&mvm
->mutex
);
4425 err
= __iwl_mvm_mac_testmode_cmd(mvm
, vif
, data
, len
);
4426 mutex_unlock(&mvm
->mutex
);
4432 static void iwl_mvm_channel_switch(struct ieee80211_hw
*hw
,
4433 struct ieee80211_vif
*vif
,
4434 struct ieee80211_channel_switch
*chsw
)
4436 /* By implementing this operation, we prevent mac80211 from
4437 * starting its own channel switch timer, so that we can call
4438 * ieee80211_chswitch_done() ourselves at the right time
4439 * (which is when the absence time event starts).
4442 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw
),
4443 "dummy channel switch op\n");
4446 static int iwl_mvm_schedule_client_csa(struct iwl_mvm
*mvm
,
4447 struct ieee80211_vif
*vif
,
4448 struct ieee80211_channel_switch
*chsw
)
4450 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4451 struct iwl_chan_switch_te_cmd cmd
= {
4452 .mac_id
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->id
,
4454 .action
= cpu_to_le32(FW_CTXT_ACTION_ADD
),
4455 .tsf
= cpu_to_le32(chsw
->timestamp
),
4456 .cs_count
= chsw
->count
,
4457 .cs_mode
= chsw
->block_tx
,
4460 lockdep_assert_held(&mvm
->mutex
);
4463 cmd
.cs_delayed_bcn_count
=
4464 DIV_ROUND_UP(chsw
->delay
, vif
->bss_conf
.beacon_int
);
4466 return iwl_mvm_send_cmd_pdu(mvm
,
4467 WIDE_ID(MAC_CONF_GROUP
,
4468 CHANNEL_SWITCH_TIME_EVENT_CMD
),
4469 0, sizeof(cmd
), &cmd
);
4472 static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm
*mvm
,
4473 struct ieee80211_vif
*vif
,
4474 struct ieee80211_channel_switch
*chsw
)
4476 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4479 /* Schedule the time event to a bit before beacon 1,
4480 * to make sure we're in the new channel when the
4481 * GO/AP arrives. In case count <= 1 immediately schedule the
4482 * TE (this might result with some packet loss or connection
4485 if (chsw
->count
<= 1)
4488 apply_time
= chsw
->device_timestamp
+
4489 ((vif
->bss_conf
.beacon_int
* (chsw
->count
- 1) -
4490 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT
) * 1024);
4493 iwl_mvm_csa_client_absent(mvm
, vif
);
4495 if (mvmvif
->bf_data
.bf_enabled
) {
4496 int ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
, 0);
4502 iwl_mvm_schedule_csa_period(mvm
, vif
, vif
->bss_conf
.beacon_int
,
4508 #define IWL_MAX_CSA_BLOCK_TX 1500
4509 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw
*hw
,
4510 struct ieee80211_vif
*vif
,
4511 struct ieee80211_channel_switch
*chsw
)
4513 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4514 struct ieee80211_vif
*csa_vif
;
4515 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4518 mutex_lock(&mvm
->mutex
);
4520 mvmvif
->csa_failed
= false;
4522 IWL_DEBUG_MAC80211(mvm
, "pre CSA to freq %d\n",
4523 chsw
->chandef
.center_freq1
);
4525 iwl_fw_dbg_trigger_simple_stop(&mvm
->fwrt
,
4526 ieee80211_vif_to_wdev(vif
),
4527 FW_DBG_TRIGGER_CHANNEL_SWITCH
);
4529 switch (vif
->type
) {
4530 case NL80211_IFTYPE_AP
:
4532 rcu_dereference_protected(mvm
->csa_vif
,
4533 lockdep_is_held(&mvm
->mutex
));
4534 if (WARN_ONCE(csa_vif
&& csa_vif
->csa_active
,
4535 "Another CSA is already in progress")) {
4540 /* we still didn't unblock tx. prevent new CS meanwhile */
4541 if (rcu_dereference_protected(mvm
->csa_tx_blocked_vif
,
4542 lockdep_is_held(&mvm
->mutex
))) {
4547 rcu_assign_pointer(mvm
->csa_vif
, vif
);
4549 if (WARN_ONCE(mvmvif
->csa_countdown
,
4550 "Previous CSA countdown didn't complete")) {
4555 mvmvif
->csa_target_freq
= chsw
->chandef
.chan
->center_freq
;
4558 case NL80211_IFTYPE_STATION
:
4559 if (chsw
->block_tx
) {
4561 * In case of undetermined / long time with immediate
4562 * quiet monitor status to gracefully disconnect
4565 chsw
->count
* vif
->bss_conf
.beacon_int
>
4566 IWL_MAX_CSA_BLOCK_TX
)
4567 schedule_delayed_work(&mvmvif
->csa_work
,
4568 msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX
));
4571 if (!fw_has_capa(&mvm
->fw
->ucode_capa
,
4572 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD
)) {
4573 ret
= iwl_mvm_old_pre_chan_sw_sta(mvm
, vif
, chsw
);
4577 iwl_mvm_schedule_client_csa(mvm
, vif
, chsw
);
4580 mvmvif
->csa_count
= chsw
->count
;
4581 mvmvif
->csa_misbehave
= false;
4587 mvmvif
->ps_disabled
= true;
4589 ret
= iwl_mvm_power_update_ps(mvm
);
4593 /* we won't be on this channel any longer */
4594 iwl_mvm_teardown_tdls_peers(mvm
);
4597 mutex_unlock(&mvm
->mutex
);
4602 static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw
*hw
,
4603 struct ieee80211_vif
*vif
,
4604 struct ieee80211_channel_switch
*chsw
)
4606 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4607 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4608 struct iwl_chan_switch_te_cmd cmd
= {
4609 .mac_id
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->id
,
4611 .action
= cpu_to_le32(FW_CTXT_ACTION_MODIFY
),
4612 .tsf
= cpu_to_le32(chsw
->timestamp
),
4613 .cs_count
= chsw
->count
,
4614 .cs_mode
= chsw
->block_tx
,
4617 if (!fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_CS_MODIFY
))
4620 if (chsw
->count
>= mvmvif
->csa_count
&& chsw
->block_tx
) {
4621 if (mvmvif
->csa_misbehave
) {
4622 /* Second time, give up on this AP*/
4623 iwl_mvm_abort_channel_switch(hw
, vif
);
4624 ieee80211_chswitch_done(vif
, false);
4625 mvmvif
->csa_misbehave
= false;
4628 mvmvif
->csa_misbehave
= true;
4630 mvmvif
->csa_count
= chsw
->count
;
4632 IWL_DEBUG_MAC80211(mvm
, "Modify CSA on mac %d\n", mvmvif
->id
);
4634 WARN_ON(iwl_mvm_send_cmd_pdu(mvm
,
4635 WIDE_ID(MAC_CONF_GROUP
,
4636 CHANNEL_SWITCH_TIME_EVENT_CMD
),
4637 CMD_ASYNC
, sizeof(cmd
), &cmd
));
4640 static void iwl_mvm_flush_no_vif(struct iwl_mvm
*mvm
, u32 queues
, bool drop
)
4644 if (!iwl_mvm_has_new_tx_api(mvm
)) {
4646 mutex_lock(&mvm
->mutex
);
4647 iwl_mvm_flush_tx_path(mvm
,
4648 iwl_mvm_flushable_queues(mvm
) & queues
, 0);
4649 mutex_unlock(&mvm
->mutex
);
4651 iwl_trans_wait_tx_queues_empty(mvm
->trans
, queues
);
4656 mutex_lock(&mvm
->mutex
);
4657 for (i
= 0; i
< ARRAY_SIZE(mvm
->fw_id_to_mac_id
); i
++) {
4658 struct ieee80211_sta
*sta
;
4660 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[i
],
4661 lockdep_is_held(&mvm
->mutex
));
4662 if (IS_ERR_OR_NULL(sta
))
4666 iwl_mvm_flush_sta_tids(mvm
, i
, 0xFFFF, 0);
4668 iwl_mvm_wait_sta_queues_empty(mvm
,
4669 iwl_mvm_sta_from_mac80211(sta
));
4671 mutex_unlock(&mvm
->mutex
);
4674 static void iwl_mvm_mac_flush(struct ieee80211_hw
*hw
,
4675 struct ieee80211_vif
*vif
, u32 queues
, bool drop
)
4677 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4678 struct iwl_mvm_vif
*mvmvif
;
4679 struct iwl_mvm_sta
*mvmsta
;
4680 struct ieee80211_sta
*sta
;
4685 iwl_mvm_flush_no_vif(mvm
, queues
, drop
);
4689 if (vif
->type
!= NL80211_IFTYPE_STATION
)
4692 /* Make sure we're done with the deferred traffic before flushing */
4693 flush_work(&mvm
->add_stream_wk
);
4695 mutex_lock(&mvm
->mutex
);
4696 mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4698 /* flush the AP-station and all TDLS peers */
4699 for (i
= 0; i
< ARRAY_SIZE(mvm
->fw_id_to_mac_id
); i
++) {
4700 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[i
],
4701 lockdep_is_held(&mvm
->mutex
));
4702 if (IS_ERR_OR_NULL(sta
))
4705 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
4706 if (mvmsta
->vif
!= vif
)
4709 /* make sure only TDLS peers or the AP are flushed */
4710 WARN_ON(i
!= mvmvif
->ap_sta_id
&& !sta
->tdls
);
4713 if (iwl_mvm_flush_sta(mvm
, mvmsta
, false, 0))
4714 IWL_ERR(mvm
, "flush request fail\n");
4716 msk
|= mvmsta
->tfd_queue_msk
;
4717 if (iwl_mvm_has_new_tx_api(mvm
))
4718 iwl_mvm_wait_sta_queues_empty(mvm
, mvmsta
);
4722 mutex_unlock(&mvm
->mutex
);
4724 /* this can take a while, and we may need/want other operations
4725 * to succeed while doing this, so do it without the mutex held
4727 if (!drop
&& !iwl_mvm_has_new_tx_api(mvm
))
4728 iwl_trans_wait_tx_queues_empty(mvm
->trans
, msk
);
4731 static int iwl_mvm_mac_get_survey(struct ieee80211_hw
*hw
, int idx
,
4732 struct survey_info
*survey
)
4734 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4737 memset(survey
, 0, sizeof(*survey
));
4739 /* only support global statistics right now */
4743 if (!fw_has_capa(&mvm
->fw
->ucode_capa
,
4744 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS
))
4747 mutex_lock(&mvm
->mutex
);
4749 if (iwl_mvm_firmware_running(mvm
)) {
4750 ret
= iwl_mvm_request_statistics(mvm
, false);
4755 survey
->filled
= SURVEY_INFO_TIME
|
4756 SURVEY_INFO_TIME_RX
|
4757 SURVEY_INFO_TIME_TX
|
4758 SURVEY_INFO_TIME_SCAN
;
4759 survey
->time
= mvm
->accu_radio_stats
.on_time_rf
+
4760 mvm
->radio_stats
.on_time_rf
;
4761 do_div(survey
->time
, USEC_PER_MSEC
);
4763 survey
->time_rx
= mvm
->accu_radio_stats
.rx_time
+
4764 mvm
->radio_stats
.rx_time
;
4765 do_div(survey
->time_rx
, USEC_PER_MSEC
);
4767 survey
->time_tx
= mvm
->accu_radio_stats
.tx_time
+
4768 mvm
->radio_stats
.tx_time
;
4769 do_div(survey
->time_tx
, USEC_PER_MSEC
);
4771 survey
->time_scan
= mvm
->accu_radio_stats
.on_time_scan
+
4772 mvm
->radio_stats
.on_time_scan
;
4773 do_div(survey
->time_scan
, USEC_PER_MSEC
);
4777 mutex_unlock(&mvm
->mutex
);
4781 static void iwl_mvm_set_sta_rate(u32 rate_n_flags
, struct rate_info
*rinfo
)
4783 switch (rate_n_flags
& RATE_MCS_CHAN_WIDTH_MSK
) {
4784 case RATE_MCS_CHAN_WIDTH_20
:
4785 rinfo
->bw
= RATE_INFO_BW_20
;
4787 case RATE_MCS_CHAN_WIDTH_40
:
4788 rinfo
->bw
= RATE_INFO_BW_40
;
4790 case RATE_MCS_CHAN_WIDTH_80
:
4791 rinfo
->bw
= RATE_INFO_BW_80
;
4793 case RATE_MCS_CHAN_WIDTH_160
:
4794 rinfo
->bw
= RATE_INFO_BW_160
;
4798 if (rate_n_flags
& RATE_MCS_HT_MSK
) {
4799 rinfo
->flags
|= RATE_INFO_FLAGS_MCS
;
4800 rinfo
->mcs
= u32_get_bits(rate_n_flags
, RATE_HT_MCS_INDEX_MSK
);
4801 rinfo
->nss
= u32_get_bits(rate_n_flags
,
4802 RATE_HT_MCS_NSS_MSK
) + 1;
4803 if (rate_n_flags
& RATE_MCS_SGI_MSK
)
4804 rinfo
->flags
|= RATE_INFO_FLAGS_SHORT_GI
;
4805 } else if (rate_n_flags
& RATE_MCS_VHT_MSK
) {
4806 rinfo
->flags
|= RATE_INFO_FLAGS_VHT_MCS
;
4807 rinfo
->mcs
= u32_get_bits(rate_n_flags
,
4808 RATE_VHT_MCS_RATE_CODE_MSK
);
4809 rinfo
->nss
= u32_get_bits(rate_n_flags
,
4810 RATE_VHT_MCS_NSS_MSK
) + 1;
4811 if (rate_n_flags
& RATE_MCS_SGI_MSK
)
4812 rinfo
->flags
|= RATE_INFO_FLAGS_SHORT_GI
;
4813 } else if (rate_n_flags
& RATE_MCS_HE_MSK
) {
4814 u32 gi_ltf
= u32_get_bits(rate_n_flags
,
4815 RATE_MCS_HE_GI_LTF_MSK
);
4817 rinfo
->flags
|= RATE_INFO_FLAGS_HE_MCS
;
4818 rinfo
->mcs
= u32_get_bits(rate_n_flags
,
4819 RATE_VHT_MCS_RATE_CODE_MSK
);
4820 rinfo
->nss
= u32_get_bits(rate_n_flags
,
4821 RATE_VHT_MCS_NSS_MSK
) + 1;
4823 if (rate_n_flags
& RATE_MCS_HE_106T_MSK
) {
4824 rinfo
->bw
= RATE_INFO_BW_HE_RU
;
4825 rinfo
->he_ru_alloc
= NL80211_RATE_INFO_HE_RU_ALLOC_106
;
4828 switch (rate_n_flags
& RATE_MCS_HE_TYPE_MSK
) {
4829 case RATE_MCS_HE_TYPE_SU
:
4830 case RATE_MCS_HE_TYPE_EXT_SU
:
4831 if (gi_ltf
== 0 || gi_ltf
== 1)
4832 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_0_8
;
4833 else if (gi_ltf
== 2)
4834 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_1_6
;
4835 else if (rate_n_flags
& RATE_MCS_SGI_MSK
)
4836 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_0_8
;
4838 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_3_2
;
4840 case RATE_MCS_HE_TYPE_MU
:
4841 if (gi_ltf
== 0 || gi_ltf
== 1)
4842 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_0_8
;
4843 else if (gi_ltf
== 2)
4844 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_1_6
;
4846 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_3_2
;
4848 case RATE_MCS_HE_TYPE_TRIG
:
4849 if (gi_ltf
== 0 || gi_ltf
== 1)
4850 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_1_6
;
4852 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_3_2
;
4856 if (rate_n_flags
& RATE_HE_DUAL_CARRIER_MODE_MSK
)
4859 switch (u32_get_bits(rate_n_flags
, RATE_LEGACY_RATE_MSK
)) {
4860 case IWL_RATE_1M_PLCP
:
4863 case IWL_RATE_2M_PLCP
:
4866 case IWL_RATE_5M_PLCP
:
4869 case IWL_RATE_11M_PLCP
:
4870 rinfo
->legacy
= 110;
4872 case IWL_RATE_6M_PLCP
:
4875 case IWL_RATE_9M_PLCP
:
4878 case IWL_RATE_12M_PLCP
:
4879 rinfo
->legacy
= 120;
4881 case IWL_RATE_18M_PLCP
:
4882 rinfo
->legacy
= 180;
4884 case IWL_RATE_24M_PLCP
:
4885 rinfo
->legacy
= 240;
4887 case IWL_RATE_36M_PLCP
:
4888 rinfo
->legacy
= 360;
4890 case IWL_RATE_48M_PLCP
:
4891 rinfo
->legacy
= 480;
4893 case IWL_RATE_54M_PLCP
:
4894 rinfo
->legacy
= 540;
4900 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw
*hw
,
4901 struct ieee80211_vif
*vif
,
4902 struct ieee80211_sta
*sta
,
4903 struct station_info
*sinfo
)
4905 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4906 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4907 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
4909 if (mvmsta
->avg_energy
) {
4910 sinfo
->signal_avg
= mvmsta
->avg_energy
;
4911 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG
);
4914 if (iwl_mvm_has_tlc_offload(mvm
)) {
4915 struct iwl_lq_sta_rs_fw
*lq_sta
= &mvmsta
->lq_sta
.rs_fw
;
4917 iwl_mvm_set_sta_rate(lq_sta
->last_rate_n_flags
, &sinfo
->txrate
);
4918 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_BITRATE
);
4921 /* if beacon filtering isn't on mac80211 does it anyway */
4922 if (!(vif
->driver_flags
& IEEE80211_VIF_BEACON_FILTER
))
4925 if (!vif
->bss_conf
.assoc
)
4928 mutex_lock(&mvm
->mutex
);
4930 if (mvmvif
->ap_sta_id
!= mvmsta
->sta_id
)
4933 if (iwl_mvm_request_statistics(mvm
, false))
4936 sinfo
->rx_beacon
= mvmvif
->beacon_stats
.num_beacons
+
4937 mvmvif
->beacon_stats
.accu_num_beacons
;
4938 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_BEACON_RX
);
4939 if (mvmvif
->beacon_stats
.avg_signal
) {
4940 /* firmware only reports a value after RXing a few beacons */
4941 sinfo
->rx_beacon_signal_avg
= mvmvif
->beacon_stats
.avg_signal
;
4942 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG
);
4945 mutex_unlock(&mvm
->mutex
);
4948 static void iwl_mvm_event_mlme_callback(struct iwl_mvm
*mvm
,
4949 struct ieee80211_vif
*vif
,
4950 const struct ieee80211_event
*event
)
4952 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4954 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4956 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4959 struct iwl_fw_dbg_trigger_tlv
*trig
;
4960 struct iwl_fw_dbg_trigger_mlme
*trig_mlme
;
4962 trig
= iwl_fw_dbg_trigger_on(&mvm
->fwrt
, ieee80211_vif_to_wdev(vif
),
4963 FW_DBG_TRIGGER_MLME
);
4967 trig_mlme
= (void *)trig
->data
;
4969 if (event
->u
.mlme
.data
== ASSOC_EVENT
) {
4970 if (event
->u
.mlme
.status
== MLME_DENIED
)
4971 CHECK_MLME_TRIGGER(stop_assoc_denied
,
4972 "DENIED ASSOC: reason %d",
4973 event
->u
.mlme
.reason
);
4974 else if (event
->u
.mlme
.status
== MLME_TIMEOUT
)
4975 CHECK_MLME_TRIGGER(stop_assoc_timeout
,
4977 } else if (event
->u
.mlme
.data
== AUTH_EVENT
) {
4978 if (event
->u
.mlme
.status
== MLME_DENIED
)
4979 CHECK_MLME_TRIGGER(stop_auth_denied
,
4980 "DENIED AUTH: reason %d",
4981 event
->u
.mlme
.reason
);
4982 else if (event
->u
.mlme
.status
== MLME_TIMEOUT
)
4983 CHECK_MLME_TRIGGER(stop_auth_timeout
,
4985 } else if (event
->u
.mlme
.data
== DEAUTH_RX_EVENT
) {
4986 CHECK_MLME_TRIGGER(stop_rx_deauth
,
4987 "DEAUTH RX %d", event
->u
.mlme
.reason
);
4988 } else if (event
->u
.mlme
.data
== DEAUTH_TX_EVENT
) {
4989 CHECK_MLME_TRIGGER(stop_tx_deauth
,
4990 "DEAUTH TX %d", event
->u
.mlme
.reason
);
4992 #undef CHECK_MLME_TRIGGER
4995 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm
*mvm
,
4996 struct ieee80211_vif
*vif
,
4997 const struct ieee80211_event
*event
)
4999 struct iwl_fw_dbg_trigger_tlv
*trig
;
5000 struct iwl_fw_dbg_trigger_ba
*ba_trig
;
5002 trig
= iwl_fw_dbg_trigger_on(&mvm
->fwrt
, ieee80211_vif_to_wdev(vif
),
5007 ba_trig
= (void *)trig
->data
;
5009 if (!(le16_to_cpu(ba_trig
->rx_bar
) & BIT(event
->u
.ba
.tid
)))
5012 iwl_fw_dbg_collect_trig(&mvm
->fwrt
, trig
,
5013 "BAR received from %pM, tid %d, ssn %d",
5014 event
->u
.ba
.sta
->addr
, event
->u
.ba
.tid
,
5018 static void iwl_mvm_mac_event_callback(struct ieee80211_hw
*hw
,
5019 struct ieee80211_vif
*vif
,
5020 const struct ieee80211_event
*event
)
5022 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
5024 switch (event
->type
) {
5026 iwl_mvm_event_mlme_callback(mvm
, vif
, event
);
5029 iwl_mvm_event_bar_rx_callback(mvm
, vif
, event
);
5031 case BA_FRAME_TIMEOUT
:
5032 iwl_mvm_event_frame_timeout_callback(mvm
, vif
, event
->u
.ba
.sta
,
5040 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm
*mvm
,
5041 struct iwl_mvm_internal_rxq_notif
*notif
,
5044 u32 qmask
= BIT(mvm
->trans
->num_rx_queues
) - 1;
5048 if (!iwl_mvm_has_new_rx_api(mvm
))
5052 notif
->cookie
= mvm
->queue_sync_cookie
;
5053 atomic_set(&mvm
->queue_sync_counter
,
5054 mvm
->trans
->num_rx_queues
);
5057 ret
= iwl_mvm_notify_rx_queue(mvm
, qmask
, (u8
*)notif
,
5058 size
, !notif
->sync
);
5060 IWL_ERR(mvm
, "Failed to trigger RX queues sync (%d)\n", ret
);
5065 lockdep_assert_held(&mvm
->mutex
);
5066 ret
= wait_event_timeout(mvm
->rx_sync_waitq
,
5067 atomic_read(&mvm
->queue_sync_counter
) == 0 ||
5068 iwl_mvm_is_radio_killed(mvm
),
5070 WARN_ON_ONCE(!ret
&& !iwl_mvm_is_radio_killed(mvm
));
5074 atomic_set(&mvm
->queue_sync_counter
, 0);
5076 mvm
->queue_sync_cookie
++;
5079 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw
*hw
)
5081 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
5082 struct iwl_mvm_internal_rxq_notif data
= {
5083 .type
= IWL_MVM_RXQ_EMPTY
,
5087 mutex_lock(&mvm
->mutex
);
5088 iwl_mvm_sync_rx_queues_internal(mvm
, &data
, sizeof(data
));
5089 mutex_unlock(&mvm
->mutex
);
5093 iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw
*hw
,
5094 struct ieee80211_vif
*vif
,
5095 struct cfg80211_ftm_responder_stats
*stats
)
5097 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
5098 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
5100 if (vif
->p2p
|| vif
->type
!= NL80211_IFTYPE_AP
||
5101 !mvmvif
->ap_ibss_active
|| !vif
->bss_conf
.ftm_responder
)
5104 mutex_lock(&mvm
->mutex
);
5105 *stats
= mvm
->ftm_resp_stats
;
5106 mutex_unlock(&mvm
->mutex
);
5108 stats
->filled
= BIT(NL80211_FTM_STATS_SUCCESS_NUM
) |
5109 BIT(NL80211_FTM_STATS_PARTIAL_NUM
) |
5110 BIT(NL80211_FTM_STATS_FAILED_NUM
) |
5111 BIT(NL80211_FTM_STATS_ASAP_NUM
) |
5112 BIT(NL80211_FTM_STATS_NON_ASAP_NUM
) |
5113 BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC
) |
5114 BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM
) |
5115 BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM
) |
5116 BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM
);
5121 static int iwl_mvm_start_pmsr(struct ieee80211_hw
*hw
,
5122 struct ieee80211_vif
*vif
,
5123 struct cfg80211_pmsr_request
*request
)
5125 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
5128 mutex_lock(&mvm
->mutex
);
5129 ret
= iwl_mvm_ftm_start(mvm
, vif
, request
);
5130 mutex_unlock(&mvm
->mutex
);
5135 static void iwl_mvm_abort_pmsr(struct ieee80211_hw
*hw
,
5136 struct ieee80211_vif
*vif
,
5137 struct cfg80211_pmsr_request
*request
)
5139 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
5141 mutex_lock(&mvm
->mutex
);
5142 iwl_mvm_ftm_abort(mvm
, request
);
5143 mutex_unlock(&mvm
->mutex
);
5146 static bool iwl_mvm_can_hw_csum(struct sk_buff
*skb
)
5148 u8 protocol
= ip_hdr(skb
)->protocol
;
5150 if (!IS_ENABLED(CONFIG_INET
))
5153 return protocol
== IPPROTO_TCP
|| protocol
== IPPROTO_UDP
;
5156 static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw
*hw
,
5157 struct sk_buff
*head
,
5158 struct sk_buff
*skb
)
5160 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
5162 /* For now don't aggregate IPv6 in AMSDU */
5163 if (skb
->protocol
!= htons(ETH_P_IP
))
5166 if (!iwl_mvm_is_csum_supported(mvm
))
5169 return iwl_mvm_can_hw_csum(skb
) == iwl_mvm_can_hw_csum(head
);
5172 const struct ieee80211_ops iwl_mvm_hw_ops
= {
5173 .tx
= iwl_mvm_mac_tx
,
5174 .wake_tx_queue
= iwl_mvm_mac_wake_tx_queue
,
5175 .ampdu_action
= iwl_mvm_mac_ampdu_action
,
5176 .get_antenna
= iwl_mvm_op_get_antenna
,
5177 .start
= iwl_mvm_mac_start
,
5178 .reconfig_complete
= iwl_mvm_mac_reconfig_complete
,
5179 .stop
= iwl_mvm_mac_stop
,
5180 .add_interface
= iwl_mvm_mac_add_interface
,
5181 .remove_interface
= iwl_mvm_mac_remove_interface
,
5182 .config
= iwl_mvm_mac_config
,
5183 .prepare_multicast
= iwl_mvm_prepare_multicast
,
5184 .configure_filter
= iwl_mvm_configure_filter
,
5185 .config_iface_filter
= iwl_mvm_config_iface_filter
,
5186 .bss_info_changed
= iwl_mvm_bss_info_changed
,
5187 .hw_scan
= iwl_mvm_mac_hw_scan
,
5188 .cancel_hw_scan
= iwl_mvm_mac_cancel_hw_scan
,
5189 .sta_pre_rcu_remove
= iwl_mvm_sta_pre_rcu_remove
,
5190 .sta_state
= iwl_mvm_mac_sta_state
,
5191 .sta_notify
= iwl_mvm_mac_sta_notify
,
5192 .allow_buffered_frames
= iwl_mvm_mac_allow_buffered_frames
,
5193 .release_buffered_frames
= iwl_mvm_mac_release_buffered_frames
,
5194 .set_rts_threshold
= iwl_mvm_mac_set_rts_threshold
,
5195 .sta_rc_update
= iwl_mvm_sta_rc_update
,
5196 .conf_tx
= iwl_mvm_mac_conf_tx
,
5197 .mgd_prepare_tx
= iwl_mvm_mac_mgd_prepare_tx
,
5198 .mgd_protect_tdls_discover
= iwl_mvm_mac_mgd_protect_tdls_discover
,
5199 .flush
= iwl_mvm_mac_flush
,
5200 .sched_scan_start
= iwl_mvm_mac_sched_scan_start
,
5201 .sched_scan_stop
= iwl_mvm_mac_sched_scan_stop
,
5202 .set_key
= iwl_mvm_mac_set_key
,
5203 .update_tkip_key
= iwl_mvm_mac_update_tkip_key
,
5204 .remain_on_channel
= iwl_mvm_roc
,
5205 .cancel_remain_on_channel
= iwl_mvm_cancel_roc
,
5206 .add_chanctx
= iwl_mvm_add_chanctx
,
5207 .remove_chanctx
= iwl_mvm_remove_chanctx
,
5208 .change_chanctx
= iwl_mvm_change_chanctx
,
5209 .assign_vif_chanctx
= iwl_mvm_assign_vif_chanctx
,
5210 .unassign_vif_chanctx
= iwl_mvm_unassign_vif_chanctx
,
5211 .switch_vif_chanctx
= iwl_mvm_switch_vif_chanctx
,
5213 .start_ap
= iwl_mvm_start_ap_ibss
,
5214 .stop_ap
= iwl_mvm_stop_ap_ibss
,
5215 .join_ibss
= iwl_mvm_start_ap_ibss
,
5216 .leave_ibss
= iwl_mvm_stop_ap_ibss
,
5218 .tx_last_beacon
= iwl_mvm_tx_last_beacon
,
5220 .set_tim
= iwl_mvm_set_tim
,
5222 .channel_switch
= iwl_mvm_channel_switch
,
5223 .pre_channel_switch
= iwl_mvm_pre_channel_switch
,
5224 .post_channel_switch
= iwl_mvm_post_channel_switch
,
5225 .abort_channel_switch
= iwl_mvm_abort_channel_switch
,
5226 .channel_switch_rx_beacon
= iwl_mvm_channel_switch_rx_beacon
,
5228 .tdls_channel_switch
= iwl_mvm_tdls_channel_switch
,
5229 .tdls_cancel_channel_switch
= iwl_mvm_tdls_cancel_channel_switch
,
5230 .tdls_recv_channel_switch
= iwl_mvm_tdls_recv_channel_switch
,
5232 .event_callback
= iwl_mvm_mac_event_callback
,
5234 .sync_rx_queues
= iwl_mvm_sync_rx_queues
,
5236 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd
)
5238 #ifdef CONFIG_PM_SLEEP
5240 .suspend
= iwl_mvm_suspend
,
5241 .resume
= iwl_mvm_resume
,
5242 .set_wakeup
= iwl_mvm_set_wakeup
,
5243 .set_rekey_data
= iwl_mvm_set_rekey_data
,
5244 #if IS_ENABLED(CONFIG_IPV6)
5245 .ipv6_addr_change
= iwl_mvm_ipv6_addr_change
,
5247 .set_default_unicast_key
= iwl_mvm_set_default_unicast_key
,
5249 .get_survey
= iwl_mvm_mac_get_survey
,
5250 .sta_statistics
= iwl_mvm_mac_sta_statistics
,
5251 .get_ftm_responder_stats
= iwl_mvm_mac_get_ftm_responder_stats
,
5252 .start_pmsr
= iwl_mvm_start_pmsr
,
5253 .abort_pmsr
= iwl_mvm_abort_pmsr
,
5255 .can_aggregate_in_amsdu
= iwl_mvm_mac_can_aggregate
,
5256 #ifdef CONFIG_IWLWIFI_DEBUGFS
5257 .sta_add_debugfs
= iwl_mvm_sta_add_debugfs
,