diff mbox series

[v2] mt76: mt7915: dump SER stats through debugfs

Message ID fe715dbd6cd43651b50172acf58bb1eab66584da.1650857049.git.Bo.Jiao@mediatek.com
State New
Headers show
Series [v2] mt76: mt7915: dump SER stats through debugfs | expand

Commit Message

Bo Jiao April 25, 2022, 3:34 a.m. UTC
From: Ryder Lee <ryder.lee@mediatek.com>

Grab status of system recovery from firmware.

Signed-off-by: Bo Jiao <Bo.Jiao@mediatek.com>
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
---
v2:
 - merge fw_ser_stats into fw_ser
---
 .../wireless/mediatek/mt76/mt7915/debugfs.c   | 95 +++++++++++++++++--
 .../net/wireless/mediatek/mt76/mt7915/mcu.c   |  5 +-
 .../net/wireless/mediatek/mt76/mt7915/mmio.c  |  3 +
 .../net/wireless/mediatek/mt76/mt7915/regs.h  | 18 +++-
 4 files changed, 105 insertions(+), 16 deletions(-)

Comments

kernel test robot April 25, 2022, 12:50 p.m. UTC | #1
Hi Bo,

I love your patch! Perhaps something to improve:

[auto build test WARNING on wireless-next/main]
[also build test WARNING on wireless/main v5.18-rc4 next-20220422]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Bo-Jiao/mt76-mt7915-dump-SER-stats-through-debugfs/20220425-113739
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20220425/202204252050.kt1MHzwD-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 1cddcfdc3c683b393df1a5c9063252eb60e52818)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/3d98cf66e18c4da1c5ee68eb987c34598e959da4
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Bo-Jiao/mt76-mt7915-dump-SER-stats-through-debugfs/20220425-113739
        git checkout 3d98cf66e18c4da1c5ee68eb987c34598e959da4
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/net/wireless/mediatek/mt76/mt7915/ lib/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c:87:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
           default:
           ^
   drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c:87:2: note: insert 'break;' to avoid fall-through
           default:
           ^
           break; 
   1 warning generated.


vim +87 drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c

