From patchwork Fri May 12 15:34:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Gonzalez X-Patchwork-Id: 761700 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wPZKS56tqz9s3w for ; Sat, 13 May 2017 01:54:20 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NZnDSpGr"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="f2urPEH/"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XJsM7Nw8r4y+AyLfDnQKcJynQtRq7p7UfjBi2d11nMs=; b=NZnDSpGrngcDP2 8t6slkrjMQCLI68CBhFGRLg8/Fl33FPYi6GiJQH6qmQSPenQZ4BdNhfrhDdb99j45bKFc/jhXikw7 wDnQpbnAU/152u1XNacyfAvloujHGEuFOgmVpumtdeZUllsPPR2Ay3Ewy9nMasxWz4QFP4yAeIPF4 qKr4/akBL5TnrDy3RRnFVpGysZTe5o9AZk6BBEMPFVFYTLWcruEVkaEZbRbbcaD3YXj6xwSP+JgHf U4BLM46Cg3hEYU7aHY4HrkUyOG7fwjSfC0F90AKANphE564+I/OjZox2aiwFUXj5JRJ4WjxChXGDN ZvvzC0DHC/BJOujSpCcA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d9CtP-0006vI-Kv; Fri, 12 May 2017 15:54:11 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d9CmT-0004fv-2c for linux-mtd@bombadil.infradead.org; Fri, 12 May 2017 15:47:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:CC:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=oArCGMZ73MlIiMPS6zslp+HtJW4Gtu4WxD0ZpJYbkvc=; b=f2urPEH/GoEKpyXs/gUk+iBuDe OLOtj6qnwlNos0nVaU98Zfd05SGY8U9qHupvWGxW0CJuwom0AnqCi11zuXyj4JcokoVFtLzoWXOyc vR7QLZScM4aTp8ztt39QWgdGPmFy8pefc+dnnfz5P5cDzVDIUsGTQur30OeLsoXsx3L6PxZ1AjH7p wgWTdr9vINohQRJEEG1w6bC3PlqEr4kKVYUOKNq3xA77+X8ZmqxxLkQpoUXhRUibaMevoGCTMzNbQ aWHwB25zxB8/iuUcSDrH+Wfv9tQtmgoHraMaMGiebRUpAKjTHstiyV0DP2R+b8EjQUCAs/vSeWdir 9sfM6exg==; Received: from us-smtp-delivery-212.mimecast.com ([63.128.21.212]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d9CbS-0007iy-Kl for linux-mtd@lists.infradead.org; Fri, 12 May 2017 15:35:41 +0000 Received: from CPH-EX1.SDESIGNS.COM (195-215-56-170-static.dk.customer.tdc.net [195.215.56.170]) (Using TLS) by us-smtp-1.mimecast.com with ESMTP id us-mta-28-U0_nFG1kNMyJ4Mn5MwoiOQ-1; Fri, 12 May 2017 11:34:05 -0400 Received: from [172.27.0.114] (172.27.0.114) by CPH-EX1.sdesigns.com (192.168.10.36) with Microsoft SMTP Server (TLS) id 14.3.294.0; Fri, 12 May 2017 17:34:02 +0200 Subject: [PATCH] mtd: nand: tango: Update ecc_stats.corrected To: Boris Brezillon , Pavel Machek References: <20170419121332.GA26979@amd> <20170419231804.5a04ed69@bbrezillon> <20170421100813.GA4332@amd> <20170421133721.GA15332@amd> <20170421154903.2782cd06@bbrezillon> <20170422104033.GA14508@amd> <53204f36-9662-e8a0-c431-09fb68276ab6@sigmadesigns.com> <20170503200427.GC17315@amd> <20170504104216.0969423f@bbrezillon> From: Marc Gonzalez Message-ID: Date: Fri, 12 May 2017 17:34:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49 MIME-Version: 1.0 In-Reply-To: <20170504104216.0969423f@bbrezillon> X-Originating-IP: [172.27.0.114] X-MC-Unique: U0_nFG1kNMyJ4Mn5MwoiOQ-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170512_163538_840603_38CFBA80 X-CRM114-Status: GOOD ( 12.49 ) X-Spam-Score: -3.4 (---) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-3.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [63.128.21.212 listed in list.dnswl.org] 0.8 SPF_NEUTRAL SPF: sender does not match SPF record (neutral) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , Brian Norris , linux-mtd , David Woodhouse , Mason Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org According to Boris, some user-space tools expect MTD drivers to update ecc_stats.corrected, and it's better to provide a lower bound than to provide no information at all. Reported-by: Pavel Machek Signed-off-by: Marc Gonzalez --- NB: this patch is based on 4.9; if it looks good, I'll rebase it on v4.12-rc1 next week. --- drivers/mtd/nand/tango_nand.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/tango_nand.c b/drivers/mtd/nand/tango_nand.c index 4a5e948c62df..471348462e42 100644 --- a/drivers/mtd/nand/tango_nand.c +++ b/drivers/mtd/nand/tango_nand.c @@ -55,10 +55,10 @@ * byte 1 for other packets in the page (PKT_N, for N > 0) * ERR_COUNT_PKT_N is the max error count over all but the first packet. */ -#define DECODE_OK_PKT_0(v) ((v) & BIT(7)) -#define DECODE_OK_PKT_N(v) ((v) & BIT(15)) #define ERR_COUNT_PKT_0(v) (((v) >> 0) & 0x3f) #define ERR_COUNT_PKT_N(v) (((v) >> 8) & 0x3f) +#define DECODE_FAIL_PKT_0(v) (((v) & BIT(7)) == 0) +#define DECODE_FAIL_PKT_N(v) (((v) & BIT(15)) == 0) /* Offsets relative to pbus_base */ #define PBUS_CS_CTRL 0x83c @@ -193,6 +193,8 @@ static int check_erased_page(struct nand_chip *chip, u8 *buf) chip->ecc.strength); if (res < 0) mtd->ecc_stats.failed++; + else + mtd->ecc_stats.corrected += res; bitflips = max(res, bitflips); buf += pkt_size; @@ -202,9 +204,10 @@ static int check_erased_page(struct nand_chip *chip, u8 *buf) return bitflips; } -static int decode_error_report(struct tango_nfc *nfc) +static int decode_error_report(struct nand_chip *chip, struct tango_nfc *nfc) { u32 status, res; + struct mtd_info *mtd = nand_to_mtd(chip); status = readl_relaxed(nfc->reg_base + NFC_XFER_STATUS); if (status & PAGE_IS_EMPTY) @@ -212,10 +215,14 @@ static int decode_error_report(struct tango_nfc *nfc) res = readl_relaxed(nfc->mem_base + ERROR_REPORT); - if (DECODE_OK_PKT_0(res) && DECODE_OK_PKT_N(res)) - return max(ERR_COUNT_PKT_0(res), ERR_COUNT_PKT_N(res)); + if (DECODE_FAIL_PKT_0(res) || DECODE_FAIL_PKT_N(res)) + return -EBADMSG; + + /* ERR_COUNT_PKT_N is max, not sum, but that's all we have */ + mtd->ecc_stats.corrected += + ERR_COUNT_PKT_0(res) + ERR_COUNT_PKT_N(res); - return -EBADMSG; + return max(ERR_COUNT_PKT_0(res), ERR_COUNT_PKT_N(res)); } static void tango_dma_callback(void *arg) @@ -280,7 +287,7 @@ static int tango_read_page(struct mtd_info *mtd, struct nand_chip *chip, if (err) return err; - res = decode_error_report(nfc); + res = decode_error_report(chip, nfc); if (res < 0) { chip->ecc.read_oob_raw(mtd, chip, page); res = check_erased_page(chip, buf);