1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2023 MediaTek Inc. */
4 #include <linux/etherdevice.h>
5 #include <linux/platform_device.h>
7 #include <linux/module.h>
8 #include <linux/ctype.h>
15 mt7925_init_he_caps(struct mt792x_phy *phy, enum nl80211_band band,
16 struct ieee80211_sband_iftype_data *data,
17 enum nl80211_iftype iftype)
19 struct ieee80211_sta_he_cap *he_cap = &data->he_cap;
20 struct ieee80211_he_cap_elem *he_cap_elem = &he_cap->he_cap_elem;
21 struct ieee80211_he_mcs_nss_supp *he_mcs = &he_cap->he_mcs_nss_supp;
22 int i, nss = hweight8(phy->mt76->antenna_mask);
25 for (i = 0; i < 8; i++) {
27 mcs_map |= (IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2));
29 mcs_map |= (IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
32 he_cap->has_he = true;
34 he_cap_elem->mac_cap_info[0] = IEEE80211_HE_MAC_CAP0_HTC_HE;
35 he_cap_elem->mac_cap_info[3] = IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
36 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3;
37 he_cap_elem->mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU;
39 if (band == NL80211_BAND_2GHZ)
40 he_cap_elem->phy_cap_info[0] =
41 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
43 he_cap_elem->phy_cap_info[0] =
44 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
45 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
47 he_cap_elem->phy_cap_info[1] =
48 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD;
49 he_cap_elem->phy_cap_info[2] =
50 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
51 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
52 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
53 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
54 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO;
57 case NL80211_IFTYPE_AP:
58 he_cap_elem->mac_cap_info[2] |=
59 IEEE80211_HE_MAC_CAP2_BSR;
60 he_cap_elem->mac_cap_info[4] |=
61 IEEE80211_HE_MAC_CAP4_BQR;
62 he_cap_elem->mac_cap_info[5] |=
63 IEEE80211_HE_MAC_CAP5_OM_CTRL_UL_MU_DATA_DIS_RX;
64 he_cap_elem->phy_cap_info[3] |=
65 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK |
66 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK;
67 he_cap_elem->phy_cap_info[6] |=
68 IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE |
69 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT;
70 he_cap_elem->phy_cap_info[9] |=
71 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
72 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU;
74 case NL80211_IFTYPE_STATION:
75 he_cap_elem->mac_cap_info[1] |=
76 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US;
78 if (band == NL80211_BAND_2GHZ)
79 he_cap_elem->phy_cap_info[0] |=
80 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G;
82 he_cap_elem->phy_cap_info[0] |=
83 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G;
85 he_cap_elem->phy_cap_info[1] |=
86 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
87 IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US;
88 he_cap_elem->phy_cap_info[3] |=
89 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK |
90 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK;
91 he_cap_elem->phy_cap_info[4] |=
92 IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE |
93 IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4 |
94 IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_4;
95 he_cap_elem->phy_cap_info[5] |=
96 IEEE80211_HE_PHY_CAP5_NG16_SU_FEEDBACK |
97 IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK;
98 he_cap_elem->phy_cap_info[6] |=
99 IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_42_SU |
100 IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU |
101 IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB |
102 IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE |
103 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT;
104 he_cap_elem->phy_cap_info[7] |=
105 IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP |
106 IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI;
107 he_cap_elem->phy_cap_info[8] |=
108 IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
109 IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
110 IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU |
111 IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_484;
112 he_cap_elem->phy_cap_info[9] |=
113 IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM |
114 IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK |
115 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
116 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU |
117 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB |
118 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB;
124 he_mcs->rx_mcs_80 = cpu_to_le16(mcs_map);
125 he_mcs->tx_mcs_80 = cpu_to_le16(mcs_map);
126 he_mcs->rx_mcs_160 = cpu_to_le16(mcs_map);
127 he_mcs->tx_mcs_160 = cpu_to_le16(mcs_map);
129 memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
131 if (he_cap_elem->phy_cap_info[6] &
132 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
133 mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss);
135 he_cap_elem->phy_cap_info[9] |=
136 u8_encode_bits(IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US,
137 IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK);
140 if (band == NL80211_BAND_6GHZ) {
141 u16 cap = IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS |
142 IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS;
144 cap |= u16_encode_bits(IEEE80211_HT_MPDU_DENSITY_0_5,
145 IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START) |
146 u16_encode_bits(IEEE80211_VHT_MAX_AMPDU_1024K,
147 IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP) |
148 u16_encode_bits(IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454,
149 IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN);
151 data->he_6ghz_capa.capa = cpu_to_le16(cap);
156 mt7925_init_eht_caps(struct mt792x_phy *phy, enum nl80211_band band,
157 struct ieee80211_sband_iftype_data *data)
159 struct ieee80211_sta_eht_cap *eht_cap = &data->eht_cap;
160 struct ieee80211_eht_cap_elem_fixed *eht_cap_elem = &eht_cap->eht_cap_elem;
161 struct ieee80211_eht_mcs_nss_supp *eht_nss = &eht_cap->eht_mcs_nss_supp;
162 enum nl80211_chan_width width = phy->mt76->chandef.width;
163 int nss = hweight8(phy->mt76->antenna_mask);
164 int sts = hweight16(phy->mt76->chainmask);
167 if (!phy->dev->has_eht)
170 eht_cap->has_eht = true;
172 eht_cap_elem->mac_cap_info[0] =
173 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
174 IEEE80211_EHT_MAC_CAP0_OM_CONTROL;
176 eht_cap_elem->phy_cap_info[0] =
177 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
178 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
179 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE;
181 eht_cap_elem->phy_cap_info[0] |=
182 u8_encode_bits(u8_get_bits(sts - 1, BIT(0)),
183 IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK);
185 eht_cap_elem->phy_cap_info[1] =
186 u8_encode_bits(u8_get_bits(sts - 1, GENMASK(2, 1)),
187 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK) |
188 u8_encode_bits(sts - 1,
189 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK);
191 eht_cap_elem->phy_cap_info[2] =
192 u8_encode_bits(sts - 1, IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK) |
193 u8_encode_bits(sts - 1, IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK);
195 eht_cap_elem->phy_cap_info[3] =
196 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
197 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
198 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
199 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
200 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
201 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
202 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK;
204 eht_cap_elem->phy_cap_info[4] =
205 u8_encode_bits(min_t(int, sts - 1, 2),
206 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK);
208 eht_cap_elem->phy_cap_info[5] =
209 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
210 u8_encode_bits(IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US,
211 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK) |
212 u8_encode_bits(u8_get_bits(0x11, GENMASK(1, 0)),
213 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK);
215 val = width == NL80211_CHAN_WIDTH_160 ? 0x7 :
216 width == NL80211_CHAN_WIDTH_80 ? 0x3 : 0x1;
217 eht_cap_elem->phy_cap_info[6] =
218 u8_encode_bits(u8_get_bits(0x11, GENMASK(4, 2)),
219 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK) |
220 u8_encode_bits(val, IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK);
222 eht_cap_elem->phy_cap_info[7] =
223 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
224 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
225 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
226 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ;
228 val = u8_encode_bits(nss, IEEE80211_EHT_MCS_NSS_RX) |
229 u8_encode_bits(nss, IEEE80211_EHT_MCS_NSS_TX);
231 eht_nss->bw._80.rx_tx_mcs9_max_nss = val;
232 eht_nss->bw._80.rx_tx_mcs11_max_nss = val;
233 eht_nss->bw._80.rx_tx_mcs13_max_nss = val;
234 eht_nss->bw._160.rx_tx_mcs9_max_nss = val;
235 eht_nss->bw._160.rx_tx_mcs11_max_nss = val;
236 eht_nss->bw._160.rx_tx_mcs13_max_nss = val;
240 __mt7925_set_stream_he_eht_caps(struct mt792x_phy *phy,
241 struct ieee80211_supported_band *sband,
242 enum nl80211_band band)
244 struct ieee80211_sband_iftype_data *data = phy->iftype[band];
247 for (i = 0; i < NUM_NL80211_IFTYPES; i++) {
249 case NL80211_IFTYPE_STATION:
250 case NL80211_IFTYPE_AP:
256 data[n].types_mask = BIT(i);
257 mt7925_init_he_caps(phy, band, &data[n], i);
258 mt7925_init_eht_caps(phy, band, &data[n]);
263 _ieee80211_set_sband_iftype_data(sband, data, n);
266 void mt7925_set_stream_he_eht_caps(struct mt792x_phy *phy)
268 if (phy->mt76->cap.has_2ghz)
269 __mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_2g.sband,
272 if (phy->mt76->cap.has_5ghz)
273 __mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_5g.sband,
276 if (phy->mt76->cap.has_6ghz)
277 __mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_6g.sband,
281 int __mt7925_start(struct mt792x_phy *phy)
283 struct mt76_phy *mphy = phy->mt76;
286 err = mt7925_mcu_set_channel_domain(mphy);
290 err = mt7925_mcu_set_rts_thresh(phy, 0x92b);
294 err = mt7925_set_tx_sar_pwr(mphy->hw, NULL);
298 mt792x_mac_reset_counters(phy);
299 set_bit(MT76_STATE_RUNNING, &mphy->state);
301 ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
302 MT792x_WATCHDOG_TIME);
306 EXPORT_SYMBOL_GPL(__mt7925_start);
308 static int mt7925_start(struct ieee80211_hw *hw)
310 struct mt792x_phy *phy = mt792x_hw_phy(hw);
313 mt792x_mutex_acquire(phy->dev);
314 err = __mt7925_start(phy);
315 mt792x_mutex_release(phy->dev);
321 mt7925_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
323 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
324 struct mt792x_dev *dev = mt792x_hw_dev(hw);
325 struct mt792x_phy *phy = mt792x_hw_phy(hw);
326 struct mt76_txq *mtxq;
329 mt792x_mutex_acquire(dev);
331 mvif->mt76.idx = __ffs64(~dev->mt76.vif_mask);
332 if (mvif->mt76.idx >= MT792x_MAX_INTERFACES) {
337 mvif->mt76.omac_idx = mvif->mt76.idx;
339 mvif->mt76.band_idx = 0;
340 mvif->mt76.wmm_idx = mvif->mt76.idx % MT76_CONNAC_MAX_WMM_SETS;
342 if (phy->mt76->chandef.chan->band != NL80211_BAND_2GHZ)
343 mvif->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL + 4;
345 mvif->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL;
347 ret = mt76_connac_mcu_uni_add_dev(&dev->mphy, vif, &mvif->sta.wcid,
352 dev->mt76.vif_mask |= BIT_ULL(mvif->mt76.idx);
353 phy->omac_mask |= BIT_ULL(mvif->mt76.omac_idx);
355 idx = MT792x_WTBL_RESERVED - mvif->mt76.idx;
357 INIT_LIST_HEAD(&mvif->sta.wcid.poll_list);
358 mvif->sta.wcid.idx = idx;
359 mvif->sta.wcid.phy_idx = mvif->mt76.band_idx;
360 mvif->sta.wcid.hw_key_idx = -1;
361 mvif->sta.wcid.tx_info |= MT_WCID_TX_INFO_SET;
362 mt76_wcid_init(&mvif->sta.wcid);
364 mt7925_mac_wtbl_update(dev, idx,
365 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
367 ewma_rssi_init(&mvif->rssi);
369 rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid);
371 mtxq = (struct mt76_txq *)vif->txq->drv_priv;
375 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
377 mt792x_mutex_release(dev);
382 static void mt7925_roc_iter(void *priv, u8 *mac,
383 struct ieee80211_vif *vif)
385 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
386 struct mt792x_phy *phy = priv;
388 mt7925_mcu_abort_roc(phy, mvif, phy->roc_token_id);
391 void mt7925_roc_work(struct work_struct *work)
393 struct mt792x_phy *phy;
395 phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy,
398 if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
401 mt792x_mutex_acquire(phy->dev);
402 ieee80211_iterate_active_interfaces(phy->mt76->hw,
403 IEEE80211_IFACE_ITER_RESUME_ALL,
404 mt7925_roc_iter, phy);
405 mt792x_mutex_release(phy->dev);
406 ieee80211_remain_on_channel_expired(phy->mt76->hw);
409 static int mt7925_abort_roc(struct mt792x_phy *phy, struct mt792x_vif *vif)
413 del_timer_sync(&phy->roc_timer);
414 cancel_work_sync(&phy->roc_work);
416 mt792x_mutex_acquire(phy->dev);
417 if (test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
418 err = mt7925_mcu_abort_roc(phy, vif, phy->roc_token_id);
419 mt792x_mutex_release(phy->dev);
424 static int mt7925_set_roc(struct mt792x_phy *phy,
425 struct mt792x_vif *vif,
426 struct ieee80211_channel *chan,
428 enum mt7925_roc_req type)
432 if (test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state))
435 phy->roc_grant = false;
437 err = mt7925_mcu_set_roc(phy, vif, chan, duration, type,
438 ++phy->roc_token_id);
440 clear_bit(MT76_STATE_ROC, &phy->mt76->state);
444 if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, 4 * HZ)) {
445 mt7925_mcu_abort_roc(phy, vif, phy->roc_token_id);
446 clear_bit(MT76_STATE_ROC, &phy->mt76->state);
454 static int mt7925_remain_on_channel(struct ieee80211_hw *hw,
455 struct ieee80211_vif *vif,
456 struct ieee80211_channel *chan,
458 enum ieee80211_roc_type type)
460 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
461 struct mt792x_phy *phy = mt792x_hw_phy(hw);
464 mt792x_mutex_acquire(phy->dev);
465 err = mt7925_set_roc(phy, mvif, chan, duration, MT7925_ROC_REQ_ROC);
466 mt792x_mutex_release(phy->dev);
471 static int mt7925_cancel_remain_on_channel(struct ieee80211_hw *hw,
472 struct ieee80211_vif *vif)
474 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
475 struct mt792x_phy *phy = mt792x_hw_phy(hw);
477 return mt7925_abort_roc(phy, mvif);
480 static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
481 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
482 struct ieee80211_key_conf *key)
484 struct mt792x_dev *dev = mt792x_hw_dev(hw);
485 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
486 struct mt792x_sta *msta = sta ? (struct mt792x_sta *)sta->drv_priv :
488 struct mt76_wcid *wcid = &msta->wcid;
489 u8 *wcid_keyidx = &wcid->hw_key_idx;
490 int idx = key->keyidx, err = 0;
492 /* The hardware does not support per-STA RX GTK, fallback
493 * to software mode for these.
495 if ((vif->type == NL80211_IFTYPE_ADHOC ||
496 vif->type == NL80211_IFTYPE_MESH_POINT) &&
497 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
498 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
499 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
502 /* fall back to sw encryption for unsupported ciphers */
503 switch (key->cipher) {
504 case WLAN_CIPHER_SUITE_AES_CMAC:
505 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
506 wcid_keyidx = &wcid->hw_key_idx2;
508 case WLAN_CIPHER_SUITE_WEP40:
509 case WLAN_CIPHER_SUITE_WEP104:
513 case WLAN_CIPHER_SUITE_TKIP:
514 case WLAN_CIPHER_SUITE_CCMP:
515 case WLAN_CIPHER_SUITE_CCMP_256:
516 case WLAN_CIPHER_SUITE_GCMP:
517 case WLAN_CIPHER_SUITE_GCMP_256:
518 case WLAN_CIPHER_SUITE_SMS4:
524 mt792x_mutex_acquire(dev);
526 if (cmd == SET_KEY && !mvif->mt76.cipher) {
527 struct mt792x_phy *phy = mt792x_hw_phy(hw);
529 mvif->mt76.cipher = mt76_connac_mcu_get_cipher(key->cipher);
530 mt7925_mcu_add_bss_info(phy, mvif->mt76.ctx, vif, sta, true);
535 else if (idx == *wcid_keyidx)
540 mt76_wcid_key_setup(&dev->mt76, wcid,
541 cmd == SET_KEY ? key : NULL);
543 err = mt7925_mcu_add_key(&dev->mt76, vif, &msta->bip,
544 key, MCU_UNI_CMD(STA_REC_UPDATE),
550 if (key->cipher == WLAN_CIPHER_SUITE_WEP104 ||
551 key->cipher == WLAN_CIPHER_SUITE_WEP40)
552 err = mt7925_mcu_add_key(&dev->mt76, vif, &mvif->wep_sta->bip,
553 key, MCU_WMWA_UNI_CMD(STA_REC_UPDATE),
554 &mvif->wep_sta->wcid, cmd);
557 mt792x_mutex_release(dev);
563 mt7925_pm_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
565 struct mt792x_dev *dev = priv;
566 struct ieee80211_hw *hw = mt76_hw(dev);
567 bool pm_enable = dev->pm.enable;
570 err = mt7925_mcu_set_beacon_filter(dev, vif, pm_enable);
575 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
576 ieee80211_hw_set(hw, CONNECTION_MONITOR);
578 vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
579 __clear_bit(IEEE80211_HW_CONNECTION_MONITOR, hw->flags);
584 mt7925_sniffer_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
586 struct mt792x_dev *dev = priv;
587 struct ieee80211_hw *hw = mt76_hw(dev);
588 struct mt76_connac_pm *pm = &dev->pm;
589 bool monitor = !!(hw->conf.flags & IEEE80211_CONF_MONITOR);
591 mt7925_mcu_set_sniffer(dev, vif, monitor);
592 pm->enable = pm->enable_user && !monitor;
593 pm->ds_enable = pm->ds_enable_user && !monitor;
595 mt7925_mcu_set_deep_sleep(dev, pm->ds_enable);
598 mt7925_mcu_set_beacon_filter(dev, vif, false);
601 void mt7925_set_runtime_pm(struct mt792x_dev *dev)
603 struct ieee80211_hw *hw = mt76_hw(dev);
604 struct mt76_connac_pm *pm = &dev->pm;
605 bool monitor = !!(hw->conf.flags & IEEE80211_CONF_MONITOR);
607 pm->enable = pm->enable_user && !monitor;
608 ieee80211_iterate_active_interfaces(hw,
609 IEEE80211_IFACE_ITER_RESUME_ALL,
610 mt7925_pm_interface_iter, dev);
611 pm->ds_enable = pm->ds_enable_user && !monitor;
612 mt7925_mcu_set_deep_sleep(dev, pm->ds_enable);
615 static int mt7925_config(struct ieee80211_hw *hw, u32 changed)
617 struct mt792x_dev *dev = mt792x_hw_dev(hw);
620 mt792x_mutex_acquire(dev);
622 if (changed & IEEE80211_CONF_CHANGE_POWER) {
623 ret = mt7925_set_tx_sar_pwr(hw, NULL);
628 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
629 ieee80211_iterate_active_interfaces(hw,
630 IEEE80211_IFACE_ITER_RESUME_ALL,
631 mt7925_sniffer_interface_iter, dev);
635 mt792x_mutex_release(dev);
640 static void mt7925_configure_filter(struct ieee80211_hw *hw,
641 unsigned int changed_flags,
642 unsigned int *total_flags,
645 #define MT7925_FILTER_FCSFAIL BIT(2)
646 #define MT7925_FILTER_CONTROL BIT(5)
647 #define MT7925_FILTER_OTHER_BSS BIT(6)
648 #define MT7925_FILTER_ENABLE BIT(31)
649 struct mt792x_dev *dev = mt792x_hw_dev(hw);
650 u32 flags = MT7925_FILTER_ENABLE;
652 #define MT7925_FILTER(_fif, _type) do { \
653 if (*total_flags & (_fif)) \
654 flags |= MT7925_FILTER_##_type; \
657 MT7925_FILTER(FIF_FCSFAIL, FCSFAIL);
658 MT7925_FILTER(FIF_CONTROL, CONTROL);
659 MT7925_FILTER(FIF_OTHER_BSS, OTHER_BSS);
661 mt792x_mutex_acquire(dev);
662 mt7925_mcu_set_rxfilter(dev, flags, 0, 0);
663 mt792x_mutex_release(dev);
665 *total_flags &= (FIF_OTHER_BSS | FIF_FCSFAIL | FIF_CONTROL);
669 mt7925_get_rates_table(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
670 bool beacon, bool mcast)
672 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
673 struct mt76_phy *mphy = hw->priv;
677 rate = mt76_connac2_mac_tx_rate_val(mphy, vif, beacon, mcast);
678 ht = FIELD_GET(MT_TX_RATE_MODE, rate) > MT_PHY_TYPE_OFDM;
681 struct mt792x_dev *dev = mt792x_hw_dev(hw);
684 idx = MT7925_BEACON_RATES_TBL + 2 * (mvif->idx % 20);
685 mt7925_mac_set_fixed_rate_table(dev, idx, rate);
689 idx = FIELD_GET(MT_TX_RATE_IDX, rate);
690 for (i = 0; i < ARRAY_SIZE(mt76_rates); i++)
691 if ((mt76_rates[i].hw_value & GENMASK(7, 0)) == idx)
692 return MT792x_BASIC_RATES_TBL + i;
694 return mvif->basic_rates_idx;
697 static void mt7925_bss_info_changed(struct ieee80211_hw *hw,
698 struct ieee80211_vif *vif,
699 struct ieee80211_bss_conf *info,
702 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
703 struct mt792x_phy *phy = mt792x_hw_phy(hw);
704 struct mt792x_dev *dev = mt792x_hw_dev(hw);
706 mt792x_mutex_acquire(dev);
708 if (changed & BSS_CHANGED_ERP_SLOT) {
709 int slottime = info->use_short_slot ? 9 : 20;
711 if (slottime != phy->slottime) {
712 phy->slottime = slottime;
713 mt792x_mac_set_timeing(phy);
717 if (changed & BSS_CHANGED_MCAST_RATE)
718 mvif->mcast_rates_idx =
719 mt7925_get_rates_table(hw, vif, false, true);
721 if (changed & BSS_CHANGED_BASIC_RATES)
722 mvif->basic_rates_idx =
723 mt7925_get_rates_table(hw, vif, false, false);
725 if (changed & (BSS_CHANGED_BEACON |
726 BSS_CHANGED_BEACON_ENABLED)) {
727 mvif->beacon_rates_idx =
728 mt7925_get_rates_table(hw, vif, true, false);
730 mt7925_mcu_uni_add_beacon_offload(dev, hw, vif,
731 info->enable_beacon);
734 /* ensure that enable txcmd_mode after bss_info */
735 if (changed & (BSS_CHANGED_QOS | BSS_CHANGED_BEACON_ENABLED))
736 mt7925_mcu_set_tx(dev, vif);
738 if (changed & BSS_CHANGED_PS)
739 mt7925_mcu_uni_bss_ps(dev, vif);
741 if (changed & BSS_CHANGED_ASSOC) {
742 mt7925_mcu_sta_update(dev, NULL, vif, true,
743 MT76_STA_INFO_STATE_ASSOC);
744 mt7925_mcu_set_beacon_filter(dev, vif, vif->cfg.assoc);
747 if (changed & BSS_CHANGED_ARP_FILTER) {
748 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
750 mt7925_mcu_update_arp_filter(&dev->mt76, &mvif->mt76, info);
753 mt792x_mutex_release(dev);
756 int mt7925_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
757 struct ieee80211_sta *sta)
759 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
760 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
761 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
764 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT792x_WTBL_STA - 1);
768 INIT_LIST_HEAD(&msta->wcid.poll_list);
771 msta->wcid.idx = idx;
772 msta->wcid.phy_idx = mvif->mt76.band_idx;
773 msta->wcid.tx_info |= MT_WCID_TX_INFO_SET;
774 msta->last_txs = jiffies;
776 ret = mt76_connac_pm_wake(&dev->mphy, &dev->pm);
780 if (vif->type == NL80211_IFTYPE_STATION)
781 mvif->wep_sta = msta;
783 mt7925_mac_wtbl_update(dev, idx,
784 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
786 /* should update bss info before STA add */
787 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
788 mt7925_mcu_add_bss_info(&dev->phy, mvif->mt76.ctx, vif, sta,
791 ret = mt7925_mcu_sta_update(dev, sta, vif, true,
792 MT76_STA_INFO_STATE_NONE);
796 mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
800 EXPORT_SYMBOL_GPL(mt7925_mac_sta_add);
802 void mt7925_mac_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif,
803 struct ieee80211_sta *sta)
805 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
806 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
807 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
809 mt792x_mutex_acquire(dev);
811 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
812 mt7925_mcu_add_bss_info(&dev->phy, mvif->mt76.ctx, vif, sta,
815 ewma_avg_signal_init(&msta->avg_ack_signal);
817 mt7925_mac_wtbl_update(dev, msta->wcid.idx,
818 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
819 memset(msta->airtime_ac, 0, sizeof(msta->airtime_ac));
821 mt7925_mcu_sta_update(dev, sta, vif, true, MT76_STA_INFO_STATE_ASSOC);
823 mt792x_mutex_release(dev);
825 EXPORT_SYMBOL_GPL(mt7925_mac_sta_assoc);
827 void mt7925_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
828 struct ieee80211_sta *sta)
830 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
831 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
833 mt76_connac_free_pending_tx_skbs(&dev->pm, &msta->wcid);
834 mt76_connac_pm_wake(&dev->mphy, &dev->pm);
836 mt7925_mcu_sta_update(dev, sta, vif, false, MT76_STA_INFO_STATE_NONE);
837 mt7925_mac_wtbl_update(dev, msta->wcid.idx,
838 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
840 if (vif->type == NL80211_IFTYPE_STATION) {
841 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
843 mvif->wep_sta = NULL;
844 ewma_rssi_init(&mvif->rssi);
846 mt7925_mcu_add_bss_info(&dev->phy, mvif->mt76.ctx, vif, sta,
850 spin_lock_bh(&mdev->sta_poll_lock);
851 if (!list_empty(&msta->wcid.poll_list))
852 list_del_init(&msta->wcid.poll_list);
853 spin_unlock_bh(&mdev->sta_poll_lock);
855 mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
857 EXPORT_SYMBOL_GPL(mt7925_mac_sta_remove);
859 static int mt7925_set_rts_threshold(struct ieee80211_hw *hw, u32 val)
861 struct mt792x_dev *dev = mt792x_hw_dev(hw);
863 mt792x_mutex_acquire(dev);
864 mt7925_mcu_set_rts_thresh(&dev->phy, val);
865 mt792x_mutex_release(dev);
871 mt7925_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
872 struct ieee80211_ampdu_params *params)
874 enum ieee80211_ampdu_mlme_action action = params->action;
875 struct mt792x_dev *dev = mt792x_hw_dev(hw);
876 struct ieee80211_sta *sta = params->sta;
877 struct ieee80211_txq *txq = sta->txq[params->tid];
878 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
879 u16 tid = params->tid;
880 u16 ssn = params->ssn;
881 struct mt76_txq *mtxq;
887 mtxq = (struct mt76_txq *)txq->drv_priv;
889 mt792x_mutex_acquire(dev);
891 case IEEE80211_AMPDU_RX_START:
892 mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, ssn,
894 mt7925_mcu_uni_rx_ba(dev, params, true);
896 case IEEE80211_AMPDU_RX_STOP:
897 mt76_rx_aggr_stop(&dev->mt76, &msta->wcid, tid);
898 mt7925_mcu_uni_rx_ba(dev, params, false);
900 case IEEE80211_AMPDU_TX_OPERATIONAL:
902 mtxq->send_bar = false;
903 mt7925_mcu_uni_tx_ba(dev, params, true);
905 case IEEE80211_AMPDU_TX_STOP_FLUSH:
906 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
908 clear_bit(tid, &msta->wcid.ampdu_state);
909 mt7925_mcu_uni_tx_ba(dev, params, false);
911 case IEEE80211_AMPDU_TX_START:
912 set_bit(tid, &msta->wcid.ampdu_state);
913 ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
915 case IEEE80211_AMPDU_TX_STOP_CONT:
917 clear_bit(tid, &msta->wcid.ampdu_state);
918 mt7925_mcu_uni_tx_ba(dev, params, false);
919 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
922 mt792x_mutex_release(dev);
927 static bool is_valid_alpha2(const char *alpha2)
932 if (alpha2[0] == '0' && alpha2[1] == '0')
935 if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
941 void mt7925_scan_work(struct work_struct *work)
943 struct mt792x_phy *phy;
945 phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy,
949 struct mt76_dev *mdev = &phy->dev->mt76;
954 spin_lock_bh(&phy->dev->mt76.lock);
955 skb = __skb_dequeue(&phy->scan_event_list);
956 spin_unlock_bh(&phy->dev->mt76.lock);
961 skb_pull(skb, sizeof(struct mt7925_mcu_rxd) + 4);
962 tlv = (struct tlv *)skb->data;
965 while (tlv_len > 0 && le16_to_cpu(tlv->len) <= tlv_len) {
966 struct mt7925_mcu_scan_chinfo_event *evt;
968 switch (le16_to_cpu(tlv->tag)) {
969 case UNI_EVENT_SCAN_DONE_BASIC:
970 if (test_and_clear_bit(MT76_HW_SCANNING, &phy->mt76->state)) {
971 struct cfg80211_scan_info info = {
974 ieee80211_scan_completed(phy->mt76->hw, &info);
977 case UNI_EVENT_SCAN_DONE_CHNLINFO:
978 evt = (struct mt7925_mcu_scan_chinfo_event *)tlv->data;
980 if (!is_valid_alpha2(evt->alpha2))
983 if (mdev->alpha2[0] != '0' && mdev->alpha2[1] != '0')
986 mt7925_mcu_set_clc(phy->dev, evt->alpha2, ENVIRON_INDOOR);
989 case UNI_EVENT_SCAN_DONE_NLO:
990 ieee80211_sched_scan_results(phy->mt76->hw);
996 tlv_len -= le16_to_cpu(tlv->len);
997 tlv = (struct tlv *)((char *)(tlv) + le16_to_cpu(tlv->len));
1005 mt7925_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1006 struct ieee80211_scan_request *req)
1008 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1009 struct mt76_phy *mphy = hw->priv;
1012 mt792x_mutex_acquire(dev);
1013 err = mt7925_mcu_hw_scan(mphy, vif, req);
1014 mt792x_mutex_release(dev);
1020 mt7925_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1022 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1023 struct mt76_phy *mphy = hw->priv;
1025 mt792x_mutex_acquire(dev);
1026 mt7925_mcu_cancel_hw_scan(mphy, vif);
1027 mt792x_mutex_release(dev);
1031 mt7925_start_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1032 struct cfg80211_sched_scan_request *req,
1033 struct ieee80211_scan_ies *ies)
1035 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1036 struct mt76_phy *mphy = hw->priv;
1039 mt792x_mutex_acquire(dev);
1041 err = mt7925_mcu_sched_scan_req(mphy, vif, req);
1045 err = mt7925_mcu_sched_scan_enable(mphy, vif, true);
1047 mt792x_mutex_release(dev);
1053 mt7925_stop_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1055 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1056 struct mt76_phy *mphy = hw->priv;
1059 mt792x_mutex_acquire(dev);
1060 err = mt7925_mcu_sched_scan_enable(mphy, vif, false);
1061 mt792x_mutex_release(dev);
1067 mt7925_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
1069 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1070 struct mt792x_phy *phy = mt792x_hw_phy(hw);
1071 int max_nss = hweight8(hw->wiphy->available_antennas_tx);
1073 if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss)
1076 if ((BIT(hweight8(tx_ant)) - 1) != tx_ant)
1077 tx_ant = BIT(ffs(tx_ant) - 1) - 1;
1079 mt792x_mutex_acquire(dev);
1081 phy->mt76->antenna_mask = tx_ant;
1082 phy->mt76->chainmask = tx_ant;
1084 mt76_set_stream_caps(phy->mt76, true);
1085 mt7925_set_stream_he_eht_caps(phy);
1087 /* TODO: update bmc_wtbl spe_idx when antenna changes */
1088 mt792x_mutex_release(dev);
1094 static int mt7925_suspend(struct ieee80211_hw *hw,
1095 struct cfg80211_wowlan *wowlan)
1097 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1098 struct mt792x_phy *phy = mt792x_hw_phy(hw);
1100 cancel_delayed_work_sync(&phy->scan_work);
1101 cancel_delayed_work_sync(&phy->mt76->mac_work);
1103 cancel_delayed_work_sync(&dev->pm.ps_work);
1104 mt76_connac_free_pending_tx_skbs(&dev->pm, NULL);
1106 mt792x_mutex_acquire(dev);
1108 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
1109 ieee80211_iterate_active_interfaces(hw,
1110 IEEE80211_IFACE_ITER_RESUME_ALL,
1111 mt7925_mcu_set_suspend_iter,
1114 mt792x_mutex_release(dev);
1119 static int mt7925_resume(struct ieee80211_hw *hw)
1121 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1122 struct mt792x_phy *phy = mt792x_hw_phy(hw);
1124 mt792x_mutex_acquire(dev);
1126 set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
1127 ieee80211_iterate_active_interfaces(hw,
1128 IEEE80211_IFACE_ITER_RESUME_ALL,
1129 mt7925_mcu_set_suspend_iter,
1132 ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
1133 MT792x_WATCHDOG_TIME);
1135 mt792x_mutex_release(dev);
1140 static void mt7925_set_rekey_data(struct ieee80211_hw *hw,
1141 struct ieee80211_vif *vif,
1142 struct cfg80211_gtk_rekey_data *data)
1144 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1146 mt792x_mutex_acquire(dev);
1147 mt76_connac_mcu_update_gtk_rekey(hw, vif, data);
1148 mt792x_mutex_release(dev);
1150 #endif /* CONFIG_PM */
1152 static void mt7925_sta_set_decap_offload(struct ieee80211_hw *hw,
1153 struct ieee80211_vif *vif,
1154 struct ieee80211_sta *sta,
1157 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
1158 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1160 mt792x_mutex_acquire(dev);
1163 set_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags);
1165 clear_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags);
1167 mt7925_mcu_wtbl_update_hdr_trans(dev, vif, sta);
1169 mt792x_mutex_release(dev);
1172 #if IS_ENABLED(CONFIG_IPV6)
1173 static void mt7925_ipv6_addr_change(struct ieee80211_hw *hw,
1174 struct ieee80211_vif *vif,
1175 struct inet6_dev *idev)
1177 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1178 struct mt792x_dev *dev = mvif->phy->dev;
1179 struct inet6_ifaddr *ifa;
1180 struct sk_buff *skb;
1188 struct mt7925_arpns_tlv arpns;
1189 struct in6_addr ns_addrs[IEEE80211_BSS_ARP_ADDR_LIST_LEN];
1192 .bss_idx = mvif->mt76.idx,
1195 .tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_ND),
1196 .len = cpu_to_le16(sizeof(req_hdr) - 4),
1201 read_lock_bh(&idev->lock);
1202 list_for_each_entry(ifa, &idev->addr_list, if_list) {
1203 if (ifa->flags & IFA_F_TENTATIVE)
1205 req_hdr.ns_addrs[idx] = ifa->addr;
1206 if (++idx >= IEEE80211_BSS_ARP_ADDR_LIST_LEN)
1209 read_unlock_bh(&idev->lock);
1214 req_hdr.arpns.ips_num = idx;
1216 skb = __mt76_mcu_msg_alloc(&dev->mt76, NULL, sizeof(req_hdr),
1221 skb_put_data(skb, &req_hdr, sizeof(req_hdr));
1223 skb_queue_tail(&dev->ipv6_ns_list, skb);
1225 ieee80211_queue_work(dev->mt76.hw, &dev->ipv6_ns_work);
1229 int mt7925_set_tx_sar_pwr(struct ieee80211_hw *hw,
1230 const struct cfg80211_sar_specs *sar)
1232 struct mt76_phy *mphy = hw->priv;
1235 int err = mt76_init_sar_power(hw, sar);
1240 mt792x_init_acpi_sar_power(mt792x_hw_phy(hw), !sar);
1242 return mt7925_mcu_set_rate_txpower(mphy);
1245 static int mt7925_set_sar_specs(struct ieee80211_hw *hw,
1246 const struct cfg80211_sar_specs *sar)
1248 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1251 mt792x_mutex_acquire(dev);
1252 err = mt7925_mcu_set_clc(dev, dev->mt76.alpha2,
1253 dev->country_ie_env);
1257 err = mt7925_set_tx_sar_pwr(hw, sar);
1259 mt792x_mutex_release(dev);
1265 mt7925_channel_switch_beacon(struct ieee80211_hw *hw,
1266 struct ieee80211_vif *vif,
1267 struct cfg80211_chan_def *chandef)
1269 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1271 mt792x_mutex_acquire(dev);
1272 mt7925_mcu_uni_add_beacon_offload(dev, hw, vif, true);
1273 mt792x_mutex_release(dev);
1277 mt7925_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1278 struct ieee80211_bss_conf *link_conf)
1280 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1281 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1284 mt792x_mutex_acquire(dev);
1286 err = mt7925_mcu_add_bss_info(&dev->phy, mvif->mt76.ctx, vif, NULL,
1291 err = mt7925_mcu_set_bss_pm(dev, vif, true);
1295 err = mt7925_mcu_sta_update(dev, NULL, vif, true,
1296 MT76_STA_INFO_STATE_NONE);
1298 mt792x_mutex_release(dev);
1304 mt7925_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1305 struct ieee80211_bss_conf *link_conf)
1307 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1308 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1311 mt792x_mutex_acquire(dev);
1313 err = mt7925_mcu_set_bss_pm(dev, vif, false);
1317 mt7925_mcu_add_bss_info(&dev->phy, mvif->mt76.ctx, vif, NULL,
1321 mt792x_mutex_release(dev);
1325 mt7925_add_chanctx(struct ieee80211_hw *hw,
1326 struct ieee80211_chanctx_conf *ctx)
1332 mt7925_remove_chanctx(struct ieee80211_hw *hw,
1333 struct ieee80211_chanctx_conf *ctx)
1337 static void mt7925_ctx_iter(void *priv, u8 *mac,
1338 struct ieee80211_vif *vif)
1340 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1341 struct ieee80211_chanctx_conf *ctx = priv;
1343 if (ctx != mvif->mt76.ctx)
1346 if (vif->type == NL80211_IFTYPE_MONITOR) {
1347 mt7925_mcu_set_sniffer(mvif->phy->dev, vif, true);
1348 mt7925_mcu_config_sniffer(mvif, ctx);
1350 mt7925_mcu_set_chctx(mvif->phy->mt76, &mvif->mt76, ctx);
1355 mt7925_change_chanctx(struct ieee80211_hw *hw,
1356 struct ieee80211_chanctx_conf *ctx,
1359 struct mt792x_phy *phy = mt792x_hw_phy(hw);
1361 mt792x_mutex_acquire(phy->dev);
1362 ieee80211_iterate_active_interfaces(phy->mt76->hw,
1363 IEEE80211_IFACE_ITER_ACTIVE,
1364 mt7925_ctx_iter, ctx);
1365 mt792x_mutex_release(phy->dev);
1368 static void mt7925_mgd_prepare_tx(struct ieee80211_hw *hw,
1369 struct ieee80211_vif *vif,
1370 struct ieee80211_prep_tx_info *info)
1372 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1373 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1374 u16 duration = info->duration ? info->duration :
1375 jiffies_to_msecs(HZ);
1377 mt792x_mutex_acquire(dev);
1378 mt7925_set_roc(mvif->phy, mvif, mvif->mt76.ctx->def.chan, duration,
1379 MT7925_ROC_REQ_JOIN);
1380 mt792x_mutex_release(dev);
1383 static void mt7925_mgd_complete_tx(struct ieee80211_hw *hw,
1384 struct ieee80211_vif *vif,
1385 struct ieee80211_prep_tx_info *info)
1387 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1389 mt7925_abort_roc(mvif->phy, mvif);
1392 const struct ieee80211_ops mt7925_ops = {
1394 .start = mt7925_start,
1395 .stop = mt792x_stop,
1396 .add_interface = mt7925_add_interface,
1397 .remove_interface = mt792x_remove_interface,
1398 .config = mt7925_config,
1399 .conf_tx = mt792x_conf_tx,
1400 .configure_filter = mt7925_configure_filter,
1401 .bss_info_changed = mt7925_bss_info_changed,
1402 .start_ap = mt7925_start_ap,
1403 .stop_ap = mt7925_stop_ap,
1404 .sta_state = mt76_sta_state,
1405 .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
1406 .set_key = mt7925_set_key,
1407 .sta_set_decap_offload = mt7925_sta_set_decap_offload,
1408 #if IS_ENABLED(CONFIG_IPV6)
1409 .ipv6_addr_change = mt7925_ipv6_addr_change,
1410 #endif /* CONFIG_IPV6 */
1411 .ampdu_action = mt7925_ampdu_action,
1412 .set_rts_threshold = mt7925_set_rts_threshold,
1413 .wake_tx_queue = mt76_wake_tx_queue,
1414 .release_buffered_frames = mt76_release_buffered_frames,
1415 .channel_switch_beacon = mt7925_channel_switch_beacon,
1416 .get_txpower = mt76_get_txpower,
1417 .get_stats = mt792x_get_stats,
1418 .get_et_sset_count = mt792x_get_et_sset_count,
1419 .get_et_strings = mt792x_get_et_strings,
1420 .get_et_stats = mt792x_get_et_stats,
1421 .get_tsf = mt792x_get_tsf,
1422 .set_tsf = mt792x_set_tsf,
1423 .get_survey = mt76_get_survey,
1424 .get_antenna = mt76_get_antenna,
1425 .set_antenna = mt7925_set_antenna,
1426 .set_coverage_class = mt792x_set_coverage_class,
1427 .hw_scan = mt7925_hw_scan,
1428 .cancel_hw_scan = mt7925_cancel_hw_scan,
1429 .sta_statistics = mt792x_sta_statistics,
1430 .sched_scan_start = mt7925_start_sched_scan,
1431 .sched_scan_stop = mt7925_stop_sched_scan,
1433 .suspend = mt7925_suspend,
1434 .resume = mt7925_resume,
1435 .set_wakeup = mt792x_set_wakeup,
1436 .set_rekey_data = mt7925_set_rekey_data,
1437 #endif /* CONFIG_PM */
1438 .flush = mt792x_flush,
1439 .set_sar_specs = mt7925_set_sar_specs,
1440 .remain_on_channel = mt7925_remain_on_channel,
1441 .cancel_remain_on_channel = mt7925_cancel_remain_on_channel,
1442 .add_chanctx = mt7925_add_chanctx,
1443 .remove_chanctx = mt7925_remove_chanctx,
1444 .change_chanctx = mt7925_change_chanctx,
1445 .assign_vif_chanctx = mt792x_assign_vif_chanctx,
1446 .unassign_vif_chanctx = mt792x_unassign_vif_chanctx,
1447 .mgd_prepare_tx = mt7925_mgd_prepare_tx,
1448 .mgd_complete_tx = mt7925_mgd_complete_tx,
1450 EXPORT_SYMBOL_GPL(mt7925_ops);
1452 MODULE_AUTHOR("Deren Wu <deren.wu@mediatek.com>");
1453 MODULE_DESCRIPTION("MediaTek MT7925 core driver");
1454 MODULE_LICENSE("Dual BSD/GPL");