6d6dc980e07d1f8 Ryder Lee 2021-01-14  43  
6d6dc980e07d1f8 Ryder Lee 2021-01-14  44  DEFINE_DEBUGFS_ATTRIBUTE(fops_implicit_txbf, mt7915_implicit_txbf_get,
6d6dc980e07d1f8 Ryder Lee 2021-01-14  45  			 mt7915_implicit_txbf_set, "%lld\n");
6d6dc980e07d1f8 Ryder Lee 2021-01-14  46  
e57b7901469fc0b Ryder Lee 2020-04-25  47  /* test knob of system layer 1/2 error recovery */
3d98cf66e18c4da Ryder Lee 2022-04-25  48  static ssize_t mt7915_fw_ser_set(struct file *file,
3d98cf66e18c4da Ryder Lee 2022-04-25  49  				 const char __user *user_buf,
3d98cf66e18c4da Ryder Lee 2022-04-25  50  				 size_t count, loff_t *ppos)
e57b7901469fc0b Ryder Lee 2020-04-25  51  {
e57b7901469fc0b Ryder Lee 2020-04-25  52  	enum {
3d98cf66e18c4da Ryder Lee 2022-04-25  53  		SER_QUERY = 0,
e57b7901469fc0b Ryder Lee 2020-04-25  54  		SER_SET_RECOVER_L1 = 1,
e57b7901469fc0b Ryder Lee 2020-04-25  55  		SER_SET_RECOVER_L2,
e57b7901469fc0b Ryder Lee 2020-04-25  56  		SER_ENABLE = 2,
e57b7901469fc0b Ryder Lee 2020-04-25  57  		SER_RECOVER
e57b7901469fc0b Ryder Lee 2020-04-25  58  	};
3d98cf66e18c4da Ryder Lee 2022-04-25  59  	struct mt7915_dev *dev = file->private_data;
3d98cf66e18c4da Ryder Lee 2022-04-25  60  	char buf[16];
3d98cf66e18c4da Ryder Lee 2022-04-25  61  	u16 val;
3d98cf66e18c4da Ryder Lee 2022-04-25  62  
3d98cf66e18c4da Ryder Lee 2022-04-25  63  	if (count >= sizeof(buf))
3d98cf66e18c4da Ryder Lee 2022-04-25  64  		return -EINVAL;
3d98cf66e18c4da Ryder Lee 2022-04-25  65  
3d98cf66e18c4da Ryder Lee 2022-04-25  66  	if (copy_from_user(buf, user_buf, count))
3d98cf66e18c4da Ryder Lee 2022-04-25  67  		return -EFAULT;
3d98cf66e18c4da Ryder Lee 2022-04-25  68  
3d98cf66e18c4da Ryder Lee 2022-04-25  69  	if (count && buf[count - 1] == '\n')
3d98cf66e18c4da Ryder Lee 2022-04-25  70  		buf[count - 1] = '\0';
3d98cf66e18c4da Ryder Lee 2022-04-25  71  	else
3d98cf66e18c4da Ryder Lee 2022-04-25  72  		buf[count] = '\0';
3d98cf66e18c4da Ryder Lee 2022-04-25  73  
3d98cf66e18c4da Ryder Lee 2022-04-25  74  	if (kstrtou16(buf, 0, &val))
3d98cf66e18c4da Ryder Lee 2022-04-25  75  		return -EINVAL;
e57b7901469fc0b Ryder Lee 2020-04-25  76  
e57b7901469fc0b Ryder Lee 2020-04-25  77  	switch (val) {
3d98cf66e18c4da Ryder Lee 2022-04-25  78  	case SER_QUERY:
3d98cf66e18c4da Ryder Lee 2022-04-25  79  		/* grab firmware SER stats */
3d98cf66e18c4da Ryder Lee 2022-04-25  80  		mt7915_mcu_set_ser(dev, 0, 0, 0);
3d98cf66e18c4da Ryder Lee 2022-04-25  81  		break;
e57b7901469fc0b Ryder Lee 2020-04-25  82  	case SER_SET_RECOVER_L1:
e57b7901469fc0b Ryder Lee 2020-04-25  83  	case SER_SET_RECOVER_L2:
3d98cf66e18c4da Ryder Lee 2022-04-25  84  		mt7915_mcu_set_ser(dev, SER_ENABLE, BIT(val), 0);
e57b7901469fc0b Ryder Lee 2020-04-25  85  
3d98cf66e18c4da Ryder Lee 2022-04-25  86  		mt7915_mcu_set_ser(dev, SER_RECOVER, val, 0);
e57b7901469fc0b Ryder Lee 2020-04-25 @87  	default:
e57b7901469fc0b Ryder Lee 2020-04-25  88  		break;
e57b7901469fc0b Ryder Lee 2020-04-25  89  	}
e57b7901469fc0b Ryder Lee 2020-04-25  90  
3d98cf66e18c4da Ryder Lee 2022-04-25  91  	return count;
3d98cf66e18c4da Ryder Lee 2022-04-25  92  }
3d98cf66e18c4da Ryder Lee 2022-04-25  93
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 dece0a6..cbfed7e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
@@ -45,34 +45,109 @@  DEFINE_DEBUGFS_ATTRIBUTE(fops_implicit_txbf, mt7915_implicit_txbf_get,
 			 mt7915_implicit_txbf_set, "%lld\n");
 
 /* test knob of system layer 1/2 error recovery */
