This source file includes following definitions.
- iwl_mvm_mac_tsf_id_iter
- iwl_mvm_mac_iface_iterator
- iwl_mvm_mac_ctxt_recalc_tsf_id
- iwl_mvm_mac_ctxt_init
- iwl_mvm_ack_rates
- iwl_mvm_mac_ctxt_set_ht_flags
- iwl_mvm_mac_ctxt_cmd_common
- iwl_mvm_mac_ctxt_send_cmd
- iwl_mvm_mac_ctxt_cmd_sta
- iwl_mvm_mac_ctxt_cmd_listener
- iwl_mvm_mac_ctxt_cmd_ibss
- iwl_mvm_go_iterator
- iwl_mvm_mac_ctxt_cmd_p2p_device
- iwl_mvm_mac_ctxt_set_tim
- iwl_mvm_find_ie_offset
- iwl_mvm_mac_ctxt_get_lowest_rate
- iwl_mvm_mac_ctxt_set_tx
- iwl_mvm_mac_ctxt_send_beacon_cmd
- iwl_mvm_mac_ctxt_send_beacon_v6
- iwl_mvm_mac_ctxt_send_beacon_v7
- iwl_mvm_mac_ctxt_send_beacon_v9
- iwl_mvm_mac_ctxt_send_beacon
- iwl_mvm_mac_ctxt_beacon_changed
- iwl_mvm_mac_ap_iterator
- iwl_mvm_mac_ctxt_cmd_fill_ap
- iwl_mvm_mac_ctxt_cmd_ap
- iwl_mvm_mac_ctxt_cmd_go
- iwl_mvm_mac_ctx_send
- iwl_mvm_mac_ctxt_add
- iwl_mvm_mac_ctxt_changed
- iwl_mvm_mac_ctxt_remove
- iwl_mvm_csa_count_down
- iwl_mvm_rx_beacon_notif
- iwl_mvm_rx_missed_beacons_notif
- iwl_mvm_rx_stored_beacon_notif
- iwl_mvm_probe_resp_data_notif
- iwl_mvm_channel_switch_noa_notif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 #include <linux/etherdevice.h>
66 #include <net/mac80211.h>
67 #include "iwl-io.h"
68 #include "iwl-prph.h"
69 #include "fw-api.h"
70 #include "mvm.h"
71 #include "time-event.h"
72
73 const u8 iwl_mvm_ac_to_tx_fifo[] = {
74 IWL_MVM_TX_FIFO_VO,
75 IWL_MVM_TX_FIFO_VI,
76 IWL_MVM_TX_FIFO_BE,
77 IWL_MVM_TX_FIFO_BK,
78 };
79
80 const u8 iwl_mvm_ac_to_gen2_tx_fifo[] = {
81 IWL_GEN2_EDCA_TX_FIFO_VO,
82 IWL_GEN2_EDCA_TX_FIFO_VI,
83 IWL_GEN2_EDCA_TX_FIFO_BE,
84 IWL_GEN2_EDCA_TX_FIFO_BK,
85 IWL_GEN2_TRIG_TX_FIFO_VO,
86 IWL_GEN2_TRIG_TX_FIFO_VI,
87 IWL_GEN2_TRIG_TX_FIFO_BE,
88 IWL_GEN2_TRIG_TX_FIFO_BK,
89 };
90
91 struct iwl_mvm_mac_iface_iterator_data {
92 struct iwl_mvm *mvm;
93 struct ieee80211_vif *vif;
94 unsigned long available_mac_ids[BITS_TO_LONGS(NUM_MAC_INDEX_DRIVER)];
95 unsigned long available_tsf_ids[BITS_TO_LONGS(NUM_TSF_IDS)];
96 enum iwl_tsf_id preferred_tsf;
97 bool found_vif;
98 };
99
100 static void iwl_mvm_mac_tsf_id_iter(void *_data, u8 *mac,
101 struct ieee80211_vif *vif)
102 {
103 struct iwl_mvm_mac_iface_iterator_data *data = _data;
104 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
105 u16 min_bi;
106
107
108 if (vif == data->vif)
109 return;
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127 switch (data->vif->type) {
128 case NL80211_IFTYPE_STATION:
129
130
131
132
133
134
135
136
137 if (vif->type != NL80211_IFTYPE_AP ||
138 data->preferred_tsf != NUM_TSF_IDS ||
139 !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
140 break;
141
142 min_bi = min(data->vif->bss_conf.beacon_int,
143 vif->bss_conf.beacon_int);
144
145 if (!min_bi)
146 break;
147
148 if ((data->vif->bss_conf.beacon_int -
149 vif->bss_conf.beacon_int) % min_bi == 0) {
150 data->preferred_tsf = mvmvif->tsf_id;
151 return;
152 }
153 break;
154
155 case NL80211_IFTYPE_AP:
156
157
158
159
160
161
162
163
164
165 if ((vif->type != NL80211_IFTYPE_AP &&
166 vif->type != NL80211_IFTYPE_STATION) ||
167 data->preferred_tsf != NUM_TSF_IDS ||
168 !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
169 break;
170
171 min_bi = min(data->vif->bss_conf.beacon_int,
172 vif->bss_conf.beacon_int);
173
174 if (!min_bi)
175 break;
176
177 if ((data->vif->bss_conf.beacon_int -
178 vif->bss_conf.beacon_int) % min_bi == 0) {
179 data->preferred_tsf = mvmvif->tsf_id;
180 return;
181 }
182 break;
183 default:
184
185
186
187
188
189
190
191 break;
192 }
193
194
195
196
197
198
199
200 __clear_bit(mvmvif->tsf_id, data->available_tsf_ids);
201
202 if (data->preferred_tsf == mvmvif->tsf_id)
203 data->preferred_tsf = NUM_TSF_IDS;
204 }
205
206 static void iwl_mvm_mac_iface_iterator(void *_data, u8 *mac,
207 struct ieee80211_vif *vif)
208 {
209 struct iwl_mvm_mac_iface_iterator_data *data = _data;
210 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
211
212
213 if (vif == data->vif) {
214 data->found_vif = true;
215 return;
216 }
217
218
219
220
221
222
223
224 __clear_bit(mvmvif->id, data->available_mac_ids);
225
226
227 iwl_mvm_mac_tsf_id_iter(_data, mac, vif);
228 }
229
230 void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm *mvm,
231 struct ieee80211_vif *vif)
232 {
233 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
234 struct iwl_mvm_mac_iface_iterator_data data = {
235 .mvm = mvm,
236 .vif = vif,
237 .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
238
239 .preferred_tsf = NUM_TSF_IDS,
240 };
241
242 ieee80211_iterate_active_interfaces_atomic(
243 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
244 iwl_mvm_mac_tsf_id_iter, &data);
245
246 if (data.preferred_tsf != NUM_TSF_IDS)
247 mvmvif->tsf_id = data.preferred_tsf;
248 else if (!test_bit(mvmvif->tsf_id, data.available_tsf_ids))
249 mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
250 NUM_TSF_IDS);
251 }
252
253 int iwl_mvm_mac_ctxt_init(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
254 {
255 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
256 struct iwl_mvm_mac_iface_iterator_data data = {
257 .mvm = mvm,
258 .vif = vif,
259 .available_mac_ids = { (1 << NUM_MAC_INDEX_DRIVER) - 1 },
260 .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
261
262 .preferred_tsf = NUM_TSF_IDS,
263 .found_vif = false,
264 };
265 int ret, i;
266
267 lockdep_assert_held(&mvm->mutex);
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286 switch (vif->type) {
287 case NL80211_IFTYPE_ADHOC:
288 break;
289 case NL80211_IFTYPE_STATION:
290 if (!vif->p2p)
291 break;
292
293 default:
294 __clear_bit(0, data.available_mac_ids);
295 }
296
297 ieee80211_iterate_active_interfaces_atomic(
298 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
299 iwl_mvm_mac_iface_iterator, &data);
300
301
302
303
304
305
306
307
308
309
310
311 if (data.found_vif)
312 return 0;
313
314
315 if (WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
316 return -EBUSY;
317
318 mvmvif->id = find_first_bit(data.available_mac_ids,
319 NUM_MAC_INDEX_DRIVER);
320 if (mvmvif->id == NUM_MAC_INDEX_DRIVER) {
321 IWL_ERR(mvm, "Failed to init MAC context - no free ID!\n");
322 ret = -EIO;
323 goto exit_fail;
324 }
325
326 if (data.preferred_tsf != NUM_TSF_IDS)
327 mvmvif->tsf_id = data.preferred_tsf;
328 else
329 mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
330 NUM_TSF_IDS);
331 if (mvmvif->tsf_id == NUM_TSF_IDS) {
332 IWL_ERR(mvm, "Failed to init MAC context - no free TSF!\n");
333 ret = -EIO;
334 goto exit_fail;
335 }
336
337 mvmvif->color = 0;
338
339 INIT_LIST_HEAD(&mvmvif->time_event_data.list);
340 mvmvif->time_event_data.id = TE_MAX;
341
342
343 if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
344 return 0;
345
346
347 if (vif->type == NL80211_IFTYPE_AP ||
348 vif->type == NL80211_IFTYPE_ADHOC) {
349
350
351
352
353 mvmvif->cab_queue = IWL_MVM_DQA_GCAST_QUEUE;
354 }
355
356 mvmvif->bcast_sta.sta_id = IWL_MVM_INVALID_STA;
357 mvmvif->mcast_sta.sta_id = IWL_MVM_INVALID_STA;
358 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
359
360 for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++)
361 mvmvif->smps_requests[i] = IEEE80211_SMPS_AUTOMATIC;
362
363 return 0;
364
365 exit_fail:
366 memset(mvmvif, 0, sizeof(struct iwl_mvm_vif));
367 return ret;
368 }
369
370 static void iwl_mvm_ack_rates(struct iwl_mvm *mvm,
371 struct ieee80211_vif *vif,
372 enum nl80211_band band,
373 u8 *cck_rates, u8 *ofdm_rates)
374 {
375 struct ieee80211_supported_band *sband;
376 unsigned long basic = vif->bss_conf.basic_rates;
377 int lowest_present_ofdm = 100;
378 int lowest_present_cck = 100;
379 u8 cck = 0;
380 u8 ofdm = 0;
381 int i;
382
383 sband = mvm->hw->wiphy->bands[band];
384
385 for_each_set_bit(i, &basic, BITS_PER_LONG) {
386 int hw = sband->bitrates[i].hw_value;
387 if (hw >= IWL_FIRST_OFDM_RATE) {
388 ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE);
389 if (lowest_present_ofdm > hw)
390 lowest_present_ofdm = hw;
391 } else {
392 BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
393
394 cck |= BIT(hw);
395 if (lowest_present_cck > hw)
396 lowest_present_cck = hw;
397 }
398 }
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423 if (IWL_RATE_24M_INDEX < lowest_present_ofdm)
424 ofdm |= IWL_RATE_BIT_MSK(24) >> IWL_FIRST_OFDM_RATE;
425 if (IWL_RATE_12M_INDEX < lowest_present_ofdm)
426 ofdm |= IWL_RATE_BIT_MSK(12) >> IWL_FIRST_OFDM_RATE;
427
428 ofdm |= IWL_RATE_BIT_MSK(6) >> IWL_FIRST_OFDM_RATE;
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443 if (IWL_RATE_11M_INDEX < lowest_present_cck)
444 cck |= IWL_RATE_BIT_MSK(11) >> IWL_FIRST_CCK_RATE;
445 if (IWL_RATE_5M_INDEX < lowest_present_cck)
446 cck |= IWL_RATE_BIT_MSK(5) >> IWL_FIRST_CCK_RATE;
447 if (IWL_RATE_2M_INDEX < lowest_present_cck)
448 cck |= IWL_RATE_BIT_MSK(2) >> IWL_FIRST_CCK_RATE;
449
450 cck |= IWL_RATE_BIT_MSK(1) >> IWL_FIRST_CCK_RATE;
451
452 *cck_rates = cck;
453 *ofdm_rates = ofdm;
454 }
455
456 static void iwl_mvm_mac_ctxt_set_ht_flags(struct iwl_mvm *mvm,
457 struct ieee80211_vif *vif,
458 struct iwl_mac_ctx_cmd *cmd)
459 {
460
461 u8 protection_mode = vif->bss_conf.ht_operation_mode &
462 IEEE80211_HT_OP_MODE_PROTECTION;
463
464 u32 ht_flag = MAC_PROT_FLG_HT_PROT | MAC_PROT_FLG_FAT_PROT;
465
466 IWL_DEBUG_RATE(mvm, "protection mode set to %d\n", protection_mode);
467
468
469
470
471 switch (protection_mode) {
472 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
473 break;
474 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
475 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
476 cmd->protection_flags |= cpu_to_le32(ht_flag);
477 break;
478 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
479
480 if (vif->bss_conf.chandef.width > NL80211_CHAN_WIDTH_20)
481 cmd->protection_flags |= cpu_to_le32(ht_flag);
482 break;
483 default:
484 IWL_ERR(mvm, "Illegal protection mode %d\n",
485 protection_mode);
486 break;
487 }
488 }
489
490 static void iwl_mvm_mac_ctxt_cmd_common(struct iwl_mvm *mvm,
491 struct ieee80211_vif *vif,
492 struct iwl_mac_ctx_cmd *cmd,
493 const u8 *bssid_override,
494 u32 action)
495 {
496 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
497 struct ieee80211_chanctx_conf *chanctx;
498 bool ht_enabled = !!(vif->bss_conf.ht_operation_mode &
499 IEEE80211_HT_OP_MODE_PROTECTION);
500 u8 cck_ack_rates, ofdm_ack_rates;
501 const u8 *bssid = bssid_override ?: vif->bss_conf.bssid;
502 int i;
503
504 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
505 mvmvif->color));
506 cmd->action = cpu_to_le32(action);
507
508 switch (vif->type) {
509 case NL80211_IFTYPE_STATION:
510 if (vif->p2p)
511 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_P2P_STA);
512 else
513 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_BSS_STA);
514 break;
515 case NL80211_IFTYPE_AP:
516 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_GO);
517 break;
518 case NL80211_IFTYPE_MONITOR:
519 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_LISTENER);
520 break;
521 case NL80211_IFTYPE_P2P_DEVICE:
522 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_P2P_DEVICE);
523 break;
524 case NL80211_IFTYPE_ADHOC:
525 cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_IBSS);
526 break;
527 default:
528 WARN_ON_ONCE(1);
529 }
530
531 cmd->tsf_id = cpu_to_le32(mvmvif->tsf_id);
532
533 memcpy(cmd->node_addr, vif->addr, ETH_ALEN);
534
535 if (bssid)
536 memcpy(cmd->bssid_addr, bssid, ETH_ALEN);
537 else
538 eth_broadcast_addr(cmd->bssid_addr);
539
540 rcu_read_lock();
541 chanctx = rcu_dereference(vif->chanctx_conf);
542 iwl_mvm_ack_rates(mvm, vif, chanctx ? chanctx->def.chan->band
543 : NL80211_BAND_2GHZ,
544 &cck_ack_rates, &ofdm_ack_rates);
545 rcu_read_unlock();
546
547 cmd->cck_rates = cpu_to_le32((u32)cck_ack_rates);
548 cmd->ofdm_rates = cpu_to_le32((u32)ofdm_ack_rates);
549
550 cmd->cck_short_preamble =
551 cpu_to_le32(vif->bss_conf.use_short_preamble ?
552 MAC_FLG_SHORT_PREAMBLE : 0);
553 cmd->short_slot =
554 cpu_to_le32(vif->bss_conf.use_short_slot ?
555 MAC_FLG_SHORT_SLOT : 0);
556
557 cmd->filter_flags = 0;
558
559 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
560 u8 txf = iwl_mvm_mac_ac_to_tx_fifo(mvm, i);
561 u8 ucode_ac = iwl_mvm_mac80211_ac_to_ucode_ac(i);
562
563 cmd->ac[ucode_ac].cw_min =
564 cpu_to_le16(mvmvif->queue_params[i].cw_min);
565 cmd->ac[ucode_ac].cw_max =
566 cpu_to_le16(mvmvif->queue_params[i].cw_max);
567 cmd->ac[ucode_ac].edca_txop =
568 cpu_to_le16(mvmvif->queue_params[i].txop * 32);
569 cmd->ac[ucode_ac].aifsn = mvmvif->queue_params[i].aifs;
570 cmd->ac[ucode_ac].fifos_mask = BIT(txf);
571 }
572
573 if (vif->bss_conf.qos)
574 cmd->qos_flags |= cpu_to_le32(MAC_QOS_FLG_UPDATE_EDCA);
575
576 if (vif->bss_conf.use_cts_prot)
577 cmd->protection_flags |= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT);
578
579 IWL_DEBUG_RATE(mvm, "use_cts_prot %d, ht_operation_mode %d\n",
580 vif->bss_conf.use_cts_prot,
581 vif->bss_conf.ht_operation_mode);
582 if (vif->bss_conf.chandef.width != NL80211_CHAN_WIDTH_20_NOHT)
583 cmd->qos_flags |= cpu_to_le32(MAC_QOS_FLG_TGN);
584 if (ht_enabled)
585 iwl_mvm_mac_ctxt_set_ht_flags(mvm, vif, cmd);
586 }
587
588 static int iwl_mvm_mac_ctxt_send_cmd(struct iwl_mvm *mvm,
589 struct iwl_mac_ctx_cmd *cmd)
590 {
591 int ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, 0,
592 sizeof(*cmd), cmd);
593 if (ret)
594 IWL_ERR(mvm, "Failed to send MAC context (action:%d): %d\n",
595 le32_to_cpu(cmd->action), ret);
596 return ret;
597 }
598
599 static int iwl_mvm_mac_ctxt_cmd_sta(struct iwl_mvm *mvm,
600 struct ieee80211_vif *vif,
601 u32 action, bool force_assoc_off,
602 const u8 *bssid_override)
603 {
604 struct iwl_mac_ctx_cmd cmd = {};
605 struct iwl_mac_data_sta *ctxt_sta;
606
607 WARN_ON(vif->type != NL80211_IFTYPE_STATION);
608
609
610 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, bssid_override, action);
611
612 if (vif->p2p) {
613 struct ieee80211_p2p_noa_attr *noa =
614 &vif->bss_conf.p2p_noa_attr;
615
616 cmd.p2p_sta.ctwin = cpu_to_le32(noa->oppps_ctwindow &
617 IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
618 ctxt_sta = &cmd.p2p_sta.sta;
619 } else {
620 ctxt_sta = &cmd.sta;
621 }
622
623
624 if (vif->bss_conf.assoc && vif->bss_conf.dtim_period &&
625 !force_assoc_off) {
626 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
627 u8 ap_sta_id = mvmvif->ap_sta_id;
628 u32 dtim_offs;
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645 dtim_offs = vif->bss_conf.sync_dtim_count *
646 vif->bss_conf.beacon_int;
647
648 dtim_offs *= 1024;
649
650 ctxt_sta->dtim_tsf =
651 cpu_to_le64(vif->bss_conf.sync_tsf + dtim_offs);
652 ctxt_sta->dtim_time =
653 cpu_to_le32(vif->bss_conf.sync_device_ts + dtim_offs);
654 ctxt_sta->assoc_beacon_arrive_time =
655 cpu_to_le32(vif->bss_conf.sync_device_ts);
656
657 IWL_DEBUG_INFO(mvm, "DTIM TBTT is 0x%llx/0x%x, offset %d\n",
658 le64_to_cpu(ctxt_sta->dtim_tsf),
659 le32_to_cpu(ctxt_sta->dtim_time),
660 dtim_offs);
661
662 ctxt_sta->is_assoc = cpu_to_le32(1);
663
664
665
666
667
668 if (ap_sta_id < IWL_MVM_STATION_COUNT) {
669 struct ieee80211_sta *sta;
670
671 rcu_read_lock();
672
673 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
674 if (!IS_ERR_OR_NULL(sta)) {
675 struct iwl_mvm_sta *mvmsta =
676 iwl_mvm_sta_from_mac80211(sta);
677
678 if (mvmsta->sta_state ==
679 IEEE80211_STA_AUTHORIZED)
680 cmd.filter_flags |=
681 cpu_to_le32(MAC_FILTER_ACCEPT_GRP);
682 }
683
684 rcu_read_unlock();
685 }
686 } else {
687 ctxt_sta->is_assoc = cpu_to_le32(0);
688
689
690
691
692 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_BEACON);
693 }
694
695 ctxt_sta->bi = cpu_to_le32(vif->bss_conf.beacon_int);
696 ctxt_sta->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
697 vif->bss_conf.dtim_period);
698
699 ctxt_sta->listen_interval = cpu_to_le32(mvm->hw->conf.listen_interval);
700 ctxt_sta->assoc_id = cpu_to_le32(vif->bss_conf.aid);
701
702 if (vif->probe_req_reg && vif->bss_conf.assoc && vif->p2p)
703 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
704
705 if (vif->bss_conf.he_support && !iwlwifi_mod_params.disable_11ax) {
706 cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_11AX);
707 if (vif->bss_conf.twt_requester && IWL_MVM_USE_TWT)
708 ctxt_sta->data_policy |= cpu_to_le32(TWT_SUPPORTED);
709 }
710
711
712 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
713 }
714
715 static int iwl_mvm_mac_ctxt_cmd_listener(struct iwl_mvm *mvm,
716 struct ieee80211_vif *vif,
717 u32 action)
718 {
719 struct iwl_mac_ctx_cmd cmd = {};
720 u32 tfd_queue_msk = BIT(mvm->snif_queue);
721 int ret;
722
723 WARN_ON(vif->type != NL80211_IFTYPE_MONITOR);
724
725 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
726
727 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROMISC |
728 MAC_FILTER_IN_CONTROL_AND_MGMT |
729 MAC_FILTER_IN_BEACON |
730 MAC_FILTER_IN_PROBE_REQUEST |
731 MAC_FILTER_IN_CRC32 |
732 MAC_FILTER_ACCEPT_GRP);
733 ieee80211_hw_set(mvm->hw, RX_INCLUDES_FCS);
734
735
736 ret = iwl_mvm_allocate_int_sta(mvm, &mvm->snif_sta, tfd_queue_msk,
737 vif->type, IWL_STA_GENERAL_PURPOSE);
738 if (ret)
739 return ret;
740
741 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
742 }
743
744 static int iwl_mvm_mac_ctxt_cmd_ibss(struct iwl_mvm *mvm,
745 struct ieee80211_vif *vif,
746 u32 action)
747 {
748 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
749 struct iwl_mac_ctx_cmd cmd = {};
750
751 WARN_ON(vif->type != NL80211_IFTYPE_ADHOC);
752
753 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
754
755 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_BEACON |
756 MAC_FILTER_IN_PROBE_REQUEST |
757 MAC_FILTER_ACCEPT_GRP);
758
759
760 cmd.ibss.bi = cpu_to_le32(vif->bss_conf.beacon_int);
761
762
763 cmd.ibss.beacon_template = cpu_to_le32(mvmvif->id);
764
765 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
766 }
767
768 struct iwl_mvm_go_iterator_data {
769 bool go_active;
770 };
771
772 static void iwl_mvm_go_iterator(void *_data, u8 *mac, struct ieee80211_vif *vif)
773 {
774 struct iwl_mvm_go_iterator_data *data = _data;
775 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
776
777 if (vif->type == NL80211_IFTYPE_AP && vif->p2p &&
778 mvmvif->ap_ibss_active)
779 data->go_active = true;
780 }
781
782 static int iwl_mvm_mac_ctxt_cmd_p2p_device(struct iwl_mvm *mvm,
783 struct ieee80211_vif *vif,
784 u32 action)
785 {
786 struct iwl_mac_ctx_cmd cmd = {};
787 struct iwl_mvm_go_iterator_data data = {};
788
789 WARN_ON(vif->type != NL80211_IFTYPE_P2P_DEVICE);
790
791 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
792
793
794 cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
795
796
797
798
799
800
801
802
803
804 ieee80211_iterate_active_interfaces_atomic(
805 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
806 iwl_mvm_go_iterator, &data);
807
808 cmd.p2p_dev.is_disc_extended = cpu_to_le32(data.go_active ? 1 : 0);
809 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
810 }
811
812 void iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm *mvm,
813 __le32 *tim_index, __le32 *tim_size,
814 u8 *beacon, u32 frame_size)
815 {
816 u32 tim_idx;
817 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
818
819
820
821 tim_idx = mgmt->u.beacon.variable - beacon;
822
823
824 while ((tim_idx < (frame_size - 2)) &&
825 (beacon[tim_idx] != WLAN_EID_TIM))
826 tim_idx += beacon[tim_idx+1] + 2;
827
828
829 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
830 *tim_index = cpu_to_le32(tim_idx);
831 *tim_size = cpu_to_le32((u32)beacon[tim_idx + 1]);
832 } else {
833 IWL_WARN(mvm, "Unable to find TIM Element in beacon\n");
834 }
835 }
836
837 static u32 iwl_mvm_find_ie_offset(u8 *beacon, u8 eid, u32 frame_size)
838 {
839 struct ieee80211_mgmt *mgmt = (void *)beacon;
840 const u8 *ie;
841
842 if (WARN_ON_ONCE(frame_size <= (mgmt->u.beacon.variable - beacon)))
843 return 0;
844
845 frame_size -= mgmt->u.beacon.variable - beacon;
846
847 ie = cfg80211_find_ie(eid, mgmt->u.beacon.variable, frame_size);
848 if (!ie)
849 return 0;
850
851 return ie - beacon;
852 }
853
854 u8 iwl_mvm_mac_ctxt_get_lowest_rate(struct ieee80211_tx_info *info,
855 struct ieee80211_vif *vif)
856 {
857 u8 rate;
858
859 if (info->band == NL80211_BAND_5GHZ || vif->p2p)
860 rate = IWL_FIRST_OFDM_RATE;
861 else
862 rate = IWL_FIRST_CCK_RATE;
863
864 return rate;
865 }
866
867 static void iwl_mvm_mac_ctxt_set_tx(struct iwl_mvm *mvm,
868 struct ieee80211_vif *vif,
869 struct sk_buff *beacon,
870 struct iwl_tx_cmd *tx)
871 {
872 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
873 struct ieee80211_tx_info *info;
874 u8 rate;
875 u32 tx_flags;
876
877 info = IEEE80211_SKB_CB(beacon);
878
879
880 tx->len = cpu_to_le16((u16)beacon->len);
881 tx->sta_id = mvmvif->bcast_sta.sta_id;
882 tx->life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
883 tx_flags = TX_CMD_FLG_SEQ_CTL | TX_CMD_FLG_TSF;
884 tx_flags |=
885 iwl_mvm_bt_coex_tx_prio(mvm, (void *)beacon->data, info, 0) <<
886 TX_CMD_FLG_BT_PRIO_POS;
887 tx->tx_flags = cpu_to_le32(tx_flags);
888
889 if (!fw_has_capa(&mvm->fw->ucode_capa,
890 IWL_UCODE_TLV_CAPA_BEACON_ANT_SELECTION))
891 iwl_mvm_toggle_tx_ant(mvm, &mvm->mgmt_last_antenna_idx);
892
893 tx->rate_n_flags =
894 cpu_to_le32(BIT(mvm->mgmt_last_antenna_idx) <<
895 RATE_MCS_ANT_POS);
896
897 rate = iwl_mvm_mac_ctxt_get_lowest_rate(info, vif);
898
899 tx->rate_n_flags |= cpu_to_le32(iwl_mvm_mac80211_idx_to_hwrate(rate));
900 if (rate == IWL_FIRST_CCK_RATE)
901 tx->rate_n_flags |= cpu_to_le32(RATE_MCS_CCK_MSK);
902
903 }
904
905 int iwl_mvm_mac_ctxt_send_beacon_cmd(struct iwl_mvm *mvm,
906 struct sk_buff *beacon,
907 void *data, int len)
908 {
909 struct iwl_host_cmd cmd = {
910 .id = BEACON_TEMPLATE_CMD,
911 .flags = CMD_ASYNC,
912 };
913
914 cmd.len[0] = len;
915 cmd.data[0] = data;
916 cmd.dataflags[0] = 0;
917 cmd.len[1] = beacon->len;
918 cmd.data[1] = beacon->data;
919 cmd.dataflags[1] = IWL_HCMD_DFL_DUP;
920
921 return iwl_mvm_send_cmd(mvm, &cmd);
922 }
923
924 static int iwl_mvm_mac_ctxt_send_beacon_v6(struct iwl_mvm *mvm,
925 struct ieee80211_vif *vif,
926 struct sk_buff *beacon)
927 {
928 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
929 struct iwl_mac_beacon_cmd_v6 beacon_cmd = {};
930
931 iwl_mvm_mac_ctxt_set_tx(mvm, vif, beacon, &beacon_cmd.tx);
932
933 beacon_cmd.template_id = cpu_to_le32((u32)mvmvif->id);
934
935 if (vif->type == NL80211_IFTYPE_AP)
936 iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd.tim_idx,
937 &beacon_cmd.tim_size,
938 beacon->data, beacon->len);
939
940 return iwl_mvm_mac_ctxt_send_beacon_cmd(mvm, beacon, &beacon_cmd,
941 sizeof(beacon_cmd));
942 }
943
944 static int iwl_mvm_mac_ctxt_send_beacon_v7(struct iwl_mvm *mvm,
945 struct ieee80211_vif *vif,
946 struct sk_buff *beacon)
947 {
948 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
949 struct iwl_mac_beacon_cmd_v7 beacon_cmd = {};
950
951 iwl_mvm_mac_ctxt_set_tx(mvm, vif, beacon, &beacon_cmd.tx);
952
953 beacon_cmd.template_id = cpu_to_le32((u32)mvmvif->id);
954
955 if (vif->type == NL80211_IFTYPE_AP)
956 iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd.tim_idx,
957 &beacon_cmd.tim_size,
958 beacon->data, beacon->len);
959
960 beacon_cmd.csa_offset =
961 cpu_to_le32(iwl_mvm_find_ie_offset(beacon->data,
962 WLAN_EID_CHANNEL_SWITCH,
963 beacon->len));
964 beacon_cmd.ecsa_offset =
965 cpu_to_le32(iwl_mvm_find_ie_offset(beacon->data,
966 WLAN_EID_EXT_CHANSWITCH_ANN,
967 beacon->len));
968
969 return iwl_mvm_mac_ctxt_send_beacon_cmd(mvm, beacon, &beacon_cmd,
970 sizeof(beacon_cmd));
971 }
972
973 static int iwl_mvm_mac_ctxt_send_beacon_v9(struct iwl_mvm *mvm,
974 struct ieee80211_vif *vif,
975 struct sk_buff *beacon)
976 {
977 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
978 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(beacon);
979 struct iwl_mac_beacon_cmd beacon_cmd = {};
980 u8 rate = iwl_mvm_mac_ctxt_get_lowest_rate(info, vif);
981 u16 flags;
982
983 flags = iwl_mvm_mac80211_idx_to_hwrate(rate);
984
985 if (rate == IWL_FIRST_CCK_RATE)
986 flags |= IWL_MAC_BEACON_CCK;
987
988 beacon_cmd.flags = cpu_to_le16(flags);
989 beacon_cmd.byte_cnt = cpu_to_le16((u16)beacon->len);
990 beacon_cmd.template_id = cpu_to_le32((u32)mvmvif->id);
991
992 if (vif->type == NL80211_IFTYPE_AP)
993 iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd.tim_idx,
994 &beacon_cmd.tim_size,
995 beacon->data, beacon->len);
996
997 beacon_cmd.csa_offset =
998 cpu_to_le32(iwl_mvm_find_ie_offset(beacon->data,
999 WLAN_EID_CHANNEL_SWITCH,
1000 beacon->len));
1001 beacon_cmd.ecsa_offset =
1002 cpu_to_le32(iwl_mvm_find_ie_offset(beacon->data,
1003 WLAN_EID_EXT_CHANSWITCH_ANN,
1004 beacon->len));
1005
1006 return iwl_mvm_mac_ctxt_send_beacon_cmd(mvm, beacon, &beacon_cmd,
1007 sizeof(beacon_cmd));
1008 }
1009
1010 int iwl_mvm_mac_ctxt_send_beacon(struct iwl_mvm *mvm,
1011 struct ieee80211_vif *vif,
1012 struct sk_buff *beacon)
1013 {
1014 if (WARN_ON(!beacon))
1015 return -EINVAL;
1016
1017 if (IWL_MVM_NON_TRANSMITTING_AP)
1018 return 0;
1019
1020 if (!fw_has_capa(&mvm->fw->ucode_capa,
1021 IWL_UCODE_TLV_CAPA_CSA_AND_TBTT_OFFLOAD))
1022 return iwl_mvm_mac_ctxt_send_beacon_v6(mvm, vif, beacon);
1023
1024 if (fw_has_api(&mvm->fw->ucode_capa,
1025 IWL_UCODE_TLV_API_NEW_BEACON_TEMPLATE))
1026 return iwl_mvm_mac_ctxt_send_beacon_v9(mvm, vif, beacon);
1027
1028 return iwl_mvm_mac_ctxt_send_beacon_v7(mvm, vif, beacon);
1029 }
1030
1031
1032 int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm,
1033 struct ieee80211_vif *vif)
1034 {
1035 struct sk_buff *beacon;
1036 int ret;
1037
1038 WARN_ON(vif->type != NL80211_IFTYPE_AP &&
1039 vif->type != NL80211_IFTYPE_ADHOC);
1040
1041 beacon = ieee80211_beacon_get_template(mvm->hw, vif, NULL);
1042 if (!beacon)
1043 return -ENOMEM;
1044
1045 #ifdef CONFIG_IWLWIFI_DEBUGFS
1046 if (mvm->beacon_inject_active)
1047 return -EBUSY;
1048 #endif
1049
1050 ret = iwl_mvm_mac_ctxt_send_beacon(mvm, vif, beacon);
1051 dev_kfree_skb(beacon);
1052 return ret;
1053 }
1054
1055 struct iwl_mvm_mac_ap_iterator_data {
1056 struct iwl_mvm *mvm;
1057 struct ieee80211_vif *vif;
1058 u32 beacon_device_ts;
1059 u16 beacon_int;
1060 };
1061
1062
1063 static void iwl_mvm_mac_ap_iterator(void *_data, u8 *mac,
1064 struct ieee80211_vif *vif)
1065 {
1066 struct iwl_mvm_mac_ap_iterator_data *data = _data;
1067
1068 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
1069 return;
1070
1071
1072 if (vif->p2p && data->beacon_device_ts)
1073 return;
1074
1075 data->beacon_device_ts = vif->bss_conf.sync_device_ts;
1076 data->beacon_int = vif->bss_conf.beacon_int;
1077 }
1078
1079
1080
1081
1082 static void iwl_mvm_mac_ctxt_cmd_fill_ap(struct iwl_mvm *mvm,
1083 struct ieee80211_vif *vif,
1084 struct iwl_mac_ctx_cmd *cmd,
1085 struct iwl_mac_data_ap *ctxt_ap,
1086 bool add)
1087 {
1088 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1089 struct iwl_mvm_mac_ap_iterator_data data = {
1090 .mvm = mvm,
1091 .vif = vif,
1092 .beacon_device_ts = 0
1093 };
1094
1095
1096 cmd->ac[IWL_MVM_TX_FIFO_VO].fifos_mask |= BIT(IWL_MVM_TX_FIFO_MCAST);
1097
1098
1099
1100
1101
1102
1103
1104 cmd->filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
1105 if (mvmvif->ap_assoc_sta_count || !mvm->drop_bcn_ap_mode) {
1106 cmd->filter_flags |= cpu_to_le32(MAC_FILTER_IN_BEACON);
1107 IWL_DEBUG_HC(mvm, "Asking FW to pass beacons\n");
1108 } else {
1109 IWL_DEBUG_HC(mvm, "No need to receive beacons\n");
1110 }
1111
1112 ctxt_ap->bi = cpu_to_le32(vif->bss_conf.beacon_int);
1113 ctxt_ap->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
1114 vif->bss_conf.dtim_period);
1115
1116 if (!fw_has_api(&mvm->fw->ucode_capa,
1117 IWL_UCODE_TLV_API_STA_TYPE))
1118 ctxt_ap->mcast_qid = cpu_to_le32(mvmvif->cab_queue);
1119
1120
1121
1122
1123
1124
1125 if (add) {
1126
1127
1128
1129
1130
1131 ieee80211_iterate_active_interfaces_atomic(
1132 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1133 iwl_mvm_mac_ap_iterator, &data);
1134
1135 if (data.beacon_device_ts) {
1136 u32 rand = (prandom_u32() % (64 - 36)) + 36;
1137 mvmvif->ap_beacon_time = data.beacon_device_ts +
1138 ieee80211_tu_to_usec(data.beacon_int * rand /
1139 100);
1140 } else {
1141 mvmvif->ap_beacon_time = iwl_mvm_get_systime(mvm);
1142 }
1143 }
1144
1145 ctxt_ap->beacon_time = cpu_to_le32(mvmvif->ap_beacon_time);
1146 ctxt_ap->beacon_tsf = 0;
1147
1148
1149 ctxt_ap->beacon_template = cpu_to_le32(mvmvif->id);
1150 }
1151
1152 static int iwl_mvm_mac_ctxt_cmd_ap(struct iwl_mvm *mvm,
1153 struct ieee80211_vif *vif,
1154 u32 action)
1155 {
1156 struct iwl_mac_ctx_cmd cmd = {};
1157
1158 WARN_ON(vif->type != NL80211_IFTYPE_AP || vif->p2p);
1159
1160
1161 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
1162
1163
1164 iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd, &cmd.ap,
1165 action == FW_CTXT_ACTION_ADD);
1166
1167 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1168 }
1169
1170 static int iwl_mvm_mac_ctxt_cmd_go(struct iwl_mvm *mvm,
1171 struct ieee80211_vif *vif,
1172 u32 action)
1173 {
1174 struct iwl_mac_ctx_cmd cmd = {};
1175 struct ieee80211_p2p_noa_attr *noa = &vif->bss_conf.p2p_noa_attr;
1176
1177 WARN_ON(vif->type != NL80211_IFTYPE_AP || !vif->p2p);
1178
1179
1180 iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
1181
1182
1183 iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd, &cmd.go.ap,
1184 action == FW_CTXT_ACTION_ADD);
1185
1186 cmd.go.ctwin = cpu_to_le32(noa->oppps_ctwindow &
1187 IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
1188 cmd.go.opp_ps_enabled =
1189 cpu_to_le32(!!(noa->oppps_ctwindow &
1190 IEEE80211_P2P_OPPPS_ENABLE_BIT));
1191
1192 return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
1193 }
1194
1195 static int iwl_mvm_mac_ctx_send(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1196 u32 action, bool force_assoc_off,
1197 const u8 *bssid_override)
1198 {
1199 switch (vif->type) {
1200 case NL80211_IFTYPE_STATION:
1201 return iwl_mvm_mac_ctxt_cmd_sta(mvm, vif, action,
1202 force_assoc_off,
1203 bssid_override);
1204 break;
1205 case NL80211_IFTYPE_AP:
1206 if (!vif->p2p)
1207 return iwl_mvm_mac_ctxt_cmd_ap(mvm, vif, action);
1208 else
1209 return iwl_mvm_mac_ctxt_cmd_go(mvm, vif, action);
1210 break;
1211 case NL80211_IFTYPE_MONITOR:
1212 return iwl_mvm_mac_ctxt_cmd_listener(mvm, vif, action);
1213 case NL80211_IFTYPE_P2P_DEVICE:
1214 return iwl_mvm_mac_ctxt_cmd_p2p_device(mvm, vif, action);
1215 case NL80211_IFTYPE_ADHOC:
1216 return iwl_mvm_mac_ctxt_cmd_ibss(mvm, vif, action);
1217 default:
1218 break;
1219 }
1220
1221 return -EOPNOTSUPP;
1222 }
1223
1224 int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1225 {
1226 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1227 int ret;
1228
1229 if (WARN_ONCE(mvmvif->uploaded, "Adding active MAC %pM/%d\n",
1230 vif->addr, ieee80211_vif_type_p2p(vif)))
1231 return -EIO;
1232
1233 ret = iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_ADD,
1234 true, NULL);
1235 if (ret)
1236 return ret;
1237
1238
1239 iwl_mvm_set_last_nonqos_seq(mvm, vif);
1240
1241 mvmvif->uploaded = true;
1242 return 0;
1243 }
1244
1245 int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1246 bool force_assoc_off, const u8 *bssid_override)
1247 {
1248 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1249
1250 if (WARN_ONCE(!mvmvif->uploaded, "Changing inactive MAC %pM/%d\n",
1251 vif->addr, ieee80211_vif_type_p2p(vif)))
1252 return -EIO;
1253
1254 return iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_MODIFY,
1255 force_assoc_off, bssid_override);
1256 }
1257
1258 int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1259 {
1260 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1261 struct iwl_mac_ctx_cmd cmd;
1262 int ret;
1263
1264 if (WARN_ONCE(!mvmvif->uploaded, "Removing inactive MAC %pM/%d\n",
1265 vif->addr, ieee80211_vif_type_p2p(vif)))
1266 return -EIO;
1267
1268 memset(&cmd, 0, sizeof(cmd));
1269
1270 cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1271 mvmvif->color));
1272 cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE);
1273
1274 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, 0,
1275 sizeof(cmd), &cmd);
1276 if (ret) {
1277 IWL_ERR(mvm, "Failed to remove MAC context: %d\n", ret);
1278 return ret;
1279 }
1280
1281 mvmvif->uploaded = false;
1282
1283 if (vif->type == NL80211_IFTYPE_MONITOR) {
1284 __clear_bit(IEEE80211_HW_RX_INCLUDES_FCS, mvm->hw->flags);
1285 iwl_mvm_dealloc_snif_sta(mvm);
1286 }
1287
1288 return 0;
1289 }
1290
1291 static void iwl_mvm_csa_count_down(struct iwl_mvm *mvm,
1292 struct ieee80211_vif *csa_vif, u32 gp2,
1293 bool tx_success)
1294 {
1295 struct iwl_mvm_vif *mvmvif =
1296 iwl_mvm_vif_from_mac80211(csa_vif);
1297
1298
1299 if (!tx_success && !mvmvif->csa_countdown)
1300 return;
1301
1302 mvmvif->csa_countdown = true;
1303
1304 if (!ieee80211_csa_is_complete(csa_vif)) {
1305 int c = ieee80211_csa_update_counter(csa_vif);
1306
1307 iwl_mvm_mac_ctxt_beacon_changed(mvm, csa_vif);
1308 if (csa_vif->p2p &&
1309 !iwl_mvm_te_scheduled(&mvmvif->time_event_data) && gp2 &&
1310 tx_success) {
1311 u32 rel_time = (c + 1) *
1312 csa_vif->bss_conf.beacon_int -
1313 IWL_MVM_CHANNEL_SWITCH_TIME_GO;
1314 u32 apply_time = gp2 + rel_time * 1024;
1315
1316 iwl_mvm_schedule_csa_period(mvm, csa_vif,
1317 IWL_MVM_CHANNEL_SWITCH_TIME_GO -
1318 IWL_MVM_CHANNEL_SWITCH_MARGIN,
1319 apply_time);
1320 }
1321 } else if (!iwl_mvm_te_scheduled(&mvmvif->time_event_data)) {
1322
1323 ieee80211_csa_finish(csa_vif);
1324 RCU_INIT_POINTER(mvm->csa_vif, NULL);
1325 }
1326 }
1327
1328 void iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
1329 struct iwl_rx_cmd_buffer *rxb)
1330 {
1331 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1332 struct iwl_extended_beacon_notif *beacon = (void *)pkt->data;
1333 struct iwl_extended_beacon_notif_v5 *beacon_v5 = (void *)pkt->data;
1334 struct ieee80211_vif *csa_vif;
1335 struct ieee80211_vif *tx_blocked_vif;
1336 struct agg_tx_status *agg_status;
1337 u16 status;
1338
1339 lockdep_assert_held(&mvm->mutex);
1340
1341 mvm->ap_last_beacon_gp2 = le32_to_cpu(beacon->gp2);
1342
1343 if (!iwl_mvm_is_short_beacon_notif_supported(mvm)) {
1344 struct iwl_mvm_tx_resp *beacon_notify_hdr =
1345 &beacon_v5->beacon_notify_hdr;
1346
1347 mvm->ibss_manager = beacon_v5->ibss_mgr_status != 0;
1348 agg_status = iwl_mvm_get_agg_status(mvm, beacon_notify_hdr);
1349 status = le16_to_cpu(agg_status->status) & TX_STATUS_MSK;
1350 IWL_DEBUG_RX(mvm,
1351 "beacon status %#x retries:%d tsf:0x%016llX gp2:0x%X rate:%d\n",
1352 status, beacon_notify_hdr->failure_frame,
1353 le64_to_cpu(beacon->tsf),
1354 mvm->ap_last_beacon_gp2,
1355 le32_to_cpu(beacon_notify_hdr->initial_rate));
1356 } else {
1357 mvm->ibss_manager = beacon->ibss_mgr_status != 0;
1358 status = le32_to_cpu(beacon->status) & TX_STATUS_MSK;
1359 IWL_DEBUG_RX(mvm,
1360 "beacon status %#x tsf:0x%016llX gp2:0x%X\n",
1361 status, le64_to_cpu(beacon->tsf),
1362 mvm->ap_last_beacon_gp2);
1363 }
1364
1365 csa_vif = rcu_dereference_protected(mvm->csa_vif,
1366 lockdep_is_held(&mvm->mutex));
1367 if (unlikely(csa_vif && csa_vif->csa_active))
1368 iwl_mvm_csa_count_down(mvm, csa_vif, mvm->ap_last_beacon_gp2,
1369 (status == TX_STATUS_SUCCESS));
1370
1371 tx_blocked_vif = rcu_dereference_protected(mvm->csa_tx_blocked_vif,
1372 lockdep_is_held(&mvm->mutex));
1373 if (unlikely(tx_blocked_vif)) {
1374 struct iwl_mvm_vif *mvmvif =
1375 iwl_mvm_vif_from_mac80211(tx_blocked_vif);
1376
1377
1378
1379
1380
1381
1382 if (!mvm->csa_tx_block_bcn_timeout)
1383 mvm->csa_tx_block_bcn_timeout =
1384 IWL_MVM_CS_UNBLOCK_TX_TIMEOUT;
1385 else
1386 mvm->csa_tx_block_bcn_timeout--;
1387
1388
1389 if (mvm->csa_tx_block_bcn_timeout == 0) {
1390 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false);
1391 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
1392 }
1393 }
1394 }
1395
1396 void iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm,
1397 struct iwl_rx_cmd_buffer *rxb)
1398 {
1399 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1400 struct iwl_missed_beacons_notif *mb = (void *)pkt->data;
1401 struct iwl_fw_dbg_trigger_missed_bcon *bcon_trig;
1402 struct iwl_fw_dbg_trigger_tlv *trigger;
1403 u32 stop_trig_missed_bcon, stop_trig_missed_bcon_since_rx;
1404 u32 rx_missed_bcon, rx_missed_bcon_since_rx;
1405 struct ieee80211_vif *vif;
1406 u32 id = le32_to_cpu(mb->mac_id);
1407
1408 IWL_DEBUG_INFO(mvm,
1409 "missed bcn mac_id=%u, consecutive=%u (%u, %u, %u)\n",
1410 le32_to_cpu(mb->mac_id),
1411 le32_to_cpu(mb->consec_missed_beacons),
1412 le32_to_cpu(mb->consec_missed_beacons_since_last_rx),
1413 le32_to_cpu(mb->num_recvd_beacons),
1414 le32_to_cpu(mb->num_expected_beacons));
1415
1416 rcu_read_lock();
1417
1418 vif = iwl_mvm_rcu_dereference_vif_id(mvm, id, true);
1419 if (!vif)
1420 goto out;
1421
1422 rx_missed_bcon = le32_to_cpu(mb->consec_missed_beacons);
1423 rx_missed_bcon_since_rx =
1424 le32_to_cpu(mb->consec_missed_beacons_since_last_rx);
1425
1426
1427
1428
1429 if (rx_missed_bcon > IWL_MVM_MISSED_BEACONS_THRESHOLD_LONG)
1430 iwl_mvm_connection_loss(mvm, vif, "missed beacons");
1431 else if (rx_missed_bcon_since_rx > IWL_MVM_MISSED_BEACONS_THRESHOLD)
1432 ieee80211_beacon_loss(vif);
1433
1434 iwl_dbg_tlv_time_point(&mvm->fwrt,
1435 IWL_FW_INI_TIME_POINT_MISSED_BEACONS, NULL);
1436
1437 trigger = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
1438 FW_DBG_TRIGGER_MISSED_BEACONS);
1439 if (!trigger)
1440 goto out;
1441
1442 bcon_trig = (void *)trigger->data;
1443 stop_trig_missed_bcon = le32_to_cpu(bcon_trig->stop_consec_missed_bcon);
1444 stop_trig_missed_bcon_since_rx =
1445 le32_to_cpu(bcon_trig->stop_consec_missed_bcon_since_rx);
1446
1447
1448
1449 if (rx_missed_bcon_since_rx >= stop_trig_missed_bcon_since_rx ||
1450 rx_missed_bcon >= stop_trig_missed_bcon)
1451 iwl_fw_dbg_collect_trig(&mvm->fwrt, trigger, NULL);
1452
1453 out:
1454 rcu_read_unlock();
1455 }
1456
1457 void iwl_mvm_rx_stored_beacon_notif(struct iwl_mvm *mvm,
1458 struct iwl_rx_cmd_buffer *rxb)
1459 {
1460 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1461 struct iwl_stored_beacon_notif *sb = (void *)pkt->data;
1462 struct ieee80211_rx_status rx_status;
1463 struct sk_buff *skb;
1464 u32 size = le32_to_cpu(sb->byte_count);
1465
1466 if (size == 0)
1467 return;
1468
1469 skb = alloc_skb(size, GFP_ATOMIC);
1470 if (!skb) {
1471 IWL_ERR(mvm, "alloc_skb failed\n");
1472 return;
1473 }
1474
1475
1476 memset(&rx_status, 0, sizeof(rx_status));
1477 rx_status.mactime = le64_to_cpu(sb->tsf);
1478
1479 rx_status.flag |= RX_FLAG_MACTIME_PLCP_START;
1480 rx_status.device_timestamp = le32_to_cpu(sb->system_time);
1481 rx_status.band =
1482 (sb->band & cpu_to_le16(RX_RES_PHY_FLAGS_BAND_24)) ?
1483 NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
1484 rx_status.freq =
1485 ieee80211_channel_to_frequency(le16_to_cpu(sb->channel),
1486 rx_status.band);
1487
1488
1489 skb_put_data(skb, sb->data, size);
1490 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
1491
1492
1493 ieee80211_rx_napi(mvm->hw, NULL, skb, NULL);
1494 }
1495
1496 void iwl_mvm_probe_resp_data_notif(struct iwl_mvm *mvm,
1497 struct iwl_rx_cmd_buffer *rxb)
1498 {
1499 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1500 struct iwl_probe_resp_data_notif *notif = (void *)pkt->data;
1501 struct iwl_probe_resp_data *old_data, *new_data;
1502 int len = iwl_rx_packet_payload_len(pkt);
1503 u32 id = le32_to_cpu(notif->mac_id);
1504 struct ieee80211_vif *vif;
1505 struct iwl_mvm_vif *mvmvif;
1506
1507 if (WARN_ON_ONCE(len < sizeof(*notif)))
1508 return;
1509
1510 IWL_DEBUG_INFO(mvm, "Probe response data notif: noa %d, csa %d\n",
1511 notif->noa_active, notif->csa_counter);
1512
1513 vif = iwl_mvm_rcu_dereference_vif_id(mvm, id, false);
1514 if (!vif)
1515 return;
1516
1517 mvmvif = iwl_mvm_vif_from_mac80211(vif);
1518
1519 new_data = kzalloc(sizeof(*new_data), GFP_KERNEL);
1520 if (!new_data)
1521 return;
1522
1523 memcpy(&new_data->notif, notif, sizeof(new_data->notif));
1524
1525
1526 new_data->noa_len = sizeof(struct ieee80211_vendor_ie) +
1527 sizeof(new_data->notif.noa_attr) - 1;
1528
1529
1530
1531
1532
1533 if (new_data->notif.noa_attr.len_low ==
1534 sizeof(struct ieee80211_p2p_noa_desc) + 2)
1535 new_data->noa_len -= sizeof(struct ieee80211_p2p_noa_desc);
1536
1537 old_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1538 lockdep_is_held(&mvmvif->mvm->mutex));
1539 rcu_assign_pointer(mvmvif->probe_resp_data, new_data);
1540
1541 if (old_data)
1542 kfree_rcu(old_data, rcu_head);
1543
1544 if (notif->csa_counter != IWL_PROBE_RESP_DATA_NO_CSA &&
1545 notif->csa_counter >= 1)
1546 ieee80211_csa_set_counter(vif, notif->csa_counter);
1547 }
1548
1549 void iwl_mvm_channel_switch_noa_notif(struct iwl_mvm *mvm,
1550 struct iwl_rx_cmd_buffer *rxb)
1551 {
1552 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1553 struct iwl_channel_switch_noa_notif *notif = (void *)pkt->data;
1554 struct ieee80211_vif *csa_vif, *vif;
1555 struct iwl_mvm_vif *mvmvif;
1556 int len = iwl_rx_packet_payload_len(pkt);
1557 u32 id_n_color, csa_id, mac_id;
1558
1559 if (WARN_ON_ONCE(len < sizeof(*notif)))
1560 return;
1561
1562 id_n_color = le32_to_cpu(notif->id_and_color);
1563 mac_id = id_n_color & FW_CTXT_ID_MSK;
1564
1565 if (WARN_ON_ONCE(mac_id >= NUM_MAC_INDEX_DRIVER))
1566 return;
1567
1568 rcu_read_lock();
1569 vif = rcu_dereference(mvm->vif_id_to_mac[mac_id]);
1570 mvmvif = iwl_mvm_vif_from_mac80211(vif);
1571
1572 switch (vif->type) {
1573 case NL80211_IFTYPE_AP:
1574 csa_vif = rcu_dereference(mvm->csa_vif);
1575 if (WARN_ON(!csa_vif || !csa_vif->csa_active ||
1576 csa_vif != vif))
1577 goto out_unlock;
1578
1579 csa_id = FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color);
1580 if (WARN(csa_id != id_n_color,
1581 "channel switch noa notification on unexpected vif (csa_vif=%d, notif=%d)",
1582 csa_id, id_n_color))
1583 goto out_unlock;
1584
1585 IWL_DEBUG_INFO(mvm, "Channel Switch Started Notification\n");
1586
1587 schedule_delayed_work(&mvm->cs_tx_unblock_dwork,
1588 msecs_to_jiffies(IWL_MVM_CS_UNBLOCK_TX_TIMEOUT *
1589 csa_vif->bss_conf.beacon_int));
1590
1591 ieee80211_csa_finish(csa_vif);
1592
1593 rcu_read_unlock();
1594
1595 RCU_INIT_POINTER(mvm->csa_vif, NULL);
1596 return;
1597 case NL80211_IFTYPE_STATION:
1598 if (!fw_has_capa(&mvm->fw->ucode_capa,
1599 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
1600 iwl_mvm_csa_client_absent(mvm, vif);
1601 cancel_delayed_work(&mvmvif->csa_work);
1602 ieee80211_chswitch_done(vif, true);
1603 break;
1604 default:
1605
1606 WARN_ON_ONCE(1);
1607 break;
1608 }
1609 out_unlock:
1610 rcu_read_unlock();
1611 }