From patchwork Tue Mar 25 08:19:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 27016 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f70.google.com (mail-qg0-f70.google.com [209.85.192.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C527C20062 for ; Tue, 25 Mar 2014 08:49:32 +0000 (UTC) Received: by mail-qg0-f70.google.com with SMTP id z60sf341604qgd.1 for ; Tue, 25 Mar 2014 01:49:32 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=YOZ+pnyZaKwCeykFk4osG3kzz+5zlKzhWJP+8AIS5w0=; b=DPtJasnhpTsek3zo+35s170YVE8BnMCgfE1HCBjMCytPJ4knS2MqOxZOIL6P54Jb+1 8qn75UTFOXb5+emQKoSTLkRRjcnAc60tcwyOh27UYY9JOPnlt5bt8bHkumisYkP5MFdt Zul9c9xZV5WZFTP+4b0lNcmRkrnbvcIWU/YuXE5gi3AY4jjipMNgrS1pVcaGp+PElguC pJru94rhCHz6LeA5NhzM4MD6MsohcFkHR70L/+AruSeYlVmpT/tmIA9zF9Il7zy+RO8N dkhSNxhWfJhFX7XODxNgmDK1zezyZEB2KyYji+v/6c2oGysrz2dQZRyKmVqkhaI3mRtl 6UdQ== X-Gm-Message-State: ALoCoQketyURtbWGE+rjzGEa75vt7Jdb/Q4i9dHGNkjjNBU0U9jwi+bZq54iVG1y0s0Lcky/11Ob X-Received: by 10.236.173.42 with SMTP id u30mr11428419yhl.2.1395737372612; Tue, 25 Mar 2014 01:49:32 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.80.145 with SMTP id c17ls149886qgd.60.gmail; Tue, 25 Mar 2014 01:49:32 -0700 (PDT) X-Received: by 10.220.109.1 with SMTP id h1mr9328816vcp.20.1395737372467; Tue, 25 Mar 2014 01:49:32 -0700 (PDT) Received: from mail-ve0-f180.google.com (mail-ve0-f180.google.com [209.85.128.180]) by mx.google.com with ESMTPS id sh5si3680868vdc.86.2014.03.25.01.49.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:49:32 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.180; Received: by mail-ve0-f180.google.com with SMTP id jz11so149648veb.39 for ; Tue, 25 Mar 2014 01:49:32 -0700 (PDT) X-Received: by 10.52.72.48 with SMTP id a16mr4993755vdv.19.1395737372395; Tue, 25 Mar 2014 01:49:32 -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.220.78.9 with SMTP id i9csp286808vck; Tue, 25 Mar 2014 01:49:31 -0700 (PDT) X-Received: by 10.68.137.136 with SMTP id qi8mr76951651pbb.79.1395737371189; Tue, 25 Mar 2014 01:49:31 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bs8si11053919pad.463.2014.03.25.01.49.01; Tue, 25 Mar 2014 01:49:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754403AbaCYIsp (ORCPT + 26 others); Tue, 25 Mar 2014 04:48:45 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:39558 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752938AbaCYIVB (ORCPT ); Tue, 25 Mar 2014 04:21:01 -0400 Received: by mail-wi0-f178.google.com with SMTP id bs8so338724wib.11 for ; Tue, 25 Mar 2014 01:20:59 -0700 (PDT) X-Received: by 10.180.97.37 with SMTP id dx5mr19869760wib.53.1395735659849; Tue, 25 Mar 2014 01:20:59 -0700 (PDT) Received: from lee--X1.home (host109-148-113-193.range109-148.btcentralplus.com. [109.148.113.193]) by mx.google.com with ESMTPSA id k4sm5567676wib.19.2014.03.25.01.20.57 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:20:58 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: lee.jones@linaro.org, kernel@stlinux.com, computersforpeace@gmail.com, linux-mtd@lists.infradead.org, dwmw2@infradead.org, angus.clark@st.com, pekon@ti.com Subject: [RFC 22/47] mtd: nand: stm_nand_bch: check erased page for zeros Date: Tue, 25 Mar 2014 08:19:39 +0000 Message-Id: <1395735604-26706-23-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1395735604-26706-1-git-send-email-lee.jones@linaro.org> References: <1395735604-26706-1-git-send-email-lee.jones@linaro.org> 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: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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: , 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 2042cdd..7874d85 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -319,6 +319,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,