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.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 *****************************************************************************/
64 #include <linux/etherdevice.h>
65 #include <net/mac80211.h>
71 const u8 iwl_mvm_ac_to_tx_fifo[] = {
78 struct iwl_mvm_mac_iface_iterator_data {
80 struct ieee80211_vif *vif;
81 unsigned long available_mac_ids[BITS_TO_LONGS(NUM_MAC_INDEX_DRIVER)];
82 unsigned long available_tsf_ids[BITS_TO_LONGS(NUM_TSF_IDS)];
83 unsigned long used_hw_queues[BITS_TO_LONGS(IWL_MVM_MAX_QUEUES)];
84 enum iwl_tsf_id preferred_tsf;
88 static void iwl_mvm_mac_tsf_id_iter(void *_data, u8 *mac,
89 struct ieee80211_vif *vif)
91 struct iwl_mvm_mac_iface_iterator_data *data = _data;
92 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
95 /* Skip the interface for which we are trying to assign a tsf_id */
100 * The TSF is a hardware/firmware resource, there are 4 and
101 * the driver should assign and free them as needed. However,
102 * there are cases where 2 MACs should share the same TSF ID
103 * for the purpose of clock sync, an optimization to avoid
104 * clock drift causing overlapping TBTTs/DTIMs for a GO and
105 * client in the system.
107 * The firmware will decide according to the MAC type which
108 * will be the master and slave. Clients that need to sync
109 * with a remote station will be the master, and an AP or GO
112 * Depending on the new interface type it can be slaved to
113 * or become the master of an existing interface.
115 switch (data->vif->type) {
116 case NL80211_IFTYPE_STATION:
118 * The new interface is a client, so if the one we're iterating
119 * is an AP, and the beacon interval of the AP is a multiple or
120 * divisor of the beacon interval of the client, the same TSF
121 * should be used to avoid drift between the new client and
122 * existing AP. The existing AP will get drift updates from the
123 * new client context in this case.
125 if (vif->type != NL80211_IFTYPE_AP ||
126 data->preferred_tsf != NUM_TSF_IDS ||
127 !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
130 min_bi = min(data->vif->bss_conf.beacon_int,
131 vif->bss_conf.beacon_int);
136 if ((data->vif->bss_conf.beacon_int -
137 vif->bss_conf.beacon_int) % min_bi == 0) {
138 data->preferred_tsf = mvmvif->tsf_id;
143 case NL80211_IFTYPE_AP:
145 * The new interface is AP/GO, so if its beacon interval is a
146 * multiple or a divisor of the beacon interval of an existing
147 * interface, it should get drift updates from an existing
148 * client or use the same TSF as an existing GO. There's no
149 * drift between TSFs internally but if they used different
150 * TSFs then a new client MAC could update one of them and
151 * cause drift that way.
153 if ((vif->type != NL80211_IFTYPE_AP &&
154 vif->type != NL80211_IFTYPE_STATION) ||
155 data->preferred_tsf != NUM_TSF_IDS ||
156 !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
159 min_bi = min(data->vif->bss_conf.beacon_int,
160 vif->bss_conf.beacon_int);
165 if ((data->vif->bss_conf.beacon_int -
166 vif->bss_conf.beacon_int) % min_bi == 0) {
167 data->preferred_tsf = mvmvif->tsf_id;
173 * For all other interface types there's no need to
174 * take drift into account. Either they're exclusive
175 * like IBSS and monitor, or we don't care much about
176 * their TSF (like P2P Device), but we won't be able
177 * to share the TSF resource.
183 * Unless we exited above, we can't share the TSF resource
184 * that the virtual interface we're iterating over is using
185 * with the new one, so clear the available bit and if this
186 * was the preferred one, reset that as well.
188 __clear_bit(mvmvif->tsf_id, data->available_tsf_ids);
190 if (data->preferred_tsf == mvmvif->tsf_id)
191 data->preferred_tsf = NUM_TSF_IDS;
194 static void iwl_mvm_mac_iface_iterator(void *_data, u8 *mac,
195 struct ieee80211_vif *vif)
197 struct iwl_mvm_mac_iface_iterator_data *data = _data;
198 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
201 /* Iterator may already find the interface being added -- skip it */
202 if (vif == data->vif) {
203 data->found_vif = true;
207 /* Mark the queues used by the vif */
208 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
209 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
210 __set_bit(vif->hw_queue[ac], data->used_hw_queues);
212 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
213 __set_bit(vif->cab_queue, data->used_hw_queues);
215 /* Mark MAC IDs as used by clearing the available bit, and
216 * (below) mark TSFs as used if their existing use is not
217 * compatible with the new interface type.
218 * No locking or atomic bit operations are needed since the
219 * data is on the stack of the caller function.
221 __clear_bit(mvmvif->id, data->available_mac_ids);
223 /* find a suitable tsf_id */
224 iwl_mvm_mac_tsf_id_iter(_data, mac, vif);
228 * Get the mask of the queus used by the vif
230 u32 iwl_mvm_mac_get_queues_mask(struct iwl_mvm *mvm,
231 struct ieee80211_vif *vif)
235 if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
236 return BIT(IWL_MVM_OFFCHANNEL_QUEUE);
238 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
239 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
240 qmask |= BIT(vif->hw_queue[ac]);
245 void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm *mvm,
246 struct ieee80211_vif *vif)
248 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
249 struct iwl_mvm_mac_iface_iterator_data data = {
252 .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
253 /* no preference yet */
254 .preferred_tsf = NUM_TSF_IDS,
257 ieee80211_iterate_active_interfaces_atomic(
258 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
259 iwl_mvm_mac_tsf_id_iter, &data);
261 if (data.preferred_tsf != NUM_TSF_IDS)
262 mvmvif->tsf_id = data.preferred_tsf;
263 else if (!test_bit(mvmvif->tsf_id, data.available_tsf_ids))
264 mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
268 static int iwl_mvm_mac_ctxt_allocate_resources(struct iwl_mvm *mvm,
269 struct ieee80211_vif *vif)
271 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
272 struct iwl_mvm_mac_iface_iterator_data data = {
275 .available_mac_ids = { (1 << NUM_MAC_INDEX_DRIVER) - 1 },
276 .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
277 /* no preference yet */
278 .preferred_tsf = NUM_TSF_IDS,
280 BIT(IWL_MVM_OFFCHANNEL_QUEUE) |
281 BIT(mvm->aux_queue) |
282 BIT(IWL_MVM_CMD_QUEUE)
290 * Allocate a MAC ID and a TSF for this MAC, along with the queues
291 * and other resources.
295 * Before the iterator, we start with all MAC IDs and TSFs available.
297 * During iteration, all MAC IDs are cleared that are in use by other
298 * virtual interfaces, and all TSF IDs are cleared that can't be used
299 * by this new virtual interface because they're used by an interface
300 * that can't share it with the new one.
301 * At the same time, we check if there's a preferred TSF in the case
302 * that we should share it with another interface.
305 /* Currently, MAC ID 0 should be used only for the managed/IBSS vif */
307 case NL80211_IFTYPE_ADHOC:
309 case NL80211_IFTYPE_STATION:
314 __clear_bit(0, data.available_mac_ids);
317 ieee80211_iterate_active_interfaces_atomic(
318 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
319 iwl_mvm_mac_iface_iterator, &data);
322 * In the case we're getting here during resume, it's similar to
323 * firmware restart, and with RESUME_ALL the iterator will find
324 * the vif being added already.
325 * We don't want to reassign any IDs in either case since doing
326 * so would probably assign different IDs (as interfaces aren't
327 * necessarily added in the same order), but the old IDs were
328 * preserved anyway, so skip ID assignment for both resume and
334 /* Therefore, in recovery, we can't get here */
335 if (WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
338 mvmvif->id = find_first_bit(data.available_mac_ids,
339 NUM_MAC_INDEX_DRIVER);
340 if (mvmvif->id == NUM_MAC_INDEX_DRIVER) {
341 IWL_ERR(mvm, "Failed to init MAC context - no free ID!\n");
346 if (data.preferred_tsf != NUM_TSF_IDS)
347 mvmvif->tsf_id = data.preferred_tsf;
349 mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
351 if (mvmvif->tsf_id == NUM_TSF_IDS) {
352 IWL_ERR(mvm, "Failed to init MAC context - no free TSF!\n");
359 INIT_LIST_HEAD(&mvmvif->time_event_data.list);
360 mvmvif->time_event_data.id = TE_MAX;
362 /* No need to allocate data queues to P2P Device MAC.*/
363 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
364 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
365 vif->hw_queue[ac] = IEEE80211_INVAL_HW_QUEUE;
370 /* Find available queues, and allocate them to the ACs */
371 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
372 u8 queue = find_first_zero_bit(data.used_hw_queues,
373 mvm->first_agg_queue);
375 if (queue >= mvm->first_agg_queue) {
376 IWL_ERR(mvm, "Failed to allocate queue\n");
381 __set_bit(queue, data.used_hw_queues);
382 vif->hw_queue[ac] = queue;
385 /* Allocate the CAB queue for softAP and GO interfaces */
386 if (vif->type == NL80211_IFTYPE_AP) {
387 u8 queue = find_first_zero_bit(data.used_hw_queues,
388 mvm->first_agg_queue);
390 if (queue >= mvm->first_agg_queue) {
391 IWL_ERR(mvm, "Failed to allocate cab queue\n");
396 vif->cab_queue = queue;
398 vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
401 mvmvif->bcast_sta.sta_id = IWL_MVM_STATION_COUNT;
402 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
404 for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++)
405 mvmvif->smps_requests[i] = IEEE80211_SMPS_AUTOMATIC;
410 memset(mvmvif, 0, sizeof(struct iwl_mvm_vif));
411 memset(vif->hw_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(vif->hw_queue));
412 vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
416 int iwl_mvm_mac_ctxt_init(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
421 lockdep_assert_held(&mvm->mutex);
423 ret = iwl_mvm_mac_ctxt_allocate_resources(mvm, vif);
428 case NL80211_IFTYPE_P2P_DEVICE:
429 iwl_trans_ac_txq_enable(mvm->trans, IWL_MVM_OFFCHANNEL_QUEUE,
432 case NL80211_IFTYPE_AP:
433 iwl_trans_ac_txq_enable(mvm->trans, vif->cab_queue,
434 IWL_MVM_TX_FIFO_MCAST);
437 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
438 iwl_trans_ac_txq_enable(mvm->trans, vif->hw_queue[ac],
439 iwl_mvm_ac_to_tx_fifo[ac]);
446 void iwl_mvm_mac_ctxt_release(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
450 lockdep_assert_held(&mvm->mutex);
453 case NL80211_IFTYPE_P2P_DEVICE:
454 iwl_trans_txq_disable(mvm->trans, IWL_MVM_OFFCHANNEL_QUEUE);
456 case NL80211_IFTYPE_AP:
457 iwl_trans_txq_disable(mvm->trans, vif->cab_queue);
460 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
461 iwl_trans_txq_disable(mvm->trans, vif->hw_queue[ac]);
465 static void iwl_mvm_ack_rates(struct iwl_mvm *mvm,
466 struct ieee80211_vif *vif,
467 enum ieee80211_band band,
468 u8 *cck_rates, u8 *ofdm_rates)
470 struct ieee80211_supported_band *sband;
471 unsigned long basic = vif->bss_conf.basic_rates;
472 int lowest_present_ofdm = 100;
473 int lowest_present_cck = 100;
478 sband = mvm->hw->wiphy->bands[band];
480 for_each_set_bit(i, &basic, BITS_PER_LONG) {
481 int hw = sband->bitrates[i].hw_value;
482 if (hw >= IWL_FIRST_OFDM_RATE) {
483 ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE);
484 if (lowest_present_ofdm > hw)
485 lowest_present_ofdm = hw;
487 BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
490 if (lowest_present_cck > hw)
491 lowest_present_cck = hw;
496 * Now we've got the basic rates as bitmaps in the ofdm and cck
497 * variables. This isn't sufficient though, as there might not
498 * be all the right rates in the bitmap. E.g. if the only basic
499 * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps
500 * and 6 Mbps because the 802.11-2007 standard says in 9.6:
502 * [...] a STA responding to a received frame shall transmit
503 * its Control Response frame [...] at the highest rate in the
504 * BSSBasicRateSet parameter that is less than or equal to the
505 * rate of the immediately previous frame in the frame exchange
506 * sequence ([...]) and that is of the same modulation class
507 * ([...]) as the received frame. If no rate contained in the
508 * BSSBasicRateSet parameter meets these conditions, then the
509 * control frame sent in response to a received frame shall be
510 * transmitted at the highest mandatory rate of the PHY that is
511 * less than or equal to the rate of the received frame, and
512 * that is of the same modulation class as the received frame.
514 * As a consequence, we need to add all mandatory rates that are
515 * lower than all of the basic rates to these bitmaps.
518 if (IWL_RATE_24M_INDEX < lowest_present_ofdm)
519 ofdm |= IWL_RATE_BIT_MSK(24) >> IWL_FIRST_OFDM_RATE;
520 if (IWL_RATE_12M_INDEX < lowest_present_ofdm)
521 ofdm |= IWL_RATE_BIT_MSK(12) >> IWL_FIRST_OFDM_RATE;
522 /* 6M already there or needed so always add */
523 ofdm |= IWL_RATE_BIT_MSK(6) >> IWL_FIRST_OFDM_RATE;
526 * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP.
528 * - if no CCK rates are basic, it must be ERP since there must
529 * be some basic rates at all, so they're OFDM => ERP PHY
530 * (or we're in 5 GHz, and the cck bitmap will never be used)
531 * - if 11M is a basic rate, it must be ERP as well, so add 5.5M
532 * - if 5.5M is basic, 1M and 2M are mandatory
533 * - if 2M is basic, 1M is mandatory
534 * - if 1M is basic, that's the only valid ACK rate.
535 * As a consequence, it's not as complicated as it sounds, just add
536 * any lower rates to the ACK rate bitmap.
538 if (IWL_RATE_11M_INDEX < lowest_present_cck)
539 cck |= IWL_RATE_BIT_MSK(11) >> IWL_FIRST_CCK_RATE;
540 if (IWL_RATE_5M_INDEX < lowest_present_cck)
541 cck |= IWL_RATE_BIT_MSK(5) >> IWL_FIRST_CCK_RATE;
542 if (IWL_RATE_2M_INDEX < lowest_present_cck)
543 cck |= IWL_RATE_BIT_MSK(2) >> IWL_FIRST_CCK_RATE;
544 /* 1M already there or needed so always add */
545 cck |= IWL_RATE_BIT_MSK(1) >> IWL_FIRST_CCK_RATE;
551 static void iwl_mvm_mac_ctxt_set_ht_flags(struct iwl_mvm *mvm,
552 struct ieee80211_vif *vif,
553 struct iwl_mac_ctx_cmd *cmd)
555 /* for both sta and ap, ht_operation_mode hold the protection_mode */
556 u8 protection_mode = vif->bss_conf.ht_operation_mode &
557 IEEE80211_HT_OP_MODE_PROTECTION;
558 /* The fw does not distinguish between ht and fat */
559 u32 ht_flag = MAC_PROT_FLG_HT_PROT | MAC_PROT_FLG_FAT_PROT;
561 IWL_DEBUG_RATE(mvm, "protection mode set to %d\n", protection_mode);
563 * See section 9.23.3.1 of IEEE 80211-2012.
564 * Nongreenfield HT STAs Present is not supported.
566 switch (protection_mode) {
567 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
569 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
570 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
571 cmd->protection_flags |= cpu_to_le32(ht_flag);
573 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
574 /* Protect when channel wider than 20MHz */
575 if (vif->bss_conf.chandef.width > NL80211_CHAN_WIDTH_20)
576 cmd->protection_flags |= cpu_to_le32(ht_flag);
579 IWL_ERR(mvm, "Illegal protection mode %d\n",
585 static void iwl_mvm_mac_ctxt_cmd_common(struct iwl_mvm *mvm,
586 struct ieee80211_vif *vif,
587 struct iwl_mac_ctx_cmd *cmd,
590 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
591 struct ieee80211_chanctx_conf *chanctx;
592 bool ht_enabled = !!(vif->bss_conf.ht_operation_mode &
593 IEEE80211_HT_OP_MODE_PROTECTION);
594 u8 cck_ack_rates, ofdm_ack_rates;
597 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
599 cmd->action = cpu_to_le32(action);
602 case NL80211_IFTYPE_STATION:
604 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_P2P_STA);
606 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_BSS_STA);
608 case NL80211_IFTYPE_AP:
609 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_GO);
611 case NL80211_IFTYPE_MONITOR:
612 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_LISTENER);
614 case NL80211_IFTYPE_P2P_DEVICE:
615 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_P2P_DEVICE);
617 case NL80211_IFTYPE_ADHOC:
618 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_IBSS);
624 cmd->tsf_id = cpu_to_le32(mvmvif->tsf_id);
626 memcpy(cmd->node_addr, vif->addr, ETH_ALEN);
627 if (vif->bss_conf.bssid)
628 memcpy(cmd->bssid_addr, vif->bss_conf.bssid, ETH_ALEN);
630 eth_broadcast_addr(cmd->bssid_addr);
633 chanctx = rcu_dereference(vif->chanctx_conf);
634 iwl_mvm_ack_rates(mvm, vif, chanctx ? chanctx->def.chan->band
635 : IEEE80211_BAND_2GHZ,
636 &cck_ack_rates, &ofdm_ack_rates);
639 cmd->cck_rates = cpu_to_le32((u32)cck_ack_rates);
640 cmd->ofdm_rates = cpu_to_le32((u32)ofdm_ack_rates);
642 cmd->cck_short_preamble =
643 cpu_to_le32(vif->bss_conf.use_short_preamble ?
644 MAC_FLG_SHORT_PREAMBLE : 0);
646 cpu_to_le32(vif->bss_conf.use_short_slot ?
647 MAC_FLG_SHORT_SLOT : 0);
649 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
650 u8 txf = iwl_mvm_ac_to_tx_fifo[i];
652 cmd->ac[txf].cw_min =
653 cpu_to_le16(mvmvif->queue_params[i].cw_min);
654 cmd->ac[txf].cw_max =
655 cpu_to_le16(mvmvif->queue_params[i].cw_max);
656 cmd->ac[txf].edca_txop =
657 cpu_to_le16(mvmvif->queue_params[i].txop * 32);
658 cmd->ac[txf].aifsn = mvmvif->queue_params[i].aifs;
659 cmd->ac[txf].fifos_mask = BIT(txf);
662 /* in AP mode, the MCAST FIFO takes the EDCA params from VO */
663 if (vif->type == NL80211_IFTYPE_AP)
664 cmd->ac[IWL_MVM_TX_FIFO_VO].fifos_mask |=
665 BIT(IWL_MVM_TX_FIFO_MCAST);
667 if (vif->bss_conf.qos)
668 cmd->qos_flags |= cpu_to_le32(MAC_QOS_FLG_UPDATE_EDCA);
670 if (vif->bss_conf.use_cts_prot) {
671 cmd->protection_flags |= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT);
672 cmd->protection_flags |= cpu_to_le32(MAC_PROT_FLG_SELF_CTS_EN);
674 IWL_DEBUG_RATE(mvm, "use_cts_prot %d, ht_operation_mode %d\n",
675 vif->bss_conf.use_cts_prot,
676 vif->bss_conf.ht_operation_mode);
677 if (vif->bss_conf.chandef.width != NL80211_CHAN_WIDTH_20_NOHT)
678 cmd->qos_flags |= cpu_to_le32(MAC_QOS_FLG_TGN);
680 iwl_mvm_mac_ctxt_set_ht_flags(mvm, vif, cmd);
682 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP);
685 static int iwl_mvm_mac_ctxt_send_cmd(struct iwl_mvm *mvm,
686 struct iwl_mac_ctx_cmd *cmd)
688 int ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, CMD_SYNC,
691 IWL_ERR(mvm, "Failed to send MAC context (action:%d): %d\n",
692 le32_to_cpu(cmd->action), ret);
697 * Fill the specific data for mac context of type station or p2p client
699 static void iwl_mvm_mac_ctxt_cmd_fill_sta(struct iwl_mvm *mvm,
700 struct ieee80211_vif *vif,
701 struct iwl_mac_data_sta *ctxt_sta,
702 bool force_assoc_off)
704 /* We need the dtim_period to set the MAC as associated */
705 if (vif->bss_conf.assoc && vif->bss_conf.dtim_period &&
710 * The DTIM count counts down, so when it is N that means N
711 * more beacon intervals happen until the DTIM TBTT. Therefore
712 * add this to the current time. If that ends up being in the
713 * future, the firmware will handle it.
715 * Also note that the system_timestamp (which we get here as
716 * "sync_device_ts") and TSF timestamp aren't at exactly the
717 * same offset in the frame -- the TSF is at the first symbol
718 * of the TSF, the system timestamp is at signal acquisition
719 * time. This means there's an offset between them of at most
720 * a few hundred microseconds (24 * 8 bits + PLCP time gives
721 * 384us in the longest case), this is currently not relevant
722 * as the firmware wakes up around 2ms before the TBTT.
724 dtim_offs = vif->bss_conf.sync_dtim_count *
725 vif->bss_conf.beacon_int;
726 /* convert TU to usecs */
730 cpu_to_le64(vif->bss_conf.sync_tsf + dtim_offs);
731 ctxt_sta->dtim_time =
732 cpu_to_le32(vif->bss_conf.sync_device_ts + dtim_offs);
734 IWL_DEBUG_INFO(mvm, "DTIM TBTT is 0x%llx/0x%x, offset %d\n",
735 le64_to_cpu(ctxt_sta->dtim_tsf),
736 le32_to_cpu(ctxt_sta->dtim_time),
739 ctxt_sta->is_assoc = cpu_to_le32(1);
741 ctxt_sta->is_assoc = cpu_to_le32(0);
744 ctxt_sta->bi = cpu_to_le32(vif->bss_conf.beacon_int);
745 ctxt_sta->bi_reciprocal =
746 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
747 ctxt_sta->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
748 vif->bss_conf.dtim_period);
749 ctxt_sta->dtim_reciprocal =
750 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int *
751 vif->bss_conf.dtim_period));
753 ctxt_sta->listen_interval = cpu_to_le32(mvm->hw->conf.listen_interval);
754 ctxt_sta->assoc_id = cpu_to_le32(vif->bss_conf.aid);
757 static int iwl_mvm_mac_ctxt_cmd_station(struct iwl_mvm *mvm,
758 struct ieee80211_vif *vif,
761 struct iwl_mac_ctx_cmd cmd = {};
763 WARN_ON(vif->type != NL80211_IFTYPE_STATION || vif->p2p);
765 /* Fill the common data for all mac context types */
766 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, action);
768 /* Allow beacons to pass through as long as we are not associated,or we
769 * do not have dtim period information */
770 if (!vif->bss_conf.assoc || !vif->bss_conf.dtim_period)
771 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_BEACON);
773 cmd.filter_flags &= ~cpu_to_le32(MAC_FILTER_IN_BEACON);
775 /* Fill the data specific for station mode */
776 iwl_mvm_mac_ctxt_cmd_fill_sta(mvm, vif, &cmd.sta,
777 action == FW_CTXT_ACTION_ADD);
779 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
782 static int iwl_mvm_mac_ctxt_cmd_p2p_client(struct iwl_mvm *mvm,
783 struct ieee80211_vif *vif,
786 struct iwl_mac_ctx_cmd cmd = {};
787 struct ieee80211_p2p_noa_attr *noa = &vif->bss_conf.p2p_noa_attr;
789 WARN_ON(vif->type != NL80211_IFTYPE_STATION || !vif->p2p);
791 /* Fill the common data for all mac context types */
792 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, action);
794 /* Fill the data specific for station mode */
795 iwl_mvm_mac_ctxt_cmd_fill_sta(mvm, vif, &cmd.p2p_sta.sta,
796 action == FW_CTXT_ACTION_ADD);
798 cmd.p2p_sta.ctwin = cpu_to_le32(noa->oppps_ctwindow &
799 IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
801 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
804 static int iwl_mvm_mac_ctxt_cmd_listener(struct iwl_mvm *mvm,
805 struct ieee80211_vif *vif,
808 struct iwl_mac_ctx_cmd cmd = {};
810 WARN_ON(vif->type != NL80211_IFTYPE_MONITOR);
812 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, action);
814 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROMISC |
815 MAC_FILTER_IN_CONTROL_AND_MGMT |
816 MAC_FILTER_IN_BEACON |
817 MAC_FILTER_IN_PROBE_REQUEST |
818 MAC_FILTER_IN_CRC32);
819 mvm->hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS;
821 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
824 static int iwl_mvm_mac_ctxt_cmd_ibss(struct iwl_mvm *mvm,
825 struct ieee80211_vif *vif,
828 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
829 struct iwl_mac_ctx_cmd cmd = {};
831 WARN_ON(vif->type != NL80211_IFTYPE_ADHOC);
833 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, action);
835 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_BEACON |
836 MAC_FILTER_IN_PROBE_REQUEST);
838 /* cmd.ibss.beacon_time/cmd.ibss.beacon_tsf are curently ignored */
839 cmd.ibss.bi = cpu_to_le32(vif->bss_conf.beacon_int);
840 cmd.ibss.bi_reciprocal =
841 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
843 /* TODO: Assumes that the beacon id == mac context id */
844 cmd.ibss.beacon_template = cpu_to_le32(mvmvif->id);
846 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
849 struct iwl_mvm_go_iterator_data {
853 static void iwl_mvm_go_iterator(void *_data, u8 *mac, struct ieee80211_vif *vif)
855 struct iwl_mvm_go_iterator_data *data = _data;
856 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
858 if (vif->type == NL80211_IFTYPE_AP && vif->p2p &&
859 mvmvif->ap_ibss_active)
860 data->go_active = true;
863 static int iwl_mvm_mac_ctxt_cmd_p2p_device(struct iwl_mvm *mvm,
864 struct ieee80211_vif *vif,
867 struct iwl_mac_ctx_cmd cmd = {};
868 struct iwl_mvm_go_iterator_data data = {};
870 WARN_ON(vif->type != NL80211_IFTYPE_P2P_DEVICE);
872 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, action);
874 cmd.protection_flags |= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT);
876 /* Override the filter flags to accept only probe requests */
877 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
880 * This flag should be set to true when the P2P Device is
881 * discoverable and there is at least another active P2P GO. Settings
882 * this flag will allow the P2P Device to be discoverable on other
883 * channels in addition to its listen channel.
884 * Note that this flag should not be set in other cases as it opens the
885 * Rx filters on all MAC and increases the number of interrupts.
887 ieee80211_iterate_active_interfaces_atomic(
888 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
889 iwl_mvm_go_iterator, &data);
891 cmd.p2p_dev.is_disc_extended = cpu_to_le32(data.go_active ? 1 : 0);
892 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
895 static void iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm *mvm,
896 struct iwl_mac_beacon_cmd *beacon_cmd,
897 u8 *beacon, u32 frame_size)
900 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
902 /* The index is relative to frame start but we start looking at the
903 * variable-length part of the beacon. */
904 tim_idx = mgmt->u.beacon.variable - beacon;
906 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
907 while ((tim_idx < (frame_size - 2)) &&
908 (beacon[tim_idx] != WLAN_EID_TIM))
909 tim_idx += beacon[tim_idx+1] + 2;
911 /* If TIM field was found, set variables */
912 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
913 beacon_cmd->tim_idx = cpu_to_le32(tim_idx);
914 beacon_cmd->tim_size = cpu_to_le32((u32)beacon[tim_idx+1]);
916 IWL_WARN(mvm, "Unable to find TIM Element in beacon\n");
920 static int iwl_mvm_mac_ctxt_send_beacon(struct iwl_mvm *mvm,
921 struct ieee80211_vif *vif,
922 struct sk_buff *beacon)
924 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
925 struct iwl_host_cmd cmd = {
926 .id = BEACON_TEMPLATE_CMD,
929 struct iwl_mac_beacon_cmd beacon_cmd = {};
930 struct ieee80211_tx_info *info;
934 if (WARN_ON(!beacon))
937 beacon_skb_len = beacon->len;
939 /* TODO: for now the beacon template id is set to be the mac context id.
940 * Might be better to handle it as another resource ... */
941 beacon_cmd.template_id = cpu_to_le32((u32)mvmvif->id);
943 /* Set up TX command fields */
944 beacon_cmd.tx.len = cpu_to_le16((u16)beacon_skb_len);
945 beacon_cmd.tx.sta_id = mvmvif->bcast_sta.sta_id;
946 beacon_cmd.tx.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
947 beacon_cmd.tx.tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
951 mvm->mgmt_last_antenna_idx =
952 iwl_mvm_next_antenna(mvm, mvm->fw->valid_tx_ant,
953 mvm->mgmt_last_antenna_idx);
955 beacon_cmd.tx.rate_n_flags =
956 cpu_to_le32(BIT(mvm->mgmt_last_antenna_idx) <<
959 info = IEEE80211_SKB_CB(beacon);
961 if (info->band == IEEE80211_BAND_5GHZ || vif->p2p) {
962 rate = IWL_FIRST_OFDM_RATE;
964 rate = IWL_FIRST_CCK_RATE;
965 beacon_cmd.tx.rate_n_flags |= cpu_to_le32(RATE_MCS_CCK_MSK);
967 beacon_cmd.tx.rate_n_flags |=
968 cpu_to_le32(iwl_mvm_mac80211_idx_to_hwrate(rate));
970 /* Set up TX beacon command fields */
971 if (vif->type == NL80211_IFTYPE_AP)
972 iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd,
977 cmd.len[0] = sizeof(beacon_cmd);
978 cmd.data[0] = &beacon_cmd;
979 cmd.dataflags[0] = 0;
980 cmd.len[1] = beacon_skb_len;
981 cmd.data[1] = beacon->data;
982 cmd.dataflags[1] = IWL_HCMD_DFL_DUP;
984 return iwl_mvm_send_cmd(mvm, &cmd);
987 /* The beacon template for the AP/GO/IBSS has changed and needs update */
988 int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm,
989 struct ieee80211_vif *vif)
991 struct sk_buff *beacon;
994 WARN_ON(vif->type != NL80211_IFTYPE_AP &&
995 vif->type != NL80211_IFTYPE_ADHOC);
997 beacon = ieee80211_beacon_get(mvm->hw, vif);
1001 ret = iwl_mvm_mac_ctxt_send_beacon(mvm, vif, beacon);
1002 dev_kfree_skb(beacon);
1006 struct iwl_mvm_mac_ap_iterator_data {
1007 struct iwl_mvm *mvm;
1008 struct ieee80211_vif *vif;
1009 u32 beacon_device_ts;
1013 /* Find the beacon_device_ts and beacon_int for a managed interface */
1014 static void iwl_mvm_mac_ap_iterator(void *_data, u8 *mac,
1015 struct ieee80211_vif *vif)
1017 struct iwl_mvm_mac_ap_iterator_data *data = _data;
1019 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
1022 /* Station client has higher priority over P2P client*/
1023 if (vif->p2p && data->beacon_device_ts)
1026 data->beacon_device_ts = vif->bss_conf.sync_device_ts;
1027 data->beacon_int = vif->bss_conf.beacon_int;
1031 * Fill the specific data for mac context of type AP of P2P GO
1033 static void iwl_mvm_mac_ctxt_cmd_fill_ap(struct iwl_mvm *mvm,
1034 struct ieee80211_vif *vif,
1035 struct iwl_mac_data_ap *ctxt_ap,
1038 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1039 struct iwl_mvm_mac_ap_iterator_data data = {
1042 .beacon_device_ts = 0
1045 ctxt_ap->bi = cpu_to_le32(vif->bss_conf.beacon_int);
1046 ctxt_ap->bi_reciprocal =
1047 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
1048 ctxt_ap->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
1049 vif->bss_conf.dtim_period);
1050 ctxt_ap->dtim_reciprocal =
1051 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int *
1052 vif->bss_conf.dtim_period));
1054 ctxt_ap->mcast_qid = cpu_to_le32(vif->cab_queue);
1057 * Only set the beacon time when the MAC is being added, when we
1058 * just modify the MAC then we should keep the time -- the firmware
1059 * can otherwise have a "jumping" TBTT.
1063 * If there is a station/P2P client interface which is
1064 * associated, set the AP's TBTT far enough from the station's
1065 * TBTT. Otherwise, set it to the current system time
1067 ieee80211_iterate_active_interfaces_atomic(
1068 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1069 iwl_mvm_mac_ap_iterator, &data);
1071 if (data.beacon_device_ts) {
1072 u32 rand = (prandom_u32() % (64 - 36)) + 36;
1073 mvmvif->ap_beacon_time = data.beacon_device_ts +
1074 ieee80211_tu_to_usec(data.beacon_int * rand /
1077 mvmvif->ap_beacon_time =
1078 iwl_read_prph(mvm->trans,
1079 DEVICE_SYSTEM_TIME_REG);
1083 ctxt_ap->beacon_time = cpu_to_le32(mvmvif->ap_beacon_time);
1084 ctxt_ap->beacon_tsf = 0; /* unused */
1086 /* TODO: Assume that the beacon id == mac context id */
1087 ctxt_ap->beacon_template = cpu_to_le32(mvmvif->id);
1090 static int iwl_mvm_mac_ctxt_cmd_ap(struct iwl_mvm *mvm,
1091 struct ieee80211_vif *vif,
1094 struct iwl_mac_ctx_cmd cmd = {};
1096 WARN_ON(vif->type != NL80211_IFTYPE_AP || vif->p2p);
1098 /* Fill the common data for all mac context types */
1099 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, action);
1101 /* Also enable probe requests to pass */
1102 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
1104 /* Fill the data specific for ap mode */
1105 iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd.ap,
1106 action == FW_CTXT_ACTION_ADD);
1108 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1111 static int iwl_mvm_mac_ctxt_cmd_go(struct iwl_mvm *mvm,
1112 struct ieee80211_vif *vif,
1115 struct iwl_mac_ctx_cmd cmd = {};
1116 struct ieee80211_p2p_noa_attr *noa = &vif->bss_conf.p2p_noa_attr;
1118 WARN_ON(vif->type != NL80211_IFTYPE_AP || !vif->p2p);
1120 /* Fill the common data for all mac context types */
1121 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, action);
1123 /* Fill the data specific for GO mode */
1124 iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd.go.ap,
1125 action == FW_CTXT_ACTION_ADD);
1127 cmd.go.ctwin = cpu_to_le32(noa->oppps_ctwindow &
1128 IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
1129 cmd.go.opp_ps_enabled =
1130 cpu_to_le32(!!(noa->oppps_ctwindow &
1131 IEEE80211_P2P_OPPPS_ENABLE_BIT));
1133 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1136 static int iwl_mvm_mac_ctx_send(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1139 switch (vif->type) {
1140 case NL80211_IFTYPE_STATION:
1142 return iwl_mvm_mac_ctxt_cmd_station(mvm, vif,
1145 return iwl_mvm_mac_ctxt_cmd_p2p_client(mvm, vif,
1148 case NL80211_IFTYPE_AP:
1150 return iwl_mvm_mac_ctxt_cmd_ap(mvm, vif, action);
1152 return iwl_mvm_mac_ctxt_cmd_go(mvm, vif, action);
1154 case NL80211_IFTYPE_MONITOR:
1155 return iwl_mvm_mac_ctxt_cmd_listener(mvm, vif, action);
1156 case NL80211_IFTYPE_P2P_DEVICE:
1157 return iwl_mvm_mac_ctxt_cmd_p2p_device(mvm, vif, action);
1158 case NL80211_IFTYPE_ADHOC:
1159 return iwl_mvm_mac_ctxt_cmd_ibss(mvm, vif, action);
1167 int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1169 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1172 if (WARN_ONCE(mvmvif->uploaded, "Adding active MAC %pM/%d\n",
1173 vif->addr, ieee80211_vif_type_p2p(vif)))
1176 ret = iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_ADD);
1180 /* will only do anything at resume from D3 time */
1181 iwl_mvm_set_last_nonqos_seq(mvm, vif);
1183 mvmvif->uploaded = true;
1187 int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1189 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1191 if (WARN_ONCE(!mvmvif->uploaded, "Changing inactive MAC %pM/%d\n",
1192 vif->addr, ieee80211_vif_type_p2p(vif)))
1195 return iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_MODIFY);
1198 int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1200 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1201 struct iwl_mac_ctx_cmd cmd;
1204 if (WARN_ONCE(!mvmvif->uploaded, "Removing inactive MAC %pM/%d\n",
1205 vif->addr, ieee80211_vif_type_p2p(vif)))
1208 memset(&cmd, 0, sizeof(cmd));
1210 cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1212 cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE);
1214 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, CMD_SYNC,
1217 IWL_ERR(mvm, "Failed to remove MAC context: %d\n", ret);
1221 mvmvif->uploaded = false;
1223 if (vif->type == NL80211_IFTYPE_MONITOR)
1224 mvm->hw->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
1229 int iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
1230 struct iwl_rx_cmd_buffer *rxb,
1231 struct iwl_device_cmd *cmd)
1233 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1234 struct iwl_beacon_notif *beacon = (void *)pkt->data;
1235 u16 status __maybe_unused =
1236 le16_to_cpu(beacon->beacon_notify_hdr.status.status);
1237 u32 rate __maybe_unused =
1238 le32_to_cpu(beacon->beacon_notify_hdr.initial_rate);
1240 IWL_DEBUG_RX(mvm, "beacon status %#x retries:%d tsf:0x%16llX rate:%d\n",
1241 status & TX_STATUS_MSK,
1242 beacon->beacon_notify_hdr.failure_frame,
1243 le64_to_cpu(beacon->tsf),
1248 static void iwl_mvm_beacon_loss_iterator(void *_data, u8 *mac,
1249 struct ieee80211_vif *vif)
1251 struct iwl_missed_beacons_notif *missed_beacons = _data;
1252 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1254 if (mvmvif->id != (u16)le32_to_cpu(missed_beacons->mac_id))
1258 * TODO: the threshold should be adjusted based on latency conditions,
1259 * and/or in case of a CS flow on one of the other AP vifs.
1261 if (le32_to_cpu(missed_beacons->consec_missed_beacons_since_last_rx) >
1262 IWL_MVM_MISSED_BEACONS_THRESHOLD)
1263 ieee80211_beacon_loss(vif);
1266 int iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm,
1267 struct iwl_rx_cmd_buffer *rxb,
1268 struct iwl_device_cmd *cmd)
1270 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1271 struct iwl_missed_beacons_notif *mb = (void *)pkt->data;
1274 "missed bcn mac_id=%u, consecutive=%u (%u, %u, %u)\n",
1275 le32_to_cpu(mb->mac_id),
1276 le32_to_cpu(mb->consec_missed_beacons),
1277 le32_to_cpu(mb->consec_missed_beacons_since_last_rx),
1278 le32_to_cpu(mb->num_recvd_beacons),
1279 le32_to_cpu(mb->num_expected_beacons));
1281 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
1282 IEEE80211_IFACE_ITER_NORMAL,
1283 iwl_mvm_beacon_loss_iterator,