From patchwork Tue Mar 11 18:23:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 329195 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C35FC2C00C2 for ; Wed, 12 Mar 2014 05:29:33 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WNRQS-0003dA-L7; Tue, 11 Mar 2014 18:29:16 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WNRLb-0007dE-BJ; Tue, 11 Mar 2014 18:24:15 +0000 Received: from top.free-electrons.com ([176.31.233.9] helo=mail.free-electrons.com) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WNRLV-0007cY-8J for linux-mtd@lists.infradead.org; Tue, 11 Mar 2014 18:24:13 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id 4924181F; Tue, 11 Mar 2014 19:23:50 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.3.2 Received: from localhost.localdomain (unknown [190.2.108.71]) by mail.free-electrons.com (Postfix) with ESMTPA id 81AC061B; Tue, 11 Mar 2014 19:23:48 +0100 (CET) From: Ezequiel Garcia To: Subject: [PATCH] mtd: Add sysfs attr to expose ECC stats Date: Tue, 11 Mar 2014 15:23:15 -0300 Message-Id: <1394562195-16406-1-git-send-email-ezequiel.garcia@free-electrons.com> X-Mailer: git-send-email 1.9.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140311_142409_387531_669CF722 X-CRM114-Status: UNSURE ( 9.45 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Brian Norris , David Woodhouse , Ezequiel Garcia X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 --- 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(+) 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, };