Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2179971lqt; Mon, 22 Apr 2024 04:04:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU2yrGHY6wCZ4iwpUz7z5tk6+aNyRueqGvuRkz5MmANXoGx5iO92/V/OfqPEKXWwwZSvKvrQU1ZKEDaLOYcxlQSMYVWp0ClPoToUp4JYA== X-Google-Smtp-Source: AGHT+IFNsz0GGoiDIF8X1W49PNKKgt5CvVPm6F2h5u26IgrkWo3ecQJPPyoWlSe44B5pZ2g14L0Z X-Received: by 2002:a17:90a:c7:b0:2a2:fec9:1bbd with SMTP id v7-20020a17090a00c700b002a2fec91bbdmr17709894pjd.17.1713783841912; Mon, 22 Apr 2024 04:04:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713783841; cv=pass; d=google.com; s=arc-20160816; b=YUsLuU1XTvc7AAy/akJaaLoVGZQVG1jW0XQJmN4yC1qCVm7LX9QjdtV3OXrPXSdcmY g8CAJAQK2HpWGYdC3fwJQe4vBbFhFQH5h1Lu3SEQNngJBJwwkWE8YjzT8dd+1xdCiYuP 7svL+JOKmB7d+Ij0x2iRdt35ZpdyL6Nw7EEf/JKrBWY5Y25rn4t0/mv+o0Yhxo8OtgkX r9tepLh9vUxncoIGPGirw6eI+If06NzFwCSxPZajIiRUsmnJDZT+7jaS2Ab1pAdxEJB0 lxGMWAazjIJUFNdptLi5yG3EbYObpaTOl66Ygg5xB7Yp22l2PQSPE8nIKGPtb467Aykb q4VQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=ioagRXJN4fM6UppnhmAHKkmP2O1Mvl5mFzYCjfiApKI=; fh=J2WUQeL4Z9/Law5EDxuI4ZJklK367A/QTZaeg2R0E6Y=; b=EhHxxwxpZ/BLkghxVhvmLeBCd/boNR8XIa+RUYTYwiMPurre9VMHYxofq6F8v6amAs ymLOoYqGw9kvXznV5Kip6BT3Fwh/FA2oJAC1khVTioa0qrKJV40ghIxeKR9kdkZwsz6K VmtV7RGpAJXWuNGEETqBq8K04fHiud5ZKhCm6bK/Kk+SmThxFzKDbUrWeliSPk+YJZOP XoaQ4tBOXOh0yXoKzLIdhiM3mw9ZW/n5R+5wx55w22U2o7blfwTmmlTpPdHuavyWteJr V77WIpZdh7f6Q+g/V2YUGaNe6eFlUkxDILmLKwQwZrapyqZ7z/jxmwteRk72iLMOyJ2f isvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-153240-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153240-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id pi11-20020a17090b1e4b00b002a609d46f35si9469873pjb.185.2024.04.22.04.04.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 04:04:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153240-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-153240-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153240-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id AADD5B223E8 for ; Mon, 22 Apr 2024 10:54:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 078A51448F6; Mon, 22 Apr 2024 10:54:00 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E63A482C1 for ; Mon, 22 Apr 2024 10:53:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713783239; cv=none; b=RwPhAra6+AgKHmpvSRLt10psjgJF1X4tlvMV2+I18UWzsq/dqrLz/zhqHqE+k6JR+mrfYSMKJw3b191l0g5QoPkdWs3Hq+Hhm+ZteanzkMX/7gdrdiXfGu6spgqqRk9rhl4hj3+RfH5Y1QzGt9+qHSid5ooYqeYKglSLnXGWMqY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713783239; c=relaxed/simple; bh=vNKjdmuiOzLKbsLCCEUPR4Vbo0Q1bX4ZBAFYmy8vwfI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nxXHeo1wvDnjjh5FkORbUZReBiMG8uAvDdG5FMlG6X2j+iXIGMbogb2ZpEJSJ0t1d0pQs6LO3cYA+/HV4G86iRKHRfBSg/H0aygnJZr8NGEJoJy02RUzRJalujUVSAfH/Or0ny/cICYuZ9Yy4PI5N/gVnLBE4vPFMjYf0v7v2HY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ryrIp-00007D-G9; Mon, 22 Apr 2024 12:53:39 +0200 Received: from [2a0a:edc0:2:b01:1d::c5] (helo=pty.whiteo.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ryrIo-00DftO-7q; Mon, 22 Apr 2024 12:53:38 +0200 Received: from sha by pty.whiteo.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1ryrIo-0086s5-0V; Mon, 22 Apr 2024 12:53:38 +0200 Date: Mon, 22 Apr 2024 12:53:38 +0200 From: Sascha Hauer To: Miquel Raynal Cc: Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 4/4] mtd: nand: mxc_nand: disable subpage reads Message-ID: References: <20240417-mtd-nand-mxc-nand-exec-op-v1-0-d12564fe54e9@pengutronix.de> <20240417-mtd-nand-mxc-nand-exec-op-v1-4-d12564fe54e9@pengutronix.de> <20240418113244.6e535d3f@xps-13> <20240419114507.5d25d8cd@xps-13> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240419114507.5d25d8cd@xps-13> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org On Fri, Apr 19, 2024 at 11:46:57AM +0200, Miquel Raynal wrote: > Hi Sascha, > > s.hauer@pengutronix.de wrote on Thu, 18 Apr 2024 13:43:15 +0200: > > > On Thu, Apr 18, 2024 at 11:32:44AM +0200, Miquel Raynal wrote: > > > Hi Sascha, > > > > > > s.hauer@pengutronix.de wrote on Thu, 18 Apr 2024 08:48:08 +0200: > > > > > > > On Wed, Apr 17, 2024 at 09:13:31AM +0200, Sascha Hauer wrote: > > > > > The NAND core enabled subpage reads when a largepage NAND is used with > > > > > SOFT_ECC. The i.MX NAND controller doesn't support subpage reads, so > > > > > clear the flag again. > > > > > > > > > > Signed-off-by: Sascha Hauer > > > > > --- > > > > > drivers/mtd/nand/raw/mxc_nand.c | 2 ++ > > > > > 1 file changed, 2 insertions(+) > > > > > > > > > > diff --git a/drivers/mtd/nand/raw/mxc_nand.c b/drivers/mtd/nand/raw/mxc_nand.c > > > > > index f44c130dca18d..19b46210bd194 100644 > > > > > --- a/drivers/mtd/nand/raw/mxc_nand.c > > > > > +++ b/drivers/mtd/nand/raw/mxc_nand.c > > > > > @@ -1667,6 +1667,8 @@ static int mxcnd_probe(struct platform_device *pdev) > > > > > if (err) > > > > > goto escan; > > > > > > > > > > + this->options &= ~NAND_SUBPAGE_READ; > > > > > + > > > > > > > > Nah, it doesn't work like this. It turns out the BBT is read using > > > > subpage reads before we can disable them here. > > > > > > > > This is the code in nand_scan_tail() we stumble upon: > > > > > > > > /* Large page NAND with SOFT_ECC should support subpage reads */ > > > > switch (ecc->engine_type) { > > > > case NAND_ECC_ENGINE_TYPE_SOFT: > > > > if (chip->page_shift > 9) > > > > chip->options |= NAND_SUBPAGE_READ; > > > > break; > > > > > > > > default: > > > > break; > > > > } > > > > > > > > So the code assumes subpage reads are ok when SOFT_ECC is in use, which > > > > in my case is not true. I guess some drivers depend on the > > > > NAND_SUBPAGE_READ bit magically be set, so simply removing this code is > > > > likely not an option. Any ideas what to do? > > > > > > Can you elaborate why subpage reads are not an option in your > > > situation? While subpage writes depend on chip capabilities, reads > > > however should always work: it's just the controller selecting the > > > column where to start and then reading less data than it could from the > > > NAND cache. It's a very basic NAND controller feature, and I remember > > > this was working on eg. an i.MX27. > > > > On the i.MX27 reading a full 2k page means triggering one read operation > > per 512 bytes in the NAND controller, so it would be possible to read > > subpages by triggering only one read operation instead of four in a row. > > > > The newer SoCs like i.MX25 always read a full page with a single read > > operation. We could likely read subpages by temporarily configuring the > > controller for a 512b page size NAND. > > > > I just realized the real problem comes with reading the OOB data. With > > software BCH the NAND layer hardcodes the read_subpage hook to > > nand_read_subpage() which uses nand_change_read_column_op() to read the > > OOB data. This uses NAND_CMD_RNDOUT and I have now idea if/how this can > > be implemented in the i.MX NAND driver. Right now the controller indeed > > reads some data and then the SRAM buffer really contains part of the > > desired OOB data, but also part of the user data. > > NAND_CMD_RNDOUT is impossible to avoid, Apparently it has been possible until now. NAND_CMD_RNDOUT has never been used with this driver and it also doesn't work like expected. One problem is that the read_page_raw() and write_page_raw() are not implemented like supposed by the NAND layer. The i.MX NAND controller uses a syndrome type ECC layout, meaning that the user data and OOB data is interleaved, so the raw r/w functions should normally pass/expect the page data in interleaved format. Unfortunately the raw functions are not implemented like that, instead they detangle the data themselves. This also means that setting the cursor using NAND_CMD_RNDOUT will not put the cursor at a meaningful place, as the raw functions are not really exect/return the raw page data. This could be fixed, but the raw operations are also exposed to userspace, so fixing these would mean that we might break some userspace applications. The other point is that with using software BCH ecc the NAND layer requests me to read 7 bytes at offset 0x824. This can't be really implemented in the i.MX NAND driver. It only allows us to read a full 512 byte subpage, so whenever the NAND layer requests me to read a few bytes the controller will always transfer 512 bytes from which I then ignore most of it (and possibly trigger another 512 bytes transfer when reading the ECC for the next subpage). I think these issues can all be handled somehow, but this comes at a rather high price, both in effort and the risk of breaking userspace. It would be far easier to tell the NAND layer not to do subpage reads. Sascha -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |