diff mbox series

[2/2] wifi: mt76: mt7915: accumulate mu-mimo ofdma muru stats

Message ID 52ff6b0b789578c7873c1c349234063a8a2a9665.1684280458.git.ryder.lee@mediatek.com (mailing list archive)
State Superseded
Delegated to: Felix Fietkau
Headers show
Series [1/2] wifi: mt76: add tx_nss histogram to ethtool stats | expand

Commit Message

Ryder Lee May 17, 2023, 3:22 a.m. UTC
The stats are clear-on-read, which makes it very difficult for tools
to adequately deal with wrapped stats and with keeping good totals.

So, accumulate these values when they are read from the firmware/radio
and present totals to user-space.

Signed-off-by: Ben Greear <greearb@candelatech.com>
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
---
 .../wireless/mediatek/mt76/mt7915/debugfs.c   |  7 +--
 .../net/wireless/mediatek/mt76/mt7915/mac.c   |  3 +
 .../net/wireless/mediatek/mt76/mt7915/main.c  | 63 +++++++++++++++++++
 .../net/wireless/mediatek/mt76/mt7915/mcu.c   | 41 ++++++++++--
 .../wireless/mediatek/mt76/mt7915/mt7915.h    | 34 +++++++++-
 5 files changed, 139 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
index 879884ead660..971213393da9 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
@@ -251,7 +251,6 @@  static int mt7915_muru_stats_show(struct seq_file *file, void *data)
 {
 	struct mt7915_phy *phy = file->private;
 	struct mt7915_dev *dev = phy->dev;
-	struct mt7915_mcu_muru_stats mu_stats = {};
 	static const char * const dl_non_he_type[] = {
 		"CCK", "OFDM", "HT MIX", "HT GF",
 		"VHT SU", "VHT 2MU", "VHT 3MU", "VHT 4MU"
@@ -275,7 +274,7 @@  static int mt7915_muru_stats_show(struct seq_file *file, void *data)
 
 	mutex_lock(&dev->mt76.mutex);
 
-	ret = mt7915_mcu_muru_debug_get(phy, &mu_stats);
+	ret = mt7915_mcu_muru_debug_get(phy);
 	if (ret)
 		goto exit;
 
@@ -285,7 +284,7 @@  static int mt7915_muru_stats_show(struct seq_file *file, void *data)
 	for (i = 0; i < 5; i++)
 		seq_printf(file, "%8s | ", dl_non_he_type[i]);
 
-#define __dl_u32(s)     le32_to_cpu(mu_stats.dl.s)
+#define __dl_u32(s)     phy->mib.dl_##s
 	seq_puts(file, "\nTotal Count:");
 	seq_printf(file, "%8u | %8u | %8u | %8u | %8u | ",
 		   __dl_u32(cck_cnt),
@@ -389,7 +388,7 @@  static int mt7915_muru_stats_show(struct seq_file *file, void *data)
 	for (i = 0; i < 3; i++)
 		seq_printf(file, "%8s | ", ul_he_type[i]);
 
-#define __ul_u32(s)     le32_to_cpu(mu_stats.ul.s)
+#define __ul_u32(s)     phy->mib.ul_##s
 	seq_puts(file, "\nTotal Count:");
 	seq_printf(file, "%8u | %8u | %8u | ",
 		   __ul_u32(hetrig_2mu_cnt),
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
index dfe42af6dc97..e06bfa4288b7 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
@@ -2075,6 +2075,9 @@  void mt7915_mac_work(struct work_struct *work)
 
 		mt7915_mac_update_stats(phy);
 		mt7915_mac_severe_check(phy);
+
+		if (phy->dev->muru_debug)
+			mt7915_mcu_muru_debug_get(phy);
 	}
 
 	mutex_unlock(&mphy->dev->mutex);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
index bf87aa4cc630..226ec3755efd 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
@@ -1255,6 +1255,38 @@  static const char mt7915_gstrings_stats[][ETH_GSTRING_LEN] = {
 	"rx_vec_queue_overflow_drop_cnt",
 	"rx_ba_cnt",
 
+	/* muru mu-mimo and ofdma related stats */
+	"dl_cck_cnt",
+	"dl_ofdm_cnt",
+	"dl_htmix_cnt",
+	"dl_htgf_cnt",
+	"dl_vht_su_cnt",
+	"dl_vht_2mu_cnt",
+	"dl_vht_3mu_cnt",
+	"dl_vht_4mu_cnt",
+	"dl_he_su_cnt",
+	"dl_he_ext_su_cnt",
+	"dl_he_2ru_cnt",
+	"dl_he_2mu_cnt",
+	"dl_he_3ru_cnt",
+	"dl_he_3mu_cnt",
+	"dl_he_4ru_cnt",
+	"dl_he_4mu_cnt",
+	"dl_he_5to8ru_cnt",
+	"dl_he_9to16ru_cnt",
+	"dl_he_gtr16ru_cnt",
+
+	"ul_hetrig_su_cnt",
+	"ul_hetrig_2ru_cnt",
+	"ul_hetrig_3ru_cnt",
+	"ul_hetrig_4ru_cnt",
+	"ul_hetrig_5to8ru_cnt",
+	"ul_hetrig_9to16ru_cnt",
+	"ul_hetrig_gtr16ru_cnt",
+	"ul_hetrig_2mu_cnt",
+	"ul_hetrig_3mu_cnt",
+	"ul_hetrig_4mu_cnt",
+
 	/* per vif counters */
 	"v_tx_mode_cck",
 	"v_tx_mode_ofdm",
@@ -1409,6 +1441,37 @@  void mt7915_get_et_stats(struct ieee80211_hw *hw,
 	data[ei++] = mib->rx_vec_queue_overflow_drop_cnt;
 	data[ei++] = mib->rx_ba_cnt;
 
+	data[ei++] = mib->dl_cck_cnt;
+	data[ei++] = mib->dl_ofdm_cnt;
+	data[ei++] = mib->dl_htmix_cnt;
+	data[ei++] = mib->dl_htgf_cnt;
+	data[ei++] = mib->dl_vht_su_cnt;
+	data[ei++] = mib->dl_vht_2mu_cnt;
+	data[ei++] = mib->dl_vht_3mu_cnt;
+	data[ei++] = mib->dl_vht_4mu_cnt;
+	data[ei++] = mib->dl_he_su_cnt;
+	data[ei++] = mib->dl_he_ext_su_cnt;
+	data[ei++] = mib->dl_he_2ru_cnt;
+	data[ei++] = mib->dl_he_2mu_cnt;
+	data[ei++] = mib->dl_he_3ru_cnt;
+	data[ei++] = mib->dl_he_3mu_cnt;
+	data[ei++] = mib->dl_he_4ru_cnt;
+	data[ei++] = mib->dl_he_4mu_cnt;
+	data[ei++] = mib->dl_he_5to8ru_cnt;
+	data[ei++] = mib->dl_he_9to16ru_cnt;
+	data[ei++] = mib->dl_he_gtr16ru_cnt;
+
+	data[ei++] = mib->ul_hetrig_su_cnt;
+	data[ei++] = mib->ul_hetrig_2ru_cnt;
+	data[ei++] = mib->ul_hetrig_3ru_cnt;
+	data[ei++] = mib->ul_hetrig_4ru_cnt;
+	data[ei++] = mib->ul_hetrig_5to8ru_cnt;
+	data[ei++] = mib->ul_hetrig_9to16ru_cnt;
+	data[ei++] = mib->ul_hetrig_gtr16ru_cnt;
+	data[ei++] = mib->ul_hetrig_2mu_cnt;
+	data[ei++] = mib->ul_hetrig_3mu_cnt;
+	data[ei++] = mib->ul_hetrig_4mu_cnt;
+
 	/* Add values for all stations owned by this vif */
 	wi.initial_stat_idx = ei;
 	ieee80211_iterate_stations_atomic(hw, mt7915_ethtool_worker, &wi);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
index 5916dcaa8c7e..1a48f2b35b03 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
@@ -2116,12 +2116,11 @@  int mt7915_mcu_muru_debug_set(struct mt7915_dev *dev, bool enabled)
 				sizeof(data), false);
 }
 
-int mt7915_mcu_muru_debug_get(struct mt7915_phy *phy, void *ms)
+int mt7915_mcu_muru_debug_get(struct mt7915_phy *phy)
 {
 	struct mt7915_dev *dev = phy->dev;
 	struct sk_buff *skb;
-	struct mt7915_mcu_muru_stats *mu_stats =
-				(struct mt7915_mcu_muru_stats *)ms;
+	struct mt7915_mcu_muru_stats *mu_stats;
 	int ret;
 
 	struct {
@@ -2137,7 +2136,41 @@  int mt7915_mcu_muru_debug_get(struct mt7915_phy *phy, void *ms)
 	if (ret)
 		return ret;
 
-	memcpy(mu_stats, skb->data, sizeof(struct mt7915_mcu_muru_stats));
+	mu_stats = (struct mt7915_mcu_muru_stats *)(skb->data);
+
+	/* accumulate stats, these are clear-on-read */
+	phy->mib.dl_cck_cnt += le32_to_cpu(mu_stats->dl.cck_cnt);
+	phy->mib.dl_ofdm_cnt += le32_to_cpu(mu_stats->dl.ofdm_cnt);
+	phy->mib.dl_htmix_cnt += le32_to_cpu(mu_stats->dl.htmix_cnt);
+	phy->mib.dl_htgf_cnt += le32_to_cpu(mu_stats->dl.htgf_cnt);
+	phy->mib.dl_vht_su_cnt += le32_to_cpu(mu_stats->dl.vht_su_cnt);
+	phy->mib.dl_vht_2mu_cnt += le32_to_cpu(mu_stats->dl.vht_2mu_cnt);
+	phy->mib.dl_vht_3mu_cnt += le32_to_cpu(mu_stats->dl.vht_3mu_cnt);
+	phy->mib.dl_vht_4mu_cnt += le32_to_cpu(mu_stats->dl.vht_4mu_cnt);
+	phy->mib.dl_he_su_cnt += le32_to_cpu(mu_stats->dl.he_su_cnt);
+	phy->mib.dl_he_2ru_cnt += le32_to_cpu(mu_stats->dl.he_2ru_cnt);
+	phy->mib.dl_he_2mu_cnt += le32_to_cpu(mu_stats->dl.he_2mu_cnt);
+	phy->mib.dl_he_3ru_cnt += le32_to_cpu(mu_stats->dl.he_3ru_cnt);
+	phy->mib.dl_he_3mu_cnt += le32_to_cpu(mu_stats->dl.he_3mu_cnt);
+	phy->mib.dl_he_4ru_cnt += le32_to_cpu(mu_stats->dl.he_4ru_cnt);
+	phy->mib.dl_he_4mu_cnt += le32_to_cpu(mu_stats->dl.he_4mu_cnt);
+	phy->mib.dl_he_5to8ru_cnt += le32_to_cpu(mu_stats->dl.he_5to8ru_cnt);
+	phy->mib.dl_he_9to16ru_cnt += le32_to_cpu(mu_stats->dl.he_9to16ru_cnt);
+	phy->mib.dl_he_gtr16ru_cnt += le32_to_cpu(mu_stats->dl.he_gtr16ru_cnt);
+
+	phy->mib.ul_hetrig_su_cnt += le32_to_cpu(mu_stats->ul.hetrig_su_cnt);
+	phy->mib.ul_hetrig_2ru_cnt += le32_to_cpu(mu_stats->ul.hetrig_2ru_cnt);
+	phy->mib.ul_hetrig_3ru_cnt += le32_to_cpu(mu_stats->ul.hetrig_3ru_cnt);
+	phy->mib.ul_hetrig_4ru_cnt += le32_to_cpu(mu_stats->ul.hetrig_4ru_cnt);
+	phy->mib.ul_hetrig_5to8ru_cnt +=
+		le32_to_cpu(mu_stats->ul.hetrig_5to8ru_cnt);
+	phy->mib.ul_hetrig_9to16ru_cnt +=
+		le32_to_cpu(mu_stats->ul.hetrig_9to16ru_cnt);
+	phy->mib.ul_hetrig_gtr16ru_cnt +=
+		le32_to_cpu(mu_stats->ul.hetrig_gtr16ru_cnt);
+	phy->mib.ul_hetrig_2mu_cnt += le32_to_cpu(mu_stats->ul.hetrig_2mu_cnt);
+	phy->mib.ul_hetrig_3mu_cnt += le32_to_cpu(mu_stats->ul.hetrig_3mu_cnt);
+	phy->mib.ul_hetrig_4mu_cnt += le32_to_cpu(mu_stats->ul.hetrig_4mu_cnt);
 	dev_kfree_skb(skb);
 
 	return 0;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
index 145f89a19443..929d49792a01 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
@@ -216,6 +216,38 @@  struct mib_stats {
 
 	u32 tx_amsdu[8];
 	u32 tx_amsdu_cnt;
+
+	/* mcu_muru_stats */
+	u32 dl_cck_cnt;
+	u32 dl_ofdm_cnt;
+	u32 dl_htmix_cnt;
+	u32 dl_htgf_cnt;
+	u32 dl_vht_su_cnt;
+	u32 dl_vht_2mu_cnt;
+	u32 dl_vht_3mu_cnt;
+	u32 dl_vht_4mu_cnt;
+	u32 dl_he_su_cnt;
+	u32 dl_he_ext_su_cnt;
+	u32 dl_he_2ru_cnt;
+	u32 dl_he_2mu_cnt;
+	u32 dl_he_3ru_cnt;
+	u32 dl_he_3mu_cnt;
+	u32 dl_he_4ru_cnt;
+	u32 dl_he_4mu_cnt;
+	u32 dl_he_5to8ru_cnt;
+	u32 dl_he_9to16ru_cnt;
+	u32 dl_he_gtr16ru_cnt;
+
+	u32 ul_hetrig_su_cnt;
+	u32 ul_hetrig_2ru_cnt;
+	u32 ul_hetrig_3ru_cnt;
+	u32 ul_hetrig_4ru_cnt;
+	u32 ul_hetrig_5to8ru_cnt;
+	u32 ul_hetrig_9to16ru_cnt;
+	u32 ul_hetrig_gtr16ru_cnt;
+	u32 ul_hetrig_2mu_cnt;
+	u32 ul_hetrig_3mu_cnt;
+	u32 ul_hetrig_4mu_cnt;
 };
 
 /* crash-dump */
@@ -625,7 +657,7 @@  void mt7915_set_stream_he_caps(struct mt7915_phy *phy);
 void mt7915_set_stream_vht_txbf_caps(struct mt7915_phy *phy);
 void mt7915_update_channel(struct mt76_phy *mphy);
 int mt7915_mcu_muru_debug_set(struct mt7915_dev *dev, bool enable);
-int mt7915_mcu_muru_debug_get(struct mt7915_phy *phy, void *ms);
+int mt7915_mcu_muru_debug_get(struct mt7915_phy *phy);
 int mt7915_mcu_wed_enable_rx_stats(struct mt7915_dev *dev);
 int mt7915_init_debugfs(struct mt7915_phy *phy);
 void mt7915_debugfs_rx_fw_monitor(struct mt7915_dev *dev, const void *data, int len);