blob: 9b8620543570d5ec4ce468af7a920285f388c4c4 [file] [log] [blame]
developera20cdc22024-05-31 18:57:31 +08001From 4e0a12871b8c134c99bd702f425c492ddc1f50b6 Mon Sep 17 00:00:00 2001
developer70180b02023-11-14 17:01:47 +08002From: Evelyn Tsai <evelyn.tsai@mediatek.com>
3Date: Wed, 1 Nov 2023 07:50:08 +0800
developera20cdc22024-05-31 18:57:31 +08004Subject: [PATCH 1/5] wifi: mt76: mt7915: wed: add per bss statistic info
developer70180b02023-11-14 17:01:47 +08005
6---
7 mt7915/init.c | 1 +
8 mt7915/mac.c | 21 +++++++++++++++++++++
developera20cdc22024-05-31 18:57:31 +08009 mt7915/main.c | 5 ++++-
developer70180b02023-11-14 17:01:47 +080010 mt7915/mcu.c | 30 +++++++++++++++++++++++++++---
developer1a173672023-12-21 14:49:33 +080011 mt7915/mmio.c | 26 +++++++++++++++++++++++++-
developer70180b02023-11-14 17:01:47 +080012 mt7915/mt7915.h | 3 ++-
13 mt7915/mtk_debugfs.c | 2 +-
developera20cdc22024-05-31 18:57:31 +080014 7 files changed, 81 insertions(+), 7 deletions(-)
developer70180b02023-11-14 17:01:47 +080015
16diff --git a/mt7915/init.c b/mt7915/init.c
developera20cdc22024-05-31 18:57:31 +080017index f38c8a1..7bc8039 100644
developer70180b02023-11-14 17:01:47 +080018--- a/mt7915/init.c
19+++ b/mt7915/init.c
developer753619c2024-02-22 13:42:45 +080020@@ -400,6 +400,7 @@ mt7915_init_wiphy(struct mt7915_phy *phy)
developer70180b02023-11-14 17:01:47 +080021 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
developerdc9eeae2024-04-08 14:36:46 +080029index 02f794d..0c12170 100644
developer70180b02023-11-14 17:01:47 +080030--- a/mt7915/mac.c
31+++ b/mt7915/mac.c
developera46f6132024-03-26 14:09:54 +080032@@ -1071,6 +1071,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
developer70180b02023-11-14 17:01:47 +080033 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
developera46f6132024-03-26 14:09:54 +080040@@ -1089,6 +1090,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
developer70180b02023-11-14 17:01:47 +080041 if (!wcid)
42 goto out;
43
44+ last_bytes = wcid->stats.tx_bytes;
45 msta = container_of(wcid, struct mt7915_sta, wcid);
46
developer753619c2024-02-22 13:42:45 +080047 if (le32_get_bits(txs_data[0], MT_TXS0_TXS_FORMAT) == MT_TXS_PPDU_FMT)
developera46f6132024-03-26 14:09:54 +080048@@ -1099,6 +1101,24 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
developer70180b02023-11-14 17:01:47 +080049 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);
developera46f6132024-03-26 14:09:54 +080073@@ -2043,6 +2063,7 @@ static void mt7915_mac_sta_stats_work(struct mt7915_phy *phy)
developer70180b02023-11-14 17:01:47 +080074 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
developera20cdc22024-05-31 18:57:31 +080082index feb2c89..722635e 100644
developer70180b02023-11-14 17:01:47 +080083--- a/mt7915/main.c
84+++ b/mt7915/main.c
developera20cdc22024-05-31 18:57:31 +080085@@ -1219,6 +1219,9 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw,
86 struct rate_info *txrate = &msta->wcid.rate;
87 struct rate_info rxrate = {};
88
89+ if (msta->wcid.idx == 0)
90+ return;
91+
92 if (is_connac_v2(&phy->dev->mt76) &&
93 !mt7915_mcu_get_rx_rate(phy, vif, sta, &rxrate)) {
94 sinfo->rxrate = rxrate;
95@@ -1247,7 +1250,7 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw,
developer70180b02023-11-14 17:01:47 +080096 sinfo->tx_bytes = msta->wcid.stats.tx_bytes;
97 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64);
98
99- if (!mt7915_mcu_wed_wa_tx_stats(phy->dev, msta->wcid.idx)) {
100+ if (!mt7915_mcu_wed_wa_tx_stats(phy->dev, msta->wcid.idx, msta)) {
101 sinfo->tx_packets = msta->wcid.stats.tx_packets;
102 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
103 }
104diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developera20cdc22024-05-31 18:57:31 +0800105index 708e7cd..342fe42 100644
developer70180b02023-11-14 17:01:47 +0800106--- a/mt7915/mcu.c
107+++ b/mt7915/mcu.c
developerdc9eeae2024-04-08 14:36:46 +0800108@@ -4750,7 +4750,8 @@ int mt7915_mcu_twt_agrt_update(struct mt7915_dev *dev,
developer70180b02023-11-14 17:01:47 +0800109 &req, sizeof(req), true);
110 }
111
112-int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx)
113+int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx,
114+ struct mt7915_sta *sta)
115 {
116 struct {
117 __le32 cmd;
developerdc9eeae2024-04-08 14:36:46 +0800118@@ -4806,11 +4807,34 @@ int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx)
developer70180b02023-11-14 17:01:47 +0800119 rcu_read_lock();
120
121 wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]);
122- if (wcid)
123+ if (wcid) {
124+ struct ieee80211_vif *vif;
125+ struct wireless_dev *wdev;
126+
127 wcid->stats.tx_packets += le32_to_cpu(res->tx_packets);
128- else
129+
130+ if (!wiphy_ext_feature_isset(dev->mphy.hw->wiphy,
131+ NL80211_EXT_FEATURE_STAS_COUNT) ||
132+ !sta)
133+ goto unlock;
134+
135+ vif = container_of((void *)sta->vif,
136+ struct ieee80211_vif,
137+ drv_priv);
138+ if (!vif)
139+ goto unlock;
140+
141+ wdev = ieee80211_vif_to_wdev(vif);
142+
143+ if (vif->type == NL80211_IFTYPE_MONITOR)
144+ goto unlock;
145+
146+ dev_sw_netstats_tx_add(wdev->netdev, le32_to_cpu(res->tx_packets), 0);
147+ } else {
148 ret = -EINVAL;
149+ }
150
151+unlock:
152 rcu_read_unlock();
153 out:
154 dev_kfree_skb(skb);
155diff --git a/mt7915/mmio.c b/mt7915/mmio.c
developerdc9eeae2024-04-08 14:36:46 +0800156index 6309dd9..142f308 100644
developer70180b02023-11-14 17:01:47 +0800157--- a/mt7915/mmio.c
158+++ b/mt7915/mmio.c
developer753619c2024-02-22 13:42:45 +0800159@@ -592,7 +592,7 @@ static void mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device *wed,
developer1a173672023-12-21 14:49:33 +0800160
161 dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed);
162
163- if (idx >= mt7915_wtbl_size(dev))
164+ if (idx <= 0 || idx >= mt7915_wtbl_size(dev))
165 return;
166
167 rcu_read_lock();
developer753619c2024-02-22 13:42:45 +0800168@@ -607,8 +607,32 @@ static void mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device *wed,
developer70180b02023-11-14 17:01:47 +0800169 wcid->stats.rx_packets += le32_to_cpu(stats->rx_pkt_cnt);
170 wcid->stats.rx_errors += le32_to_cpu(stats->rx_err_cnt);
171 wcid->stats.rx_drops += le32_to_cpu(stats->rx_drop_cnt);
172+
173+ if (wiphy_ext_feature_isset(dev->mphy.hw->wiphy,
174+ NL80211_EXT_FEATURE_STAS_COUNT)) {
175+ struct mt7915_sta *msta;
176+ struct ieee80211_vif *vif;
177+ struct wireless_dev *wdev;
178+
179+ msta = container_of(wcid, struct mt7915_sta, wcid);
180+
181+ vif = container_of((void *)msta->vif,
182+ struct ieee80211_vif,
183+ drv_priv);
184+ if (!vif)
185+ goto unlock;
186+
187+ wdev = ieee80211_vif_to_wdev(vif);
188+
189+ if (vif->type == NL80211_IFTYPE_MONITOR)
190+ goto unlock;
191+
192+ dev_sw_netstats_rx_add(wdev->netdev, le32_to_cpu(stats->rx_pkt_cnt),
193+ le32_to_cpu(stats->rx_byte_cnt));
194+ }
195 }
196
197+unlock:
198 rcu_read_unlock();
199 }
200
201diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developera20cdc22024-05-31 18:57:31 +0800202index 945c82e..6e7ed9e 100644
developer70180b02023-11-14 17:01:47 +0800203--- a/mt7915/mt7915.h
204+++ b/mt7915/mt7915.h
developera20cdc22024-05-31 18:57:31 +0800205@@ -756,7 +756,8 @@ int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif,
developer70180b02023-11-14 17:01:47 +0800206 struct ieee80211_sta *sta, struct rate_info *rate);
207 int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy,
208 struct cfg80211_chan_def *chandef);
209-int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid);
210+int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid,
211+ struct mt7915_sta *sta);
212 int mt7915_get_tx_stat(struct mt7915_phy *phy, u16 wlan_idx);
213 int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set);
214 int mt7915_mcu_wa_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2, u32 a3);
215diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c
developera20cdc22024-05-31 18:57:31 +0800216index c63bf90..2c9f198 100644
developer70180b02023-11-14 17:01:47 +0800217--- a/mt7915/mtk_debugfs.c
218+++ b/mt7915/mtk_debugfs.c
developera46f6132024-03-26 14:09:54 +0800219@@ -4034,7 +4034,7 @@ static int mt7915_reset_counter(void *data, u64 val)
developer70180b02023-11-14 17:01:47 +0800220 struct mt76_wcid *wcid;
221
222 /* Clear the firmware counters */
223- mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx);
224+ mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx, NULL);
225 mt7915_get_tx_stat(phy, dev->wlan_idx);
226
227 rcu_read_lock();
228--
2292.18.0
230