xref: /linux/drivers/net/wireless/mediatek/mt76/mt7925/main.c (revision cbf5e61da66028ea30b52515dc1f1af969589bf7)
1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2023 MediaTek Inc. */
3 
4 #include <linux/etherdevice.h>
5 #include <linux/platform_device.h>
6 #include <linux/pci.h>
7 #include <linux/module.h>
8 #include <linux/ctype.h>
9 #include <net/ipv6.h>
10 #include "mt7925.h"
11 #include "mcu.h"
12 #include "mac.h"
13 
14 static void
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)
18 {
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);
23 	u16 mcs_map = 0;
24 
25 	for (i = 0; i < 8; i++) {
26 		if (i < nss)
27 			mcs_map |= (IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2));
28 		else
29 			mcs_map |= (IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
30 	}
31 
32 	he_cap->has_he = true;
33 
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;
38 
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;
42 	else
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;
46 
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;
55 
56 	switch (iftype) {
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;
73 		break;
74 	case NL80211_IFTYPE_STATION:
75 		he_cap_elem->mac_cap_info[1] |=
76 			IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US;
77 
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;
81 		else
82 			he_cap_elem->phy_cap_info[0] |=
83 				IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G;
84 
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;
119 		break;
120 	default:
121 		break;
122 	}
123 
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);
128 
129 	memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
130 
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);
134 	} else {
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);
138 	}
139 
140 	if (band == NL80211_BAND_6GHZ) {
141 		u16 cap = IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS |
142 			  IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS;
143 
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);
150 
151 		data->he_6ghz_capa.capa = cpu_to_le16(cap);
152 	}
153 }
154 
155 static void
156 mt7925_init_eht_caps(struct mt792x_phy *phy, enum nl80211_band band,
157 		     struct ieee80211_sband_iftype_data *data)
158 {
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);
165 	u8 val;
166 
167 	if (!phy->dev->has_eht)
168 		return;
169 
170 	eht_cap->has_eht = true;
171 
172 	eht_cap_elem->mac_cap_info[0] =
173 		IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
174 		IEEE80211_EHT_MAC_CAP0_OM_CONTROL;
175 
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;
180 
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);
184 
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);
190 
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);
194 
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;
203 
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);
207 
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);
214 
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);
221 
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;
227 
228 	val = u8_encode_bits(nss, IEEE80211_EHT_MCS_NSS_RX) |
229 	      u8_encode_bits(nss, IEEE80211_EHT_MCS_NSS_TX);
230 
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;
237 }
238 
239 int mt7925_init_mlo_caps(struct mt792x_phy *phy)
240 {
241 	struct wiphy *wiphy = phy->mt76->hw->wiphy;
242 	static const u8 ext_capa_sta[] = {
243 		[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
244 	};
245 	static struct wiphy_iftype_ext_capab ext_capab[] = {
246 		{
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),
251 		},
252 	};
253 
254 	if (!(phy->chip_cap & MT792x_CHIP_CAP_MLO_EVT_EN))
255 		return 0;
256 
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);
260 
261 	wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO;
262 	wiphy->iftype_ext_capab = ext_capab;
263 	wiphy->num_iftype_ext_capab = ARRAY_SIZE(ext_capab);
264 
265 	return 0;
266 }
267 
268 static void
269 __mt7925_set_stream_he_eht_caps(struct mt792x_phy *phy,
270 				struct ieee80211_supported_band *sband,
271 				enum nl80211_band band)
272 {
273 	struct ieee80211_sband_iftype_data *data = phy->iftype[band];
274 	int i, n = 0;
275 
276 	for (i = 0; i < NUM_NL80211_IFTYPES; i++) {
277 		switch (i) {
278 		case NL80211_IFTYPE_STATION:
279 		case NL80211_IFTYPE_AP:
280 			break;
281 		default:
282 			continue;
283 		}
284 
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]);
288 
289 		n++;
290 	}
291 
292 	_ieee80211_set_sband_iftype_data(sband, data, n);
293 }
294 
295 void mt7925_set_stream_he_eht_caps(struct mt792x_phy *phy)
296 {
297 	if (phy->mt76->cap.has_2ghz)
298 		__mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_2g.sband,
299 						NL80211_BAND_2GHZ);
300 
301 	if (phy->mt76->cap.has_5ghz)
302 		__mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_5g.sband,
303 						NL80211_BAND_5GHZ);
304 
305 	if (phy->mt76->cap.has_6ghz)
306 		__mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_6g.sband,
307 						NL80211_BAND_6GHZ);
308 }
309 
310 int __mt7925_start(struct mt792x_phy *phy)
311 {
312 	struct mt76_phy *mphy = phy->mt76;
313 	int err;
314 
315 	err = mt7925_mcu_set_channel_domain(mphy);
316 	if (err)
317 		return err;
318 
319 	err = mt7925_mcu_set_rts_thresh(phy, 0x92b);
320 	if (err)
321 		return err;
322 
323 	err = mt7925_set_tx_sar_pwr(mphy->hw, NULL);
324 	if (err)
325 		return err;
326 
327 	mt792x_mac_reset_counters(phy);
328 	set_bit(MT76_STATE_RUNNING, &mphy->state);
329 
330 	ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
331 				     MT792x_WATCHDOG_TIME);
332 
333 	return 0;
334 }
335 EXPORT_SYMBOL_GPL(__mt7925_start);
336 
337 static int mt7925_start(struct ieee80211_hw *hw)
338 {
339 	struct mt792x_phy *phy = mt792x_hw_phy(hw);
340 	int err;
341 
342 	mt792x_mutex_acquire(phy->dev);
343 	err = __mt7925_start(phy);
344 	mt792x_mutex_release(phy->dev);
345 
346 	return err;
347 }
348 
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)
352 {
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;
357 	int idx, ret = 0;
358 
359 	mconf->mt76.idx = __ffs64(~dev->mt76.vif_mask);
360 	if (mconf->mt76.idx >= MT792x_MAX_INTERFACES) {
361 		ret = -ENOSPC;
362 		goto out;
363 	}
364 
365 	mconf->mt76.omac_idx = ieee80211_vif_is_mld(vif) ?
366 			       0 : mconf->mt76.idx;
367 	mconf->mt76.band_idx = 0xff;
368 	mconf->mt76.wmm_idx = ieee80211_vif_is_mld(vif) ?
369 			      0 : mconf->mt76.idx % MT76_CONNAC_MAX_WMM_SETS;
370 
371 	if (mvif->phy->mt76->chandef.chan->band != NL80211_BAND_2GHZ)
372 		mconf->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL + 4;
373 	else
374 		mconf->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL;
375 
376 	dev->mt76.vif_mask |= BIT_ULL(mconf->mt76.idx);
377 	mvif->phy->omac_mask |= BIT_ULL(mconf->mt76.omac_idx);
378 
379 	idx = MT792x_WTBL_RESERVED - mconf->mt76.idx;
380 
381 	mlink->wcid.idx = idx;
382 	mlink->wcid.tx_info |= MT_WCID_TX_INFO_SET;
383 	mt76_wcid_init(&mlink->wcid, 0);
384 
385 	mt7925_mac_wtbl_update(dev, idx,
386 			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
387 
388 	ewma_rssi_init(&mconf->rssi);
389 
390 	rcu_assign_pointer(dev->mt76.wcid[idx], &mlink->wcid);
391 
392 	ret = mt76_connac_mcu_uni_add_dev(&dev->mphy, link_conf, &mconf->mt76,
393 					  &mlink->wcid, true);
394 	if (ret)
395 		goto out;
396 
397 	if (vif->txq) {
398 		mtxq = (struct mt76_txq *)vif->txq->drv_priv;
399 		mtxq->wcid = idx;
400 	}
401 
402 out:
403 	return ret;
404 }
405 
406 static int
407 mt7925_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
408 {
409 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
410 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
411 	struct mt792x_phy *phy = mt792x_hw_phy(hw);
412 	int ret = 0;
413 
414 	mt792x_mutex_acquire(dev);
415 
416 	mvif->phy = phy;
417 	mvif->bss_conf.vif = mvif;
418 	mvif->sta.vif = mvif;
419 	mvif->deflink_id = IEEE80211_LINK_UNSPECIFIED;
420 
421 	ret = mt7925_mac_link_bss_add(dev, &vif->bss_conf, &mvif->sta.deflink);
422 	if (ret < 0)
423 		goto out;
424 
425 	vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
426 out:
427 	mt792x_mutex_release(dev);
428 
429 	return ret;
430 }
431 
432 static void mt7925_roc_iter(void *priv, u8 *mac,
433 			    struct ieee80211_vif *vif)
434 {
435 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
436 	struct mt792x_phy *phy = priv;
437 
438 	mt7925_mcu_abort_roc(phy, &mvif->bss_conf, phy->roc_token_id);
439 }
440 
441 void mt7925_roc_abort_sync(struct mt792x_dev *dev)
442 {
443 	struct mt792x_phy *phy = &dev->phy;
444 
445 	del_timer_sync(&phy->roc_timer);
446 	cancel_work_sync(&phy->roc_work);
447 	if (test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
448 		ieee80211_iterate_interfaces(mt76_hw(dev),
449 					     IEEE80211_IFACE_ITER_RESUME_ALL,
450 					     mt7925_roc_iter, (void *)phy);
451 }
452 EXPORT_SYMBOL_GPL(mt7925_roc_abort_sync);
453 
454 void mt7925_roc_work(struct work_struct *work)
455 {
456 	struct mt792x_phy *phy;
457 
458 	phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy,
459 						roc_work);
460 
461 	if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
462 		return;
463 
464 	mt792x_mutex_acquire(phy->dev);
465 	ieee80211_iterate_active_interfaces(phy->mt76->hw,
466 					    IEEE80211_IFACE_ITER_RESUME_ALL,
467 					    mt7925_roc_iter, phy);
468 	mt792x_mutex_release(phy->dev);
469 	ieee80211_remain_on_channel_expired(phy->mt76->hw);
470 }
471 
472 static int mt7925_abort_roc(struct mt792x_phy *phy,
473 			    struct mt792x_bss_conf *mconf)
474 {
475 	int err = 0;
476 
477 	del_timer_sync(&phy->roc_timer);
478 	cancel_work_sync(&phy->roc_work);
479 
480 	mt792x_mutex_acquire(phy->dev);
481 	if (test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
482 		err = mt7925_mcu_abort_roc(phy, mconf, phy->roc_token_id);
483 	mt792x_mutex_release(phy->dev);
484 
485 	return err;
486 }
487 
488 static int mt7925_set_roc(struct mt792x_phy *phy,
489 			  struct mt792x_bss_conf *mconf,
490 			  struct ieee80211_channel *chan,
491 			  int duration,
492 			  enum mt7925_roc_req type)
493 {
494 	int err;
495 
496 	if (test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state))
497 		return -EBUSY;
498 
499 	phy->roc_grant = false;
500 
501 	err = mt7925_mcu_set_roc(phy, mconf, chan, duration, type,
502 				 ++phy->roc_token_id);
503 	if (err < 0) {
504 		clear_bit(MT76_STATE_ROC, &phy->mt76->state);
505 		goto out;
506 	}
507 
508 	if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, 4 * HZ)) {
509 		mt7925_mcu_abort_roc(phy, mconf, phy->roc_token_id);
510 		clear_bit(MT76_STATE_ROC, &phy->mt76->state);
511 		err = -ETIMEDOUT;
512 	}
513 
514 out:
515 	return err;
516 }
517 
518 static int mt7925_set_mlo_roc(struct mt792x_phy *phy,
519 			      struct mt792x_bss_conf *mconf,
520 			      u16 sel_links)
521 {
522 	int err;
523 
524 	if (WARN_ON_ONCE(test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state)))
525 		return -EBUSY;
526 
527 	phy->roc_grant = false;
528 
529 	err = mt7925_mcu_set_mlo_roc(mconf, sel_links, 5, ++phy->roc_token_id);
530 	if (err < 0) {
531 		clear_bit(MT76_STATE_ROC, &phy->mt76->state);
532 		goto out;
533 	}
534 
535 	if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, 4 * HZ)) {
536 		mt7925_mcu_abort_roc(phy, mconf, phy->roc_token_id);
537 		clear_bit(MT76_STATE_ROC, &phy->mt76->state);
538 		err = -ETIMEDOUT;
539 	}
540 
541 out:
542 	return err;
543 }
544 
545 static int mt7925_remain_on_channel(struct ieee80211_hw *hw,
546 				    struct ieee80211_vif *vif,
547 				    struct ieee80211_channel *chan,
548 				    int duration,
549 				    enum ieee80211_roc_type type)
550 {
551 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
552 	struct mt792x_phy *phy = mt792x_hw_phy(hw);
553 	int err;
554 
555 	mt792x_mutex_acquire(phy->dev);
556 	err = mt7925_set_roc(phy, &mvif->bss_conf,
557 			     chan, duration, MT7925_ROC_REQ_ROC);
558 	mt792x_mutex_release(phy->dev);
559 
560 	return err;
561 }
562 
563 static int mt7925_cancel_remain_on_channel(struct ieee80211_hw *hw,
564 					   struct ieee80211_vif *vif)
565 {
566 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
567 	struct mt792x_phy *phy = mt792x_hw_phy(hw);
568 
569 	return mt7925_abort_roc(phy, &mvif->bss_conf);
570 }
571 
572 static int mt7925_set_link_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
573 			       struct ieee80211_vif *vif, struct ieee80211_sta *sta,
574 			       struct ieee80211_key_conf *key, int link_id)
575 {
576 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
577 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
578 	struct mt792x_sta *msta = sta ? (struct mt792x_sta *)sta->drv_priv :
579 				  &mvif->sta;
580 	struct ieee80211_bss_conf *link_conf;
581 	struct ieee80211_link_sta *link_sta;
582 	int idx = key->keyidx, err = 0;
583 	struct mt792x_link_sta *mlink;
584 	struct mt792x_bss_conf *mconf;
585 	struct mt76_wcid *wcid;
586 	u8 *wcid_keyidx;
587 
588 	link_conf = mt792x_vif_to_bss_conf(vif, link_id);
589 	link_sta = sta ? mt792x_sta_to_link_sta(vif, sta, link_id) : NULL;
590 	mconf = mt792x_vif_to_link(mvif, link_id);
591 	mlink = mt792x_sta_to_link(msta, link_id);
592 	wcid = &mlink->wcid;
593 	wcid_keyidx = &wcid->hw_key_idx;
594 
595 	/* fall back to sw encryption for unsupported ciphers */
596 	switch (key->cipher) {
597 	case WLAN_CIPHER_SUITE_AES_CMAC:
598 		key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
599 		wcid_keyidx = &wcid->hw_key_idx2;
600 		break;
601 	case WLAN_CIPHER_SUITE_WEP40:
602 	case WLAN_CIPHER_SUITE_WEP104:
603 		if (!mvif->wep_sta)
604 			return -EOPNOTSUPP;
605 		break;
606 	case WLAN_CIPHER_SUITE_TKIP:
607 	case WLAN_CIPHER_SUITE_CCMP:
608 	case WLAN_CIPHER_SUITE_CCMP_256:
609 	case WLAN_CIPHER_SUITE_GCMP:
610 	case WLAN_CIPHER_SUITE_GCMP_256:
611 	case WLAN_CIPHER_SUITE_SMS4:
612 		break;
613 	default:
614 		return -EOPNOTSUPP;
615 	}
616 
617 	if (cmd == SET_KEY && !mconf->mt76.cipher) {
618 		struct mt792x_phy *phy = mt792x_hw_phy(hw);
619 
620 		mconf->mt76.cipher = mt7925_mcu_get_cipher(key->cipher);
621 		mt7925_mcu_add_bss_info(phy, mconf->mt76.ctx, link_conf,
622 					link_sta, true);
623 	}
624 
625 	if (cmd == SET_KEY)
626 		*wcid_keyidx = idx;
627 	else if (idx == *wcid_keyidx)
628 		*wcid_keyidx = -1;
629 	else
630 		goto out;
631 
632 	mt76_wcid_key_setup(&dev->mt76, wcid,
633 			    cmd == SET_KEY ? key : NULL);
634 
635 	err = mt7925_mcu_add_key(&dev->mt76, vif, &mlink->bip,
636 				 key, MCU_UNI_CMD(STA_REC_UPDATE),
637 				 &mlink->wcid, cmd, msta);
638 
639 	if (err)
640 		goto out;
641 
642 	if (key->cipher == WLAN_CIPHER_SUITE_WEP104 ||
643 	    key->cipher == WLAN_CIPHER_SUITE_WEP40)
644 		err = mt7925_mcu_add_key(&dev->mt76, vif, &mvif->wep_sta->deflink.bip,
645 					 key, MCU_WMWA_UNI_CMD(STA_REC_UPDATE),
646 					 &mvif->wep_sta->deflink.wcid, cmd, msta);
647 out:
648 	return err;
649 }
650 
651 static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
652 			  struct ieee80211_vif *vif, struct ieee80211_sta *sta,
653 			  struct ieee80211_key_conf *key)
654 {
655 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
656 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
657 	struct mt792x_sta *msta = sta ? (struct mt792x_sta *)sta->drv_priv :
658 				  &mvif->sta;
659 	int err;
660 
661 	/* The hardware does not support per-STA RX GTK, fallback
662 	 * to software mode for these.
663 	 */
664 	if ((vif->type == NL80211_IFTYPE_ADHOC ||
665 	     vif->type == NL80211_IFTYPE_MESH_POINT) &&
666 	    (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
667 	     key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
668 	    !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
669 		return -EOPNOTSUPP;
670 
671 	mt792x_mutex_acquire(dev);
672 
673 	if (ieee80211_vif_is_mld(vif)) {
674 		unsigned int link_id;
675 		unsigned long add;
676 
677 		add = key->link_id != -1 ? BIT(key->link_id) : msta->valid_links;
678 
679 		for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
680 			err = mt7925_set_link_key(hw, cmd, vif, sta, key, link_id);
681 			if (err < 0)
682 				break;
683 		}
684 	} else {
685 		err = mt7925_set_link_key(hw, cmd, vif, sta, key, vif->bss_conf.link_id);
686 	}
687 
688 	mt792x_mutex_release(dev);
689 
690 	return err;
691 }
692 
693 static void
694 mt7925_pm_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
695 {
696 	struct mt792x_dev *dev = priv;
697 	struct ieee80211_hw *hw = mt76_hw(dev);
698 	bool pm_enable = dev->pm.enable;
699 	int err;
700 
701 	err = mt7925_mcu_set_beacon_filter(dev, vif, pm_enable);
702 	if (err < 0)
703 		return;
704 
705 	if (pm_enable) {
706 		vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
707 		ieee80211_hw_set(hw, CONNECTION_MONITOR);
708 	} else {
709 		vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
710 		__clear_bit(IEEE80211_HW_CONNECTION_MONITOR, hw->flags);
711 	}
712 }
713 
714 static void
715 mt7925_sniffer_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
716 {
717 	struct mt792x_dev *dev = priv;
718 	struct ieee80211_hw *hw = mt76_hw(dev);
719 	struct mt76_connac_pm *pm = &dev->pm;
720 	bool monitor = !!(hw->conf.flags & IEEE80211_CONF_MONITOR);
721 
722 	mt7925_mcu_set_sniffer(dev, vif, monitor);
723 	pm->enable = pm->enable_user && !monitor;
724 	pm->ds_enable = pm->ds_enable_user && !monitor;
725 
726 	mt7925_mcu_set_deep_sleep(dev, pm->ds_enable);
727 
728 	if (monitor)
729 		mt7925_mcu_set_beacon_filter(dev, vif, false);
730 }
731 
732 void mt7925_set_runtime_pm(struct mt792x_dev *dev)
733 {
734 	struct ieee80211_hw *hw = mt76_hw(dev);
735 	struct mt76_connac_pm *pm = &dev->pm;
736 	bool monitor = !!(hw->conf.flags & IEEE80211_CONF_MONITOR);
737 
738 	pm->enable = pm->enable_user && !monitor;
739 	ieee80211_iterate_active_interfaces(hw,
740 					    IEEE80211_IFACE_ITER_RESUME_ALL,
741 					    mt7925_pm_interface_iter, dev);
742 	pm->ds_enable = pm->ds_enable_user && !monitor;
743 	mt7925_mcu_set_deep_sleep(dev, pm->ds_enable);
744 }
745 
746 static int mt7925_config(struct ieee80211_hw *hw, u32 changed)
747 {
748 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
749 	int ret = 0;
750 
751 	mt792x_mutex_acquire(dev);
752 
753 	if (changed & IEEE80211_CONF_CHANGE_POWER) {
754 		ret = mt7925_set_tx_sar_pwr(hw, NULL);
755 		if (ret)
756 			goto out;
757 	}
758 
759 	if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
760 		ieee80211_iterate_active_interfaces(hw,
761 						    IEEE80211_IFACE_ITER_RESUME_ALL,
762 						    mt7925_sniffer_interface_iter, dev);
763 	}
764 
765 out:
766 	mt792x_mutex_release(dev);
767 
768 	return ret;
769 }
770 
771 static void mt7925_configure_filter(struct ieee80211_hw *hw,
772 				    unsigned int changed_flags,
773 				    unsigned int *total_flags,
774 				    u64 multicast)
775 {
776 #define MT7925_FILTER_FCSFAIL    BIT(2)
777 #define MT7925_FILTER_CONTROL    BIT(5)
778 #define MT7925_FILTER_OTHER_BSS  BIT(6)
779 #define MT7925_FILTER_ENABLE     BIT(31)
780 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
781 	u32 flags = MT7925_FILTER_ENABLE;
782 
783 #define MT7925_FILTER(_fif, _type) do {			\
784 		if (*total_flags & (_fif))		\
785 			flags |= MT7925_FILTER_##_type;	\
786 	} while (0)
787 
788 	MT7925_FILTER(FIF_FCSFAIL, FCSFAIL);
789 	MT7925_FILTER(FIF_CONTROL, CONTROL);
790 	MT7925_FILTER(FIF_OTHER_BSS, OTHER_BSS);
791 
792 	mt792x_mutex_acquire(dev);
793 	mt7925_mcu_set_rxfilter(dev, flags, 0, 0);
794 	mt792x_mutex_release(dev);
795 
796 	*total_flags &= (FIF_OTHER_BSS | FIF_FCSFAIL | FIF_CONTROL);
797 }
798 
799 static u8
800 mt7925_get_rates_table(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
801 		       bool beacon, bool mcast)
802 {
803 	struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv;
804 	struct mt76_phy *mphy = hw->priv;
805 	u16 rate;
806 	u8 i, idx, ht;
807 
808 	rate = mt76_connac2_mac_tx_rate_val(mphy, vif, beacon, mcast);
809 	ht = FIELD_GET(MT_TX_RATE_MODE, rate) > MT_PHY_TYPE_OFDM;
810 
811 	if (beacon && ht) {
812 		struct mt792x_dev *dev = mt792x_hw_dev(hw);
813 
814 		/* must odd index */
815 		idx = MT7925_BEACON_RATES_TBL + 2 * (mvif->idx % 20);
816 		mt7925_mac_set_fixed_rate_table(dev, idx, rate);
817 		return idx;
818 	}
819 
820 	idx = FIELD_GET(MT_TX_RATE_IDX, rate);
821 	for (i = 0; i < ARRAY_SIZE(mt76_rates); i++)
822 		if ((mt76_rates[i].hw_value & GENMASK(7, 0)) == idx)
823 			return MT792x_BASIC_RATES_TBL + i;
824 
825 	return mvif->basic_rates_idx;
826 }
827 
828 static int mt7925_mac_link_sta_add(struct mt76_dev *mdev,
829 				   struct ieee80211_vif *vif,
830 				   struct ieee80211_link_sta *link_sta)
831 {
832 	struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
833 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
834 	struct ieee80211_bss_conf *link_conf;
835 	struct mt792x_bss_conf *mconf;
836 	u8 link_id = link_sta->link_id;
837 	struct mt792x_link_sta *mlink;
838 	struct mt792x_sta *msta;
839 	struct mt76_wcid *wcid;
840 	int ret, idx;
841 
842 	msta = (struct mt792x_sta *)link_sta->sta->drv_priv;
843 	mlink = mt792x_sta_to_link(msta, link_id);
844 
845 	idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT792x_WTBL_STA - 1);
846 	if (idx < 0)
847 		return -ENOSPC;
848 
849 	mconf = mt792x_vif_to_link(mvif, link_id);
850 	mt76_wcid_init(&mlink->wcid, 0);
851 	mlink->wcid.sta = 1;
852 	mlink->wcid.idx = idx;
853 	mlink->wcid.tx_info |= MT_WCID_TX_INFO_SET;
854 	mlink->last_txs = jiffies;
855 	mlink->wcid.link_id = link_sta->link_id;
856 	mlink->wcid.link_valid = !!link_sta->sta->valid_links;
857 	mlink->sta = msta;
858 
859 	wcid = &mlink->wcid;
860 	ewma_signal_init(&wcid->rssi);
861 	rcu_assign_pointer(dev->mt76.wcid[wcid->idx], wcid);
862 	mt76_wcid_init(wcid, 0);
863 	ewma_avg_signal_init(&mlink->avg_ack_signal);
864 	memset(mlink->airtime_ac, 0,
865 	       sizeof(msta->deflink.airtime_ac));
866 
867 	ret = mt76_connac_pm_wake(&dev->mphy, &dev->pm);
868 	if (ret)
869 		return ret;
870 
871 	mt7925_mac_wtbl_update(dev, idx,
872 			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
873 
874 	link_conf = mt792x_vif_to_bss_conf(vif, link_id);
875 
876 	/* should update bss info before STA add */
877 	if (vif->type == NL80211_IFTYPE_STATION && !link_sta->sta->tdls) {
878 		if (ieee80211_vif_is_mld(vif))
879 			mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx,
880 						link_conf, link_sta, link_sta != mlink->pri_link);
881 		else
882 			mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx,
883 						link_conf, link_sta, false);
884 	}
885 
886 	if (ieee80211_vif_is_mld(vif) &&
887 	    link_sta == mlink->pri_link) {
888 		ret = mt7925_mcu_sta_update(dev, link_sta, vif, true,
889 					    MT76_STA_INFO_STATE_NONE);
890 		if (ret)
891 			return ret;
892 	} else if (ieee80211_vif_is_mld(vif) &&
893 		   link_sta != mlink->pri_link) {
894 		ret = mt7925_mcu_sta_update(dev, mlink->pri_link, vif,
895 					    true, MT76_STA_INFO_STATE_ASSOC);
896 		if (ret)
897 			return ret;
898 
899 		ret = mt7925_mcu_sta_update(dev, link_sta, vif, true,
900 					    MT76_STA_INFO_STATE_ASSOC);
901 		if (ret)
902 			return ret;
903 	} else {
904 		ret = mt7925_mcu_sta_update(dev, link_sta, vif, true,
905 					    MT76_STA_INFO_STATE_NONE);
906 		if (ret)
907 			return ret;
908 	}
909 
910 	mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
911 
912 	return 0;
913 }
914 
915 static int
916 mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
917 			 struct ieee80211_sta *sta, unsigned long new_links)
918 {
919 	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
920 	unsigned int link_id;
921 	int err = 0;
922 
923 	for_each_set_bit(link_id, &new_links, IEEE80211_MLD_MAX_NUM_LINKS) {
924 		struct ieee80211_link_sta *link_sta;
925 		struct mt792x_link_sta *mlink;
926 
927 		if (msta->deflink_id == IEEE80211_LINK_UNSPECIFIED) {
928 			mlink = &msta->deflink;
929 			msta->deflink_id = link_id;
930 		} else {
931 			mlink = devm_kzalloc(dev->mt76.dev, sizeof(*mlink), GFP_KERNEL);
932 			if (!mlink) {
933 				err = -ENOMEM;
934 				break;
935 			}
936 		}
937 
938 		msta->valid_links |= BIT(link_id);
939 		rcu_assign_pointer(msta->link[link_id], mlink);
940 		mlink->sta = msta;
941 		mlink->pri_link = &sta->deflink;
942 		mlink->wcid.def_wcid = &msta->deflink.wcid;
943 
944 		link_sta = mt792x_sta_to_link_sta(vif, sta, link_id);
945 		mt7925_mac_link_sta_add(&dev->mt76, vif, link_sta);
946 	}
947 
948 	return err;
949 }
950 
951 int mt7925_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
952 		       struct ieee80211_sta *sta)
953 {
954 	struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
955 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
956 	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
957 	int err;
958 
959 	msta->vif = mvif;
960 
961 	if (vif->type == NL80211_IFTYPE_STATION)
962 		mvif->wep_sta = msta;
963 
964 	if (ieee80211_vif_is_mld(vif)) {
965 		msta->deflink_id = IEEE80211_LINK_UNSPECIFIED;
966 
967 		err = mt7925_mac_sta_add_links(dev, vif, sta, sta->valid_links);
968 	} else {
969 		err = mt7925_mac_link_sta_add(mdev, vif, &sta->deflink);
970 	}
971 
972 	return err;
973 }
974 EXPORT_SYMBOL_GPL(mt7925_mac_sta_add);
975 
976 static u16
977 mt7925_mac_select_links(struct mt76_dev *mdev, struct ieee80211_vif *vif)
978 {
979 	unsigned long usable_links = ieee80211_vif_usable_links(vif);
980 	struct  {
981 		u8 link_id;
982 		enum nl80211_band band;
983 	} data[IEEE80211_MLD_MAX_NUM_LINKS];
984 	u8 link_id, i, j, n_data = 0;
985 	u16 sel_links = 0;
986 
987 	if (!ieee80211_vif_is_mld(vif))
988 		return 0;
989 
990 	if (vif->active_links == usable_links)
991 		return vif->active_links;
992 
993 	rcu_read_lock();
994 	for_each_set_bit(link_id, &usable_links, IEEE80211_MLD_MAX_NUM_LINKS) {
995 		struct ieee80211_bss_conf *link_conf =
996 			rcu_dereference(vif->link_conf[link_id]);
997 
998 		if (WARN_ON_ONCE(!link_conf))
999 			continue;
1000 
1001 		data[n_data].link_id = link_id;
1002 		data[n_data].band = link_conf->chanreq.oper.chan->band;
1003 		n_data++;
1004 	}
1005 	rcu_read_unlock();
1006 
1007 	for (i = 0; i < n_data; i++) {
1008 		if (!(BIT(data[i].link_id) & vif->active_links))
1009 			continue;
1010 
1011 		sel_links = BIT(data[i].link_id);
1012 
1013 		for (j = 0; j < n_data; j++) {
1014 			if (data[i].band != data[j].band) {
1015 				sel_links |= BIT(data[j].link_id);
1016 				break;
1017 			}
1018 		}
1019 
1020 		break;
1021 	}
1022 
1023 	return sel_links;
1024 }
1025 
1026 static void
1027 mt7925_mac_set_links(struct mt76_dev *mdev, struct ieee80211_vif *vif)
1028 {
1029 	struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
1030 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1031 	struct ieee80211_bss_conf *link_conf =
1032 		mt792x_vif_to_bss_conf(vif, mvif->deflink_id);
1033 	struct cfg80211_chan_def *chandef = &link_conf->chanreq.oper;
1034 	enum nl80211_band band = chandef->chan->band, secondary_band;
1035 
1036 	u16 sel_links = mt7925_mac_select_links(mdev, vif);
1037 	u8 secondary_link_id = __ffs(~BIT(mvif->deflink_id) & sel_links);
1038 
1039 	if (!ieee80211_vif_is_mld(vif) || hweight16(sel_links) < 2)
1040 		return;
1041 
1042 	link_conf = mt792x_vif_to_bss_conf(vif, secondary_link_id);
1043 	secondary_band = link_conf->chanreq.oper.chan->band;
1044 
1045 	if (band == NL80211_BAND_2GHZ ||
1046 	    (band == NL80211_BAND_5GHZ && secondary_band == NL80211_BAND_6GHZ)) {
1047 		mt7925_abort_roc(mvif->phy, &mvif->bss_conf);
1048 
1049 		mt792x_mutex_acquire(dev);
1050 
1051 		mt7925_set_mlo_roc(mvif->phy, &mvif->bss_conf, sel_links);
1052 
1053 		mt792x_mutex_release(dev);
1054 	}
1055 
1056 	ieee80211_set_active_links_async(vif, sel_links);
1057 }
1058 
1059 static void mt7925_mac_link_sta_assoc(struct mt76_dev *mdev,
1060 				      struct ieee80211_vif *vif,
1061 				      struct ieee80211_link_sta *link_sta)
1062 {
1063 	struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
1064 	struct ieee80211_bss_conf *link_conf;
1065 	struct mt792x_link_sta *mlink;
1066 	struct mt792x_sta *msta;
1067 
1068 	msta = (struct mt792x_sta *)link_sta->sta->drv_priv;
1069 	mlink = mt792x_sta_to_link(msta, link_sta->link_id);
1070 
1071 	mt792x_mutex_acquire(dev);
1072 
1073 	if (ieee80211_vif_is_mld(vif)) {
1074 		link_conf = mt792x_vif_to_bss_conf(vif, msta->deflink_id);
1075 	} else {
1076 		link_conf = mt792x_vif_to_bss_conf(vif, vif->bss_conf.link_id);
1077 	}
1078 
1079 	if (vif->type == NL80211_IFTYPE_STATION && !link_sta->sta->tdls) {
1080 		struct mt792x_bss_conf *mconf;
1081 
1082 		mconf = mt792x_link_conf_to_mconf(link_conf);
1083 		mt7925_mcu_add_bss_info(&dev->phy, mconf->mt76.ctx,
1084 					link_conf, link_sta, true);
1085 	}
1086 
1087 	ewma_avg_signal_init(&mlink->avg_ack_signal);
1088 
1089 	mt7925_mac_wtbl_update(dev, mlink->wcid.idx,
1090 			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
1091 	memset(mlink->airtime_ac, 0, sizeof(mlink->airtime_ac));
1092 
1093 	mt7925_mcu_sta_update(dev, link_sta, vif, true, MT76_STA_INFO_STATE_ASSOC);
1094 
1095 	mt792x_mutex_release(dev);
1096 }
1097 
1098 int mt7925_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif,
1099 			 struct ieee80211_sta *sta, enum mt76_sta_event ev)
1100 {
1101 	struct ieee80211_link_sta *link_sta = &sta->deflink;
1102 
1103 	if (ev != MT76_STA_EVENT_ASSOC)
1104 		return 0;
1105 
1106 	if (ieee80211_vif_is_mld(vif)) {
1107 		struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
1108 
1109 		link_sta = mt792x_sta_to_link_sta(vif, sta, msta->deflink_id);
1110 		mt7925_mac_set_links(mdev, vif);
1111 	}
1112 
1113 	mt7925_mac_link_sta_assoc(mdev, vif, link_sta);
1114 
1115 	return 0;
1116 }
1117 EXPORT_SYMBOL_GPL(mt7925_mac_sta_event);
1118 
1119 static void mt7925_mac_link_sta_remove(struct mt76_dev *mdev,
1120 				       struct ieee80211_vif *vif,
1121 				       struct ieee80211_link_sta *link_sta)
1122 {
1123 	struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
1124 	struct ieee80211_bss_conf *link_conf;
1125 	u8 link_id = link_sta->link_id;
1126 	struct mt792x_link_sta *mlink;
1127 	struct mt792x_sta *msta;
1128 
1129 	msta = (struct mt792x_sta *)link_sta->sta->drv_priv;
1130 	mlink = mt792x_sta_to_link(msta, link_id);
1131 
1132 	mt7925_roc_abort_sync(dev);
1133 
1134 	mt76_connac_free_pending_tx_skbs(&dev->pm, &mlink->wcid);
1135 	mt76_connac_pm_wake(&dev->mphy, &dev->pm);
1136 
1137 	mt7925_mcu_sta_update(dev, link_sta, vif, false,
1138 			      MT76_STA_INFO_STATE_NONE);
1139 	mt7925_mac_wtbl_update(dev, mlink->wcid.idx,
1140 			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
1141 
1142 	link_conf = mt792x_vif_to_bss_conf(vif, link_id);
1143 
1144 	if (vif->type == NL80211_IFTYPE_STATION && !link_sta->sta->tdls) {
1145 		struct mt792x_bss_conf *mconf;
1146 
1147 		mconf = mt792x_link_conf_to_mconf(link_conf);
1148 		mt792x_mac_link_bss_remove(dev, mconf, mlink);
1149 	}
1150 
1151 	spin_lock_bh(&mdev->sta_poll_lock);
1152 	if (!list_empty(&mlink->wcid.poll_list))
1153 		list_del_init(&mlink->wcid.poll_list);
1154 	spin_unlock_bh(&mdev->sta_poll_lock);
1155 
1156 	mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
1157 }
1158 
1159 static int
1160 mt7925_mac_sta_remove_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
1161 			    struct ieee80211_sta *sta, unsigned long old_links)
1162 {
1163 	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
1164 	struct mt76_dev *mdev = &dev->mt76;
1165 	struct mt76_wcid *wcid;
1166 	unsigned int link_id;
1167 
1168 	for_each_set_bit(link_id, &old_links, IEEE80211_MLD_MAX_NUM_LINKS) {
1169 		struct ieee80211_link_sta *link_sta;
1170 		struct mt792x_link_sta *mlink;
1171 
1172 		link_sta = mt792x_sta_to_link_sta(vif, sta, link_id);
1173 		if (!link_sta)
1174 			continue;
1175 
1176 		mlink = mt792x_sta_to_link(msta, link_id);
1177 		if (!mlink)
1178 			continue;
1179 
1180 		mt7925_mac_link_sta_remove(&dev->mt76, vif, link_sta);
1181 
1182 		wcid = &mlink->wcid;
1183 		rcu_assign_pointer(msta->link[link_id], NULL);
1184 		msta->valid_links &= ~BIT(link_id);
1185 		mlink->sta = NULL;
1186 		mlink->pri_link = NULL;
1187 
1188 		if (link_sta != mlink->pri_link) {
1189 			mt76_wcid_cleanup(mdev, wcid);
1190 			mt76_wcid_mask_clear(mdev->wcid_mask, wcid->idx);
1191 			mt76_wcid_mask_clear(mdev->wcid_phy_mask, wcid->idx);
1192 		}
1193 
1194 		if (msta->deflink_id == link_id)
1195 			msta->deflink_id = IEEE80211_LINK_UNSPECIFIED;
1196 	}
1197 
1198 	return 0;
1199 }
1200 
1201 void mt7925_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
1202 			   struct ieee80211_sta *sta)
1203 {
1204 	struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
1205 	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
1206 	struct {
1207 		struct {
1208 			u8 omac_idx;
1209 			u8 band_idx;
1210 			__le16 pad;
1211 		} __packed hdr;
1212 		struct req_tlv {
1213 			__le16 tag;
1214 			__le16 len;
1215 			u8 active;
1216 			u8 link_idx; /* hw link idx */
1217 			u8 omac_addr[ETH_ALEN];
1218 		} __packed tlv;
1219 	} dev_req = {
1220 		.hdr = {
1221 			.omac_idx = 0,
1222 			.band_idx = 0,
1223 		},
1224 		.tlv = {
1225 			.tag = cpu_to_le16(DEV_INFO_ACTIVE),
1226 			.len = cpu_to_le16(sizeof(struct req_tlv)),
1227 			.active = true,
1228 		},
1229 	};
1230 	unsigned long rem;
1231 
1232 	rem = ieee80211_vif_is_mld(vif) ? msta->valid_links : BIT(0);
1233 
1234 	mt7925_mac_sta_remove_links(dev, vif, sta, rem);
1235 
1236 	if (ieee80211_vif_is_mld(vif)) {
1237 		mt7925_mcu_set_dbdc(&dev->mphy, false);
1238 
1239 		/* recovery omac address for the legacy interface */
1240 		memcpy(dev_req.tlv.omac_addr, vif->addr, ETH_ALEN);
1241 		mt76_mcu_send_msg(mdev, MCU_UNI_CMD(DEV_INFO_UPDATE),
1242 				  &dev_req, sizeof(dev_req), true);
1243 	}
1244 
1245 	if (vif->type == NL80211_IFTYPE_STATION) {
1246 		struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1247 
1248 		mvif->wep_sta = NULL;
1249 		ewma_rssi_init(&mvif->bss_conf.rssi);
1250 	}
1251 }
1252 EXPORT_SYMBOL_GPL(mt7925_mac_sta_remove);
1253 
1254 static int mt7925_set_rts_threshold(struct ieee80211_hw *hw, u32 val)
1255 {
1256 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1257 
1258 	mt792x_mutex_acquire(dev);
1259 	mt7925_mcu_set_rts_thresh(&dev->phy, val);
1260 	mt792x_mutex_release(dev);
1261 
1262 	return 0;
1263 }
1264 
1265 static int
1266 mt7925_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1267 		    struct ieee80211_ampdu_params *params)
1268 {
1269 	enum ieee80211_ampdu_mlme_action action = params->action;
1270 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1271 	struct ieee80211_sta *sta = params->sta;
1272 	struct ieee80211_txq *txq = sta->txq[params->tid];
1273 	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
1274 	u16 tid = params->tid;
1275 	u16 ssn = params->ssn;
1276 	struct mt76_txq *mtxq;
1277 	int ret = 0;
1278 
1279 	if (!txq)
1280 		return -EINVAL;
1281 
1282 	mtxq = (struct mt76_txq *)txq->drv_priv;
1283 
1284 	mt792x_mutex_acquire(dev);
1285 	switch (action) {
1286 	case IEEE80211_AMPDU_RX_START:
1287 		mt76_rx_aggr_start(&dev->mt76, &msta->deflink.wcid, tid, ssn,
1288 				   params->buf_size);
1289 		mt7925_mcu_uni_rx_ba(dev, vif, params, true);
1290 		break;
1291 	case IEEE80211_AMPDU_RX_STOP:
1292 		mt76_rx_aggr_stop(&dev->mt76, &msta->deflink.wcid, tid);
1293 		mt7925_mcu_uni_rx_ba(dev, vif, params, false);
1294 		break;
1295 	case IEEE80211_AMPDU_TX_OPERATIONAL:
1296 		mtxq->aggr = true;
1297 		mtxq->send_bar = false;
1298 		mt7925_mcu_uni_tx_ba(dev, vif, params, true);
1299 		break;
1300 	case IEEE80211_AMPDU_TX_STOP_FLUSH:
1301 	case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1302 		mtxq->aggr = false;
1303 		clear_bit(tid, &msta->deflink.wcid.ampdu_state);
1304 		mt7925_mcu_uni_tx_ba(dev, vif, params, false);
1305 		break;
1306 	case IEEE80211_AMPDU_TX_START:
1307 		set_bit(tid, &msta->deflink.wcid.ampdu_state);
1308 		ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
1309 		break;
1310 	case IEEE80211_AMPDU_TX_STOP_CONT:
1311 		mtxq->aggr = false;
1312 		clear_bit(tid, &msta->deflink.wcid.ampdu_state);
1313 		mt7925_mcu_uni_tx_ba(dev, vif, params, false);
1314 		ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1315 		break;
1316 	}
1317 	mt792x_mutex_release(dev);
1318 
1319 	return ret;
1320 }
1321 
1322 static bool is_valid_alpha2(const char *alpha2)
1323 {
1324 	if (!alpha2)
1325 		return false;
1326 
1327 	if (alpha2[0] == '0' && alpha2[1] == '0')
1328 		return true;
1329 
1330 	if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
1331 		return true;
1332 
1333 	return false;
1334 }
1335 
1336 void mt7925_scan_work(struct work_struct *work)
1337 {
1338 	struct mt792x_phy *phy;
1339 
1340 	phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy,
1341 						scan_work.work);
1342 
1343 	while (true) {
1344 		struct mt76_dev *mdev = &phy->dev->mt76;
1345 		struct sk_buff *skb;
1346 		struct tlv *tlv;
1347 		int tlv_len;
1348 
1349 		spin_lock_bh(&phy->dev->mt76.lock);
1350 		skb = __skb_dequeue(&phy->scan_event_list);
1351 		spin_unlock_bh(&phy->dev->mt76.lock);
1352 
1353 		if (!skb)
1354 			break;
1355 
1356 		skb_pull(skb, sizeof(struct mt7925_mcu_rxd) + 4);
1357 		tlv = (struct tlv *)skb->data;
1358 		tlv_len = skb->len;
1359 
1360 		while (tlv_len > 0 && le16_to_cpu(tlv->len) <= tlv_len) {
1361 			struct mt7925_mcu_scan_chinfo_event *evt;
1362 
1363 			switch (le16_to_cpu(tlv->tag)) {
1364 			case UNI_EVENT_SCAN_DONE_BASIC:
1365 				if (test_and_clear_bit(MT76_HW_SCANNING, &phy->mt76->state)) {
1366 					struct cfg80211_scan_info info = {
1367 						.aborted = false,
1368 					};
1369 					ieee80211_scan_completed(phy->mt76->hw, &info);
1370 				}
1371 				break;
1372 			case UNI_EVENT_SCAN_DONE_CHNLINFO:
1373 				evt = (struct mt7925_mcu_scan_chinfo_event *)tlv->data;
1374 
1375 				if (!is_valid_alpha2(evt->alpha2))
1376 					break;
1377 
1378 				if (mdev->alpha2[0] != '0' && mdev->alpha2[1] != '0')
1379 					break;
1380 
1381 				mt7925_mcu_set_clc(phy->dev, evt->alpha2, ENVIRON_INDOOR);
1382 
1383 				break;
1384 			case UNI_EVENT_SCAN_DONE_NLO:
1385 				ieee80211_sched_scan_results(phy->mt76->hw);
1386 				break;
1387 			default:
1388 				break;
1389 			}
1390 
1391 			tlv_len -= le16_to_cpu(tlv->len);
1392 			tlv = (struct tlv *)((char *)(tlv) + le16_to_cpu(tlv->len));
1393 		}
1394 
1395 		dev_kfree_skb(skb);
1396 	}
1397 }
1398 
1399 static int
1400 mt7925_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1401 	       struct ieee80211_scan_request *req)
1402 {
1403 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1404 	struct mt76_phy *mphy = hw->priv;
1405 	int err;
1406 
1407 	mt792x_mutex_acquire(dev);
1408 	err = mt7925_mcu_hw_scan(mphy, vif, req);
1409 	mt792x_mutex_release(dev);
1410 
1411 	return err;
1412 }
1413 
1414 static void
1415 mt7925_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1416 {
1417 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1418 	struct mt76_phy *mphy = hw->priv;
1419 
1420 	mt792x_mutex_acquire(dev);
1421 	mt7925_mcu_cancel_hw_scan(mphy, vif);
1422 	mt792x_mutex_release(dev);
1423 }
1424 
1425 static int
1426 mt7925_start_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1427 			struct cfg80211_sched_scan_request *req,
1428 			struct ieee80211_scan_ies *ies)
1429 {
1430 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1431 	struct mt76_phy *mphy = hw->priv;
1432 	int err;
1433 
1434 	mt792x_mutex_acquire(dev);
1435 
1436 	err = mt7925_mcu_sched_scan_req(mphy, vif, req);
1437 	if (err < 0)
1438 		goto out;
1439 
1440 	err = mt7925_mcu_sched_scan_enable(mphy, vif, true);
1441 out:
1442 	mt792x_mutex_release(dev);
1443 
1444 	return err;
1445 }
1446 
1447 static int
1448 mt7925_stop_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1449 {
1450 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1451 	struct mt76_phy *mphy = hw->priv;
1452 	int err;
1453 
1454 	mt792x_mutex_acquire(dev);
1455 	err = mt7925_mcu_sched_scan_enable(mphy, vif, false);
1456 	mt792x_mutex_release(dev);
1457 
1458 	return err;
1459 }
1460 
1461 static int
1462 mt7925_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
1463 {
1464 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1465 	struct mt792x_phy *phy = mt792x_hw_phy(hw);
1466 	int max_nss = hweight8(hw->wiphy->available_antennas_tx);
1467 
1468 	if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss)
1469 		return -EINVAL;
1470 
1471 	if ((BIT(hweight8(tx_ant)) - 1) != tx_ant)
1472 		tx_ant = BIT(ffs(tx_ant) - 1) - 1;
1473 
1474 	mt792x_mutex_acquire(dev);
1475 
1476 	phy->mt76->antenna_mask = tx_ant;
1477 	phy->mt76->chainmask = tx_ant;
1478 
1479 	mt76_set_stream_caps(phy->mt76, true);
1480 	mt7925_set_stream_he_eht_caps(phy);
1481 
1482 	/* TODO: update bmc_wtbl spe_idx when antenna changes */
1483 	mt792x_mutex_release(dev);
1484 
1485 	return 0;
1486 }
1487 
1488 #ifdef CONFIG_PM
1489 static int mt7925_suspend(struct ieee80211_hw *hw,
1490 			  struct cfg80211_wowlan *wowlan)
1491 {
1492 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1493 	struct mt792x_phy *phy = mt792x_hw_phy(hw);
1494 
1495 	cancel_delayed_work_sync(&phy->scan_work);
1496 	cancel_delayed_work_sync(&phy->mt76->mac_work);
1497 
1498 	cancel_delayed_work_sync(&dev->pm.ps_work);
1499 	mt76_connac_free_pending_tx_skbs(&dev->pm, NULL);
1500 
1501 	mt792x_mutex_acquire(dev);
1502 
1503 	clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
1504 	ieee80211_iterate_active_interfaces(hw,
1505 					    IEEE80211_IFACE_ITER_RESUME_ALL,
1506 					    mt7925_mcu_set_suspend_iter,
1507 					    &dev->mphy);
1508 
1509 	mt792x_mutex_release(dev);
1510 
1511 	return 0;
1512 }
1513 
1514 static int mt7925_resume(struct ieee80211_hw *hw)
1515 {
1516 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1517 	struct mt792x_phy *phy = mt792x_hw_phy(hw);
1518 
1519 	mt792x_mutex_acquire(dev);
1520 
1521 	set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
1522 	ieee80211_iterate_active_interfaces(hw,
1523 					    IEEE80211_IFACE_ITER_RESUME_ALL,
1524 					    mt7925_mcu_set_suspend_iter,
1525 					    &dev->mphy);
1526 
1527 	ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
1528 				     MT792x_WATCHDOG_TIME);
1529 
1530 	mt792x_mutex_release(dev);
1531 
1532 	return 0;
1533 }
1534 
1535 static void mt7925_set_rekey_data(struct ieee80211_hw *hw,
1536 				  struct ieee80211_vif *vif,
1537 				  struct cfg80211_gtk_rekey_data *data)
1538 {
1539 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1540 
1541 	mt792x_mutex_acquire(dev);
1542 	mt76_connac_mcu_update_gtk_rekey(hw, vif, data);
1543 	mt792x_mutex_release(dev);
1544 }
1545 #endif /* CONFIG_PM */
1546 
1547 static void mt7925_sta_set_decap_offload(struct ieee80211_hw *hw,
1548 					 struct ieee80211_vif *vif,
1549 					 struct ieee80211_sta *sta,
1550 					 bool enabled)
1551 {
1552 	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
1553 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1554 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1555 	unsigned long valid = mvif->valid_links;
1556 	u8 i;
1557 
1558 	mt792x_mutex_acquire(dev);
1559 
1560 	valid = ieee80211_vif_is_mld(vif) ? mvif->valid_links : BIT(0);
1561 
1562 	for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
1563 		struct mt792x_link_sta *mlink;
1564 
1565 		mlink = mt792x_sta_to_link(msta, i);
1566 
1567 		if (enabled)
1568 			set_bit(MT_WCID_FLAG_HDR_TRANS, &mlink->wcid.flags);
1569 		else
1570 			clear_bit(MT_WCID_FLAG_HDR_TRANS, &mlink->wcid.flags);
1571 
1572 		mt7925_mcu_wtbl_update_hdr_trans(dev, vif, sta, i);
1573 	}
1574 
1575 	mt792x_mutex_release(dev);
1576 }
1577 
1578 #if IS_ENABLED(CONFIG_IPV6)
1579 static void __mt7925_ipv6_addr_change(struct ieee80211_hw *hw,
1580 				      struct ieee80211_bss_conf *link_conf,
1581 				      struct inet6_dev *idev)
1582 {
1583 	struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf);
1584 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1585 	struct inet6_ifaddr *ifa;
1586 	struct sk_buff *skb;
1587 	u8 idx = 0;
1588 
1589 	struct {
1590 		struct {
1591 			u8 bss_idx;
1592 			u8 pad[3];
1593 		} __packed hdr;
1594 		struct mt7925_arpns_tlv arpns;
1595 		struct in6_addr ns_addrs[IEEE80211_BSS_ARP_ADDR_LIST_LEN];
1596 	} req_hdr = {
1597 		.hdr = {
1598 			.bss_idx = mconf->mt76.idx,
1599 		},
1600 		.arpns = {
1601 			.tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_ND),
1602 			.len = cpu_to_le16(sizeof(req_hdr) - 4),
1603 			.enable = true,
1604 		},
1605 	};
1606 
1607 	read_lock_bh(&idev->lock);
1608 	list_for_each_entry(ifa, &idev->addr_list, if_list) {
1609 		if (ifa->flags & IFA_F_TENTATIVE)
1610 			continue;
1611 		req_hdr.ns_addrs[idx] = ifa->addr;
1612 		if (++idx >= IEEE80211_BSS_ARP_ADDR_LIST_LEN)
1613 			break;
1614 	}
1615 	read_unlock_bh(&idev->lock);
1616 
1617 	if (!idx)
1618 		return;
1619 
1620 	req_hdr.arpns.ips_num = idx;
1621 
1622 	skb = __mt76_mcu_msg_alloc(&dev->mt76, NULL, sizeof(req_hdr),
1623 				   0, GFP_ATOMIC);
1624 	if (!skb)
1625 		return;
1626 
1627 	skb_put_data(skb, &req_hdr, sizeof(req_hdr));
1628 
1629 	skb_queue_tail(&dev->ipv6_ns_list, skb);
1630 
1631 	ieee80211_queue_work(dev->mt76.hw, &dev->ipv6_ns_work);
1632 }
1633 
1634 static void mt7925_ipv6_addr_change(struct ieee80211_hw *hw,
1635 				    struct ieee80211_vif *vif,
1636 				    struct inet6_dev *idev)
1637 {
1638 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1639 	unsigned long valid = ieee80211_vif_is_mld(vif) ?
1640 			      mvif->valid_links : BIT(0);
1641 	struct ieee80211_bss_conf *bss_conf;
1642 	int i;
1643 
1644 	for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
1645 		bss_conf = mt792x_vif_to_bss_conf(vif, i);
1646 		__mt7925_ipv6_addr_change(hw, bss_conf, idev);
1647 	}
1648 }
1649 
1650 #endif
1651 
1652 int mt7925_set_tx_sar_pwr(struct ieee80211_hw *hw,
1653 			  const struct cfg80211_sar_specs *sar)
1654 {
1655 	struct mt76_phy *mphy = hw->priv;
1656 
1657 	if (sar) {
1658 		int err = mt76_init_sar_power(hw, sar);
1659 
1660 		if (err)
1661 			return err;
1662 	}
1663 	mt792x_init_acpi_sar_power(mt792x_hw_phy(hw), !sar);
1664 
1665 	return mt7925_mcu_set_rate_txpower(mphy);
1666 }
1667 
1668 static int mt7925_set_sar_specs(struct ieee80211_hw *hw,
1669 				const struct cfg80211_sar_specs *sar)
1670 {
1671 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1672 	int err;
1673 
1674 	mt792x_mutex_acquire(dev);
1675 	err = mt7925_mcu_set_clc(dev, dev->mt76.alpha2,
1676 				 dev->country_ie_env);
1677 	if (err < 0)
1678 		goto out;
1679 
1680 	err = mt7925_set_tx_sar_pwr(hw, sar);
1681 out:
1682 	mt792x_mutex_release(dev);
1683 
1684 	return err;
1685 }
1686 
1687 static void
1688 mt7925_channel_switch_beacon(struct ieee80211_hw *hw,
1689 			     struct ieee80211_vif *vif,
1690 			     struct cfg80211_chan_def *chandef)
1691 {
1692 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1693 
1694 	mt792x_mutex_acquire(dev);
1695 	mt7925_mcu_uni_add_beacon_offload(dev, hw, vif, true);
1696 	mt792x_mutex_release(dev);
1697 }
1698 
1699 static int
1700 mt7925_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1701 	       unsigned int link_id, u16 queue,
1702 	       const struct ieee80211_tx_queue_params *params)
1703 {
1704 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1705 	struct mt792x_bss_conf *mconf = mt792x_vif_to_link(mvif, link_id);
1706 	static const u8 mq_to_aci[] = {
1707 		    [IEEE80211_AC_VO] = 3,
1708 		    [IEEE80211_AC_VI] = 2,
1709 		    [IEEE80211_AC_BE] = 0,
1710 		    [IEEE80211_AC_BK] = 1,
1711 	};
1712 
1713 	/* firmware uses access class index */
1714 	mconf->queue_params[mq_to_aci[queue]] = *params;
1715 
1716 	return 0;
1717 }
1718 
1719 static int
1720 mt7925_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1721 		struct ieee80211_bss_conf *link_conf)
1722 {
1723 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1724 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1725 	int err;
1726 
1727 	mt792x_mutex_acquire(dev);
1728 
1729 	err = mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx,
1730 				      link_conf, NULL, true);
1731 	if (err)
1732 		goto out;
1733 
1734 	err = mt7925_mcu_set_bss_pm(dev, link_conf, true);
1735 	if (err)
1736 		goto out;
1737 
1738 	err = mt7925_mcu_sta_update(dev, NULL, vif, true,
1739 				    MT76_STA_INFO_STATE_NONE);
1740 out:
1741 	mt792x_mutex_release(dev);
1742 
1743 	return err;
1744 }
1745 
1746 static void
1747 mt7925_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1748 	       struct ieee80211_bss_conf *link_conf)
1749 {
1750 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1751 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1752 	int err;
1753 
1754 	mt792x_mutex_acquire(dev);
1755 
1756 	err = mt7925_mcu_set_bss_pm(dev, link_conf, false);
1757 	if (err)
1758 		goto out;
1759 
1760 	mt7925_mcu_add_bss_info(&dev->phy, mvif->bss_conf.mt76.ctx, link_conf,
1761 				NULL, false);
1762 
1763 out:
1764 	mt792x_mutex_release(dev);
1765 }
1766 
1767 static int
1768 mt7925_add_chanctx(struct ieee80211_hw *hw,
1769 		   struct ieee80211_chanctx_conf *ctx)
1770 {
1771 	return 0;
1772 }
1773 
1774 static void
1775 mt7925_remove_chanctx(struct ieee80211_hw *hw,
1776 		      struct ieee80211_chanctx_conf *ctx)
1777 {
1778 }
1779 
1780 static void
1781 mt7925_change_chanctx(struct ieee80211_hw *hw,
1782 		      struct ieee80211_chanctx_conf *ctx,
1783 		      u32 changed)
1784 {
1785 	struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv;
1786 	struct mt792x_phy *phy = mt792x_hw_phy(hw);
1787 	struct mt792x_bss_conf *mconf;
1788 	struct ieee80211_vif *vif;
1789 	struct mt792x_vif *mvif;
1790 
1791 	if (!mctx->bss_conf)
1792 		return;
1793 
1794 	mconf = mctx->bss_conf;
1795 	mvif = mconf->vif;
1796 	vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv);
1797 
1798 	mt792x_mutex_acquire(phy->dev);
1799 	if (vif->type == NL80211_IFTYPE_MONITOR) {
1800 		mt7925_mcu_set_sniffer(mvif->phy->dev, vif, true);
1801 		mt7925_mcu_config_sniffer(mvif, ctx);
1802 	} else {
1803 		if (ieee80211_vif_is_mld(vif)) {
1804 			unsigned long valid = mvif->valid_links;
1805 			u8 i;
1806 
1807 			for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
1808 				mconf = mt792x_vif_to_link(mvif, i);
1809 				if (mconf && mconf->mt76.ctx == ctx)
1810 					break;
1811 			}
1812 
1813 		} else {
1814 			mconf = &mvif->bss_conf;
1815 		}
1816 
1817 		if (mconf) {
1818 			struct ieee80211_bss_conf *link_conf;
1819 
1820 			link_conf = mt792x_vif_to_bss_conf(vif, mconf->link_id);
1821 			mt7925_mcu_set_chctx(mvif->phy->mt76, &mconf->mt76,
1822 					     link_conf, ctx);
1823 		}
1824 	}
1825 
1826 	mt792x_mutex_release(phy->dev);
1827 }
1828 
1829 static void mt7925_mgd_prepare_tx(struct ieee80211_hw *hw,
1830 				  struct ieee80211_vif *vif,
1831 				  struct ieee80211_prep_tx_info *info)
1832 {
1833 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1834 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1835 	u16 duration = info->duration ? info->duration :
1836 		       jiffies_to_msecs(HZ);
1837 
1838 	mt792x_mutex_acquire(dev);
1839 	mt7925_set_roc(mvif->phy, &mvif->bss_conf,
1840 		       mvif->bss_conf.mt76.ctx->def.chan, duration,
1841 		       MT7925_ROC_REQ_JOIN);
1842 	mt792x_mutex_release(dev);
1843 }
1844 
1845 static void mt7925_mgd_complete_tx(struct ieee80211_hw *hw,
1846 				   struct ieee80211_vif *vif,
1847 				   struct ieee80211_prep_tx_info *info)
1848 {
1849 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1850 
1851 	mt7925_abort_roc(mvif->phy, &mvif->bss_conf);
1852 }
1853 
1854 static void mt7925_vif_cfg_changed(struct ieee80211_hw *hw,
1855 				   struct ieee80211_vif *vif,
1856 				   u64 changed)
1857 {
1858 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1859 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1860 	unsigned long valid = ieee80211_vif_is_mld(vif) ?
1861 				      mvif->valid_links : BIT(0);
1862 	struct ieee80211_bss_conf *bss_conf;
1863 	int i;
1864 
1865 	mt792x_mutex_acquire(dev);
1866 
1867 	if (changed & BSS_CHANGED_ASSOC) {
1868 		mt7925_mcu_sta_update(dev, NULL, vif, true,
1869 				      MT76_STA_INFO_STATE_ASSOC);
1870 		mt7925_mcu_set_beacon_filter(dev, vif, vif->cfg.assoc);
1871 	}
1872 
1873 	if (changed & BSS_CHANGED_ARP_FILTER) {
1874 		for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
1875 			bss_conf = mt792x_vif_to_bss_conf(vif, i);
1876 			mt7925_mcu_update_arp_filter(&dev->mt76, bss_conf);
1877 		}
1878 	}
1879 
1880 	if (changed & BSS_CHANGED_PS) {
1881 		for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
1882 			bss_conf = mt792x_vif_to_bss_conf(vif, i);
1883 			mt7925_mcu_uni_bss_ps(dev, bss_conf);
1884 		}
1885 	}
1886 
1887 	mt792x_mutex_release(dev);
1888 }
1889 
1890 static void mt7925_link_info_changed(struct ieee80211_hw *hw,
1891 				     struct ieee80211_vif *vif,
1892 				     struct ieee80211_bss_conf *info,
1893 				     u64 changed)
1894 {
1895 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1896 	struct mt792x_phy *phy = mt792x_hw_phy(hw);
1897 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1898 	struct mt792x_bss_conf *mconf;
1899 
1900 	mconf = mt792x_vif_to_link(mvif, info->link_id);
1901 
1902 	mt792x_mutex_acquire(dev);
1903 
1904 	if (changed & BSS_CHANGED_ERP_SLOT) {
1905 		int slottime = info->use_short_slot ? 9 : 20;
1906 
1907 		if (slottime != phy->slottime) {
1908 			phy->slottime = slottime;
1909 			mt7925_mcu_set_timing(phy, info);
1910 		}
1911 	}
1912 
1913 	if (changed & BSS_CHANGED_MCAST_RATE)
1914 		mconf->mt76.mcast_rates_idx =
1915 				mt7925_get_rates_table(hw, vif, false, true);
1916 
1917 	if (changed & BSS_CHANGED_BASIC_RATES)
1918 		mconf->mt76.basic_rates_idx =
1919 				mt7925_get_rates_table(hw, vif, false, false);
1920 
1921 	if (changed & (BSS_CHANGED_BEACON |
1922 		       BSS_CHANGED_BEACON_ENABLED)) {
1923 		mconf->mt76.beacon_rates_idx =
1924 				mt7925_get_rates_table(hw, vif, true, false);
1925 
1926 		mt7925_mcu_uni_add_beacon_offload(dev, hw, vif,
1927 						  info->enable_beacon);
1928 	}
1929 
1930 	/* ensure that enable txcmd_mode after bss_info */
1931 	if (changed & (BSS_CHANGED_QOS | BSS_CHANGED_BEACON_ENABLED))
1932 		mt7925_mcu_set_tx(dev, info);
1933 
1934 	if (changed & BSS_CHANGED_BSSID) {
1935 		if (ieee80211_vif_is_mld(vif) &&
1936 		    hweight16(mvif->valid_links) == 2)
1937 			/* Indicate the secondary setup done */
1938 			mt7925_mcu_uni_bss_bcnft(dev, info, true);
1939 	}
1940 
1941 	mt792x_mutex_release(dev);
1942 }
1943 
1944 static int
1945 mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1946 			u16 old_links, u16 new_links,
1947 			struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
1948 {
1949 	struct mt792x_bss_conf *mconfs[IEEE80211_MLD_MAX_NUM_LINKS] = {}, *mconf;
1950 	struct mt792x_link_sta *mlinks[IEEE80211_MLD_MAX_NUM_LINKS] = {}, *mlink;
1951 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1952 	unsigned long add = new_links & ~old_links;
1953 	unsigned long rem = old_links & ~new_links;
1954 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
1955 	struct mt792x_phy *phy = mt792x_hw_phy(hw);
1956 	struct ieee80211_bss_conf *link_conf;
1957 	unsigned int link_id;
1958 	int err;
1959 
1960 	if (old_links == new_links)
1961 		return 0;
1962 
1963 	mt792x_mutex_acquire(dev);
1964 
1965 	for_each_set_bit(link_id, &rem, IEEE80211_MLD_MAX_NUM_LINKS) {
1966 		mconf = mt792x_vif_to_link(mvif, link_id);
1967 		mlink = mt792x_sta_to_link(&mvif->sta, link_id);
1968 
1969 		if (!mconf || !mlink)
1970 			continue;
1971 
1972 		if (mconf != &mvif->bss_conf) {
1973 			mt792x_mac_link_bss_remove(dev, mconf, mlink);
1974 			devm_kfree(dev->mt76.dev, mconf);
1975 			devm_kfree(dev->mt76.dev, mlink);
1976 		}
1977 
1978 		rcu_assign_pointer(mvif->link_conf[link_id], NULL);
1979 		rcu_assign_pointer(mvif->sta.link[link_id], NULL);
1980 	}
1981 
1982 	for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
1983 		if (!old_links) {
1984 			mvif->deflink_id = link_id;
1985 			mconf = &mvif->bss_conf;
1986 			mlink = &mvif->sta.deflink;
1987 		} else {
1988 			mconf = devm_kzalloc(dev->mt76.dev, sizeof(*mconf),
1989 					     GFP_KERNEL);
1990 			mlink = devm_kzalloc(dev->mt76.dev, sizeof(*mlink),
1991 					     GFP_KERNEL);
1992 			if (!mconf || !mlink)
1993 				return -ENOMEM;
1994 		}
1995 
1996 		mconfs[link_id] = mconf;
1997 		mlinks[link_id] = mlink;
1998 		mconf->link_id = link_id;
1999 		mconf->vif = mvif;
2000 		mlink->wcid.link_id = link_id;
2001 		mlink->wcid.link_valid = !!vif->valid_links;
2002 		mlink->wcid.def_wcid = &mvif->sta.deflink.wcid;
2003 	}
2004 
2005 	if (hweight16(mvif->valid_links) == 0)
2006 		mt792x_mac_link_bss_remove(dev, &mvif->bss_conf,
2007 					   &mvif->sta.deflink);
2008 
2009 	for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
2010 		mconf = mconfs[link_id];
2011 		mlink = mlinks[link_id];
2012 		link_conf = mt792x_vif_to_bss_conf(vif, link_id);
2013 
2014 		rcu_assign_pointer(mvif->link_conf[link_id], mconf);
2015 		rcu_assign_pointer(mvif->sta.link[link_id], mlink);
2016 
2017 		err = mt7925_mac_link_bss_add(dev, link_conf, mlink);
2018 		if (err < 0)
2019 			goto free;
2020 
2021 		if (mconf != &mvif->bss_conf) {
2022 			mt7925_mcu_set_bss_pm(dev, link_conf, true);
2023 
2024 			err = mt7925_set_mlo_roc(phy, &mvif->bss_conf,
2025 						 vif->active_links);
2026 			if (err < 0)
2027 				goto free;
2028 		}
2029 	}
2030 
2031 	mvif->valid_links = new_links;
2032 
2033 	mt792x_mutex_release(dev);
2034 
2035 	return 0;
2036 
2037 free:
2038 	for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
2039 		rcu_assign_pointer(mvif->link_conf[link_id], NULL);
2040 		rcu_assign_pointer(mvif->sta.link[link_id], NULL);
2041 
2042 		if (mconf != &mvif->bss_conf)
2043 			devm_kfree(dev->mt76.dev, mconfs[link_id]);
2044 		if (mlink != &mvif->sta.deflink)
2045 			devm_kfree(dev->mt76.dev, mlinks[link_id]);
2046 	}
2047 
2048 	mt792x_mutex_release(dev);
2049 
2050 	return err;
2051 }
2052 
2053 static int
2054 mt7925_change_sta_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2055 			struct ieee80211_sta *sta, u16 old_links, u16 new_links)
2056 {
2057 	unsigned long add = new_links & ~old_links;
2058 	unsigned long rem = old_links & ~new_links;
2059 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
2060 	int err = 0;
2061 
2062 	if (old_links == new_links)
2063 		return 0;
2064 
2065 	mt792x_mutex_acquire(dev);
2066 
2067 	err = mt7925_mac_sta_remove_links(dev, vif, sta, rem);
2068 	if (err < 0)
2069 		goto out;
2070 
2071 	err = mt7925_mac_sta_add_links(dev, vif, sta, add);
2072 	if (err < 0)
2073 		goto out;
2074 
2075 out:
2076 	mt792x_mutex_release(dev);
2077 
2078 	return err;
2079 }
2080 
2081 static int mt7925_assign_vif_chanctx(struct ieee80211_hw *hw,
2082 				     struct ieee80211_vif *vif,
2083 				     struct ieee80211_bss_conf *link_conf,
2084 				     struct ieee80211_chanctx_conf *ctx)
2085 {
2086 	struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv;
2087 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
2088 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
2089 	struct ieee80211_bss_conf *pri_link_conf;
2090 	struct mt792x_bss_conf *mconf;
2091 
2092 	mutex_lock(&dev->mt76.mutex);
2093 
2094 	if (ieee80211_vif_is_mld(vif)) {
2095 		mconf = mt792x_vif_to_link(mvif, link_conf->link_id);
2096 		pri_link_conf = mt792x_vif_to_bss_conf(vif, mvif->deflink_id);
2097 
2098 		if (vif->type == NL80211_IFTYPE_STATION &&
2099 		    mconf == &mvif->bss_conf)
2100 			mt7925_mcu_add_bss_info(&dev->phy, NULL, pri_link_conf,
2101 						NULL, true);
2102 	} else {
2103 		mconf = &mvif->bss_conf;
2104 	}
2105 
2106 	mconf->mt76.ctx = ctx;
2107 	mctx->bss_conf = mconf;
2108 	mutex_unlock(&dev->mt76.mutex);
2109 
2110 	return 0;
2111 }
2112 
2113 static void mt7925_unassign_vif_chanctx(struct ieee80211_hw *hw,
2114 					struct ieee80211_vif *vif,
2115 					struct ieee80211_bss_conf *link_conf,
2116 					struct ieee80211_chanctx_conf *ctx)
2117 {
2118 	struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv;
2119 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
2120 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
2121 	struct mt792x_bss_conf *mconf;
2122 
2123 	mutex_lock(&dev->mt76.mutex);
2124 
2125 	if (ieee80211_vif_is_mld(vif)) {
2126 		mconf = mt792x_vif_to_link(mvif, link_conf->link_id);
2127 
2128 		if (vif->type == NL80211_IFTYPE_STATION &&
2129 		    mconf == &mvif->bss_conf)
2130 			mt7925_mcu_add_bss_info(&dev->phy, NULL, link_conf,
2131 						NULL, false);
2132 	} else {
2133 		mconf = &mvif->bss_conf;
2134 	}
2135 
2136 	mctx->bss_conf = NULL;
2137 	mconf->mt76.ctx = NULL;
2138 	mutex_unlock(&dev->mt76.mutex);
2139 }
2140 
2141 const struct ieee80211_ops mt7925_ops = {
2142 	.tx = mt792x_tx,
2143 	.start = mt7925_start,
2144 	.stop = mt792x_stop,
2145 	.add_interface = mt7925_add_interface,
2146 	.remove_interface = mt792x_remove_interface,
2147 	.config = mt7925_config,
2148 	.conf_tx = mt7925_conf_tx,
2149 	.configure_filter = mt7925_configure_filter,
2150 	.start_ap = mt7925_start_ap,
2151 	.stop_ap = mt7925_stop_ap,
2152 	.sta_state = mt76_sta_state,
2153 	.sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
2154 	.set_key = mt7925_set_key,
2155 	.sta_set_decap_offload = mt7925_sta_set_decap_offload,
2156 #if IS_ENABLED(CONFIG_IPV6)
2157 	.ipv6_addr_change = mt7925_ipv6_addr_change,
2158 #endif /* CONFIG_IPV6 */
2159 	.ampdu_action = mt7925_ampdu_action,
2160 	.set_rts_threshold = mt7925_set_rts_threshold,
2161 	.wake_tx_queue = mt76_wake_tx_queue,
2162 	.release_buffered_frames = mt76_release_buffered_frames,
2163 	.channel_switch_beacon = mt7925_channel_switch_beacon,
2164 	.get_txpower = mt76_get_txpower,
2165 	.get_stats = mt792x_get_stats,
2166 	.get_et_sset_count = mt792x_get_et_sset_count,
2167 	.get_et_strings = mt792x_get_et_strings,
2168 	.get_et_stats = mt792x_get_et_stats,
2169 	.get_tsf = mt792x_get_tsf,
2170 	.set_tsf = mt792x_set_tsf,
2171 	.get_survey = mt76_get_survey,
2172 	.get_antenna = mt76_get_antenna,
2173 	.set_antenna = mt7925_set_antenna,
2174 	.set_coverage_class = mt792x_set_coverage_class,
2175 	.hw_scan = mt7925_hw_scan,
2176 	.cancel_hw_scan = mt7925_cancel_hw_scan,
2177 	.sta_statistics = mt792x_sta_statistics,
2178 	.sched_scan_start = mt7925_start_sched_scan,
2179 	.sched_scan_stop = mt7925_stop_sched_scan,
2180 #ifdef CONFIG_PM
2181 	.suspend = mt7925_suspend,
2182 	.resume = mt7925_resume,
2183 	.set_wakeup = mt792x_set_wakeup,
2184 	.set_rekey_data = mt7925_set_rekey_data,
2185 #endif /* CONFIG_PM */
2186 	.flush = mt792x_flush,
2187 	.set_sar_specs = mt7925_set_sar_specs,
2188 	.remain_on_channel = mt7925_remain_on_channel,
2189 	.cancel_remain_on_channel = mt7925_cancel_remain_on_channel,
2190 	.add_chanctx = mt7925_add_chanctx,
2191 	.remove_chanctx = mt7925_remove_chanctx,
2192 	.change_chanctx = mt7925_change_chanctx,
2193 	.assign_vif_chanctx = mt7925_assign_vif_chanctx,
2194 	.unassign_vif_chanctx = mt7925_unassign_vif_chanctx,
2195 	.mgd_prepare_tx = mt7925_mgd_prepare_tx,
2196 	.mgd_complete_tx = mt7925_mgd_complete_tx,
2197 	.vif_cfg_changed = mt7925_vif_cfg_changed,
2198 	.link_info_changed = mt7925_link_info_changed,
2199 	.change_vif_links = mt7925_change_vif_links,
2200 	.change_sta_links = mt7925_change_sta_links,
2201 };
2202 EXPORT_SYMBOL_GPL(mt7925_ops);
2203 
2204 MODULE_AUTHOR("Deren Wu <deren.wu@mediatek.com>");
2205 MODULE_DESCRIPTION("MediaTek MT7925 core driver");
2206 MODULE_LICENSE("Dual BSD/GPL");
2207