From patchwork Thu May 1 09:56:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 29485 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C765A203F3 for ; Thu, 1 May 2014 09:58:32 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id gq1sf15300723obb.10 for ; Thu, 01 May 2014 02:58: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:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=if5BVHwJSkllweUJnWjEKQbL0yO9abbsmxigMW+i2to=; b=jMEHF7ne/4fFFc5qnjI1JcXnYr+bc3wHhvno5VsWoSas1VCeVuG+/UJif+BZ4q7Fyk 1Q/kR2PEcMkMBN8+XsDpj5WJsSciPHD/nWeNNTjYhgFOt6lZx+KFADHrwObDzuZx3WLQ JXpXS6r4msCB0yXPFKou3X1f5UmOrkiSY12GI3p3XW12zcnYFkGr3iJ8rKRX0IR9sFMn m3e6L0QoEM7rIlki/3bMLdZeFgWdOnHEY0yIWs6bTfx1s6VGUdF/NABTlTqiS2Z0iggQ lgzCmgS5fg1H0zvr7M8eexq54TQhrrc8cpM+e/WVuQjrsC7BgOtQOqBKiENHxPtyQn21 Dx+g== X-Gm-Message-State: ALoCoQlcaGqtZklHBY3PT6bAZF08K5ReS15Te/l/OBVX2iV4f+W2DZ/osUXWTpxP1a4IKvGCYDdu X-Received: by 10.182.230.132 with SMTP id sy4mr5221474obc.48.1398938312369; Thu, 01 May 2014 02:58:32 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.35.210 with SMTP id n76ls1069185qgn.15.gmail; Thu, 01 May 2014 02:58:32 -0700 (PDT) X-Received: by 10.220.147.16 with SMTP id j16mr8233181vcv.14.1398938312252; Thu, 01 May 2014 02:58:32 -0700 (PDT) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id vd8si5952450vdc.70.2014.05.01.02.58.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:32 -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.178; Received: by mail-ve0-f178.google.com with SMTP id jw12so3700553veb.9 for ; Thu, 01 May 2014 02:58:32 -0700 (PDT) X-Received: by 10.220.59.65 with SMTP id k1mr8111460vch.22.1398938312192; Thu, 01 May 2014 02:58:32 -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 ib8csp12978vcb; Thu, 1 May 2014 02:58:31 -0700 (PDT) X-Received: by 10.180.95.4 with SMTP id dg4mr1495303wib.9.1398938311357; Thu, 01 May 2014 02:58:31 -0700 (PDT) Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by mx.google.com with ESMTPS id k12si10544744wjw.96.2014.05.01.02.58.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:31 -0700 (PDT) Received-SPF: none (google.com: lee.jones@linaro.org does not designate permitted sender hosts) client-ip=209.85.212.172; Received: by mail-wi0-f172.google.com with SMTP id hi2so406372wib.17 for ; Thu, 01 May 2014 02:58:31 -0700 (PDT) X-Received: by 10.180.94.8 with SMTP id cy8mr1471406wib.29.1398938310953; Thu, 01 May 2014 02:58:30 -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.28 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:29 -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 42/47] mtd: nand: stm_nand_bch: MTD mark and check for bad blocks (BCH) Date: Thu, 1 May 2014 10:56:49 +0100 Message-Id: <1398938214-17847-43-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: , Use the local BBM helpers to check for and mark bad blocks. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 11735ee..046e435 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -1275,6 +1275,53 @@ static int bch_scan_bbt(struct mtd_info *mtd) return 0; } +static int bch_block_isbad(struct mtd_info *mtd, loff_t offs, int getchip) +{ + 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_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 */ + ret = bch_update_bbts(nandi, &nandi->info.bbt_info, + NAND_IBBT_UPDATE_BOTH, + nandi->info.bbt_info.bbt_vers[0] + 1); + + return ret; +} + static void nandi_dump_bad_blocks(struct nandi_controller *nandi) { int bad_count = 0; @@ -1383,6 +1430,8 @@ static void nandi_set_mtd_defaults(struct nandi_controller *nandi, chip->erase = bch_erase; chip->scan_bbt = bch_scan_bbt; + chip->block_bad = bch_block_isbad; + chip->block_markbad = bch_block_markbad; } /*