Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/contrib/dev/iwlwifi/mld/mac80211.c
48285 views
1
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2
/*
3
* Copyright (C) 2024-2025 Intel Corporation
4
*/
5
6
#include <net/mac80211.h>
7
#include <linux/fips.h>
8
#include <linux/ip.h>
9
10
#include "mld.h"
11
#include "mac80211.h"
12
#include "phy.h"
13
#include "iface.h"
14
#include "power.h"
15
#include "sta.h"
16
#include "agg.h"
17
#include "scan.h"
18
#include "d3.h"
19
#include "tlc.h"
20
#include "key.h"
21
#include "ap.h"
22
#include "tx.h"
23
#include "roc.h"
24
#include "mlo.h"
25
#include "stats.h"
26
#include "ftm-initiator.h"
27
#include "low_latency.h"
28
#include "fw/api/scan.h"
29
#include "fw/api/context.h"
30
#include "fw/api/filter.h"
31
#include "fw/api/sta.h"
32
#include "fw/api/tdls.h"
33
#ifdef CONFIG_PM_SLEEP
34
#include "fw/api/d3.h"
35
#endif /* CONFIG_PM_SLEEP */
36
#include "iwl-trans.h"
37
38
#define IWL_MLD_LIMITS(ap) \
39
{ \
40
.max = 2, \
41
.types = BIT(NL80211_IFTYPE_STATION), \
42
}, \
43
{ \
44
.max = 1, \
45
.types = ap | \
46
BIT(NL80211_IFTYPE_P2P_CLIENT) | \
47
BIT(NL80211_IFTYPE_P2P_GO), \
48
}, \
49
{ \
50
.max = 1, \
51
.types = BIT(NL80211_IFTYPE_P2P_DEVICE), \
52
}
53
54
static const struct ieee80211_iface_limit iwl_mld_limits[] = {
55
IWL_MLD_LIMITS(0)
56
};
57
58
static const struct ieee80211_iface_limit iwl_mld_limits_ap[] = {
59
IWL_MLD_LIMITS(BIT(NL80211_IFTYPE_AP))
60
};
61
62
static const struct ieee80211_iface_combination
63
iwl_mld_iface_combinations[] = {
64
{
65
.num_different_channels = 2,
66
.max_interfaces = 4,
67
.limits = iwl_mld_limits,
68
.n_limits = ARRAY_SIZE(iwl_mld_limits),
69
},
70
{
71
.num_different_channels = 1,
72
.max_interfaces = 4,
73
.limits = iwl_mld_limits_ap,
74
.n_limits = ARRAY_SIZE(iwl_mld_limits_ap),
75
},
76
};
77
78
static const u8 if_types_ext_capa_sta[] = {
79
[0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
80
[2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
81
[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF |
82
WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB,
83
[8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB,
84
[9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
85
};
86
87
#define IWL_MLD_EMLSR_CAPA (IEEE80211_EML_CAP_EMLSR_SUPP | \
88
IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_32US << \
89
__bf_shf(IEEE80211_EML_CAP_EMLSR_PADDING_DELAY) | \
90
IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_64US << \
91
__bf_shf(IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY))
92
#define IWL_MLD_CAPA_OPS (FIELD_PREP_CONST( \
93
IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP, \
94
IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP_SAME) | \
95
IEEE80211_MLD_CAP_OP_LINK_RECONF_SUPPORT)
96
97
static const struct wiphy_iftype_ext_capab iftypes_ext_capa[] = {
98
{
99
.iftype = NL80211_IFTYPE_STATION,
100
.extended_capabilities = if_types_ext_capa_sta,
101
.extended_capabilities_mask = if_types_ext_capa_sta,
102
.extended_capabilities_len = sizeof(if_types_ext_capa_sta),
103
/* relevant only if EHT is supported */
104
.eml_capabilities = IWL_MLD_EMLSR_CAPA,
105
.mld_capa_and_ops = IWL_MLD_CAPA_OPS,
106
},
107
};
108
109
static void iwl_mld_hw_set_addresses(struct iwl_mld *mld)
110
{
111
struct wiphy *wiphy = mld->wiphy;
112
int num_addrs = 1;
113
114
/* Extract MAC address */
115
memcpy(mld->addresses[0].addr, mld->nvm_data->hw_addr, ETH_ALEN);
116
wiphy->addresses = mld->addresses;
117
wiphy->n_addresses = 1;
118
119
/* Extract additional MAC addresses if available */
120
if (mld->nvm_data->n_hw_addrs > 1)
121
num_addrs = min(mld->nvm_data->n_hw_addrs,
122
IWL_MLD_MAX_ADDRESSES);
123
124
for (int i = 1; i < num_addrs; i++) {
125
memcpy(mld->addresses[i].addr,
126
mld->addresses[i - 1].addr,
127
ETH_ALEN);
128
mld->addresses[i].addr[ETH_ALEN - 1]++;
129
wiphy->n_addresses++;
130
}
131
}
132
133
static void iwl_mld_hw_set_channels(struct iwl_mld *mld)
134
{
135
struct wiphy *wiphy = mld->wiphy;
136
struct ieee80211_supported_band *bands = mld->nvm_data->bands;
137
138
wiphy->bands[NL80211_BAND_2GHZ] = &bands[NL80211_BAND_2GHZ];
139
wiphy->bands[NL80211_BAND_5GHZ] = &bands[NL80211_BAND_5GHZ];
140
141
if (bands[NL80211_BAND_6GHZ].n_channels)
142
wiphy->bands[NL80211_BAND_6GHZ] = &bands[NL80211_BAND_6GHZ];
143
}
144
145
static void iwl_mld_hw_set_security(struct iwl_mld *mld)
146
{
147
struct ieee80211_hw *hw = mld->hw;
148
static const u32 mld_ciphers[] = {
149
WLAN_CIPHER_SUITE_WEP40,
150
WLAN_CIPHER_SUITE_WEP104,
151
WLAN_CIPHER_SUITE_TKIP,
152
WLAN_CIPHER_SUITE_CCMP,
153
WLAN_CIPHER_SUITE_GCMP,
154
WLAN_CIPHER_SUITE_GCMP_256,
155
WLAN_CIPHER_SUITE_AES_CMAC,
156
WLAN_CIPHER_SUITE_BIP_GMAC_128,
157
WLAN_CIPHER_SUITE_BIP_GMAC_256
158
};
159
160
if (fips_enabled)
161
return;
162
163
hw->wiphy->n_cipher_suites = ARRAY_SIZE(mld_ciphers);
164
hw->wiphy->cipher_suites = mld_ciphers;
165
166
ieee80211_hw_set(hw, MFP_CAPABLE);
167
wiphy_ext_feature_set(hw->wiphy,
168
NL80211_EXT_FEATURE_BEACON_PROTECTION);
169
}
170
171
static void iwl_mld_hw_set_antennas(struct iwl_mld *mld)
172
{
173
struct wiphy *wiphy = mld->wiphy;
174
175
wiphy->available_antennas_tx = iwl_mld_get_valid_tx_ant(mld);
176
wiphy->available_antennas_rx = iwl_mld_get_valid_rx_ant(mld);
177
}
178
179
static void iwl_mld_hw_set_pm(struct iwl_mld *mld)
180
{
181
#ifdef CONFIG_PM_SLEEP
182
struct wiphy *wiphy = mld->wiphy;
183
184
if (!device_can_wakeup(mld->trans->dev))
185
return;
186
187
if (fips_enabled)
188
return;
189
190
mld->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
191
WIPHY_WOWLAN_DISCONNECT |
192
WIPHY_WOWLAN_EAP_IDENTITY_REQ |
193
WIPHY_WOWLAN_RFKILL_RELEASE |
194
WIPHY_WOWLAN_NET_DETECT |
195
WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
196
WIPHY_WOWLAN_GTK_REKEY_FAILURE |
197
WIPHY_WOWLAN_4WAY_HANDSHAKE;
198
199
mld->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
200
mld->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
201
mld->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
202
mld->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES_V2;
203
204
wiphy->wowlan = &mld->wowlan;
205
#endif /* CONFIG_PM_SLEEP */
206
}
207
208
static void iwl_mac_hw_set_radiotap(struct iwl_mld *mld)
209
{
210
struct ieee80211_hw *hw = mld->hw;
211
212
hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
213
IEEE80211_RADIOTAP_MCS_HAVE_STBC;
214
215
hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
216
IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
217
218
hw->radiotap_timestamp.units_pos =
219
IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
220
IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
221
222
/* this is the case for CCK frames, it's better (only 8) for OFDM */
223
hw->radiotap_timestamp.accuracy = 22;
224
}
225
226
static void iwl_mac_hw_set_flags(struct iwl_mld *mld)
227
{
228
struct ieee80211_hw *hw = mld->hw;
229
230
ieee80211_hw_set(hw, USES_RSS);
231
ieee80211_hw_set(hw, HANDLES_QUIET_CSA);
232
ieee80211_hw_set(hw, AP_LINK_PS);
233
ieee80211_hw_set(hw, SIGNAL_DBM);
234
ieee80211_hw_set(hw, SPECTRUM_MGMT);
235
ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
236
ieee80211_hw_set(hw, WANT_MONITOR_VIF);
237
ieee80211_hw_set(hw, SUPPORTS_PS);
238
ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
239
ieee80211_hw_set(hw, AMPDU_AGGREGATION);
240
ieee80211_hw_set(hw, CONNECTION_MONITOR);
241
ieee80211_hw_set(hw, CHANCTX_STA_CSA);
242
ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
243
ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
244
ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
245
ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
246
ieee80211_hw_set(hw, BUFF_MMPDU_TXQ);
247
ieee80211_hw_set(hw, STA_MMPDU_TXQ);
248
ieee80211_hw_set(hw, TX_AMSDU);
249
ieee80211_hw_set(hw, TX_FRAG_LIST);
250
ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
251
ieee80211_hw_set(hw, HAS_RATE_CONTROL);
252
ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
253
ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
254
ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
255
ieee80211_hw_set(hw, TDLS_WIDER_BW);
256
}
257
258
static void iwl_mac_hw_set_wiphy(struct iwl_mld *mld)
259
{
260
struct ieee80211_hw *hw = mld->hw;
261
struct wiphy *wiphy = hw->wiphy;
262
const struct iwl_ucode_capabilities *ucode_capa = &mld->fw->ucode_capa;
263
264
snprintf(wiphy->fw_version,
265
sizeof(wiphy->fw_version),
266
"%.31s", mld->fw->fw_version);
267
268
wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
269
BIT(NL80211_IFTYPE_P2P_CLIENT) |
270
BIT(NL80211_IFTYPE_AP) |
271
BIT(NL80211_IFTYPE_P2P_GO) |
272
BIT(NL80211_IFTYPE_P2P_DEVICE) |
273
BIT(NL80211_IFTYPE_ADHOC);
274
275
wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
276
NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
277
NL80211_FEATURE_ND_RANDOM_MAC_ADDR |
278
NL80211_FEATURE_HT_IBSS |
279
NL80211_FEATURE_P2P_GO_CTWIN |
280
NL80211_FEATURE_LOW_PRIORITY_SCAN |
281
NL80211_FEATURE_P2P_GO_OPPPS |
282
NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
283
NL80211_FEATURE_SUPPORTS_WMM_ADMISSION |
284
NL80211_FEATURE_TX_POWER_INSERTION |
285
NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
286
287
wiphy->flags |= WIPHY_FLAG_IBSS_RSN |
288
WIPHY_FLAG_AP_UAPSD |
289
WIPHY_FLAG_HAS_CHANNEL_SWITCH |
290
WIPHY_FLAG_SPLIT_SCAN_6GHZ |
291
WIPHY_FLAG_SUPPORTS_TDLS |
292
WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK;
293
294
/* For fips_enabled, don't support WiFi7 due to WPA3/MFP requirements */
295
if (mld->nvm_data->sku_cap_11be_enable &&
296
!iwlwifi_mod_params.disable_11ax &&
297
!iwlwifi_mod_params.disable_11be &&
298
!fips_enabled)
299
wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO;
300
301
/* the firmware uses u8 for num of iterations, but 0xff is saved for
302
* infinite loop, so the maximum number of iterations is actually 254.
303
*/
304
wiphy->max_sched_scan_plan_iterations = 254;
305
wiphy->max_sched_scan_ie_len = iwl_mld_scan_max_template_size();
306
wiphy->max_scan_ie_len = iwl_mld_scan_max_template_size();
307
wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
308
wiphy->max_scan_ssids = PROBE_OPTION_MAX;
309
wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
310
wiphy->max_sched_scan_reqs = 1;
311
wiphy->max_sched_scan_plan_interval = U16_MAX;
312
wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES_V2;
313
314
wiphy->max_remain_on_channel_duration = 10000;
315
316
wiphy->hw_version = mld->trans->info.hw_id;
317
318
wiphy->hw_timestamp_max_peers = 1;
319
320
wiphy->iface_combinations = iwl_mld_iface_combinations;
321
wiphy->n_iface_combinations = ARRAY_SIZE(iwl_mld_iface_combinations);
322
323
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
324
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_DFS_CONCURRENT);
325
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_LEGACY);
326
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SCAN_START_TIME);
327
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BSS_PARENT_TSF);
328
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT);
329
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
330
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
331
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
332
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
333
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SPP_AMSDU_SUPPORT);
334
335
if (fw_has_capa(ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT))
336
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_PROTECTED_TWT);
337
338
wiphy->iftype_ext_capab = NULL;
339
wiphy->num_iftype_ext_capab = 0;
340
341
if (!iwlwifi_mod_params.disable_11ax) {
342
wiphy->iftype_ext_capab = iftypes_ext_capa;
343
wiphy->num_iftype_ext_capab = ARRAY_SIZE(iftypes_ext_capa);
344
345
ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
346
ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID);
347
}
348
349
if (iwlmld_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
350
wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
351
else
352
wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
353
}
354
355
static void iwl_mac_hw_set_misc(struct iwl_mld *mld)
356
{
357
struct ieee80211_hw *hw = mld->hw;
358
359
hw->queues = IEEE80211_NUM_ACS;
360
361
hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
362
hw->netdev_features |= mld->trans->mac_cfg->base->features;
363
364
hw->max_tx_fragments = mld->trans->info.max_skb_frags;
365
hw->max_listen_interval = IWL_MLD_CONN_LISTEN_INTERVAL;
366
367
hw->uapsd_max_sp_len = IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL;
368
hw->uapsd_queues = IEEE80211_WMM_IE_STA_QOSINFO_AC_VO |
369
IEEE80211_WMM_IE_STA_QOSINFO_AC_VI |
370
IEEE80211_WMM_IE_STA_QOSINFO_AC_BK |
371
IEEE80211_WMM_IE_STA_QOSINFO_AC_BE;
372
373
hw->chanctx_data_size = sizeof(struct iwl_mld_phy);
374
hw->vif_data_size = sizeof(struct iwl_mld_vif);
375
hw->sta_data_size = sizeof(struct iwl_mld_sta);
376
hw->txq_data_size = sizeof(struct iwl_mld_txq);
377
378
/* TODO: Remove this division when IEEE80211_MAX_AMPDU_BUF_EHT size
379
* is supported.
380
* Note: ensure that IWL_DEFAULT_QUEUE_SIZE_EHT is updated accordingly.
381
*/
382
hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_EHT / 2;
383
}
384
385
static int iwl_mld_hw_verify_preconditions(struct iwl_mld *mld)
386
{
387
int ratecheck;
388
389
/* check for rates version 3 */
390
ratecheck =
391
(iwl_fw_lookup_cmd_ver(mld->fw, TX_CMD, 0) >= 11) +
392
(iwl_fw_lookup_notif_ver(mld->fw, DATA_PATH_GROUP,
393
TLC_MNG_UPDATE_NOTIF, 0) >= 4) +
394
(iwl_fw_lookup_notif_ver(mld->fw, LEGACY_GROUP,
395
REPLY_RX_MPDU_CMD, 0) >= 6) +
396
(iwl_fw_lookup_notif_ver(mld->fw, DATA_PATH_GROUP,
397
RX_NO_DATA_NOTIF, 0) >= 4) +
398
(iwl_fw_lookup_notif_ver(mld->fw, LONG_GROUP, TX_CMD, 0) >= 9);
399
400
if (ratecheck != 0 && ratecheck != 5) {
401
IWL_ERR(mld, "Firmware has inconsistent rates\n");
402
return -EINVAL;
403
}
404
405
/* 11ax is expected to be enabled for all supported devices */
406
if (WARN_ON(!mld->nvm_data->sku_cap_11ax_enable))
407
return -EINVAL;
408
409
/* LAR is expected to be enabled for all supported devices */
410
if (WARN_ON(!mld->nvm_data->lar_enabled))
411
return -EINVAL;
412
413
/* All supported devices are currently using version 3 of the cmd.
414
* Since version 3, IWL_SCAN_MAX_PROFILES_V2 shall be used where
415
* necessary.
416
*/
417
if (WARN_ON(iwl_fw_lookup_cmd_ver(mld->fw,
418
SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
419
IWL_FW_CMD_VER_UNKNOWN) != 3))
420
return -EINVAL;
421
422
return 0;
423
}
424
425
int iwl_mld_register_hw(struct iwl_mld *mld)
426
{
427
/* verify once essential preconditions required for setting
428
* the hw capabilities
429
*/
430
if (iwl_mld_hw_verify_preconditions(mld))
431
return -EINVAL;
432
433
iwl_mld_hw_set_addresses(mld);
434
iwl_mld_hw_set_channels(mld);
435
iwl_mld_hw_set_security(mld);
436
iwl_mld_hw_set_pm(mld);
437
iwl_mld_hw_set_antennas(mld);
438
iwl_mac_hw_set_radiotap(mld);
439
iwl_mac_hw_set_flags(mld);
440
iwl_mac_hw_set_wiphy(mld);
441
iwl_mac_hw_set_misc(mld);
442
443
SET_IEEE80211_DEV(mld->hw, mld->trans->dev);
444
445
return ieee80211_register_hw(mld->hw);
446
}
447
448
static void
449
iwl_mld_mac80211_tx(struct ieee80211_hw *hw,
450
struct ieee80211_tx_control *control, struct sk_buff *skb)
451
{
452
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
453
struct ieee80211_sta *sta = control->sta;
454
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
455
struct ieee80211_hdr *hdr = (void *)skb->data;
456
u32 link_id = u32_get_bits(info->control.flags,
457
IEEE80211_TX_CTRL_MLO_LINK);
458
459
/* In AP mode, mgmt frames are sent on the bcast station,
460
* so the FW can't translate the MLD addr to the link addr. Do it here
461
*/
462
if (ieee80211_is_mgmt(hdr->frame_control) && sta &&
463
link_id != IEEE80211_LINK_UNSPECIFIED &&
464
!ieee80211_is_probe_resp(hdr->frame_control)) {
465
/* translate MLD addresses to LINK addresses */
466
struct ieee80211_link_sta *link_sta =
467
rcu_dereference(sta->link[link_id]);
468
struct ieee80211_bss_conf *link_conf =
469
rcu_dereference(info->control.vif->link_conf[link_id]);
470
struct ieee80211_mgmt *mgmt;
471
472
if (WARN_ON(!link_sta || !link_conf)) {
473
ieee80211_free_txskb(hw, skb);
474
return;
475
}
476
477
mgmt = (void *)hdr;
478
memcpy(mgmt->da, link_sta->addr, ETH_ALEN);
479
memcpy(mgmt->sa, link_conf->addr, ETH_ALEN);
480
memcpy(mgmt->bssid, link_conf->bssid, ETH_ALEN);
481
}
482
483
iwl_mld_tx_skb(mld, skb, NULL);
484
}
485
486
static void
487
iwl_mld_restart_cleanup(struct iwl_mld *mld)
488
{
489
iwl_cleanup_mld(mld);
490
491
ieee80211_iterate_interfaces(mld->hw, IEEE80211_IFACE_ITER_ACTIVE,
492
iwl_mld_cleanup_vif, NULL);
493
494
ieee80211_iterate_stations_atomic(mld->hw,
495
iwl_mld_cleanup_sta, NULL);
496
497
iwl_mld_ftm_restart_cleanup(mld);
498
}
499
500
static
501
int iwl_mld_mac80211_start(struct ieee80211_hw *hw)
502
{
503
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
504
bool in_d3 = false;
505
int ret = 0;
506
507
lockdep_assert_wiphy(mld->wiphy);
508
509
#ifdef CONFIG_PM_SLEEP
510
/* Unless the host goes into hibernate the FW always stays on and
511
* the d3_resume flow is used. When wowlan is configured, mac80211
512
* would call it's resume callback and the wowlan_resume flow
513
* would be used.
514
*/
515
516
in_d3 = mld->fw_status.in_d3;
517
if (in_d3) {
518
/* mac80211 already cleaned up the state, no need for cleanup */
519
ret = iwl_mld_no_wowlan_resume(mld);
520
if (ret) {
521
iwl_mld_stop_fw(mld);
522
/* We're not really restarting in the sense of
523
* in_hw_restart even if we got an error during
524
* this. We'll just start again below and have
525
* nothing to recover, mac80211 will do anyway.
526
*/
527
mld->fw_status.in_hw_restart = false;
528
}
529
}
530
#endif /* CONFIG_PM_SLEEP */
531
532
if (mld->fw_status.in_hw_restart) {
533
iwl_mld_stop_fw(mld);
534
iwl_mld_restart_cleanup(mld);
535
}
536
537
if (!in_d3 || ret) {
538
ret = iwl_mld_start_fw(mld);
539
if (ret)
540
goto error;
541
}
542
543
mld->scan.last_start_time_jiffies = jiffies;
544
545
iwl_dbg_tlv_time_point(&mld->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT,
546
NULL);
547
iwl_dbg_tlv_time_point(&mld->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC,
548
NULL);
549
550
return 0;
551
552
error:
553
/* If we failed to restart the hw, there is nothing useful
554
* we can do but indicate we are no longer in restart.
555
*/
556
mld->fw_status.in_hw_restart = false;
557
558
return ret;
559
}
560
561
static
562
void iwl_mld_mac80211_stop(struct ieee80211_hw *hw, bool suspend)
563
{
564
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
565
566
lockdep_assert_wiphy(mld->wiphy);
567
568
wiphy_work_cancel(mld->wiphy, &mld->add_txqs_wk);
569
570
/* if the suspend flow fails the fw is in error. Stop it here, and it
571
* will be started upon wakeup
572
*/
573
if (!suspend ||
574
(IS_ENABLED(CONFIG_PM_SLEEP) && iwl_mld_no_wowlan_suspend(mld)))
575
iwl_mld_stop_fw(mld);
576
577
/* Clear in_hw_restart flag when stopping the hw, as mac80211 won't
578
* execute the restart.
579
*/
580
mld->fw_status.in_hw_restart = false;
581
582
/* We shouldn't have any UIDs still set. Loop over all the UIDs to
583
* make sure there's nothing left there and warn if any is found.
584
*/
585
for (int i = 0; i < ARRAY_SIZE(mld->scan.uid_status); i++)
586
if (WARN_ONCE(mld->scan.uid_status[i],
587
"UMAC scan UID %d status was not cleaned (0x%x 0x%x)\n",
588
i, mld->scan.uid_status[i], mld->scan.status))
589
mld->scan.uid_status[i] = 0;
590
}
591
592
static
593
int iwl_mld_mac80211_config(struct ieee80211_hw *hw, int radio_idx,
594
u32 changed)
595
{
596
return 0;
597
}
598
599
static
600
int iwl_mld_mac80211_add_interface(struct ieee80211_hw *hw,
601
struct ieee80211_vif *vif)
602
{
603
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
604
int ret;
605
606
lockdep_assert_wiphy(mld->wiphy);
607
608
/* Construct mld_vif, add it to fw, and map its ID to ieee80211_vif */
609
ret = iwl_mld_add_vif(mld, vif);
610
if (ret)
611
return ret;
612
613
/*
614
* Add the default link, but not if this is an MLD vif as that implies
615
* the HW is restarting and it will be configured by change_vif_links.
616
*/
617
if (!ieee80211_vif_is_mld(vif))
618
ret = iwl_mld_add_link(mld, &vif->bss_conf);
619
if (ret)
620
goto err;
621
622
if (vif->type == NL80211_IFTYPE_STATION) {
623
vif->driver_flags |= IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC;
624
if (!vif->p2p)
625
vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
626
IEEE80211_VIF_SUPPORTS_CQM_RSSI;
627
}
628
629
if (vif->p2p || iwl_fw_lookup_cmd_ver(mld->fw, PHY_CONTEXT_CMD, 0) < 5)
630
vif->driver_flags |= IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW;
631
632
/*
633
* For an MLD vif (in restart) we may not have a link; delay the call
634
* the initial change_vif_links.
635
*/
636
if (vif->type == NL80211_IFTYPE_STATION &&
637
!ieee80211_vif_is_mld(vif))
638
iwl_mld_update_mac_power(mld, vif, false);
639
640
if (vif->type == NL80211_IFTYPE_MONITOR) {
641
mld->monitor.on = true;
642
ieee80211_hw_set(mld->hw, RX_INCLUDES_FCS);
643
}
644
645
if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
646
mld->p2p_device_vif = vif;
647
648
return 0;
649
650
err:
651
iwl_mld_rm_vif(mld, vif);
652
return ret;
653
}
654
655
static
656
void iwl_mld_mac80211_remove_interface(struct ieee80211_hw *hw,
657
struct ieee80211_vif *vif)
658
{
659
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
660
661
lockdep_assert_wiphy(mld->wiphy);
662
663
if (ieee80211_vif_type_p2p(vif) == NL80211_IFTYPE_STATION)
664
vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
665
IEEE80211_VIF_SUPPORTS_CQM_RSSI);
666
667
if (vif->type == NL80211_IFTYPE_MONITOR) {
668
__clear_bit(IEEE80211_HW_RX_INCLUDES_FCS, mld->hw->flags);
669
mld->monitor.on = false;
670
}
671
672
if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
673
mld->p2p_device_vif = NULL;
674
675
iwl_mld_remove_link(mld, &vif->bss_conf);
676
677
#ifdef CONFIG_IWLWIFI_DEBUGFS
678
debugfs_remove(iwl_mld_vif_from_mac80211(vif)->dbgfs_slink);
679
iwl_mld_vif_from_mac80211(vif)->dbgfs_slink = NULL;
680
#endif
681
682
iwl_mld_rm_vif(mld, vif);
683
}
684
685
struct iwl_mld_mc_iter_data {
686
struct iwl_mld *mld;
687
int port_id;
688
};
689
690
static void iwl_mld_mc_iface_iterator(void *data, u8 *mac,
691
struct ieee80211_vif *vif)
692
{
693
struct iwl_mld_mc_iter_data *mc_data = data;
694
struct iwl_mld *mld = mc_data->mld;
695
struct iwl_mcast_filter_cmd *cmd = mld->mcast_filter_cmd;
696
struct iwl_host_cmd hcmd = {
697
.id = MCAST_FILTER_CMD,
698
.dataflags[0] = IWL_HCMD_DFL_NOCOPY,
699
};
700
int ret, len;
701
702
/* If we don't have free ports, mcast frames will be dropped */
703
if (WARN_ON_ONCE(mc_data->port_id >= MAX_PORT_ID_NUM))
704
return;
705
706
if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc)
707
return;
708
709
cmd->port_id = mc_data->port_id++;
710
ether_addr_copy(cmd->bssid, vif->bss_conf.bssid);
711
len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
712
713
hcmd.len[0] = len;
714
hcmd.data[0] = cmd;
715
716
ret = iwl_mld_send_cmd(mld, &hcmd);
717
if (ret)
718
IWL_ERR(mld, "mcast filter cmd error. ret=%d\n", ret);
719
}
720
721
void iwl_mld_recalc_multicast_filter(struct iwl_mld *mld)
722
{
723
struct iwl_mld_mc_iter_data iter_data = {
724
.mld = mld,
725
};
726
727
if (WARN_ON_ONCE(!mld->mcast_filter_cmd))
728
return;
729
730
ieee80211_iterate_active_interfaces(mld->hw,
731
IEEE80211_IFACE_ITER_NORMAL,
732
iwl_mld_mc_iface_iterator,
733
&iter_data);
734
}
735
736
static u64
737
iwl_mld_mac80211_prepare_multicast(struct ieee80211_hw *hw,
738
struct netdev_hw_addr_list *mc_list)
739
{
740
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
741
struct iwl_mcast_filter_cmd *cmd;
742
struct netdev_hw_addr *addr;
743
int addr_count = netdev_hw_addr_list_count(mc_list);
744
bool pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES;
745
int len;
746
747
if (pass_all)
748
addr_count = 0;
749
750
/* len must be a multiple of 4 */
751
len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
752
cmd = kzalloc(len, GFP_ATOMIC);
753
if (!cmd)
754
return 0;
755
756
if (pass_all) {
757
cmd->pass_all = 1;
758
goto out;
759
}
760
761
netdev_hw_addr_list_for_each(addr, mc_list) {
762
IWL_DEBUG_MAC80211(mld, "mcast addr (%d): %pM\n",
763
cmd->count, addr->addr);
764
ether_addr_copy(&cmd->addr_list[cmd->count * ETH_ALEN],
765
addr->addr);
766
cmd->count++;
767
}
768
769
out:
770
return (u64)(unsigned long)cmd;
771
}
772
773
static
774
void iwl_mld_mac80211_configure_filter(struct ieee80211_hw *hw,
775
unsigned int changed_flags,
776
unsigned int *total_flags,
777
u64 multicast)
778
{
779
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
780
struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
781
782
/* Replace previous configuration */
783
kfree(mld->mcast_filter_cmd);
784
mld->mcast_filter_cmd = cmd;
785
786
if (!cmd)
787
goto out;
788
789
if (changed_flags & FIF_ALLMULTI)
790
cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
791
792
if (cmd->pass_all)
793
cmd->count = 0;
794
795
iwl_mld_recalc_multicast_filter(mld);
796
out:
797
*total_flags = 0;
798
}
799
800
static
801
void iwl_mld_mac80211_wake_tx_queue(struct ieee80211_hw *hw,
802
struct ieee80211_txq *txq)
803
{
804
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
805
struct iwl_mld_txq *mld_txq = iwl_mld_txq_from_mac80211(txq);
806
807
if (likely(mld_txq->status.allocated) || !txq->sta) {
808
iwl_mld_tx_from_txq(mld, txq);
809
return;
810
}
811
812
/* We don't support TSPEC tids. %IEEE80211_NUM_TIDS is for mgmt */
813
if (txq->tid != IEEE80211_NUM_TIDS && txq->tid >= IWL_MAX_TID_COUNT) {
814
IWL_DEBUG_MAC80211(mld, "TID %d is not supported\n", txq->tid);
815
return;
816
}
817
818
/* The worker will handle any packets we leave on the txq now */
819
820
spin_lock_bh(&mld->add_txqs_lock);
821
/* The list is being deleted only after the queue is fully allocated. */
822
if (list_empty(&mld_txq->list) &&
823
/* recheck under lock, otherwise it can be added twice */
824
!mld_txq->status.allocated) {
825
list_add_tail(&mld_txq->list, &mld->txqs_to_add);
826
wiphy_work_queue(mld->wiphy, &mld->add_txqs_wk);
827
}
828
spin_unlock_bh(&mld->add_txqs_lock);
829
}
830
831
static void iwl_mld_teardown_tdls_peers(struct iwl_mld *mld)
832
{
833
lockdep_assert_wiphy(mld->wiphy);
834
835
for (int i = 0; i < mld->fw->ucode_capa.num_stations; i++) {
836
struct ieee80211_link_sta *link_sta;
837
struct iwl_mld_sta *mld_sta;
838
839
link_sta = wiphy_dereference(mld->wiphy,
840
mld->fw_id_to_link_sta[i]);
841
if (IS_ERR_OR_NULL(link_sta))
842
continue;
843
844
if (!link_sta->sta->tdls)
845
continue;
846
847
mld_sta = iwl_mld_sta_from_mac80211(link_sta->sta);
848
849
ieee80211_tdls_oper_request(mld_sta->vif, link_sta->addr,
850
NL80211_TDLS_TEARDOWN,
851
WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED,
852
GFP_KERNEL);
853
}
854
}
855
856
static
857
int iwl_mld_add_chanctx(struct ieee80211_hw *hw,
858
struct ieee80211_chanctx_conf *ctx)
859
{
860
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
861
struct iwl_mld_phy *phy = iwl_mld_phy_from_mac80211(ctx);
862
int fw_id = iwl_mld_allocate_fw_phy_id(mld);
863
int ret;
864
865
if (fw_id < 0)
866
return fw_id;
867
868
phy->mld = mld;
869
phy->fw_id = fw_id;
870
phy->chandef = *iwl_mld_get_chandef_from_chanctx(mld, ctx);
871
872
ret = iwl_mld_phy_fw_action(mld, ctx, FW_CTXT_ACTION_ADD);
873
if (ret) {
874
mld->used_phy_ids &= ~BIT(phy->fw_id);
875
return ret;
876
}
877
878
if (hweight8(mld->used_phy_ids) > 1)
879
iwl_mld_teardown_tdls_peers(mld);
880
881
return 0;
882
}
883
884
static
885
void iwl_mld_remove_chanctx(struct ieee80211_hw *hw,
886
struct ieee80211_chanctx_conf *ctx)
887
{
888
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
889
struct iwl_mld_phy *phy = iwl_mld_phy_from_mac80211(ctx);
890
891
iwl_mld_phy_fw_action(mld, ctx, FW_CTXT_ACTION_REMOVE);
892
mld->used_phy_ids &= ~BIT(phy->fw_id);
893
}
894
895
static
896
void iwl_mld_change_chanctx(struct ieee80211_hw *hw,
897
struct ieee80211_chanctx_conf *ctx, u32 changed)
898
{
899
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
900
struct iwl_mld_phy *phy = iwl_mld_phy_from_mac80211(ctx);
901
struct cfg80211_chan_def *chandef =
902
iwl_mld_get_chandef_from_chanctx(mld, ctx);
903
904
/* We don't care about these */
905
if (!(changed & ~(IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
906
IEEE80211_CHANCTX_CHANGE_RADAR |
907
IEEE80211_CHANCTX_CHANGE_CHANNEL)))
908
return;
909
910
/* Check if a FW update is required */
911
912
if (changed & IEEE80211_CHANCTX_CHANGE_AP)
913
goto update;
914
915
if (chandef->chan == phy->chandef.chan &&
916
chandef->center_freq1 == phy->chandef.center_freq1 &&
917
chandef->punctured == phy->chandef.punctured) {
918
/* Check if we are toggling between HT and non-HT, no-op */
919
if (phy->chandef.width == chandef->width ||
920
(phy->chandef.width <= NL80211_CHAN_WIDTH_20 &&
921
chandef->width <= NL80211_CHAN_WIDTH_20))
922
return;
923
}
924
update:
925
926
iwl_mld_update_phy_chandef(mld, ctx);
927
}
928
929
static u8
930
iwl_mld_chandef_get_primary_80(struct cfg80211_chan_def *chandef)
931
{
932
int data_start;
933
int control_start;
934
int bw;
935
936
if (chandef->width == NL80211_CHAN_WIDTH_320)
937
bw = 320;
938
else if (chandef->width == NL80211_CHAN_WIDTH_160)
939
bw = 160;
940
else
941
return 0;
942
943
/* data is bw wide so the start is half the width */
944
data_start = chandef->center_freq1 - bw / 2;
945
/* control is 20Mhz width */
946
control_start = chandef->chan->center_freq - 10;
947
948
return (control_start - data_start) / 80;
949
}
950
951
static bool iwl_mld_can_activate_link(struct iwl_mld *mld,
952
struct ieee80211_vif *vif,
953
struct ieee80211_bss_conf *link)
954
{
955
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
956
struct iwl_mld_sta *mld_sta;
957
struct iwl_mld_link_sta *link_sta;
958
959
/* In association, we activate the assoc link before adding the STA. */
960
if (!mld_vif->ap_sta || !vif->cfg.assoc)
961
return true;
962
963
mld_sta = iwl_mld_sta_from_mac80211(mld_vif->ap_sta);
964
965
/* When switching links, we need to wait with the activation until the
966
* STA was added to the FW. It'll be activated in
967
* iwl_mld_update_link_stas
968
*/
969
link_sta = wiphy_dereference(mld->wiphy, mld_sta->link[link->link_id]);
970
971
/* In restart we can have a link_sta that doesn't exist in FW yet */
972
return link_sta && link_sta->in_fw;
973
}
974
975
static
976
int iwl_mld_assign_vif_chanctx(struct ieee80211_hw *hw,
977
struct ieee80211_vif *vif,
978
struct ieee80211_bss_conf *link,
979
struct ieee80211_chanctx_conf *ctx)
980
{
981
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
982
struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link);
983
unsigned int n_active = iwl_mld_count_active_links(mld, vif);
984
int ret;
985
986
lockdep_assert_wiphy(mld->wiphy);
987
988
if (WARN_ON(!mld_link))
989
return -EINVAL;
990
991
/* if the assigned one was not counted yet, count it now */
992
if (!rcu_access_pointer(mld_link->chan_ctx)) {
993
n_active++;
994
995
/* Track addition of non-BSS link */
996
if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION) {
997
ret = iwl_mld_emlsr_check_non_bss_block(mld, 1);
998
if (ret)
999
return ret;
1000
}
1001
}
1002
1003
/* for AP, mac parameters such as HE support are updated at this stage. */
1004
if (vif->type == NL80211_IFTYPE_AP) {
1005
ret = iwl_mld_mac_fw_action(mld, vif, FW_CTXT_ACTION_MODIFY);
1006
1007
if (ret) {
1008
IWL_ERR(mld, "failed to update MAC %pM\n", vif->addr);
1009
return -EINVAL;
1010
}
1011
}
1012
1013
rcu_assign_pointer(mld_link->chan_ctx, ctx);
1014
1015
if (n_active > 1) {
1016
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
1017
1018
/* Indicate to mac80211 that EML is enabled */
1019
vif->driver_flags |= IEEE80211_VIF_EML_ACTIVE;
1020
mld_vif->emlsr.last_entry_ts = jiffies;
1021
1022
if (vif->active_links & BIT(mld_vif->emlsr.selected_links))
1023
mld_vif->emlsr.primary = mld_vif->emlsr.selected_primary;
1024
else
1025
mld_vif->emlsr.primary = __ffs(vif->active_links);
1026
1027
iwl_dbg_tlv_time_point(&mld->fwrt, IWL_FW_INI_TIME_ESR_LINK_UP,
1028
NULL);
1029
}
1030
1031
/* First send the link command with the phy context ID.
1032
* Now that we have the phy, we know the band so also the rates
1033
*/
1034
ret = iwl_mld_change_link_in_fw(mld, link,
1035
LINK_CONTEXT_MODIFY_RATES_INFO);
1036
if (ret)
1037
goto err;
1038
1039
/* TODO: Initialize rate control for the AP station, since we might be
1040
* doing a link switch here - we cannot initialize it before since
1041
* this needs the phy context assigned (and in FW?), and we cannot
1042
* do it later because it needs to be initialized as soon as we're
1043
* able to TX on the link, i.e. when active. (task=link-switch)
1044
*/
1045
1046
/* Now activate the link */
1047
if (iwl_mld_can_activate_link(mld, vif, link)) {
1048
ret = iwl_mld_activate_link(mld, link);
1049
if (ret)
1050
goto err;
1051
}
1052
1053
if (vif->type == NL80211_IFTYPE_STATION)
1054
iwl_mld_send_ap_tx_power_constraint_cmd(mld, vif, link);
1055
1056
if (vif->type == NL80211_IFTYPE_MONITOR) {
1057
ret = iwl_mld_add_mon_sta(mld, vif, link);
1058
if (ret)
1059
goto deactivate_link;
1060
1061
mld->monitor.p80 =
1062
iwl_mld_chandef_get_primary_80(&vif->bss_conf.chanreq.oper);
1063
}
1064
1065
return 0;
1066
1067
deactivate_link:
1068
if (mld_link->active)
1069
iwl_mld_deactivate_link(mld, link);
1070
err:
1071
RCU_INIT_POINTER(mld_link->chan_ctx, NULL);
1072
return ret;
1073
}
1074
1075
static
1076
void iwl_mld_unassign_vif_chanctx(struct ieee80211_hw *hw,
1077
struct ieee80211_vif *vif,
1078
struct ieee80211_bss_conf *link,
1079
struct ieee80211_chanctx_conf *ctx)
1080
{
1081
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1082
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
1083
struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link);
1084
unsigned int n_active = iwl_mld_count_active_links(mld, vif);
1085
1086
if (WARN_ON(!mld_link))
1087
return;
1088
1089
/* Track removal of non-BSS link */
1090
if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION)
1091
iwl_mld_emlsr_check_non_bss_block(mld, -1);
1092
1093
iwl_mld_deactivate_link(mld, link);
1094
1095
if (vif->type == NL80211_IFTYPE_MONITOR)
1096
iwl_mld_remove_mon_sta(mld, vif, link);
1097
1098
if (n_active > 1) {
1099
/* Indicate to mac80211 that EML is disabled */
1100
vif->driver_flags &= ~IEEE80211_VIF_EML_ACTIVE;
1101
1102
iwl_dbg_tlv_time_point(&mld->fwrt,
1103
IWL_FW_INI_TIME_ESR_LINK_DOWN,
1104
NULL);
1105
}
1106
1107
RCU_INIT_POINTER(mld_link->chan_ctx, NULL);
1108
1109
/* in the non-MLO case, remove/re-add the link to clean up FW state.
1110
* In MLO, it'll be done in drv_change_vif_link
1111
*/
1112
if (!ieee80211_vif_is_mld(vif) && !mld_vif->ap_sta &&
1113
!WARN_ON_ONCE(vif->cfg.assoc) &&
1114
vif->type != NL80211_IFTYPE_AP && !mld->fw_status.in_hw_restart) {
1115
iwl_mld_remove_link(mld, link);
1116
iwl_mld_add_link(mld, link);
1117
}
1118
}
1119
1120
static
1121
int iwl_mld_mac80211_set_rts_threshold(struct ieee80211_hw *hw, int radio_idx,
1122
u32 value)
1123
{
1124
return 0;
1125
}
1126
1127
static void
1128
iwl_mld_link_info_changed_ap_ibss(struct iwl_mld *mld,
1129
struct ieee80211_vif *vif,
1130
struct ieee80211_bss_conf *link,
1131
u64 changes)
1132
{
1133
u32 link_changes = 0;
1134
1135
if (changes & BSS_CHANGED_ERP_SLOT)
1136
link_changes |= LINK_CONTEXT_MODIFY_RATES_INFO;
1137
1138
if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT))
1139
link_changes |= LINK_CONTEXT_MODIFY_PROTECT_FLAGS;
1140
1141
if (changes & (BSS_CHANGED_QOS | BSS_CHANGED_BANDWIDTH))
1142
link_changes |= LINK_CONTEXT_MODIFY_QOS_PARAMS;
1143
1144
if (changes & BSS_CHANGED_HE_BSS_COLOR)
1145
link_changes |= LINK_CONTEXT_MODIFY_HE_PARAMS;
1146
1147
if (link_changes)
1148
iwl_mld_change_link_in_fw(mld, link, link_changes);
1149
1150
if (changes & BSS_CHANGED_BEACON)
1151
iwl_mld_update_beacon_template(mld, vif, link);
1152
}
1153
1154
static
1155
u32 iwl_mld_link_changed_mapping(struct iwl_mld *mld,
1156
struct ieee80211_vif *vif,
1157
struct ieee80211_bss_conf *link_conf,
1158
u64 changes)
1159
{
1160
u32 link_changes = 0;
1161
bool has_he, has_eht;
1162
1163
if (changes & BSS_CHANGED_QOS && vif->cfg.assoc && link_conf->qos)
1164
link_changes |= LINK_CONTEXT_MODIFY_QOS_PARAMS;
1165
1166
if (changes & (BSS_CHANGED_ERP_PREAMBLE | BSS_CHANGED_BASIC_RATES |
1167
BSS_CHANGED_ERP_SLOT))
1168
link_changes |= LINK_CONTEXT_MODIFY_RATES_INFO;
1169
1170
if (changes & (BSS_CHANGED_HT | BSS_CHANGED_ERP_CTS_PROT))
1171
link_changes |= LINK_CONTEXT_MODIFY_PROTECT_FLAGS;
1172
1173
/* TODO: task=MLO check mac80211's HE flags and if command is needed
1174
* every time there's a link change. Currently used flags are
1175
* BSS_CHANGED_HE_OBSS_PD and BSS_CHANGED_HE_BSS_COLOR.
1176
*/
1177
has_he = link_conf->he_support && !iwlwifi_mod_params.disable_11ax;
1178
has_eht = link_conf->eht_support && !iwlwifi_mod_params.disable_11be;
1179
1180
if (vif->cfg.assoc && (has_he || has_eht)) {
1181
IWL_DEBUG_MAC80211(mld, "Associated in HE mode\n");
1182
link_changes |= LINK_CONTEXT_MODIFY_HE_PARAMS;
1183
}
1184
1185
return link_changes;
1186
}
1187
1188
static void
1189
iwl_mld_mac80211_link_info_changed_sta(struct iwl_mld *mld,
1190
struct ieee80211_vif *vif,
1191
struct ieee80211_bss_conf *link_conf,
1192
u64 changes)
1193
{
1194
u32 link_changes = iwl_mld_link_changed_mapping(mld, vif, link_conf,
1195
changes);
1196
1197
if (link_changes)
1198
iwl_mld_change_link_in_fw(mld, link_conf, link_changes);
1199
1200
if (changes & BSS_CHANGED_TPE)
1201
iwl_mld_send_ap_tx_power_constraint_cmd(mld, vif, link_conf);
1202
1203
if (changes & BSS_CHANGED_BEACON_INFO)
1204
iwl_mld_update_mac_power(mld, vif, false);
1205
1206
/* The firmware will wait quite a while after association before it
1207
* starts filtering the beacons. We can safely enable beacon filtering
1208
* upon CQM configuration, even if we didn't get a beacon yet.
1209
*/
1210
if (changes & (BSS_CHANGED_CQM | BSS_CHANGED_BEACON_INFO))
1211
iwl_mld_enable_beacon_filter(mld, link_conf, false);
1212
1213
if (changes & BSS_CHANGED_BANDWIDTH)
1214
iwl_mld_retry_emlsr(mld, vif);
1215
}
1216
1217
static int iwl_mld_update_mu_groups(struct iwl_mld *mld,
1218
struct ieee80211_bss_conf *link_conf)
1219
{
1220
struct iwl_mu_group_mgmt_cmd cmd = {};
1221
1222
BUILD_BUG_ON(sizeof(cmd.membership_status) !=
1223
sizeof(link_conf->mu_group.membership));
1224
BUILD_BUG_ON(sizeof(cmd.user_position) !=
1225
sizeof(link_conf->mu_group.position));
1226
1227
memcpy(cmd.membership_status, link_conf->mu_group.membership,
1228
WLAN_MEMBERSHIP_LEN);
1229
memcpy(cmd.user_position, link_conf->mu_group.position,
1230
WLAN_USER_POSITION_LEN);
1231
1232
return iwl_mld_send_cmd_pdu(mld,
1233
WIDE_ID(DATA_PATH_GROUP,
1234
UPDATE_MU_GROUPS_CMD),
1235
&cmd);
1236
}
1237
1238
static void
1239
iwl_mld_mac80211_link_info_changed(struct ieee80211_hw *hw,
1240
struct ieee80211_vif *vif,
1241
struct ieee80211_bss_conf *link_conf,
1242
u64 changes)
1243
{
1244
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1245
1246
switch (vif->type) {
1247
case NL80211_IFTYPE_STATION:
1248
iwl_mld_mac80211_link_info_changed_sta(mld, vif, link_conf,
1249
changes);
1250
break;
1251
case NL80211_IFTYPE_AP:
1252
case NL80211_IFTYPE_ADHOC:
1253
iwl_mld_link_info_changed_ap_ibss(mld, vif, link_conf,
1254
changes);
1255
break;
1256
case NL80211_IFTYPE_MONITOR:
1257
/* The firmware tracks this on its own in STATION mode, but
1258
* obviously not in sniffer mode.
1259
*/
1260
if (changes & BSS_CHANGED_MU_GROUPS)
1261
iwl_mld_update_mu_groups(mld, link_conf);
1262
break;
1263
default:
1264
/* shouldn't happen */
1265
WARN_ON_ONCE(1);
1266
}
1267
1268
/* We now know our BSSID, we can configure the MAC context with
1269
* eht_support if needed.
1270
*/
1271
if (changes & BSS_CHANGED_BSSID)
1272
iwl_mld_mac_fw_action(mld, vif, FW_CTXT_ACTION_MODIFY);
1273
1274
if (changes & BSS_CHANGED_TXPOWER)
1275
iwl_mld_set_tx_power(mld, link_conf, link_conf->txpower);
1276
}
1277
1278
static void
1279
iwl_mld_smps_workaround(struct iwl_mld *mld, struct ieee80211_vif *vif, bool enable)
1280
{
1281
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
1282
bool workaround_required =
1283
iwl_fw_lookup_cmd_ver(mld->fw, MAC_PM_POWER_TABLE, 0) < 2;
1284
1285
if (!workaround_required)
1286
return;
1287
1288
/* Send the device-level power commands since the
1289
* firmware checks the POWER_TABLE_CMD's POWER_SAVE_EN bit to
1290
* determine SMPS mode.
1291
*/
1292
if (mld_vif->ps_disabled == !enable)
1293
return;
1294
1295
mld_vif->ps_disabled = !enable;
1296
1297
iwl_mld_update_device_power(mld, false);
1298
}
1299
1300
static
1301
void iwl_mld_mac80211_vif_cfg_changed(struct ieee80211_hw *hw,
1302
struct ieee80211_vif *vif,
1303
u64 changes)
1304
{
1305
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1306
int ret;
1307
1308
lockdep_assert_wiphy(mld->wiphy);
1309
1310
if (vif->type != NL80211_IFTYPE_STATION)
1311
return;
1312
1313
if (changes & BSS_CHANGED_ASSOC) {
1314
ret = iwl_mld_mac_fw_action(mld, vif, FW_CTXT_ACTION_MODIFY);
1315
if (ret)
1316
IWL_ERR(mld, "failed to update context\n");
1317
1318
if (vif->cfg.assoc) {
1319
/* Clear statistics to get clean beacon counter, and
1320
* ask for periodic statistics, as they are needed for
1321
* link selection and RX OMI decisions.
1322
*/
1323
iwl_mld_clear_stats_in_fw(mld);
1324
iwl_mld_request_periodic_fw_stats(mld, true);
1325
1326
iwl_mld_set_vif_associated(mld, vif);
1327
} else {
1328
iwl_mld_request_periodic_fw_stats(mld, false);
1329
}
1330
}
1331
1332
if (changes & BSS_CHANGED_PS) {
1333
iwl_mld_smps_workaround(mld, vif, vif->cfg.ps);
1334
iwl_mld_update_mac_power(mld, vif, false);
1335
}
1336
1337
/* TODO: task=MLO BSS_CHANGED_MLD_VALID_LINKS/CHANGED_MLD_TTLM */
1338
}
1339
1340
static int
1341
iwl_mld_mac80211_hw_scan(struct ieee80211_hw *hw,
1342
struct ieee80211_vif *vif,
1343
struct ieee80211_scan_request *hw_req)
1344
{
1345
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1346
int ret;
1347
1348
if (WARN_ON(!hw_req->req.n_channels ||
1349
hw_req->req.n_channels >
1350
mld->fw->ucode_capa.n_scan_channels))
1351
return -EINVAL;
1352
1353
ret = iwl_mld_regular_scan_start(mld, vif, &hw_req->req, &hw_req->ies);
1354
if (!ret) {
1355
/* We will be busy with scanning, so the counters may not reflect the
1356
* reality. Stop checking the counters until the scan ends
1357
*/
1358
iwl_mld_start_ignoring_tpt_updates(mld);
1359
}
1360
1361
return ret;
1362
}
1363
1364
static void
1365
iwl_mld_mac80211_cancel_hw_scan(struct ieee80211_hw *hw,
1366
struct ieee80211_vif *vif)
1367
{
1368
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1369
1370
/* Due to a race condition, it's possible that mac80211 asks
1371
* us to stop a hw_scan when it's already stopped. This can
1372
* happen, for instance, if we stopped the scan ourselves,
1373
* called ieee80211_scan_completed() and the userspace called
1374
* cancel scan before ieee80211_scan_work() could run.
1375
* To handle that, simply return if the scan is not running.
1376
*/
1377
if (mld->scan.status & IWL_MLD_SCAN_REGULAR) {
1378
iwl_mld_scan_stop(mld, IWL_MLD_SCAN_REGULAR, true);
1379
/* Scan is over, we can check again the tpt counters */
1380
iwl_mld_stop_ignoring_tpt_updates(mld);
1381
}
1382
}
1383
1384
static int
1385
iwl_mld_mac80211_sched_scan_start(struct ieee80211_hw *hw,
1386
struct ieee80211_vif *vif,
1387
struct cfg80211_sched_scan_request *req,
1388
struct ieee80211_scan_ies *ies)
1389
{
1390
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1391
1392
return iwl_mld_sched_scan_start(mld, vif, req, ies, IWL_MLD_SCAN_SCHED);
1393
}
1394
1395
static int
1396
iwl_mld_mac80211_sched_scan_stop(struct ieee80211_hw *hw,
1397
struct ieee80211_vif *vif)
1398
{
1399
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1400
1401
/* Due to a race condition, it's possible that mac80211 asks
1402
* us to stop a sched_scan when it's already stopped. This
1403
* can happen, for instance, if we stopped the scan ourselves,
1404
* called ieee80211_sched_scan_stopped() and the userspace called
1405
* stop sched scan before ieee80211_sched_scan_stopped_work()
1406
* could run. To handle this, simply return if the scan is
1407
* not running.
1408
*/
1409
if (!(mld->scan.status & IWL_MLD_SCAN_SCHED))
1410
return 0;
1411
1412
return iwl_mld_scan_stop(mld, IWL_MLD_SCAN_SCHED, false);
1413
}
1414
1415
static void
1416
iwl_mld_mac80211_reconfig_complete(struct ieee80211_hw *hw,
1417
enum ieee80211_reconfig_type reconfig_type)
1418
{
1419
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1420
1421
switch (reconfig_type) {
1422
case IEEE80211_RECONFIG_TYPE_RESTART:
1423
mld->fw_status.in_hw_restart = false;
1424
iwl_mld_send_recovery_cmd(mld, ERROR_RECOVERY_END_OF_RECOVERY);
1425
iwl_trans_finish_sw_reset(mld->trans);
1426
/* no need to lock, adding in parallel would schedule too */
1427
if (!list_empty(&mld->txqs_to_add))
1428
wiphy_work_queue(mld->wiphy, &mld->add_txqs_wk);
1429
1430
IWL_INFO(mld, "restart completed\n");
1431
break;
1432
case IEEE80211_RECONFIG_TYPE_SUSPEND:
1433
break;
1434
}
1435
}
1436
1437
static
1438
void iwl_mld_mac80211_mgd_prepare_tx(struct ieee80211_hw *hw,
1439
struct ieee80211_vif *vif,
1440
struct ieee80211_prep_tx_info *info)
1441
{
1442
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1443
u32 duration = IWL_MLD_SESSION_PROTECTION_ASSOC_TIME_MS;
1444
1445
/* After a successful association the connection is established
1446
* and we can rely on the quota to send the disassociation frame.
1447
*/
1448
if (info->was_assoc)
1449
return;
1450
1451
if (info->duration > duration)
1452
duration = info->duration;
1453
1454
iwl_mld_schedule_session_protection(mld, vif, duration,
1455
IWL_MLD_SESSION_PROTECTION_MIN_TIME_MS,
1456
info->link_id);
1457
}
1458
1459
static
1460
void iwl_mld_mac_mgd_complete_tx(struct ieee80211_hw *hw,
1461
struct ieee80211_vif *vif,
1462
struct ieee80211_prep_tx_info *info)
1463
{
1464
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1465
1466
/* Successful authentication is the only case that requires to let
1467
* the session protection go. We'll need it for the upcoming
1468
* association. For all the other cases, we need to cancel the session
1469
* protection.
1470
* After successful association the connection is established and
1471
* further mgd tx can rely on the quota.
1472
*/
1473
if (info->success && info->subtype == IEEE80211_STYPE_AUTH)
1474
return;
1475
1476
/* The firmware will be on medium after we configure the vif as
1477
* associated. Removing the session protection allows the firmware
1478
* to stop being on medium. In order to ensure the continuity of our
1479
* presence on medium, we need first to configure the vif as associated
1480
* and only then, remove the session protection.
1481
* Currently, mac80211 calls vif_cfg_changed() first and then,
1482
* drv_mgd_complete_tx(). Ensure that this assumption stays true by
1483
* a warning.
1484
*/
1485
WARN_ON(info->success &&
1486
(info->subtype == IEEE80211_STYPE_ASSOC_REQ ||
1487
info->subtype == IEEE80211_STYPE_REASSOC_REQ) &&
1488
!vif->cfg.assoc);
1489
1490
iwl_mld_cancel_session_protection(mld, vif, info->link_id);
1491
}
1492
1493
static int
1494
iwl_mld_mac80211_conf_tx(struct ieee80211_hw *hw,
1495
struct ieee80211_vif *vif,
1496
unsigned int link_id, u16 ac,
1497
const struct ieee80211_tx_queue_params *params)
1498
{
1499
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1500
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
1501
struct iwl_mld_link *link;
1502
1503
lockdep_assert_wiphy(mld->wiphy);
1504
1505
link = iwl_mld_link_dereference_check(mld_vif, link_id);
1506
if (!link)
1507
return -EINVAL;
1508
1509
link->queue_params[ac] = *params;
1510
1511
/* No need to update right away, we'll get BSS_CHANGED_QOS
1512
* The exception is P2P_DEVICE interface which needs immediate update.
1513
*/
1514
if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
1515
iwl_mld_change_link_in_fw(mld, &vif->bss_conf,
1516
LINK_CONTEXT_MODIFY_QOS_PARAMS);
1517
1518
return 0;
1519
}
1520
1521
static void iwl_mld_set_uapsd(struct iwl_mld *mld, struct ieee80211_vif *vif)
1522
{
1523
vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
1524
1525
if (vif->type != NL80211_IFTYPE_STATION)
1526
return;
1527
1528
if (vif->p2p &&
1529
!(iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_P2P_CLIENT))
1530
vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
1531
1532
if (!vif->p2p &&
1533
!(iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS))
1534
vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
1535
}
1536
1537
int iwl_mld_tdls_sta_count(struct iwl_mld *mld)
1538
{
1539
int count = 0;
1540
1541
lockdep_assert_wiphy(mld->wiphy);
1542
1543
for (int i = 0; i < mld->fw->ucode_capa.num_stations; i++) {
1544
struct ieee80211_link_sta *link_sta;
1545
1546
link_sta = wiphy_dereference(mld->wiphy,
1547
mld->fw_id_to_link_sta[i]);
1548
if (IS_ERR_OR_NULL(link_sta))
1549
continue;
1550
1551
if (!link_sta->sta->tdls)
1552
continue;
1553
1554
count++;
1555
}
1556
1557
return count;
1558
}
1559
1560
static void iwl_mld_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy,
1561
struct cfg80211_bss *bss,
1562
void *_data)
1563
{
1564
bool *tolerated = _data;
1565
const struct cfg80211_bss_ies *ies;
1566
const struct element *elem;
1567
1568
rcu_read_lock();
1569
ies = rcu_dereference(bss->ies);
1570
elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data,
1571
ies->len);
1572
1573
if (!elem || elem->datalen < 10 ||
1574
!(elem->data[10] &
1575
WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) {
1576
*tolerated = false;
1577
}
1578
rcu_read_unlock();
1579
}
1580
1581
static void
1582
iwl_mld_check_he_obss_narrow_bw_ru(struct iwl_mld *mld,
1583
struct iwl_mld_link *mld_link,
1584
struct ieee80211_bss_conf *link_conf)
1585
{
1586
bool tolerated = true;
1587
1588
if (WARN_ON_ONCE(!link_conf->chanreq.oper.chan))
1589
return;
1590
1591
if (!(link_conf->chanreq.oper.chan->flags & IEEE80211_CHAN_RADAR)) {
1592
mld_link->he_ru_2mhz_block = false;
1593
return;
1594
}
1595
1596
cfg80211_bss_iter(mld->wiphy, &link_conf->chanreq.oper,
1597
iwl_mld_check_he_obss_narrow_bw_ru_iter, &tolerated);
1598
1599
/* If there is at least one AP on radar channel that cannot
1600
* tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU.
1601
*/
1602
mld_link->he_ru_2mhz_block = !tolerated;
1603
}
1604
1605
static void iwl_mld_link_set_2mhz_block(struct iwl_mld *mld,
1606
struct ieee80211_vif *vif,
1607
struct ieee80211_sta *sta)
1608
{
1609
struct ieee80211_link_sta *link_sta;
1610
unsigned int link_id;
1611
1612
for_each_sta_active_link(vif, sta, link_sta, link_id) {
1613
struct ieee80211_bss_conf *link_conf =
1614
link_conf_dereference_protected(vif, link_id);
1615
struct iwl_mld_link *mld_link =
1616
iwl_mld_link_from_mac80211(link_conf);
1617
1618
if (WARN_ON(!link_conf || !mld_link))
1619
continue;
1620
1621
if (link_sta->he_cap.has_he)
1622
iwl_mld_check_he_obss_narrow_bw_ru(mld, mld_link,
1623
link_conf);
1624
}
1625
}
1626
1627
static int iwl_mld_move_sta_state_up(struct iwl_mld *mld,
1628
struct ieee80211_vif *vif,
1629
struct ieee80211_sta *sta,
1630
enum ieee80211_sta_state old_state,
1631
enum ieee80211_sta_state new_state)
1632
{
1633
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
1634
int tdls_count = 0;
1635
int ret;
1636
1637
if (old_state == IEEE80211_STA_NOTEXIST &&
1638
new_state == IEEE80211_STA_NONE) {
1639
if (sta->tdls) {
1640
if (vif->p2p || hweight8(mld->used_phy_ids) != 1)
1641
return -EBUSY;
1642
1643
tdls_count = iwl_mld_tdls_sta_count(mld);
1644
if (tdls_count >= IWL_TDLS_STA_COUNT)
1645
return -EBUSY;
1646
}
1647
1648
ret = iwl_mld_add_sta(mld, sta, vif, STATION_TYPE_PEER);
1649
if (ret)
1650
return ret;
1651
1652
/* just added first TDLS STA, so disable PM */
1653
if (sta->tdls && tdls_count == 0)
1654
iwl_mld_update_mac_power(mld, vif, false);
1655
1656
if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
1657
mld_vif->ap_sta = sta;
1658
1659
/* Initialize TLC here already - this really tells
1660
* the firmware only what the supported legacy rates are
1661
* (may be) since it's initialized already from what the
1662
* AP advertised in the beacon/probe response. This will
1663
* allow the firmware to send auth/assoc frames with one
1664
* of the supported rates already, rather than having to
1665
* use a mandatory rate.
1666
* If we're the AP, we'll just assume mandatory rates at
1667
* this point, but we know nothing about the STA anyway.
1668
*/
1669
iwl_mld_config_tlc(mld, vif, sta);
1670
1671
return ret;
1672
} else if (old_state == IEEE80211_STA_NONE &&
1673
new_state == IEEE80211_STA_AUTH) {
1674
iwl_mld_set_uapsd(mld, vif);
1675
return 0;
1676
} else if (old_state == IEEE80211_STA_AUTH &&
1677
new_state == IEEE80211_STA_ASSOC) {
1678
ret = iwl_mld_update_all_link_stations(mld, sta);
1679
1680
if (vif->type == NL80211_IFTYPE_STATION)
1681
iwl_mld_link_set_2mhz_block(mld, vif, sta);
1682
/* Now the link_sta's capabilities are set, update the FW */
1683
iwl_mld_config_tlc(mld, vif, sta);
1684
1685
if (vif->type == NL80211_IFTYPE_AP) {
1686
/* Update MAC_CFG_FILTER_ACCEPT_BEACON if at least
1687
* one sta is associated
1688
*/
1689
if (++mld_vif->num_associated_stas == 1)
1690
ret = iwl_mld_mac_fw_action(mld, vif,
1691
FW_CTXT_ACTION_MODIFY);
1692
}
1693
1694
return ret;
1695
} else if (old_state == IEEE80211_STA_ASSOC &&
1696
new_state == IEEE80211_STA_AUTHORIZED) {
1697
ret = 0;
1698
1699
if (!sta->tdls) {
1700
mld_vif->authorized = true;
1701
1702
/* Ensure any block due to a non-BSS link is synced */
1703
iwl_mld_emlsr_check_non_bss_block(mld, 0);
1704
1705
/* Block EMLSR until a certain throughput it reached */
1706
if (!mld->fw_status.in_hw_restart &&
1707
IWL_MLD_ENTER_EMLSR_TPT_THRESH > 0)
1708
iwl_mld_block_emlsr(mld_vif->mld, vif,
1709
IWL_MLD_EMLSR_BLOCKED_TPT,
1710
0);
1711
1712
/* clear COEX_HIGH_PRIORITY_ENABLE */
1713
ret = iwl_mld_mac_fw_action(mld, vif,
1714
FW_CTXT_ACTION_MODIFY);
1715
if (ret)
1716
return ret;
1717
iwl_mld_smps_workaround(mld, vif, vif->cfg.ps);
1718
}
1719
1720
/* MFP is set by default before the station is authorized.
1721
* Clear it here in case it's not used.
1722
*/
1723
if (!sta->mfp)
1724
ret = iwl_mld_update_all_link_stations(mld, sta);
1725
1726
/* We can use wide bandwidth now, not only 20 MHz */
1727
iwl_mld_config_tlc(mld, vif, sta);
1728
1729
return ret;
1730
} else {
1731
return -EINVAL;
1732
}
1733
}
1734
1735
static int iwl_mld_move_sta_state_down(struct iwl_mld *mld,
1736
struct ieee80211_vif *vif,
1737
struct ieee80211_sta *sta,
1738
enum ieee80211_sta_state old_state,
1739
enum ieee80211_sta_state new_state)
1740
{
1741
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
1742
1743
if (old_state == IEEE80211_STA_AUTHORIZED &&
1744
new_state == IEEE80211_STA_ASSOC) {
1745
if (!sta->tdls) {
1746
mld_vif->authorized = false;
1747
1748
memset(&mld_vif->emlsr.zeroed_on_not_authorized, 0,
1749
sizeof(mld_vif->emlsr.zeroed_on_not_authorized));
1750
1751
wiphy_delayed_work_cancel(mld->wiphy,
1752
&mld_vif->emlsr.prevent_done_wk);
1753
wiphy_delayed_work_cancel(mld->wiphy,
1754
&mld_vif->emlsr.tmp_non_bss_done_wk);
1755
wiphy_work_cancel(mld->wiphy, &mld_vif->emlsr.unblock_tpt_wk);
1756
wiphy_delayed_work_cancel(mld->wiphy,
1757
&mld_vif->emlsr.check_tpt_wk);
1758
1759
iwl_mld_reset_cca_40mhz_workaround(mld, vif);
1760
iwl_mld_smps_workaround(mld, vif, true);
1761
}
1762
1763
/* once we move into assoc state, need to update the FW to
1764
* stop using wide bandwidth
1765
*/
1766
iwl_mld_config_tlc(mld, vif, sta);
1767
} else if (old_state == IEEE80211_STA_ASSOC &&
1768
new_state == IEEE80211_STA_AUTH) {
1769
if (vif->type == NL80211_IFTYPE_AP &&
1770
!WARN_ON(!mld_vif->num_associated_stas)) {
1771
/* Update MAC_CFG_FILTER_ACCEPT_BEACON if the last sta
1772
* is disassociating
1773
*/
1774
if (--mld_vif->num_associated_stas == 0)
1775
iwl_mld_mac_fw_action(mld, vif,
1776
FW_CTXT_ACTION_MODIFY);
1777
}
1778
} else if (old_state == IEEE80211_STA_AUTH &&
1779
new_state == IEEE80211_STA_NONE) {
1780
/* nothing */
1781
} else if (old_state == IEEE80211_STA_NONE &&
1782
new_state == IEEE80211_STA_NOTEXIST) {
1783
iwl_mld_remove_sta(mld, sta);
1784
1785
if (sta->tdls && iwl_mld_tdls_sta_count(mld) == 0) {
1786
/* just removed last TDLS STA, so enable PM */
1787
iwl_mld_update_mac_power(mld, vif, false);
1788
}
1789
} else {
1790
return -EINVAL;
1791
}
1792
return 0;
1793
}
1794
1795
static int iwl_mld_mac80211_sta_state(struct ieee80211_hw *hw,
1796
struct ieee80211_vif *vif,
1797
struct ieee80211_sta *sta,
1798
enum ieee80211_sta_state old_state,
1799
enum ieee80211_sta_state new_state)
1800
{
1801
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1802
struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta);
1803
1804
IWL_DEBUG_MAC80211(mld, "station %pM state change %d->%d\n",
1805
sta->addr, old_state, new_state);
1806
1807
mld_sta->sta_state = new_state;
1808
1809
if (old_state < new_state)
1810
return iwl_mld_move_sta_state_up(mld, vif, sta, old_state,
1811
new_state);
1812
else
1813
return iwl_mld_move_sta_state_down(mld, vif, sta, old_state,
1814
new_state);
1815
}
1816
1817
static void iwl_mld_mac80211_flush(struct ieee80211_hw *hw,
1818
struct ieee80211_vif *vif,
1819
u32 queues, bool drop)
1820
{
1821
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1822
1823
/* Make sure we're done with the deferred traffic before flushing */
1824
iwl_mld_add_txq_list(mld);
1825
1826
for (int i = 0; i < mld->fw->ucode_capa.num_stations; i++) {
1827
struct ieee80211_link_sta *link_sta =
1828
wiphy_dereference(mld->wiphy,
1829
mld->fw_id_to_link_sta[i]);
1830
1831
if (IS_ERR_OR_NULL(link_sta))
1832
continue;
1833
1834
/* Check that the sta belongs to the given vif */
1835
if (vif && vif != iwl_mld_sta_from_mac80211(link_sta->sta)->vif)
1836
continue;
1837
1838
if (drop)
1839
iwl_mld_flush_sta_txqs(mld, link_sta->sta);
1840
else
1841
iwl_mld_wait_sta_txqs_empty(mld, link_sta->sta);
1842
}
1843
}
1844
1845
static void iwl_mld_mac80211_flush_sta(struct ieee80211_hw *hw,
1846
struct ieee80211_vif *vif,
1847
struct ieee80211_sta *sta)
1848
{
1849
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1850
1851
iwl_mld_flush_sta_txqs(mld, sta);
1852
}
1853
1854
static int
1855
iwl_mld_mac80211_ampdu_action(struct ieee80211_hw *hw,
1856
struct ieee80211_vif *vif,
1857
struct ieee80211_ampdu_params *params)
1858
{
1859
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1860
struct ieee80211_sta *sta = params->sta;
1861
enum ieee80211_ampdu_mlme_action action = params->action;
1862
u16 tid = params->tid;
1863
u16 ssn = params->ssn;
1864
u16 buf_size = params->buf_size;
1865
u16 timeout = params->timeout;
1866
int ret;
1867
1868
IWL_DEBUG_HT(mld, "A-MPDU action on addr %pM tid: %d action: %d\n",
1869
sta->addr, tid, action);
1870
1871
switch (action) {
1872
case IEEE80211_AMPDU_RX_START:
1873
if (!iwl_enable_rx_ampdu()) {
1874
ret = -EINVAL;
1875
break;
1876
}
1877
ret = iwl_mld_ampdu_rx_start(mld, sta, tid, ssn, buf_size,
1878
timeout);
1879
break;
1880
case IEEE80211_AMPDU_RX_STOP:
1881
ret = iwl_mld_ampdu_rx_stop(mld, sta, tid);
1882
break;
1883
default:
1884
/* The mac80211 TX_AMPDU_SETUP_IN_HW flag is set for all
1885
* devices, since all support TX A-MPDU offload in hardware.
1886
* Therefore, no TX action should be requested here.
1887
*/
1888
WARN_ON_ONCE(1);
1889
return -EINVAL;
1890
}
1891
1892
return ret;
1893
}
1894
1895
static bool iwl_mld_can_hw_csum(struct sk_buff *skb)
1896
{
1897
u8 protocol = ip_hdr(skb)->protocol;
1898
1899
return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
1900
}
1901
1902
static bool iwl_mld_mac80211_can_aggregate(struct ieee80211_hw *hw,
1903
struct sk_buff *head,
1904
struct sk_buff *skb)
1905
{
1906
if (!IS_ENABLED(CONFIG_INET))
1907
return false;
1908
1909
/* For now don't aggregate IPv6 in AMSDU */
1910
if (skb->protocol != htons(ETH_P_IP))
1911
return false;
1912
1913
/* Allow aggregation only if both frames have the same HW csum offload
1914
* capability, ensuring consistent HW or SW csum handling in A-MSDU.
1915
*/
1916
return iwl_mld_can_hw_csum(skb) == iwl_mld_can_hw_csum(head);
1917
}
1918
1919
static void iwl_mld_mac80211_sync_rx_queues(struct ieee80211_hw *hw)
1920
{
1921
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1922
1923
iwl_mld_sync_rx_queues(mld, IWL_MLD_RXQ_EMPTY, NULL, 0);
1924
}
1925
1926
static void iwl_mld_sta_rc_update(struct ieee80211_hw *hw,
1927
struct ieee80211_vif *vif,
1928
struct ieee80211_link_sta *link_sta,
1929
u32 changed)
1930
{
1931
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1932
1933
if (changed & (IEEE80211_RC_BW_CHANGED |
1934
IEEE80211_RC_SUPP_RATES_CHANGED |
1935
IEEE80211_RC_NSS_CHANGED)) {
1936
struct ieee80211_bss_conf *link =
1937
link_conf_dereference_check(vif, link_sta->link_id);
1938
1939
if (WARN_ON(!link))
1940
return;
1941
1942
iwl_mld_config_tlc_link(mld, vif, link, link_sta);
1943
}
1944
}
1945
1946
#ifdef CONFIG_PM_SLEEP
1947
static void iwl_mld_set_wakeup(struct ieee80211_hw *hw, bool enabled)
1948
{
1949
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1950
1951
device_set_wakeup_enable(mld->trans->dev, enabled);
1952
}
1953
1954
/* Returns 0 on success. 1 if failed to suspend with wowlan:
1955
* If the circumstances didn't satisfy the conditions for suspension
1956
* with wowlan, mac80211 would use the no_wowlan flow.
1957
* If an error had occurred we update the trans status and state here
1958
* and the result will be stopping the FW.
1959
*/
1960
static int
1961
iwl_mld_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
1962
{
1963
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1964
int ret;
1965
1966
iwl_fw_runtime_suspend(&mld->fwrt);
1967
1968
ret = iwl_mld_wowlan_suspend(mld, wowlan);
1969
if (ret) {
1970
if (ret < 0) {
1971
mld->trans->state = IWL_TRANS_NO_FW;
1972
set_bit(STATUS_FW_ERROR, &mld->trans->status);
1973
}
1974
return 1;
1975
}
1976
1977
if (iwl_mld_no_wowlan_suspend(mld))
1978
return 1;
1979
1980
return 0;
1981
}
1982
1983
static int iwl_mld_resume(struct ieee80211_hw *hw)
1984
{
1985
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1986
int ret;
1987
1988
ret = iwl_mld_wowlan_resume(mld);
1989
if (ret)
1990
return ret;
1991
1992
iwl_fw_runtime_resume(&mld->fwrt);
1993
1994
iwl_mld_low_latency_restart(mld);
1995
1996
return 0;
1997
}
1998
#endif
1999
2000
static int iwl_mld_alloc_ptk_pn(struct iwl_mld *mld,
2001
struct iwl_mld_sta *mld_sta,
2002
struct ieee80211_key_conf *key,
2003
struct iwl_mld_ptk_pn **ptk_pn)
2004
{
2005
u8 num_rx_queues = mld->trans->info.num_rxqs;
2006
int keyidx = key->keyidx;
2007
struct ieee80211_key_seq seq;
2008
2009
if (WARN_ON(keyidx >= ARRAY_SIZE(mld_sta->ptk_pn)))
2010
return -EINVAL;
2011
2012
WARN_ON(rcu_access_pointer(mld_sta->ptk_pn[keyidx]));
2013
*ptk_pn = kzalloc(struct_size(*ptk_pn, q, num_rx_queues),
2014
GFP_KERNEL);
2015
if (!*ptk_pn)
2016
return -ENOMEM;
2017
2018
for (u8 tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2019
ieee80211_get_key_rx_seq(key, tid, &seq);
2020
for (u8 q = 0; q < num_rx_queues; q++)
2021
memcpy((*ptk_pn)->q[q].pn[tid], seq.ccmp.pn,
2022
IEEE80211_CCMP_PN_LEN);
2023
}
2024
2025
rcu_assign_pointer(mld_sta->ptk_pn[keyidx], *ptk_pn);
2026
2027
return 0;
2028
}
2029
2030
static int iwl_mld_set_key_add(struct iwl_mld *mld,
2031
struct ieee80211_vif *vif,
2032
struct ieee80211_sta *sta,
2033
struct ieee80211_key_conf *key)
2034
{
2035
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2036
struct iwl_mld_sta *mld_sta =
2037
sta ? iwl_mld_sta_from_mac80211(sta) : NULL;
2038
struct iwl_mld_ptk_pn *ptk_pn = NULL;
2039
int keyidx = key->keyidx;
2040
int ret;
2041
2042
/* Will be set to 0 if added successfully */
2043
key->hw_key_idx = STA_KEY_IDX_INVALID;
2044
2045
switch (key->cipher) {
2046
case WLAN_CIPHER_SUITE_WEP40:
2047
case WLAN_CIPHER_SUITE_WEP104:
2048
IWL_DEBUG_MAC80211(mld, "Use SW encryption for WEP\n");
2049
return -EOPNOTSUPP;
2050
case WLAN_CIPHER_SUITE_TKIP:
2051
if (vif->type == NL80211_IFTYPE_STATION) {
2052
key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
2053
break;
2054
}
2055
IWL_DEBUG_MAC80211(mld, "Use SW encryption for TKIP\n");
2056
return -EOPNOTSUPP;
2057
case WLAN_CIPHER_SUITE_CCMP:
2058
case WLAN_CIPHER_SUITE_GCMP:
2059
case WLAN_CIPHER_SUITE_GCMP_256:
2060
case WLAN_CIPHER_SUITE_AES_CMAC:
2061
case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2062
case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2063
break;
2064
default:
2065
return -EOPNOTSUPP;
2066
}
2067
2068
if (vif->type == NL80211_IFTYPE_STATION &&
2069
(keyidx == 6 || keyidx == 7))
2070
rcu_assign_pointer(mld_vif->bigtks[keyidx - 6], key);
2071
2072
/* After exiting from RFKILL, hostapd configures GTK/ITGK before the
2073
* AP is started, but those keys can't be sent to the FW before the
2074
* MCAST/BCAST STAs are added to it (which happens upon AP start).
2075
* Store it here to be sent later when the AP is started.
2076
*/
2077
if ((vif->type == NL80211_IFTYPE_ADHOC ||
2078
vif->type == NL80211_IFTYPE_AP) && !sta &&
2079
!mld_vif->ap_ibss_active)
2080
return iwl_mld_store_ap_early_key(mld, key, mld_vif);
2081
2082
if (!mld->fw_status.in_hw_restart && mld_sta &&
2083
key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
2084
(key->cipher == WLAN_CIPHER_SUITE_CCMP ||
2085
key->cipher == WLAN_CIPHER_SUITE_GCMP ||
2086
key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
2087
ret = iwl_mld_alloc_ptk_pn(mld, mld_sta, key, &ptk_pn);
2088
if (ret)
2089
return ret;
2090
}
2091
2092
IWL_DEBUG_MAC80211(mld, "set hwcrypto key (sta:%pM, id:%d)\n",
2093
sta ? sta->addr : NULL, keyidx);
2094
2095
ret = iwl_mld_add_key(mld, vif, sta, key);
2096
if (ret) {
2097
IWL_WARN(mld, "set key failed (%d)\n", ret);
2098
if (ptk_pn) {
2099
RCU_INIT_POINTER(mld_sta->ptk_pn[keyidx], NULL);
2100
kfree(ptk_pn);
2101
}
2102
2103
return -EOPNOTSUPP;
2104
}
2105
2106
return 0;
2107
}
2108
2109
static void iwl_mld_set_key_remove(struct iwl_mld *mld,
2110
struct ieee80211_vif *vif,
2111
struct ieee80211_sta *sta,
2112
struct ieee80211_key_conf *key)
2113
{
2114
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2115
struct iwl_mld_sta *mld_sta =
2116
sta ? iwl_mld_sta_from_mac80211(sta) : NULL;
2117
int keyidx = key->keyidx;
2118
2119
if (vif->type == NL80211_IFTYPE_STATION &&
2120
(keyidx == 6 || keyidx == 7))
2121
RCU_INIT_POINTER(mld_vif->bigtks[keyidx - 6], NULL);
2122
2123
if (mld_sta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
2124
(key->cipher == WLAN_CIPHER_SUITE_CCMP ||
2125
key->cipher == WLAN_CIPHER_SUITE_GCMP ||
2126
key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
2127
struct iwl_mld_ptk_pn *ptk_pn;
2128
2129
if (WARN_ON(keyidx >= ARRAY_SIZE(mld_sta->ptk_pn)))
2130
return;
2131
2132
ptk_pn = wiphy_dereference(mld->wiphy,
2133
mld_sta->ptk_pn[keyidx]);
2134
RCU_INIT_POINTER(mld_sta->ptk_pn[keyidx], NULL);
2135
if (!WARN_ON(!ptk_pn))
2136
kfree_rcu(ptk_pn, rcu_head);
2137
}
2138
2139
/* if this key was stored to be added later to the FW - free it here */
2140
if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
2141
iwl_mld_free_ap_early_key(mld, key, mld_vif);
2142
2143
/* We already removed it */
2144
if (key->hw_key_idx == STA_KEY_IDX_INVALID)
2145
return;
2146
2147
IWL_DEBUG_MAC80211(mld, "disable hwcrypto key\n");
2148
2149
iwl_mld_remove_key(mld, vif, sta, key);
2150
}
2151
2152
static int iwl_mld_mac80211_set_key(struct ieee80211_hw *hw,
2153
enum set_key_cmd cmd,
2154
struct ieee80211_vif *vif,
2155
struct ieee80211_sta *sta,
2156
struct ieee80211_key_conf *key)
2157
{
2158
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2159
int ret;
2160
2161
switch (cmd) {
2162
case SET_KEY:
2163
ret = iwl_mld_set_key_add(mld, vif, sta, key);
2164
if (ret)
2165
ret = -EOPNOTSUPP;
2166
break;
2167
case DISABLE_KEY:
2168
iwl_mld_set_key_remove(mld, vif, sta, key);
2169
ret = 0;
2170
break;
2171
default:
2172
ret = -EINVAL;
2173
break;
2174
}
2175
2176
return ret;
2177
}
2178
2179
static int
2180
iwl_mld_pre_channel_switch(struct ieee80211_hw *hw,
2181
struct ieee80211_vif *vif,
2182
struct ieee80211_channel_switch *chsw)
2183
{
2184
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2185
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2186
struct iwl_mld_link *mld_link =
2187
iwl_mld_link_dereference_check(mld_vif, chsw->link_id);
2188
u8 primary;
2189
int selected;
2190
2191
lockdep_assert_wiphy(mld->wiphy);
2192
2193
if (WARN_ON(!mld_link))
2194
return -EINVAL;
2195
2196
IWL_DEBUG_MAC80211(mld, "pre CSA to freq %d\n",
2197
chsw->chandef.center_freq1);
2198
2199
if (!iwl_mld_emlsr_active(vif))
2200
return 0;
2201
2202
primary = iwl_mld_get_primary_link(vif);
2203
2204
/* stay on the primary link unless it is undergoing a CSA with quiet */
2205
if (chsw->link_id == primary && chsw->block_tx)
2206
selected = iwl_mld_get_other_link(vif, primary);
2207
else
2208
selected = primary;
2209
2210
/* Remember to tell the firmware that this link can't tx
2211
* Note that this logic seems to be unrelated to emlsr, but it
2212
* really is needed only when emlsr is active. When we have a
2213
* single link, the firmware will handle all this on its own.
2214
* In multi-link scenarios, we can learn about the CSA from
2215
* another link and this logic is too complex for the firmware
2216
* to track.
2217
* Since we want to de-activate the link that got a CSA with mode=1,
2218
* we need to tell the firmware not to send any frame on that link
2219
* as the firmware may not be aware that link is under a CSA
2220
* with mode=1 (no Tx allowed).
2221
*/
2222
mld_link->silent_deactivation = chsw->block_tx;
2223
iwl_mld_exit_emlsr(mld, vif, IWL_MLD_EMLSR_EXIT_CSA, selected);
2224
2225
return 0;
2226
}
2227
2228
static void
2229
iwl_mld_channel_switch(struct ieee80211_hw *hw,
2230
struct ieee80211_vif *vif,
2231
struct ieee80211_channel_switch *chsw)
2232
{
2233
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2234
2235
/* By implementing this operation, we prevent mac80211 from
2236
* starting its own channel switch timer, so that we can call
2237
* ieee80211_chswitch_done() ourselves at the right time
2238
* (Upon receiving the channel_switch_start notification from the fw)
2239
*/
2240
IWL_DEBUG_MAC80211(mld,
2241
"dummy channel switch op\n");
2242
}
2243
2244
static int
2245
iwl_mld_post_channel_switch(struct ieee80211_hw *hw,
2246
struct ieee80211_vif *vif,
2247
struct ieee80211_bss_conf *link_conf)
2248
{
2249
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2250
struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link_conf);
2251
2252
lockdep_assert_wiphy(mld->wiphy);
2253
2254
WARN_ON(mld_link->silent_deactivation);
2255
2256
return 0;
2257
}
2258
2259
static void
2260
iwl_mld_abort_channel_switch(struct ieee80211_hw *hw,
2261
struct ieee80211_vif *vif,
2262
struct ieee80211_bss_conf *link_conf)
2263
{
2264
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2265
struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link_conf);
2266
2267
IWL_DEBUG_MAC80211(mld,
2268
"abort channel switch op\n");
2269
mld_link->silent_deactivation = false;
2270
}
2271
2272
static int
2273
iwl_mld_switch_vif_chanctx_swap(struct ieee80211_hw *hw,
2274
struct ieee80211_vif_chanctx_switch *vifs)
2275
{
2276
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2277
int ret;
2278
2279
iwl_mld_unassign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2280
vifs[0].old_ctx);
2281
iwl_mld_remove_chanctx(hw, vifs[0].old_ctx);
2282
2283
ret = iwl_mld_add_chanctx(hw, vifs[0].new_ctx);
2284
if (ret) {
2285
IWL_ERR(mld, "failed to add new_ctx during channel switch\n");
2286
goto out_reassign;
2287
}
2288
2289
ret = iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2290
vifs[0].new_ctx);
2291
if (ret) {
2292
IWL_ERR(mld,
2293
"failed to assign new_ctx during channel switch\n");
2294
goto out_remove;
2295
}
2296
2297
return 0;
2298
2299
out_remove:
2300
iwl_mld_remove_chanctx(hw, vifs[0].new_ctx);
2301
out_reassign:
2302
if (iwl_mld_add_chanctx(hw, vifs[0].old_ctx)) {
2303
IWL_ERR(mld, "failed to add old_ctx after failure\n");
2304
return ret;
2305
}
2306
2307
if (iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2308
vifs[0].old_ctx))
2309
IWL_ERR(mld, "failed to reassign old_ctx after failure\n");
2310
2311
return ret;
2312
}
2313
2314
static int
2315
iwl_mld_switch_vif_chanctx_reassign(struct ieee80211_hw *hw,
2316
struct ieee80211_vif_chanctx_switch *vifs)
2317
{
2318
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2319
int ret;
2320
2321
iwl_mld_unassign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2322
vifs[0].old_ctx);
2323
ret = iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2324
vifs[0].new_ctx);
2325
if (ret) {
2326
IWL_ERR(mld,
2327
"failed to assign new_ctx during channel switch\n");
2328
goto out_reassign;
2329
}
2330
2331
return 0;
2332
2333
out_reassign:
2334
if (iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2335
vifs[0].old_ctx))
2336
IWL_ERR(mld, "failed to reassign old_ctx after failure\n");
2337
2338
return ret;
2339
}
2340
2341
static int
2342
iwl_mld_switch_vif_chanctx(struct ieee80211_hw *hw,
2343
struct ieee80211_vif_chanctx_switch *vifs,
2344
int n_vifs,
2345
enum ieee80211_chanctx_switch_mode mode)
2346
{
2347
int ret;
2348
2349
/* we only support a single-vif right now */
2350
if (n_vifs > 1)
2351
return -EOPNOTSUPP;
2352
2353
switch (mode) {
2354
case CHANCTX_SWMODE_SWAP_CONTEXTS:
2355
ret = iwl_mld_switch_vif_chanctx_swap(hw, vifs);
2356
break;
2357
case CHANCTX_SWMODE_REASSIGN_VIF:
2358
ret = iwl_mld_switch_vif_chanctx_reassign(hw, vifs);
2359
break;
2360
default:
2361
ret = -EOPNOTSUPP;
2362
break;
2363
}
2364
2365
return ret;
2366
}
2367
2368
static void iwl_mld_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2369
struct ieee80211_vif *vif,
2370
struct ieee80211_sta *sta)
2371
{
2372
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2373
struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta);
2374
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2375
struct iwl_mld_link_sta *mld_link_sta;
2376
u8 link_id;
2377
2378
lockdep_assert_wiphy(mld->wiphy);
2379
2380
/* This is called before mac80211 does RCU synchronisation,
2381
* so here we already invalidate our internal RCU-protected
2382
* station pointer. The rest of the code will thus no longer
2383
* be able to find the station this way, and we don't rely
2384
* on further RCU synchronisation after the sta_state()
2385
* callback deleted the station.
2386
*/
2387
for_each_mld_link_sta(mld_sta, mld_link_sta, link_id)
2388
RCU_INIT_POINTER(mld->fw_id_to_link_sta[mld_link_sta->fw_id],
2389
NULL);
2390
2391
if (sta == mld_vif->ap_sta)
2392
mld_vif->ap_sta = NULL;
2393
}
2394
2395
static void
2396
iwl_mld_mac80211_mgd_protect_tdls_discover(struct ieee80211_hw *hw,
2397
struct ieee80211_vif *vif,
2398
unsigned int link_id)
2399
{
2400
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2401
struct ieee80211_bss_conf *link_conf;
2402
u32 duration;
2403
int ret;
2404
2405
link_conf = wiphy_dereference(hw->wiphy, vif->link_conf[link_id]);
2406
if (WARN_ON_ONCE(!link_conf))
2407
return;
2408
2409
/* Protect the session to hear the TDLS setup response on the channel */
2410
2411
duration = 2 * link_conf->dtim_period * link_conf->beacon_int;
2412
2413
ret = iwl_mld_start_session_protection(mld, vif, duration, duration,
2414
link_id, HZ / 5);
2415
if (ret)
2416
IWL_ERR(mld,
2417
"Failed to start session protection for TDLS: %d\n",
2418
ret);
2419
}
2420
2421
static bool iwl_mld_can_activate_links(struct ieee80211_hw *hw,
2422
struct ieee80211_vif *vif,
2423
u16 desired_links)
2424
{
2425
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2426
int n_links = hweight16(desired_links);
2427
2428
/* Check if HW supports the wanted number of links */
2429
return n_links <= iwl_mld_max_active_links(mld, vif);
2430
}
2431
2432
static int
2433
iwl_mld_change_vif_links(struct ieee80211_hw *hw,
2434
struct ieee80211_vif *vif,
2435
u16 old_links, u16 new_links,
2436
struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
2437
{
2438
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2439
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2440
struct ieee80211_bss_conf *link_conf;
2441
u16 removed = old_links & ~new_links;
2442
u16 added = new_links & ~old_links;
2443
int err;
2444
2445
lockdep_assert_wiphy(mld->wiphy);
2446
2447
/*
2448
* No bits designate non-MLO mode. We can handle MLO exit/enter by
2449
* simply mapping that to link ID zero internally.
2450
* Note that mac80211 does such a non-MLO to MLO switch during restart
2451
* if it was in MLO before. In that case, we do not have a link to
2452
* remove.
2453
*/
2454
if (old_links == 0 && !mld->fw_status.in_hw_restart)
2455
removed |= BIT(0);
2456
2457
if (new_links == 0)
2458
added |= BIT(0);
2459
2460
for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
2461
if (removed & BIT(i) && !WARN_ON(!old[i]))
2462
iwl_mld_remove_link(mld, old[i]);
2463
}
2464
2465
for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
2466
if (added & BIT(i)) {
2467
link_conf = link_conf_dereference_protected(vif, i);
2468
if (!link_conf) {
2469
err = -EINVAL;
2470
goto remove_added_links;
2471
}
2472
2473
err = iwl_mld_add_link(mld, link_conf);
2474
if (err)
2475
goto remove_added_links;
2476
}
2477
}
2478
2479
/*
2480
* Ensure we always have a valid primary_link. When using multiple
2481
* links the proper value is set in assign_vif_chanctx.
2482
*/
2483
mld_vif->emlsr.primary = new_links ? __ffs(new_links) : 0;
2484
2485
/*
2486
* Special MLO restart case. We did not have a link when the interface
2487
* was added, so do the power configuration now.
2488
*/
2489
if (old_links == 0 && mld->fw_status.in_hw_restart)
2490
iwl_mld_update_mac_power(mld, vif, false);
2491
2492
return 0;
2493
2494
remove_added_links:
2495
for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
2496
if (!(added & BIT(i)))
2497
continue;
2498
2499
link_conf = link_conf_dereference_protected(vif, i);
2500
if (!link_conf || !iwl_mld_link_from_mac80211(link_conf))
2501
continue;
2502
2503
iwl_mld_remove_link(mld, link_conf);
2504
}
2505
2506
if (WARN_ON(!iwl_mld_error_before_recovery(mld)))
2507
return err;
2508
2509
/* reconfig will fix us anyway */
2510
return 0;
2511
}
2512
2513
static int iwl_mld_change_sta_links(struct ieee80211_hw *hw,
2514
struct ieee80211_vif *vif,
2515
struct ieee80211_sta *sta,
2516
u16 old_links, u16 new_links)
2517
{
2518
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2519
2520
return iwl_mld_update_link_stas(mld, vif, sta, old_links, new_links);
2521
}
2522
2523
static int iwl_mld_mac80211_join_ibss(struct ieee80211_hw *hw,
2524
struct ieee80211_vif *vif)
2525
{
2526
return iwl_mld_start_ap_ibss(hw, vif, &vif->bss_conf);
2527
}
2528
2529
static void iwl_mld_mac80211_leave_ibss(struct ieee80211_hw *hw,
2530
struct ieee80211_vif *vif)
2531
{
2532
return iwl_mld_stop_ap_ibss(hw, vif, &vif->bss_conf);
2533
}
2534
2535
static int iwl_mld_mac80211_tx_last_beacon(struct ieee80211_hw *hw)
2536
{
2537
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2538
2539
return mld->ibss_manager;
2540
}
2541
2542
static void iwl_mld_prep_add_interface(struct ieee80211_hw *hw,
2543
enum nl80211_iftype type)
2544
{
2545
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2546
2547
IWL_DEBUG_MAC80211(mld, "prep_add_interface: type=%u\n", type);
2548
2549
if (!(type == NL80211_IFTYPE_AP ||
2550
type == NL80211_IFTYPE_P2P_GO ||
2551
type == NL80211_IFTYPE_P2P_CLIENT))
2552
return;
2553
2554
iwl_mld_emlsr_block_tmp_non_bss(mld);
2555
}
2556
2557
static int iwl_mld_set_hw_timestamp(struct ieee80211_hw *hw,
2558
struct ieee80211_vif *vif,
2559
struct cfg80211_set_hw_timestamp *hwts)
2560
{
2561
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2562
u32 protocols = 0;
2563
2564
/* HW timestamping is only supported for a specific station */
2565
if (!hwts->macaddr)
2566
return -EOPNOTSUPP;
2567
2568
if (hwts->enable)
2569
protocols =
2570
IWL_TIME_SYNC_PROTOCOL_TM | IWL_TIME_SYNC_PROTOCOL_FTM;
2571
2572
return iwl_mld_time_sync_config(mld, hwts->macaddr, protocols);
2573
}
2574
2575
static int iwl_mld_start_pmsr(struct ieee80211_hw *hw,
2576
struct ieee80211_vif *vif,
2577
struct cfg80211_pmsr_request *request)
2578
{
2579
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2580
2581
return iwl_mld_ftm_start(mld, vif, request);
2582
}
2583
2584
static enum ieee80211_neg_ttlm_res
2585
iwl_mld_can_neg_ttlm(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2586
struct ieee80211_neg_ttlm *neg_ttlm)
2587
{
2588
u16 map;
2589
2590
/* Verify all TIDs are mapped to the same links set */
2591
map = neg_ttlm->downlink[0];
2592
for (int i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) {
2593
if (neg_ttlm->downlink[i] != neg_ttlm->uplink[i] ||
2594
neg_ttlm->uplink[i] != map)
2595
return NEG_TTLM_RES_REJECT;
2596
}
2597
2598
return NEG_TTLM_RES_ACCEPT;
2599
}
2600
2601
const struct ieee80211_ops iwl_mld_hw_ops = {
2602
.tx = iwl_mld_mac80211_tx,
2603
.start = iwl_mld_mac80211_start,
2604
.stop = iwl_mld_mac80211_stop,
2605
.config = iwl_mld_mac80211_config,
2606
.add_interface = iwl_mld_mac80211_add_interface,
2607
.remove_interface = iwl_mld_mac80211_remove_interface,
2608
.conf_tx = iwl_mld_mac80211_conf_tx,
2609
.prepare_multicast = iwl_mld_mac80211_prepare_multicast,
2610
.configure_filter = iwl_mld_mac80211_configure_filter,
2611
.reconfig_complete = iwl_mld_mac80211_reconfig_complete,
2612
.wake_tx_queue = iwl_mld_mac80211_wake_tx_queue,
2613
.add_chanctx = iwl_mld_add_chanctx,
2614
.remove_chanctx = iwl_mld_remove_chanctx,
2615
.change_chanctx = iwl_mld_change_chanctx,
2616
.assign_vif_chanctx = iwl_mld_assign_vif_chanctx,
2617
.unassign_vif_chanctx = iwl_mld_unassign_vif_chanctx,
2618
.set_rts_threshold = iwl_mld_mac80211_set_rts_threshold,
2619
.link_info_changed = iwl_mld_mac80211_link_info_changed,
2620
.vif_cfg_changed = iwl_mld_mac80211_vif_cfg_changed,
2621
.set_key = iwl_mld_mac80211_set_key,
2622
.hw_scan = iwl_mld_mac80211_hw_scan,
2623
.cancel_hw_scan = iwl_mld_mac80211_cancel_hw_scan,
2624
.sched_scan_start = iwl_mld_mac80211_sched_scan_start,
2625
.sched_scan_stop = iwl_mld_mac80211_sched_scan_stop,
2626
.mgd_prepare_tx = iwl_mld_mac80211_mgd_prepare_tx,
2627
.mgd_complete_tx = iwl_mld_mac_mgd_complete_tx,
2628
.sta_state = iwl_mld_mac80211_sta_state,
2629
.sta_statistics = iwl_mld_mac80211_sta_statistics,
2630
.get_survey = iwl_mld_mac80211_get_survey,
2631
.flush = iwl_mld_mac80211_flush,
2632
.flush_sta = iwl_mld_mac80211_flush_sta,
2633
.ampdu_action = iwl_mld_mac80211_ampdu_action,
2634
.can_aggregate_in_amsdu = iwl_mld_mac80211_can_aggregate,
2635
.sync_rx_queues = iwl_mld_mac80211_sync_rx_queues,
2636
.link_sta_rc_update = iwl_mld_sta_rc_update,
2637
.start_ap = iwl_mld_start_ap_ibss,
2638
.stop_ap = iwl_mld_stop_ap_ibss,
2639
.pre_channel_switch = iwl_mld_pre_channel_switch,
2640
.channel_switch = iwl_mld_channel_switch,
2641
.post_channel_switch = iwl_mld_post_channel_switch,
2642
.abort_channel_switch = iwl_mld_abort_channel_switch,
2643
.switch_vif_chanctx = iwl_mld_switch_vif_chanctx,
2644
.sta_pre_rcu_remove = iwl_mld_sta_pre_rcu_remove,
2645
.remain_on_channel = iwl_mld_start_roc,
2646
.cancel_remain_on_channel = iwl_mld_cancel_roc,
2647
.can_activate_links = iwl_mld_can_activate_links,
2648
.change_vif_links = iwl_mld_change_vif_links,
2649
.change_sta_links = iwl_mld_change_sta_links,
2650
#ifdef CONFIG_PM_SLEEP
2651
.suspend = iwl_mld_suspend,
2652
.resume = iwl_mld_resume,
2653
.set_wakeup = iwl_mld_set_wakeup,
2654
.set_rekey_data = iwl_mld_set_rekey_data,
2655
#if IS_ENABLED(CONFIG_IPV6)
2656
.ipv6_addr_change = iwl_mld_ipv6_addr_change,
2657
#endif /* IS_ENABLED(CONFIG_IPV6) */
2658
#endif /* CONFIG_PM_SLEEP */
2659
#ifdef CONFIG_IWLWIFI_DEBUGFS
2660
.vif_add_debugfs = iwl_mld_add_vif_debugfs,
2661
.link_add_debugfs = iwl_mld_add_link_debugfs,
2662
.link_sta_add_debugfs = iwl_mld_add_link_sta_debugfs,
2663
#endif
2664
.mgd_protect_tdls_discover = iwl_mld_mac80211_mgd_protect_tdls_discover,
2665
.join_ibss = iwl_mld_mac80211_join_ibss,
2666
.leave_ibss = iwl_mld_mac80211_leave_ibss,
2667
.tx_last_beacon = iwl_mld_mac80211_tx_last_beacon,
2668
.prep_add_interface = iwl_mld_prep_add_interface,
2669
.set_hw_timestamp = iwl_mld_set_hw_timestamp,
2670
.start_pmsr = iwl_mld_start_pmsr,
2671
.can_neg_ttlm = iwl_mld_can_neg_ttlm,
2672
};
2673
2674