1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2023 MediaTek Inc. */
4 #include <linux/etherdevice.h>
5 #include <linux/platform_device.h>
7 #include <linux/module.h>
8 #include <linux/ctype.h>
15 mt7925_init_he_caps(struct mt792x_phy
*phy
, enum nl80211_band band
,
16 struct ieee80211_sband_iftype_data
*data
,
17 enum nl80211_iftype iftype
)
19 struct ieee80211_sta_he_cap
*he_cap
= &data
->he_cap
;
20 struct ieee80211_he_cap_elem
*he_cap_elem
= &he_cap
->he_cap_elem
;
21 struct ieee80211_he_mcs_nss_supp
*he_mcs
= &he_cap
->he_mcs_nss_supp
;
22 int i
, nss
= hweight8(phy
->mt76
->antenna_mask
);
25 for (i
= 0; i
< 8; i
++) {
27 mcs_map
|= (IEEE80211_HE_MCS_SUPPORT_0_11
<< (i
* 2));
29 mcs_map
|= (IEEE80211_HE_MCS_NOT_SUPPORTED
<< (i
* 2));
32 he_cap
->has_he
= true;
34 he_cap_elem
->mac_cap_info
[0] = IEEE80211_HE_MAC_CAP0_HTC_HE
;
35 he_cap_elem
->mac_cap_info
[3] = IEEE80211_HE_MAC_CAP3_OMI_CONTROL
|
36 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3
;
37 he_cap_elem
->mac_cap_info
[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU
;
39 if (band
== NL80211_BAND_2GHZ
)
40 he_cap_elem
->phy_cap_info
[0] =
41 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G
;
43 he_cap_elem
->phy_cap_info
[0] =
44 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G
|
45 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G
;
47 he_cap_elem
->phy_cap_info
[1] =
48 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD
;
49 he_cap_elem
->phy_cap_info
[2] =
50 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US
|
51 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ
|
52 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ
|
53 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO
|
54 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO
;
57 case NL80211_IFTYPE_AP
:
58 he_cap_elem
->mac_cap_info
[2] |=
59 IEEE80211_HE_MAC_CAP2_BSR
;
60 he_cap_elem
->mac_cap_info
[4] |=
61 IEEE80211_HE_MAC_CAP4_BQR
;
62 he_cap_elem
->mac_cap_info
[5] |=
63 IEEE80211_HE_MAC_CAP5_OM_CTRL_UL_MU_DATA_DIS_RX
;
64 he_cap_elem
->phy_cap_info
[3] |=
65 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK
|
66 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK
;
67 he_cap_elem
->phy_cap_info
[6] |=
68 IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE
|
69 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT
;
70 he_cap_elem
->phy_cap_info
[9] |=
71 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU
|
72 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU
;
74 case NL80211_IFTYPE_STATION
:
75 he_cap_elem
->mac_cap_info
[1] |=
76 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US
;
78 if (band
== NL80211_BAND_2GHZ
)
79 he_cap_elem
->phy_cap_info
[0] |=
80 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G
;
82 he_cap_elem
->phy_cap_info
[0] |=
83 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G
;
85 he_cap_elem
->phy_cap_info
[1] |=
86 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A
|
87 IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US
;
88 he_cap_elem
->phy_cap_info
[3] |=
89 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK
|
90 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK
;
91 he_cap_elem
->phy_cap_info
[4] |=
92 IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE
|
93 IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4
|
94 IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_4
;
95 he_cap_elem
->phy_cap_info
[5] |=
96 IEEE80211_HE_PHY_CAP5_NG16_SU_FEEDBACK
|
97 IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK
;
98 he_cap_elem
->phy_cap_info
[6] |=
99 IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_42_SU
|
100 IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU
|
101 IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB
|
102 IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE
|
103 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT
;
104 he_cap_elem
->phy_cap_info
[7] |=
105 IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP
|
106 IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI
;
107 he_cap_elem
->phy_cap_info
[8] |=
108 IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G
|
109 IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU
|
110 IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU
|
111 IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_484
;
112 he_cap_elem
->phy_cap_info
[9] |=
113 IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM
|
114 IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK
|
115 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU
|
116 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU
|
117 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB
|
118 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB
;
124 he_mcs
->rx_mcs_80
= cpu_to_le16(mcs_map
);
125 he_mcs
->tx_mcs_80
= cpu_to_le16(mcs_map
);
126 he_mcs
->rx_mcs_160
= cpu_to_le16(mcs_map
);
127 he_mcs
->tx_mcs_160
= cpu_to_le16(mcs_map
);
129 memset(he_cap
->ppe_thres
, 0, sizeof(he_cap
->ppe_thres
));
131 if (he_cap_elem
->phy_cap_info
[6] &
132 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT
) {
133 mt76_connac_gen_ppe_thresh(he_cap
->ppe_thres
, nss
);
135 he_cap_elem
->phy_cap_info
[9] |=
136 u8_encode_bits(IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US
,
137 IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK
);
140 if (band
== NL80211_BAND_6GHZ
) {
141 u16 cap
= IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS
|
142 IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS
;
144 cap
|= u16_encode_bits(IEEE80211_HT_MPDU_DENSITY_0_5
,
145 IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START
) |
146 u16_encode_bits(IEEE80211_VHT_MAX_AMPDU_1024K
,
147 IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP
) |
148 u16_encode_bits(IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454
,
149 IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN
);
151 data
->he_6ghz_capa
.capa
= cpu_to_le16(cap
);
156 mt7925_init_eht_caps(struct mt792x_phy
*phy
, enum nl80211_band band
,
157 struct ieee80211_sband_iftype_data
*data
)
159 struct ieee80211_sta_eht_cap
*eht_cap
= &data
->eht_cap
;
160 struct ieee80211_eht_cap_elem_fixed
*eht_cap_elem
= &eht_cap
->eht_cap_elem
;
161 struct ieee80211_eht_mcs_nss_supp
*eht_nss
= &eht_cap
->eht_mcs_nss_supp
;
162 enum nl80211_chan_width width
= phy
->mt76
->chandef
.width
;
163 int nss
= hweight8(phy
->mt76
->antenna_mask
);
164 int sts
= hweight16(phy
->mt76
->chainmask
);
167 if (!phy
->dev
->has_eht
)
170 eht_cap
->has_eht
= true;
172 eht_cap_elem
->mac_cap_info
[0] =
173 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS
|
174 IEEE80211_EHT_MAC_CAP0_OM_CONTROL
;
176 eht_cap_elem
->phy_cap_info
[0] =
177 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI
|
178 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER
|
179 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE
;
181 eht_cap_elem
->phy_cap_info
[0] |=
182 u8_encode_bits(u8_get_bits(sts
- 1, BIT(0)),
183 IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK
);
185 eht_cap_elem
->phy_cap_info
[1] =
186 u8_encode_bits(u8_get_bits(sts
- 1, GENMASK(2, 1)),
187 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK
) |
188 u8_encode_bits(sts
- 1,
189 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK
);
191 eht_cap_elem
->phy_cap_info
[2] =
192 u8_encode_bits(sts
- 1, IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK
) |
193 u8_encode_bits(sts
- 1, IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK
);
195 eht_cap_elem
->phy_cap_info
[3] =
196 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK
|
197 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK
|
198 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK
|
199 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK
|
200 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK
|
201 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK
|
202 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK
;
204 eht_cap_elem
->phy_cap_info
[4] =
205 u8_encode_bits(min_t(int, sts
- 1, 2),
206 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK
);
208 eht_cap_elem
->phy_cap_info
[5] =
209 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK
|
210 u8_encode_bits(IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US
,
211 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK
) |
212 u8_encode_bits(u8_get_bits(0x11, GENMASK(1, 0)),
213 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK
);
215 val
= width
== NL80211_CHAN_WIDTH_160
? 0x7 :
216 width
== NL80211_CHAN_WIDTH_80
? 0x3 : 0x1;
217 eht_cap_elem
->phy_cap_info
[6] =
218 u8_encode_bits(u8_get_bits(0x11, GENMASK(4, 2)),
219 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK
) |
220 u8_encode_bits(val
, IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK
);
222 eht_cap_elem
->phy_cap_info
[7] =
223 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ
|
224 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ
|
225 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ
|
226 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ
;
228 val
= u8_encode_bits(nss
, IEEE80211_EHT_MCS_NSS_RX
) |
229 u8_encode_bits(nss
, IEEE80211_EHT_MCS_NSS_TX
);
231 eht_nss
->bw
._80
.rx_tx_mcs9_max_nss
= val
;
232 eht_nss
->bw
._80
.rx_tx_mcs11_max_nss
= val
;
233 eht_nss
->bw
._80
.rx_tx_mcs13_max_nss
= val
;
234 eht_nss
->bw
._160
.rx_tx_mcs9_max_nss
= val
;
235 eht_nss
->bw
._160
.rx_tx_mcs11_max_nss
= val
;
236 eht_nss
->bw
._160
.rx_tx_mcs13_max_nss
= val
;
239 int mt7925_init_mlo_caps(struct mt792x_phy
*phy
)
241 struct wiphy
*wiphy
= phy
->mt76
->hw
->wiphy
;
242 static const u8 ext_capa_sta
[] = {
243 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF
,
245 static struct wiphy_iftype_ext_capab ext_capab
[] = {
247 .iftype
= NL80211_IFTYPE_STATION
,
248 .extended_capabilities
= ext_capa_sta
,
249 .extended_capabilities_mask
= ext_capa_sta
,
250 .extended_capabilities_len
= sizeof(ext_capa_sta
),
254 if (!(phy
->chip_cap
& MT792x_CHIP_CAP_MLO_EVT_EN
))
257 ext_capab
[0].eml_capabilities
= phy
->eml_cap
;
258 ext_capab
[0].mld_capa_and_ops
=
259 u16_encode_bits(1, IEEE80211_MLD_CAP_OP_MAX_SIMUL_LINKS
);
261 wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_MLO
;
262 wiphy
->iftype_ext_capab
= ext_capab
;
263 wiphy
->num_iftype_ext_capab
= ARRAY_SIZE(ext_capab
);
269 __mt7925_set_stream_he_eht_caps(struct mt792x_phy
*phy
,
270 struct ieee80211_supported_band
*sband
,
271 enum nl80211_band band
)
273 struct ieee80211_sband_iftype_data
*data
= phy
->iftype
[band
];
276 for (i
= 0; i
< NUM_NL80211_IFTYPES
; i
++) {
278 case NL80211_IFTYPE_STATION
:
279 case NL80211_IFTYPE_AP
:
285 data
[n
].types_mask
= BIT(i
);
286 mt7925_init_he_caps(phy
, band
, &data
[n
], i
);
287 mt7925_init_eht_caps(phy
, band
, &data
[n
]);
292 _ieee80211_set_sband_iftype_data(sband
, data
, n
);
295 void mt7925_set_stream_he_eht_caps(struct mt792x_phy
*phy
)
297 if (phy
->mt76
->cap
.has_2ghz
)
298 __mt7925_set_stream_he_eht_caps(phy
, &phy
->mt76
->sband_2g
.sband
,
301 if (phy
->mt76
->cap
.has_5ghz
)
302 __mt7925_set_stream_he_eht_caps(phy
, &phy
->mt76
->sband_5g
.sband
,
305 if (phy
->mt76
->cap
.has_6ghz
)
306 __mt7925_set_stream_he_eht_caps(phy
, &phy
->mt76
->sband_6g
.sband
,
310 int __mt7925_start(struct mt792x_phy
*phy
)
312 struct mt76_phy
*mphy
= phy
->mt76
;
315 err
= mt7925_mcu_set_channel_domain(mphy
);
319 err
= mt7925_mcu_set_rts_thresh(phy
, 0x92b);
323 err
= mt7925_set_tx_sar_pwr(mphy
->hw
, NULL
);
327 mt792x_mac_reset_counters(phy
);
328 set_bit(MT76_STATE_RUNNING
, &mphy
->state
);
330 ieee80211_queue_delayed_work(mphy
->hw
, &mphy
->mac_work
,
331 MT792x_WATCHDOG_TIME
);
335 EXPORT_SYMBOL_GPL(__mt7925_start
);
337 static int mt7925_start(struct ieee80211_hw
*hw
)
339 struct mt792x_phy
*phy
= mt792x_hw_phy(hw
);
342 mt792x_mutex_acquire(phy
->dev
);
343 err
= __mt7925_start(phy
);
344 mt792x_mutex_release(phy
->dev
);
349 static int mt7925_mac_link_bss_add(struct mt792x_dev
*dev
,
350 struct ieee80211_bss_conf
*link_conf
,
351 struct mt792x_link_sta
*mlink
)
353 struct mt792x_bss_conf
*mconf
= mt792x_link_conf_to_mconf(link_conf
);
354 struct ieee80211_vif
*vif
= link_conf
->vif
;
355 struct mt792x_vif
*mvif
= mconf
->vif
;
356 struct mt76_txq
*mtxq
;
359 mconf
->mt76
.idx
= __ffs64(~dev
->mt76
.vif_mask
);
360 if (mconf
->mt76
.idx
>= MT792x_MAX_INTERFACES
) {
365 mconf
->mt76
.omac_idx
= ieee80211_vif_is_mld(vif
) ?
367 mconf
->mt76
.band_idx
= 0xff;
368 mconf
->mt76
.wmm_idx
= mconf
->mt76
.idx
% MT76_CONNAC_MAX_WMM_SETS
;
370 if (mvif
->phy
->mt76
->chandef
.chan
->band
!= NL80211_BAND_2GHZ
)
371 mconf
->mt76
.basic_rates_idx
= MT792x_BASIC_RATES_TBL
+ 4;
373 mconf
->mt76
.basic_rates_idx
= MT792x_BASIC_RATES_TBL
;
375 ret
= mt76_connac_mcu_uni_add_dev(&dev
->mphy
, link_conf
,
380 dev
->mt76
.vif_mask
|= BIT_ULL(mconf
->mt76
.idx
);
381 mvif
->phy
->omac_mask
|= BIT_ULL(mconf
->mt76
.omac_idx
);
383 idx
= MT792x_WTBL_RESERVED
- mconf
->mt76
.idx
;
385 INIT_LIST_HEAD(&mlink
->wcid
.poll_list
);
386 mlink
->wcid
.idx
= idx
;
387 mlink
->wcid
.phy_idx
= mconf
->mt76
.band_idx
;
388 mlink
->wcid
.hw_key_idx
= -1;
389 mlink
->wcid
.tx_info
|= MT_WCID_TX_INFO_SET
;
390 mt76_wcid_init(&mlink
->wcid
);
392 mt7925_mac_wtbl_update(dev
, idx
,
393 MT_WTBL_UPDATE_ADM_COUNT_CLEAR
);
395 ewma_rssi_init(&mconf
->rssi
);
397 rcu_assign_pointer(dev
->mt76
.wcid
[idx
], &mlink
->wcid
);
399 mtxq
= (struct mt76_txq
*)vif
->txq
->drv_priv
;
408 mt7925_add_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
410 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
411 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
412 struct mt792x_phy
*phy
= mt792x_hw_phy(hw
);
415 mt792x_mutex_acquire(dev
);
418 mvif
->bss_conf
.vif
= mvif
;
419 mvif
->sta
.vif
= mvif
;
420 mvif
->deflink_id
= IEEE80211_LINK_UNSPECIFIED
;
422 ret
= mt7925_mac_link_bss_add(dev
, &vif
->bss_conf
, &mvif
->sta
.deflink
);
426 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
;
428 mt792x_mutex_release(dev
);
433 static void mt7925_roc_iter(void *priv
, u8
*mac
,
434 struct ieee80211_vif
*vif
)
436 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
437 struct mt792x_phy
*phy
= priv
;
439 mt7925_mcu_abort_roc(phy
, &mvif
->bss_conf
, phy
->roc_token_id
);
442 void mt7925_roc_abort_sync(struct mt792x_dev
*dev
)
444 struct mt792x_phy
*phy
= &dev
->phy
;
446 del_timer_sync(&phy
->roc_timer
);
447 cancel_work_sync(&phy
->roc_work
);
448 if (test_and_clear_bit(MT76_STATE_ROC
, &phy
->mt76
->state
))
449 ieee80211_iterate_interfaces(mt76_hw(dev
),
450 IEEE80211_IFACE_ITER_RESUME_ALL
,
451 mt7925_roc_iter
, (void *)phy
);
453 EXPORT_SYMBOL_GPL(mt7925_roc_abort_sync
);
455 void mt7925_roc_work(struct work_struct
*work
)
457 struct mt792x_phy
*phy
;
459 phy
= (struct mt792x_phy
*)container_of(work
, struct mt792x_phy
,
462 if (!test_and_clear_bit(MT76_STATE_ROC
, &phy
->mt76
->state
))
465 mt792x_mutex_acquire(phy
->dev
);
466 ieee80211_iterate_active_interfaces(phy
->mt76
->hw
,
467 IEEE80211_IFACE_ITER_RESUME_ALL
,
468 mt7925_roc_iter
, phy
);
469 mt792x_mutex_release(phy
->dev
);
470 ieee80211_remain_on_channel_expired(phy
->mt76
->hw
);
473 static int mt7925_abort_roc(struct mt792x_phy
*phy
,
474 struct mt792x_bss_conf
*mconf
)
478 del_timer_sync(&phy
->roc_timer
);
479 cancel_work_sync(&phy
->roc_work
);
481 mt792x_mutex_acquire(phy
->dev
);
482 if (test_and_clear_bit(MT76_STATE_ROC
, &phy
->mt76
->state
))
483 err
= mt7925_mcu_abort_roc(phy
, mconf
, phy
->roc_token_id
);
484 mt792x_mutex_release(phy
->dev
);
489 static int mt7925_set_roc(struct mt792x_phy
*phy
,
490 struct mt792x_bss_conf
*mconf
,
491 struct ieee80211_channel
*chan
,
493 enum mt7925_roc_req type
)
497 if (test_and_set_bit(MT76_STATE_ROC
, &phy
->mt76
->state
))
500 phy
->roc_grant
= false;
502 err
= mt7925_mcu_set_roc(phy
, mconf
, chan
, duration
, type
,
503 ++phy
->roc_token_id
);
505 clear_bit(MT76_STATE_ROC
, &phy
->mt76
->state
);
509 if (!wait_event_timeout(phy
->roc_wait
, phy
->roc_grant
, 4 * HZ
)) {
510 mt7925_mcu_abort_roc(phy
, mconf
, phy
->roc_token_id
);
511 clear_bit(MT76_STATE_ROC
, &phy
->mt76
->state
);
519 static int mt7925_set_mlo_roc(struct mt792x_phy
*phy
,
520 struct mt792x_bss_conf
*mconf
,
525 if (WARN_ON_ONCE(test_and_set_bit(MT76_STATE_ROC
, &phy
->mt76
->state
)))
528 phy
->roc_grant
= false;
530 err
= mt7925_mcu_set_mlo_roc(mconf
, sel_links
, 5, ++phy
->roc_token_id
);
532 clear_bit(MT76_STATE_ROC
, &phy
->mt76
->state
);
536 if (!wait_event_timeout(phy
->roc_wait
, phy
->roc_grant
, 4 * HZ
)) {
537 mt7925_mcu_abort_roc(phy
, mconf
, phy
->roc_token_id
);
538 clear_bit(MT76_STATE_ROC
, &phy
->mt76
->state
);
546 static int mt7925_remain_on_channel(struct ieee80211_hw
*hw
,
547 struct ieee80211_vif
*vif
,
548 struct ieee80211_channel
*chan
,
550 enum ieee80211_roc_type type
)
552 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
553 struct mt792x_phy
*phy
= mt792x_hw_phy(hw
);
556 mt792x_mutex_acquire(phy
->dev
);
557 err
= mt7925_set_roc(phy
, &mvif
->bss_conf
,
558 chan
, duration
, MT7925_ROC_REQ_ROC
);
559 mt792x_mutex_release(phy
->dev
);
564 static int mt7925_cancel_remain_on_channel(struct ieee80211_hw
*hw
,
565 struct ieee80211_vif
*vif
)
567 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
568 struct mt792x_phy
*phy
= mt792x_hw_phy(hw
);
570 return mt7925_abort_roc(phy
, &mvif
->bss_conf
);
573 static int mt7925_set_link_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
574 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
575 struct ieee80211_key_conf
*key
, int link_id
)
577 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
578 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
579 struct mt792x_sta
*msta
= sta
? (struct mt792x_sta
*)sta
->drv_priv
:
581 struct ieee80211_bss_conf
*link_conf
;
582 struct ieee80211_link_sta
*link_sta
;
583 int idx
= key
->keyidx
, err
= 0;
584 struct mt792x_link_sta
*mlink
;
585 struct mt792x_bss_conf
*mconf
;
586 struct mt76_wcid
*wcid
;
589 link_conf
= mt792x_vif_to_bss_conf(vif
, link_id
);
590 link_sta
= sta
? mt792x_sta_to_link_sta(vif
, sta
, link_id
) : NULL
;
591 mconf
= mt792x_vif_to_link(mvif
, link_id
);
592 mlink
= mt792x_sta_to_link(msta
, link_id
);
594 wcid_keyidx
= &wcid
->hw_key_idx
;
596 /* fall back to sw encryption for unsupported ciphers */
597 switch (key
->cipher
) {
598 case WLAN_CIPHER_SUITE_AES_CMAC
:
599 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIE
;
600 wcid_keyidx
= &wcid
->hw_key_idx2
;
602 case WLAN_CIPHER_SUITE_WEP40
:
603 case WLAN_CIPHER_SUITE_WEP104
:
607 case WLAN_CIPHER_SUITE_TKIP
:
608 case WLAN_CIPHER_SUITE_CCMP
:
609 case WLAN_CIPHER_SUITE_CCMP_256
:
610 case WLAN_CIPHER_SUITE_GCMP
:
611 case WLAN_CIPHER_SUITE_GCMP_256
:
612 case WLAN_CIPHER_SUITE_SMS4
:
618 if (cmd
== SET_KEY
&& !mconf
->mt76
.cipher
) {
619 struct mt792x_phy
*phy
= mt792x_hw_phy(hw
);
621 mconf
->mt76
.cipher
= mt7925_mcu_get_cipher(key
->cipher
);
622 mt7925_mcu_add_bss_info(phy
, mconf
->mt76
.ctx
, link_conf
,
628 else if (idx
== *wcid_keyidx
)
633 mt76_wcid_key_setup(&dev
->mt76
, wcid
,
634 cmd
== SET_KEY
? key
: NULL
);
636 err
= mt7925_mcu_add_key(&dev
->mt76
, vif
, &mlink
->bip
,
637 key
, MCU_UNI_CMD(STA_REC_UPDATE
),
638 &mlink
->wcid
, cmd
, msta
);
643 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
||
644 key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
645 err
= mt7925_mcu_add_key(&dev
->mt76
, vif
, &mvif
->wep_sta
->deflink
.bip
,
646 key
, MCU_WMWA_UNI_CMD(STA_REC_UPDATE
),
647 &mvif
->wep_sta
->deflink
.wcid
, cmd
, msta
);
652 static int mt7925_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
653 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
654 struct ieee80211_key_conf
*key
)
656 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
657 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
658 struct mt792x_sta
*msta
= sta
? (struct mt792x_sta
*)sta
->drv_priv
:
662 /* The hardware does not support per-STA RX GTK, fallback
663 * to software mode for these.
665 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
666 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
667 (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
||
668 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
) &&
669 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
672 mt792x_mutex_acquire(dev
);
674 if (ieee80211_vif_is_mld(vif
)) {
675 unsigned int link_id
;
678 add
= key
->link_id
!= -1 ? BIT(key
->link_id
) : msta
->valid_links
;
680 for_each_set_bit(link_id
, &add
, IEEE80211_MLD_MAX_NUM_LINKS
) {
681 err
= mt7925_set_link_key(hw
, cmd
, vif
, sta
, key
, link_id
);
686 err
= mt7925_set_link_key(hw
, cmd
, vif
, sta
, key
, vif
->bss_conf
.link_id
);
689 mt792x_mutex_release(dev
);
695 mt7925_pm_interface_iter(void *priv
, u8
*mac
, struct ieee80211_vif
*vif
)
697 struct mt792x_dev
*dev
= priv
;
698 struct ieee80211_hw
*hw
= mt76_hw(dev
);
699 bool pm_enable
= dev
->pm
.enable
;
702 err
= mt7925_mcu_set_beacon_filter(dev
, vif
, pm_enable
);
707 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
;
708 ieee80211_hw_set(hw
, CONNECTION_MONITOR
);
710 vif
->driver_flags
&= ~IEEE80211_VIF_BEACON_FILTER
;
711 __clear_bit(IEEE80211_HW_CONNECTION_MONITOR
, hw
->flags
);
716 mt7925_sniffer_interface_iter(void *priv
, u8
*mac
, struct ieee80211_vif
*vif
)
718 struct mt792x_dev
*dev
= priv
;
719 struct ieee80211_hw
*hw
= mt76_hw(dev
);
720 struct mt76_connac_pm
*pm
= &dev
->pm
;
721 bool monitor
= !!(hw
->conf
.flags
& IEEE80211_CONF_MONITOR
);
723 mt7925_mcu_set_sniffer(dev
, vif
, monitor
);
724 pm
->enable
= pm
->enable_user
&& !monitor
;
725 pm
->ds_enable
= pm
->ds_enable_user
&& !monitor
;
727 mt7925_mcu_set_deep_sleep(dev
, pm
->ds_enable
);
730 mt7925_mcu_set_beacon_filter(dev
, vif
, false);
733 void mt7925_set_runtime_pm(struct mt792x_dev
*dev
)
735 struct ieee80211_hw
*hw
= mt76_hw(dev
);
736 struct mt76_connac_pm
*pm
= &dev
->pm
;
737 bool monitor
= !!(hw
->conf
.flags
& IEEE80211_CONF_MONITOR
);
739 pm
->enable
= pm
->enable_user
&& !monitor
;
740 ieee80211_iterate_active_interfaces(hw
,
741 IEEE80211_IFACE_ITER_RESUME_ALL
,
742 mt7925_pm_interface_iter
, dev
);
743 pm
->ds_enable
= pm
->ds_enable_user
&& !monitor
;
744 mt7925_mcu_set_deep_sleep(dev
, pm
->ds_enable
);
747 static int mt7925_config(struct ieee80211_hw
*hw
, u32 changed
)
749 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
752 mt792x_mutex_acquire(dev
);
754 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
755 ret
= mt7925_set_tx_sar_pwr(hw
, NULL
);
760 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
761 ieee80211_iterate_active_interfaces(hw
,
762 IEEE80211_IFACE_ITER_RESUME_ALL
,
763 mt7925_sniffer_interface_iter
, dev
);
767 mt792x_mutex_release(dev
);
772 static void mt7925_configure_filter(struct ieee80211_hw
*hw
,
773 unsigned int changed_flags
,
774 unsigned int *total_flags
,
777 #define MT7925_FILTER_FCSFAIL BIT(2)
778 #define MT7925_FILTER_CONTROL BIT(5)
779 #define MT7925_FILTER_OTHER_BSS BIT(6)
780 #define MT7925_FILTER_ENABLE BIT(31)
781 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
782 u32 flags
= MT7925_FILTER_ENABLE
;
784 #define MT7925_FILTER(_fif, _type) do { \
785 if (*total_flags & (_fif)) \
786 flags |= MT7925_FILTER_##_type; \
789 MT7925_FILTER(FIF_FCSFAIL
, FCSFAIL
);
790 MT7925_FILTER(FIF_CONTROL
, CONTROL
);
791 MT7925_FILTER(FIF_OTHER_BSS
, OTHER_BSS
);
793 mt792x_mutex_acquire(dev
);
794 mt7925_mcu_set_rxfilter(dev
, flags
, 0, 0);
795 mt792x_mutex_release(dev
);
797 *total_flags
&= (FIF_OTHER_BSS
| FIF_FCSFAIL
| FIF_CONTROL
);
801 mt7925_get_rates_table(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
802 bool beacon
, bool mcast
)
804 struct mt76_vif
*mvif
= (struct mt76_vif
*)vif
->drv_priv
;
805 struct mt76_phy
*mphy
= hw
->priv
;
809 rate
= mt76_connac2_mac_tx_rate_val(mphy
, vif
, beacon
, mcast
);
810 ht
= FIELD_GET(MT_TX_RATE_MODE
, rate
) > MT_PHY_TYPE_OFDM
;
813 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
816 idx
= MT7925_BEACON_RATES_TBL
+ 2 * (mvif
->idx
% 20);
817 mt7925_mac_set_fixed_rate_table(dev
, idx
, rate
);
821 idx
= FIELD_GET(MT_TX_RATE_IDX
, rate
);
822 for (i
= 0; i
< ARRAY_SIZE(mt76_rates
); i
++)
823 if ((mt76_rates
[i
].hw_value
& GENMASK(7, 0)) == idx
)
824 return MT792x_BASIC_RATES_TBL
+ i
;
826 return mvif
->basic_rates_idx
;
829 static int mt7925_mac_link_sta_add(struct mt76_dev
*mdev
,
830 struct ieee80211_vif
*vif
,
831 struct ieee80211_link_sta
*link_sta
)
833 struct mt792x_dev
*dev
= container_of(mdev
, struct mt792x_dev
, mt76
);
834 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
835 struct ieee80211_bss_conf
*link_conf
;
836 struct mt792x_bss_conf
*mconf
;
837 u8 link_id
= link_sta
->link_id
;
838 struct mt792x_link_sta
*mlink
;
839 struct mt792x_sta
*msta
;
842 msta
= (struct mt792x_sta
*)link_sta
->sta
->drv_priv
;
843 mlink
= mt792x_sta_to_link(msta
, link_id
);
845 idx
= mt76_wcid_alloc(dev
->mt76
.wcid_mask
, MT792x_WTBL_STA
- 1);
849 mconf
= mt792x_vif_to_link(mvif
, link_id
);
850 INIT_LIST_HEAD(&mlink
->wcid
.poll_list
);
852 mlink
->wcid
.idx
= idx
;
853 mlink
->wcid
.phy_idx
= mconf
->mt76
.band_idx
;
854 mlink
->wcid
.tx_info
|= MT_WCID_TX_INFO_SET
;
855 mlink
->last_txs
= jiffies
;
856 mlink
->wcid
.link_id
= link_sta
->link_id
;
857 mlink
->wcid
.link_valid
= !!link_sta
->sta
->valid_links
;
859 ret
= mt76_connac_pm_wake(&dev
->mphy
, &dev
->pm
);
863 mt7925_mac_wtbl_update(dev
, idx
,
864 MT_WTBL_UPDATE_ADM_COUNT_CLEAR
);
866 link_conf
= mt792x_vif_to_bss_conf(vif
, link_id
);
868 /* should update bss info before STA add */
869 if (vif
->type
== NL80211_IFTYPE_STATION
&& !link_sta
->sta
->tdls
)
870 mt7925_mcu_add_bss_info(&dev
->phy
, mconf
->mt76
.ctx
,
871 link_conf
, link_sta
, false);
873 if (ieee80211_vif_is_mld(vif
) &&
874 link_sta
== mlink
->pri_link
) {
875 ret
= mt7925_mcu_sta_update(dev
, link_sta
, vif
, true,
876 MT76_STA_INFO_STATE_NONE
);
879 } else if (ieee80211_vif_is_mld(vif
) &&
880 link_sta
!= mlink
->pri_link
) {
881 ret
= mt7925_mcu_sta_update(dev
, mlink
->pri_link
, vif
,
882 true, MT76_STA_INFO_STATE_ASSOC
);
886 ret
= mt7925_mcu_sta_update(dev
, link_sta
, vif
, true,
887 MT76_STA_INFO_STATE_ASSOC
);
891 ret
= mt7925_mcu_sta_update(dev
, link_sta
, vif
, true,
892 MT76_STA_INFO_STATE_NONE
);
897 mt76_connac_power_save_sched(&dev
->mphy
, &dev
->pm
);
903 mt7925_mac_sta_add_links(struct mt792x_dev
*dev
, struct ieee80211_vif
*vif
,
904 struct ieee80211_sta
*sta
, unsigned long new_links
)
906 struct mt792x_sta
*msta
= (struct mt792x_sta
*)sta
->drv_priv
;
907 struct mt76_wcid
*wcid
;
908 unsigned int link_id
;
911 for_each_set_bit(link_id
, &new_links
, IEEE80211_MLD_MAX_NUM_LINKS
) {
912 struct ieee80211_link_sta
*link_sta
;
913 struct mt792x_link_sta
*mlink
;
915 if (msta
->deflink_id
== IEEE80211_LINK_UNSPECIFIED
) {
916 mlink
= &msta
->deflink
;
917 msta
->deflink_id
= link_id
;
919 mlink
= devm_kzalloc(dev
->mt76
.dev
, sizeof(*mlink
), GFP_KERNEL
);
926 ewma_signal_init(&wcid
->rssi
);
927 rcu_assign_pointer(dev
->mt76
.wcid
[wcid
->idx
], wcid
);
928 mt76_wcid_init(wcid
);
929 ewma_avg_signal_init(&mlink
->avg_ack_signal
);
930 memset(mlink
->airtime_ac
, 0,
931 sizeof(msta
->deflink
.airtime_ac
));
934 msta
->valid_links
|= BIT(link_id
);
935 rcu_assign_pointer(msta
->link
[link_id
], mlink
);
937 mlink
->pri_link
= &sta
->deflink
;
938 mlink
->wcid
.def_wcid
= &msta
->deflink
.wcid
;
940 link_sta
= mt792x_sta_to_link_sta(vif
, sta
, link_id
);
941 mt7925_mac_link_sta_add(&dev
->mt76
, vif
, link_sta
);
947 int mt7925_mac_sta_add(struct mt76_dev
*mdev
, struct ieee80211_vif
*vif
,
948 struct ieee80211_sta
*sta
)
950 struct mt792x_dev
*dev
= container_of(mdev
, struct mt792x_dev
, mt76
);
951 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
952 struct mt792x_sta
*msta
= (struct mt792x_sta
*)sta
->drv_priv
;
957 if (vif
->type
== NL80211_IFTYPE_STATION
)
958 mvif
->wep_sta
= msta
;
960 if (ieee80211_vif_is_mld(vif
)) {
961 msta
->deflink_id
= IEEE80211_LINK_UNSPECIFIED
;
963 err
= mt7925_mac_sta_add_links(dev
, vif
, sta
, sta
->valid_links
);
965 err
= mt7925_mac_link_sta_add(mdev
, vif
, &sta
->deflink
);
970 EXPORT_SYMBOL_GPL(mt7925_mac_sta_add
);
973 mt7925_mac_select_links(struct mt76_dev
*mdev
, struct ieee80211_vif
*vif
)
975 unsigned long usable_links
= ieee80211_vif_usable_links(vif
);
978 enum nl80211_band band
;
979 } data
[IEEE80211_MLD_MAX_NUM_LINKS
];
980 u8 link_id
, i
, j
, n_data
= 0;
983 if (!ieee80211_vif_is_mld(vif
))
986 if (vif
->active_links
== usable_links
)
987 return vif
->active_links
;
990 for_each_set_bit(link_id
, &usable_links
, IEEE80211_MLD_MAX_NUM_LINKS
) {
991 struct ieee80211_bss_conf
*link_conf
=
992 rcu_dereference(vif
->link_conf
[link_id
]);
994 if (WARN_ON_ONCE(!link_conf
))
997 data
[n_data
].link_id
= link_id
;
998 data
[n_data
].band
= link_conf
->chanreq
.oper
.chan
->band
;
1003 for (i
= 0; i
< n_data
; i
++) {
1004 if (!(BIT(data
[i
].link_id
) & vif
->active_links
))
1007 sel_links
= BIT(data
[i
].link_id
);
1009 for (j
= 0; j
< n_data
; j
++) {
1010 if (data
[i
].band
!= data
[j
].band
) {
1011 sel_links
|= BIT(data
[j
].link_id
);
1023 mt7925_mac_set_links(struct mt76_dev
*mdev
, struct ieee80211_vif
*vif
)
1025 struct mt792x_dev
*dev
= container_of(mdev
, struct mt792x_dev
, mt76
);
1026 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1027 struct ieee80211_bss_conf
*link_conf
=
1028 mt792x_vif_to_bss_conf(vif
, mvif
->deflink_id
);
1029 struct cfg80211_chan_def
*chandef
= &link_conf
->chanreq
.oper
;
1030 enum nl80211_band band
= chandef
->chan
->band
, secondary_band
;
1032 u16 sel_links
= mt7925_mac_select_links(mdev
, vif
);
1033 u8 secondary_link_id
= __ffs(~BIT(mvif
->deflink_id
) & sel_links
);
1035 if (!ieee80211_vif_is_mld(vif
) || hweight16(sel_links
) < 2)
1038 link_conf
= mt792x_vif_to_bss_conf(vif
, secondary_link_id
);
1039 secondary_band
= link_conf
->chanreq
.oper
.chan
->band
;
1041 if (band
== NL80211_BAND_2GHZ
||
1042 (band
== NL80211_BAND_5GHZ
&& secondary_band
== NL80211_BAND_6GHZ
)) {
1043 mt7925_abort_roc(mvif
->phy
, &mvif
->bss_conf
);
1045 mt792x_mutex_acquire(dev
);
1047 mt7925_set_mlo_roc(mvif
->phy
, &mvif
->bss_conf
, sel_links
);
1049 mt792x_mutex_release(dev
);
1052 ieee80211_set_active_links_async(vif
, sel_links
);
1055 static void mt7925_mac_link_sta_assoc(struct mt76_dev
*mdev
,
1056 struct ieee80211_vif
*vif
,
1057 struct ieee80211_link_sta
*link_sta
)
1059 struct mt792x_dev
*dev
= container_of(mdev
, struct mt792x_dev
, mt76
);
1060 struct ieee80211_bss_conf
*link_conf
;
1061 struct mt792x_link_sta
*mlink
;
1062 struct mt792x_sta
*msta
;
1064 msta
= (struct mt792x_sta
*)link_sta
->sta
->drv_priv
;
1065 mlink
= mt792x_sta_to_link(msta
, link_sta
->link_id
);
1067 mt792x_mutex_acquire(dev
);
1069 if (ieee80211_vif_is_mld(vif
)) {
1070 link_conf
= mt792x_vif_to_bss_conf(vif
, msta
->deflink_id
);
1072 link_conf
= mt792x_vif_to_bss_conf(vif
, vif
->bss_conf
.link_id
);
1075 if (vif
->type
== NL80211_IFTYPE_STATION
&& !link_sta
->sta
->tdls
) {
1076 struct mt792x_bss_conf
*mconf
;
1078 mconf
= mt792x_link_conf_to_mconf(link_conf
);
1079 mt7925_mcu_add_bss_info(&dev
->phy
, mconf
->mt76
.ctx
,
1080 link_conf
, link_sta
, true);
1083 ewma_avg_signal_init(&mlink
->avg_ack_signal
);
1085 mt7925_mac_wtbl_update(dev
, mlink
->wcid
.idx
,
1086 MT_WTBL_UPDATE_ADM_COUNT_CLEAR
);
1087 memset(mlink
->airtime_ac
, 0, sizeof(mlink
->airtime_ac
));
1089 mt7925_mcu_sta_update(dev
, link_sta
, vif
, true, MT76_STA_INFO_STATE_ASSOC
);
1091 mt792x_mutex_release(dev
);
1094 int mt7925_mac_sta_event(struct mt76_dev
*mdev
, struct ieee80211_vif
*vif
,
1095 struct ieee80211_sta
*sta
, enum mt76_sta_event ev
)
1097 struct ieee80211_link_sta
*link_sta
= &sta
->deflink
;
1099 if (ev
!= MT76_STA_EVENT_ASSOC
)
1102 if (ieee80211_vif_is_mld(vif
)) {
1103 struct mt792x_sta
*msta
= (struct mt792x_sta
*)sta
->drv_priv
;
1105 link_sta
= mt792x_sta_to_link_sta(vif
, sta
, msta
->deflink_id
);
1106 mt7925_mac_set_links(mdev
, vif
);
1109 mt7925_mac_link_sta_assoc(mdev
, vif
, link_sta
);
1113 EXPORT_SYMBOL_GPL(mt7925_mac_sta_event
);
1115 static void mt7925_mac_link_sta_remove(struct mt76_dev
*mdev
,
1116 struct ieee80211_vif
*vif
,
1117 struct ieee80211_link_sta
*link_sta
)
1119 struct mt792x_dev
*dev
= container_of(mdev
, struct mt792x_dev
, mt76
);
1120 struct ieee80211_bss_conf
*link_conf
;
1121 u8 link_id
= link_sta
->link_id
;
1122 struct mt792x_link_sta
*mlink
;
1123 struct mt792x_sta
*msta
;
1125 msta
= (struct mt792x_sta
*)link_sta
->sta
->drv_priv
;
1126 mlink
= mt792x_sta_to_link(msta
, link_id
);
1128 mt7925_roc_abort_sync(dev
);
1130 mt76_connac_free_pending_tx_skbs(&dev
->pm
, &mlink
->wcid
);
1131 mt76_connac_pm_wake(&dev
->mphy
, &dev
->pm
);
1133 mt7925_mcu_sta_update(dev
, link_sta
, vif
, false,
1134 MT76_STA_INFO_STATE_NONE
);
1135 mt7925_mac_wtbl_update(dev
, mlink
->wcid
.idx
,
1136 MT_WTBL_UPDATE_ADM_COUNT_CLEAR
);
1138 link_conf
= mt792x_vif_to_bss_conf(vif
, link_id
);
1140 if (vif
->type
== NL80211_IFTYPE_STATION
&& !link_sta
->sta
->tdls
) {
1141 struct mt792x_bss_conf
*mconf
;
1143 mconf
= mt792x_link_conf_to_mconf(link_conf
);
1144 mt7925_mcu_add_bss_info(&dev
->phy
, mconf
->mt76
.ctx
, link_conf
,
1148 spin_lock_bh(&mdev
->sta_poll_lock
);
1149 if (!list_empty(&mlink
->wcid
.poll_list
))
1150 list_del_init(&mlink
->wcid
.poll_list
);
1151 spin_unlock_bh(&mdev
->sta_poll_lock
);
1153 mt76_connac_power_save_sched(&dev
->mphy
, &dev
->pm
);
1157 mt7925_mac_sta_remove_links(struct mt792x_dev
*dev
, struct ieee80211_vif
*vif
,
1158 struct ieee80211_sta
*sta
, unsigned long old_links
)
1160 struct mt792x_sta
*msta
= (struct mt792x_sta
*)sta
->drv_priv
;
1161 struct mt76_dev
*mdev
= &dev
->mt76
;
1162 struct mt76_wcid
*wcid
;
1163 unsigned int link_id
;
1165 for_each_set_bit(link_id
, &old_links
, IEEE80211_MLD_MAX_NUM_LINKS
) {
1166 struct ieee80211_link_sta
*link_sta
;
1167 struct mt792x_link_sta
*mlink
;
1169 link_sta
= mt792x_sta_to_link_sta(vif
, sta
, link_id
);
1173 mlink
= mt792x_sta_to_link(msta
, link_id
);
1177 mt7925_mac_link_sta_remove(&dev
->mt76
, vif
, link_sta
);
1179 wcid
= &mlink
->wcid
;
1180 rcu_assign_pointer(msta
->link
[link_id
], NULL
);
1181 msta
->valid_links
&= ~BIT(link_id
);
1183 mlink
->pri_link
= NULL
;
1185 if (link_sta
!= mlink
->pri_link
) {
1186 mt76_wcid_cleanup(mdev
, wcid
);
1187 mt76_wcid_mask_clear(mdev
->wcid_mask
, wcid
->idx
);
1188 mt76_wcid_mask_clear(mdev
->wcid_phy_mask
, wcid
->idx
);
1191 if (msta
->deflink_id
== link_id
)
1192 msta
->deflink_id
= IEEE80211_LINK_UNSPECIFIED
;
1198 void mt7925_mac_sta_remove(struct mt76_dev
*mdev
, struct ieee80211_vif
*vif
,
1199 struct ieee80211_sta
*sta
)
1201 struct mt792x_dev
*dev
= container_of(mdev
, struct mt792x_dev
, mt76
);
1202 struct mt792x_sta
*msta
= (struct mt792x_sta
*)sta
->drv_priv
;
1205 rem
= ieee80211_vif_is_mld(vif
) ? msta
->valid_links
: BIT(0);
1207 mt7925_mac_sta_remove_links(dev
, vif
, sta
, rem
);
1209 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1210 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1212 mvif
->wep_sta
= NULL
;
1213 ewma_rssi_init(&mvif
->bss_conf
.rssi
);
1216 EXPORT_SYMBOL_GPL(mt7925_mac_sta_remove
);
1218 static int mt7925_set_rts_threshold(struct ieee80211_hw
*hw
, u32 val
)
1220 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1222 mt792x_mutex_acquire(dev
);
1223 mt7925_mcu_set_rts_thresh(&dev
->phy
, val
);
1224 mt792x_mutex_release(dev
);
1230 mt7925_ampdu_action(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1231 struct ieee80211_ampdu_params
*params
)
1233 enum ieee80211_ampdu_mlme_action action
= params
->action
;
1234 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1235 struct ieee80211_sta
*sta
= params
->sta
;
1236 struct ieee80211_txq
*txq
= sta
->txq
[params
->tid
];
1237 struct mt792x_sta
*msta
= (struct mt792x_sta
*)sta
->drv_priv
;
1238 u16 tid
= params
->tid
;
1239 u16 ssn
= params
->ssn
;
1240 struct mt76_txq
*mtxq
;
1246 mtxq
= (struct mt76_txq
*)txq
->drv_priv
;
1248 mt792x_mutex_acquire(dev
);
1250 case IEEE80211_AMPDU_RX_START
:
1251 mt76_rx_aggr_start(&dev
->mt76
, &msta
->deflink
.wcid
, tid
, ssn
,
1253 mt7925_mcu_uni_rx_ba(dev
, params
, true);
1255 case IEEE80211_AMPDU_RX_STOP
:
1256 mt76_rx_aggr_stop(&dev
->mt76
, &msta
->deflink
.wcid
, tid
);
1257 mt7925_mcu_uni_rx_ba(dev
, params
, false);
1259 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1261 mtxq
->send_bar
= false;
1262 mt7925_mcu_uni_tx_ba(dev
, params
, true);
1264 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
1265 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
1267 clear_bit(tid
, &msta
->deflink
.wcid
.ampdu_state
);
1268 mt7925_mcu_uni_tx_ba(dev
, params
, false);
1270 case IEEE80211_AMPDU_TX_START
:
1271 set_bit(tid
, &msta
->deflink
.wcid
.ampdu_state
);
1272 ret
= IEEE80211_AMPDU_TX_START_IMMEDIATE
;
1274 case IEEE80211_AMPDU_TX_STOP_CONT
:
1276 clear_bit(tid
, &msta
->deflink
.wcid
.ampdu_state
);
1277 mt7925_mcu_uni_tx_ba(dev
, params
, false);
1278 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1281 mt792x_mutex_release(dev
);
1286 static bool is_valid_alpha2(const char *alpha2
)
1291 if (alpha2
[0] == '0' && alpha2
[1] == '0')
1294 if (isalpha(alpha2
[0]) && isalpha(alpha2
[1]))
1300 void mt7925_scan_work(struct work_struct
*work
)
1302 struct mt792x_phy
*phy
;
1304 phy
= (struct mt792x_phy
*)container_of(work
, struct mt792x_phy
,
1308 struct mt76_dev
*mdev
= &phy
->dev
->mt76
;
1309 struct sk_buff
*skb
;
1313 spin_lock_bh(&phy
->dev
->mt76
.lock
);
1314 skb
= __skb_dequeue(&phy
->scan_event_list
);
1315 spin_unlock_bh(&phy
->dev
->mt76
.lock
);
1320 skb_pull(skb
, sizeof(struct mt7925_mcu_rxd
) + 4);
1321 tlv
= (struct tlv
*)skb
->data
;
1324 while (tlv_len
> 0 && le16_to_cpu(tlv
->len
) <= tlv_len
) {
1325 struct mt7925_mcu_scan_chinfo_event
*evt
;
1327 switch (le16_to_cpu(tlv
->tag
)) {
1328 case UNI_EVENT_SCAN_DONE_BASIC
:
1329 if (test_and_clear_bit(MT76_HW_SCANNING
, &phy
->mt76
->state
)) {
1330 struct cfg80211_scan_info info
= {
1333 ieee80211_scan_completed(phy
->mt76
->hw
, &info
);
1336 case UNI_EVENT_SCAN_DONE_CHNLINFO
:
1337 evt
= (struct mt7925_mcu_scan_chinfo_event
*)tlv
->data
;
1339 if (!is_valid_alpha2(evt
->alpha2
))
1342 if (mdev
->alpha2
[0] != '0' && mdev
->alpha2
[1] != '0')
1345 mt7925_mcu_set_clc(phy
->dev
, evt
->alpha2
, ENVIRON_INDOOR
);
1348 case UNI_EVENT_SCAN_DONE_NLO
:
1349 ieee80211_sched_scan_results(phy
->mt76
->hw
);
1355 tlv_len
-= le16_to_cpu(tlv
->len
);
1356 tlv
= (struct tlv
*)((char *)(tlv
) + le16_to_cpu(tlv
->len
));
1364 mt7925_hw_scan(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1365 struct ieee80211_scan_request
*req
)
1367 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1368 struct mt76_phy
*mphy
= hw
->priv
;
1371 mt792x_mutex_acquire(dev
);
1372 err
= mt7925_mcu_hw_scan(mphy
, vif
, req
);
1373 mt792x_mutex_release(dev
);
1379 mt7925_cancel_hw_scan(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1381 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1382 struct mt76_phy
*mphy
= hw
->priv
;
1384 mt792x_mutex_acquire(dev
);
1385 mt7925_mcu_cancel_hw_scan(mphy
, vif
);
1386 mt792x_mutex_release(dev
);
1390 mt7925_start_sched_scan(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1391 struct cfg80211_sched_scan_request
*req
,
1392 struct ieee80211_scan_ies
*ies
)
1394 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1395 struct mt76_phy
*mphy
= hw
->priv
;
1398 mt792x_mutex_acquire(dev
);
1400 err
= mt7925_mcu_sched_scan_req(mphy
, vif
, req
);
1404 err
= mt7925_mcu_sched_scan_enable(mphy
, vif
, true);
1406 mt792x_mutex_release(dev
);
1412 mt7925_stop_sched_scan(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1414 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1415 struct mt76_phy
*mphy
= hw
->priv
;
1418 mt792x_mutex_acquire(dev
);
1419 err
= mt7925_mcu_sched_scan_enable(mphy
, vif
, false);
1420 mt792x_mutex_release(dev
);
1426 mt7925_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
1428 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1429 struct mt792x_phy
*phy
= mt792x_hw_phy(hw
);
1430 int max_nss
= hweight8(hw
->wiphy
->available_antennas_tx
);
1432 if (!tx_ant
|| tx_ant
!= rx_ant
|| ffs(tx_ant
) > max_nss
)
1435 if ((BIT(hweight8(tx_ant
)) - 1) != tx_ant
)
1436 tx_ant
= BIT(ffs(tx_ant
) - 1) - 1;
1438 mt792x_mutex_acquire(dev
);
1440 phy
->mt76
->antenna_mask
= tx_ant
;
1441 phy
->mt76
->chainmask
= tx_ant
;
1443 mt76_set_stream_caps(phy
->mt76
, true);
1444 mt7925_set_stream_he_eht_caps(phy
);
1446 /* TODO: update bmc_wtbl spe_idx when antenna changes */
1447 mt792x_mutex_release(dev
);
1453 static int mt7925_suspend(struct ieee80211_hw
*hw
,
1454 struct cfg80211_wowlan
*wowlan
)
1456 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1457 struct mt792x_phy
*phy
= mt792x_hw_phy(hw
);
1459 cancel_delayed_work_sync(&phy
->scan_work
);
1460 cancel_delayed_work_sync(&phy
->mt76
->mac_work
);
1462 cancel_delayed_work_sync(&dev
->pm
.ps_work
);
1463 mt76_connac_free_pending_tx_skbs(&dev
->pm
, NULL
);
1465 mt792x_mutex_acquire(dev
);
1467 clear_bit(MT76_STATE_RUNNING
, &phy
->mt76
->state
);
1468 ieee80211_iterate_active_interfaces(hw
,
1469 IEEE80211_IFACE_ITER_RESUME_ALL
,
1470 mt7925_mcu_set_suspend_iter
,
1473 mt792x_mutex_release(dev
);
1478 static int mt7925_resume(struct ieee80211_hw
*hw
)
1480 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1481 struct mt792x_phy
*phy
= mt792x_hw_phy(hw
);
1483 mt792x_mutex_acquire(dev
);
1485 set_bit(MT76_STATE_RUNNING
, &phy
->mt76
->state
);
1486 ieee80211_iterate_active_interfaces(hw
,
1487 IEEE80211_IFACE_ITER_RESUME_ALL
,
1488 mt7925_mcu_set_suspend_iter
,
1491 ieee80211_queue_delayed_work(hw
, &phy
->mt76
->mac_work
,
1492 MT792x_WATCHDOG_TIME
);
1494 mt792x_mutex_release(dev
);
1499 static void mt7925_set_rekey_data(struct ieee80211_hw
*hw
,
1500 struct ieee80211_vif
*vif
,
1501 struct cfg80211_gtk_rekey_data
*data
)
1503 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1505 mt792x_mutex_acquire(dev
);
1506 mt76_connac_mcu_update_gtk_rekey(hw
, vif
, data
);
1507 mt792x_mutex_release(dev
);
1509 #endif /* CONFIG_PM */
1511 static void mt7925_sta_set_decap_offload(struct ieee80211_hw
*hw
,
1512 struct ieee80211_vif
*vif
,
1513 struct ieee80211_sta
*sta
,
1516 struct mt792x_sta
*msta
= (struct mt792x_sta
*)sta
->drv_priv
;
1517 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1518 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1519 unsigned long valid
= mvif
->valid_links
;
1522 mt792x_mutex_acquire(dev
);
1524 valid
= ieee80211_vif_is_mld(vif
) ? mvif
->valid_links
: BIT(0);
1526 for_each_set_bit(i
, &valid
, IEEE80211_MLD_MAX_NUM_LINKS
) {
1527 struct mt792x_link_sta
*mlink
;
1529 mlink
= mt792x_sta_to_link(msta
, i
);
1532 set_bit(MT_WCID_FLAG_HDR_TRANS
, &mlink
->wcid
.flags
);
1534 clear_bit(MT_WCID_FLAG_HDR_TRANS
, &mlink
->wcid
.flags
);
1536 mt7925_mcu_wtbl_update_hdr_trans(dev
, vif
, sta
, i
);
1539 mt792x_mutex_release(dev
);
1542 #if IS_ENABLED(CONFIG_IPV6)
1543 static void __mt7925_ipv6_addr_change(struct ieee80211_hw
*hw
,
1544 struct ieee80211_bss_conf
*link_conf
,
1545 struct inet6_dev
*idev
)
1547 struct mt792x_bss_conf
*mconf
= mt792x_link_conf_to_mconf(link_conf
);
1548 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1549 struct inet6_ifaddr
*ifa
;
1550 struct sk_buff
*skb
;
1558 struct mt7925_arpns_tlv arpns
;
1559 struct in6_addr ns_addrs
[IEEE80211_BSS_ARP_ADDR_LIST_LEN
];
1562 .bss_idx
= mconf
->mt76
.idx
,
1565 .tag
= cpu_to_le16(UNI_OFFLOAD_OFFLOAD_ND
),
1566 .len
= cpu_to_le16(sizeof(req_hdr
) - 4),
1571 read_lock_bh(&idev
->lock
);
1572 list_for_each_entry(ifa
, &idev
->addr_list
, if_list
) {
1573 if (ifa
->flags
& IFA_F_TENTATIVE
)
1575 req_hdr
.ns_addrs
[idx
] = ifa
->addr
;
1576 if (++idx
>= IEEE80211_BSS_ARP_ADDR_LIST_LEN
)
1579 read_unlock_bh(&idev
->lock
);
1584 req_hdr
.arpns
.ips_num
= idx
;
1586 skb
= __mt76_mcu_msg_alloc(&dev
->mt76
, NULL
, sizeof(req_hdr
),
1591 skb_put_data(skb
, &req_hdr
, sizeof(req_hdr
));
1593 skb_queue_tail(&dev
->ipv6_ns_list
, skb
);
1595 ieee80211_queue_work(dev
->mt76
.hw
, &dev
->ipv6_ns_work
);
1598 static void mt7925_ipv6_addr_change(struct ieee80211_hw
*hw
,
1599 struct ieee80211_vif
*vif
,
1600 struct inet6_dev
*idev
)
1602 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1603 unsigned long valid
= ieee80211_vif_is_mld(vif
) ?
1604 mvif
->valid_links
: BIT(0);
1605 struct ieee80211_bss_conf
*bss_conf
;
1608 for_each_set_bit(i
, &valid
, IEEE80211_MLD_MAX_NUM_LINKS
) {
1609 bss_conf
= mt792x_vif_to_bss_conf(vif
, i
);
1610 __mt7925_ipv6_addr_change(hw
, bss_conf
, idev
);
1616 int mt7925_set_tx_sar_pwr(struct ieee80211_hw
*hw
,
1617 const struct cfg80211_sar_specs
*sar
)
1619 struct mt76_phy
*mphy
= hw
->priv
;
1622 int err
= mt76_init_sar_power(hw
, sar
);
1627 mt792x_init_acpi_sar_power(mt792x_hw_phy(hw
), !sar
);
1629 return mt7925_mcu_set_rate_txpower(mphy
);
1632 static int mt7925_set_sar_specs(struct ieee80211_hw
*hw
,
1633 const struct cfg80211_sar_specs
*sar
)
1635 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1638 mt792x_mutex_acquire(dev
);
1639 err
= mt7925_mcu_set_clc(dev
, dev
->mt76
.alpha2
,
1640 dev
->country_ie_env
);
1644 err
= mt7925_set_tx_sar_pwr(hw
, sar
);
1646 mt792x_mutex_release(dev
);
1652 mt7925_channel_switch_beacon(struct ieee80211_hw
*hw
,
1653 struct ieee80211_vif
*vif
,
1654 struct cfg80211_chan_def
*chandef
)
1656 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1658 mt792x_mutex_acquire(dev
);
1659 mt7925_mcu_uni_add_beacon_offload(dev
, hw
, vif
, true);
1660 mt792x_mutex_release(dev
);
1664 mt7925_conf_tx(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1665 unsigned int link_id
, u16 queue
,
1666 const struct ieee80211_tx_queue_params
*params
)
1668 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1669 struct mt792x_bss_conf
*mconf
= mt792x_vif_to_link(mvif
, link_id
);
1670 static const u8 mq_to_aci
[] = {
1671 [IEEE80211_AC_VO
] = 3,
1672 [IEEE80211_AC_VI
] = 2,
1673 [IEEE80211_AC_BE
] = 0,
1674 [IEEE80211_AC_BK
] = 1,
1677 /* firmware uses access class index */
1678 mconf
->queue_params
[mq_to_aci
[queue
]] = *params
;
1684 mt7925_start_ap(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1685 struct ieee80211_bss_conf
*link_conf
)
1687 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1688 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1691 mt792x_mutex_acquire(dev
);
1693 err
= mt7925_mcu_add_bss_info(&dev
->phy
, mvif
->bss_conf
.mt76
.ctx
,
1694 link_conf
, NULL
, true);
1698 err
= mt7925_mcu_set_bss_pm(dev
, link_conf
, true);
1702 err
= mt7925_mcu_sta_update(dev
, NULL
, vif
, true,
1703 MT76_STA_INFO_STATE_NONE
);
1705 mt792x_mutex_release(dev
);
1711 mt7925_stop_ap(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1712 struct ieee80211_bss_conf
*link_conf
)
1714 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1715 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1718 mt792x_mutex_acquire(dev
);
1720 err
= mt7925_mcu_set_bss_pm(dev
, link_conf
, false);
1724 mt7925_mcu_add_bss_info(&dev
->phy
, mvif
->bss_conf
.mt76
.ctx
, link_conf
,
1728 mt792x_mutex_release(dev
);
1732 mt7925_add_chanctx(struct ieee80211_hw
*hw
,
1733 struct ieee80211_chanctx_conf
*ctx
)
1739 mt7925_remove_chanctx(struct ieee80211_hw
*hw
,
1740 struct ieee80211_chanctx_conf
*ctx
)
1745 mt7925_change_chanctx(struct ieee80211_hw
*hw
,
1746 struct ieee80211_chanctx_conf
*ctx
,
1749 struct mt792x_chanctx
*mctx
= (struct mt792x_chanctx
*)ctx
->drv_priv
;
1750 struct mt792x_phy
*phy
= mt792x_hw_phy(hw
);
1751 struct mt792x_bss_conf
*mconf
;
1752 struct ieee80211_vif
*vif
;
1753 struct mt792x_vif
*mvif
;
1755 if (!mctx
->bss_conf
)
1758 mconf
= mctx
->bss_conf
;
1760 vif
= container_of((void *)mvif
, struct ieee80211_vif
, drv_priv
);
1762 mt792x_mutex_acquire(phy
->dev
);
1763 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
1764 mt7925_mcu_set_sniffer(mvif
->phy
->dev
, vif
, true);
1765 mt7925_mcu_config_sniffer(mvif
, ctx
);
1767 if (ieee80211_vif_is_mld(vif
)) {
1768 unsigned long valid
= mvif
->valid_links
;
1771 for_each_set_bit(i
, &valid
, IEEE80211_MLD_MAX_NUM_LINKS
) {
1772 mconf
= mt792x_vif_to_link(mvif
, i
);
1773 if (mconf
&& mconf
->mt76
.ctx
== ctx
)
1778 mconf
= &mvif
->bss_conf
;
1782 struct ieee80211_bss_conf
*link_conf
;
1784 link_conf
= mt792x_vif_to_bss_conf(vif
, mconf
->link_id
);
1785 mt7925_mcu_set_chctx(mvif
->phy
->mt76
, &mconf
->mt76
,
1790 mt792x_mutex_release(phy
->dev
);
1793 static void mt7925_mgd_prepare_tx(struct ieee80211_hw
*hw
,
1794 struct ieee80211_vif
*vif
,
1795 struct ieee80211_prep_tx_info
*info
)
1797 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1798 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1799 u16 duration
= info
->duration
? info
->duration
:
1800 jiffies_to_msecs(HZ
);
1802 mt792x_mutex_acquire(dev
);
1803 mt7925_set_roc(mvif
->phy
, &mvif
->bss_conf
,
1804 mvif
->bss_conf
.mt76
.ctx
->def
.chan
, duration
,
1805 MT7925_ROC_REQ_JOIN
);
1806 mt792x_mutex_release(dev
);
1809 static void mt7925_mgd_complete_tx(struct ieee80211_hw
*hw
,
1810 struct ieee80211_vif
*vif
,
1811 struct ieee80211_prep_tx_info
*info
)
1813 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1815 mt7925_abort_roc(mvif
->phy
, &mvif
->bss_conf
);
1818 static void mt7925_vif_cfg_changed(struct ieee80211_hw
*hw
,
1819 struct ieee80211_vif
*vif
,
1822 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1823 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1824 unsigned long valid
= ieee80211_vif_is_mld(vif
) ?
1825 mvif
->valid_links
: BIT(0);
1826 struct ieee80211_bss_conf
*bss_conf
;
1829 mt792x_mutex_acquire(dev
);
1831 if (changed
& BSS_CHANGED_ASSOC
) {
1832 mt7925_mcu_sta_update(dev
, NULL
, vif
, true,
1833 MT76_STA_INFO_STATE_ASSOC
);
1834 mt7925_mcu_set_beacon_filter(dev
, vif
, vif
->cfg
.assoc
);
1837 if (changed
& BSS_CHANGED_ARP_FILTER
) {
1838 for_each_set_bit(i
, &valid
, IEEE80211_MLD_MAX_NUM_LINKS
) {
1839 bss_conf
= mt792x_vif_to_bss_conf(vif
, i
);
1840 mt7925_mcu_update_arp_filter(&dev
->mt76
, bss_conf
);
1844 if (changed
& BSS_CHANGED_PS
) {
1845 for_each_set_bit(i
, &valid
, IEEE80211_MLD_MAX_NUM_LINKS
) {
1846 bss_conf
= mt792x_vif_to_bss_conf(vif
, i
);
1847 mt7925_mcu_uni_bss_ps(dev
, bss_conf
);
1851 mt792x_mutex_release(dev
);
1854 static void mt7925_link_info_changed(struct ieee80211_hw
*hw
,
1855 struct ieee80211_vif
*vif
,
1856 struct ieee80211_bss_conf
*info
,
1859 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1860 struct mt792x_phy
*phy
= mt792x_hw_phy(hw
);
1861 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1862 struct mt792x_bss_conf
*mconf
;
1864 mconf
= mt792x_vif_to_link(mvif
, info
->link_id
);
1866 mt792x_mutex_acquire(dev
);
1868 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1869 int slottime
= info
->use_short_slot
? 9 : 20;
1871 if (slottime
!= phy
->slottime
) {
1872 phy
->slottime
= slottime
;
1873 mt7925_mcu_set_timing(phy
, info
);
1877 if (changed
& BSS_CHANGED_MCAST_RATE
)
1878 mconf
->mt76
.mcast_rates_idx
=
1879 mt7925_get_rates_table(hw
, vif
, false, true);
1881 if (changed
& BSS_CHANGED_BASIC_RATES
)
1882 mconf
->mt76
.basic_rates_idx
=
1883 mt7925_get_rates_table(hw
, vif
, false, false);
1885 if (changed
& (BSS_CHANGED_BEACON
|
1886 BSS_CHANGED_BEACON_ENABLED
)) {
1887 mconf
->mt76
.beacon_rates_idx
=
1888 mt7925_get_rates_table(hw
, vif
, true, false);
1890 mt7925_mcu_uni_add_beacon_offload(dev
, hw
, vif
,
1891 info
->enable_beacon
);
1894 /* ensure that enable txcmd_mode after bss_info */
1895 if (changed
& (BSS_CHANGED_QOS
| BSS_CHANGED_BEACON_ENABLED
))
1896 mt7925_mcu_set_tx(dev
, info
);
1898 mt792x_mutex_release(dev
);
1902 mt7925_change_vif_links(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1903 u16 old_links
, u16 new_links
,
1904 struct ieee80211_bss_conf
*old
[IEEE80211_MLD_MAX_NUM_LINKS
])
1906 struct mt792x_bss_conf
*mconfs
[IEEE80211_MLD_MAX_NUM_LINKS
] = {}, *mconf
;
1907 struct mt792x_link_sta
*mlinks
[IEEE80211_MLD_MAX_NUM_LINKS
] = {}, *mlink
;
1908 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
1909 unsigned long add
= new_links
& ~old_links
;
1910 unsigned long rem
= old_links
& ~new_links
;
1911 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
1912 struct mt792x_phy
*phy
= mt792x_hw_phy(hw
);
1913 struct ieee80211_bss_conf
*link_conf
;
1914 unsigned int link_id
;
1917 if (old_links
== new_links
)
1920 mt792x_mutex_acquire(dev
);
1922 for_each_set_bit(link_id
, &rem
, IEEE80211_MLD_MAX_NUM_LINKS
) {
1923 mconf
= mt792x_vif_to_link(mvif
, link_id
);
1924 mlink
= mt792x_sta_to_link(&mvif
->sta
, link_id
);
1926 if (!mconf
|| !mlink
)
1929 if (mconf
!= &mvif
->bss_conf
) {
1930 mt792x_mac_link_bss_remove(dev
, mconf
, mlink
);
1931 devm_kfree(dev
->mt76
.dev
, mconf
);
1932 devm_kfree(dev
->mt76
.dev
, mlink
);
1935 rcu_assign_pointer(mvif
->link_conf
[link_id
], NULL
);
1936 rcu_assign_pointer(mvif
->sta
.link
[link_id
], NULL
);
1939 for_each_set_bit(link_id
, &add
, IEEE80211_MLD_MAX_NUM_LINKS
) {
1941 mvif
->deflink_id
= link_id
;
1942 mconf
= &mvif
->bss_conf
;
1943 mlink
= &mvif
->sta
.deflink
;
1945 mconf
= devm_kzalloc(dev
->mt76
.dev
, sizeof(*mconf
),
1947 mlink
= devm_kzalloc(dev
->mt76
.dev
, sizeof(*mlink
),
1951 mconfs
[link_id
] = mconf
;
1952 mlinks
[link_id
] = mlink
;
1953 mconf
->link_id
= link_id
;
1955 mlink
->wcid
.link_id
= link_id
;
1956 mlink
->wcid
.link_valid
= !!vif
->valid_links
;
1957 mlink
->wcid
.def_wcid
= &mvif
->sta
.deflink
.wcid
;
1960 if (hweight16(mvif
->valid_links
) == 0)
1961 mt792x_mac_link_bss_remove(dev
, &mvif
->bss_conf
,
1962 &mvif
->sta
.deflink
);
1964 for_each_set_bit(link_id
, &add
, IEEE80211_MLD_MAX_NUM_LINKS
) {
1965 mconf
= mconfs
[link_id
];
1966 mlink
= mlinks
[link_id
];
1967 link_conf
= mt792x_vif_to_bss_conf(vif
, link_id
);
1969 rcu_assign_pointer(mvif
->link_conf
[link_id
], mconf
);
1970 rcu_assign_pointer(mvif
->sta
.link
[link_id
], mlink
);
1972 err
= mt7925_mac_link_bss_add(dev
, link_conf
, mlink
);
1976 if (mconf
!= &mvif
->bss_conf
) {
1977 err
= mt7925_set_mlo_roc(phy
, &mvif
->bss_conf
,
1984 mvif
->valid_links
= new_links
;
1986 mt792x_mutex_release(dev
);
1991 for_each_set_bit(link_id
, &add
, IEEE80211_MLD_MAX_NUM_LINKS
) {
1992 rcu_assign_pointer(mvif
->link_conf
[link_id
], NULL
);
1993 rcu_assign_pointer(mvif
->sta
.link
[link_id
], NULL
);
1995 if (mconf
!= &mvif
->bss_conf
)
1996 devm_kfree(dev
->mt76
.dev
, mconfs
[link_id
]);
1997 if (mlink
!= &mvif
->sta
.deflink
)
1998 devm_kfree(dev
->mt76
.dev
, mlinks
[link_id
]);
2001 mt792x_mutex_release(dev
);
2007 mt7925_change_sta_links(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
2008 struct ieee80211_sta
*sta
, u16 old_links
, u16 new_links
)
2010 unsigned long add
= new_links
& ~old_links
;
2011 unsigned long rem
= old_links
& ~new_links
;
2012 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
2015 if (old_links
== new_links
)
2018 mt792x_mutex_acquire(dev
);
2020 err
= mt7925_mac_sta_remove_links(dev
, vif
, sta
, rem
);
2024 err
= mt7925_mac_sta_add_links(dev
, vif
, sta
, add
);
2029 mt792x_mutex_release(dev
);
2034 static int mt7925_assign_vif_chanctx(struct ieee80211_hw
*hw
,
2035 struct ieee80211_vif
*vif
,
2036 struct ieee80211_bss_conf
*link_conf
,
2037 struct ieee80211_chanctx_conf
*ctx
)
2039 struct mt792x_chanctx
*mctx
= (struct mt792x_chanctx
*)ctx
->drv_priv
;
2040 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
2041 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
2042 struct ieee80211_bss_conf
*pri_link_conf
;
2043 struct mt792x_bss_conf
*mconf
;
2045 mutex_lock(&dev
->mt76
.mutex
);
2047 if (ieee80211_vif_is_mld(vif
)) {
2048 mconf
= mt792x_vif_to_link(mvif
, link_conf
->link_id
);
2049 pri_link_conf
= mt792x_vif_to_bss_conf(vif
, mvif
->deflink_id
);
2051 if (vif
->type
== NL80211_IFTYPE_STATION
&&
2052 mconf
== &mvif
->bss_conf
)
2053 mt7925_mcu_add_bss_info(&dev
->phy
, NULL
, pri_link_conf
,
2056 mconf
= &mvif
->bss_conf
;
2059 mconf
->mt76
.ctx
= ctx
;
2060 mctx
->bss_conf
= mconf
;
2061 mutex_unlock(&dev
->mt76
.mutex
);
2066 static void mt7925_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
2067 struct ieee80211_vif
*vif
,
2068 struct ieee80211_bss_conf
*link_conf
,
2069 struct ieee80211_chanctx_conf
*ctx
)
2071 struct mt792x_chanctx
*mctx
= (struct mt792x_chanctx
*)ctx
->drv_priv
;
2072 struct mt792x_vif
*mvif
= (struct mt792x_vif
*)vif
->drv_priv
;
2073 struct mt792x_dev
*dev
= mt792x_hw_dev(hw
);
2074 struct ieee80211_bss_conf
*pri_link_conf
;
2075 struct mt792x_bss_conf
*mconf
;
2077 mutex_lock(&dev
->mt76
.mutex
);
2079 if (ieee80211_vif_is_mld(vif
)) {
2080 mconf
= mt792x_vif_to_link(mvif
, link_conf
->link_id
);
2081 pri_link_conf
= mt792x_vif_to_bss_conf(vif
, mvif
->deflink_id
);
2083 if (vif
->type
== NL80211_IFTYPE_STATION
&&
2084 mconf
== &mvif
->bss_conf
)
2085 mt7925_mcu_add_bss_info(&dev
->phy
, NULL
, pri_link_conf
,
2088 mconf
= &mvif
->bss_conf
;
2091 mctx
->bss_conf
= NULL
;
2092 mconf
->mt76
.ctx
= NULL
;
2093 mutex_unlock(&dev
->mt76
.mutex
);
2096 const struct ieee80211_ops mt7925_ops
= {
2098 .start
= mt7925_start
,
2099 .stop
= mt792x_stop
,
2100 .add_interface
= mt7925_add_interface
,
2101 .remove_interface
= mt792x_remove_interface
,
2102 .config
= mt7925_config
,
2103 .conf_tx
= mt7925_conf_tx
,
2104 .configure_filter
= mt7925_configure_filter
,
2105 .start_ap
= mt7925_start_ap
,
2106 .stop_ap
= mt7925_stop_ap
,
2107 .sta_state
= mt76_sta_state
,
2108 .sta_pre_rcu_remove
= mt76_sta_pre_rcu_remove
,
2109 .set_key
= mt7925_set_key
,
2110 .sta_set_decap_offload
= mt7925_sta_set_decap_offload
,
2111 #if IS_ENABLED(CONFIG_IPV6)
2112 .ipv6_addr_change
= mt7925_ipv6_addr_change
,
2113 #endif /* CONFIG_IPV6 */
2114 .ampdu_action
= mt7925_ampdu_action
,
2115 .set_rts_threshold
= mt7925_set_rts_threshold
,
2116 .wake_tx_queue
= mt76_wake_tx_queue
,
2117 .release_buffered_frames
= mt76_release_buffered_frames
,
2118 .channel_switch_beacon
= mt7925_channel_switch_beacon
,
2119 .get_txpower
= mt76_get_txpower
,
2120 .get_stats
= mt792x_get_stats
,
2121 .get_et_sset_count
= mt792x_get_et_sset_count
,
2122 .get_et_strings
= mt792x_get_et_strings
,
2123 .get_et_stats
= mt792x_get_et_stats
,
2124 .get_tsf
= mt792x_get_tsf
,
2125 .set_tsf
= mt792x_set_tsf
,
2126 .get_survey
= mt76_get_survey
,
2127 .get_antenna
= mt76_get_antenna
,
2128 .set_antenna
= mt7925_set_antenna
,
2129 .set_coverage_class
= mt792x_set_coverage_class
,
2130 .hw_scan
= mt7925_hw_scan
,
2131 .cancel_hw_scan
= mt7925_cancel_hw_scan
,
2132 .sta_statistics
= mt792x_sta_statistics
,
2133 .sched_scan_start
= mt7925_start_sched_scan
,
2134 .sched_scan_stop
= mt7925_stop_sched_scan
,
2136 .suspend
= mt7925_suspend
,
2137 .resume
= mt7925_resume
,
2138 .set_wakeup
= mt792x_set_wakeup
,
2139 .set_rekey_data
= mt7925_set_rekey_data
,
2140 #endif /* CONFIG_PM */
2141 .flush
= mt792x_flush
,
2142 .set_sar_specs
= mt7925_set_sar_specs
,
2143 .remain_on_channel
= mt7925_remain_on_channel
,
2144 .cancel_remain_on_channel
= mt7925_cancel_remain_on_channel
,
2145 .add_chanctx
= mt7925_add_chanctx
,
2146 .remove_chanctx
= mt7925_remove_chanctx
,
2147 .change_chanctx
= mt7925_change_chanctx
,
2148 .assign_vif_chanctx
= mt7925_assign_vif_chanctx
,
2149 .unassign_vif_chanctx
= mt7925_unassign_vif_chanctx
,
2150 .mgd_prepare_tx
= mt7925_mgd_prepare_tx
,
2151 .mgd_complete_tx
= mt7925_mgd_complete_tx
,
2152 .vif_cfg_changed
= mt7925_vif_cfg_changed
,
2153 .link_info_changed
= mt7925_link_info_changed
,
2154 .change_vif_links
= mt7925_change_vif_links
,
2155 .change_sta_links
= mt7925_change_sta_links
,
2157 EXPORT_SYMBOL_GPL(mt7925_ops
);
2159 MODULE_AUTHOR("Deren Wu <deren.wu@mediatek.com>");
2160 MODULE_DESCRIPTION("MediaTek MT7925 core driver");
2161 MODULE_LICENSE("Dual BSD/GPL");