From patchwork Tue Mar 14 17:45:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 95306 Delivered-To: patch@linaro.org Received: by 10.140.89.134 with SMTP id v6csp367655qgd; Tue, 14 Mar 2017 10:47:14 -0700 (PDT) X-Received: by 10.99.253.5 with SMTP id d5mr44368015pgh.47.1489513634787; Tue, 14 Mar 2017 10:47:14 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id d18si15370887pgn.60.2017.03.14.10.47.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Mar 2017 10:47:14 -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: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:In-Reply-To: References:List-Owner; bh=76n+g9ZYSstNte7QdgDRui4m1NEonZgvescTcyE5O4k=; b=Weg lRX8hZ6kaxAg4Gfh94vb3F2LI+THyL1uAHIRe95v2xYeSj6KYx6B3+8Ec8+gHsOx/iLXsg2ldVDJS aUdfO+TbvWOEZyz95ZJG5OnS3gjWbCXvzbvl25WYoyfai8/+rBoYKSK/L3weqEE+aWFPCjG8tq9yB mfKtCjIhXbzM9JpzTJRxO3ww2uyqb5lBlEeYPiScOLaLZZPiStBG1E7GjllfDUBwTocC+Gzd0rXFf gyQ2GxM543TcGBf6gPPmN2mjqTbdy6A1ahIcL4NpLW8i0/FrvteMzgc1a/AKY9YwNWqYpvJbKW6wx xYy2g5Ajn2NxoURELfADP8/gxPeFoeQ==; 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 1cnqXK-0007LZ-Td; Tue, 14 Mar 2017 17:47:06 +0000 Received: from conuserg-11.nifty.com ([210.131.2.78]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cnqXG-0007J8-Mb for linux-mtd@lists.infradead.org; Tue, 14 Mar 2017 17:47:05 +0000 Received: from grover.sesame (FL1-111-169-71-157.osk.mesh.ad.jp [111.169.71.157]) (authenticated) by conuserg-11.nifty.com with ESMTP id v2EHjtWQ005957; Wed, 15 Mar 2017 02:46:01 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com v2EHjtWQ005957 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1489513561; bh=5Cl2rcWEwaOLxOhO1PKDN4d5382GrmNQiOHnksZvmjU=; h=From:To:Cc:Subject:Date:From; b=lYWrmAnVVi8pMinLILach0uFE5pGql/2oMIQupx/A6MKzwv5Jky8hPYLAoZKIz2cE ji7Vg9V16nV1rqiaF12dR/dv9IgRJXUm9Pse19xW16X+auvp9DphCkn/6RGoNXngCE L+OmLwwVpvInS2WfpNJqmWHBTrKmhBkhNUPx9Lxwpxm2AN5exmS5li1HD3WHFVQEVq hf+GmMYsEv1r4Dhgv0vqQj8Jz+XLmFWM79cNmFs7KCaH6fucIXccwTSZlSRdnt8j1j 8MYBBfDRtKsYEJp7u8h2qufNi8U+zS+uej/0XBjq2uDsjRGHkloVufnwshMQNYkiC1 aqqcaJs5zFnZQ== X-Nifty-SrcIP: [111.169.71.157] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Subject: [PATCH] mtd: nand: use .read_oob() instead of .cmdfunc() for bad block check Date: Wed, 15 Mar 2017 02:45:48 +0900 Message-Id: <1489513548-3248-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170314_104703_111145_2AAD4C8D X-CRM114-Status: GOOD ( 14.83 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.5 RCVD_IN_SORBS_SPAM RBL: SORBS: sender is a spam source [210.131.2.78 listed in dnsbl.sorbs.net] 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: Boris Brezillon , Marek Vasut , Richard Weinberger , linux-kernel@vger.kernel.org, Masahiro Yamada , Cyrille Pitchen , Brian Norris , David Woodhouse MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org The nand_default_block_markbad() is the default implementation of chip->block_markbad(). This is called for marking a block as bad. It invokes nand_do_write_oob(), then calls a higher level accessor ecc->write_oob(). On the other hand, when reading BBM from the OOB, chip->block_bad() is called, and nand_block_bad() is the default implementation. This function calls a lower level chip->cmdfunc(). If a driver wants to re-use nand_block_bad(), it is required to support NAND_CMD_READOOB in its cmdfunc(). This is strange. If the controller supports optimized read operation and the driver has its own ecc->read_oob(), it should be able to use it. Besides, NAND_CMD_READOOB (0x50) is not a real command for large page devices. So, recent drivers may not be happy to handle this command. Signed-off-by: Masahiro Yamada --- At first, I tried to call nand_do_read_oob() from nand_block_bad() in order to make to make things symmetry, but it did not work. chip->select_chip() is handled outside of nand_block_bad(), so nand_do_read_oob() can not be used there. drivers/mtd/nand/nand_base.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 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..78c5cd6 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -354,9 +354,9 @@ 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, res = 0, ret = 0, i = 0; struct nand_chip *chip = mtd_to_nand(mtd); - u16 bad; + u8 bad; if (chip->bbt_options & NAND_BBT_SCANLASTPAGE) ofs += mtd->erasesize - mtd->writesize; @@ -364,30 +364,26 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs) page = (int)(ofs >> chip->page_shift) & chip->pagemask; 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; + res = chip->ecc.read_oob(mtd, chip, page); + if (!res) { + bad = chip->oob_poi[chip->badblockpos]; + + if (likely(chip->badblockbits == 8)) + res = bad != 0xFF; else - bad &= 0xFF; - } else { - chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos, - page); - bad = chip->read_byte(mtd); + res = hweight8(bad) < chip->badblockbits; + if (res) + return res; } - 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; + if (!ret) + ret = res; + + page++; i++; - } while (!res && i < 2 && (chip->bbt_options & NAND_BBT_SCAN2NDPAGE)); + } while (chip->bbt_options & NAND_BBT_SCAN2NDPAGE && i < 2); - return res; + return ret; } /**