From patchwork Mon Apr 4 19:54:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Xu X-Patchwork-Id: 1613162 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=xlIvDN+8; 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=p3V7nA8L; 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 4KXMNL18Ftz9sCD for ; Tue, 5 Apr 2022 06:10:58 +1000 (AEST) 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=gcjr3j9n/MQUjNc0Vs7gdxx8vIJfX2bRA/o+WRjX6dQ=; b=xlIvDN+88H6jJs 3EiGprYtb3DKb0UBMEEXYUbgg2e1eCgQkTtSnAp0DLDRFcj1XgT1QyhvyK7Z66d5CoVacWmvDwnc+ 3Vn7ul7948tBeYEyVswvRXGI+/8Ql8KMu1BzSfniVtnDN5n5wYUIYtLZ1uBbwJy0Pa+X8MdwLNKcS ffQSoPgYBc1pGsyetqUXL98jAc6NZIi/02gb7z1vj1I9iZi+0fM/wXovU7Lwa7oodeG66iLoWzK0M mM1h+Q6zOa4aFPwirH22TsIYYpXhnraOqBP7B/JCV4HvHeFZqAaebdHMGguDP/D4KCO3YVelL4+AA QldtJdNryO93lteGiKwQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbT1m-00GKBJ-2B; Mon, 04 Apr 2022 20:10:18 +0000 Received: from mail-vi1eur05on2061f.outbound.protection.outlook.com ([2a01:111:f400:7d00::61f] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbT1i-00GKAA-OA for linux-mtd@lists.infradead.org; Mon, 04 Apr 2022 20:10:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UiymYYbKWA5kI1Xu8TZ2WZdOGdSaNUGyBBz3+qcSosVMbjumjbYmf+rAqY/sj6h/ftHCXjsBMiNuiSFueF+OMP+2fPCquI4EW9Ob5JB+yn5TN7XyCO9vF2/EWE1hGXn7t+++9VWgwKaCnqgmtGk2J4XHhq78LKRdfgiTyTu9/+1TJ6UCtuNggsD1AxkqwMrZkpqThzIdJwKQ6paW3CvyC4jf9fqY+isw4QmiWwKIqdtyHbnlSRXV5i5fD4LEi28K6XeW8ZPOtX8ZgpzKRJvtxz60UwWIbbjRWOll6idL0ZdQSD39zJAzcI8BKdOdnGuiVIQlqPpWZVpT2Q8xqqQq9Q== 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=aqdEMlt5lsSw1hyIJp+16Lfm1PrSDbuE9kqGrKUvBps=; b=P+/LZgPUPo3oZTa4+Oqt0ED0EBaZSsX6yy+irYHDRBfp1V+0vNPpQF1j1GUC8pld2jTNxykFupfgS2Kf/zk/7jD6adBM4V8GBJp6j6LTGbfu/3A7HyW1pvJh1EENfAMIODLKYy6RA8a+U+6oak8Qw8i61N8GZzSeu1itO5kkzUQCpgzb5LaJYP/4+ZvJqKUzo76NaE0qJrfaLkr3NFXt4+MWMjZntQvU5CeHr3EFO66oOFNnbvjzIeYufSq3CN2iYw23qEZm9imtjsumEQV/Ew49SFFNHT4ZSeFIg1aIGa4afJMumbDwu5HqJeLpMfikPkuMIxTL/Sq4hlWUQVeneQ== 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=aqdEMlt5lsSw1hyIJp+16Lfm1PrSDbuE9kqGrKUvBps=; b=p3V7nA8Lv3Eb3IVs3WWCrwE0xj2liY8Hq2ur9R7mXMGnDgddnui71T5GkwLvlQBnfGLBNODzKSGBjjRDe/76YuimHWskmy7QWgNqz87XG2BxJBx+ASKi5G3nrTtLxJia+Uveqi1bKxNVwDIEyYtEmSjkzNzPuzrzkIp1WKNtY1A= 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 DB8PR04MB7164.eurprd04.prod.outlook.com (2603:10a6:10:129::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.31; Mon, 4 Apr 2022 19:54:42 +0000 Received: from DU2PR04MB8774.eurprd04.prod.outlook.com ([fe80::b048:39cb:7748:ed56]) by DU2PR04MB8774.eurprd04.prod.outlook.com ([fe80::b048:39cb:7748:ed56%7]) with mapi id 15.20.5123.031; Mon, 4 Apr 2022 19:54:42 +0000 From: Han Xu To: 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 v3 1/4] mtd: rawnand: gpmi: Refactor bch geometry settings function Date: Mon, 4 Apr 2022 14:54:24 -0500 Message-Id: <20220404195427.8871-1-han.xu@nxp.com> X-Mailer: git-send-email 2.17.1 X-ClientProxiedBy: SN4PR0501CA0010.namprd05.prod.outlook.com (2603:10b6:803:40::23) 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: cd8eea88-3f45-4091-622d-08da1674f568 X-MS-TrafficTypeDiagnostic: DB8PR04MB7164: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: Sf/eO+pX0ehPFA90KykTDImk0tWEuaaA6TnHFzs9fbe7vjbW56xp4e2Gr+Ab9z+6SRk2GDzAf5K9FN8uZmS6+St1m8bATIxaOimjbZBMk4PxxXp0SLQM51GJkt6Kp1FnfX/T/Ig/eVIq9k9371wEA/Ni4Gy54/acM/es978VmtRPexa1XGreC8cjDEb+Wju3xCvz7p2e/de0jgOlOWA0BGCYHk/poE9t+dr7DdCPgeP7RcXGHJu1W8B9aN5dx5POdG2G4fjHw2m9kDAM1Yv6ofuj7PJ4ArE3wjj4cqDOEv4vwPxP7O0FWONOLlbyki6Igo0SEIWbHxcUj/4SFjdhZykHsCOqPYDrx0tTBkR1z867kWoeu8coptFSacBOioQbDVZbiY3BKIVOGFU+9lKvhzmGElrtiXDEUVttYb59JTqIVcXCMzqVQEHxyxJVCIjCh/LYKuN7C01gIr2FfLFdTXz2DvC2oofcR4SP/xtbc4IDEHrZT1yqAapzhn7BSm/vSVGLaUPGyxvfWqIomrnO0GQ3c7AXwiJEZYZFfM6AhWYG2qA+CaCI+xlQgNNSfT9l+0MsSnLlOzW+hxiKJCAYD+/6c8E55YB9AsYaPTibRm+jqAcfPErf0CiUtAxCPpSbL/vhaSzz6ZG4TJ2NaOM2I4eKuI1BmW3rakuAxMSy2xAhyQEXVBsPxwYAOnoqruPpt2UMuAypSFEZ37K89fZ6NQ== 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)(4326008)(8676002)(38100700002)(66476007)(66556008)(508600001)(66946007)(1076003)(8936002)(38350700002)(6512007)(52116002)(5660300002)(2616005)(6506007)(36756003)(316002)(2906002)(6666004)(44832011)(186003)(26005)(83380400001)(6486002)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CPWfTaORuZKYtLmutcjR+MTQVQMVPkiN6K5WCkw765Ydk4qA4uRSbhfMcssqgamQjlc/1r4O2ZM+Lfkn2pReiAZbnbduUcGzIxsXvt8LGie3qVJ69dVb5kDET6lOQ0qwDGNLZxZ3JJq4RIoXc+OeSLbe0/C7Moy33Flpt9xbp1f+rstSOv81sv5BNs83q71i2i1XjwXdjZ4zQ/PydG3c2QSUS6BiO4gy3ICUlM8EtqdCqMMU7W0jZ/GzGHy7Tmqx/pvKmtg1Yhk4fHsqlojazyr/FMSBOCFRZ967zz2sghRkABHvbgbafgCR2R4HNUYxxrRbJ9n0ppT6sMZj7rYDxeWtjsWesT9WCkMbdXTtmudEvfaB/+D4ZLcSlufofb2s7EeZuBH9IpJKdJXDY5EPRFp4KK817cb6mjC8l/g7pAF63lCeNYCzlaPLPrU1xgoLqEIWTIJ2/ZvWENctjk4olQtHPjPxc8w5C0rZHQkYjhixiaW5Lx0Qp7Rf2WAOH+mu1nt+DNixzwUW/hYn3Xo1QlnD8P/eHOcwja/BNqFZREifiEMqoFHiP37timT6ph9lJXtvR1xTZ2pyRK8W4mT/BfUeA7L9fBsz72j+JV0w16rP5VC9KE7mHA2F3Rkcwn7ZZr8pYAkdcRzfjQBPqfAuNQRgEZouJKcIa22QxVePbZfqHKQrpHbzW/l/JHo1LLQarognQMghx84jEF/whwR93oJCuTo6GsXkTDQq832tHbB/Nr10h4ZgN5986D5zv2R49uC59Ouv5mwJd7S1B7DVCNr7r0IDnlJH1tYgSXXiHNLIharfjH44rkhnA5q6BWKXOL1sQcKMgy/J8od8V+EbJmsFX02glP9F5gHRR5xlPR5EcVwb5K//n4nI2qZtLvjDmZHPE4fcCqf796xrThxkTYfND3vZBPN9tbMM4DiYuO1Ia/8AfO5oJf1Upm36AjqAPa4NTZ7L62lB8/mgTkzxpnpPpu6wk/qqRXTwrVask81fCJ6OQuzNEVwRDuh2rah7Ycf8wR2SFl/fksmiwkG+TdG7/UV2cxTKskiurmJt73TEhRTGhCiI9OVYuWVOuH1vlHaMKSRbKSAKVHxbiYe+xRtIt8tPeec584XO7YvzgTZ8dPDVSjjAhkZ76Ax0+zo+wcYDy7TTQyzyau2GI+D0AJfgAcQN8VL/FSTIndHmAdhl6i8USrdhBCeTa5wSIiMCHbtajouuBzFqkNSBHZyaR1tTesU8fGHZKJunQudbY0dZP9ZciVI7aed6C6uxAZV7mngcDalrlgtXDXc3Dh4aKb+W+GxQTN7Kg/krhA6/RaIyffYi7dvEfeVLWESa1rb2xRP4Y+ZwvVZ4uX3p+5yV58oqHi9ebFjTU2Y3o/lHP+1z4svjwcs4D0yCi8fIw9uDnCGYadGBdgiIXvHcpROqCeT6Ct6pe3GTOi0v4gZUIkQeOqiUOh2n3xyJpNeMUIrP3zS/vkrWDNaak2DLO1ULCidBchTG37rDmCrVLvPQoFrj+EIpwC8Swo/TwWRqF7yXERUMlfFUR3PnpG+E8i1hBnG/Hk4dZF+JpbZT9eJRwustbaUWpDhqRhriWXDGS8OswfBlcKUgD2fJIfvnT/1AfNuwB1HFJh2s1/FOMU5Fu6IMnIS/YR2Fme8zK8ONpuz+RcWXTQ4ijj0ZqimfVvgmbMtU7DbPABsDJNv0TEbUxdRIrt7QR0IUhRFewuCsRPjLI05UzJgSBUqXveIirDHrdg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd8eea88-3f45-4091-622d-08da1674f568 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8774.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2022 19:54:41.8590 (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: 4jYEkIrQbmZqG5MqHgURXR6bAXvFuLh9ktwJMBqZ1meJ/4fYoJaja8hYx+3kyAmw X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB7164 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220404_131014_826899_5EB557C9 X-CRM114-Status: GOOD ( 19.09 ) 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:7d00:0:0:0:61f 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". 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 strength 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 since v2 - split the ecc check to a single patch Changes since v1 - split the patch to two parts - change the commit log - add test tag --- --- drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 32 ++++++++++++++-------- 1 file changed, 20 insertions(+), 12 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..4144d5937103 100644 --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c @@ -514,24 +514,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 Mon Apr 4 19:54:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Xu X-Patchwork-Id: 1613163 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=BaiOdTV9; 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=RstMLZt5; 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 4KXMNj5Lmlz9sCD for ; Tue, 5 Apr 2022 06:11:17 +1000 (AEST) 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=Pc1y9H6ZfOVLOYRjy6/AKObJDj/Pep7MrCxkcEswZ1U=; b=BaiOdTV9Kk+gp4 oP/WM51yk2+DvNLvkStteU6rn1i3A6pxLlMsnfrAr63v6YE8jLQXc76/4YFcsG6HfJDHMvXqCVOps z1fSG0PWPBTZEZEhovwHuZo5clGPPFt3sHQDynwvPfku18lJezsE+cNQyUrF5upafbsa9MuT6DbJ0 ixynQxuGntxqraOvqZsbOqY2h+yyGOHZ4W8nUhP8utva0qqa/vD2h28kosZJqrKf45pyASOGndTOG wr+zD+eEpNKCXXUwbRIQLwjJuuJn1dDJKOVym6hy+QWdeK8Y80nRZFVzv6EZC+zFrHaldXsQ/+Zs+ GHV48r5LGv5tc7tNnjqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbT21-00GKFI-Ng; Mon, 04 Apr 2022 20:10:33 +0000 Received: from mail-am5eur02on0605.outbound.protection.outlook.com ([2a01:111:f400:fe07::605] helo=EUR02-AM5-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbT1y-00GKE6-Ct for linux-mtd@lists.infradead.org; Mon, 04 Apr 2022 20:10:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CO26pl4xhviWKRiOYpDyh1kxqsAzGOHSKj7oJAflbvmWAV4dzsOF3vjxRWNb56S8KRLWRztUD/WI5l3l1vnX/ZoI8FwbeTFOMp9P+VaxNg8vY7/IB/zZgAtSyNFkPzFD5oka6gh7SrQydSKjFT2/BxpJl+H470VCV/JbMm+4T/prvFv04dhb14+U4CxBHnsDo6C2JmC9t9mgsv52I2fYj2yMTteTTiVedpf3YYkw2IIGoth05Kh8sZUNRM30jpxaNFZRCcpxSDxyYlacppCa7nR2sgd6H4C4Sw3F+l7KicgTBUsXXH6xh1NgzHBF9BRPcOf+bDDpnyAVexu0OvWquw== 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=wm+fw/UdVQgFzcMvHX/EsmwDazQhmpW7lZDsc3GXpIg=; b=RKC+5ISU4qajT/umtGsOMHQg2XNB8Ihssl4E+zRtznM9q0QCjP01pmEN5NG6XrxC0ckAlmGmT24Sr0NTWWwzUOJqgeGANFCJx8ehKmrqlvnqOloa1YR1h3IBNUOdI4lccui7+TJ0qrPqOfqgGPDf469mIbj5MUIXxLIeQu8DyRFmVXm2XrYJHzOhxRK7T+EX3fYUfpZmhZr8021zmZKIozNbnpY/83bBKsJ0WNAPKA1RyQgqJT+VhCoavtfs4MlYyPW6JD3KhNjVlEwERe2jxY9pLJ3O/py81Z0UfjQxQSFk5YOOyYmzQGLj8gXIp2hpEHSOZyejsyK/H+UoAiBRBQ== 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=wm+fw/UdVQgFzcMvHX/EsmwDazQhmpW7lZDsc3GXpIg=; b=RstMLZt5rL4GVubjLyNQePj5KfK2RvB7FPcEOU6zVqHd7kCRdmmQZIBwx2B6Cp83F7deu2J1Az82KMpAScqY0w1ST2+AfUTxwRQai9Va6gudzXsmWk31RYjsVYshoieBDzLJen+d3l8KSKgVhzvFSAQ4dFx4tgDYrPGUE0uzgvI= 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 AM6PR04MB6552.eurprd04.prod.outlook.com (2603:10a6:20b:f3::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.31; Mon, 4 Apr 2022 19:54:43 +0000 Received: from DU2PR04MB8774.eurprd04.prod.outlook.com ([fe80::b048:39cb:7748:ed56]) by DU2PR04MB8774.eurprd04.prod.outlook.com ([fe80::b048:39cb:7748:ed56%7]) with mapi id 15.20.5123.031; Mon, 4 Apr 2022 19:54:43 +0000 From: Han Xu To: 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 v3 2/4] mtd: rawnand: gpmi: Add strict ecc strength check Date: Mon, 4 Apr 2022 14:54:25 -0500 Message-Id: <20220404195427.8871-2-han.xu@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220404195427.8871-1-han.xu@nxp.com> References: <20220404195427.8871-1-han.xu@nxp.com> X-ClientProxiedBy: SN4PR0501CA0010.namprd05.prod.outlook.com (2603:10b6:803:40::23) 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: 37f69a02-b5b8-4c76-0203-08da1674f689 X-MS-TrafficTypeDiagnostic: AM6PR04MB6552: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: NmZp35bM+7UQntHdPX725HPsY2R8DeozxNSTE1aea6y4nF50VhbEUUQqLHTbclXhtYUnrDhjCkX7qudfV4rT7Oiq04FH44RebTn7kJTo8UN0ylf4e+wOWhY0/5i4oxW8DFsnVt/D39x/UBox3i0cQ/DMngIrjMStNlIEp+JytQUukPNPylkW3TQW6MtYeXEMoNa8LCQoK7RfAh0E9v7N8Y1RfosTkBo6FGqj2otPhvgS/uSNiYe4HBLxunFXWOGAPwUi19FzS5gE24OFGyJ5Uu8D+XNC3OSf4SS4naCMFtClvGG375fATr8PMB2TjTgEWjhjgQWQ8cApygNPvgnAk25i6SHe/wFVplhHVPmyMn0JiaYPJyilwPgSCPugSHligZtMJJ6DFYAxWLAAxuZb9wEhia1A35FTbSi6tPL2ymQ0ygQNNYekrbAq6VuXxyJDRV33j3uTTbFkwtsZF2lGURxYqrcg2oZosDIfylwBRB77O/u6ad+9FzckP5cDxQ5DsepAdr9GHN9n3qwsgu+Y7o2fzyNOGYySI4mcBYkxs7xMPsODa+KF+45r1X+evuU+1BVzVhq+4u6fKm9hTdlStNTFtyAf6gZHCX2XQoa15TrUlACZgKmOjHzcwFWFCFoFEnvXHVEvd4cRRnAH7jOJd0fvesN9NgSK+bfVZOP3i4YiaskFDAk6ue2/0Sf0y3Togq7+U8Iwisl58DqbW5OoWg== 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)(4326008)(8676002)(66946007)(66556008)(316002)(66476007)(83380400001)(36756003)(1076003)(26005)(186003)(2616005)(38350700002)(52116002)(6512007)(2906002)(86362001)(6666004)(38100700002)(6506007)(5660300002)(6486002)(44832011)(508600001)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /n3HIZwHlSmsqDMcv68LDZD/Mo3lC/fmh7PjIuLWbKoS21UQdwVTv3kBZYFKJfB02mQWrafItQfzSGXc4qh18sgyaqPSfxdbNki698iuo3uXkUF7wIMbAveOauCjNfdNFUvElt/NhE4GCaV3ZdSbw54KCeCE3lewLkxWPuT6sJbU+N5ckg7kM1FNGJYxUs7ZY7/KnFFRZ3lS3kRZ/wRF9ysAD7avPydRuJNMvBfrByHPVmg6MFpHPL+krJJWmw1kdcIgMXsmAvrVne9IzzkkVFakeF8yMEFb4oUt1CbLwazZAkRLNWXzcNH32Jsh3zX/RU1E1sCfPubztE5JGoVW1gPfYAfq4+KdrabLEFPphI4R8hiKAJcYGEfFnStxJ9PM1F+i4cFb+g8jbmYg8JamqkLFIEsK5amxyBPHhHXdl+sfvA58ZhGnTHENtZJRdBN95b7qZ0s/Q8qO6saDD9PDDEAj7sC+atlFp/fNHsLvecMa1yXrxpuhKI+5MdwkliEgFNTaFo/FDds0cwUOK+TxBuAbmZ2wfNZDBrTuOZVcOsfDSjK0jpUDloVyi0kHYmn2XzeVr54QEpBEBBuxhfJwVISEq+zEURQkB64FZrgjHzgib0NmqVsTv3Fe5AN8w8Ln1mPLd2ghNz+uC4Ufj+6D9ij/g5j1oOBGzIzyUBxva0rUXRadh8HEz9SS/yIIhozAE1m3ZNfT6uOW5Pnq1SKIiDnXdiAsXC0QD0HleKAgGbB5iLglbeADhD2fvvQu2/AQ/LgpnFuEJZ+10RDd6Fiz13Z6tCCdHc5tjVPQIEElPioDVyX4B9vrweq4Gc5p49bUoOpxkDvgu1rsN0jwPcDmJW2Xzez36it+SZ1G6k4ySpV+B+gW9UHSQ+Xud3RgSeA2jhFMUQj238qLEr5Ljk85YOawbG4g86ilRutYg7rAi87hMgITo81LG8f2rj2mpaKB84dy09a4cQylWEIT923Y5Zz1JCj+VHsYlfOHhK9VHz1BOX+RpkSsbnJPz0gtBdkCRPpZLlMumI1pyNlI+eWhnF1i/EVTzcN4e7ogKeg9d0VFT7qQP/Eivu7Sx3QUyZH3I+2K/M+4pBAG7lipbDedVnWjUSM81j7nJvpQIUhGaniFmXH6aGsQZTN2D15MikVl3tSC6e/0E23c5YN3aVpsYQF1Olmqag82NFdfI7LMPbgM4xAuC9WI5Vc/57DlAl79671WDdLbqjtJ5utY2WHVEvVTjmTkeHNB0zo8Tr+usZk5alwzY61suEuQ1eIatkS7euO+AESYClUaFo4WElo6HqcZ/xStzPP6F60fPktX4EpWVAEIcTjIrqOULzz7TPEyQ+Xgd6jnoS6uJQAXcA1WeRedB9UgKRcZC9UE/qYgZ7xhl7He0MH9tSTJv7Kty8sZybDyEgPuoBPwx8e1oonrl6WUXGq4C7a5ZMhaBR1+MUnO9qBKRb/x3WAjQJcSaDgk+qdZ4MnloL6RSh3tHS1+xUKyMOydOPITJ9Vs8qToiJsPCb1RCpMjkCsoKwUChx8kfwCLmy3+j9qMu+7lNDHVkY+aZqkNCqqkvUwl39uWUTnwSiVOkizSJsPf+UHRs/hUtPN5eMJo4AZ3ZAUewP9sGBm161Ydj75EyqR1SM1IYkgPKaQTMJx/DPkiCPij+7vpnof6H+IM+lpvzmUBtH4MNaEmzPqtbgeSu0qFB6xz9ttPtdZUSz5QHLZ5Dyct2pHf6RxgiCvXQzhcS0wVGOJmXw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 37f69a02-b5b8-4c76-0203-08da1674f689 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8774.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2022 19:54:43.7182 (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: eLpc4OHWohtNbaZEKVC/aMxVYRXQXfFwZHdwxsK3aeOyi12cqpuPWnhd0txv36/T X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB6552 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220404_131030_471435_39E245D0 X-CRM114-Status: GOOD ( 15.77 ) 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: Add strict ecc strength check in gpmi_check_ecc() function, which is same as nand_ecc_is_strong_enough() did. It will check both correct bits and correct bits per byte to ensure it meets chip required [...] Content analysis details: (0.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 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 Add strict ecc strength check in gpmi_check_ecc() function, which is same as nand_ecc_is_strong_enough() did. It will check both correct bits and correct bits per byte to ensure it meets chip required ecc strength. Signed-off-by: Han Xu --- Changes since v2: - split the ecc check to a single patch --- --- drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c index 4144d5937103..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; } /* From patchwork Mon Apr 4 19:54:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Xu X-Patchwork-Id: 1613160 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=YR1he1Rd; 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=io2DtV+f; 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 4KXMMt2pHtz9sCD for ; Tue, 5 Apr 2022 06:10:34 +1000 (AEST) 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=UBZmtOCW62Pvaw0K4mHtLa1gFte76PWj5+/zxPslLYM=; b=YR1he1RdIvZts8 Bn1zBiOW6MMnN2RqeftTOE1Obhj3CtukrvdtkdtVHuYNrxt7ic1G+dKKM4z+xTSC43VqgAvkcBvKc 4/pe2yYcxFtXoyEv2xQ4atU05rTWOjYIp/XMXrhEVLSgxjjfmtLSPCSSh8IhjW4uPm2bR5im15qO1 GoZ1eOvyDng7hKj9fNERpbuafQAUHz1fAyzOXMfUPdsp/ZV8bELPlT7AEm5+P2XE+HZKEJPEyW8tu 6YQ69+ksW/J2rEzpOgZxSI0DtgN4ogJv3M+Adahc2vSu1mzINWJhp+jMeU/HkUDHwXQXhRZRjacqz n2IHMpdR5vBPTlaNsbrg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbT12-00GK5k-H7; Mon, 04 Apr 2022 20:09:32 +0000 Received: from mail-ve1eur02on061a.outbound.protection.outlook.com ([2a01:111:f400:fe06::61a] helo=EUR02-VE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbT0y-00GK4b-GI for linux-mtd@lists.infradead.org; Mon, 04 Apr 2022 20:09:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kSLh9zPdVzeZn48Z3ePTPzNFgj45IkJakuwMSD5e8tJRioZkkA2UW3XF5NbctnowjPFM3czv0OUkRPo14mFnTYUyolhZdO3AFy7AgmMPFZqoBIjNZ2bhvOs3vfPH5l628Rg6hEL9XtCuvUIWv9g9rNwKPl2Qh8GGmUWirGIQTQtBkYquhMYVz3iXvpSmRAbdO6mtAV43SAtVqxuOJZ4IBU1zts88mOEDm2vSGp7t9sLxOCkvr/KRfkQv4WRpUnTEGAfIdvLw57wT8hSSxRP73IQbNhu8JMjc8RU2pU4FVCtETCai7RjnBFw9k+OkOR9js/qht9GsEl6w2X5UrYk+Kg== 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=Pq+u5dVUi9zcj92NjMWqJy3qrCQOC+zIj+FFBvSVM0U=; b=hBp70n9FltsNHdKrNGlPBNO/We914HklMXWCt9yFuX4Rf2UOFFwFPJQeyJY/UjnoIPd6LehK38/uaGQH2IzPDF94ecY7fSp9rHl+bDb8zFFBt+ZjUcePZbDN2VxE8VWAgqMjXBJT1mQ8GsvjhghFqekJjAmhaM1LRSs759goS7PKzH4L8rMf66eUT4dfs0AQOnq6VtP6D1Y7Uiq7z5nCGHLyesWaKbNHC5YQh/WaQPZfjXOp8zpchDP+azD67dnaYtJpn+MnJtnfrAZ8cO1RQqqkeKp7whtQd+CdbFunZdKfaDlUJXFJKeyMoOVdVgkGLieAHvjrWPPkWhnPfHuiVw== 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=Pq+u5dVUi9zcj92NjMWqJy3qrCQOC+zIj+FFBvSVM0U=; b=io2DtV+ffHIp9N85/bAbIIfi7wyS3Li6MHQmKddpXIeYsc6mMgerKlpHj3XLrukmlGDmhHNF88muVGx6Xz7xqjjZWqXvw4/GLQjTUO9Ega7pCK+1Re7sdmjHK14Um5g9H6MmO1XGO2WNF6kUKRtVT61XyZDlXo5+ZkW2ggd8u44= 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 AM6PR04MB6552.eurprd04.prod.outlook.com (2603:10a6:20b:f3::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.31; Mon, 4 Apr 2022 19:54:46 +0000 Received: from DU2PR04MB8774.eurprd04.prod.outlook.com ([fe80::b048:39cb:7748:ed56]) by DU2PR04MB8774.eurprd04.prod.outlook.com ([fe80::b048:39cb:7748:ed56%7]) with mapi id 15.20.5123.031; Mon, 4 Apr 2022 19:54:46 +0000 From: Han Xu To: 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 v3 3/4] mtd: rawnand: gpmi: Rename the variable ecc_chunk_size Date: Mon, 4 Apr 2022 14:54:26 -0500 Message-Id: <20220404195427.8871-3-han.xu@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220404195427.8871-1-han.xu@nxp.com> References: <20220404195427.8871-1-han.xu@nxp.com> X-ClientProxiedBy: SN4PR0501CA0010.namprd05.prod.outlook.com (2603:10b6:803:40::23) 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: c568839e-d4ec-497e-9831-08da1674f7ee X-MS-TrafficTypeDiagnostic: AM6PR04MB6552: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: n30CGJ/CHowWmlg297bMB9HL5r48pCvBzNsdH0wzOA8kaiiEnAZ11k24AMIv9ajuaK/RmQoBu4eUzy3YSJbqkunq+hG0+CHFqfEF0gyuPnmljkdlL7L6t26x7FyHMMDy8GsuVBlCwWTc0JYbdAwjcG9qJL/hr8eK6lFCsuPjhFoJlChc1HzRbxfFv6Yc9bAbxnueFtyx7DGBKdffCSa+k7lkw8kBPdqj7jVKaV/9oBIul0wgllqJhoAD2U2mXUJpwse4VBqU3uD6IJxWoXR0mscCU//Cm1VT0ZbNNQx1OABg8rWYHKgRuzHmtwbUqZaJknOpXUL3kYJKpTExab0n5V6SFyC7T1mrZU95CAMV2MKzomNG4ozHYzNM4bfNnbkWJ69YamFbVOEZa9VqjUBBOELfWihw+WIbm/Au4YDd0HfOa6hcC2LI0hsSUwW9EKV/agakJ2gSTIHoY+EtqCf6eHK3KseeU12NQ+SjexxwbXaur16X336N7A6dEmPSFyax3ig+MmaVsZcdzwHedtzsai6W07TRtsqih4Ce16wSLlyunrFquDouAAu9mwfNmNCKD2Nn0T5rIOrHAAIzydJIIS14KhN/13p+QJ++/MTNMvq8TivCO9hqIcv9XdxFwo/NoLpBrp7mmhDB/fNPAqBX9im7AOP5mWiiJFuISN3wjnaz15D8qdVQ2xmcqquUyL4iRmbaa1SSmXbJiNNFb06etg== 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)(4326008)(8676002)(66946007)(66556008)(316002)(66476007)(83380400001)(36756003)(1076003)(26005)(186003)(2616005)(38350700002)(52116002)(6512007)(2906002)(86362001)(6666004)(38100700002)(6506007)(5660300002)(6486002)(44832011)(508600001)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HswJr2JkWXxqsbfRyTBCECPHUVGClBnfeuIdvn77zUkeZRl3HXDpJ6Edp4beCH79G1B1olXEFGd2W4+raVt3lhrXUcgix2Z9HqS0txcvhO16u5rdFxU5VymIRtKSWqnJnPP4Z9NllZhilO9fm/VYxhMijOHVxNKMBHVKGRb6NPqZDWKFJLllwhoEyqP5TtIjASxorcYQxrhzi1Zkj6oeh5HnBxRDVeChd9jmA6mmoQ1uWD88pbCPz0tfWQg4mkerq87QYRVdY0HNuA9w8wXxKx7bGivjJ9eiG+ipoP41HvqPXqLiX9FP1JzqxmkHFTqy+45JOsqhb1EmgamnWotLINXnW+fjXn5NfOTxfdESEmaO9bz7JsDtsBUhW7V17Ip/ijItV6AMt/o5xFiY4eYNDziOCsNZCYTnYHIEtpoEzanqyoxweDh/pLJDNR0/CD6z3dMUEfOAgGZyL0CzOD30Pu7NggWXCEgyZd8otH21OUU6fdy1aZJOBxF3qXFvNrHz1AsCla+Nvrdrm8KydSI4kDCZ7FEEylxF+/FL06/IME6J2tYJTlcI3xgl9nlUWntUtgOvAW4DMXK+JrMLlsQ0aV/27s1ISyMiJ/2Z2SXSH+JvWzADqTUpZRpkH/5ziZX8+gzwHXORfLiuA2vOMb3Ud5Rgrl/VFxgzjQa/SCS1pl4cx8tGCLkPvrAurYyPCvT2SyTsPTQP/TZBTelrrbiGJmk0o8rPKm8GChUsXsrXEjCPj3ACbNAdQijykIgZWN+evJX5wfRXThG5Q2d3O1MHhk4A67vkxoqYOX0ClKU1sFSyQ+rcAzwk6YIqYPdkw9bubnCTo502X36cTh6FaW1MOvHy6PhG0UrFQ1RBo1yhXUYUWD0zKp+zohaU+WolTnmWwYoz1bvdkkUBD0XsaFGHp1mDuQNFXQGYnp+xrTZe2++Zma9+6XcNpJ0qZ0MbNGOr17INnOly64aWA0iWC6xNzfpuZkIL68g0qcnHtRCWeUVOQb2IHGhqeQeQl0Hy4BZbhclgHljLysz4wwF5VP26zioT8JJi1ZgEQC4Han0KR4L3qhpLnBVSMHL3G0i7VD4nWdrKboFOtf09X8qX3UdADtetdR85aWo+YVKsVr/XFgIuua08G2k1gxhammEAW1ibdQQWApnrDylrn0ezSwePyG3a0jFY7M0kSfnur1lzDDr1YTKyQCjHkmgocHBRQi+UyOFw+CdKNn4mx1qCAtzpA02aQcL/enHzLzOdSYtuimPV2z53CTE6XtPArsUN4guptHG2AcY/mtt0SBsm4oMdovXN+9d46XYoMyHI1Zng9CTLs8ee1m8VLtEZB8F3mGPu2CPbs8j6A4IUDTor+wtJH4qnVFF+xDHSbgG4h9fo2zeoX4cDA6/sgN/WXtHG+uFEZQmIgOoxMxOTyut4UsnnKyOU3SE/7DBVzE/uK1FvXVQ7lLYNmf160usxVFbJ7Knhh+EfaZ8wE9f1vQQIzI9iCyNACj+AXmYAC4wvpY1LdPdkSoJGJkI9KzezU3Pal31LJPaFWar2+pCQCSqpKKG4V+xZXhoBlxmBQ+NRn8KnFed5KMLG6vv5NDNSfhTubfM1VIHkyGNNvKQPXUaiMXIJlaSrMVs5eyf+m2FirAwMWW2dQsFwExkHu9UUO44+/WvjWsL/PzmSi7ljNGmUE7Ga4n4OGtXpnPXKxJQLjZyYtLL0dY4maXAKR5a2cIC8761bYoSv7SI45IvXJJXn+2GxXw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c568839e-d4ec-497e-9831-08da1674f7ee X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8774.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2022 19:54:46.0472 (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: 8iC6BqLi9DE9gRuOlJiBUitiYzZfYfcssehUhm1KWIoMA/23G9WmMXhD8S09bzm3 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB6552 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220404_130928_764366_51224842 X-CRM114-Status: GOOD ( 19.79 ) 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: There is only one variable ecc_chunk_size in bch_geometry data structure but two different field in BCH registers. The data0_size in BCH_FLASH0LAYOUT0 and datan_size in BCH_FLASH0LAYOUT1 should have d [...] Content analysis details: (0.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 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 There is only one variable ecc_chunk_size in bch_geometry data structure but two different field in BCH registers. The data0_size in BCH_FLASH0LAYOUT0 and datan_size in BCH_FLASH0LAYOUT1 should have dedicate variable since they might set to different values in some cases. Signed-off-by: Han Xu --- Changes since v2: - split the variable rename to a single patch --- --- drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 54 ++++++++++++---------- drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h | 9 ++-- 2 files changed, 35 insertions(+), 28 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..cdbf0e05087f 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" + "ECC0 Chunk Size in Bytes: %u\n" + "ECCn Chunk 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->ecc0_chunk_size, + geo->eccn_chunk_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->eccn_chunk_size; ds_corr = mtd->writesize * requirements->strength / requirements->step_size; if (corr < ds_corr || @@ -300,13 +302,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->ecc0_chunk_size = ecc_step; + geo->eccn_chunk_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->eccn_chunk_size < mtd->oobsize) { dev_err(this->dev, "unsupported nand chip. ecc size: %d, oob size : %d\n", ecc_step, mtd->oobsize); @@ -316,7 +319,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->eccn_chunk_size; /* * Now, the NAND chip with 2K page(data chunk is 512byte) shows below: @@ -438,13 +441,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->ecc0_chunk_size = 512; + geo->eccn_chunk_size = 512; + while (geo->eccn_chunk_size < mtd->oobsize) { + geo->ecc0_chunk_size *= 2; /* keep C >= O */ + geo->eccn_chunk_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->eccn_chunk_size; /* We use the same ECC strength for all chunks. */ geo->ecc_strength = get_ecc_strength(this); @@ -871,7 +876,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.eccn_chunk_size); else return raw_len; } @@ -1263,7 +1268,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->eccn_chunk_size) + eccbits) * (i + 1); offset -= eccbits; bitoffset = offset % 8; eccbytes = DIV_ROUND_UP(offset + eccbits, 8); @@ -1300,16 +1305,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->eccn_chunk_size, + nfc_geo->eccn_chunk_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->eccn_chunk_size, + nfc_geo->eccn_chunk_size, eccbuf, eccbytes, NULL, 0, nfc_geo->ecc_strength); @@ -1338,20 +1343,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->ecc0_chunk_size; + unsigned int blockn_size = geo->eccn_chunk_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, @@ -1451,12 +1457,12 @@ static int gpmi_ecc_read_subpage(struct nand_chip *chip, uint32_t offs, 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->eccn_chunk_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->eccn_chunk_size, this); this->bch = true; @@ -1625,7 +1631,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->eccn_chunk_size; int eccbits = nfc_geo->ecc_strength * nfc_geo->gf_len; u8 *tmp_buf = this->raw_buffer; size_t src_bit_off; @@ -1710,7 +1716,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->eccn_chunk_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 +2090,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->eccn_chunk_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..5b217feb0ec1 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. + * @ecc0_chunk_size: The size, in bytes, of a first ECC chunk. + * @eccn_chunk_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. @@ -48,7 +48,8 @@ struct bch_geometry { unsigned int ecc_strength; unsigned int page_size; unsigned int metadata_size; - unsigned int ecc_chunk_size; + unsigned int ecc0_chunk_size; + unsigned int eccn_chunk_size; unsigned int ecc_chunk_count; unsigned int payload_size; unsigned int auxiliary_size; From patchwork Mon Apr 4 19:54:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Xu X-Patchwork-Id: 1613161 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=mhpMjM/H; 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=oW9V5bY1; 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 4KXMMt2yzKz9sFk for ; Tue, 5 Apr 2022 06:10:34 +1000 (AEST) 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=nLGf8SIN7TWEcuWWbX7MVxB5EYwXei6um6LqnDODarw=; b=mhpMjM/Hz8D+3p sFyf8M81dAVzAgsgp2RgTj1wFEfrw3mUSv2cliHd7er58SKtAjJJPi77LNpz5/jzB3cYeOI8nurw5 h3wBHX1MkrnIeBmiI5p7EME/pL7jqjbcCIIK2fnZzZPE0XWssrNHLiEDz4OGJQzUV6NSL+3U3bnUf HSJfGkq7M12peaiBMNUXKlL2/vsuIyZgmDu6vlz8MwEudU+VRRNXUFxv0zWRyKJ9nYnAK2QZAIj8J QrBNfE/+JINYv+GT+SClItuOwmCDQqcDcK1p5Rg7zhjGrXUL9ASSksoTp3mPALer6QjRkpYLznbRU Gq4BtsH4NUbV6hScdkaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbT1B-00GK62-6c; Mon, 04 Apr 2022 20:09:41 +0000 Received: from mail-ve1eur02on061a.outbound.protection.outlook.com ([2a01:111:f400:fe06::61a] helo=EUR02-VE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbT10-00GK4b-Us for linux-mtd@lists.infradead.org; Mon, 04 Apr 2022 20:09:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c1/YUm0S315/a+pOzsuDHemj2w5wksVJgPAvoJOyEM3clFR0j1f+NxI6FZxcp01wvtLyHnODWuhEINT+yv4vuiInWTCXfex4j7OIt5HPV7SrMfIzAhCkcg8PA0e3LQyjgv6S1oZCQnSsbmM1MI+J7Yn0/n0cfAQrk5fUtFiI4f1FSAhDp+Thg9UmTqzK073ik28avs+4dGc4xUwm9sgSIthtb//aHIaS/N+dR9nMmETEQCAxHGwpEocn8K6MLaFl9M9U+BYBOMh8yslz07FAnrHbXNC5luIO3e0tCN3m141kSYZARAjWIAEZnqzTRUF8BQ4ufjjkAm8S8Dz1yHGv9g== 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=EtzfJIGAd6Obkvh5Uyl9qNd4kLXpxIbTPqodD8OrNbE=; b=FeaZODCsNuLE7pPksJrVByL7PZRCDVuk78LR3nrOoA20A4eevwN1USxORtwHYisQMfPsXQEaceTuFL79qfxgxicCsRo6n/NVpMAqp3ZQ1d2E9C7uL1b3FhJ5bRx/yaqdARWKPPdF/hx41CXeWxS5NH2t/gk3i8NISqJVqJMtREhctvbcTs/KBBgnXGAH41sVQsdei8aC8ZLo5aSZBjZPy6YtltaK94vE0faY5YoJn7Yq0F2gZPQwNyn7PycEFLDexHcEtdB5H+MFsx+m/414I7Bt2gACIYLx2+y4n7EUWXZLCZpXUGZ5CLbLfE2HpQmf4Rkl3417BAJta4YUZg9lTA== 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=EtzfJIGAd6Obkvh5Uyl9qNd4kLXpxIbTPqodD8OrNbE=; b=oW9V5bY1+Bs13kb9ssPrjUDBhTSz7G93W26I+b/g5WzmmC70iGHLKosh4SvHv7u1kMW0oozBM7+0lTku2Ku83xjcud5t0bWfdc0iT5my7qsPqEY0ZJ8xZ8VwbYLE9oCUXP4rzbE8lQipv1u8KYZJW3Z4q0ezMG62u/bJ9syftzA= 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 AM6PR04MB6552.eurprd04.prod.outlook.com (2603:10a6:20b:f3::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.31; Mon, 4 Apr 2022 19:54:48 +0000 Received: from DU2PR04MB8774.eurprd04.prod.outlook.com ([fe80::b048:39cb:7748:ed56]) by DU2PR04MB8774.eurprd04.prod.outlook.com ([fe80::b048:39cb:7748:ed56%7]) with mapi id 15.20.5123.031; Mon, 4 Apr 2022 19:54:48 +0000 From: Han Xu To: 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 v3 4/4] mtd: rawnand: gpmi: Add large oob bch setting support Date: Mon, 4 Apr 2022 14:54:27 -0500 Message-Id: <20220404195427.8871-4-han.xu@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220404195427.8871-1-han.xu@nxp.com> References: <20220404195427.8871-1-han.xu@nxp.com> X-ClientProxiedBy: SN4PR0501CA0010.namprd05.prod.outlook.com (2603:10b6:803:40::23) 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: b09a6714-46ce-4460-c034-08da1674f918 X-MS-TrafficTypeDiagnostic: AM6PR04MB6552: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: YecNvyp9sDywUHshxT02eVku5vsS2+7COqeYxXRrMgw57NJS1RQc29hDBGLtD8eaF516QRnp9RRS1pWshNiaZs4s4iW23phhRbmCkMWARgvG+IDJrhn5VFaRxxE2F14hk9iY+boTjSwHBEtAwWCn/DA3FtLsnlUuXRi4M2CM77bd+1gPpYq0Bh7HOQweyiwmqGA7Uyvklf7wfmWokShLzB9pMrwVVg9/63firSjfBYoMcgaPArEfFtsh+nLGO0oNFKg+5LSRe5CH7Ecqn3abvyUFOsDCo+K0uBLyrb5tpbDq5TBdYenm14dIHbSqF0bnhWqnQ8cvxzUQhTm+9MlDdoQFgcAXV9FHoQXu0KBf5yGYyDn4rOIRzyM3tAeJniEKhgD/OAabRlm3QZ1SZZ1CpX+bZelpqsPkYwWuVA7d+bEsBHpMk6F3S6/xiCuolT50JUxWQf2WtZPb4mqMApAfjR0PBAwkASvUZvsykCmNJUXCoJNcTLQsdfobQrtV0u1R3r/Jr7aF6lGlxrgx/Wu4drLSQbUkAzFA02HW2lkzOOLkkS4TimSmXK0cW15bEOxgQum52cpXBy6NWi/H9BSpV8P/6cBOMRMPkHKmi1F7YaYOhF+CWw0rawzDn9HcR5edzAZ93yI/BwkRNM5IaUXcQ9ZK+jSOHocjDJbHWvFqtmC+ji6Gk8KDr8I5koEiqeA8KJqyIm+y6jKQqK++MFni+A== 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)(4326008)(8676002)(66946007)(66556008)(316002)(66476007)(83380400001)(36756003)(1076003)(26005)(186003)(2616005)(38350700002)(52116002)(6512007)(2906002)(86362001)(6666004)(38100700002)(6506007)(5660300002)(6486002)(44832011)(508600001)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nuStsyDW/mB2B7vUr+c+N37t2pxwjPSyC9949dKYPOlQZG33OYUhiJ6dAjPNRXqmEHxWLunQ8g8CVbV9qKumthoVGRpbKrMT8kg10JwkYsi1C7oMm5SjMuR33uqtc5TREo8uigtpNdEP5QWtv1pXjQDnjtf9m81tAr94V71HNC2jhYEfLKWjwVloSfO+1hQPBk4TstsKlttl8jZwRK1MBVFqqcddQSmHy8hdGSud9/SWDDBUPhGS6HMJZ/5oaNPxukFCwe3bg+13qBADcJyGBRyOs/2oKwdP8wkAHqPyHP/yJVCz8erj37DM2aKZt15wvfT++VhKrjVyO/llwQ9fN88uShySWnfiOraZBP+hkVRFVsDZLFX5gEKl6mu9lPiDeHUus+aXZNnQ1R1aE2gbSIo6TNHK36om0JfFJoaT2OymVJFYPI2F99eKM737bi0bhMhyCIuw/1gWEWHOv7J88W9gGdtK8J6XKLhlTZ7qw3A1JTf9z0Qas8MQWhPGjrWPhljKF4ILca+x4ZevlrG1LDxxvHMI7zz1hLMFAlx7ovmK6V8bw82oX1tXxd2AZfT+k6BCwMgSdeZn/tvPwqThoTtJx/6s3nCpANvgWtdvUtxHA6IDoxpuN676Q+L5/eAGwVPl+7cmwRt3VJ3mDRkMYwOEyijqI1qYx1EK7c+oj4X8CiBJ1UWzY2xd0BJSoO9wdCKSzorACq/uY5uY/2+bK+zkzq1iDHP+Lu0FS/tiqDLvxm2hwYIGUL4Y/GEAbPLaXit5TiK61OUDzzKw82seaVdSxyK9lLcihaOkSJFYArYs/KhqQdNJJIs220i136H1yNSeR3IWyzUyb31SPDGgDGVLlG0qnzhlSBrUtnCAjY5Rarf5mxq+9ncUu2AThQf1fZ6yABh9H9vKtDsIf1OWxlGWgk2W6QEnnFP36u0D1ImuLffDXLZTfL3rf3UNHoK13bnMXtsXAk8BTaHfngUxJEcLbQcX6yeib9qoawc+/mZ6dhgHTI4Afc3OeU6G5eXyviVycVqbitOQVo01C926VOrBQYZSN8DKYTx9nkKsJlDWo//nfFMCqNxgSqszcq5feq3Phj+vqw/ioJu9//ftBfCKMLgf1pp6oDCGcr03Ha+XVpdOP9+mGRmwPy5EhpMQlxJ030EOKMHYEP/JN60vfzXLJ0hl3+W0UQgbqz+mP1EkETZj2jMJ+zg13joPlPzLoH7vQ3MHYbqp32OqLsm17v4Uc9c+Qo9/wffEP6skuryaU/YK6Z9CubcUiSHkmUCpoOoHVRLN/02f+ffjgyHY4PwgFFeupDlYVxtDEpmrD+lHkhVQONNoGf6NaHt41Z+8XUx5jaVm4KRzSAt9xq3zQOAR7Km1xRr9JCMQX9lNICdBY5AS4LS5swS9av8uAoxnxoKq0r6WglpIZxiMtAvHQscmqWz5PD09799Nq43vjxRTcsw6WXd72e7MlPN+mnAMkoFHt9vQyVvY5ecjNnoba5DDPvdnibOd+Zn3aathPM2C1QQrNGkls4vk5Wo4lk+15UiZSv/3cUpQ8DBJ4By3HE3BbyBldllL7lqRxFg5TwZKRfleHVauwxap8SSN4NmLZF+xIEcH4McDoykQpw9hUH38ODZMclti/kwm+3aA5ODUgLcrZEqpZKFF6KqOvsOTnSqIy5AKbnOh0kNs5Vzcro2wDCzg9fXRhcPerJ+w95muDlmMch2CfTRBw6+XJnwbJtttQnw1vueqL2p4S8+dyQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b09a6714-46ce-4460-c034-08da1674f918 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8774.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2022 19:54:48.0168 (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: BhVpBsox6mFQEAlmm26iseGDEt6dtidZSZ3GTVhhcKFkdiBn8OiFT7PRaT/bVy6u X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB6552 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220404_130931_013596_0D9CAA7C X-CRM114-Status: GOOD ( 26.54 ) 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 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 maximum ecc that controller can support to minimum value required by NAND chip, 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 since v2: - calculate the ecc strength from max controller can support to minimum that NAND chips required. - split the variable rename to a single patch Changes since v1: - split the large oob part to a single patch --- --- drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 199 ++++++++++++++++++++- drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h | 3 + 2 files changed, 197 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c index cdbf0e05087f..bad261e1afd6 100644 --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c @@ -273,6 +273,39 @@ 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->ecc0_chunk_size != geo->eccn_chunk_size) { + dev_err(this->dev, + "The size of ecc0_chunk must equal to eccn_chunk\n"); + return false; + } + + i = (mtd->writesize * 8 - geo->metadata_size * 8) / + (geo->gf_len * geo->ecc_strength + + geo->eccn_chunk_size * 8); + + j = (mtd->writesize * 8 - geo->metadata_size * 8) - + (geo->gf_len * geo->ecc_strength + + geo->eccn_chunk_size * 8) * i; + + if (j < geo->eccn_chunk_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. @@ -422,6 +455,134 @@ 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->ecc0_chunk_size = 1024; + geo->eccn_chunk_size = 1024; + geo->ecc_chunk_count = mtd->writesize / geo->eccn_chunk_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 = max_ecc; + while (!(geo->ecc_strength < requirements->strength)) { + 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->ecc0_chunk_size = 0; + geo->ecc_chunk_count = (mtd->writesize / geo->eccn_chunk_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->eccn_chunk_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->eccn_chunk_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" + "ECC0 Chunk Size in Bytes: %u\n" + "ECCn Chunk 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->ecc0_chunk_size, + geo->eccn_chunk_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; @@ -557,6 +718,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, @@ -1440,24 +1609,44 @@ 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. + * - ecc0_chunk 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; } 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->eccn_chunk_size, this); + BF_BCH_FLASH0LAYOUT0_DATA0_SIZE((geo->ecc_for_meta ? + 0 : geo->ecc0_chunk_size), this); this->bch_flashlayout1 = BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(page_size) | BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this) | diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h index 5b217feb0ec1..c3ff56ac62a7 100644 --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h @@ -42,6 +42,8 @@ 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; @@ -56,6 +58,7 @@ struct bch_geometry { 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 */ }; /**