diff mbox series

scsi: ufs-debugfs: Add error counters

Message ID 20201216133818.25935-1-adrian.hunter@intel.com
State New
Headers show
Series scsi: ufs-debugfs: Add error counters | expand

Commit Message

Adrian Hunter Dec. 16, 2020, 1:38 p.m. UTC
People testing have a need to know how many errors might be occurring
over time. Add error counters and expose them via debugfs.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 drivers/scsi/ufs/Makefile      |  1 +
 drivers/scsi/ufs/ufs-debugfs.c | 55 ++++++++++++++++++++++++++++++++++
 drivers/scsi/ufs/ufs-debugfs.h | 22 ++++++++++++++
 drivers/scsi/ufs/ufshcd.c      | 19 ++++++++++++
 drivers/scsi/ufs/ufshcd.h      |  5 ++++
 5 files changed, 102 insertions(+)
 create mode 100644 drivers/scsi/ufs/ufs-debugfs.c
 create mode 100644 drivers/scsi/ufs/ufs-debugfs.h

Comments

kernel test robot Dec. 16, 2020, 4:47 p.m. UTC | #1
Hi Adrian,

I love your patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on scsi/for-next next-20201215]
[cannot apply to v5.10]
[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/0day-ci/linux/commits/Adrian-Hunter/scsi-ufs-debugfs-Add-error-counters/20201216-222801
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: x86_64-randconfig-s021-20201216 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.3-184-g1b896707-dirty
        # https://github.com/0day-ci/linux/commit/d62bfd1751cd091c2ae671208b026c6885b8184e
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Adrian-Hunter/scsi-ufs-debugfs-Add-error-counters/20201216-222801
        git checkout d62bfd1751cd091c2ae671208b026c6885b8184e
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64 

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/scsi/ufs/ufs-debugfs.c:10:6: warning: no previous prototype for 'ufs_debugfs_init' [-Wmissing-prototypes]
      10 | void ufs_debugfs_init(void)
         |      ^~~~~~~~~~~~~~~~
>> drivers/scsi/ufs/ufs-debugfs.c:15:6: warning: no previous prototype for 'ufs_debugfs_exit' [-Wmissing-prototypes]
      15 | void ufs_debugfs_exit(void)
         |      ^~~~~~~~~~~~~~~~
>> drivers/scsi/ufs/ufs-debugfs.c:46:6: warning: no previous prototype for 'ufs_debugfs_hba_init' [-Wmissing-prototypes]
      46 | void ufs_debugfs_hba_init(struct ufs_hba *hba)
         |      ^~~~~~~~~~~~~~~~~~~~
>> drivers/scsi/ufs/ufs-debugfs.c:52:6: warning: no previous prototype for 'ufs_debugfs_hba_exit' [-Wmissing-prototypes]
      52 | void ufs_debugfs_hba_exit(struct ufs_hba *hba)
         |      ^~~~~~~~~~~~~~~~~~~~


vim +/ufs_debugfs_init +10 drivers/scsi/ufs/ufs-debugfs.c

     9	
  > 10	void ufs_debugfs_init(void)
    11	{
    12		ufs_debugfs_root = debugfs_create_dir("ufshcd", NULL);
    13	}
    14	
  > 15	void ufs_debugfs_exit(void)
    16	{
    17		debugfs_remove_recursive(ufs_debugfs_root);
    18	}
    19	
    20	static int ufs_debugfs_stats_show(struct seq_file *s, void *data)
    21	{
    22		struct ufs_hba *hba = s->private;
    23		struct ufs_event_hist *e = hba->ufs_stats.event;
    24	
    25	#define PRT(fmt, typ) \
    26		seq_printf(s, fmt, e[UFS_EVT_ ## typ].cnt)
    27	
    28		PRT("PHY Adapter Layer errors (except LINERESET): %llu\n", PA_ERR);
    29		PRT("Data Link Layer errors: %llu\n", DL_ERR);
    30		PRT("Network Layer errors: %llu\n", NL_ERR);
    31		PRT("Transport Layer errors: %llu\n", TL_ERR);
    32		PRT("Generic DME errors: %llu\n", DME_ERR);
    33		PRT("Auto-hibernate errors: %llu\n", AUTO_HIBERN8_ERR);
    34		PRT("IS Fatal errors (CEFES, SBFES, HCFES, DFES): %llu\n", FATAL_ERR);
    35		PRT("DME Link Startup errors: %llu\n", LINK_STARTUP_FAIL);
    36		PRT("PM Resume errors: %llu\n", RESUME_ERR);
    37		PRT("PM Suspend errors : %llu\n", SUSPEND_ERR);
    38		PRT("Logical Unit Resets: %llu\n", DEV_RESET);
    39		PRT("Host Resets: %llu\n", HOST_RESET);
    40		PRT("SCSI command aborts: %llu\n", ABORT);
    41	#undef PRT
    42		return 0;
    43	}
    44	DEFINE_SHOW_ATTRIBUTE(ufs_debugfs_stats);
    45	
  > 46	void ufs_debugfs_hba_init(struct ufs_hba *hba)
    47	{
    48		hba->debugfs_root = debugfs_create_dir(dev_name(hba->dev), ufs_debugfs_root);
    49		debugfs_create_file("stats", 0400, hba->debugfs_root, hba, &ufs_debugfs_stats_fops);
    50	}
    51	
  > 52	void ufs_debugfs_hba_exit(struct ufs_hba *hba)

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/scsi/ufs/Makefile b/drivers/scsi/ufs/Makefile
index 4679af1b564e..9ca32b1143cb 100644
--- a/drivers/scsi/ufs/Makefile
+++ b/drivers/scsi/ufs/Makefile
@@ -9,6 +9,7 @@  ufs_qcom-$(CONFIG_SCSI_UFS_CRYPTO) += ufs-qcom-ice.o
 obj-$(CONFIG_SCSI_UFS_EXYNOS) += ufs-exynos.o
 obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o
 ufshcd-core-y				+= ufshcd.o ufs-sysfs.o
+ufshcd-core-$(CONFIG_DEBUG_FS)		+= ufs-debugfs.o
 ufshcd-core-$(CONFIG_SCSI_UFS_BSG)	+= ufs_bsg.o
 ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO) += ufshcd-crypto.o
 obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o
diff --git a/drivers/scsi/ufs/ufs-debugfs.c b/drivers/scsi/ufs/ufs-debugfs.c
new file mode 100644
index 000000000000..cb765e2d6c21
--- /dev/null
+++ b/drivers/scsi/ufs/ufs-debugfs.c
@@ -0,0 +1,55 @@ 
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2020 Intel Corporation
+
+#include <linux/debugfs.h>
+
+#include "ufshcd.h"
+
+static struct dentry *ufs_debugfs_root;
+
+void ufs_debugfs_init(void)
+{
+	ufs_debugfs_root = debugfs_create_dir("ufshcd", NULL);
+}
+
+void ufs_debugfs_exit(void)
+{
+	debugfs_remove_recursive(ufs_debugfs_root);
+}
+
+static int ufs_debugfs_stats_show(struct seq_file *s, void *data)
+{
+	struct ufs_hba *hba = s->private;
+	struct ufs_event_hist *e = hba->ufs_stats.event;
+
+#define PRT(fmt, typ) \
+	seq_printf(s, fmt, e[UFS_EVT_ ## typ].cnt)
+
+	PRT("PHY Adapter Layer errors (except LINERESET): %llu\n", PA_ERR);
+	PRT("Data Link Layer errors: %llu\n", DL_ERR);
+	PRT("Network Layer errors: %llu\n", NL_ERR);
+	PRT("Transport Layer errors: %llu\n", TL_ERR);
+	PRT("Generic DME errors: %llu\n", DME_ERR);
+	PRT("Auto-hibernate errors: %llu\n", AUTO_HIBERN8_ERR);
+	PRT("IS Fatal errors (CEFES, SBFES, HCFES, DFES): %llu\n", FATAL_ERR);
+	PRT("DME Link Startup errors: %llu\n", LINK_STARTUP_FAIL);
+	PRT("PM Resume errors: %llu\n", RESUME_ERR);
+	PRT("PM Suspend errors : %llu\n", SUSPEND_ERR);
+	PRT("Logical Unit Resets: %llu\n", DEV_RESET);
+	PRT("Host Resets: %llu\n", HOST_RESET);
+	PRT("SCSI command aborts: %llu\n", ABORT);
+#undef PRT
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(ufs_debugfs_stats);
+
+void ufs_debugfs_hba_init(struct ufs_hba *hba)
+{
+	hba->debugfs_root = debugfs_create_dir(dev_name(hba->dev), ufs_debugfs_root);
+	debugfs_create_file("stats", 0400, hba->debugfs_root, hba, &ufs_debugfs_stats_fops);
+}
+
+void ufs_debugfs_hba_exit(struct ufs_hba *hba)
+{
+	debugfs_remove_recursive(hba->debugfs_root);
+}
diff --git a/drivers/scsi/ufs/ufs-debugfs.h b/drivers/scsi/ufs/ufs-debugfs.h
new file mode 100644
index 000000000000..d5e744c7bd2d
--- /dev/null
+++ b/drivers/scsi/ufs/ufs-debugfs.h
@@ -0,0 +1,22 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2020 Intel Corporation
+ */
+
+#ifndef __UFS_DEBUGFS_H__
+#define __UFS_DEBUGFS_H__
+
+struct ufs_hba;
+
+#ifdef CONFIG_DEBUG_FS
+void ufs_debugfs_init(void);
+void ufs_debugfs_exit(void);
+void ufs_debugfs_hba_init(struct ufs_hba *hba);
+void ufs_debugfs_hba_exit(struct ufs_hba *hba);
+#else
+static inline void ufs_debugfs_init(void) {}
+static inline void ufs_debugfs_exit(void) {}
+static inline void ufs_debugfs_hba_init(struct ufs_hba *hba) {}
+static inline void ufs_debugfs_hba_exit(struct ufs_hba *hba) {}
+#endif
+
+#endif
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 82ad31781bc9..d8a3cf0cd6d5 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -20,6 +20,7 @@ 
 #include "ufs_quirks.h"
 #include "unipro.h"
 #include "ufs-sysfs.h"
+#include "ufs-debugfs.h"
 #include "ufs_bsg.h"
 #include "ufshcd-crypto.h"
 #include <asm/unaligned.h>
@@ -4540,6 +4541,7 @@  void ufshcd_update_evt_hist(struct ufs_hba *hba, u32 id, u32 val)
 	e = &hba->ufs_stats.event[id];
 	e->val[e->pos] = val;
 	e->tstamp[e->pos] = ktime_get();
+	e->cnt += 1;
 	e->pos = (e->pos + 1) % UFS_EVENT_HIST_LENGTH;
 
 	ufshcd_vops_event_notify(hba, id, &val);
@@ -8334,6 +8336,8 @@  static int ufshcd_hba_init(struct ufs_hba *hba)
 	if (err)
 		goto out_disable_vreg;
 
+	ufs_debugfs_hba_init(hba);
+
 	hba->is_powered = true;
 	goto out;
 
@@ -8350,6 +8354,7 @@  static int ufshcd_hba_init(struct ufs_hba *hba)
 static void ufshcd_hba_exit(struct ufs_hba *hba)
 {
 	if (hba->is_powered) {
+		ufs_debugfs_hba_exit(hba);
 		ufshcd_variant_hba_exit(hba);
 		ufshcd_setup_vreg(hba, false);
 		ufshcd_suspend_clkscaling(hba);
@@ -9436,6 +9441,20 @@  int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
 }
 EXPORT_SYMBOL_GPL(ufshcd_init);
 
+static int __init ufshcd_core_init(void)
+{
+	ufs_debugfs_init();
+	return 0;
+}
+
+static void __exit ufshcd_core_exit(void)
+{
+	ufs_debugfs_exit();
+}
+
+module_init(ufshcd_core_init);
+module_exit(ufshcd_core_exit);
+
 MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
 MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
 MODULE_DESCRIPTION("Generic UFS host controller driver Core");
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index aa9ea3552323..8c51ce01517e 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -445,11 +445,13 @@  struct ufs_clk_scaling {
  * @pos: index to indicate cyclic buffer position
  * @reg: cyclic buffer for registers value
  * @tstamp: cyclic buffer for time stamp
+ * @cnt: error counter
  */
 struct ufs_event_hist {
 	int pos;
 	u32 val[UFS_EVENT_HIST_LENGTH];
 	ktime_t tstamp[UFS_EVENT_HIST_LENGTH];
+	unsigned long long cnt;
 };
 
 /**
@@ -817,6 +819,9 @@  struct ufs_hba {
 	u32 crypto_cfg_register;
 	struct blk_keyslot_manager ksm;
 #endif
+#ifdef CONFIG_DEBUG_FS
+	struct dentry *debugfs_root;
+#endif
 };
 
 /* Returns true if clocks can be gated. Otherwise false */