Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp931527rdh; Fri, 24 Nov 2023 01:07:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IHz2AF5kpOvGGbcJHrtrRRrprbkOq9bNe4wtXGGRrC5h1M8ICKo25I1m5W5J/gghjeo9cy2 X-Received: by 2002:a05:6a20:734d:b0:18b:5390:293a with SMTP id v13-20020a056a20734d00b0018b5390293amr2213149pzc.3.1700816838813; Fri, 24 Nov 2023 01:07:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700816838; cv=none; d=google.com; s=arc-20160816; b=LInXJfAJFlNocqaPSwYt/pGf14cvgI/JcMcTdLdTYY0SAa/xzOK2JHKbYE6FgtQyyQ pyNJ9Q5BbxAhjmo/rUr8QhTNQMHNKyid14ESKNrCHJPsTAo9LTXHdNBQUZm257+2FsSc kkMsRiUYpGO6kFCMgNze9p/MoOlemcRcRwxf01ZB7F3nkRTqO/pfvUIjt0KQWsYwjVBa rUHLUIxFPm5TFHKDMuCN6psBQXVoKVX9sGIix/cMrWcQaziG5rolHUcx5tS54qFl8PB0 e+iWdNwd0P1DmONHpYpW3ciAsCCA3CKkmDPIR5ET02DZKxvhbtfCJNn4IiDOzwWU40Ns zFHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=PcaWZO0Dkmbqcz5MfADesr8jRHXPKhmFcuSLiJu9N6c=; fh=3sBv6ij2qKLdB+xTQG4NyJvkqXmJZnaZDE0kqi4XMyg=; b=bvJzartBkRGb0JjK/epDXmbPTK9UYJ1m96o3RLVHG6Es5aQM1AM3uxlDyIaHKxHkfi AgQujNpEm6psJteGBYh21H1XCwzSsOucvCrOFFCQZWJ027HL4ATx8brlvZdOj5xvvXOw 2n/2r6p0RhsCCgk/GhcU06gGf0YUEHe3FU2HOcCXS5OV6hw/ILJDtz8Zpo4fD9TaTfQP +eGXhln6JscLOvHGvIb5zBTXHgtCcPdHfHkj3Dg05/mKpjzaA37cWXmTccTKcwZnssII taFaOaPrYXZChDh3kwMhdOKOswClKQ5OxoyjLhcoM/PhHk2EMX1dL2gfEnfNcgvPWWgf iB1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="OxWvtk/P"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id z1-20020a056a001d8100b006cbf2bc6eaesi1681861pfw.188.2023.11.24.01.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 01:07:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="OxWvtk/P"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 553288263756; Fri, 24 Nov 2023 01:07:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231590AbjKXJG6 (ORCPT + 99 others); Fri, 24 Nov 2023 04:06:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbjKXJG4 (ORCPT ); Fri, 24 Nov 2023 04:06:56 -0500 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::221]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE8641BD for ; Fri, 24 Nov 2023 01:07:01 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 1DF50240013; Fri, 24 Nov 2023 09:06:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1700816820; 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=PcaWZO0Dkmbqcz5MfADesr8jRHXPKhmFcuSLiJu9N6c=; b=OxWvtk/PaHumDm4DrHkspMlPL9mIMLBuTz4yXJb5tYm/lJVB/J3hTg1v00iw0ZgEPpeLeq 0uRC5uy7xD5LueyouRR6+Er3w04yEgkLq5XZoEsFmy6oebOB/45j/tj237CsroX4aXNqKE ftiQvBgxZlbh3l8wsYFwFdMs+x6dhO7nSwPy/5SOgYvBJIsb1lF3exerDASnSOi9fCpIa3 4vONdWZP717ZLGgAQpSh1K+bV4dSF1rgmVKxJzEUwDdbBG2fFFXJ5+9HKEqOJcfnZ4gnxb wAB0yZar5TpeAXH8yhRZnJXNKV52DEZ3hYSVBjZ7fJRN+P4FGaqOOy/MEUPrHA== Date: Fri, 24 Nov 2023 10:06:57 +0100 From: Miquel Raynal To: Arseniy Krasnov Cc: Viacheslav Bocharov , Richard Weinberger , Vignesh Raghavendra , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , , , , , Subject: Re: [PATCH v1] mtd: rawnand: meson: handle OOB buffer according OOB layout Message-ID: <20231124100657.245d258f@xps-13> In-Reply-To: References: <20231109053953.3863664-1-avkrasnov@salutedevices.com> <5a82e3b96c94b45821707eb5d392384e1a026c2e.camel@lexina.in> <98c5a6ef-3865-9254-0af7-2d041a64d368@salutedevices.com> Organization: Bootlin X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 24 Nov 2023 01:07:16 -0800 (PST) Hi Arseniy, avkrasnov@salutedevices.com wrote on Fri, 24 Nov 2023 10:50:54 +0300: > Hello all, 2 weeks from 9.11, please ping I'm waiting for Viacheslav. >=20 > Thanks, Arseniy >=20 >=20 > On 09.11.2023 12:09, Arseniy Krasnov wrote: > > Hello, thanks for review! > >=20 > > On 09.11.2023 11:06, Viacheslav Bocharov wrote: =20 > >> Hi! > >> > >> On Thu, 2023-11-09 at 08:39 +0300, Arseniy Krasnov wrote: =20 > >>> In case of MTD_OPS_AUTO_OOB mode, MTD/NAND layer fills/reads OOB buff= er > >>> according current OOB layout so we need to follow it in the driver. > >>> > >>> Signed-off-by: Arseniy Krasnov > >>> --- > >>> drivers/mtd/nand/raw/meson_nand.c | 4 ++-- > >>> 1 file changed, 2 insertions(+), 2 deletions(-) > >>> > >>> diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw= /meson_nand.c > >>> index 561d46d860b7..0d4d358152d7 100644 > >>> --- a/drivers/mtd/nand/raw/meson_nand.c > >>> +++ b/drivers/mtd/nand/raw/meson_nand.c > >>> @@ -510,7 +510,7 @@ static void meson_nfc_set_user_byte(struct nand_c= hip *nand, u8 *oob_buf) > >>> __le64 *info; > >>> int i, count; > >>> =20 > >>> - for (i =3D 0, count =3D 0; i < nand->ecc.steps; i++, count +=3D 2) { > >>> + for (i =3D 0, count =3D 0; i < nand->ecc.steps; i++, count +=3D (2 = + nand->ecc.bytes)) { > >>> info =3D &meson_chip->info_buf[i]; > >>> *info |=3D oob_buf[count]; > >>> *info |=3D oob_buf[count + 1] << 8; =20 > >> Seems something wrong with your logic here. > >> I think this code should most likely look like this: > >> > >> for (i =3D 0, count =3D 0; i < nand->ecc.steps; i++, count +=3D nand->= ecc.bytes) { > >> info =3D &meson_chip->info_buf[i]; > >> *info |=3D oob_buf[count]; > >> if (nand->ecc.bytes > 1) > >> *info |=3D oob_buf[count + 1] << 8; > >> } =20 > >=20 > > For 64 bytes OOB and 512 bytes ECC this driver reports free areas as: > >=20 > > AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB > > AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB > > AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB > > AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB > >=20 > > where AA is free byte(user byte), BB - ECC codes. So to access user byt= es > > we need bytes 0,1,16,17,32,33,48,49. nand->ecc.bytes =3D=3D 14, so 'cou= nt' is > > increased at 16 every iteration, so i guess this is correct. > >=20 > > WDYT? > >=20 > > Thanks, Arseniy > > =20 > >> > >> =20 > >>> @@ -523,7 +523,7 @@ static void meson_nfc_get_user_byte(struct nand_c= hip *nand, u8 *oob_buf) > >>> __le64 *info; > >>> int i, count; > >>> =20 > >>> - for (i =3D 0, count =3D 0; i < nand->ecc.steps; i++, count +=3D 2) { > >>> + for (i =3D 0, count =3D 0; i < nand->ecc.steps; i++, count +=3D (2 = + nand->ecc.bytes)) { > >>> info =3D &meson_chip->info_buf[i]; > >>> oob_buf[count] =3D *info; > >>> oob_buf[count + 1] =3D *info >> 8; =20 > >> And there: > >> > >> for (i =3D 0, count =3D 0; i < nand->ecc.steps; i++, count +=3D nand->= ecc.bytes) { > >> info =3D &meson_chip->info_buf[i]; > >> oob_buf[count] =3D *info; > >> if (nand->ecc.bytes > 1) > >> oob_buf[count + 1] =3D *info >> 8; > >> } > >> > >> > >> This is more similar to the behavior of similar functions in the propr= ietary U-Boot. > >> > >> -- > >> Viacheslav Bocharov > >> =20 Thanks, Miqu=C3=A8l