Debian Codegraph @

drivers/net/wireless/intel/iwlwifi/mvm/mld-mac80211.c

raw
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3 * Copyright (C) 2022-2025 Intel Corporation
4 */
5 #include "mvm.h"
6
7 static int iwl_mvm_mld_mac_add_interface(struct ieee80211_hw *hw,
8 struct ieee80211_vif *vif)
9 {
10 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
11 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
12 int ret;
13 int i;
14
15 guard(mvm)(mvm);
16
17 iwl_mvm_mac_init_mvmvif(mvm, mvmvif);
18
19 mvmvif->mvm = mvm;
20
21 vif->driver_flags |= IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC;
22
23 /* Not much to do here. The stack will not allow interface
24 * types or combinations that we didn't advertise, so we
25 * don't really have to check the types.
26 */
27
28 /* make sure that beacon statistics don't go backwards with FW reset */
29 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
30 for_each_mvm_vif_valid_link(mvmvif, i)
31 mvmvif->link[i]->beacon_stats.accu_num_beacons +=
32 mvmvif->link[i]->beacon_stats.num_beacons;
33
34 /* Allocate resources for the MAC context, and add it to the fw */
35 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
36 if (ret)
37 return ret;
38
39 rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif);
40
41 mvmvif->features |= hw->netdev_features;
42
43 /* reset deflink MLO parameters */
44 mvmvif->deflink.fw_link_id = IWL_MVM_FW_LINK_ID_INVALID;
45 mvmvif->deflink.active = 0;
46
47 ret = iwl_mvm_mld_mac_ctxt_add(mvm, vif);
48 if (ret)
49 return ret;
50
51 /* beacon filtering */
52 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
53 if (ret)
54 goto out_remove_mac;
55
56 if (!mvm->bf_allowed_vif &&
57 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
58 mvm->bf_allowed_vif = mvmvif;
59 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
60 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
61 }
62
63 /* We want link[0] to point to the default link. */
64 mvmvif->link[0] = &mvmvif->deflink;
65
66 ret = iwl_mvm_add_link(mvm, vif, &vif->bss_conf);
67 if (ret)
68 goto out_free_bf;
69
70 /* Save a pointer to p2p device vif, so it can later be used to
71 * update the p2p device MAC when a GO is started/stopped
72 */
73 if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
74 mvm->p2p_device_vif = vif;
75
76 ret = iwl_mvm_power_update_mac(mvm);
77 if (ret)
78 goto out_free_bf;
79
80 iwl_mvm_tcm_add_vif(mvm, vif);
81
82 if (vif->type == NL80211_IFTYPE_MONITOR) {
83 mvm->monitor_on = true;
84 ieee80211_hw_set(mvm->hw, RX_INCLUDES_FCS);
85 }
86
87 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
88 iwl_mvm_vif_dbgfs_add_link(mvm, vif);
89
90 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
91 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
92 !mvm->csme_vif && mvm->mei_registered) {
93 iwl_mei_set_nic_info(vif->addr, mvm->nvm_data->hw_addr);
94 iwl_mei_set_netdev(ieee80211_vif_to_wdev(vif)->netdev);
95 mvm->csme_vif = vif;
96 }
97
98 return 0;
99
100 out_free_bf:
101 if (mvm->bf_allowed_vif == mvmvif) {
102 mvm->bf_allowed_vif = NULL;
103 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
104 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
105 }
106 out_remove_mac:
107 mvmvif->link[0] = NULL;
108 iwl_mvm_mld_mac_ctxt_remove(mvm, vif);
109 return ret;
110 }
111
112 static void iwl_mvm_mld_mac_remove_interface(struct ieee80211_hw *hw,
113 struct ieee80211_vif *vif)
114 {
115 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
116 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
117 struct iwl_probe_resp_data *probe_data;
118
119 iwl_mvm_prepare_mac_removal(mvm, vif);
120
121 if (!(vif->type == NL80211_IFTYPE_AP ||
122 vif->type == NL80211_IFTYPE_ADHOC))
123 iwl_mvm_tcm_rm_vif(mvm, vif);
124
125 guard(mvm)(mvm);
126
127 if (vif == mvm->csme_vif) {
128 iwl_mei_set_netdev(NULL);
129 mvm->csme_vif = NULL;
130 }
131
132 if (mvm->bf_allowed_vif == mvmvif) {
133 mvm->bf_allowed_vif = NULL;
134 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
135 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
136 }
137
138 if (vif->bss_conf.ftm_responder)
139 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats));
140
141 iwl_mvm_vif_dbgfs_rm_link(mvm, vif);
142
143 iwl_mvm_power_update_mac(mvm);
144
145 /* Before the interface removal, mac80211 would cancel the ROC, and the
146 * ROC worker would be scheduled if needed. The worker would be flushed
147 * in iwl_mvm_prepare_mac_removal() and thus at this point the link is
148 * not active. So need only to remove the link.
149 */
150 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
151 if (mvmvif->deflink.phy_ctxt) {
152 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt);
153 mvmvif->deflink.phy_ctxt = NULL;
154 }
155 mvm->p2p_device_vif = NULL;
156 iwl_mvm_remove_link(mvm, vif, &vif->bss_conf);
157 } else {
158 iwl_mvm_disable_link(mvm, vif, &vif->bss_conf);
159 }
160
161 iwl_mvm_mld_mac_ctxt_remove(mvm, vif);
162
163 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL);
164
165 probe_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data,
166 lockdep_is_held(&mvm->mutex));
167 RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL);
168 if (probe_data)
169 kfree_rcu(probe_data, rcu_head);
170
171 if (vif->type == NL80211_IFTYPE_MONITOR) {
172 mvm->monitor_on = false;
173 __clear_bit(IEEE80211_HW_RX_INCLUDES_FCS, mvm->hw->flags);
174 }
175 }
176
177 static int
178 __iwl_mvm_mld_assign_vif_chanctx(struct iwl_mvm *mvm,
179 struct ieee80211_vif *vif,
180 struct ieee80211_bss_conf *link_conf,
181 struct ieee80211_chanctx_conf *ctx,
182 bool switching_chanctx)
183 {
184 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
185 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
186 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
187 unsigned int link_id = link_conf->link_id;
188 int ret;
189
190 if (WARN_ON_ONCE(!mvmvif->link[link_id]))
191 return -EINVAL;
192
193 /* mac parameters such as HE support can change at this stage
194 * For sta, need first to configure correct state from drv_sta_state
195 * and only after that update mac config.
196 */
197 if (vif->type == NL80211_IFTYPE_AP) {
198 ret = iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false);
199 if (ret) {
200 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
201 return -EINVAL;
202 }
203 }
204
205 mvmvif->link[link_id]->phy_ctxt = phy_ctxt;
206
207 if (switching_chanctx) {
208 /* reactivate if we turned this off during channel switch */
209 if (vif->type == NL80211_IFTYPE_AP)
210 mvmvif->ap_ibss_active = true;
211 }
212
213 /* send it first with phy context ID */
214 ret = iwl_mvm_link_changed(mvm, vif, link_conf, 0, false);
215 if (ret)
216 goto out;
217
218 /*
219 * if link switching (link not active yet) we'll activate it in
220 * firmware later on link-info change, which mac80211 guarantees
221 * for link switch after the stations are set up
222 */
223 if (ieee80211_vif_link_active(vif, link_conf->link_id)) {
224 ret = iwl_mvm_link_changed(mvm, vif, link_conf,
225 LINK_CONTEXT_MODIFY_ACTIVE |
226 LINK_CONTEXT_MODIFY_RATES_INFO,
227 true);
228 if (ret)
229 goto out;
230 }
231
232 if (vif->type == NL80211_IFTYPE_STATION)
233 iwl_mvm_send_ap_tx_power_constraint_cmd(mvm, vif,
234 link_conf,
235 false);
236
237 /*
238 * Power state must be updated before quotas,
239 * otherwise fw will complain.
240 */
241 iwl_mvm_power_update_mac(mvm);
242
243 if (vif->type == NL80211_IFTYPE_MONITOR) {
244 ret = iwl_mvm_mld_add_snif_sta(mvm, vif, link_conf);
245 if (ret)
246 goto deactivate;
247 }
248
249 return 0;
250
251 deactivate:
252 iwl_mvm_link_changed(mvm, vif, link_conf, LINK_CONTEXT_MODIFY_ACTIVE,
253 false);
254 out:
255 mvmvif->link[link_id]->phy_ctxt = NULL;
256 iwl_mvm_power_update_mac(mvm);
257 return ret;
258 }
259
260 static int iwl_mvm_mld_assign_vif_chanctx(struct ieee80211_hw *hw,
261 struct ieee80211_vif *vif,
262 struct ieee80211_bss_conf *link_conf,
263 struct ieee80211_chanctx_conf *ctx)
264 {
265 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
266
267 guard(mvm)(mvm);
268 return __iwl_mvm_mld_assign_vif_chanctx(mvm, vif, link_conf, ctx, false);
269 }
270
271 static void
272 __iwl_mvm_mld_unassign_vif_chanctx(struct iwl_mvm *mvm,
273 struct ieee80211_vif *vif,
274 struct ieee80211_bss_conf *link_conf,
275 struct ieee80211_chanctx_conf *ctx,
276 bool switching_chanctx)
277
278 {
279 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
280 unsigned int link_id = link_conf->link_id;
281
282 /* shouldn't happen, but verify link_id is valid before accessing */
283 if (WARN_ON_ONCE(!mvmvif->link[link_id]))
284 return;
285
286 if (vif->type == NL80211_IFTYPE_AP && switching_chanctx) {
287 mvmvif->csa_countdown = false;
288
289 /* Set CS bit on all the stations */
290 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
291
292 /* Save blocked iface, the timeout is set on the next beacon */
293 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
294
295 mvmvif->ap_ibss_active = false;
296 }
297
298 iwl_mvm_link_changed(mvm, vif, link_conf,
299 LINK_CONTEXT_MODIFY_ACTIVE, false);
300
301 if (vif->type == NL80211_IFTYPE_MONITOR)
302 iwl_mvm_mld_rm_snif_sta(mvm, vif);
303
304 if (switching_chanctx)
305 return;
306 mvmvif->link[link_id]->phy_ctxt = NULL;
307 iwl_mvm_power_update_mac(mvm);
308 }
309
310 static void iwl_mvm_mld_unassign_vif_chanctx(struct ieee80211_hw *hw,
311 struct ieee80211_vif *vif,
312 struct ieee80211_bss_conf *link_conf,
313 struct ieee80211_chanctx_conf *ctx)
314 {
315 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
316 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
317
318 mutex_lock(&mvm->mutex);
319 __iwl_mvm_mld_unassign_vif_chanctx(mvm, vif, link_conf, ctx, false);
320 /* Remove/re-add the link to clean up FW state */
321 if (!mvmvif->ap_sta && !WARN_ON_ONCE(vif->cfg.assoc)) {
322 iwl_mvm_remove_link(mvm, vif, link_conf);
323 iwl_mvm_add_link(mvm, vif, link_conf);
324 }
325 mutex_unlock(&mvm->mutex);
326 }
327
328 static void
329 iwl_mvm_tpe_sta_cmd_data(struct iwl_txpower_constraints_cmd *cmd,
330 const struct ieee80211_bss_conf *bss_info)
331 {
332 u8 i;
333
334 /*
335 * NOTE: the 0 here is IEEE80211_TPE_CAT_6GHZ_DEFAULT,
336 * we fully ignore IEEE80211_TPE_CAT_6GHZ_SUBORDINATE
337 */
338
339 BUILD_BUG_ON(ARRAY_SIZE(cmd->psd_pwr) !=
340 ARRAY_SIZE(bss_info->tpe.psd_local[0].power));
341
342 /* if not valid, mac80211 puts default (max value) */
343 for (i = 0; i < ARRAY_SIZE(cmd->psd_pwr); i++)
344 cmd->psd_pwr[i] = min(bss_info->tpe.psd_local[0].power[i],
345 bss_info->tpe.psd_reg_client[0].power[i]);
346
347 BUILD_BUG_ON(ARRAY_SIZE(cmd->eirp_pwr) !=
348 ARRAY_SIZE(bss_info->tpe.max_local[0].power));
349
350 for (i = 0; i < ARRAY_SIZE(cmd->eirp_pwr); i++)
351 cmd->eirp_pwr[i] = min(bss_info->tpe.max_local[0].power[i],
352 bss_info->tpe.max_reg_client[0].power[i]);
353 }
354
355 void
356 iwl_mvm_send_ap_tx_power_constraint_cmd(struct iwl_mvm *mvm,
357 struct ieee80211_vif *vif,
358 struct ieee80211_bss_conf *bss_conf,
359 bool is_ap)
360 {
361 struct iwl_txpower_constraints_cmd cmd = {};
362 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
363 struct iwl_mvm_vif_link_info *link_info =
364 mvmvif->link[bss_conf->link_id];
365 u32 cmd_id = WIDE_ID(PHY_OPS_GROUP, AP_TX_POWER_CONSTRAINTS_CMD);
366 u32 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id,
367 IWL_FW_CMD_VER_UNKNOWN);
368 int ret;
369
370 lockdep_assert_held(&mvm->mutex);
371
372 if (cmd_ver == IWL_FW_CMD_VER_UNKNOWN)
373 return;
374
375 if (!link_info->active ||
376 link_info->fw_link_id == IWL_MVM_FW_LINK_ID_INVALID)
377 return;
378
379 if (bss_conf->chanreq.oper.chan->band != NL80211_BAND_6GHZ)
380 return;
381
382 cmd.link_id = cpu_to_le16(link_info->fw_link_id);
383 memset(cmd.psd_pwr, DEFAULT_TPE_TX_POWER, sizeof(cmd.psd_pwr));
384 memset(cmd.eirp_pwr, DEFAULT_TPE_TX_POWER, sizeof(cmd.eirp_pwr));
385
386 if (is_ap) {
387 cmd.ap_type = cpu_to_le16(IWL_6GHZ_AP_TYPE_VLP);
388 } else if (bss_conf->power_type == IEEE80211_REG_UNSET_AP) {
389 return;
390 } else {
391 cmd.ap_type = cpu_to_le16(bss_conf->power_type - 1);
392 iwl_mvm_tpe_sta_cmd_data(&cmd, bss_conf);
393 }
394
395 ret = iwl_mvm_send_cmd_pdu(mvm,
396 WIDE_ID(PHY_OPS_GROUP,
397 AP_TX_POWER_CONSTRAINTS_CMD),
398 0, sizeof(cmd), &cmd);
399 if (ret)
400 IWL_ERR(mvm,
401 "failed to send AP_TX_POWER_CONSTRAINTS_CMD (%d)\n",
402 ret);
403 }
404
405 static int iwl_mvm_mld_start_ap_ibss(struct ieee80211_hw *hw,
406 struct ieee80211_vif *vif,
407 struct ieee80211_bss_conf *link_conf)
408 {
409 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
410 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
411 int ret;
412
413 guard(mvm)(mvm);
414
415 if (vif->type == NL80211_IFTYPE_AP)
416 iwl_mvm_send_ap_tx_power_constraint_cmd(mvm, vif,
417 link_conf, true);
418
419 /* Send the beacon template */
420 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf);
421 if (ret)
422 return ret;
423
424 /* the link should be already activated when assigning chan context */
425 ret = iwl_mvm_link_changed(mvm, vif, link_conf,
426 LINK_CONTEXT_MODIFY_ALL &
427 ~LINK_CONTEXT_MODIFY_ACTIVE,
428 true);
429 if (ret)
430 return ret;
431
432 ret = iwl_mvm_mld_add_mcast_sta(mvm, vif, link_conf);
433 if (ret)
434 return ret;
435
436 /* Send the bcast station. At this stage the TBTT and DTIM time
437 * events are added and applied to the scheduler
438 */
439 ret = iwl_mvm_mld_add_bcast_sta(mvm, vif, link_conf);
440 if (ret)
441 goto out_rm_mcast;
442
443 if (iwl_mvm_start_ap_ibss_common(hw, vif, &ret))
444 goto out_failed;
445
446 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
447 if (vif->p2p && mvm->p2p_device_vif)
448 iwl_mvm_mld_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false);
449
450 iwl_mvm_bt_coex_vif_change(mvm);
451
452 /* we don't support TDLS during DCM */
453 if (iwl_mvm_phy_ctx_count(mvm) > 1)
454 iwl_mvm_teardown_tdls_peers(mvm);
455
456 iwl_mvm_ftm_restart_responder(mvm, vif, link_conf);
457
458 return 0;
459
460 out_failed:
461 iwl_mvm_power_update_mac(mvm);
462 mvmvif->ap_ibss_active = false;
463 iwl_mvm_mld_rm_bcast_sta(mvm, vif, link_conf);
464 out_rm_mcast:
465 iwl_mvm_mld_rm_mcast_sta(mvm, vif, link_conf);
466 return ret;
467 }
468
469 static int iwl_mvm_mld_start_ap(struct ieee80211_hw *hw,
470 struct ieee80211_vif *vif,
471 struct ieee80211_bss_conf *link_conf)
472 {
473 return iwl_mvm_mld_start_ap_ibss(hw, vif, link_conf);
474 }
475
476 static int iwl_mvm_mld_start_ibss(struct ieee80211_hw *hw,
477 struct ieee80211_vif *vif)
478 {
479 return iwl_mvm_mld_start_ap_ibss(hw, vif, &vif->bss_conf);
480 }
481
482 static void iwl_mvm_mld_stop_ap_ibss(struct ieee80211_hw *hw,
483 struct ieee80211_vif *vif,
484 struct ieee80211_bss_conf *link_conf)
485 {
486 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
487
488 guard(mvm)(mvm);
489
490 iwl_mvm_stop_ap_ibss_common(mvm, vif);
491
492 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
493 if (vif->p2p && mvm->p2p_device_vif)
494 iwl_mvm_mld_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false);
495
496 iwl_mvm_ftm_responder_clear(mvm, vif);
497
498 iwl_mvm_mld_rm_bcast_sta(mvm, vif, link_conf);
499 iwl_mvm_mld_rm_mcast_sta(mvm, vif, link_conf);
500
501 iwl_mvm_power_update_mac(mvm);
502 }
503
504 static void iwl_mvm_mld_stop_ap(struct ieee80211_hw *hw,
505 struct ieee80211_vif *vif,
506 struct ieee80211_bss_conf *link_conf)
507 {
508 iwl_mvm_mld_stop_ap_ibss(hw, vif, link_conf);
509 }
510
511 static void iwl_mvm_mld_stop_ibss(struct ieee80211_hw *hw,
512 struct ieee80211_vif *vif)
513 {
514 iwl_mvm_mld_stop_ap_ibss(hw, vif, &vif->bss_conf);
515 }
516
517 static int iwl_mvm_mld_mac_sta_state(struct ieee80211_hw *hw,
518 struct ieee80211_vif *vif,
519 struct ieee80211_sta *sta,
520 enum ieee80211_sta_state old_state,
521 enum ieee80211_sta_state new_state)
522 {
523 static const struct iwl_mvm_sta_state_ops callbacks = {
524 .add_sta = iwl_mvm_mld_add_sta,
525 .update_sta = iwl_mvm_mld_update_sta,
526 .rm_sta = iwl_mvm_mld_rm_sta,
527 .mac_ctxt_changed = iwl_mvm_mld_mac_ctxt_changed,
528 };
529
530 return iwl_mvm_mac_sta_state_common(hw, vif, sta, old_state, new_state,
531 &callbacks);
532 }
533
534 static void
535 iwl_mvm_mld_link_info_changed_station(struct iwl_mvm *mvm,
536 struct ieee80211_vif *vif,
537 struct ieee80211_bss_conf *link_conf,
538 u64 changes)
539 {
540 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
541 bool has_he, has_eht;
542 u32 link_changes = 0;
543 int ret;
544
545 if (WARN_ON_ONCE(!mvmvif->link[link_conf->link_id]))
546 return;
547
548 /* not yet marked active in vif means during link switch */
549 if (!ieee80211_vif_link_active(vif, link_conf->link_id) &&
550 vif->cfg.assoc && mvmvif->link[link_conf->link_id]->phy_ctxt)
551 link_changes |= LINK_CONTEXT_MODIFY_ACTIVE;
552
553 has_he = link_conf->he_support && !iwlwifi_mod_params.disable_11ax;
554 has_eht = link_conf->eht_support && !iwlwifi_mod_params.disable_11be;
555
556 /* Update EDCA params */
557 if (changes & BSS_CHANGED_QOS && vif->cfg.assoc && link_conf->qos)
558 link_changes |= LINK_CONTEXT_MODIFY_QOS_PARAMS;
559
560 if (changes & BSS_CHANGED_ERP_SLOT)
561 link_changes |= LINK_CONTEXT_MODIFY_RATES_INFO;
562
563 if (vif->cfg.assoc && (has_he || has_eht)) {
564 IWL_DEBUG_MAC80211(mvm, "Associated in HE mode\n");
565 link_changes |= LINK_CONTEXT_MODIFY_HE_PARAMS;
566 }
567
568 /* if associated, maybe puncturing changed - we'll check later */
569 if (vif->cfg.assoc)
570 link_changes |= LINK_CONTEXT_MODIFY_EHT_PARAMS;
571
572 if (link_changes) {
573 ret = iwl_mvm_link_changed(mvm, vif, link_conf, link_changes,
574 true);
575 if (ret)
576 IWL_ERR(mvm, "failed to update link\n");
577 }
578
579 ret = iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false);
580 if (ret)
581 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
582
583 memcpy(mvmvif->link[link_conf->link_id]->bssid, link_conf->bssid,
584 ETH_ALEN);
585
586 iwl_mvm_bss_info_changed_station_common(mvm, vif, link_conf, changes);
587 }
588
589 static bool iwl_mvm_mld_vif_have_valid_ap_sta(struct iwl_mvm_vif *mvmvif)
590 {
591 int i;
592
593 for_each_mvm_vif_valid_link(mvmvif, i) {
594 if (mvmvif->link[i]->ap_sta_id != IWL_INVALID_STA)
595 return true;
596 }
597
598 return false;
599 }
600
601 static void iwl_mvm_mld_vif_cfg_changed_station(struct iwl_mvm *mvm,
602 struct ieee80211_vif *vif,
603 u64 changes)
604 {
605 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
606 struct ieee80211_bss_conf *link_conf;
607 bool protect = false;
608 unsigned int i;
609 int ret;
610
611 /* This might get called without active links during the
612 * chanctx switch, but we don't care about it anyway.
613 */
614 if (changes == BSS_CHANGED_IDLE)
615 return;
616
617 ret = iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false);
618 if (ret)
619 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
620
621 mvmvif->associated = vif->cfg.assoc;
622
623 if (changes & BSS_CHANGED_ASSOC) {
624 if (vif->cfg.assoc) {
625 mvmvif->session_prot_connection_loss = false;
626
627 /*
628 * Clear statistics to get clean beacon counter, and ask for
629 * periodic statistics, as they are needed for link
630 * selection and RX OMI decisions.
631 */
632 iwl_mvm_request_statistics(mvm, true);
633 iwl_mvm_request_periodic_system_statistics(mvm, true);
634 iwl_mvm_sf_update(mvm, vif, false);
635 iwl_mvm_power_vif_assoc(mvm, vif);
636
637 for_each_mvm_vif_valid_link(mvmvif, i) {
638 memset(&mvmvif->link[i]->beacon_stats, 0,
639 sizeof(mvmvif->link[i]->beacon_stats));
640
641 if (vif->p2p) {
642 iwl_mvm_update_smps(mvm, vif,
643 IWL_MVM_SMPS_REQ_PROT,
644 IEEE80211_SMPS_DYNAMIC, i);
645 }
646
647 rcu_read_lock();
648 link_conf = rcu_dereference(vif->link_conf[i]);
649 if (link_conf && !link_conf->dtim_period)
650 protect = true;
651 rcu_read_unlock();
652 }
653
654 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
655 protect) {
656 /* If we're not restarting and still haven't
657 * heard a beacon (dtim period unknown) then
658 * make sure we still have enough minimum time
659 * remaining in the time event, since the auth
660 * might actually have taken quite a while
661 * (especially for SAE) and so the remaining
662 * time could be small without us having heard
663 * a beacon yet.
664 */
665 iwl_mvm_protect_assoc(mvm, vif, 0);
666 }
667
668 iwl_mvm_sf_update(mvm, vif, false);
669
670 /* FIXME: need to decide about misbehaving AP handling */
671 iwl_mvm_power_vif_assoc(mvm, vif);
672 } else if (iwl_mvm_mld_vif_have_valid_ap_sta(mvmvif)) {
673 iwl_mvm_mei_host_disassociated(mvm);
674
675 iwl_mvm_request_periodic_system_statistics(mvm, false);
676
677 /* If update fails - SF might be running in associated
678 * mode while disassociated - which is forbidden.
679 */
680 ret = iwl_mvm_sf_update(mvm, vif, false);
681 WARN_ONCE(ret &&
682 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
683 &mvm->status),
684 "Failed to update SF upon disassociation\n");
685 }
686
687 iwl_mvm_bss_info_changed_station_assoc(mvm, vif, changes);
688 }
689
690 if (changes & BSS_CHANGED_PS) {
691 iwl_mvm_smps_workaround(mvm, vif, false);
692 ret = iwl_mvm_power_update_mac(mvm);
693 if (ret)
694 IWL_ERR(mvm, "failed to update power mode\n");
695 }
696 }
697
698 static void
699 iwl_mvm_mld_link_info_changed_ap_ibss(struct iwl_mvm *mvm,
700 struct ieee80211_vif *vif,
701 struct ieee80211_bss_conf *link_conf,
702 u64 changes)
703 {
704 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
705 u32 link_changes = LINK_CONTEXT_MODIFY_PROTECT_FLAGS |
706 LINK_CONTEXT_MODIFY_QOS_PARAMS;
707
708 /* Changes will be applied when the AP/IBSS is started */
709 if (!mvmvif->ap_ibss_active)
710 return;
711
712 if (link_conf->he_support)
713 link_changes |= LINK_CONTEXT_MODIFY_HE_PARAMS;
714
715 if (changes & BSS_CHANGED_ERP_SLOT)
716 link_changes |= LINK_CONTEXT_MODIFY_RATES_INFO;
717
718 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_ERP_SLOT |
719 BSS_CHANGED_HT |
720 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS |
721 BSS_CHANGED_HE_BSS_COLOR) &&
722 iwl_mvm_link_changed(mvm, vif, link_conf,
723 link_changes, true))
724 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
725
726 /* Need to send a new beacon template to the FW */
727 if (changes & BSS_CHANGED_BEACON &&
728 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf))
729 IWL_WARN(mvm, "Failed updating beacon data\n");
730
731 /* FIXME: need to decide if we need FTM responder per link */
732 if (changes & BSS_CHANGED_FTM_RESPONDER) {
733 int ret = iwl_mvm_ftm_start_responder(mvm, vif, link_conf);
734
735 if (ret)
736 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n",
737 ret);
738 }
739 }
740
741 static void iwl_mvm_mld_link_info_changed(struct ieee80211_hw *hw,
742 struct ieee80211_vif *vif,
743 struct ieee80211_bss_conf *link_conf,
744 u64 changes)
745 {
746 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
747
748 guard(mvm)(mvm);
749
750 switch (vif->type) {
751 case NL80211_IFTYPE_STATION:
752 iwl_mvm_mld_link_info_changed_station(mvm, vif, link_conf,
753 changes);
754 break;
755 case NL80211_IFTYPE_AP:
756 case NL80211_IFTYPE_ADHOC:
757 iwl_mvm_mld_link_info_changed_ap_ibss(mvm, vif, link_conf,
758 changes);
759 break;
760 case NL80211_IFTYPE_MONITOR:
761 if (changes & BSS_CHANGED_MU_GROUPS)
762 iwl_mvm_update_mu_groups(mvm, vif);
763 break;
764 default:
765 /* shouldn't happen */
766 WARN_ON_ONCE(1);
767 }
768
769 if (changes & BSS_CHANGED_TXPOWER) {
770 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n",
771 link_conf->txpower);
772 iwl_mvm_set_tx_power(mvm, link_conf, link_conf->txpower);
773 }
774 }
775
776 static void iwl_mvm_mld_vif_cfg_changed(struct ieee80211_hw *hw,
777 struct ieee80211_vif *vif,
778 u64 changes)
779 {
780 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
781
782 guard(mvm)(mvm);
783
784 if (changes & BSS_CHANGED_IDLE && !vif->cfg.idle)
785 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
786
787 if (vif->type == NL80211_IFTYPE_STATION)
788 iwl_mvm_mld_vif_cfg_changed_station(mvm, vif, changes);
789 }
790
791 static int
792 iwl_mvm_mld_switch_vif_chanctx(struct ieee80211_hw *hw,
793 struct ieee80211_vif_chanctx_switch *vifs,
794 int n_vifs,
795 enum ieee80211_chanctx_switch_mode mode)
796 {
797 static const struct iwl_mvm_switch_vif_chanctx_ops ops = {
798 .__assign_vif_chanctx = __iwl_mvm_mld_assign_vif_chanctx,
799 .__unassign_vif_chanctx = __iwl_mvm_mld_unassign_vif_chanctx,
800 };
801
802 return iwl_mvm_switch_vif_chanctx_common(hw, vifs, n_vifs, mode, &ops);
803 }
804
805 static void iwl_mvm_mld_config_iface_filter(struct ieee80211_hw *hw,
806 struct ieee80211_vif *vif,
807 unsigned int filter_flags,
808 unsigned int changed_flags)
809 {
810 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
811
812 /* We support only filter for probe requests */
813 if (!(changed_flags & FIF_PROBE_REQ))
814 return;
815
816 /* Supported only for p2p client interfaces */
817 if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc ||
818 !vif->p2p)
819 return;
820
821 guard(mvm)(mvm);
822 iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false);
823 }
824
825 static int
826 iwl_mvm_mld_mac_conf_tx(struct ieee80211_hw *hw,
827 struct ieee80211_vif *vif,
828 unsigned int link_id, u16 ac,
829 const struct ieee80211_tx_queue_params *params)
830 {
831 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
832 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
833 struct iwl_mvm_vif_link_info *mvm_link = mvmvif->link[link_id];
834
835 if (!mvm_link)
836 return -EINVAL;
837
838 mvm_link->queue_params[ac] = *params;
839
840 /* No need to update right away, we'll get BSS_CHANGED_QOS
841 * The exception is P2P_DEVICE interface which needs immediate update.
842 */
843 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
844 guard(mvm)(mvm);
845 return iwl_mvm_link_changed(mvm, vif, &vif->bss_conf,
846 LINK_CONTEXT_MODIFY_QOS_PARAMS,
847 true);
848 }
849 return 0;
850 }
851
852 static int iwl_mvm_mld_roc_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
853 {
854 int ret;
855
856 lockdep_assert_held(&mvm->mutex);
857
858 /* The PHY context ID might have changed so need to set it */
859 ret = iwl_mvm_link_changed(mvm, vif, &vif->bss_conf, 0, false);
860 if (WARN(ret, "Failed to set PHY context ID\n"))
861 return ret;
862
863 ret = iwl_mvm_link_changed(mvm, vif, &vif->bss_conf,
864 LINK_CONTEXT_MODIFY_ACTIVE |
865 LINK_CONTEXT_MODIFY_RATES_INFO,
866 true);
867
868 if (WARN(ret, "Failed linking P2P_DEVICE\n"))
869 return ret;
870
871 /* The station and queue allocation must be done only after the linking
872 * is done, as otherwise the FW might incorrectly configure its state.
873 */
874 return iwl_mvm_mld_add_bcast_sta(mvm, vif, &vif->bss_conf);
875 }
876
877 static int iwl_mvm_mld_roc(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
878 struct ieee80211_channel *channel, int duration,
879 enum ieee80211_roc_type type)
880 {
881 static const struct iwl_mvm_roc_ops ops = {
882 .add_aux_sta_for_hs20 = iwl_mvm_mld_add_aux_sta,
883 .link = iwl_mvm_mld_roc_link,
884 };
885
886 return iwl_mvm_roc_common(hw, vif, channel, duration, type, &ops);
887 }
888
889 static int
890 iwl_mvm_mld_change_vif_links(struct ieee80211_hw *hw,
891 struct ieee80211_vif *vif,
892 u16 old_links, u16 new_links,
893 struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
894 {
895 struct iwl_mvm_vif_link_info *new_link[IEEE80211_MLD_MAX_NUM_LINKS] = {};
896 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
897 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
898 u16 removed = old_links & ~new_links;
899 u16 added = new_links & ~old_links;
900 int err, i;
901
902 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
903 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
904 break;
905
906 if (!(added & BIT(i)))
907 continue;
908 new_link[i] = kzalloc_obj(*new_link[i]);
909 if (!new_link[i]) {
910 err = -ENOMEM;
911 goto free;
912 }
913
914 new_link[i]->fw_link_id = IWL_MVM_FW_LINK_ID_INVALID;
915 iwl_mvm_init_link(new_link[i]);
916 }
917
918 mutex_lock(&mvm->mutex);
919
920 /* If we're in RESTART flow, the default link wasn't added in
921 * drv_add_interface(), and link[0] doesn't point to it.
922 */
923 if (old_links == 0 && !test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
924 &mvm->status)) {
925 err = iwl_mvm_disable_link(mvm, vif, &vif->bss_conf);
926 if (err)
927 goto out_err;
928 mvmvif->link[0] = NULL;
929 }
930
931 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
932 if (removed & BIT(i)) {
933 struct ieee80211_bss_conf *link_conf = old[i];
934
935 err = iwl_mvm_disable_link(mvm, vif, link_conf);
936 if (err)
937 goto out_err;
938 kfree(mvmvif->link[i]);
939 mvmvif->link[i] = NULL;
940 } else if (added & BIT(i)) {
941 struct ieee80211_bss_conf *link_conf;
942
943 link_conf = link_conf_dereference_protected(vif, i);
944 if (WARN_ON(!link_conf))
945 continue;
946
947 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
948 &mvm->status))
949 mvmvif->link[i] = new_link[i];
950 new_link[i] = NULL;
951 err = iwl_mvm_add_link(mvm, vif, link_conf);
952 if (err)
953 goto out_err;
954 }
955 }
956
957 err = 0;
958 if (new_links == 0) {
959 mvmvif->link[0] = &mvmvif->deflink;
960 err = iwl_mvm_add_link(mvm, vif, &vif->bss_conf);
961 }
962
963 out_err:
964 /* we really don't have a good way to roll back here ... */
965 mutex_unlock(&mvm->mutex);
966
967 free:
968 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++)
969 kfree(new_link[i]);
970 return err;
971 }
972
973 static int
974 iwl_mvm_mld_change_sta_links(struct ieee80211_hw *hw,
975 struct ieee80211_vif *vif,
976 struct ieee80211_sta *sta,
977 u16 old_links, u16 new_links)
978 {
979 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
980
981 guard(mvm)(mvm);
982 return iwl_mvm_mld_update_sta_links(mvm, vif, sta, old_links, new_links);
983 }
984
985 static bool iwl_mvm_mld_can_activate_links(struct ieee80211_hw *hw,
986 struct ieee80211_vif *vif,
987 u16 desired_links)
988 {
989 int n_links = hweight16(desired_links);
990
991 if (n_links <= 1)
992 return true;
993
994 WARN_ON(1);
995 return false;
996 }
997
998 static enum ieee80211_neg_ttlm_res
999 iwl_mvm_mld_can_neg_ttlm(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1000 struct ieee80211_neg_ttlm *neg_ttlm)
1001 {
1002 u16 map;
1003 u8 i;
1004
1005 /* Verify all TIDs are mapped to the same links set */
1006 map = neg_ttlm->downlink[0];
1007 for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) {
1008 if (neg_ttlm->downlink[i] != neg_ttlm->uplink[i] ||
1009 neg_ttlm->uplink[i] != map)
1010 return NEG_TTLM_RES_REJECT;
1011 }
1012
1013 return NEG_TTLM_RES_ACCEPT;
1014 }
1015
1016 const struct ieee80211_ops iwl_mvm_mld_hw_ops = {
1017 .tx = iwl_mvm_mac_tx,
1018 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue,
1019 .ampdu_action = iwl_mvm_mac_ampdu_action,
1020 .get_antenna = iwl_mvm_op_get_antenna,
1021 .set_antenna = iwl_mvm_op_set_antenna,
1022 .start = iwl_mvm_mac_start,
1023 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
1024 .stop = iwl_mvm_mac_stop,
1025 .add_interface = iwl_mvm_mld_mac_add_interface,
1026 .remove_interface = iwl_mvm_mld_mac_remove_interface,
1027 .config = iwl_mvm_mac_config,
1028 .prepare_multicast = iwl_mvm_prepare_multicast,
1029 .configure_filter = iwl_mvm_configure_filter,
1030 .config_iface_filter = iwl_mvm_mld_config_iface_filter,
1031 .link_info_changed = iwl_mvm_mld_link_info_changed,
1032 .vif_cfg_changed = iwl_mvm_mld_vif_cfg_changed,
1033 .hw_scan = iwl_mvm_mac_hw_scan,
1034 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1035 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
1036 .sta_state = iwl_mvm_mld_mac_sta_state,
1037 .sta_notify = iwl_mvm_mac_sta_notify,
1038 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
1039 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
1040 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1041 .link_sta_rc_update = iwl_mvm_sta_rc_update,
1042 .conf_tx = iwl_mvm_mld_mac_conf_tx,
1043 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
1044 .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx,
1045 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
1046 .flush = iwl_mvm_mac_flush,
1047 .flush_sta = iwl_mvm_mac_flush_sta,
1048 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
1049 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
1050 .set_key = iwl_mvm_mac_set_key,
1051 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
1052 .remain_on_channel = iwl_mvm_mld_roc,
1053 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
1054 .add_chanctx = iwl_mvm_add_chanctx,
1055 .remove_chanctx = iwl_mvm_remove_chanctx,
1056 .change_chanctx = iwl_mvm_change_chanctx,
1057 .assign_vif_chanctx = iwl_mvm_mld_assign_vif_chanctx,
1058 .unassign_vif_chanctx = iwl_mvm_mld_unassign_vif_chanctx,
1059 .switch_vif_chanctx = iwl_mvm_mld_switch_vif_chanctx,
1060
1061 .start_ap = iwl_mvm_mld_start_ap,
1062 .stop_ap = iwl_mvm_mld_stop_ap,
1063 .join_ibss = iwl_mvm_mld_start_ibss,
1064 .leave_ibss = iwl_mvm_mld_stop_ibss,
1065
1066 .tx_last_beacon = iwl_mvm_tx_last_beacon,
1067
1068 .channel_switch = iwl_mvm_channel_switch,
1069 .pre_channel_switch = iwl_mvm_mac_pre_channel_switch,
1070 .post_channel_switch = iwl_mvm_post_channel_switch,
1071 .abort_channel_switch = iwl_mvm_abort_channel_switch,
1072 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon,
1073
1074 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
1075 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
1076 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
1077
1078 .event_callback = iwl_mvm_mac_event_callback,
1079
1080 .sync_rx_queues = iwl_mvm_sync_rx_queues,
1081
1082 #ifdef CONFIG_PM_SLEEP
1083 /* look at d3.c */
1084 .suspend = iwl_mvm_suspend,
1085 .resume = iwl_mvm_resume,
1086 .set_wakeup = iwl_mvm_set_wakeup,
1087 .set_rekey_data = iwl_mvm_set_rekey_data,
1088 #if IS_ENABLED(CONFIG_IPV6)
1089 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
1090 #endif
1091 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
1092 #endif
1093 .get_survey = iwl_mvm_mac_get_survey,
1094 .sta_statistics = iwl_mvm_mac_sta_statistics,
1095 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats,
1096 .start_pmsr = iwl_mvm_start_pmsr,
1097 .abort_pmsr = iwl_mvm_abort_pmsr,
1098
1099 #ifdef CONFIG_IWLWIFI_DEBUGFS
1100 .vif_add_debugfs = iwl_mvm_vif_add_debugfs,
1101 .link_add_debugfs = iwl_mvm_link_add_debugfs,
1102 .link_sta_add_debugfs = iwl_mvm_link_sta_add_debugfs,
1103 #endif
1104 .set_hw_timestamp = iwl_mvm_set_hw_timestamp,
1105
1106 .change_vif_links = iwl_mvm_mld_change_vif_links,
1107 .change_sta_links = iwl_mvm_mld_change_sta_links,
1108 .can_activate_links = iwl_mvm_mld_can_activate_links,
1109 .can_neg_ttlm = iwl_mvm_mld_can_neg_ttlm,
1110 };