blob: fe8d1661274d9ae831bc07d4e1ad10e702647f64 [file] [log] [blame]
developerc2cfe0f2023-09-22 04:11:09 +08001From 3cee39db21222ca86581819f72fcc4839dfea429 Mon Sep 17 00:00:00 2001
2From: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com>
3Date: Fri, 18 Aug 2023 10:17:08 +0800
4Subject: [PATCH] wifi: mt76: mt7996: add per bss statistic info
5
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
25index 1cdf81a..6b30820 100644
26--- a/mt7996/init.c
27+++ b/mt7996/init.c
28@@ -375,6 +375,7 @@ mt7996_init_wiphy(struct ieee80211_hw *hw)
29 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT);
30 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
31 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
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
37index 52e9666..a8ed204 100644
38--- a/mt7996/main.c
39+++ b/mt7996/main.c
40@@ -254,6 +254,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
49index a4c6cd5..0653882 100644
50--- a/mt7996/mcu.c
51+++ b/mt7996/mcu.c
52@@ -552,6 +552,27 @@ static void mt7996_mcu_rx_rro(struct mt7996_dev *dev, struct sk_buff *skb)
53
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@@ -567,7 +588,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@@ -595,6 +616,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@@ -606,10 +630,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--
1212.18.0
122