blob: 4aa42801e76485665ef4226ba7031824c2f8fd6d [file] [log] [blame]
developer849549c2023-08-02 17:26:48 +08001From a3bc2ff25993c37117aad833b5f4cb39cbedd5bf Mon Sep 17 00:00:00 2001
developer7be29542023-06-28 17:30:38 +08002From: "sujuan.chen" <sujuan.chen@mediatek.com>
3Date: Wed, 28 Jun 2023 17:11:18 +0800
developer849549c2023-08-02 17:26:48 +08004Subject: [PATCH 2009/2010] wifi: mt76: mt7915: wed: add per bss statistic info
developer7be29542023-06-28 17:30:38 +08005
6Signed-off-by: sujuan.chen <sujuan.chen@mediatek.com>
7---
8 mt7915/init.c | 1 +
9 mt7915/mac.c | 19 +++++++++++++++++++
10 mt7915/main.c | 2 +-
11 mt7915/mcu.c | 29 ++++++++++++++++++++++++++---
12 mt7915/mmio.c | 26 ++++++++++++++++++++++++++
13 mt7915/mt7915.h | 3 ++-
14 mt7915/mtk_debugfs.c | 2 +-
15 7 files changed, 76 insertions(+), 6 deletions(-)
16
17diff --git a/mt7915/init.c b/mt7915/init.c
developer849549c2023-08-02 17:26:48 +080018index 58e044ea..a2aca371 100644
developer7be29542023-06-28 17:30:38 +080019--- a/mt7915/init.c
20+++ b/mt7915/init.c
developer849549c2023-08-02 17:26:48 +080021@@ -386,6 +386,7 @@ mt7915_init_wiphy(struct mt7915_phy *phy)
developer7be29542023-06-28 17:30:38 +080022 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_FILS_DISCOVERY);
23 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT);
24 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
25+ wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STAS_COUNT);
26
27 if (!is_mt7915(&dev->mt76))
28 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STA_TX_PWR);
29diff --git a/mt7915/mac.c b/mt7915/mac.c
developer849549c2023-08-02 17:26:48 +080030index debc2f9d..244dff46 100644
developer7be29542023-06-28 17:30:38 +080031--- a/mt7915/mac.c
32+++ b/mt7915/mac.c
33@@ -1048,6 +1048,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
34 struct mt7915_phy *phy;
35 struct mt76_wcid *wcid;
36 __le32 *txs_data = data;
37+ u64 last_bytes;
38 u16 wcidx;
39 u8 pid;
40
41@@ -1066,6 +1067,7 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
42 if (!wcid)
43 goto out;
44
45+ last_bytes = wcid->stats.tx_bytes;
46 msta = container_of(wcid, struct mt7915_sta, wcid);
47
48 if (pid == MT_PACKET_ID_WED)
49@@ -1076,6 +1078,22 @@ static void mt7915_mac_add_txs(struct mt7915_dev *dev, void *data)
50 if (!wcid->sta)
51 goto out;
52
53+ if (wiphy_ext_feature_isset(dev->mphy.hw->wiphy,
54+ NL80211_EXT_FEATURE_STAS_COUNT)) {
55+ struct ieee80211_vif *vif;
56+ struct wireless_dev *wdev;
57+ struct pcpu_sw_netstats *tstats;
58+
59+ vif = container_of((void *)msta->vif, struct ieee80211_vif,
60+ drv_priv);
61+ if (!vif)
62+ goto out;
63+
64+ wdev = ieee80211_vif_to_wdev(vif);
65+ tstats = this_cpu_ptr(wdev->netdev->tstats);
66+
67+ tstats->tx_bytes += wcid->stats.tx_bytes - last_bytes;
68+ }
69 spin_lock_bh(&dev->mt76.sta_poll_lock);
70 if (list_empty(&msta->wcid.poll_list))
71 list_add_tail(&msta->wcid.poll_list, &dev->mt76.sta_poll_list);
72@@ -2053,6 +2071,7 @@ static void mt7915_mac_sta_stats_work(struct mt7915_phy *phy)
73 spin_unlock_bh(&phy->stats_lock);
74
75 mt7915_mcu_get_tx_rate(phy, sta->wcid.idx);
76+ mt7915_mcu_wed_wa_tx_stats(phy->dev, sta->wcid.idx, sta);
77
78 spin_lock_bh(&phy->stats_lock);
79 }
80diff --git a/mt7915/main.c b/mt7915/main.c
developer849549c2023-08-02 17:26:48 +080081index 03697bac..22d1d25b 100644
developer7be29542023-06-28 17:30:38 +080082--- a/mt7915/main.c
83+++ b/mt7915/main.c
developer849549c2023-08-02 17:26:48 +080084@@ -1173,7 +1173,7 @@ static void mt7915_sta_statistics(struct ieee80211_hw *hw,
developer7be29542023-06-28 17:30:38 +080085 sinfo->tx_bytes = msta->wcid.stats.tx_bytes;
86 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64);
87
88- if (!mt7915_mcu_wed_wa_tx_stats(phy->dev, msta->wcid.idx)) {
89+ if (!mt7915_mcu_wed_wa_tx_stats(phy->dev, msta->wcid.idx, msta)) {
90 sinfo->tx_packets = msta->wcid.stats.tx_packets;
91 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
92 }
93diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developer849549c2023-08-02 17:26:48 +080094index a4225675..6f93b3b0 100644
developer7be29542023-06-28 17:30:38 +080095--- a/mt7915/mcu.c
96+++ b/mt7915/mcu.c
developer8f0d89b2023-07-28 07:16:44 +080097@@ -4408,7 +4408,8 @@ int mt7915_mcu_twt_agrt_update(struct mt7915_dev *dev,
developer7be29542023-06-28 17:30:38 +080098 &req, sizeof(req), true);
99 }
100
101-int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx)
102+int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx,
103+ struct mt7915_sta *sta)
104 {
105 struct {
106 __le32 cmd;
developer8f0d89b2023-07-28 07:16:44 +0800107@@ -4452,11 +4453,33 @@ int mt7915_mcu_wed_wa_tx_stats(struct mt7915_dev *dev, u16 wlan_idx)
developer7be29542023-06-28 17:30:38 +0800108 rcu_read_lock();
109
110 wcid = rcu_dereference(dev->mt76.wcid[wlan_idx]);
111- if (wcid)
112+ if (wcid) {
113+ struct ieee80211_vif *vif;
114+ struct wireless_dev *wdev;
115+ struct pcpu_sw_netstats *tstats;
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+ tstats = this_cpu_ptr(wdev->netdev->tstats);
134+ tstats->tx_packets += le32_to_cpu(res->tx_packets);
135+ } else {
136 ret = -EINVAL;
137+ }
138
139+unlock:
140 rcu_read_unlock();
141 out:
142 dev_kfree_skb(skb);
143diff --git a/mt7915/mmio.c b/mt7915/mmio.c
developer849549c2023-08-02 17:26:48 +0800144index 89523a52..00c190c7 100644
developer7be29542023-06-28 17:30:38 +0800145--- a/mt7915/mmio.c
146+++ b/mt7915/mmio.c
developer8f0d89b2023-07-28 07:16:44 +0800147@@ -704,8 +704,34 @@ static void mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device *wed,
developer7be29542023-06-28 17:30:38 +0800148 wcid->stats.rx_packets += le32_to_cpu(stats->rx_pkt_cnt);
149 wcid->stats.rx_errors += le32_to_cpu(stats->rx_err_cnt);
150 wcid->stats.rx_drops += le32_to_cpu(stats->rx_drop_cnt);
151+
152+ if (wiphy_ext_feature_isset(dev->mphy.hw->wiphy,
153+ NL80211_EXT_FEATURE_STAS_COUNT)) {
154+ struct mt7915_sta *msta;
155+ struct ieee80211_vif *vif;
156+ struct wireless_dev *wdev;
157+ struct pcpu_sw_netstats *tstats;
158+
159+ msta = container_of(wcid, struct mt7915_sta, wcid);
160+
161+ if (!msta || !msta->vif)
162+ goto unlock;
163+
164+ vif = container_of((void *)msta->vif,
165+ struct ieee80211_vif,
166+ drv_priv);
167+ if (!vif)
168+ goto unlock;
169+
170+ wdev = ieee80211_vif_to_wdev(vif);
171+ tstats = this_cpu_ptr(wdev->netdev->tstats);
172+
173+ tstats->rx_packets += le32_to_cpu(stats->rx_pkt_cnt);
174+ tstats->rx_bytes += 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
developer849549c2023-08-02 17:26:48 +0800183index 70e92734..8171ea8a 100644
developer7be29542023-06-28 17:30:38 +0800184--- a/mt7915/mt7915.h
185+++ b/mt7915/mt7915.h
developer849549c2023-08-02 17:26:48 +0800186@@ -673,7 +673,8 @@ int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif,
developer7be29542023-06-28 17:30:38 +0800187 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
developer849549c2023-08-02 17:26:48 +0800197index 401b4dd6..7a641b10 100644
developer7be29542023-06-28 17:30:38 +0800198--- a/mt7915/mtk_debugfs.c
199+++ b/mt7915/mtk_debugfs.c
200@@ -3797,7 +3797,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--
developer849549c2023-08-02 17:26:48 +08002102.39.2
developer7be29542023-06-28 17:30:38 +0800211