From patchwork Fri Mar 25 21:14:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Xu X-Patchwork-Id: 1609585 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=hFJ9mG4m; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256 header.s=selector2 header.b=SDCNWUrR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KQFHL199Tz9s0B for ; Sat, 26 Mar 2022 08:15:26 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :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=QFdVR8VukcxNFsz4/yMC844aSR91jvxhaxGOh+nQzOo=; b=hFJ9mG4muVQ332 tU0wn8PZ4FvILh2J9H3S61lW/KEawDr82vmAkEaO4omOEdzD54bcmCGc/x5jKovjC0HF6IHyyIxlR cRhG+q7xScxIIK2FgZ49lO1BEvSdhZJ9YKOhZq9mAtJby1YloK4uYM0NLgd1Dsms2exVAO9OfOgea uE8N7ahj7wAWTL8xiNW+hcZuwkzUqatNkWtfTy171HaQgkUaJSTcg6FZMSZjP9k4VUdiQwqrFC5LC TWRuklO+B393mW517Vj2dr+TQTcPseKnLdjbGKwByxv05XFxvNx8xkHgliMqEowLjpOAch0x+ffIx jYRlS02HC5rI8m4pPUDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nXrGl-003Jod-1Y; Fri, 25 Mar 2022 21:14:51 +0000 Received: from mail-am6eur05on20614.outbound.protection.outlook.com ([2a01:111:f400:7e1b::614] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nXrGg-003JkO-Jm for linux-mtd@lists.infradead.org; Fri, 25 Mar 2022 21:14:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gQm1xmR6HfMEHOahBDhwupcZ6BCJ3XbDit7fvgHwdeOpY/ZzEj5PWQ/QaG4m82bkhs5scs4eQItytpDKMoWOgMAR+HQhf9FOOK9hcnYNBKhCg6z+Jkz0qrA5hE/Zx24ieYYSQXwRAgezX1Ccf4QYHiHUwTUXywW3QrO8i0p7YkpYSG6bbUYN+5WKDXKWWU3d+hJdd5da+G7e37C338wgtaX2Duw/8ThywDsNA3Wf8hWSmwe7dWse6mKfincL5skV6EY+8T8yN0Mt0zftvYOXB8vbobx4Lh4lnOo87YXZw7AqQxnBmRGzEjrw2K3lZroyWr7bTIxx1t7EeUWhe0Ie7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LHVfWG4GIYnsryba7r4Bf5MIS+6ZN05eyPh54mq/0jk=; b=SCW57MHCXEQQyB/m0yTpRW1HGja4B+Tg1l7fTk9jvujxA0nVoV/acQto6dVzHK9131DVppo+2iD8VjbZroPWLYjZHlSNp8CUljIaMNvTu9ohHUhwau/9p0nakg2J9uaup0uxseGGbBqbzzpztHecBXAw3pgrUadyuDUwg9xgal9tezXYk0Fc46ubdNj/GFHKACqpabwIlm0qZVN/802DDyR86Yz9NAXL/CosPWrDN1PaGREiJmDYc4kkjY1ni5OEADTDrrOA/kE0XU3Qwoax6Z1yfMHVJidML+EeqnO9N9HkmXzpFy7jnCkVU5z//UrcurTlKEmjTCi9qt86LUEmMQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LHVfWG4GIYnsryba7r4Bf5MIS+6ZN05eyPh54mq/0jk=; b=SDCNWUrRr423GXeEWhJXME1F7Xs8zwhRoJvj9MJl5VYkpWGKjhe3vAOJz8xp9QQdOyCm9pKtlJQM2T0DUCXJJZL56A+4dIxxVUQgvrCjTAw5ePoN3jVerrPl8vyr0ys/bbOByp75xqSyCeGCBz/g2RZ1aGoYLGzc/VXdeU39VfI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8774.eurprd04.prod.outlook.com (2603:10a6:10:2e1::21) by DB3PR0402MB3881.eurprd04.prod.outlook.com (2603:10a6:8:12::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.19; Fri, 25 Mar 2022 21:14:33 +0000 Received: from DU2PR04MB8774.eurprd04.prod.outlook.com ([fe80::5416:5d1:cc34:ca9b]) by DU2PR04MB8774.eurprd04.prod.outlook.com ([fe80::5416:5d1:cc34:ca9b%7]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 21:14:33 +0000 From: Han Xu To: sbabic@denx.de, sean@geanix.com, frieder.schrempf@kontron.de, festevam@gmail.com Cc: ye.li@nxp.com, peng.fan@nxp.com, han.xu@nxp.com, miquel.raynal@bootlin.com, linux-mtd@lists.infradead.org Subject: [PATCH v2 1/2] mtd: rawnand: gpmi: Refactor bch geometry settings function Date: Fri, 25 Mar 2022 16:14:10 -0500 Message-Id: <20220325211411.30714-1-han.xu@nxp.com> X-Mailer: git-send-email 2.17.1 X-ClientProxiedBy: BYAPR01CA0057.prod.exchangelabs.com (2603:10b6:a03:94::34) To DU2PR04MB8774.eurprd04.prod.outlook.com (2603:10a6:10:2e1::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5bc62685-d67e-4388-6a56-08da0ea47542 X-MS-TrafficTypeDiagnostic: DB3PR0402MB3881:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OX+ltEK2zuqkPAsTlj4+XstUjL9pUvxJWgM5PiVY4aI8L3SvBOPPVPNZngSM38xzujCo7QheYExmw3+K4VyCSWncLrlEyCpDoYSl5TNMr2bJsVZYVH8/76rGMuvR72pB/TA46TvZm1xwrf0GKFBMs7PWnkgOjOk565EfyPHb0nyjrAoxfTkW/CgAGUIkfyRXRc4H88978OHMu0iYKteY0ddESZDXZOrXOp9XXUEa8l1TMjfNwbRVk1EZIXtsO5RVBuSYF9xmiBwDKnacm4FYRAPzIlud1PU8XMaTpPyz0gmvddL9IFb9YQ5bRursY7cbogkBxrh/F/MdKrqRlAf+4aAZyiCczI30D0RIeAkUKsBfo1PwhMcEsCIsWVCDvM42r0X0fwGSRJjlYATqlt3pRvudc6wxU+eASGe2QbmwGEBQZCOPmbpTpM/UYKZsnpt+z1AqDDmtgazjDYOr6zT7TxnJJjWdqsAcHtwkVk7I/xXXWR+m2i19yFiLombSS/h7BoYKegWudlNjNHoG5Cv3KoyUrSQ7yznc3YEuyLwwqzKlaoqCTmtpdy9sYHl+R4dS05ASpL4FAk0zfO6N8LeCp7RqGiClSVG9YdUFgvz4ho21QQwfJRS3ezhjpNbzGkR6mh5P6HVHO8RLgcQfcxAAPe2axXeSfc9wLAc8fKySozlZJ9eFQo4I4iIjswNOurL8sW+mthj9qWVq9N1ekSVXZw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU2PR04MB8774.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(316002)(36756003)(83380400001)(186003)(44832011)(8676002)(66476007)(2616005)(4326008)(66556008)(66946007)(5660300002)(38100700002)(1076003)(6486002)(8936002)(6512007)(38350700002)(52116002)(2906002)(6506007)(26005)(86362001)(508600001)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SvAagNvFukpmmcz+MJh/gZNA5uSmguUxwkkHpoBdurPXTMl767zx631Vh6JaCrYIAynjDIKsIt1d4DkPugeS/6xqT6vjoijr1sr53p/u2TnAqR4ge1xm8L+u6aOQxxhnAfET5ppBoQydWXNelBl1hIpCLrIVRfd+jDzBerl31j1Gev6SEVDD2UAle9cbKukI2hiidAhEJGWsa76SJCJNi2HcCKMoKslXrSBGRBJCR6RVuEAUOFnsvGl1wcTd1tueyTcsl21iUjaGo6yNnMJ71Ih+teESjw75wEe+qdT4fJHcj+KMEDIBZthSHQPp+SV5hhg21teeCKflYQQFq5w8/kEAZJUum2vtccuky4bVHYlj9WHd6F7t6RSufhDIcoxi6RH0B+Yk6IFo0mAwsyYheGD+rOdJSlV7ounBpmIdy7O35wEOg3rfSPGjQ2tkgWnipsBAWfZm4bbSaNL55UavKe6SRuQ9Wuqqp6hGhT2iPQMJsZqEtTHCvoDIHYUUdPuvWmNbE0JctJ9PZe4vdZJmnDavo1+YFHPhZDXR6rVJKs0+lQ+UepFejFYpRLwVtQ7HMV9xhbuUGu9xtTmxqWbwZcEekKLQVWTbnwQRvBpC/SGgi3MY2plWIYghoOZCfzSoe7nWiH9GAKMXeLJgdtYv+8tM7PVAifk1a0a4sTMmQINVSAPAlL9kTT5Kg3R2JDocUrlDUoARTErpl7EV6xG0hoiU076pTDvxe6q1SnM8eXGfRdWdLspVi/zmk3gpzBA/nZMvCTKARuPZEI/HK7hV4ioOyEv7wfjX/4tcnkT9aWF4PMuFd4aZY3yrCKIZL8c8Jso8bxmodyjT+786IDIP9Bq9QccgKBm4OQeaJUEB/o1e1Yfk9L6TYa2eDG+KT8a02zr2ynIAxNhst6P+Qzi0YtBdUh8A9sO6ZFU/SvgCJ8wZ+ocOtdLeY8HzplrgPFflLRciQLQ9nIiwHv5GN7wFgCqjPh3JIX/n4jcQS9rVf0IUPJiojdrJ24Yjp9W1WnBDqR2ehSIJ6mf6UvNDSG/YVr4lEu/atoGROOYzPh8nvDNvLYcEfEJqIA9ZVHJgGXS4kqCCFpEwUESxy7v/WUjsrYIKNtGbzKc0v5V8o9JmL7PBz4/uAbff3nUfpIFE8yMv89o7sV512kEHRA50SGSlmo4UY0sdG9OTdfAJ64FJTFb2HtfExuKeTJ0WLL+knmLRmdJNAwyKspYKXo1HBLR02Z6/+3C/d5WMd+ig853sYGd7Iqn35ll22DvfXLDrLHJ9Utp+hzttmbPHtMXYjYAyBxOcG32oxYp7oWAXh0j0wgTGWjGGMpSkI31W6KHdvMGfZ49uOcTc8mW0/FFpdCBSyG6UbsNhient9PZ+vvwLVE8ozqDQydXtxu8MwHMOCeqeW63ohD99dDAHfrpnQET6y9GLcgfN8KHji9KrzxuA59Aku2oKcyZxLaI5Rv8nAWmHknu6lCLyfP3RePVvQNSA0RVCieFYanXRX/ynQY8OksHGQ1UVErUmx3Z7cz8rB/+vGNmrz9ATXO+VqT1t9cadEyXfUtsKebpErW6dMlwCUFrsldGiqymkJW8p/O9hX6S5QjhneDb2ozOg7f+Bo+IwmU8FoyQZPHWbFzvw92WwFX5TXrp5roDeo0nJJPvfC3NlOBSnbcnvL9WRw/HZhm+IOAz/QxzhxCTnxm9co2QoeYuTTFyUotzfw1czDG35e8QKjcjcJyDnsfqFtOlHPK+kOg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5bc62685-d67e-4388-6a56-08da0ea47542 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8774.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 21:14:33.3402 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iLny6RwOsYl4S3Jz9uJtfV4WU4vvmTMl3lqngSXsAr0OhCxZHXie1dvjwUH+4T4a X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0402MB3881 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220325_141446_731142_F7A1C8EB X-CRM114-Status: GOOD ( 20.99 ) X-Spam-Score: 0.8 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The code change refactor the bch geometry setting function, which still use the legacy bch setting as default option, while user may choose to use chips required minimum ecc strength by DT flag "fsl,u [...] Content analysis details: (0.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a01:111:f400:7e1b:0:0:0:614 listed in] [list.dnswl.org] 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 1.0 FORGED_SPF_HELO No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The code change refactor the bch geometry setting function, which still use the legacy bch setting as default option, while user may choose to use chips required minimum ecc strength by DT flag "fsl,use-minimum-ecc". It also improve the gpmi_check_ecc function to check if the selected ecc strength is strong enough. The driver uses legacy bch geometry settings by default, if the NAND chips oob size is less than 1KB. The legacy_set_geometry() sets the data chunk size(step_size) larger than oob size to make sure BBM locates in data chunk, then set the maximum ecc stength oob can hold. It always use unbalanced ECC layout, which ecc0 will cover both meta and data0 chunk. For all other cases,set the bch geometry by chip required strength and step size, which uses the minimum ecc strength chip required. It can be explicitly enabled by DT flag "fsl,use-minimum-ecc", but need to be en/disabled in both u-boot and kernel at the same time. Signed-off-by: Han Xu Tested-by: Sean Nyekjaer --- Changes in v2 - split the patch to two parts - change the commit log - add test tag --- drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 56 ++++++++++++++++------ 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c index d96899fa90b7..9a37f8cc663e 100644 --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c @@ -238,9 +238,14 @@ static void gpmi_dump_info(struct gpmi_nand_data *this) geo->block_mark_bit_offset); } -static inline bool gpmi_check_ecc(struct gpmi_nand_data *this) +static bool gpmi_check_ecc(struct gpmi_nand_data *this) { + struct nand_chip *chip = &this->nand; + struct mtd_info *mtd = nand_to_mtd(&this->nand); struct bch_geometry *geo = &this->bch_geometry; + const struct nand_ecc_props *requirements = + nanddev_get_ecc_requirements(&chip->base); + int corr, ds_corr; /* Do the sanity check. */ if (GPMI_IS_MXS(this)) { @@ -248,7 +253,22 @@ static inline bool gpmi_check_ecc(struct gpmi_nand_data *this) if (geo->gf_len == 14) return false; } - return geo->ecc_strength <= this->devdata->bch_max_ecc_strength; + + if (geo->ecc_strength > this->devdata->bch_max_ecc_strength) + return false; + + /* check ecc strength, same as nand_ecc_is_strong_enough() did */ + if (requirements->step_size) { + corr = mtd->writesize * geo->ecc_strength / + geo->ecc_chunk_size; + ds_corr = mtd->writesize * requirements->strength / + requirements->step_size; + if (corr < ds_corr || + geo->ecc_strength < requirements->strength) + return false; + } + + return true; } /* @@ -514,24 +534,32 @@ static int legacy_set_geometry(struct gpmi_nand_data *this) static int common_nfc_set_geometry(struct gpmi_nand_data *this) { struct nand_chip *chip = &this->nand; + struct mtd_info *mtd = nand_to_mtd(&this->nand); const struct nand_ecc_props *requirements = nanddev_get_ecc_requirements(&chip->base); + bool use_minimun_ecc; + int err; - if (chip->ecc.strength > 0 && chip->ecc.size > 0) - return set_geometry_by_ecc_info(this, chip->ecc.strength, - chip->ecc.size); - - if ((of_property_read_bool(this->dev->of_node, "fsl,use-minimum-ecc")) - || legacy_set_geometry(this)) { - if (!(requirements->strength > 0 && requirements->step_size > 0)) - return -EINVAL; + use_minimun_ecc = of_property_read_bool(this->dev->of_node, + "fsl,use-minimum-ecc"); - return set_geometry_by_ecc_info(this, - requirements->strength, - requirements->step_size); + /* use legacy bch geometry settings by default*/ + if ((!use_minimun_ecc && mtd->oobsize < 1024) || + !(requirements->strength > 0 && requirements->step_size > 0)) { + dev_dbg(this->dev, "use legacy bch geometry\n"); + err = legacy_set_geometry(this); + if (!err) + return 0; } - return 0; + /* otherwise use the minimum ecc nand chip required */ + dev_dbg(this->dev, "use minimum ecc bch geometry\n"); + err = set_geometry_by_ecc_info(this, requirements->strength, + requirements->step_size); + if (err) + dev_err(this->dev, "none of the bch geometry setting works\n"); + + return err; } /* Configures the geometry for BCH. */ From patchwork Fri Mar 25 21:14:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Xu X-Patchwork-Id: 1609586 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=DH5pMXUa; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256 header.s=selector2 header.b=oKqMycNT; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KQFHZ0syxz9s0B for ; Sat, 26 Mar 2022 08:15:38 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=l0yC48OZmvm0jqlljIcExgZ0YTT0YcwJVGe3CwNtUYE=; b=DH5pMXUamIZ3AV 2/BwhgpL2S1oPAewfvBimiqyi1zC7Lxb8ihVM24WNUUn7p1F3kgWZIsBpo0y22zBJLjanCt4vd2ts iM5BzlNAcoaAMISSUYBu6gWh7q+4jZ+1FLBCuUcsGt+kzyG87DG+Nf8IEzAsiAvOxaOz2gvFcb6t1 ZPaNx5Ia8VVTX6U+yp/G0ecGJTRLqwkp48svhCnCYqn5BhNy5aBwnw+3syfS5HdF9OYFWKeSvtNWo IeYnK1v8oKH2LeBF8tjYnSEIWJdUDYZw6r7PVkX5NcxjCKlcgj02NshJDVh/MVbsVvQirVClvoU7M ei1m0UTbEFYHjUPBrNvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nXrGv-003Jqv-2E; Fri, 25 Mar 2022 21:15:01 +0000 Received: from mail-am6eur05on20614.outbound.protection.outlook.com ([2a01:111:f400:7e1b::614] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nXrGj-003JkO-8S for linux-mtd@lists.infradead.org; Fri, 25 Mar 2022 21:14:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WnPHOMK+nZbCkV3+/P10qJjzeQrjCl7guTECL2xecBnediaxLLm3Mhvouv0P8pcj2BLOKyPRnJN3ulkFrEnOz2n1zR7msHsX57LdLwNvk/OJ9lIx7B13PSg3a+rY1N/Ymk1emiLGTZM6j6zUML8RNqyodjQY1xcQhvOE8LtzjjfzasXrA3Fk/du+cdIew28ragixvdM2SjxirtCLupwsioVwmZ4cuY73l4ty1KJcRrzffHsK4JdyL+4hYrfs6ndZ3B6PM1HWQ7jojGTHTpzYeBRTk1HL+IQapLXfr3mi7T4CufR+uUatcsXMMtFCeM1fO71Xod4HJD3NMHvf8psZJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QnFf1bco7rKsEHapUdvHlnGn/KujKQiNTFQAAYpy0HY=; b=POaHLYPstuvtjT3JG0lI8LXtwTOxYEC+xPHqapFTVb3DIUVglnBbzog19M3YHIRZqbG1H5HjupVZeZOfL4tgo7iIx8ne0kokUpH7kSBveY4NhDqqq2J2jqJUqDDtt/yyfkYWLIpXMP8CGgYXDcIPYdVrtrDMTjCvV1QXwMsAt1+MjdsU+mz2v1A8wNef2ekV8U/D+WIQiIrQylzIvfmvEQaRqNNO5dxFnt9JzD3y0GNept2/LV1I9YIvhQbzqFt12nHMo/THpS2xk/OGtzfoEA2TyTmB+wtf3DIjmUN1pyiOT8qg/mY1yOQ98Yekf3AakSrOA7bzf6oClzKYw8Sjzg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QnFf1bco7rKsEHapUdvHlnGn/KujKQiNTFQAAYpy0HY=; b=oKqMycNTPHJxGiz5qDmqjmQMn0lC5fSZVqbSyuKhlollQJVH2CAJ06vAUlqyAu+cAZcEt99pXboLrCBqg7HEpbm8bTL3j3emwPf7ndntnmWF8mwdlV4ofDqaQ1HtlKAC534g8kThONKICUxBeBpa19R/7HF3SVv4aSUTyT7Rl78= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8774.eurprd04.prod.outlook.com (2603:10a6:10:2e1::21) by DB3PR0402MB3881.eurprd04.prod.outlook.com (2603:10a6:8:12::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.19; Fri, 25 Mar 2022 21:14:35 +0000 Received: from DU2PR04MB8774.eurprd04.prod.outlook.com ([fe80::5416:5d1:cc34:ca9b]) by DU2PR04MB8774.eurprd04.prod.outlook.com ([fe80::5416:5d1:cc34:ca9b%7]) with mapi id 15.20.5102.019; Fri, 25 Mar 2022 21:14:35 +0000 From: Han Xu To: sbabic@denx.de, sean@geanix.com, frieder.schrempf@kontron.de, festevam@gmail.com Cc: ye.li@nxp.com, peng.fan@nxp.com, han.xu@nxp.com, miquel.raynal@bootlin.com, linux-mtd@lists.infradead.org Subject: [PATCH v2 2/2] mtd: rawnand: gpmi: Add large oob bch setting support Date: Fri, 25 Mar 2022 16:14:11 -0500 Message-Id: <20220325211411.30714-2-han.xu@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220325211411.30714-1-han.xu@nxp.com> References: <20220325211411.30714-1-han.xu@nxp.com> X-ClientProxiedBy: BYAPR01CA0057.prod.exchangelabs.com (2603:10b6:a03:94::34) To DU2PR04MB8774.eurprd04.prod.outlook.com (2603:10a6:10:2e1::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b2fb61e3-294c-49b6-8e9c-08da0ea476c4 X-MS-TrafficTypeDiagnostic: DB3PR0402MB3881:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7YdLAq7lP3GrE2NXfnw1yj8fGGrIMgW+US4DrByN3dITJmWlB7WCOiWerY5jBKA4tEXte7k53/HEUfrLjm8MQVyYQ0hT5ofxtR4O5NxQMdlfmUNO7hB6C/aIX8c6wTl8FQNMyTcXaFvlvCDr2rbHaUPM9DQ85OggYb9umbZ5+LBZxEf5fKms9yIBdIgg8+1PqG1ADJdXqWRryvheHS1LEiJ73P2sqTeNkmPMIQvYvZcujgwyFboZ6F9L+h0vDt3TmzARvu1yMm5ICdq8hUfzb5uy2HmiCcw6R2hi8fk6wgFe/H5cjpLbh/5HKLEWLcjMdcm+CP69r2U/s29LkATuWWGBOx3ifRPw2+T8iPyiCAcAI2K6bqtQ6NJ8LFV5TLfRXWA2AjHa1fVUnk9vBt4HMUbDVxdAQrFne7GA9KvxJjglF/1A2r3BDEizMdz74yDDO1IW/9MEcBFekuSMVNuTyXrrL8rIJtI1ZRTpSbawxa6CwU2nMtxPrF06EzjPUoxXURMzGGT4ym4VpA+J4xgi0sDcmnZFuTQHK4XwQsVBuuSGAACRWtZ3DAviil4aCNelKPmRZ7Vyg/r4d4FVaWXjGgazDYheovVmHzxGzM55Tqlxwv2BJni53AuYziIbJYc+X6ZLtqpcqEFdsNFtkq7Y4QnIlS6doFTijxWOLHvBLV38uIqFMD/54BcCxd4DiiyFDB6VY+jE7aQ7QLgqTzdFVQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU2PR04MB8774.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(30864003)(316002)(36756003)(83380400001)(186003)(44832011)(8676002)(66476007)(2616005)(4326008)(66556008)(66946007)(5660300002)(38100700002)(1076003)(6486002)(8936002)(6512007)(38350700002)(52116002)(2906002)(6506007)(26005)(86362001)(508600001)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Mp3UKm7So1wmQW4QGIdlthzLdmsWVXj2zrlnaCaldsBTOVg5kCeYBM1L3t9rhx9fL2zWi9qB+rbBfKY35d0O0x1DJF1QQkAYiSlXb7V5HcgtIBJHXBBu8JeSMF/isgikFLlQyOlCTxZiaGCY6DJA3zBys3v7r+yhHiseKCxDNYQvjq25dwKA31/IP2Mtu1xYDSIYKSoyzMvMcOMzBMjj0equoi4wSdgPBY9wc2hdF3nRQer1uc5GJ3wvB00/iwBx2+gBTjxQU5dM9SEDeGNIKYF1y9b0PMs9IXAXHqLbpbsbNbXKmeZlbviDk+aE0JXGZobnQAjLyvkITuUyd3z3gTkh52+ySKZs755ZmK6oc9Yjq7ST8YvMWYJomZ7fuoSqSQF8Vy9luvU6iLtLjMz6+kxYel/WR+xBjF/G273KA2nG5wFVuVmRHim9jhvzvP/IVaXToqI0uGT4D8v1XP8r3hl0lT9ZY7ORmbQbfbYNhwI/IDR6SFsx2rKLDIlM/SE2eXWQB82oHkwNwlAJWKqIGF460ndjP17bc+XQ9W4CL85IdyLyxPd2Vnbgt3SDV/dOn7YMlwWpOAUddPRNH6RT6rTGIgCuMPp1hHR27mFaDcsnTaiH63xHBFLjYZ6TDfS9A/aNWZ7ohjQ9s1TTxCd/C+Fba+Oxs4wU21R8kVu2V7qQbJqa5fwVSkOae5j5DoSjFhQotTZkq7TfKTmgSG70kPEEgGqd3GtEo3ff+rC4be2ipBH1mn4MPapnyGFVsK9MUWBqUSPYwCCiB/gDUD0kY3ntmDrbSXLEawD80jGCxx/bxuwN3f1OswkFNesZ5geHE0JaaTNbBgDjR38Lr37fPGQI0Kr1ar1gsR+yIfAZFTNRgQ611M58hw3e9hBHC5HZL45RtYvaJt1N3P2B9q1JCnNsSC2A8xfGHAYF/lfLq9yDSuTopaJgNN38pF88PO1IKa3UI8x3JK5dBwce+XgFkYF5nm4UtL+uKPm7S1UlYrL+8d0i7i1Hqilp/c78LdsMHHka6PxhWSn1HxbgKNkDgPX5Ffvn8D603GmvQTdkqacNNKnfku6eGlrn3TvnCoDzKfgQClgShpcHlvJvG7mglTfe3NozTRS9Rp1kdNCEU4WI21o4yD2Ry+xemDBtYu9gCGPlhLpKVuZqsZrWDrExK8tD0oUuSn8p0LMBpjT2J25LyF7co70hRW5xVQk/WRt0vUz2D7SnGnOuQfAmiIOuTK8maoL6KBnZfD/OacY0Lw+3h3PKf0EsQG0A44lIupv3G1dM8KBd3ahskQp51SXIszsvXm8i6Ig/JcQDu1qmF/eH3MfTjYiklOwU3PILg/Osk0N777xQxwsgRGNfKkFqY3AeC0opF4SS7+1l2L10mX4h0a8x7n4740a5XoeqGaJaUdIcQ5bAUQUqnv/uo3vz5stLkMS/4yIZEYFxXIrhKVXkjrCD1z38RKUdZdlr3TeOA26ptu0xCfQqt44GLQV0cV3bU5FyijfTdvJkKYXyuVY2/+nn6YUOMvlj/j4rANbRQcIWgAF6yQlwZmZbXmRIJHZbKM076g5ovD8Z96NyJONyMB71oLHNwl+Kx7r12MHLFFesA897CucBf7GaUr98j1+FKzu7hRS2RhG9xZryP2swW1d4vbvUoxT6vOcWYG3cruldH9HiK0LDy/lKDz5w/7L3Gjth6UG/oH0hXZBns2ZjleDwBJC7n9wh96xUJQp1l/NddQ2WDAw7oCk1yKbByQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b2fb61e3-294c-49b6-8e9c-08da0ea476c4 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8774.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2022 21:14:35.8877 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eGAHNxYSI1S+4xeh9TCX0JaJq7E0gkgfj+hnsA/9xg5GVivCZqA79HndNqfpyCXm X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0402MB3881 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220325_141449_339547_D46B911D X-CRM114-Status: GOOD ( 24.19 ) X-Spam-Score: 0.8 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The code change proposes a new way to set bch geometry for large oob NAND (oobsize > 1KB). In this case, previous implementation can NOT guarantee the bad block mark always locates in data chunk, so w [...] Content analysis details: (0.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a01:111:f400:7e1b:0:0:0:614 listed in] [list.dnswl.org] 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 1.0 FORGED_SPF_HELO No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The code change proposes a new way to set bch geometry for large oob NAND (oobsize > 1KB). In this case, previous implementation can NOT guarantee the bad block mark always locates in data chunk, so we need a new way to do it, the general idea is, 1.Try all ECC strength from the minimum value required by NAND chip to the maximum one that controller can provide, any ECC strength makes the BBM locate in data chunk can be eligible. 2.If none of them works, using separate ECC for meta, which will add one extra ecc with the same ECC strength as other data chunks. This extra ECC can guarantee BBM located in data chunk, also we need to check if oob can afford it. Signed-off-by: Han Xu --- Changes in v2: - split the large oob part to a single patch --- drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 247 ++++++++++++++++++--- drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h | 12 +- 2 files changed, 228 insertions(+), 31 deletions(-) diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c index 9a37f8cc663e..0b2193bc7e08 100644 --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c @@ -218,7 +218,8 @@ static void gpmi_dump_info(struct gpmi_nand_data *this) "ECC Strength : %u\n" "Page Size in Bytes : %u\n" "Metadata Size in Bytes : %u\n" - "ECC Chunk Size in Bytes: %u\n" + "ECC Chunk0 Size in Bytes: %u\n" + "ECC Chunkn Size in Bytes: %u\n" "ECC Chunk Count : %u\n" "Payload Size in Bytes : %u\n" "Auxiliary Size in Bytes: %u\n" @@ -229,7 +230,8 @@ static void gpmi_dump_info(struct gpmi_nand_data *this) geo->ecc_strength, geo->page_size, geo->metadata_size, - geo->ecc_chunk_size, + geo->ecc_chunk0_size, + geo->ecc_chunkn_size, geo->ecc_chunk_count, geo->payload_size, geo->auxiliary_size, @@ -260,7 +262,7 @@ static bool gpmi_check_ecc(struct gpmi_nand_data *this) /* check ecc strength, same as nand_ecc_is_strong_enough() did */ if (requirements->step_size) { corr = mtd->writesize * geo->ecc_strength / - geo->ecc_chunk_size; + geo->ecc_chunkn_size; ds_corr = mtd->writesize * requirements->strength / requirements->step_size; if (corr < ds_corr || @@ -271,6 +273,38 @@ static bool gpmi_check_ecc(struct gpmi_nand_data *this) return true; } +/* check if bbm locates in data chunk rather than ecc chunk */ +static bool bbm_in_data_chunk(struct gpmi_nand_data *this, + unsigned int *chunk_num) +{ + struct bch_geometry *geo = &this->bch_geometry; + struct nand_chip *chip = &this->nand; + struct mtd_info *mtd = nand_to_mtd(chip); + unsigned int i, j; + + if (geo->ecc_chunk0_size != geo->ecc_chunkn_size) { + dev_err(this->dev, "The size of chunk0 must equal to chunkn\n"); + return false; + } + + i = (mtd->writesize * 8 - geo->metadata_size * 8) / + (geo->gf_len * geo->ecc_strength + + geo->ecc_chunkn_size * 8); + + j = (mtd->writesize * 8 - geo->metadata_size * 8) - + (geo->gf_len * geo->ecc_strength + + geo->ecc_chunkn_size * 8) * i; + + if (j < geo->ecc_chunkn_size * 8) { + *chunk_num = i+1; + dev_dbg(this->dev, "Set ecc to %d and bbm in chunk %d\n", + geo->ecc_strength, *chunk_num); + return true; + } + + return false; +} + /* * If we can get the ECC information from the nand chip, we do not * need to calculate them ourselves. @@ -300,13 +334,14 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this, nanddev_get_ecc_requirements(&chip->base)->step_size); return -EINVAL; } - geo->ecc_chunk_size = ecc_step; + geo->ecc_chunk0_size = ecc_step; + geo->ecc_chunkn_size = ecc_step; geo->ecc_strength = round_up(ecc_strength, 2); if (!gpmi_check_ecc(this)) return -EINVAL; /* Keep the C >= O */ - if (geo->ecc_chunk_size < mtd->oobsize) { + if (geo->ecc_chunkn_size < mtd->oobsize) { dev_err(this->dev, "unsupported nand chip. ecc size: %d, oob size : %d\n", ecc_step, mtd->oobsize); @@ -316,7 +351,7 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this, /* The default value, see comment in the legacy_set_geometry(). */ geo->metadata_size = 10; - geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunk_size; + geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunkn_size; /* * Now, the NAND chip with 2K page(data chunk is 512byte) shows below: @@ -419,6 +454,132 @@ static inline int get_ecc_strength(struct gpmi_nand_data *this) return round_down(ecc_strength, 2); } +static int set_geometry_for_large_oob(struct gpmi_nand_data *this) +{ + struct bch_geometry *geo = &this->bch_geometry; + struct nand_chip *chip = &this->nand; + struct mtd_info *mtd = nand_to_mtd(chip); + const struct nand_ecc_props *requirements = + nanddev_get_ecc_requirements(&chip->base); + unsigned int block_mark_bit_offset; + unsigned int max_ecc; + unsigned int bbm_chunk; + unsigned int i; + + /* sanity check for the minimum ecc nand required */ + if (!(requirements->strength > 0 && + requirements->step_size > 0)) + return -EINVAL; + geo->ecc_strength = requirements->strength; + + /* check if platform can support this nand */ + if (!gpmi_check_ecc(this)) { + dev_err(this->dev, + "unsupported NAND chip, minimum ecc required %d\n", + geo->ecc_strength); + return -EINVAL; + } + + /* calculate the maximum ecc platform can support*/ + geo->metadata_size = 10; + geo->gf_len = 14; + geo->ecc_chunk0_size = 1024; + geo->ecc_chunkn_size = 1024; + geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunkn_size; + max_ecc = min(get_ecc_strength(this), + this->devdata->bch_max_ecc_strength); + + /* search a supported ecc strength that makes bbm */ + /* located in data chunk */ + geo->ecc_strength = requirements->strength; + while (!(geo->ecc_strength > max_ecc)) { + if (bbm_in_data_chunk(this, &bbm_chunk)) + goto geo_setting; + geo->ecc_strength += 2; + } + + /* if none of them works, keep using the minimum ecc */ + /* nand required but changing ecc page layout */ + geo->ecc_strength = requirements->strength; + /* add extra ecc for meta data */ + geo->ecc_chunk0_size = 0; + geo->ecc_chunk_count = (mtd->writesize / geo->ecc_chunkn_size) + 1; + geo->ecc_for_meta = 1; + /* check if oob can afford this extra ecc chunk */ + if (mtd->oobsize * 8 < geo->metadata_size * 8 + + geo->gf_len * geo->ecc_strength * geo->ecc_chunk_count) { + dev_err(this->dev, "unsupported NAND chip with new layout\n"); + return -EINVAL; + } + + /* calculate in which chunk bbm located */ + bbm_chunk = (mtd->writesize * 8 - geo->metadata_size * 8 - + geo->gf_len * geo->ecc_strength) / + (geo->gf_len * geo->ecc_strength + + geo->ecc_chunkn_size * 8) + 1; + +geo_setting: + + geo->page_size = mtd->writesize + geo->metadata_size + + (geo->gf_len * geo->ecc_strength * geo->ecc_chunk_count) / 8; + geo->payload_size = mtd->writesize; + + /* + * The auxiliary buffer contains the metadata and the ECC status. The + * metadata is padded to the nearest 32-bit boundary. The ECC status + * contains one byte for every ECC chunk, and is also padded to the + * nearest 32-bit boundary. + */ + geo->auxiliary_status_offset = ALIGN(geo->metadata_size, 4); + geo->auxiliary_size = ALIGN(geo->metadata_size, 4) + + ALIGN(geo->ecc_chunk_count, 4); + + if (!this->swap_block_mark) + return 0; + + /* calculate the number of ecc chunk behind the bbm */ + i = (mtd->writesize / geo->ecc_chunkn_size) - bbm_chunk + 1; + + block_mark_bit_offset = mtd->writesize * 8 - + (geo->ecc_strength * geo->gf_len * (geo->ecc_chunk_count - i) + + geo->metadata_size * 8); + + geo->block_mark_byte_offset = block_mark_bit_offset / 8; + geo->block_mark_bit_offset = block_mark_bit_offset % 8; + + dev_dbg(this->dev, "BCH Geometry :\n" + "GF length : %u\n" + "ECC Strength : %u\n" + "Page Size in Bytes : %u\n" + "Metadata Size in Bytes : %u\n" + "ECC Chunk0 Size in Bytes: %u\n" + "ECC Chunkn Size in Bytes: %u\n" + "ECC Chunk Count : %u\n" + "Payload Size in Bytes : %u\n" + "Auxiliary Size in Bytes: %u\n" + "Auxiliary Status Offset: %u\n" + "Block Mark Byte Offset : %u\n" + "Block Mark Bit Offset : %u\n" + "Block Mark in chunk : %u\n" + "Ecc for Meta data : %u\n", + geo->gf_len, + geo->ecc_strength, + geo->page_size, + geo->metadata_size, + geo->ecc_chunk0_size, + geo->ecc_chunkn_size, + geo->ecc_chunk_count, + geo->payload_size, + geo->auxiliary_size, + geo->auxiliary_status_offset, + geo->block_mark_byte_offset, + geo->block_mark_bit_offset, + bbm_chunk, + geo->ecc_for_meta); + + return 0; +} + static int legacy_set_geometry(struct gpmi_nand_data *this) { struct bch_geometry *geo = &this->bch_geometry; @@ -438,13 +599,15 @@ static int legacy_set_geometry(struct gpmi_nand_data *this) geo->gf_len = 13; /* The default for chunk size. */ - geo->ecc_chunk_size = 512; - while (geo->ecc_chunk_size < mtd->oobsize) { - geo->ecc_chunk_size *= 2; /* keep C >= O */ + geo->ecc_chunk0_size = 512; + geo->ecc_chunkn_size = 512; + while (geo->ecc_chunkn_size < mtd->oobsize) { + geo->ecc_chunk0_size *= 2; /* keep C >= O */ + geo->ecc_chunkn_size *= 2; /* keep C >= O */ geo->gf_len = 14; } - geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunk_size; + geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunkn_size; /* We use the same ECC strength for all chunks. */ geo->ecc_strength = get_ecc_strength(this); @@ -552,6 +715,14 @@ static int common_nfc_set_geometry(struct gpmi_nand_data *this) return 0; } + /* for large oob nand */ + if (mtd->oobsize > 1024) { + dev_dbg(this->dev, "use large oob bch geometry\n"); + err = set_geometry_for_large_oob(this); + if (!err) + return 0; + } + /* otherwise use the minimum ecc nand chip required */ dev_dbg(this->dev, "use minimum ecc bch geometry\n"); err = set_geometry_by_ecc_info(this, requirements->strength, @@ -871,7 +1042,7 @@ static int gpmi_raw_len_to_len(struct gpmi_nand_data *this, int raw_len) * we are passed in exec_op. Calculate the data length from it. */ if (this->bch) - return ALIGN_DOWN(raw_len, this->bch_geometry.ecc_chunk_size); + return ALIGN_DOWN(raw_len, this->bch_geometry.ecc_chunkn_size); else return raw_len; } @@ -1263,7 +1434,7 @@ static int gpmi_count_bitflips(struct nand_chip *chip, void *buf, int first, /* Read ECC bytes into our internal raw_buffer */ offset = nfc_geo->metadata_size * 8; - offset += ((8 * nfc_geo->ecc_chunk_size) + eccbits) * (i + 1); + offset += ((8 * nfc_geo->ecc_chunkn_size) + eccbits) * (i + 1); offset -= eccbits; bitoffset = offset % 8; eccbytes = DIV_ROUND_UP(offset + eccbits, 8); @@ -1300,16 +1471,16 @@ static int gpmi_count_bitflips(struct nand_chip *chip, void *buf, int first, if (i == 0) { /* The first block includes metadata */ flips = nand_check_erased_ecc_chunk( - buf + i * nfc_geo->ecc_chunk_size, - nfc_geo->ecc_chunk_size, + buf + i * nfc_geo->ecc_chunkn_size, + nfc_geo->ecc_chunkn_size, eccbuf, eccbytes, this->auxiliary_virt, nfc_geo->metadata_size, nfc_geo->ecc_strength); } else { flips = nand_check_erased_ecc_chunk( - buf + i * nfc_geo->ecc_chunk_size, - nfc_geo->ecc_chunk_size, + buf + i * nfc_geo->ecc_chunkn_size, + nfc_geo->ecc_chunkn_size, eccbuf, eccbytes, NULL, 0, nfc_geo->ecc_strength); @@ -1338,20 +1509,21 @@ static void gpmi_bch_layout_std(struct gpmi_nand_data *this) struct bch_geometry *geo = &this->bch_geometry; unsigned int ecc_strength = geo->ecc_strength >> 1; unsigned int gf_len = geo->gf_len; - unsigned int block_size = geo->ecc_chunk_size; + unsigned int block0_size = geo->ecc_chunk0_size; + unsigned int blockn_size = geo->ecc_chunkn_size; this->bch_flashlayout0 = BF_BCH_FLASH0LAYOUT0_NBLOCKS(geo->ecc_chunk_count - 1) | BF_BCH_FLASH0LAYOUT0_META_SIZE(geo->metadata_size) | BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this) | BF_BCH_FLASH0LAYOUT0_GF(gf_len, this) | - BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size, this); + BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block0_size, this); this->bch_flashlayout1 = BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(geo->page_size) | BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this) | BF_BCH_FLASH0LAYOUT1_GF(gf_len, this) | - BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size, this); + BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(blockn_size, this); } static int gpmi_ecc_read_page(struct nand_chip *chip, uint8_t *buf, @@ -1434,9 +1606,22 @@ static int gpmi_ecc_read_subpage(struct nand_chip *chip, uint32_t offs, } } + /* + * if there is an ECC dedicate for meta: + * - need to add an extra ECC size when calculating col and page_size, + * if the meta size is NOT zero. + * - chunk0 size need to set to the same size as other chunks, + * if the meta size is zero. + */ + meta = geo->metadata_size; if (first) { - col = meta + (size + ecc_parity_size) * first; + if (geo->ecc_for_meta) + col = meta + ecc_parity_size + + (size + ecc_parity_size) * first; + else + col = meta + (size + ecc_parity_size) * first; + meta = 0; buf = buf + first * size; } @@ -1444,19 +1629,27 @@ static int gpmi_ecc_read_subpage(struct nand_chip *chip, uint32_t offs, ecc_parity_size = geo->gf_len * geo->ecc_strength / 8; n = last - first + 1; - page_size = meta + (size + ecc_parity_size) * n; + + if (geo->ecc_for_meta && meta) + page_size = meta + ecc_parity_size + + (size + ecc_parity_size) * n; + else + page_size = meta + (size + ecc_parity_size) * n; + ecc_strength = geo->ecc_strength >> 1; - this->bch_flashlayout0 = BF_BCH_FLASH0LAYOUT0_NBLOCKS(n - 1) | + this->bch_flashlayout0 = BF_BCH_FLASH0LAYOUT0_NBLOCKS( + (geo->ecc_for_meta ? n : n - 1)) | BF_BCH_FLASH0LAYOUT0_META_SIZE(meta) | BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this) | BF_BCH_FLASH0LAYOUT0_GF(geo->gf_len, this) | - BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(geo->ecc_chunk_size, this); + BF_BCH_FLASH0LAYOUT0_DATA0_SIZE((geo->ecc_for_meta ? + 0 : geo->ecc_chunk0_size), this); this->bch_flashlayout1 = BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(page_size) | BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this) | BF_BCH_FLASH0LAYOUT1_GF(geo->gf_len, this) | - BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(geo->ecc_chunk_size, this); + BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(geo->ecc_chunkn_size, this); this->bch = true; @@ -1625,7 +1818,7 @@ static int gpmi_ecc_read_page_raw(struct nand_chip *chip, uint8_t *buf, struct mtd_info *mtd = nand_to_mtd(chip); struct gpmi_nand_data *this = nand_get_controller_data(chip); struct bch_geometry *nfc_geo = &this->bch_geometry; - int eccsize = nfc_geo->ecc_chunk_size; + int eccsize = nfc_geo->ecc_chunkn_size; int eccbits = nfc_geo->ecc_strength * nfc_geo->gf_len; u8 *tmp_buf = this->raw_buffer; size_t src_bit_off; @@ -1710,7 +1903,7 @@ static int gpmi_ecc_write_page_raw(struct nand_chip *chip, const uint8_t *buf, struct mtd_info *mtd = nand_to_mtd(chip); struct gpmi_nand_data *this = nand_get_controller_data(chip); struct bch_geometry *nfc_geo = &this->bch_geometry; - int eccsize = nfc_geo->ecc_chunk_size; + int eccsize = nfc_geo->ecc_chunkn_size; int eccbits = nfc_geo->ecc_strength * nfc_geo->gf_len; u8 *tmp_buf = this->raw_buffer; uint8_t *oob = chip->oob_poi; @@ -2084,7 +2277,7 @@ static int gpmi_init_last(struct gpmi_nand_data *this) ecc->read_oob_raw = gpmi_ecc_read_oob_raw; ecc->write_oob_raw = gpmi_ecc_write_oob_raw; ecc->engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; - ecc->size = bch_geo->ecc_chunk_size; + ecc->size = bch_geo->ecc_chunkn_size; ecc->strength = bch_geo->ecc_strength; mtd_set_ooblayout(mtd, &gpmi_ooblayout_ops); diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h index 5e1c3ddae5f8..9ade40d0f586 100644 --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h @@ -30,9 +30,9 @@ struct resources { * @page_size: The size, in bytes, of a physical page, including * both data and OOB. * @metadata_size: The size, in bytes, of the metadata. - * @ecc_chunk_size: The size, in bytes, of a single ECC chunk. Note - * the first chunk in the page includes both data and - * metadata, so it's a bit larger than this value. + * @ecc_chunk0_size: The size, in bytes, of a first ECC chunk. + * @ecc_chunkn_size: The size, in bytes, of a single ECC chunk after + * the first chunk in the page. * @ecc_chunk_count: The number of ECC chunks in the page, * @payload_size: The size, in bytes, of the payload buffer. * @auxiliary_size: The size, in bytes, of the auxiliary buffer. @@ -42,19 +42,23 @@ struct resources { * which the underlying physical block mark appears. * @block_mark_bit_offset: The bit offset into the ECC-based page view at * which the underlying physical block mark appears. + * @ecc_for_meta: The flag to indicate if there is a dedicate ecc + * for meta. */ struct bch_geometry { unsigned int gf_len; unsigned int ecc_strength; unsigned int page_size; unsigned int metadata_size; - unsigned int ecc_chunk_size; + unsigned int ecc_chunk0_size; + unsigned int ecc_chunkn_size; unsigned int ecc_chunk_count; unsigned int payload_size; unsigned int auxiliary_size; unsigned int auxiliary_status_offset; unsigned int block_mark_byte_offset; unsigned int block_mark_bit_offset; + unsigned int ecc_for_meta; /* ECC for meta data */ }; /**