blob: 3295f14db8f714ff36096c596e6970a82ef6b0de [file] [log] [blame]
developer7e2761e2023-10-12 08:11:13 +08001From d97655d3fe3ddf2bbd508de52e207bc91d0115e2 Mon Sep 17 00:00:00 2001
developerc2cfe0f2023-09-22 04:11:09 +08002From: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com>
3Date: Fri, 18 Aug 2023 10:17:08 +0800
developer7e2761e2023-10-12 08:11:13 +08004Subject: [PATCH 76/98] wifi: mt76: mt7996: add per bss statistic info
developerc2cfe0f2023-09-22 04:11:09 +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
developer7e2761e2023-10-12 08:11:13 +080025index 51649dd..20e14e7 100644
developerc2cfe0f2023-09-22 04:11:09 +080026--- a/mt7996/init.c
27+++ b/mt7996/init.c
developer7e2761e2023-10-12 08:11:13 +080028@@ -378,6 +378,7 @@ mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed)
developerc2cfe0f2023-09-22 04:11:09 +080029 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
developer7e2761e2023-10-12 08:11:13 +080037index d27275a..2e0b1f1 100644
developerc2cfe0f2023-09-22 04:11:09 +080038--- a/mt7996/main.c
39+++ b/mt7996/main.c
developer7e2761e2023-10-12 08:11:13 +080040@@ -251,6 +251,7 @@ static int mt7996_add_interface(struct ieee80211_hw *hw,
developerc2cfe0f2023-09-22 04:11:09 +080041 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
developer7e2761e2023-10-12 08:11:13 +080049index bebd020..b2cb627 100644
developerc2cfe0f2023-09-22 04:11:09 +080050--- a/mt7996/mcu.c
51+++ b/mt7996/mcu.c
developer7e2761e2023-10-12 08:11:13 +080052@@ -592,6 +592,27 @@ static void mt7996_mcu_rx_rro(struct mt7996_dev *dev, struct sk_buff *skb)
developerc2cfe0f2023-09-22 04:11:09 +080053
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 {
developer7e2761e2023-10-12 08:11:13 +080080@@ -607,7 +628,7 @@ mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb)
developerc2cfe0f2023-09-22 04:11:09 +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:
developer7e2761e2023-10-12 08:11:13 +080089@@ -635,6 +656,9 @@ mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb)
developerc2cfe0f2023-09-22 04:11:09 +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 }
developer7e2761e2023-10-12 08:11:13 +080099@@ -646,10 +670,16 @@ mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb)
developerc2cfe0f2023-09-22 04:11:09 +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--
1212.18.0
122