blob: dfae6e11feee6b12e41bd60ede7dd97db44cda88 [file] [log] [blame]
developerd0c89452024-10-11 16:53:27 +08001From 663d6e60f6a431146594178ffbbbf7fd54180c38 Mon Sep 17 00:00:00 2001
developer66e89bc2024-04-23 14:50:01 +08002From: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com>
3Date: Fri, 18 Aug 2023 10:17:08 +0800
developerd0c89452024-10-11 16:53:27 +08004Subject: [PATCH 058/223] mtk: mt76: mt7996: add per bss statistic info
developer66e89bc2024-04-23 14:50:01 +08005
6Whenever WED is enabled, unicast traffic might run through HW path.
7As a result, we need to count them using WM event.
8Broadcast and multicast traffic on the other hand, will be counted in mac80211
9as 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
24diff --git a/mt7996/init.c b/mt7996/init.c
developerd0c89452024-10-11 16:53:27 +080025index f493a373..f6cddac1 100644
developer66e89bc2024-04-23 14:50:01 +080026--- a/mt7996/init.c
27+++ b/mt7996/init.c
developer05f3b2b2024-08-19 19:17:34 +080028@@ -403,6 +403,7 @@ mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed)
developer66e89bc2024-04-23 14:50:01 +080029 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);
36diff --git a/mt7996/main.c b/mt7996/main.c
developerd0c89452024-10-11 16:53:27 +080037index f02f447e..dcf1fc38 100644
developer66e89bc2024-04-23 14:50:01 +080038--- 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,
48diff --git a/mt7996/mcu.c b/mt7996/mcu.c
developerd0c89452024-10-11 16:53:27 +080049index 70e1984a..8b84c9dc 100644
developer66e89bc2024-04-23 14:50:01 +080050--- a/mt7996/mcu.c
51+++ b/mt7996/mcu.c
developerd0c89452024-10-11 16:53:27 +080052@@ -529,6 +529,27 @@ mt7996_mcu_update_tx_gi(struct rate_info *rate, struct all_sta_trx_rate *mcu_rat
developer66e89bc2024-04-23 14:50:01 +080053 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 {
developerd0c89452024-10-11 16:53:27 +080080@@ -544,7 +565,7 @@ mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb)
developer66e89bc2024-04-23 14:50:01 +080081 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:
developerd0c89452024-10-11 16:53:27 +080089@@ -572,6 +593,9 @@ mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb)
developer66e89bc2024-04-23 14:50:01 +080090 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 }
developerd0c89452024-10-11 16:53:27 +080099@@ -583,10 +607,16 @@ mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb)
developer66e89bc2024-04-23 14:50:01 +0800100 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--
developerd0c89452024-10-11 16:53:27 +08001212.45.2
developer66e89bc2024-04-23 14:50:01 +0800122