blob: e8fd2b17049a753fb136f8d8c8857689f03b6847 [file] [log] [blame]
developer3f52c302024-04-08 14:36:46 +08001From ba04dd5323962bbed89405ceb8d7fd9c6796f09a Mon Sep 17 00:00:00 2001
developerbf0f2d62023-11-14 17:01:47 +08002From: Evelyn Tsai <evelyn.tsai@mediatek.com>
3Date: Wed, 1 Nov 2023 07:50:08 +0800
developer3f52c302024-04-08 14:36:46 +08004Subject: [PATCH 2012/2014] wifi: mt76: mt7915: wed: add per bss statistic info
developerbf0f2d62023-11-14 17:01:47 +08005
6---
7 mt7915/init.c | 1 +
8 mt7915/mac.c | 21 +++++++++++++++++++++
9 mt7915/main.c | 2 +-
10 mt7915/mcu.c | 30 +++++++++++++++++++++++++++---
developerd243af02023-12-21 14:49:33 +080011 mt7915/mmio.c | 26 +++++++++++++++++++++++++-
developerbf0f2d62023-11-14 17:01:47 +080012 mt7915/mt7915.h | 3 ++-
13 mt7915/mtk_debugfs.c | 2 +-
developerd243af02023-12-21 14:49:33 +080014 7 files changed, 78 insertions(+), 7 deletions(-)
developerbf0f2d62023-11-14 17:01:47 +080015
16diff --git a/mt7915/init.c b/mt7915/init.c
developer3f52c302024-04-08 14:36:46 +080017index 16c3632..e5327be 100644
developerbf0f2d62023-11-14 17:01:47 +080018--- a/mt7915/init.c
19+++ b/mt7915/init.c
developerebda9012024-02-22 13:42:45 +080020@@ -400,6 +400,7 @@ mt7915_init_wiphy(struct mt7915_phy *phy)
developerbf0f2d62023-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
developer3f52c302024-04-08 14:36:46 +080029index 02f794d..0c12170 100644
developerbf0f2d62023-11-14 17:01:47 +080030--- a/mt7915/mac.c
31+++ b/mt7915/mac.c
developer43a264f2024-03-26 14:09:54 +080032@@ -1071,6 +1071,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
developerbf0f2d62023-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
developer43a264f2024-03-26 14:09:54 +080040@@ -1089,6 +1090,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
developerbf0f2d62023-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
developerebda9012024-02-22 13:42:45 +080047 if (le32_get_bits(txs_data[0], MT_TXS0_TXS_FORMAT) == MT_TXS_PPDU_FMT)
developer43a264f2024-03-26 14:09:54 +080048@@ -1099,6 +1101,24 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
developerbf0f2d62023-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);
developer43a264f2024-03-26 14:09:54 +080073@@ -2043,6 +2063,7 @@ static void mt7915_mac_sta_stats_work(struct mt7915_phy *phy)
developerbf0f2d62023-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
developer3f52c302024-04-08 14:36:46 +080082index 199ce82..17a380b 100644
developerbf0f2d62023-11-14 17:01:47 +080083--- a/mt7915/main.c
84+++ b/mt7915/main.c
developer3f52c302024-04-08 14:36:46 +080085@@ -1245,7 +1245,7 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw,
developerbf0f2d62023-11-14 17:01:47 +080086 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
developer3f52c302024-04-08 14:36:46 +080095index d9d4fea..f0273fe 100644
developerbf0f2d62023-11-14 17:01:47 +080096--- a/mt7915/mcu.c
97+++ b/mt7915/mcu.c
developer3f52c302024-04-08 14:36:46 +080098@@ -4750,7 +4750,8 @@ int mt7915_mcu_twt_agrt_update(struct mt7915_dev *dev,
developerbf0f2d62023-11-14 17:01:47 +080099 &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;
developer3f52c302024-04-08 14:36:46 +0800108@@ -4806,11 +4807,34 @@ int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx)
developerbf0f2d62023-11-14 17:01:47 +0800109 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
developer3f52c302024-04-08 14:36:46 +0800146index 6309dd9..142f308 100644
developerbf0f2d62023-11-14 17:01:47 +0800147--- a/mt7915/mmio.c
148+++ b/mt7915/mmio.c
developerebda9012024-02-22 13:42:45 +0800149@@ -592,7 +592,7 @@ static void mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device *wed,
developerd243af02023-12-21 14:49:33 +0800150
151 dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed);
152
153- if (idx >= mt7915_wtbl_size(dev))
154+ if (idx <= 0 || idx >= mt7915_wtbl_size(dev))
155 return;
156
157 rcu_read_lock();
developerebda9012024-02-22 13:42:45 +0800158@@ -607,8 +607,32 @@ static void mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device *wed,
developerbf0f2d62023-11-14 17:01:47 +0800159 wcid->stats.rx_packets += le32_to_cpu(stats->rx_pkt_cnt);
160 wcid->stats.rx_errors += le32_to_cpu(stats->rx_err_cnt);
161 wcid->stats.rx_drops += le32_to_cpu(stats->rx_drop_cnt);
162+
163+ if (wiphy_ext_feature_isset(dev->mphy.hw->wiphy,
164+ NL80211_EXT_FEATURE_STAS_COUNT)) {
165+ struct mt7915_sta *msta;
166+ struct ieee80211_vif *vif;
167+ struct wireless_dev *wdev;
168+
169+ msta = container_of(wcid, struct mt7915_sta, wcid);
170+
171+ vif = container_of((void *)msta->vif,
172+ struct ieee80211_vif,
173+ drv_priv);
174+ if (!vif)
175+ goto unlock;
176+
177+ wdev = ieee80211_vif_to_wdev(vif);
178+
179+ if (vif->type == NL80211_IFTYPE_MONITOR)
180+ goto unlock;
181+
182+ dev_sw_netstats_rx_add(wdev->netdev, le32_to_cpu(stats->rx_pkt_cnt),
183+ le32_to_cpu(stats->rx_byte_cnt));
184+ }
185 }
186
187+unlock:
188 rcu_read_unlock();
189 }
190
191diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer3f52c302024-04-08 14:36:46 +0800192index c5bacf8..696b64e 100644
developerbf0f2d62023-11-14 17:01:47 +0800193--- a/mt7915/mt7915.h
194+++ b/mt7915/mt7915.h
developer43a264f2024-03-26 14:09:54 +0800195@@ -754,7 +754,8 @@ int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif,
developerbf0f2d62023-11-14 17:01:47 +0800196 struct ieee80211_sta *sta, struct rate_info *rate);
197 int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy,
198 struct cfg80211_chan_def *chandef);
199-int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid);
200+int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wcid,
201+ struct mt7915_sta *sta);
202 int mt7915_get_tx_stat(struct mt7915_phy *phy, u16 wlan_idx);
203 int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set);
204 int mt7915_mcu_wa_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2, u32 a3);
205diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c
developer3f52c302024-04-08 14:36:46 +0800206index a80ddeb..129a4dd 100644
developerbf0f2d62023-11-14 17:01:47 +0800207--- a/mt7915/mtk_debugfs.c
208+++ b/mt7915/mtk_debugfs.c
developer43a264f2024-03-26 14:09:54 +0800209@@ -4034,7 +4034,7 @@ static int mt7915_reset_counter(void *data, u64 val)
developerbf0f2d62023-11-14 17:01:47 +0800210 struct mt76_wcid *wcid;
211
212 /* Clear the firmware counters */
213- mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx);
214+ mt7915_mcu_wed_wa_tx_stats(dev, dev->wlan_idx, NULL);
215 mt7915_get_tx_stat(phy, dev->wlan_idx);
216
217 rcu_read_lock();
218--
2192.18.0
220