1bfcc09ddSBjoern A. Zeeb // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2bfcc09ddSBjoern A. Zeeb /*
3a4128aadSBjoern A. Zeeb * Copyright (C) 2012-2014, 2018-2024 Intel Corporation
4bfcc09ddSBjoern A. Zeeb * Copyright (C) 2013-2014 Intel Mobile Communications GmbH
5bfcc09ddSBjoern A. Zeeb * Copyright (C) 2015-2017 Intel Deutschland GmbH
6bfcc09ddSBjoern A. Zeeb */
7bfcc09ddSBjoern A. Zeeb #include <linux/etherdevice.h>
8bfcc09ddSBjoern A. Zeeb #include <linux/crc32.h>
9bfcc09ddSBjoern A. Zeeb #include <net/mac80211.h>
10bfcc09ddSBjoern A. Zeeb #include "iwl-io.h"
11bfcc09ddSBjoern A. Zeeb #include "iwl-prph.h"
12bfcc09ddSBjoern A. Zeeb #include "fw-api.h"
13bfcc09ddSBjoern A. Zeeb #include "mvm.h"
14bfcc09ddSBjoern A. Zeeb #include "time-event.h"
15bfcc09ddSBjoern A. Zeeb
16bfcc09ddSBjoern A. Zeeb const u8 iwl_mvm_ac_to_tx_fifo[] = {
17bfcc09ddSBjoern A. Zeeb IWL_MVM_TX_FIFO_VO,
18bfcc09ddSBjoern A. Zeeb IWL_MVM_TX_FIFO_VI,
19bfcc09ddSBjoern A. Zeeb IWL_MVM_TX_FIFO_BE,
20bfcc09ddSBjoern A. Zeeb IWL_MVM_TX_FIFO_BK,
21bfcc09ddSBjoern A. Zeeb };
22bfcc09ddSBjoern A. Zeeb
23bfcc09ddSBjoern A. Zeeb const u8 iwl_mvm_ac_to_gen2_tx_fifo[] = {
24bfcc09ddSBjoern A. Zeeb IWL_GEN2_EDCA_TX_FIFO_VO,
25bfcc09ddSBjoern A. Zeeb IWL_GEN2_EDCA_TX_FIFO_VI,
26bfcc09ddSBjoern A. Zeeb IWL_GEN2_EDCA_TX_FIFO_BE,
27bfcc09ddSBjoern A. Zeeb IWL_GEN2_EDCA_TX_FIFO_BK,
28bfcc09ddSBjoern A. Zeeb IWL_GEN2_TRIG_TX_FIFO_VO,
29bfcc09ddSBjoern A. Zeeb IWL_GEN2_TRIG_TX_FIFO_VI,
30bfcc09ddSBjoern A. Zeeb IWL_GEN2_TRIG_TX_FIFO_BE,
31bfcc09ddSBjoern A. Zeeb IWL_GEN2_TRIG_TX_FIFO_BK,
32bfcc09ddSBjoern A. Zeeb };
33bfcc09ddSBjoern A. Zeeb
34a4128aadSBjoern A. Zeeb const u8 iwl_mvm_ac_to_bz_tx_fifo[] = {
35a4128aadSBjoern A. Zeeb IWL_BZ_EDCA_TX_FIFO_VO,
36a4128aadSBjoern A. Zeeb IWL_BZ_EDCA_TX_FIFO_VI,
37a4128aadSBjoern A. Zeeb IWL_BZ_EDCA_TX_FIFO_BE,
38a4128aadSBjoern A. Zeeb IWL_BZ_EDCA_TX_FIFO_BK,
39a4128aadSBjoern A. Zeeb IWL_BZ_TRIG_TX_FIFO_VO,
40a4128aadSBjoern A. Zeeb IWL_BZ_TRIG_TX_FIFO_VI,
41a4128aadSBjoern A. Zeeb IWL_BZ_TRIG_TX_FIFO_BE,
42a4128aadSBjoern A. Zeeb IWL_BZ_TRIG_TX_FIFO_BK,
43a4128aadSBjoern A. Zeeb };
44a4128aadSBjoern A. Zeeb
45bfcc09ddSBjoern A. Zeeb struct iwl_mvm_mac_iface_iterator_data {
46bfcc09ddSBjoern A. Zeeb struct iwl_mvm *mvm;
47bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif;
48bfcc09ddSBjoern A. Zeeb unsigned long available_mac_ids[BITS_TO_LONGS(NUM_MAC_INDEX_DRIVER)];
49bfcc09ddSBjoern A. Zeeb unsigned long available_tsf_ids[BITS_TO_LONGS(NUM_TSF_IDS)];
50bfcc09ddSBjoern A. Zeeb enum iwl_tsf_id preferred_tsf;
51bfcc09ddSBjoern A. Zeeb bool found_vif;
52bfcc09ddSBjoern A. Zeeb };
53bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_tsf_id_iter(void * _data,u8 * mac,struct ieee80211_vif * vif)54bfcc09ddSBjoern A. Zeeb static void iwl_mvm_mac_tsf_id_iter(void *_data, u8 *mac,
55bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif)
56bfcc09ddSBjoern A. Zeeb {
57bfcc09ddSBjoern A. Zeeb struct iwl_mvm_mac_iface_iterator_data *data = _data;
58bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
59bfcc09ddSBjoern A. Zeeb u16 min_bi;
60bfcc09ddSBjoern A. Zeeb
61bfcc09ddSBjoern A. Zeeb /* Skip the interface for which we are trying to assign a tsf_id */
62bfcc09ddSBjoern A. Zeeb if (vif == data->vif)
63bfcc09ddSBjoern A. Zeeb return;
64bfcc09ddSBjoern A. Zeeb
65bfcc09ddSBjoern A. Zeeb /*
66bfcc09ddSBjoern A. Zeeb * The TSF is a hardware/firmware resource, there are 4 and
67bfcc09ddSBjoern A. Zeeb * the driver should assign and free them as needed. However,
68bfcc09ddSBjoern A. Zeeb * there are cases where 2 MACs should share the same TSF ID
69bfcc09ddSBjoern A. Zeeb * for the purpose of clock sync, an optimization to avoid
70bfcc09ddSBjoern A. Zeeb * clock drift causing overlapping TBTTs/DTIMs for a GO and
71bfcc09ddSBjoern A. Zeeb * client in the system.
72bfcc09ddSBjoern A. Zeeb *
73bfcc09ddSBjoern A. Zeeb * The firmware will decide according to the MAC type which
74bfcc09ddSBjoern A. Zeeb * will be the leader and follower. Clients that need to sync
75bfcc09ddSBjoern A. Zeeb * with a remote station will be the leader, and an AP or GO
76bfcc09ddSBjoern A. Zeeb * will be the follower.
77bfcc09ddSBjoern A. Zeeb *
78bfcc09ddSBjoern A. Zeeb * Depending on the new interface type it can be following
79bfcc09ddSBjoern A. Zeeb * or become the leader of an existing interface.
80bfcc09ddSBjoern A. Zeeb */
81bfcc09ddSBjoern A. Zeeb switch (data->vif->type) {
82bfcc09ddSBjoern A. Zeeb case NL80211_IFTYPE_STATION:
83bfcc09ddSBjoern A. Zeeb /*
84bfcc09ddSBjoern A. Zeeb * The new interface is a client, so if the one we're iterating
85bfcc09ddSBjoern A. Zeeb * is an AP, and the beacon interval of the AP is a multiple or
86bfcc09ddSBjoern A. Zeeb * divisor of the beacon interval of the client, the same TSF
87bfcc09ddSBjoern A. Zeeb * should be used to avoid drift between the new client and
88bfcc09ddSBjoern A. Zeeb * existing AP. The existing AP will get drift updates from the
89bfcc09ddSBjoern A. Zeeb * new client context in this case.
90bfcc09ddSBjoern A. Zeeb */
91bfcc09ddSBjoern A. Zeeb if (vif->type != NL80211_IFTYPE_AP ||
92bfcc09ddSBjoern A. Zeeb data->preferred_tsf != NUM_TSF_IDS ||
93bfcc09ddSBjoern A. Zeeb !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
94bfcc09ddSBjoern A. Zeeb break;
95bfcc09ddSBjoern A. Zeeb
96bfcc09ddSBjoern A. Zeeb min_bi = min(data->vif->bss_conf.beacon_int,
97bfcc09ddSBjoern A. Zeeb vif->bss_conf.beacon_int);
98bfcc09ddSBjoern A. Zeeb
99bfcc09ddSBjoern A. Zeeb if (!min_bi)
100bfcc09ddSBjoern A. Zeeb break;
101bfcc09ddSBjoern A. Zeeb
102bfcc09ddSBjoern A. Zeeb if ((data->vif->bss_conf.beacon_int -
103bfcc09ddSBjoern A. Zeeb vif->bss_conf.beacon_int) % min_bi == 0) {
104bfcc09ddSBjoern A. Zeeb data->preferred_tsf = mvmvif->tsf_id;
105bfcc09ddSBjoern A. Zeeb return;
106bfcc09ddSBjoern A. Zeeb }
107bfcc09ddSBjoern A. Zeeb break;
108bfcc09ddSBjoern A. Zeeb
109bfcc09ddSBjoern A. Zeeb case NL80211_IFTYPE_AP:
110bfcc09ddSBjoern A. Zeeb /*
111bfcc09ddSBjoern A. Zeeb * The new interface is AP/GO, so if its beacon interval is a
112bfcc09ddSBjoern A. Zeeb * multiple or a divisor of the beacon interval of an existing
113bfcc09ddSBjoern A. Zeeb * interface, it should get drift updates from an existing
114bfcc09ddSBjoern A. Zeeb * client or use the same TSF as an existing GO. There's no
115bfcc09ddSBjoern A. Zeeb * drift between TSFs internally but if they used different
116bfcc09ddSBjoern A. Zeeb * TSFs then a new client MAC could update one of them and
117bfcc09ddSBjoern A. Zeeb * cause drift that way.
118bfcc09ddSBjoern A. Zeeb */
119bfcc09ddSBjoern A. Zeeb if ((vif->type != NL80211_IFTYPE_AP &&
120bfcc09ddSBjoern A. Zeeb vif->type != NL80211_IFTYPE_STATION) ||
121bfcc09ddSBjoern A. Zeeb data->preferred_tsf != NUM_TSF_IDS ||
122bfcc09ddSBjoern A. Zeeb !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
123bfcc09ddSBjoern A. Zeeb break;
124bfcc09ddSBjoern A. Zeeb
125bfcc09ddSBjoern A. Zeeb min_bi = min(data->vif->bss_conf.beacon_int,
126bfcc09ddSBjoern A. Zeeb vif->bss_conf.beacon_int);
127bfcc09ddSBjoern A. Zeeb
128bfcc09ddSBjoern A. Zeeb if (!min_bi)
129bfcc09ddSBjoern A. Zeeb break;
130bfcc09ddSBjoern A. Zeeb
131bfcc09ddSBjoern A. Zeeb if ((data->vif->bss_conf.beacon_int -
132bfcc09ddSBjoern A. Zeeb vif->bss_conf.beacon_int) % min_bi == 0) {
133bfcc09ddSBjoern A. Zeeb data->preferred_tsf = mvmvif->tsf_id;
134bfcc09ddSBjoern A. Zeeb return;
135bfcc09ddSBjoern A. Zeeb }
136bfcc09ddSBjoern A. Zeeb break;
137bfcc09ddSBjoern A. Zeeb default:
138bfcc09ddSBjoern A. Zeeb /*
139bfcc09ddSBjoern A. Zeeb * For all other interface types there's no need to
140bfcc09ddSBjoern A. Zeeb * take drift into account. Either they're exclusive
141bfcc09ddSBjoern A. Zeeb * like IBSS and monitor, or we don't care much about
142bfcc09ddSBjoern A. Zeeb * their TSF (like P2P Device), but we won't be able
143bfcc09ddSBjoern A. Zeeb * to share the TSF resource.
144bfcc09ddSBjoern A. Zeeb */
145bfcc09ddSBjoern A. Zeeb break;
146bfcc09ddSBjoern A. Zeeb }
147bfcc09ddSBjoern A. Zeeb
148bfcc09ddSBjoern A. Zeeb /*
149bfcc09ddSBjoern A. Zeeb * Unless we exited above, we can't share the TSF resource
150bfcc09ddSBjoern A. Zeeb * that the virtual interface we're iterating over is using
151bfcc09ddSBjoern A. Zeeb * with the new one, so clear the available bit and if this
152bfcc09ddSBjoern A. Zeeb * was the preferred one, reset that as well.
153bfcc09ddSBjoern A. Zeeb */
154bfcc09ddSBjoern A. Zeeb __clear_bit(mvmvif->tsf_id, data->available_tsf_ids);
155bfcc09ddSBjoern A. Zeeb
156bfcc09ddSBjoern A. Zeeb if (data->preferred_tsf == mvmvif->tsf_id)
157bfcc09ddSBjoern A. Zeeb data->preferred_tsf = NUM_TSF_IDS;
158bfcc09ddSBjoern A. Zeeb }
159bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_iface_iterator(void * _data,u8 * mac,struct ieee80211_vif * vif)160bfcc09ddSBjoern A. Zeeb static void iwl_mvm_mac_iface_iterator(void *_data, u8 *mac,
161bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif)
162bfcc09ddSBjoern A. Zeeb {
163bfcc09ddSBjoern A. Zeeb struct iwl_mvm_mac_iface_iterator_data *data = _data;
164bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
165bfcc09ddSBjoern A. Zeeb
166bfcc09ddSBjoern A. Zeeb /* Iterator may already find the interface being added -- skip it */
167bfcc09ddSBjoern A. Zeeb if (vif == data->vif) {
168bfcc09ddSBjoern A. Zeeb data->found_vif = true;
169bfcc09ddSBjoern A. Zeeb return;
170bfcc09ddSBjoern A. Zeeb }
171bfcc09ddSBjoern A. Zeeb
172bfcc09ddSBjoern A. Zeeb /* Mark MAC IDs as used by clearing the available bit, and
173bfcc09ddSBjoern A. Zeeb * (below) mark TSFs as used if their existing use is not
174bfcc09ddSBjoern A. Zeeb * compatible with the new interface type.
175bfcc09ddSBjoern A. Zeeb * No locking or atomic bit operations are needed since the
176bfcc09ddSBjoern A. Zeeb * data is on the stack of the caller function.
177bfcc09ddSBjoern A. Zeeb */
178bfcc09ddSBjoern A. Zeeb __clear_bit(mvmvif->id, data->available_mac_ids);
179bfcc09ddSBjoern A. Zeeb
180bfcc09ddSBjoern A. Zeeb /* find a suitable tsf_id */
181bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_tsf_id_iter(_data, mac, vif);
182bfcc09ddSBjoern A. Zeeb }
183bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm * mvm,struct ieee80211_vif * vif)184bfcc09ddSBjoern A. Zeeb void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm *mvm,
185bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif)
186bfcc09ddSBjoern A. Zeeb {
187bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
188bfcc09ddSBjoern A. Zeeb struct iwl_mvm_mac_iface_iterator_data data = {
189bfcc09ddSBjoern A. Zeeb .mvm = mvm,
190bfcc09ddSBjoern A. Zeeb .vif = vif,
191bfcc09ddSBjoern A. Zeeb .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
192bfcc09ddSBjoern A. Zeeb /* no preference yet */
193bfcc09ddSBjoern A. Zeeb .preferred_tsf = NUM_TSF_IDS,
194bfcc09ddSBjoern A. Zeeb };
195bfcc09ddSBjoern A. Zeeb
196bfcc09ddSBjoern A. Zeeb ieee80211_iterate_active_interfaces_atomic(
197bfcc09ddSBjoern A. Zeeb mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
198bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_tsf_id_iter, &data);
199bfcc09ddSBjoern A. Zeeb
200bfcc09ddSBjoern A. Zeeb if (data.preferred_tsf != NUM_TSF_IDS)
201bfcc09ddSBjoern A. Zeeb mvmvif->tsf_id = data.preferred_tsf;
202bfcc09ddSBjoern A. Zeeb else if (!test_bit(mvmvif->tsf_id, data.available_tsf_ids))
203bfcc09ddSBjoern A. Zeeb mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
204bfcc09ddSBjoern A. Zeeb NUM_TSF_IDS);
205bfcc09ddSBjoern A. Zeeb }
206bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_init(struct iwl_mvm * mvm,struct ieee80211_vif * vif)207bfcc09ddSBjoern A. Zeeb int iwl_mvm_mac_ctxt_init(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
208bfcc09ddSBjoern A. Zeeb {
209bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
210bfcc09ddSBjoern A. Zeeb struct iwl_mvm_mac_iface_iterator_data data = {
211bfcc09ddSBjoern A. Zeeb .mvm = mvm,
212bfcc09ddSBjoern A. Zeeb .vif = vif,
213bfcc09ddSBjoern A. Zeeb .available_mac_ids = { (1 << NUM_MAC_INDEX_DRIVER) - 1 },
214bfcc09ddSBjoern A. Zeeb .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
215bfcc09ddSBjoern A. Zeeb /* no preference yet */
216bfcc09ddSBjoern A. Zeeb .preferred_tsf = NUM_TSF_IDS,
217bfcc09ddSBjoern A. Zeeb .found_vif = false,
218bfcc09ddSBjoern A. Zeeb };
219bfcc09ddSBjoern A. Zeeb int ret, i;
220bfcc09ddSBjoern A. Zeeb
221bfcc09ddSBjoern A. Zeeb lockdep_assert_held(&mvm->mutex);
222bfcc09ddSBjoern A. Zeeb
223bfcc09ddSBjoern A. Zeeb /*
224bfcc09ddSBjoern A. Zeeb * Allocate a MAC ID and a TSF for this MAC, along with the queues
225bfcc09ddSBjoern A. Zeeb * and other resources.
226bfcc09ddSBjoern A. Zeeb */
227bfcc09ddSBjoern A. Zeeb
228bfcc09ddSBjoern A. Zeeb /*
229bfcc09ddSBjoern A. Zeeb * Before the iterator, we start with all MAC IDs and TSFs available.
230bfcc09ddSBjoern A. Zeeb *
231bfcc09ddSBjoern A. Zeeb * During iteration, all MAC IDs are cleared that are in use by other
232bfcc09ddSBjoern A. Zeeb * virtual interfaces, and all TSF IDs are cleared that can't be used
233bfcc09ddSBjoern A. Zeeb * by this new virtual interface because they're used by an interface
234bfcc09ddSBjoern A. Zeeb * that can't share it with the new one.
235bfcc09ddSBjoern A. Zeeb * At the same time, we check if there's a preferred TSF in the case
236bfcc09ddSBjoern A. Zeeb * that we should share it with another interface.
237bfcc09ddSBjoern A. Zeeb */
238bfcc09ddSBjoern A. Zeeb
2399af1bba4SBjoern A. Zeeb /* MAC ID 0 should be used only for the managed/IBSS vif with non-MLO
2409af1bba4SBjoern A. Zeeb * FW API
2419af1bba4SBjoern A. Zeeb */
2429af1bba4SBjoern A. Zeeb if (!mvm->mld_api_is_used) {
243bfcc09ddSBjoern A. Zeeb switch (vif->type) {
244bfcc09ddSBjoern A. Zeeb case NL80211_IFTYPE_ADHOC:
245bfcc09ddSBjoern A. Zeeb break;
246bfcc09ddSBjoern A. Zeeb case NL80211_IFTYPE_STATION:
247bfcc09ddSBjoern A. Zeeb if (!vif->p2p)
248bfcc09ddSBjoern A. Zeeb break;
249bfcc09ddSBjoern A. Zeeb fallthrough;
250bfcc09ddSBjoern A. Zeeb default:
251bfcc09ddSBjoern A. Zeeb __clear_bit(0, data.available_mac_ids);
252bfcc09ddSBjoern A. Zeeb }
2539af1bba4SBjoern A. Zeeb }
254bfcc09ddSBjoern A. Zeeb
255bfcc09ddSBjoern A. Zeeb ieee80211_iterate_active_interfaces_atomic(
256bfcc09ddSBjoern A. Zeeb mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
257bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_iface_iterator, &data);
258bfcc09ddSBjoern A. Zeeb
259bfcc09ddSBjoern A. Zeeb /*
260bfcc09ddSBjoern A. Zeeb * In the case we're getting here during resume, it's similar to
261bfcc09ddSBjoern A. Zeeb * firmware restart, and with RESUME_ALL the iterator will find
262bfcc09ddSBjoern A. Zeeb * the vif being added already.
263bfcc09ddSBjoern A. Zeeb * We don't want to reassign any IDs in either case since doing
264bfcc09ddSBjoern A. Zeeb * so would probably assign different IDs (as interfaces aren't
265bfcc09ddSBjoern A. Zeeb * necessarily added in the same order), but the old IDs were
266bfcc09ddSBjoern A. Zeeb * preserved anyway, so skip ID assignment for both resume and
267bfcc09ddSBjoern A. Zeeb * recovery.
268bfcc09ddSBjoern A. Zeeb */
269bfcc09ddSBjoern A. Zeeb if (data.found_vif)
270bfcc09ddSBjoern A. Zeeb return 0;
271bfcc09ddSBjoern A. Zeeb
272bfcc09ddSBjoern A. Zeeb /* Therefore, in recovery, we can't get here */
273bfcc09ddSBjoern A. Zeeb if (WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
274bfcc09ddSBjoern A. Zeeb return -EBUSY;
275bfcc09ddSBjoern A. Zeeb
276bfcc09ddSBjoern A. Zeeb mvmvif->id = find_first_bit(data.available_mac_ids,
277bfcc09ddSBjoern A. Zeeb NUM_MAC_INDEX_DRIVER);
278bfcc09ddSBjoern A. Zeeb if (mvmvif->id == NUM_MAC_INDEX_DRIVER) {
279bfcc09ddSBjoern A. Zeeb IWL_ERR(mvm, "Failed to init MAC context - no free ID!\n");
280bfcc09ddSBjoern A. Zeeb ret = -EIO;
281bfcc09ddSBjoern A. Zeeb goto exit_fail;
282bfcc09ddSBjoern A. Zeeb }
283bfcc09ddSBjoern A. Zeeb
284bfcc09ddSBjoern A. Zeeb if (data.preferred_tsf != NUM_TSF_IDS)
285bfcc09ddSBjoern A. Zeeb mvmvif->tsf_id = data.preferred_tsf;
286bfcc09ddSBjoern A. Zeeb else
287bfcc09ddSBjoern A. Zeeb mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
288bfcc09ddSBjoern A. Zeeb NUM_TSF_IDS);
289bfcc09ddSBjoern A. Zeeb if (mvmvif->tsf_id == NUM_TSF_IDS) {
290bfcc09ddSBjoern A. Zeeb IWL_ERR(mvm, "Failed to init MAC context - no free TSF!\n");
291bfcc09ddSBjoern A. Zeeb ret = -EIO;
292bfcc09ddSBjoern A. Zeeb goto exit_fail;
293bfcc09ddSBjoern A. Zeeb }
294bfcc09ddSBjoern A. Zeeb
295bfcc09ddSBjoern A. Zeeb mvmvif->color = 0;
296bfcc09ddSBjoern A. Zeeb
297bfcc09ddSBjoern A. Zeeb INIT_LIST_HEAD(&mvmvif->time_event_data.list);
298bfcc09ddSBjoern A. Zeeb mvmvif->time_event_data.id = TE_MAX;
299a4128aadSBjoern A. Zeeb mvmvif->roc_activity = ROC_NUM_ACTIVITIES;
300a4128aadSBjoern A. Zeeb
301a4128aadSBjoern A. Zeeb mvmvif->deflink.bcast_sta.sta_id = IWL_MVM_INVALID_STA;
302a4128aadSBjoern A. Zeeb mvmvif->deflink.mcast_sta.sta_id = IWL_MVM_INVALID_STA;
303a4128aadSBjoern A. Zeeb mvmvif->deflink.ap_sta_id = IWL_MVM_INVALID_STA;
304bfcc09ddSBjoern A. Zeeb
305bfcc09ddSBjoern A. Zeeb /* No need to allocate data queues to P2P Device MAC and NAN.*/
306bfcc09ddSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
307bfcc09ddSBjoern A. Zeeb return 0;
308bfcc09ddSBjoern A. Zeeb
309bfcc09ddSBjoern A. Zeeb /* Allocate the CAB queue for softAP and GO interfaces */
310bfcc09ddSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_AP ||
311bfcc09ddSBjoern A. Zeeb vif->type == NL80211_IFTYPE_ADHOC) {
312bfcc09ddSBjoern A. Zeeb /*
313bfcc09ddSBjoern A. Zeeb * For TVQM this will be overwritten later with the FW assigned
314bfcc09ddSBjoern A. Zeeb * queue value (when queue is enabled).
315bfcc09ddSBjoern A. Zeeb */
3169af1bba4SBjoern A. Zeeb mvmvif->deflink.cab_queue = IWL_MVM_DQA_GCAST_QUEUE;
317bfcc09ddSBjoern A. Zeeb }
318bfcc09ddSBjoern A. Zeeb
319bfcc09ddSBjoern A. Zeeb for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++)
3209af1bba4SBjoern A. Zeeb mvmvif->deflink.smps_requests[i] = IEEE80211_SMPS_AUTOMATIC;
321bfcc09ddSBjoern A. Zeeb
322bfcc09ddSBjoern A. Zeeb return 0;
323bfcc09ddSBjoern A. Zeeb
324bfcc09ddSBjoern A. Zeeb exit_fail:
325bfcc09ddSBjoern A. Zeeb memset(mvmvif, 0, sizeof(struct iwl_mvm_vif));
326bfcc09ddSBjoern A. Zeeb return ret;
327bfcc09ddSBjoern A. Zeeb }
328bfcc09ddSBjoern A. Zeeb
iwl_mvm_ack_rates(struct iwl_mvm * mvm,struct ieee80211_vif * vif,enum nl80211_band band,u8 * cck_rates,u8 * ofdm_rates)329bfcc09ddSBjoern A. Zeeb static void iwl_mvm_ack_rates(struct iwl_mvm *mvm,
330bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif,
331bfcc09ddSBjoern A. Zeeb enum nl80211_band band,
332bfcc09ddSBjoern A. Zeeb u8 *cck_rates, u8 *ofdm_rates)
333bfcc09ddSBjoern A. Zeeb {
334bfcc09ddSBjoern A. Zeeb struct ieee80211_supported_band *sband;
335bfcc09ddSBjoern A. Zeeb unsigned long basic = vif->bss_conf.basic_rates;
336bfcc09ddSBjoern A. Zeeb int lowest_present_ofdm = 100;
337bfcc09ddSBjoern A. Zeeb int lowest_present_cck = 100;
338bfcc09ddSBjoern A. Zeeb u8 cck = 0;
339bfcc09ddSBjoern A. Zeeb u8 ofdm = 0;
340bfcc09ddSBjoern A. Zeeb int i;
341bfcc09ddSBjoern A. Zeeb
342bfcc09ddSBjoern A. Zeeb sband = mvm->hw->wiphy->bands[band];
343bfcc09ddSBjoern A. Zeeb
344bfcc09ddSBjoern A. Zeeb for_each_set_bit(i, &basic, BITS_PER_LONG) {
345bfcc09ddSBjoern A. Zeeb int hw = sband->bitrates[i].hw_value;
346bfcc09ddSBjoern A. Zeeb if (hw >= IWL_FIRST_OFDM_RATE) {
347bfcc09ddSBjoern A. Zeeb ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE);
348bfcc09ddSBjoern A. Zeeb if (lowest_present_ofdm > hw)
349bfcc09ddSBjoern A. Zeeb lowest_present_ofdm = hw;
350bfcc09ddSBjoern A. Zeeb } else {
351bfcc09ddSBjoern A. Zeeb BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
352bfcc09ddSBjoern A. Zeeb
353bfcc09ddSBjoern A. Zeeb cck |= BIT(hw);
354bfcc09ddSBjoern A. Zeeb if (lowest_present_cck > hw)
355bfcc09ddSBjoern A. Zeeb lowest_present_cck = hw;
356bfcc09ddSBjoern A. Zeeb }
357bfcc09ddSBjoern A. Zeeb }
358bfcc09ddSBjoern A. Zeeb
359bfcc09ddSBjoern A. Zeeb /*
360bfcc09ddSBjoern A. Zeeb * Now we've got the basic rates as bitmaps in the ofdm and cck
361bfcc09ddSBjoern A. Zeeb * variables. This isn't sufficient though, as there might not
362bfcc09ddSBjoern A. Zeeb * be all the right rates in the bitmap. E.g. if the only basic
363bfcc09ddSBjoern A. Zeeb * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps
364bfcc09ddSBjoern A. Zeeb * and 6 Mbps because the 802.11-2007 standard says in 9.6:
365bfcc09ddSBjoern A. Zeeb *
366bfcc09ddSBjoern A. Zeeb * [...] a STA responding to a received frame shall transmit
367bfcc09ddSBjoern A. Zeeb * its Control Response frame [...] at the highest rate in the
368bfcc09ddSBjoern A. Zeeb * BSSBasicRateSet parameter that is less than or equal to the
369bfcc09ddSBjoern A. Zeeb * rate of the immediately previous frame in the frame exchange
370bfcc09ddSBjoern A. Zeeb * sequence ([...]) and that is of the same modulation class
371bfcc09ddSBjoern A. Zeeb * ([...]) as the received frame. If no rate contained in the
372bfcc09ddSBjoern A. Zeeb * BSSBasicRateSet parameter meets these conditions, then the
373bfcc09ddSBjoern A. Zeeb * control frame sent in response to a received frame shall be
374bfcc09ddSBjoern A. Zeeb * transmitted at the highest mandatory rate of the PHY that is
375bfcc09ddSBjoern A. Zeeb * less than or equal to the rate of the received frame, and
376bfcc09ddSBjoern A. Zeeb * that is of the same modulation class as the received frame.
377bfcc09ddSBjoern A. Zeeb *
378bfcc09ddSBjoern A. Zeeb * As a consequence, we need to add all mandatory rates that are
379bfcc09ddSBjoern A. Zeeb * lower than all of the basic rates to these bitmaps.
380bfcc09ddSBjoern A. Zeeb */
381bfcc09ddSBjoern A. Zeeb
382bfcc09ddSBjoern A. Zeeb if (IWL_RATE_24M_INDEX < lowest_present_ofdm)
383bfcc09ddSBjoern A. Zeeb ofdm |= IWL_RATE_BIT_MSK(24) >> IWL_FIRST_OFDM_RATE;
384bfcc09ddSBjoern A. Zeeb if (IWL_RATE_12M_INDEX < lowest_present_ofdm)
385bfcc09ddSBjoern A. Zeeb ofdm |= IWL_RATE_BIT_MSK(12) >> IWL_FIRST_OFDM_RATE;
386bfcc09ddSBjoern A. Zeeb /* 6M already there or needed so always add */
387bfcc09ddSBjoern A. Zeeb ofdm |= IWL_RATE_BIT_MSK(6) >> IWL_FIRST_OFDM_RATE;
388bfcc09ddSBjoern A. Zeeb
389bfcc09ddSBjoern A. Zeeb /*
390bfcc09ddSBjoern A. Zeeb * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP.
391bfcc09ddSBjoern A. Zeeb * Note, however:
392bfcc09ddSBjoern A. Zeeb * - if no CCK rates are basic, it must be ERP since there must
393bfcc09ddSBjoern A. Zeeb * be some basic rates at all, so they're OFDM => ERP PHY
394bfcc09ddSBjoern A. Zeeb * (or we're in 5 GHz, and the cck bitmap will never be used)
395bfcc09ddSBjoern A. Zeeb * - if 11M is a basic rate, it must be ERP as well, so add 5.5M
396bfcc09ddSBjoern A. Zeeb * - if 5.5M is basic, 1M and 2M are mandatory
397bfcc09ddSBjoern A. Zeeb * - if 2M is basic, 1M is mandatory
398bfcc09ddSBjoern A. Zeeb * - if 1M is basic, that's the only valid ACK rate.
399bfcc09ddSBjoern A. Zeeb * As a consequence, it's not as complicated as it sounds, just add
400bfcc09ddSBjoern A. Zeeb * any lower rates to the ACK rate bitmap.
401bfcc09ddSBjoern A. Zeeb */
402bfcc09ddSBjoern A. Zeeb if (IWL_RATE_11M_INDEX < lowest_present_cck)
403bfcc09ddSBjoern A. Zeeb cck |= IWL_RATE_BIT_MSK(11) >> IWL_FIRST_CCK_RATE;
404bfcc09ddSBjoern A. Zeeb if (IWL_RATE_5M_INDEX < lowest_present_cck)
405bfcc09ddSBjoern A. Zeeb cck |= IWL_RATE_BIT_MSK(5) >> IWL_FIRST_CCK_RATE;
406bfcc09ddSBjoern A. Zeeb if (IWL_RATE_2M_INDEX < lowest_present_cck)
407bfcc09ddSBjoern A. Zeeb cck |= IWL_RATE_BIT_MSK(2) >> IWL_FIRST_CCK_RATE;
408bfcc09ddSBjoern A. Zeeb /* 1M already there or needed so always add */
409bfcc09ddSBjoern A. Zeeb cck |= IWL_RATE_BIT_MSK(1) >> IWL_FIRST_CCK_RATE;
410bfcc09ddSBjoern A. Zeeb
411bfcc09ddSBjoern A. Zeeb *cck_rates = cck;
412bfcc09ddSBjoern A. Zeeb *ofdm_rates = ofdm;
413bfcc09ddSBjoern A. Zeeb }
414bfcc09ddSBjoern A. Zeeb
iwl_mvm_set_fw_basic_rates(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,__le32 * cck_rates,__le32 * ofdm_rates)4159af1bba4SBjoern A. Zeeb void iwl_mvm_set_fw_basic_rates(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
4169af1bba4SBjoern A. Zeeb struct ieee80211_bss_conf *link_conf,
4179af1bba4SBjoern A. Zeeb __le32 *cck_rates, __le32 *ofdm_rates)
4189af1bba4SBjoern A. Zeeb {
4199af1bba4SBjoern A. Zeeb struct ieee80211_chanctx_conf *chanctx;
4209af1bba4SBjoern A. Zeeb u8 cck_ack_rates = 0, ofdm_ack_rates = 0;
4219af1bba4SBjoern A. Zeeb
4229af1bba4SBjoern A. Zeeb rcu_read_lock();
4239af1bba4SBjoern A. Zeeb chanctx = rcu_dereference(link_conf->chanctx_conf);
4249af1bba4SBjoern A. Zeeb iwl_mvm_ack_rates(mvm, vif, chanctx ? chanctx->def.chan->band
4259af1bba4SBjoern A. Zeeb : NL80211_BAND_2GHZ,
4269af1bba4SBjoern A. Zeeb &cck_ack_rates, &ofdm_ack_rates);
4279af1bba4SBjoern A. Zeeb
4289af1bba4SBjoern A. Zeeb rcu_read_unlock();
4299af1bba4SBjoern A. Zeeb
4309af1bba4SBjoern A. Zeeb *cck_rates = cpu_to_le32((u32)cck_ack_rates);
4319af1bba4SBjoern A. Zeeb *ofdm_rates = cpu_to_le32((u32)ofdm_ack_rates);
4329af1bba4SBjoern A. Zeeb }
4339af1bba4SBjoern A. Zeeb
iwl_mvm_set_fw_protection_flags(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,__le32 * protection_flags,u32 ht_flag,u32 tgg_flag)4349af1bba4SBjoern A. Zeeb void iwl_mvm_set_fw_protection_flags(struct iwl_mvm *mvm,
435bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif,
4369af1bba4SBjoern A. Zeeb struct ieee80211_bss_conf *link_conf,
4379af1bba4SBjoern A. Zeeb __le32 *protection_flags, u32 ht_flag,
4389af1bba4SBjoern A. Zeeb u32 tgg_flag)
439bfcc09ddSBjoern A. Zeeb {
440bfcc09ddSBjoern A. Zeeb /* for both sta and ap, ht_operation_mode hold the protection_mode */
4419af1bba4SBjoern A. Zeeb u8 protection_mode = link_conf->ht_operation_mode &
442bfcc09ddSBjoern A. Zeeb IEEE80211_HT_OP_MODE_PROTECTION;
4439af1bba4SBjoern A. Zeeb bool ht_enabled = !!(link_conf->ht_operation_mode &
4449af1bba4SBjoern A. Zeeb IEEE80211_HT_OP_MODE_PROTECTION);
4459af1bba4SBjoern A. Zeeb
4469af1bba4SBjoern A. Zeeb if (link_conf->use_cts_prot)
4479af1bba4SBjoern A. Zeeb *protection_flags |= cpu_to_le32(tgg_flag);
4489af1bba4SBjoern A. Zeeb
4499af1bba4SBjoern A. Zeeb IWL_DEBUG_RATE(mvm, "use_cts_prot %d, ht_operation_mode %d\n",
4509af1bba4SBjoern A. Zeeb link_conf->use_cts_prot,
4519af1bba4SBjoern A. Zeeb link_conf->ht_operation_mode);
4529af1bba4SBjoern A. Zeeb
4539af1bba4SBjoern A. Zeeb if (!ht_enabled)
4549af1bba4SBjoern A. Zeeb return;
455bfcc09ddSBjoern A. Zeeb
456bfcc09ddSBjoern A. Zeeb IWL_DEBUG_RATE(mvm, "protection mode set to %d\n", protection_mode);
457bfcc09ddSBjoern A. Zeeb /*
458bfcc09ddSBjoern A. Zeeb * See section 9.23.3.1 of IEEE 80211-2012.
459bfcc09ddSBjoern A. Zeeb * Nongreenfield HT STAs Present is not supported.
460bfcc09ddSBjoern A. Zeeb */
461bfcc09ddSBjoern A. Zeeb switch (protection_mode) {
462bfcc09ddSBjoern A. Zeeb case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
463bfcc09ddSBjoern A. Zeeb break;
464bfcc09ddSBjoern A. Zeeb case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
465bfcc09ddSBjoern A. Zeeb case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
4669af1bba4SBjoern A. Zeeb *protection_flags |= cpu_to_le32(ht_flag);
467bfcc09ddSBjoern A. Zeeb break;
468bfcc09ddSBjoern A. Zeeb case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
469bfcc09ddSBjoern A. Zeeb /* Protect when channel wider than 20MHz */
470a4128aadSBjoern A. Zeeb if (link_conf->chanreq.oper.width > NL80211_CHAN_WIDTH_20)
4719af1bba4SBjoern A. Zeeb *protection_flags |= cpu_to_le32(ht_flag);
472bfcc09ddSBjoern A. Zeeb break;
473bfcc09ddSBjoern A. Zeeb default:
474bfcc09ddSBjoern A. Zeeb IWL_ERR(mvm, "Illegal protection mode %d\n",
475bfcc09ddSBjoern A. Zeeb protection_mode);
476bfcc09ddSBjoern A. Zeeb break;
477bfcc09ddSBjoern A. Zeeb }
478bfcc09ddSBjoern A. Zeeb }
479bfcc09ddSBjoern A. Zeeb
iwl_mvm_set_fw_qos_params(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,struct iwl_ac_qos * ac,__le32 * qos_flags)4809af1bba4SBjoern A. Zeeb void iwl_mvm_set_fw_qos_params(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
4819af1bba4SBjoern A. Zeeb struct ieee80211_bss_conf *link_conf,
4829af1bba4SBjoern A. Zeeb struct iwl_ac_qos *ac, __le32 *qos_flags)
4839af1bba4SBjoern A. Zeeb {
4849af1bba4SBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4859af1bba4SBjoern A. Zeeb struct iwl_mvm_vif_link_info *mvm_link =
4869af1bba4SBjoern A. Zeeb mvmvif->link[link_conf->link_id];
4879af1bba4SBjoern A. Zeeb int i;
4889af1bba4SBjoern A. Zeeb
4899af1bba4SBjoern A. Zeeb if (!mvm_link)
4909af1bba4SBjoern A. Zeeb return;
4919af1bba4SBjoern A. Zeeb
4929af1bba4SBjoern A. Zeeb for (i = 0; i < IEEE80211_NUM_ACS; i++) {
4939af1bba4SBjoern A. Zeeb u8 txf = iwl_mvm_mac_ac_to_tx_fifo(mvm, i);
4949af1bba4SBjoern A. Zeeb u8 ucode_ac = iwl_mvm_mac80211_ac_to_ucode_ac(i);
4959af1bba4SBjoern A. Zeeb
4969af1bba4SBjoern A. Zeeb ac[ucode_ac].cw_min =
4979af1bba4SBjoern A. Zeeb cpu_to_le16(mvm_link->queue_params[i].cw_min);
4989af1bba4SBjoern A. Zeeb ac[ucode_ac].cw_max =
4999af1bba4SBjoern A. Zeeb cpu_to_le16(mvm_link->queue_params[i].cw_max);
5009af1bba4SBjoern A. Zeeb ac[ucode_ac].edca_txop =
5019af1bba4SBjoern A. Zeeb cpu_to_le16(mvm_link->queue_params[i].txop * 32);
5029af1bba4SBjoern A. Zeeb ac[ucode_ac].aifsn = mvm_link->queue_params[i].aifs;
5039af1bba4SBjoern A. Zeeb ac[ucode_ac].fifos_mask = BIT(txf);
5049af1bba4SBjoern A. Zeeb }
5059af1bba4SBjoern A. Zeeb
5069af1bba4SBjoern A. Zeeb if (link_conf->qos)
5079af1bba4SBjoern A. Zeeb *qos_flags |= cpu_to_le32(MAC_QOS_FLG_UPDATE_EDCA);
5089af1bba4SBjoern A. Zeeb
509a4128aadSBjoern A. Zeeb if (link_conf->chanreq.oper.width != NL80211_CHAN_WIDTH_20_NOHT)
5109af1bba4SBjoern A. Zeeb *qos_flags |= cpu_to_le32(MAC_QOS_FLG_TGN);
5119af1bba4SBjoern A. Zeeb }
5129af1bba4SBjoern A. Zeeb
iwl_mvm_get_mac_type(struct ieee80211_vif * vif)5139af1bba4SBjoern A. Zeeb int iwl_mvm_get_mac_type(struct ieee80211_vif *vif)
5149af1bba4SBjoern A. Zeeb {
5159af1bba4SBjoern A. Zeeb u32 mac_type = FW_MAC_TYPE_BSS_STA;
5169af1bba4SBjoern A. Zeeb
5179af1bba4SBjoern A. Zeeb switch (vif->type) {
5189af1bba4SBjoern A. Zeeb case NL80211_IFTYPE_STATION:
5199af1bba4SBjoern A. Zeeb if (vif->p2p)
5209af1bba4SBjoern A. Zeeb mac_type = FW_MAC_TYPE_P2P_STA;
5219af1bba4SBjoern A. Zeeb else
5229af1bba4SBjoern A. Zeeb mac_type = FW_MAC_TYPE_BSS_STA;
5239af1bba4SBjoern A. Zeeb break;
5249af1bba4SBjoern A. Zeeb case NL80211_IFTYPE_AP:
5259af1bba4SBjoern A. Zeeb mac_type = FW_MAC_TYPE_GO;
5269af1bba4SBjoern A. Zeeb break;
5279af1bba4SBjoern A. Zeeb case NL80211_IFTYPE_MONITOR:
5289af1bba4SBjoern A. Zeeb mac_type = FW_MAC_TYPE_LISTENER;
5299af1bba4SBjoern A. Zeeb break;
5309af1bba4SBjoern A. Zeeb case NL80211_IFTYPE_P2P_DEVICE:
5319af1bba4SBjoern A. Zeeb mac_type = FW_MAC_TYPE_P2P_DEVICE;
5329af1bba4SBjoern A. Zeeb break;
5339af1bba4SBjoern A. Zeeb case NL80211_IFTYPE_ADHOC:
5349af1bba4SBjoern A. Zeeb mac_type = FW_MAC_TYPE_IBSS;
5359af1bba4SBjoern A. Zeeb break;
5369af1bba4SBjoern A. Zeeb default:
5379af1bba4SBjoern A. Zeeb WARN_ON_ONCE(1);
5389af1bba4SBjoern A. Zeeb }
5399af1bba4SBjoern A. Zeeb return mac_type;
5409af1bba4SBjoern A. Zeeb }
5419af1bba4SBjoern A. Zeeb
iwl_mvm_mac_ctxt_cmd_common(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct iwl_mac_ctx_cmd * cmd,const u8 * bssid_override,u32 action)542bfcc09ddSBjoern A. Zeeb static void iwl_mvm_mac_ctxt_cmd_common(struct iwl_mvm *mvm,
543bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif,
544bfcc09ddSBjoern A. Zeeb struct iwl_mac_ctx_cmd *cmd,
545bfcc09ddSBjoern A. Zeeb const u8 *bssid_override,
546bfcc09ddSBjoern A. Zeeb u32 action)
547bfcc09ddSBjoern A. Zeeb {
548bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
549bfcc09ddSBjoern A. Zeeb const u8 *bssid = bssid_override ?: vif->bss_conf.bssid;
5509af1bba4SBjoern A. Zeeb u32 ht_flag;
551bfcc09ddSBjoern A. Zeeb
552bfcc09ddSBjoern A. Zeeb cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
553bfcc09ddSBjoern A. Zeeb mvmvif->color));
554bfcc09ddSBjoern A. Zeeb cmd->action = cpu_to_le32(action);
5559af1bba4SBjoern A. Zeeb cmd->mac_type = cpu_to_le32(iwl_mvm_get_mac_type(vif));
556bfcc09ddSBjoern A. Zeeb
557bfcc09ddSBjoern A. Zeeb cmd->tsf_id = cpu_to_le32(mvmvif->tsf_id);
558bfcc09ddSBjoern A. Zeeb
559bfcc09ddSBjoern A. Zeeb memcpy(cmd->node_addr, vif->addr, ETH_ALEN);
560bfcc09ddSBjoern A. Zeeb
561bfcc09ddSBjoern A. Zeeb if (bssid)
562bfcc09ddSBjoern A. Zeeb memcpy(cmd->bssid_addr, bssid, ETH_ALEN);
563bfcc09ddSBjoern A. Zeeb else
564bfcc09ddSBjoern A. Zeeb eth_broadcast_addr(cmd->bssid_addr);
565bfcc09ddSBjoern A. Zeeb
5669af1bba4SBjoern A. Zeeb iwl_mvm_set_fw_basic_rates(mvm, vif, &vif->bss_conf, &cmd->cck_rates,
5679af1bba4SBjoern A. Zeeb &cmd->ofdm_rates);
568bfcc09ddSBjoern A. Zeeb
569bfcc09ddSBjoern A. Zeeb cmd->cck_short_preamble =
570bfcc09ddSBjoern A. Zeeb cpu_to_le32(vif->bss_conf.use_short_preamble ?
571bfcc09ddSBjoern A. Zeeb MAC_FLG_SHORT_PREAMBLE : 0);
572bfcc09ddSBjoern A. Zeeb cmd->short_slot =
573bfcc09ddSBjoern A. Zeeb cpu_to_le32(vif->bss_conf.use_short_slot ?
574bfcc09ddSBjoern A. Zeeb MAC_FLG_SHORT_SLOT : 0);
575bfcc09ddSBjoern A. Zeeb
576bfcc09ddSBjoern A. Zeeb cmd->filter_flags = 0;
577bfcc09ddSBjoern A. Zeeb
5789af1bba4SBjoern A. Zeeb iwl_mvm_set_fw_qos_params(mvm, vif, &vif->bss_conf, cmd->ac,
5799af1bba4SBjoern A. Zeeb &cmd->qos_flags);
580bfcc09ddSBjoern A. Zeeb
5819af1bba4SBjoern A. Zeeb /* The fw does not distinguish between ht and fat */
5829af1bba4SBjoern A. Zeeb ht_flag = MAC_PROT_FLG_HT_PROT | MAC_PROT_FLG_FAT_PROT;
5839af1bba4SBjoern A. Zeeb iwl_mvm_set_fw_protection_flags(mvm, vif, &vif->bss_conf,
5849af1bba4SBjoern A. Zeeb &cmd->protection_flags,
5859af1bba4SBjoern A. Zeeb ht_flag, MAC_PROT_FLG_TGG_PROTECT);
586bfcc09ddSBjoern A. Zeeb }
587bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_send_cmd(struct iwl_mvm * mvm,struct iwl_mac_ctx_cmd * cmd)588bfcc09ddSBjoern A. Zeeb static int iwl_mvm_mac_ctxt_send_cmd(struct iwl_mvm *mvm,
589bfcc09ddSBjoern A. Zeeb struct iwl_mac_ctx_cmd *cmd)
590bfcc09ddSBjoern A. Zeeb {
591bfcc09ddSBjoern A. Zeeb int ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, 0,
592bfcc09ddSBjoern A. Zeeb sizeof(*cmd), cmd);
593bfcc09ddSBjoern A. Zeeb if (ret)
5949af1bba4SBjoern A. Zeeb IWL_ERR(mvm, "Failed to send MAC_CONTEXT_CMD (action:%d): %d\n",
595bfcc09ddSBjoern A. Zeeb le32_to_cpu(cmd->action), ret);
596bfcc09ddSBjoern A. Zeeb return ret;
597bfcc09ddSBjoern A. Zeeb }
598bfcc09ddSBjoern A. Zeeb
iwl_mvm_set_fw_dtim_tbtt(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,__le64 * dtim_tsf,__le32 * dtim_time,__le32 * assoc_beacon_arrive_time)5999af1bba4SBjoern A. Zeeb void iwl_mvm_set_fw_dtim_tbtt(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
6009af1bba4SBjoern A. Zeeb struct ieee80211_bss_conf *link_conf,
6019af1bba4SBjoern A. Zeeb __le64 *dtim_tsf, __le32 *dtim_time,
6029af1bba4SBjoern A. Zeeb __le32 *assoc_beacon_arrive_time)
603bfcc09ddSBjoern A. Zeeb {
604bfcc09ddSBjoern A. Zeeb u32 dtim_offs;
605bfcc09ddSBjoern A. Zeeb
606bfcc09ddSBjoern A. Zeeb /*
607bfcc09ddSBjoern A. Zeeb * The DTIM count counts down, so when it is N that means N
608bfcc09ddSBjoern A. Zeeb * more beacon intervals happen until the DTIM TBTT. Therefore
609bfcc09ddSBjoern A. Zeeb * add this to the current time. If that ends up being in the
610bfcc09ddSBjoern A. Zeeb * future, the firmware will handle it.
611bfcc09ddSBjoern A. Zeeb *
612bfcc09ddSBjoern A. Zeeb * Also note that the system_timestamp (which we get here as
613bfcc09ddSBjoern A. Zeeb * "sync_device_ts") and TSF timestamp aren't at exactly the
614bfcc09ddSBjoern A. Zeeb * same offset in the frame -- the TSF is at the first symbol
615bfcc09ddSBjoern A. Zeeb * of the TSF, the system timestamp is at signal acquisition
616bfcc09ddSBjoern A. Zeeb * time. This means there's an offset between them of at most
617bfcc09ddSBjoern A. Zeeb * a few hundred microseconds (24 * 8 bits + PLCP time gives
618bfcc09ddSBjoern A. Zeeb * 384us in the longest case), this is currently not relevant
619bfcc09ddSBjoern A. Zeeb * as the firmware wakes up around 2ms before the TBTT.
620bfcc09ddSBjoern A. Zeeb */
6219af1bba4SBjoern A. Zeeb dtim_offs = link_conf->sync_dtim_count *
6229af1bba4SBjoern A. Zeeb link_conf->beacon_int;
623bfcc09ddSBjoern A. Zeeb /* convert TU to usecs */
624bfcc09ddSBjoern A. Zeeb dtim_offs *= 1024;
625bfcc09ddSBjoern A. Zeeb
6269af1bba4SBjoern A. Zeeb *dtim_tsf =
6279af1bba4SBjoern A. Zeeb cpu_to_le64(link_conf->sync_tsf + dtim_offs);
6289af1bba4SBjoern A. Zeeb *dtim_time =
6299af1bba4SBjoern A. Zeeb cpu_to_le32(link_conf->sync_device_ts + dtim_offs);
6309af1bba4SBjoern A. Zeeb *assoc_beacon_arrive_time =
6319af1bba4SBjoern A. Zeeb cpu_to_le32(link_conf->sync_device_ts);
632bfcc09ddSBjoern A. Zeeb
633bfcc09ddSBjoern A. Zeeb IWL_DEBUG_INFO(mvm, "DTIM TBTT is 0x%llx/0x%x, offset %d\n",
6349af1bba4SBjoern A. Zeeb le64_to_cpu(*dtim_tsf),
6359af1bba4SBjoern A. Zeeb le32_to_cpu(*dtim_time),
636bfcc09ddSBjoern A. Zeeb dtim_offs);
6379af1bba4SBjoern A. Zeeb }
6389af1bba4SBjoern A. Zeeb
iwl_mvm_mac_ctxt_cmd_p2p_sta_get_oppps_ctwin(struct iwl_mvm * mvm,struct ieee80211_vif * vif)6399af1bba4SBjoern A. Zeeb __le32 iwl_mvm_mac_ctxt_cmd_p2p_sta_get_oppps_ctwin(struct iwl_mvm *mvm,
6409af1bba4SBjoern A. Zeeb struct ieee80211_vif *vif)
6419af1bba4SBjoern A. Zeeb {
6429af1bba4SBjoern A. Zeeb struct ieee80211_p2p_noa_attr *noa =
6439af1bba4SBjoern A. Zeeb &vif->bss_conf.p2p_noa_attr;
6449af1bba4SBjoern A. Zeeb
6459af1bba4SBjoern A. Zeeb return cpu_to_le32(noa->oppps_ctwindow &
6469af1bba4SBjoern A. Zeeb IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
6479af1bba4SBjoern A. Zeeb }
6489af1bba4SBjoern A. Zeeb
iwl_mvm_mac_ctxt_cmd_sta_get_twt_policy(struct iwl_mvm * mvm,struct ieee80211_vif * vif)6499af1bba4SBjoern A. Zeeb u32 iwl_mvm_mac_ctxt_cmd_sta_get_twt_policy(struct iwl_mvm *mvm,
6509af1bba4SBjoern A. Zeeb struct ieee80211_vif *vif)
6519af1bba4SBjoern A. Zeeb {
6529af1bba4SBjoern A. Zeeb u32 twt_policy = 0;
6539af1bba4SBjoern A. Zeeb
6549af1bba4SBjoern A. Zeeb if (vif->bss_conf.twt_requester && IWL_MVM_USE_TWT)
6559af1bba4SBjoern A. Zeeb twt_policy |= TWT_SUPPORTED;
6569af1bba4SBjoern A. Zeeb if (vif->bss_conf.twt_protected)
6579af1bba4SBjoern A. Zeeb twt_policy |= PROTECTED_TWT_SUPPORTED;
6589af1bba4SBjoern A. Zeeb if (vif->bss_conf.twt_broadcast)
6599af1bba4SBjoern A. Zeeb twt_policy |= BROADCAST_TWT_SUPPORTED;
6609af1bba4SBjoern A. Zeeb
6619af1bba4SBjoern A. Zeeb return twt_policy;
6629af1bba4SBjoern A. Zeeb }
6639af1bba4SBjoern A. Zeeb
iwl_mvm_mac_ctxt_cmd_sta(struct iwl_mvm * mvm,struct ieee80211_vif * vif,u32 action,bool force_assoc_off,const u8 * bssid_override)6649af1bba4SBjoern A. Zeeb static int iwl_mvm_mac_ctxt_cmd_sta(struct iwl_mvm *mvm,
6659af1bba4SBjoern A. Zeeb struct ieee80211_vif *vif,
6669af1bba4SBjoern A. Zeeb u32 action, bool force_assoc_off,
6679af1bba4SBjoern A. Zeeb const u8 *bssid_override)
6689af1bba4SBjoern A. Zeeb {
6699af1bba4SBjoern A. Zeeb struct iwl_mac_ctx_cmd cmd = {};
6709af1bba4SBjoern A. Zeeb struct iwl_mac_data_sta *ctxt_sta;
6719af1bba4SBjoern A. Zeeb
6729af1bba4SBjoern A. Zeeb WARN_ON(vif->type != NL80211_IFTYPE_STATION);
6739af1bba4SBjoern A. Zeeb
6749af1bba4SBjoern A. Zeeb /* Fill the common data for all mac context types */
6759af1bba4SBjoern A. Zeeb iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, bssid_override, action);
6769af1bba4SBjoern A. Zeeb
6779af1bba4SBjoern A. Zeeb /*
6789af1bba4SBjoern A. Zeeb * We always want to hear MCAST frames, if we're not authorized yet,
6799af1bba4SBjoern A. Zeeb * we'll drop them.
6809af1bba4SBjoern A. Zeeb */
6819af1bba4SBjoern A. Zeeb cmd.filter_flags |= cpu_to_le32(MAC_FILTER_ACCEPT_GRP);
6829af1bba4SBjoern A. Zeeb
6839af1bba4SBjoern A. Zeeb if (vif->p2p) {
6849af1bba4SBjoern A. Zeeb cmd.p2p_sta.ctwin =
6859af1bba4SBjoern A. Zeeb iwl_mvm_mac_ctxt_cmd_p2p_sta_get_oppps_ctwin(mvm, vif);
6869af1bba4SBjoern A. Zeeb
6879af1bba4SBjoern A. Zeeb ctxt_sta = &cmd.p2p_sta.sta;
6889af1bba4SBjoern A. Zeeb } else {
6899af1bba4SBjoern A. Zeeb ctxt_sta = &cmd.sta;
6909af1bba4SBjoern A. Zeeb }
6919af1bba4SBjoern A. Zeeb
6929af1bba4SBjoern A. Zeeb /* We need the dtim_period to set the MAC as associated */
6939af1bba4SBjoern A. Zeeb if (vif->cfg.assoc && vif->bss_conf.dtim_period &&
6949af1bba4SBjoern A. Zeeb !force_assoc_off) {
6959af1bba4SBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
6969af1bba4SBjoern A. Zeeb
6979af1bba4SBjoern A. Zeeb iwl_mvm_set_fw_dtim_tbtt(mvm, vif, &vif->bss_conf,
6989af1bba4SBjoern A. Zeeb &ctxt_sta->dtim_tsf,
6999af1bba4SBjoern A. Zeeb &ctxt_sta->dtim_time,
7009af1bba4SBjoern A. Zeeb &ctxt_sta->assoc_beacon_arrive_time);
701bfcc09ddSBjoern A. Zeeb
702bfcc09ddSBjoern A. Zeeb ctxt_sta->is_assoc = cpu_to_le32(1);
703bfcc09ddSBjoern A. Zeeb
704bfcc09ddSBjoern A. Zeeb if (!mvmvif->authorized &&
705bfcc09ddSBjoern A. Zeeb fw_has_capa(&mvm->fw->ucode_capa,
706bfcc09ddSBjoern A. Zeeb IWL_UCODE_TLV_CAPA_COEX_HIGH_PRIO))
707bfcc09ddSBjoern A. Zeeb ctxt_sta->data_policy |=
708bfcc09ddSBjoern A. Zeeb cpu_to_le32(COEX_HIGH_PRIORITY_ENABLE);
709bfcc09ddSBjoern A. Zeeb } else {
710bfcc09ddSBjoern A. Zeeb ctxt_sta->is_assoc = cpu_to_le32(0);
711bfcc09ddSBjoern A. Zeeb
712bfcc09ddSBjoern A. Zeeb /* Allow beacons to pass through as long as we are not
713bfcc09ddSBjoern A. Zeeb * associated, or we do not have dtim period information.
714bfcc09ddSBjoern A. Zeeb */
715bfcc09ddSBjoern A. Zeeb cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_BEACON);
716bfcc09ddSBjoern A. Zeeb }
717bfcc09ddSBjoern A. Zeeb
718bfcc09ddSBjoern A. Zeeb ctxt_sta->bi = cpu_to_le32(vif->bss_conf.beacon_int);
719bfcc09ddSBjoern A. Zeeb ctxt_sta->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
720bfcc09ddSBjoern A. Zeeb vif->bss_conf.dtim_period);
721bfcc09ddSBjoern A. Zeeb
722bfcc09ddSBjoern A. Zeeb ctxt_sta->listen_interval = cpu_to_le32(mvm->hw->conf.listen_interval);
7239af1bba4SBjoern A. Zeeb ctxt_sta->assoc_id = cpu_to_le32(vif->cfg.aid);
724bfcc09ddSBjoern A. Zeeb
7259af1bba4SBjoern A. Zeeb if (vif->probe_req_reg && vif->cfg.assoc && vif->p2p)
726bfcc09ddSBjoern A. Zeeb cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
727bfcc09ddSBjoern A. Zeeb
728bfcc09ddSBjoern A. Zeeb if (vif->bss_conf.he_support && !iwlwifi_mod_params.disable_11ax) {
729bfcc09ddSBjoern A. Zeeb cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_11AX);
730bfcc09ddSBjoern A. Zeeb ctxt_sta->data_policy |=
7319af1bba4SBjoern A. Zeeb cpu_to_le32(iwl_mvm_mac_ctxt_cmd_sta_get_twt_policy(mvm, vif));
732bfcc09ddSBjoern A. Zeeb }
733bfcc09ddSBjoern A. Zeeb
734bfcc09ddSBjoern A. Zeeb
735bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
736bfcc09ddSBjoern A. Zeeb }
737bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_cmd_listener(struct iwl_mvm * mvm,struct ieee80211_vif * vif,u32 action)738bfcc09ddSBjoern A. Zeeb static int iwl_mvm_mac_ctxt_cmd_listener(struct iwl_mvm *mvm,
739bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif,
740bfcc09ddSBjoern A. Zeeb u32 action)
741bfcc09ddSBjoern A. Zeeb {
742bfcc09ddSBjoern A. Zeeb struct iwl_mac_ctx_cmd cmd = {};
7439af1bba4SBjoern A. Zeeb u32 tfd_queue_msk = 0;
744bfcc09ddSBjoern A. Zeeb int ret;
745bfcc09ddSBjoern A. Zeeb
746bfcc09ddSBjoern A. Zeeb WARN_ON(vif->type != NL80211_IFTYPE_MONITOR);
747bfcc09ddSBjoern A. Zeeb
748bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
749bfcc09ddSBjoern A. Zeeb
750bfcc09ddSBjoern A. Zeeb cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROMISC |
751bfcc09ddSBjoern A. Zeeb MAC_FILTER_IN_CONTROL_AND_MGMT |
752bfcc09ddSBjoern A. Zeeb MAC_FILTER_IN_BEACON |
753bfcc09ddSBjoern A. Zeeb MAC_FILTER_IN_PROBE_REQUEST |
754bfcc09ddSBjoern A. Zeeb MAC_FILTER_IN_CRC32 |
755bfcc09ddSBjoern A. Zeeb MAC_FILTER_ACCEPT_GRP);
756bfcc09ddSBjoern A. Zeeb ieee80211_hw_set(mvm->hw, RX_INCLUDES_FCS);
757bfcc09ddSBjoern A. Zeeb
7589af1bba4SBjoern A. Zeeb /*
7599af1bba4SBjoern A. Zeeb * the queue mask is only relevant for old TX API, and
7609af1bba4SBjoern A. Zeeb * mvm->snif_queue isn't set here (it's still set to
7619af1bba4SBjoern A. Zeeb * IWL_MVM_INVALID_QUEUE so the BIT() of it is UB)
7629af1bba4SBjoern A. Zeeb */
7639af1bba4SBjoern A. Zeeb if (!iwl_mvm_has_new_tx_api(mvm))
7649af1bba4SBjoern A. Zeeb tfd_queue_msk = BIT(mvm->snif_queue);
7659af1bba4SBjoern A. Zeeb
766bfcc09ddSBjoern A. Zeeb /* Allocate sniffer station */
767bfcc09ddSBjoern A. Zeeb ret = iwl_mvm_allocate_int_sta(mvm, &mvm->snif_sta, tfd_queue_msk,
768bfcc09ddSBjoern A. Zeeb vif->type, IWL_STA_GENERAL_PURPOSE);
769bfcc09ddSBjoern A. Zeeb if (ret)
770bfcc09ddSBjoern A. Zeeb return ret;
771bfcc09ddSBjoern A. Zeeb
772bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
773bfcc09ddSBjoern A. Zeeb }
774bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_cmd_ibss(struct iwl_mvm * mvm,struct ieee80211_vif * vif,u32 action)775bfcc09ddSBjoern A. Zeeb static int iwl_mvm_mac_ctxt_cmd_ibss(struct iwl_mvm *mvm,
776bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif,
777bfcc09ddSBjoern A. Zeeb u32 action)
778bfcc09ddSBjoern A. Zeeb {
779bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
780bfcc09ddSBjoern A. Zeeb struct iwl_mac_ctx_cmd cmd = {};
781bfcc09ddSBjoern A. Zeeb
782bfcc09ddSBjoern A. Zeeb WARN_ON(vif->type != NL80211_IFTYPE_ADHOC);
783bfcc09ddSBjoern A. Zeeb
784bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
785bfcc09ddSBjoern A. Zeeb
786bfcc09ddSBjoern A. Zeeb cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_BEACON |
787bfcc09ddSBjoern A. Zeeb MAC_FILTER_IN_PROBE_REQUEST |
788bfcc09ddSBjoern A. Zeeb MAC_FILTER_ACCEPT_GRP);
789bfcc09ddSBjoern A. Zeeb
790bfcc09ddSBjoern A. Zeeb /* cmd.ibss.beacon_time/cmd.ibss.beacon_tsf are curently ignored */
791bfcc09ddSBjoern A. Zeeb cmd.ibss.bi = cpu_to_le32(vif->bss_conf.beacon_int);
792bfcc09ddSBjoern A. Zeeb
793bfcc09ddSBjoern A. Zeeb /* TODO: Assumes that the beacon id == mac context id */
794bfcc09ddSBjoern A. Zeeb cmd.ibss.beacon_template = cpu_to_le32(mvmvif->id);
795bfcc09ddSBjoern A. Zeeb
796bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
797bfcc09ddSBjoern A. Zeeb }
798bfcc09ddSBjoern A. Zeeb
799bfcc09ddSBjoern A. Zeeb struct iwl_mvm_go_iterator_data {
800bfcc09ddSBjoern A. Zeeb bool go_active;
801bfcc09ddSBjoern A. Zeeb };
802bfcc09ddSBjoern A. Zeeb
iwl_mvm_go_iterator(void * _data,u8 * mac,struct ieee80211_vif * vif)803bfcc09ddSBjoern A. Zeeb static void iwl_mvm_go_iterator(void *_data, u8 *mac, struct ieee80211_vif *vif)
804bfcc09ddSBjoern A. Zeeb {
805bfcc09ddSBjoern A. Zeeb struct iwl_mvm_go_iterator_data *data = _data;
806bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
807bfcc09ddSBjoern A. Zeeb
808bfcc09ddSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_AP && vif->p2p &&
809bfcc09ddSBjoern A. Zeeb mvmvif->ap_ibss_active)
810bfcc09ddSBjoern A. Zeeb data->go_active = true;
811bfcc09ddSBjoern A. Zeeb }
812bfcc09ddSBjoern A. Zeeb
iwl_mac_ctxt_p2p_dev_has_extended_disc(struct iwl_mvm * mvm,struct ieee80211_vif * vif)8139af1bba4SBjoern A. Zeeb __le32 iwl_mac_ctxt_p2p_dev_has_extended_disc(struct iwl_mvm *mvm,
8149af1bba4SBjoern A. Zeeb struct ieee80211_vif *vif)
815bfcc09ddSBjoern A. Zeeb {
816bfcc09ddSBjoern A. Zeeb struct iwl_mvm_go_iterator_data data = {};
817bfcc09ddSBjoern A. Zeeb
818bfcc09ddSBjoern A. Zeeb /*
819bfcc09ddSBjoern A. Zeeb * This flag should be set to true when the P2P Device is
820bfcc09ddSBjoern A. Zeeb * discoverable and there is at least another active P2P GO. Settings
821bfcc09ddSBjoern A. Zeeb * this flag will allow the P2P Device to be discoverable on other
822bfcc09ddSBjoern A. Zeeb * channels in addition to its listen channel.
823bfcc09ddSBjoern A. Zeeb * Note that this flag should not be set in other cases as it opens the
824bfcc09ddSBjoern A. Zeeb * Rx filters on all MAC and increases the number of interrupts.
825bfcc09ddSBjoern A. Zeeb */
826bfcc09ddSBjoern A. Zeeb ieee80211_iterate_active_interfaces_atomic(
827bfcc09ddSBjoern A. Zeeb mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
828bfcc09ddSBjoern A. Zeeb iwl_mvm_go_iterator, &data);
829bfcc09ddSBjoern A. Zeeb
8309af1bba4SBjoern A. Zeeb return cpu_to_le32(data.go_active ? 1 : 0);
8319af1bba4SBjoern A. Zeeb }
8329af1bba4SBjoern A. Zeeb
iwl_mvm_mac_ctxt_cmd_p2p_device(struct iwl_mvm * mvm,struct ieee80211_vif * vif,u32 action)8339af1bba4SBjoern A. Zeeb static int iwl_mvm_mac_ctxt_cmd_p2p_device(struct iwl_mvm *mvm,
8349af1bba4SBjoern A. Zeeb struct ieee80211_vif *vif,
8359af1bba4SBjoern A. Zeeb u32 action)
8369af1bba4SBjoern A. Zeeb {
8379af1bba4SBjoern A. Zeeb struct iwl_mac_ctx_cmd cmd = {};
8389af1bba4SBjoern A. Zeeb
8399af1bba4SBjoern A. Zeeb WARN_ON(vif->type != NL80211_IFTYPE_P2P_DEVICE);
8409af1bba4SBjoern A. Zeeb
8419af1bba4SBjoern A. Zeeb iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
8429af1bba4SBjoern A. Zeeb
8439af1bba4SBjoern A. Zeeb cmd.p2p_dev.is_disc_extended =
8449af1bba4SBjoern A. Zeeb iwl_mac_ctxt_p2p_dev_has_extended_disc(mvm, vif);
8459af1bba4SBjoern A. Zeeb
8469af1bba4SBjoern A. Zeeb /* Override the filter flags to accept only probe requests */
8479af1bba4SBjoern A. Zeeb cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
8489af1bba4SBjoern A. Zeeb
849bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
850bfcc09ddSBjoern A. Zeeb }
851bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm * mvm,__le32 * tim_index,__le32 * tim_size,u8 * beacon,u32 frame_size)852bfcc09ddSBjoern A. Zeeb void iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm *mvm,
853bfcc09ddSBjoern A. Zeeb __le32 *tim_index, __le32 *tim_size,
854bfcc09ddSBjoern A. Zeeb u8 *beacon, u32 frame_size)
855bfcc09ddSBjoern A. Zeeb {
856bfcc09ddSBjoern A. Zeeb u32 tim_idx;
857bfcc09ddSBjoern A. Zeeb struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
858bfcc09ddSBjoern A. Zeeb
859bfcc09ddSBjoern A. Zeeb /* The index is relative to frame start but we start looking at the
860bfcc09ddSBjoern A. Zeeb * variable-length part of the beacon. */
861bfcc09ddSBjoern A. Zeeb tim_idx = mgmt->u.beacon.variable - beacon;
862bfcc09ddSBjoern A. Zeeb
863bfcc09ddSBjoern A. Zeeb /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
864bfcc09ddSBjoern A. Zeeb while ((tim_idx < (frame_size - 2)) &&
865bfcc09ddSBjoern A. Zeeb (beacon[tim_idx] != WLAN_EID_TIM))
866bfcc09ddSBjoern A. Zeeb tim_idx += beacon[tim_idx+1] + 2;
867bfcc09ddSBjoern A. Zeeb
868bfcc09ddSBjoern A. Zeeb /* If TIM field was found, set variables */
869bfcc09ddSBjoern A. Zeeb if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
870bfcc09ddSBjoern A. Zeeb *tim_index = cpu_to_le32(tim_idx);
871bfcc09ddSBjoern A. Zeeb *tim_size = cpu_to_le32((u32)beacon[tim_idx + 1]);
872bfcc09ddSBjoern A. Zeeb } else {
873bfcc09ddSBjoern A. Zeeb IWL_WARN(mvm, "Unable to find TIM Element in beacon\n");
874bfcc09ddSBjoern A. Zeeb }
875bfcc09ddSBjoern A. Zeeb }
876bfcc09ddSBjoern A. Zeeb
iwl_mvm_find_ie_offset(u8 * beacon,u8 eid,u32 frame_size)877a4128aadSBjoern A. Zeeb u32 iwl_mvm_find_ie_offset(u8 *beacon, u8 eid, u32 frame_size)
878bfcc09ddSBjoern A. Zeeb {
879bfcc09ddSBjoern A. Zeeb struct ieee80211_mgmt *mgmt = (void *)beacon;
880bfcc09ddSBjoern A. Zeeb const u8 *ie;
881bfcc09ddSBjoern A. Zeeb
882bfcc09ddSBjoern A. Zeeb if (WARN_ON_ONCE(frame_size <= (mgmt->u.beacon.variable - beacon)))
883bfcc09ddSBjoern A. Zeeb return 0;
884bfcc09ddSBjoern A. Zeeb
885bfcc09ddSBjoern A. Zeeb frame_size -= mgmt->u.beacon.variable - beacon;
886bfcc09ddSBjoern A. Zeeb
887bfcc09ddSBjoern A. Zeeb ie = cfg80211_find_ie(eid, mgmt->u.beacon.variable, frame_size);
888bfcc09ddSBjoern A. Zeeb if (!ie)
889bfcc09ddSBjoern A. Zeeb return 0;
890bfcc09ddSBjoern A. Zeeb
891bfcc09ddSBjoern A. Zeeb return ie - beacon;
892bfcc09ddSBjoern A. Zeeb }
893bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_get_lowest_rate(struct iwl_mvm * mvm,struct ieee80211_tx_info * info,struct ieee80211_vif * vif)8949af1bba4SBjoern A. Zeeb u8 iwl_mvm_mac_ctxt_get_lowest_rate(struct iwl_mvm *mvm,
8959af1bba4SBjoern A. Zeeb struct ieee80211_tx_info *info,
896bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif)
897bfcc09ddSBjoern A. Zeeb {
8989af1bba4SBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8999af1bba4SBjoern A. Zeeb struct ieee80211_supported_band *sband;
9009af1bba4SBjoern A. Zeeb unsigned long basic = vif->bss_conf.basic_rates;
9019af1bba4SBjoern A. Zeeb u16 lowest_cck = IWL_RATE_COUNT, lowest_ofdm = IWL_RATE_COUNT;
9029af1bba4SBjoern A. Zeeb u32 link_id = u32_get_bits(info->control.flags,
9039af1bba4SBjoern A. Zeeb IEEE80211_TX_CTRL_MLO_LINK);
9049af1bba4SBjoern A. Zeeb u8 band = info->band;
905bfcc09ddSBjoern A. Zeeb u8 rate;
9069af1bba4SBjoern A. Zeeb u32 i;
9079af1bba4SBjoern A. Zeeb
9089af1bba4SBjoern A. Zeeb if (link_id == IEEE80211_LINK_UNSPECIFIED && ieee80211_vif_is_mld(vif)) {
9099af1bba4SBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(mvmvif->link); i++) {
9109af1bba4SBjoern A. Zeeb if (!mvmvif->link[i])
9119af1bba4SBjoern A. Zeeb continue;
9129af1bba4SBjoern A. Zeeb /* shouldn't do this when >1 link is active */
9139af1bba4SBjoern A. Zeeb WARN_ON_ONCE(link_id != IEEE80211_LINK_UNSPECIFIED);
9149af1bba4SBjoern A. Zeeb link_id = i;
9159af1bba4SBjoern A. Zeeb }
9169af1bba4SBjoern A. Zeeb }
9179af1bba4SBjoern A. Zeeb
9189af1bba4SBjoern A. Zeeb if (link_id < IEEE80211_LINK_UNSPECIFIED) {
9199af1bba4SBjoern A. Zeeb struct ieee80211_bss_conf *link_conf;
9209af1bba4SBjoern A. Zeeb
9219af1bba4SBjoern A. Zeeb rcu_read_lock();
9229af1bba4SBjoern A. Zeeb link_conf = rcu_dereference(vif->link_conf[link_id]);
9239af1bba4SBjoern A. Zeeb if (link_conf) {
9249af1bba4SBjoern A. Zeeb basic = link_conf->basic_rates;
925a4128aadSBjoern A. Zeeb if (link_conf->chanreq.oper.chan)
926a4128aadSBjoern A. Zeeb band = link_conf->chanreq.oper.chan->band;
9279af1bba4SBjoern A. Zeeb }
9289af1bba4SBjoern A. Zeeb rcu_read_unlock();
9299af1bba4SBjoern A. Zeeb }
9309af1bba4SBjoern A. Zeeb
9319af1bba4SBjoern A. Zeeb sband = mvm->hw->wiphy->bands[band];
9329af1bba4SBjoern A. Zeeb for_each_set_bit(i, &basic, BITS_PER_LONG) {
9339af1bba4SBjoern A. Zeeb u16 hw = sband->bitrates[i].hw_value;
9349af1bba4SBjoern A. Zeeb
9359af1bba4SBjoern A. Zeeb if (hw >= IWL_FIRST_OFDM_RATE) {
9369af1bba4SBjoern A. Zeeb if (lowest_ofdm > hw)
9379af1bba4SBjoern A. Zeeb lowest_ofdm = hw;
9389af1bba4SBjoern A. Zeeb } else if (lowest_cck > hw) {
9399af1bba4SBjoern A. Zeeb lowest_cck = hw;
9409af1bba4SBjoern A. Zeeb }
9419af1bba4SBjoern A. Zeeb }
9429af1bba4SBjoern A. Zeeb
9439af1bba4SBjoern A. Zeeb if (band == NL80211_BAND_2GHZ && !vif->p2p &&
9449af1bba4SBjoern A. Zeeb vif->type != NL80211_IFTYPE_P2P_DEVICE &&
9459af1bba4SBjoern A. Zeeb !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)) {
9469af1bba4SBjoern A. Zeeb if (lowest_cck != IWL_RATE_COUNT)
9479af1bba4SBjoern A. Zeeb rate = lowest_cck;
9489af1bba4SBjoern A. Zeeb else if (lowest_ofdm != IWL_RATE_COUNT)
9499af1bba4SBjoern A. Zeeb rate = lowest_ofdm;
950bfcc09ddSBjoern A. Zeeb else
9519af1bba4SBjoern A. Zeeb rate = IWL_RATE_1M_INDEX;
9529af1bba4SBjoern A. Zeeb } else if (lowest_ofdm != IWL_RATE_COUNT) {
9539af1bba4SBjoern A. Zeeb rate = lowest_ofdm;
9549af1bba4SBjoern A. Zeeb } else {
9559af1bba4SBjoern A. Zeeb rate = IWL_RATE_6M_INDEX;
9569af1bba4SBjoern A. Zeeb }
957bfcc09ddSBjoern A. Zeeb
958bfcc09ddSBjoern A. Zeeb return rate;
959bfcc09ddSBjoern A. Zeeb }
960bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_get_beacon_flags(const struct iwl_fw * fw,u8 rate_idx)961bfcc09ddSBjoern A. Zeeb u16 iwl_mvm_mac_ctxt_get_beacon_flags(const struct iwl_fw *fw, u8 rate_idx)
962bfcc09ddSBjoern A. Zeeb {
963bfcc09ddSBjoern A. Zeeb u16 flags = iwl_mvm_mac80211_idx_to_hwrate(fw, rate_idx);
964d9836fb4SBjoern A. Zeeb bool is_new_rate = iwl_fw_lookup_cmd_ver(fw, BEACON_TEMPLATE_CMD, 0) > 10;
965bfcc09ddSBjoern A. Zeeb
966bfcc09ddSBjoern A. Zeeb if (rate_idx <= IWL_FIRST_CCK_RATE)
967bfcc09ddSBjoern A. Zeeb flags |= is_new_rate ? IWL_MAC_BEACON_CCK
968bfcc09ddSBjoern A. Zeeb : IWL_MAC_BEACON_CCK_V1;
969bfcc09ddSBjoern A. Zeeb
970bfcc09ddSBjoern A. Zeeb return flags;
971bfcc09ddSBjoern A. Zeeb }
972bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_get_beacon_rate(struct iwl_mvm * mvm,struct ieee80211_tx_info * info,struct ieee80211_vif * vif)9739af1bba4SBjoern A. Zeeb u8 iwl_mvm_mac_ctxt_get_beacon_rate(struct iwl_mvm *mvm,
9749af1bba4SBjoern A. Zeeb struct ieee80211_tx_info *info,
9759af1bba4SBjoern A. Zeeb struct ieee80211_vif *vif)
9769af1bba4SBjoern A. Zeeb {
9779af1bba4SBjoern A. Zeeb struct ieee80211_supported_band *sband =
9789af1bba4SBjoern A. Zeeb mvm->hw->wiphy->bands[info->band];
9799af1bba4SBjoern A. Zeeb u32 legacy = vif->bss_conf.beacon_tx_rate.control[info->band].legacy;
9809af1bba4SBjoern A. Zeeb
9819af1bba4SBjoern A. Zeeb /* if beacon rate was configured try using it */
9829af1bba4SBjoern A. Zeeb if (hweight32(legacy) == 1) {
9839af1bba4SBjoern A. Zeeb u32 rate = ffs(legacy) - 1;
9849af1bba4SBjoern A. Zeeb
9859af1bba4SBjoern A. Zeeb return sband->bitrates[rate].hw_value;
9869af1bba4SBjoern A. Zeeb }
9879af1bba4SBjoern A. Zeeb
9889af1bba4SBjoern A. Zeeb return iwl_mvm_mac_ctxt_get_lowest_rate(mvm, info, vif);
9899af1bba4SBjoern A. Zeeb }
9909af1bba4SBjoern A. Zeeb
iwl_mvm_mac_ctxt_set_tx(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct sk_buff * beacon,struct iwl_tx_cmd * tx)991bfcc09ddSBjoern A. Zeeb static void iwl_mvm_mac_ctxt_set_tx(struct iwl_mvm *mvm,
992bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif,
993bfcc09ddSBjoern A. Zeeb struct sk_buff *beacon,
994bfcc09ddSBjoern A. Zeeb struct iwl_tx_cmd *tx)
995bfcc09ddSBjoern A. Zeeb {
996bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
997bfcc09ddSBjoern A. Zeeb struct ieee80211_tx_info *info;
998bfcc09ddSBjoern A. Zeeb u8 rate;
999bfcc09ddSBjoern A. Zeeb u32 tx_flags;
1000bfcc09ddSBjoern A. Zeeb
1001bfcc09ddSBjoern A. Zeeb info = IEEE80211_SKB_CB(beacon);
1002bfcc09ddSBjoern A. Zeeb
1003bfcc09ddSBjoern A. Zeeb /* Set up TX command fields */
1004bfcc09ddSBjoern A. Zeeb tx->len = cpu_to_le16((u16)beacon->len);
10059af1bba4SBjoern A. Zeeb tx->sta_id = mvmvif->deflink.bcast_sta.sta_id;
1006bfcc09ddSBjoern A. Zeeb tx->life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
1007bfcc09ddSBjoern A. Zeeb tx_flags = TX_CMD_FLG_SEQ_CTL | TX_CMD_FLG_TSF;
1008bfcc09ddSBjoern A. Zeeb tx_flags |=
1009bfcc09ddSBjoern A. Zeeb iwl_mvm_bt_coex_tx_prio(mvm, (void *)beacon->data, info, 0) <<
1010bfcc09ddSBjoern A. Zeeb TX_CMD_FLG_BT_PRIO_POS;
1011bfcc09ddSBjoern A. Zeeb tx->tx_flags = cpu_to_le32(tx_flags);
1012bfcc09ddSBjoern A. Zeeb
1013bfcc09ddSBjoern A. Zeeb if (!fw_has_capa(&mvm->fw->ucode_capa,
1014a4128aadSBjoern A. Zeeb IWL_UCODE_TLV_CAPA_BEACON_ANT_SELECTION)) {
1015bfcc09ddSBjoern A. Zeeb iwl_mvm_toggle_tx_ant(mvm, &mvm->mgmt_last_antenna_idx);
1016bfcc09ddSBjoern A. Zeeb
1017bfcc09ddSBjoern A. Zeeb tx->rate_n_flags =
1018bfcc09ddSBjoern A. Zeeb cpu_to_le32(BIT(mvm->mgmt_last_antenna_idx) <<
1019bfcc09ddSBjoern A. Zeeb RATE_MCS_ANT_POS);
1020a4128aadSBjoern A. Zeeb }
1021bfcc09ddSBjoern A. Zeeb
10229af1bba4SBjoern A. Zeeb rate = iwl_mvm_mac_ctxt_get_beacon_rate(mvm, info, vif);
1023bfcc09ddSBjoern A. Zeeb
1024bfcc09ddSBjoern A. Zeeb tx->rate_n_flags |=
1025bfcc09ddSBjoern A. Zeeb cpu_to_le32(iwl_mvm_mac80211_idx_to_hwrate(mvm->fw, rate));
1026bfcc09ddSBjoern A. Zeeb if (rate == IWL_FIRST_CCK_RATE)
1027bfcc09ddSBjoern A. Zeeb tx->rate_n_flags |= cpu_to_le32(RATE_MCS_CCK_MSK_V1);
1028bfcc09ddSBjoern A. Zeeb
1029bfcc09ddSBjoern A. Zeeb }
1030bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_send_beacon_cmd(struct iwl_mvm * mvm,struct sk_buff * beacon,void * data,int len)1031bfcc09ddSBjoern A. Zeeb int iwl_mvm_mac_ctxt_send_beacon_cmd(struct iwl_mvm *mvm,
1032bfcc09ddSBjoern A. Zeeb struct sk_buff *beacon,
1033bfcc09ddSBjoern A. Zeeb void *data, int len)
1034bfcc09ddSBjoern A. Zeeb {
1035bfcc09ddSBjoern A. Zeeb struct iwl_host_cmd cmd = {
1036bfcc09ddSBjoern A. Zeeb .id = BEACON_TEMPLATE_CMD,
1037bfcc09ddSBjoern A. Zeeb .flags = CMD_ASYNC,
1038bfcc09ddSBjoern A. Zeeb };
1039bfcc09ddSBjoern A. Zeeb
1040bfcc09ddSBjoern A. Zeeb cmd.len[0] = len;
1041bfcc09ddSBjoern A. Zeeb cmd.data[0] = data;
1042bfcc09ddSBjoern A. Zeeb cmd.dataflags[0] = 0;
1043bfcc09ddSBjoern A. Zeeb cmd.len[1] = beacon->len;
1044bfcc09ddSBjoern A. Zeeb cmd.data[1] = beacon->data;
1045bfcc09ddSBjoern A. Zeeb cmd.dataflags[1] = IWL_HCMD_DFL_DUP;
1046bfcc09ddSBjoern A. Zeeb
1047bfcc09ddSBjoern A. Zeeb return iwl_mvm_send_cmd(mvm, &cmd);
1048bfcc09ddSBjoern A. Zeeb }
1049bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_send_beacon_v6(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct sk_buff * beacon)1050bfcc09ddSBjoern A. Zeeb static int iwl_mvm_mac_ctxt_send_beacon_v6(struct iwl_mvm *mvm,
1051bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif,
1052bfcc09ddSBjoern A. Zeeb struct sk_buff *beacon)
1053bfcc09ddSBjoern A. Zeeb {
1054bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1055bfcc09ddSBjoern A. Zeeb struct iwl_mac_beacon_cmd_v6 beacon_cmd = {};
1056bfcc09ddSBjoern A. Zeeb
1057bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_ctxt_set_tx(mvm, vif, beacon, &beacon_cmd.tx);
1058bfcc09ddSBjoern A. Zeeb
1059bfcc09ddSBjoern A. Zeeb beacon_cmd.template_id = cpu_to_le32((u32)mvmvif->id);
1060bfcc09ddSBjoern A. Zeeb
1061bfcc09ddSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_AP)
1062bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd.tim_idx,
1063bfcc09ddSBjoern A. Zeeb &beacon_cmd.tim_size,
1064bfcc09ddSBjoern A. Zeeb beacon->data, beacon->len);
1065bfcc09ddSBjoern A. Zeeb
1066bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_send_beacon_cmd(mvm, beacon, &beacon_cmd,
1067bfcc09ddSBjoern A. Zeeb sizeof(beacon_cmd));
1068bfcc09ddSBjoern A. Zeeb }
1069bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_send_beacon_v7(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct sk_buff * beacon)1070bfcc09ddSBjoern A. Zeeb static int iwl_mvm_mac_ctxt_send_beacon_v7(struct iwl_mvm *mvm,
1071bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif,
1072bfcc09ddSBjoern A. Zeeb struct sk_buff *beacon)
1073bfcc09ddSBjoern A. Zeeb {
1074bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1075bfcc09ddSBjoern A. Zeeb struct iwl_mac_beacon_cmd_v7 beacon_cmd = {};
1076bfcc09ddSBjoern A. Zeeb
1077bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_ctxt_set_tx(mvm, vif, beacon, &beacon_cmd.tx);
1078bfcc09ddSBjoern A. Zeeb
1079bfcc09ddSBjoern A. Zeeb beacon_cmd.template_id = cpu_to_le32((u32)mvmvif->id);
1080bfcc09ddSBjoern A. Zeeb
1081bfcc09ddSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_AP)
1082bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd.tim_idx,
1083bfcc09ddSBjoern A. Zeeb &beacon_cmd.tim_size,
1084bfcc09ddSBjoern A. Zeeb beacon->data, beacon->len);
1085bfcc09ddSBjoern A. Zeeb
1086bfcc09ddSBjoern A. Zeeb beacon_cmd.csa_offset =
1087bfcc09ddSBjoern A. Zeeb cpu_to_le32(iwl_mvm_find_ie_offset(beacon->data,
1088bfcc09ddSBjoern A. Zeeb WLAN_EID_CHANNEL_SWITCH,
1089bfcc09ddSBjoern A. Zeeb beacon->len));
1090bfcc09ddSBjoern A. Zeeb beacon_cmd.ecsa_offset =
1091bfcc09ddSBjoern A. Zeeb cpu_to_le32(iwl_mvm_find_ie_offset(beacon->data,
1092bfcc09ddSBjoern A. Zeeb WLAN_EID_EXT_CHANSWITCH_ANN,
1093bfcc09ddSBjoern A. Zeeb beacon->len));
1094bfcc09ddSBjoern A. Zeeb
1095bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_send_beacon_cmd(mvm, beacon, &beacon_cmd,
1096bfcc09ddSBjoern A. Zeeb sizeof(beacon_cmd));
1097bfcc09ddSBjoern A. Zeeb }
1098bfcc09ddSBjoern A. Zeeb
iwl_mvm_enable_fils(struct iwl_mvm * mvm,struct ieee80211_chanctx_conf * ctx)1099a4128aadSBjoern A. Zeeb bool iwl_mvm_enable_fils(struct iwl_mvm *mvm,
1100a4128aadSBjoern A. Zeeb struct ieee80211_chanctx_conf *ctx)
1101a4128aadSBjoern A. Zeeb {
1102a4128aadSBjoern A. Zeeb if (IWL_MVM_DISABLE_AP_FILS)
1103a4128aadSBjoern A. Zeeb return false;
1104a4128aadSBjoern A. Zeeb
1105a4128aadSBjoern A. Zeeb if (cfg80211_channel_is_psc(ctx->def.chan))
1106a4128aadSBjoern A. Zeeb return true;
1107a4128aadSBjoern A. Zeeb
1108a4128aadSBjoern A. Zeeb return (ctx->def.chan->band == NL80211_BAND_6GHZ &&
1109a4128aadSBjoern A. Zeeb ctx->def.width >= NL80211_CHAN_WIDTH_80);
1110a4128aadSBjoern A. Zeeb }
1111a4128aadSBjoern A. Zeeb
iwl_mvm_mac_ctxt_send_beacon_v9(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct sk_buff * beacon,struct ieee80211_bss_conf * link_conf)1112bfcc09ddSBjoern A. Zeeb static int iwl_mvm_mac_ctxt_send_beacon_v9(struct iwl_mvm *mvm,
1113bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif,
11149af1bba4SBjoern A. Zeeb struct sk_buff *beacon,
11159af1bba4SBjoern A. Zeeb struct ieee80211_bss_conf *link_conf)
1116bfcc09ddSBjoern A. Zeeb {
1117bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1118bfcc09ddSBjoern A. Zeeb struct ieee80211_tx_info *info = IEEE80211_SKB_CB(beacon);
1119bfcc09ddSBjoern A. Zeeb struct iwl_mac_beacon_cmd beacon_cmd = {};
11209af1bba4SBjoern A. Zeeb u8 rate = iwl_mvm_mac_ctxt_get_beacon_rate(mvm, info, vif);
1121bfcc09ddSBjoern A. Zeeb u16 flags;
1122bfcc09ddSBjoern A. Zeeb struct ieee80211_chanctx_conf *ctx;
1123bfcc09ddSBjoern A. Zeeb int channel;
1124bfcc09ddSBjoern A. Zeeb flags = iwl_mvm_mac_ctxt_get_beacon_flags(mvm->fw, rate);
1125bfcc09ddSBjoern A. Zeeb
1126bfcc09ddSBjoern A. Zeeb /* Enable FILS on PSC channels only */
1127bfcc09ddSBjoern A. Zeeb rcu_read_lock();
11289af1bba4SBjoern A. Zeeb ctx = rcu_dereference(link_conf->chanctx_conf);
1129bfcc09ddSBjoern A. Zeeb channel = ieee80211_frequency_to_channel(ctx->def.chan->center_freq);
1130bfcc09ddSBjoern A. Zeeb WARN_ON(channel == 0);
1131a4128aadSBjoern A. Zeeb if (iwl_mvm_enable_fils(mvm, ctx)) {
1132d9836fb4SBjoern A. Zeeb flags |= iwl_fw_lookup_cmd_ver(mvm->fw, BEACON_TEMPLATE_CMD,
1133bfcc09ddSBjoern A. Zeeb 0) > 10 ?
1134bfcc09ddSBjoern A. Zeeb IWL_MAC_BEACON_FILS :
1135bfcc09ddSBjoern A. Zeeb IWL_MAC_BEACON_FILS_V1;
1136bfcc09ddSBjoern A. Zeeb beacon_cmd.short_ssid =
11379af1bba4SBjoern A. Zeeb cpu_to_le32(~crc32_le(~0, vif->cfg.ssid,
11389af1bba4SBjoern A. Zeeb vif->cfg.ssid_len));
1139bfcc09ddSBjoern A. Zeeb }
1140bfcc09ddSBjoern A. Zeeb rcu_read_unlock();
1141bfcc09ddSBjoern A. Zeeb
1142bfcc09ddSBjoern A. Zeeb beacon_cmd.flags = cpu_to_le16(flags);
1143bfcc09ddSBjoern A. Zeeb beacon_cmd.byte_cnt = cpu_to_le16((u16)beacon->len);
11449af1bba4SBjoern A. Zeeb
11459af1bba4SBjoern A. Zeeb if (WARN_ON(!mvmvif->link[link_conf->link_id]))
11469af1bba4SBjoern A. Zeeb return -EINVAL;
11479af1bba4SBjoern A. Zeeb
11489af1bba4SBjoern A. Zeeb if (iwl_fw_lookup_cmd_ver(mvm->fw, BEACON_TEMPLATE_CMD, 0) > 12)
11499af1bba4SBjoern A. Zeeb beacon_cmd.link_id =
11509af1bba4SBjoern A. Zeeb cpu_to_le32(mvmvif->link[link_conf->link_id]->fw_link_id);
11519af1bba4SBjoern A. Zeeb else
11529af1bba4SBjoern A. Zeeb beacon_cmd.link_id = cpu_to_le32((u32)mvmvif->id);
1153bfcc09ddSBjoern A. Zeeb
1154bfcc09ddSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_AP)
1155bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd.tim_idx,
1156bfcc09ddSBjoern A. Zeeb &beacon_cmd.tim_size,
1157bfcc09ddSBjoern A. Zeeb beacon->data, beacon->len);
1158bfcc09ddSBjoern A. Zeeb
1159bfcc09ddSBjoern A. Zeeb beacon_cmd.csa_offset =
1160bfcc09ddSBjoern A. Zeeb cpu_to_le32(iwl_mvm_find_ie_offset(beacon->data,
1161bfcc09ddSBjoern A. Zeeb WLAN_EID_CHANNEL_SWITCH,
1162bfcc09ddSBjoern A. Zeeb beacon->len));
1163bfcc09ddSBjoern A. Zeeb beacon_cmd.ecsa_offset =
1164bfcc09ddSBjoern A. Zeeb cpu_to_le32(iwl_mvm_find_ie_offset(beacon->data,
1165bfcc09ddSBjoern A. Zeeb WLAN_EID_EXT_CHANSWITCH_ANN,
1166bfcc09ddSBjoern A. Zeeb beacon->len));
1167bfcc09ddSBjoern A. Zeeb
1168a4128aadSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_AP &&
1169a4128aadSBjoern A. Zeeb iwl_fw_lookup_cmd_ver(mvm->fw, BEACON_TEMPLATE_CMD, 0) >= 14)
1170a4128aadSBjoern A. Zeeb beacon_cmd.btwt_offset =
1171a4128aadSBjoern A. Zeeb cpu_to_le32(iwl_mvm_find_ie_offset(beacon->data,
1172a4128aadSBjoern A. Zeeb WLAN_EID_S1G_TWT,
1173a4128aadSBjoern A. Zeeb beacon->len));
1174a4128aadSBjoern A. Zeeb
1175bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_send_beacon_cmd(mvm, beacon, &beacon_cmd,
1176bfcc09ddSBjoern A. Zeeb sizeof(beacon_cmd));
1177bfcc09ddSBjoern A. Zeeb }
1178bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_send_beacon(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct sk_buff * beacon,struct ieee80211_bss_conf * link_conf)11799af1bba4SBjoern A. Zeeb static int iwl_mvm_mac_ctxt_send_beacon(struct iwl_mvm *mvm,
1180bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif,
11819af1bba4SBjoern A. Zeeb struct sk_buff *beacon,
11829af1bba4SBjoern A. Zeeb struct ieee80211_bss_conf *link_conf)
1183bfcc09ddSBjoern A. Zeeb {
1184bfcc09ddSBjoern A. Zeeb if (WARN_ON(!beacon))
1185bfcc09ddSBjoern A. Zeeb return -EINVAL;
1186bfcc09ddSBjoern A. Zeeb
1187bfcc09ddSBjoern A. Zeeb if (IWL_MVM_NON_TRANSMITTING_AP)
1188bfcc09ddSBjoern A. Zeeb return 0;
1189bfcc09ddSBjoern A. Zeeb
1190bfcc09ddSBjoern A. Zeeb if (!fw_has_capa(&mvm->fw->ucode_capa,
1191bfcc09ddSBjoern A. Zeeb IWL_UCODE_TLV_CAPA_CSA_AND_TBTT_OFFLOAD))
1192bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_send_beacon_v6(mvm, vif, beacon);
1193bfcc09ddSBjoern A. Zeeb
1194bfcc09ddSBjoern A. Zeeb if (fw_has_api(&mvm->fw->ucode_capa,
1195bfcc09ddSBjoern A. Zeeb IWL_UCODE_TLV_API_NEW_BEACON_TEMPLATE))
11969af1bba4SBjoern A. Zeeb return iwl_mvm_mac_ctxt_send_beacon_v9(mvm, vif, beacon,
11979af1bba4SBjoern A. Zeeb link_conf);
1198bfcc09ddSBjoern A. Zeeb
1199bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_send_beacon_v7(mvm, vif, beacon);
1200bfcc09ddSBjoern A. Zeeb }
1201bfcc09ddSBjoern A. Zeeb
1202bfcc09ddSBjoern A. Zeeb /* The beacon template for the AP/GO/IBSS has changed and needs update */
iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)1203bfcc09ddSBjoern A. Zeeb int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm,
12049af1bba4SBjoern A. Zeeb struct ieee80211_vif *vif,
12059af1bba4SBjoern A. Zeeb struct ieee80211_bss_conf *link_conf)
1206bfcc09ddSBjoern A. Zeeb {
1207bfcc09ddSBjoern A. Zeeb struct sk_buff *beacon;
1208bfcc09ddSBjoern A. Zeeb int ret;
1209bfcc09ddSBjoern A. Zeeb
1210bfcc09ddSBjoern A. Zeeb WARN_ON(vif->type != NL80211_IFTYPE_AP &&
1211bfcc09ddSBjoern A. Zeeb vif->type != NL80211_IFTYPE_ADHOC);
1212bfcc09ddSBjoern A. Zeeb
12139af1bba4SBjoern A. Zeeb beacon = ieee80211_beacon_get_template(mvm->hw, vif, NULL,
12149af1bba4SBjoern A. Zeeb link_conf->link_id);
1215bfcc09ddSBjoern A. Zeeb if (!beacon)
1216bfcc09ddSBjoern A. Zeeb return -ENOMEM;
1217bfcc09ddSBjoern A. Zeeb
1218bfcc09ddSBjoern A. Zeeb #ifdef CONFIG_IWLWIFI_DEBUGFS
1219bfcc09ddSBjoern A. Zeeb if (mvm->beacon_inject_active) {
1220bfcc09ddSBjoern A. Zeeb dev_kfree_skb(beacon);
1221bfcc09ddSBjoern A. Zeeb return -EBUSY;
1222bfcc09ddSBjoern A. Zeeb }
1223bfcc09ddSBjoern A. Zeeb #endif
1224bfcc09ddSBjoern A. Zeeb
12259af1bba4SBjoern A. Zeeb ret = iwl_mvm_mac_ctxt_send_beacon(mvm, vif, beacon, link_conf);
1226bfcc09ddSBjoern A. Zeeb dev_kfree_skb(beacon);
1227bfcc09ddSBjoern A. Zeeb return ret;
1228bfcc09ddSBjoern A. Zeeb }
1229bfcc09ddSBjoern A. Zeeb
1230bfcc09ddSBjoern A. Zeeb struct iwl_mvm_mac_ap_iterator_data {
1231bfcc09ddSBjoern A. Zeeb struct iwl_mvm *mvm;
1232bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif;
1233bfcc09ddSBjoern A. Zeeb u32 beacon_device_ts;
1234bfcc09ddSBjoern A. Zeeb u16 beacon_int;
1235bfcc09ddSBjoern A. Zeeb };
1236bfcc09ddSBjoern A. Zeeb
1237bfcc09ddSBjoern A. Zeeb /* Find the beacon_device_ts and beacon_int for a managed interface */
iwl_mvm_mac_ap_iterator(void * _data,u8 * mac,struct ieee80211_vif * vif)1238bfcc09ddSBjoern A. Zeeb static void iwl_mvm_mac_ap_iterator(void *_data, u8 *mac,
1239bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif)
1240bfcc09ddSBjoern A. Zeeb {
1241bfcc09ddSBjoern A. Zeeb struct iwl_mvm_mac_ap_iterator_data *data = _data;
1242bfcc09ddSBjoern A. Zeeb
12439af1bba4SBjoern A. Zeeb if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc)
1244bfcc09ddSBjoern A. Zeeb return;
1245bfcc09ddSBjoern A. Zeeb
1246bfcc09ddSBjoern A. Zeeb /* Station client has higher priority over P2P client*/
1247bfcc09ddSBjoern A. Zeeb if (vif->p2p && data->beacon_device_ts)
1248bfcc09ddSBjoern A. Zeeb return;
1249bfcc09ddSBjoern A. Zeeb
1250bfcc09ddSBjoern A. Zeeb data->beacon_device_ts = vif->bss_conf.sync_device_ts;
1251bfcc09ddSBjoern A. Zeeb data->beacon_int = vif->bss_conf.beacon_int;
1252bfcc09ddSBjoern A. Zeeb }
1253bfcc09ddSBjoern A. Zeeb
1254bfcc09ddSBjoern A. Zeeb /*
12559af1bba4SBjoern A. Zeeb * Fill the filter flags for mac context of type AP or P2P GO.
12569af1bba4SBjoern A. Zeeb */
iwl_mvm_mac_ctxt_cmd_ap_set_filter_flags(struct iwl_mvm * mvm,struct iwl_mvm_vif * mvmvif,__le32 * filter_flags,int accept_probe_req_flag,int accept_beacon_flag)12579af1bba4SBjoern A. Zeeb void iwl_mvm_mac_ctxt_cmd_ap_set_filter_flags(struct iwl_mvm *mvm,
12589af1bba4SBjoern A. Zeeb struct iwl_mvm_vif *mvmvif,
12599af1bba4SBjoern A. Zeeb __le32 *filter_flags,
12609af1bba4SBjoern A. Zeeb int accept_probe_req_flag,
12619af1bba4SBjoern A. Zeeb int accept_beacon_flag)
12629af1bba4SBjoern A. Zeeb {
12639af1bba4SBjoern A. Zeeb /*
12649af1bba4SBjoern A. Zeeb * in AP mode, pass probe requests and beacons from other APs
12659af1bba4SBjoern A. Zeeb * (needed for ht protection); when there're no any associated
12669af1bba4SBjoern A. Zeeb * station don't ask FW to pass beacons to prevent unnecessary
12679af1bba4SBjoern A. Zeeb * wake-ups.
12689af1bba4SBjoern A. Zeeb */
12699af1bba4SBjoern A. Zeeb *filter_flags |= cpu_to_le32(accept_probe_req_flag);
12709af1bba4SBjoern A. Zeeb if (mvmvif->ap_assoc_sta_count || !mvm->drop_bcn_ap_mode) {
12719af1bba4SBjoern A. Zeeb *filter_flags |= cpu_to_le32(accept_beacon_flag);
12729af1bba4SBjoern A. Zeeb IWL_DEBUG_HC(mvm, "Asking FW to pass beacons\n");
12739af1bba4SBjoern A. Zeeb } else {
12749af1bba4SBjoern A. Zeeb IWL_DEBUG_HC(mvm, "No need to receive beacons\n");
12759af1bba4SBjoern A. Zeeb }
12769af1bba4SBjoern A. Zeeb }
12779af1bba4SBjoern A. Zeeb
12789af1bba4SBjoern A. Zeeb /*
1279bfcc09ddSBjoern A. Zeeb * Fill the specific data for mac context of type AP of P2P GO
1280bfcc09ddSBjoern A. Zeeb */
iwl_mvm_mac_ctxt_cmd_fill_ap(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct iwl_mac_ctx_cmd * cmd,struct iwl_mac_data_ap * ctxt_ap,bool add)1281bfcc09ddSBjoern A. Zeeb static void iwl_mvm_mac_ctxt_cmd_fill_ap(struct iwl_mvm *mvm,
1282bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif,
1283bfcc09ddSBjoern A. Zeeb struct iwl_mac_ctx_cmd *cmd,
1284bfcc09ddSBjoern A. Zeeb struct iwl_mac_data_ap *ctxt_ap,
1285bfcc09ddSBjoern A. Zeeb bool add)
1286bfcc09ddSBjoern A. Zeeb {
1287bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1288bfcc09ddSBjoern A. Zeeb struct iwl_mvm_mac_ap_iterator_data data = {
1289bfcc09ddSBjoern A. Zeeb .mvm = mvm,
1290bfcc09ddSBjoern A. Zeeb .vif = vif,
1291bfcc09ddSBjoern A. Zeeb .beacon_device_ts = 0
1292bfcc09ddSBjoern A. Zeeb };
1293bfcc09ddSBjoern A. Zeeb
1294bfcc09ddSBjoern A. Zeeb /* in AP mode, the MCAST FIFO takes the EDCA params from VO */
1295bfcc09ddSBjoern A. Zeeb cmd->ac[IWL_MVM_TX_FIFO_VO].fifos_mask |= BIT(IWL_MVM_TX_FIFO_MCAST);
1296bfcc09ddSBjoern A. Zeeb
12979af1bba4SBjoern A. Zeeb iwl_mvm_mac_ctxt_cmd_ap_set_filter_flags(mvm, mvmvif,
12989af1bba4SBjoern A. Zeeb &cmd->filter_flags,
12999af1bba4SBjoern A. Zeeb MAC_FILTER_IN_PROBE_REQUEST,
13009af1bba4SBjoern A. Zeeb MAC_FILTER_IN_BEACON);
1301bfcc09ddSBjoern A. Zeeb
1302bfcc09ddSBjoern A. Zeeb ctxt_ap->bi = cpu_to_le32(vif->bss_conf.beacon_int);
1303bfcc09ddSBjoern A. Zeeb ctxt_ap->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
1304bfcc09ddSBjoern A. Zeeb vif->bss_conf.dtim_period);
1305bfcc09ddSBjoern A. Zeeb
1306bfcc09ddSBjoern A. Zeeb if (!fw_has_api(&mvm->fw->ucode_capa,
1307bfcc09ddSBjoern A. Zeeb IWL_UCODE_TLV_API_STA_TYPE))
13089af1bba4SBjoern A. Zeeb ctxt_ap->mcast_qid = cpu_to_le32(mvmvif->deflink.cab_queue);
1309bfcc09ddSBjoern A. Zeeb
1310bfcc09ddSBjoern A. Zeeb /*
1311bfcc09ddSBjoern A. Zeeb * Only set the beacon time when the MAC is being added, when we
1312bfcc09ddSBjoern A. Zeeb * just modify the MAC then we should keep the time -- the firmware
1313bfcc09ddSBjoern A. Zeeb * can otherwise have a "jumping" TBTT.
1314bfcc09ddSBjoern A. Zeeb */
1315bfcc09ddSBjoern A. Zeeb if (add) {
1316bfcc09ddSBjoern A. Zeeb /*
1317bfcc09ddSBjoern A. Zeeb * If there is a station/P2P client interface which is
1318bfcc09ddSBjoern A. Zeeb * associated, set the AP's TBTT far enough from the station's
1319bfcc09ddSBjoern A. Zeeb * TBTT. Otherwise, set it to the current system time
1320bfcc09ddSBjoern A. Zeeb */
1321bfcc09ddSBjoern A. Zeeb ieee80211_iterate_active_interfaces_atomic(
1322bfcc09ddSBjoern A. Zeeb mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1323bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_ap_iterator, &data);
1324bfcc09ddSBjoern A. Zeeb
1325bfcc09ddSBjoern A. Zeeb if (data.beacon_device_ts) {
13269af1bba4SBjoern A. Zeeb u32 rand = get_random_u32_inclusive(36, 63);
1327bfcc09ddSBjoern A. Zeeb mvmvif->ap_beacon_time = data.beacon_device_ts +
1328bfcc09ddSBjoern A. Zeeb ieee80211_tu_to_usec(data.beacon_int * rand /
1329bfcc09ddSBjoern A. Zeeb 100);
1330bfcc09ddSBjoern A. Zeeb } else {
1331bfcc09ddSBjoern A. Zeeb mvmvif->ap_beacon_time = iwl_mvm_get_systime(mvm);
1332bfcc09ddSBjoern A. Zeeb }
1333bfcc09ddSBjoern A. Zeeb }
1334bfcc09ddSBjoern A. Zeeb
1335bfcc09ddSBjoern A. Zeeb ctxt_ap->beacon_time = cpu_to_le32(mvmvif->ap_beacon_time);
1336bfcc09ddSBjoern A. Zeeb ctxt_ap->beacon_tsf = 0; /* unused */
1337bfcc09ddSBjoern A. Zeeb
1338bfcc09ddSBjoern A. Zeeb /* TODO: Assume that the beacon id == mac context id */
1339bfcc09ddSBjoern A. Zeeb ctxt_ap->beacon_template = cpu_to_le32(mvmvif->id);
1340bfcc09ddSBjoern A. Zeeb }
1341bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_cmd_ap(struct iwl_mvm * mvm,struct ieee80211_vif * vif,u32 action)1342bfcc09ddSBjoern A. Zeeb static int iwl_mvm_mac_ctxt_cmd_ap(struct iwl_mvm *mvm,
1343bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif,
1344bfcc09ddSBjoern A. Zeeb u32 action)
1345bfcc09ddSBjoern A. Zeeb {
1346bfcc09ddSBjoern A. Zeeb struct iwl_mac_ctx_cmd cmd = {};
1347bfcc09ddSBjoern A. Zeeb
1348bfcc09ddSBjoern A. Zeeb WARN_ON(vif->type != NL80211_IFTYPE_AP || vif->p2p);
1349bfcc09ddSBjoern A. Zeeb
1350bfcc09ddSBjoern A. Zeeb /* Fill the common data for all mac context types */
1351bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
1352bfcc09ddSBjoern A. Zeeb
1353bfcc09ddSBjoern A. Zeeb /* Fill the data specific for ap mode */
1354bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd, &cmd.ap,
1355bfcc09ddSBjoern A. Zeeb action == FW_CTXT_ACTION_ADD);
1356bfcc09ddSBjoern A. Zeeb
1357bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1358bfcc09ddSBjoern A. Zeeb }
1359bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_cmd_go(struct iwl_mvm * mvm,struct ieee80211_vif * vif,u32 action)1360bfcc09ddSBjoern A. Zeeb static int iwl_mvm_mac_ctxt_cmd_go(struct iwl_mvm *mvm,
1361bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif,
1362bfcc09ddSBjoern A. Zeeb u32 action)
1363bfcc09ddSBjoern A. Zeeb {
1364bfcc09ddSBjoern A. Zeeb struct iwl_mac_ctx_cmd cmd = {};
1365bfcc09ddSBjoern A. Zeeb struct ieee80211_p2p_noa_attr *noa = &vif->bss_conf.p2p_noa_attr;
1366bfcc09ddSBjoern A. Zeeb
1367bfcc09ddSBjoern A. Zeeb WARN_ON(vif->type != NL80211_IFTYPE_AP || !vif->p2p);
1368bfcc09ddSBjoern A. Zeeb
1369bfcc09ddSBjoern A. Zeeb /* Fill the common data for all mac context types */
1370bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
1371bfcc09ddSBjoern A. Zeeb
1372bfcc09ddSBjoern A. Zeeb /* Fill the data specific for GO mode */
1373bfcc09ddSBjoern A. Zeeb iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd, &cmd.go.ap,
1374bfcc09ddSBjoern A. Zeeb action == FW_CTXT_ACTION_ADD);
1375bfcc09ddSBjoern A. Zeeb
1376bfcc09ddSBjoern A. Zeeb cmd.go.ctwin = cpu_to_le32(noa->oppps_ctwindow &
1377bfcc09ddSBjoern A. Zeeb IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
1378bfcc09ddSBjoern A. Zeeb cmd.go.opp_ps_enabled =
1379bfcc09ddSBjoern A. Zeeb cpu_to_le32(!!(noa->oppps_ctwindow &
1380bfcc09ddSBjoern A. Zeeb IEEE80211_P2P_OPPPS_ENABLE_BIT));
1381bfcc09ddSBjoern A. Zeeb
1382bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1383bfcc09ddSBjoern A. Zeeb }
1384bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctx_send(struct iwl_mvm * mvm,struct ieee80211_vif * vif,u32 action,bool force_assoc_off,const u8 * bssid_override)1385bfcc09ddSBjoern A. Zeeb static int iwl_mvm_mac_ctx_send(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1386bfcc09ddSBjoern A. Zeeb u32 action, bool force_assoc_off,
1387bfcc09ddSBjoern A. Zeeb const u8 *bssid_override)
1388bfcc09ddSBjoern A. Zeeb {
1389bfcc09ddSBjoern A. Zeeb switch (vif->type) {
1390bfcc09ddSBjoern A. Zeeb case NL80211_IFTYPE_STATION:
1391bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_cmd_sta(mvm, vif, action,
1392bfcc09ddSBjoern A. Zeeb force_assoc_off,
1393bfcc09ddSBjoern A. Zeeb bssid_override);
1394bfcc09ddSBjoern A. Zeeb case NL80211_IFTYPE_AP:
1395bfcc09ddSBjoern A. Zeeb if (!vif->p2p)
1396bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_cmd_ap(mvm, vif, action);
1397bfcc09ddSBjoern A. Zeeb else
1398bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_cmd_go(mvm, vif, action);
1399bfcc09ddSBjoern A. Zeeb case NL80211_IFTYPE_MONITOR:
1400bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_cmd_listener(mvm, vif, action);
1401bfcc09ddSBjoern A. Zeeb case NL80211_IFTYPE_P2P_DEVICE:
1402bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_cmd_p2p_device(mvm, vif, action);
1403bfcc09ddSBjoern A. Zeeb case NL80211_IFTYPE_ADHOC:
1404bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctxt_cmd_ibss(mvm, vif, action);
1405bfcc09ddSBjoern A. Zeeb default:
1406bfcc09ddSBjoern A. Zeeb break;
1407bfcc09ddSBjoern A. Zeeb }
1408bfcc09ddSBjoern A. Zeeb
1409bfcc09ddSBjoern A. Zeeb return -EOPNOTSUPP;
1410bfcc09ddSBjoern A. Zeeb }
1411bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_add(struct iwl_mvm * mvm,struct ieee80211_vif * vif)1412bfcc09ddSBjoern A. Zeeb int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1413bfcc09ddSBjoern A. Zeeb {
1414bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1415bfcc09ddSBjoern A. Zeeb int ret;
1416bfcc09ddSBjoern A. Zeeb
1417bfcc09ddSBjoern A. Zeeb if (WARN_ONCE(mvmvif->uploaded, "Adding active MAC %pM/%d\n",
1418bfcc09ddSBjoern A. Zeeb vif->addr, ieee80211_vif_type_p2p(vif)))
1419bfcc09ddSBjoern A. Zeeb return -EIO;
1420bfcc09ddSBjoern A. Zeeb
1421bfcc09ddSBjoern A. Zeeb ret = iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_ADD,
1422bfcc09ddSBjoern A. Zeeb true, NULL);
1423bfcc09ddSBjoern A. Zeeb if (ret)
1424bfcc09ddSBjoern A. Zeeb return ret;
1425bfcc09ddSBjoern A. Zeeb
1426bfcc09ddSBjoern A. Zeeb /* will only do anything at resume from D3 time */
1427bfcc09ddSBjoern A. Zeeb iwl_mvm_set_last_nonqos_seq(mvm, vif);
1428bfcc09ddSBjoern A. Zeeb
1429bfcc09ddSBjoern A. Zeeb mvmvif->uploaded = true;
1430bfcc09ddSBjoern A. Zeeb return 0;
1431bfcc09ddSBjoern A. Zeeb }
1432bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_changed(struct iwl_mvm * mvm,struct ieee80211_vif * vif,bool force_assoc_off,const u8 * bssid_override)1433bfcc09ddSBjoern A. Zeeb int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1434bfcc09ddSBjoern A. Zeeb bool force_assoc_off, const u8 *bssid_override)
1435bfcc09ddSBjoern A. Zeeb {
1436bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1437bfcc09ddSBjoern A. Zeeb
1438bfcc09ddSBjoern A. Zeeb if (WARN_ONCE(!mvmvif->uploaded, "Changing inactive MAC %pM/%d\n",
1439bfcc09ddSBjoern A. Zeeb vif->addr, ieee80211_vif_type_p2p(vif)))
1440bfcc09ddSBjoern A. Zeeb return -EIO;
1441bfcc09ddSBjoern A. Zeeb
1442bfcc09ddSBjoern A. Zeeb return iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_MODIFY,
1443bfcc09ddSBjoern A. Zeeb force_assoc_off, bssid_override);
1444bfcc09ddSBjoern A. Zeeb }
1445bfcc09ddSBjoern A. Zeeb
iwl_mvm_mac_ctxt_remove(struct iwl_mvm * mvm,struct ieee80211_vif * vif)1446bfcc09ddSBjoern A. Zeeb int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1447bfcc09ddSBjoern A. Zeeb {
1448bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1449bfcc09ddSBjoern A. Zeeb struct iwl_mac_ctx_cmd cmd;
1450bfcc09ddSBjoern A. Zeeb int ret;
1451bfcc09ddSBjoern A. Zeeb
1452bfcc09ddSBjoern A. Zeeb if (WARN_ONCE(!mvmvif->uploaded, "Removing inactive MAC %pM/%d\n",
1453bfcc09ddSBjoern A. Zeeb vif->addr, ieee80211_vif_type_p2p(vif)))
1454bfcc09ddSBjoern A. Zeeb return -EIO;
1455bfcc09ddSBjoern A. Zeeb
1456bfcc09ddSBjoern A. Zeeb memset(&cmd, 0, sizeof(cmd));
1457bfcc09ddSBjoern A. Zeeb
1458bfcc09ddSBjoern A. Zeeb cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1459bfcc09ddSBjoern A. Zeeb mvmvif->color));
1460bfcc09ddSBjoern A. Zeeb cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE);
1461bfcc09ddSBjoern A. Zeeb
14629af1bba4SBjoern A. Zeeb ret = iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
14639af1bba4SBjoern A. Zeeb if (ret)
1464bfcc09ddSBjoern A. Zeeb return ret;
1465bfcc09ddSBjoern A. Zeeb
1466bfcc09ddSBjoern A. Zeeb mvmvif->uploaded = false;
1467bfcc09ddSBjoern A. Zeeb
1468bfcc09ddSBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_MONITOR) {
1469bfcc09ddSBjoern A. Zeeb __clear_bit(IEEE80211_HW_RX_INCLUDES_FCS, mvm->hw->flags);
1470bfcc09ddSBjoern A. Zeeb iwl_mvm_dealloc_snif_sta(mvm);
1471bfcc09ddSBjoern A. Zeeb }
1472bfcc09ddSBjoern A. Zeeb
1473bfcc09ddSBjoern A. Zeeb return 0;
1474bfcc09ddSBjoern A. Zeeb }
1475bfcc09ddSBjoern A. Zeeb
iwl_mvm_csa_count_down(struct iwl_mvm * mvm,struct ieee80211_vif * csa_vif,u32 gp2,bool tx_success)1476bfcc09ddSBjoern A. Zeeb static void iwl_mvm_csa_count_down(struct iwl_mvm *mvm,
1477bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *csa_vif, u32 gp2,
1478bfcc09ddSBjoern A. Zeeb bool tx_success)
1479bfcc09ddSBjoern A. Zeeb {
1480bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif =
1481bfcc09ddSBjoern A. Zeeb iwl_mvm_vif_from_mac80211(csa_vif);
1482bfcc09ddSBjoern A. Zeeb
1483bfcc09ddSBjoern A. Zeeb /* Don't start to countdown from a failed beacon */
1484bfcc09ddSBjoern A. Zeeb if (!tx_success && !mvmvif->csa_countdown)
1485bfcc09ddSBjoern A. Zeeb return;
1486bfcc09ddSBjoern A. Zeeb
1487bfcc09ddSBjoern A. Zeeb mvmvif->csa_countdown = true;
1488bfcc09ddSBjoern A. Zeeb
1489a4128aadSBjoern A. Zeeb if (!ieee80211_beacon_cntdwn_is_complete(csa_vif, 0)) {
1490a4128aadSBjoern A. Zeeb int c = ieee80211_beacon_update_cntdwn(csa_vif, 0);
1491bfcc09ddSBjoern A. Zeeb
14929af1bba4SBjoern A. Zeeb iwl_mvm_mac_ctxt_beacon_changed(mvm, csa_vif,
14939af1bba4SBjoern A. Zeeb &csa_vif->bss_conf);
1494bfcc09ddSBjoern A. Zeeb if (csa_vif->p2p &&
1495bfcc09ddSBjoern A. Zeeb !iwl_mvm_te_scheduled(&mvmvif->time_event_data) && gp2 &&
1496bfcc09ddSBjoern A. Zeeb tx_success) {
1497bfcc09ddSBjoern A. Zeeb u32 rel_time = (c + 1) *
1498bfcc09ddSBjoern A. Zeeb csa_vif->bss_conf.beacon_int -
1499bfcc09ddSBjoern A. Zeeb IWL_MVM_CHANNEL_SWITCH_TIME_GO;
1500bfcc09ddSBjoern A. Zeeb u32 apply_time = gp2 + rel_time * 1024;
1501bfcc09ddSBjoern A. Zeeb
1502bfcc09ddSBjoern A. Zeeb iwl_mvm_schedule_csa_period(mvm, csa_vif,
1503bfcc09ddSBjoern A. Zeeb IWL_MVM_CHANNEL_SWITCH_TIME_GO -
1504bfcc09ddSBjoern A. Zeeb IWL_MVM_CHANNEL_SWITCH_MARGIN,
1505bfcc09ddSBjoern A. Zeeb apply_time);
1506bfcc09ddSBjoern A. Zeeb }
1507bfcc09ddSBjoern A. Zeeb } else if (!iwl_mvm_te_scheduled(&mvmvif->time_event_data)) {
1508bfcc09ddSBjoern A. Zeeb /* we don't have CSA NoA scheduled yet, switch now */
1509a4128aadSBjoern A. Zeeb ieee80211_csa_finish(csa_vif, 0);
1510bfcc09ddSBjoern A. Zeeb RCU_INIT_POINTER(mvm->csa_vif, NULL);
1511bfcc09ddSBjoern A. Zeeb }
1512bfcc09ddSBjoern A. Zeeb }
1513bfcc09ddSBjoern A. Zeeb
iwl_mvm_rx_beacon_notif(struct iwl_mvm * mvm,struct iwl_rx_cmd_buffer * rxb)1514bfcc09ddSBjoern A. Zeeb void iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
1515bfcc09ddSBjoern A. Zeeb struct iwl_rx_cmd_buffer *rxb)
1516bfcc09ddSBjoern A. Zeeb {
1517bfcc09ddSBjoern A. Zeeb struct iwl_rx_packet *pkt = rxb_addr(rxb);
1518bfcc09ddSBjoern A. Zeeb unsigned int pkt_len = iwl_rx_packet_payload_len(pkt);
1519bfcc09ddSBjoern A. Zeeb struct iwl_extended_beacon_notif *beacon = (void *)pkt->data;
1520bfcc09ddSBjoern A. Zeeb struct iwl_extended_beacon_notif_v5 *beacon_v5 = (void *)pkt->data;
1521bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *csa_vif;
1522bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *tx_blocked_vif;
1523bfcc09ddSBjoern A. Zeeb struct agg_tx_status *agg_status;
1524bfcc09ddSBjoern A. Zeeb u16 status;
1525bfcc09ddSBjoern A. Zeeb
1526bfcc09ddSBjoern A. Zeeb lockdep_assert_held(&mvm->mutex);
1527bfcc09ddSBjoern A. Zeeb
1528bfcc09ddSBjoern A. Zeeb mvm->ap_last_beacon_gp2 = le32_to_cpu(beacon->gp2);
1529bfcc09ddSBjoern A. Zeeb
1530bfcc09ddSBjoern A. Zeeb if (!iwl_mvm_is_short_beacon_notif_supported(mvm)) {
1531bfcc09ddSBjoern A. Zeeb struct iwl_mvm_tx_resp *beacon_notify_hdr =
1532bfcc09ddSBjoern A. Zeeb &beacon_v5->beacon_notify_hdr;
1533bfcc09ddSBjoern A. Zeeb
1534bfcc09ddSBjoern A. Zeeb if (unlikely(pkt_len < sizeof(*beacon_v5)))
1535bfcc09ddSBjoern A. Zeeb return;
1536bfcc09ddSBjoern A. Zeeb
1537bfcc09ddSBjoern A. Zeeb mvm->ibss_manager = beacon_v5->ibss_mgr_status != 0;
1538bfcc09ddSBjoern A. Zeeb agg_status = iwl_mvm_get_agg_status(mvm, beacon_notify_hdr);
1539bfcc09ddSBjoern A. Zeeb status = le16_to_cpu(agg_status->status) & TX_STATUS_MSK;
1540bfcc09ddSBjoern A. Zeeb IWL_DEBUG_RX(mvm,
1541bfcc09ddSBjoern A. Zeeb "beacon status %#x retries:%d tsf:0x%016llX gp2:0x%X rate:%d\n",
1542bfcc09ddSBjoern A. Zeeb status, beacon_notify_hdr->failure_frame,
1543bfcc09ddSBjoern A. Zeeb le64_to_cpu(beacon->tsf),
1544bfcc09ddSBjoern A. Zeeb mvm->ap_last_beacon_gp2,
1545bfcc09ddSBjoern A. Zeeb le32_to_cpu(beacon_notify_hdr->initial_rate));
1546bfcc09ddSBjoern A. Zeeb } else {
1547bfcc09ddSBjoern A. Zeeb if (unlikely(pkt_len < sizeof(*beacon)))
1548bfcc09ddSBjoern A. Zeeb return;
1549bfcc09ddSBjoern A. Zeeb
1550bfcc09ddSBjoern A. Zeeb mvm->ibss_manager = beacon->ibss_mgr_status != 0;
1551bfcc09ddSBjoern A. Zeeb status = le32_to_cpu(beacon->status) & TX_STATUS_MSK;
1552bfcc09ddSBjoern A. Zeeb IWL_DEBUG_RX(mvm,
1553bfcc09ddSBjoern A. Zeeb "beacon status %#x tsf:0x%016llX gp2:0x%X\n",
1554bfcc09ddSBjoern A. Zeeb status, le64_to_cpu(beacon->tsf),
1555bfcc09ddSBjoern A. Zeeb mvm->ap_last_beacon_gp2);
1556bfcc09ddSBjoern A. Zeeb }
1557bfcc09ddSBjoern A. Zeeb
1558bfcc09ddSBjoern A. Zeeb csa_vif = rcu_dereference_protected(mvm->csa_vif,
1559bfcc09ddSBjoern A. Zeeb lockdep_is_held(&mvm->mutex));
15609af1bba4SBjoern A. Zeeb if (unlikely(csa_vif && csa_vif->bss_conf.csa_active))
1561bfcc09ddSBjoern A. Zeeb iwl_mvm_csa_count_down(mvm, csa_vif, mvm->ap_last_beacon_gp2,
1562bfcc09ddSBjoern A. Zeeb (status == TX_STATUS_SUCCESS));
1563bfcc09ddSBjoern A. Zeeb
1564bfcc09ddSBjoern A. Zeeb tx_blocked_vif = rcu_dereference_protected(mvm->csa_tx_blocked_vif,
1565bfcc09ddSBjoern A. Zeeb lockdep_is_held(&mvm->mutex));
1566bfcc09ddSBjoern A. Zeeb if (unlikely(tx_blocked_vif)) {
1567bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif =
1568bfcc09ddSBjoern A. Zeeb iwl_mvm_vif_from_mac80211(tx_blocked_vif);
1569bfcc09ddSBjoern A. Zeeb
1570bfcc09ddSBjoern A. Zeeb /*
1571bfcc09ddSBjoern A. Zeeb * The channel switch is started and we have blocked the
1572bfcc09ddSBjoern A. Zeeb * stations. If this is the first beacon (the timeout wasn't
1573bfcc09ddSBjoern A. Zeeb * set), set the unblock timeout, otherwise countdown
1574bfcc09ddSBjoern A. Zeeb */
1575bfcc09ddSBjoern A. Zeeb if (!mvm->csa_tx_block_bcn_timeout)
1576bfcc09ddSBjoern A. Zeeb mvm->csa_tx_block_bcn_timeout =
1577bfcc09ddSBjoern A. Zeeb IWL_MVM_CS_UNBLOCK_TX_TIMEOUT;
1578bfcc09ddSBjoern A. Zeeb else
1579bfcc09ddSBjoern A. Zeeb mvm->csa_tx_block_bcn_timeout--;
1580bfcc09ddSBjoern A. Zeeb
1581bfcc09ddSBjoern A. Zeeb /* Check if the timeout is expired, and unblock tx */
1582bfcc09ddSBjoern A. Zeeb if (mvm->csa_tx_block_bcn_timeout == 0) {
1583bfcc09ddSBjoern A. Zeeb iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false);
1584bfcc09ddSBjoern A. Zeeb RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
1585bfcc09ddSBjoern A. Zeeb }
1586bfcc09ddSBjoern A. Zeeb }
1587bfcc09ddSBjoern A. Zeeb }
1588bfcc09ddSBjoern A. Zeeb
iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm * mvm,struct iwl_rx_cmd_buffer * rxb)1589bfcc09ddSBjoern A. Zeeb void iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm,
1590bfcc09ddSBjoern A. Zeeb struct iwl_rx_cmd_buffer *rxb)
1591bfcc09ddSBjoern A. Zeeb {
1592bfcc09ddSBjoern A. Zeeb struct iwl_rx_packet *pkt = rxb_addr(rxb);
1593bfcc09ddSBjoern A. Zeeb struct iwl_missed_beacons_notif *mb = (void *)pkt->data;
1594bfcc09ddSBjoern A. Zeeb struct iwl_fw_dbg_trigger_missed_bcon *bcon_trig;
1595bfcc09ddSBjoern A. Zeeb struct iwl_fw_dbg_trigger_tlv *trigger;
1596bfcc09ddSBjoern A. Zeeb u32 stop_trig_missed_bcon, stop_trig_missed_bcon_since_rx;
1597bfcc09ddSBjoern A. Zeeb u32 rx_missed_bcon, rx_missed_bcon_since_rx;
1598bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif;
15999af1bba4SBjoern A. Zeeb /* Id can be mac/link id depending on the notification version */
16009af1bba4SBjoern A. Zeeb u32 id = le32_to_cpu(mb->link_id);
1601bfcc09ddSBjoern A. Zeeb union iwl_dbg_tlv_tp_data tp_data = { .fw_pkt = pkt };
16029af1bba4SBjoern A. Zeeb u32 mac_type;
1603a4128aadSBjoern A. Zeeb int link_id = -1;
16049af1bba4SBjoern A. Zeeb u8 notif_ver = iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,
16059af1bba4SBjoern A. Zeeb MISSED_BEACONS_NOTIFICATION,
16069af1bba4SBjoern A. Zeeb 0);
16079af1bba4SBjoern A. Zeeb
16089af1bba4SBjoern A. Zeeb /* before version four the ID in the notification refers to mac ID */
16099af1bba4SBjoern A. Zeeb if (notif_ver < 4) {
1610a4128aadSBjoern A. Zeeb vif = iwl_mvm_rcu_dereference_vif_id(mvm, id, false);
16119af1bba4SBjoern A. Zeeb } else {
16129af1bba4SBjoern A. Zeeb struct ieee80211_bss_conf *bss_conf =
1613a4128aadSBjoern A. Zeeb iwl_mvm_rcu_fw_link_id_to_link_conf(mvm, id, false);
16149af1bba4SBjoern A. Zeeb
16159af1bba4SBjoern A. Zeeb if (!bss_conf)
1616a4128aadSBjoern A. Zeeb return;
16179af1bba4SBjoern A. Zeeb
16189af1bba4SBjoern A. Zeeb vif = bss_conf->vif;
1619a4128aadSBjoern A. Zeeb link_id = bss_conf->link_id;
16209af1bba4SBjoern A. Zeeb }
1621bfcc09ddSBjoern A. Zeeb
1622bfcc09ddSBjoern A. Zeeb IWL_DEBUG_INFO(mvm,
16239af1bba4SBjoern A. Zeeb "missed bcn %s_id=%u, consecutive=%u (%u, %u, %u)\n",
16249af1bba4SBjoern A. Zeeb notif_ver < 4 ? "mac" : "link",
16259af1bba4SBjoern A. Zeeb id,
1626bfcc09ddSBjoern A. Zeeb le32_to_cpu(mb->consec_missed_beacons),
1627bfcc09ddSBjoern A. Zeeb le32_to_cpu(mb->consec_missed_beacons_since_last_rx),
1628bfcc09ddSBjoern A. Zeeb le32_to_cpu(mb->num_recvd_beacons),
1629bfcc09ddSBjoern A. Zeeb le32_to_cpu(mb->num_expected_beacons));
1630bfcc09ddSBjoern A. Zeeb
1631bfcc09ddSBjoern A. Zeeb if (!vif)
1632a4128aadSBjoern A. Zeeb return;
1633bfcc09ddSBjoern A. Zeeb
16349af1bba4SBjoern A. Zeeb mac_type = iwl_mvm_get_mac_type(vif);
16359af1bba4SBjoern A. Zeeb
16369af1bba4SBjoern A. Zeeb IWL_DEBUG_INFO(mvm, "missed beacon mac_type=%u,\n", mac_type);
16379af1bba4SBjoern A. Zeeb
16389af1bba4SBjoern A. Zeeb mvm->trans->dbg.dump_file_name_ext_valid = true;
16399af1bba4SBjoern A. Zeeb snprintf(mvm->trans->dbg.dump_file_name_ext, IWL_FW_INI_MAX_NAME,
16409af1bba4SBjoern A. Zeeb "MacId_%d_MacType_%d", id, mac_type);
16419af1bba4SBjoern A. Zeeb
1642bfcc09ddSBjoern A. Zeeb rx_missed_bcon = le32_to_cpu(mb->consec_missed_beacons);
1643bfcc09ddSBjoern A. Zeeb rx_missed_bcon_since_rx =
1644bfcc09ddSBjoern A. Zeeb le32_to_cpu(mb->consec_missed_beacons_since_last_rx);
1645bfcc09ddSBjoern A. Zeeb /*
1646bfcc09ddSBjoern A. Zeeb * TODO: the threshold should be adjusted based on latency conditions,
1647bfcc09ddSBjoern A. Zeeb * and/or in case of a CS flow on one of the other AP vifs.
1648bfcc09ddSBjoern A. Zeeb */
1649a4128aadSBjoern A. Zeeb if (rx_missed_bcon >= IWL_MVM_MISSED_BEACONS_THRESHOLD_LONG) {
1650a4128aadSBjoern A. Zeeb if (rx_missed_bcon_since_rx >= IWL_MVM_MISSED_BEACONS_SINCE_RX_THOLD) {
1651bfcc09ddSBjoern A. Zeeb iwl_mvm_connection_loss(mvm, vif, "missed beacons");
1652a4128aadSBjoern A. Zeeb } else {
1653a4128aadSBjoern A. Zeeb IWL_WARN(mvm,
1654a4128aadSBjoern A. Zeeb "missed beacons exceeds threshold, but receiving data. Stay connected, Expect bugs.\n");
1655a4128aadSBjoern A. Zeeb IWL_WARN(mvm,
1656a4128aadSBjoern A. Zeeb "missed_beacons:%d, missed_beacons_since_rx:%d\n",
1657a4128aadSBjoern A. Zeeb rx_missed_bcon, rx_missed_bcon_since_rx);
1658a4128aadSBjoern A. Zeeb }
1659a4128aadSBjoern A. Zeeb } else if (rx_missed_bcon >= IWL_MVM_MISSED_BEACONS_EXIT_ESR_THRESH &&
1660a4128aadSBjoern A. Zeeb link_id >= 0 && hweight16(vif->active_links) > 1) {
1661a4128aadSBjoern A. Zeeb iwl_mvm_exit_esr(mvm, vif, IWL_MVM_ESR_EXIT_MISSED_BEACON,
1662a4128aadSBjoern A. Zeeb iwl_mvm_get_other_link(vif, link_id));
1663a4128aadSBjoern A. Zeeb } else if (rx_missed_bcon_since_rx > IWL_MVM_MISSED_BEACONS_THRESHOLD) {
1664a4128aadSBjoern A. Zeeb if (!iwl_mvm_has_new_tx_api(mvm))
1665bfcc09ddSBjoern A. Zeeb ieee80211_beacon_loss(vif);
1666a4128aadSBjoern A. Zeeb else
1667a4128aadSBjoern A. Zeeb ieee80211_cqm_beacon_loss_notify(vif, GFP_ATOMIC);
1668a4128aadSBjoern A. Zeeb }
1669bfcc09ddSBjoern A. Zeeb
1670bfcc09ddSBjoern A. Zeeb iwl_dbg_tlv_time_point(&mvm->fwrt,
1671bfcc09ddSBjoern A. Zeeb IWL_FW_INI_TIME_POINT_MISSED_BEACONS, &tp_data);
1672bfcc09ddSBjoern A. Zeeb
1673bfcc09ddSBjoern A. Zeeb trigger = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
1674bfcc09ddSBjoern A. Zeeb FW_DBG_TRIGGER_MISSED_BEACONS);
1675bfcc09ddSBjoern A. Zeeb if (!trigger)
1676a4128aadSBjoern A. Zeeb return;
1677bfcc09ddSBjoern A. Zeeb
1678bfcc09ddSBjoern A. Zeeb bcon_trig = (void *)trigger->data;
1679bfcc09ddSBjoern A. Zeeb stop_trig_missed_bcon = le32_to_cpu(bcon_trig->stop_consec_missed_bcon);
1680bfcc09ddSBjoern A. Zeeb stop_trig_missed_bcon_since_rx =
1681bfcc09ddSBjoern A. Zeeb le32_to_cpu(bcon_trig->stop_consec_missed_bcon_since_rx);
1682bfcc09ddSBjoern A. Zeeb
1683bfcc09ddSBjoern A. Zeeb /* TODO: implement start trigger */
1684bfcc09ddSBjoern A. Zeeb
1685bfcc09ddSBjoern A. Zeeb if (rx_missed_bcon_since_rx >= stop_trig_missed_bcon_since_rx ||
1686bfcc09ddSBjoern A. Zeeb rx_missed_bcon >= stop_trig_missed_bcon)
1687f621b087SBjoern A. Zeeb #if defined(__linux__)
1688bfcc09ddSBjoern A. Zeeb iwl_fw_dbg_collect_trig(&mvm->fwrt, trigger, NULL);
1689f621b087SBjoern A. Zeeb #elif defined(__FreeBSD__)
1690f621b087SBjoern A. Zeeb iwl_fw_dbg_collect_trig(&mvm->fwrt, trigger, "");
1691f621b087SBjoern A. Zeeb #endif
1692bfcc09ddSBjoern A. Zeeb }
1693bfcc09ddSBjoern A. Zeeb
iwl_mvm_rx_stored_beacon_notif(struct iwl_mvm * mvm,struct iwl_rx_cmd_buffer * rxb)1694bfcc09ddSBjoern A. Zeeb void iwl_mvm_rx_stored_beacon_notif(struct iwl_mvm *mvm,
1695bfcc09ddSBjoern A. Zeeb struct iwl_rx_cmd_buffer *rxb)
1696bfcc09ddSBjoern A. Zeeb {
1697bfcc09ddSBjoern A. Zeeb struct iwl_rx_packet *pkt = rxb_addr(rxb);
1698bfcc09ddSBjoern A. Zeeb unsigned int pkt_len = iwl_rx_packet_payload_len(pkt);
1699bfcc09ddSBjoern A. Zeeb struct iwl_stored_beacon_notif_common *sb = (void *)pkt->data;
1700bfcc09ddSBjoern A. Zeeb struct ieee80211_rx_status rx_status;
1701bfcc09ddSBjoern A. Zeeb struct sk_buff *skb;
1702bfcc09ddSBjoern A. Zeeb u8 *data;
1703bfcc09ddSBjoern A. Zeeb u32 size = le32_to_cpu(sb->byte_count);
1704d9836fb4SBjoern A. Zeeb int ver = iwl_fw_lookup_cmd_ver(mvm->fw,
1705d9836fb4SBjoern A. Zeeb WIDE_ID(PROT_OFFLOAD_GROUP, STORED_BEACON_NTF),
1706d9836fb4SBjoern A. Zeeb 0);
1707bfcc09ddSBjoern A. Zeeb
1708bfcc09ddSBjoern A. Zeeb if (size == 0)
1709bfcc09ddSBjoern A. Zeeb return;
1710bfcc09ddSBjoern A. Zeeb
1711bfcc09ddSBjoern A. Zeeb /* handle per-version differences */
1712bfcc09ddSBjoern A. Zeeb if (ver <= 2) {
1713bfcc09ddSBjoern A. Zeeb struct iwl_stored_beacon_notif_v2 *sb_v2 = (void *)pkt->data;
1714bfcc09ddSBjoern A. Zeeb
1715bfcc09ddSBjoern A. Zeeb if (pkt_len < struct_size(sb_v2, data, size))
1716bfcc09ddSBjoern A. Zeeb return;
1717bfcc09ddSBjoern A. Zeeb
1718bfcc09ddSBjoern A. Zeeb data = sb_v2->data;
1719bfcc09ddSBjoern A. Zeeb } else {
1720bfcc09ddSBjoern A. Zeeb struct iwl_stored_beacon_notif_v3 *sb_v3 = (void *)pkt->data;
1721bfcc09ddSBjoern A. Zeeb
1722bfcc09ddSBjoern A. Zeeb if (pkt_len < struct_size(sb_v3, data, size))
1723bfcc09ddSBjoern A. Zeeb return;
1724bfcc09ddSBjoern A. Zeeb
1725bfcc09ddSBjoern A. Zeeb data = sb_v3->data;
1726bfcc09ddSBjoern A. Zeeb }
1727bfcc09ddSBjoern A. Zeeb
1728bfcc09ddSBjoern A. Zeeb skb = alloc_skb(size, GFP_ATOMIC);
1729bfcc09ddSBjoern A. Zeeb if (!skb) {
1730bfcc09ddSBjoern A. Zeeb IWL_ERR(mvm, "alloc_skb failed\n");
1731bfcc09ddSBjoern A. Zeeb return;
1732bfcc09ddSBjoern A. Zeeb }
1733bfcc09ddSBjoern A. Zeeb
1734bfcc09ddSBjoern A. Zeeb /* update rx_status according to the notification's metadata */
1735bfcc09ddSBjoern A. Zeeb memset(&rx_status, 0, sizeof(rx_status));
1736bfcc09ddSBjoern A. Zeeb rx_status.mactime = le64_to_cpu(sb->tsf);
1737bfcc09ddSBjoern A. Zeeb /* TSF as indicated by the firmware is at INA time */
1738bfcc09ddSBjoern A. Zeeb rx_status.flag |= RX_FLAG_MACTIME_PLCP_START;
1739bfcc09ddSBjoern A. Zeeb rx_status.device_timestamp = le32_to_cpu(sb->system_time);
1740bfcc09ddSBjoern A. Zeeb rx_status.band =
1741bfcc09ddSBjoern A. Zeeb (sb->band & cpu_to_le16(RX_RES_PHY_FLAGS_BAND_24)) ?
1742bfcc09ddSBjoern A. Zeeb NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
1743bfcc09ddSBjoern A. Zeeb rx_status.freq =
1744bfcc09ddSBjoern A. Zeeb ieee80211_channel_to_frequency(le16_to_cpu(sb->channel),
1745bfcc09ddSBjoern A. Zeeb rx_status.band);
1746bfcc09ddSBjoern A. Zeeb
1747bfcc09ddSBjoern A. Zeeb /* copy the data */
1748bfcc09ddSBjoern A. Zeeb skb_put_data(skb, data, size);
1749bfcc09ddSBjoern A. Zeeb memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
1750bfcc09ddSBjoern A. Zeeb
1751bfcc09ddSBjoern A. Zeeb /* pass it as regular rx to mac80211 */
1752bfcc09ddSBjoern A. Zeeb ieee80211_rx_napi(mvm->hw, NULL, skb, NULL);
1753bfcc09ddSBjoern A. Zeeb }
1754bfcc09ddSBjoern A. Zeeb
iwl_mvm_probe_resp_data_notif(struct iwl_mvm * mvm,struct iwl_rx_cmd_buffer * rxb)1755bfcc09ddSBjoern A. Zeeb void iwl_mvm_probe_resp_data_notif(struct iwl_mvm *mvm,
1756bfcc09ddSBjoern A. Zeeb struct iwl_rx_cmd_buffer *rxb)
1757bfcc09ddSBjoern A. Zeeb {
1758bfcc09ddSBjoern A. Zeeb struct iwl_rx_packet *pkt = rxb_addr(rxb);
1759bfcc09ddSBjoern A. Zeeb struct iwl_probe_resp_data_notif *notif = (void *)pkt->data;
1760bfcc09ddSBjoern A. Zeeb struct iwl_probe_resp_data *old_data, *new_data;
1761bfcc09ddSBjoern A. Zeeb u32 id = le32_to_cpu(notif->mac_id);
1762bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif;
1763bfcc09ddSBjoern A. Zeeb struct iwl_mvm_vif *mvmvif;
1764bfcc09ddSBjoern A. Zeeb
1765bfcc09ddSBjoern A. Zeeb IWL_DEBUG_INFO(mvm, "Probe response data notif: noa %d, csa %d\n",
1766bfcc09ddSBjoern A. Zeeb notif->noa_active, notif->csa_counter);
1767bfcc09ddSBjoern A. Zeeb
1768bfcc09ddSBjoern A. Zeeb vif = iwl_mvm_rcu_dereference_vif_id(mvm, id, false);
1769bfcc09ddSBjoern A. Zeeb if (!vif)
1770bfcc09ddSBjoern A. Zeeb return;
1771bfcc09ddSBjoern A. Zeeb
1772bfcc09ddSBjoern A. Zeeb mvmvif = iwl_mvm_vif_from_mac80211(vif);
1773bfcc09ddSBjoern A. Zeeb
1774bfcc09ddSBjoern A. Zeeb new_data = kzalloc(sizeof(*new_data), GFP_KERNEL);
1775bfcc09ddSBjoern A. Zeeb if (!new_data)
1776bfcc09ddSBjoern A. Zeeb return;
1777bfcc09ddSBjoern A. Zeeb
1778bfcc09ddSBjoern A. Zeeb memcpy(&new_data->notif, notif, sizeof(new_data->notif));
1779bfcc09ddSBjoern A. Zeeb
1780bfcc09ddSBjoern A. Zeeb /* noa_attr contains 1 reserved byte, need to substruct it */
1781bfcc09ddSBjoern A. Zeeb new_data->noa_len = sizeof(struct ieee80211_vendor_ie) +
1782bfcc09ddSBjoern A. Zeeb sizeof(new_data->notif.noa_attr) - 1;
1783bfcc09ddSBjoern A. Zeeb
1784bfcc09ddSBjoern A. Zeeb /*
1785bfcc09ddSBjoern A. Zeeb * If it's a one time NoA, only one descriptor is needed,
1786bfcc09ddSBjoern A. Zeeb * adjust the length according to len_low.
1787bfcc09ddSBjoern A. Zeeb */
1788bfcc09ddSBjoern A. Zeeb if (new_data->notif.noa_attr.len_low ==
1789bfcc09ddSBjoern A. Zeeb sizeof(struct ieee80211_p2p_noa_desc) + 2)
1790bfcc09ddSBjoern A. Zeeb new_data->noa_len -= sizeof(struct ieee80211_p2p_noa_desc);
1791bfcc09ddSBjoern A. Zeeb
17929af1bba4SBjoern A. Zeeb old_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data,
1793bfcc09ddSBjoern A. Zeeb lockdep_is_held(&mvmvif->mvm->mutex));
17949af1bba4SBjoern A. Zeeb rcu_assign_pointer(mvmvif->deflink.probe_resp_data, new_data);
1795bfcc09ddSBjoern A. Zeeb
1796bfcc09ddSBjoern A. Zeeb if (old_data)
1797bfcc09ddSBjoern A. Zeeb kfree_rcu(old_data, rcu_head);
1798bfcc09ddSBjoern A. Zeeb
1799bfcc09ddSBjoern A. Zeeb if (notif->csa_counter != IWL_PROBE_RESP_DATA_NO_CSA &&
1800bfcc09ddSBjoern A. Zeeb notif->csa_counter >= 1)
1801bfcc09ddSBjoern A. Zeeb ieee80211_beacon_set_cntdwn(vif, notif->csa_counter);
1802bfcc09ddSBjoern A. Zeeb }
1803bfcc09ddSBjoern A. Zeeb
iwl_mvm_channel_switch_start_notif(struct iwl_mvm * mvm,struct iwl_rx_cmd_buffer * rxb)1804bfcc09ddSBjoern A. Zeeb void iwl_mvm_channel_switch_start_notif(struct iwl_mvm *mvm,
1805bfcc09ddSBjoern A. Zeeb struct iwl_rx_cmd_buffer *rxb)
1806bfcc09ddSBjoern A. Zeeb {
1807bfcc09ddSBjoern A. Zeeb struct iwl_rx_packet *pkt = rxb_addr(rxb);
1808bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *csa_vif, *vif;
18099af1bba4SBjoern A. Zeeb struct iwl_mvm_vif *mvmvif, *csa_mvmvif;
18109af1bba4SBjoern A. Zeeb u32 id_n_color, csa_id;
18119af1bba4SBjoern A. Zeeb /* save mac_id or link_id to use later to cancel csa if needed */
18129af1bba4SBjoern A. Zeeb u32 id;
1813a4128aadSBjoern A. Zeeb u32 mac_link_id = 0;
18149af1bba4SBjoern A. Zeeb u8 notif_ver = iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
18159af1bba4SBjoern A. Zeeb CHANNEL_SWITCH_START_NOTIF, 0);
18169af1bba4SBjoern A. Zeeb bool csa_active;
18179af1bba4SBjoern A. Zeeb
18189af1bba4SBjoern A. Zeeb rcu_read_lock();
18199af1bba4SBjoern A. Zeeb
18209af1bba4SBjoern A. Zeeb if (notif_ver < 3) {
18219af1bba4SBjoern A. Zeeb struct iwl_channel_switch_start_notif_v1 *notif = (void *)pkt->data;
18229af1bba4SBjoern A. Zeeb u32 mac_id;
1823bfcc09ddSBjoern A. Zeeb
1824bfcc09ddSBjoern A. Zeeb id_n_color = le32_to_cpu(notif->id_and_color);
1825bfcc09ddSBjoern A. Zeeb mac_id = id_n_color & FW_CTXT_ID_MSK;
1826bfcc09ddSBjoern A. Zeeb
18279af1bba4SBjoern A. Zeeb vif = iwl_mvm_rcu_dereference_vif_id(mvm, mac_id, true);
18289af1bba4SBjoern A. Zeeb if (!vif)
18299af1bba4SBjoern A. Zeeb goto out_unlock;
1830bfcc09ddSBjoern A. Zeeb
18319af1bba4SBjoern A. Zeeb id = mac_id;
18329af1bba4SBjoern A. Zeeb csa_active = vif->bss_conf.csa_active;
18339af1bba4SBjoern A. Zeeb } else {
18349af1bba4SBjoern A. Zeeb struct iwl_channel_switch_start_notif *notif = (void *)pkt->data;
18359af1bba4SBjoern A. Zeeb u32 link_id = le32_to_cpu(notif->link_id);
18369af1bba4SBjoern A. Zeeb struct ieee80211_bss_conf *bss_conf =
18379af1bba4SBjoern A. Zeeb iwl_mvm_rcu_fw_link_id_to_link_conf(mvm, link_id, true);
18389af1bba4SBjoern A. Zeeb
18399af1bba4SBjoern A. Zeeb if (!bss_conf)
18409af1bba4SBjoern A. Zeeb goto out_unlock;
18419af1bba4SBjoern A. Zeeb
18429af1bba4SBjoern A. Zeeb id = link_id;
1843a4128aadSBjoern A. Zeeb mac_link_id = bss_conf->link_id;
18449af1bba4SBjoern A. Zeeb vif = bss_conf->vif;
18459af1bba4SBjoern A. Zeeb csa_active = bss_conf->csa_active;
18469af1bba4SBjoern A. Zeeb }
18479af1bba4SBjoern A. Zeeb
1848bfcc09ddSBjoern A. Zeeb mvmvif = iwl_mvm_vif_from_mac80211(vif);
18499af1bba4SBjoern A. Zeeb if (notif_ver >= 3)
18509af1bba4SBjoern A. Zeeb id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color);
1851bfcc09ddSBjoern A. Zeeb
1852bfcc09ddSBjoern A. Zeeb switch (vif->type) {
1853bfcc09ddSBjoern A. Zeeb case NL80211_IFTYPE_AP:
1854bfcc09ddSBjoern A. Zeeb csa_vif = rcu_dereference(mvm->csa_vif);
18559af1bba4SBjoern A. Zeeb if (WARN_ON(!csa_vif || !csa_vif->bss_conf.csa_active ||
1856bfcc09ddSBjoern A. Zeeb csa_vif != vif))
1857bfcc09ddSBjoern A. Zeeb goto out_unlock;
1858bfcc09ddSBjoern A. Zeeb
18599af1bba4SBjoern A. Zeeb csa_mvmvif = iwl_mvm_vif_from_mac80211(csa_vif);
18609af1bba4SBjoern A. Zeeb csa_id = FW_CMD_ID_AND_COLOR(csa_mvmvif->id, csa_mvmvif->color);
1861bfcc09ddSBjoern A. Zeeb if (WARN(csa_id != id_n_color,
1862bfcc09ddSBjoern A. Zeeb "channel switch noa notification on unexpected vif (csa_vif=%d, notif=%d)",
1863bfcc09ddSBjoern A. Zeeb csa_id, id_n_color))
1864bfcc09ddSBjoern A. Zeeb goto out_unlock;
1865bfcc09ddSBjoern A. Zeeb
1866bfcc09ddSBjoern A. Zeeb IWL_DEBUG_INFO(mvm, "Channel Switch Started Notification\n");
1867bfcc09ddSBjoern A. Zeeb
1868bfcc09ddSBjoern A. Zeeb schedule_delayed_work(&mvm->cs_tx_unblock_dwork,
1869bfcc09ddSBjoern A. Zeeb msecs_to_jiffies(IWL_MVM_CS_UNBLOCK_TX_TIMEOUT *
1870bfcc09ddSBjoern A. Zeeb csa_vif->bss_conf.beacon_int));
1871bfcc09ddSBjoern A. Zeeb
1872a4128aadSBjoern A. Zeeb ieee80211_csa_finish(csa_vif, 0);
1873bfcc09ddSBjoern A. Zeeb
1874bfcc09ddSBjoern A. Zeeb rcu_read_unlock();
1875bfcc09ddSBjoern A. Zeeb
1876bfcc09ddSBjoern A. Zeeb RCU_INIT_POINTER(mvm->csa_vif, NULL);
1877bfcc09ddSBjoern A. Zeeb return;
1878bfcc09ddSBjoern A. Zeeb case NL80211_IFTYPE_STATION:
1879d9836fb4SBjoern A. Zeeb /*
1880d9836fb4SBjoern A. Zeeb * if we don't know about an ongoing channel switch,
1881d9836fb4SBjoern A. Zeeb * make sure FW cancels it
1882d9836fb4SBjoern A. Zeeb */
1883d9836fb4SBjoern A. Zeeb if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
1884d9836fb4SBjoern A. Zeeb CHANNEL_SWITCH_ERROR_NOTIF,
18859af1bba4SBjoern A. Zeeb 0) && !csa_active) {
1886d9836fb4SBjoern A. Zeeb IWL_DEBUG_INFO(mvm, "Channel Switch was canceled\n");
18879af1bba4SBjoern A. Zeeb iwl_mvm_cancel_channel_switch(mvm, vif, id);
1888d9836fb4SBjoern A. Zeeb break;
1889d9836fb4SBjoern A. Zeeb }
1890d9836fb4SBjoern A. Zeeb
1891bfcc09ddSBjoern A. Zeeb iwl_mvm_csa_client_absent(mvm, vif);
1892bfcc09ddSBjoern A. Zeeb cancel_delayed_work(&mvmvif->csa_work);
1893a4128aadSBjoern A. Zeeb ieee80211_chswitch_done(vif, true, mac_link_id);
1894bfcc09ddSBjoern A. Zeeb break;
1895bfcc09ddSBjoern A. Zeeb default:
1896bfcc09ddSBjoern A. Zeeb /* should never happen */
1897bfcc09ddSBjoern A. Zeeb WARN_ON_ONCE(1);
1898bfcc09ddSBjoern A. Zeeb break;
1899bfcc09ddSBjoern A. Zeeb }
1900bfcc09ddSBjoern A. Zeeb out_unlock:
1901bfcc09ddSBjoern A. Zeeb rcu_read_unlock();
1902bfcc09ddSBjoern A. Zeeb }
1903bfcc09ddSBjoern A. Zeeb
iwl_mvm_channel_switch_error_notif(struct iwl_mvm * mvm,struct iwl_rx_cmd_buffer * rxb)1904d9836fb4SBjoern A. Zeeb void iwl_mvm_channel_switch_error_notif(struct iwl_mvm *mvm,
1905d9836fb4SBjoern A. Zeeb struct iwl_rx_cmd_buffer *rxb)
1906d9836fb4SBjoern A. Zeeb {
1907d9836fb4SBjoern A. Zeeb struct iwl_rx_packet *pkt = rxb_addr(rxb);
1908d9836fb4SBjoern A. Zeeb struct iwl_channel_switch_error_notif *notif = (void *)pkt->data;
1909d9836fb4SBjoern A. Zeeb struct ieee80211_vif *vif;
19109af1bba4SBjoern A. Zeeb u32 id = le32_to_cpu(notif->link_id);
1911d9836fb4SBjoern A. Zeeb u32 csa_err_mask = le32_to_cpu(notif->csa_err_mask);
1912d9836fb4SBjoern A. Zeeb
1913d9836fb4SBjoern A. Zeeb rcu_read_lock();
1914d9836fb4SBjoern A. Zeeb vif = iwl_mvm_rcu_dereference_vif_id(mvm, id, true);
1915d9836fb4SBjoern A. Zeeb if (!vif) {
1916d9836fb4SBjoern A. Zeeb rcu_read_unlock();
1917d9836fb4SBjoern A. Zeeb return;
1918d9836fb4SBjoern A. Zeeb }
1919d9836fb4SBjoern A. Zeeb
19209af1bba4SBjoern A. Zeeb IWL_DEBUG_INFO(mvm, "FW reports CSA error: id=%u, csa_err_mask=%u\n",
1921d9836fb4SBjoern A. Zeeb id, csa_err_mask);
1922d9836fb4SBjoern A. Zeeb if (csa_err_mask & (CS_ERR_COUNT_ERROR |
1923d9836fb4SBjoern A. Zeeb CS_ERR_LONG_DELAY_AFTER_CS |
1924d9836fb4SBjoern A. Zeeb CS_ERR_TX_BLOCK_TIMER_EXPIRED))
1925*e6010da6SBjoern A. Zeeb ieee80211_channel_switch_disconnect(vif);
1926d9836fb4SBjoern A. Zeeb rcu_read_unlock();
1927d9836fb4SBjoern A. Zeeb }
1928d9836fb4SBjoern A. Zeeb
iwl_mvm_rx_missed_vap_notif(struct iwl_mvm * mvm,struct iwl_rx_cmd_buffer * rxb)1929bfcc09ddSBjoern A. Zeeb void iwl_mvm_rx_missed_vap_notif(struct iwl_mvm *mvm,
1930bfcc09ddSBjoern A. Zeeb struct iwl_rx_cmd_buffer *rxb)
1931bfcc09ddSBjoern A. Zeeb {
1932bfcc09ddSBjoern A. Zeeb struct iwl_rx_packet *pkt = rxb_addr(rxb);
1933bfcc09ddSBjoern A. Zeeb struct iwl_missed_vap_notif *mb = (void *)pkt->data;
1934bfcc09ddSBjoern A. Zeeb struct ieee80211_vif *vif;
1935bfcc09ddSBjoern A. Zeeb u32 id = le32_to_cpu(mb->mac_id);
1936bfcc09ddSBjoern A. Zeeb
1937bfcc09ddSBjoern A. Zeeb IWL_DEBUG_INFO(mvm,
1938bfcc09ddSBjoern A. Zeeb "missed_vap notify mac_id=%u, num_beacon_intervals_elapsed=%u, profile_periodicity=%u\n",
1939bfcc09ddSBjoern A. Zeeb le32_to_cpu(mb->mac_id),
1940bfcc09ddSBjoern A. Zeeb mb->num_beacon_intervals_elapsed,
1941bfcc09ddSBjoern A. Zeeb mb->profile_periodicity);
1942bfcc09ddSBjoern A. Zeeb
1943bfcc09ddSBjoern A. Zeeb rcu_read_lock();
1944bfcc09ddSBjoern A. Zeeb
1945bfcc09ddSBjoern A. Zeeb vif = iwl_mvm_rcu_dereference_vif_id(mvm, id, true);
1946bfcc09ddSBjoern A. Zeeb if (vif)
1947bfcc09ddSBjoern A. Zeeb iwl_mvm_connection_loss(mvm, vif, "missed vap beacon");
1948bfcc09ddSBjoern A. Zeeb
1949bfcc09ddSBjoern A. Zeeb rcu_read_unlock();
1950bfcc09ddSBjoern A. Zeeb }
1951