Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp356040lqh; Tue, 7 May 2024 00:46:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU6rXjuY8LmiMTiIkYUPz4wfBykonYK0UOf3SfW+8oQbJFzK+TmhQXWgRjh3lsU4YZvossNM1FIW3wL6xzZV5y5kz0VubPmGUt2C8hv0Q== X-Google-Smtp-Source: AGHT+IEBfYx+nug0RQkzvx87pHpLK0jBXBiRqEwBcgmELFckJhhalgoB+KXbw+dh7hzc+bMvM3u9 X-Received: by 2002:a17:90a:e40b:b0:2b5:af07:1ce7 with SMTP id hv11-20020a17090ae40b00b002b5af071ce7mr2444229pjb.35.1715067975054; Tue, 07 May 2024 00:46:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715067975; cv=pass; d=google.com; s=arc-20160816; b=Y0rcMmiMyY15PqYHz8/vNGxNLdbm3vJEE5/KssM5cZjEclLW0VeT35J2MrxilSKDEw mOTGK2c94xigGAZ4tjH2NP0uLW12vHDJIQhAYr2cv1OVCPpr9TtLtb8GdbzOUwINOBuf QRgLLQNoFTH8J8GVEXyZJeWPXw+poQtXPM672Cx4E7H8qZx45VMmclfCOwVppmRU/Cke wUDkBFUXHEyArO+eHfYmJHlaSnmYQkIXP760o1sKXFtqEVLZ6byBsgvCezLkhPA/poiS lV/3wwo+qFinRoT4xJ25/APHc64y0ypMus4Efw2qPFVKabVd7Fevav/P7ICdBFFn2LWY u/1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date:dkim-signature; bh=g1uefqDLk/fsECxmCZwtq2WLO2NPd1F1ghvyIHDig/M=; fh=RsD2Wu/PkL4LmNZy/9z1j6mcj+O7Tm7PbiyQTKBxpww=; b=rfoC+wQr5ybVuK9YgKellAljOHVv+GP926MaxXmdojlVABp+l7XW7YX2Y07xzIyNiQ cC0P5vEZ6WH7A5tGkDP7M5Td4/8h8jDaTHAujNeRih8ZUTrlWSTqdNeOW9ktWhkXhz9h io1+oDm13FqdiUocMYjEp89A7thwdxySkGiER91ZMFVW78BJTmty28C7eqgxSo061mO2 xRf3Zjpgpk5L0JPK0hWQ/9aYTm1MbfMgL/IEIYZUbCvkjUbkvevxrxlHBjh5GE20K0J+ u7CJAKIJB9RP1WSqV4tmule22gd1TCUPMrto6w9PV6MyyWJLvxEmej27SSZlMJN+4CgW ro4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=M00XljaE; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-170832-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170832-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id mp3-20020a17090b190300b002b1628b0e07si11915651pjb.175.2024.05.07.00.46.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 00:46:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170832-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=M00XljaE; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-170832-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170832-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 86BB52860BB for ; Tue, 7 May 2024 07:45:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13DCC13C3F0; Tue, 7 May 2024 07:45:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="M00XljaE" Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (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 BC49613C3C0 for ; Tue, 7 May 2024 07:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715067952; cv=none; b=bEqcF/TKH1Ud6UC+rOiruE7rCdNkyrsg4mdlJWDGzlHwes+8iqmpGfwWuEs817jYAhUdb5DKwxvvSWn6ruuzyKtSfnCedg1H2XlWL2zQmDQvvfJyMkfIe/9Vh3O3e/3Wdddq7XSZaZFIZSd8+1nBoX+ETtkEN2mKsNQPzlSU+pA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715067952; c=relaxed/simple; bh=AxHL9xg+mFC6sPc7w09Awd3HmVldm43BtK2rfpIjzAQ=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PSPEQ2SOWnhXz9V1jsG/jr4QLl6QBQn4DvrPqL28xuLMSzOWWnfRMd+XcY0vzmAH1uYh0+ZV5lV0bowTFcwrViOmoNX1W7jFwNqsNNNM79FrZXQ8K7C6KzMHwGjxuDKc5Az/o3XYks1qW4g0fM43Q5VVK3xcMdQ4hPXo+pxUv68= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=M00XljaE; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id ADE29C0003; Tue, 7 May 2024 07:45:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1715067942; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g1uefqDLk/fsECxmCZwtq2WLO2NPd1F1ghvyIHDig/M=; b=M00XljaEOXxbAQmAVgHUGBQNUTKDAQnYHvs5ieaX/Bbrm9QQv/xpZ+WYNaPQkcz/q4LW5t BmPZlrlsV67keHukDm2p6WDeQoA7qfMpjNA1bKU/w9jalEVdaRUzdocIIxvyg73zT1e+Nn RBljTJvWyy4CV0hJrOjI92L4b5qyEJetfUCLDgpYUiATqFHJcJXzVcwQXjwWCd7zY3y4LR 95KepSm2c5BxRCJ9suMOZ6O42LyauPD4/f0QCJW+Ad/RRZoF7i7ldtzJktwRbYaFf6FYCW Qs6qEc+LVphaXnP4ibBfcokO3CPQvycRyIZgplF4+NUDZPUqa3fWEqiNijrfpA== Date: Tue, 7 May 2024 09:45:38 +0200 From: Miquel Raynal To: Sascha Hauer Cc: Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/4] mtd: nand: mxc_nand: support software ECC Message-ID: <20240507094538.745fb5a9@xps-13> In-Reply-To: References: <20240417-mtd-nand-mxc-nand-exec-op-v1-0-d12564fe54e9@pengutronix.de> <20240417-mtd-nand-mxc-nand-exec-op-v1-3-d12564fe54e9@pengutronix.de> <20240506160508.6c60d50f@xps-13> <20240506175106.2ab7c844@xps-13> Organization: Bootlin X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) 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=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: miquel.raynal@bootlin.com Hi Sascha, s.hauer@pengutronix.de wrote on Tue, 7 May 2024 09:12:30 +0200: > On Mon, May 06, 2024 at 05:51:06PM +0200, Miquel Raynal wrote: > > Hi Miquel, > >=20 > > miquel.raynal@bootlin.com wrote on Mon, 6 May 2024 16:05:08 +0200: > > =20 > > > Hi Sascha, > > >=20 > > > s.hauer@pengutronix.de wrote on Wed, 17 Apr 2024 09:13:30 +0200: > > > =20 > > > > To support software ECC we still need the driver provided read_oob, > > > > read_page_raw and write_page_raw ops, so set them unconditionally > > > > no matter which engine_type we use. The OOB layout on the other hand > > > > represents the layout the i.MX ECC hardware uses, so set this only > > > > when NAND_ECC_ENGINE_TYPE_ON_HOST is in use. > > > >=20 > > > > With these changes the driver can be used with software BCH ECC whi= ch > > > > is useful for NAND chips that require a stronger ECC than the i.MX > > > > hardware supports. > > > >=20 > > > > Signed-off-by: Sascha Hauer > > > > --- > > > > drivers/mtd/nand/raw/mxc_nand.c | 9 +++++---- > > > > 1 file changed, 5 insertions(+), 4 deletions(-) > > > >=20 > > > > diff --git a/drivers/mtd/nand/raw/mxc_nand.c b/drivers/mtd/nand/raw= /mxc_nand.c > > > > index fc70c65dea268..f44c130dca18d 100644 > > > > --- a/drivers/mtd/nand/raw/mxc_nand.c > > > > +++ b/drivers/mtd/nand/raw/mxc_nand.c > > > > @@ -1394,15 +1394,16 @@ static int mxcnd_attach_chip(struct nand_ch= ip *chip) > > > > chip->ecc.bytes =3D host->devtype_data->eccbytes; > > > > host->eccsize =3D host->devtype_data->eccsize; > > > > chip->ecc.size =3D 512; > > > > - mtd_set_ooblayout(mtd, host->devtype_data->ooblayout); > > > > + > > > > + chip->ecc.read_oob =3D mxc_nand_read_oob; > > > > + chip->ecc.read_page_raw =3D mxc_nand_read_page_raw; > > > > + chip->ecc.write_page_raw =3D mxc_nand_write_page_raw; =20 > >=20 > > A second thought on this. Maybe you should consider keeping these for > > on-host operations only. > >=20 > > The read/write_page_raw operations are supposed to detangle the data > > organization to show a proper [all data][all oob] organization to the > > user. =20 >=20 > Let me take one step back. The organisation in the raw NAND is like this > when using hardware ECC: >=20 > [512b data0][16b oob0][512b data1][16b oob1][512b data2][16b oob2][512b d= ata3][16b oob3] >=20 > For a standard 2k+64b NAND. The read/write_page_raw operations detangle > this and present the data to the user like this: >=20 > [2048b data][64b OOB] >=20 > Is this the correct behaviour or should that be changed? I believe so, yes. > (Side note: The GPMI NAND driver behaves differently here. It has the > same interleaved organisation on the chip and also presents the same > interleaved organisation to the user when using read_page_raw) I'd say the GPMI driver is wrong? > With my current approach for software ECC the same layout is used on the > NAND chip. It would interleave the data with the OOB on the NAND chip > and, since using the same read/write_page_raw operations, also presents > [2048b data][64b OOB] to the user. No need, I believe the only reason for interleaving is that your hardware ECC engine works like that (writes the ECC bytes slightly after each chunk of data). So if you don't use on-host hardware ECC, you don't need to deal with this data layout. > This works fine currently, but means that NAND_CMD_RNDOUT can't be used. > Using NAND_CMD_RNDOUT to position the cursor at offset 512b for example > doesn't give you the second subpage, but instead oob0. Positioning the > cursor at offset 2048 doesn't give you the start of OOB, but some > position in the middle of data3. >=20 > Ok, NAND_CMD_RNDOUT can't be used for hardware ECC and there's no way > around it. For software ECC we could change the organisation in the chip > to be [2048b data][64b oob]. With that NAND_CMD_RNDOUT then could be > used with software ECC. >=20 > You say that NAND_CMD_RNDOUT is a basic command that is supported by all > controllers, and yes, it is also supported with the mxc_nand controller. > You just can't control how many bytes are transferred between the NAND > chip and the controller. When using NAND_CMD_RNDOUT to read a few bytes > at a certain page offset we'll end up reading 512 bytes discarding most > of it. For the next ECC block we would move the cursor forward using > another NAND_CMD_RNDOUT command, again read 512 bytes and discard most > it (altough the desired data would have been in the first read already). I'm not sure the controller limitations are so bad in this case. The core helpers (using the same example) will ask for: - 512b at offset 0 - 512b at offset 512... - and finally 64b at offset 2048. In practice it does not look like a huge drawback? I don't understand in which case so much data would be read and then discarded? > So I think NAND_CMD_RNDOUT should really be avoided for this controller, > eventhough we might be able to support it. I also mentioned the monolithic accessors which try to avoid these random column changes. You probably want to check them out, they might just avoid the need for NAND_CMD_RNDOUT by forcing full page accesses directly. The reason why they were introduced is not exactly our current use case, but it feels like they might be handy. 658beb663960 ("mtd: rawnand: Expose monolithic read/write_page_raw() helper= s") 0e7f4b64ea46 ("mtd: rawnand: Allow controllers to overload soft ECC hooks") Thanks, Miqu=C3=A8l