developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 1 | From 05a99ecc4978355bccc95be925a2b479754b193c Mon Sep 17 00:00:00 2001 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 2 | From: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com> |
| 3 | Date: Fri, 18 Aug 2023 10:17:08 +0800 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 070/199] mtk: mt76: mt7996: add per bss statistic info |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 5 | |
| 6 | Whenever WED is enabled, unicast traffic might run through HW path. |
| 7 | As a result, we need to count them using WM event. |
| 8 | Broadcast and multicast traffic on the other hand, will be counted in mac80211 |
| 9 | as they always go through SW path and thus mac80211 can always see and count them. |
| 10 | |
| 11 | | | Tx | Rx | |
| 12 | |---------|--------------------------------|---------------------------| |
| 13 | | Unicast | mt76 | mt76 | |
| 14 | | | __mt7996_stat_to_netdev() | __mt7996_stat_to_netdev() | |
| 15 | |---------|--------------------------------|---------------------------| |
| 16 | | BMCast | mac80211 | mac80211 | |
| 17 | | | __ieee80211_subif_start_xmit() | ieee80211_deliver_skb() | |
| 18 | --- |
| 19 | mt7996/init.c | 1 + |
| 20 | mt7996/main.c | 1 + |
| 21 | mt7996/mcu.c | 40 +++++++++++++++++++++++++++++++++++----- |
| 22 | 3 files changed, 37 insertions(+), 5 deletions(-) |
| 23 | |
| 24 | diff --git a/mt7996/init.c b/mt7996/init.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 25 | index 6563974d..9d918268 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 26 | --- a/mt7996/init.c |
| 27 | +++ b/mt7996/init.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 28 | @@ -403,6 +403,7 @@ mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 29 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0); |
| 30 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER); |
| 31 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_PUNCT); |
| 32 | + wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STAS_COUNT); |
| 33 | |
| 34 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_OPERATING_CHANNEL_VALIDATION); |
| 35 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_PROTECTION); |
| 36 | diff --git a/mt7996/main.c b/mt7996/main.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 37 | index 3bc9dc15..d26c55ed 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 38 | --- a/mt7996/main.c |
| 39 | +++ b/mt7996/main.c |
| 40 | @@ -265,6 +265,7 @@ static int mt7996_add_interface(struct ieee80211_hw *hw, |
| 41 | mvif->sta.wcid.phy_idx = band_idx; |
| 42 | mvif->sta.wcid.hw_key_idx = -1; |
| 43 | mvif->sta.wcid.tx_info |= MT_WCID_TX_INFO_SET; |
| 44 | + mvif->sta.vif = mvif; |
| 45 | mt76_wcid_init(&mvif->sta.wcid); |
| 46 | |
| 47 | mt7996_mac_wtbl_update(dev, idx, |
| 48 | diff --git a/mt7996/mcu.c b/mt7996/mcu.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 49 | index 7fa44f84..061461fb 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 50 | --- a/mt7996/mcu.c |
| 51 | +++ b/mt7996/mcu.c |
| 52 | @@ -524,6 +524,27 @@ mt7996_mcu_update_tx_gi(struct rate_info *rate, struct all_sta_trx_rate *mcu_rat |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | +static inline void __mt7996_stat_to_netdev(struct mt76_phy *mphy, |
| 57 | + struct mt76_wcid *wcid, |
| 58 | + u32 tx_bytes, u32 rx_bytes, |
| 59 | + u32 tx_packets, u32 rx_packets) |
| 60 | +{ |
| 61 | + struct mt7996_sta *msta; |
| 62 | + struct ieee80211_vif *vif; |
| 63 | + struct wireless_dev *wdev; |
| 64 | + |
| 65 | + if (wiphy_ext_feature_isset(mphy->hw->wiphy, |
| 66 | + NL80211_EXT_FEATURE_STAS_COUNT)) { |
| 67 | + msta = container_of(wcid, struct mt7996_sta, wcid); |
| 68 | + vif = container_of((void *)msta->vif, struct ieee80211_vif, |
| 69 | + drv_priv); |
| 70 | + wdev = ieee80211_vif_to_wdev(vif); |
| 71 | + |
| 72 | + dev_sw_netstats_tx_add(wdev->netdev, tx_packets, tx_bytes); |
| 73 | + dev_sw_netstats_rx_add(wdev->netdev, rx_packets, rx_bytes); |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | static void |
| 78 | mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb) |
| 79 | { |
| 80 | @@ -539,7 +560,7 @@ mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb) |
| 81 | u16 wlan_idx; |
| 82 | struct mt76_wcid *wcid; |
| 83 | struct mt76_phy *mphy; |
| 84 | - u32 tx_bytes, rx_bytes; |
| 85 | + u32 tx_bytes, rx_bytes, tx_packets, rx_packets; |
| 86 | |
| 87 | switch (le16_to_cpu(res->tag)) { |
| 88 | case UNI_ALL_STA_TXRX_RATE: |
| 89 | @@ -567,6 +588,9 @@ mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb) |
| 90 | wcid->stats.tx_bytes += tx_bytes; |
| 91 | wcid->stats.rx_bytes += rx_bytes; |
| 92 | |
| 93 | + __mt7996_stat_to_netdev(mphy, wcid, |
| 94 | + tx_bytes, rx_bytes, 0, 0); |
| 95 | + |
| 96 | ieee80211_tpt_led_trig_tx(mphy->hw, tx_bytes); |
| 97 | ieee80211_tpt_led_trig_rx(mphy->hw, rx_bytes); |
| 98 | } |
| 99 | @@ -578,10 +602,16 @@ mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb) |
| 100 | if (!wcid) |
| 101 | break; |
| 102 | |
| 103 | - wcid->stats.tx_packets += |
| 104 | - le32_to_cpu(res->msdu_cnt[i].tx_msdu_cnt); |
| 105 | - wcid->stats.rx_packets += |
| 106 | - le32_to_cpu(res->msdu_cnt[i].rx_msdu_cnt); |
| 107 | + mphy = mt76_dev_phy(&dev->mt76, wcid->phy_idx); |
| 108 | + |
| 109 | + tx_packets = le32_to_cpu(res->msdu_cnt[i].tx_msdu_cnt); |
| 110 | + rx_packets = le32_to_cpu(res->msdu_cnt[i].rx_msdu_cnt); |
| 111 | + |
| 112 | + wcid->stats.tx_packets += tx_packets; |
| 113 | + wcid->stats.rx_packets += rx_packets; |
| 114 | + |
| 115 | + __mt7996_stat_to_netdev(mphy, wcid, 0, 0, |
| 116 | + tx_packets, rx_packets); |
| 117 | break; |
| 118 | default: |
| 119 | break; |
| 120 | -- |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 121 | 2.18.0 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 122 | |