Received: by 10.223.176.5 with SMTP id f5csp806729wra; Tue, 6 Feb 2018 07:41:44 -0800 (PST) X-Google-Smtp-Source: AH8x224nDC48VQoyrrSeduON0xWmRfsuLI3XCiHBgM4UWw3QZD/k2PQ+X8/HG6SPGuQqQP0DVhvr X-Received: by 10.98.247.25 with SMTP id h25mr2815489pfi.162.1517931703682; Tue, 06 Feb 2018 07:41:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517931703; cv=none; d=google.com; s=arc-20160816; b=p1cLmGdJbX1+IwCSr9iLhCUVn/+pmXjmpwdQOcGyPzs14wCWtrFpI2zS1hYiTriESs w7pQYrbLH5kEsvws1vkcGsAkr9r283dxoEuQtdzfmurO1Y7L5cRvVZ0v2Cbdq8Fp1tu9 ihOHJ13MUN1JQLZ8XGolnkPYDVNCLW1i8TY4K8uQwL5wWsRIbGALo+lTTOi/r/sKt2vj c4+hlrN5ZKpsWC76jzcsDb0j++NRiSlfADJZYUyEx+nRxcpVE/DEUTYK4p9amORLnK66 8NqrFjMCS0dP8cr+3/48AqRyNWrb2qeAAJAz6ucCKa1ty49JRrtrx+9p2zDqRoIbEOmM +/3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=OO5ojpQKA1w4zDoMvEU29BO+M322q96d9sG2nWZ0WZA=; b=tObE3Dy1EZjlliF3v7M+7FpMqTs0Jd1/Uxe+ZSxcPjaurjg5lf+1P1kshwtsJ1vjNp sc0J1h37zJ1c/UWhS/KuL3giRhmp5Rsr4/pB2jbQ6UFUniLuFgptinsxlYCgTKx9mBjV T8TgBMAd9xAY3JYpeXXlklN25jfs/VncLLjRXxNHr7hdMyg8Y1WNgWdpigb2W4d1JeGT CttpMCgb5rZy64vLR7E3yGMFa6VXg3UO9jop+SoCogusNdF1hfCqFHfpodMp+OB1Fa3n FWgQ1g1vhhmkQUIW6SkKpv5PUMkH+UdRJSjPu260zjR6+1/GbEk/rTxiDfskfWmjG/9F EatA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u5-v6si1467764plz.513.2018.02.06.07.41.29; Tue, 06 Feb 2018 07:41:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752450AbeBFPlJ convert rfc822-to-8bit (ORCPT + 99 others); Tue, 6 Feb 2018 10:41:09 -0500 Received: from mail.free-electrons.com ([62.4.15.54]:57520 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752237AbeBFPlF (ORCPT ); Tue, 6 Feb 2018 10:41:05 -0500 Received: by mail.free-electrons.com (Postfix, from userid 110) id A4CF0205F3; Tue, 6 Feb 2018 16:41:03 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 2F2052039D; Tue, 6 Feb 2018 16:40:53 +0100 (CET) Date: Tue, 6 Feb 2018 16:40:53 +0100 From: Boris Brezillon To: stefan@agner.ch Cc: Boris Brezillon , shijie.huang@arm.com, max.oss.09@gmail.com, richard@nod.at, linux-kernel@vger.kernel.org, marek.vasut@gmail.com, linux-mtd@lists.infradead.org, cyrille.pitchen@wedev4u.fr, han.xu@nxp.com, dwmw2@infradead.org Subject: Re: [PATCH] mtd: nand: gpmi: fall back to legacy mode if no ECC information present Message-ID: <20180206164053.67fe4d0a@bbrezillon> In-Reply-To: <4952bf96840ae5b0caba7b8f472e2b1b@agner.ch> References: <20180129144440.13648-1-stefan@agner.ch> <20180130142348.35f1bce3@bbrezillon> <20180131105705.17bbe858@bbrezillon> <33bcf28ff1c613886c950465160e5a97@agner.ch> <4952bf96840ae5b0caba7b8f472e2b1b@agner.ch> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 05 Feb 2018 23:16:57 +0100 stefan@agner.ch wrote: > Hi Boris, > > [Also adding Huang] > > On 31.01.2018 22:18, stefan@agner.ch wrote: > > I accidentally removed ML/cc before, re-adding. > > > > On 31.01.2018 10:57, Boris Brezillon wrote: > >> On Wed, 31 Jan 2018 10:19:05 +0100 > >> stefan@agner.ch wrote: > >> > >>> On 30.01.2018 14:23, Boris Brezillon wrote: > >>> > Hi Stefan, > >>> > > >>> > On Mon, 29 Jan 2018 15:44:40 +0100 > >>> > Stefan Agner wrote: > >>> > > >>> >> In case fsl,use-minimum-ecc is set, the driver tries to determine > >>> >> ECC layout by using the ECC information provided by the MTD stack. > >>> >> However, in case the NAND chip does not provide any information, > >>> >> the driver currently fails with: > >>> >> nand: device found, Manufacturer ID: 0xc2, Chip ID: 0xf1 > >>> >> nand: Macronix NAND 128MiB 3,3V 8-bit > >>> >> nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64 > >>> >> gpmi-nand 1806000.gpmi-nand: Error setting BCH geometry : 1 > >>> >> gpmi-nand: probe of 1806000.gpmi-nand failed with error 1 > >>> >> > >>> >> Fall back to implementation specific default mode if no ECC > >>> >> information are provided by the NAND chip and fsl,use-minimum-ecc > >>> >> is specified. > >>> > > >>> > Hm, this sounds a bit fragile: if we ever fix the Macronix driver > >>> > (which should be done BTW) to set the appropriate ECC requirements, it > >>> > will break all platforms that were relying on this 'fall back to legacy > >>> > logic'. > >>> > >>> I see. It is just that downstream behaves that way, hence we sell > >>> modules which use minimal ECC on ONFI enabled chips and legacy (maximum > >>> ECC which fits into OOB) on modules with non-ONFI chips. > >> > >> And I guess you use the same DT for both variants of the board :-/ > >> > > > > Actually we only have two SKUs, and they differ also otherwise so I have > > two DTs anyway. > > > >>> > >>> Currently we operate the above Macronix chip with 8-bit ECC since quite > >>> a while. > >> > >> Honestly, I don't see a good solution here except adding an extra DT or > >> live-patching it from the bootloader, because, even if this hack works > >> for you know, it might not in the future. > > > > Extra DT is fine for Linux. > > > > The problem is more with U-Boot, where I tried to add minimal ECC > > support via Kconfig symbol and align with Linux behavior. For U-Boot I > > would really prefer to have a single binary for all SKUs... > > > > I already sent a first patchset > > https://patchwork.ozlabs.org/patch/867180/ > > > > I guess it should be somehow possible to do a board specific selection > > of ECC. But this is a discussion for another thread. > > > >> > >> In the future, if you plan to have boards with different variants of > >> NANDs, I recommend that you always maximize ECC, this way you won't > >> have this kind of issues. > > > > Makes sense. Unfortunately, for those products we already ship, changing > > would be rather painful. > > > >> > >>> > >>> > So, if what you really want is legacy_set_geometry(), don't specify > >>> > "fsl,use-minimum-ecc" in your DT and you should be good. Otherwise, fix > >>> > the Macronix driver to initialize ->ecc_{strength,step_size}_ds > >>> > appropriately. > >>> > >>> The datasheet says: > >>> • High Reliability > >>> - Endurance: 100K cycles (with 1-bit ECC per 528-byte) > >>> > >>> So we would set ecc_strenght to 1? > >> > >> If the datasheet says so, then yes, you should have > >> ->ecc_strength_ds = 1 and ->ecc_step_size_ds = 512. > >> > >>> But then there is almost no room for > >>> wear leveling. I remember that I dumped the fixed bits once on such a > >>> chip, and there were several blocks from factory which needed one bit > >>> fixed... > >> > >> Well, that's a different issue. You might want to maximize the ECC > >> strength for your specific board. In this case, you should not specify > >> "fsl,use-minimum-ecc" in your DT, or, if the driver supports it (but I > >> doubt it does), you should add "nand-ecc-maximize". Alternatively, if > >> you want to keep some of the OOB space, you can ask for a specific ECC > >> config with the "nand-ecc-strength" and "nand-ecc-step-size" properties. > > > > Different issue, but in the end all I care about: Does wear leveling > > work properly. > > > > The NAND chip documentation also mentions that typical access is per > > page (2K), I guess if one uses a single ECC across the complete page > > then 4-bits are available, which should allow a somewhat decent wear > > leveling. > > > > I guess we can go with nand-ecc-strength/nand-ecc-step-size for that > > chip for now. > > This seems not to be the case for the driver in question gpmi_nand_init > calls: > nand_scan_ident -> nand_dt_init (which fills > chip->ecc.strength/chip->ecc.size) > > then > > gpmi_init_last -> gpmi_set_geometry -> bch_set_geometry -> > legacy_set_geometry/set_geometry_by_ecc_info > > In both cases struct bch_geometry is calculated and overwrites > ecc.strength/ecc.size (without considering either of them, > set_geometry_by_ecc_info is considering ecc_strength_ds/ecc_step_ds > though). > > I guess we would have to add a third option in case device tree > specifies strength/size, and validate whether it can be reasonably > fulfilled? > > E.g. extend common_nfc_set_geometry: > > > int common_nfc_set_geometry(struct gpmi_nand_data *this) > { > + struct nand_chip *chip = &this->nand; > + > + if (chip->ecc.strength set && chip->ecc.strength set) > + return set_geometry_by_ecc_dt_info(this); > + > if ((of_property_read_bool(this->dev->of_node, "fsl,use-minimum-ecc")) > || legacy_set_geometry(this)) > return set_geometry_by_ecc_info(this); > > return 0; > } Or you can just patch set_geometry_by_ecc_info() to use chip->ecc.strength and chip->ecc.size if they are set and fall back to chip->ecc_strength_ds and chip->ecc_step_ds when they're not: --->8--- diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c index ab9a0a2ed3b2..ded4b7389960 100644 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c @@ -204,11 +204,19 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this) struct nand_chip *chip = &this->nand; struct mtd_info *mtd = nand_to_mtd(chip); unsigned int block_mark_bit_offset; - - if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0)) + unsigned int ecc_strength, ecc_step; + + if (chip->ecc.strength > 0 && chip->ecc.size > 0) { + ecc_strength = chip->ecc.strength; + ecc_step = chip->ecc.size; + } else if (chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0) { + ecc_strength = chip->ecc_strength_ds; + ecc_step = chip->ecc_step_ds; + } else { return -EINVAL; + } - switch (chip->ecc_step_ds) { + switch (ecc_step) { case SZ_512: geo->gf_len = 13; break; @@ -218,11 +226,11 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this) default: dev_err(this->dev, "unsupported nand chip. ecc bits : %d, ecc size : %d\n", - chip->ecc_strength_ds, chip->ecc_step_ds); + ecc_strength, ecc_step); return -EINVAL; } - geo->ecc_chunk_size = chip->ecc_step_ds; - geo->ecc_strength = round_up(chip->ecc_strength_ds, 2); + geo->ecc_chunk_size = ecc_step; + geo->ecc_strength = round_up(ecc_strength, 2); if (!gpmi_check_ecc(this)) return -EINVAL; @@ -230,10 +238,12 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this) if (geo->ecc_chunk_size < mtd->oobsize) { dev_err(this->dev, "unsupported nand chip. ecc size: %d, oob size : %d\n", - chip->ecc_step_ds, mtd->oobsize); + ecc_step, mtd->oobsize); return -EINVAL; } + chip->ecc.strength = geo->ecc_strength; + /* The default value, see comment in the legacy_set_geometry(). */ geo->metadata_size = 10;