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) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *****************************************************************************/
66 #include <linux/etherdevice.h>
67 #include <net/mac80211.h>
72 #include "time-event.h"
74 const u8 iwl_mvm_ac_to_tx_fifo[] = {
81 struct iwl_mvm_mac_iface_iterator_data {
83 struct ieee80211_vif *vif;
84 unsigned long available_mac_ids[BITS_TO_LONGS(NUM_MAC_INDEX_DRIVER)];
85 unsigned long available_tsf_ids[BITS_TO_LONGS(NUM_TSF_IDS)];
87 enum iwl_tsf_id preferred_tsf;
91 static void iwl_mvm_mac_tsf_id_iter(void *_data, u8 *mac,
92 struct ieee80211_vif *vif)
94 struct iwl_mvm_mac_iface_iterator_data *data = _data;
95 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
98 /* Skip the interface for which we are trying to assign a tsf_id */
103 * The TSF is a hardware/firmware resource, there are 4 and
104 * the driver should assign and free them as needed. However,
105 * there are cases where 2 MACs should share the same TSF ID
106 * for the purpose of clock sync, an optimization to avoid
107 * clock drift causing overlapping TBTTs/DTIMs for a GO and
108 * client in the system.
110 * The firmware will decide according to the MAC type which
111 * will be the master and slave. Clients that need to sync
112 * with a remote station will be the master, and an AP or GO
115 * Depending on the new interface type it can be slaved to
116 * or become the master of an existing interface.
118 switch (data->vif->type) {
119 case NL80211_IFTYPE_STATION:
121 * The new interface is a client, so if the one we're iterating
122 * is an AP, and the beacon interval of the AP is a multiple or
123 * divisor of the beacon interval of the client, the same TSF
124 * should be used to avoid drift between the new client and
125 * existing AP. The existing AP will get drift updates from the
126 * new client context in this case.
128 if (vif->type != NL80211_IFTYPE_AP ||
129 data->preferred_tsf != NUM_TSF_IDS ||
130 !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
133 min_bi = min(data->vif->bss_conf.beacon_int,
134 vif->bss_conf.beacon_int);
139 if ((data->vif->bss_conf.beacon_int -
140 vif->bss_conf.beacon_int) % min_bi == 0) {
141 data->preferred_tsf = mvmvif->tsf_id;
146 case NL80211_IFTYPE_AP:
148 * The new interface is AP/GO, so if its beacon interval is a
149 * multiple or a divisor of the beacon interval of an existing
150 * interface, it should get drift updates from an existing
151 * client or use the same TSF as an existing GO. There's no
152 * drift between TSFs internally but if they used different
153 * TSFs then a new client MAC could update one of them and
154 * cause drift that way.
156 if ((vif->type != NL80211_IFTYPE_AP &&
157 vif->type != NL80211_IFTYPE_STATION) ||
158 data->preferred_tsf != NUM_TSF_IDS ||
159 !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
162 min_bi = min(data->vif->bss_conf.beacon_int,
163 vif->bss_conf.beacon_int);
168 if ((data->vif->bss_conf.beacon_int -
169 vif->bss_conf.beacon_int) % min_bi == 0) {
170 data->preferred_tsf = mvmvif->tsf_id;
176 * For all other interface types there's no need to
177 * take drift into account. Either they're exclusive
178 * like IBSS and monitor, or we don't care much about
179 * their TSF (like P2P Device), but we won't be able
180 * to share the TSF resource.
186 * Unless we exited above, we can't share the TSF resource
187 * that the virtual interface we're iterating over is using
188 * with the new one, so clear the available bit and if this
189 * was the preferred one, reset that as well.
191 __clear_bit(mvmvif->tsf_id, data->available_tsf_ids);
193 if (data->preferred_tsf == mvmvif->tsf_id)
194 data->preferred_tsf = NUM_TSF_IDS;
198 * Get the mask of the queues used by the vif
200 u32 iwl_mvm_mac_get_queues_mask(struct iwl_mvm *mvm,
201 struct ieee80211_vif *vif)
205 if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
206 return BIT(IWL_MVM_OFFCHANNEL_QUEUE);
208 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
209 qmask |= BIT(vif->hw_queue[ac]);
211 if (vif->type == NL80211_IFTYPE_AP)
212 qmask |= BIT(vif->cab_queue);
217 static void iwl_mvm_mac_iface_iterator(void *_data, u8 *mac,
218 struct ieee80211_vif *vif)
220 struct iwl_mvm_mac_iface_iterator_data *data = _data;
221 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
223 /* Iterator may already find the interface being added -- skip it */
224 if (vif == data->vif) {
225 data->found_vif = true;
229 /* Mark the queues used by the vif */
230 data->used_hw_queues |= iwl_mvm_mac_get_queues_mask(data->mvm, vif);
232 /* Mark MAC IDs as used by clearing the available bit, and
233 * (below) mark TSFs as used if their existing use is not
234 * compatible with the new interface type.
235 * No locking or atomic bit operations are needed since the
236 * data is on the stack of the caller function.
238 __clear_bit(mvmvif->id, data->available_mac_ids);
240 /* find a suitable tsf_id */
241 iwl_mvm_mac_tsf_id_iter(_data, mac, vif);
244 void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm *mvm,
245 struct ieee80211_vif *vif)
247 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
248 struct iwl_mvm_mac_iface_iterator_data data = {
251 .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
252 /* no preference yet */
253 .preferred_tsf = NUM_TSF_IDS,
256 ieee80211_iterate_active_interfaces_atomic(
257 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
258 iwl_mvm_mac_tsf_id_iter, &data);
260 if (data.preferred_tsf != NUM_TSF_IDS)
261 mvmvif->tsf_id = data.preferred_tsf;
262 else if (!test_bit(mvmvif->tsf_id, data.available_tsf_ids))
263 mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
267 static int iwl_mvm_mac_ctxt_allocate_resources(struct iwl_mvm *mvm,
268 struct ieee80211_vif *vif)
270 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
271 struct iwl_mvm_mac_iface_iterator_data data = {
274 .available_mac_ids = { (1 << NUM_MAC_INDEX_DRIVER) - 1 },
275 .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
276 /* no preference yet */
277 .preferred_tsf = NUM_TSF_IDS,
279 BIT(IWL_MVM_OFFCHANNEL_QUEUE) |
280 BIT(mvm->aux_queue) |
281 BIT(IWL_MVM_CMD_QUEUE),
286 unsigned long used_hw_queues;
289 * Allocate a MAC ID and a TSF for this MAC, along with the queues
290 * and other resources.
294 * Before the iterator, we start with all MAC IDs and TSFs available.
296 * During iteration, all MAC IDs are cleared that are in use by other
297 * virtual interfaces, and all TSF IDs are cleared that can't be used
298 * by this new virtual interface because they're used by an interface
299 * that can't share it with the new one.
300 * At the same time, we check if there's a preferred TSF in the case
301 * that we should share it with another interface.
304 /* Currently, MAC ID 0 should be used only for the managed/IBSS vif */
306 case NL80211_IFTYPE_ADHOC:
308 case NL80211_IFTYPE_STATION:
313 __clear_bit(0, data.available_mac_ids);
316 ieee80211_iterate_active_interfaces_atomic(
317 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
318 iwl_mvm_mac_iface_iterator, &data);
321 * In the case we're getting here during resume, it's similar to
322 * firmware restart, and with RESUME_ALL the iterator will find
323 * the vif being added already.
324 * We don't want to reassign any IDs in either case since doing
325 * so would probably assign different IDs (as interfaces aren't
326 * necessarily added in the same order), but the old IDs were
327 * preserved anyway, so skip ID assignment for both resume and
333 /* Therefore, in recovery, we can't get here */
334 if (WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
337 mvmvif->id = find_first_bit(data.available_mac_ids,
338 NUM_MAC_INDEX_DRIVER);
339 if (mvmvif->id == NUM_MAC_INDEX_DRIVER) {
340 IWL_ERR(mvm, "Failed to init MAC context - no free ID!\n");
345 if (data.preferred_tsf != NUM_TSF_IDS)
346 mvmvif->tsf_id = data.preferred_tsf;
348 mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
350 if (mvmvif->tsf_id == NUM_TSF_IDS) {
351 IWL_ERR(mvm, "Failed to init MAC context - no free TSF!\n");
358 INIT_LIST_HEAD(&mvmvif->time_event_data.list);
359 mvmvif->time_event_data.id = TE_MAX;
361 /* No need to allocate data queues to P2P Device MAC.*/
362 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
363 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
364 vif->hw_queue[ac] = IEEE80211_INVAL_HW_QUEUE;
369 used_hw_queues = data.used_hw_queues;
371 /* Find available queues, and allocate them to the ACs */
372 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
373 u8 queue = find_first_zero_bit(&used_hw_queues,
374 mvm->first_agg_queue);
376 if (queue >= mvm->first_agg_queue) {
377 IWL_ERR(mvm, "Failed to allocate queue\n");
382 __set_bit(queue, &used_hw_queues);
383 vif->hw_queue[ac] = queue;
386 /* Allocate the CAB queue for softAP and GO interfaces */
387 if (vif->type == NL80211_IFTYPE_AP) {
388 u8 queue = find_first_zero_bit(&used_hw_queues,
389 mvm->first_agg_queue);
391 if (queue >= mvm->first_agg_queue) {
392 IWL_ERR(mvm, "Failed to allocate cab queue\n");
397 vif->cab_queue = queue;
399 vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
402 mvmvif->bcast_sta.sta_id = IWL_MVM_STATION_COUNT;
403 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
405 for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++)
406 mvmvif->smps_requests[i] = IEEE80211_SMPS_AUTOMATIC;
411 memset(mvmvif, 0, sizeof(struct iwl_mvm_vif));
412 memset(vif->hw_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(vif->hw_queue));
413 vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
417 int iwl_mvm_mac_ctxt_init(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
422 lockdep_assert_held(&mvm->mutex);
424 ret = iwl_mvm_mac_ctxt_allocate_resources(mvm, vif);
429 case NL80211_IFTYPE_P2P_DEVICE:
430 iwl_trans_ac_txq_enable(mvm->trans, IWL_MVM_OFFCHANNEL_QUEUE,
433 case NL80211_IFTYPE_AP:
434 iwl_trans_ac_txq_enable(mvm->trans, vif->cab_queue,
435 IWL_MVM_TX_FIFO_MCAST);
438 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
439 iwl_trans_ac_txq_enable(mvm->trans, vif->hw_queue[ac],
440 iwl_mvm_ac_to_tx_fifo[ac]);
447 void iwl_mvm_mac_ctxt_release(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
451 lockdep_assert_held(&mvm->mutex);
454 case NL80211_IFTYPE_P2P_DEVICE:
455 iwl_trans_txq_disable(mvm->trans, IWL_MVM_OFFCHANNEL_QUEUE,
458 case NL80211_IFTYPE_AP:
459 iwl_trans_txq_disable(mvm->trans, vif->cab_queue, true);
462 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
463 iwl_trans_txq_disable(mvm->trans, vif->hw_queue[ac],
468 static void iwl_mvm_ack_rates(struct iwl_mvm *mvm,
469 struct ieee80211_vif *vif,
470 enum ieee80211_band band,
471 u8 *cck_rates, u8 *ofdm_rates)
473 struct ieee80211_supported_band *sband;
474 unsigned long basic = vif->bss_conf.basic_rates;
475 int lowest_present_ofdm = 100;
476 int lowest_present_cck = 100;
481 sband = mvm->hw->wiphy->bands[band];
483 for_each_set_bit(i, &basic, BITS_PER_LONG) {
484 int hw = sband->bitrates[i].hw_value;
485 if (hw >= IWL_FIRST_OFDM_RATE) {
486 ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE);
487 if (lowest_present_ofdm > hw)
488 lowest_present_ofdm = hw;
490 BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
493 if (lowest_present_cck > hw)
494 lowest_present_cck = hw;
499 * Now we've got the basic rates as bitmaps in the ofdm and cck
500 * variables. This isn't sufficient though, as there might not
501 * be all the right rates in the bitmap. E.g. if the only basic
502 * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps
503 * and 6 Mbps because the 802.11-2007 standard says in 9.6:
505 * [...] a STA responding to a received frame shall transmit
506 * its Control Response frame [...] at the highest rate in the
507 * BSSBasicRateSet parameter that is less than or equal to the
508 * rate of the immediately previous frame in the frame exchange
509 * sequence ([...]) and that is of the same modulation class
510 * ([...]) as the received frame. If no rate contained in the
511 * BSSBasicRateSet parameter meets these conditions, then the
512 * control frame sent in response to a received frame shall be
513 * transmitted at the highest mandatory rate of the PHY that is
514 * less than or equal to the rate of the received frame, and
515 * that is of the same modulation class as the received frame.
517 * As a consequence, we need to add all mandatory rates that are
518 * lower than all of the basic rates to these bitmaps.
521 if (IWL_RATE_24M_INDEX < lowest_present_ofdm)
522 ofdm |= IWL_RATE_BIT_MSK(24) >> IWL_FIRST_OFDM_RATE;
523 if (IWL_RATE_12M_INDEX < lowest_present_ofdm)
524 ofdm |= IWL_RATE_BIT_MSK(12) >> IWL_FIRST_OFDM_RATE;
525 /* 6M already there or needed so always add */
526 ofdm |= IWL_RATE_BIT_MSK(6) >> IWL_FIRST_OFDM_RATE;
529 * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP.
531 * - if no CCK rates are basic, it must be ERP since there must
532 * be some basic rates at all, so they're OFDM => ERP PHY
533 * (or we're in 5 GHz, and the cck bitmap will never be used)
534 * - if 11M is a basic rate, it must be ERP as well, so add 5.5M
535 * - if 5.5M is basic, 1M and 2M are mandatory
536 * - if 2M is basic, 1M is mandatory
537 * - if 1M is basic, that's the only valid ACK rate.
538 * As a consequence, it's not as complicated as it sounds, just add
539 * any lower rates to the ACK rate bitmap.
541 if (IWL_RATE_11M_INDEX < lowest_present_cck)
542 cck |= IWL_RATE_BIT_MSK(11) >> IWL_FIRST_CCK_RATE;
543 if (IWL_RATE_5M_INDEX < lowest_present_cck)
544 cck |= IWL_RATE_BIT_MSK(5) >> IWL_FIRST_CCK_RATE;
545 if (IWL_RATE_2M_INDEX < lowest_present_cck)
546 cck |= IWL_RATE_BIT_MSK(2) >> IWL_FIRST_CCK_RATE;
547 /* 1M already there or needed so always add */
548 cck |= IWL_RATE_BIT_MSK(1) >> IWL_FIRST_CCK_RATE;
554 static void iwl_mvm_mac_ctxt_set_ht_flags(struct iwl_mvm *mvm,
555 struct ieee80211_vif *vif,
556 struct iwl_mac_ctx_cmd *cmd)
558 /* for both sta and ap, ht_operation_mode hold the protection_mode */
559 u8 protection_mode = vif->bss_conf.ht_operation_mode &
560 IEEE80211_HT_OP_MODE_PROTECTION;
561 /* The fw does not distinguish between ht and fat */
562 u32 ht_flag = MAC_PROT_FLG_HT_PROT | MAC_PROT_FLG_FAT_PROT;
564 IWL_DEBUG_RATE(mvm, "protection mode set to %d\n", protection_mode);
566 * See section 9.23.3.1 of IEEE 80211-2012.
567 * Nongreenfield HT STAs Present is not supported.
569 switch (protection_mode) {
570 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
572 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
573 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
574 cmd->protection_flags |= cpu_to_le32(ht_flag);
576 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
577 /* Protect when channel wider than 20MHz */
578 if (vif->bss_conf.chandef.width > NL80211_CHAN_WIDTH_20)
579 cmd->protection_flags |= cpu_to_le32(ht_flag);
582 IWL_ERR(mvm, "Illegal protection mode %d\n",
588 static void iwl_mvm_mac_ctxt_cmd_common(struct iwl_mvm *mvm,
589 struct ieee80211_vif *vif,
590 struct iwl_mac_ctx_cmd *cmd,
591 const u8 *bssid_override,
594 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
595 struct ieee80211_chanctx_conf *chanctx;
596 bool ht_enabled = !!(vif->bss_conf.ht_operation_mode &
597 IEEE80211_HT_OP_MODE_PROTECTION);
598 u8 cck_ack_rates, ofdm_ack_rates;
599 const u8 *bssid = bssid_override ?: vif->bss_conf.bssid;
602 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
604 cmd->action = cpu_to_le32(action);
607 case NL80211_IFTYPE_STATION:
609 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_P2P_STA);
611 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_BSS_STA);
613 case NL80211_IFTYPE_AP:
614 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_GO);
616 case NL80211_IFTYPE_MONITOR:
617 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_LISTENER);
619 case NL80211_IFTYPE_P2P_DEVICE:
620 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_P2P_DEVICE);
622 case NL80211_IFTYPE_ADHOC:
623 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_IBSS);
629 cmd->tsf_id = cpu_to_le32(mvmvif->tsf_id);
631 memcpy(cmd->node_addr, vif->addr, ETH_ALEN);
634 memcpy(cmd->bssid_addr, bssid, ETH_ALEN);
636 eth_broadcast_addr(cmd->bssid_addr);
639 chanctx = rcu_dereference(vif->chanctx_conf);
640 iwl_mvm_ack_rates(mvm, vif, chanctx ? chanctx->def.chan->band
641 : IEEE80211_BAND_2GHZ,
642 &cck_ack_rates, &ofdm_ack_rates);
645 cmd->cck_rates = cpu_to_le32((u32)cck_ack_rates);
646 cmd->ofdm_rates = cpu_to_le32((u32)ofdm_ack_rates);
648 cmd->cck_short_preamble =
649 cpu_to_le32(vif->bss_conf.use_short_preamble ?
650 MAC_FLG_SHORT_PREAMBLE : 0);
652 cpu_to_le32(vif->bss_conf.use_short_slot ?
653 MAC_FLG_SHORT_SLOT : 0);
655 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
656 u8 txf = iwl_mvm_ac_to_tx_fifo[i];
658 cmd->ac[txf].cw_min =
659 cpu_to_le16(mvmvif->queue_params[i].cw_min);
660 cmd->ac[txf].cw_max =
661 cpu_to_le16(mvmvif->queue_params[i].cw_max);
662 cmd->ac[txf].edca_txop =
663 cpu_to_le16(mvmvif->queue_params[i].txop * 32);
664 cmd->ac[txf].aifsn = mvmvif->queue_params[i].aifs;
665 cmd->ac[txf].fifos_mask = BIT(txf);
668 /* in AP mode, the MCAST FIFO takes the EDCA params from VO */
669 if (vif->type == NL80211_IFTYPE_AP)
670 cmd->ac[IWL_MVM_TX_FIFO_VO].fifos_mask |=
671 BIT(IWL_MVM_TX_FIFO_MCAST);
673 if (vif->bss_conf.qos)
674 cmd->qos_flags |= cpu_to_le32(MAC_QOS_FLG_UPDATE_EDCA);
676 if (vif->bss_conf.use_cts_prot)
677 cmd->protection_flags |= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT);
679 IWL_DEBUG_RATE(mvm, "use_cts_prot %d, ht_operation_mode %d\n",
680 vif->bss_conf.use_cts_prot,
681 vif->bss_conf.ht_operation_mode);
682 if (vif->bss_conf.chandef.width != NL80211_CHAN_WIDTH_20_NOHT)
683 cmd->qos_flags |= cpu_to_le32(MAC_QOS_FLG_TGN);
685 iwl_mvm_mac_ctxt_set_ht_flags(mvm, vif, cmd);
687 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP);
690 static int iwl_mvm_mac_ctxt_send_cmd(struct iwl_mvm *mvm,
691 struct iwl_mac_ctx_cmd *cmd)
693 int ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, 0,
696 IWL_ERR(mvm, "Failed to send MAC context (action:%d): %d\n",
697 le32_to_cpu(cmd->action), ret);
701 static int iwl_mvm_mac_ctxt_cmd_sta(struct iwl_mvm *mvm,
702 struct ieee80211_vif *vif,
703 u32 action, bool force_assoc_off,
704 const u8 *bssid_override)
706 struct iwl_mac_ctx_cmd cmd = {};
707 struct iwl_mac_data_sta *ctxt_sta;
709 WARN_ON(vif->type != NL80211_IFTYPE_STATION);
711 /* Fill the common data for all mac context types */
712 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, bssid_override, action);
715 struct ieee80211_p2p_noa_attr *noa =
716 &vif->bss_conf.p2p_noa_attr;
718 cmd.p2p_sta.ctwin = cpu_to_le32(noa->oppps_ctwindow &
719 IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
720 ctxt_sta = &cmd.p2p_sta.sta;
725 /* We need the dtim_period to set the MAC as associated */
726 if (vif->bss_conf.assoc && vif->bss_conf.dtim_period &&
731 * The DTIM count counts down, so when it is N that means N
732 * more beacon intervals happen until the DTIM TBTT. Therefore
733 * add this to the current time. If that ends up being in the
734 * future, the firmware will handle it.
736 * Also note that the system_timestamp (which we get here as
737 * "sync_device_ts") and TSF timestamp aren't at exactly the
738 * same offset in the frame -- the TSF is at the first symbol
739 * of the TSF, the system timestamp is at signal acquisition
740 * time. This means there's an offset between them of at most
741 * a few hundred microseconds (24 * 8 bits + PLCP time gives
742 * 384us in the longest case), this is currently not relevant
743 * as the firmware wakes up around 2ms before the TBTT.
745 dtim_offs = vif->bss_conf.sync_dtim_count *
746 vif->bss_conf.beacon_int;
747 /* convert TU to usecs */
751 cpu_to_le64(vif->bss_conf.sync_tsf + dtim_offs);
752 ctxt_sta->dtim_time =
753 cpu_to_le32(vif->bss_conf.sync_device_ts + dtim_offs);
755 IWL_DEBUG_INFO(mvm, "DTIM TBTT is 0x%llx/0x%x, offset %d\n",
756 le64_to_cpu(ctxt_sta->dtim_tsf),
757 le32_to_cpu(ctxt_sta->dtim_time),
760 ctxt_sta->is_assoc = cpu_to_le32(1);
762 ctxt_sta->is_assoc = cpu_to_le32(0);
764 /* Allow beacons to pass through as long as we are not
765 * associated, or we do not have dtim period information.
767 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_BEACON);
770 ctxt_sta->bi = cpu_to_le32(vif->bss_conf.beacon_int);
771 ctxt_sta->bi_reciprocal =
772 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
773 ctxt_sta->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
774 vif->bss_conf.dtim_period);
775 ctxt_sta->dtim_reciprocal =
776 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int *
777 vif->bss_conf.dtim_period));
779 ctxt_sta->listen_interval = cpu_to_le32(mvm->hw->conf.listen_interval);
780 ctxt_sta->assoc_id = cpu_to_le32(vif->bss_conf.aid);
782 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
785 static int iwl_mvm_mac_ctxt_cmd_listener(struct iwl_mvm *mvm,
786 struct ieee80211_vif *vif,
789 struct iwl_mac_ctx_cmd cmd = {};
791 WARN_ON(vif->type != NL80211_IFTYPE_MONITOR);
793 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
795 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROMISC |
796 MAC_FILTER_IN_CONTROL_AND_MGMT |
797 MAC_FILTER_IN_BEACON |
798 MAC_FILTER_IN_PROBE_REQUEST |
799 MAC_FILTER_IN_CRC32);
800 mvm->hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS;
802 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
805 static int iwl_mvm_mac_ctxt_cmd_ibss(struct iwl_mvm *mvm,
806 struct ieee80211_vif *vif,
809 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
810 struct iwl_mac_ctx_cmd cmd = {};
812 WARN_ON(vif->type != NL80211_IFTYPE_ADHOC);
814 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
816 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_BEACON |
817 MAC_FILTER_IN_PROBE_REQUEST);
819 /* cmd.ibss.beacon_time/cmd.ibss.beacon_tsf are curently ignored */
820 cmd.ibss.bi = cpu_to_le32(vif->bss_conf.beacon_int);
821 cmd.ibss.bi_reciprocal =
822 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
824 /* TODO: Assumes that the beacon id == mac context id */
825 cmd.ibss.beacon_template = cpu_to_le32(mvmvif->id);
827 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
830 struct iwl_mvm_go_iterator_data {
834 static void iwl_mvm_go_iterator(void *_data, u8 *mac, struct ieee80211_vif *vif)
836 struct iwl_mvm_go_iterator_data *data = _data;
837 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
839 if (vif->type == NL80211_IFTYPE_AP && vif->p2p &&
840 mvmvif->ap_ibss_active)
841 data->go_active = true;
844 static int iwl_mvm_mac_ctxt_cmd_p2p_device(struct iwl_mvm *mvm,
845 struct ieee80211_vif *vif,
848 struct iwl_mac_ctx_cmd cmd = {};
849 struct iwl_mvm_go_iterator_data data = {};
851 WARN_ON(vif->type != NL80211_IFTYPE_P2P_DEVICE);
853 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
855 cmd.protection_flags |= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT);
857 /* Override the filter flags to accept only probe requests */
858 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
861 * This flag should be set to true when the P2P Device is
862 * discoverable and there is at least another active P2P GO. Settings
863 * this flag will allow the P2P Device to be discoverable on other
864 * channels in addition to its listen channel.
865 * Note that this flag should not be set in other cases as it opens the
866 * Rx filters on all MAC and increases the number of interrupts.
868 ieee80211_iterate_active_interfaces_atomic(
869 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
870 iwl_mvm_go_iterator, &data);
872 cmd.p2p_dev.is_disc_extended = cpu_to_le32(data.go_active ? 1 : 0);
873 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
876 static void iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm *mvm,
877 struct iwl_mac_beacon_cmd *beacon_cmd,
878 u8 *beacon, u32 frame_size)
881 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
883 /* The index is relative to frame start but we start looking at the
884 * variable-length part of the beacon. */
885 tim_idx = mgmt->u.beacon.variable - beacon;
887 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
888 while ((tim_idx < (frame_size - 2)) &&
889 (beacon[tim_idx] != WLAN_EID_TIM))
890 tim_idx += beacon[tim_idx+1] + 2;
892 /* If TIM field was found, set variables */
893 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
894 beacon_cmd->tim_idx = cpu_to_le32(tim_idx);
895 beacon_cmd->tim_size = cpu_to_le32((u32)beacon[tim_idx+1]);
897 IWL_WARN(mvm, "Unable to find TIM Element in beacon\n");
901 static int iwl_mvm_mac_ctxt_send_beacon(struct iwl_mvm *mvm,
902 struct ieee80211_vif *vif,
903 struct sk_buff *beacon)
905 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
906 struct iwl_host_cmd cmd = {
907 .id = BEACON_TEMPLATE_CMD,
910 struct iwl_mac_beacon_cmd beacon_cmd = {};
911 struct ieee80211_tx_info *info;
915 if (WARN_ON(!beacon))
918 beacon_skb_len = beacon->len;
920 /* TODO: for now the beacon template id is set to be the mac context id.
921 * Might be better to handle it as another resource ... */
922 beacon_cmd.template_id = cpu_to_le32((u32)mvmvif->id);
923 info = IEEE80211_SKB_CB(beacon);
925 /* Set up TX command fields */
926 beacon_cmd.tx.len = cpu_to_le16((u16)beacon_skb_len);
927 beacon_cmd.tx.sta_id = mvmvif->bcast_sta.sta_id;
928 beacon_cmd.tx.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
929 tx_flags = TX_CMD_FLG_SEQ_CTL | TX_CMD_FLG_TSF;
931 iwl_mvm_bt_coex_tx_prio(mvm, (void *)beacon->data, info, 0) <<
932 TX_CMD_FLG_BT_PRIO_POS;
933 beacon_cmd.tx.tx_flags = cpu_to_le32(tx_flags);
935 mvm->mgmt_last_antenna_idx =
936 iwl_mvm_next_antenna(mvm, mvm->fw->valid_tx_ant,
937 mvm->mgmt_last_antenna_idx);
939 beacon_cmd.tx.rate_n_flags =
940 cpu_to_le32(BIT(mvm->mgmt_last_antenna_idx) <<
943 if (info->band == IEEE80211_BAND_5GHZ || vif->p2p) {
944 rate = IWL_FIRST_OFDM_RATE;
946 rate = IWL_FIRST_CCK_RATE;
947 beacon_cmd.tx.rate_n_flags |= cpu_to_le32(RATE_MCS_CCK_MSK);
949 beacon_cmd.tx.rate_n_flags |=
950 cpu_to_le32(iwl_mvm_mac80211_idx_to_hwrate(rate));
952 /* Set up TX beacon command fields */
953 if (vif->type == NL80211_IFTYPE_AP)
954 iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd,
959 cmd.len[0] = sizeof(beacon_cmd);
960 cmd.data[0] = &beacon_cmd;
961 cmd.dataflags[0] = 0;
962 cmd.len[1] = beacon_skb_len;
963 cmd.data[1] = beacon->data;
964 cmd.dataflags[1] = IWL_HCMD_DFL_DUP;
966 return iwl_mvm_send_cmd(mvm, &cmd);
969 /* The beacon template for the AP/GO/IBSS has changed and needs update */
970 int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm,
971 struct ieee80211_vif *vif)
973 struct sk_buff *beacon;
976 WARN_ON(vif->type != NL80211_IFTYPE_AP &&
977 vif->type != NL80211_IFTYPE_ADHOC);
979 beacon = ieee80211_beacon_get_template(mvm->hw, vif, NULL);
983 ret = iwl_mvm_mac_ctxt_send_beacon(mvm, vif, beacon);
984 dev_kfree_skb(beacon);
988 struct iwl_mvm_mac_ap_iterator_data {
990 struct ieee80211_vif *vif;
991 u32 beacon_device_ts;
995 /* Find the beacon_device_ts and beacon_int for a managed interface */
996 static void iwl_mvm_mac_ap_iterator(void *_data, u8 *mac,
997 struct ieee80211_vif *vif)
999 struct iwl_mvm_mac_ap_iterator_data *data = _data;
1001 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
1004 /* Station client has higher priority over P2P client*/
1005 if (vif->p2p && data->beacon_device_ts)
1008 data->beacon_device_ts = vif->bss_conf.sync_device_ts;
1009 data->beacon_int = vif->bss_conf.beacon_int;
1013 * Fill the specific data for mac context of type AP of P2P GO
1015 static void iwl_mvm_mac_ctxt_cmd_fill_ap(struct iwl_mvm *mvm,
1016 struct ieee80211_vif *vif,
1017 struct iwl_mac_data_ap *ctxt_ap,
1020 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1021 struct iwl_mvm_mac_ap_iterator_data data = {
1024 .beacon_device_ts = 0
1027 ctxt_ap->bi = cpu_to_le32(vif->bss_conf.beacon_int);
1028 ctxt_ap->bi_reciprocal =
1029 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
1030 ctxt_ap->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
1031 vif->bss_conf.dtim_period);
1032 ctxt_ap->dtim_reciprocal =
1033 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int *
1034 vif->bss_conf.dtim_period));
1036 ctxt_ap->mcast_qid = cpu_to_le32(vif->cab_queue);
1039 * Only set the beacon time when the MAC is being added, when we
1040 * just modify the MAC then we should keep the time -- the firmware
1041 * can otherwise have a "jumping" TBTT.
1045 * If there is a station/P2P client interface which is
1046 * associated, set the AP's TBTT far enough from the station's
1047 * TBTT. Otherwise, set it to the current system time
1049 ieee80211_iterate_active_interfaces_atomic(
1050 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1051 iwl_mvm_mac_ap_iterator, &data);
1053 if (data.beacon_device_ts) {
1054 u32 rand = (prandom_u32() % (64 - 36)) + 36;
1055 mvmvif->ap_beacon_time = data.beacon_device_ts +
1056 ieee80211_tu_to_usec(data.beacon_int * rand /
1059 mvmvif->ap_beacon_time =
1060 iwl_read_prph(mvm->trans,
1061 DEVICE_SYSTEM_TIME_REG);
1065 ctxt_ap->beacon_time = cpu_to_le32(mvmvif->ap_beacon_time);
1066 ctxt_ap->beacon_tsf = 0; /* unused */
1068 /* TODO: Assume that the beacon id == mac context id */
1069 ctxt_ap->beacon_template = cpu_to_le32(mvmvif->id);
1072 static int iwl_mvm_mac_ctxt_cmd_ap(struct iwl_mvm *mvm,
1073 struct ieee80211_vif *vif,
1076 struct iwl_mac_ctx_cmd cmd = {};
1078 WARN_ON(vif->type != NL80211_IFTYPE_AP || vif->p2p);
1080 /* Fill the common data for all mac context types */
1081 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
1084 * pass probe requests and beacons from other APs (needed
1085 * for ht protection)
1087 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST |
1088 MAC_FILTER_IN_BEACON);
1090 /* Fill the data specific for ap mode */
1091 iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd.ap,
1092 action == FW_CTXT_ACTION_ADD);
1094 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1097 static int iwl_mvm_mac_ctxt_cmd_go(struct iwl_mvm *mvm,
1098 struct ieee80211_vif *vif,
1101 struct iwl_mac_ctx_cmd cmd = {};
1102 struct ieee80211_p2p_noa_attr *noa = &vif->bss_conf.p2p_noa_attr;
1104 WARN_ON(vif->type != NL80211_IFTYPE_AP || !vif->p2p);
1106 /* Fill the common data for all mac context types */
1107 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
1110 * pass probe requests and beacons from other APs (needed
1111 * for ht protection)
1113 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST |
1114 MAC_FILTER_IN_BEACON);
1116 /* Fill the data specific for GO mode */
1117 iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd.go.ap,
1118 action == FW_CTXT_ACTION_ADD);
1120 cmd.go.ctwin = cpu_to_le32(noa->oppps_ctwindow &
1121 IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
1122 cmd.go.opp_ps_enabled =
1123 cpu_to_le32(!!(noa->oppps_ctwindow &
1124 IEEE80211_P2P_OPPPS_ENABLE_BIT));
1126 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1129 static int iwl_mvm_mac_ctx_send(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1130 u32 action, bool force_assoc_off,
1131 const u8 *bssid_override)
1133 switch (vif->type) {
1134 case NL80211_IFTYPE_STATION:
1135 return iwl_mvm_mac_ctxt_cmd_sta(mvm, vif, action,
1139 case NL80211_IFTYPE_AP:
1141 return iwl_mvm_mac_ctxt_cmd_ap(mvm, vif, action);
1143 return iwl_mvm_mac_ctxt_cmd_go(mvm, vif, action);
1145 case NL80211_IFTYPE_MONITOR:
1146 return iwl_mvm_mac_ctxt_cmd_listener(mvm, vif, action);
1147 case NL80211_IFTYPE_P2P_DEVICE:
1148 return iwl_mvm_mac_ctxt_cmd_p2p_device(mvm, vif, action);
1149 case NL80211_IFTYPE_ADHOC:
1150 return iwl_mvm_mac_ctxt_cmd_ibss(mvm, vif, action);
1158 int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1160 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1163 if (WARN_ONCE(mvmvif->uploaded, "Adding active MAC %pM/%d\n",
1164 vif->addr, ieee80211_vif_type_p2p(vif)))
1167 ret = iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_ADD,
1172 /* will only do anything at resume from D3 time */
1173 iwl_mvm_set_last_nonqos_seq(mvm, vif);
1175 mvmvif->uploaded = true;
1179 int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1180 bool force_assoc_off, const u8 *bssid_override)
1182 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1184 if (WARN_ONCE(!mvmvif->uploaded, "Changing inactive MAC %pM/%d\n",
1185 vif->addr, ieee80211_vif_type_p2p(vif)))
1188 return iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_MODIFY,
1189 force_assoc_off, bssid_override);
1192 int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1194 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1195 struct iwl_mac_ctx_cmd cmd;
1198 if (WARN_ONCE(!mvmvif->uploaded, "Removing inactive MAC %pM/%d\n",
1199 vif->addr, ieee80211_vif_type_p2p(vif)))
1202 memset(&cmd, 0, sizeof(cmd));
1204 cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1206 cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE);
1208 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, 0,
1211 IWL_ERR(mvm, "Failed to remove MAC context: %d\n", ret);
1215 mvmvif->uploaded = false;
1217 if (vif->type == NL80211_IFTYPE_MONITOR)
1218 mvm->hw->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
1223 static void iwl_mvm_csa_count_down(struct iwl_mvm *mvm,
1224 struct ieee80211_vif *csa_vif, u32 gp2)
1226 struct iwl_mvm_vif *mvmvif =
1227 iwl_mvm_vif_from_mac80211(csa_vif);
1229 if (!ieee80211_csa_is_complete(csa_vif)) {
1230 int c = ieee80211_csa_update_counter(csa_vif);
1232 iwl_mvm_mac_ctxt_beacon_changed(mvm, csa_vif);
1234 !iwl_mvm_te_scheduled(&mvmvif->time_event_data) && gp2) {
1235 u32 rel_time = (c + 1) *
1236 csa_vif->bss_conf.beacon_int -
1237 IWL_MVM_CHANNEL_SWITCH_TIME;
1238 u32 apply_time = gp2 + rel_time * 1024;
1240 iwl_mvm_schedule_csa_noa(mvm, csa_vif,
1241 IWL_MVM_CHANNEL_SWITCH_TIME -
1242 IWL_MVM_CHANNEL_SWITCH_MARGIN,
1245 } else if (!iwl_mvm_te_scheduled(&mvmvif->time_event_data)) {
1246 /* we don't have CSA NoA scheduled yet, switch now */
1247 ieee80211_csa_finish(csa_vif);
1248 RCU_INIT_POINTER(mvm->csa_vif, NULL);
1252 int iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
1253 struct iwl_rx_cmd_buffer *rxb,
1254 struct iwl_device_cmd *cmd)
1256 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1257 struct iwl_mvm_tx_resp *beacon_notify_hdr;
1258 struct ieee80211_vif *csa_vif;
1259 struct ieee80211_vif *tx_blocked_vif;
1262 lockdep_assert_held(&mvm->mutex);
1264 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_CAPA_EXTENDED_BEACON) {
1265 struct iwl_extended_beacon_notif *beacon = (void *)pkt->data;
1267 beacon_notify_hdr = &beacon->beacon_notify_hdr;
1268 tsf = le64_to_cpu(beacon->tsf);
1269 mvm->ap_last_beacon_gp2 = le32_to_cpu(beacon->gp2);
1271 struct iwl_beacon_notif *beacon = (void *)pkt->data;
1273 beacon_notify_hdr = &beacon->beacon_notify_hdr;
1274 tsf = le64_to_cpu(beacon->tsf);
1278 "beacon status %#x retries:%d tsf:0x%16llX gp2:0x%X rate:%d\n",
1279 le16_to_cpu(beacon_notify_hdr->status.status) &
1281 beacon_notify_hdr->failure_frame, tsf,
1282 mvm->ap_last_beacon_gp2,
1283 le32_to_cpu(beacon_notify_hdr->initial_rate));
1285 csa_vif = rcu_dereference_protected(mvm->csa_vif,
1286 lockdep_is_held(&mvm->mutex));
1287 if (unlikely(csa_vif && csa_vif->csa_active))
1288 iwl_mvm_csa_count_down(mvm, csa_vif, mvm->ap_last_beacon_gp2);
1290 tx_blocked_vif = rcu_dereference_protected(mvm->csa_tx_blocked_vif,
1291 lockdep_is_held(&mvm->mutex));
1292 if (unlikely(tx_blocked_vif)) {
1293 struct iwl_mvm_vif *mvmvif =
1294 iwl_mvm_vif_from_mac80211(tx_blocked_vif);
1297 * The channel switch is started and we have blocked the
1298 * stations. If this is the first beacon (the timeout wasn't
1299 * set), set the unblock timeout, otherwise countdown
1301 if (!mvm->csa_tx_block_bcn_timeout)
1302 mvm->csa_tx_block_bcn_timeout =
1303 IWL_MVM_CS_UNBLOCK_TX_TIMEOUT;
1305 mvm->csa_tx_block_bcn_timeout--;
1307 /* Check if the timeout is expired, and unblock tx */
1308 if (mvm->csa_tx_block_bcn_timeout == 0) {
1309 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false);
1310 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
1317 static void iwl_mvm_beacon_loss_iterator(void *_data, u8 *mac,
1318 struct ieee80211_vif *vif)
1320 struct iwl_missed_beacons_notif *missed_beacons = _data;
1321 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1323 if (mvmvif->id != (u16)le32_to_cpu(missed_beacons->mac_id))
1327 * TODO: the threshold should be adjusted based on latency conditions,
1328 * and/or in case of a CS flow on one of the other AP vifs.
1330 if (le32_to_cpu(missed_beacons->consec_missed_beacons_since_last_rx) >
1331 IWL_MVM_MISSED_BEACONS_THRESHOLD)
1332 ieee80211_beacon_loss(vif);
1335 int iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm,
1336 struct iwl_rx_cmd_buffer *rxb,
1337 struct iwl_device_cmd *cmd)
1339 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1340 struct iwl_missed_beacons_notif *mb = (void *)pkt->data;
1343 "missed bcn mac_id=%u, consecutive=%u (%u, %u, %u)\n",
1344 le32_to_cpu(mb->mac_id),
1345 le32_to_cpu(mb->consec_missed_beacons),
1346 le32_to_cpu(mb->consec_missed_beacons_since_last_rx),
1347 le32_to_cpu(mb->num_recvd_beacons),
1348 le32_to_cpu(mb->num_expected_beacons));
1350 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
1351 IEEE80211_IFACE_ITER_NORMAL,
1352 iwl_mvm_beacon_loss_iterator,