iwlwifi: mvm: support bss dynamic alloc/dealloc of queues
[deliverable/linux.git] / drivers / net / wireless / intel / iwlwifi / mvm / mac-ctxt.c
CommitLineData
8ca151b5
JB
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
51368bf7 8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8b4139dc 9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
0db056d3 10 * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
8ca151b5
JB
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * USA
25 *
26 * The full GNU General Public License is included in this distribution
410dc5aa 27 * in the file called COPYING.
8ca151b5
JB
28 *
29 * Contact Information:
cb2f8277 30 * Intel Linux Wireless <linuxwifi@intel.com>
8ca151b5
JB
31 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
51368bf7 35 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8b4139dc 36 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
0db056d3 37 * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
8ca151b5
JB
38 * All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 *
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * * Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in
48 * the documentation and/or other materials provided with the
49 * distribution.
50 * * Neither the name Intel Corporation nor the names of its
51 * contributors may be used to endorse or promote products derived
52 * from this software without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 *
66 *****************************************************************************/
67
68#include <linux/etherdevice.h>
69#include <net/mac80211.h>
70#include "iwl-io.h"
71#include "iwl-prph.h"
72#include "fw-api.h"
73#include "mvm.h"
7f0a7c67 74#include "time-event.h"
2f89a5d7 75#include "fw-dbg.h"
8ca151b5
JB
76
77const u8 iwl_mvm_ac_to_tx_fifo[] = {
8ca151b5 78 IWL_MVM_TX_FIFO_VO,
3dd94794
EG
79 IWL_MVM_TX_FIFO_VI,
80 IWL_MVM_TX_FIFO_BE,
81 IWL_MVM_TX_FIFO_BK,
8ca151b5
JB
82};
83
84struct iwl_mvm_mac_iface_iterator_data {
85 struct iwl_mvm *mvm;
86 struct ieee80211_vif *vif;
87 unsigned long available_mac_ids[BITS_TO_LONGS(NUM_MAC_INDEX_DRIVER)];
88 unsigned long available_tsf_ids[BITS_TO_LONGS(NUM_TSF_IDS)];
8ca151b5
JB
89 enum iwl_tsf_id preferred_tsf;
90 bool found_vif;
91};
92
a74346d7
AN
93struct iwl_mvm_hw_queues_iface_iterator_data {
94 struct ieee80211_vif *exclude_vif;
95 unsigned long used_hw_queues;
96};
97
6e97b0d2
IP
98static void iwl_mvm_mac_tsf_id_iter(void *_data, u8 *mac,
99 struct ieee80211_vif *vif)
8ca151b5
JB
100{
101 struct iwl_mvm_mac_iface_iterator_data *data = _data;
102 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2c3e62a1 103 u16 min_bi;
8ca151b5 104
6e97b0d2
IP
105 /* Skip the interface for which we are trying to assign a tsf_id */
106 if (vif == data->vif)
8ca151b5 107 return;
8ca151b5
JB
108
109 /*
110 * The TSF is a hardware/firmware resource, there are 4 and
111 * the driver should assign and free them as needed. However,
112 * there are cases where 2 MACs should share the same TSF ID
113 * for the purpose of clock sync, an optimization to avoid
114 * clock drift causing overlapping TBTTs/DTIMs for a GO and
115 * client in the system.
116 *
117 * The firmware will decide according to the MAC type which
118 * will be the master and slave. Clients that need to sync
119 * with a remote station will be the master, and an AP or GO
120 * will be the slave.
121 *
122 * Depending on the new interface type it can be slaved to
123 * or become the master of an existing interface.
124 */
125 switch (data->vif->type) {
126 case NL80211_IFTYPE_STATION:
127 /*
2c3e62a1
IP
128 * The new interface is a client, so if the one we're iterating
129 * is an AP, and the beacon interval of the AP is a multiple or
130 * divisor of the beacon interval of the client, the same TSF
131 * should be used to avoid drift between the new client and
132 * existing AP. The existing AP will get drift updates from the
133 * new client context in this case.
8ca151b5 134 */
2c3e62a1
IP
135 if (vif->type != NL80211_IFTYPE_AP ||
136 data->preferred_tsf != NUM_TSF_IDS ||
137 !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
138 break;
139
140 min_bi = min(data->vif->bss_conf.beacon_int,
141 vif->bss_conf.beacon_int);
142
143 if (!min_bi)
144 break;
145
146 if ((data->vif->bss_conf.beacon_int -
147 vif->bss_conf.beacon_int) % min_bi == 0) {
148 data->preferred_tsf = mvmvif->tsf_id;
149 return;
8ca151b5
JB
150 }
151 break;
2c3e62a1 152
8ca151b5
JB
153 case NL80211_IFTYPE_AP:
154 /*
2c3e62a1
IP
155 * The new interface is AP/GO, so if its beacon interval is a
156 * multiple or a divisor of the beacon interval of an existing
157 * interface, it should get drift updates from an existing
158 * client or use the same TSF as an existing GO. There's no
159 * drift between TSFs internally but if they used different
160 * TSFs then a new client MAC could update one of them and
161 * cause drift that way.
8ca151b5 162 */
2c3e62a1
IP
163 if ((vif->type != NL80211_IFTYPE_AP &&
164 vif->type != NL80211_IFTYPE_STATION) ||
165 data->preferred_tsf != NUM_TSF_IDS ||
166 !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
167 break;
168
169 min_bi = min(data->vif->bss_conf.beacon_int,
170 vif->bss_conf.beacon_int);
171
172 if (!min_bi)
173 break;
174
175 if ((data->vif->bss_conf.beacon_int -
176 vif->bss_conf.beacon_int) % min_bi == 0) {
177 data->preferred_tsf = mvmvif->tsf_id;
178 return;
8ca151b5
JB
179 }
180 break;
181 default:
182 /*
183 * For all other interface types there's no need to
184 * take drift into account. Either they're exclusive
185 * like IBSS and monitor, or we don't care much about
186 * their TSF (like P2P Device), but we won't be able
187 * to share the TSF resource.
188 */
189 break;
190 }
191
192 /*
193 * Unless we exited above, we can't share the TSF resource
194 * that the virtual interface we're iterating over is using
195 * with the new one, so clear the available bit and if this
196 * was the preferred one, reset that as well.
197 */
198 __clear_bit(mvmvif->tsf_id, data->available_tsf_ids);
199
200 if (data->preferred_tsf == mvmvif->tsf_id)
201 data->preferred_tsf = NUM_TSF_IDS;
202}
203
110cf810
JB
204/*
205 * Get the mask of the queues used by the vif
206 */
d92b732e 207u32 iwl_mvm_mac_get_queues_mask(struct ieee80211_vif *vif)
110cf810
JB
208{
209 u32 qmask = 0, ac;
210
211 if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
212 return BIT(IWL_MVM_OFFCHANNEL_QUEUE);
213
1008e442
IP
214 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
215 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
216 qmask |= BIT(vif->hw_queue[ac]);
217 }
110cf810
JB
218
219 if (vif->type == NL80211_IFTYPE_AP)
220 qmask |= BIT(vif->cab_queue);
221
222 return qmask;
223}
224
a74346d7
AN
225static void iwl_mvm_iface_hw_queues_iter(void *_data, u8 *mac,
226 struct ieee80211_vif *vif)
227{
228 struct iwl_mvm_hw_queues_iface_iterator_data *data = _data;
229
230 /* exclude the given vif */
231 if (vif == data->exclude_vif)
232 return;
233
234 data->used_hw_queues |= iwl_mvm_mac_get_queues_mask(vif);
235}
236
237static void iwl_mvm_mac_sta_hw_queues_iter(void *_data,
238 struct ieee80211_sta *sta)
239{
240 struct iwl_mvm_hw_queues_iface_iterator_data *data = _data;
241 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
242
243 /* Mark the queues used by the sta */
244 data->used_hw_queues |= mvmsta->tfd_queue_msk;
245}
246
247unsigned long iwl_mvm_get_used_hw_queues(struct iwl_mvm *mvm,
248 struct ieee80211_vif *exclude_vif)
249{
51ec09af 250 u8 sta_id;
a74346d7
AN
251 struct iwl_mvm_hw_queues_iface_iterator_data data = {
252 .exclude_vif = exclude_vif,
253 .used_hw_queues =
254 BIT(IWL_MVM_OFFCHANNEL_QUEUE) |
255 BIT(mvm->aux_queue) |
256 BIT(IWL_MVM_CMD_QUEUE),
257 };
258
259 lockdep_assert_held(&mvm->mutex);
260
261 /* mark all VIF used hw queues */
262 ieee80211_iterate_active_interfaces_atomic(
263 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
264 iwl_mvm_iface_hw_queues_iter, &data);
265
266 /* don't assign the same hw queues as TDLS stations */
267 ieee80211_iterate_stations_atomic(mvm->hw,
268 iwl_mvm_mac_sta_hw_queues_iter,
269 &data);
270
51ec09af
AN
271 /*
272 * Some TDLS stations may be removed but are in the process of being
273 * drained. Don't touch their queues.
274 */
275 for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT)
276 data.used_hw_queues |= mvm->tfd_drained[sta_id];
277
a74346d7
AN
278 return data.used_hw_queues;
279}
280
6e97b0d2
IP
281static void iwl_mvm_mac_iface_iterator(void *_data, u8 *mac,
282 struct ieee80211_vif *vif)
283{
284 struct iwl_mvm_mac_iface_iterator_data *data = _data;
285 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
6e97b0d2
IP
286
287 /* Iterator may already find the interface being added -- skip it */
288 if (vif == data->vif) {
289 data->found_vif = true;
290 return;
291 }
292
6e97b0d2
IP
293 /* Mark MAC IDs as used by clearing the available bit, and
294 * (below) mark TSFs as used if their existing use is not
295 * compatible with the new interface type.
296 * No locking or atomic bit operations are needed since the
297 * data is on the stack of the caller function.
298 */
299 __clear_bit(mvmvif->id, data->available_mac_ids);
300
301 /* find a suitable tsf_id */
302 iwl_mvm_mac_tsf_id_iter(_data, mac, vif);
303}
304
6e97b0d2
IP
305void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm *mvm,
306 struct ieee80211_vif *vif)
307{
308 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
309 struct iwl_mvm_mac_iface_iterator_data data = {
310 .mvm = mvm,
311 .vif = vif,
312 .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
313 /* no preference yet */
314 .preferred_tsf = NUM_TSF_IDS,
315 };
316
317 ieee80211_iterate_active_interfaces_atomic(
318 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
319 iwl_mvm_mac_tsf_id_iter, &data);
320
321 if (data.preferred_tsf != NUM_TSF_IDS)
322 mvmvif->tsf_id = data.preferred_tsf;
323 else if (!test_bit(mvmvif->tsf_id, data.available_tsf_ids))
324 mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
325 NUM_TSF_IDS);
326}
327
8ca151b5
JB
328static int iwl_mvm_mac_ctxt_allocate_resources(struct iwl_mvm *mvm,
329 struct ieee80211_vif *vif)
330{
331 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
332 struct iwl_mvm_mac_iface_iterator_data data = {
333 .mvm = mvm,
334 .vif = vif,
335 .available_mac_ids = { (1 << NUM_MAC_INDEX_DRIVER) - 1 },
336 .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
337 /* no preference yet */
338 .preferred_tsf = NUM_TSF_IDS,
8ca151b5
JB
339 .found_vif = false,
340 };
341 u32 ac;
9ee718aa 342 int ret, i;
110cf810 343 unsigned long used_hw_queues;
8ca151b5
JB
344
345 /*
346 * Allocate a MAC ID and a TSF for this MAC, along with the queues
347 * and other resources.
348 */
349
350 /*
351 * Before the iterator, we start with all MAC IDs and TSFs available.
352 *
353 * During iteration, all MAC IDs are cleared that are in use by other
354 * virtual interfaces, and all TSF IDs are cleared that can't be used
355 * by this new virtual interface because they're used by an interface
356 * that can't share it with the new one.
357 * At the same time, we check if there's a preferred TSF in the case
358 * that we should share it with another interface.
359 */
360
5023d966
JB
361 /* Currently, MAC ID 0 should be used only for the managed/IBSS vif */
362 switch (vif->type) {
363 case NL80211_IFTYPE_ADHOC:
364 break;
365 case NL80211_IFTYPE_STATION:
366 if (!vif->p2p)
367 break;
368 /* fall through */
369 default:
ec8b6885 370 __clear_bit(0, data.available_mac_ids);
5023d966 371 }
ec8b6885 372
8ca151b5
JB
373 ieee80211_iterate_active_interfaces_atomic(
374 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
375 iwl_mvm_mac_iface_iterator, &data);
376
a74346d7
AN
377 used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, vif);
378
8ca151b5
JB
379 /*
380 * In the case we're getting here during resume, it's similar to
381 * firmware restart, and with RESUME_ALL the iterator will find
382 * the vif being added already.
383 * We don't want to reassign any IDs in either case since doing
384 * so would probably assign different IDs (as interfaces aren't
385 * necessarily added in the same order), but the old IDs were
386 * preserved anyway, so skip ID assignment for both resume and
387 * recovery.
388 */
389 if (data.found_vif)
390 return 0;
391
392 /* Therefore, in recovery, we can't get here */
fd11bd05
IP
393 if (WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
394 return -EBUSY;
8ca151b5
JB
395
396 mvmvif->id = find_first_bit(data.available_mac_ids,
397 NUM_MAC_INDEX_DRIVER);
398 if (mvmvif->id == NUM_MAC_INDEX_DRIVER) {
399 IWL_ERR(mvm, "Failed to init MAC context - no free ID!\n");
400 ret = -EIO;
401 goto exit_fail;
402 }
403
404 if (data.preferred_tsf != NUM_TSF_IDS)
405 mvmvif->tsf_id = data.preferred_tsf;
406 else
407 mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
408 NUM_TSF_IDS);
409 if (mvmvif->tsf_id == NUM_TSF_IDS) {
410 IWL_ERR(mvm, "Failed to init MAC context - no free TSF!\n");
411 ret = -EIO;
412 goto exit_fail;
413 }
414
415 mvmvif->color = 0;
416
1e849c93
IP
417 INIT_LIST_HEAD(&mvmvif->time_event_data.list);
418 mvmvif->time_event_data.id = TE_MAX;
419
8ca151b5
JB
420 /* No need to allocate data queues to P2P Device MAC.*/
421 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
422 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
423 vif->hw_queue[ac] = IEEE80211_INVAL_HW_QUEUE;
424
425 return 0;
426 }
427
24afba76
LK
428 /*
429 * Find available queues, and allocate them to the ACs. When in
430 * DQA-mode they aren't really used, and this is done only so the
431 * mac80211 ieee80211_check_queues() function won't fail
432 */
8ca151b5 433 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
110cf810 434 u8 queue = find_first_zero_bit(&used_hw_queues,
19e737c9 435 mvm->first_agg_queue);
8ca151b5 436
24afba76
LK
437 if (!iwl_mvm_is_dqa_supported(mvm) &&
438 queue >= mvm->first_agg_queue) {
8ca151b5
JB
439 IWL_ERR(mvm, "Failed to allocate queue\n");
440 ret = -EIO;
441 goto exit_fail;
442 }
443
110cf810 444 __set_bit(queue, &used_hw_queues);
8ca151b5
JB
445 vif->hw_queue[ac] = queue;
446 }
447
448 /* Allocate the CAB queue for softAP and GO interfaces */
449 if (vif->type == NL80211_IFTYPE_AP) {
110cf810 450 u8 queue = find_first_zero_bit(&used_hw_queues,
19e737c9 451 mvm->first_agg_queue);
8ca151b5 452
19e737c9 453 if (queue >= mvm->first_agg_queue) {
8ca151b5
JB
454 IWL_ERR(mvm, "Failed to allocate cab queue\n");
455 ret = -EIO;
456 goto exit_fail;
457 }
458
459 vif->cab_queue = queue;
460 } else {
461 vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
462 }
463
464 mvmvif->bcast_sta.sta_id = IWL_MVM_STATION_COUNT;
465 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
466
9ee718aa
EL
467 for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++)
468 mvmvif->smps_requests[i] = IEEE80211_SMPS_AUTOMATIC;
469
8ca151b5
JB
470 return 0;
471
472exit_fail:
473 memset(mvmvif, 0, sizeof(struct iwl_mvm_vif));
474 memset(vif->hw_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(vif->hw_queue));
475 vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
476 return ret;
477}
478
479int iwl_mvm_mac_ctxt_init(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
480{
5d42e7b2
EG
481 unsigned int wdg_timeout =
482 iwl_mvm_get_wd_timeout(mvm, vif, false, false);
8ca151b5
JB
483 u32 ac;
484 int ret;
485
486 lockdep_assert_held(&mvm->mutex);
487
488 ret = iwl_mvm_mac_ctxt_allocate_resources(mvm, vif);
489 if (ret)
490 return ret;
491
492 switch (vif->type) {
493 case NL80211_IFTYPE_P2P_DEVICE:
3edf8ff6 494 iwl_mvm_enable_ac_txq(mvm, IWL_MVM_OFFCHANNEL_QUEUE,
4ecafae9 495 IWL_MVM_OFFCHANNEL_QUEUE,
5c1156ef 496 IWL_MVM_TX_FIFO_VO, 0, wdg_timeout);
8ca151b5
JB
497 break;
498 case NL80211_IFTYPE_AP:
4ecafae9 499 iwl_mvm_enable_ac_txq(mvm, vif->cab_queue, vif->cab_queue,
5c1156ef 500 IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout);
8ca151b5
JB
501 /* fall through */
502 default:
24afba76
LK
503 /* If DQA is supported - queues will be enabled when needed */
504 if (iwl_mvm_is_dqa_supported(mvm))
505 break;
506
8ca151b5 507 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3edf8ff6 508 iwl_mvm_enable_ac_txq(mvm, vif->hw_queue[ac],
4ecafae9 509 vif->hw_queue[ac],
5c1156ef 510 iwl_mvm_ac_to_tx_fifo[ac], 0,
4cf677fd 511 wdg_timeout);
8ca151b5
JB
512 break;
513 }
514
515 return 0;
516}
517
518void iwl_mvm_mac_ctxt_release(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
519{
520 int ac;
521
522 lockdep_assert_held(&mvm->mutex);
523
524 switch (vif->type) {
525 case NL80211_IFTYPE_P2P_DEVICE:
4ecafae9
LK
526 iwl_mvm_disable_txq(mvm, IWL_MVM_OFFCHANNEL_QUEUE,
527 IWL_MVM_OFFCHANNEL_QUEUE, IWL_MAX_TID_COUNT,
528 0);
8ca151b5
JB
529 break;
530 case NL80211_IFTYPE_AP:
4ecafae9
LK
531 iwl_mvm_disable_txq(mvm, vif->cab_queue, vif->cab_queue,
532 IWL_MAX_TID_COUNT, 0);
8ca151b5
JB
533 /* fall through */
534 default:
24afba76
LK
535 /*
536 * If DQA is supported - queues were already disabled, since in
537 * DQA-mode the queues are a property of the STA and not of the
538 * vif, and at this point the STA was already deleted
539 */
540 if (iwl_mvm_is_dqa_supported(mvm))
541 break;
542
8ca151b5 543 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
4ecafae9
LK
544 iwl_mvm_disable_txq(mvm, vif->hw_queue[ac],
545 vif->hw_queue[ac],
546 IWL_MAX_TID_COUNT, 0);
8ca151b5
JB
547 }
548}
549
550static void iwl_mvm_ack_rates(struct iwl_mvm *mvm,
551 struct ieee80211_vif *vif,
552 enum ieee80211_band band,
553 u8 *cck_rates, u8 *ofdm_rates)
554{
555 struct ieee80211_supported_band *sband;
556 unsigned long basic = vif->bss_conf.basic_rates;
557 int lowest_present_ofdm = 100;
558 int lowest_present_cck = 100;
559 u8 cck = 0;
560 u8 ofdm = 0;
561 int i;
562
563 sband = mvm->hw->wiphy->bands[band];
564
565 for_each_set_bit(i, &basic, BITS_PER_LONG) {
566 int hw = sband->bitrates[i].hw_value;
567 if (hw >= IWL_FIRST_OFDM_RATE) {
568 ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE);
569 if (lowest_present_ofdm > hw)
570 lowest_present_ofdm = hw;
571 } else {
572 BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
573
574 cck |= BIT(hw);
575 if (lowest_present_cck > hw)
576 lowest_present_cck = hw;
577 }
578 }
579
580 /*
581 * Now we've got the basic rates as bitmaps in the ofdm and cck
582 * variables. This isn't sufficient though, as there might not
583 * be all the right rates in the bitmap. E.g. if the only basic
584 * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps
585 * and 6 Mbps because the 802.11-2007 standard says in 9.6:
586 *
587 * [...] a STA responding to a received frame shall transmit
588 * its Control Response frame [...] at the highest rate in the
589 * BSSBasicRateSet parameter that is less than or equal to the
590 * rate of the immediately previous frame in the frame exchange
591 * sequence ([...]) and that is of the same modulation class
592 * ([...]) as the received frame. If no rate contained in the
593 * BSSBasicRateSet parameter meets these conditions, then the
594 * control frame sent in response to a received frame shall be
595 * transmitted at the highest mandatory rate of the PHY that is
596 * less than or equal to the rate of the received frame, and
597 * that is of the same modulation class as the received frame.
598 *
599 * As a consequence, we need to add all mandatory rates that are
600 * lower than all of the basic rates to these bitmaps.
601 */
602
603 if (IWL_RATE_24M_INDEX < lowest_present_ofdm)
604 ofdm |= IWL_RATE_BIT_MSK(24) >> IWL_FIRST_OFDM_RATE;
605 if (IWL_RATE_12M_INDEX < lowest_present_ofdm)
606 ofdm |= IWL_RATE_BIT_MSK(12) >> IWL_FIRST_OFDM_RATE;
607 /* 6M already there or needed so always add */
608 ofdm |= IWL_RATE_BIT_MSK(6) >> IWL_FIRST_OFDM_RATE;
609
610 /*
611 * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP.
612 * Note, however:
613 * - if no CCK rates are basic, it must be ERP since there must
614 * be some basic rates at all, so they're OFDM => ERP PHY
615 * (or we're in 5 GHz, and the cck bitmap will never be used)
616 * - if 11M is a basic rate, it must be ERP as well, so add 5.5M
617 * - if 5.5M is basic, 1M and 2M are mandatory
618 * - if 2M is basic, 1M is mandatory
619 * - if 1M is basic, that's the only valid ACK rate.
620 * As a consequence, it's not as complicated as it sounds, just add
621 * any lower rates to the ACK rate bitmap.
622 */
623 if (IWL_RATE_11M_INDEX < lowest_present_cck)
624 cck |= IWL_RATE_BIT_MSK(11) >> IWL_FIRST_CCK_RATE;
625 if (IWL_RATE_5M_INDEX < lowest_present_cck)
626 cck |= IWL_RATE_BIT_MSK(5) >> IWL_FIRST_CCK_RATE;
627 if (IWL_RATE_2M_INDEX < lowest_present_cck)
628 cck |= IWL_RATE_BIT_MSK(2) >> IWL_FIRST_CCK_RATE;
629 /* 1M already there or needed so always add */
630 cck |= IWL_RATE_BIT_MSK(1) >> IWL_FIRST_CCK_RATE;
631
632 *cck_rates = cck;
633 *ofdm_rates = ofdm;
634}
635
8a5e3660
AA
636static void iwl_mvm_mac_ctxt_set_ht_flags(struct iwl_mvm *mvm,
637 struct ieee80211_vif *vif,
638 struct iwl_mac_ctx_cmd *cmd)
639{
640 /* for both sta and ap, ht_operation_mode hold the protection_mode */
641 u8 protection_mode = vif->bss_conf.ht_operation_mode &
642 IEEE80211_HT_OP_MODE_PROTECTION;
643 /* The fw does not distinguish between ht and fat */
644 u32 ht_flag = MAC_PROT_FLG_HT_PROT | MAC_PROT_FLG_FAT_PROT;
645
646 IWL_DEBUG_RATE(mvm, "protection mode set to %d\n", protection_mode);
647 /*
648 * See section 9.23.3.1 of IEEE 80211-2012.
649 * Nongreenfield HT STAs Present is not supported.
650 */
651 switch (protection_mode) {
652 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
653 break;
654 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
655 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
656 cmd->protection_flags |= cpu_to_le32(ht_flag);
657 break;
658 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
659 /* Protect when channel wider than 20MHz */
660 if (vif->bss_conf.chandef.width > NL80211_CHAN_WIDTH_20)
661 cmd->protection_flags |= cpu_to_le32(ht_flag);
662 break;
663 default:
664 IWL_ERR(mvm, "Illegal protection mode %d\n",
665 protection_mode);
666 break;
667 }
668}
669
8ca151b5
JB
670static void iwl_mvm_mac_ctxt_cmd_common(struct iwl_mvm *mvm,
671 struct ieee80211_vif *vif,
672 struct iwl_mac_ctx_cmd *cmd,
3dfd3a97 673 const u8 *bssid_override,
8ca151b5
JB
674 u32 action)
675{
676 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
677 struct ieee80211_chanctx_conf *chanctx;
8a5e3660
AA
678 bool ht_enabled = !!(vif->bss_conf.ht_operation_mode &
679 IEEE80211_HT_OP_MODE_PROTECTION);
8ca151b5 680 u8 cck_ack_rates, ofdm_ack_rates;
3dfd3a97 681 const u8 *bssid = bssid_override ?: vif->bss_conf.bssid;
8ca151b5
JB
682 int i;
683
684 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
685 mvmvif->color));
686 cmd->action = cpu_to_le32(action);
687
688 switch (vif->type) {
689 case NL80211_IFTYPE_STATION:
690 if (vif->p2p)
691 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_P2P_STA);
692 else
693 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_BSS_STA);
694 break;
695 case NL80211_IFTYPE_AP:
696 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_GO);
697 break;
698 case NL80211_IFTYPE_MONITOR:
699 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_LISTENER);
700 break;
701 case NL80211_IFTYPE_P2P_DEVICE:
702 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_P2P_DEVICE);
703 break;
704 case NL80211_IFTYPE_ADHOC:
705 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_IBSS);
706 break;
707 default:
708 WARN_ON_ONCE(1);
709 }
710
711 cmd->tsf_id = cpu_to_le32(mvmvif->tsf_id);
712
713 memcpy(cmd->node_addr, vif->addr, ETH_ALEN);
3dfd3a97
JB
714
715 if (bssid)
716 memcpy(cmd->bssid_addr, bssid, ETH_ALEN);
8ca151b5
JB
717 else
718 eth_broadcast_addr(cmd->bssid_addr);
719
720 rcu_read_lock();
721 chanctx = rcu_dereference(vif->chanctx_conf);
722 iwl_mvm_ack_rates(mvm, vif, chanctx ? chanctx->def.chan->band
723 : IEEE80211_BAND_2GHZ,
724 &cck_ack_rates, &ofdm_ack_rates);
725 rcu_read_unlock();
726
727 cmd->cck_rates = cpu_to_le32((u32)cck_ack_rates);
728 cmd->ofdm_rates = cpu_to_le32((u32)ofdm_ack_rates);
729
730 cmd->cck_short_preamble =
731 cpu_to_le32(vif->bss_conf.use_short_preamble ?
732 MAC_FLG_SHORT_PREAMBLE : 0);
733 cmd->short_slot =
734 cpu_to_le32(vif->bss_conf.use_short_slot ?
735 MAC_FLG_SHORT_SLOT : 0);
736
bd6f5bd7
AB
737 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP);
738
3dd94794
EG
739 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
740 u8 txf = iwl_mvm_ac_to_tx_fifo[i];
741
742 cmd->ac[txf].cw_min =
743 cpu_to_le16(mvmvif->queue_params[i].cw_min);
744 cmd->ac[txf].cw_max =
745 cpu_to_le16(mvmvif->queue_params[i].cw_max);
746 cmd->ac[txf].edca_txop =
8ca151b5 747 cpu_to_le16(mvmvif->queue_params[i].txop * 32);
3dd94794
EG
748 cmd->ac[txf].aifsn = mvmvif->queue_params[i].aifs;
749 cmd->ac[txf].fifos_mask = BIT(txf);
8ca151b5
JB
750 }
751
bd6f5bd7
AB
752 if (vif->type == NL80211_IFTYPE_AP) {
753 /* in AP mode, the MCAST FIFO takes the EDCA params from VO */
3dd94794
EG
754 cmd->ac[IWL_MVM_TX_FIFO_VO].fifos_mask |=
755 BIT(IWL_MVM_TX_FIFO_MCAST);
86a91ec7 756
bd6f5bd7
AB
757 /*
758 * in AP mode, pass probe requests and beacons from other APs
759 * (needed for ht protection); when there're no any associated
760 * station don't ask FW to pass beacons to prevent unnecessary
761 * wake-ups.
762 */
763 cmd->filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
c89e333d 764 if (mvmvif->ap_assoc_sta_count || !mvm->drop_bcn_ap_mode) {
bd6f5bd7
AB
765 cmd->filter_flags |= cpu_to_le32(MAC_FILTER_IN_BEACON);
766 IWL_DEBUG_HC(mvm, "Asking FW to pass beacons\n");
767 } else {
768 IWL_DEBUG_HC(mvm, "No need to receive beacons\n");
769 }
770 }
771
8ca151b5
JB
772 if (vif->bss_conf.qos)
773 cmd->qos_flags |= cpu_to_le32(MAC_QOS_FLG_UPDATE_EDCA);
774
dc271ee0 775 if (vif->bss_conf.use_cts_prot)
cc7ee2ba 776 cmd->protection_flags |= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT);
dc271ee0 777
8a5e3660
AA
778 IWL_DEBUG_RATE(mvm, "use_cts_prot %d, ht_operation_mode %d\n",
779 vif->bss_conf.use_cts_prot,
780 vif->bss_conf.ht_operation_mode);
781 if (vif->bss_conf.chandef.width != NL80211_CHAN_WIDTH_20_NOHT)
8ca151b5 782 cmd->qos_flags |= cpu_to_le32(MAC_QOS_FLG_TGN);
8a5e3660
AA
783 if (ht_enabled)
784 iwl_mvm_mac_ctxt_set_ht_flags(mvm, vif, cmd);
8ca151b5
JB
785}
786
787static int iwl_mvm_mac_ctxt_send_cmd(struct iwl_mvm *mvm,
788 struct iwl_mac_ctx_cmd *cmd)
789{
a1022927 790 int ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, 0,
8ca151b5
JB
791 sizeof(*cmd), cmd);
792 if (ret)
793 IWL_ERR(mvm, "Failed to send MAC context (action:%d): %d\n",
794 le32_to_cpu(cmd->action), ret);
795 return ret;
796}
797
cf52023c
LC
798static int iwl_mvm_mac_ctxt_cmd_sta(struct iwl_mvm *mvm,
799 struct ieee80211_vif *vif,
3dfd3a97
JB
800 u32 action, bool force_assoc_off,
801 const u8 *bssid_override)
8ca151b5 802{
cf52023c
LC
803 struct iwl_mac_ctx_cmd cmd = {};
804 struct iwl_mac_data_sta *ctxt_sta;
805
806 WARN_ON(vif->type != NL80211_IFTYPE_STATION);
807
808 /* Fill the common data for all mac context types */
3dfd3a97 809 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, bssid_override, action);
cf52023c
LC
810
811 if (vif->p2p) {
812 struct ieee80211_p2p_noa_attr *noa =
813 &vif->bss_conf.p2p_noa_attr;
814
815 cmd.p2p_sta.ctwin = cpu_to_le32(noa->oppps_ctwindow &
816 IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
817 ctxt_sta = &cmd.p2p_sta.sta;
818 } else {
cf52023c
LC
819 ctxt_sta = &cmd.sta;
820 }
821
210a544e 822 /* We need the dtim_period to set the MAC as associated */
ba283927
AB
823 if (vif->bss_conf.assoc && vif->bss_conf.dtim_period &&
824 !force_assoc_off) {
d2931bbd
JB
825 u32 dtim_offs;
826
827 /*
828 * The DTIM count counts down, so when it is N that means N
829 * more beacon intervals happen until the DTIM TBTT. Therefore
830 * add this to the current time. If that ends up being in the
831 * future, the firmware will handle it.
832 *
833 * Also note that the system_timestamp (which we get here as
834 * "sync_device_ts") and TSF timestamp aren't at exactly the
835 * same offset in the frame -- the TSF is at the first symbol
836 * of the TSF, the system timestamp is at signal acquisition
837 * time. This means there's an offset between them of at most
838 * a few hundred microseconds (24 * 8 bits + PLCP time gives
839 * 384us in the longest case), this is currently not relevant
840 * as the firmware wakes up around 2ms before the TBTT.
841 */
842 dtim_offs = vif->bss_conf.sync_dtim_count *
843 vif->bss_conf.beacon_int;
844 /* convert TU to usecs */
845 dtim_offs *= 1024;
846
847 ctxt_sta->dtim_tsf =
848 cpu_to_le64(vif->bss_conf.sync_tsf + dtim_offs);
849 ctxt_sta->dtim_time =
850 cpu_to_le32(vif->bss_conf.sync_device_ts + dtim_offs);
851
852 IWL_DEBUG_INFO(mvm, "DTIM TBTT is 0x%llx/0x%x, offset %d\n",
853 le64_to_cpu(ctxt_sta->dtim_tsf),
854 le32_to_cpu(ctxt_sta->dtim_time),
855 dtim_offs);
856
210a544e 857 ctxt_sta->is_assoc = cpu_to_le32(1);
d2931bbd 858 } else {
210a544e 859 ctxt_sta->is_assoc = cpu_to_le32(0);
7c8b3bc6
LC
860
861 /* Allow beacons to pass through as long as we are not
862 * associated, or we do not have dtim period information.
863 */
864 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_BEACON);
d2931bbd 865 }
8ca151b5
JB
866
867 ctxt_sta->bi = cpu_to_le32(vif->bss_conf.beacon_int);
868 ctxt_sta->bi_reciprocal =
869 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
870 ctxt_sta->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
871 vif->bss_conf.dtim_period);
872 ctxt_sta->dtim_reciprocal =
873 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int *
874 vif->bss_conf.dtim_period));
875
876 ctxt_sta->listen_interval = cpu_to_le32(mvm->hw->conf.listen_interval);
877 ctxt_sta->assoc_id = cpu_to_le32(vif->bss_conf.aid);
8ca151b5 878
effd1929
AO
879 if (vif->probe_req_reg && vif->bss_conf.assoc && vif->p2p)
880 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
881
8ca151b5
JB
882 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
883}
884
885static int iwl_mvm_mac_ctxt_cmd_listener(struct iwl_mvm *mvm,
886 struct ieee80211_vif *vif,
887 u32 action)
888{
889 struct iwl_mac_ctx_cmd cmd = {};
0e39eb03
CRI
890 u32 tfd_queue_msk = 0;
891 int ret, i;
8ca151b5
JB
892
893 WARN_ON(vif->type != NL80211_IFTYPE_MONITOR);
894
3dfd3a97 895 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
53585495 896
0e39eb03
CRI
897 for (i = 0; i < IEEE80211_NUM_ACS; i++)
898 if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE)
899 tfd_queue_msk |= BIT(vif->hw_queue[i]);
900
53585495
JB
901 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROMISC |
902 MAC_FILTER_IN_CONTROL_AND_MGMT |
903 MAC_FILTER_IN_BEACON |
fb8b8ee1
JB
904 MAC_FILTER_IN_PROBE_REQUEST |
905 MAC_FILTER_IN_CRC32);
30686bf7 906 ieee80211_hw_set(mvm->hw, RX_INCLUDES_FCS);
53585495 907
0e39eb03
CRI
908 /* Allocate sniffer station */
909 ret = iwl_mvm_allocate_int_sta(mvm, &mvm->snif_sta, tfd_queue_msk,
910 vif->type);
911 if (ret)
912 return ret;
913
8ca151b5
JB
914 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
915}
916
5023d966
JB
917static int iwl_mvm_mac_ctxt_cmd_ibss(struct iwl_mvm *mvm,
918 struct ieee80211_vif *vif,
919 u32 action)
920{
921 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
922 struct iwl_mac_ctx_cmd cmd = {};
923
924 WARN_ON(vif->type != NL80211_IFTYPE_ADHOC);
925
3dfd3a97 926 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
5023d966
JB
927
928 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_BEACON |
929 MAC_FILTER_IN_PROBE_REQUEST);
930
931 /* cmd.ibss.beacon_time/cmd.ibss.beacon_tsf are curently ignored */
932 cmd.ibss.bi = cpu_to_le32(vif->bss_conf.beacon_int);
933 cmd.ibss.bi_reciprocal =
934 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
935
936 /* TODO: Assumes that the beacon id == mac context id */
937 cmd.ibss.beacon_template = cpu_to_le32(mvmvif->id);
938
939 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
940}
941
8ca151b5
JB
942struct iwl_mvm_go_iterator_data {
943 bool go_active;
944};
945
946static void iwl_mvm_go_iterator(void *_data, u8 *mac, struct ieee80211_vif *vif)
947{
948 struct iwl_mvm_go_iterator_data *data = _data;
949 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
950
5023d966
JB
951 if (vif->type == NL80211_IFTYPE_AP && vif->p2p &&
952 mvmvif->ap_ibss_active)
8ca151b5
JB
953 data->go_active = true;
954}
955
956static int iwl_mvm_mac_ctxt_cmd_p2p_device(struct iwl_mvm *mvm,
957 struct ieee80211_vif *vif,
958 u32 action)
959{
960 struct iwl_mac_ctx_cmd cmd = {};
961 struct iwl_mvm_go_iterator_data data = {};
962
963 WARN_ON(vif->type != NL80211_IFTYPE_P2P_DEVICE);
964
3dfd3a97 965 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
8ca151b5
JB
966
967 cmd.protection_flags |= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT);
1dcd15ee
IP
968
969 /* Override the filter flags to accept only probe requests */
970 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
8ca151b5
JB
971
972 /*
973 * This flag should be set to true when the P2P Device is
974 * discoverable and there is at least another active P2P GO. Settings
975 * this flag will allow the P2P Device to be discoverable on other
976 * channels in addition to its listen channel.
977 * Note that this flag should not be set in other cases as it opens the
978 * Rx filters on all MAC and increases the number of interrupts.
979 */
980 ieee80211_iterate_active_interfaces_atomic(
981 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
982 iwl_mvm_go_iterator, &data);
983
984 cmd.p2p_dev.is_disc_extended = cpu_to_le32(data.go_active ? 1 : 0);
985 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
986}
987
988static void iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm *mvm,
989 struct iwl_mac_beacon_cmd *beacon_cmd,
990 u8 *beacon, u32 frame_size)
991{
992 u32 tim_idx;
993 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
994
995 /* The index is relative to frame start but we start looking at the
996 * variable-length part of the beacon. */
997 tim_idx = mgmt->u.beacon.variable - beacon;
998
999 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
1000 while ((tim_idx < (frame_size - 2)) &&
1001 (beacon[tim_idx] != WLAN_EID_TIM))
1002 tim_idx += beacon[tim_idx+1] + 2;
1003
1004 /* If TIM field was found, set variables */
1005 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
1006 beacon_cmd->tim_idx = cpu_to_le32(tim_idx);
1007 beacon_cmd->tim_size = cpu_to_le32((u32)beacon[tim_idx+1]);
1008 } else {
1009 IWL_WARN(mvm, "Unable to find TIM Element in beacon\n");
1010 }
1011}
1012
1013static int iwl_mvm_mac_ctxt_send_beacon(struct iwl_mvm *mvm,
1014 struct ieee80211_vif *vif,
1015 struct sk_buff *beacon)
1016{
1017 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1018 struct iwl_host_cmd cmd = {
1019 .id = BEACON_TEMPLATE_CMD,
1020 .flags = CMD_ASYNC,
1021 };
1022 struct iwl_mac_beacon_cmd beacon_cmd = {};
1023 struct ieee80211_tx_info *info;
1024 u32 beacon_skb_len;
75f6b9b6 1025 u32 rate, tx_flags;
8ca151b5
JB
1026
1027 if (WARN_ON(!beacon))
1028 return -EINVAL;
1029
1030 beacon_skb_len = beacon->len;
1031
1032 /* TODO: for now the beacon template id is set to be the mac context id.
1033 * Might be better to handle it as another resource ... */
1034 beacon_cmd.template_id = cpu_to_le32((u32)mvmvif->id);
75f6b9b6 1035 info = IEEE80211_SKB_CB(beacon);
8ca151b5
JB
1036
1037 /* Set up TX command fields */
1038 beacon_cmd.tx.len = cpu_to_le16((u16)beacon_skb_len);
1039 beacon_cmd.tx.sta_id = mvmvif->bcast_sta.sta_id;
1040 beacon_cmd.tx.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
75f6b9b6
EG
1041 tx_flags = TX_CMD_FLG_SEQ_CTL | TX_CMD_FLG_TSF;
1042 tx_flags |=
1043 iwl_mvm_bt_coex_tx_prio(mvm, (void *)beacon->data, info, 0) <<
1044 TX_CMD_FLG_BT_PRIO_POS;
1045 beacon_cmd.tx.tx_flags = cpu_to_le32(tx_flags);
8ca151b5 1046
1e3c3c35
EG
1047 if (!fw_has_capa(&mvm->fw->ucode_capa,
1048 IWL_UCODE_TLV_CAPA_BEACON_ANT_SELECTION)) {
1049 mvm->mgmt_last_antenna_idx =
1050 iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm),
1051 mvm->mgmt_last_antenna_idx);
1052 }
8ca151b5
JB
1053
1054 beacon_cmd.tx.rate_n_flags =
1055 cpu_to_le32(BIT(mvm->mgmt_last_antenna_idx) <<
1056 RATE_MCS_ANT_POS);
1057
8ca151b5
JB
1058 if (info->band == IEEE80211_BAND_5GHZ || vif->p2p) {
1059 rate = IWL_FIRST_OFDM_RATE;
1060 } else {
1061 rate = IWL_FIRST_CCK_RATE;
1062 beacon_cmd.tx.rate_n_flags |= cpu_to_le32(RATE_MCS_CCK_MSK);
1063 }
1064 beacon_cmd.tx.rate_n_flags |=
1065 cpu_to_le32(iwl_mvm_mac80211_idx_to_hwrate(rate));
1066
1067 /* Set up TX beacon command fields */
5023d966
JB
1068 if (vif->type == NL80211_IFTYPE_AP)
1069 iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd,
1070 beacon->data,
1071 beacon_skb_len);
8ca151b5
JB
1072
1073 /* Submit command */
1074 cmd.len[0] = sizeof(beacon_cmd);
1075 cmd.data[0] = &beacon_cmd;
1076 cmd.dataflags[0] = 0;
1077 cmd.len[1] = beacon_skb_len;
1078 cmd.data[1] = beacon->data;
1079 cmd.dataflags[1] = IWL_HCMD_DFL_DUP;
1080
1081 return iwl_mvm_send_cmd(mvm, &cmd);
1082}
1083
5023d966 1084/* The beacon template for the AP/GO/IBSS has changed and needs update */
8ca151b5
JB
1085int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm,
1086 struct ieee80211_vif *vif)
1087{
1088 struct sk_buff *beacon;
1089 int ret;
1090
5023d966
JB
1091 WARN_ON(vif->type != NL80211_IFTYPE_AP &&
1092 vif->type != NL80211_IFTYPE_ADHOC);
8ca151b5 1093
fe887665 1094 beacon = ieee80211_beacon_get_template(mvm->hw, vif, NULL);
8ca151b5
JB
1095 if (!beacon)
1096 return -ENOMEM;
1097
1098 ret = iwl_mvm_mac_ctxt_send_beacon(mvm, vif, beacon);
1099 dev_kfree_skb(beacon);
1100 return ret;
1101}
1102
3a3cb92e
IP
1103struct iwl_mvm_mac_ap_iterator_data {
1104 struct iwl_mvm *mvm;
1105 struct ieee80211_vif *vif;
1106 u32 beacon_device_ts;
1107 u16 beacon_int;
1108};
1109
1110/* Find the beacon_device_ts and beacon_int for a managed interface */
1111static void iwl_mvm_mac_ap_iterator(void *_data, u8 *mac,
1112 struct ieee80211_vif *vif)
1113{
1114 struct iwl_mvm_mac_ap_iterator_data *data = _data;
1115
1116 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
1117 return;
1118
1119 /* Station client has higher priority over P2P client*/
1120 if (vif->p2p && data->beacon_device_ts)
1121 return;
1122
1123 data->beacon_device_ts = vif->bss_conf.sync_device_ts;
1124 data->beacon_int = vif->bss_conf.beacon_int;
1125}
1126
8ca151b5
JB
1127/*
1128 * Fill the specific data for mac context of type AP of P2P GO
1129 */
1130static void iwl_mvm_mac_ctxt_cmd_fill_ap(struct iwl_mvm *mvm,
1131 struct ieee80211_vif *vif,
506a81e6
JB
1132 struct iwl_mac_data_ap *ctxt_ap,
1133 bool add)
8ca151b5
JB
1134{
1135 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3a3cb92e
IP
1136 struct iwl_mvm_mac_ap_iterator_data data = {
1137 .mvm = mvm,
1138 .vif = vif,
1139 .beacon_device_ts = 0
1140 };
8ca151b5
JB
1141
1142 ctxt_ap->bi = cpu_to_le32(vif->bss_conf.beacon_int);
1143 ctxt_ap->bi_reciprocal =
1144 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
1145 ctxt_ap->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
1146 vif->bss_conf.dtim_period);
1147 ctxt_ap->dtim_reciprocal =
1148 cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int *
1149 vif->bss_conf.dtim_period));
1150
1151 ctxt_ap->mcast_qid = cpu_to_le32(vif->cab_queue);
8ca151b5 1152
506a81e6 1153 /*
3a3cb92e 1154 * Only set the beacon time when the MAC is being added, when we
506a81e6
JB
1155 * just modify the MAC then we should keep the time -- the firmware
1156 * can otherwise have a "jumping" TBTT.
1157 */
3a3cb92e
IP
1158 if (add) {
1159 /*
1160 * If there is a station/P2P client interface which is
1161 * associated, set the AP's TBTT far enough from the station's
1162 * TBTT. Otherwise, set it to the current system time
1163 */
1164 ieee80211_iterate_active_interfaces_atomic(
1165 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1166 iwl_mvm_mac_ap_iterator, &data);
1167
1168 if (data.beacon_device_ts) {
9f8f8ca5 1169 u32 rand = (prandom_u32() % (64 - 36)) + 36;
3a3cb92e
IP
1170 mvmvif->ap_beacon_time = data.beacon_device_ts +
1171 ieee80211_tu_to_usec(data.beacon_int * rand /
1172 100);
1173 } else {
1174 mvmvif->ap_beacon_time =
1175 iwl_read_prph(mvm->trans,
1176 DEVICE_SYSTEM_TIME_REG);
1177 }
1178 }
506a81e6
JB
1179
1180 ctxt_ap->beacon_time = cpu_to_le32(mvmvif->ap_beacon_time);
506a81e6 1181 ctxt_ap->beacon_tsf = 0; /* unused */
8ca151b5
JB
1182
1183 /* TODO: Assume that the beacon id == mac context id */
1184 ctxt_ap->beacon_template = cpu_to_le32(mvmvif->id);
1185}
1186
f82c8339
IP
1187static int iwl_mvm_mac_ctxt_cmd_ap(struct iwl_mvm *mvm,
1188 struct ieee80211_vif *vif,
1189 u32 action)
8ca151b5
JB
1190{
1191 struct iwl_mac_ctx_cmd cmd = {};
1192
1193 WARN_ON(vif->type != NL80211_IFTYPE_AP || vif->p2p);
1194
1195 /* Fill the common data for all mac context types */
3dfd3a97 1196 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
8ca151b5
JB
1197
1198 /* Fill the data specific for ap mode */
506a81e6
JB
1199 iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd.ap,
1200 action == FW_CTXT_ACTION_ADD);
8ca151b5
JB
1201
1202 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1203}
1204
1205static int iwl_mvm_mac_ctxt_cmd_go(struct iwl_mvm *mvm,
1206 struct ieee80211_vif *vif,
1207 u32 action)
1208{
1209 struct iwl_mac_ctx_cmd cmd = {};
67baf663 1210 struct ieee80211_p2p_noa_attr *noa = &vif->bss_conf.p2p_noa_attr;
8ca151b5
JB
1211
1212 WARN_ON(vif->type != NL80211_IFTYPE_AP || !vif->p2p);
1213
1214 /* Fill the common data for all mac context types */
3dfd3a97 1215 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
8ca151b5
JB
1216
1217 /* Fill the data specific for GO mode */
506a81e6
JB
1218 iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd.go.ap,
1219 action == FW_CTXT_ACTION_ADD);
8ca151b5 1220
67baf663
JD
1221 cmd.go.ctwin = cpu_to_le32(noa->oppps_ctwindow &
1222 IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
1223 cmd.go.opp_ps_enabled =
1224 cpu_to_le32(!!(noa->oppps_ctwindow &
1225 IEEE80211_P2P_OPPPS_ENABLE_BIT));
8ca151b5
JB
1226
1227 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1228}
1229
1230static int iwl_mvm_mac_ctx_send(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
3dfd3a97
JB
1231 u32 action, bool force_assoc_off,
1232 const u8 *bssid_override)
8ca151b5
JB
1233{
1234 switch (vif->type) {
1235 case NL80211_IFTYPE_STATION:
cf52023c 1236 return iwl_mvm_mac_ctxt_cmd_sta(mvm, vif, action,
3dfd3a97
JB
1237 force_assoc_off,
1238 bssid_override);
8ca151b5
JB
1239 break;
1240 case NL80211_IFTYPE_AP:
1241 if (!vif->p2p)
1242 return iwl_mvm_mac_ctxt_cmd_ap(mvm, vif, action);
1243 else
1244 return iwl_mvm_mac_ctxt_cmd_go(mvm, vif, action);
1245 break;
1246 case NL80211_IFTYPE_MONITOR:
1247 return iwl_mvm_mac_ctxt_cmd_listener(mvm, vif, action);
1248 case NL80211_IFTYPE_P2P_DEVICE:
1249 return iwl_mvm_mac_ctxt_cmd_p2p_device(mvm, vif, action);
5023d966
JB
1250 case NL80211_IFTYPE_ADHOC:
1251 return iwl_mvm_mac_ctxt_cmd_ibss(mvm, vif, action);
8ca151b5
JB
1252 default:
1253 break;
1254 }
1255
1256 return -EOPNOTSUPP;
1257}
1258
1259int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1260{
1261 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1262 int ret;
1263
1264 if (WARN_ONCE(mvmvif->uploaded, "Adding active MAC %pM/%d\n",
1265 vif->addr, ieee80211_vif_type_p2p(vif)))
1266 return -EIO;
1267
bca49d9a 1268 ret = iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_ADD,
3dfd3a97 1269 true, NULL);
8ca151b5
JB
1270 if (ret)
1271 return ret;
1272
6d9d32b8
JB
1273 /* will only do anything at resume from D3 time */
1274 iwl_mvm_set_last_nonqos_seq(mvm, vif);
1275
8ca151b5
JB
1276 mvmvif->uploaded = true;
1277 return 0;
1278}
1279
bca49d9a 1280int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
3dfd3a97 1281 bool force_assoc_off, const u8 *bssid_override)
8ca151b5
JB
1282{
1283 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1284
1285 if (WARN_ONCE(!mvmvif->uploaded, "Changing inactive MAC %pM/%d\n",
1286 vif->addr, ieee80211_vif_type_p2p(vif)))
1287 return -EIO;
1288
bca49d9a 1289 return iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_MODIFY,
3dfd3a97 1290 force_assoc_off, bssid_override);
8ca151b5
JB
1291}
1292
1293int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1294{
1295 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1296 struct iwl_mac_ctx_cmd cmd;
1297 int ret;
1298
1299 if (WARN_ONCE(!mvmvif->uploaded, "Removing inactive MAC %pM/%d\n",
1300 vif->addr, ieee80211_vif_type_p2p(vif)))
1301 return -EIO;
1302
1303 memset(&cmd, 0, sizeof(cmd));
1304
1305 cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1306 mvmvif->color));
1307 cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE);
1308
a1022927 1309 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, 0,
8ca151b5
JB
1310 sizeof(cmd), &cmd);
1311 if (ret) {
1312 IWL_ERR(mvm, "Failed to remove MAC context: %d\n", ret);
1313 return ret;
1314 }
1315
1316 mvmvif->uploaded = false;
fb8b8ee1 1317
0e39eb03 1318 if (vif->type == NL80211_IFTYPE_MONITOR) {
30686bf7 1319 __clear_bit(IEEE80211_HW_RX_INCLUDES_FCS, mvm->hw->flags);
0e39eb03
CRI
1320 iwl_mvm_dealloc_snif_sta(mvm);
1321 }
fb8b8ee1 1322
8ca151b5
JB
1323 return 0;
1324}
571765c8 1325
7f0a7c67 1326static void iwl_mvm_csa_count_down(struct iwl_mvm *mvm,
7ef0aab6
AO
1327 struct ieee80211_vif *csa_vif, u32 gp2,
1328 bool tx_success)
7f0a7c67
AO
1329{
1330 struct iwl_mvm_vif *mvmvif =
1331 iwl_mvm_vif_from_mac80211(csa_vif);
1332
7ef0aab6
AO
1333 /* Don't start to countdown from a failed beacon */
1334 if (!tx_success && !mvmvif->csa_countdown)
1335 return;
1336
1337 mvmvif->csa_countdown = true;
1338
7f0a7c67
AO
1339 if (!ieee80211_csa_is_complete(csa_vif)) {
1340 int c = ieee80211_csa_update_counter(csa_vif);
1341
1342 iwl_mvm_mac_ctxt_beacon_changed(mvm, csa_vif);
1343 if (csa_vif->p2p &&
7ef0aab6
AO
1344 !iwl_mvm_te_scheduled(&mvmvif->time_event_data) && gp2 &&
1345 tx_success) {
7f0a7c67
AO
1346 u32 rel_time = (c + 1) *
1347 csa_vif->bss_conf.beacon_int -
f991e17b 1348 IWL_MVM_CHANNEL_SWITCH_TIME_GO;
7f0a7c67
AO
1349 u32 apply_time = gp2 + rel_time * 1024;
1350
f991e17b
LC
1351 iwl_mvm_schedule_csa_period(mvm, csa_vif,
1352 IWL_MVM_CHANNEL_SWITCH_TIME_GO -
1353 IWL_MVM_CHANNEL_SWITCH_MARGIN,
1354 apply_time);
7f0a7c67
AO
1355 }
1356 } else if (!iwl_mvm_te_scheduled(&mvmvif->time_event_data)) {
1357 /* we don't have CSA NoA scheduled yet, switch now */
1358 ieee80211_csa_finish(csa_vif);
1359 RCU_INIT_POINTER(mvm->csa_vif, NULL);
1360 }
1361}
1362
0416841d
JB
1363void iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
1364 struct iwl_rx_cmd_buffer *rxb)
571765c8
IP
1365{
1366 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2d2c0e9c 1367 struct iwl_extended_beacon_notif *beacon = (void *)pkt->data;
1c87bbad 1368 struct iwl_mvm_tx_resp *beacon_notify_hdr;
664322fa 1369 struct ieee80211_vif *csa_vif;
003e5236 1370 struct ieee80211_vif *tx_blocked_vif;
7ef0aab6 1371 u16 status;
571765c8 1372
bd3398e2
AO
1373 lockdep_assert_held(&mvm->mutex);
1374
2d2c0e9c
EG
1375 beacon_notify_hdr = &beacon->beacon_notify_hdr;
1376 mvm->ap_last_beacon_gp2 = le32_to_cpu(beacon->gp2);
1c87bbad 1377
7ef0aab6 1378 status = le16_to_cpu(beacon_notify_hdr->status.status) & TX_STATUS_MSK;
1c87bbad
DS
1379 IWL_DEBUG_RX(mvm,
1380 "beacon status %#x retries:%d tsf:0x%16llX gp2:0x%X rate:%d\n",
2d2c0e9c
EG
1381 status, beacon_notify_hdr->failure_frame,
1382 le64_to_cpu(beacon->tsf),
1c87bbad
DS
1383 mvm->ap_last_beacon_gp2,
1384 le32_to_cpu(beacon_notify_hdr->initial_rate));
bd3398e2 1385
664322fa
AO
1386 csa_vif = rcu_dereference_protected(mvm->csa_vif,
1387 lockdep_is_held(&mvm->mutex));
7f0a7c67 1388 if (unlikely(csa_vif && csa_vif->csa_active))
7ef0aab6
AO
1389 iwl_mvm_csa_count_down(mvm, csa_vif, mvm->ap_last_beacon_gp2,
1390 (status == TX_STATUS_SUCCESS));
bd3398e2 1391
003e5236
AO
1392 tx_blocked_vif = rcu_dereference_protected(mvm->csa_tx_blocked_vif,
1393 lockdep_is_held(&mvm->mutex));
1394 if (unlikely(tx_blocked_vif)) {
1395 struct iwl_mvm_vif *mvmvif =
1396 iwl_mvm_vif_from_mac80211(tx_blocked_vif);
1397
1398 /*
1399 * The channel switch is started and we have blocked the
1400 * stations. If this is the first beacon (the timeout wasn't
1401 * set), set the unblock timeout, otherwise countdown
1402 */
1403 if (!mvm->csa_tx_block_bcn_timeout)
1404 mvm->csa_tx_block_bcn_timeout =
1405 IWL_MVM_CS_UNBLOCK_TX_TIMEOUT;
1406 else
1407 mvm->csa_tx_block_bcn_timeout--;
1408
1409 /* Check if the timeout is expired, and unblock tx */
1410 if (mvm->csa_tx_block_bcn_timeout == 0) {
1411 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false);
1412 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
1413 }
1414 }
571765c8 1415}
d64048ed
HG
1416
1417static void iwl_mvm_beacon_loss_iterator(void *_data, u8 *mac,
1418 struct ieee80211_vif *vif)
1419{
12d423e8 1420 struct iwl_missed_beacons_notif *missed_beacons = _data;
d64048ed 1421 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
9d761fd8
EG
1422 struct iwl_mvm *mvm = mvmvif->mvm;
1423 struct iwl_fw_dbg_trigger_missed_bcon *bcon_trig;
1424 struct iwl_fw_dbg_trigger_tlv *trigger;
1425 u32 stop_trig_missed_bcon, stop_trig_missed_bcon_since_rx;
1426 u32 rx_missed_bcon, rx_missed_bcon_since_rx;
d64048ed 1427
12d423e8
IP
1428 if (mvmvif->id != (u16)le32_to_cpu(missed_beacons->mac_id))
1429 return;
1430
9d761fd8
EG
1431 rx_missed_bcon = le32_to_cpu(missed_beacons->consec_missed_beacons);
1432 rx_missed_bcon_since_rx =
1433 le32_to_cpu(missed_beacons->consec_missed_beacons_since_last_rx);
12d423e8
IP
1434 /*
1435 * TODO: the threshold should be adjusted based on latency conditions,
1436 * and/or in case of a CS flow on one of the other AP vifs.
1437 */
1438 if (le32_to_cpu(missed_beacons->consec_missed_beacons_since_last_rx) >
1439 IWL_MVM_MISSED_BEACONS_THRESHOLD)
d64048ed 1440 ieee80211_beacon_loss(vif);
9d761fd8
EG
1441
1442 if (!iwl_fw_dbg_trigger_enabled(mvm->fw,
1443 FW_DBG_TRIGGER_MISSED_BEACONS))
1444 return;
1445
1446 trigger = iwl_fw_dbg_get_trigger(mvm->fw,
1447 FW_DBG_TRIGGER_MISSED_BEACONS);
1448 bcon_trig = (void *)trigger->data;
1449 stop_trig_missed_bcon = le32_to_cpu(bcon_trig->stop_consec_missed_bcon);
1450 stop_trig_missed_bcon_since_rx =
1451 le32_to_cpu(bcon_trig->stop_consec_missed_bcon_since_rx);
1452
1453 /* TODO: implement start trigger */
1454
1455 if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trigger))
1456 return;
1457
1458 if (rx_missed_bcon_since_rx >= stop_trig_missed_bcon_since_rx ||
1459 rx_missed_bcon >= stop_trig_missed_bcon)
5d4f929e 1460 iwl_mvm_fw_dbg_collect_trig(mvm, trigger, NULL);
d64048ed
HG
1461}
1462
0416841d
JB
1463void iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm,
1464 struct iwl_rx_cmd_buffer *rxb)
d64048ed
HG
1465{
1466 struct iwl_rx_packet *pkt = rxb_addr(rxb);
12d423e8
IP
1467 struct iwl_missed_beacons_notif *mb = (void *)pkt->data;
1468
1469 IWL_DEBUG_INFO(mvm,
1470 "missed bcn mac_id=%u, consecutive=%u (%u, %u, %u)\n",
1471 le32_to_cpu(mb->mac_id),
1472 le32_to_cpu(mb->consec_missed_beacons),
1473 le32_to_cpu(mb->consec_missed_beacons_since_last_rx),
1474 le32_to_cpu(mb->num_recvd_beacons),
1475 le32_to_cpu(mb->num_expected_beacons));
d64048ed
HG
1476
1477 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
1478 IEEE80211_IFACE_ITER_NORMAL,
1479 iwl_mvm_beacon_loss_iterator,
12d423e8 1480 mb);
d64048ed 1481}
0db056d3
SS
1482
1483void iwl_mvm_rx_stored_beacon_notif(struct iwl_mvm *mvm,
1484 struct iwl_rx_cmd_buffer *rxb)
1485{
1486 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1487 struct iwl_stored_beacon_notif *sb = (void *)pkt->data;
1488 struct ieee80211_rx_status rx_status;
1489 struct sk_buff *skb;
1490 u32 size = le32_to_cpu(sb->byte_count);
1491
1492 if (size == 0)
1493 return;
1494
1495 skb = alloc_skb(size, GFP_ATOMIC);
1496 if (!skb) {
1497 IWL_ERR(mvm, "alloc_skb failed\n");
1498 return;
1499 }
1500
1501 /* update rx_status according to the notification's metadata */
1502 memset(&rx_status, 0, sizeof(rx_status));
1503 rx_status.mactime = le64_to_cpu(sb->tsf);
77fe7395
SS
1504 /* TSF as indicated by the firmware is at INA time */
1505 rx_status.flag |= RX_FLAG_MACTIME_PLCP_START;
0db056d3
SS
1506 rx_status.device_timestamp = le32_to_cpu(sb->system_time);
1507 rx_status.band =
1508 (sb->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_BAND_24)) ?
1509 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
1510 rx_status.freq =
1511 ieee80211_channel_to_frequency(le16_to_cpu(sb->channel),
1512 rx_status.band);
1513
1514 /* copy the data */
1515 memcpy(skb_put(skb, size), sb->data, size);
1516 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
1517
1518 /* pass it as regular rx to mac80211 */
1519 ieee80211_rx_napi(mvm->hw, skb, NULL);
1520}
This page took 0.235594 seconds and 5 git commands to generate.