From patchwork Tue Mar 25 08:19:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 26976 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9B5C620062 for ; Tue, 25 Mar 2014 08:22:03 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id gq1sf490396obb.7 for ; Tue, 25 Mar 2014 01:22:03 -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=2V0HtmkcxHTGC6EpC2URDisA/F5LAzTaNWpn83QbwdY=; b=OfTAJR0kD3oRxgoatw8QljM45k9w0AlHR2WZaTe54Hz+QQ00tdkHtd4l/v6J+b1g/H oybl7ppxorRqvnbGfcAeb7Ze/nem7tEpzt+cSvhGmNQkZ+hn/G/dh8rCBWKAuCmopjPg MsLj35wmcqpFjoAbIkZ33a2qZ7bbDz3S/EnoWOZv3FpbrIWrTEHBNen1c2C4P96VTd2M nYUPtfGzFnxnpi2/F3JIMvPUPkV7isLsNoG5IehdLZ5JrF46MffBVSWQ08JmCYi4GmPY i34wUPFRtdwZm74B/dQNzaWLZS1PwnD1Ihp/JXiUM4ZE4Js48YF1mVdNoFuPro5TPdzy 2k5Q== X-Gm-Message-State: ALoCoQmkgUndma1xy3LZDAo3OozhSi8l+zchABDDfhlL/yasfeg+LhRiSE+/EsoXs5uQ8QG+DXLp X-Received: by 10.42.146.199 with SMTP id k7mr26141731icv.24.1395735723132; Tue, 25 Mar 2014 01:22:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.32.11 with SMTP id g11ls150428qgg.11.gmail; Tue, 25 Mar 2014 01:22:03 -0700 (PDT) X-Received: by 10.52.72.48 with SMTP id a16mr4904178vdv.19.1395735723046; Tue, 25 Mar 2014 01:22:03 -0700 (PDT) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id vd8si3669871vdc.124.2014.03.25.01.22.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:22:03 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.171 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.171; Received: by mail-ve0-f171.google.com with SMTP id cz12so130448veb.30 for ; Tue, 25 Mar 2014 01:22:03 -0700 (PDT) X-Received: by 10.52.78.231 with SMTP id e7mr4635467vdx.28.1395735722967; Tue, 25 Mar 2014 01:22:02 -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 i9csp285344vck; Tue, 25 Mar 2014 01:22:01 -0700 (PDT) X-Received: by 10.68.230.200 with SMTP id ta8mr7004508pbc.10.1395735719968; Tue, 25 Mar 2014 01:21:59 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b5si10889653pbq.233.2014.03.25.01.21.59; Tue, 25 Mar 2014 01:21:59 -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 S1753288AbaCYIVj (ORCPT + 26 others); Tue, 25 Mar 2014 04:21:39 -0400 Received: from mail-we0-f173.google.com ([74.125.82.173]:62231 "EHLO mail-we0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753132AbaCYIVh (ORCPT ); Tue, 25 Mar 2014 04:21:37 -0400 Received: by mail-we0-f173.google.com with SMTP id w61so75952wes.18 for ; Tue, 25 Mar 2014 01:21:36 -0700 (PDT) X-Received: by 10.180.96.66 with SMTP id dq2mr19990757wib.54.1395735696337; Tue, 25 Mar 2014 01:21:36 -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.34 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:21:35 -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 41/47] mtd: nand: stm_nand_bch: MTD mark and check for bad blocks (BCH) Date: Tue, 25 Mar 2014 08:19:58 +0000 Message-Id: <1395735604-26706-42-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.171 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: , Use the local BBM helpers to check for and mark bad blocks. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 55f4a4c..38658b8 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -1218,6 +1218,55 @@ static int flex_do_write_ops(struct nandi_controller *nandi, return 0; } +static int bch_mtd_block_isbad(struct mtd_info *mtd, loff_t offs) +{ + struct nand_chip *chip = mtd->priv; + struct nandi_controller *nandi = chip->priv; + + uint32_t block; + + /* Check for invalid offset */ + if (offs > mtd->size) + return -EINVAL; + + block = offs >> nandi->block_shift; + + /* Protect blocks reserved for BBTs */ + if (block >= (nandi->blocks_per_device - NAND_IBBT_NBLOCKS)) + return 1; + + return bbt_is_block_bad(nandi->info.bbt_info.bbt, block); +} + +static int bch_mtd_block_markbad(struct mtd_info *mtd, loff_t offs) +{ + struct nand_chip *chip = mtd->priv; + struct nandi_controller *nandi = chip->priv; + + uint32_t block; + int ret; + + /* Is block already considered bad? (will also catch invalid offsets) */ + ret = mtd_block_isbad(mtd, offs); + if (ret < 0) + return ret; + if (ret == 1) + return 0; + + /* Mark bad */ + block = offs >> nandi->block_shift; + bbt_set_block_mark(nandi->info.bbt_info.bbt, block, BBT_MARK_BAD_WEAR); + + /* Update BBTs, incrementing bbt_vers */ + nand_get_device(mtd, FL_WRITING); + ret = bch_update_bbts(nandi, &nandi->info.bbt_info, + NAND_IBBT_UPDATE_BOTH, + nandi->info.bbt_info.bbt_vers[0] + 1); + nand_release_device(mtd); + + return ret; +} + static int bch_mtd_erase(struct mtd_info *mtd, struct erase_info *instr) { struct nand_chip *chip = mtd->priv; @@ -1405,6 +1454,8 @@ static void nandi_set_mtd_defaults(struct nandi_controller *nandi, mtd->subpage_sft = 0; mtd->_erase = bch_mtd_erase; + mtd->_block_isbad = bch_mtd_block_isbad; + mtd->_block_markbad = bch_mtd_block_markbad; mtd->_point = NULL; mtd->_unpoint = NULL;