1 // SPDX-License-Identifier: ISC
3 * Copyright (C) 2022 MediaTek Inc.
10 static bool mt7996_dev_running(struct mt7996_dev
*dev
)
12 struct mt7996_phy
*phy
;
14 if (test_bit(MT76_STATE_RUNNING
, &dev
->mphy
.state
))
17 phy
= mt7996_phy2(dev
);
18 if (phy
&& test_bit(MT76_STATE_RUNNING
, &phy
->mt76
->state
))
21 phy
= mt7996_phy3(dev
);
23 return phy
&& test_bit(MT76_STATE_RUNNING
, &phy
->mt76
->state
);
26 int mt7996_run(struct ieee80211_hw
*hw
)
28 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
29 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
33 running
= mt7996_dev_running(dev
);
35 ret
= mt7996_mcu_set_hdr_trans(dev
, true);
39 if (is_mt7992(&dev
->mt76
)) {
40 u8 queue
= mt76_connac_lmac_mapping(IEEE80211_AC_VI
);
42 ret
= mt7996_mcu_cp_support(dev
, queue
);
48 mt7996_mac_enable_nf(dev
, phy
->mt76
->band_idx
);
50 ret
= mt7996_mcu_set_rts_thresh(phy
, 0x92b);
54 ret
= mt7996_mcu_set_radio_en(phy
, true);
58 ret
= mt7996_mcu_set_chan_info(phy
, UNI_CHANNEL_RX_PATH
);
62 ret
= mt7996_mcu_set_thermal_throttling(phy
, MT7996_THERMAL_THROTTLE_MAX
);
66 ret
= mt7996_mcu_set_thermal_protect(phy
, true);
70 set_bit(MT76_STATE_RUNNING
, &phy
->mt76
->state
);
72 ieee80211_queue_delayed_work(hw
, &phy
->mt76
->mac_work
,
73 MT7996_WATCHDOG_TIME
);
76 mt7996_mac_reset_counters(phy
);
82 static int mt7996_start(struct ieee80211_hw
*hw
)
84 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
87 flush_work(&dev
->init_work
);
89 mutex_lock(&dev
->mt76
.mutex
);
91 mutex_unlock(&dev
->mt76
.mutex
);
96 static void mt7996_stop(struct ieee80211_hw
*hw
, bool suspend
)
98 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
99 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
101 cancel_delayed_work_sync(&phy
->mt76
->mac_work
);
103 mutex_lock(&dev
->mt76
.mutex
);
105 mt7996_mcu_set_radio_en(phy
, false);
107 clear_bit(MT76_STATE_RUNNING
, &phy
->mt76
->state
);
109 mutex_unlock(&dev
->mt76
.mutex
);
112 static inline int get_free_idx(u32 mask
, u8 start
, u8 end
)
114 return ffs(~mask
& GENMASK(end
, start
));
117 static int get_omac_idx(enum nl80211_iftype type
, u64 mask
)
122 case NL80211_IFTYPE_MESH_POINT
:
123 case NL80211_IFTYPE_ADHOC
:
124 case NL80211_IFTYPE_STATION
:
125 /* prefer hw bssid slot 1-3 */
126 i
= get_free_idx(mask
, HW_BSSID_1
, HW_BSSID_3
);
130 if (type
!= NL80211_IFTYPE_STATION
)
133 i
= get_free_idx(mask
, EXT_BSSID_1
, EXT_BSSID_MAX
);
137 if (~mask
& BIT(HW_BSSID_0
))
141 case NL80211_IFTYPE_MONITOR
:
142 case NL80211_IFTYPE_AP
:
143 /* ap uses hw bssid 0 and ext bssid */
144 if (~mask
& BIT(HW_BSSID_0
))
147 i
= get_free_idx(mask
, EXT_BSSID_1
, EXT_BSSID_MAX
);
160 static void mt7996_init_bitrate_mask(struct ieee80211_vif
*vif
)
162 struct mt7996_vif
*mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
165 for (i
= 0; i
< ARRAY_SIZE(mvif
->bitrate_mask
.control
); i
++) {
166 mvif
->bitrate_mask
.control
[i
].gi
= NL80211_TXRATE_DEFAULT_GI
;
167 mvif
->bitrate_mask
.control
[i
].he_gi
= 0xff;
168 mvif
->bitrate_mask
.control
[i
].he_ltf
= 0xff;
169 mvif
->bitrate_mask
.control
[i
].legacy
= GENMASK(31, 0);
170 memset(mvif
->bitrate_mask
.control
[i
].ht_mcs
, 0xff,
171 sizeof(mvif
->bitrate_mask
.control
[i
].ht_mcs
));
172 memset(mvif
->bitrate_mask
.control
[i
].vht_mcs
, 0xff,
173 sizeof(mvif
->bitrate_mask
.control
[i
].vht_mcs
));
174 memset(mvif
->bitrate_mask
.control
[i
].he_mcs
, 0xff,
175 sizeof(mvif
->bitrate_mask
.control
[i
].he_mcs
));
179 static int mt7996_add_interface(struct ieee80211_hw
*hw
,
180 struct ieee80211_vif
*vif
)
182 struct mt7996_vif
*mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
183 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
184 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
185 struct mt76_txq
*mtxq
;
186 u8 band_idx
= phy
->mt76
->band_idx
;
189 mutex_lock(&dev
->mt76
.mutex
);
191 if (vif
->type
== NL80211_IFTYPE_MONITOR
&&
192 is_zero_ether_addr(vif
->addr
))
193 phy
->monitor_vif
= vif
;
195 mvif
->mt76
.idx
= __ffs64(~dev
->mt76
.vif_mask
);
196 if (mvif
->mt76
.idx
>= mt7996_max_interface_num(dev
)) {
201 idx
= get_omac_idx(vif
->type
, phy
->omac_mask
);
206 mvif
->mt76
.omac_idx
= idx
;
208 mvif
->mt76
.band_idx
= band_idx
;
209 mvif
->mt76
.wmm_idx
= vif
->type
== NL80211_IFTYPE_AP
? 0 : 3;
211 ret
= mt7996_mcu_add_dev_info(phy
, vif
, true);
215 dev
->mt76
.vif_mask
|= BIT_ULL(mvif
->mt76
.idx
);
216 phy
->omac_mask
|= BIT_ULL(mvif
->mt76
.omac_idx
);
218 idx
= MT7996_WTBL_RESERVED
- mvif
->mt76
.idx
;
220 INIT_LIST_HEAD(&mvif
->sta
.rc_list
);
221 INIT_LIST_HEAD(&mvif
->sta
.wcid
.poll_list
);
222 mvif
->sta
.wcid
.idx
= idx
;
223 mvif
->sta
.wcid
.phy_idx
= band_idx
;
224 mvif
->sta
.wcid
.hw_key_idx
= -1;
225 mvif
->sta
.wcid
.tx_info
|= MT_WCID_TX_INFO_SET
;
226 mt76_wcid_init(&mvif
->sta
.wcid
);
228 mt7996_mac_wtbl_update(dev
, idx
,
229 MT_WTBL_UPDATE_ADM_COUNT_CLEAR
);
232 mtxq
= (struct mt76_txq
*)vif
->txq
->drv_priv
;
236 if (vif
->type
!= NL80211_IFTYPE_AP
&&
237 (!mvif
->mt76
.omac_idx
|| mvif
->mt76
.omac_idx
> 3))
238 vif
->offload_flags
= 0;
239 vif
->offload_flags
|= IEEE80211_OFFLOAD_ENCAP_4ADDR
;
241 if (phy
->mt76
->chandef
.chan
->band
!= NL80211_BAND_2GHZ
)
242 mvif
->mt76
.basic_rates_idx
= MT7996_BASIC_RATES_TBL
+ 4;
244 mvif
->mt76
.basic_rates_idx
= MT7996_BASIC_RATES_TBL
;
246 mt7996_init_bitrate_mask(vif
);
248 mt7996_mcu_add_bss_info(phy
, vif
, true);
249 /* defer the first STA_REC of BMC entry to BSS_CHANGED_BSSID for STA
250 * interface, since firmware only records BSSID when the entry is new
252 if (vif
->type
!= NL80211_IFTYPE_STATION
)
253 mt7996_mcu_add_sta(dev
, vif
, NULL
, true, true);
254 rcu_assign_pointer(dev
->mt76
.wcid
[idx
], &mvif
->sta
.wcid
);
257 mutex_unlock(&dev
->mt76
.mutex
);
262 static void mt7996_remove_interface(struct ieee80211_hw
*hw
,
263 struct ieee80211_vif
*vif
)
265 struct mt7996_vif
*mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
266 struct mt7996_sta
*msta
= &mvif
->sta
;
267 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
268 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
269 int idx
= msta
->wcid
.idx
;
271 mt7996_mcu_add_sta(dev
, vif
, NULL
, false, false);
272 mt7996_mcu_add_bss_info(phy
, vif
, false);
274 if (vif
== phy
->monitor_vif
)
275 phy
->monitor_vif
= NULL
;
277 mt7996_mcu_add_dev_info(phy
, vif
, false);
279 rcu_assign_pointer(dev
->mt76
.wcid
[idx
], NULL
);
281 mutex_lock(&dev
->mt76
.mutex
);
282 dev
->mt76
.vif_mask
&= ~BIT_ULL(mvif
->mt76
.idx
);
283 phy
->omac_mask
&= ~BIT_ULL(mvif
->mt76
.omac_idx
);
284 mutex_unlock(&dev
->mt76
.mutex
);
286 spin_lock_bh(&dev
->mt76
.sta_poll_lock
);
287 if (!list_empty(&msta
->wcid
.poll_list
))
288 list_del_init(&msta
->wcid
.poll_list
);
289 spin_unlock_bh(&dev
->mt76
.sta_poll_lock
);
291 mt76_wcid_cleanup(&dev
->mt76
, &msta
->wcid
);
294 int mt7996_set_channel(struct mt76_phy
*mphy
)
296 struct mt7996_phy
*phy
= mphy
->priv
;
299 ret
= mt7996_mcu_set_chan_info(phy
, UNI_CHANNEL_SWITCH
);
303 ret
= mt7996_mcu_set_chan_info(phy
, UNI_CHANNEL_RX_PATH
);
307 ret
= mt7996_dfs_init_radar_detector(phy
);
308 mt7996_mac_cca_stats_reset(phy
);
310 mt7996_mac_reset_counters(phy
);
314 ieee80211_queue_delayed_work(mphy
->hw
, &mphy
->mac_work
,
315 MT7996_WATCHDOG_TIME
);
320 static int mt7996_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
321 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
322 struct ieee80211_key_conf
*key
)
324 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
325 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
326 struct mt7996_vif
*mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
327 struct mt7996_sta
*msta
= sta
? (struct mt7996_sta
*)sta
->drv_priv
:
329 struct mt76_wcid
*wcid
= &msta
->wcid
;
330 u8
*wcid_keyidx
= &wcid
->hw_key_idx
;
331 int idx
= key
->keyidx
;
334 /* The hardware does not support per-STA RX GTK, fallback
335 * to software mode for these.
337 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
338 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
339 (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
||
340 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
) &&
341 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
344 /* fall back to sw encryption for unsupported ciphers */
345 switch (key
->cipher
) {
346 case WLAN_CIPHER_SUITE_TKIP
:
347 case WLAN_CIPHER_SUITE_CCMP
:
348 case WLAN_CIPHER_SUITE_CCMP_256
:
349 case WLAN_CIPHER_SUITE_GCMP
:
350 case WLAN_CIPHER_SUITE_GCMP_256
:
351 case WLAN_CIPHER_SUITE_SMS4
:
353 case WLAN_CIPHER_SUITE_AES_CMAC
:
354 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
355 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
356 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
357 if (key
->keyidx
== 6 || key
->keyidx
== 7) {
358 wcid_keyidx
= &wcid
->hw_key_idx2
;
359 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIE
;
363 case WLAN_CIPHER_SUITE_WEP40
:
364 case WLAN_CIPHER_SUITE_WEP104
:
369 mutex_lock(&dev
->mt76
.mutex
);
371 if (cmd
== SET_KEY
&& !sta
&& !mvif
->mt76
.cipher
) {
372 mvif
->mt76
.cipher
= mt76_connac_mcu_get_cipher(key
->cipher
);
373 mt7996_mcu_add_bss_info(phy
, vif
, true);
376 if (cmd
== SET_KEY
) {
379 if (idx
== *wcid_keyidx
)
384 mt76_wcid_key_setup(&dev
->mt76
, wcid
, key
);
386 if (key
->keyidx
== 6 || key
->keyidx
== 7)
387 err
= mt7996_mcu_bcn_prot_enable(dev
, vif
, key
);
389 err
= mt7996_mcu_add_key(&dev
->mt76
, vif
, key
,
390 MCU_WMWA_UNI_CMD(STA_REC_UPDATE
),
393 mutex_unlock(&dev
->mt76
.mutex
);
398 static int mt7996_config(struct ieee80211_hw
*hw
, u32 changed
)
400 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
401 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
404 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
405 ret
= mt76_update_channel(phy
->mt76
);
410 if (changed
& (IEEE80211_CONF_CHANGE_POWER
|
411 IEEE80211_CONF_CHANGE_CHANNEL
)) {
412 ret
= mt7996_mcu_set_txpower_sku(phy
);
417 mutex_lock(&dev
->mt76
.mutex
);
419 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
420 bool enabled
= !!(hw
->conf
.flags
& IEEE80211_CONF_MONITOR
);
423 phy
->rxfilter
|= MT_WF_RFCR_DROP_OTHER_UC
;
425 phy
->rxfilter
&= ~MT_WF_RFCR_DROP_OTHER_UC
;
427 mt76_rmw_field(dev
, MT_DMA_DCR0(phy
->mt76
->band_idx
),
428 MT_DMA_DCR0_RXD_G5_EN
, enabled
);
429 mt76_wr(dev
, MT_WF_RFCR(phy
->mt76
->band_idx
), phy
->rxfilter
);
432 mutex_unlock(&dev
->mt76
.mutex
);
438 mt7996_conf_tx(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
439 unsigned int link_id
, u16 queue
,
440 const struct ieee80211_tx_queue_params
*params
)
442 struct mt7996_vif
*mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
443 static const u8 mq_to_aci
[] = {
444 [IEEE80211_AC_VO
] = 3,
445 [IEEE80211_AC_VI
] = 2,
446 [IEEE80211_AC_BE
] = 0,
447 [IEEE80211_AC_BK
] = 1,
450 /* firmware uses access class index */
451 mvif
->queue_params
[mq_to_aci
[queue
]] = *params
;
452 /* no need to update right away, we'll get BSS_CHANGED_QOS */
457 static void mt7996_configure_filter(struct ieee80211_hw
*hw
,
458 unsigned int changed_flags
,
459 unsigned int *total_flags
,
462 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
463 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
464 u32 ctl_flags
= MT_WF_RFCR1_DROP_ACK
|
465 MT_WF_RFCR1_DROP_BF_POLL
|
466 MT_WF_RFCR1_DROP_BA
|
467 MT_WF_RFCR1_DROP_CFEND
|
468 MT_WF_RFCR1_DROP_CFACK
;
471 #define MT76_FILTER(_flag, _hw) do { \
472 flags |= *total_flags & FIF_##_flag; \
473 phy->rxfilter &= ~(_hw); \
474 phy->rxfilter |= !(flags & FIF_##_flag) * (_hw); \
477 mutex_lock(&dev
->mt76
.mutex
);
479 phy
->rxfilter
&= ~(MT_WF_RFCR_DROP_OTHER_BSS
|
480 MT_WF_RFCR_DROP_OTHER_BEACON
|
481 MT_WF_RFCR_DROP_FRAME_REPORT
|
482 MT_WF_RFCR_DROP_PROBEREQ
|
483 MT_WF_RFCR_DROP_MCAST_FILTERED
|
484 MT_WF_RFCR_DROP_MCAST
|
485 MT_WF_RFCR_DROP_BCAST
|
486 MT_WF_RFCR_DROP_DUPLICATE
|
487 MT_WF_RFCR_DROP_A2_BSSID
|
488 MT_WF_RFCR_DROP_UNWANTED_CTL
|
489 MT_WF_RFCR_DROP_STBC_MULTI
);
491 MT76_FILTER(OTHER_BSS
, MT_WF_RFCR_DROP_OTHER_TIM
|
492 MT_WF_RFCR_DROP_A3_MAC
|
493 MT_WF_RFCR_DROP_A3_BSSID
);
495 MT76_FILTER(FCSFAIL
, MT_WF_RFCR_DROP_FCSFAIL
);
497 MT76_FILTER(CONTROL
, MT_WF_RFCR_DROP_CTS
|
498 MT_WF_RFCR_DROP_RTS
|
499 MT_WF_RFCR_DROP_CTL_RSV
|
500 MT_WF_RFCR_DROP_NDPA
);
502 *total_flags
= flags
;
503 mt76_wr(dev
, MT_WF_RFCR(phy
->mt76
->band_idx
), phy
->rxfilter
);
505 if (*total_flags
& FIF_CONTROL
)
506 mt76_clear(dev
, MT_WF_RFCR1(phy
->mt76
->band_idx
), ctl_flags
);
508 mt76_set(dev
, MT_WF_RFCR1(phy
->mt76
->band_idx
), ctl_flags
);
510 mutex_unlock(&dev
->mt76
.mutex
);
514 mt7996_update_bss_color(struct ieee80211_hw
*hw
,
515 struct ieee80211_vif
*vif
,
516 struct cfg80211_he_bss_color
*bss_color
)
518 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
521 case NL80211_IFTYPE_AP
: {
522 struct mt7996_vif
*mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
524 if (mvif
->mt76
.omac_idx
> HW_BSSID_MAX
)
528 case NL80211_IFTYPE_STATION
:
529 mt7996_mcu_update_bss_color(dev
, vif
, bss_color
);
537 mt7996_get_rates_table(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
538 bool beacon
, bool mcast
)
540 struct mt76_vif
*mvif
= (struct mt76_vif
*)vif
->drv_priv
;
541 struct mt76_phy
*mphy
= hw
->priv
;
545 rate
= mt76_connac2_mac_tx_rate_val(mphy
, vif
, beacon
, mcast
);
548 struct mt7996_phy
*phy
= mphy
->priv
;
550 /* odd index for driver, even index for firmware */
551 idx
= MT7996_BEACON_RATES_TBL
+ 2 * phy
->mt76
->band_idx
;
552 if (phy
->beacon_rate
!= rate
)
553 mt7996_mcu_set_fixed_rate_table(phy
, idx
, rate
, beacon
);
558 idx
= FIELD_GET(MT_TX_RATE_IDX
, rate
);
559 for (i
= 0; i
< ARRAY_SIZE(mt76_rates
); i
++)
560 if ((mt76_rates
[i
].hw_value
& GENMASK(7, 0)) == idx
)
561 return MT7996_BASIC_RATES_TBL
+ 2 * i
;
563 return mvif
->basic_rates_idx
;
567 mt7996_update_mu_group(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
568 struct ieee80211_bss_conf
*info
)
570 struct mt7996_vif
*mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
571 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
572 u8 band
= mvif
->mt76
.band_idx
;
575 mu
= (u32
*)info
->mu_group
.membership
;
576 mt76_wr(dev
, MT_WF_PHYRX_BAND_GID_TAB_VLD0(band
), mu
[0]);
577 mt76_wr(dev
, MT_WF_PHYRX_BAND_GID_TAB_VLD1(band
), mu
[1]);
579 mu
= (u32
*)info
->mu_group
.position
;
580 mt76_wr(dev
, MT_WF_PHYRX_BAND_GID_TAB_POS0(band
), mu
[0]);
581 mt76_wr(dev
, MT_WF_PHYRX_BAND_GID_TAB_POS1(band
), mu
[1]);
582 mt76_wr(dev
, MT_WF_PHYRX_BAND_GID_TAB_POS2(band
), mu
[2]);
583 mt76_wr(dev
, MT_WF_PHYRX_BAND_GID_TAB_POS3(band
), mu
[3]);
586 static void mt7996_bss_info_changed(struct ieee80211_hw
*hw
,
587 struct ieee80211_vif
*vif
,
588 struct ieee80211_bss_conf
*info
,
591 struct mt76_vif
*mvif
= (struct mt76_vif
*)vif
->drv_priv
;
592 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
593 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
595 mutex_lock(&dev
->mt76
.mutex
);
597 /* station mode uses BSSID to map the wlan entry to a peer,
598 * and then peer references bss_info_rfch to set bandwidth cap.
600 if ((changed
& BSS_CHANGED_BSSID
&& !is_zero_ether_addr(info
->bssid
)) ||
601 (changed
& BSS_CHANGED_ASSOC
&& vif
->cfg
.assoc
) ||
602 (changed
& BSS_CHANGED_BEACON_ENABLED
&& info
->enable_beacon
)) {
603 mt7996_mcu_add_bss_info(phy
, vif
, true);
604 mt7996_mcu_add_sta(dev
, vif
, NULL
, true,
605 !!(changed
& BSS_CHANGED_BSSID
));
608 if (changed
& BSS_CHANGED_ERP_CTS_PROT
)
609 mt7996_mac_enable_rtscts(dev
, vif
, info
->use_cts_prot
);
611 if (changed
& BSS_CHANGED_ERP_SLOT
) {
612 int slottime
= info
->use_short_slot
? 9 : 20;
614 if (slottime
!= phy
->slottime
) {
615 phy
->slottime
= slottime
;
616 mt7996_mcu_set_timing(phy
, vif
);
620 if (changed
& BSS_CHANGED_MCAST_RATE
)
621 mvif
->mcast_rates_idx
=
622 mt7996_get_rates_table(hw
, vif
, false, true);
624 if (changed
& BSS_CHANGED_BASIC_RATES
)
625 mvif
->basic_rates_idx
=
626 mt7996_get_rates_table(hw
, vif
, false, false);
628 /* ensure that enable txcmd_mode after bss_info */
629 if (changed
& (BSS_CHANGED_QOS
| BSS_CHANGED_BEACON_ENABLED
))
630 mt7996_mcu_set_tx(dev
, vif
);
632 if (changed
& BSS_CHANGED_HE_OBSS_PD
)
633 mt7996_mcu_add_obss_spr(phy
, vif
, &info
->he_obss_pd
);
635 if (changed
& BSS_CHANGED_HE_BSS_COLOR
)
636 mt7996_update_bss_color(hw
, vif
, &info
->he_bss_color
);
638 if (changed
& (BSS_CHANGED_BEACON
|
639 BSS_CHANGED_BEACON_ENABLED
)) {
640 mvif
->beacon_rates_idx
=
641 mt7996_get_rates_table(hw
, vif
, true, false);
643 mt7996_mcu_add_beacon(hw
, vif
, info
->enable_beacon
);
646 if (changed
& (BSS_CHANGED_UNSOL_BCAST_PROBE_RESP
|
647 BSS_CHANGED_FILS_DISCOVERY
))
648 mt7996_mcu_beacon_inband_discov(dev
, vif
, changed
);
650 if (changed
& BSS_CHANGED_MU_GROUPS
)
651 mt7996_update_mu_group(hw
, vif
, info
);
653 mutex_unlock(&dev
->mt76
.mutex
);
657 mt7996_channel_switch_beacon(struct ieee80211_hw
*hw
,
658 struct ieee80211_vif
*vif
,
659 struct cfg80211_chan_def
*chandef
)
661 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
663 mutex_lock(&dev
->mt76
.mutex
);
664 mt7996_mcu_add_beacon(hw
, vif
, true);
665 mutex_unlock(&dev
->mt76
.mutex
);
668 int mt7996_mac_sta_add(struct mt76_dev
*mdev
, struct ieee80211_vif
*vif
,
669 struct ieee80211_sta
*sta
)
671 struct mt7996_dev
*dev
= container_of(mdev
, struct mt7996_dev
, mt76
);
672 struct mt7996_sta
*msta
= (struct mt7996_sta
*)sta
->drv_priv
;
673 struct mt7996_vif
*mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
674 u8 band_idx
= mvif
->phy
->mt76
->band_idx
;
677 idx
= mt76_wcid_alloc(dev
->mt76
.wcid_mask
, MT7996_WTBL_STA
);
681 INIT_LIST_HEAD(&msta
->rc_list
);
682 INIT_LIST_HEAD(&msta
->wcid
.poll_list
);
685 msta
->wcid
.idx
= idx
;
686 msta
->wcid
.phy_idx
= band_idx
;
687 msta
->wcid
.tx_info
|= MT_WCID_TX_INFO_SET
;
689 ewma_avg_signal_init(&msta
->avg_ack_signal
);
691 mt7996_mac_wtbl_update(dev
, idx
,
692 MT_WTBL_UPDATE_ADM_COUNT_CLEAR
);
694 ret
= mt7996_mcu_add_sta(dev
, vif
, sta
, true, true);
698 return mt7996_mcu_add_rate_ctrl(dev
, vif
, sta
, false);
701 void mt7996_mac_sta_remove(struct mt76_dev
*mdev
, struct ieee80211_vif
*vif
,
702 struct ieee80211_sta
*sta
)
704 struct mt7996_dev
*dev
= container_of(mdev
, struct mt7996_dev
, mt76
);
705 struct mt7996_sta
*msta
= (struct mt7996_sta
*)sta
->drv_priv
;
708 mt7996_mcu_add_sta(dev
, vif
, sta
, false, false);
710 mt7996_mac_wtbl_update(dev
, msta
->wcid
.idx
,
711 MT_WTBL_UPDATE_ADM_COUNT_CLEAR
);
713 for (i
= 0; i
< ARRAY_SIZE(msta
->twt
.flow
); i
++)
714 mt7996_mac_twt_teardown_flow(dev
, msta
, i
);
716 spin_lock_bh(&mdev
->sta_poll_lock
);
717 if (!list_empty(&msta
->wcid
.poll_list
))
718 list_del_init(&msta
->wcid
.poll_list
);
719 if (!list_empty(&msta
->rc_list
))
720 list_del_init(&msta
->rc_list
);
721 spin_unlock_bh(&mdev
->sta_poll_lock
);
724 static void mt7996_tx(struct ieee80211_hw
*hw
,
725 struct ieee80211_tx_control
*control
,
728 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
729 struct mt76_phy
*mphy
= hw
->priv
;
730 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
731 struct ieee80211_vif
*vif
= info
->control
.vif
;
732 struct mt76_wcid
*wcid
= &dev
->mt76
.global_wcid
;
735 struct mt7996_sta
*sta
;
737 sta
= (struct mt7996_sta
*)control
->sta
->drv_priv
;
741 if (vif
&& !control
->sta
) {
742 struct mt7996_vif
*mvif
;
744 mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
745 wcid
= &mvif
->sta
.wcid
;
748 mt76_tx(mphy
, control
->sta
, wcid
, skb
);
751 static int mt7996_set_rts_threshold(struct ieee80211_hw
*hw
, u32 val
)
753 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
756 mutex_lock(&phy
->dev
->mt76
.mutex
);
757 ret
= mt7996_mcu_set_rts_thresh(phy
, val
);
758 mutex_unlock(&phy
->dev
->mt76
.mutex
);
764 mt7996_ampdu_action(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
765 struct ieee80211_ampdu_params
*params
)
767 enum ieee80211_ampdu_mlme_action action
= params
->action
;
768 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
769 struct ieee80211_sta
*sta
= params
->sta
;
770 struct ieee80211_txq
*txq
= sta
->txq
[params
->tid
];
771 struct mt7996_sta
*msta
= (struct mt7996_sta
*)sta
->drv_priv
;
772 u16 tid
= params
->tid
;
773 u16 ssn
= params
->ssn
;
774 struct mt76_txq
*mtxq
;
780 mtxq
= (struct mt76_txq
*)txq
->drv_priv
;
782 mutex_lock(&dev
->mt76
.mutex
);
784 case IEEE80211_AMPDU_RX_START
:
785 mt76_rx_aggr_start(&dev
->mt76
, &msta
->wcid
, tid
, ssn
,
787 ret
= mt7996_mcu_add_rx_ba(dev
, params
, true);
789 case IEEE80211_AMPDU_RX_STOP
:
790 mt76_rx_aggr_stop(&dev
->mt76
, &msta
->wcid
, tid
);
791 ret
= mt7996_mcu_add_rx_ba(dev
, params
, false);
793 case IEEE80211_AMPDU_TX_OPERATIONAL
:
795 mtxq
->send_bar
= false;
796 ret
= mt7996_mcu_add_tx_ba(dev
, params
, true);
798 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
799 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
801 clear_bit(tid
, &msta
->wcid
.ampdu_state
);
802 ret
= mt7996_mcu_add_tx_ba(dev
, params
, false);
804 case IEEE80211_AMPDU_TX_START
:
805 set_bit(tid
, &msta
->wcid
.ampdu_state
);
806 ret
= IEEE80211_AMPDU_TX_START_IMMEDIATE
;
808 case IEEE80211_AMPDU_TX_STOP_CONT
:
810 clear_bit(tid
, &msta
->wcid
.ampdu_state
);
811 ret
= mt7996_mcu_add_tx_ba(dev
, params
, false);
812 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
815 mutex_unlock(&dev
->mt76
.mutex
);
821 mt7996_sta_add(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
822 struct ieee80211_sta
*sta
)
824 return mt76_sta_state(hw
, vif
, sta
, IEEE80211_STA_NOTEXIST
,
829 mt7996_sta_remove(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
830 struct ieee80211_sta
*sta
)
832 return mt76_sta_state(hw
, vif
, sta
, IEEE80211_STA_NONE
,
833 IEEE80211_STA_NOTEXIST
);
837 mt7996_get_stats(struct ieee80211_hw
*hw
,
838 struct ieee80211_low_level_stats
*stats
)
840 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
841 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
842 struct mt76_mib_stats
*mib
= &phy
->mib
;
844 mutex_lock(&dev
->mt76
.mutex
);
846 stats
->dot11RTSSuccessCount
= mib
->rts_cnt
;
847 stats
->dot11RTSFailureCount
= mib
->rts_retries_cnt
;
848 stats
->dot11FCSErrorCount
= mib
->fcs_err_cnt
;
849 stats
->dot11ACKFailureCount
= mib
->ack_fail_cnt
;
851 mutex_unlock(&dev
->mt76
.mutex
);
856 u64
__mt7996_get_tsf(struct ieee80211_hw
*hw
, struct mt7996_vif
*mvif
)
858 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
859 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
866 lockdep_assert_held(&dev
->mt76
.mutex
);
868 n
= mvif
->mt76
.omac_idx
> HW_BSSID_MAX
? HW_BSSID_0
869 : mvif
->mt76
.omac_idx
;
870 /* TSF software read */
871 mt76_rmw(dev
, MT_LPON_TCR(phy
->mt76
->band_idx
, n
), MT_LPON_TCR_SW_MODE
,
872 MT_LPON_TCR_SW_READ
);
873 tsf
.t32
[0] = mt76_rr(dev
, MT_LPON_UTTR0(phy
->mt76
->band_idx
));
874 tsf
.t32
[1] = mt76_rr(dev
, MT_LPON_UTTR1(phy
->mt76
->band_idx
));
880 mt7996_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
882 struct mt7996_vif
*mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
883 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
886 mutex_lock(&dev
->mt76
.mutex
);
887 ret
= __mt7996_get_tsf(hw
, mvif
);
888 mutex_unlock(&dev
->mt76
.mutex
);
894 mt7996_set_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
897 struct mt7996_vif
*mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
898 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
899 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
903 } tsf
= { .t64
= timestamp
, };
906 mutex_lock(&dev
->mt76
.mutex
);
908 n
= mvif
->mt76
.omac_idx
> HW_BSSID_MAX
? HW_BSSID_0
909 : mvif
->mt76
.omac_idx
;
910 mt76_wr(dev
, MT_LPON_UTTR0(phy
->mt76
->band_idx
), tsf
.t32
[0]);
911 mt76_wr(dev
, MT_LPON_UTTR1(phy
->mt76
->band_idx
), tsf
.t32
[1]);
912 /* TSF software overwrite */
913 mt76_rmw(dev
, MT_LPON_TCR(phy
->mt76
->band_idx
, n
), MT_LPON_TCR_SW_MODE
,
914 MT_LPON_TCR_SW_WRITE
);
916 mutex_unlock(&dev
->mt76
.mutex
);
920 mt7996_offset_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
923 struct mt7996_vif
*mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
924 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
925 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
929 } tsf
= { .t64
= timestamp
, };
932 mutex_lock(&dev
->mt76
.mutex
);
934 n
= mvif
->mt76
.omac_idx
> HW_BSSID_MAX
? HW_BSSID_0
935 : mvif
->mt76
.omac_idx
;
936 mt76_wr(dev
, MT_LPON_UTTR0(phy
->mt76
->band_idx
), tsf
.t32
[0]);
937 mt76_wr(dev
, MT_LPON_UTTR1(phy
->mt76
->band_idx
), tsf
.t32
[1]);
938 /* TSF software adjust*/
939 mt76_rmw(dev
, MT_LPON_TCR(phy
->mt76
->band_idx
, n
), MT_LPON_TCR_SW_MODE
,
940 MT_LPON_TCR_SW_ADJUST
);
942 mutex_unlock(&dev
->mt76
.mutex
);
946 mt7996_set_coverage_class(struct ieee80211_hw
*hw
, s16 coverage_class
)
948 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
949 struct mt7996_dev
*dev
= phy
->dev
;
951 mutex_lock(&dev
->mt76
.mutex
);
952 phy
->coverage_class
= max_t(s16
, coverage_class
, 0);
953 mt7996_mac_set_coverage_class(phy
);
954 mutex_unlock(&dev
->mt76
.mutex
);
958 mt7996_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
960 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
961 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
962 int max_nss
= hweight8(hw
->wiphy
->available_antennas_tx
);
963 u8 band_idx
= phy
->mt76
->band_idx
, shift
= dev
->chainshift
[band_idx
];
965 if (!tx_ant
|| tx_ant
!= rx_ant
|| ffs(tx_ant
) > max_nss
)
968 if ((BIT(hweight8(tx_ant
)) - 1) != tx_ant
)
969 tx_ant
= BIT(ffs(tx_ant
) - 1) - 1;
971 mutex_lock(&dev
->mt76
.mutex
);
973 phy
->mt76
->antenna_mask
= tx_ant
;
975 /* restore to the origin chainmask which might have auxiliary path */
976 if (hweight8(tx_ant
) == max_nss
&& band_idx
< MT_BAND2
)
977 phy
->mt76
->chainmask
= ((dev
->chainmask
>> shift
) &
978 (BIT(dev
->chainshift
[band_idx
+ 1] - shift
) - 1)) << shift
;
979 else if (hweight8(tx_ant
) == max_nss
)
980 phy
->mt76
->chainmask
= (dev
->chainmask
>> shift
) << shift
;
982 phy
->mt76
->chainmask
= tx_ant
<< shift
;
984 mt76_set_stream_caps(phy
->mt76
, true);
985 mt7996_set_stream_vht_txbf_caps(phy
);
986 mt7996_set_stream_he_eht_caps(phy
);
987 mt7996_mcu_set_txpower_sku(phy
);
989 mutex_unlock(&dev
->mt76
.mutex
);
994 static void mt7996_sta_statistics(struct ieee80211_hw
*hw
,
995 struct ieee80211_vif
*vif
,
996 struct ieee80211_sta
*sta
,
997 struct station_info
*sinfo
)
999 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
1000 struct mt7996_sta
*msta
= (struct mt7996_sta
*)sta
->drv_priv
;
1001 struct rate_info
*txrate
= &msta
->wcid
.rate
;
1003 if (txrate
->legacy
|| txrate
->flags
) {
1004 if (txrate
->legacy
) {
1005 sinfo
->txrate
.legacy
= txrate
->legacy
;
1007 sinfo
->txrate
.mcs
= txrate
->mcs
;
1008 sinfo
->txrate
.nss
= txrate
->nss
;
1009 sinfo
->txrate
.bw
= txrate
->bw
;
1010 sinfo
->txrate
.he_gi
= txrate
->he_gi
;
1011 sinfo
->txrate
.he_dcm
= txrate
->he_dcm
;
1012 sinfo
->txrate
.he_ru_alloc
= txrate
->he_ru_alloc
;
1013 sinfo
->txrate
.eht_gi
= txrate
->eht_gi
;
1015 sinfo
->txrate
.flags
= txrate
->flags
;
1016 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_BITRATE
);
1018 sinfo
->txrate
.flags
= txrate
->flags
;
1019 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_BITRATE
);
1021 sinfo
->tx_failed
= msta
->wcid
.stats
.tx_failed
;
1022 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_FAILED
);
1024 sinfo
->tx_retries
= msta
->wcid
.stats
.tx_retries
;
1025 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_RETRIES
);
1027 sinfo
->ack_signal
= (s8
)msta
->ack_signal
;
1028 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL
);
1030 sinfo
->avg_ack_signal
= -(s8
)ewma_avg_signal_read(&msta
->avg_ack_signal
);
1031 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG
);
1033 if (mtk_wed_device_active(&phy
->dev
->mt76
.mmio
.wed
)) {
1034 sinfo
->tx_bytes
= msta
->wcid
.stats
.tx_bytes
;
1035 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_BYTES64
);
1037 sinfo
->rx_bytes
= msta
->wcid
.stats
.rx_bytes
;
1038 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_RX_BYTES64
);
1040 sinfo
->tx_packets
= msta
->wcid
.stats
.tx_packets
;
1041 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_PACKETS
);
1043 sinfo
->rx_packets
= msta
->wcid
.stats
.rx_packets
;
1044 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_RX_PACKETS
);
1048 static void mt7996_sta_rc_work(void *data
, struct ieee80211_sta
*sta
)
1050 struct mt7996_sta
*msta
= (struct mt7996_sta
*)sta
->drv_priv
;
1051 struct mt7996_dev
*dev
= msta
->vif
->phy
->dev
;
1052 u32
*changed
= data
;
1054 spin_lock_bh(&dev
->mt76
.sta_poll_lock
);
1055 msta
->changed
|= *changed
;
1056 if (list_empty(&msta
->rc_list
))
1057 list_add_tail(&msta
->rc_list
, &dev
->sta_rc_list
);
1058 spin_unlock_bh(&dev
->mt76
.sta_poll_lock
);
1061 static void mt7996_sta_rc_update(struct ieee80211_hw
*hw
,
1062 struct ieee80211_vif
*vif
,
1063 struct ieee80211_link_sta
*link_sta
,
1066 struct ieee80211_sta
*sta
= link_sta
->sta
;
1067 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
1068 struct mt7996_dev
*dev
= phy
->dev
;
1070 mt7996_sta_rc_work(&changed
, sta
);
1071 ieee80211_queue_work(hw
, &dev
->rc_work
);
1075 mt7996_set_bitrate_mask(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1076 const struct cfg80211_bitrate_mask
*mask
)
1078 struct mt7996_vif
*mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
1079 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
1080 struct mt7996_dev
*dev
= phy
->dev
;
1081 u32 changed
= IEEE80211_RC_SUPP_RATES_CHANGED
;
1083 mvif
->bitrate_mask
= *mask
;
1085 /* if multiple rates across different preambles are given we can
1086 * reconfigure this info with all peers using sta_rec command with
1087 * the below exception cases.
1088 * - single rate : if a rate is passed along with different preambles,
1089 * we select the highest one as fixed rate. i.e VHT MCS for VHT peers.
1090 * - multiple rates: if it's not in range format i.e 0-{7,8,9} for VHT
1091 * then multiple MCS setting (MCS 4,5,6) is not supported.
1093 ieee80211_iterate_stations_atomic(hw
, mt7996_sta_rc_work
, &changed
);
1094 ieee80211_queue_work(hw
, &dev
->rc_work
);
1099 static void mt7996_sta_set_4addr(struct ieee80211_hw
*hw
,
1100 struct ieee80211_vif
*vif
,
1101 struct ieee80211_sta
*sta
,
1104 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
1105 struct mt7996_sta
*msta
= (struct mt7996_sta
*)sta
->drv_priv
;
1108 set_bit(MT_WCID_FLAG_4ADDR
, &msta
->wcid
.flags
);
1110 clear_bit(MT_WCID_FLAG_4ADDR
, &msta
->wcid
.flags
);
1112 mt7996_mcu_wtbl_update_hdr_trans(dev
, vif
, sta
);
1115 static void mt7996_sta_set_decap_offload(struct ieee80211_hw
*hw
,
1116 struct ieee80211_vif
*vif
,
1117 struct ieee80211_sta
*sta
,
1120 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
1121 struct mt7996_sta
*msta
= (struct mt7996_sta
*)sta
->drv_priv
;
1124 set_bit(MT_WCID_FLAG_HDR_TRANS
, &msta
->wcid
.flags
);
1126 clear_bit(MT_WCID_FLAG_HDR_TRANS
, &msta
->wcid
.flags
);
1128 mt7996_mcu_wtbl_update_hdr_trans(dev
, vif
, sta
);
1131 static const char mt7996_gstrings_stats
[][ETH_GSTRING_LEN
] = {
1133 "tx_stop_q_empty_cnt",
1141 "tx_ampdu_len:2-10",
1142 "tx_ampdu_len:11-19",
1143 "tx_ampdu_len:20-28",
1144 "tx_ampdu_len:29-37",
1145 "tx_ampdu_len:38-46",
1146 "tx_ampdu_len:47-55",
1147 "tx_ampdu_len:56-79",
1148 "tx_ampdu_len:80-103",
1149 "tx_ampdu_len:104-127",
1150 "tx_ampdu_len:128-151",
1151 "tx_ampdu_len:152-175",
1152 "tx_ampdu_len:176-199",
1153 "tx_ampdu_len:200-223",
1154 "tx_ampdu_len:224-247",
1156 "tx_beamformer_ppdu_iBF",
1157 "tx_beamformer_ppdu_eBF",
1158 "tx_beamformer_rx_feedback_all",
1159 "tx_beamformer_rx_feedback_he",
1160 "tx_beamformer_rx_feedback_vht",
1161 "tx_beamformer_rx_feedback_ht",
1162 "tx_beamformer_rx_feedback_bw", /* zero based idx: 20, 40, 80, 160 */
1163 "tx_beamformer_rx_feedback_nc",
1164 "tx_beamformer_rx_feedback_nr",
1165 "tx_beamformee_ok_feedback_pkts",
1166 "tx_beamformee_feedback_trig",
1167 "tx_mu_beamforming",
1169 "tx_mu_successful_mpdu",
1170 "tx_su_successful_mpdu",
1184 "rx_vector_mismatch_cnt",
1185 "rx_delimiter_fail_cnt",
1186 "rx_len_mismatch_cnt",
1188 "rx_ampdu_bytes_cnt",
1189 "rx_ampdu_valid_subframe_cnt",
1190 "rx_ampdu_valid_subframe_b_cnt",
1192 "rx_vec_queue_overflow_drop_cnt",
1195 /* per vif counters */
1202 "v_tx_mode_he_ext_su",
1206 "v_tx_mode_eht_trig",
1233 #define MT7996_SSTATS_LEN ARRAY_SIZE(mt7996_gstrings_stats)
1235 /* Ethtool related API */
1237 void mt7996_get_et_strings(struct ieee80211_hw
*hw
,
1238 struct ieee80211_vif
*vif
,
1241 if (sset
== ETH_SS_STATS
)
1242 memcpy(data
, mt7996_gstrings_stats
,
1243 sizeof(mt7996_gstrings_stats
));
1247 int mt7996_get_et_sset_count(struct ieee80211_hw
*hw
,
1248 struct ieee80211_vif
*vif
, int sset
)
1250 if (sset
== ETH_SS_STATS
)
1251 return MT7996_SSTATS_LEN
;
1256 static void mt7996_ethtool_worker(void *wi_data
, struct ieee80211_sta
*sta
)
1258 struct mt76_ethtool_worker_info
*wi
= wi_data
;
1259 struct mt7996_sta
*msta
= (struct mt7996_sta
*)sta
->drv_priv
;
1261 if (msta
->vif
->mt76
.idx
!= wi
->idx
)
1264 mt76_ethtool_worker(wi
, &msta
->wcid
.stats
, true);
1268 void mt7996_get_et_stats(struct ieee80211_hw
*hw
,
1269 struct ieee80211_vif
*vif
,
1270 struct ethtool_stats
*stats
, u64
*data
)
1272 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
1273 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
1274 struct mt7996_vif
*mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
1275 struct mt76_mib_stats
*mib
= &phy
->mib
;
1276 struct mt76_ethtool_worker_info wi
= {
1278 .idx
= mvif
->mt76
.idx
,
1280 /* See mt7996_ampdu_stat_read_phy, etc */
1283 mutex_lock(&dev
->mt76
.mutex
);
1285 mt7996_mac_update_stats(phy
);
1287 data
[ei
++] = mib
->tx_ampdu_cnt
;
1288 data
[ei
++] = mib
->tx_stop_q_empty_cnt
;
1289 data
[ei
++] = mib
->tx_mpdu_attempts_cnt
;
1290 data
[ei
++] = mib
->tx_mpdu_success_cnt
;
1291 data
[ei
++] = mib
->tx_rwp_fail_cnt
;
1292 data
[ei
++] = mib
->tx_rwp_need_cnt
;
1293 data
[ei
++] = mib
->tx_bf_ebf_ppdu_cnt
;
1294 data
[ei
++] = mib
->tx_bf_ibf_ppdu_cnt
;
1297 for (i
= 0; i
< 15 /*ARRAY_SIZE(bound)*/; i
++)
1298 data
[ei
++] = phy
->mt76
->aggr_stats
[i
];
1299 data
[ei
++] = phy
->mib
.ba_miss_cnt
;
1301 /* Tx Beamformer monitor */
1302 data
[ei
++] = mib
->tx_bf_ibf_ppdu_cnt
;
1303 data
[ei
++] = mib
->tx_bf_ebf_ppdu_cnt
;
1305 /* Tx Beamformer Rx feedback monitor */
1306 data
[ei
++] = mib
->tx_bf_rx_fb_all_cnt
;
1307 data
[ei
++] = mib
->tx_bf_rx_fb_he_cnt
;
1308 data
[ei
++] = mib
->tx_bf_rx_fb_vht_cnt
;
1309 data
[ei
++] = mib
->tx_bf_rx_fb_ht_cnt
;
1311 data
[ei
++] = mib
->tx_bf_rx_fb_bw
;
1312 data
[ei
++] = mib
->tx_bf_rx_fb_nc_cnt
;
1313 data
[ei
++] = mib
->tx_bf_rx_fb_nr_cnt
;
1315 /* Tx Beamformee Rx NDPA & Tx feedback report */
1316 data
[ei
++] = mib
->tx_bf_fb_cpl_cnt
;
1317 data
[ei
++] = mib
->tx_bf_fb_trig_cnt
;
1319 /* Tx SU & MU counters */
1320 data
[ei
++] = mib
->tx_mu_bf_cnt
;
1321 data
[ei
++] = mib
->tx_mu_mpdu_cnt
;
1322 data
[ei
++] = mib
->tx_mu_acked_mpdu_cnt
;
1323 data
[ei
++] = mib
->tx_su_acked_mpdu_cnt
;
1325 /* Tx amsdu info (pack-count histogram) */
1326 for (i
= 0; i
< ARRAY_SIZE(mib
->tx_amsdu
); i
++)
1327 data
[ei
++] = mib
->tx_amsdu
[i
];
1330 data
[ei
++] = mib
->rx_fifo_full_cnt
;
1331 data
[ei
++] = mib
->rx_mpdu_cnt
;
1332 data
[ei
++] = mib
->channel_idle_cnt
;
1333 data
[ei
++] = mib
->rx_vector_mismatch_cnt
;
1334 data
[ei
++] = mib
->rx_delimiter_fail_cnt
;
1335 data
[ei
++] = mib
->rx_len_mismatch_cnt
;
1336 data
[ei
++] = mib
->rx_ampdu_cnt
;
1337 data
[ei
++] = mib
->rx_ampdu_bytes_cnt
;
1338 data
[ei
++] = mib
->rx_ampdu_valid_subframe_cnt
;
1339 data
[ei
++] = mib
->rx_ampdu_valid_subframe_bytes_cnt
;
1340 data
[ei
++] = mib
->rx_pfdrop_cnt
;
1341 data
[ei
++] = mib
->rx_vec_queue_overflow_drop_cnt
;
1342 data
[ei
++] = mib
->rx_ba_cnt
;
1344 /* Add values for all stations owned by this vif */
1345 wi
.initial_stat_idx
= ei
;
1346 ieee80211_iterate_stations_atomic(hw
, mt7996_ethtool_worker
, &wi
);
1348 mutex_unlock(&dev
->mt76
.mutex
);
1350 if (wi
.sta_count
== 0)
1353 ei
+= wi
.worker_stat_count
;
1354 if (ei
!= MT7996_SSTATS_LEN
)
1355 dev_err(dev
->mt76
.dev
, "ei: %d MT7996_SSTATS_LEN: %d",
1356 ei
, (int)MT7996_SSTATS_LEN
);
1360 mt7996_twt_teardown_request(struct ieee80211_hw
*hw
,
1361 struct ieee80211_sta
*sta
,
1364 struct mt7996_sta
*msta
= (struct mt7996_sta
*)sta
->drv_priv
;
1365 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
1367 mutex_lock(&dev
->mt76
.mutex
);
1368 mt7996_mac_twt_teardown_flow(dev
, msta
, flowid
);
1369 mutex_unlock(&dev
->mt76
.mutex
);
1373 mt7996_set_radar_background(struct ieee80211_hw
*hw
,
1374 struct cfg80211_chan_def
*chandef
)
1376 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
1377 struct mt7996_dev
*dev
= phy
->dev
;
1381 mutex_lock(&dev
->mt76
.mutex
);
1383 if (dev
->mt76
.region
== NL80211_DFS_UNSET
)
1386 if (dev
->rdd2_phy
&& dev
->rdd2_phy
!= phy
) {
1387 /* rdd2 is already locked */
1392 /* rdd2 already configured on a radar channel */
1393 running
= dev
->rdd2_phy
&&
1394 cfg80211_chandef_valid(&dev
->rdd2_chandef
) &&
1395 !!(dev
->rdd2_chandef
.chan
->flags
& IEEE80211_CHAN_RADAR
);
1397 if (!chandef
|| running
||
1398 !(chandef
->chan
->flags
& IEEE80211_CHAN_RADAR
)) {
1399 ret
= mt7996_mcu_rdd_background_enable(phy
, NULL
);
1407 ret
= mt7996_mcu_rdd_background_enable(phy
, chandef
);
1412 dev
->rdd2_phy
= chandef
? phy
: NULL
;
1414 dev
->rdd2_chandef
= *chandef
;
1416 mutex_unlock(&dev
->mt76
.mutex
);
1421 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
1423 mt7996_net_fill_forward_path(struct ieee80211_hw
*hw
,
1424 struct ieee80211_vif
*vif
,
1425 struct ieee80211_sta
*sta
,
1426 struct net_device_path_ctx
*ctx
,
1427 struct net_device_path
*path
)
1429 struct mt7996_vif
*mvif
= (struct mt7996_vif
*)vif
->drv_priv
;
1430 struct mt7996_sta
*msta
= (struct mt7996_sta
*)sta
->drv_priv
;
1431 struct mt7996_dev
*dev
= mt7996_hw_dev(hw
);
1432 struct mt7996_phy
*phy
= mt7996_hw_phy(hw
);
1433 struct mtk_wed_device
*wed
= &dev
->mt76
.mmio
.wed
;
1435 if (phy
!= &dev
->phy
&& phy
->mt76
->band_idx
== MT_BAND2
)
1436 wed
= &dev
->mt76
.mmio
.wed_hif2
;
1438 if (!mtk_wed_device_active(wed
))
1441 if (msta
->wcid
.idx
> MT7996_WTBL_STA
)
1444 path
->type
= DEV_PATH_MTK_WDMA
;
1445 path
->dev
= ctx
->dev
;
1446 path
->mtk_wdma
.wdma_idx
= wed
->wdma_idx
;
1447 path
->mtk_wdma
.bss
= mvif
->mt76
.idx
;
1448 path
->mtk_wdma
.queue
= 0;
1449 path
->mtk_wdma
.wcid
= msta
->wcid
.idx
;
1451 path
->mtk_wdma
.amsdu
= mtk_wed_is_amsdu_supported(wed
);
1459 const struct ieee80211_ops mt7996_ops
= {
1460 .add_chanctx
= ieee80211_emulate_add_chanctx
,
1461 .remove_chanctx
= ieee80211_emulate_remove_chanctx
,
1462 .change_chanctx
= ieee80211_emulate_change_chanctx
,
1463 .switch_vif_chanctx
= ieee80211_emulate_switch_vif_chanctx
,
1465 .start
= mt7996_start
,
1466 .stop
= mt7996_stop
,
1467 .add_interface
= mt7996_add_interface
,
1468 .remove_interface
= mt7996_remove_interface
,
1469 .config
= mt7996_config
,
1470 .conf_tx
= mt7996_conf_tx
,
1471 .configure_filter
= mt7996_configure_filter
,
1472 .bss_info_changed
= mt7996_bss_info_changed
,
1473 .sta_add
= mt7996_sta_add
,
1474 .sta_remove
= mt7996_sta_remove
,
1475 .sta_pre_rcu_remove
= mt76_sta_pre_rcu_remove
,
1476 .link_sta_rc_update
= mt7996_sta_rc_update
,
1477 .set_key
= mt7996_set_key
,
1478 .ampdu_action
= mt7996_ampdu_action
,
1479 .set_rts_threshold
= mt7996_set_rts_threshold
,
1480 .wake_tx_queue
= mt76_wake_tx_queue
,
1481 .sw_scan_start
= mt76_sw_scan
,
1482 .sw_scan_complete
= mt76_sw_scan_complete
,
1483 .release_buffered_frames
= mt76_release_buffered_frames
,
1484 .get_txpower
= mt76_get_txpower
,
1485 .channel_switch_beacon
= mt7996_channel_switch_beacon
,
1486 .get_stats
= mt7996_get_stats
,
1487 .get_et_sset_count
= mt7996_get_et_sset_count
,
1488 .get_et_stats
= mt7996_get_et_stats
,
1489 .get_et_strings
= mt7996_get_et_strings
,
1490 .get_tsf
= mt7996_get_tsf
,
1491 .set_tsf
= mt7996_set_tsf
,
1492 .offset_tsf
= mt7996_offset_tsf
,
1493 .get_survey
= mt76_get_survey
,
1494 .get_antenna
= mt76_get_antenna
,
1495 .set_antenna
= mt7996_set_antenna
,
1496 .set_bitrate_mask
= mt7996_set_bitrate_mask
,
1497 .set_coverage_class
= mt7996_set_coverage_class
,
1498 .sta_statistics
= mt7996_sta_statistics
,
1499 .sta_set_4addr
= mt7996_sta_set_4addr
,
1500 .sta_set_decap_offload
= mt7996_sta_set_decap_offload
,
1501 .add_twt_setup
= mt7996_mac_add_twt_setup
,
1502 .twt_teardown_request
= mt7996_twt_teardown_request
,
1503 #ifdef CONFIG_MAC80211_DEBUGFS
1504 .sta_add_debugfs
= mt7996_sta_add_debugfs
,
1506 .set_radar_background
= mt7996_set_radar_background
,
1507 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
1508 .net_fill_forward_path
= mt7996_net_fill_forward_path
,
1509 .net_setup_tc
= mt76_wed_net_setup_tc
,