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>
70 #include "time-event.h"
72 const u8 iwl_mvm_ac_to_tx_fifo[] = {
79 struct iwl_mvm_mac_iface_iterator_data {
81 struct ieee80211_vif *vif;
82 unsigned long available_mac_ids[BITS_TO_LONGS(NUM_MAC_INDEX_DRIVER)];
83 unsigned long available_tsf_ids[BITS_TO_LONGS(NUM_TSF_IDS)];
84 unsigned long used_hw_queues[BITS_TO_LONGS(IWL_MVM_MAX_QUEUES)];
85 enum iwl_tsf_id preferred_tsf;
89 static void iwl_mvm_mac_tsf_id_iter(void *_data, u8 *mac,
90 struct ieee80211_vif *vif)
92 struct iwl_mvm_mac_iface_iterator_data *data = _data;
93 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
96 /* Skip the interface for which we are trying to assign a tsf_id */
101 * The TSF is a hardware/firmware resource, there are 4 and
102 * the driver should assign and free them as needed. However,
103 * there are cases where 2 MACs should share the same TSF ID
104 * for the purpose of clock sync, an optimization to avoid
105 * clock drift causing overlapping TBTTs/DTIMs for a GO and
106 * client in the system.
108 * The firmware will decide according to the MAC type which
109 * will be the master and slave. Clients that need to sync
110 * with a remote station will be the master, and an AP or GO
113 * Depending on the new interface type it can be slaved to
114 * or become the master of an existing interface.
116 switch (data->vif->type) {
117 case NL80211_IFTYPE_STATION:
119 * The new interface is a client, so if the one we're iterating
120 * is an AP, and the beacon interval of the AP is a multiple or
121 * divisor of the beacon interval of the client, the same TSF
122 * should be used to avoid drift between the new client and
123 * existing AP. The existing AP will get drift updates from the
124 * new client context in this case.
126 if (vif->type != NL80211_IFTYPE_AP ||
127 data->preferred_tsf != NUM_TSF_IDS ||
128 !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
131 min_bi = min(data->vif->bss_conf.beacon_int,
132 vif->bss_conf.beacon_int);
137 if ((data->vif->bss_conf.beacon_int -
138 vif->bss_conf.beacon_int) % min_bi == 0) {
139 data->preferred_tsf = mvmvif->tsf_id;
144 case NL80211_IFTYPE_AP:
146 * The new interface is AP/GO, so if its beacon interval is a
147 * multiple or a divisor of the beacon interval of an existing
148 * interface, it should get drift updates from an existing
149 * client or use the same TSF as an existing GO. There's no
150 * drift between TSFs internally but if they used different
151 * TSFs then a new client MAC could update one of them and
152 * cause drift that way.
154 if ((vif->type != NL80211_IFTYPE_AP &&
155 vif->type != NL80211_IFTYPE_STATION) ||
156 data->preferred_tsf != NUM_TSF_IDS ||
157 !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
160 min_bi = min(data->vif->bss_conf.beacon_int,
161 vif->bss_conf.beacon_int);
166 if ((data->vif->bss_conf.beacon_int -
167 vif->bss_conf.beacon_int) % min_bi == 0) {
168 data->preferred_tsf = mvmvif->tsf_id;
174 * For all other interface types there's no need to
175 * take drift into account. Either they're exclusive
176 * like IBSS and monitor, or we don't care much about
177 * their TSF (like P2P Device), but we won't be able
178 * to share the TSF resource.
184 * Unless we exited above, we can't share the TSF resource
185 * that the virtual interface we're iterating over is using
186 * with the new one, so clear the available bit and if this
187 * was the preferred one, reset that as well.
189 __clear_bit(mvmvif->tsf_id, data->available_tsf_ids);
191 if (data->preferred_tsf == mvmvif->tsf_id)
192 data->preferred_tsf = NUM_TSF_IDS;
195 static void iwl_mvm_mac_iface_iterator(void *_data, u8 *mac,
196 struct ieee80211_vif *vif)
198 struct iwl_mvm_mac_iface_iterator_data *data = _data;
199 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
202 /* Iterator may already find the interface being added -- skip it */
203 if (vif == data->vif) {
204 data->found_vif = true;
208 /* Mark the queues used by the vif */
209 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
210 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
211 __set_bit(vif->hw_queue[ac], data->used_hw_queues);
213 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
214 __set_bit(vif->cab_queue, data->used_hw_queues);
216 /* Mark MAC IDs as used by clearing the available bit, and
217 * (below) mark TSFs as used if their existing use is not
218 * compatible with the new interface type.
219 * No locking or atomic bit operations are needed since the
220 * data is on the stack of the caller function.
222 __clear_bit(mvmvif->id, data->available_mac_ids);
224 /* find a suitable tsf_id */
225 iwl_mvm_mac_tsf_id_iter(_data, mac, vif);
229 * Get the mask of the queus used by the vif
231 u32 iwl_mvm_mac_get_queues_mask(struct iwl_mvm *mvm,
232 struct ieee80211_vif *vif)
236 if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
237 return BIT(IWL_MVM_OFFCHANNEL_QUEUE);
239 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
240 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
241 qmask |= BIT(vif->hw_queue[ac]);
246 void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm *mvm,
247 struct ieee80211_vif *vif)
249 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
250 struct iwl_mvm_mac_iface_iterator_data data = {
253 .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
254 /* no preference yet */
255 .preferred_tsf = NUM_TSF_IDS,
258 ieee80211_iterate_active_interfaces_atomic(
259 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
260 iwl_mvm_mac_tsf_id_iter, &data);
262 if (data.preferred_tsf != NUM_TSF_IDS)
263 mvmvif->tsf_id = data.preferred_tsf;
264 else if (!test_bit(mvmvif->tsf_id, data.available_tsf_ids))
265 mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
269 static int iwl_mvm_mac_ctxt_allocate_resources(struct iwl_mvm *mvm,
270 struct ieee80211_vif *vif)
272 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
273 struct iwl_mvm_mac_iface_iterator_data data = {
276 .available_mac_ids = { (1 << NUM_MAC_INDEX_DRIVER) - 1 },
277 .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
278 /* no preference yet */
279 .preferred_tsf = NUM_TSF_IDS,
281 BIT(IWL_MVM_OFFCHANNEL_QUEUE) |
282 BIT(mvm->aux_queue) |
283 BIT(IWL_MVM_CMD_QUEUE)
291 * Allocate a MAC ID and a TSF for this MAC, along with the queues
292 * and other resources.
296 * Before the iterator, we start with all MAC IDs and TSFs available.
298 * During iteration, all MAC IDs are cleared that are in use by other
299 * virtual interfaces, and all TSF IDs are cleared that can't be used
300 * by this new virtual interface because they're used by an interface
301 * that can't share it with the new one.
302 * At the same time, we check if there's a preferred TSF in the case
303 * that we should share it with another interface.
306 /* Currently, MAC ID 0 should be used only for the managed/IBSS vif */
308 case NL80211_IFTYPE_ADHOC:
310 case NL80211_IFTYPE_STATION:
315 __clear_bit(0, data.available_mac_ids);
318 ieee80211_iterate_active_interfaces_atomic(
319 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
320 iwl_mvm_mac_iface_iterator, &data);
323 * In the case we're getting here during resume, it's similar to
324 * firmware restart, and with RESUME_ALL the iterator will find
325 * the vif being added already.
326 * We don't want to reassign any IDs in either case since doing
327 * so would probably assign different IDs (as interfaces aren't
328 * necessarily added in the same order), but the old IDs were
329 * preserved anyway, so skip ID assignment for both resume and
335 /* Therefore, in recovery, we can't get here */
336 if (WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
339 mvmvif->id = find_first_bit(data.available_mac_ids,
340 NUM_MAC_INDEX_DRIVER);
341 if (mvmvif->id == NUM_MAC_INDEX_DRIVER) {
342 IWL_ERR(mvm, "Failed to init MAC context - no free ID!\n");
347 if (data.preferred_tsf != NUM_TSF_IDS)
348 mvmvif->tsf_id = data.preferred_tsf;
350 mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
352 if (mvmvif->tsf_id == NUM_TSF_IDS) {
353 IWL_ERR(mvm, "Failed to init MAC context - no free TSF!\n");
360 INIT_LIST_HEAD(&mvmvif->time_event_data.list);
361 mvmvif->time_event_data.id = TE_MAX;
363 /* No need to allocate data queues to P2P Device MAC.*/
364 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
365 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
366 vif->hw_queue[ac] = IEEE80211_INVAL_HW_QUEUE;
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(data.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, data.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(data.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);
457 case NL80211_IFTYPE_AP:
458 iwl_trans_txq_disable(mvm->trans, vif->cab_queue);
461 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
462 iwl_trans_txq_disable(mvm->trans, vif->hw_queue[ac]);
466 static void iwl_mvm_ack_rates(struct iwl_mvm *mvm,
467 struct ieee80211_vif *vif,
468 enum ieee80211_band band,
469 u8 *cck_rates, u8 *ofdm_rates)
471 struct ieee80211_supported_band *sband;
472 unsigned long basic = vif->bss_conf.basic_rates;
473 int lowest_present_ofdm = 100;
474 int lowest_present_cck = 100;
479 sband = mvm->hw->wiphy->bands[band];
481 for_each_set_bit(i, &basic, BITS_PER_LONG) {
482 int hw = sband->bitrates[i].hw_value;
483 if (hw >= IWL_FIRST_OFDM_RATE) {
484 ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE);
485 if (lowest_present_ofdm > hw)
486 lowest_present_ofdm = hw;
488 BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
491 if (lowest_present_cck > hw)
492 lowest_present_cck = hw;
497 * Now we've got the basic rates as bitmaps in the ofdm and cck
498 * variables. This isn't sufficient though, as there might not
499 * be all the right rates in the bitmap. E.g. if the only basic
500 * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps
501 * and 6 Mbps because the 802.11-2007 standard says in 9.6:
503 * [...] a STA responding to a received frame shall transmit
504 * its Control Response frame [...] at the highest rate in the
505 * BSSBasicRateSet parameter that is less than or equal to the
506 * rate of the immediately previous frame in the frame exchange
507 * sequence ([...]) and that is of the same modulation class
508 * ([...]) as the received frame. If no rate contained in the
509 * BSSBasicRateSet parameter meets these conditions, then the
510 * control frame sent in response to a received frame shall be
511 * transmitted at the highest mandatory rate of the PHY that is
512 * less than or equal to the rate of the received frame, and
513 * that is of the same modulation class as the received frame.
515 * As a consequence, we need to add all mandatory rates that are
516 * lower than all of the basic rates to these bitmaps.
519 if (IWL_RATE_24M_INDEX < lowest_present_ofdm)
520 ofdm |= IWL_RATE_BIT_MSK(24) >> IWL_FIRST_OFDM_RATE;
521 if (IWL_RATE_12M_INDEX < lowest_present_ofdm)
522 ofdm |= IWL_RATE_BIT_MSK(12) >> IWL_FIRST_OFDM_RATE;
523 /* 6M already there or needed so always add */
524 ofdm |= IWL_RATE_BIT_MSK(6) >> IWL_FIRST_OFDM_RATE;
527 * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP.
529 * - if no CCK rates are basic, it must be ERP since there must
530 * be some basic rates at all, so they're OFDM => ERP PHY
531 * (or we're in 5 GHz, and the cck bitmap will never be used)
532 * - if 11M is a basic rate, it must be ERP as well, so add 5.5M
533 * - if 5.5M is basic, 1M and 2M are mandatory
534 * - if 2M is basic, 1M is mandatory
535 * - if 1M is basic, that's the only valid ACK rate.
536 * As a consequence, it's not as complicated as it sounds, just add
537 * any lower rates to the ACK rate bitmap.
539 if (IWL_RATE_11M_INDEX < lowest_present_cck)
540 cck |= IWL_RATE_BIT_MSK(11) >> IWL_FIRST_CCK_RATE;
541 if (IWL_RATE_5M_INDEX < lowest_present_cck)
542 cck |= IWL_RATE_BIT_MSK(5) >> IWL_FIRST_CCK_RATE;
543 if (IWL_RATE_2M_INDEX < lowest_present_cck)
544 cck |= IWL_RATE_BIT_MSK(2) >> IWL_FIRST_CCK_RATE;
545 /* 1M already there or needed so always add */
546 cck |= IWL_RATE_BIT_MSK(1) >> IWL_FIRST_CCK_RATE;
552 static void iwl_mvm_mac_ctxt_set_ht_flags(struct iwl_mvm *mvm,
553 struct ieee80211_vif *vif,
554 struct iwl_mac_ctx_cmd *cmd)
556 /* for both sta and ap, ht_operation_mode hold the protection_mode */
557 u8 protection_mode = vif->bss_conf.ht_operation_mode &
558 IEEE80211_HT_OP_MODE_PROTECTION;
559 /* The fw does not distinguish between ht and fat */
560 u32 ht_flag = MAC_PROT_FLG_HT_PROT | MAC_PROT_FLG_FAT_PROT;
562 IWL_DEBUG_RATE(mvm, "protection mode set to %d\n", protection_mode);
564 * See section 9.23.3.1 of IEEE 80211-2012.
565 * Nongreenfield HT STAs Present is not supported.
567 switch (protection_mode) {
568 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
570 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
571 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
572 cmd->protection_flags |= cpu_to_le32(ht_flag);
574 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
575 /* Protect when channel wider than 20MHz */
576 if (vif->bss_conf.chandef.width > NL80211_CHAN_WIDTH_20)
577 cmd->protection_flags |= cpu_to_le32(ht_flag);
580 IWL_ERR(mvm, "Illegal protection mode %d\n",
586 static void iwl_mvm_mac_ctxt_cmd_common(struct iwl_mvm *mvm,
587 struct ieee80211_vif *vif,
588 struct iwl_mac_ctx_cmd *cmd,
591 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
592 struct ieee80211_chanctx_conf *chanctx;
593 bool ht_enabled = !!(vif->bss_conf.ht_operation_mode &
594 IEEE80211_HT_OP_MODE_PROTECTION);
595 u8 cck_ack_rates, ofdm_ack_rates;
598 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
600 cmd->action = cpu_to_le32(action);
603 case NL80211_IFTYPE_STATION:
605 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_P2P_STA);
607 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_BSS_STA);
609 case NL80211_IFTYPE_AP:
610 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_GO);
612 case NL80211_IFTYPE_MONITOR:
613 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_LISTENER);
615 case NL80211_IFTYPE_P2P_DEVICE:
616 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_P2P_DEVICE);
618 case NL80211_IFTYPE_ADHOC:
619 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_IBSS);
625 cmd->tsf_id = cpu_to_le32(mvmvif->tsf_id);
627 memcpy(cmd->node_addr, vif->addr, ETH_ALEN);
628 if (vif->bss_conf.bssid)
629 memcpy(cmd->bssid_addr, vif->bss_conf.bssid, ETH_ALEN);
631 eth_broadcast_addr(cmd->bssid_addr);
634 chanctx = rcu_dereference(vif->chanctx_conf);
635 iwl_mvm_ack_rates(mvm, vif, chanctx ? chanctx->def.chan->band
636 : IEEE80211_BAND_2GHZ,
637 &cck_ack_rates, &ofdm_ack_rates);
640 cmd->cck_rates = cpu_to_le32((u32)cck_ack_rates);
641 cmd->ofdm_rates = cpu_to_le32((u32)ofdm_ack_rates);
643 cmd->cck_short_preamble =
644 cpu_to_le32(vif->bss_conf.use_short_preamble ?
645 MAC_FLG_SHORT_PREAMBLE : 0);
647 cpu_to_le32(vif->bss_conf.use_short_slot ?
648 MAC_FLG_SHORT_SLOT : 0);
650 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
651 u8 txf = iwl_mvm_ac_to_tx_fifo[i];
653 cmd->ac[txf].cw_min =
654 cpu_to_le16(mvmvif->queue_params[i].cw_min);
655 cmd->ac[txf].cw_max =
656 cpu_to_le16(mvmvif->queue_params[i].cw_max);
657 cmd->ac[txf].edca_txop =
658 cpu_to_le16(mvmvif->queue_params[i].txop * 32);
659 cmd->ac[txf].aifsn = mvmvif->queue_params[i].aifs;
660 cmd->ac[txf].fifos_mask = BIT(txf);
663 /* in AP mode, the MCAST FIFO takes the EDCA params from VO */
664 if (vif->type == NL80211_IFTYPE_AP)
665 cmd->ac[IWL_MVM_TX_FIFO_VO].fifos_mask |=
666 BIT(IWL_MVM_TX_FIFO_MCAST);
668 if (vif->bss_conf.qos)
669 cmd->qos_flags |= cpu_to_le32(MAC_QOS_FLG_UPDATE_EDCA);
671 if (vif->bss_conf.use_cts_prot)
672 cmd->protection_flags |= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT);
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, 0,
691 IWL_ERR(mvm, "Failed to send MAC context (action:%d): %d\n",
692 le32_to_cpu(cmd->action), ret);
696 static int iwl_mvm_mac_ctxt_cmd_sta(struct iwl_mvm *mvm,
697 struct ieee80211_vif *vif,
698 u32 action, bool force_assoc_off)
700 struct iwl_mac_ctx_cmd cmd = {};
701 struct iwl_mac_data_sta *ctxt_sta;
703 WARN_ON(vif->type != NL80211_IFTYPE_STATION);
705 /* Fill the common data for all mac context types */
706 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, action);
709 struct ieee80211_p2p_noa_attr *noa =
710 &vif->bss_conf.p2p_noa_attr;
712 cmd.p2p_sta.ctwin = cpu_to_le32(noa->oppps_ctwindow &
713 IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
714 ctxt_sta = &cmd.p2p_sta.sta;
719 /* We need the dtim_period to set the MAC as associated */
720 if (vif->bss_conf.assoc && vif->bss_conf.dtim_period &&
724 /* Allow beacons to pass through as long as we are not
725 * associated, or we do not have dtim period information.
727 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_BEACON);
730 * The DTIM count counts down, so when it is N that means N
731 * more beacon intervals happen until the DTIM TBTT. Therefore
732 * add this to the current time. If that ends up being in the
733 * future, the firmware will handle it.
735 * Also note that the system_timestamp (which we get here as
736 * "sync_device_ts") and TSF timestamp aren't at exactly the
737 * same offset in the frame -- the TSF is at the first symbol
738 * of the TSF, the system timestamp is at signal acquisition
739 * time. This means there's an offset between them of at most
740 * a few hundred microseconds (24 * 8 bits + PLCP time gives
741 * 384us in the longest case), this is currently not relevant
742 * as the firmware wakes up around 2ms before the TBTT.
744 dtim_offs = vif->bss_conf.sync_dtim_count *
745 vif->bss_conf.beacon_int;
746 /* convert TU to usecs */
750 cpu_to_le64(vif->bss_conf.sync_tsf + dtim_offs);
751 ctxt_sta->dtim_time =
752 cpu_to_le32(vif->bss_conf.sync_device_ts + dtim_offs);
754 IWL_DEBUG_INFO(mvm, "DTIM TBTT is 0x%llx/0x%x, offset %d\n",
755 le64_to_cpu(ctxt_sta->dtim_tsf),
756 le32_to_cpu(ctxt_sta->dtim_time),
759 ctxt_sta->is_assoc = cpu_to_le32(1);
761 ctxt_sta->is_assoc = cpu_to_le32(0);
764 ctxt_sta->bi = cpu_to_le32(vif->bss_conf.beacon_int);
765 ctxt_sta->bi_reciprocal =
766 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
767 ctxt_sta->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
768 vif->bss_conf.dtim_period);
769 ctxt_sta->dtim_reciprocal =
770 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int *
771 vif->bss_conf.dtim_period));
773 ctxt_sta->listen_interval = cpu_to_le32(mvm->hw->conf.listen_interval);
774 ctxt_sta->assoc_id = cpu_to_le32(vif->bss_conf.aid);
776 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
779 static int iwl_mvm_mac_ctxt_cmd_listener(struct iwl_mvm *mvm,
780 struct ieee80211_vif *vif,
783 struct iwl_mac_ctx_cmd cmd = {};
785 WARN_ON(vif->type != NL80211_IFTYPE_MONITOR);
787 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, action);
789 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROMISC |
790 MAC_FILTER_IN_CONTROL_AND_MGMT |
791 MAC_FILTER_IN_BEACON |
792 MAC_FILTER_IN_PROBE_REQUEST |
793 MAC_FILTER_IN_CRC32);
794 mvm->hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS;
796 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
799 static int iwl_mvm_mac_ctxt_cmd_ibss(struct iwl_mvm *mvm,
800 struct ieee80211_vif *vif,
803 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
804 struct iwl_mac_ctx_cmd cmd = {};
806 WARN_ON(vif->type != NL80211_IFTYPE_ADHOC);
808 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, action);
810 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_BEACON |
811 MAC_FILTER_IN_PROBE_REQUEST);
813 /* cmd.ibss.beacon_time/cmd.ibss.beacon_tsf are curently ignored */
814 cmd.ibss.bi = cpu_to_le32(vif->bss_conf.beacon_int);
815 cmd.ibss.bi_reciprocal =
816 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
818 /* TODO: Assumes that the beacon id == mac context id */
819 cmd.ibss.beacon_template = cpu_to_le32(mvmvif->id);
821 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
824 struct iwl_mvm_go_iterator_data {
828 static void iwl_mvm_go_iterator(void *_data, u8 *mac, struct ieee80211_vif *vif)
830 struct iwl_mvm_go_iterator_data *data = _data;
831 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
833 if (vif->type == NL80211_IFTYPE_AP && vif->p2p &&
834 mvmvif->ap_ibss_active)
835 data->go_active = true;
838 static int iwl_mvm_mac_ctxt_cmd_p2p_device(struct iwl_mvm *mvm,
839 struct ieee80211_vif *vif,
842 struct iwl_mac_ctx_cmd cmd = {};
843 struct iwl_mvm_go_iterator_data data = {};
845 WARN_ON(vif->type != NL80211_IFTYPE_P2P_DEVICE);
847 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, action);
849 cmd.protection_flags |= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT);
851 /* Override the filter flags to accept only probe requests */
852 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
855 * This flag should be set to true when the P2P Device is
856 * discoverable and there is at least another active P2P GO. Settings
857 * this flag will allow the P2P Device to be discoverable on other
858 * channels in addition to its listen channel.
859 * Note that this flag should not be set in other cases as it opens the
860 * Rx filters on all MAC and increases the number of interrupts.
862 ieee80211_iterate_active_interfaces_atomic(
863 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
864 iwl_mvm_go_iterator, &data);
866 cmd.p2p_dev.is_disc_extended = cpu_to_le32(data.go_active ? 1 : 0);
867 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
870 static void iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm *mvm,
871 struct iwl_mac_beacon_cmd *beacon_cmd,
872 u8 *beacon, u32 frame_size)
875 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
877 /* The index is relative to frame start but we start looking at the
878 * variable-length part of the beacon. */
879 tim_idx = mgmt->u.beacon.variable - beacon;
881 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
882 while ((tim_idx < (frame_size - 2)) &&
883 (beacon[tim_idx] != WLAN_EID_TIM))
884 tim_idx += beacon[tim_idx+1] + 2;
886 /* If TIM field was found, set variables */
887 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
888 beacon_cmd->tim_idx = cpu_to_le32(tim_idx);
889 beacon_cmd->tim_size = cpu_to_le32((u32)beacon[tim_idx+1]);
891 IWL_WARN(mvm, "Unable to find TIM Element in beacon\n");
895 static int iwl_mvm_mac_ctxt_send_beacon(struct iwl_mvm *mvm,
896 struct ieee80211_vif *vif,
897 struct sk_buff *beacon)
899 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
900 struct iwl_host_cmd cmd = {
901 .id = BEACON_TEMPLATE_CMD,
904 struct iwl_mac_beacon_cmd beacon_cmd = {};
905 struct ieee80211_tx_info *info;
909 if (WARN_ON(!beacon))
912 beacon_skb_len = beacon->len;
914 /* TODO: for now the beacon template id is set to be the mac context id.
915 * Might be better to handle it as another resource ... */
916 beacon_cmd.template_id = cpu_to_le32((u32)mvmvif->id);
917 info = IEEE80211_SKB_CB(beacon);
919 /* Set up TX command fields */
920 beacon_cmd.tx.len = cpu_to_le16((u16)beacon_skb_len);
921 beacon_cmd.tx.sta_id = mvmvif->bcast_sta.sta_id;
922 beacon_cmd.tx.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
923 tx_flags = TX_CMD_FLG_SEQ_CTL | TX_CMD_FLG_TSF;
925 iwl_mvm_bt_coex_tx_prio(mvm, (void *)beacon->data, info, 0) <<
926 TX_CMD_FLG_BT_PRIO_POS;
927 beacon_cmd.tx.tx_flags = cpu_to_le32(tx_flags);
929 mvm->mgmt_last_antenna_idx =
930 iwl_mvm_next_antenna(mvm, mvm->fw->valid_tx_ant,
931 mvm->mgmt_last_antenna_idx);
933 beacon_cmd.tx.rate_n_flags =
934 cpu_to_le32(BIT(mvm->mgmt_last_antenna_idx) <<
937 if (info->band == IEEE80211_BAND_5GHZ || vif->p2p) {
938 rate = IWL_FIRST_OFDM_RATE;
940 rate = IWL_FIRST_CCK_RATE;
941 beacon_cmd.tx.rate_n_flags |= cpu_to_le32(RATE_MCS_CCK_MSK);
943 beacon_cmd.tx.rate_n_flags |=
944 cpu_to_le32(iwl_mvm_mac80211_idx_to_hwrate(rate));
946 /* Set up TX beacon command fields */
947 if (vif->type == NL80211_IFTYPE_AP)
948 iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd,
953 cmd.len[0] = sizeof(beacon_cmd);
954 cmd.data[0] = &beacon_cmd;
955 cmd.dataflags[0] = 0;
956 cmd.len[1] = beacon_skb_len;
957 cmd.data[1] = beacon->data;
958 cmd.dataflags[1] = IWL_HCMD_DFL_DUP;
960 return iwl_mvm_send_cmd(mvm, &cmd);
963 /* The beacon template for the AP/GO/IBSS has changed and needs update */
964 int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm,
965 struct ieee80211_vif *vif)
967 struct sk_buff *beacon;
970 WARN_ON(vif->type != NL80211_IFTYPE_AP &&
971 vif->type != NL80211_IFTYPE_ADHOC);
973 beacon = ieee80211_beacon_get_template(mvm->hw, vif, NULL);
977 ret = iwl_mvm_mac_ctxt_send_beacon(mvm, vif, beacon);
978 dev_kfree_skb(beacon);
982 struct iwl_mvm_mac_ap_iterator_data {
984 struct ieee80211_vif *vif;
985 u32 beacon_device_ts;
989 /* Find the beacon_device_ts and beacon_int for a managed interface */
990 static void iwl_mvm_mac_ap_iterator(void *_data, u8 *mac,
991 struct ieee80211_vif *vif)
993 struct iwl_mvm_mac_ap_iterator_data *data = _data;
995 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
998 /* Station client has higher priority over P2P client*/
999 if (vif->p2p && data->beacon_device_ts)
1002 data->beacon_device_ts = vif->bss_conf.sync_device_ts;
1003 data->beacon_int = vif->bss_conf.beacon_int;
1007 * Fill the specific data for mac context of type AP of P2P GO
1009 static void iwl_mvm_mac_ctxt_cmd_fill_ap(struct iwl_mvm *mvm,
1010 struct ieee80211_vif *vif,
1011 struct iwl_mac_data_ap *ctxt_ap,
1014 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1015 struct iwl_mvm_mac_ap_iterator_data data = {
1018 .beacon_device_ts = 0
1021 ctxt_ap->bi = cpu_to_le32(vif->bss_conf.beacon_int);
1022 ctxt_ap->bi_reciprocal =
1023 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
1024 ctxt_ap->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
1025 vif->bss_conf.dtim_period);
1026 ctxt_ap->dtim_reciprocal =
1027 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int *
1028 vif->bss_conf.dtim_period));
1030 ctxt_ap->mcast_qid = cpu_to_le32(vif->cab_queue);
1033 * Only set the beacon time when the MAC is being added, when we
1034 * just modify the MAC then we should keep the time -- the firmware
1035 * can otherwise have a "jumping" TBTT.
1039 * If there is a station/P2P client interface which is
1040 * associated, set the AP's TBTT far enough from the station's
1041 * TBTT. Otherwise, set it to the current system time
1043 ieee80211_iterate_active_interfaces_atomic(
1044 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1045 iwl_mvm_mac_ap_iterator, &data);
1047 if (data.beacon_device_ts) {
1048 u32 rand = (prandom_u32() % (64 - 36)) + 36;
1049 mvmvif->ap_beacon_time = data.beacon_device_ts +
1050 ieee80211_tu_to_usec(data.beacon_int * rand /
1053 mvmvif->ap_beacon_time =
1054 iwl_read_prph(mvm->trans,
1055 DEVICE_SYSTEM_TIME_REG);
1059 ctxt_ap->beacon_time = cpu_to_le32(mvmvif->ap_beacon_time);
1060 ctxt_ap->beacon_tsf = 0; /* unused */
1062 /* TODO: Assume that the beacon id == mac context id */
1063 ctxt_ap->beacon_template = cpu_to_le32(mvmvif->id);
1066 static int iwl_mvm_mac_ctxt_cmd_ap(struct iwl_mvm *mvm,
1067 struct ieee80211_vif *vif,
1070 struct iwl_mac_ctx_cmd cmd = {};
1072 WARN_ON(vif->type != NL80211_IFTYPE_AP || vif->p2p);
1074 /* Fill the common data for all mac context types */
1075 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, action);
1078 * pass probe requests and beacons from other APs (needed
1079 * for ht protection)
1081 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST |
1082 MAC_FILTER_IN_BEACON);
1084 /* Fill the data specific for ap mode */
1085 iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd.ap,
1086 action == FW_CTXT_ACTION_ADD);
1088 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1091 static int iwl_mvm_mac_ctxt_cmd_go(struct iwl_mvm *mvm,
1092 struct ieee80211_vif *vif,
1095 struct iwl_mac_ctx_cmd cmd = {};
1096 struct ieee80211_p2p_noa_attr *noa = &vif->bss_conf.p2p_noa_attr;
1098 WARN_ON(vif->type != NL80211_IFTYPE_AP || !vif->p2p);
1100 /* Fill the common data for all mac context types */
1101 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, action);
1104 * pass probe requests and beacons from other APs (needed
1105 * for ht protection)
1107 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST |
1108 MAC_FILTER_IN_BEACON);
1110 /* Fill the data specific for GO mode */
1111 iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd.go.ap,
1112 action == FW_CTXT_ACTION_ADD);
1114 cmd.go.ctwin = cpu_to_le32(noa->oppps_ctwindow &
1115 IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
1116 cmd.go.opp_ps_enabled =
1117 cpu_to_le32(!!(noa->oppps_ctwindow &
1118 IEEE80211_P2P_OPPPS_ENABLE_BIT));
1120 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1123 static int iwl_mvm_mac_ctx_send(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1124 u32 action, bool force_assoc_off)
1126 switch (vif->type) {
1127 case NL80211_IFTYPE_STATION:
1128 return iwl_mvm_mac_ctxt_cmd_sta(mvm, vif, action,
1131 case NL80211_IFTYPE_AP:
1133 return iwl_mvm_mac_ctxt_cmd_ap(mvm, vif, action);
1135 return iwl_mvm_mac_ctxt_cmd_go(mvm, vif, action);
1137 case NL80211_IFTYPE_MONITOR:
1138 return iwl_mvm_mac_ctxt_cmd_listener(mvm, vif, action);
1139 case NL80211_IFTYPE_P2P_DEVICE:
1140 return iwl_mvm_mac_ctxt_cmd_p2p_device(mvm, vif, action);
1141 case NL80211_IFTYPE_ADHOC:
1142 return iwl_mvm_mac_ctxt_cmd_ibss(mvm, vif, action);
1150 int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1152 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1155 if (WARN_ONCE(mvmvif->uploaded, "Adding active MAC %pM/%d\n",
1156 vif->addr, ieee80211_vif_type_p2p(vif)))
1159 ret = iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_ADD,
1164 /* will only do anything at resume from D3 time */
1165 iwl_mvm_set_last_nonqos_seq(mvm, vif);
1167 mvmvif->uploaded = true;
1171 int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1172 bool force_assoc_off)
1174 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1176 if (WARN_ONCE(!mvmvif->uploaded, "Changing inactive MAC %pM/%d\n",
1177 vif->addr, ieee80211_vif_type_p2p(vif)))
1180 return iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_MODIFY,
1184 int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1186 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1187 struct iwl_mac_ctx_cmd cmd;
1190 if (WARN_ONCE(!mvmvif->uploaded, "Removing inactive MAC %pM/%d\n",
1191 vif->addr, ieee80211_vif_type_p2p(vif)))
1194 memset(&cmd, 0, sizeof(cmd));
1196 cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1198 cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE);
1200 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, 0,
1203 IWL_ERR(mvm, "Failed to remove MAC context: %d\n", ret);
1207 mvmvif->uploaded = false;
1209 if (vif->type == NL80211_IFTYPE_MONITOR)
1210 mvm->hw->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
1215 static void iwl_mvm_csa_count_down(struct iwl_mvm *mvm,
1216 struct ieee80211_vif *csa_vif, u32 gp2)
1218 struct iwl_mvm_vif *mvmvif =
1219 iwl_mvm_vif_from_mac80211(csa_vif);
1221 if (!ieee80211_csa_is_complete(csa_vif)) {
1222 int c = ieee80211_csa_update_counter(csa_vif);
1224 iwl_mvm_mac_ctxt_beacon_changed(mvm, csa_vif);
1226 !iwl_mvm_te_scheduled(&mvmvif->time_event_data) && gp2) {
1227 u32 rel_time = (c + 1) *
1228 csa_vif->bss_conf.beacon_int -
1229 IWL_MVM_CHANNEL_SWITCH_TIME;
1230 u32 apply_time = gp2 + rel_time * 1024;
1232 iwl_mvm_schedule_csa_noa(mvm, csa_vif,
1233 IWL_MVM_CHANNEL_SWITCH_TIME -
1234 IWL_MVM_CHANNEL_SWITCH_MARGIN,
1237 } else if (!iwl_mvm_te_scheduled(&mvmvif->time_event_data)) {
1238 /* we don't have CSA NoA scheduled yet, switch now */
1239 ieee80211_csa_finish(csa_vif);
1240 RCU_INIT_POINTER(mvm->csa_vif, NULL);
1244 int iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
1245 struct iwl_rx_cmd_buffer *rxb,
1246 struct iwl_device_cmd *cmd)
1248 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1249 struct iwl_mvm_tx_resp *beacon_notify_hdr;
1250 struct ieee80211_vif *csa_vif;
1251 struct ieee80211_vif *tx_blocked_vif;
1254 lockdep_assert_held(&mvm->mutex);
1256 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_CAPA_EXTENDED_BEACON) {
1257 struct iwl_extended_beacon_notif *beacon = (void *)pkt->data;
1259 beacon_notify_hdr = &beacon->beacon_notify_hdr;
1260 tsf = le64_to_cpu(beacon->tsf);
1261 mvm->ap_last_beacon_gp2 = le32_to_cpu(beacon->gp2);
1263 struct iwl_beacon_notif *beacon = (void *)pkt->data;
1265 beacon_notify_hdr = &beacon->beacon_notify_hdr;
1266 tsf = le64_to_cpu(beacon->tsf);
1270 "beacon status %#x retries:%d tsf:0x%16llX gp2:0x%X rate:%d\n",
1271 le16_to_cpu(beacon_notify_hdr->status.status) &
1273 beacon_notify_hdr->failure_frame, tsf,
1274 mvm->ap_last_beacon_gp2,
1275 le32_to_cpu(beacon_notify_hdr->initial_rate));
1277 csa_vif = rcu_dereference_protected(mvm->csa_vif,
1278 lockdep_is_held(&mvm->mutex));
1279 if (unlikely(csa_vif && csa_vif->csa_active))
1280 iwl_mvm_csa_count_down(mvm, csa_vif, mvm->ap_last_beacon_gp2);
1282 tx_blocked_vif = rcu_dereference_protected(mvm->csa_tx_blocked_vif,
1283 lockdep_is_held(&mvm->mutex));
1284 if (unlikely(tx_blocked_vif)) {
1285 struct iwl_mvm_vif *mvmvif =
1286 iwl_mvm_vif_from_mac80211(tx_blocked_vif);
1289 * The channel switch is started and we have blocked the
1290 * stations. If this is the first beacon (the timeout wasn't
1291 * set), set the unblock timeout, otherwise countdown
1293 if (!mvm->csa_tx_block_bcn_timeout)
1294 mvm->csa_tx_block_bcn_timeout =
1295 IWL_MVM_CS_UNBLOCK_TX_TIMEOUT;
1297 mvm->csa_tx_block_bcn_timeout--;
1299 /* Check if the timeout is expired, and unblock tx */
1300 if (mvm->csa_tx_block_bcn_timeout == 0) {
1301 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false);
1302 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
1309 static void iwl_mvm_beacon_loss_iterator(void *_data, u8 *mac,
1310 struct ieee80211_vif *vif)
1312 struct iwl_missed_beacons_notif *missed_beacons = _data;
1313 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1315 if (mvmvif->id != (u16)le32_to_cpu(missed_beacons->mac_id))
1319 * TODO: the threshold should be adjusted based on latency conditions,
1320 * and/or in case of a CS flow on one of the other AP vifs.
1322 if (le32_to_cpu(missed_beacons->consec_missed_beacons_since_last_rx) >
1323 IWL_MVM_MISSED_BEACONS_THRESHOLD)
1324 ieee80211_beacon_loss(vif);
1327 int iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm,
1328 struct iwl_rx_cmd_buffer *rxb,
1329 struct iwl_device_cmd *cmd)
1331 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1332 struct iwl_missed_beacons_notif *mb = (void *)pkt->data;
1335 "missed bcn mac_id=%u, consecutive=%u (%u, %u, %u)\n",
1336 le32_to_cpu(mb->mac_id),
1337 le32_to_cpu(mb->consec_missed_beacons),
1338 le32_to_cpu(mb->consec_missed_beacons_since_last_rx),
1339 le32_to_cpu(mb->num_recvd_beacons),
1340 le32_to_cpu(mb->num_expected_beacons));
1342 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
1343 IEEE80211_IFACE_ITER_NORMAL,
1344 iwl_mvm_beacon_loss_iterator,