From patchwork Tue Mar 25 08:19:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 26992 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f199.google.com (mail-vc0-f199.google.com [209.85.220.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AA0A720062 for ; Tue, 25 Mar 2014 08:27:15 +0000 (UTC) Received: by mail-vc0-f199.google.com with SMTP id lh14sf296811vcb.10 for ; Tue, 25 Mar 2014 01:27:15 -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=/orSnZiptF0xm9I1te5tRy9P7MWTGdlngq4RF5aSWow=; b=jsjd0OfOQikQJAwSYfzWPDhjYhb4OcRRClUWDMAshVux5/TcUVFHWJGz0wnDtub80L NEziT7URG/kWIrmg3H0N+gl7UZ+zAgQvr53n038/1/rSoetOhYavotZIyNYxUFsVXbPQ IFZP1sthG3KoLSyyCVUh9cMwSIQdQcysY8gAGT8aJkZtipk09PMel4AtiTIZdjWwGEqM /7V/UUHqSQeLsuRRBxPlOwrUrhyW8D5gHTubYlcu983Ca73/wxtUBX1PrNdzwMhyNFBF 38rjGCXLDgULf07NFlzuCj2SKBT2gSLVCxIGsFACAXzOCkfcTcjCRkxWRGzAG7+ZJALy q4Zw== X-Gm-Message-State: ALoCoQmTayM352ULAa7anF7WZHKg4q9WWtbSDOBMypM7iCvIBFXkgcR1mASOmCWoSgJqraB4zLzi X-Received: by 10.58.59.104 with SMTP id y8mr17165160veq.18.1395736035422; Tue, 25 Mar 2014 01:27:15 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.21.40 with SMTP id 37ls124236qgk.32.gmail; Tue, 25 Mar 2014 01:27:15 -0700 (PDT) X-Received: by 10.52.37.161 with SMTP id z1mr454630vdj.29.1395736035272; Tue, 25 Mar 2014 01:27:15 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id 16si3544573vce.12.2014.03.25.01.27.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:27:15 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id hu19so136272vcb.15 for ; Tue, 25 Mar 2014 01:27:15 -0700 (PDT) X-Received: by 10.58.96.36 with SMTP id dp4mr6388092veb.21.1395736035171; Tue, 25 Mar 2014 01:27:15 -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 i9csp285598vck; Tue, 25 Mar 2014 01:27:14 -0700 (PDT) X-Received: by 10.181.13.82 with SMTP id ew18mr20330101wid.22.1395736033762; Tue, 25 Mar 2014 01:27:13 -0700 (PDT) Received: from casper.infradead.org (casper.infradead.org. [85.118.1.10]) by mx.google.com with ESMTPS id ce2si1361347wib.115.2014.03.25.01.27.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Mar 2014 01:27:13 -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 1WSMfG-0001S9-Os; Tue, 25 Mar 2014 08:24:56 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMe1-0002WY-VL; Tue, 25 Mar 2014 08:23:38 +0000 Received: from mail-wi0-f169.google.com ([209.85.212.169]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMcA-0002EN-B6 for linux-arm-kernel@lists.infradead.org; Tue, 25 Mar 2014 08:21:49 +0000 Received: by mail-wi0-f169.google.com with SMTP id hm4so3176985wib.2 for ; Tue, 25 Mar 2014 01:21:21 -0700 (PDT) X-Received: by 10.180.87.9 with SMTP id t9mr20936561wiz.36.1395735681074; Tue, 25 Mar 2014 01:21:21 -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.19 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:21:20 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC 33/47] mtd: nand: stm_nand_bch: search for and load flash-resident BBT Date: Tue, 25 Mar 2014 08:19:50 +0000 Message-Id: <1395735604-26706-34-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_042143_354975_33DD26D1 X-CRM114-Status: GOOD ( 13.90 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.169 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.220.170 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 If a BBT already exists in flash, it's this function's task to locate it and load it into the driver for local consumption. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 87 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index d7d97720..d1d84c1 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -973,6 +973,93 @@ static int bch_find_ibbt_sig(struct nandi_controller *nandi, return 1; } +/* Search for and load Flash-resident BBT, updating Primary/Mirror if req'd */ +static int bch_load_bbt(struct nandi_controller *nandi, + struct nandi_bbt_info *bbt_info) +{ + unsigned int update = 0; + uint32_t block; + loff_t offs; + uint8_t vers; + char author[64]; + int bak; + + dev_dbg(nandi->dev, "looking for Flash-resident BBTs\n"); + + bbt_info->bbt_block[0] = 0; + bbt_info->bbt_block[1] = 0; + bbt_info->bbt_vers[0] = 0; + bbt_info->bbt_vers[1] = 0; + + /* Look for IBBT signatures */ + for (block = nandi->blocks_per_device - NAND_IBBT_NBLOCKS; + block < nandi->blocks_per_device; + block++) { + offs = (loff_t)block << nandi->block_shift; + + if (bch_find_ibbt_sig(nandi, block, &bak, &vers, author)) { + dev_dbg(nandi->dev, + "found BBT [%s:%u] at 0x%012llx [%u] (%s)\n", + bbt_strs[bak], vers, offs, block, + author); + + if (bbt_info->bbt_block[bak] == 0 || + ((int8_t)(bbt_info->bbt_vers[bak] - vers)) < 0) { + bbt_info->bbt_block[bak] = block; + bbt_info->bbt_vers[bak] = vers; + } + } + } + + /* What have we found? */ + if (bbt_info->bbt_block[0] == 0 && bbt_info->bbt_block[1] == 0) { + /* no primary, no mirror: return error */ + return 1; + } else if (bbt_info->bbt_block[0] == 0) { + /* no primary: use mirror, update primary */ + bak = 1; + update = NAND_IBBT_UPDATE_PRIMARY; + bbt_info->bbt_block[0] = nandi->blocks_per_device - 1; + } else if (bbt_info->bbt_block[1] == 0) { + /* no mirror: use primary, update mirror */ + bak = 0; + update = NAND_IBBT_UPDATE_MIRROR; + bbt_info->bbt_block[1] = nandi->blocks_per_device - 1; + } else if (bbt_info->bbt_vers[0] == bbt_info->bbt_vers[1]) { + /* primary == mirror: use primary, no update required */ + bak = 0; + } else if ((int8_t)(bbt_info->bbt_vers[1] - + bbt_info->bbt_vers[0]) < 0) { + /* primary > mirror: use primary, update mirror */ + bak = 0; + update = NAND_IBBT_UPDATE_MIRROR; + } else { + /* mirror > primary: use mirror, update primary */ + bak = 1; + update = NAND_IBBT_UPDATE_PRIMARY; + } + + vers = bbt_info->bbt_vers[bak]; + block = bbt_info->bbt_block[bak]; + offs = block << nandi->block_shift; + dev_info(nandi->dev, "using BBT [%s:%u] at 0x%012llx [%u]\n", + bbt_strs[bak], vers, offs, block); + + /* Read BBT data */ + if (bch_read_page(nandi, offs, bbt_info->bbt) < 0) { + dev_err(nandi->dev, + "error while reading BBT %s:%u] at 0x%012llx [%u]\n", + bbt_strs[bak], vers, offs, block); + return 1; + } + + /* Update other BBT if required */ + if (update) + bch_update_bbts(nandi, bbt_info, update, vers); + + return 0; +} + /* * Initialisation */