blob: 3707c519e7f3a38510866deff252dc9c399eb5ae [file] [log] [blame]
From 5cdb0e4160589abdd04c2a5bdc3bad935e7dbf32 Mon Sep 17 00:00:00 2001
From: Peter Chiu <chui-hao.chiu@mediatek.com>
Date: Mon, 30 Jan 2023 11:36:32 +0800
Subject: [PATCH 3014/3015] wifi: mt76: update debugfs knob for reset counter
and get tx packet error rate
---
mt7915/mtk_debugfs.c | 62 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c
index 5e64fe91..dbbf7ecc 100644
--- a/mt7915/mtk_debugfs.c
+++ b/mt7915/mtk_debugfs.c
@@ -3190,6 +3190,66 @@ mt7915_sw_aci_set(void *data, u64 val)
DEFINE_DEBUGFS_ATTRIBUTE(fops_sw_aci, NULL,
mt7915_sw_aci_set, "%llx\n");
+static int mt7915_reset_counter(void *data, u64 val)
+{
+ struct mt7915_phy *phy = data;
+ struct mt7915_dev *dev = phy->dev;
+ struct mt76_wcid *wcid;
+
+ /* Clear the firmware counters */
+ mt7915_mcu_get_tx_stat_wa(dev, dev->wlan_idx);
+ mt7915_get_tx_stat(phy, dev->wlan_idx);
+
+ rcu_read_lock();
+ wcid = rcu_dereference(dev->mt76.wcid[dev->wlan_idx]);
+ if (!wcid)
+ return -EINVAL;
+
+ memset(&wcid->stats, 0, sizeof(struct mt76_sta_stats));
+
+ rcu_read_unlock();
+
+ return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_reset_counter, NULL,
+ mt7915_reset_counter, "%lld\n");
+
+static int
+mt7915_per_read(struct seq_file *s, void *data)
+{
+ struct mt7915_dev *dev = dev_get_drvdata(s->private);
+ struct mt76_sta_stats *stats;
+ struct mt76_wcid *wcid;
+ int ret;
+ u8 phy_idx;
+
+ if (!dev->mt76.wcid[dev->wlan_idx])
+ return -EINVAL;
+
+ phy_idx = dev->mt76.wcid[dev->wlan_idx]->phy_idx;
+
+ ret = mt7915_get_tx_stat(dev->mt76.phys[phy_idx]->priv, dev->wlan_idx);
+ if (ret)
+ return ret;
+
+ rcu_read_lock();
+ wcid = rcu_dereference(dev->mt76.wcid[dev->wlan_idx]);
+ if (!wcid)
+ return -EINVAL;
+
+ stats = &wcid->stats;
+
+ seq_printf(s, "sta %d, tx_mpdu_cnt = %u, tx_failed = %u, PER = %u.%u%%\n", dev->wlan_idx,
+ stats->tx_mpdu_cnt, stats->tx_failed,
+ stats->tx_mpdu_cnt ? stats->tx_failed * 1000 / stats->tx_mpdu_cnt / 10 : 0,
+ stats->tx_mpdu_cnt ? stats->tx_failed * 1000 / stats->tx_mpdu_cnt % 10 : 0);
+
+ rcu_read_unlock();
+
+ return 0;
+}
+
int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
{
struct mt7915_dev *dev = phy->dev;
@@ -3279,6 +3339,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
mt7915_show_eeprom_mode);
debugfs_create_file("sw_aci", 0600, dir, dev,
&fops_sw_aci);
+ debugfs_create_file("reset_counter", 0200, dir, dev, &fops_reset_counter);
+ debugfs_create_devm_seqfile(dev->mt76.dev, "per", dir, mt7915_per_read);
return 0;
}
#endif
--
2.18.0