From patchwork Thu May 1 09:56:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 29471 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E1320203F3 for ; Thu, 1 May 2014 09:58:07 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id a41sf1831856yho.9 for ; Thu, 01 May 2014 02:58:07 -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=r7eSJA8yy//E7aoRRacJLLmNDUG/mhBcFLWUwcT/k6c=; b=EK4uAxUcDQnz5bXoiJFgkXWCXigi2+gtLyt/srEvO6IvG1I40qYGdCrmcIepl1oMYC j7fhsBVmOaurwumJ4plmam7tbzmF2rN9TFvTv/1d6ltNybj65k6qNV65iN8WjPIhC1il bzmWr1DZ9qW7g4zmBm9l3kRzL05fg7a8wLLBxH6qERup/rl8+B/lU7VBjhsN0arWSOWi eFuO/eGK+cfLNui2DYmrD3OeOMM2puM1ZNBa0jGCZTIorvJTvOn5qysfVswoN9jUhW5s GPuBI/m5K7+zSvEx+28rRxfXJXdXq1D3YtOk34Oo8ylPAA48eC4eJbBlR2iU6qbrIV9n lQTw== X-Gm-Message-State: ALoCoQn35tQbg155dkv/nTQRDP44WPnMsIJ8aGGJ9oeV9piddCF3hfUhv7m3zyjeEuVGSxY5XPf5 X-Received: by 10.236.142.212 with SMTP id i60mr4211152yhj.39.1398938287704; Thu, 01 May 2014 02:58:07 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.82.42 with SMTP id g39ls962875qgd.25.gmail; Thu, 01 May 2014 02:58:07 -0700 (PDT) X-Received: by 10.52.15.132 with SMTP id x4mr976732vdc.31.1398938287593; Thu, 01 May 2014 02:58:07 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id af10si5968245vec.23.2014.05.01.02.58.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:07 -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.220.182; Received: by mail-vc0-f182.google.com with SMTP id lf12so3786303vcb.27 for ; Thu, 01 May 2014 02:58:07 -0700 (PDT) X-Received: by 10.220.162.6 with SMTP id t6mr8301271vcx.12.1398938287529; Thu, 01 May 2014 02:58:07 -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 ib8csp12950vcb; Thu, 1 May 2014 02:58:07 -0700 (PDT) X-Received: by 10.194.60.114 with SMTP id g18mr405281wjr.61.1398938286640; Thu, 01 May 2014 02:58:06 -0700 (PDT) Received: from mail-we0-f182.google.com (mail-we0-f182.google.com [74.125.82.182]) by mx.google.com with ESMTPS id dl9si10526028wjb.233.2014.05.01.02.58.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:06 -0700 (PDT) Received-SPF: none (google.com: lee.jones@linaro.org does not designate permitted sender hosts) client-ip=74.125.82.182; Received: by mail-we0-f182.google.com with SMTP id u57so2914206wes.27 for ; Thu, 01 May 2014 02:58:06 -0700 (PDT) X-Received: by 10.194.88.106 with SMTP id bf10mr8309637wjb.26.1398938286150; Thu, 01 May 2014 02:58:06 -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.58.04 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:05 -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 28/47] mtd: nand: stm_nand_bch: bad block marking helpers Date: Thu, 1 May 2014 10:56:35 +0100 Message-Id: <1398938214-17847-29-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: , 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 83faffe..27a87a3 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -712,6 +712,35 @@ static int bch_write(struct mtd_info *mtd, struct nand_chip *chip, return 0; } +/* + * 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,