From patchwork Tue Mar 25 08:19:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 26996 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2DD6E20062 for ; Tue, 25 Mar 2014 08:37:31 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id i17sf322578qcy.3 for ; Tue, 25 Mar 2014 01:37:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=0W44gaftmC13UoJAvc1dd9OrM6VFvEV+j4t/Gjqa29k=; b=iQIlbTklvEt4Jt0h4Cf1Eb0kfjI8s5kMOPavw8/npo7idzavM+jIodL4if6vmrbev5 Kt02sfUKWKumqc/1waecag4A8cPJJPdVI44oGpMXT5n0C+L6h9RSKtEX9jfjwkNcAJFi qykRII69fOwoC9yjNzYhYAe7sVXgIh0d8VPlIO9Nh3O9fvzNu5M8V7/7niFb8ZJuZE+l SbdjzBu2TsQjnG3OH1Fxb19PrOnUdv0sdrWlIzGDIsJ2hSZ1/ajRRE3vvcn9rgSIh07r CJE03gkWugMjX/w9NWrqx2JAAgg+K4YveZOPlrpWbg+uuouY2GhELBi/QSKBdsX6h7wO DDsg== X-Gm-Message-State: ALoCoQkyr+VNrElnNZt4KIJe4KnlPvlrCNwGqWVpTu0FcVNDXg3GXnTYKRbjupyb28RGnrvEDzAk X-Received: by 10.58.112.1 with SMTP id im1mr17385402veb.33.1395736650670; Tue, 25 Mar 2014 01:37:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.70 with SMTP id u64ls139134qgd.80.gmail; Tue, 25 Mar 2014 01:37:30 -0700 (PDT) X-Received: by 10.220.103.141 with SMTP id k13mr340569vco.25.1395736650576; Tue, 25 Mar 2014 01:37:30 -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 be7si3537799vcb.143.2014.03.25.01.37.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:37:30 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.178 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.178; Received: by mail-ve0-f178.google.com with SMTP id jw12so139888veb.23 for ; Tue, 25 Mar 2014 01:37:30 -0700 (PDT) X-Received: by 10.221.4.66 with SMTP id ob2mr98962vcb.28.1395736650256; Tue, 25 Mar 2014 01:37:30 -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 i9csp286210vck; Tue, 25 Mar 2014 01:37:29 -0700 (PDT) X-Received: by 10.180.219.44 with SMTP id pl12mr20610985wic.12.1395736648969; Tue, 25 Mar 2014 01:37:28 -0700 (PDT) Received: from casper.infradead.org (casper.infradead.org. [85.118.1.10]) by mx.google.com with ESMTPS id fw3si796733wib.51.2014.03.25.01.37.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Mar 2014 01:37:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 85.118.1.10 as permitted sender) client-ip=85.118.1.10; Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMrM-000780-8t; Tue, 25 Mar 2014 08:37:24 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMrJ-00037g-Kd; Tue, 25 Mar 2014 08:37:21 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMrG-00036r-GA for linux-arm-kernel@merlin.infradead.org; Tue, 25 Mar 2014 08:37:18 +0000 Received: from mail-we0-f180.google.com ([74.125.82.180]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMcB-000832-8G for linux-arm-kernel@lists.infradead.org; Tue, 25 Mar 2014 08:21:43 +0000 Received: by mail-we0-f180.google.com with SMTP id p61so76340wes.25 for ; Tue, 25 Mar 2014 01:21:17 -0700 (PDT) X-Received: by 10.180.24.134 with SMTP id u6mr21529397wif.41.1395735677358; Tue, 25 Mar 2014 01:21:17 -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.15 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:21:16 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC 31/47] mtd: nand: stm_nand_bch: scan block for BBM(s) according to specified BBT options Date: Tue, 25 Mar 2014 08:19:48 +0000 Message-Id: <1395735604-26706-32-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140325_082143_312852_C07B9160 X-CRM114-Status: GOOD ( 15.47 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on casper.infradead.org summary: Content analysis details: (-2.6 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.180 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: angus.clark@st.com, kernel@stlinux.com, lee.jones@linaro.org, linux-mtd@lists.infradead.org, pekon@ti.com, computersforpeace@gmail.com, dwmw2@infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.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.178 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 Search the specified (first and, second or last) page in a block for the BBT. Support Hamming or Advanced Flex Mode (AFM) BBMs too. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 4812431..29eeee8 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -643,6 +643,66 @@ 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 page for BBM(s), according to specified BBT options */ +static int nandi_scan_bad_block_markers_page(struct nandi_controller *nandi, + uint32_t page) +{ + struct mtd_info *mtd = &nandi->info.mtd; + struct nand_chip *chip = mtd->priv; + uint8_t *oob_buf = nandi->oob_buf; + int i, e; + + /* Read the OOB area */ + flex_read_raw(nandi, page, mtd->writesize, oob_buf, mtd->oobsize); + + if (oob_buf[chip->badblockpos] == 0xff) + return 0; + + /* Tolerate 'alien' Hamming Boot Mode ECC */ + e = 0; + for (i = 0; i < mtd->oobsize; i += 16) + e += hweight8(oob_buf[i + 3] ^ 'B'); + if (e <= 1) + return 0; + + /* Tolerate 'alien' Hamming AFM ECC */ + e = 0; + for (i = 0; i < mtd->oobsize; i += 16) { + e += hweight8(oob_buf[i + 3] ^ 'A'); + e += hweight8(oob_buf[i + 4] ^ 'F'); + e += hweight8(oob_buf[i + 5] ^ 'M'); + if (e <= 1) + return 0; + } + + return 1; +} + +/* Scan block for BBM(s), according to specified BBT options */ +static int nandi_scan_bad_block_markers_block(struct nandi_controller *nandi, + uint32_t block) + +{ + struct mtd_info *mtd = &nandi->info.mtd; + struct nand_chip *chip = mtd->priv; + uint32_t pages_per_block = mtd->erasesize >> nandi->page_shift; + uint32_t page = block << (nandi->block_shift - nandi->page_shift); + + if (nandi_scan_bad_block_markers_page(nandi, page)) + return 1; + + if ((chip->bbt_options & NAND_BBT_SCAN2NDPAGE) && + nandi_scan_bad_block_markers_page(nandi, page + 1)) + return 1; + + if ((chip->bbt_options & NAND_BBT_SCANLASTPAGE) && + nandi_scan_bad_block_markers_page(nandi, + page + pages_per_block - 1)) + return 1; + + return 0; +} + /* Populate IBBT BCH Header */ static void bch_fill_ibbt_header(struct nandi_controller *nandi, struct nand_ibbt_bch_header *ibbt_header, @@ -957,6 +1017,8 @@ static void nandi_set_mtd_defaults(struct nandi_controller *nandi, chip->priv = nandi; chip->ecc.layout = &info->ecclayout; + chip->bbt_options |= NAND_BBT_USE_FLASH; + /* mtd_info */ mtd->owner = THIS_MODULE; mtd->type = MTD_NANDFLASH;