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
);
94 /* Skip the interface for which we are trying to assign a tsf_id */
99 * The TSF is a hardware/firmware resource, there are 4 and
100 * the driver should assign and free them as needed. However,
101 * there are cases where 2 MACs should share the same TSF ID
102 * for the purpose of clock sync, an optimization to avoid
103 * clock drift causing overlapping TBTTs/DTIMs for a GO and
104 * client in the system.
106 * The firmware will decide according to the MAC type which
107 * will be the master and slave. Clients that need to sync
108 * with a remote station will be the master, and an AP or GO
111 * Depending on the new interface type it can be slaved to
112 * or become the master of an existing interface.
114 switch (data
->vif
->type
) {
115 case NL80211_IFTYPE_STATION
:
117 * The new interface is client, so if the existing one
118 * we're iterating is an AP, and both interfaces have the
119 * same beacon interval, the same TSF should be used to
120 * avoid drift between the new client and existing AP,
121 * the existing AP will get drift updates from the new
122 * client context in this case
124 if (vif
->type
== NL80211_IFTYPE_AP
) {
125 if (data
->preferred_tsf
== NUM_TSF_IDS
&&
126 test_bit(mvmvif
->tsf_id
, data
->available_tsf_ids
) &&
127 (vif
->bss_conf
.beacon_int
==
128 data
->vif
->bss_conf
.beacon_int
)) {
129 data
->preferred_tsf
= mvmvif
->tsf_id
;
134 case NL80211_IFTYPE_AP
:
136 * The new interface is AP/GO, so in case both interfaces
137 * have the same beacon interval, it should get drift
138 * updates from an existing client or use the same
139 * TSF as an existing GO. There's no drift between
140 * TSFs internally but if they used different TSFs
141 * then a new client MAC could update one of them
142 * and cause drift that way.
144 if (vif
->type
== NL80211_IFTYPE_STATION
||
145 vif
->type
== NL80211_IFTYPE_AP
) {
146 if (data
->preferred_tsf
== NUM_TSF_IDS
&&
147 test_bit(mvmvif
->tsf_id
, data
->available_tsf_ids
) &&
148 (vif
->bss_conf
.beacon_int
==
149 data
->vif
->bss_conf
.beacon_int
)) {
150 data
->preferred_tsf
= mvmvif
->tsf_id
;
157 * For all other interface types there's no need to
158 * take drift into account. Either they're exclusive
159 * like IBSS and monitor, or we don't care much about
160 * their TSF (like P2P Device), but we won't be able
161 * to share the TSF resource.
167 * Unless we exited above, we can't share the TSF resource
168 * that the virtual interface we're iterating over is using
169 * with the new one, so clear the available bit and if this
170 * was the preferred one, reset that as well.
172 __clear_bit(mvmvif
->tsf_id
, data
->available_tsf_ids
);
174 if (data
->preferred_tsf
== mvmvif
->tsf_id
)
175 data
->preferred_tsf
= NUM_TSF_IDS
;
178 static void iwl_mvm_mac_iface_iterator(void *_data
, u8
*mac
,
179 struct ieee80211_vif
*vif
)
181 struct iwl_mvm_mac_iface_iterator_data
*data
= _data
;
182 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
185 /* Iterator may already find the interface being added -- skip it */
186 if (vif
== data
->vif
) {
187 data
->found_vif
= true;
191 /* Mark the queues used by the vif */
192 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
193 if (vif
->hw_queue
[ac
] != IEEE80211_INVAL_HW_QUEUE
)
194 __set_bit(vif
->hw_queue
[ac
], data
->used_hw_queues
);
196 if (vif
->cab_queue
!= IEEE80211_INVAL_HW_QUEUE
)
197 __set_bit(vif
->cab_queue
, data
->used_hw_queues
);
199 /* Mark MAC IDs as used by clearing the available bit, and
200 * (below) mark TSFs as used if their existing use is not
201 * compatible with the new interface type.
202 * No locking or atomic bit operations are needed since the
203 * data is on the stack of the caller function.
205 __clear_bit(mvmvif
->id
, data
->available_mac_ids
);
207 /* find a suitable tsf_id */
208 iwl_mvm_mac_tsf_id_iter(_data
, mac
, vif
);
212 * Get the mask of the queus used by the vif
214 u32
iwl_mvm_mac_get_queues_mask(struct iwl_mvm
*mvm
,
215 struct ieee80211_vif
*vif
)
219 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
)
220 return BIT(IWL_MVM_OFFCHANNEL_QUEUE
);
222 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
223 if (vif
->hw_queue
[ac
] != IEEE80211_INVAL_HW_QUEUE
)
224 qmask
|= BIT(vif
->hw_queue
[ac
]);
229 void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm
*mvm
,
230 struct ieee80211_vif
*vif
)
232 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
233 struct iwl_mvm_mac_iface_iterator_data data
= {
236 .available_tsf_ids
= { (1 << NUM_TSF_IDS
) - 1 },
237 /* no preference yet */
238 .preferred_tsf
= NUM_TSF_IDS
,
241 ieee80211_iterate_active_interfaces_atomic(
242 mvm
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
243 iwl_mvm_mac_tsf_id_iter
, &data
);
245 if (data
.preferred_tsf
!= NUM_TSF_IDS
)
246 mvmvif
->tsf_id
= data
.preferred_tsf
;
247 else if (!test_bit(mvmvif
->tsf_id
, data
.available_tsf_ids
))
248 mvmvif
->tsf_id
= find_first_bit(data
.available_tsf_ids
,
252 static int iwl_mvm_mac_ctxt_allocate_resources(struct iwl_mvm
*mvm
,
253 struct ieee80211_vif
*vif
)
255 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
256 struct iwl_mvm_mac_iface_iterator_data data
= {
259 .available_mac_ids
= { (1 << NUM_MAC_INDEX_DRIVER
) - 1 },
260 .available_tsf_ids
= { (1 << NUM_TSF_IDS
) - 1 },
261 /* no preference yet */
262 .preferred_tsf
= NUM_TSF_IDS
,
264 BIT(IWL_MVM_OFFCHANNEL_QUEUE
) |
265 BIT(mvm
->aux_queue
) |
266 BIT(IWL_MVM_CMD_QUEUE
)
274 * Allocate a MAC ID and a TSF for this MAC, along with the queues
275 * and other resources.
279 * Before the iterator, we start with all MAC IDs and TSFs available.
281 * During iteration, all MAC IDs are cleared that are in use by other
282 * virtual interfaces, and all TSF IDs are cleared that can't be used
283 * by this new virtual interface because they're used by an interface
284 * that can't share it with the new one.
285 * At the same time, we check if there's a preferred TSF in the case
286 * that we should share it with another interface.
289 /* Currently, MAC ID 0 should be used only for the managed/IBSS vif */
291 case NL80211_IFTYPE_ADHOC
:
293 case NL80211_IFTYPE_STATION
:
298 __clear_bit(0, data
.available_mac_ids
);
301 ieee80211_iterate_active_interfaces_atomic(
302 mvm
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
303 iwl_mvm_mac_iface_iterator
, &data
);
306 * In the case we're getting here during resume, it's similar to
307 * firmware restart, and with RESUME_ALL the iterator will find
308 * the vif being added already.
309 * We don't want to reassign any IDs in either case since doing
310 * so would probably assign different IDs (as interfaces aren't
311 * necessarily added in the same order), but the old IDs were
312 * preserved anyway, so skip ID assignment for both resume and
318 /* Therefore, in recovery, we can't get here */
319 if (WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)))
322 mvmvif
->id
= find_first_bit(data
.available_mac_ids
,
323 NUM_MAC_INDEX_DRIVER
);
324 if (mvmvif
->id
== NUM_MAC_INDEX_DRIVER
) {
325 IWL_ERR(mvm
, "Failed to init MAC context - no free ID!\n");
330 if (data
.preferred_tsf
!= NUM_TSF_IDS
)
331 mvmvif
->tsf_id
= data
.preferred_tsf
;
333 mvmvif
->tsf_id
= find_first_bit(data
.available_tsf_ids
,
335 if (mvmvif
->tsf_id
== NUM_TSF_IDS
) {
336 IWL_ERR(mvm
, "Failed to init MAC context - no free TSF!\n");
343 INIT_LIST_HEAD(&mvmvif
->time_event_data
.list
);
344 mvmvif
->time_event_data
.id
= TE_MAX
;
346 /* No need to allocate data queues to P2P Device MAC.*/
347 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
348 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
349 vif
->hw_queue
[ac
] = IEEE80211_INVAL_HW_QUEUE
;
354 /* Find available queues, and allocate them to the ACs */
355 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
356 u8 queue
= find_first_zero_bit(data
.used_hw_queues
,
357 mvm
->first_agg_queue
);
359 if (queue
>= mvm
->first_agg_queue
) {
360 IWL_ERR(mvm
, "Failed to allocate queue\n");
365 __set_bit(queue
, data
.used_hw_queues
);
366 vif
->hw_queue
[ac
] = queue
;
369 /* Allocate the CAB queue for softAP and GO interfaces */
370 if (vif
->type
== NL80211_IFTYPE_AP
) {
371 u8 queue
= find_first_zero_bit(data
.used_hw_queues
,
372 mvm
->first_agg_queue
);
374 if (queue
>= mvm
->first_agg_queue
) {
375 IWL_ERR(mvm
, "Failed to allocate cab queue\n");
380 vif
->cab_queue
= queue
;
382 vif
->cab_queue
= IEEE80211_INVAL_HW_QUEUE
;
385 mvmvif
->bcast_sta
.sta_id
= IWL_MVM_STATION_COUNT
;
386 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
388 for (i
= 0; i
< NUM_IWL_MVM_SMPS_REQ
; i
++)
389 mvmvif
->smps_requests
[i
] = IEEE80211_SMPS_AUTOMATIC
;
394 memset(mvmvif
, 0, sizeof(struct iwl_mvm_vif
));
395 memset(vif
->hw_queue
, IEEE80211_INVAL_HW_QUEUE
, sizeof(vif
->hw_queue
));
396 vif
->cab_queue
= IEEE80211_INVAL_HW_QUEUE
;
400 int iwl_mvm_mac_ctxt_init(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
405 lockdep_assert_held(&mvm
->mutex
);
407 ret
= iwl_mvm_mac_ctxt_allocate_resources(mvm
, vif
);
412 case NL80211_IFTYPE_P2P_DEVICE
:
413 iwl_trans_ac_txq_enable(mvm
->trans
, IWL_MVM_OFFCHANNEL_QUEUE
,
416 case NL80211_IFTYPE_AP
:
417 iwl_trans_ac_txq_enable(mvm
->trans
, vif
->cab_queue
,
418 IWL_MVM_TX_FIFO_MCAST
);
421 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
422 iwl_trans_ac_txq_enable(mvm
->trans
, vif
->hw_queue
[ac
],
423 iwl_mvm_ac_to_tx_fifo
[ac
]);
430 void iwl_mvm_mac_ctxt_release(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
434 lockdep_assert_held(&mvm
->mutex
);
437 case NL80211_IFTYPE_P2P_DEVICE
:
438 iwl_trans_txq_disable(mvm
->trans
, IWL_MVM_OFFCHANNEL_QUEUE
);
440 case NL80211_IFTYPE_AP
:
441 iwl_trans_txq_disable(mvm
->trans
, vif
->cab_queue
);
444 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
445 iwl_trans_txq_disable(mvm
->trans
, vif
->hw_queue
[ac
]);
449 static void iwl_mvm_ack_rates(struct iwl_mvm
*mvm
,
450 struct ieee80211_vif
*vif
,
451 enum ieee80211_band band
,
452 u8
*cck_rates
, u8
*ofdm_rates
)
454 struct ieee80211_supported_band
*sband
;
455 unsigned long basic
= vif
->bss_conf
.basic_rates
;
456 int lowest_present_ofdm
= 100;
457 int lowest_present_cck
= 100;
462 sband
= mvm
->hw
->wiphy
->bands
[band
];
464 for_each_set_bit(i
, &basic
, BITS_PER_LONG
) {
465 int hw
= sband
->bitrates
[i
].hw_value
;
466 if (hw
>= IWL_FIRST_OFDM_RATE
) {
467 ofdm
|= BIT(hw
- IWL_FIRST_OFDM_RATE
);
468 if (lowest_present_ofdm
> hw
)
469 lowest_present_ofdm
= hw
;
471 BUILD_BUG_ON(IWL_FIRST_CCK_RATE
!= 0);
474 if (lowest_present_cck
> hw
)
475 lowest_present_cck
= hw
;
480 * Now we've got the basic rates as bitmaps in the ofdm and cck
481 * variables. This isn't sufficient though, as there might not
482 * be all the right rates in the bitmap. E.g. if the only basic
483 * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps
484 * and 6 Mbps because the 802.11-2007 standard says in 9.6:
486 * [...] a STA responding to a received frame shall transmit
487 * its Control Response frame [...] at the highest rate in the
488 * BSSBasicRateSet parameter that is less than or equal to the
489 * rate of the immediately previous frame in the frame exchange
490 * sequence ([...]) and that is of the same modulation class
491 * ([...]) as the received frame. If no rate contained in the
492 * BSSBasicRateSet parameter meets these conditions, then the
493 * control frame sent in response to a received frame shall be
494 * transmitted at the highest mandatory rate of the PHY that is
495 * less than or equal to the rate of the received frame, and
496 * that is of the same modulation class as the received frame.
498 * As a consequence, we need to add all mandatory rates that are
499 * lower than all of the basic rates to these bitmaps.
502 if (IWL_RATE_24M_INDEX
< lowest_present_ofdm
)
503 ofdm
|= IWL_RATE_BIT_MSK(24) >> IWL_FIRST_OFDM_RATE
;
504 if (IWL_RATE_12M_INDEX
< lowest_present_ofdm
)
505 ofdm
|= IWL_RATE_BIT_MSK(12) >> IWL_FIRST_OFDM_RATE
;
506 /* 6M already there or needed so always add */
507 ofdm
|= IWL_RATE_BIT_MSK(6) >> IWL_FIRST_OFDM_RATE
;
510 * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP.
512 * - if no CCK rates are basic, it must be ERP since there must
513 * be some basic rates at all, so they're OFDM => ERP PHY
514 * (or we're in 5 GHz, and the cck bitmap will never be used)
515 * - if 11M is a basic rate, it must be ERP as well, so add 5.5M
516 * - if 5.5M is basic, 1M and 2M are mandatory
517 * - if 2M is basic, 1M is mandatory
518 * - if 1M is basic, that's the only valid ACK rate.
519 * As a consequence, it's not as complicated as it sounds, just add
520 * any lower rates to the ACK rate bitmap.
522 if (IWL_RATE_11M_INDEX
< lowest_present_cck
)
523 cck
|= IWL_RATE_BIT_MSK(11) >> IWL_FIRST_CCK_RATE
;
524 if (IWL_RATE_5M_INDEX
< lowest_present_cck
)
525 cck
|= IWL_RATE_BIT_MSK(5) >> IWL_FIRST_CCK_RATE
;
526 if (IWL_RATE_2M_INDEX
< lowest_present_cck
)
527 cck
|= IWL_RATE_BIT_MSK(2) >> IWL_FIRST_CCK_RATE
;
528 /* 1M already there or needed so always add */
529 cck
|= IWL_RATE_BIT_MSK(1) >> IWL_FIRST_CCK_RATE
;
535 static void iwl_mvm_mac_ctxt_set_ht_flags(struct iwl_mvm
*mvm
,
536 struct ieee80211_vif
*vif
,
537 struct iwl_mac_ctx_cmd
*cmd
)
539 /* for both sta and ap, ht_operation_mode hold the protection_mode */
540 u8 protection_mode
= vif
->bss_conf
.ht_operation_mode
&
541 IEEE80211_HT_OP_MODE_PROTECTION
;
542 /* The fw does not distinguish between ht and fat */
543 u32 ht_flag
= MAC_PROT_FLG_HT_PROT
| MAC_PROT_FLG_FAT_PROT
;
545 IWL_DEBUG_RATE(mvm
, "protection mode set to %d\n", protection_mode
);
547 * See section 9.23.3.1 of IEEE 80211-2012.
548 * Nongreenfield HT STAs Present is not supported.
550 switch (protection_mode
) {
551 case IEEE80211_HT_OP_MODE_PROTECTION_NONE
:
553 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER
:
554 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
555 cmd
->protection_flags
|= cpu_to_le32(ht_flag
);
557 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
558 /* Protect when channel wider than 20MHz */
559 if (vif
->bss_conf
.chandef
.width
> NL80211_CHAN_WIDTH_20
)
560 cmd
->protection_flags
|= cpu_to_le32(ht_flag
);
563 IWL_ERR(mvm
, "Illegal protection mode %d\n",
569 static void iwl_mvm_mac_ctxt_cmd_common(struct iwl_mvm
*mvm
,
570 struct ieee80211_vif
*vif
,
571 struct iwl_mac_ctx_cmd
*cmd
,
574 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
575 struct ieee80211_chanctx_conf
*chanctx
;
576 bool ht_enabled
= !!(vif
->bss_conf
.ht_operation_mode
&
577 IEEE80211_HT_OP_MODE_PROTECTION
);
578 u8 cck_ack_rates
, ofdm_ack_rates
;
581 cmd
->id_and_color
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->id
,
583 cmd
->action
= cpu_to_le32(action
);
586 case NL80211_IFTYPE_STATION
:
588 cmd
->mac_type
= cpu_to_le32(FW_MAC_TYPE_P2P_STA
);
590 cmd
->mac_type
= cpu_to_le32(FW_MAC_TYPE_BSS_STA
);
592 case NL80211_IFTYPE_AP
:
593 cmd
->mac_type
= cpu_to_le32(FW_MAC_TYPE_GO
);
595 case NL80211_IFTYPE_MONITOR
:
596 cmd
->mac_type
= cpu_to_le32(FW_MAC_TYPE_LISTENER
);
598 case NL80211_IFTYPE_P2P_DEVICE
:
599 cmd
->mac_type
= cpu_to_le32(FW_MAC_TYPE_P2P_DEVICE
);
601 case NL80211_IFTYPE_ADHOC
:
602 cmd
->mac_type
= cpu_to_le32(FW_MAC_TYPE_IBSS
);
608 cmd
->tsf_id
= cpu_to_le32(mvmvif
->tsf_id
);
610 memcpy(cmd
->node_addr
, vif
->addr
, ETH_ALEN
);
611 if (vif
->bss_conf
.bssid
)
612 memcpy(cmd
->bssid_addr
, vif
->bss_conf
.bssid
, ETH_ALEN
);
614 eth_broadcast_addr(cmd
->bssid_addr
);
617 chanctx
= rcu_dereference(vif
->chanctx_conf
);
618 iwl_mvm_ack_rates(mvm
, vif
, chanctx
? chanctx
->def
.chan
->band
619 : IEEE80211_BAND_2GHZ
,
620 &cck_ack_rates
, &ofdm_ack_rates
);
623 cmd
->cck_rates
= cpu_to_le32((u32
)cck_ack_rates
);
624 cmd
->ofdm_rates
= cpu_to_le32((u32
)ofdm_ack_rates
);
626 cmd
->cck_short_preamble
=
627 cpu_to_le32(vif
->bss_conf
.use_short_preamble
?
628 MAC_FLG_SHORT_PREAMBLE
: 0);
630 cpu_to_le32(vif
->bss_conf
.use_short_slot
?
631 MAC_FLG_SHORT_SLOT
: 0);
633 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++) {
634 u8 txf
= iwl_mvm_ac_to_tx_fifo
[i
];
636 cmd
->ac
[txf
].cw_min
=
637 cpu_to_le16(mvmvif
->queue_params
[i
].cw_min
);
638 cmd
->ac
[txf
].cw_max
=
639 cpu_to_le16(mvmvif
->queue_params
[i
].cw_max
);
640 cmd
->ac
[txf
].edca_txop
=
641 cpu_to_le16(mvmvif
->queue_params
[i
].txop
* 32);
642 cmd
->ac
[txf
].aifsn
= mvmvif
->queue_params
[i
].aifs
;
643 cmd
->ac
[txf
].fifos_mask
= BIT(txf
);
646 /* in AP mode, the MCAST FIFO takes the EDCA params from VO */
647 if (vif
->type
== NL80211_IFTYPE_AP
)
648 cmd
->ac
[IWL_MVM_TX_FIFO_VO
].fifos_mask
|=
649 BIT(IWL_MVM_TX_FIFO_MCAST
);
651 if (vif
->bss_conf
.qos
)
652 cmd
->qos_flags
|= cpu_to_le32(MAC_QOS_FLG_UPDATE_EDCA
);
654 /* Don't use cts to self as the fw doesn't support it currently. */
655 if (vif
->bss_conf
.use_cts_prot
) {
656 cmd
->protection_flags
|= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT
);
657 if (IWL_UCODE_API(mvm
->fw
->ucode_ver
) >= 8)
658 cmd
->protection_flags
|=
659 cpu_to_le32(MAC_PROT_FLG_SELF_CTS_EN
);
661 IWL_DEBUG_RATE(mvm
, "use_cts_prot %d, ht_operation_mode %d\n",
662 vif
->bss_conf
.use_cts_prot
,
663 vif
->bss_conf
.ht_operation_mode
);
664 if (vif
->bss_conf
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
)
665 cmd
->qos_flags
|= cpu_to_le32(MAC_QOS_FLG_TGN
);
667 iwl_mvm_mac_ctxt_set_ht_flags(mvm
, vif
, cmd
);
669 cmd
->filter_flags
= cpu_to_le32(MAC_FILTER_ACCEPT_GRP
);
672 static int iwl_mvm_mac_ctxt_send_cmd(struct iwl_mvm
*mvm
,
673 struct iwl_mac_ctx_cmd
*cmd
)
675 int ret
= iwl_mvm_send_cmd_pdu(mvm
, MAC_CONTEXT_CMD
, CMD_SYNC
,
678 IWL_ERR(mvm
, "Failed to send MAC context (action:%d): %d\n",
679 le32_to_cpu(cmd
->action
), ret
);
684 * Fill the specific data for mac context of type station or p2p client
686 static void iwl_mvm_mac_ctxt_cmd_fill_sta(struct iwl_mvm
*mvm
,
687 struct ieee80211_vif
*vif
,
688 struct iwl_mac_data_sta
*ctxt_sta
,
689 bool force_assoc_off
)
691 /* We need the dtim_period to set the MAC as associated */
692 if (vif
->bss_conf
.assoc
&& vif
->bss_conf
.dtim_period
&&
697 * The DTIM count counts down, so when it is N that means N
698 * more beacon intervals happen until the DTIM TBTT. Therefore
699 * add this to the current time. If that ends up being in the
700 * future, the firmware will handle it.
702 * Also note that the system_timestamp (which we get here as
703 * "sync_device_ts") and TSF timestamp aren't at exactly the
704 * same offset in the frame -- the TSF is at the first symbol
705 * of the TSF, the system timestamp is at signal acquisition
706 * time. This means there's an offset between them of at most
707 * a few hundred microseconds (24 * 8 bits + PLCP time gives
708 * 384us in the longest case), this is currently not relevant
709 * as the firmware wakes up around 2ms before the TBTT.
711 dtim_offs
= vif
->bss_conf
.sync_dtim_count
*
712 vif
->bss_conf
.beacon_int
;
713 /* convert TU to usecs */
717 cpu_to_le64(vif
->bss_conf
.sync_tsf
+ dtim_offs
);
718 ctxt_sta
->dtim_time
=
719 cpu_to_le32(vif
->bss_conf
.sync_device_ts
+ dtim_offs
);
721 IWL_DEBUG_INFO(mvm
, "DTIM TBTT is 0x%llx/0x%x, offset %d\n",
722 le64_to_cpu(ctxt_sta
->dtim_tsf
),
723 le32_to_cpu(ctxt_sta
->dtim_time
),
726 ctxt_sta
->is_assoc
= cpu_to_le32(1);
728 ctxt_sta
->is_assoc
= cpu_to_le32(0);
731 ctxt_sta
->bi
= cpu_to_le32(vif
->bss_conf
.beacon_int
);
732 ctxt_sta
->bi_reciprocal
=
733 cpu_to_le32(iwl_mvm_reciprocal(vif
->bss_conf
.beacon_int
));
734 ctxt_sta
->dtim_interval
= cpu_to_le32(vif
->bss_conf
.beacon_int
*
735 vif
->bss_conf
.dtim_period
);
736 ctxt_sta
->dtim_reciprocal
=
737 cpu_to_le32(iwl_mvm_reciprocal(vif
->bss_conf
.beacon_int
*
738 vif
->bss_conf
.dtim_period
));
740 ctxt_sta
->listen_interval
= cpu_to_le32(mvm
->hw
->conf
.listen_interval
);
741 ctxt_sta
->assoc_id
= cpu_to_le32(vif
->bss_conf
.aid
);
744 static int iwl_mvm_mac_ctxt_cmd_station(struct iwl_mvm
*mvm
,
745 struct ieee80211_vif
*vif
,
748 struct iwl_mac_ctx_cmd cmd
= {};
750 WARN_ON(vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
);
752 /* Fill the common data for all mac context types */
753 iwl_mvm_mac_ctxt_cmd_common(mvm
, vif
, &cmd
, action
);
755 /* Allow beacons to pass through as long as we are not associated,or we
756 * do not have dtim period information */
757 if (!vif
->bss_conf
.assoc
|| !vif
->bss_conf
.dtim_period
)
758 cmd
.filter_flags
|= cpu_to_le32(MAC_FILTER_IN_BEACON
);
760 cmd
.filter_flags
&= ~cpu_to_le32(MAC_FILTER_IN_BEACON
);
762 /* Fill the data specific for station mode */
763 iwl_mvm_mac_ctxt_cmd_fill_sta(mvm
, vif
, &cmd
.sta
,
764 action
== FW_CTXT_ACTION_ADD
);
766 return iwl_mvm_mac_ctxt_send_cmd(mvm
, &cmd
);
769 static int iwl_mvm_mac_ctxt_cmd_p2p_client(struct iwl_mvm
*mvm
,
770 struct ieee80211_vif
*vif
,
773 struct iwl_mac_ctx_cmd cmd
= {};
774 struct ieee80211_p2p_noa_attr
*noa
= &vif
->bss_conf
.p2p_noa_attr
;
776 WARN_ON(vif
->type
!= NL80211_IFTYPE_STATION
|| !vif
->p2p
);
778 /* Fill the common data for all mac context types */
779 iwl_mvm_mac_ctxt_cmd_common(mvm
, vif
, &cmd
, action
);
781 /* Fill the data specific for station mode */
782 iwl_mvm_mac_ctxt_cmd_fill_sta(mvm
, vif
, &cmd
.p2p_sta
.sta
,
783 action
== FW_CTXT_ACTION_ADD
);
785 cmd
.p2p_sta
.ctwin
= cpu_to_le32(noa
->oppps_ctwindow
&
786 IEEE80211_P2P_OPPPS_CTWINDOW_MASK
);
788 return iwl_mvm_mac_ctxt_send_cmd(mvm
, &cmd
);
791 static int iwl_mvm_mac_ctxt_cmd_listener(struct iwl_mvm
*mvm
,
792 struct ieee80211_vif
*vif
,
795 struct iwl_mac_ctx_cmd cmd
= {};
797 WARN_ON(vif
->type
!= NL80211_IFTYPE_MONITOR
);
799 iwl_mvm_mac_ctxt_cmd_common(mvm
, vif
, &cmd
, action
);
801 cmd
.filter_flags
= cpu_to_le32(MAC_FILTER_IN_PROMISC
|
802 MAC_FILTER_IN_CONTROL_AND_MGMT
|
803 MAC_FILTER_IN_BEACON
|
804 MAC_FILTER_IN_PROBE_REQUEST
|
805 MAC_FILTER_IN_CRC32
);
806 mvm
->hw
->flags
|= IEEE80211_HW_RX_INCLUDES_FCS
;
808 return iwl_mvm_mac_ctxt_send_cmd(mvm
, &cmd
);
811 static int iwl_mvm_mac_ctxt_cmd_ibss(struct iwl_mvm
*mvm
,
812 struct ieee80211_vif
*vif
,
815 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
816 struct iwl_mac_ctx_cmd cmd
= {};
818 WARN_ON(vif
->type
!= NL80211_IFTYPE_ADHOC
);
820 iwl_mvm_mac_ctxt_cmd_common(mvm
, vif
, &cmd
, action
);
822 cmd
.filter_flags
= cpu_to_le32(MAC_FILTER_IN_BEACON
|
823 MAC_FILTER_IN_PROBE_REQUEST
);
825 /* cmd.ibss.beacon_time/cmd.ibss.beacon_tsf are curently ignored */
826 cmd
.ibss
.bi
= cpu_to_le32(vif
->bss_conf
.beacon_int
);
827 cmd
.ibss
.bi_reciprocal
=
828 cpu_to_le32(iwl_mvm_reciprocal(vif
->bss_conf
.beacon_int
));
830 /* TODO: Assumes that the beacon id == mac context id */
831 cmd
.ibss
.beacon_template
= cpu_to_le32(mvmvif
->id
);
833 return iwl_mvm_mac_ctxt_send_cmd(mvm
, &cmd
);
836 struct iwl_mvm_go_iterator_data
{
840 static void iwl_mvm_go_iterator(void *_data
, u8
*mac
, struct ieee80211_vif
*vif
)
842 struct iwl_mvm_go_iterator_data
*data
= _data
;
843 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
845 if (vif
->type
== NL80211_IFTYPE_AP
&& vif
->p2p
&&
846 mvmvif
->ap_ibss_active
)
847 data
->go_active
= true;
850 static int iwl_mvm_mac_ctxt_cmd_p2p_device(struct iwl_mvm
*mvm
,
851 struct ieee80211_vif
*vif
,
854 struct iwl_mac_ctx_cmd cmd
= {};
855 struct iwl_mvm_go_iterator_data data
= {};
857 WARN_ON(vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
);
859 iwl_mvm_mac_ctxt_cmd_common(mvm
, vif
, &cmd
, action
);
861 cmd
.protection_flags
|= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT
);
863 /* Override the filter flags to accept only probe requests */
864 cmd
.filter_flags
= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST
);
867 * This flag should be set to true when the P2P Device is
868 * discoverable and there is at least another active P2P GO. Settings
869 * this flag will allow the P2P Device to be discoverable on other
870 * channels in addition to its listen channel.
871 * Note that this flag should not be set in other cases as it opens the
872 * Rx filters on all MAC and increases the number of interrupts.
874 ieee80211_iterate_active_interfaces_atomic(
875 mvm
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
876 iwl_mvm_go_iterator
, &data
);
878 cmd
.p2p_dev
.is_disc_extended
= cpu_to_le32(data
.go_active
? 1 : 0);
879 return iwl_mvm_mac_ctxt_send_cmd(mvm
, &cmd
);
882 static void iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm
*mvm
,
883 struct iwl_mac_beacon_cmd
*beacon_cmd
,
884 u8
*beacon
, u32 frame_size
)
887 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*)beacon
;
889 /* The index is relative to frame start but we start looking at the
890 * variable-length part of the beacon. */
891 tim_idx
= mgmt
->u
.beacon
.variable
- beacon
;
893 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
894 while ((tim_idx
< (frame_size
- 2)) &&
895 (beacon
[tim_idx
] != WLAN_EID_TIM
))
896 tim_idx
+= beacon
[tim_idx
+1] + 2;
898 /* If TIM field was found, set variables */
899 if ((tim_idx
< (frame_size
- 1)) && (beacon
[tim_idx
] == WLAN_EID_TIM
)) {
900 beacon_cmd
->tim_idx
= cpu_to_le32(tim_idx
);
901 beacon_cmd
->tim_size
= cpu_to_le32((u32
)beacon
[tim_idx
+1]);
903 IWL_WARN(mvm
, "Unable to find TIM Element in beacon\n");
907 static int iwl_mvm_mac_ctxt_send_beacon(struct iwl_mvm
*mvm
,
908 struct ieee80211_vif
*vif
,
909 struct sk_buff
*beacon
)
911 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
912 struct iwl_host_cmd cmd
= {
913 .id
= BEACON_TEMPLATE_CMD
,
916 struct iwl_mac_beacon_cmd beacon_cmd
= {};
917 struct ieee80211_tx_info
*info
;
921 if (WARN_ON(!beacon
))
924 beacon_skb_len
= beacon
->len
;
926 /* TODO: for now the beacon template id is set to be the mac context id.
927 * Might be better to handle it as another resource ... */
928 beacon_cmd
.template_id
= cpu_to_le32((u32
)mvmvif
->id
);
930 /* Set up TX command fields */
931 beacon_cmd
.tx
.len
= cpu_to_le16((u16
)beacon_skb_len
);
932 beacon_cmd
.tx
.sta_id
= mvmvif
->bcast_sta
.sta_id
;
933 beacon_cmd
.tx
.life_time
= cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE
);
934 beacon_cmd
.tx
.tx_flags
= cpu_to_le32(TX_CMD_FLG_SEQ_CTL
|
938 mvm
->mgmt_last_antenna_idx
=
939 iwl_mvm_next_antenna(mvm
, iwl_fw_valid_tx_ant(mvm
->fw
),
940 mvm
->mgmt_last_antenna_idx
);
942 beacon_cmd
.tx
.rate_n_flags
=
943 cpu_to_le32(BIT(mvm
->mgmt_last_antenna_idx
) <<
946 info
= IEEE80211_SKB_CB(beacon
);
948 if (info
->band
== IEEE80211_BAND_5GHZ
|| vif
->p2p
) {
949 rate
= IWL_FIRST_OFDM_RATE
;
951 rate
= IWL_FIRST_CCK_RATE
;
952 beacon_cmd
.tx
.rate_n_flags
|= cpu_to_le32(RATE_MCS_CCK_MSK
);
954 beacon_cmd
.tx
.rate_n_flags
|=
955 cpu_to_le32(iwl_mvm_mac80211_idx_to_hwrate(rate
));
957 /* Set up TX beacon command fields */
958 if (vif
->type
== NL80211_IFTYPE_AP
)
959 iwl_mvm_mac_ctxt_set_tim(mvm
, &beacon_cmd
,
964 cmd
.len
[0] = sizeof(beacon_cmd
);
965 cmd
.data
[0] = &beacon_cmd
;
966 cmd
.dataflags
[0] = 0;
967 cmd
.len
[1] = beacon_skb_len
;
968 cmd
.data
[1] = beacon
->data
;
969 cmd
.dataflags
[1] = IWL_HCMD_DFL_DUP
;
971 return iwl_mvm_send_cmd(mvm
, &cmd
);
974 /* The beacon template for the AP/GO/IBSS has changed and needs update */
975 int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm
*mvm
,
976 struct ieee80211_vif
*vif
)
978 struct sk_buff
*beacon
;
981 WARN_ON(vif
->type
!= NL80211_IFTYPE_AP
&&
982 vif
->type
!= NL80211_IFTYPE_ADHOC
);
984 beacon
= ieee80211_beacon_get(mvm
->hw
, vif
);
988 ret
= iwl_mvm_mac_ctxt_send_beacon(mvm
, vif
, beacon
);
989 dev_kfree_skb(beacon
);
993 struct iwl_mvm_mac_ap_iterator_data
{
995 struct ieee80211_vif
*vif
;
996 u32 beacon_device_ts
;
1000 /* Find the beacon_device_ts and beacon_int for a managed interface */
1001 static void iwl_mvm_mac_ap_iterator(void *_data
, u8
*mac
,
1002 struct ieee80211_vif
*vif
)
1004 struct iwl_mvm_mac_ap_iterator_data
*data
= _data
;
1006 if (vif
->type
!= NL80211_IFTYPE_STATION
|| !vif
->bss_conf
.assoc
)
1009 /* Station client has higher priority over P2P client*/
1010 if (vif
->p2p
&& data
->beacon_device_ts
)
1013 data
->beacon_device_ts
= vif
->bss_conf
.sync_device_ts
;
1014 data
->beacon_int
= vif
->bss_conf
.beacon_int
;
1018 * Fill the specific data for mac context of type AP of P2P GO
1020 static void iwl_mvm_mac_ctxt_cmd_fill_ap(struct iwl_mvm
*mvm
,
1021 struct ieee80211_vif
*vif
,
1022 struct iwl_mac_data_ap
*ctxt_ap
,
1025 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1026 struct iwl_mvm_mac_ap_iterator_data data
= {
1029 .beacon_device_ts
= 0
1032 ctxt_ap
->bi
= cpu_to_le32(vif
->bss_conf
.beacon_int
);
1033 ctxt_ap
->bi_reciprocal
=
1034 cpu_to_le32(iwl_mvm_reciprocal(vif
->bss_conf
.beacon_int
));
1035 ctxt_ap
->dtim_interval
= cpu_to_le32(vif
->bss_conf
.beacon_int
*
1036 vif
->bss_conf
.dtim_period
);
1037 ctxt_ap
->dtim_reciprocal
=
1038 cpu_to_le32(iwl_mvm_reciprocal(vif
->bss_conf
.beacon_int
*
1039 vif
->bss_conf
.dtim_period
));
1041 ctxt_ap
->mcast_qid
= cpu_to_le32(vif
->cab_queue
);
1044 * Only set the beacon time when the MAC is being added, when we
1045 * just modify the MAC then we should keep the time -- the firmware
1046 * can otherwise have a "jumping" TBTT.
1050 * If there is a station/P2P client interface which is
1051 * associated, set the AP's TBTT far enough from the station's
1052 * TBTT. Otherwise, set it to the current system time
1054 ieee80211_iterate_active_interfaces_atomic(
1055 mvm
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
1056 iwl_mvm_mac_ap_iterator
, &data
);
1058 if (data
.beacon_device_ts
) {
1059 u32 rand
= (prandom_u32() % (64 - 36)) + 36;
1060 mvmvif
->ap_beacon_time
= data
.beacon_device_ts
+
1061 ieee80211_tu_to_usec(data
.beacon_int
* rand
/
1064 mvmvif
->ap_beacon_time
=
1065 iwl_read_prph(mvm
->trans
,
1066 DEVICE_SYSTEM_TIME_REG
);
1070 ctxt_ap
->beacon_time
= cpu_to_le32(mvmvif
->ap_beacon_time
);
1071 ctxt_ap
->beacon_tsf
= 0; /* unused */
1073 /* TODO: Assume that the beacon id == mac context id */
1074 ctxt_ap
->beacon_template
= cpu_to_le32(mvmvif
->id
);
1077 static int iwl_mvm_mac_ctxt_cmd_ap(struct iwl_mvm
*mvm
,
1078 struct ieee80211_vif
*vif
,
1081 struct iwl_mac_ctx_cmd cmd
= {};
1083 WARN_ON(vif
->type
!= NL80211_IFTYPE_AP
|| vif
->p2p
);
1085 /* Fill the common data for all mac context types */
1086 iwl_mvm_mac_ctxt_cmd_common(mvm
, vif
, &cmd
, action
);
1088 /* Also enable probe requests to pass */
1089 cmd
.filter_flags
|= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST
);
1091 /* Fill the data specific for ap mode */
1092 iwl_mvm_mac_ctxt_cmd_fill_ap(mvm
, vif
, &cmd
.ap
,
1093 action
== FW_CTXT_ACTION_ADD
);
1095 return iwl_mvm_mac_ctxt_send_cmd(mvm
, &cmd
);
1098 static int iwl_mvm_mac_ctxt_cmd_go(struct iwl_mvm
*mvm
,
1099 struct ieee80211_vif
*vif
,
1102 struct iwl_mac_ctx_cmd cmd
= {};
1103 struct ieee80211_p2p_noa_attr
*noa
= &vif
->bss_conf
.p2p_noa_attr
;
1105 WARN_ON(vif
->type
!= NL80211_IFTYPE_AP
|| !vif
->p2p
);
1107 /* Fill the common data for all mac context types */
1108 iwl_mvm_mac_ctxt_cmd_common(mvm
, vif
, &cmd
, action
);
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
,
1126 switch (vif
->type
) {
1127 case NL80211_IFTYPE_STATION
:
1129 return iwl_mvm_mac_ctxt_cmd_station(mvm
, vif
,
1132 return iwl_mvm_mac_ctxt_cmd_p2p_client(mvm
, vif
,
1135 case NL80211_IFTYPE_AP
:
1137 return iwl_mvm_mac_ctxt_cmd_ap(mvm
, vif
, action
);
1139 return iwl_mvm_mac_ctxt_cmd_go(mvm
, vif
, action
);
1141 case NL80211_IFTYPE_MONITOR
:
1142 return iwl_mvm_mac_ctxt_cmd_listener(mvm
, vif
, action
);
1143 case NL80211_IFTYPE_P2P_DEVICE
:
1144 return iwl_mvm_mac_ctxt_cmd_p2p_device(mvm
, vif
, action
);
1145 case NL80211_IFTYPE_ADHOC
:
1146 return iwl_mvm_mac_ctxt_cmd_ibss(mvm
, vif
, action
);
1154 int iwl_mvm_mac_ctxt_add(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1156 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1159 if (WARN_ONCE(mvmvif
->uploaded
, "Adding active MAC %pM/%d\n",
1160 vif
->addr
, ieee80211_vif_type_p2p(vif
)))
1163 ret
= iwl_mvm_mac_ctx_send(mvm
, vif
, FW_CTXT_ACTION_ADD
);
1167 /* will only do anything at resume from D3 time */
1168 iwl_mvm_set_last_nonqos_seq(mvm
, vif
);
1170 mvmvif
->uploaded
= true;
1174 int iwl_mvm_mac_ctxt_changed(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1176 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1178 if (WARN_ONCE(!mvmvif
->uploaded
, "Changing inactive MAC %pM/%d\n",
1179 vif
->addr
, ieee80211_vif_type_p2p(vif
)))
1182 return iwl_mvm_mac_ctx_send(mvm
, vif
, FW_CTXT_ACTION_MODIFY
);
1185 int iwl_mvm_mac_ctxt_remove(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1187 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1188 struct iwl_mac_ctx_cmd cmd
;
1191 if (WARN_ONCE(!mvmvif
->uploaded
, "Removing inactive MAC %pM/%d\n",
1192 vif
->addr
, ieee80211_vif_type_p2p(vif
)))
1195 memset(&cmd
, 0, sizeof(cmd
));
1197 cmd
.id_and_color
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->id
,
1199 cmd
.action
= cpu_to_le32(FW_CTXT_ACTION_REMOVE
);
1201 ret
= iwl_mvm_send_cmd_pdu(mvm
, MAC_CONTEXT_CMD
, CMD_SYNC
,
1204 IWL_ERR(mvm
, "Failed to remove MAC context: %d\n", ret
);
1208 mvmvif
->uploaded
= false;
1210 if (vif
->type
== NL80211_IFTYPE_MONITOR
)
1211 mvm
->hw
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
1216 int iwl_mvm_rx_beacon_notif(struct iwl_mvm
*mvm
,
1217 struct iwl_rx_cmd_buffer
*rxb
,
1218 struct iwl_device_cmd
*cmd
)
1220 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1221 struct iwl_beacon_notif
*beacon
= (void *)pkt
->data
;
1222 u16 status __maybe_unused
=
1223 le16_to_cpu(beacon
->beacon_notify_hdr
.status
.status
);
1224 u32 rate __maybe_unused
=
1225 le32_to_cpu(beacon
->beacon_notify_hdr
.initial_rate
);
1227 IWL_DEBUG_RX(mvm
, "beacon status %#x retries:%d tsf:0x%16llX rate:%d\n",
1228 status
& TX_STATUS_MSK
,
1229 beacon
->beacon_notify_hdr
.failure_frame
,
1230 le64_to_cpu(beacon
->tsf
),
1235 static void iwl_mvm_beacon_loss_iterator(void *_data
, u8
*mac
,
1236 struct ieee80211_vif
*vif
)
1238 struct iwl_missed_beacons_notif
*missed_beacons
= _data
;
1239 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1241 if (mvmvif
->id
!= (u16
)le32_to_cpu(missed_beacons
->mac_id
))
1245 * TODO: the threshold should be adjusted based on latency conditions,
1246 * and/or in case of a CS flow on one of the other AP vifs.
1248 if (le32_to_cpu(missed_beacons
->consec_missed_beacons_since_last_rx
) >
1249 IWL_MVM_MISSED_BEACONS_THRESHOLD
)
1250 ieee80211_beacon_loss(vif
);
1253 int iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm
*mvm
,
1254 struct iwl_rx_cmd_buffer
*rxb
,
1255 struct iwl_device_cmd
*cmd
)
1257 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1258 struct iwl_missed_beacons_notif
*mb
= (void *)pkt
->data
;
1261 "missed bcn mac_id=%u, consecutive=%u (%u, %u, %u)\n",
1262 le32_to_cpu(mb
->mac_id
),
1263 le32_to_cpu(mb
->consec_missed_beacons
),
1264 le32_to_cpu(mb
->consec_missed_beacons_since_last_rx
),
1265 le32_to_cpu(mb
->num_recvd_beacons
),
1266 le32_to_cpu(mb
->num_expected_beacons
));
1268 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
1269 IEEE80211_IFACE_ITER_NORMAL
,
1270 iwl_mvm_beacon_loss_iterator
,