blob: e9267b52d78b53625bee2177db630164ec99c124 [file] [log] [blame]
developerbf0f2d62023-11-14 17:01:47 +08001From 72f6ac700c7a66508aeb8a8341789b138360c416 Mon Sep 17 00:00:00 2001
2From: Evelyn Tsai <evelyn.tsai@mediatek.com>
3Date: Wed, 1 Nov 2023 07:50:08 +0800
4Subject: [PATCH 1/6] wifi: mt76: mt7915: wed: add per bss statistic info
5
6---
7 mt7915/init.c | 1 +
8 mt7915/mac.c | 21 +++++++++++++++++++++
9 mt7915/main.c | 2 +-
10 mt7915/mcu.c | 30 +++++++++++++++++++++++++++---
11 mt7915/mmio.c | 24 ++++++++++++++++++++++++
12 mt7915/mt7915.h | 3 ++-
13 mt7915/mtk_debugfs.c | 2 +-
14 7 files changed, 77 insertions(+), 6 deletions(-)
15
16diff --git a/mt7915/init.c b/mt7915/init.c
17index c643c33..9978edb 100644
18--- a/mt7915/init.c
19+++ b/mt7915/init.c
20@@ -397,6 +397,7 @@ mt7915_init_wiphy(struct mt7915_phy *phy)
21 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_FILS_DISCOVERY);
22 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT);
23 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
24+ wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STAS_COUNT);
25
26 if (!is_mt7915(&dev->mt76))
27 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STA_TX_PWR);
28diff --git a/mt7915/mac.c b/mt7915/mac.c
29index a473fc6..e403f0f 100644
30--- a/mt7915/mac.c
31+++ b/mt7915/mac.c
32@@ -1067,6 +1067,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
33 struct mt7915_phy *phy;
34 struct mt76_wcid *wcid;
35 __le32 *txs_data = data;
36+ u64 last_bytes;
37 u16 wcidx;
38 u8 pid;
39
40@@ -1085,6 +1086,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
41 if (!wcid)
42 goto out;
43
44+ last_bytes = wcid->stats.tx_bytes;
45 msta = container_of(wcid, struct mt7915_sta, wcid);
46
47 if (pid == MT_PACKET_ID_WED)
48@@ -1095,6 +1097,24 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
49 if (!wcid->sta)
50 goto out;
51
52+ if (wiphy_ext_feature_isset(dev->mphy.hw->wiphy,
53+ NL80211_EXT_FEATURE_STAS_COUNT)) {
54+ struct ieee80211_vif *vif;
55+ struct wireless_dev *wdev;
56+
57+ vif = container_of((void *)msta->vif, struct ieee80211_vif,
58+ drv_priv);
59+ if (!vif)
60+ goto out;
61+
62+ wdev = ieee80211_vif_to_wdev(vif);
63+
64+ if (vif->type == NL80211_IFTYPE_MONITOR)
65+ goto out;
66+
67+ dev_sw_netstats_tx_add(wdev->netdev, 0, (wcid->stats.tx_bytes - last_bytes));
68+ }
69+
70 spin_lock_bh(&dev->mt76.sta_poll_lock);
71 if (list_empty(&msta->wcid.poll_list))
72 list_add_tail(&msta->wcid.poll_list, &dev->mt76.sta_poll_list);
73@@ -2081,6 +2101,7 @@ static void mt7915_mac_sta_stats_work(struct mt7915_phy *phy)
74 spin_unlock_bh(&phy->stats_lock);
75
76 mt7915_mcu_get_tx_rate(phy, sta->wcid.idx);
77+ mt7915_mcu_wed_wa_tx_stats(phy->dev, sta->wcid.idx, sta);
78
79 spin_lock_bh(&phy->stats_lock);
80 }
81diff --git a/mt7915/main.c b/mt7915/main.c
82index 72bcaab..9595b55 100644
83--- a/mt7915/main.c
84+++ b/mt7915/main.c
85@@ -1188,7 +1188,7 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw,
86 sinfo->tx_bytes = msta->wcid.stats.tx_bytes;
87 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64);
88
89- if (!mt7915_mcu_wed_wa_tx_stats(phy->dev, msta->wcid.idx)) {
90+ if (!mt7915_mcu_wed_wa_tx_stats(phy->dev, msta->wcid.idx, msta)) {
91 sinfo->tx_packets = msta->wcid.stats.tx_packets;
92 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
93 }
94diff --git a/mt7915/mcu.c b/mt7915/mcu.c
95index fe3f151..72f74e1 100644
96--- a/mt7915/mcu.c
97+++ b/mt7915/mcu.c
98@@ -4467,7 +4467,8 @@ int mt7915_mcu_twt_agrt_update(struct mt7915_dev *dev,
99 &req, sizeof(req), true);
100 }
101
102-int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx)
103+int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx,
104+ struct mt7915_sta *sta)
105 {
106 struct {
107 __le32 cmd;
108@@ -4511,11 +4512,34 @@ int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx)
109 rcu_read_lock();
110
111 wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]);
112- if (wcid)
113+ if (wcid) {
114+ struct ieee80211_vif *vif;
115+ struct wireless_dev *wdev;
116+
117 wcid->stats.tx_packets += le32_to_cpu(res->tx_packets);
118- else
119+
120+ if (!wiphy_ext_feature_isset(dev->mphy.hw->wiphy,
121+ NL80211_EXT_FEATURE_STAS_COUNT) ||
122+ !sta)
123+ goto unlock;
124+
125+ vif = container_of((void *)sta->vif,
126+ struct ieee80211_vif,
127+ drv_priv);
128+ if (!vif)
129+ goto unlock;
130+
131+ wdev = ieee80211_vif_to_wdev(vif);
132+
133+ if (vif->type == NL80211_IFTYPE_MONITOR)
134+ goto unlock;
135+
136+ dev_sw_netstats_tx_add(wdev->netdev, le32_to_cpu(res->tx_packets), 0);
137+ } else {
138 ret = -EINVAL;
139+ }
140
141+unlock:
142 rcu_read_unlock();
143 out:
144 dev_kfree_skb(skb);
145diff --git a/mt7915/mmio.c b/mt7915/mmio.c
146index 2ad7ba4..ce976b4 100644
147--- a/mt7915/mmio.c
148+++ b/mt7915/mmio.c
149@@ -742,8 +742,32 @@ static void mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device *wed,
150 wcid->stats.rx_packets += le32_to_cpu(stats->rx_pkt_cnt);
151 wcid->stats.rx_errors += le32_to_cpu(stats->rx_err_cnt);
152 wcid->stats.rx_drops += le32_to_cpu(stats->rx_drop_cnt);
153+
154+ if (wiphy_ext_feature_isset(dev->mphy.hw->wiphy,
155+ NL80211_EXT_FEATURE_STAS_COUNT)) {
156+ struct mt7915_sta *msta;
157+ struct ieee80211_vif *vif;
158+ struct wireless_dev *wdev;
159+
160+ msta = container_of(wcid, struct mt7915_sta, wcid);
161+
162+ vif = container_of((void *)msta->vif,
163+ struct ieee80211_vif,
164+ drv_priv);
165+ if (!vif)
166+ goto unlock;
167+
168+ wdev = ieee80211_vif_to_wdev(vif);
169+
170+ if (vif->type == NL80211_IFTYPE_MONITOR)
171+ goto unlock;
172+
173+ dev_sw_netstats_rx_add(wdev->netdev, le32_to_cpu(stats->rx_pkt_cnt),
174+ le32_to_cpu(stats->rx_byte_cnt));
175+ }
176 }
177
178+unlock:
179 rcu_read_unlock();
180 }
181
182diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
183index 091af43..1510f10 100644
184--- a/mt7915/mt7915.h
185+++ b/mt7915/mt7915.h
186@@ -683,7 +683,8 @@ int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif,
187 struct ieee80211_sta *sta, struct rate_info *rate);
188 int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy,
189 struct cfg80211_chan_def *chandef);
190-int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid);
191+int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid,
192+ struct mt7915_sta *sta);
193 int mt7915_get_tx_stat(struct mt7915_phy *phy, u16 wlan_idx);
194 int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set);
195 int mt7915_mcu_wa_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2, u32 a3);
196diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c
197index e73db5d..f481231 100644
198--- a/mt7915/mtk_debugfs.c
199+++ b/mt7915/mtk_debugfs.c
200@@ -3812,7 +3812,7 @@ static int mt7915_reset_counter(void *data, u64 val)
201 struct mt76_wcid *wcid;
202
203 /* Clear the firmware counters */
204- mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx);
205+ mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx, NULL);
206 mt7915_get_tx_stat(phy, dev->wlan_idx);
207
208 rcu_read_lock();
209--
2102.18.0
211