-static int mt7915_ser_trigger_set(void *data, u64 val)
+static ssize_t mt7915_fw_ser_set(struct file *file,
+				 const char __user *user_buf,
+				 size_t count, loff_t *ppos)
 {
 	enum {
+		SER_QUERY = 0,
 		SER_SET_RECOVER_L1 = 1,
 		SER_SET_RECOVER_L2,
 		SER_ENABLE = 2,
 		SER_RECOVER
 	};
-	struct mt7915_dev *dev = data;
-	int ret = 0;
+	struct mt7915_dev *dev = file->private_data;
+	char buf[16];
+	u16 val;
+
+	if (count >= sizeof(buf))
+		return -EINVAL;
+
+	if (copy_from_user(buf, user_buf, count))
+		return -EFAULT;
+
+	if (count && buf[count - 1] == '\n')
+		buf[count - 1] = '\0';
+	else
+		buf[count] = '\0';
+
+	if (kstrtou16(buf, 0, &val))
+		return -EINVAL;
 
 	switch (val) {
+	case SER_QUERY:
+		/* grab firmware SER stats */
+		mt7915_mcu_set_ser(dev, 0, 0, 0);
+		break;
 	case SER_SET_RECOVER_L1:
 	case SER_SET_RECOVER_L2:
-		ret = mt7915_mcu_set_ser(dev, SER_ENABLE, BIT(val), 0);
-		if (ret)
-			return ret;
+		mt7915_mcu_set_ser(dev, SER_ENABLE, BIT(val), 0);
 
-		return mt7915_mcu_set_ser(dev, SER_RECOVER, val, 0);
+		mt7915_mcu_set_ser(dev, SER_RECOVER, val, 0);
 	default:
 		break;
 	}
 
+	return count;
+}
+
+static ssize_t
+mt7915_fw_ser_get(struct file *file,
+		  char __user *user_buf,
+		  size_t count, loff_t *ppos)
+{
+	struct mt7915_dev *dev = file->private_data;
+	char *buff;
+	int desc = 0;
+	ssize_t ret;
+	static const size_t bufsz = 400;
+
+	buff = kmalloc(bufsz, GFP_KERNEL);
+	if (!buff)
+		return -ENOMEM;
+
+	desc += scnprintf(buff + desc, bufsz - desc,
+			  "::E  R , SER_STATUS        = 0x%08x\n",
+			  mt76_rr(dev, MT_SWDEF_SER_STATS));
+	desc += scnprintf(buff + desc, bufsz - desc,
+			  "::E  R , SER_PLE_ERR       = 0x%08x\n",
+			  mt76_rr(dev, MT_SWDEF_PLE_STATS));
+	desc += scnprintf(buff + desc, bufsz - desc,
+			  "::E  R , SER_PLE_ERR_1     = 0x%08x\n",
+			  mt76_rr(dev, MT_SWDEF_PLE1_STATS));
+	desc += scnprintf(buff + desc, bufsz - desc,
+			  "::E  R , SER_PLE_ERR_AMSDU = 0x%08x\n",
+			  mt76_rr(dev, MT_SWDEF_PLE_AMSDU_STATS));
+	desc += scnprintf(buff + desc, bufsz - desc,
+			  "::E  R , SER_PSE_ERR       = 0x%08x\n",
+			  mt76_rr(dev, MT_SWDEF_PSE_STATS));
+	desc += scnprintf(buff + desc, bufsz - desc,
+			  "::E  R , SER_PSE_ERR_1     = 0x%08x\n",
+			  mt76_rr(dev, MT_SWDEF_PSE1_STATS));
+	desc += scnprintf(buff + desc, bufsz - desc,
+			  "::E  R , SER_LMAC_WISR6_B0 = 0x%08x\n",
+			  mt76_rr(dev, MT_SWDEF_LAMC_WISR6_BN0_STATS));
+	desc += scnprintf(buff + desc, bufsz - desc,
+			  "::E  R , SER_LMAC_WISR6_B1 = 0x%08x\n",
+			  mt76_rr(dev, MT_SWDEF_LAMC_WISR6_BN1_STATS));
+	desc += scnprintf(buff + desc, bufsz - desc,
+			  "::E  R , SER_LMAC_WISR7_B0 = 0x%08x\n",
+			  mt76_rr(dev, MT_SWDEF_LAMC_WISR7_BN0_STATS));
+	desc += scnprintf(buff + desc, bufsz - desc,
+			  "::E  R , SER_LMAC_WISR7_B1 = 0x%08x\n",
+			  mt76_rr(dev, MT_SWDEF_LAMC_WISR7_BN1_STATS));
+
+	ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
+	kfree(buff);
 	return ret;
 }
 
-DEFINE_DEBUGFS_ATTRIBUTE(fops_ser_trigger, NULL,
-			 mt7915_ser_trigger_set, "%lld\n");
+static const struct file_operations mt7915_fw_ser_ops = {
+	.write = mt7915_fw_ser_set,
+	.read = mt7915_fw_ser_get,
+	.open = simple_open,
+	.llseek = default_llseek,
+};
 
 static int
 mt7915_radar_trigger(void *data, u64 val)
@@ -884,6 +959,7 @@  int mt7915_init_debugfs(struct mt7915_phy *phy)
 	debugfs_create_file("xmit-queues", 0400, dir, phy,
 			    &mt7915_xmit_queues_fops);
 	debugfs_create_file("tx_stats", 0400, dir, phy, &mt7915_tx_stats_fops);
+	debugfs_create_file("fw_ser", 0600, dir, dev, &mt7915_fw_ser_ops);
 	debugfs_create_file("fw_debug_wm", 0600, dir, dev, &fops_fw_debug_wm);
 	debugfs_create_file("fw_debug_wa", 0600, dir, dev, &fops_fw_debug_wa);
 	debugfs_create_file("fw_debug_bin", 0600, dir, dev, &fops_fw_debug_bin);
@@ -897,7 +973,6 @@  int mt7915_init_debugfs(struct mt7915_phy *phy)
 			    &mt7915_rate_txpower_fops);
 	debugfs_create_devm_seqfile(dev->mt76.dev, "twt_stats", dir,
 				    mt7915_twt_stats);
