From patchwork Wed Mar 22 14:07:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 95771 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp260549qgd; Wed, 22 Mar 2017 07:16:29 -0700 (PDT) X-Received: by 10.99.161.17 with SMTP id b17mr44207028pgf.72.1490192189560; Wed, 22 Mar 2017 07:16:29 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id a5si1972103pgg.258.2017.03.22.07.16.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Mar 2017 07:16:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) client-ip=65.50.211.133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=linux-mtd-bounces+patch=linaro.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=EGMOIJ9UaHISLHpncgeU+6pRUTGr/+gUitkdInJ6Gno=; b=lcwj7z1blpYQ1lrzvOuUFxp100 pqdYR2DjT09O2+X9k9MN5AAhvGFCXF+q1aUYFjegit7hGKWTrK5Se/Iq5nezoYElLtpcRLXAvmvvk VfIXUmrvIr3ekeKQIO8kSdsVy7fibb/BrtOV7a6V+gjYIkbZB5Cvac/5dmFLLp9BVMQ2MMblCpt8K 32zpo/4LuKH5ki+mpIWsiY9YwOMleRVkuIE3xVVJmiiBX12BOUnx4DWp5PDGgcWxECL9YCPq8yfWn l46qows+1Sx3jk1uM4ArG/3lZTPw1NdURkP0DP+ZSan9Vp4gZAm9CcYJW/P00WoC5rgPLbsj6EOrg D7lMe76Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cqh3p-0006uk-0G; Wed, 22 Mar 2017 14:16:25 +0000 Received: from conuserg-07.nifty.com ([210.131.2.74]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cqgwz-0005uF-1x for linux-mtd@lists.infradead.org; Wed, 22 Mar 2017 14:09:25 +0000 Received: from pug.jp.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-07.nifty.com with ESMTP id v2ME8LDL010154; Wed, 22 Mar 2017 23:08:24 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com v2ME8LDL010154 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1490191706; bh=aC+G4L1ivWCzubp/gZ1RMNCmminZYxtmKyRD5jPgu2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1sIZKG6kbj5WqaoDkWexBPnERx4MB+KYz5Wa/eTTUKFtfTQFCGvBn974t07KkM8ek noMG8aZ9KDxZu5D1jhRsdMwbsJUQ+Xg73uapiwnWTstB4qpaTFjeVCB0bvO6YjLGQA zLo3fjAnPV0mp8/ZyWwaix7X5YJBhuxNcZa8Sqetii+Bd5zPl9Z0b5Um6QsSav35Ww 4FyRMZujC8uDUXMBSrpzbRU9oGc63Kh2Tn/EAxQosIj4ihXdaVi019OIpqXUdeEGbD WjUVSm+fZ+3AT9nwVh6e9tzP6yFsx75xZB9JHGgPgyNRduC89jeGgUIXh1BAHgJJAC PdEkedC8Ve4yw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Subject: [PATCH v2 02/53] mtd: nand: use read_oob() instead of cmdfunc() for bad block check Date: Wed, 22 Mar 2017 23:07:09 +0900 Message-Id: <1490191680-14481-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490191680-14481-1-git-send-email-yamada.masahiro@socionext.com> References: <1490191680-14481-1-git-send-email-yamada.masahiro@socionext.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170322_070921_644827_C2CD4A8E X-CRM114-Status: GOOD ( 13.55 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: laurent.monat@idquantique.com, Boris Brezillon , thorsten.christiansson@idquantique.com, Richard Weinberger , Marek Vasut , Masahiro Yamada , Artem Bityutskiy , Cyrille Pitchen , Jason Roberts , linux-kernel@vger.kernel.org, Dinh Nguyen , Masami Hiramatsu , Chuanxiao Dong , Jassi Brar , Brian Norris , Enrico Jorns , David Woodhouse , Graham Moore MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org The nand_default_block_markbad() and scan_block_fast() use high level APIs to get access to the BBM. On the other hand, nand_block_bad (the default implementation of ->block_bad) calls the lower level ->cmdfunc hook. This prevents drivers from using ->ecc.read_oob() even if optimized read operation is implemented. Besides, some NAND controllers may protect the BBM with ECC. Signed-off-by: Masahiro Yamada --- Changes in v2: - Error out immediately if the first page access fails - Use for() {} instead of do {} while() - Update git-log drivers/mtd/nand/nand_base.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) -- 2.7.4 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index a3c0f47..807398d 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -354,40 +354,32 @@ static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len) */ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs) { - int page, res = 0, i = 0; + int page, page_end, res; struct nand_chip *chip = mtd_to_nand(mtd); - u16 bad; + u8 bad; if (chip->bbt_options & NAND_BBT_SCANLASTPAGE) ofs += mtd->erasesize - mtd->writesize; page = (int)(ofs >> chip->page_shift) & chip->pagemask; + page_end = page + (chip->bbt_options & NAND_BBT_SCAN2NDPAGE ? 2 : 1); - do { - if (chip->options & NAND_BUSWIDTH_16) { - chip->cmdfunc(mtd, NAND_CMD_READOOB, - chip->badblockpos & 0xFE, page); - bad = cpu_to_le16(chip->read_word(mtd)); - if (chip->badblockpos & 0x1) - bad >>= 8; - else - bad &= 0xFF; - } else { - chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos, - page); - bad = chip->read_byte(mtd); - } + for (; page < page_end; page++) { + res = chip->ecc.read_oob(mtd, chip, page); + if (res) + return res; + + bad = chip->oob_poi[chip->badblockpos]; if (likely(chip->badblockbits == 8)) res = bad != 0xFF; else res = hweight8(bad) < chip->badblockbits; - ofs += mtd->writesize; - page = (int)(ofs >> chip->page_shift) & chip->pagemask; - i++; - } while (!res && i < 2 && (chip->bbt_options & NAND_BBT_SCAN2NDPAGE)); + if (res) + return res; + } - return res; + return 0; } /**