From patchwork Tue Oct 21 13:53:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 39147 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EAE5B202DB for ; Tue, 21 Oct 2014 13:54:41 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id e51sf453100eek.2 for ; Tue, 21 Oct 2014 06:54:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=FulYa0khD10LoSeOF4biP7MXv81qa7seYUdGq0Lqi/8=; b=f8lEA/vWHJK5f3K+Jz9aXHJZkHQ9Q27swBNNDL3lRjZwpRq/HFTARIJTa7DFqCo7my +l64WX4PMY6wkELztzcSjYnEqGblua0+2+nQ3aVH5KJg/4rZ8UUgMOZ5Af0W01SmEuny Hvaz79dLNlMB8Mov9okKPnO7+oSe/lgwPxeLVWlhoiFJinhl1UJDQrynL7waFxjmpO+b 2GHFqd2AYmeSye7WQQVkLeHoY82cLzETkAw3YfJx9D5MMLMlES6xZXt1JMhDjGD2x29g gM5K6UYZLLhz/vE6/Kj7GzPrWM96sppH3e7mBjyBytiAYsOL84T9ROKPT+Go+KJAHEVv b8Dg== X-Gm-Message-State: ALoCoQmWyzMdUGeF0kBSZXyJAZCirPnB1MwGJOWOmjjb4AaX8fr1vKT2F2+cPbGTj3vEpGHlcFQ9 X-Received: by 10.194.241.232 with SMTP id wl8mr418866wjc.5.1413899680862; Tue, 21 Oct 2014 06:54:40 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.200 with SMTP id y8ls62106lal.93.gmail; Tue, 21 Oct 2014 06:54:40 -0700 (PDT) X-Received: by 10.112.225.225 with SMTP id rn1mr3440422lbc.98.1413899680667; Tue, 21 Oct 2014 06:54:40 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id yf4si19009760lbb.124.2014.10.21.06.54.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 21 Oct 2014 06:54:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by mail-lb0-f177.google.com with SMTP id w7so1039537lbi.8 for ; Tue, 21 Oct 2014 06:54:40 -0700 (PDT) X-Received: by 10.112.77.74 with SMTP id q10mr26405483lbw.66.1413899680433; Tue, 21 Oct 2014 06:54:40 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp501984lbz; Tue, 21 Oct 2014 06:54:39 -0700 (PDT) X-Received: by 10.66.120.176 with SMTP id ld16mr35683108pab.86.1413899678774; Tue, 21 Oct 2014 06:54:38 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ra10si11275816pab.86.2014.10.21.06.54.31 for ; Tue, 21 Oct 2014 06:54:38 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932829AbaJUNyQ (ORCPT + 27 others); Tue, 21 Oct 2014 09:54:16 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:56533 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932711AbaJUNyN (ORCPT ); Tue, 21 Oct 2014 09:54:13 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id s9LDroUb017984; Tue, 21 Oct 2014 08:53:50 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9LDro1Y001556; Tue, 21 Oct 2014 08:53:50 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Tue, 21 Oct 2014 08:53:49 -0500 Received: from localhost.localdomain (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9LDrgf4021645; Tue, 21 Oct 2014 08:53:47 -0500 From: Roger Quadros To: , CC: , , , Roger Quadros , Sekhar Nori Subject: [PATCH 2/2] mtd: mtd_oobtest: add bitflip_limit parameter Date: Tue, 21 Oct 2014 16:53:28 +0300 Message-ID: <1413899608-3911-3-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1413899608-3911-1-git-send-email-rogerq@ti.com> References: <1413899608-3911-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: rogerq@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , It is common for NAND devices to have bitflip errors. Add a bitflip_limit parameter to specify how many bitflips per page we can tolerate without flagging an error. By default zero bitflips are tolerated. Signed-off-by: Roger Quadros Signed-off-by: Sekhar Nori --- drivers/mtd/tests/oobtest.c | 65 ++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/drivers/mtd/tests/oobtest.c b/drivers/mtd/tests/oobtest.c index edd859d..1fd2cda 100644 --- a/drivers/mtd/tests/oobtest.c +++ b/drivers/mtd/tests/oobtest.c @@ -34,8 +34,11 @@ #include "mtd_test.h" static int dev = -EINVAL; +static int bitflip_limit; module_param(dev, int, S_IRUGO); MODULE_PARM_DESC(dev, "MTD device number to use"); +module_param(bitflip_limit, int, S_IRUGO); +MODULE_PARM_DESC(bitflip_limit, "Max. allowed bitflips per page"); static struct mtd_info *mtd; static unsigned char *readbuf; @@ -115,24 +118,27 @@ static int write_whole_device(void) return 0; } -/* Display the address, offset and data bytes at comparison failure */ -static int memcmpshow(loff_t addr, const void *cs, const void *ct, size_t count) +/* + * Display the address, offset and data bytes at comparison failure. + * Return number of bitflips encountered. + */ +static size_t memcmpshow(loff_t addr, const void *cs, const void *ct, size_t count) { const unsigned char *su1, *su2; int res; - int ret = 0; size_t i = 0; + size_t bitflips = 0; for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--, i++) { res = *su1 ^ *su2; if (res) { pr_info("error @addr[0x%lx:0x%x] 0x%x -> 0x%x diff 0x%x\n", (unsigned long)addr, i, *su1, *su2, res); - ret = 1; + bitflips += hweight8(res); } } - return ret; + return bitflips; } static int verify_eraseblock(int ebnum) @@ -141,6 +147,7 @@ static int verify_eraseblock(int ebnum) struct mtd_oob_ops ops; int err = 0; loff_t addr = (loff_t)ebnum * mtd->erasesize; + size_t bitflips; prandom_bytes_state(&rnd_state, writebuf, use_len_max * pgcnt); for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { @@ -159,9 +166,11 @@ static int verify_eraseblock(int ebnum) errcnt += 1; return err ? err : -1; } - if (memcmpshow(addr, readbuf, - writebuf + (use_len_max * i) + use_offset, - use_len)) { + + bitflips = memcmpshow(addr, readbuf, + writebuf + (use_len_max * i) + use_offset, + use_len); + if (bitflips > bitflip_limit) { pr_err("error: verify failed at %#llx\n", (long long)addr); errcnt += 1; @@ -169,7 +178,10 @@ static int verify_eraseblock(int ebnum) pr_err("error: too many errors\n"); return -1; } + } else if (bitflips) { + pr_info("ignoring error as within bitflip_limit\n"); } + if (use_offset != 0 || use_len < mtd->ecclayout->oobavail) { int k; @@ -188,9 +200,10 @@ static int verify_eraseblock(int ebnum) errcnt += 1; return err ? err : -1; } - if (memcmpshow(addr, readbuf + use_offset, - writebuf + (use_len_max * i) + use_offset, - use_len)) { + bitflips = memcmpshow(addr, readbuf + use_offset, + writebuf + (use_len_max * i) + use_offset, + use_len); + if (bitflips > bitflip_limit) { pr_err("error: verify failed at %#llx\n", (long long)addr); errcnt += 1; @@ -198,7 +211,10 @@ static int verify_eraseblock(int ebnum) pr_err("error: too many errors\n"); return -1; } + } else if (bitflips) { + pr_info("ignoring error as within bitflip_limit\n"); } + for (k = 0; k < use_offset; ++k) if (readbuf[k] != 0xff) { pr_err("error: verify 0xff " @@ -237,6 +253,9 @@ static int verify_eraseblock_in_one_go(int ebnum) int err = 0; loff_t addr = (loff_t)ebnum * mtd->erasesize; size_t len = mtd->ecclayout->oobavail * pgcnt; + size_t oobavail = mtd->ecclayout->oobavail; + size_t bitflips; + int i; prandom_bytes_state(&rnd_state, writebuf, len); ops.mode = MTD_OPS_AUTO_OOB; @@ -247,6 +266,8 @@ static int verify_eraseblock_in_one_go(int ebnum) ops.ooboffs = 0; ops.datbuf = NULL; ops.oobbuf = readbuf; + + /* read entire block's OOB at one go */ err = mtd_read_oob(mtd, addr, &ops); if (err || ops.oobretlen != len) { pr_err("error: readoob failed at %#llx\n", @@ -254,13 +275,21 @@ static int verify_eraseblock_in_one_go(int ebnum) errcnt += 1; return err ? err : -1; } - if (memcmpshow(addr, readbuf, writebuf, len)) { - pr_err("error: verify failed at %#llx\n", - (long long)addr); - errcnt += 1; - if (errcnt > 1000) { - pr_err("error: too many errors\n"); - return -1; + + /* verify one page OOB at a time for bitflip per page limit check */ + for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { + bitflips = memcmpshow(addr, readbuf + (i * oobavail), + writebuf + (i * oobavail), oobavail); + if (bitflips > bitflip_limit) { + pr_err("error: verify failed at %#llx\n", + (long long)addr); + errcnt += 1; + if (errcnt > 1000) { + pr_err("error: too many errors\n"); + return -1; + } + } else if (bitflips) { + pr_info("ignoring error as within bitflip_limit\n"); } }