-	debugfs_create_file("ser_trigger", 0200, dir, dev, &fops_ser_trigger);
 	if (!dev->dbdc_support || phy->band_idx) {
 		debugfs_create_u32("dfs_hw_pattern", 0400, dir,
 				   &dev->hw_pattern);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
index ee2956c..d4af707 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
@@ -2471,10 +2471,7 @@  int mt7915_mcu_init(struct mt7915_dev *dev)
 	/* force firmware operation mode into normal state,
 	 * which should be set before firmware download stage.
 	 */
-	if (is_mt7915(&dev->mt76))
-		mt76_wr(dev, MT_SWDEF_MODE, MT_SWDEF_NORMAL_MODE);
-	else
-		mt76_wr(dev, MT_SWDEF_MODE_MT7916, MT_SWDEF_NORMAL_MODE);
+	mt76_wr(dev, MT_SWDEF_MODE, MT_SWDEF_NORMAL_MODE);
 
 	ret = mt7915_driver_own(dev, 0);
 	if (ret)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c b/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
index 89ea285..cd4dfd2 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
@@ -22,6 +22,7 @@  static const u32 mt7915_reg[] = {
 	[WFDMA_EXT_CSR_ADDR]	= 0xd7000,
 	[CBTOP1_PHY_END]	= 0x77ffffff,
 	[INFRA_MCU_ADDR_END]	= 0x7c3fffff,
+	[SWDEF_BASE_ADDR]	= 0x41f200,
 };
 
 static const u32 mt7916_reg[] = {
@@ -36,6 +37,7 @@  static const u32 mt7916_reg[] = {
 	[WFDMA_EXT_CSR_ADDR]	= 0xd7000,
 	[CBTOP1_PHY_END]	= 0x7fffffff,
 	[INFRA_MCU_ADDR_END]	= 0x7c085fff,
+	[SWDEF_BASE_ADDR]	= 0x411400,
 };
 
 static const u32 mt7986_reg[] = {
@@ -50,6 +52,7 @@  static const u32 mt7986_reg[] = {
 	[WFDMA_EXT_CSR_ADDR]	= 0x27000,
 	[CBTOP1_PHY_END]	= 0x7fffffff,
 	[INFRA_MCU_ADDR_END]	= 0x7c085fff,
+	[SWDEF_BASE_ADDR]	= 0x411400,
 };
 
 static const u32 mt7915_offs[] = {
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/regs.h b/drivers/net/wireless/mediatek/mt76/mt7915/regs.h
index bb0dec8..8e77c28 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/regs.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/regs.h
@@ -30,6 +30,7 @@  enum reg_rev {
 	WFDMA_EXT_CSR_ADDR,
 	CBTOP1_PHY_END,
 	INFRA_MCU_ADDR_END,
+	SWDEF_BASE_ADDR,
 	__MT_REG_MAX,
 };
 
@@ -929,12 +930,25 @@  enum offs_rev {
 #define MT_ADIE_TYPE_MASK		BIT(1)
 
 /* FW MODE SYNC */
-#define MT_SWDEF_MODE			0x41f23c
-#define MT_SWDEF_MODE_MT7916		0x41143c
+#define MT_SWDEF_BASE			__REG(SWDEF_BASE_ADDR)
+
+#define MT_SWDEF(ofs)			(MT_SWDEF_BASE + (ofs))
+#define MT_SWDEF_MODE			MT_SWDEF(0x3c)
 #define MT_SWDEF_NORMAL_MODE		0
 #define MT_SWDEF_ICAP_MODE		1
 #define MT_SWDEF_SPECTRUM_MODE		2
 
+#define MT_SWDEF_SER_STATS		MT_SWDEF(0x040)
+#define MT_SWDEF_PLE_STATS		MT_SWDEF(0x044)
+#define MT_SWDEF_PLE1_STATS		MT_SWDEF(0x048)
+#define MT_SWDEF_PLE_AMSDU_STATS	MT_SWDEF(0x04C)
+#define MT_SWDEF_PSE_STATS		MT_SWDEF(0x050)
+#define MT_SWDEF_PSE1_STATS		MT_SWDEF(0x054)
+#define MT_SWDEF_LAMC_WISR6_BN0_STATS	MT_SWDEF(0x058)
+#define MT_SWDEF_LAMC_WISR6_BN1_STATS	MT_SWDEF(0x05C)
+#define MT_SWDEF_LAMC_WISR7_BN0_STATS	MT_SWDEF(0x060)
+#define MT_SWDEF_LAMC_WISR7_BN1_STATS	MT_SWDEF(0x064)
+
 #define MT_DIC_CMD_REG_BASE		0x41f000
 #define MT_DIC_CMD_REG(ofs)		(MT_DIC_CMD_REG_BASE + (ofs))
 #define MT_DIC_CMD_REG_CMD		MT_DIC_CMD_REG(0x10)