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