From patchwork Tue Mar 25 08:19:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 27000 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f71.google.com (mail-pb0-f71.google.com [209.85.160.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D1A4A20062 for ; Tue, 25 Mar 2014 08:40:35 +0000 (UTC) Received: by mail-pb0-f71.google.com with SMTP id up15sf337353pbc.10 for ; Tue, 25 Mar 2014 01:40:35 -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:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=EiHVTnlbz92FAIse+iwzMZAdtuSgMINMxkKlNi8+we4=; b=Z6oVXsXzfSCOLZAGbgD1IwIK65WeU0s6NnWJaBwtZOT5L92naYKRHo3chIaBdav2yZ FARoYEjm2ZrWqgpHxOBJUoQU+UuPdUL35jeGafBwaujWbAbXkYJ2bt5t2pdDqBr5sIqX TZdOkvn29FXn99V4+gphYJzXUEhv0tl2v+h3t+mnDdPyTU6wTqR/M5V/uYcZNL5wK8zp XhPcioayurzQYXB685d2a1g66WltdLikm1Ucxb17sMc1LP8ocRdWuN+4P2GJrfpqLjGl eQfJxu+xnC6aj8gI/UChxgMl8ia6S9tHJ26MzHT6xKGtLyqgHG8TfM7fL/itbRSSHNEv SXxQ== X-Gm-Message-State: ALoCoQmno9nuJ/HpngCbosLg9WJ5mL4t7ak2KzQqeBuILpj1u9EJ5DJrQ9lQz/1l718/e7eCj5lh X-Received: by 10.66.148.10 with SMTP id to10mr14426790pab.12.1395736834946; Tue, 25 Mar 2014 01:40:34 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.90.80 with SMTP id w74ls152346qgd.95.gmail; Tue, 25 Mar 2014 01:40:34 -0700 (PDT) X-Received: by 10.58.229.167 with SMTP id sr7mr52652514vec.7.1395736834848; Tue, 25 Mar 2014 01:40:34 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id eb17si1922038veb.130.2014.03.25.01.40.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:40:34 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id ik5so152768vcb.14 for ; Tue, 25 Mar 2014 01:40:34 -0700 (PDT) X-Received: by 10.52.240.207 with SMTP id wc15mr47262439vdc.14.1395736834761; Tue, 25 Mar 2014 01:40:34 -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 i9csp286358vck; Tue, 25 Mar 2014 01:40:34 -0700 (PDT) X-Received: by 10.180.72.136 with SMTP id d8mr21728441wiv.44.1395736833679; Tue, 25 Mar 2014 01:40:33 -0700 (PDT) Received: from casper.infradead.org (casper.infradead.org. [85.118.1.10]) by mx.google.com with ESMTPS id db6si12262082wib.25.2014.03.25.01.40.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Mar 2014 01:40:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 85.118.1.10 as permitted sender) client-ip=85.118.1.10; Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMsP-0007da-1Z; Tue, 25 Mar 2014 08:38:29 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMry-0003FH-6V; Tue, 25 Mar 2014 08:38:02 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMrM-00036r-6k for linux-arm-kernel@merlin.infradead.org; Tue, 25 Mar 2014 08:37:24 +0000 Received: from mail-wg0-f50.google.com ([74.125.82.50]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMbu-0007te-B9 for linux-arm-kernel@lists.infradead.org; Tue, 25 Mar 2014 08:21:27 +0000 Received: by mail-wg0-f50.google.com with SMTP id x13so75773wgg.21 for ; Tue, 25 Mar 2014 01:21:05 -0700 (PDT) X-Received: by 10.180.102.97 with SMTP id fn1mr20165790wib.15.1395735665789; Tue, 25 Mar 2014 01:21:05 -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.21.03 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:21:04 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC 25/47] mtd: nand: stm_nand_bch: bad block marking helpers Date: Tue, 25 Mar 2014 08:19:42 +0000 Message-Id: <1395735604-26706-26-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140325_082126_439600_C6C21900 X-CRM114-Status: GOOD ( 10.12 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on casper.infradead.org summary: Content analysis details: (-2.6 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.50 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: angus.clark@st.com, kernel@stlinux.com, lee.jones@linaro.org, linux-mtd@lists.infradead.org, pekon@ti.com, computersforpeace@gmail.com, dwmw2@infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.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.220.169 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 Bad Block Markers (BBMs) keep track of unusable/unsuitable memory blocks which can prevent unnecessary data loss. These helpers aid in reading and writing to/from the Bad Block Tables (BBTs) where the BBMs are stored. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 5bcaabbc..e1c71be 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -495,6 +495,35 @@ static uint8_t bch_write_page(struct nandi_controller *nandi, return status; } +/* + * Bad Block Tables/Bad Block Markers + */ +#define BBT_MARK_BAD_FACTORY 0x0 +#define BBT_MARK_BAD_WEAR 0x1 +#define BBT_MARK_GOOD 0x3 + +static void bbt_set_block_mark(uint8_t *bbt, uint32_t block, uint8_t mark) +{ + unsigned int byte = block >> 2; + unsigned int shift = (block & 0x3) << 1; + + bbt[byte] &= ~(0x3 << shift); + bbt[byte] |= ((mark & 0x3) << shift); +} + +static uint8_t bbt_get_block_mark(uint8_t *bbt, uint32_t block) +{ + unsigned int byte = block >> 2; + unsigned int shift = (block & 0x3) << 1; + + return (bbt[byte] >> shift) & 0x3; +} + +static int bbt_is_block_bad(uint8_t *bbt, uint32_t block) +{ + return bbt_get_block_mark(bbt, block) == BBT_MARK_GOOD ? 0 : 1; +} + /* Scan block for IBBT signature */ static int bch_find_ibbt_sig(struct nandi_controller *nandi, uint32_t block, int *bak, uint8_t *vers,