1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2012-2014, 2018-2024 Intel Corporation
4 * Copyright (C) 2013-2014 Intel Mobile Communications GmbH
5 * Copyright (C) 2015-2017 Intel Deutschland GmbH
7 #include <linux/etherdevice.h>
8 #include <linux/crc32.h>
9 #include <net/mac80211.h>
14 #include "time-event.h"
16 const u8 iwl_mvm_ac_to_tx_fifo[] = {
23 const u8 iwl_mvm_ac_to_gen2_tx_fifo[] = {
24 IWL_GEN2_EDCA_TX_FIFO_VO,
25 IWL_GEN2_EDCA_TX_FIFO_VI,
26 IWL_GEN2_EDCA_TX_FIFO_BE,
27 IWL_GEN2_EDCA_TX_FIFO_BK,
28 IWL_GEN2_TRIG_TX_FIFO_VO,
29 IWL_GEN2_TRIG_TX_FIFO_VI,
30 IWL_GEN2_TRIG_TX_FIFO_BE,
31 IWL_GEN2_TRIG_TX_FIFO_BK,
34 const u8 iwl_mvm_ac_to_bz_tx_fifo[] = {
35 IWL_BZ_EDCA_TX_FIFO_VO,
36 IWL_BZ_EDCA_TX_FIFO_VI,
37 IWL_BZ_EDCA_TX_FIFO_BE,
38 IWL_BZ_EDCA_TX_FIFO_BK,
39 IWL_BZ_TRIG_TX_FIFO_VO,
40 IWL_BZ_TRIG_TX_FIFO_VI,
41 IWL_BZ_TRIG_TX_FIFO_BE,
42 IWL_BZ_TRIG_TX_FIFO_BK,
45 struct iwl_mvm_mac_iface_iterator_data {
47 struct ieee80211_vif *vif;
48 unsigned long available_mac_ids[BITS_TO_LONGS(NUM_MAC_INDEX_DRIVER)];
49 unsigned long available_tsf_ids[BITS_TO_LONGS(NUM_TSF_IDS)];
50 enum iwl_tsf_id preferred_tsf;
54 static void iwl_mvm_mac_tsf_id_iter(void *_data, u8 *mac,
55 struct ieee80211_vif *vif)
57 struct iwl_mvm_mac_iface_iterator_data *data = _data;
58 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
61 /* Skip the interface for which we are trying to assign a tsf_id */
66 * The TSF is a hardware/firmware resource, there are 4 and
67 * the driver should assign and free them as needed. However,
68 * there are cases where 2 MACs should share the same TSF ID
69 * for the purpose of clock sync, an optimization to avoid
70 * clock drift causing overlapping TBTTs/DTIMs for a GO and
71 * client in the system.
73 * The firmware will decide according to the MAC type which
74 * will be the leader and follower. Clients that need to sync
75 * with a remote station will be the leader, and an AP or GO
76 * will be the follower.
78 * Depending on the new interface type it can be following
79 * or become the leader of an existing interface.
81 switch (data->vif->type) {
82 case NL80211_IFTYPE_STATION:
84 * The new interface is a client, so if the one we're iterating
85 * is an AP, and the beacon interval of the AP is a multiple or
86 * divisor of the beacon interval of the client, the same TSF
87 * should be used to avoid drift between the new client and
88 * existing AP. The existing AP will get drift updates from the
89 * new client context in this case.
91 if (vif->type != NL80211_IFTYPE_AP ||
92 data->preferred_tsf != NUM_TSF_IDS ||
93 !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
96 min_bi = min(data->vif->bss_conf.beacon_int,
97 vif->bss_conf.beacon_int);
102 if ((data->vif->bss_conf.beacon_int -
103 vif->bss_conf.beacon_int) % min_bi == 0) {
104 data->preferred_tsf = mvmvif->tsf_id;
109 case NL80211_IFTYPE_AP:
111 * The new interface is AP/GO, so if its beacon interval is a
112 * multiple or a divisor of the beacon interval of an existing
113 * interface, it should get drift updates from an existing
114 * client or use the same TSF as an existing GO. There's no
115 * drift between TSFs internally but if they used different
116 * TSFs then a new client MAC could update one of them and
117 * cause drift that way.
119 if ((vif->type != NL80211_IFTYPE_AP &&
120 vif->type != NL80211_IFTYPE_STATION) ||
121 data->preferred_tsf != NUM_TSF_IDS ||
122 !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
125 min_bi = min(data->vif->bss_conf.beacon_int,
126 vif->bss_conf.beacon_int);
131 if ((data->vif->bss_conf.beacon_int -
132 vif->bss_conf.beacon_int) % min_bi == 0) {
133 data->preferred_tsf = mvmvif->tsf_id;
139 * For all other interface types there's no need to
140 * take drift into account. Either they're exclusive
141 * like IBSS and monitor, or we don't care much about
142 * their TSF (like P2P Device), but we won't be able
143 * to share the TSF resource.
149 * Unless we exited above, we can't share the TSF resource
150 * that the virtual interface we're iterating over is using
151 * with the new one, so clear the available bit and if this
152 * was the preferred one, reset that as well.
154 __clear_bit(mvmvif->tsf_id, data->available_tsf_ids);
156 if (data->preferred_tsf == mvmvif->tsf_id)
157 data->preferred_tsf = NUM_TSF_IDS;
160 static void iwl_mvm_mac_iface_iterator(void *_data, u8 *mac,
161 struct ieee80211_vif *vif)
163 struct iwl_mvm_mac_iface_iterator_data *data = _data;
164 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
166 /* Iterator may already find the interface being added -- skip it */
167 if (vif == data->vif) {
168 data->found_vif = true;
172 /* Mark MAC IDs as used by clearing the available bit, and
173 * (below) mark TSFs as used if their existing use is not
174 * compatible with the new interface type.
175 * No locking or atomic bit operations are needed since the
176 * data is on the stack of the caller function.
178 __clear_bit(mvmvif->id, data->available_mac_ids);
180 /* find a suitable tsf_id */
181 iwl_mvm_mac_tsf_id_iter(_data, mac, vif);
184 void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm *mvm,
185 struct ieee80211_vif *vif)
187 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
188 struct iwl_mvm_mac_iface_iterator_data data = {
191 .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
192 /* no preference yet */
193 .preferred_tsf = NUM_TSF_IDS,
196 ieee80211_iterate_active_interfaces_atomic(
197 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
198 iwl_mvm_mac_tsf_id_iter, &data);
200 if (data.preferred_tsf != NUM_TSF_IDS)
201 mvmvif->tsf_id = data.preferred_tsf;
202 else if (!test_bit(mvmvif->tsf_id, data.available_tsf_ids))
203 mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
207 int iwl_mvm_mac_ctxt_init(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
209 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
210 struct iwl_mvm_mac_iface_iterator_data data = {
213 .available_mac_ids = { (1 << NUM_MAC_INDEX_DRIVER) - 1 },
214 .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
215 /* no preference yet */
216 .preferred_tsf = NUM_TSF_IDS,
221 lockdep_assert_held(&mvm->mutex);
224 * Allocate a MAC ID and a TSF for this MAC, along with the queues
225 * and other resources.
229 * Before the iterator, we start with all MAC IDs and TSFs available.
231 * During iteration, all MAC IDs are cleared that are in use by other
232 * virtual interfaces, and all TSF IDs are cleared that can't be used
233 * by this new virtual interface because they're used by an interface
234 * that can't share it with the new one.
235 * At the same time, we check if there's a preferred TSF in the case
236 * that we should share it with another interface.
239 /* MAC ID 0 should be used only for the managed/IBSS vif with non-MLO
242 if (!mvm->mld_api_is_used) {
244 case NL80211_IFTYPE_ADHOC:
246 case NL80211_IFTYPE_STATION:
251 __clear_bit(0, data.available_mac_ids);
255 ieee80211_iterate_active_interfaces_atomic(
256 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
257 iwl_mvm_mac_iface_iterator, &data);
260 * In the case we're getting here during resume, it's similar to
261 * firmware restart, and with RESUME_ALL the iterator will find
262 * the vif being added already.
263 * We don't want to reassign any IDs in either case since doing
264 * so would probably assign different IDs (as interfaces aren't
265 * necessarily added in the same order), but the old IDs were
266 * preserved anyway, so skip ID assignment for both resume and
272 /* Therefore, in recovery, we can't get here */
273 if (WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
276 mvmvif->id = find_first_bit(data.available_mac_ids,
277 NUM_MAC_INDEX_DRIVER);
278 if (mvmvif->id == NUM_MAC_INDEX_DRIVER) {
279 IWL_ERR(mvm, "Failed to init MAC context - no free ID!\n");
284 if (data.preferred_tsf != NUM_TSF_IDS)
285 mvmvif->tsf_id = data.preferred_tsf;
287 mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
289 if (mvmvif->tsf_id == NUM_TSF_IDS) {
290 IWL_ERR(mvm, "Failed to init MAC context - no free TSF!\n");
297 INIT_LIST_HEAD(&mvmvif->time_event_data.list);
298 mvmvif->time_event_data.id = TE_MAX;
300 mvmvif->deflink.bcast_sta.sta_id = IWL_MVM_INVALID_STA;
301 mvmvif->deflink.mcast_sta.sta_id = IWL_MVM_INVALID_STA;
302 mvmvif->deflink.ap_sta_id = IWL_MVM_INVALID_STA;
304 /* No need to allocate data queues to P2P Device MAC and NAN.*/
305 if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
308 /* Allocate the CAB queue for softAP and GO interfaces */
309 if (vif->type == NL80211_IFTYPE_AP ||
310 vif->type == NL80211_IFTYPE_ADHOC) {
312 * For TVQM this will be overwritten later with the FW assigned
313 * queue value (when queue is enabled).
315 mvmvif->deflink.cab_queue = IWL_MVM_DQA_GCAST_QUEUE;
318 for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++)
319 mvmvif->deflink.smps_requests[i] = IEEE80211_SMPS_AUTOMATIC;
324 memset(mvmvif, 0, sizeof(struct iwl_mvm_vif));
328 static void iwl_mvm_ack_rates(struct iwl_mvm *mvm,
329 struct ieee80211_vif *vif,
330 enum nl80211_band band,
331 u8 *cck_rates, u8 *ofdm_rates)
333 struct ieee80211_supported_band *sband;
334 unsigned long basic = vif->bss_conf.basic_rates;
335 int lowest_present_ofdm = 100;
336 int lowest_present_cck = 100;
341 sband = mvm->hw->wiphy->bands[band];
343 for_each_set_bit(i, &basic, BITS_PER_LONG) {
344 int hw = sband->bitrates[i].hw_value;
345 if (hw >= IWL_FIRST_OFDM_RATE) {
346 ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE);
347 if (lowest_present_ofdm > hw)
348 lowest_present_ofdm = hw;
350 BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
353 if (lowest_present_cck > hw)
354 lowest_present_cck = hw;
359 * Now we've got the basic rates as bitmaps in the ofdm and cck
360 * variables. This isn't sufficient though, as there might not
361 * be all the right rates in the bitmap. E.g. if the only basic
362 * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps
363 * and 6 Mbps because the 802.11-2007 standard says in 9.6:
365 * [...] a STA responding to a received frame shall transmit
366 * its Control Response frame [...] at the highest rate in the
367 * BSSBasicRateSet parameter that is less than or equal to the
368 * rate of the immediately previous frame in the frame exchange
369 * sequence ([...]) and that is of the same modulation class
370 * ([...]) as the received frame. If no rate contained in the
371 * BSSBasicRateSet parameter meets these conditions, then the
372 * control frame sent in response to a received frame shall be
373 * transmitted at the highest mandatory rate of the PHY that is
374 * less than or equal to the rate of the received frame, and
375 * that is of the same modulation class as the received frame.
377 * As a consequence, we need to add all mandatory rates that are
378 * lower than all of the basic rates to these bitmaps.
381 if (IWL_RATE_24M_INDEX < lowest_present_ofdm)
382 ofdm |= IWL_RATE_BIT_MSK(24) >> IWL_FIRST_OFDM_RATE;
383 if (IWL_RATE_12M_INDEX < lowest_present_ofdm)
384 ofdm |= IWL_RATE_BIT_MSK(12) >> IWL_FIRST_OFDM_RATE;
385 /* 6M already there or needed so always add */
386 ofdm |= IWL_RATE_BIT_MSK(6) >> IWL_FIRST_OFDM_RATE;
389 * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP.
391 * - if no CCK rates are basic, it must be ERP since there must
392 * be some basic rates at all, so they're OFDM => ERP PHY
393 * (or we're in 5 GHz, and the cck bitmap will never be used)
394 * - if 11M is a basic rate, it must be ERP as well, so add 5.5M
395 * - if 5.5M is basic, 1M and 2M are mandatory
396 * - if 2M is basic, 1M is mandatory
397 * - if 1M is basic, that's the only valid ACK rate.
398 * As a consequence, it's not as complicated as it sounds, just add
399 * any lower rates to the ACK rate bitmap.
401 if (IWL_RATE_11M_INDEX < lowest_present_cck)
402 cck |= IWL_RATE_BIT_MSK(11) >> IWL_FIRST_CCK_RATE;
403 if (IWL_RATE_5M_INDEX < lowest_present_cck)
404 cck |= IWL_RATE_BIT_MSK(5) >> IWL_FIRST_CCK_RATE;
405 if (IWL_RATE_2M_INDEX < lowest_present_cck)
406 cck |= IWL_RATE_BIT_MSK(2) >> IWL_FIRST_CCK_RATE;
407 /* 1M already there or needed so always add */
408 cck |= IWL_RATE_BIT_MSK(1) >> IWL_FIRST_CCK_RATE;
414 void iwl_mvm_set_fw_basic_rates(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
415 struct ieee80211_bss_conf *link_conf,
416 __le32 *cck_rates, __le32 *ofdm_rates)
418 struct ieee80211_chanctx_conf *chanctx;
419 u8 cck_ack_rates = 0, ofdm_ack_rates = 0;
422 chanctx = rcu_dereference(link_conf->chanctx_conf);
423 iwl_mvm_ack_rates(mvm, vif, chanctx ? chanctx->def.chan->band
425 &cck_ack_rates, &ofdm_ack_rates);
429 *cck_rates = cpu_to_le32((u32)cck_ack_rates);
430 *ofdm_rates = cpu_to_le32((u32)ofdm_ack_rates);
433 void iwl_mvm_set_fw_protection_flags(struct iwl_mvm *mvm,
434 struct ieee80211_vif *vif,
435 struct ieee80211_bss_conf *link_conf,
436 __le32 *protection_flags, u32 ht_flag,
439 /* for both sta and ap, ht_operation_mode hold the protection_mode */
440 u8 protection_mode = link_conf->ht_operation_mode &
441 IEEE80211_HT_OP_MODE_PROTECTION;
442 bool ht_enabled = !!(link_conf->ht_operation_mode &
443 IEEE80211_HT_OP_MODE_PROTECTION);
445 if (link_conf->use_cts_prot)
446 *protection_flags |= cpu_to_le32(tgg_flag);
448 IWL_DEBUG_RATE(mvm, "use_cts_prot %d, ht_operation_mode %d\n",
449 link_conf->use_cts_prot,
450 link_conf->ht_operation_mode);
455 IWL_DEBUG_RATE(mvm, "protection mode set to %d\n", protection_mode);
457 * See section 9.23.3.1 of IEEE 80211-2012.
458 * Nongreenfield HT STAs Present is not supported.
460 switch (protection_mode) {
461 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
463 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
464 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
465 *protection_flags |= cpu_to_le32(ht_flag);
467 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
468 /* Protect when channel wider than 20MHz */
469 if (link_conf->chanreq.oper.width > NL80211_CHAN_WIDTH_20)
470 *protection_flags |= cpu_to_le32(ht_flag);
473 IWL_ERR(mvm, "Illegal protection mode %d\n",
479 void iwl_mvm_set_fw_qos_params(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
480 struct ieee80211_bss_conf *link_conf,
481 struct iwl_ac_qos *ac, __le32 *qos_flags)
483 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
484 struct iwl_mvm_vif_link_info *mvm_link =
485 mvmvif->link[link_conf->link_id];
491 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
492 u8 txf = iwl_mvm_mac_ac_to_tx_fifo(mvm, i);
493 u8 ucode_ac = iwl_mvm_mac80211_ac_to_ucode_ac(i);
495 ac[ucode_ac].cw_min =
496 cpu_to_le16(mvm_link->queue_params[i].cw_min);
497 ac[ucode_ac].cw_max =
498 cpu_to_le16(mvm_link->queue_params[i].cw_max);
499 ac[ucode_ac].edca_txop =
500 cpu_to_le16(mvm_link->queue_params[i].txop * 32);
501 ac[ucode_ac].aifsn = mvm_link->queue_params[i].aifs;
502 ac[ucode_ac].fifos_mask = BIT(txf);
506 *qos_flags |= cpu_to_le32(MAC_QOS_FLG_UPDATE_EDCA);
508 if (link_conf->chanreq.oper.width != NL80211_CHAN_WIDTH_20_NOHT)
509 *qos_flags |= cpu_to_le32(MAC_QOS_FLG_TGN);
512 int iwl_mvm_get_mac_type(struct ieee80211_vif *vif)
514 u32 mac_type = FW_MAC_TYPE_BSS_STA;
517 case NL80211_IFTYPE_STATION:
519 mac_type = FW_MAC_TYPE_P2P_STA;
521 mac_type = FW_MAC_TYPE_BSS_STA;
523 case NL80211_IFTYPE_AP:
524 mac_type = FW_MAC_TYPE_GO;
526 case NL80211_IFTYPE_MONITOR:
527 mac_type = FW_MAC_TYPE_LISTENER;
529 case NL80211_IFTYPE_P2P_DEVICE:
530 mac_type = FW_MAC_TYPE_P2P_DEVICE;
532 case NL80211_IFTYPE_ADHOC:
533 mac_type = FW_MAC_TYPE_IBSS;
541 static void iwl_mvm_mac_ctxt_cmd_common(struct iwl_mvm *mvm,
542 struct ieee80211_vif *vif,
543 struct iwl_mac_ctx_cmd *cmd,
544 const u8 *bssid_override,
547 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
548 const u8 *bssid = bssid_override ?: vif->bss_conf.bssid;
551 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
553 cmd->action = cpu_to_le32(action);
554 cmd->mac_type = cpu_to_le32(iwl_mvm_get_mac_type(vif));
556 cmd->tsf_id = cpu_to_le32(mvmvif->tsf_id);
558 memcpy(cmd->node_addr, vif->addr, ETH_ALEN);
561 memcpy(cmd->bssid_addr, bssid, ETH_ALEN);
563 eth_broadcast_addr(cmd->bssid_addr);
565 iwl_mvm_set_fw_basic_rates(mvm, vif, &vif->bss_conf, &cmd->cck_rates,
568 cmd->cck_short_preamble =
569 cpu_to_le32(vif->bss_conf.use_short_preamble ?
570 MAC_FLG_SHORT_PREAMBLE : 0);
572 cpu_to_le32(vif->bss_conf.use_short_slot ?
573 MAC_FLG_SHORT_SLOT : 0);
575 cmd->filter_flags = 0;
577 iwl_mvm_set_fw_qos_params(mvm, vif, &vif->bss_conf, cmd->ac,
580 /* The fw does not distinguish between ht and fat */
581 ht_flag = MAC_PROT_FLG_HT_PROT | MAC_PROT_FLG_FAT_PROT;
582 iwl_mvm_set_fw_protection_flags(mvm, vif, &vif->bss_conf,
583 &cmd->protection_flags,
584 ht_flag, MAC_PROT_FLG_TGG_PROTECT);
587 static int iwl_mvm_mac_ctxt_send_cmd(struct iwl_mvm *mvm,
588 struct iwl_mac_ctx_cmd *cmd)
590 int ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, 0,
593 IWL_ERR(mvm, "Failed to send MAC_CONTEXT_CMD (action:%d): %d\n",
594 le32_to_cpu(cmd->action), ret);
598 void iwl_mvm_set_fw_dtim_tbtt(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
599 struct ieee80211_bss_conf *link_conf,
600 __le64 *dtim_tsf, __le32 *dtim_time,
601 __le32 *assoc_beacon_arrive_time)
606 * The DTIM count counts down, so when it is N that means N
607 * more beacon intervals happen until the DTIM TBTT. Therefore
608 * add this to the current time. If that ends up being in the
609 * future, the firmware will handle it.
611 * Also note that the system_timestamp (which we get here as
612 * "sync_device_ts") and TSF timestamp aren't at exactly the
613 * same offset in the frame -- the TSF is at the first symbol
614 * of the TSF, the system timestamp is at signal acquisition
615 * time. This means there's an offset between them of at most
616 * a few hundred microseconds (24 * 8 bits + PLCP time gives
617 * 384us in the longest case), this is currently not relevant
618 * as the firmware wakes up around 2ms before the TBTT.
620 dtim_offs = link_conf->sync_dtim_count *
621 link_conf->beacon_int;
622 /* convert TU to usecs */
626 cpu_to_le64(link_conf->sync_tsf + dtim_offs);
628 cpu_to_le32(link_conf->sync_device_ts + dtim_offs);
629 *assoc_beacon_arrive_time =
630 cpu_to_le32(link_conf->sync_device_ts);
632 IWL_DEBUG_INFO(mvm, "DTIM TBTT is 0x%llx/0x%x, offset %d\n",
633 le64_to_cpu(*dtim_tsf),
634 le32_to_cpu(*dtim_time),
638 __le32 iwl_mvm_mac_ctxt_cmd_p2p_sta_get_oppps_ctwin(struct iwl_mvm *mvm,
639 struct ieee80211_vif *vif)
641 struct ieee80211_p2p_noa_attr *noa =
642 &vif->bss_conf.p2p_noa_attr;
644 return cpu_to_le32(noa->oppps_ctwindow &
645 IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
648 u32 iwl_mvm_mac_ctxt_cmd_sta_get_twt_policy(struct iwl_mvm *mvm,
649 struct ieee80211_vif *vif)
653 if (vif->bss_conf.twt_requester && IWL_MVM_USE_TWT)
654 twt_policy |= TWT_SUPPORTED;
655 if (vif->bss_conf.twt_protected)
656 twt_policy |= PROTECTED_TWT_SUPPORTED;
657 if (vif->bss_conf.twt_broadcast)
658 twt_policy |= BROADCAST_TWT_SUPPORTED;
663 static int iwl_mvm_mac_ctxt_cmd_sta(struct iwl_mvm *mvm,
664 struct ieee80211_vif *vif,
665 u32 action, bool force_assoc_off,
666 const u8 *bssid_override)
668 struct iwl_mac_ctx_cmd cmd = {};
669 struct iwl_mac_data_sta *ctxt_sta;
671 WARN_ON(vif->type != NL80211_IFTYPE_STATION);
673 /* Fill the common data for all mac context types */
674 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, bssid_override, action);
677 * We always want to hear MCAST frames, if we're not authorized yet,
680 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_ACCEPT_GRP);
684 iwl_mvm_mac_ctxt_cmd_p2p_sta_get_oppps_ctwin(mvm, vif);
686 ctxt_sta = &cmd.p2p_sta.sta;
691 /* We need the dtim_period to set the MAC as associated */
692 if (vif->cfg.assoc && vif->bss_conf.dtim_period &&
694 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
696 iwl_mvm_set_fw_dtim_tbtt(mvm, vif, &vif->bss_conf,
698 &ctxt_sta->dtim_time,
699 &ctxt_sta->assoc_beacon_arrive_time);
701 ctxt_sta->is_assoc = cpu_to_le32(1);
703 if (!mvmvif->authorized &&
704 fw_has_capa(&mvm->fw->ucode_capa,
705 IWL_UCODE_TLV_CAPA_COEX_HIGH_PRIO))
706 ctxt_sta->data_policy |=
707 cpu_to_le32(COEX_HIGH_PRIORITY_ENABLE);
709 ctxt_sta->is_assoc = cpu_to_le32(0);
711 /* Allow beacons to pass through as long as we are not
712 * associated, or we do not have dtim period information.
714 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_BEACON);
717 ctxt_sta->bi = cpu_to_le32(vif->bss_conf.beacon_int);
718 ctxt_sta->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
719 vif->bss_conf.dtim_period);
721 ctxt_sta->listen_interval = cpu_to_le32(mvm->hw->conf.listen_interval);
722 ctxt_sta->assoc_id = cpu_to_le32(vif->cfg.aid);
724 if (vif->probe_req_reg && vif->cfg.assoc && vif->p2p)
725 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
727 if (vif->bss_conf.he_support && !iwlwifi_mod_params.disable_11ax) {
728 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_11AX);
729 ctxt_sta->data_policy |=
730 cpu_to_le32(iwl_mvm_mac_ctxt_cmd_sta_get_twt_policy(mvm, vif));
734 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
737 static int iwl_mvm_mac_ctxt_cmd_listener(struct iwl_mvm *mvm,
738 struct ieee80211_vif *vif,
741 struct iwl_mac_ctx_cmd cmd = {};
742 u32 tfd_queue_msk = 0;
745 WARN_ON(vif->type != NL80211_IFTYPE_MONITOR);
747 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
749 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROMISC |
750 MAC_FILTER_IN_CONTROL_AND_MGMT |
751 MAC_FILTER_IN_BEACON |
752 MAC_FILTER_IN_PROBE_REQUEST |
753 MAC_FILTER_IN_CRC32 |
754 MAC_FILTER_ACCEPT_GRP);
755 ieee80211_hw_set(mvm->hw, RX_INCLUDES_FCS);
758 * the queue mask is only relevant for old TX API, and
759 * mvm->snif_queue isn't set here (it's still set to
760 * IWL_MVM_INVALID_QUEUE so the BIT() of it is UB)
762 if (!iwl_mvm_has_new_tx_api(mvm))
763 tfd_queue_msk = BIT(mvm->snif_queue);
765 /* Allocate sniffer station */
766 ret = iwl_mvm_allocate_int_sta(mvm, &mvm->snif_sta, tfd_queue_msk,
767 vif->type, IWL_STA_GENERAL_PURPOSE);
771 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
774 static int iwl_mvm_mac_ctxt_cmd_ibss(struct iwl_mvm *mvm,
775 struct ieee80211_vif *vif,
778 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
779 struct iwl_mac_ctx_cmd cmd = {};
781 WARN_ON(vif->type != NL80211_IFTYPE_ADHOC);
783 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
785 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_BEACON |
786 MAC_FILTER_IN_PROBE_REQUEST |
787 MAC_FILTER_ACCEPT_GRP);
789 /* cmd.ibss.beacon_time/cmd.ibss.beacon_tsf are curently ignored */
790 cmd.ibss.bi = cpu_to_le32(vif->bss_conf.beacon_int);
792 /* TODO: Assumes that the beacon id == mac context id */
793 cmd.ibss.beacon_template = cpu_to_le32(mvmvif->id);
795 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
798 struct iwl_mvm_go_iterator_data {
802 static void iwl_mvm_go_iterator(void *_data, u8 *mac, struct ieee80211_vif *vif)
804 struct iwl_mvm_go_iterator_data *data = _data;
805 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
807 if (vif->type == NL80211_IFTYPE_AP && vif->p2p &&
808 mvmvif->ap_ibss_active)
809 data->go_active = true;
812 __le32 iwl_mac_ctxt_p2p_dev_has_extended_disc(struct iwl_mvm *mvm,
813 struct ieee80211_vif *vif)
815 struct iwl_mvm_go_iterator_data data = {};
818 * This flag should be set to true when the P2P Device is
819 * discoverable and there is at least another active P2P GO. Settings
820 * this flag will allow the P2P Device to be discoverable on other
821 * channels in addition to its listen channel.
822 * Note that this flag should not be set in other cases as it opens the
823 * Rx filters on all MAC and increases the number of interrupts.
825 ieee80211_iterate_active_interfaces_atomic(
826 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
827 iwl_mvm_go_iterator, &data);
829 return cpu_to_le32(data.go_active ? 1 : 0);
832 static int iwl_mvm_mac_ctxt_cmd_p2p_device(struct iwl_mvm *mvm,
833 struct ieee80211_vif *vif,
836 struct iwl_mac_ctx_cmd cmd = {};
838 WARN_ON(vif->type != NL80211_IFTYPE_P2P_DEVICE);
840 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
842 cmd.p2p_dev.is_disc_extended =
843 iwl_mac_ctxt_p2p_dev_has_extended_disc(mvm, vif);
845 /* Override the filter flags to accept only probe requests */
846 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
848 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
851 void iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm *mvm,
852 __le32 *tim_index, __le32 *tim_size,
853 u8 *beacon, u32 frame_size)
856 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
858 /* The index is relative to frame start but we start looking at the
859 * variable-length part of the beacon. */
860 tim_idx = mgmt->u.beacon.variable - beacon;
862 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
863 while ((tim_idx < (frame_size - 2)) &&
864 (beacon[tim_idx] != WLAN_EID_TIM))
865 tim_idx += beacon[tim_idx+1] + 2;
867 /* If TIM field was found, set variables */
868 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
869 *tim_index = cpu_to_le32(tim_idx);
870 *tim_size = cpu_to_le32((u32)beacon[tim_idx + 1]);
872 IWL_WARN(mvm, "Unable to find TIM Element in beacon\n");
876 u32 iwl_mvm_find_ie_offset(u8 *beacon, u8 eid, u32 frame_size)
878 struct ieee80211_mgmt *mgmt = (void *)beacon;
881 if (WARN_ON_ONCE(frame_size <= (mgmt->u.beacon.variable - beacon)))
884 frame_size -= mgmt->u.beacon.variable - beacon;
886 ie = cfg80211_find_ie(eid, mgmt->u.beacon.variable, frame_size);
893 u8 iwl_mvm_mac_ctxt_get_lowest_rate(struct iwl_mvm *mvm,
894 struct ieee80211_tx_info *info,
895 struct ieee80211_vif *vif)
897 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
898 struct ieee80211_supported_band *sband;
899 unsigned long basic = vif->bss_conf.basic_rates;
900 u16 lowest_cck = IWL_RATE_COUNT, lowest_ofdm = IWL_RATE_COUNT;
901 u32 link_id = u32_get_bits(info->control.flags,
902 IEEE80211_TX_CTRL_MLO_LINK);
903 u8 band = info->band;
907 if (link_id == IEEE80211_LINK_UNSPECIFIED && ieee80211_vif_is_mld(vif)) {
908 for (i = 0; i < ARRAY_SIZE(mvmvif->link); i++) {
909 if (!mvmvif->link[i])
911 /* shouldn't do this when >1 link is active */
912 WARN_ON_ONCE(link_id != IEEE80211_LINK_UNSPECIFIED);
917 if (link_id < IEEE80211_LINK_UNSPECIFIED) {
918 struct ieee80211_bss_conf *link_conf;
921 link_conf = rcu_dereference(vif->link_conf[link_id]);
923 basic = link_conf->basic_rates;
924 if (link_conf->chanreq.oper.chan)
925 band = link_conf->chanreq.oper.chan->band;
930 sband = mvm->hw->wiphy->bands[band];
931 for_each_set_bit(i, &basic, BITS_PER_LONG) {
932 u16 hw = sband->bitrates[i].hw_value;
934 if (hw >= IWL_FIRST_OFDM_RATE) {
935 if (lowest_ofdm > hw)
937 } else if (lowest_cck > hw) {
942 if (band == NL80211_BAND_2GHZ && !vif->p2p &&
943 vif->type != NL80211_IFTYPE_P2P_DEVICE &&
944 !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)) {
945 if (lowest_cck != IWL_RATE_COUNT)
947 else if (lowest_ofdm != IWL_RATE_COUNT)
950 rate = IWL_RATE_1M_INDEX;
951 } else if (lowest_ofdm != IWL_RATE_COUNT) {
954 rate = IWL_RATE_6M_INDEX;
960 u16 iwl_mvm_mac_ctxt_get_beacon_flags(const struct iwl_fw *fw, u8 rate_idx)
962 u16 flags = iwl_mvm_mac80211_idx_to_hwrate(fw, rate_idx);
963 bool is_new_rate = iwl_fw_lookup_cmd_ver(fw, BEACON_TEMPLATE_CMD, 0) > 10;
965 if (rate_idx <= IWL_FIRST_CCK_RATE)
966 flags |= is_new_rate ? IWL_MAC_BEACON_CCK
967 : IWL_MAC_BEACON_CCK_V1;
972 u8 iwl_mvm_mac_ctxt_get_beacon_rate(struct iwl_mvm *mvm,
973 struct ieee80211_tx_info *info,
974 struct ieee80211_vif *vif)
976 struct ieee80211_supported_band *sband =
977 mvm->hw->wiphy->bands[info->band];
978 u32 legacy = vif->bss_conf.beacon_tx_rate.control[info->band].legacy;
980 /* if beacon rate was configured try using it */
981 if (hweight32(legacy) == 1) {
982 u32 rate = ffs(legacy) - 1;
984 return sband->bitrates[rate].hw_value;
987 return iwl_mvm_mac_ctxt_get_lowest_rate(mvm, info, vif);
990 static void iwl_mvm_mac_ctxt_set_tx(struct iwl_mvm *mvm,
991 struct ieee80211_vif *vif,
992 struct sk_buff *beacon,
993 struct iwl_tx_cmd *tx)
995 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
996 struct ieee80211_tx_info *info;
1000 info = IEEE80211_SKB_CB(beacon);
1002 /* Set up TX command fields */
1003 tx->len = cpu_to_le16((u16)beacon->len);
1004 tx->sta_id = mvmvif->deflink.bcast_sta.sta_id;
1005 tx->life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
1006 tx_flags = TX_CMD_FLG_SEQ_CTL | TX_CMD_FLG_TSF;
1008 iwl_mvm_bt_coex_tx_prio(mvm, (void *)beacon->data, info, 0) <<
1009 TX_CMD_FLG_BT_PRIO_POS;
1010 tx->tx_flags = cpu_to_le32(tx_flags);
1012 if (!fw_has_capa(&mvm->fw->ucode_capa,
1013 IWL_UCODE_TLV_CAPA_BEACON_ANT_SELECTION))
1014 iwl_mvm_toggle_tx_ant(mvm, &mvm->mgmt_last_antenna_idx);
1017 cpu_to_le32(BIT(mvm->mgmt_last_antenna_idx) <<
1020 rate = iwl_mvm_mac_ctxt_get_beacon_rate(mvm, info, vif);
1023 cpu_to_le32(iwl_mvm_mac80211_idx_to_hwrate(mvm->fw, rate));
1024 if (rate == IWL_FIRST_CCK_RATE)
1025 tx->rate_n_flags |= cpu_to_le32(RATE_MCS_CCK_MSK_V1);
1029 int iwl_mvm_mac_ctxt_send_beacon_cmd(struct iwl_mvm *mvm,
1030 struct sk_buff *beacon,
1031 void *data, int len)
1033 struct iwl_host_cmd cmd = {
1034 .id = BEACON_TEMPLATE_CMD,
1040 cmd.dataflags[0] = 0;
1041 cmd.len[1] = beacon->len;
1042 cmd.data[1] = beacon->data;
1043 cmd.dataflags[1] = IWL_HCMD_DFL_DUP;
1045 return iwl_mvm_send_cmd(mvm, &cmd);
1048 static int iwl_mvm_mac_ctxt_send_beacon_v6(struct iwl_mvm *mvm,
1049 struct ieee80211_vif *vif,
1050 struct sk_buff *beacon)
1052 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1053 struct iwl_mac_beacon_cmd_v6 beacon_cmd = {};
1055 iwl_mvm_mac_ctxt_set_tx(mvm, vif, beacon, &beacon_cmd.tx);
1057 beacon_cmd.template_id = cpu_to_le32((u32)mvmvif->id);
1059 if (vif->type == NL80211_IFTYPE_AP)
1060 iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd.tim_idx,
1061 &beacon_cmd.tim_size,
1062 beacon->data, beacon->len);
1064 return iwl_mvm_mac_ctxt_send_beacon_cmd(mvm, beacon, &beacon_cmd,
1065 sizeof(beacon_cmd));
1068 static int iwl_mvm_mac_ctxt_send_beacon_v7(struct iwl_mvm *mvm,
1069 struct ieee80211_vif *vif,
1070 struct sk_buff *beacon)
1072 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1073 struct iwl_mac_beacon_cmd_v7 beacon_cmd = {};
1075 iwl_mvm_mac_ctxt_set_tx(mvm, vif, beacon, &beacon_cmd.tx);
1077 beacon_cmd.template_id = cpu_to_le32((u32)mvmvif->id);
1079 if (vif->type == NL80211_IFTYPE_AP)
1080 iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd.tim_idx,
1081 &beacon_cmd.tim_size,
1082 beacon->data, beacon->len);
1084 beacon_cmd.csa_offset =
1085 cpu_to_le32(iwl_mvm_find_ie_offset(beacon->data,
1086 WLAN_EID_CHANNEL_SWITCH,
1088 beacon_cmd.ecsa_offset =
1089 cpu_to_le32(iwl_mvm_find_ie_offset(beacon->data,
1090 WLAN_EID_EXT_CHANSWITCH_ANN,
1093 return iwl_mvm_mac_ctxt_send_beacon_cmd(mvm, beacon, &beacon_cmd,
1094 sizeof(beacon_cmd));
1097 bool iwl_mvm_enable_fils(struct iwl_mvm *mvm,
1098 struct ieee80211_chanctx_conf *ctx)
1100 if (IWL_MVM_DISABLE_AP_FILS)
1103 if (cfg80211_channel_is_psc(ctx->def.chan))
1106 return (ctx->def.chan->band == NL80211_BAND_6GHZ &&
1107 ctx->def.width >= NL80211_CHAN_WIDTH_80);
1110 static int iwl_mvm_mac_ctxt_send_beacon_v9(struct iwl_mvm *mvm,
1111 struct ieee80211_vif *vif,
1112 struct sk_buff *beacon,
1113 struct ieee80211_bss_conf *link_conf)
1115 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1116 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(beacon);
1117 struct iwl_mac_beacon_cmd beacon_cmd = {};
1118 u8 rate = iwl_mvm_mac_ctxt_get_beacon_rate(mvm, info, vif);
1120 struct ieee80211_chanctx_conf *ctx;
1122 flags = iwl_mvm_mac_ctxt_get_beacon_flags(mvm->fw, rate);
1124 /* Enable FILS on PSC channels only */
1126 ctx = rcu_dereference(link_conf->chanctx_conf);
1127 channel = ieee80211_frequency_to_channel(ctx->def.chan->center_freq);
1128 WARN_ON(channel == 0);
1129 if (iwl_mvm_enable_fils(mvm, ctx)) {
1130 flags |= iwl_fw_lookup_cmd_ver(mvm->fw, BEACON_TEMPLATE_CMD,
1132 IWL_MAC_BEACON_FILS :
1133 IWL_MAC_BEACON_FILS_V1;
1134 beacon_cmd.short_ssid =
1135 cpu_to_le32(~crc32_le(~0, vif->cfg.ssid,
1136 vif->cfg.ssid_len));
1140 beacon_cmd.flags = cpu_to_le16(flags);
1141 beacon_cmd.byte_cnt = cpu_to_le16((u16)beacon->len);
1143 if (WARN_ON(!mvmvif->link[link_conf->link_id]))
1146 if (iwl_fw_lookup_cmd_ver(mvm->fw, BEACON_TEMPLATE_CMD, 0) > 12)
1147 beacon_cmd.link_id =
1148 cpu_to_le32(mvmvif->link[link_conf->link_id]->fw_link_id);
1150 beacon_cmd.link_id = cpu_to_le32((u32)mvmvif->id);
1152 if (vif->type == NL80211_IFTYPE_AP)
1153 iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd.tim_idx,
1154 &beacon_cmd.tim_size,
1155 beacon->data, beacon->len);
1157 beacon_cmd.csa_offset =
1158 cpu_to_le32(iwl_mvm_find_ie_offset(beacon->data,
1159 WLAN_EID_CHANNEL_SWITCH,
1161 beacon_cmd.ecsa_offset =
1162 cpu_to_le32(iwl_mvm_find_ie_offset(beacon->data,
1163 WLAN_EID_EXT_CHANSWITCH_ANN,
1166 if (vif->type == NL80211_IFTYPE_AP &&
1167 iwl_fw_lookup_cmd_ver(mvm->fw, BEACON_TEMPLATE_CMD, 0) >= 14)
1168 beacon_cmd.btwt_offset =
1169 cpu_to_le32(iwl_mvm_find_ie_offset(beacon->data,
1173 return iwl_mvm_mac_ctxt_send_beacon_cmd(mvm, beacon, &beacon_cmd,
1174 sizeof(beacon_cmd));
1177 static int iwl_mvm_mac_ctxt_send_beacon(struct iwl_mvm *mvm,
1178 struct ieee80211_vif *vif,
1179 struct sk_buff *beacon,
1180 struct ieee80211_bss_conf *link_conf)
1182 if (WARN_ON(!beacon))
1185 if (IWL_MVM_NON_TRANSMITTING_AP)
1188 if (!fw_has_capa(&mvm->fw->ucode_capa,
1189 IWL_UCODE_TLV_CAPA_CSA_AND_TBTT_OFFLOAD))
1190 return iwl_mvm_mac_ctxt_send_beacon_v6(mvm, vif, beacon);
1192 if (fw_has_api(&mvm->fw->ucode_capa,
1193 IWL_UCODE_TLV_API_NEW_BEACON_TEMPLATE))
1194 return iwl_mvm_mac_ctxt_send_beacon_v9(mvm, vif, beacon,
1197 return iwl_mvm_mac_ctxt_send_beacon_v7(mvm, vif, beacon);
1200 /* The beacon template for the AP/GO/IBSS has changed and needs update */
1201 int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm,
1202 struct ieee80211_vif *vif,
1203 struct ieee80211_bss_conf *link_conf)
1205 struct sk_buff *beacon;
1208 WARN_ON(vif->type != NL80211_IFTYPE_AP &&
1209 vif->type != NL80211_IFTYPE_ADHOC);
1211 beacon = ieee80211_beacon_get_template(mvm->hw, vif, NULL,
1212 link_conf->link_id);
1216 #ifdef CONFIG_IWLWIFI_DEBUGFS
1217 if (mvm->beacon_inject_active) {
1218 dev_kfree_skb(beacon);
1223 ret = iwl_mvm_mac_ctxt_send_beacon(mvm, vif, beacon, link_conf);
1224 dev_kfree_skb(beacon);
1228 struct iwl_mvm_mac_ap_iterator_data {
1229 struct iwl_mvm *mvm;
1230 struct ieee80211_vif *vif;
1231 u32 beacon_device_ts;
1235 /* Find the beacon_device_ts and beacon_int for a managed interface */
1236 static void iwl_mvm_mac_ap_iterator(void *_data, u8 *mac,
1237 struct ieee80211_vif *vif)
1239 struct iwl_mvm_mac_ap_iterator_data *data = _data;
1241 if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc)
1244 /* Station client has higher priority over P2P client*/
1245 if (vif->p2p && data->beacon_device_ts)
1248 data->beacon_device_ts = vif->bss_conf.sync_device_ts;
1249 data->beacon_int = vif->bss_conf.beacon_int;
1253 * Fill the filter flags for mac context of type AP or P2P GO.
1255 void iwl_mvm_mac_ctxt_cmd_ap_set_filter_flags(struct iwl_mvm *mvm,
1256 struct iwl_mvm_vif *mvmvif,
1257 __le32 *filter_flags,
1258 int accept_probe_req_flag,
1259 int accept_beacon_flag)
1262 * in AP mode, pass probe requests and beacons from other APs
1263 * (needed for ht protection); when there're no any associated
1264 * station don't ask FW to pass beacons to prevent unnecessary
1267 *filter_flags |= cpu_to_le32(accept_probe_req_flag);
1268 if (mvmvif->ap_assoc_sta_count || !mvm->drop_bcn_ap_mode) {
1269 *filter_flags |= cpu_to_le32(accept_beacon_flag);
1270 IWL_DEBUG_HC(mvm, "Asking FW to pass beacons\n");
1272 IWL_DEBUG_HC(mvm, "No need to receive beacons\n");
1277 * Fill the specific data for mac context of type AP of P2P GO
1279 static void iwl_mvm_mac_ctxt_cmd_fill_ap(struct iwl_mvm *mvm,
1280 struct ieee80211_vif *vif,
1281 struct iwl_mac_ctx_cmd *cmd,
1282 struct iwl_mac_data_ap *ctxt_ap,
1285 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1286 struct iwl_mvm_mac_ap_iterator_data data = {
1289 .beacon_device_ts = 0
1292 /* in AP mode, the MCAST FIFO takes the EDCA params from VO */
1293 cmd->ac[IWL_MVM_TX_FIFO_VO].fifos_mask |= BIT(IWL_MVM_TX_FIFO_MCAST);
1295 iwl_mvm_mac_ctxt_cmd_ap_set_filter_flags(mvm, mvmvif,
1297 MAC_FILTER_IN_PROBE_REQUEST,
1298 MAC_FILTER_IN_BEACON);
1300 ctxt_ap->bi = cpu_to_le32(vif->bss_conf.beacon_int);
1301 ctxt_ap->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
1302 vif->bss_conf.dtim_period);
1304 if (!fw_has_api(&mvm->fw->ucode_capa,
1305 IWL_UCODE_TLV_API_STA_TYPE))
1306 ctxt_ap->mcast_qid = cpu_to_le32(mvmvif->deflink.cab_queue);
1309 * Only set the beacon time when the MAC is being added, when we
1310 * just modify the MAC then we should keep the time -- the firmware
1311 * can otherwise have a "jumping" TBTT.
1315 * If there is a station/P2P client interface which is
1316 * associated, set the AP's TBTT far enough from the station's
1317 * TBTT. Otherwise, set it to the current system time
1319 ieee80211_iterate_active_interfaces_atomic(
1320 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1321 iwl_mvm_mac_ap_iterator, &data);
1323 if (data.beacon_device_ts) {
1324 u32 rand = get_random_u32_inclusive(36, 63);
1325 mvmvif->ap_beacon_time = data.beacon_device_ts +
1326 ieee80211_tu_to_usec(data.beacon_int * rand /
1329 mvmvif->ap_beacon_time = iwl_mvm_get_systime(mvm);
1333 ctxt_ap->beacon_time = cpu_to_le32(mvmvif->ap_beacon_time);
1334 ctxt_ap->beacon_tsf = 0; /* unused */
1336 /* TODO: Assume that the beacon id == mac context id */
1337 ctxt_ap->beacon_template = cpu_to_le32(mvmvif->id);
1340 static int iwl_mvm_mac_ctxt_cmd_ap(struct iwl_mvm *mvm,
1341 struct ieee80211_vif *vif,
1344 struct iwl_mac_ctx_cmd cmd = {};
1346 WARN_ON(vif->type != NL80211_IFTYPE_AP || vif->p2p);
1348 /* Fill the common data for all mac context types */
1349 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
1351 /* Fill the data specific for ap mode */
1352 iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd, &cmd.ap,
1353 action == FW_CTXT_ACTION_ADD);
1355 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1358 static int iwl_mvm_mac_ctxt_cmd_go(struct iwl_mvm *mvm,
1359 struct ieee80211_vif *vif,
1362 struct iwl_mac_ctx_cmd cmd = {};
1363 struct ieee80211_p2p_noa_attr *noa = &vif->bss_conf.p2p_noa_attr;
1365 WARN_ON(vif->type != NL80211_IFTYPE_AP || !vif->p2p);
1367 /* Fill the common data for all mac context types */
1368 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
1370 /* Fill the data specific for GO mode */
1371 iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd, &cmd.go.ap,
1372 action == FW_CTXT_ACTION_ADD);
1374 cmd.go.ctwin = cpu_to_le32(noa->oppps_ctwindow &
1375 IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
1376 cmd.go.opp_ps_enabled =
1377 cpu_to_le32(!!(noa->oppps_ctwindow &
1378 IEEE80211_P2P_OPPPS_ENABLE_BIT));
1380 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1383 static int iwl_mvm_mac_ctx_send(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1384 u32 action, bool force_assoc_off,
1385 const u8 *bssid_override)
1387 switch (vif->type) {
1388 case NL80211_IFTYPE_STATION:
1389 return iwl_mvm_mac_ctxt_cmd_sta(mvm, vif, action,
1392 case NL80211_IFTYPE_AP:
1394 return iwl_mvm_mac_ctxt_cmd_ap(mvm, vif, action);
1396 return iwl_mvm_mac_ctxt_cmd_go(mvm, vif, action);
1397 case NL80211_IFTYPE_MONITOR:
1398 return iwl_mvm_mac_ctxt_cmd_listener(mvm, vif, action);
1399 case NL80211_IFTYPE_P2P_DEVICE:
1400 return iwl_mvm_mac_ctxt_cmd_p2p_device(mvm, vif, action);
1401 case NL80211_IFTYPE_ADHOC:
1402 return iwl_mvm_mac_ctxt_cmd_ibss(mvm, vif, action);
1410 int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1412 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1415 if (WARN_ONCE(mvmvif->uploaded, "Adding active MAC %pM/%d\n",
1416 vif->addr, ieee80211_vif_type_p2p(vif)))
1419 ret = iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_ADD,
1424 /* will only do anything at resume from D3 time */
1425 iwl_mvm_set_last_nonqos_seq(mvm, vif);
1427 mvmvif->uploaded = true;
1431 int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1432 bool force_assoc_off, const u8 *bssid_override)
1434 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1436 if (WARN_ONCE(!mvmvif->uploaded, "Changing inactive MAC %pM/%d\n",
1437 vif->addr, ieee80211_vif_type_p2p(vif)))
1440 return iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_MODIFY,
1441 force_assoc_off, bssid_override);
1444 int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1446 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1447 struct iwl_mac_ctx_cmd cmd;
1450 if (WARN_ONCE(!mvmvif->uploaded, "Removing inactive MAC %pM/%d\n",
1451 vif->addr, ieee80211_vif_type_p2p(vif)))
1454 memset(&cmd, 0, sizeof(cmd));
1456 cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1458 cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE);
1460 ret = iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1464 mvmvif->uploaded = false;
1466 if (vif->type == NL80211_IFTYPE_MONITOR) {
1467 __clear_bit(IEEE80211_HW_RX_INCLUDES_FCS, mvm->hw->flags);
1468 iwl_mvm_dealloc_snif_sta(mvm);
1474 static void iwl_mvm_csa_count_down(struct iwl_mvm *mvm,
1475 struct ieee80211_vif *csa_vif, u32 gp2,
1478 struct iwl_mvm_vif *mvmvif =
1479 iwl_mvm_vif_from_mac80211(csa_vif);
1481 /* Don't start to countdown from a failed beacon */
1482 if (!tx_success && !mvmvif->csa_countdown)
1485 mvmvif->csa_countdown = true;
1487 if (!ieee80211_beacon_cntdwn_is_complete(csa_vif, 0)) {
1488 int c = ieee80211_beacon_update_cntdwn(csa_vif, 0);
1490 iwl_mvm_mac_ctxt_beacon_changed(mvm, csa_vif,
1491 &csa_vif->bss_conf);
1493 !iwl_mvm_te_scheduled(&mvmvif->time_event_data) && gp2 &&
1495 u32 rel_time = (c + 1) *
1496 csa_vif->bss_conf.beacon_int -
1497 IWL_MVM_CHANNEL_SWITCH_TIME_GO;
1498 u32 apply_time = gp2 + rel_time * 1024;
1500 iwl_mvm_schedule_csa_period(mvm, csa_vif,
1501 IWL_MVM_CHANNEL_SWITCH_TIME_GO -
1502 IWL_MVM_CHANNEL_SWITCH_MARGIN,
1505 } else if (!iwl_mvm_te_scheduled(&mvmvif->time_event_data)) {
1506 /* we don't have CSA NoA scheduled yet, switch now */
1507 ieee80211_csa_finish(csa_vif, 0);
1508 RCU_INIT_POINTER(mvm->csa_vif, NULL);
1512 void iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
1513 struct iwl_rx_cmd_buffer *rxb)
1515 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1516 unsigned int pkt_len = iwl_rx_packet_payload_len(pkt);
1517 struct iwl_extended_beacon_notif *beacon = (void *)pkt->data;
1518 struct iwl_extended_beacon_notif_v5 *beacon_v5 = (void *)pkt->data;
1519 struct ieee80211_vif *csa_vif;
1520 struct ieee80211_vif *tx_blocked_vif;
1521 struct agg_tx_status *agg_status;
1524 lockdep_assert_held(&mvm->mutex);
1526 mvm->ap_last_beacon_gp2 = le32_to_cpu(beacon->gp2);
1528 if (!iwl_mvm_is_short_beacon_notif_supported(mvm)) {
1529 struct iwl_mvm_tx_resp *beacon_notify_hdr =
1530 &beacon_v5->beacon_notify_hdr;
1532 if (unlikely(pkt_len < sizeof(*beacon_v5)))
1535 mvm->ibss_manager = beacon_v5->ibss_mgr_status != 0;
1536 agg_status = iwl_mvm_get_agg_status(mvm, beacon_notify_hdr);
1537 status = le16_to_cpu(agg_status->status) & TX_STATUS_MSK;
1539 "beacon status %#x retries:%d tsf:0x%016llX gp2:0x%X rate:%d\n",
1540 status, beacon_notify_hdr->failure_frame,
1541 le64_to_cpu(beacon->tsf),
1542 mvm->ap_last_beacon_gp2,
1543 le32_to_cpu(beacon_notify_hdr->initial_rate));
1545 if (unlikely(pkt_len < sizeof(*beacon)))
1548 mvm->ibss_manager = beacon->ibss_mgr_status != 0;
1549 status = le32_to_cpu(beacon->status) & TX_STATUS_MSK;
1551 "beacon status %#x tsf:0x%016llX gp2:0x%X\n",
1552 status, le64_to_cpu(beacon->tsf),
1553 mvm->ap_last_beacon_gp2);
1556 csa_vif = rcu_dereference_protected(mvm->csa_vif,
1557 lockdep_is_held(&mvm->mutex));
1558 if (unlikely(csa_vif && csa_vif->bss_conf.csa_active))
1559 iwl_mvm_csa_count_down(mvm, csa_vif, mvm->ap_last_beacon_gp2,
1560 (status == TX_STATUS_SUCCESS));
1562 tx_blocked_vif = rcu_dereference_protected(mvm->csa_tx_blocked_vif,
1563 lockdep_is_held(&mvm->mutex));
1564 if (unlikely(tx_blocked_vif)) {
1565 struct iwl_mvm_vif *mvmvif =
1566 iwl_mvm_vif_from_mac80211(tx_blocked_vif);
1569 * The channel switch is started and we have blocked the
1570 * stations. If this is the first beacon (the timeout wasn't
1571 * set), set the unblock timeout, otherwise countdown
1573 if (!mvm->csa_tx_block_bcn_timeout)
1574 mvm->csa_tx_block_bcn_timeout =
1575 IWL_MVM_CS_UNBLOCK_TX_TIMEOUT;
1577 mvm->csa_tx_block_bcn_timeout--;
1579 /* Check if the timeout is expired, and unblock tx */
1580 if (mvm->csa_tx_block_bcn_timeout == 0) {
1581 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false);
1582 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
1587 void iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm,
1588 struct iwl_rx_cmd_buffer *rxb)
1590 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1591 struct iwl_missed_beacons_notif *mb = (void *)pkt->data;
1592 struct iwl_fw_dbg_trigger_missed_bcon *bcon_trig;
1593 struct iwl_fw_dbg_trigger_tlv *trigger;
1594 u32 stop_trig_missed_bcon, stop_trig_missed_bcon_since_rx;
1595 u32 rx_missed_bcon, rx_missed_bcon_since_rx;
1596 struct ieee80211_vif *vif;
1597 /* Id can be mac/link id depending on the notification version */
1598 u32 id = le32_to_cpu(mb->link_id);
1599 union iwl_dbg_tlv_tp_data tp_data = { .fw_pkt = pkt };
1602 u8 notif_ver = iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,
1603 MISSED_BEACONS_NOTIFICATION,
1606 /* before version four the ID in the notification refers to mac ID */
1607 if (notif_ver < 4) {
1608 vif = iwl_mvm_rcu_dereference_vif_id(mvm, id, false);
1610 struct ieee80211_bss_conf *bss_conf =
1611 iwl_mvm_rcu_fw_link_id_to_link_conf(mvm, id, false);
1616 vif = bss_conf->vif;
1617 link_id = bss_conf->link_id;
1621 "missed bcn %s_id=%u, consecutive=%u (%u, %u, %u)\n",
1622 notif_ver < 4 ? "mac" : "link",
1624 le32_to_cpu(mb->consec_missed_beacons),
1625 le32_to_cpu(mb->consec_missed_beacons_since_last_rx),
1626 le32_to_cpu(mb->num_recvd_beacons),
1627 le32_to_cpu(mb->num_expected_beacons));
1632 mac_type = iwl_mvm_get_mac_type(vif);
1634 IWL_DEBUG_INFO(mvm, "missed beacon mac_type=%u,\n", mac_type);
1636 mvm->trans->dbg.dump_file_name_ext_valid = true;
1637 snprintf(mvm->trans->dbg.dump_file_name_ext, IWL_FW_INI_MAX_NAME,
1638 "MacId_%d_MacType_%d", id, mac_type);
1640 rx_missed_bcon = le32_to_cpu(mb->consec_missed_beacons);
1641 rx_missed_bcon_since_rx =
1642 le32_to_cpu(mb->consec_missed_beacons_since_last_rx);
1644 * TODO: the threshold should be adjusted based on latency conditions,
1645 * and/or in case of a CS flow on one of the other AP vifs.
1647 if (rx_missed_bcon >= IWL_MVM_MISSED_BEACONS_THRESHOLD_LONG) {
1648 if (rx_missed_bcon_since_rx >= IWL_MVM_MISSED_BEACONS_SINCE_RX_THOLD) {
1649 iwl_mvm_connection_loss(mvm, vif, "missed beacons");
1652 "missed beacons exceeds threshold, but receiving data. Stay connected, Expect bugs.\n");
1654 "missed_beacons:%d, missed_beacons_since_rx:%d\n",
1655 rx_missed_bcon, rx_missed_bcon_since_rx);
1657 } else if (rx_missed_bcon >= IWL_MVM_MISSED_BEACONS_EXIT_ESR_THRESH &&
1658 link_id >= 0 && hweight16(vif->active_links) > 1) {
1659 iwl_mvm_exit_esr(mvm, vif, IWL_MVM_ESR_EXIT_MISSED_BEACON,
1660 iwl_mvm_get_other_link(vif, link_id));
1661 } else if (rx_missed_bcon_since_rx > IWL_MVM_MISSED_BEACONS_THRESHOLD) {
1662 if (!iwl_mvm_has_new_tx_api(mvm))
1663 ieee80211_beacon_loss(vif);
1665 ieee80211_cqm_beacon_loss_notify(vif, GFP_ATOMIC);
1668 iwl_dbg_tlv_time_point(&mvm->fwrt,
1669 IWL_FW_INI_TIME_POINT_MISSED_BEACONS, &tp_data);
1671 trigger = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
1672 FW_DBG_TRIGGER_MISSED_BEACONS);
1676 bcon_trig = (void *)trigger->data;
1677 stop_trig_missed_bcon = le32_to_cpu(bcon_trig->stop_consec_missed_bcon);
1678 stop_trig_missed_bcon_since_rx =
1679 le32_to_cpu(bcon_trig->stop_consec_missed_bcon_since_rx);
1681 /* TODO: implement start trigger */
1683 if (rx_missed_bcon_since_rx >= stop_trig_missed_bcon_since_rx ||
1684 rx_missed_bcon >= stop_trig_missed_bcon)
1685 iwl_fw_dbg_collect_trig(&mvm->fwrt, trigger, NULL);
1688 void iwl_mvm_rx_stored_beacon_notif(struct iwl_mvm *mvm,
1689 struct iwl_rx_cmd_buffer *rxb)
1691 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1692 unsigned int pkt_len = iwl_rx_packet_payload_len(pkt);
1693 struct iwl_stored_beacon_notif_common *sb = (void *)pkt->data;
1694 struct ieee80211_rx_status rx_status;
1695 struct sk_buff *skb;
1697 u32 size = le32_to_cpu(sb->byte_count);
1698 int ver = iwl_fw_lookup_cmd_ver(mvm->fw,
1699 WIDE_ID(PROT_OFFLOAD_GROUP, STORED_BEACON_NTF),
1705 /* handle per-version differences */
1707 struct iwl_stored_beacon_notif_v2 *sb_v2 = (void *)pkt->data;
1709 if (pkt_len < struct_size(sb_v2, data, size))
1714 struct iwl_stored_beacon_notif_v3 *sb_v3 = (void *)pkt->data;
1716 if (pkt_len < struct_size(sb_v3, data, size))
1722 skb = alloc_skb(size, GFP_ATOMIC);
1724 IWL_ERR(mvm, "alloc_skb failed\n");
1728 /* update rx_status according to the notification's metadata */
1729 memset(&rx_status, 0, sizeof(rx_status));
1730 rx_status.mactime = le64_to_cpu(sb->tsf);
1731 /* TSF as indicated by the firmware is at INA time */
1732 rx_status.flag |= RX_FLAG_MACTIME_PLCP_START;
1733 rx_status.device_timestamp = le32_to_cpu(sb->system_time);
1735 (sb->band & cpu_to_le16(RX_RES_PHY_FLAGS_BAND_24)) ?
1736 NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
1738 ieee80211_channel_to_frequency(le16_to_cpu(sb->channel),
1742 skb_put_data(skb, data, size);
1743 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
1745 /* pass it as regular rx to mac80211 */
1746 ieee80211_rx_napi(mvm->hw, NULL, skb, NULL);
1749 void iwl_mvm_probe_resp_data_notif(struct iwl_mvm *mvm,
1750 struct iwl_rx_cmd_buffer *rxb)
1752 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1753 struct iwl_probe_resp_data_notif *notif = (void *)pkt->data;
1754 struct iwl_probe_resp_data *old_data, *new_data;
1755 u32 id = le32_to_cpu(notif->mac_id);
1756 struct ieee80211_vif *vif;
1757 struct iwl_mvm_vif *mvmvif;
1759 IWL_DEBUG_INFO(mvm, "Probe response data notif: noa %d, csa %d\n",
1760 notif->noa_active, notif->csa_counter);
1762 vif = iwl_mvm_rcu_dereference_vif_id(mvm, id, false);
1766 mvmvif = iwl_mvm_vif_from_mac80211(vif);
1768 new_data = kzalloc(sizeof(*new_data), GFP_KERNEL);
1772 memcpy(&new_data->notif, notif, sizeof(new_data->notif));
1774 /* noa_attr contains 1 reserved byte, need to substruct it */
1775 new_data->noa_len = sizeof(struct ieee80211_vendor_ie) +
1776 sizeof(new_data->notif.noa_attr) - 1;
1779 * If it's a one time NoA, only one descriptor is needed,
1780 * adjust the length according to len_low.
1782 if (new_data->notif.noa_attr.len_low ==
1783 sizeof(struct ieee80211_p2p_noa_desc) + 2)
1784 new_data->noa_len -= sizeof(struct ieee80211_p2p_noa_desc);
1786 old_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data,
1787 lockdep_is_held(&mvmvif->mvm->mutex));
1788 rcu_assign_pointer(mvmvif->deflink.probe_resp_data, new_data);
1791 kfree_rcu(old_data, rcu_head);
1793 if (notif->csa_counter != IWL_PROBE_RESP_DATA_NO_CSA &&
1794 notif->csa_counter >= 1)
1795 ieee80211_beacon_set_cntdwn(vif, notif->csa_counter);
1798 void iwl_mvm_channel_switch_start_notif(struct iwl_mvm *mvm,
1799 struct iwl_rx_cmd_buffer *rxb)
1801 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1802 struct ieee80211_vif *csa_vif, *vif;
1803 struct iwl_mvm_vif *mvmvif, *csa_mvmvif;
1804 u32 id_n_color, csa_id;
1805 /* save mac_id or link_id to use later to cancel csa if needed */
1807 u32 mac_link_id = 0;
1808 u8 notif_ver = iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
1809 CHANNEL_SWITCH_START_NOTIF, 0);
1814 if (notif_ver < 3) {
1815 struct iwl_channel_switch_start_notif_v1 *notif = (void *)pkt->data;
1818 id_n_color = le32_to_cpu(notif->id_and_color);
1819 mac_id = id_n_color & FW_CTXT_ID_MSK;
1821 vif = iwl_mvm_rcu_dereference_vif_id(mvm, mac_id, true);
1826 csa_active = vif->bss_conf.csa_active;
1828 struct iwl_channel_switch_start_notif *notif = (void *)pkt->data;
1829 u32 link_id = le32_to_cpu(notif->link_id);
1830 struct ieee80211_bss_conf *bss_conf =
1831 iwl_mvm_rcu_fw_link_id_to_link_conf(mvm, link_id, true);
1837 mac_link_id = bss_conf->link_id;
1838 vif = bss_conf->vif;
1839 csa_active = bss_conf->csa_active;
1842 mvmvif = iwl_mvm_vif_from_mac80211(vif);
1844 id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color);
1846 switch (vif->type) {
1847 case NL80211_IFTYPE_AP:
1848 csa_vif = rcu_dereference(mvm->csa_vif);
1849 if (WARN_ON(!csa_vif || !csa_vif->bss_conf.csa_active ||
1853 csa_mvmvif = iwl_mvm_vif_from_mac80211(csa_vif);
1854 csa_id = FW_CMD_ID_AND_COLOR(csa_mvmvif->id, csa_mvmvif->color);
1855 if (WARN(csa_id != id_n_color,
1856 "channel switch noa notification on unexpected vif (csa_vif=%d, notif=%d)",
1857 csa_id, id_n_color))
1860 IWL_DEBUG_INFO(mvm, "Channel Switch Started Notification\n");
1862 schedule_delayed_work(&mvm->cs_tx_unblock_dwork,
1863 msecs_to_jiffies(IWL_MVM_CS_UNBLOCK_TX_TIMEOUT *
1864 csa_vif->bss_conf.beacon_int));
1866 ieee80211_csa_finish(csa_vif, 0);
1870 RCU_INIT_POINTER(mvm->csa_vif, NULL);
1872 case NL80211_IFTYPE_STATION:
1874 * if we don't know about an ongoing channel switch,
1875 * make sure FW cancels it
1877 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
1878 CHANNEL_SWITCH_ERROR_NOTIF,
1879 0) && !csa_active) {
1880 IWL_DEBUG_INFO(mvm, "Channel Switch was canceled\n");
1881 iwl_mvm_cancel_channel_switch(mvm, vif, id);
1885 iwl_mvm_csa_client_absent(mvm, vif);
1886 cancel_delayed_work(&mvmvif->csa_work);
1887 ieee80211_chswitch_done(vif, true, mac_link_id);
1890 /* should never happen */
1898 void iwl_mvm_channel_switch_error_notif(struct iwl_mvm *mvm,
1899 struct iwl_rx_cmd_buffer *rxb)
1901 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1902 struct iwl_channel_switch_error_notif *notif = (void *)pkt->data;
1903 struct ieee80211_vif *vif;
1904 u32 id = le32_to_cpu(notif->link_id);
1905 u32 csa_err_mask = le32_to_cpu(notif->csa_err_mask);
1908 vif = iwl_mvm_rcu_dereference_vif_id(mvm, id, true);
1914 IWL_DEBUG_INFO(mvm, "FW reports CSA error: id=%u, csa_err_mask=%u\n",
1916 if (csa_err_mask & (CS_ERR_COUNT_ERROR |
1917 CS_ERR_LONG_DELAY_AFTER_CS |
1918 CS_ERR_TX_BLOCK_TIMER_EXPIRED))
1919 ieee80211_channel_switch_disconnect(vif, true);
1923 void iwl_mvm_rx_missed_vap_notif(struct iwl_mvm *mvm,
1924 struct iwl_rx_cmd_buffer *rxb)
1926 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1927 struct iwl_missed_vap_notif *mb = (void *)pkt->data;
1928 struct ieee80211_vif *vif;
1929 u32 id = le32_to_cpu(mb->mac_id);
1932 "missed_vap notify mac_id=%u, num_beacon_intervals_elapsed=%u, profile_periodicity=%u\n",
1933 le32_to_cpu(mb->mac_id),
1934 mb->num_beacon_intervals_elapsed,
1935 mb->profile_periodicity);
1939 vif = iwl_mvm_rcu_dereference_vif_id(mvm, id, true);
1941 iwl_mvm_connection_loss(mvm, vif, "missed vap beacon");