Patchwork mtd: Add sysfs attr to expose ECC stats

login
register
mail settings
Submitter Ezequiel Garcia
Date March 11, 2014, 6:23 p.m.
Message ID <1394562195-16406-1-git-send-email-ezequiel.garcia@free-electrons.com>
Download mbox | patch
Permalink /patch/329195/
State Superseded
Headers show

Comments

Ezequiel Garcia - March 11, 2014, 6:23 p.m.
This new sysfs device attribute allows to retrieve the ECC stats
by poking a sysfs file, which is much simpler than using the ioctl.

The output format is inspired in block device sysfs 'stat' file.
The ecc_stats struct fields are shown as ordered in the structure,
in a machine parseable format.

Here's a typical output showing 3 ECC-corrected and 8 bad blocks:
       3        0        8        0

Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
---
The above example seems to be wrong, as the 8 "bad" blocks are
actually the 8 "reserved" blocks for the BBT. As such, I expected
them to appear on the 4th column. Is this a bug?

This issue is completely independent from this patch, but I wanted
to mention it now, before my brain circular buffer forgets about it.

 drivers/mtd/mtdcore.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Patch

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 0a7d77e..db50a51 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -298,6 +298,19 @@  static ssize_t mtd_ecc_step_size_show(struct device *dev,
 }
 static DEVICE_ATTR(ecc_step_size, S_IRUGO, mtd_ecc_step_size_show, NULL);
 
+static ssize_t mtd_ecc_stats_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct mtd_info *mtd = dev_get_drvdata(dev);
+	struct mtd_ecc_stats *ecc_stats = &mtd->ecc_stats;
+
+	return snprintf(buf, PAGE_SIZE, "%8u %8u %8u %8u\n", ecc_stats->corrected,
+						ecc_stats->failed,
+						ecc_stats->badblocks,
+						ecc_stats->bbtblocks);
+}
+static DEVICE_ATTR(ecc_stats, S_IRUGO, mtd_ecc_stats_show, NULL);
+
 static struct attribute *mtd_attrs[] = {
 	&dev_attr_type.attr,
 	&dev_attr_flags.attr,
@@ -310,6 +323,7 @@  static struct attribute *mtd_attrs[] = {
 	&dev_attr_name.attr,
 	&dev_attr_ecc_strength.attr,
 	&dev_attr_ecc_step_size.attr,
+	&dev_attr_ecc_stats.attr,
 	&dev_attr_bitflip_threshold.attr,
 	NULL,
 };