1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3 * Copyright (C) 2022-2024 Intel Corporation
4 */
5 #include "mvm.h"
6
iwl_mvm_mld_mac_add_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)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, unless we have MLO and
64 * in this case this will be modified later by .change_vif_links()
65 * If we are in the restart flow with an MLD connection, we will wait
66 * to .change_vif_links() to setup the links.
67 */
68 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
69 !ieee80211_vif_is_mld(vif)) {
70 mvmvif->link[0] = &mvmvif->deflink;
71
72 ret = iwl_mvm_add_link(mvm, vif, &vif->bss_conf);
73 if (ret)
74 goto out_free_bf;
75 }
76
77 /* Save a pointer to p2p device vif, so it can later be used to
78 * update the p2p device MAC when a GO is started/stopped
79 */
80 if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
81 mvm->p2p_device_vif = vif;
82
83 ret = iwl_mvm_power_update_mac(mvm);
84 if (ret)
85 goto out_free_bf;
86
87 iwl_mvm_tcm_add_vif(mvm, vif);
88
89 if (vif->type == NL80211_IFTYPE_MONITOR) {
90 mvm->monitor_on = true;
91 ieee80211_hw_set(mvm->hw, RX_INCLUDES_FCS);
92 }
93
94 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
95 iwl_mvm_vif_dbgfs_add_link(mvm, vif);
96
97 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
98 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
99 !mvm->csme_vif && mvm->mei_registered) {
100 iwl_mei_set_nic_info(vif->addr, mvm->nvm_data->hw_addr);
101 iwl_mei_set_netdev(ieee80211_vif_to_wdev(vif)->netdev);
102 mvm->csme_vif = vif;
103 }
104
105 if (vif->p2p || iwl_fw_lookup_cmd_ver(mvm->fw, PHY_CONTEXT_CMD, 1) < 5)
106 vif->driver_flags |= IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW;
107
108 return 0;
109
110 out_free_bf:
111 if (mvm->bf_allowed_vif == mvmvif) {
112 mvm->bf_allowed_vif = NULL;
113 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
114 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
115 }
116 out_remove_mac:
117 mvmvif->link[0] = NULL;
118 iwl_mvm_mld_mac_ctxt_remove(mvm, vif);
119 return ret;
120 }
121
iwl_mvm_mld_mac_remove_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)122 static void iwl_mvm_mld_mac_remove_interface(struct ieee80211_hw *hw,
123 struct ieee80211_vif *vif)
124 {
125 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
126 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
127 struct iwl_probe_resp_data *probe_data;
128
129 iwl_mvm_prepare_mac_removal(mvm, vif);
130
131 if (!(vif->type == NL80211_IFTYPE_AP ||
132 vif->type == NL80211_IFTYPE_ADHOC))
133 iwl_mvm_tcm_rm_vif(mvm, vif);
134
135 guard(mvm)(mvm);
136
137 if (vif == mvm->csme_vif) {
138 iwl_mei_set_netdev(NULL);
139 mvm->csme_vif = NULL;
140 }
141
142 if (mvm->bf_allowed_vif == mvmvif) {
143 mvm->bf_allowed_vif = NULL;
144 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
145 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
146 }
147
148 if (vif->bss_conf.ftm_responder)
149 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats));
150
151 iwl_mvm_vif_dbgfs_rm_link(mvm, vif);
152
153 /* For AP/GO interface, the tear down of the resources allocated to the
154 * interface is be handled as part of the stop_ap flow.
155 */
156 if (vif->type == NL80211_IFTYPE_AP ||
157 vif->type == NL80211_IFTYPE_ADHOC) {
158 #ifdef CONFIG_NL80211_TESTMODE
159 if (vif == mvm->noa_vif) {
160 mvm->noa_vif = NULL;
161 mvm->noa_duration = 0;
162 }
163 #endif
164 }
165
166 iwl_mvm_power_update_mac(mvm);
167
168 /* Before the interface removal, mac80211 would cancel the ROC, and the
169 * ROC worker would be scheduled if needed. The worker would be flushed
170 * in iwl_mvm_prepare_mac_removal() and thus at this point the link is
171 * not active. So need only to remove the link.
172 */
173 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
174 if (mvmvif->deflink.phy_ctxt) {
175 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt);
176 mvmvif->deflink.phy_ctxt = NULL;
177 }
178 mvm->p2p_device_vif = NULL;
179 iwl_mvm_remove_link(mvm, vif, &vif->bss_conf);
180 } else {
181 iwl_mvm_disable_link(mvm, vif, &vif->bss_conf);
182 }
183
184 iwl_mvm_mld_mac_ctxt_remove(mvm, vif);
185
186 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL);
187
188 probe_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data,
189 lockdep_is_held(&mvm->mutex));
190 RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL);
191 if (probe_data)
192 kfree_rcu(probe_data, rcu_head);
193
194 if (vif->type == NL80211_IFTYPE_MONITOR) {
195 mvm->monitor_on = false;
196 __clear_bit(IEEE80211_HW_RX_INCLUDES_FCS, mvm->hw->flags);
197 }
198 }
199
iwl_mvm_mld_count_active_links(struct iwl_mvm_vif * mvmvif)200 static unsigned int iwl_mvm_mld_count_active_links(struct iwl_mvm_vif *mvmvif)
201 {
202 unsigned int n_active = 0;
203 int i;
204
205 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
206 if (mvmvif->link[i] && mvmvif->link[i]->phy_ctxt)
207 n_active++;
208 }
209
210 return n_active;
211 }
212
iwl_mvm_esr_mode_active(struct iwl_mvm * mvm,struct ieee80211_vif * vif)213 static int iwl_mvm_esr_mode_active(struct iwl_mvm *mvm,
214 struct ieee80211_vif *vif)
215 {
216 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
217 int link_id, ret = 0;
218
219 mvmvif->esr_active = true;
220
221 /* Indicate to mac80211 that EML is enabled */
222 vif->driver_flags |= IEEE80211_VIF_EML_ACTIVE;
223
224 iwl_mvm_update_smps_on_active_links(mvm, vif, IWL_MVM_SMPS_REQ_FW,
225 IEEE80211_SMPS_OFF);
226
227 for_each_mvm_vif_valid_link(mvmvif, link_id) {
228 struct iwl_mvm_vif_link_info *link = mvmvif->link[link_id];
229
230 if (!link->phy_ctxt)
231 continue;
232
233 ret = iwl_mvm_phy_send_rlc(mvm, link->phy_ctxt, 2, 2);
234 if (ret)
235 break;
236
237 link->phy_ctxt->rlc_disabled = true;
238 }
239
240 if (vif->active_links == mvmvif->link_selection_res &&
241 !WARN_ON(!(vif->active_links & BIT(mvmvif->link_selection_primary))))
242 mvmvif->primary_link = mvmvif->link_selection_primary;
243 else
244 mvmvif->primary_link = __ffs(vif->active_links);
245
246 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_ESR_LINK_UP,
247 NULL);
248
249 return ret;
250 }
251
252 static int
__iwl_mvm_mld_assign_vif_chanctx(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,struct ieee80211_chanctx_conf * ctx,bool switching_chanctx)253 __iwl_mvm_mld_assign_vif_chanctx(struct iwl_mvm *mvm,
254 struct ieee80211_vif *vif,
255 struct ieee80211_bss_conf *link_conf,
256 struct ieee80211_chanctx_conf *ctx,
257 bool switching_chanctx)
258 {
259 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
260 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
261 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
262 unsigned int n_active = iwl_mvm_mld_count_active_links(mvmvif);
263 unsigned int link_id = link_conf->link_id;
264 int ret;
265
266 if (WARN_ON_ONCE(!mvmvif->link[link_id]))
267 return -EINVAL;
268
269 /* if the assigned one was not counted yet, count it now */
270 if (!mvmvif->link[link_id]->phy_ctxt)
271 n_active++;
272
273 /* mac parameters such as HE support can change at this stage
274 * For sta, need first to configure correct state from drv_sta_state
275 * and only after that update mac config.
276 */
277 if (vif->type == NL80211_IFTYPE_AP) {
278 ret = iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false);
279 if (ret) {
280 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
281 return -EINVAL;
282 }
283 }
284
285 mvmvif->link[link_id]->phy_ctxt = phy_ctxt;
286
287 if (iwl_mvm_is_esr_supported(mvm->fwrt.trans) && n_active > 1) {
288 mvmvif->link[link_id]->listen_lmac = true;
289 ret = iwl_mvm_esr_mode_active(mvm, vif);
290 if (ret) {
291 IWL_ERR(mvm, "failed to activate ESR mode (%d)\n", ret);
292 goto out;
293 }
294 }
295
296 if (switching_chanctx) {
297 /* reactivate if we turned this off during channel switch */
298 if (vif->type == NL80211_IFTYPE_AP)
299 mvmvif->ap_ibss_active = true;
300 }
301
302 /* send it first with phy context ID */
303 ret = iwl_mvm_link_changed(mvm, vif, link_conf, 0, false);
304 if (ret)
305 goto out;
306
307 /*
308 * if link switching (link not active yet) we'll activate it in
309 * firmware later on link-info change, which mac80211 guarantees
310 * for link switch after the stations are set up
311 */
312 if (ieee80211_vif_link_active(vif, link_conf->link_id)) {
313 ret = iwl_mvm_link_changed(mvm, vif, link_conf,
314 LINK_CONTEXT_MODIFY_ACTIVE |
315 LINK_CONTEXT_MODIFY_RATES_INFO,
316 true);
317 if (ret)
318 goto out;
319 }
320
321 if (vif->type == NL80211_IFTYPE_STATION)
322 iwl_mvm_send_ap_tx_power_constraint_cmd(mvm, vif,
323 link_conf,
324 false);
325
326 /*
327 * Power state must be updated before quotas,
328 * otherwise fw will complain.
329 */
330 iwl_mvm_power_update_mac(mvm);
331
332 if (vif->type == NL80211_IFTYPE_MONITOR) {
333 ret = iwl_mvm_mld_add_snif_sta(mvm, vif, link_conf);
334 if (ret)
335 goto deactivate;
336 }
337
338 return 0;
339
340 deactivate:
341 iwl_mvm_link_changed(mvm, vif, link_conf, LINK_CONTEXT_MODIFY_ACTIVE,
342 false);
343 out:
344 mvmvif->link[link_id]->phy_ctxt = NULL;
345 iwl_mvm_power_update_mac(mvm);
346 return ret;
347 }
348
iwl_mvm_mld_assign_vif_chanctx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,struct ieee80211_chanctx_conf * ctx)349 static int iwl_mvm_mld_assign_vif_chanctx(struct ieee80211_hw *hw,
350 struct ieee80211_vif *vif,
351 struct ieee80211_bss_conf *link_conf,
352 struct ieee80211_chanctx_conf *ctx)
353 {
354 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
355
356 /* update EMLSR mode */
357 if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION) {
358 int ret;
359
360 ret = iwl_mvm_esr_non_bss_link(mvm, vif, link_conf->link_id,
361 true);
362 /*
363 * Don't activate this link if failed to exit EMLSR in
364 * the BSS interface
365 */
366 if (ret)
367 return ret;
368 }
369
370 guard(mvm)(mvm);
371 return __iwl_mvm_mld_assign_vif_chanctx(mvm, vif, link_conf, ctx, false);
372 }
373
iwl_mvm_esr_mode_inactive(struct iwl_mvm * mvm,struct ieee80211_vif * vif)374 static int iwl_mvm_esr_mode_inactive(struct iwl_mvm *mvm,
375 struct ieee80211_vif *vif)
376 {
377 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
378 struct ieee80211_bss_conf *link_conf;
379 int link_id, ret = 0;
380
381 mvmvif->esr_active = false;
382
383 vif->driver_flags &= ~IEEE80211_VIF_EML_ACTIVE;
384
385 iwl_mvm_update_smps_on_active_links(mvm, vif, IWL_MVM_SMPS_REQ_FW,
386 IEEE80211_SMPS_AUTOMATIC);
387
388 for_each_vif_active_link(vif, link_conf, link_id) {
389 struct ieee80211_chanctx_conf *chanctx_conf;
390 struct iwl_mvm_phy_ctxt *phy_ctxt;
391 u8 static_chains, dynamic_chains;
392
393 mvmvif->link[link_id]->listen_lmac = false;
394
395 rcu_read_lock();
396
397 chanctx_conf = rcu_dereference(link_conf->chanctx_conf);
398 phy_ctxt = mvmvif->link[link_id]->phy_ctxt;
399
400 if (!chanctx_conf || !phy_ctxt) {
401 rcu_read_unlock();
402 continue;
403 }
404
405 phy_ctxt->rlc_disabled = false;
406 static_chains = chanctx_conf->rx_chains_static;
407 dynamic_chains = chanctx_conf->rx_chains_dynamic;
408
409 rcu_read_unlock();
410
411 ret = iwl_mvm_phy_send_rlc(mvm, phy_ctxt, static_chains,
412 dynamic_chains);
413 if (ret)
414 break;
415 }
416
417 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_ESR_LINK_DOWN,
418 NULL);
419
420 return ret;
421 }
422
423 static void
__iwl_mvm_mld_unassign_vif_chanctx(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,struct ieee80211_chanctx_conf * ctx,bool switching_chanctx)424 __iwl_mvm_mld_unassign_vif_chanctx(struct iwl_mvm *mvm,
425 struct ieee80211_vif *vif,
426 struct ieee80211_bss_conf *link_conf,
427 struct ieee80211_chanctx_conf *ctx,
428 bool switching_chanctx)
429
430 {
431 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
432 unsigned int n_active = iwl_mvm_mld_count_active_links(mvmvif);
433 unsigned int link_id = link_conf->link_id;
434
435 /* shouldn't happen, but verify link_id is valid before accessing */
436 if (WARN_ON_ONCE(!mvmvif->link[link_id]))
437 return;
438
439 if (vif->type == NL80211_IFTYPE_AP && switching_chanctx) {
440 mvmvif->csa_countdown = false;
441
442 /* Set CS bit on all the stations */
443 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
444
445 /* Save blocked iface, the timeout is set on the next beacon */
446 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
447
448 mvmvif->ap_ibss_active = false;
449 }
450
451 iwl_mvm_link_changed(mvm, vif, link_conf,
452 LINK_CONTEXT_MODIFY_ACTIVE, false);
453
454 if (iwl_mvm_is_esr_supported(mvm->fwrt.trans) && n_active > 1) {
455 int ret = iwl_mvm_esr_mode_inactive(mvm, vif);
456
457 if (ret)
458 IWL_ERR(mvm, "failed to deactivate ESR mode (%d)\n",
459 ret);
460 }
461
462 if (vif->type == NL80211_IFTYPE_MONITOR)
463 iwl_mvm_mld_rm_snif_sta(mvm, vif);
464
465 if (switching_chanctx)
466 return;
467 mvmvif->link[link_id]->phy_ctxt = NULL;
468 iwl_mvm_power_update_mac(mvm);
469 }
470
iwl_mvm_mld_unassign_vif_chanctx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,struct ieee80211_chanctx_conf * ctx)471 static void iwl_mvm_mld_unassign_vif_chanctx(struct ieee80211_hw *hw,
472 struct ieee80211_vif *vif,
473 struct ieee80211_bss_conf *link_conf,
474 struct ieee80211_chanctx_conf *ctx)
475 {
476 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
477 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
478
479 mutex_lock(&mvm->mutex);
480 __iwl_mvm_mld_unassign_vif_chanctx(mvm, vif, link_conf, ctx, false);
481 /* in the non-MLD case, remove/re-add the link to clean up FW state */
482 if (!ieee80211_vif_is_mld(vif) && !mvmvif->ap_sta &&
483 !WARN_ON_ONCE(vif->cfg.assoc)) {
484 iwl_mvm_remove_link(mvm, vif, link_conf);
485 iwl_mvm_add_link(mvm, vif, link_conf);
486 }
487 mutex_unlock(&mvm->mutex);
488
489 /* update EMLSR mode */
490 if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION)
491 iwl_mvm_esr_non_bss_link(mvm, vif, link_conf->link_id, false);
492 }
493
494 static void
iwl_mvm_tpe_sta_cmd_data(struct iwl_txpower_constraints_cmd * cmd,const struct ieee80211_bss_conf * bss_info)495 iwl_mvm_tpe_sta_cmd_data(struct iwl_txpower_constraints_cmd *cmd,
496 const struct ieee80211_bss_conf *bss_info)
497 {
498 u8 i;
499
500 /*
501 * NOTE: the 0 here is IEEE80211_TPE_CAT_6GHZ_DEFAULT,
502 * we fully ignore IEEE80211_TPE_CAT_6GHZ_SUBORDINATE
503 */
504
505 BUILD_BUG_ON(ARRAY_SIZE(cmd->psd_pwr) !=
506 ARRAY_SIZE(bss_info->tpe.psd_local[0].power));
507
508 /* if not valid, mac80211 puts default (max value) */
509 for (i = 0; i < ARRAY_SIZE(cmd->psd_pwr); i++)
510 cmd->psd_pwr[i] = min(bss_info->tpe.psd_local[0].power[i],
511 bss_info->tpe.psd_reg_client[0].power[i]);
512
513 BUILD_BUG_ON(ARRAY_SIZE(cmd->eirp_pwr) !=
514 ARRAY_SIZE(bss_info->tpe.max_local[0].power));
515
516 for (i = 0; i < ARRAY_SIZE(cmd->eirp_pwr); i++)
517 cmd->eirp_pwr[i] = min(bss_info->tpe.max_local[0].power[i],
518 bss_info->tpe.max_reg_client[0].power[i]);
519 }
520
521 void
iwl_mvm_send_ap_tx_power_constraint_cmd(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct ieee80211_bss_conf * bss_conf,bool is_ap)522 iwl_mvm_send_ap_tx_power_constraint_cmd(struct iwl_mvm *mvm,
523 struct ieee80211_vif *vif,
524 struct ieee80211_bss_conf *bss_conf,
525 bool is_ap)
526 {
527 struct iwl_txpower_constraints_cmd cmd = {};
528 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
529 struct iwl_mvm_vif_link_info *link_info =
530 mvmvif->link[bss_conf->link_id];
531 u32 cmd_id = WIDE_ID(PHY_OPS_GROUP, AP_TX_POWER_CONSTRAINTS_CMD);
532 u32 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id,
533 IWL_FW_CMD_VER_UNKNOWN);
534 int ret;
535
536 lockdep_assert_held(&mvm->mutex);
537
538 if (cmd_ver == IWL_FW_CMD_VER_UNKNOWN)
539 return;
540
541 if (!link_info->active ||
542 link_info->fw_link_id == IWL_MVM_FW_LINK_ID_INVALID)
543 return;
544
545 if (bss_conf->chanreq.oper.chan->band != NL80211_BAND_6GHZ)
546 return;
547
548 cmd.link_id = cpu_to_le16(link_info->fw_link_id);
549 memset(cmd.psd_pwr, DEFAULT_TPE_TX_POWER, sizeof(cmd.psd_pwr));
550 memset(cmd.eirp_pwr, DEFAULT_TPE_TX_POWER, sizeof(cmd.eirp_pwr));
551
552 if (is_ap) {
553 cmd.ap_type = cpu_to_le16(IWL_6GHZ_AP_TYPE_VLP);
554 } else if (bss_conf->power_type == IEEE80211_REG_UNSET_AP) {
555 return;
556 } else {
557 cmd.ap_type = cpu_to_le16(bss_conf->power_type - 1);
558 iwl_mvm_tpe_sta_cmd_data(&cmd, bss_conf);
559 }
560
561 ret = iwl_mvm_send_cmd_pdu(mvm,
562 WIDE_ID(PHY_OPS_GROUP,
563 AP_TX_POWER_CONSTRAINTS_CMD),
564 0, sizeof(cmd), &cmd);
565 if (ret)
566 IWL_ERR(mvm,
567 "failed to send AP_TX_POWER_CONSTRAINTS_CMD (%d)\n",
568 ret);
569 }
570
iwl_mvm_mld_start_ap_ibss(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)571 static int iwl_mvm_mld_start_ap_ibss(struct ieee80211_hw *hw,
572 struct ieee80211_vif *vif,
573 struct ieee80211_bss_conf *link_conf)
574 {
575 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
576 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
577 int ret;
578
579 guard(mvm)(mvm);
580
581 if (vif->type == NL80211_IFTYPE_AP)
582 iwl_mvm_send_ap_tx_power_constraint_cmd(mvm, vif,
583 link_conf, true);
584
585 /* Send the beacon template */
586 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf);
587 if (ret)
588 return ret;
589
590 /* the link should be already activated when assigning chan context */
591 ret = iwl_mvm_link_changed(mvm, vif, link_conf,
592 LINK_CONTEXT_MODIFY_ALL &
593 ~LINK_CONTEXT_MODIFY_ACTIVE,
594 true);
595 if (ret)
596 return ret;
597
598 ret = iwl_mvm_mld_add_mcast_sta(mvm, vif, link_conf);
599 if (ret)
600 return ret;
601
602 /* Send the bcast station. At this stage the TBTT and DTIM time
603 * events are added and applied to the scheduler
604 */
605 ret = iwl_mvm_mld_add_bcast_sta(mvm, vif, link_conf);
606 if (ret)
607 goto out_rm_mcast;
608
609 if (iwl_mvm_start_ap_ibss_common(hw, vif, &ret))
610 goto out_failed;
611
612 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
613 if (vif->p2p && mvm->p2p_device_vif)
614 iwl_mvm_mld_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false);
615
616 iwl_mvm_bt_coex_vif_change(mvm);
617
618 /* we don't support TDLS during DCM */
619 if (iwl_mvm_phy_ctx_count(mvm) > 1)
620 iwl_mvm_teardown_tdls_peers(mvm);
621
622 iwl_mvm_ftm_restart_responder(mvm, vif, link_conf);
623
624 return 0;
625
626 out_failed:
627 iwl_mvm_power_update_mac(mvm);
628 mvmvif->ap_ibss_active = false;
629 iwl_mvm_mld_rm_bcast_sta(mvm, vif, link_conf);
630 out_rm_mcast:
631 iwl_mvm_mld_rm_mcast_sta(mvm, vif, link_conf);
632 return ret;
633 }
634
iwl_mvm_mld_start_ap(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)635 static int iwl_mvm_mld_start_ap(struct ieee80211_hw *hw,
636 struct ieee80211_vif *vif,
637 struct ieee80211_bss_conf *link_conf)
638 {
639 return iwl_mvm_mld_start_ap_ibss(hw, vif, link_conf);
640 }
641
iwl_mvm_mld_start_ibss(struct ieee80211_hw * hw,struct ieee80211_vif * vif)642 static int iwl_mvm_mld_start_ibss(struct ieee80211_hw *hw,
643 struct ieee80211_vif *vif)
644 {
645 return iwl_mvm_mld_start_ap_ibss(hw, vif, &vif->bss_conf);
646 }
647
iwl_mvm_mld_stop_ap_ibss(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)648 static void iwl_mvm_mld_stop_ap_ibss(struct ieee80211_hw *hw,
649 struct ieee80211_vif *vif,
650 struct ieee80211_bss_conf *link_conf)
651 {
652 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
653
654 guard(mvm)(mvm);
655
656 iwl_mvm_stop_ap_ibss_common(mvm, vif);
657
658 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
659 if (vif->p2p && mvm->p2p_device_vif)
660 iwl_mvm_mld_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false);
661
662 iwl_mvm_ftm_responder_clear(mvm, vif);
663
664 iwl_mvm_mld_rm_bcast_sta(mvm, vif, link_conf);
665 iwl_mvm_mld_rm_mcast_sta(mvm, vif, link_conf);
666
667 iwl_mvm_power_update_mac(mvm);
668 }
669
iwl_mvm_mld_stop_ap(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)670 static void iwl_mvm_mld_stop_ap(struct ieee80211_hw *hw,
671 struct ieee80211_vif *vif,
672 struct ieee80211_bss_conf *link_conf)
673 {
674 iwl_mvm_mld_stop_ap_ibss(hw, vif, link_conf);
675 }
676
iwl_mvm_mld_stop_ibss(struct ieee80211_hw * hw,struct ieee80211_vif * vif)677 static void iwl_mvm_mld_stop_ibss(struct ieee80211_hw *hw,
678 struct ieee80211_vif *vif)
679 {
680 iwl_mvm_mld_stop_ap_ibss(hw, vif, &vif->bss_conf);
681 }
682
iwl_mvm_mld_mac_sta_state(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta,enum ieee80211_sta_state old_state,enum ieee80211_sta_state new_state)683 static int iwl_mvm_mld_mac_sta_state(struct ieee80211_hw *hw,
684 struct ieee80211_vif *vif,
685 struct ieee80211_sta *sta,
686 enum ieee80211_sta_state old_state,
687 enum ieee80211_sta_state new_state)
688 {
689 static const struct iwl_mvm_sta_state_ops callbacks = {
690 .add_sta = iwl_mvm_mld_add_sta,
691 .update_sta = iwl_mvm_mld_update_sta,
692 .rm_sta = iwl_mvm_mld_rm_sta,
693 .mac_ctxt_changed = iwl_mvm_mld_mac_ctxt_changed,
694 };
695
696 return iwl_mvm_mac_sta_state_common(hw, vif, sta, old_state, new_state,
697 &callbacks);
698 }
699
iwl_mvm_esr_bw_criteria(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)700 static bool iwl_mvm_esr_bw_criteria(struct iwl_mvm *mvm,
701 struct ieee80211_vif *vif,
702 struct ieee80211_bss_conf *link_conf)
703 {
704 struct ieee80211_bss_conf *other_link;
705 int link_id;
706
707 /* Exit EMLSR if links don't have equal bandwidths */
708 for_each_vif_active_link(vif, other_link, link_id) {
709 if (link_id == link_conf->link_id)
710 continue;
711 if (link_conf->chanreq.oper.width ==
712 other_link->chanreq.oper.width)
713 return true;
714 }
715
716 return false;
717 }
718
719 static void
iwl_mvm_mld_link_info_changed_station(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,u64 changes)720 iwl_mvm_mld_link_info_changed_station(struct iwl_mvm *mvm,
721 struct ieee80211_vif *vif,
722 struct ieee80211_bss_conf *link_conf,
723 u64 changes)
724 {
725 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
726 bool has_he, has_eht;
727 u32 link_changes = 0;
728 int ret;
729
730 if (WARN_ON_ONCE(!mvmvif->link[link_conf->link_id]))
731 return;
732
733 /* not yet marked active in vif means during link switch */
734 if (!ieee80211_vif_link_active(vif, link_conf->link_id) &&
735 vif->cfg.assoc && mvmvif->link[link_conf->link_id]->phy_ctxt)
736 link_changes |= LINK_CONTEXT_MODIFY_ACTIVE;
737
738 has_he = link_conf->he_support && !iwlwifi_mod_params.disable_11ax;
739 has_eht = link_conf->eht_support && !iwlwifi_mod_params.disable_11be;
740
741 /* Update EDCA params */
742 if (changes & BSS_CHANGED_QOS && vif->cfg.assoc && link_conf->qos)
743 link_changes |= LINK_CONTEXT_MODIFY_QOS_PARAMS;
744
745 if (changes & BSS_CHANGED_ERP_SLOT)
746 link_changes |= LINK_CONTEXT_MODIFY_RATES_INFO;
747
748 if (vif->cfg.assoc && (has_he || has_eht)) {
749 IWL_DEBUG_MAC80211(mvm, "Associated in HE mode\n");
750 link_changes |= LINK_CONTEXT_MODIFY_HE_PARAMS;
751 }
752
753 if ((changes & BSS_CHANGED_BANDWIDTH) &&
754 ieee80211_vif_link_active(vif, link_conf->link_id) &&
755 mvmvif->esr_active &&
756 !iwl_mvm_esr_bw_criteria(mvm, vif, link_conf))
757 iwl_mvm_exit_esr(mvm, vif,
758 IWL_MVM_ESR_EXIT_BANDWIDTH,
759 iwl_mvm_get_primary_link(vif));
760
761 /* if associated, maybe puncturing changed - we'll check later */
762 if (vif->cfg.assoc)
763 link_changes |= LINK_CONTEXT_MODIFY_EHT_PARAMS;
764
765 if (link_changes) {
766 ret = iwl_mvm_link_changed(mvm, vif, link_conf, link_changes,
767 true);
768 if (ret)
769 IWL_ERR(mvm, "failed to update link\n");
770 }
771
772 ret = iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false);
773 if (ret)
774 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
775
776 memcpy(mvmvif->link[link_conf->link_id]->bssid, link_conf->bssid,
777 ETH_ALEN);
778
779 iwl_mvm_bss_info_changed_station_common(mvm, vif, link_conf, changes);
780 }
781
iwl_mvm_mld_vif_have_valid_ap_sta(struct iwl_mvm_vif * mvmvif)782 static bool iwl_mvm_mld_vif_have_valid_ap_sta(struct iwl_mvm_vif *mvmvif)
783 {
784 int i;
785
786 for_each_mvm_vif_valid_link(mvmvif, i) {
787 if (mvmvif->link[i]->ap_sta_id != IWL_INVALID_STA)
788 return true;
789 }
790
791 return false;
792 }
793
iwl_mvm_mld_vif_cfg_changed_station(struct iwl_mvm * mvm,struct ieee80211_vif * vif,u64 changes)794 static void iwl_mvm_mld_vif_cfg_changed_station(struct iwl_mvm *mvm,
795 struct ieee80211_vif *vif,
796 u64 changes)
797 {
798 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
799 struct ieee80211_bss_conf *link_conf;
800 bool protect = false;
801 unsigned int i;
802 int ret;
803
804 /* This might get called without active links during the
805 * chanctx switch, but we don't care about it anyway.
806 */
807 if (changes == BSS_CHANGED_IDLE)
808 return;
809
810 ret = iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false);
811 if (ret)
812 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
813
814 mvmvif->associated = vif->cfg.assoc;
815
816 if (changes & BSS_CHANGED_ASSOC) {
817 if (vif->cfg.assoc) {
818 mvmvif->session_prot_connection_loss = false;
819
820 /*
821 * Clear statistics to get clean beacon counter, and ask for
822 * periodic statistics, as they are needed for link
823 * selection and RX OMI decisions.
824 */
825 iwl_mvm_request_statistics(mvm, true);
826 iwl_mvm_request_periodic_system_statistics(mvm, true);
827 iwl_mvm_sf_update(mvm, vif, false);
828 iwl_mvm_power_vif_assoc(mvm, vif);
829
830 for_each_mvm_vif_valid_link(mvmvif, i) {
831 memset(&mvmvif->link[i]->beacon_stats, 0,
832 sizeof(mvmvif->link[i]->beacon_stats));
833
834 if (vif->p2p) {
835 iwl_mvm_update_smps(mvm, vif,
836 IWL_MVM_SMPS_REQ_PROT,
837 IEEE80211_SMPS_DYNAMIC, i);
838 }
839
840 rcu_read_lock();
841 link_conf = rcu_dereference(vif->link_conf[i]);
842 if (link_conf && !link_conf->dtim_period)
843 protect = true;
844 rcu_read_unlock();
845 }
846
847 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
848 protect) {
849 /* We are in assoc so only one link is active-
850 * The association link
851 */
852 unsigned int link_id =
853 ffs(vif->active_links) - 1;
854
855 /* If we're not restarting and still haven't
856 * heard a beacon (dtim period unknown) then
857 * make sure we still have enough minimum time
858 * remaining in the time event, since the auth
859 * might actually have taken quite a while
860 * (especially for SAE) and so the remaining
861 * time could be small without us having heard
862 * a beacon yet.
863 */
864 iwl_mvm_protect_assoc(mvm, vif, 0, link_id);
865 }
866
867 iwl_mvm_sf_update(mvm, vif, false);
868
869 /* FIXME: need to decide about misbehaving AP handling */
870 iwl_mvm_power_vif_assoc(mvm, vif);
871 } else if (iwl_mvm_mld_vif_have_valid_ap_sta(mvmvif)) {
872 iwl_mvm_mei_host_disassociated(mvm);
873
874 iwl_mvm_request_periodic_system_statistics(mvm, false);
875
876 /* If update fails - SF might be running in associated
877 * mode while disassociated - which is forbidden.
878 */
879 ret = iwl_mvm_sf_update(mvm, vif, false);
880 WARN_ONCE(ret &&
881 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
882 &mvm->status),
883 "Failed to update SF upon disassociation\n");
884 }
885
886 iwl_mvm_bss_info_changed_station_assoc(mvm, vif, changes);
887 }
888
889 if (changes & BSS_CHANGED_PS) {
890 ret = iwl_mvm_power_update_mac(mvm);
891 if (ret)
892 IWL_ERR(mvm, "failed to update power mode\n");
893 }
894
895 if (changes & (BSS_CHANGED_MLD_VALID_LINKS | BSS_CHANGED_MLD_TTLM) &&
896 ieee80211_vif_is_mld(vif) && mvmvif->authorized)
897 wiphy_delayed_work_queue(mvm->hw->wiphy,
898 &mvmvif->mlo_int_scan_wk, 0);
899 }
900
901 static void
iwl_mvm_mld_link_info_changed_ap_ibss(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,u64 changes)902 iwl_mvm_mld_link_info_changed_ap_ibss(struct iwl_mvm *mvm,
903 struct ieee80211_vif *vif,
904 struct ieee80211_bss_conf *link_conf,
905 u64 changes)
906 {
907 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
908 u32 link_changes = LINK_CONTEXT_MODIFY_PROTECT_FLAGS |
909 LINK_CONTEXT_MODIFY_QOS_PARAMS;
910
911 /* Changes will be applied when the AP/IBSS is started */
912 if (!mvmvif->ap_ibss_active)
913 return;
914
915 if (link_conf->he_support)
916 link_changes |= LINK_CONTEXT_MODIFY_HE_PARAMS;
917
918 if (changes & BSS_CHANGED_ERP_SLOT)
919 link_changes |= LINK_CONTEXT_MODIFY_RATES_INFO;
920
921 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_ERP_SLOT |
922 BSS_CHANGED_HT |
923 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS |
924 BSS_CHANGED_HE_BSS_COLOR) &&
925 iwl_mvm_link_changed(mvm, vif, link_conf,
926 link_changes, true))
927 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
928
929 /* Need to send a new beacon template to the FW */
930 if (changes & BSS_CHANGED_BEACON &&
931 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf))
932 IWL_WARN(mvm, "Failed updating beacon data\n");
933
934 /* FIXME: need to decide if we need FTM responder per link */
935 if (changes & BSS_CHANGED_FTM_RESPONDER) {
936 int ret = iwl_mvm_ftm_start_responder(mvm, vif, link_conf);
937
938 if (ret)
939 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n",
940 ret);
941 }
942 }
943
iwl_mvm_mld_link_info_changed(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,u64 changes)944 static void iwl_mvm_mld_link_info_changed(struct ieee80211_hw *hw,
945 struct ieee80211_vif *vif,
946 struct ieee80211_bss_conf *link_conf,
947 u64 changes)
948 {
949 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
950
951 guard(mvm)(mvm);
952
953 switch (vif->type) {
954 case NL80211_IFTYPE_STATION:
955 iwl_mvm_mld_link_info_changed_station(mvm, vif, link_conf,
956 changes);
957 break;
958 case NL80211_IFTYPE_AP:
959 case NL80211_IFTYPE_ADHOC:
960 iwl_mvm_mld_link_info_changed_ap_ibss(mvm, vif, link_conf,
961 changes);
962 break;
963 case NL80211_IFTYPE_MONITOR:
964 if (changes & BSS_CHANGED_MU_GROUPS)
965 iwl_mvm_update_mu_groups(mvm, vif);
966 break;
967 default:
968 /* shouldn't happen */
969 WARN_ON_ONCE(1);
970 }
971
972 if (changes & BSS_CHANGED_TXPOWER) {
973 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n",
974 link_conf->txpower);
975 iwl_mvm_set_tx_power(mvm, link_conf, link_conf->txpower);
976 }
977 }
978
iwl_mvm_mld_vif_cfg_changed(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u64 changes)979 static void iwl_mvm_mld_vif_cfg_changed(struct ieee80211_hw *hw,
980 struct ieee80211_vif *vif,
981 u64 changes)
982 {
983 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
984
985 guard(mvm)(mvm);
986
987 if (changes & BSS_CHANGED_IDLE && !vif->cfg.idle)
988 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
989
990 if (vif->type == NL80211_IFTYPE_STATION)
991 iwl_mvm_mld_vif_cfg_changed_station(mvm, vif, changes);
992 }
993
994 static int
iwl_mvm_mld_switch_vif_chanctx(struct ieee80211_hw * hw,struct ieee80211_vif_chanctx_switch * vifs,int n_vifs,enum ieee80211_chanctx_switch_mode mode)995 iwl_mvm_mld_switch_vif_chanctx(struct ieee80211_hw *hw,
996 struct ieee80211_vif_chanctx_switch *vifs,
997 int n_vifs,
998 enum ieee80211_chanctx_switch_mode mode)
999 {
1000 static const struct iwl_mvm_switch_vif_chanctx_ops ops = {
1001 .__assign_vif_chanctx = __iwl_mvm_mld_assign_vif_chanctx,
1002 .__unassign_vif_chanctx = __iwl_mvm_mld_unassign_vif_chanctx,
1003 };
1004
1005 return iwl_mvm_switch_vif_chanctx_common(hw, vifs, n_vifs, mode, &ops);
1006 }
1007
iwl_mvm_mld_config_iface_filter(struct ieee80211_hw * hw,struct ieee80211_vif * vif,unsigned int filter_flags,unsigned int changed_flags)1008 static void iwl_mvm_mld_config_iface_filter(struct ieee80211_hw *hw,
1009 struct ieee80211_vif *vif,
1010 unsigned int filter_flags,
1011 unsigned int changed_flags)
1012 {
1013 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1014
1015 /* We support only filter for probe requests */
1016 if (!(changed_flags & FIF_PROBE_REQ))
1017 return;
1018
1019 /* Supported only for p2p client interfaces */
1020 if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc ||
1021 !vif->p2p)
1022 return;
1023
1024 guard(mvm)(mvm);
1025 iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false);
1026 }
1027
1028 static int
iwl_mvm_mld_mac_conf_tx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,unsigned int link_id,u16 ac,const struct ieee80211_tx_queue_params * params)1029 iwl_mvm_mld_mac_conf_tx(struct ieee80211_hw *hw,
1030 struct ieee80211_vif *vif,
1031 unsigned int link_id, u16 ac,
1032 const struct ieee80211_tx_queue_params *params)
1033 {
1034 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1035 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1036 struct iwl_mvm_vif_link_info *mvm_link = mvmvif->link[link_id];
1037
1038 if (!mvm_link)
1039 return -EINVAL;
1040
1041 mvm_link->queue_params[ac] = *params;
1042
1043 /* No need to update right away, we'll get BSS_CHANGED_QOS
1044 * The exception is P2P_DEVICE interface which needs immediate update.
1045 */
1046 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1047 guard(mvm)(mvm);
1048 return iwl_mvm_link_changed(mvm, vif, &vif->bss_conf,
1049 LINK_CONTEXT_MODIFY_QOS_PARAMS,
1050 true);
1051 }
1052 return 0;
1053 }
1054
iwl_mvm_mld_roc_link(struct iwl_mvm * mvm,struct ieee80211_vif * vif)1055 static int iwl_mvm_mld_roc_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1056 {
1057 int ret;
1058
1059 lockdep_assert_held(&mvm->mutex);
1060
1061 /* The PHY context ID might have changed so need to set it */
1062 ret = iwl_mvm_link_changed(mvm, vif, &vif->bss_conf, 0, false);
1063 if (WARN(ret, "Failed to set PHY context ID\n"))
1064 return ret;
1065
1066 ret = iwl_mvm_link_changed(mvm, vif, &vif->bss_conf,
1067 LINK_CONTEXT_MODIFY_ACTIVE |
1068 LINK_CONTEXT_MODIFY_RATES_INFO,
1069 true);
1070
1071 if (WARN(ret, "Failed linking P2P_DEVICE\n"))
1072 return ret;
1073
1074 /* The station and queue allocation must be done only after the linking
1075 * is done, as otherwise the FW might incorrectly configure its state.
1076 */
1077 return iwl_mvm_mld_add_bcast_sta(mvm, vif, &vif->bss_conf);
1078 }
1079
iwl_mvm_mld_roc(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_channel * channel,int duration,enum ieee80211_roc_type type)1080 static int iwl_mvm_mld_roc(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1081 struct ieee80211_channel *channel, int duration,
1082 enum ieee80211_roc_type type)
1083 {
1084 static const struct iwl_mvm_roc_ops ops = {
1085 .add_aux_sta_for_hs20 = iwl_mvm_mld_add_aux_sta,
1086 .link = iwl_mvm_mld_roc_link,
1087 };
1088
1089 return iwl_mvm_roc_common(hw, vif, channel, duration, type, &ops);
1090 }
1091
1092 static int
iwl_mvm_mld_change_vif_links(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u16 old_links,u16 new_links,struct ieee80211_bss_conf * old[IEEE80211_MLD_MAX_NUM_LINKS])1093 iwl_mvm_mld_change_vif_links(struct ieee80211_hw *hw,
1094 struct ieee80211_vif *vif,
1095 u16 old_links, u16 new_links,
1096 struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
1097 {
1098 struct iwl_mvm_vif_link_info *new_link[IEEE80211_MLD_MAX_NUM_LINKS] = {};
1099 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1100 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1101 u16 removed = old_links & ~new_links;
1102 u16 added = new_links & ~old_links;
1103 int err, i;
1104
1105 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
1106 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1107 break;
1108
1109 if (!(added & BIT(i)))
1110 continue;
1111 new_link[i] = kzalloc(sizeof(*new_link[i]), GFP_KERNEL);
1112 if (!new_link[i]) {
1113 err = -ENOMEM;
1114 goto free;
1115 }
1116
1117 new_link[i]->fw_link_id = IWL_MVM_FW_LINK_ID_INVALID;
1118 iwl_mvm_init_link(new_link[i]);
1119 }
1120
1121 mutex_lock(&mvm->mutex);
1122
1123 /* If we're in RESTART flow, the default link wasn't added in
1124 * drv_add_interface(), and link[0] doesn't point to it.
1125 */
1126 if (old_links == 0 && !test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1127 &mvm->status)) {
1128 err = iwl_mvm_disable_link(mvm, vif, &vif->bss_conf);
1129 if (err)
1130 goto out_err;
1131 mvmvif->link[0] = NULL;
1132 }
1133
1134 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
1135 if (removed & BIT(i)) {
1136 struct ieee80211_bss_conf *link_conf = old[i];
1137
1138 err = iwl_mvm_disable_link(mvm, vif, link_conf);
1139 if (err)
1140 goto out_err;
1141 kfree(mvmvif->link[i]);
1142 mvmvif->link[i] = NULL;
1143 } else if (added & BIT(i)) {
1144 struct ieee80211_bss_conf *link_conf;
1145
1146 link_conf = link_conf_dereference_protected(vif, i);
1147 if (WARN_ON(!link_conf))
1148 continue;
1149
1150 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1151 &mvm->status))
1152 mvmvif->link[i] = new_link[i];
1153 new_link[i] = NULL;
1154 err = iwl_mvm_add_link(mvm, vif, link_conf);
1155 if (err)
1156 goto out_err;
1157 }
1158 }
1159
1160 err = 0;
1161 if (new_links == 0) {
1162 mvmvif->link[0] = &mvmvif->deflink;
1163 err = iwl_mvm_add_link(mvm, vif, &vif->bss_conf);
1164 if (err == 0)
1165 mvmvif->primary_link = 0;
1166 } else if (!(new_links & BIT(mvmvif->primary_link))) {
1167 /*
1168 * Ensure we always have a valid primary_link, the real
1169 * decision happens later when PHY is activated.
1170 */
1171 mvmvif->primary_link = __ffs(new_links);
1172 }
1173
1174 out_err:
1175 /* we really don't have a good way to roll back here ... */
1176 mutex_unlock(&mvm->mutex);
1177
1178 free:
1179 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++)
1180 kfree(new_link[i]);
1181 return err;
1182 }
1183
1184 static int
iwl_mvm_mld_change_sta_links(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta,u16 old_links,u16 new_links)1185 iwl_mvm_mld_change_sta_links(struct ieee80211_hw *hw,
1186 struct ieee80211_vif *vif,
1187 struct ieee80211_sta *sta,
1188 u16 old_links, u16 new_links)
1189 {
1190 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1191
1192 guard(mvm)(mvm);
1193 return iwl_mvm_mld_update_sta_links(mvm, vif, sta, old_links, new_links);
1194 }
1195
iwl_mvm_vif_has_esr_cap(struct iwl_mvm * mvm,struct ieee80211_vif * vif)1196 bool iwl_mvm_vif_has_esr_cap(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1197 {
1198 const struct wiphy_iftype_ext_capab *ext_capa;
1199
1200 lockdep_assert_held(&mvm->mutex);
1201
1202 if (!ieee80211_vif_is_mld(vif) || !vif->cfg.assoc ||
1203 hweight16(ieee80211_vif_usable_links(vif)) == 1)
1204 return false;
1205
1206 if (!(vif->cfg.eml_cap & IEEE80211_EML_CAP_EMLSR_SUPP))
1207 return false;
1208
1209 ext_capa = cfg80211_get_iftype_ext_capa(mvm->hw->wiphy,
1210 ieee80211_vif_type_p2p(vif));
1211 return (ext_capa &&
1212 (ext_capa->eml_capabilities & IEEE80211_EML_CAP_EMLSR_SUPP));
1213 }
1214
iwl_mvm_mld_can_activate_links(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u16 desired_links)1215 static bool iwl_mvm_mld_can_activate_links(struct ieee80211_hw *hw,
1216 struct ieee80211_vif *vif,
1217 u16 desired_links)
1218 {
1219 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1220 int n_links = hweight16(desired_links);
1221
1222 if (n_links <= 1)
1223 return true;
1224
1225 guard(mvm)(mvm);
1226
1227 /* Check if HW supports the wanted number of links */
1228 if (n_links > iwl_mvm_max_active_links(mvm, vif))
1229 return false;
1230
1231 /* If it is an eSR device, check that we can enter eSR */
1232 return iwl_mvm_is_esr_supported(mvm->fwrt.trans) &&
1233 iwl_mvm_vif_has_esr_cap(mvm, vif);
1234 }
1235
1236 static enum ieee80211_neg_ttlm_res
iwl_mvm_mld_can_neg_ttlm(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_neg_ttlm * neg_ttlm)1237 iwl_mvm_mld_can_neg_ttlm(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1238 struct ieee80211_neg_ttlm *neg_ttlm)
1239 {
1240 u16 map;
1241 u8 i;
1242
1243 /* Verify all TIDs are mapped to the same links set */
1244 map = neg_ttlm->downlink[0];
1245 for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) {
1246 if (neg_ttlm->downlink[i] != neg_ttlm->uplink[i] ||
1247 neg_ttlm->uplink[i] != map)
1248 return NEG_TTLM_RES_REJECT;
1249 }
1250
1251 return NEG_TTLM_RES_ACCEPT;
1252 }
1253
1254 static int
iwl_mvm_mld_mac_pre_channel_switch(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_channel_switch * chsw)1255 iwl_mvm_mld_mac_pre_channel_switch(struct ieee80211_hw *hw,
1256 struct ieee80211_vif *vif,
1257 struct ieee80211_channel_switch *chsw)
1258 {
1259 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1260 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1261 int ret;
1262
1263 mutex_lock(&mvm->mutex);
1264 if (mvmvif->esr_active) {
1265 u8 primary = iwl_mvm_get_primary_link(vif);
1266 int selected;
1267
1268 /* prefer primary unless quiet CSA on it */
1269 if (chsw->link_id == primary && chsw->block_tx)
1270 selected = iwl_mvm_get_other_link(vif, primary);
1271 else
1272 selected = primary;
1273
1274 /*
1275 * remembers to tell the firmware that this link can't tx
1276 * Note that this logic seems to be unrelated to esr, but it
1277 * really is needed only when esr is active. When we have a
1278 * single link, the firmware will handle all this on its own.
1279 * In multi-link scenarios, we can learn about the CSA from
1280 * another link and this logic is too complex for the firmware
1281 * to track.
1282 * Since we want to de-activate the link that got a CSA, we
1283 * need to tell the firmware not to send any frame on that link
1284 * as the firmware may not be aware that link is under a CSA
1285 * with mode=1 (no Tx allowed).
1286 */
1287 if (chsw->block_tx && mvmvif->link[chsw->link_id])
1288 mvmvif->link[chsw->link_id]->csa_block_tx = true;
1289
1290 iwl_mvm_exit_esr(mvm, vif, IWL_MVM_ESR_EXIT_CSA, selected);
1291 mutex_unlock(&mvm->mutex);
1292
1293 /*
1294 * If we've not kept the link active that's doing the CSA
1295 * then we don't need to do anything else, just return.
1296 */
1297 if (selected != chsw->link_id)
1298 return 0;
1299
1300 mutex_lock(&mvm->mutex);
1301 }
1302
1303 ret = iwl_mvm_pre_channel_switch(mvm, vif, chsw);
1304 mutex_unlock(&mvm->mutex);
1305
1306 return ret;
1307 }
1308
1309 #define IWL_MVM_MLD_UNBLOCK_ESR_NON_BSS_TIMEOUT (5 * HZ)
1310
iwl_mvm_mld_prep_add_interface(struct ieee80211_hw * hw,enum nl80211_iftype type)1311 static void iwl_mvm_mld_prep_add_interface(struct ieee80211_hw *hw,
1312 enum nl80211_iftype type)
1313 {
1314 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1315 struct ieee80211_vif *bss_vif = iwl_mvm_get_bss_vif(mvm);
1316 struct iwl_mvm_vif *mvmvif;
1317 int ret;
1318
1319 IWL_DEBUG_MAC80211(mvm, "prep_add_interface: type=%u\n",
1320 type);
1321
1322 if (IS_ERR_OR_NULL(bss_vif) ||
1323 !(type == NL80211_IFTYPE_AP ||
1324 type == NL80211_IFTYPE_P2P_GO ||
1325 type == NL80211_IFTYPE_P2P_CLIENT))
1326 return;
1327
1328 mvmvif = iwl_mvm_vif_from_mac80211(bss_vif);
1329 ret = iwl_mvm_block_esr_sync(mvm, bss_vif,
1330 IWL_MVM_ESR_BLOCKED_TMP_NON_BSS);
1331 if (ret)
1332 return;
1333
1334 wiphy_delayed_work_queue(mvmvif->mvm->hw->wiphy,
1335 &mvmvif->unblock_esr_tmp_non_bss_wk,
1336 IWL_MVM_MLD_UNBLOCK_ESR_NON_BSS_TIMEOUT);
1337 }
1338
1339 const struct ieee80211_ops iwl_mvm_mld_hw_ops = {
1340 .tx = iwl_mvm_mac_tx,
1341 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue,
1342 .ampdu_action = iwl_mvm_mac_ampdu_action,
1343 .get_antenna = iwl_mvm_op_get_antenna,
1344 .set_antenna = iwl_mvm_op_set_antenna,
1345 .start = iwl_mvm_mac_start,
1346 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
1347 .stop = iwl_mvm_mac_stop,
1348 .add_interface = iwl_mvm_mld_mac_add_interface,
1349 .remove_interface = iwl_mvm_mld_mac_remove_interface,
1350 .config = iwl_mvm_mac_config,
1351 .prepare_multicast = iwl_mvm_prepare_multicast,
1352 .configure_filter = iwl_mvm_configure_filter,
1353 .config_iface_filter = iwl_mvm_mld_config_iface_filter,
1354 .link_info_changed = iwl_mvm_mld_link_info_changed,
1355 .vif_cfg_changed = iwl_mvm_mld_vif_cfg_changed,
1356 .hw_scan = iwl_mvm_mac_hw_scan,
1357 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1358 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
1359 .sta_state = iwl_mvm_mld_mac_sta_state,
1360 .sta_notify = iwl_mvm_mac_sta_notify,
1361 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
1362 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
1363 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1364 .link_sta_rc_update = iwl_mvm_sta_rc_update,
1365 .conf_tx = iwl_mvm_mld_mac_conf_tx,
1366 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
1367 .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx,
1368 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
1369 .flush = iwl_mvm_mac_flush,
1370 .flush_sta = iwl_mvm_mac_flush_sta,
1371 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
1372 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
1373 .set_key = iwl_mvm_mac_set_key,
1374 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
1375 .remain_on_channel = iwl_mvm_mld_roc,
1376 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
1377 .add_chanctx = iwl_mvm_add_chanctx,
1378 .remove_chanctx = iwl_mvm_remove_chanctx,
1379 .change_chanctx = iwl_mvm_change_chanctx,
1380 .assign_vif_chanctx = iwl_mvm_mld_assign_vif_chanctx,
1381 .unassign_vif_chanctx = iwl_mvm_mld_unassign_vif_chanctx,
1382 .switch_vif_chanctx = iwl_mvm_mld_switch_vif_chanctx,
1383
1384 .start_ap = iwl_mvm_mld_start_ap,
1385 .stop_ap = iwl_mvm_mld_stop_ap,
1386 .join_ibss = iwl_mvm_mld_start_ibss,
1387 .leave_ibss = iwl_mvm_mld_stop_ibss,
1388
1389 .tx_last_beacon = iwl_mvm_tx_last_beacon,
1390
1391 .channel_switch = iwl_mvm_channel_switch,
1392 .pre_channel_switch = iwl_mvm_mld_mac_pre_channel_switch,
1393 .post_channel_switch = iwl_mvm_post_channel_switch,
1394 .abort_channel_switch = iwl_mvm_abort_channel_switch,
1395 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon,
1396
1397 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
1398 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
1399 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
1400
1401 .event_callback = iwl_mvm_mac_event_callback,
1402
1403 .sync_rx_queues = iwl_mvm_sync_rx_queues,
1404
1405 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
1406
1407 #ifdef CONFIG_PM_SLEEP
1408 /* look at d3.c */
1409 .suspend = iwl_mvm_suspend,
1410 .resume = iwl_mvm_resume,
1411 .set_wakeup = iwl_mvm_set_wakeup,
1412 .set_rekey_data = iwl_mvm_set_rekey_data,
1413 #if IS_ENABLED(CONFIG_IPV6)
1414 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
1415 #endif
1416 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
1417 #endif
1418 .get_survey = iwl_mvm_mac_get_survey,
1419 .sta_statistics = iwl_mvm_mac_sta_statistics,
1420 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats,
1421 .start_pmsr = iwl_mvm_start_pmsr,
1422 .abort_pmsr = iwl_mvm_abort_pmsr,
1423
1424 #ifdef CONFIG_IWLWIFI_DEBUGFS
1425 .vif_add_debugfs = iwl_mvm_vif_add_debugfs,
1426 .link_add_debugfs = iwl_mvm_link_add_debugfs,
1427 .link_sta_add_debugfs = iwl_mvm_link_sta_add_debugfs,
1428 #endif
1429 .set_hw_timestamp = iwl_mvm_set_hw_timestamp,
1430
1431 .change_vif_links = iwl_mvm_mld_change_vif_links,
1432 .change_sta_links = iwl_mvm_mld_change_sta_links,
1433 .can_activate_links = iwl_mvm_mld_can_activate_links,
1434 .can_neg_ttlm = iwl_mvm_mld_can_neg_ttlm,
1435 .prep_add_interface = iwl_mvm_mld_prep_add_interface,
1436 };
1437