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,
158 enum nl80211_iftype iftype)
160 struct ieee80211_sta_eht_cap *eht_cap = &data->eht_cap;
161 struct ieee80211_eht_cap_elem_fixed *eht_cap_elem = &eht_cap->eht_cap_elem;
162 struct ieee80211_eht_mcs_nss_supp *eht_nss = &eht_cap->eht_mcs_nss_supp;
163 enum nl80211_chan_width width = phy->mt76->chandef.width;
164 int nss = hweight8(phy->mt76->antenna_mask);
165 int sts = hweight16(phy->mt76->chainmask);
168 if (!phy->dev->has_eht)
171 eht_cap->has_eht = true;
173 eht_cap_elem->mac_cap_info[0] =
174 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
175 IEEE80211_EHT_MAC_CAP0_OM_CONTROL;
177 eht_cap_elem->phy_cap_info[0] =
178 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
179 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
180 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE;
182 eht_cap_elem->phy_cap_info[0] |=
183 u8_encode_bits(u8_get_bits(sts - 1, BIT(0)),
184 IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK);
186 eht_cap_elem->phy_cap_info[1] =
187 u8_encode_bits(u8_get_bits(sts - 1, GENMASK(2, 1)),
188 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK) |
189 u8_encode_bits(sts - 1,
190 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK);
192 eht_cap_elem->phy_cap_info[2] =
193 u8_encode_bits(sts - 1, IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK) |
194 u8_encode_bits(sts - 1, IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK);
196 eht_cap_elem->phy_cap_info[3] =
197 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
198 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
199 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
200 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
201 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
202 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
203 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK;
205 eht_cap_elem->phy_cap_info[4] =
206 u8_encode_bits(min_t(int, sts - 1, 2),
207 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK);
209 eht_cap_elem->phy_cap_info[5] =
210 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
211 u8_encode_bits(IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US,
212 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK) |
213 u8_encode_bits(u8_get_bits(0x11, GENMASK(1, 0)),
214 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK);
216 val = width == NL80211_CHAN_WIDTH_160 ? 0x7 :
217 width == NL80211_CHAN_WIDTH_80 ? 0x3 : 0x1;
218 eht_cap_elem->phy_cap_info[6] =
219 u8_encode_bits(u8_get_bits(0x11, GENMASK(4, 2)),
220 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK) |
221 u8_encode_bits(val, IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK);
223 eht_cap_elem->phy_cap_info[7] =
224 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
225 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
226 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
227 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ;
229 val = u8_encode_bits(nss, IEEE80211_EHT_MCS_NSS_RX) |
230 u8_encode_bits(nss, IEEE80211_EHT_MCS_NSS_TX);
232 eht_nss->bw._80.rx_tx_mcs9_max_nss = val;
233 eht_nss->bw._80.rx_tx_mcs11_max_nss = val;
234 eht_nss->bw._80.rx_tx_mcs13_max_nss = val;
235 eht_nss->bw._160.rx_tx_mcs9_max_nss = val;
236 eht_nss->bw._160.rx_tx_mcs11_max_nss = val;
237 eht_nss->bw._160.rx_tx_mcs13_max_nss = val;
241 __mt7925_set_stream_he_eht_caps(struct mt792x_phy *phy,
242 struct ieee80211_supported_band *sband,
243 enum nl80211_band band)
245 struct ieee80211_sband_iftype_data *data = phy->iftype[band];
248 for (i = 0; i < NUM_NL80211_IFTYPES; i++) {
250 case NL80211_IFTYPE_STATION:
251 case NL80211_IFTYPE_AP:
257 data[n].types_mask = BIT(i);
258 mt7925_init_he_caps(phy, band, &data[n], i);
259 mt7925_init_eht_caps(phy, band, &data[n], i);
264 _ieee80211_set_sband_iftype_data(sband, data, n);
267 void mt7925_set_stream_he_eht_caps(struct mt792x_phy *phy)
269 if (phy->mt76->cap.has_2ghz)
270 __mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_2g.sband,
273 if (phy->mt76->cap.has_5ghz)
274 __mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_5g.sband,
277 if (phy->mt76->cap.has_6ghz)
278 __mt7925_set_stream_he_eht_caps(phy, &phy->mt76->sband_6g.sband,
282 int __mt7925_start(struct mt792x_phy *phy)
284 struct mt76_phy *mphy = phy->mt76;
287 err = mt7925_mcu_set_channel_domain(mphy);
291 err = mt7925_mcu_set_rts_thresh(phy, 0x92b);
295 err = mt7925_set_tx_sar_pwr(mphy->hw, NULL);
299 mt792x_mac_reset_counters(phy);
300 set_bit(MT76_STATE_RUNNING, &mphy->state);
302 ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
303 MT792x_WATCHDOG_TIME);
307 EXPORT_SYMBOL_GPL(__mt7925_start);
309 static int mt7925_start(struct ieee80211_hw *hw)
311 struct mt792x_phy *phy = mt792x_hw_phy(hw);
314 mt792x_mutex_acquire(phy->dev);
315 err = __mt7925_start(phy);
316 mt792x_mutex_release(phy->dev);
322 mt7925_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
324 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
325 struct mt792x_dev *dev = mt792x_hw_dev(hw);
326 struct mt792x_phy *phy = mt792x_hw_phy(hw);
327 struct mt76_txq *mtxq;
330 mt792x_mutex_acquire(dev);
332 mvif->mt76.idx = __ffs64(~dev->mt76.vif_mask);
333 if (mvif->mt76.idx >= MT792x_MAX_INTERFACES) {
338 mvif->mt76.omac_idx = mvif->mt76.idx;
340 mvif->mt76.band_idx = 0;
341 mvif->mt76.wmm_idx = mvif->mt76.idx % MT76_CONNAC_MAX_WMM_SETS;
343 if (phy->mt76->chandef.chan->band != NL80211_BAND_2GHZ)
344 mvif->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL + 4;
346 mvif->mt76.basic_rates_idx = MT792x_BASIC_RATES_TBL;
348 ret = mt76_connac_mcu_uni_add_dev(&dev->mphy, vif, &mvif->sta.wcid,
353 dev->mt76.vif_mask |= BIT_ULL(mvif->mt76.idx);
354 phy->omac_mask |= BIT_ULL(mvif->mt76.omac_idx);
356 idx = MT792x_WTBL_RESERVED - mvif->mt76.idx;
358 INIT_LIST_HEAD(&mvif->sta.wcid.poll_list);
359 mvif->sta.wcid.idx = idx;
360 mvif->sta.wcid.phy_idx = mvif->mt76.band_idx;
361 mvif->sta.wcid.hw_key_idx = -1;
362 mvif->sta.wcid.tx_info |= MT_WCID_TX_INFO_SET;
363 mt76_wcid_init(&mvif->sta.wcid);
365 mt7925_mac_wtbl_update(dev, idx,
366 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
368 ewma_rssi_init(&mvif->rssi);
370 rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid);
372 mtxq = (struct mt76_txq *)vif->txq->drv_priv;
376 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
378 mt792x_mutex_release(dev);
383 static void mt7925_roc_iter(void *priv, u8 *mac,
384 struct ieee80211_vif *vif)
386 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
387 struct mt792x_phy *phy = priv;
389 mt7925_mcu_abort_roc(phy, mvif, phy->roc_token_id);
392 void mt7925_roc_work(struct work_struct *work)
394 struct mt792x_phy *phy;
396 phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy,
399 if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
402 mt792x_mutex_acquire(phy->dev);
403 ieee80211_iterate_active_interfaces(phy->mt76->hw,
404 IEEE80211_IFACE_ITER_RESUME_ALL,
405 mt7925_roc_iter, phy);
406 mt792x_mutex_release(phy->dev);
407 ieee80211_remain_on_channel_expired(phy->mt76->hw);
410 static int mt7925_abort_roc(struct mt792x_phy *phy, struct mt792x_vif *vif)
414 del_timer_sync(&phy->roc_timer);
415 cancel_work_sync(&phy->roc_work);
417 mt792x_mutex_acquire(phy->dev);
418 if (test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
419 err = mt7925_mcu_abort_roc(phy, vif, phy->roc_token_id);
420 mt792x_mutex_release(phy->dev);
425 static int mt7925_set_roc(struct mt792x_phy *phy,
426 struct mt792x_vif *vif,
427 struct ieee80211_channel *chan,
429 enum mt7925_roc_req type)
433 if (test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state))
436 phy->roc_grant = false;
438 err = mt7925_mcu_set_roc(phy, vif, chan, duration, type,
439 ++phy->roc_token_id);
441 clear_bit(MT76_STATE_ROC, &phy->mt76->state);
445 if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, 4 * HZ)) {
446 mt7925_mcu_abort_roc(phy, vif, phy->roc_token_id);
447 clear_bit(MT76_STATE_ROC, &phy->mt76->state);
455 static int mt7925_remain_on_channel(struct ieee80211_hw *hw,
456 struct ieee80211_vif *vif,
457 struct ieee80211_channel *chan,
459 enum ieee80211_roc_type type)
461 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
462 struct mt792x_phy *phy = mt792x_hw_phy(hw);
465 mt792x_mutex_acquire(phy->dev);
466 err = mt7925_set_roc(phy, mvif, chan, duration, MT7925_ROC_REQ_ROC);
467 mt792x_mutex_release(phy->dev);
472 static int mt7925_cancel_remain_on_channel(struct ieee80211_hw *hw,
473 struct ieee80211_vif *vif)
475 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
476 struct mt792x_phy *phy = mt792x_hw_phy(hw);
478 return mt7925_abort_roc(phy, mvif);
481 static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
482 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
483 struct ieee80211_key_conf *key)
485 struct mt792x_dev *dev = mt792x_hw_dev(hw);
486 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
487 struct mt792x_sta *msta = sta ? (struct mt792x_sta *)sta->drv_priv :
489 struct mt76_wcid *wcid = &msta->wcid;
490 u8 *wcid_keyidx = &wcid->hw_key_idx;
491 int idx = key->keyidx, err = 0;
493 /* The hardware does not support per-STA RX GTK, fallback
494 * to software mode for these.
496 if ((vif->type == NL80211_IFTYPE_ADHOC ||
497 vif->type == NL80211_IFTYPE_MESH_POINT) &&
498 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
499 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
500 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
503 /* fall back to sw encryption for unsupported ciphers */
504 switch (key->cipher) {
505 case WLAN_CIPHER_SUITE_AES_CMAC:
506 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
507 wcid_keyidx = &wcid->hw_key_idx2;
509 case WLAN_CIPHER_SUITE_WEP40:
510 case WLAN_CIPHER_SUITE_WEP104:
514 case WLAN_CIPHER_SUITE_TKIP:
515 case WLAN_CIPHER_SUITE_CCMP:
516 case WLAN_CIPHER_SUITE_CCMP_256:
517 case WLAN_CIPHER_SUITE_GCMP:
518 case WLAN_CIPHER_SUITE_GCMP_256:
519 case WLAN_CIPHER_SUITE_SMS4:
525 mt792x_mutex_acquire(dev);
527 if (cmd == SET_KEY && !mvif->mt76.cipher) {
528 struct mt792x_phy *phy = mt792x_hw_phy(hw);
530 mvif->mt76.cipher = mt76_connac_mcu_get_cipher(key->cipher);
531 mt7925_mcu_add_bss_info(phy, mvif->mt76.ctx, vif, sta, true);
536 else if (idx == *wcid_keyidx)
541 mt76_wcid_key_setup(&dev->mt76, wcid,
542 cmd == SET_KEY ? key : NULL);
544 err = mt7925_mcu_add_key(&dev->mt76, vif, &msta->bip,
545 key, MCU_UNI_CMD(STA_REC_UPDATE),
551 if (key->cipher == WLAN_CIPHER_SUITE_WEP104 ||
552 key->cipher == WLAN_CIPHER_SUITE_WEP40)
553 err = mt7925_mcu_add_key(&dev->mt76, vif, &mvif->wep_sta->bip,
554 key, MCU_WMWA_UNI_CMD(STA_REC_UPDATE),
555 &mvif->wep_sta->wcid, cmd);
558 mt792x_mutex_release(dev);
564 mt7925_pm_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
566 struct mt792x_dev *dev = priv;
567 struct ieee80211_hw *hw = mt76_hw(dev);
568 bool pm_enable = dev->pm.enable;
571 err = mt7925_mcu_set_beacon_filter(dev, vif, pm_enable);
576 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
577 ieee80211_hw_set(hw, CONNECTION_MONITOR);
579 vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
580 __clear_bit(IEEE80211_HW_CONNECTION_MONITOR, hw->flags);
585 mt7925_sniffer_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
587 struct mt792x_dev *dev = priv;
588 struct ieee80211_hw *hw = mt76_hw(dev);
589 struct mt76_connac_pm *pm = &dev->pm;
590 bool monitor = !!(hw->conf.flags & IEEE80211_CONF_MONITOR);
592 mt7925_mcu_set_sniffer(dev, vif, monitor);
593 pm->enable = pm->enable_user && !monitor;
594 pm->ds_enable = pm->ds_enable_user && !monitor;
596 mt7925_mcu_set_deep_sleep(dev, pm->ds_enable);
599 mt7925_mcu_set_beacon_filter(dev, vif, false);
602 void mt7925_set_runtime_pm(struct mt792x_dev *dev)
604 struct ieee80211_hw *hw = mt76_hw(dev);
605 struct mt76_connac_pm *pm = &dev->pm;
606 bool monitor = !!(hw->conf.flags & IEEE80211_CONF_MONITOR);
608 pm->enable = pm->enable_user && !monitor;
609 ieee80211_iterate_active_interfaces(hw,
610 IEEE80211_IFACE_ITER_RESUME_ALL,
611 mt7925_pm_interface_iter, dev);
612 pm->ds_enable = pm->ds_enable_user && !monitor;
613 mt7925_mcu_set_deep_sleep(dev, pm->ds_enable);
616 static int mt7925_config(struct ieee80211_hw *hw, u32 changed)
618 struct mt792x_dev *dev = mt792x_hw_dev(hw);
621 mt792x_mutex_acquire(dev);
623 if (changed & IEEE80211_CONF_CHANGE_POWER) {
624 ret = mt7925_set_tx_sar_pwr(hw, NULL);
629 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
630 ieee80211_iterate_active_interfaces(hw,
631 IEEE80211_IFACE_ITER_RESUME_ALL,
632 mt7925_sniffer_interface_iter, dev);
636 mt792x_mutex_release(dev);
641 static void mt7925_configure_filter(struct ieee80211_hw *hw,
642 unsigned int changed_flags,
643 unsigned int *total_flags,
646 #define MT7925_FILTER_FCSFAIL BIT(2)
647 #define MT7925_FILTER_CONTROL BIT(5)
648 #define MT7925_FILTER_OTHER_BSS BIT(6)
649 #define MT7925_FILTER_ENABLE BIT(31)
650 struct mt792x_dev *dev = mt792x_hw_dev(hw);
651 u32 flags = MT7925_FILTER_ENABLE;
653 #define MT7925_FILTER(_fif, _type) do { \
654 if (*total_flags & (_fif)) \
655 flags |= MT7925_FILTER_##_type; \
658 MT7925_FILTER(FIF_FCSFAIL, FCSFAIL);
659 MT7925_FILTER(FIF_CONTROL, CONTROL);
660 MT7925_FILTER(FIF_OTHER_BSS, OTHER_BSS);
662 mt792x_mutex_acquire(dev);
663 mt7925_mcu_set_rxfilter(dev, flags, 0, 0);
664 mt792x_mutex_release(dev);
666 *total_flags &= (FIF_OTHER_BSS | FIF_FCSFAIL | FIF_CONTROL);
670 mt7925_get_rates_table(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
671 bool beacon, bool mcast)
673 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
674 struct mt76_phy *mphy = hw->priv;
678 rate = mt76_connac2_mac_tx_rate_val(mphy, vif, beacon, mcast);
679 ht = FIELD_GET(MT_TX_RATE_MODE, rate) > MT_PHY_TYPE_OFDM;
682 struct mt792x_dev *dev = mt792x_hw_dev(hw);
685 idx = MT7925_BEACON_RATES_TBL + 2 * (mvif->idx % 20);
686 mt7925_mac_set_fixed_rate_table(dev, idx, rate);
690 idx = FIELD_GET(MT_TX_RATE_IDX, rate);
691 for (i = 0; i < ARRAY_SIZE(mt76_rates); i++)
692 if ((mt76_rates[i].hw_value & GENMASK(7, 0)) == idx)
693 return MT792x_BASIC_RATES_TBL + i;
695 return mvif->basic_rates_idx;
698 static void mt7925_bss_info_changed(struct ieee80211_hw *hw,
699 struct ieee80211_vif *vif,
700 struct ieee80211_bss_conf *info,
703 struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
704 struct mt792x_phy *phy = mt792x_hw_phy(hw);
705 struct mt792x_dev *dev = mt792x_hw_dev(hw);
707 mt792x_mutex_acquire(dev);
709 if (changed & BSS_CHANGED_ERP_SLOT) {
710 int slottime = info->use_short_slot ? 9 : 20;
712 if (slottime != phy->slottime) {
713 phy->slottime = slottime;
714 mt792x_mac_set_timeing(phy);
718 if (changed & BSS_CHANGED_MCAST_RATE)
719 mvif->mcast_rates_idx =
720 mt7925_get_rates_table(hw, vif, false, true);
722 if (changed & BSS_CHANGED_BASIC_RATES)
723 mvif->basic_rates_idx =
724 mt7925_get_rates_table(hw, vif, false, false);
726 if (changed & (BSS_CHANGED_BEACON |
727 BSS_CHANGED_BEACON_ENABLED)) {
728 mvif->beacon_rates_idx =
729 mt7925_get_rates_table(hw, vif, true, false);
731 mt7925_mcu_uni_add_beacon_offload(dev, hw, vif,
732 info->enable_beacon);
735 /* ensure that enable txcmd_mode after bss_info */
736 if (changed & (BSS_CHANGED_QOS | BSS_CHANGED_BEACON_ENABLED))
737 mt7925_mcu_set_tx(dev, vif);
739 if (changed & BSS_CHANGED_PS)
740 mt7925_mcu_uni_bss_ps(dev, vif);
742 if (changed & BSS_CHANGED_ASSOC) {
743 mt7925_mcu_sta_update(dev, NULL, vif, true,
744 MT76_STA_INFO_STATE_ASSOC);
745 mt7925_mcu_set_beacon_filter(dev, vif, vif->cfg.assoc);
748 if (changed & BSS_CHANGED_ARP_FILTER) {
749 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
751 mt7925_mcu_update_arp_filter(&dev->mt76, &mvif->mt76, info);
754 mt792x_mutex_release(dev);
757 int mt7925_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
758 struct ieee80211_sta *sta)
760 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
761 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
762 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
765 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT792x_WTBL_STA - 1);
769 INIT_LIST_HEAD(&msta->wcid.poll_list);
772 msta->wcid.idx = idx;
773 msta->wcid.phy_idx = mvif->mt76.band_idx;
774 msta->wcid.tx_info |= MT_WCID_TX_INFO_SET;
775 msta->last_txs = jiffies;
777 ret = mt76_connac_pm_wake(&dev->mphy, &dev->pm);
781 if (vif->type == NL80211_IFTYPE_STATION)
782 mvif->wep_sta = msta;
784 mt7925_mac_wtbl_update(dev, idx,
785 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
787 /* should update bss info before STA add */
788 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
789 mt7925_mcu_add_bss_info(&dev->phy, mvif->mt76.ctx, vif, sta,
792 ret = mt7925_mcu_sta_update(dev, sta, vif, true,
793 MT76_STA_INFO_STATE_NONE);
797 mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
801 EXPORT_SYMBOL_GPL(mt7925_mac_sta_add);
803 void mt7925_mac_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif,
804 struct ieee80211_sta *sta)
806 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
807 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
808 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
810 mt792x_mutex_acquire(dev);
812 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
813 mt7925_mcu_add_bss_info(&dev->phy, mvif->mt76.ctx, vif, sta,
816 ewma_avg_signal_init(&msta->avg_ack_signal);
818 mt7925_mac_wtbl_update(dev, msta->wcid.idx,
819 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
820 memset(msta->airtime_ac, 0, sizeof(msta->airtime_ac));
822 mt7925_mcu_sta_update(dev, sta, vif, true, MT76_STA_INFO_STATE_ASSOC);
824 mt792x_mutex_release(dev);
826 EXPORT_SYMBOL_GPL(mt7925_mac_sta_assoc);
828 void mt7925_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
829 struct ieee80211_sta *sta)
831 struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
832 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
834 mt76_connac_free_pending_tx_skbs(&dev->pm, &msta->wcid);
835 mt76_connac_pm_wake(&dev->mphy, &dev->pm);
837 mt7925_mcu_sta_update(dev, sta, vif, false, MT76_STA_INFO_STATE_NONE);
838 mt7925_mac_wtbl_update(dev, msta->wcid.idx,
839 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
841 if (vif->type == NL80211_IFTYPE_STATION) {
842 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
844 mvif->wep_sta = NULL;
845 ewma_rssi_init(&mvif->rssi);
847 mt7925_mcu_add_bss_info(&dev->phy, mvif->mt76.ctx, vif, sta,
851 spin_lock_bh(&mdev->sta_poll_lock);
852 if (!list_empty(&msta->wcid.poll_list))
853 list_del_init(&msta->wcid.poll_list);
854 spin_unlock_bh(&mdev->sta_poll_lock);
856 mt76_connac_power_save_sched(&dev->mphy, &dev->pm);
858 EXPORT_SYMBOL_GPL(mt7925_mac_sta_remove);
860 static int mt7925_set_rts_threshold(struct ieee80211_hw *hw, u32 val)
862 struct mt792x_dev *dev = mt792x_hw_dev(hw);
864 mt792x_mutex_acquire(dev);
865 mt7925_mcu_set_rts_thresh(&dev->phy, val);
866 mt792x_mutex_release(dev);
872 mt7925_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
873 struct ieee80211_ampdu_params *params)
875 enum ieee80211_ampdu_mlme_action action = params->action;
876 struct mt792x_dev *dev = mt792x_hw_dev(hw);
877 struct ieee80211_sta *sta = params->sta;
878 struct ieee80211_txq *txq = sta->txq[params->tid];
879 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
880 u16 tid = params->tid;
881 u16 ssn = params->ssn;
882 struct mt76_txq *mtxq;
888 mtxq = (struct mt76_txq *)txq->drv_priv;
890 mt792x_mutex_acquire(dev);
892 case IEEE80211_AMPDU_RX_START:
893 mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, ssn,
895 mt7925_mcu_uni_rx_ba(dev, params, true);
897 case IEEE80211_AMPDU_RX_STOP:
898 mt76_rx_aggr_stop(&dev->mt76, &msta->wcid, tid);
899 mt7925_mcu_uni_rx_ba(dev, params, false);
901 case IEEE80211_AMPDU_TX_OPERATIONAL:
903 mtxq->send_bar = false;
904 mt7925_mcu_uni_tx_ba(dev, params, true);
906 case IEEE80211_AMPDU_TX_STOP_FLUSH:
907 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
909 clear_bit(tid, &msta->wcid.ampdu_state);
910 mt7925_mcu_uni_tx_ba(dev, params, false);
912 case IEEE80211_AMPDU_TX_START:
913 set_bit(tid, &msta->wcid.ampdu_state);
914 ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
916 case IEEE80211_AMPDU_TX_STOP_CONT:
918 clear_bit(tid, &msta->wcid.ampdu_state);
919 mt7925_mcu_uni_tx_ba(dev, params, false);
920 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
923 mt792x_mutex_release(dev);
928 static bool is_valid_alpha2(const char *alpha2)
933 if (alpha2[0] == '0' && alpha2[1] == '0')
936 if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
942 void mt7925_scan_work(struct work_struct *work)
944 struct mt792x_phy *phy;
946 phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy,
950 struct mt76_dev *mdev = &phy->dev->mt76;
955 spin_lock_bh(&phy->dev->mt76.lock);
956 skb = __skb_dequeue(&phy->scan_event_list);
957 spin_unlock_bh(&phy->dev->mt76.lock);
962 skb_pull(skb, sizeof(struct mt7925_mcu_rxd) + 4);
963 tlv = (struct tlv *)skb->data;
966 while (tlv_len > 0 && le16_to_cpu(tlv->len) <= tlv_len) {
967 struct mt7925_mcu_scan_chinfo_event *evt;
969 switch (le16_to_cpu(tlv->tag)) {
970 case UNI_EVENT_SCAN_DONE_BASIC:
971 if (test_and_clear_bit(MT76_HW_SCANNING, &phy->mt76->state)) {
972 struct cfg80211_scan_info info = {
975 ieee80211_scan_completed(phy->mt76->hw, &info);
978 case UNI_EVENT_SCAN_DONE_CHNLINFO:
979 evt = (struct mt7925_mcu_scan_chinfo_event *)tlv->data;
981 if (!is_valid_alpha2(evt->alpha2))
984 if (mdev->alpha2[0] != '0' && mdev->alpha2[1] != '0')
987 mt7925_mcu_set_clc(phy->dev, evt->alpha2, ENVIRON_INDOOR);
990 case UNI_EVENT_SCAN_DONE_NLO:
991 ieee80211_sched_scan_results(phy->mt76->hw);
997 tlv_len -= le16_to_cpu(tlv->len);
998 tlv = (struct tlv *)((char *)(tlv) + le16_to_cpu(tlv->len));
1006 mt7925_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1007 struct ieee80211_scan_request *req)
1009 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1010 struct mt76_phy *mphy = hw->priv;
1013 mt792x_mutex_acquire(dev);
1014 err = mt7925_mcu_hw_scan(mphy, vif, req);
1015 mt792x_mutex_release(dev);
1021 mt7925_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1023 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1024 struct mt76_phy *mphy = hw->priv;
1026 mt792x_mutex_acquire(dev);
1027 mt7925_mcu_cancel_hw_scan(mphy, vif);
1028 mt792x_mutex_release(dev);
1032 mt7925_start_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1033 struct cfg80211_sched_scan_request *req,
1034 struct ieee80211_scan_ies *ies)
1036 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1037 struct mt76_phy *mphy = hw->priv;
1040 mt792x_mutex_acquire(dev);
1042 err = mt7925_mcu_sched_scan_req(mphy, vif, req);
1046 err = mt7925_mcu_sched_scan_enable(mphy, vif, true);
1048 mt792x_mutex_release(dev);
1054 mt7925_stop_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1056 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1057 struct mt76_phy *mphy = hw->priv;
1060 mt792x_mutex_acquire(dev);
1061 err = mt7925_mcu_sched_scan_enable(mphy, vif, false);
1062 mt792x_mutex_release(dev);
1068 mt7925_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
1070 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1071 struct mt792x_phy *phy = mt792x_hw_phy(hw);
1072 int max_nss = hweight8(hw->wiphy->available_antennas_tx);
1074 if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss)
1077 if ((BIT(hweight8(tx_ant)) - 1) != tx_ant)
1078 tx_ant = BIT(ffs(tx_ant) - 1) - 1;
1080 mt792x_mutex_acquire(dev);
1082 phy->mt76->antenna_mask = tx_ant;
1083 phy->mt76->chainmask = tx_ant;
1085 mt76_set_stream_caps(phy->mt76, true);
1086 mt7925_set_stream_he_eht_caps(phy);
1088 /* TODO: update bmc_wtbl spe_idx when antenna changes */
1089 mt792x_mutex_release(dev);
1095 static int mt7925_suspend(struct ieee80211_hw *hw,
1096 struct cfg80211_wowlan *wowlan)
1098 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1099 struct mt792x_phy *phy = mt792x_hw_phy(hw);
1101 cancel_delayed_work_sync(&phy->scan_work);
1102 cancel_delayed_work_sync(&phy->mt76->mac_work);
1104 cancel_delayed_work_sync(&dev->pm.ps_work);
1105 mt76_connac_free_pending_tx_skbs(&dev->pm, NULL);
1107 mt792x_mutex_acquire(dev);
1109 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
1110 ieee80211_iterate_active_interfaces(hw,
1111 IEEE80211_IFACE_ITER_RESUME_ALL,
1112 mt7925_mcu_set_suspend_iter,
1115 mt792x_mutex_release(dev);
1120 static int mt7925_resume(struct ieee80211_hw *hw)
1122 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1123 struct mt792x_phy *phy = mt792x_hw_phy(hw);
1125 mt792x_mutex_acquire(dev);
1127 set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
1128 ieee80211_iterate_active_interfaces(hw,
1129 IEEE80211_IFACE_ITER_RESUME_ALL,
1130 mt7925_mcu_set_suspend_iter,
1133 ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
1134 MT792x_WATCHDOG_TIME);
1136 mt792x_mutex_release(dev);
1141 static void mt7925_set_rekey_data(struct ieee80211_hw *hw,
1142 struct ieee80211_vif *vif,
1143 struct cfg80211_gtk_rekey_data *data)
1145 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1147 mt792x_mutex_acquire(dev);
1148 mt76_connac_mcu_update_gtk_rekey(hw, vif, data);
1149 mt792x_mutex_release(dev);
1151 #endif /* CONFIG_PM */
1153 static void mt7925_sta_set_decap_offload(struct ieee80211_hw *hw,
1154 struct ieee80211_vif *vif,
1155 struct ieee80211_sta *sta,
1158 struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
1159 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1161 mt792x_mutex_acquire(dev);
1164 set_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags);
1166 clear_bit(MT_WCID_FLAG_HDR_TRANS, &msta->wcid.flags);
1168 mt7925_mcu_wtbl_update_hdr_trans(dev, vif, sta);
1170 mt792x_mutex_release(dev);
1173 #if IS_ENABLED(CONFIG_IPV6)
1174 static void mt7925_ipv6_addr_change(struct ieee80211_hw *hw,
1175 struct ieee80211_vif *vif,
1176 struct inet6_dev *idev)
1178 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1179 struct mt792x_dev *dev = mvif->phy->dev;
1180 struct inet6_ifaddr *ifa;
1181 struct sk_buff *skb;
1189 struct mt7925_arpns_tlv arpns;
1190 struct in6_addr ns_addrs[IEEE80211_BSS_ARP_ADDR_LIST_LEN];
1193 .bss_idx = mvif->mt76.idx,
1196 .tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_ND),
1197 .len = cpu_to_le16(sizeof(req_hdr) - 4),
1202 read_lock_bh(&idev->lock);
1203 list_for_each_entry(ifa, &idev->addr_list, if_list) {
1204 if (ifa->flags & IFA_F_TENTATIVE)
1206 req_hdr.ns_addrs[idx] = ifa->addr;
1207 if (++idx >= IEEE80211_BSS_ARP_ADDR_LIST_LEN)
1210 read_unlock_bh(&idev->lock);
1215 req_hdr.arpns.ips_num = idx;
1217 skb = __mt76_mcu_msg_alloc(&dev->mt76, NULL, sizeof(req_hdr),
1222 skb_put_data(skb, &req_hdr, sizeof(req_hdr));
1224 skb_queue_tail(&dev->ipv6_ns_list, skb);
1226 ieee80211_queue_work(dev->mt76.hw, &dev->ipv6_ns_work);
1230 int mt7925_set_tx_sar_pwr(struct ieee80211_hw *hw,
1231 const struct cfg80211_sar_specs *sar)
1233 struct mt76_phy *mphy = hw->priv;
1236 int err = mt76_init_sar_power(hw, sar);
1241 mt792x_init_acpi_sar_power(mt792x_hw_phy(hw), !sar);
1243 return mt7925_mcu_set_rate_txpower(mphy);
1246 static int mt7925_set_sar_specs(struct ieee80211_hw *hw,
1247 const struct cfg80211_sar_specs *sar)
1249 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1252 mt792x_mutex_acquire(dev);
1253 err = mt7925_mcu_set_clc(dev, dev->mt76.alpha2,
1254 dev->country_ie_env);
1258 err = mt7925_set_tx_sar_pwr(hw, sar);
1260 mt792x_mutex_release(dev);
1266 mt7925_channel_switch_beacon(struct ieee80211_hw *hw,
1267 struct ieee80211_vif *vif,
1268 struct cfg80211_chan_def *chandef)
1270 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1272 mt792x_mutex_acquire(dev);
1273 mt7925_mcu_uni_add_beacon_offload(dev, hw, vif, true);
1274 mt792x_mutex_release(dev);
1278 mt7925_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1279 struct ieee80211_bss_conf *link_conf)
1281 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1282 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1285 mt792x_mutex_acquire(dev);
1287 err = mt7925_mcu_add_bss_info(&dev->phy, mvif->mt76.ctx, vif, NULL,
1292 err = mt7925_mcu_set_bss_pm(dev, vif, true);
1296 err = mt7925_mcu_sta_update(dev, NULL, vif, true,
1297 MT76_STA_INFO_STATE_NONE);
1299 mt792x_mutex_release(dev);
1305 mt7925_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1306 struct ieee80211_bss_conf *link_conf)
1308 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1309 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1312 mt792x_mutex_acquire(dev);
1314 err = mt7925_mcu_set_bss_pm(dev, vif, false);
1318 mt7925_mcu_add_bss_info(&dev->phy, mvif->mt76.ctx, vif, NULL,
1322 mt792x_mutex_release(dev);
1326 mt7925_add_chanctx(struct ieee80211_hw *hw,
1327 struct ieee80211_chanctx_conf *ctx)
1333 mt7925_remove_chanctx(struct ieee80211_hw *hw,
1334 struct ieee80211_chanctx_conf *ctx)
1338 static void mt7925_ctx_iter(void *priv, u8 *mac,
1339 struct ieee80211_vif *vif)
1341 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1342 struct ieee80211_chanctx_conf *ctx = priv;
1344 if (ctx != mvif->mt76.ctx)
1347 if (vif->type == NL80211_IFTYPE_MONITOR) {
1348 mt7925_mcu_set_sniffer(mvif->phy->dev, vif, true);
1349 mt7925_mcu_config_sniffer(mvif, ctx);
1351 mt7925_mcu_set_chctx(mvif->phy->mt76, &mvif->mt76, ctx);
1356 mt7925_change_chanctx(struct ieee80211_hw *hw,
1357 struct ieee80211_chanctx_conf *ctx,
1360 struct mt792x_phy *phy = mt792x_hw_phy(hw);
1362 mt792x_mutex_acquire(phy->dev);
1363 ieee80211_iterate_active_interfaces(phy->mt76->hw,
1364 IEEE80211_IFACE_ITER_ACTIVE,
1365 mt7925_ctx_iter, ctx);
1366 mt792x_mutex_release(phy->dev);
1369 static void mt7925_mgd_prepare_tx(struct ieee80211_hw *hw,
1370 struct ieee80211_vif *vif,
1371 struct ieee80211_prep_tx_info *info)
1373 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1374 struct mt792x_dev *dev = mt792x_hw_dev(hw);
1375 u16 duration = info->duration ? info->duration :
1376 jiffies_to_msecs(HZ);
1378 mt792x_mutex_acquire(dev);
1379 mt7925_set_roc(mvif->phy, mvif, mvif->mt76.ctx->def.chan, duration,
1380 MT7925_ROC_REQ_JOIN);
1381 mt792x_mutex_release(dev);
1384 static void mt7925_mgd_complete_tx(struct ieee80211_hw *hw,
1385 struct ieee80211_vif *vif,
1386 struct ieee80211_prep_tx_info *info)
1388 struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
1390 mt7925_abort_roc(mvif->phy, mvif);
1393 const struct ieee80211_ops mt7925_ops = {
1395 .start = mt7925_start,
1396 .stop = mt792x_stop,
1397 .add_interface = mt7925_add_interface,
1398 .remove_interface = mt792x_remove_interface,
1399 .config = mt7925_config,
1400 .conf_tx = mt792x_conf_tx,
1401 .configure_filter = mt7925_configure_filter,
1402 .bss_info_changed = mt7925_bss_info_changed,
1403 .start_ap = mt7925_start_ap,
1404 .stop_ap = mt7925_stop_ap,
1405 .sta_state = mt76_sta_state,
1406 .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
1407 .set_key = mt7925_set_key,
1408 .sta_set_decap_offload = mt7925_sta_set_decap_offload,
1409 #if IS_ENABLED(CONFIG_IPV6)
1410 .ipv6_addr_change = mt7925_ipv6_addr_change,
1411 #endif /* CONFIG_IPV6 */
1412 .ampdu_action = mt7925_ampdu_action,
1413 .set_rts_threshold = mt7925_set_rts_threshold,
1414 .wake_tx_queue = mt76_wake_tx_queue,
1415 .release_buffered_frames = mt76_release_buffered_frames,
1416 .channel_switch_beacon = mt7925_channel_switch_beacon,
1417 .get_txpower = mt76_get_txpower,
1418 .get_stats = mt792x_get_stats,
1419 .get_et_sset_count = mt792x_get_et_sset_count,
1420 .get_et_strings = mt792x_get_et_strings,
1421 .get_et_stats = mt792x_get_et_stats,
1422 .get_tsf = mt792x_get_tsf,
1423 .set_tsf = mt792x_set_tsf,
1424 .get_survey = mt76_get_survey,
1425 .get_antenna = mt76_get_antenna,
1426 .set_antenna = mt7925_set_antenna,
1427 .set_coverage_class = mt792x_set_coverage_class,
1428 .hw_scan = mt7925_hw_scan,
1429 .cancel_hw_scan = mt7925_cancel_hw_scan,
1430 .sta_statistics = mt792x_sta_statistics,
1431 .sched_scan_start = mt7925_start_sched_scan,
1432 .sched_scan_stop = mt7925_stop_sched_scan,
1434 .suspend = mt7925_suspend,
1435 .resume = mt7925_resume,
1436 .set_wakeup = mt792x_set_wakeup,
1437 .set_rekey_data = mt7925_set_rekey_data,
1438 #endif /* CONFIG_PM */
1439 .flush = mt792x_flush,
1440 .set_sar_specs = mt7925_set_sar_specs,
1441 .remain_on_channel = mt7925_remain_on_channel,
1442 .cancel_remain_on_channel = mt7925_cancel_remain_on_channel,
1443 .add_chanctx = mt7925_add_chanctx,
1444 .remove_chanctx = mt7925_remove_chanctx,
1445 .change_chanctx = mt7925_change_chanctx,
1446 .assign_vif_chanctx = mt792x_assign_vif_chanctx,
1447 .unassign_vif_chanctx = mt792x_unassign_vif_chanctx,
1448 .mgd_prepare_tx = mt7925_mgd_prepare_tx,
1449 .mgd_complete_tx = mt7925_mgd_complete_tx,
1451 EXPORT_SYMBOL_GPL(mt7925_ops);
1453 MODULE_AUTHOR("Deren Wu <deren.wu@mediatek.com>");
1454 MODULE_LICENSE("Dual BSD/GPL");