From patchwork Thu May 1 09:56:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 29467 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f72.google.com (mail-qa0-f72.google.com [209.85.216.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 050AD20B8D for ; Thu, 1 May 2014 09:57:58 +0000 (UTC) Received: by mail-qa0-f72.google.com with SMTP id hw13sf824182qab.11 for ; Thu, 01 May 2014 02:57:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=16KLZsQT0TImsZIwr6V5T7SKLnaKtv1IvxxSdqyXTnk=; b=AezjJ/qXKlC8hMRJ67+NWZYbcc+djUAv287e9UmN9t21/Hy3k/63qSSsWUgbQfiWUu 9IxWRkCcCOP+64jU5GNP6oZEQFC2yodKsq5dCD/Gk2GxaV75DMPcfQGI2o5OyoMUt4q7 fu5otsXPyFtK7E5M8Qwe7+hRQoKUywMPDWlvVp3cIY34J2QBu4RML3Wpoagi/eY4K7BG tARUUTLch/7T/O0B0arTukf5As7v5X14okodVDo5wWFINZI3Fgy55rbUucrUwa14VrxX SRAp11YnD/v6C8RYG3ebmSyOjCtkdSsN6SDJhW6nk1MaajpSpWC35FhS0T+RvxPZnn0l CxVA== X-Gm-Message-State: ALoCoQlyeQbNPodCXdUjSfqUflgUapPTCaG7swvRJzNHpJRn9YyR1EhNvppsLB87OebaW70cvkh3 X-Received: by 10.58.150.194 with SMTP id uk2mr2119973veb.0.1398938278778; Thu, 01 May 2014 02:57:58 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.21.203 with SMTP id 69ls1002463qgl.35.gmail; Thu, 01 May 2014 02:57:58 -0700 (PDT) X-Received: by 10.221.27.8 with SMTP id ro8mr470068vcb.30.1398938278660; Thu, 01 May 2014 02:57:58 -0700 (PDT) Received: from mail-ve0-f170.google.com (mail-ve0-f170.google.com [209.85.128.170]) by mx.google.com with ESMTPS id dq1si5968711vcb.149.2014.05.01.02.57.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:58 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.170; Received: by mail-ve0-f170.google.com with SMTP id sa20so3694247veb.1 for ; Thu, 01 May 2014 02:57:58 -0700 (PDT) X-Received: by 10.52.228.134 with SMTP id si6mr2098705vdc.5.1398938278596; Thu, 01 May 2014 02:57:58 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp12939vcb; Thu, 1 May 2014 02:57:58 -0700 (PDT) X-Received: by 10.194.92.81 with SMTP id ck17mr8405469wjb.14.1398938277806; Thu, 01 May 2014 02:57:57 -0700 (PDT) Received: from mail-we0-f178.google.com (mail-we0-f178.google.com [74.125.82.178]) by mx.google.com with ESMTPS id we6si10542609wjb.78.2014.05.01.02.57.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:57 -0700 (PDT) Received-SPF: none (google.com: lee.jones@linaro.org does not designate permitted sender hosts) client-ip=74.125.82.178; Received: by mail-we0-f178.google.com with SMTP id u56so1978367wes.37 for ; Thu, 01 May 2014 02:57:57 -0700 (PDT) X-Received: by 10.194.1.242 with SMTP id 18mr8394689wjp.22.1398938277298; Thu, 01 May 2014 02:57:57 -0700 (PDT) Received: from lee--X1.home (host109-148-238-223.range109-148.btcentralplus.com. [109.148.238.223]) by mx.google.com with ESMTPSA id bj5sm2696494wib.3.2014.05.01.02.57.55 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:56 -0700 (PDT) From: Lee Jones To: linux-kernel@vger.kernel.org Cc: computersforpeace@gmail.com, linux-mtd@lists.infradead.org, kernel@stlinux.com, Lee Jones Subject: [PATCH 24/47] mtd: nand: stm_nand_bch: check erased page for zeros Date: Thu, 1 May 2014 10:56:31 +0100 Message-Id: <1398938214-17847-25-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1398938214-17847-1-git-send-email-lee.jones@linaro.org> References: <1398938214-17847-1-git-send-email-lee.jones@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Detect an erased page, tolerating and correcting up to a specified number of bits at '0'. Downgrade uncorrectable ECC error for an erased page, tolerating 'sectors_per_page' bits at '0'. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 6d7ab79..2ff72c9 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -486,6 +486,33 @@ static uint8_t bch_erase_block(struct nandi_controller *nandi, } /* + * Detect an erased page, tolerating and correcting up to a specified number of + * bits at '0'. (For many devices, it is now deemed within spec for an erased + * page to include a number of bits at '0', either as a result of read-disturb + * behaviour or 'stuck-at-zero' failures.) Returns the number of corrected + * bits, or a '-1' if we have exceeded the maximum number of bits at '0' (likely + * to be a genuine uncorrectable ECC error). In the latter case, the data must + * be returned unmodified, in accordance with the MTD API. + */ +static int check_erased_page(uint8_t *data, uint32_t page_size, int max_zeros) +{ + uint8_t *b = data; + int zeros = 0; + int i; + + for (i = 0; i < page_size; i++) { + zeros += hweight8(~*b++); + if (zeros > max_zeros) + return -1; + } + + if (zeros) + memset(data, 0xff, page_size); + + return zeros; +} + +/* * Initialisation */ static int bch_check_compatibility(struct nandi_controller *nandi,