From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223460; b=GMkAAsvN1QLwKVYHDyCK7FDjEDb+pPgl62GcM7LQkuof+7hMLr5iLOA4jpBIyIjCG9In JSmIQ3b30ZBYEH0LYhQtrb2AkYY3LiklALfhTfP18KXVb4E69Ik4ysgU/yfZOndIxIN9X t41wce29OX5u0UidhBjSpLpN8p+4VzUFkPQX/daI6QT0ViY3Che6+0IfZvVLxWkOZZYeo VRfSeIkQZ8lfibkelDxbiovnSm5RYEoQSWIDi0536hK3rVbXFvC1t3WZcEzeD0v+t3CAc jEX5qevKiF/cILG/MPxbqeSu7Q+OPwp0LJ/DikVhNnMfTjh20GlM7QmSw8YQe6x0r+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223460; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=SRAIIk9U6fp4Kf8B545qVrRs6kaxTJjBXvTeCKe8iRc=; b=HFCv1fSiulBGAcq0PgJhc+mUBq/vmJrBCPwN+2iqsqBmCPaPzWR4BqhfTxYf38v1WGUy uB0g8lrj7epKIjUJ4ah/OC7UzMfTMejhUCj2Ztys9ucB8I/wKgXqaPmxamkjezdLrK07d ULKYHyl79z+wHILrbPG80tBod/K/kJF7b8I9xy79JJoCdghx2oHK7Sky2tsR5zJuKrpo/ RtVS081QEwjLVsO3sMh4RMbU2N2Oa13LiYdVe2bXqFKAAErYy8cYGwCgEjrDukjJFx1HV WhM6zdEl21kC1SXfs3j4aVo/JMvYMZAcv3au7ZinR3nK6kfVRjmDVgpibXr545IK38A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=JNuVTiSU; arc=none smtp.remote-ip=209.85.167.173 Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77BB8606A331 for ; Sat, 21 Nov 2026 01:10:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 77BB8606A331 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=JNuVTiSU Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-563a0462094so851224b6e.1 for ; Fri, 20 Nov 2026 17:10:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223456; x=1795828256; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SRAIIk9U6fp4Kf8B545qVrRs6kaxTJjBXvTeCKe8iRc=; b=JNuVTiSUuEsTWj7qCnZYdRCXwqSht9IdUt8F33iMN7Nm35L9CFozxS+eOT5RG8ia+u j/iSQZOBfWJ0uiuv4309io0ck47D/I6U7Whbd/xljYzjTdZxp9lYWdwu9OKygAB822+7 gwZ56w5UrvP92Ot9nbbxZiDj1Zp+V46VuI89J2zrl5tdr3/s+dDdWQGHNanrGXtkqJlz /CTPUc2KfrsZ0ISPwcBsnonhzh5hZwRbLHEeJMzkkAvuxHIUUg97mIZR3j7YZ2bkmeV2 8GDKXC4HEgcwYYXBVmGg9WtHDwF+QQnoASQ9x/SrhCTYSSAQIMTWdeC3Pl/AdbFUWOqj vD1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223456; x=1795828256; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=SRAIIk9U6fp4Kf8B545qVrRs6kaxTJjBXvTeCKe8iRc=; b=OK12k28RuZUo6PkbZU2xmH2OjpGjpJ7ucPvYZ5Cjum0JJRFnwgqO6suIRg9YSmC5/7 QFWH3IwMbw9s77s0NlxDZ/9YdDe1JqTf/TdhyKySByHgAqLiHKyAv1peXXm11h4hXIUz XE1uz5uoN//an72ROEkrSJIU+/xGwOTVtJhrVio3VjMP/THhljonQcEFwdl32q22SEZs KgLR9zHOKJQ4CHpBNzBxYFopQhSX4HuSlucqVCk9AuuDzs29c8gcVHoG/8xns75D9xmD D1ryQrxmaM9xeD4fQf0rhFzqwEAXwgEiaRYsEmSXZ5Nng5EHxsQwy8Ntkx7q1RPfUI1O 7rZw== X-Forwarded-Encrypted: i=1; AL+hErFpI+UuRI5a2wJ0Aug8WBY8n5EsW0O/qD23McdJJunxfh6A6jNO+Fm4IhNftpWteLMrulOPUmckQ1z91hE=@vger.kernel.org X-Gm-Message-State: APuU4Z8yOF2BrxeAeMeHLiz6j3lOcdtbAphmKgBrC5aSAnklsoI2bjbz /9JYajvxlo4zPBZJNPcJQ2HPBM/Ad2fKM4rBnHLM5tD71e3ukgle5oE7 X-Gm-Gg: AYBFou2LzRsQEkl1D4Nb6obqal/UJne+xLzfPtRBVm7llwDwEEMCfmYJplQB4Yuj5PM yChMx2xCaPgPMAn1njr5irjBrOf7NRYYdvNLIiCxaGqN0GPH3cWvgYylcCN2zchEFENpTIiBKSw EZD+SVemZIDl/ud5QnmPxutYzs3saEiz/YFwfi+4kl6s4PQCioeVcogAOQYSBTDFhTo4BS0J3bt iJS0p+Q7a79kzWDckFUtQoewHfWlggX1hYkywMfJybnEeL8LxEag+HYw3JrWfTMGdIise52sIyn 4iRO5RQlaJ6J79FUrB0VgDXmhEe1cCgim4gvooUbGwpb43aih5dvyZvWHBEppPfFKEntqMOkGRl UdO4VoaOkxUxQ0wOBYFmRG69wzG3sGVb23D0eS6sbtqHfdeuj8sZI/zyH+/JBhFgyfJhu9ZeCFM 5wf+HZqSovfqEhyBf+8vCVfo7t9rnrshbnbkPoYRCDOe1rdA7Zv1R9vNTchUPo+zrdT8dW5yasl QlQI61tntxu3QbsRuwnw2367RMymFRN+wNsINrRvw0qPAR72s4jylH4SAOVFMyvu0SqN/fEPd6x 4HDUVEkGbBBUCOdFKG/6fB32SyiOMxuO++Vzrdt21X0JGVWoN9uHcxatshuK3XgcIo1FfJP8Ymv ovOz0ElnLKr8NyjpF3xx8HXxTyC7GzQKmCt3oVfVJJPAueVVNH2u831z24C7XOo9KU8LCr0ZIHD MkDFxHHO4ojqkpYZRfauhlQXxdGQbBu9pjktqza5rWGiQQIRZ+Wjq6 X-Received: by 2002:a05:6808:c12b:b0:4f6:5279:5c89 with SMTP id 5614622812f47-57a0b03f55bmr5137406b6e.47.1795223456322; Fri, 20 Nov 2026 17:10:56 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.10.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:10:55 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:24 -0700 Subject: [PATCH v11 01/26] mtd: rawnand: sunxi: select the protected OOB layout from match data X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-1-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev The ECC strength chosen at attach and the OOB layout used for page transfers must reserve space for the same protected bytes. A10 and A23 store four bytes per step. Their strength calculation also reserves two extra bytes for historical compatibility. H616 needs only one four-byte word for the bad-block marker; after choosing the strength it can distribute the remaining space among the steps. Select the reservation and initialization together from controller match data. Keep the fixed layout independent of the step count at attach: the NAND core can subsequently choose a software ECC geometry. The selected strengths and on-flash byte positions stay the same. Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 98 ++++++++++++++++++-----------------= ---- 1 file changed, 46 insertions(+), 52 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 66ce53850eef..c6001349266f 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -293,6 +293,13 @@ struct sunxi_nfc_mdma_desc { __le32 next; } __packed __aligned(4); =20 +struct sunxi_nfc_user_data_layout { + /* Space to reserve before choosing the ECC strength. */ + unsigned int (*min_user_data)(int nsteps); + /* Optional setup after the step size and parity length are known. */ + int (*init_user_data)(struct nand_chip *nand, int nsteps); +}; + /* * NAND Controller capabilities structure: stores NAND controller capabili= ties * for distinction between compatible strings. @@ -302,8 +309,7 @@ struct sunxi_nfc_mdma_desc { * @has_ecc_block_512: If the ECC can handle 512B or only 1024B chunks * @has_ecc_clk: If the controller needs an ECC clock. * @has_mbus_clk: If the controller needs a mbus clock. - * @legacy_max_strength:If the maximize strength function was off by 2 byt= es - * NB: this should not be used in new controllers + * @layout: protected user-data layout for the controller * @reg_io_data: I/O data register * @reg_ecc_err_cnt: ECC error counter register * @reg_user_data: User data register @@ -335,7 +341,7 @@ struct sunxi_nfc_caps { bool has_ecc_block_512; bool has_ecc_clk; bool has_mbus_clk; - bool legacy_max_strength; + const struct sunxi_nfc_user_data_layout *layout; unsigned int reg_io_data; unsigned int reg_ecc_err_cnt; unsigned int reg_user_data; @@ -2026,24 +2032,35 @@ static void sunxi_nand_detach_chip(struct nand_chip= *nand) sunxi_nand->user_data_bytes =3D NULL; } =20 -static int sunxi_nfc_maximize_user_data(struct nand_chip *nand, uint32_t o= obsize, - int ecc_bytes, int nsectors) +static unsigned int sunxi_nfc_fixed_min_user_data(int nsteps) +{ + /* Preserve the ECC strength selected with the legacy BBM allowance. */ + return nsteps * USER_DATA_SZ + 2; +} + +static unsigned int sunxi_nfc_variable_min_user_data(int nsteps) +{ + /* The first protected word contains the bad-block marker. */ + return USER_DATA_SZ; +} + +static int sunxi_nfc_variable_init_user_data(struct nand_chip *nand, int n= steps) { struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); const struct sunxi_nfc_caps *c =3D nfc->caps; - int remaining_bytes =3D oobsize - (ecc_bytes * nsectors); + int remaining_bytes =3D nand_to_mtd(nand)->oobsize - nand->ecc.bytes * ns= teps; int i, step; =20 - if (nsectors <=3D 0) + if (nsteps <=3D 0) return -EINVAL; =20 - sunxi_nand->user_data_bytes =3D devm_kzalloc(nfc->dev, nsectors, + sunxi_nand->user_data_bytes =3D devm_kzalloc(nfc->dev, nsteps, GFP_KERNEL); if (!sunxi_nand->user_data_bytes) return -ENOMEM; =20 - for (step =3D 0; (step < nsectors) && (remaining_bytes > 0); step++) { + for (step =3D 0; (step < nsteps) && (remaining_bytes > 0); step++) { for (i =3D 0; i < c->nuser_data_tab; i++) { if (c->user_data_len_tab[i] > remaining_bytes) break; @@ -2059,12 +2076,21 @@ static int sunxi_nfc_maximize_user_data(struct nand= _chip *nand, uint32_t oobsize return 0; } =20 +static const struct sunxi_nfc_user_data_layout sunxi_nfc_fixed_layout =3D { + .min_user_data =3D sunxi_nfc_fixed_min_user_data, +}; + +static const struct sunxi_nfc_user_data_layout sunxi_nfc_variable_layout = =3D { + .min_user_data =3D sunxi_nfc_variable_min_user_data, + .init_user_data =3D sunxi_nfc_variable_init_user_data, +}; + static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, - struct nand_ecc_ctrl *ecc, - struct device_node *np) + struct nand_ecc_ctrl *ecc) { struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); + const struct sunxi_nfc_user_data_layout *layout =3D nfc->caps->layout; const u8 *strengths =3D nfc->caps->ecc_strengths; struct mtd_info *mtd =3D nand_to_mtd(nand); struct nand_device *nanddev =3D mtd_to_nanddev(mtd); @@ -2083,33 +2109,7 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_c= hip *nand, ecc->size =3D 1024; nsectors =3D mtd->writesize / ecc->size; =20 - if (!nfc->caps->reg_user_data_len) { - /* - * If there's a fixed user data length, subtract it before - * computing the max ECC strength - */ - - for (i =3D 0; i < nsectors; i++) - total_user_data_sz +=3D sunxi_nfc_user_data_sz(sunxi_nand, i); - - /* - * The 2 BBM bytes should not be removed from the grand total, - * because they are part of the USER_DATA_SZ. - * But we can't modify that for older platform since it may - * result in a stronger ECC at the end, and break the - * compatibility. - */ - if (nfc->caps->legacy_max_strength) - bytes -=3D 2; - - bytes -=3D total_user_data_sz; - } else { - /* - * User-data lengths are encoded in four-byte units. Reserve - * the first word because it contains the two BBM bytes. - */ - bytes -=3D USER_DATA_SZ; - } + bytes -=3D layout->min_user_data(nsectors); =20 /* * Once all user data has been subtracted, the rest can be used @@ -2173,20 +2173,14 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_= chip *nand, return -EINVAL; } =20 - /* - * The rationale for variable data length is to prioritize maximum ECC - * strength, and then use the remaining space for user data. - */ - if (nfc->caps->reg_user_data_len) { - ret =3D sunxi_nfc_maximize_user_data(nand, mtd->oobsize, - ecc->bytes, nsectors); + if (layout->init_user_data) { + ret =3D layout->init_user_data(nand, nsectors); if (ret) return ret; } =20 - if (total_user_data_sz =3D=3D 0) - for (i =3D 0; i < nsectors; i++) - total_user_data_sz +=3D sunxi_nfc_user_data_sz(sunxi_nand, i); + for (i =3D 0; i < nsectors; i++) + total_user_data_sz +=3D sunxi_nfc_user_data_sz(sunxi_nand, i); =20 if (mtd->oobsize < (ecc->bytes * nsectors + total_user_data_sz)) return -EINVAL; @@ -2233,7 +2227,6 @@ static int sunxi_nand_attach_chip(struct nand_chip *n= and) const struct nand_ecc_props *requirements =3D nanddev_get_ecc_requirements(&nand->base); struct nand_ecc_ctrl *ecc =3D &nand->ecc; - struct device_node *np =3D nand_get_flash_node(nand); int ret; =20 if (nand->bbt_options & NAND_BBT_USE_FLASH) @@ -2254,7 +2247,7 @@ static int sunxi_nand_attach_chip(struct nand_chip *n= and) =20 switch (ecc->engine_type) { case NAND_ECC_ENGINE_TYPE_ON_HOST: - ret =3D sunxi_nand_hw_ecc_ctrl_init(nand, ecc, np); + ret =3D sunxi_nand_hw_ecc_ctrl_init(nand, ecc); if (ret) return ret; break; @@ -2725,7 +2718,7 @@ static const u8 sunxi_user_data_len_h6[] =3D { =20 static const struct sunxi_nfc_caps sunxi_nfc_a10_caps =3D { .has_ecc_block_512 =3D true, - .legacy_max_strength =3D true, + .layout =3D &sunxi_nfc_fixed_layout, .reg_io_data =3D NFC_REG_A10_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, @@ -2748,7 +2741,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_caps= =3D { static const struct sunxi_nfc_caps sunxi_nfc_a23_caps =3D { .has_mdma =3D true, .has_ecc_block_512 =3D true, - .legacy_max_strength =3D true, + .layout =3D &sunxi_nfc_fixed_layout, .reg_io_data =3D NFC_REG_A23_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, @@ -2769,6 +2762,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a23_caps= =3D { }; =20 static const struct sunxi_nfc_caps sunxi_nfc_h616_caps =3D { + .layout =3D &sunxi_nfc_variable_layout, .has_mdma_desc =3D true, .has_ecc_clk =3D true, .has_mbus_clk =3D true, --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223463; b=bMG78xg76O2Hf4KSCsp8gQvCVNJNEYjMZjkpukRmw5R9Pnl8xLtBZzUIfeeVHtUuGO9x eaL52NEnZ0c+A5UJ93IFtmjGYpvHGz6OFYaeLXMvFRQ5kgYNtS5jliEd2qBBLJRgy/VkM s1jCtb/Zqmbca2jGOrsH+GT5AAuUIkEoAUMZcUDmQIqZ4p1mySwmkgM3r6a+QAIJ/7kKg jHPLpDt688E81WPXlvtX6aVoJSKYQ3hGhteSNNvU4n5sJ3JWjLogBCtqQWjT+dZpxfkqh SVL2GSjySrEoODln+yjqiZF26UyBBPQi7b8MHe7+AXNssfaAFNTzV13VOUpHZyuYTHA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223463; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=8/B8gGukZxMNCk9kG+bQ03cwup62u0VomkG0JFdqRS0=; b=rOtABuNxzJDkYAmuJFn9onXlXtrE06ghy5ybb0+S9u5R7fAXOXAPnbzyyNoJWqMEwr9x 7hXbn0wfG4OZ1fGXbpXOs0OxgtQIBAOJoGvJSD5TRd2PEZQYtcsfvUZLaKDa6tzPedA0a XpuO8Nd4BST7hT2EN3Tg7bZRFl5KFz4DkUdzkaCrxxtMY9MT/tzNCputoZpnOpekwkGwy aCEMfnjqKYDButD+vGc7ptz2pO6GzDszXNM6Dxlnci4KrYusgoFy5kGjmiAHNRDv4xUIH I7P8y9x6Rj/4+3Fa5T3OibhNLz5tVElkcryAZFFOTp5aG9LvTn5NCkuhxE+C5BFtOGA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=K7j+Md8W; arc=none smtp.remote-ip=209.85.167.174 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D052606A6A6 for ; Sat, 21 Nov 2026 01:10:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2D052606A6A6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=K7j+Md8W Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-4c5d8c7f326so664140b6e.1 for ; Fri, 20 Nov 2026 17:10:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223458; x=1795828258; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8/B8gGukZxMNCk9kG+bQ03cwup62u0VomkG0JFdqRS0=; b=K7j+Md8WLnplGjt6beXjGVW9VOqJhKWkWJOP1SRinco7njvxpt+4bOj/7Qe0CanTp6 /mvzZbjqB6d2/hxrdzCtDWJpCY+jxdOd5D1wZF1qX4tN5uOMiJhbPM4204A/f2KPHeft rqlAvtjnu+6/RsgbhZr0ilISjbAPloolZAmRem3PvmdBUPTViloSFUoudmTny65hwOfi F6HJz5vymHu5aYPhiNgtXlajzMzVHedo/Ixc/WOjBk1iTzxWVd+MgrFNmU68ZVd68yl2 +CBr9h7PR+1h9Rq/AnFFrHc49XRLG6D5u7HbewktevDpbhqCzJOFMXkaw7aax7OEUwTj 1zXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223458; x=1795828258; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=8/B8gGukZxMNCk9kG+bQ03cwup62u0VomkG0JFdqRS0=; b=ufG3+5aOsTdLi6WoDLqegKTPNHbux8ieAyrmixsCkvnMWEgePK4Og4mxklieBqvfGi FeGiYINe3ViSZ4QJxfPTHuPHFfe/HV0ZoHq/iPcwsZUAIkaV2AnVNGoRP1JKYNijJSxg ZZxrCft92Ua2Bces/AFATIgucoP5yFwIPM7MMv1G9mfY17Hi3uKmkXGqhC8hB5bw5jWj ucnDluZfDIM9h99/Te3ZgRXO6sSdxNvQnJfA+VmKj77JQrOSitvldlmZP99ZNFjvn6Q2 J/YlV0IIn/hLb+8hHVvcLwgd+OdSxRKrHHUo9TZS7Wp0Na6NADC24uk0VUX4nmRlSOGu dv/A== X-Forwarded-Encrypted: i=1; AL+hErFnq7HkynbdGmkZyQHwRxUo12X4J3c15K9n44mM2eZXX6K09bhKrpbF/oiI1Yd4fP+fP38dV9y/XHh/5iE=@vger.kernel.org X-Gm-Message-State: APuU4Z8tne1zDpw1Aq5Cu9xSXp/s473DWH2yX0ZBCBBn+61snixXfLQJ fz8BDYCfH6dfJvGwRQct5XGuVdx8Jy09qwkPYd36eMOlUE2qD8FmTOMf X-Gm-Gg: AYBFou35uHHlvLtXalqL1eT9AxGTc8mEyscre33NJQKi+uIf4mrYAAwwvjg6Wk5p3qg 8URDItYYW+1qY3sZAI6hz3A6I4HThKvimN96Z9lO1JHebzNERnAiImmRWe3sVBv0LgYrYZAXqgX 8YKN6BU+ZW4mMVy4meU4G9dIDN3eRpBAv3MAjQMUVXaJQzBlZBUDzNFy9d3/jRhNe9LSk1T/YBT St+0coYHIzhsU56Szpkg9Tq68YRRAjqNq6bvamtb2YrQO1lEUouL6oZOLY3XxO6Hxuo0iS8wW8u hnVxIMerW35pTogdqGIiey/EbZXwJwW8mdiKhlvrFpjRNZG6DHTSlwEHqlJD5zga6pEPaJ+Aacs fg5mLskMZs7zPN21ce61NqWOhjmDES8C2ykL2hTUPTusMmyn/37kUsgGHiJf5v7ghn6leJRfa+O 5yx7R/v0orLc6oUsGOEamEaaCk/NxfmTZ4FTz2MlMr1K6EOcDR4jtXeqOWtwao+CXfEgOi9Nz2Q zucgQeSBwnhMtqEOSlgbvrNppYpOPCs0Yr46qdMUGHn/FZ64w4/KxjsPdIUIDGX2UO3m7qy3POe lX9ximTm0HNNEDxrXfx784hLRVwhAZ8M3EJlyt87/TnlH8W3q9raHCLyFERBArNg9P2eRFMKa8I 5eROzTPnWSnA82pWbe+WiCk7g5H2t58/PcojgFYS9GjPjXOgsYAj9cb/+jK92kqDbTyCw5K6Fe3 TQDpi/+ZI6UotH1lsMqSZLQ3T4fAn0fhtlDLCtE+cARiog7ybC+rAl84KL24/FirOEv8xDtd5T8 w== X-Received: by 2002:a05:6808:4f46:b0:4d6:90f3:74b2 with SMTP id 5614622812f47-57a0bb54161mr6128010b6e.50.1795223458025; Fri, 20 Nov 2026 17:10:58 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:10:57 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:25 -0700 Subject: [PATCH v11 02/26] mtd: rawnand: sunxi: compute protected OOB offsets from page geometry X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-2-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev PIO and DMA need the OOB offset of each ECC step. The driver finds it by summing the protected lengths of all preceding steps, repeating the same walk across a page. On H616 it also allocates a length array when the chip is attached, although its entries follow a fixed rule. On A10 and A23 each step has four protected bytes. Keep that rule independent of the step count chosen at attach: the NAND core can fall back to software ECC with a different geometry. H616 assigns the available space to the earliest steps first, in four-byte units up to 32 bytes per step. Store the total and the per-step limit. The number of protected bytes before a given step is then its index times the limit, capped at the page total. This gives both the OOB and parity offsets without walking an array or allocating memory at attach. Use the same four-byte encoding to program the controller's length fields. The ECC strength and on-flash offsets do not change. Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 132 ++++++++++++++--------------------= ---- 1 file changed, 49 insertions(+), 83 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index c6001349266f..f57184927fe9 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -267,7 +267,8 @@ struct sunxi_nfc_timings { * @timing_ctl: TIMING_CTL register value for this NAND chip * @nsels: number of CS lines required by the NAND chip * @sels: array of CS lines descriptions - * @user_data_bytes: array of user data lengths for all ECC steps + * @user_data_total: protected user bytes in a programmable layout + * @user_data_step: maximum bytes assigned to each step, zero for a fixed = layout */ struct sunxi_nand_chip { struct list_head node; @@ -276,7 +277,8 @@ struct sunxi_nand_chip { unsigned long clk_rate; u32 timing_cfg; u32 timing_ctl; - u8 *user_data_bytes; + u16 user_data_total; + u8 user_data_step; int nsels; struct sunxi_nand_chip_sel sels[] __counted_by(nsels); }; @@ -327,11 +329,7 @@ struct sunxi_nfc_user_data_layout { * @nstrengths: Size of @ecc_strengths * @max_ecc_steps: Maximum supported steps for ECC, this is also the * number of user data registers - * @user_data_len_tab: Table of lengths supported by USER_DATA_LEN regist= er - * The table index is the value to set in NFC_USER_DATA_LEN - * registers, and the corresponding value is the number of - * bytes to write - * @nuser_data_tab: Size of @user_data_len_tab + * @max_user_data_len: Maximum programmable user-data bytes per ECC step * @sram_size: Size of the NAND controller SRAM * @timings: Controller timing characteristics */ @@ -357,8 +355,7 @@ struct sunxi_nfc_caps { unsigned int dma_maxburst; const u8 *ecc_strengths; unsigned int nstrengths; - const u8 *user_data_len_tab; - unsigned int nuser_data_tab; + unsigned int max_user_data_len; unsigned int max_ecc_steps; int sram_size; const struct sunxi_nfc_timings *timings; @@ -911,12 +908,21 @@ static inline u32 sunxi_nfc_buf_to_user_data(const u8= *buf) return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); } =20 -static u8 sunxi_nfc_user_data_sz(struct sunxi_nand_chip *sunxi_nand, int s= tep) +/* Earlier ECC steps take their full share before later steps use any byte= s. */ +static unsigned int sunxi_nfc_user_data_before(struct sunxi_nand_chip *sun= xi_nand, + unsigned int step) { - if (!sunxi_nand->user_data_bytes) - return USER_DATA_SZ; + if (!sunxi_nand->user_data_step) + return step * USER_DATA_SZ; + + return min_t(unsigned int, step * sunxi_nand->user_data_step, + sunxi_nand->user_data_total); +} =20 - return sunxi_nand->user_data_bytes[step]; +static u8 sunxi_nfc_user_data_sz(struct sunxi_nand_chip *sunxi_nand, int s= tep) +{ + return sunxi_nfc_user_data_before(sunxi_nand, step + 1) - + sunxi_nfc_user_data_before(sunxi_nand, step); } =20 static void sunxi_nfc_hw_ecc_get_prot_oob_bytes(struct nand_chip *nand, u8= *oob, @@ -977,34 +983,35 @@ static void sunxi_nfc_reset_user_data_len(struct sunx= i_nfc *nfc) writel(0, nfc->regs + NFC_REG_USER_DATA_LEN(nfc, i)); } =20 +static int sunxi_nfc_user_data_len_code(struct sunxi_nfc *nfc, int len) +{ + /* Each code counts four-byte words; larger codes are reserved. */ + if (len < 0 || len > nfc->caps->max_user_data_len || !IS_ALIGNED(len, USE= R_DATA_SZ)) { + dev_warn(nfc->dev, "Unsupported length for user data reg: %d\n", len); + return -EINVAL; + } + + return len / USER_DATA_SZ; +} + static void sunxi_nfc_set_user_data_len(struct sunxi_nfc *nfc, int len, int step) { - bool found =3D false; u32 val; - int i; + int code; =20 /* not all SoCs have this register */ if (!nfc->caps->reg_user_data_len) return; =20 - for (i =3D 0; i < nfc->caps->nuser_data_tab; i++) { - if (len =3D=3D nfc->caps->user_data_len_tab[i]) { - found =3D true; - break; - } - } - - if (!found) { - dev_warn(nfc->dev, - "Unsupported length for user data reg: %d\n", len); + code =3D sunxi_nfc_user_data_len_code(nfc, len); + if (code < 0) return; - } =20 val =3D readl(nfc->regs + NFC_REG_USER_DATA_LEN(nfc, step)); =20 val &=3D ~NFC_USER_DATA_LEN_MSK(step); - val |=3D field_prep(NFC_USER_DATA_LEN_MSK(step), i); + val |=3D field_prep(NFC_USER_DATA_LEN_MSK(step), code); writel(val, nfc->regs + NFC_REG_USER_DATA_LEN(nfc, step)); } =20 @@ -1204,13 +1211,7 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_c= hip *nand, static int sunxi_get_oob_offset(struct sunxi_nand_chip *sunxi_nand, struct nand_ecc_ctrl *ecc, int step) { - int ecc_off =3D step * ecc->bytes; - int i; - - for (i =3D 0; i < step; i++) - ecc_off +=3D sunxi_nfc_user_data_sz(sunxi_nand, i); - - return ecc_off; + return step * ecc->bytes + sunxi_nfc_user_data_before(sunxi_nand, step); } =20 /* @@ -1221,8 +1222,7 @@ static int sunxi_get_oob_offset(struct sunxi_nand_chi= p *sunxi_nand, static int sunxi_get_ecc_offset(struct sunxi_nand_chip *sunxi_nand, struct nand_ecc_ctrl *ecc, int step) { - return sunxi_get_oob_offset(sunxi_nand, ecc, step) + - sunxi_nfc_user_data_sz(sunxi_nand, step); + return step * ecc->bytes + sunxi_nfc_user_data_before(sunxi_nand, step + = 1); } =20 static void sunxi_nfc_hw_ecc_read_extra_oob(struct nand_chip *nand, @@ -1991,10 +1991,7 @@ static int sunxi_nand_ooblayout_free(struct mtd_info= *mtd, int section, struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); unsigned int user_data_sz; =20 - /* - * The controller does not provide access to OOB bytes - * past the end of the ECC data. - */ + /* Only ECC-protected user data is exposed as free OOB. */ if (section >=3D ecc->steps) return -ERANGE; =20 @@ -2023,15 +2020,6 @@ static const struct mtd_ooblayout_ops sunxi_nand_oob= layout_ops =3D { .free =3D sunxi_nand_ooblayout_free, }; =20 -static void sunxi_nand_detach_chip(struct nand_chip *nand) -{ - struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); - struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); - - devm_kfree(nfc->dev, sunxi_nand->user_data_bytes); - sunxi_nand->user_data_bytes =3D NULL; -} - static unsigned int sunxi_nfc_fixed_min_user_data(int nsteps) { /* Preserve the ECC strength selected with the legacy BBM allowance. */ @@ -2048,31 +2036,19 @@ static int sunxi_nfc_variable_init_user_data(struct= nand_chip *nand, int nsteps) { struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); - const struct sunxi_nfc_caps *c =3D nfc->caps; - int remaining_bytes =3D nand_to_mtd(nand)->oobsize - nand->ecc.bytes * ns= teps; - int i, step; + const struct sunxi_nfc_caps *caps =3D nfc->caps; + unsigned int oobsize =3D nand_to_mtd(nand)->oobsize; + unsigned int parity =3D nsteps * nand->ecc.bytes; + unsigned int available; =20 - if (nsteps <=3D 0) - return -EINVAL; - - sunxi_nand->user_data_bytes =3D devm_kzalloc(nfc->dev, nsteps, - GFP_KERNEL); - if (!sunxi_nand->user_data_bytes) - return -ENOMEM; - - for (step =3D 0; (step < nsteps) && (remaining_bytes > 0); step++) { - for (i =3D 0; i < c->nuser_data_tab; i++) { - if (c->user_data_len_tab[i] > remaining_bytes) - break; - sunxi_nand->user_data_bytes[step] =3D c->user_data_len_tab[i]; - } - remaining_bytes -=3D sunxi_nand->user_data_bytes[step]; - if (sunxi_nand->user_data_bytes[step] =3D=3D 0) - break; - } - if (sunxi_nand->user_data_bytes[0] < USER_DATA_SZ) + /* The first protected word must contain the bad-block marker. */ + if (!nsteps || oobsize < parity + USER_DATA_SZ) return -EINVAL; =20 + /* Use as many complete words as fit after parity. */ + available =3D min(oobsize - parity, nsteps * caps->max_user_data_len); + sunxi_nand->user_data_step =3D caps->max_user_data_len; + sunxi_nand->user_data_total =3D round_down(available, USER_DATA_SZ); return 0; } =20 @@ -2094,7 +2070,6 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_ch= ip *nand, const u8 *strengths =3D nfc->caps->ecc_strengths; struct mtd_info *mtd =3D nand_to_mtd(nand); struct nand_device *nanddev =3D mtd_to_nanddev(mtd); - int total_user_data_sz =3D 0; int nsectors; int ecc_mode; int ret; @@ -2179,10 +2154,7 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_c= hip *nand, return ret; } =20 - for (i =3D 0; i < nsectors; i++) - total_user_data_sz +=3D sunxi_nfc_user_data_sz(sunxi_nand, i); - - if (mtd->oobsize < (ecc->bytes * nsectors + total_user_data_sz)) + if (mtd->oobsize < sunxi_get_oob_offset(sunxi_nand, ecc, nsectors)) return -EINVAL; =20 ecc->read_oob =3D sunxi_nfc_hw_ecc_read_oob; @@ -2413,7 +2385,6 @@ static int sunxi_nfc_exec_op(struct nand_chip *nand, =20 static const struct nand_controller_ops sunxi_nand_controller_ops =3D { .attach_chip =3D sunxi_nand_attach_chip, - .detach_chip =3D sunxi_nand_detach_chip, .setup_interface =3D sunxi_nfc_setup_interface, .exec_op =3D sunxi_nfc_exec_op, }; @@ -2712,10 +2683,6 @@ static const u8 sunxi_ecc_strengths_h6[] =3D { 16, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80 }; =20 -static const u8 sunxi_user_data_len_h6[] =3D { - 0, 4, 8, 12, 16, 20, 24, 28, 32 -}; - static const struct sunxi_nfc_caps sunxi_nfc_a10_caps =3D { .has_ecc_block_512 =3D true, .layout =3D &sunxi_nfc_fixed_layout, @@ -2781,8 +2748,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_h616_cap= s =3D { .dma_maxburst =3D 8, .ecc_strengths =3D sunxi_ecc_strengths_h6, .nstrengths =3D ARRAY_SIZE(sunxi_ecc_strengths_h6), - .user_data_len_tab =3D sunxi_user_data_len_h6, - .nuser_data_tab =3D ARRAY_SIZE(sunxi_user_data_len_h6), + .max_user_data_len =3D 32, .max_ecc_steps =3D 32, .sram_size =3D 8192, .timings =3D &sun50i_h616_nfc_timings, --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223463; b=dhlQxwq6Sf8uBrLQoO94sPa9Kz9AaP+8ai10+iIBRruG1hXheCZ4vIqq1haAd3Ja1Z2/ 1ppVkX9Kn5/ZpRVWa0SPvkOnI1jmrPBWm/7CAPojD841a2w5g5qxf416o/85M4Md/DLFw ThFvbyExgCHXoe+REHsJRwN3UoviTN4+KYUD2Fae6HAiBwMZ5qVD6sW8BMIGEZXJoBGgf SPr9tQREbrhaLCcctR+nbHF9n30ySZXPMg+Tf02ShuUOs6QwToOXh5FuqBNZHqgElpHIz 6VqZ95JmICg6DzBu1446bImaOqizJyHWGoT/wAynj7jdOW3Bchz8KNcmGNLMCEzpgRA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223463; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=jSA/8+JIJhXyIE6wPAaPD1PdPonBWuUoA8eu4aZnEWs=; b=UWSkl+0OumBEweYQw5WTC2fGHTT/XHaynPJRHE9QnSjvBoa+270nSdZDluQ2Gwj1r3S8 wdSTMjGu0qAMgEc48nVo44EbJWzWQumLjU9F6x2Dh1eznHevXoElI2AhzdiyZ0F/SE1Pr VTDEKQnwZPnRg2QwRA3VXEvyx7MpBWdxIuLvQejZ1rLL2KRihST49ahrC6KOyvr8cSkMP yjugql3kt9te0HqMoOYW41BSl/Nh/LLia7lZScsWajMW2QNTM/LBbvVwfU10c5+JKXaZX Qspw/ymuSKVDeJJaE8fkff0RMCyArn5W3tu7EKm0SFP95TyWf7OCydyeniOBS5z4kBQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=hT0S+JG8; arc=none smtp.remote-ip=209.85.160.44 Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC8F360A2615 for ; Sat, 21 Nov 2026 01:11:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CC8F360A2615 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=hT0S+JG8 Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-48e9476e26aso572263fac.3 for ; Fri, 20 Nov 2026 17:11:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223460; x=1795828260; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=jSA/8+JIJhXyIE6wPAaPD1PdPonBWuUoA8eu4aZnEWs=; b=hT0S+JG8I6YYgGITV7Jl7Aif2ijt0Un4OiRttS6vndWP78uQgAHyUswlHhS1iJGuY7 a++UyVtijuvwLSJH51qU4VonuHyKNrp7JBjFSqBulgyAdjqMzLDv6va8AIsLe5EVAQSK UWNSKtm5zV6c00U0eHoXTdnNZM9m687hTWFJPt5A7IPhcXxKG1DIcTv1PyLXZkT+foRL bUFJTRUm6DhtnEHC924/1lLOXAYYqQgJIfbJ28po2nG0krf0d3XK0EfVrTZjJh74ce8a oYyDwvnONHAjKWDlEu2Qp7LG6ZY7nuKJBsmXYjREQKYZYxY4lTIe+OSijn5Y0y477/6x TMdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223460; x=1795828260; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=jSA/8+JIJhXyIE6wPAaPD1PdPonBWuUoA8eu4aZnEWs=; b=v+ojrabVA5uC+V9pXJ3Fgglw1XL6zNWoqqzaXTkzsoZt2iKTA55TgNvH40DOqfdy+B vcjIdsnbJazhF34A4dGvsZ7c4vDoLeQGdxVO6kavowtAWQ8cQ+XdjUC0CoeF+g8kUn6s pbvw1xbZfjGlI9kBtj++N7UqZL/ngxPVh1CWEAsKUB8Z96seSMAwLwnDaghdoolURzkT tJII04HNgRbb0bLgLdLGEGDrHN6Eaxxeph+D30ZzOr7pajJUttGPiat5aN6/kzi6hvqR 4M2TDIUPqE7TqhZKliakAhrZM0M8tgAlukn0Sz5xRESq3DAzH+/oeJep8l5IRzMv+dg5 bQlw== X-Forwarded-Encrypted: i=1; AL+hErETUQzaBSTKNfBvYnUw8W/tnMPEIIlh4T94yov9tKN6MOFmVhDn4EkryrUc7zbtdyqipsuU77nHRJA974c=@vger.kernel.org X-Gm-Message-State: APuU4Z+JJ5u09dMh1E/Nj1NipPuK0j8r4wHJEyUbONhYj8lG06sXXCrB PgbLV6WI/S8P3BQG9Spu/U76Ls06iZJh+LQX3VgxePoL+U4Z71B8oU7V X-Gm-Gg: AYBFou2NoxeabgY9cMKcYQm6dlveAeAKBsNix5H0BgYdjKzNHf1RJPquxCnwMGwFmHP vYBJPXWxPMaJFXnbvqQJ/azSJPQeyiLpsuoXdcS0YnMhksae29zjXijJL6GWRxZfpceUZ1FqIL5 VtdRtaHg1pmNmHA0eobmMTNSlyi9lyn5ciBbMFNuIOpCjdkDnerZKhiq+arCkmargaT8ifwI5zB joCG7X8SFtQYLUpyM8fdCvcDzhgxxmcMJ5Ii4Bk+XWSUWY/1IdqezqXhDXhxvSmCwU/FM1hm6NY v27NJy7nVzCKvLy+1c8mLTlZr5bbueJ3lxLaLCPC6t1+c/051ggZanexWI7lyPac7gvP6qbbi8W /H6tfT0k0mV0SEL/A3PAO09wFLLW0J/Ye+9tatiDdH5okAKOykQmuks1KlXkx7hi8CUNd0LDeF4 l0LTAJpyWa21Zbn8BGggZbGZ8/vhvSVlhrYwyeTmBiMu4qwgu2Jq17KnORXc+kWP08j/G4c9e3i vfl1J+hOwQwtB0676BWITbnIAihxn4GQ3SRFCJEq5SEPrA7T6OX6fKqmw2nSZUKc9N6JosKRN3o DwxYuXpaZ3qFXXN4lTB0WBg0Uho9ey0pXm0VxRki5OmtNq8CO36o/e5O8REosop8YfV24aIJmHH c4RTMLy20sDwcWby0kCMLApfh02VU0iAS/jBQ7IwZsidpN2PFesb3SDh19L9FYZ2anzE4+IN6tX CUa2hq62nuPUnO1v2wfVmbtGODIusJVY7Hc0pf0w3eY9YmEmcpX0nc X-Received: by 2002:a05:6808:3503:b0:4f5:eaac:5151 with SMTP id 5614622812f47-57a0b0414a8mr5815721b6e.39.1795223459632; Fri, 20 Nov 2026 17:10:59 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.10.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:10:59 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:26 -0700 Subject: [PATCH v11 03/26] mtd: rawnand: sunxi: share ECC read handling between PIO and DMA X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-3-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev For a full-page read, the caller should get the same corrected data, protected OOB and ECC statistics whether the controller uses PIO or DMA. Each path currently implements its own pattern handling and erased-chunk checks. Use one PIO loop for a full page or the requested steps of a subpage. Pass each PIO step or completed DMA batch to the same ECC reader. An erased-step check derives its data and OOB positions from the logical step, even when the controller reports its result in slot zero. Keep the page buffer, correction count and erased-chunk state until the read is finished. DMA must collect corrected OOB before any raw reread, which can overwrite the controller registers. Keep that order and let each transfer path issue its own commands. Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 446 ++++++++++++++++++----------------= ---- 1 file changed, 216 insertions(+), 230 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index f57184927fe9..8c5aed1fdfb3 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -925,6 +925,7 @@ static u8 sunxi_nfc_user_data_sz(struct sunxi_nand_chip= *sunxi_nand, int step) sunxi_nfc_user_data_before(sunxi_nand, step); } =20 +/* PIO uses register zero; DMA concatenates user data within each transfer= . */ static void sunxi_nfc_hw_ecc_get_prot_oob_bytes(struct nand_chip *nand, u8= *oob, int step, bool bbm, int page, unsigned int user_data_sz) @@ -1073,6 +1074,16 @@ static void sunxi_nfc_hw_ecc_update_stats(struct nan= d_chip *nand, } } =20 +/* Shared across a read's transfers; buf remains the full-page buffer base= . */ +struct sunxi_nfc_ecc_read { + u8 *buf; + int page; + unsigned int max_bitflips; + bool oob_required; + bool dma; + bool has_erased_chunk; +}; + static int sunxi_nfc_hw_ecc_correct(struct nand_chip *nand, u8 *data, u8 *= oob, int step, u32 status, u32 pattern_found, bool *erased) @@ -1112,98 +1123,6 @@ static int sunxi_nfc_hw_ecc_correct(struct nand_chip= *nand, u8 *data, u8 *oob, return NFC_ECC_ERR_CNT(step, tmp); } =20 -static int sunxi_nfc_hw_ecc_read_chunk(struct nand_chip *nand, - u8 *data, int data_off, - u8 *oob, int oob_off, - int *cur_off, - unsigned int *max_bitflips, - int step, bool oob_required, int page) -{ - struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); - struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); - unsigned int user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, step); - struct nand_ecc_ctrl *ecc =3D &nand->ecc; - int raw_mode =3D 0; - u32 pattern_found; - bool bbm =3D !step; - bool erased; - int ret; - /* From the controller point of view, we are at step 0 */ - const int nfc_step =3D 0; - - if (*cur_off !=3D data_off) - nand_change_read_column_op(nand, data_off, NULL, 0, false); - - sunxi_nfc_randomizer_read_buf(nand, NULL, ecc->size, false, page); - - if (data_off + ecc->size !=3D oob_off) - nand_change_read_column_op(nand, oob_off, NULL, 0, false); - - ret =3D sunxi_nfc_wait_cmd_fifo_empty(nfc); - if (ret) - return ret; - - sunxi_nfc_set_user_data_len(nfc, user_data_sz, nfc_step); - sunxi_nfc_randomizer_config(nand, page, false); - sunxi_nfc_randomizer_enable(nand); - writel(NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD | NFC_ECC_OP, - nfc->regs + NFC_REG_CMD); - - ret =3D sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, false, 0); - sunxi_nfc_randomizer_disable(nand); - if (ret) - return ret; - - *cur_off =3D oob_off + ecc->bytes + user_data_sz; - - pattern_found =3D readl(nfc->regs + nfc->caps->reg_pat_found); - pattern_found =3D field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); - - ret =3D sunxi_nfc_hw_ecc_correct(nand, data, oob_required ? oob : NULL, - nfc_step, readl(nfc->regs + NFC_REG_ECC_ST), - pattern_found, &erased); - if (erased) - return 1; - - if (ret < 0) { - /* - * Re-read the data with the randomizer disabled to identify - * bitflips in erased pages. - */ - if (nand->options & NAND_NEED_SCRAMBLING) - nand_change_read_column_op(nand, data_off, data, - ecc->size, false); - else - memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, - ecc->size); - - nand_change_read_column_op(nand, oob_off, oob, - ecc->bytes + user_data_sz, false); - - ret =3D nand_check_erased_ecc_chunk(data, ecc->size, oob, - ecc->bytes + user_data_sz, - NULL, 0, ecc->strength); - if (ret >=3D 0) - raw_mode =3D 1; - } else { - memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, ecc->size); - - if (oob_required) { - nand_change_read_column_op(nand, oob_off, NULL, 0, - false); - sunxi_nfc_randomizer_read_buf(nand, oob, ecc->bytes + user_data_sz, - true, page); - - sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, nfc_step, - bbm, page, user_data_sz); - } - } - - sunxi_nfc_hw_ecc_update_stats(nand, max_bitflips, ret); - - return raw_mode; -} - /* * Returns the offset of the OOB for each step. * (it includes the user data before the ECC data.) @@ -1225,6 +1144,37 @@ static int sunxi_get_ecc_offset(struct sunxi_nand_ch= ip *sunxi_nand, return step * ecc->bytes + sunxi_nfc_user_data_before(sunxi_nand, step + = 1); } =20 +/* Account for the ECC result and record erased chunks. */ +static int sunxi_nfc_hw_ecc_read_error(struct nand_chip *nand, + struct sunxi_nfc_ecc_read *read, int step) +{ + struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); + struct nand_ecc_ctrl *ecc =3D &nand->ecc; + int data_off =3D step * ecc->size; + int oob_off =3D sunxi_get_oob_offset(sunxi_nand, ecc, step); + unsigned int oob_len =3D ecc->bytes + sunxi_nfc_user_data_sz(sunxi_nand, = step); + u8 *data =3D read->buf + data_off; + u8 *oob =3D nand->oob_poi + oob_off; + int ret; + + /* Check the physical representation for bitflips in erased pages. */ + if (nand->options & NAND_NEED_SCRAMBLING) + nand_change_read_column_op(nand, data_off, data, ecc->size, false); + + nand_change_read_column_op(nand, nand_to_mtd(nand)->writesize + oob_off, + oob, oob_len, false); + + ret =3D nand_check_erased_ecc_chunk(data, ecc->size, oob, oob_len, NULL, = 0, + ecc->strength); + + sunxi_nfc_hw_ecc_update_stats(nand, &read->max_bitflips, ret); + + if (ret >=3D 0) + read->has_erased_chunk =3D true; + + return 0; +} + static void sunxi_nfc_hw_ecc_read_extra_oob(struct nand_chip *nand, u8 *oob, int *cur_off, bool randomize, int page) @@ -1252,18 +1202,157 @@ static void sunxi_nfc_hw_ecc_read_extra_oob(struct= nand_chip *nand, *cur_off =3D mtd->oobsize + mtd->writesize; } =20 -static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, uint8_= t *buf, - int oob_required, int page, - int nchunks) +/* Interpret one PIO step or a completed DMA batch before reusing its stat= us. */ +static int sunxi_nfc_oob_read_batch(struct nand_chip *nand, + struct sunxi_nfc_ecc_read *read, + u32 status, u32 pattern_found, + int first_step, int nsteps) { - bool randomized =3D nand->options & NAND_NEED_SCRAMBLING; struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); struct mtd_info *mtd =3D nand_to_mtd(nand); struct nand_ecc_ctrl *ecc =3D &nand->ecc; - unsigned int max_bitflips =3D 0; - int ret, i, raw_mode =3D 0; + bool randomized =3D nand->options & NAND_NEED_SCRAMBLING; + unsigned int user_data_sz; + int i, ret; + + for (i =3D 0; i < nsteps; i++) { + int step =3D first_step + i; + int oob_off =3D sunxi_get_oob_offset(sunxi_nand, ecc, step); + u8 *data =3D read->buf + step * ecc->size; + u8 *oob =3D nand->oob_poi + oob_off; + bool erased; + int bitflips; + + user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, step); + bitflips =3D sunxi_nfc_hw_ecc_correct(nand, + !read->dma || randomized ? data : NULL, + read->oob_required ? oob : NULL, + i, status, pattern_found, &erased); + if (bitflips < 0) { + /* Preserve PIO data before the raw erased-page check. */ + if (!read->dma && !randomized) + memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, ecc->size); + continue; + } + + if (erased) { + read->has_erased_chunk =3D true; + continue; + } + + if (!read->dma) + memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, ecc->size); + + if (read->oob_required) { + /* Keep the existing PIO and DMA representations of parity. */ + if (read->dma) { + nand_change_read_column_op(nand, mtd->writesize + oob_off, + oob, ecc->bytes + user_data_sz, false); + } else { + nand_change_read_column_op(nand, mtd->writesize + oob_off, + NULL, 0, false); + sunxi_nfc_randomizer_read_buf(nand, oob, + ecc->bytes + user_data_sz, + true, read->page); + } + + sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, i, !step, + read->page, user_data_sz); + } + + sunxi_nfc_hw_ecc_update_stats(nand, &read->max_bitflips, bitflips); + } + + if (!(status & NFC_ECC_ERR_MSK(nfc))) + return 0; + + /* Finish consuming the batch's corrected OOB before raw error rereads. */ + for (i =3D 0; i < nsteps; i++) { + int step =3D first_step + i; + + if (!(status & NFC_ECC_ERR(i))) + continue; + + ret =3D sunxi_nfc_hw_ecc_read_error(nand, read, step); + if (ret < 0) + return ret; + } + + return 0; +} + +static int sunxi_nfc_oob_finish_read(struct nand_chip *nand, + struct sunxi_nfc_ecc_read *read, int *cur_off) +{ + if (read->oob_required) + sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi, cur_off, + !read->has_erased_chunk, read->page); + + return read->max_bitflips; +} + +static int sunxi_nfc_hw_ecc_read_chunk(struct nand_chip *nand, + struct sunxi_nfc_ecc_read *read, + int step, int *cur_off) +{ + struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); + unsigned int user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, step); + struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); + struct nand_ecc_ctrl *ecc =3D &nand->ecc; + int data_off =3D step * ecc->size; + int oob_off =3D nand_to_mtd(nand)->writesize + sunxi_get_oob_offset(sunxi= _nand, ecc, step); + int page =3D read->page; + u32 pattern_found; + int ret; + + if (*cur_off !=3D data_off) + nand_change_read_column_op(nand, data_off, NULL, 0, false); + + sunxi_nfc_randomizer_read_buf(nand, NULL, ecc->size, false, page); + + if (data_off + ecc->size !=3D oob_off) + nand_change_read_column_op(nand, oob_off, NULL, 0, false); + + ret =3D sunxi_nfc_wait_cmd_fifo_empty(nfc); + if (ret) + return ret; + + sunxi_nfc_set_user_data_len(nfc, user_data_sz, 0); + sunxi_nfc_randomizer_config(nand, page, false); + sunxi_nfc_randomizer_enable(nand); + writel(NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD | NFC_ECC_OP, + nfc->regs + NFC_REG_CMD); + + ret =3D sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, false, 0); + sunxi_nfc_randomizer_disable(nand); + if (ret) + return ret; + + *cur_off =3D oob_off + ecc->bytes + user_data_sz; + + pattern_found =3D readl(nfc->regs + nfc->caps->reg_pat_found); + pattern_found =3D field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); + + return sunxi_nfc_oob_read_batch(nand, read, + readl(nfc->regs + NFC_REG_ECC_ST), + pattern_found, step, 1); +} + +static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *bu= f, + int oob_required, int page, int nchunks) +{ + struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); + struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); + struct nand_ecc_ctrl *ecc =3D &nand->ecc; + struct sunxi_nfc_ecc_read read =3D { + .buf =3D buf, + .page =3D page, + .oob_required =3D oob_required, + .dma =3D true, + }; struct scatterlist sg; + int ret, i; u32 status, pattern_found, wait; =20 ret =3D sunxi_nfc_wait_cmd_fifo_empty(nfc); @@ -1310,83 +1399,12 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct = nand_chip *nand, uint8_t *buf status =3D readl(nfc->regs + NFC_REG_ECC_ST); pattern_found =3D readl(nfc->regs + nfc->caps->reg_pat_found); pattern_found =3D field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); + ret =3D sunxi_nfc_oob_read_batch(nand, &read, status, pattern_found, + 0, nchunks); + if (ret) + return ret; =20 - for (i =3D 0; i < nchunks; i++) { - int data_off =3D i * ecc->size; - unsigned int user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, i); - int oob_off =3D sunxi_get_oob_offset(sunxi_nand, ecc, i); - u8 *data =3D buf + data_off; - u8 *oob =3D nand->oob_poi + oob_off; - bool erased; - - ret =3D sunxi_nfc_hw_ecc_correct(nand, randomized ? data : NULL, - oob_required ? oob : NULL, - i, status, pattern_found, - &erased); - - /* ECC errors are handled in the second loop. */ - if (ret < 0) - continue; - - if (oob_required && !erased) { - /* TODO: use DMA to retrieve OOB */ - nand_change_read_column_op(nand, - mtd->writesize + oob_off, - oob, ecc->bytes + user_data_sz, false); - - sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, i, !i, - page, user_data_sz); - } - - if (erased) - raw_mode =3D 1; - - sunxi_nfc_hw_ecc_update_stats(nand, &max_bitflips, ret); - } - - if (status & NFC_ECC_ERR_MSK(nfc)) { - for (i =3D 0; i < nchunks; i++) { - int data_off =3D i * ecc->size; - unsigned int user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, i); - int oob_off =3D sunxi_get_oob_offset(sunxi_nand, ecc, i); - u8 *data =3D buf + data_off; - u8 *oob =3D nand->oob_poi + oob_off; - - if (!(status & NFC_ECC_ERR(i))) - continue; - - /* - * Re-read the data with the randomizer disabled to - * identify bitflips in erased pages. - * TODO: use DMA to read page in raw mode - */ - if (randomized) - nand_change_read_column_op(nand, data_off, - data, ecc->size, - false); - - /* TODO: use DMA to retrieve OOB */ - nand_change_read_column_op(nand, - mtd->writesize + oob_off, - oob, ecc->bytes + user_data_sz, false); - - ret =3D nand_check_erased_ecc_chunk(data, ecc->size, oob, - ecc->bytes + user_data_sz, - NULL, 0, - ecc->strength); - if (ret >=3D 0) - raw_mode =3D 1; - - sunxi_nfc_hw_ecc_update_stats(nand, &max_bitflips, ret); - } - } - - if (oob_required) - sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi, - NULL, !raw_mode, - page); - - return max_bitflips; + return sunxi_nfc_oob_finish_read(nand, &read, NULL); } =20 static int sunxi_nfc_hw_ecc_write_chunk(struct nand_chip *nand, @@ -1458,45 +1476,40 @@ static void sunxi_nfc_hw_ecc_write_extra_oob(struct= nand_chip *nand, *cur_off =3D mtd->oobsize + mtd->writesize; } =20 -static int sunxi_nfc_hw_ecc_read_page(struct nand_chip *nand, uint8_t *buf, - int oob_required, int page) +static int sunxi_nfc_hw_ecc_read_chunks_pio(struct nand_chip *nand, u8 *bu= f, + int oob_required, int page, + int first_step, int end_step) { struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); - struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); - struct mtd_info *mtd =3D nand_to_mtd(nand); - struct nand_ecc_ctrl *ecc =3D &nand->ecc; - unsigned int max_bitflips =3D 0; - int ret, i, cur_off =3D 0; - bool raw_mode =3D false; + struct sunxi_nfc_ecc_read read =3D { + .buf =3D buf, + .page =3D page, + .oob_required =3D oob_required, + }; + int ret, step, cur_off =3D 0; =20 nand_read_page_op(nand, page, 0, NULL, 0); =20 sunxi_nfc_hw_ecc_enable(nand); =20 sunxi_nfc_reset_user_data_len(nfc); - for (i =3D 0; i < ecc->steps; i++) { - int data_off =3D i * ecc->size; - int oob_off =3D sunxi_get_oob_offset(sunxi_nand, ecc, i); - u8 *data =3D buf + data_off; - u8 *oob =3D nand->oob_poi + oob_off; - - ret =3D sunxi_nfc_hw_ecc_read_chunk(nand, data, data_off, oob, - oob_off + mtd->writesize, - &cur_off, &max_bitflips, - i, oob_required, page); + for (step =3D first_step; step < end_step; step++) { + ret =3D sunxi_nfc_hw_ecc_read_chunk(nand, &read, step, &cur_off); if (ret < 0) return ret; - else if (ret) - raw_mode =3D true; } =20 - if (oob_required) - sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi, &cur_off, - !raw_mode, page); - + ret =3D sunxi_nfc_oob_finish_read(nand, &read, &cur_off); sunxi_nfc_hw_ecc_disable(nand); =20 - return max_bitflips; + return ret; +} + +static int sunxi_nfc_hw_ecc_read_page(struct nand_chip *nand, u8 *buf, + int oob_required, int page) +{ + return sunxi_nfc_hw_ecc_read_chunks_pio(nand, buf, oob_required, page, 0, + nand->ecc.steps); } =20 static int sunxi_nfc_hw_ecc_read_page_dma(struct nand_chip *nand, u8 *buf, @@ -1517,39 +1530,12 @@ static int sunxi_nfc_hw_ecc_read_page_dma(struct na= nd_chip *nand, u8 *buf, =20 static int sunxi_nfc_hw_ecc_read_subpage(struct nand_chip *nand, u32 data_offs, u32 readlen, - u8 *bufpoi, int page) + u8 *buf, int page) { - struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); - struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); - struct mtd_info *mtd =3D nand_to_mtd(nand); - struct nand_ecc_ctrl *ecc =3D &nand->ecc; - int ret, i, cur_off =3D 0; - unsigned int max_bitflips =3D 0; - - nand_read_page_op(nand, page, 0, NULL, 0); - - sunxi_nfc_hw_ecc_enable(nand); - - sunxi_nfc_reset_user_data_len(nfc); - for (i =3D data_offs / ecc->size; - i < DIV_ROUND_UP(data_offs + readlen, ecc->size); i++) { - int data_off =3D i * ecc->size; - int oob_off =3D sunxi_get_oob_offset(sunxi_nand, ecc, i); - u8 *data =3D bufpoi + data_off; - u8 *oob =3D nand->oob_poi + oob_off; - - ret =3D sunxi_nfc_hw_ecc_read_chunk(nand, data, data_off, - oob, - oob_off + mtd->writesize, - &cur_off, &max_bitflips, i, - false, page); - if (ret < 0) - return ret; - } - - sunxi_nfc_hw_ecc_disable(nand); + int first_step =3D data_offs / nand->ecc.size; + int end_step =3D DIV_ROUND_UP(data_offs + readlen, nand->ecc.size); =20 - return max_bitflips; + return sunxi_nfc_hw_ecc_read_chunks_pio(nand, buf, false, page, first_ste= p, end_step); } =20 static int sunxi_nfc_hw_ecc_read_subpage_dma(struct nand_chip *nand, --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223468; b=j4nr1wGy0YDmz/zgMzrQxKg+wQN5Jwv3OEv6nQOZpSZ9nHtOozTCW9LiR7J5sMeQsUed 98IrNk1UJN16w52pJMmGq25IKsjzk66VagggRs6wP+jX8NuRuikaAmT43+P+2d5lbE7yW UVTB0m5ptSCTvq0lsvlZV6e14iAG3+onfjbqqetCInQumUKBKx8uQle7OaiAxeoTfOX7u LW7zIoe6GDJkOIskuGdwDvAlI6VFkEXmzDtNXlptp4eyGb6YMh2dVidZe2MA3YqLAsFGh VNKZocp2d2QV5HTxfDRunQYFSNiuoeRcsWtREW8AXCXsGLf5/UDxcXZTPsFFt6K4ioQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223468; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=DQGkpSAcUEldrefS3FgTooTEIoCcU3OOOCqakdoP+Go=; b=LcbvERTx7X0jGZ7umqTQqqf3LTfQlMuNpfrJLDf8UtI3h9JoSyMqDn/bpJY7G5wBkv0b IY5dTwr7rLBo9A7enyXo7qRWtn2L8KlOOyAom0mhoQFbadhUCbiudNQxKUBrRJYIbWaNm nsZjy9NHT7D2gInuOYmFNbtKi5hbg4MqU36QLInjhxp6Z2Gs2KcpvpRL2mNdtZVED1lYd EF6Oj7OB/gAFqjuLns+vYw8ZLc62lkA+g9tiT2NF2l2lDqCPlP06pavIVZBAfqZhdl7tL n2nh68LwW9gGWW4j3QgLYDTe9sZLMCUE4bIFmgPUQNd4Rknhqxed5rS0ul1YaGg4tCw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=PtKTVdg0; arc=none smtp.remote-ip=209.85.167.171 Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7012E606A334 for ; Sat, 21 Nov 2026 01:11:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7012E606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=PtKTVdg0 Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-5642e0910a3so741935b6e.0 for ; Fri, 20 Nov 2026 17:11:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223461; x=1795828261; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DQGkpSAcUEldrefS3FgTooTEIoCcU3OOOCqakdoP+Go=; b=PtKTVdg0TBSFwEMvs0ufRtpT9ioQcalRjBzMfjMbrTJBdKkVOxeDIBK1C4l1yEX5F3 R7PYfs7RRkMe+Yc4UibocTqa1yY1M3TTkhAqCqtT1xMcwibJSGuLLs4xah2ui+f5xtxf oHq5orG3WcU7nW19hCnCZcOn4jU9ZRbZv4HJnU1WNdoVUAjpFIjdXFZ9XV5bVuCi2P2Y GpCAeNP7DOOo7B7KFDWIFh9341w3vST6e5hYwkqUTwGyn+PfPHTkxhtbqowjgFO7UOSu /TrqV0IURgYSsnKSdoJ935mFfyDtinY3Ohv4uPPA2hTLO2SqAAT0310PuCXleJ1OsoL3 QIqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223461; x=1795828261; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=DQGkpSAcUEldrefS3FgTooTEIoCcU3OOOCqakdoP+Go=; b=Fo62QTcvY5WLHeIQXJ+cNLWKQqUBxXf4PL+6ukp3OiR+gCdJlKbnHeRg9PEUR6YalO Vt1WARwcDl1tfUo5SsAG6HzjOrVRQm9QEc6SGU/6BWE9A+2hP4CAGmECu65J/LiL5s2q cziciD8jQ+dMJLgJnyRMbqYFA5Wd3/W5eFL6hXB5m0cMvLyS9sb9Wh6+RoNQ5pfmCgza 6LoEoe6KKU2XT3MA3l5bfbZOG8roKGVQI4We3NTrVeo/0KvjOLUxFhXWq1Ir4Eiyrkfh FK1iwTMvKPRxudVDAjREgyY/X/GfW4LxzpT7396vx+F/ppiT+V4O85j0r3/uy4yldTl8 C38g== X-Forwarded-Encrypted: i=1; AL+hErFFbMpv09AIQ8nljlEBHMBL/J/IHoJtw6LCt5prn+eN9b8IEv+XeLh54ZXnfMJEX0I6CPG5gwTlnKjoH74=@vger.kernel.org X-Gm-Message-State: APuU4Z/2YKqsyL+O9Wb5xDroimGbBj1sXJflZ1GZEp7RIeJrwduiHdse Fv5cP+Z+3q9mCzuDST14YaH9pt4sinK0gF94JZRdJEKL6vL6XfF5h6+v X-Gm-Gg: AYBFou2VZFAyfwU6gJQ5eErd2S0KJFCwwvDBYTv4vvzgE3BwQNMizE+7UZI/ltlfIf3 9lV8J3GirZvvT50BsM2RFrkUuCcKBLVdI9Ooz0KdGzDCCA9SRKn5zb+Nt7XseMnLu7uo9aMimMh FQPRg5S/DP+zMc5K+7trj6fswXceLuEBc9kmZD2nlh2O9SgHjgpdcpMv3aIb9ViuBHy2LMvJVft ewpx5A8/bmKQnjyarOIdOuRWJeJxUs+j2mq8VBs1Zmjy7xyhPqf5tpyki1aUWXjYG6ExxYSB8oX Q35VBQg/vL7nz2XlPiZxkjOiKzNCklQYePujuv/26iV9/QDSNMxAmNQnfNyyHIk+qxsJIw3IZrV 6u5zEyUHrO9L2OTZz9Cj4FunksjM5q2TIruhN2nYWXLjUpAJG8i8V1VnRHFg9e0WsJ59iSXC9Qa Wo72S7HEusmKIYIg0RVVZD4tXo8UKBgBmpQelz1hU8riGmwQrIJNgLmU+tPBaa8zZvEXD0VZG0f +Ge54fHJBow53UAKMpo14hDJL9QLffwSnnaqUZCblE42N05P6vBdwx7VK5sk6pvJZOupttxukc3 43kvwr5lm+kc9q9TavSy4yzA/jTXuThPa99SuJTUrG6zI1tfQwinudoVlmI5LH1Ksc99PM692/E I+S2CRW2C2oSBbVSIRPu2YCgc2g7l5nML3I3HXsIEYYvQa+93pD3X1uFuMJyWiLc5lb0PNMXb/G OdJoY5vbmTeAFup6srOaBnw3z4TCek6TBRJ/wuC5iANdusdwjM22in X-Received: by 2002:a05:6808:30aa:b0:4d6:90f3:74a4 with SMTP id 5614622812f47-57a0c0a40e2mr5697337b6e.47.1795223461220; Fri, 20 Nov 2026 17:11:01 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.10.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:00 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:27 -0700 Subject: [PATCH v11 04/26] mtd: rawnand: sunxi: use the logical step's OOB length in PIO X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-4-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev On H6/H616, when a PIO read detects a pattern and OOB was requested, filling the OOB with that pattern can overwrite the next step's bytes. On the last step the fill can run past the end of the OOB buffer. A PIO write can likewise fetch more protected bytes than the step owns. Each PIO transfer uses hardware slot zero. Looking up the protected length by slot therefore always gives the first step's length, which can be 32 bytes even when a later step has only 16 bytes or none. Pass the logical step's user-data length to both helpers. PIO still addresses hardware slot zero. DMA passes the length for the current step and still addresses the same user-data registers. Fixes: 54dcd6aa69db ("mtd: rawnand: sunxi: introduce maximize variable user= data length") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 96 +++++++++++------------------------= ---- 1 file changed, 26 insertions(+), 70 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 8c5aed1fdfb3..ffbe851b87c7 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -927,43 +927,19 @@ static u8 sunxi_nfc_user_data_sz(struct sunxi_nand_ch= ip *sunxi_nand, int step) =20 /* PIO uses register zero; DMA concatenates user data within each transfer= . */ static void sunxi_nfc_hw_ecc_get_prot_oob_bytes(struct nand_chip *nand, u8= *oob, - int step, bool bbm, int page, + unsigned int reg_index, bool bbm, int page, unsigned int user_data_sz) { - struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); u32 user_data; + unsigned int i; =20 - if (!nfc->caps->reg_user_data_len) { - /* - * For A10, the user data for step n is in the nth - * REG_USER_DATA - */ - user_data =3D readl(nfc->regs + NFC_REG_USER_DATA(nfc, step)); - sunxi_nfc_user_data_to_buf(user_data, oob); - } else { - /* - * For H6 NAND controller, the user data for all steps is - * contained in 32 user data registers, but not at a specific - * offset for each step, they are just concatenated. - */ - unsigned int user_data_off =3D 0; - unsigned int reg_off; - u8 *ptr =3D oob; - unsigned int i; - - for (i =3D 0; i < step; i++) - user_data_off +=3D sunxi_nfc_user_data_sz(sunxi_nand, i); - - user_data_off /=3D 4; - for (i =3D 0; i < user_data_sz / 4; i++, ptr +=3D 4) { - reg_off =3D NFC_REG_USER_DATA(nfc, user_data_off + i); - user_data =3D readl(nfc->regs + reg_off); - sunxi_nfc_user_data_to_buf(user_data, ptr); - } + for (i =3D 0; i < user_data_sz / 4; i++) { + user_data =3D readl(nfc->regs + NFC_REG_USER_DATA(nfc, reg_index + i)); + sunxi_nfc_user_data_to_buf(user_data, oob + i * 4); } =20 - /* De-randomize the Bad Block Marker. */ + /* Undo hardware de-randomization of the plain on-flash BBM. */ if (bbm && (nand->options & NAND_NEED_SCRAMBLING)) sunxi_nfc_randomize_bbm(nand, page, oob); } @@ -1017,48 +993,25 @@ static void sunxi_nfc_set_user_data_len(struct sunxi= _nfc *nfc, } =20 static void sunxi_nfc_hw_ecc_set_prot_oob_bytes(struct nand_chip *nand, - const u8 *oob, int step, - bool bbm, int page) + const u8 *oob, unsigned int reg_index, + bool bbm, int page, + unsigned int user_data_sz) { struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); - struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); - unsigned int user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, step); u8 user_data[SUNXI_NFC_MAX_USER_DATA_SZ] =3D {}; + unsigned int i; =20 - /* Randomize the Bad Block Marker. */ + /* Compensate hardware randomization so the BBM stays plain on flash. */ if (bbm && (nand->options & NAND_NEED_SCRAMBLING)) { memcpy(user_data, oob, user_data_sz); sunxi_nfc_randomize_bbm(nand, page, user_data); oob =3D user_data; } =20 - if (!nfc->caps->reg_user_data_len) { - /* - * For A10, the user data for step n is in the nth - * REG_USER_DATA - */ - writel(sunxi_nfc_buf_to_user_data(oob), - nfc->regs + NFC_REG_USER_DATA(nfc, step)); - } else { - /* - * For H6 NAND controller, the user data for all steps is - * contained in 32 user data registers, but not at a specific - * offset for each step, they are just concatenated. - */ - unsigned int user_data_off =3D 0; - const u8 *ptr =3D oob; - unsigned int i; - - for (i =3D 0; i < step; i++) - user_data_off +=3D sunxi_nfc_user_data_sz(sunxi_nand, i); - - user_data_off /=3D 4; - for (i =3D 0; i < user_data_sz / 4; i++, ptr +=3D 4) { - writel(sunxi_nfc_buf_to_user_data(ptr), - nfc->regs + NFC_REG_USER_DATA(nfc, user_data_off + i)); - } + for (i =3D 0; i < user_data_sz / 4; i++) { + writel(sunxi_nfc_buf_to_user_data(oob + i * 4), + nfc->regs + NFC_REG_USER_DATA(nfc, reg_index + i)); } - } =20 static void sunxi_nfc_hw_ecc_update_stats(struct nand_chip *nand, @@ -1086,11 +1039,9 @@ struct sunxi_nfc_ecc_read { =20 static int sunxi_nfc_hw_ecc_correct(struct nand_chip *nand, u8 *data, u8 *= oob, int step, u32 status, u32 pattern_found, - bool *erased) + unsigned int user_data_sz, bool *erased) { struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); - struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); - unsigned int user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, step); struct nand_ecc_ctrl *ecc =3D &nand->ecc; u32 tmp; =20 @@ -1213,10 +1164,10 @@ static int sunxi_nfc_oob_read_batch(struct nand_chi= p *nand, struct mtd_info *mtd =3D nand_to_mtd(nand); struct nand_ecc_ctrl *ecc =3D &nand->ecc; bool randomized =3D nand->options & NAND_NEED_SCRAMBLING; - unsigned int user_data_sz; + unsigned int reg_index =3D 0, user_data_sz; int i, ret; =20 - for (i =3D 0; i < nsteps; i++) { + for (i =3D 0; i < nsteps; i++, reg_index +=3D user_data_sz / 4) { int step =3D first_step + i; int oob_off =3D sunxi_get_oob_offset(sunxi_nand, ecc, step); u8 *data =3D read->buf + step * ecc->size; @@ -1228,7 +1179,8 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip = *nand, bitflips =3D sunxi_nfc_hw_ecc_correct(nand, !read->dma || randomized ? data : NULL, read->oob_required ? oob : NULL, - i, status, pattern_found, &erased); + i, status, pattern_found, + user_data_sz, &erased); if (bitflips < 0) { /* Preserve PIO data before the raw erased-page check. */ if (!read->dma && !randomized) @@ -1257,7 +1209,7 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip = *nand, true, read->page); } =20 - sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, i, !step, + sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, reg_index, !step, read->page, user_data_sz); } =20 @@ -1437,7 +1389,8 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct nand_c= hip *nand, sunxi_nfc_randomizer_config(nand, page, false); sunxi_nfc_randomizer_enable(nand); sunxi_nfc_set_user_data_len(nfc, user_data_sz, nfc_step); - sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, nfc_step, bbm, page); + sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, nfc_step, bbm, page, + user_data_sz); =20 writel(NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD | NFC_ACCESS_DIR | NFC_ECC_OP, @@ -1637,6 +1590,7 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct nan= d_chip *nand, struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct nand_ecc_ctrl *ecc =3D &nand->ecc; struct scatterlist sg; + unsigned int reg_index =3D 0; u32 wait; int ret, i; =20 @@ -1657,8 +1611,10 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct na= nd_chip *nand, int oob_off =3D sunxi_get_oob_offset(sunxi_nand, ecc, i); const u8 *oob =3D nand->oob_poi + oob_off; =20 - sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, i, !i, page); + sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, reg_index, !i, page, + user_data_sz); sunxi_nfc_set_user_data_len(nfc, user_data_sz, i); + reg_index +=3D user_data_sz / 4; } =20 nand_prog_page_begin_op(nand, page, 0, NULL, 0); --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223470; b=P0wKMKZ3TksUhaEKkNm7KLwluqUSe/4Fzxk80TeXAFWiTV+bdgq2mm/WZDiTr2+Pg7Ya W+VMKS/umU/jUTtA4FgMv9qpBks/RQSd9hNiKByupkdDr8YbWCuiGGVtELGMF+7G2VRuN WVZfjJPSU74Uc74OLBYQtorTNCwqjWdTpmN6gjFWjH+3XXpK9XlVf30+jESGBhPvkpvEG yGD4fviw3djp0G+pHfg2QrDnnvqfTOb7JIb2s/hUJnRqJNV9vV3ikBYent9hpT3rV52QZ oX7ke+cb7RX2RfYjrr794rjnrzFD/h6TBzB3oWDf0RXgdNr0aeUnHsJxpY6W3e0u4NA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223470; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=qRrftGPwx46kokq6Qlnqorb+rnqytcdDxCR8IL9gaTA=; b=iEtjwQZC/SkUUi75x5hN0IH45WpWDqg+GOW5nrbxl/c3TFeSn0RFD2nt5VOluXM8FAtD ggqs01GHu8ixCezl9cW6PJU2c8/y6t/PrPWXZTCUUrjSph0iWoPnioK0YFigiN9/5fu8h VQwjhfM+4eS83R1R3lrp9SJIX+wayMXAv6/JOcOZAcMdlJ+UhMMnGnULvxQDAUKmAM6FP k07Xen+P8RqONcw6a0LJ+OsxvcmqOgvM4u2R9i003gLQR/oYtaRCpQKJh84/T24sVeXI8 0E22s+JDnL6zmbaraUp0fGCfR/kLesh6UnOWlE+u2hotXt45YmiMNWhdYhMTJHX2GZw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=urHA8UV9; arc=none smtp.remote-ip=209.85.160.52 Received: from mail-oa1-f52.google.com (mail-oa1-f52.google.com [209.85.160.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4E31606A6AF for ; Sat, 21 Nov 2026 01:11:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A4E31606A6AF Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=urHA8UV9 Received: by mail-oa1-f52.google.com with SMTP id 586e51a60fabf-4adea5b7a2fso639881fac.2 for ; Fri, 20 Nov 2026 17:11:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223462; x=1795828262; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=qRrftGPwx46kokq6Qlnqorb+rnqytcdDxCR8IL9gaTA=; b=urHA8UV9aC9N/3eLeoNbfkRK7TFK+v/AKaDDkdh9ymQgcv7WDKnq1ql//pWdy6BGUH NHHon/zLIuUbD9ipU9zLNKXcK0P/b6hKHsRqZkPk/+GJ5mnFZXffcAcPYEYwLB1bjVbI 4fnEXZwJixKEu0gmRZz8fwEYqggdEpXx6WlkS1FMBosr78lB9WiH01IMcRT6T8NtNasY 2iqs0aMTllNEzFaBVg7ci+F9anEN6o/Mh8lHg0wRTW2LpQlsE7vZDyGBs2mtq6A/oMhi 8261VDcwywEe9wb8uWyL7OiLPyKt+lYe2pXkzlVILuoxpRhzCHtWjOxKYN+Vx4OFkO23 IOYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223462; x=1795828262; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=qRrftGPwx46kokq6Qlnqorb+rnqytcdDxCR8IL9gaTA=; b=nGDycz9LUGD3mVZAAtcNtMh1xnnz9t/KS+1dNooxIaw2VeYGlcRG4fP7lA5HsZcjIz mxc0zhrmR3TRi+e2KCTmKBkskbV3DrwhTCdvO0cvuvRw8sIO0GxwOEsfSMyaV8Wo/pWT yKWpDJdVv1Vj57BX9Gs6WxhUVLSv2WLSkaECZ3G6zZpLDqHQpe7hOL+wHxHsfL+G0/gh ceuVW4VoWvxJA30YNOw7JynB7nnQ1jPLopQgvbRPY7xCsS4DnsGx+FQ8oIzY17UDgyIT +qgvuN/Lr15i51YGDY8IYb3pkeSLY1EvlcMCSFnOrHRUn9s6phNL4Zg+xovVQUExBhn6 UvtQ== X-Forwarded-Encrypted: i=1; AL+hErEiY/fN84XyTjyXa/mUF0D7gpv3h4ZtP1pxJar11bEmf5lPIaCqDiBB3XL5LjmjHWwvfYbUL9Jura3AoeA=@vger.kernel.org X-Gm-Message-State: APuU4Z9GJ9lbU4xMqLdSC0j+Na0A/wNSNvsLjkpM7LkKsClOAeNHzMz6 JjOzfra0tqUTlxUBpTObqvuGRi8koyt1A0tGNb6v7AAkHXCrkyx8I1g6 X-Gm-Gg: AYBFou0detES8uus47rVY5HSViGmoSlYuqxi7t7Yu2riMEtt0UGHh/jZIhaCiYcBFBl R9hkPspdv/Lqpyi+KtJIXBROWcBw2bRsPwPnMaQyDuHQZnZ4Pykjgpw8sqlZ5s1ecegYS35Pk5c ++beWuINFvqi9d0cFsaF71krkhTa/PAaabJcf4X0AHW+3IwPqbp2VdCLeBDtI1HysbXviSyU5tB NlTkN9+e73WU6P7h8T/JFmtzn2lmHy9giovvG/O+JQs9jXR1c6Vyi1c2WHX4gTvZ9e8ZYJUSYzP /qvJahv9tS8AlMsWXd7c3J5bj+jgmk7Dja931cKgHEiQwCGcwqV0YlufyZ3mDXnYcIpZi5atdI8 NF9cskKZDn7YsdfSKx97OatIUWtap8lCISkPDExYpyGMASRRpwnwA5xDIkfO91a4S2YRR/XExYU 2vwKcWWdXc5YRLlV8NQ+N8UacFi9kJDjVM3Kwqj3qhdkqLZaOBhTK57TUqPKTTevKT9ih4MfGA0 zwCshrQxdvl5UreFIP2lYzlI5m4nCHoNXWe/MsavkM1vp1zeX3Dy77PhW9aRQ4Kmwi11sFbCpBM jt2sTWPOkCv9Fg8TbY1EisQn0hHZPUXmcZiEHOgyAQUBINxY/W1cRK/IqcdjAOLg43U9QKVXG07 slSmSJthVuX81Zuirnp3oEE+t7Jmb57fk1R7XcH7Bj2bsxftBT2kH1vvMNCDM9xUnTOeE8N3C5K d2RAZKzTzh80I8eJmFwnhc3MlQHa+nBfNxH+ZwcsfT76vaniIhzQyT X-Received: by 2002:a05:6808:e8c:b0:4f3:e98f:fa27 with SMTP id 5614622812f47-57a09c1107cmr6207418b6e.16.1795223462573; Fri, 20 Nov 2026 17:11:02 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:02 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:28 -0700 Subject: [PATCH v11 05/26] mtd: rawnand: sunxi: reject ECC layouts that overwrite the bad-block marker X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-5-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev On 8-bit NAND with 512-byte pages the factory bad-block marker is at OOB byte 5. With a 512-byte BCH16 step and 32 spare bytes, A10 and A23 can fit all the parity, but only bytes 0 through 3 are user data. Byte 5 is generated parity: programming a good block can change its marker, and a mark-bad write cannot set it independently. Reject on-host ECC if the marker is outside the two bytes reserved for it by the layout. Leave the on-flash marker at its NAND-defined offset. This also rejects some configurations that used to probe. On A10 and A23, requesting a 1 KiB hardware ECC step on a 512-byte page could trigger a fallback to software Hamming. That fallback kept the controller's OOB layout: its first three parity bytes occupied offsets 4 through 6, including the marker at byte 5. Selecting software ECC or no ECC explicitly does not install the controller's layout. Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index ffbe851b87c7..086618dee999 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -221,6 +221,7 @@ * On H6/H616, this size became configurable, from 0 bytes to 32, via the * USER_DATA_LEN registers. */ +#define SUNXI_NFC_BBM_SIZE 2 #define USER_DATA_SZ 4 #define SUNXI_NFC_MAX_USER_DATA_SZ 32 =20 @@ -1939,14 +1940,9 @@ static int sunxi_nand_ooblayout_free(struct mtd_info= *mtd, int section, =20 user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, section); =20 - /* - * The first 2 bytes are used for BB markers, hence we - * only have user_data_sz - 2 bytes available in the first user data - * section. - */ if (section =3D=3D 0) { - oobregion->offset =3D 2; - oobregion->length =3D user_data_sz > 2 ? user_data_sz - 2 : 0; + oobregion->offset =3D SUNXI_NFC_BBM_SIZE; + oobregion->length =3D user_data_sz - SUNXI_NFC_BBM_SIZE; =20 return 0; } @@ -2099,6 +2095,12 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_c= hip *nand, if (mtd->oobsize < sunxi_get_oob_offset(sunxi_nand, ecc, nsectors)) return -EINVAL; =20 + if (nand->badblockpos >=3D SUNXI_NFC_BBM_SIZE) { + dev_err(nfc->dev, "cannot store bad-block marker at OOB byte %u\n", + nand->badblockpos); + return -EOPNOTSUPP; + } + ecc->read_oob =3D sunxi_nfc_hw_ecc_read_oob; ecc->write_oob =3D sunxi_nfc_hw_ecc_write_oob; mtd_set_ooblayout(mtd, &sunxi_nand_ooblayout_ops); --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223469; b=q4AycO0uDc6LUEHhZX2oCQrNn/RlVTBtbBQGwh+w39NCLEhlJJxtLs0ilrnlAMtEpOW+ RUoH6VZsrfgjb7M0VJrszqrBTK4eiwfrv0Xp4eZ4NGSCJbNBqDJPykNGm0ybr6zl8c8Ac gQtLDYIUcPBK+ehnX5OEh7QNMONn9LyNa9gTX7etKQrNuNhH17ciJz2scc2Am13GISzJ/ Fz0BUd3kxHR5bSrxQIPVK7wgawwUo7k6CN/CgXAAjK8k8I3kt7WJ1UADMFSBysWMFgPGa v7OWekQ/STuL4c73nYWe7/oU7ZMm3xDk4GoRi9tUrQOWzLDp+wFc1/kP/aZeQrnkSZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223469; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=0IrAGyQNQ+9vmexJ3HX+RGvKm7PP0ZR37lEcYjBayK8=; b=PDdeI569WrLgLdFESxuTCyiqnAxJncd9Gp/npiX0YUCU2f6hH5FBC8F5mBXerjhnjsCn 4O1qqBWlVmGx94nW1MS+jODLK5DP+PLov42vuJCRjuN6wXIDCw/Qln5xCECOHPdzCV2kd 6eh8A0GwvFvd95fiCuuSf4yRXeNN/VTxv9/SR7MO2FJE7i1zd+G7PAOmKR9KBP5vX2mqk MOHK/0KSlw4dl4t/By0NGOwbsAQoHNz1nZPeVduenonJXJy04QJqO3kCckbP1WBRLWg2Z 7kAwCpWFY1jdbaWnpZMWel649nJvENoKnyL85u73Atn5TawPo9R/xVv5dXFGEW6qvxQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=wA+gocC3; arc=none smtp.remote-ip=209.85.161.54 Received: from mail-oo1-f54.google.com (mail-oo1-f54.google.com [209.85.161.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F1EB606A6A7 for ; Sat, 21 Nov 2026 01:11:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8F1EB606A6A7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=wA+gocC3 Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-717080a2d50so1386320eaf.0 for ; Fri, 20 Nov 2026 17:11:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223464; x=1795828264; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0IrAGyQNQ+9vmexJ3HX+RGvKm7PP0ZR37lEcYjBayK8=; b=wA+gocC3cINfQJysjlhm1wWwd9fwDKpCIMdkLBs9xSFYRo514mTsibmbMjvsFTyuJZ qISsD72LyACapDfMi19sBBXYXhyhZ/PE7drKYWmrrkj+CKfPMlSPH4QvE2qwnM7fnHii aujPxAfhrB7c82uB1bjbzrjfDrXoBQUy/zhKTTHJdARTS/7rLqa/a2h16T3C3A9r7YtS oiBGH9Gm/AsimfLVkcjiMiGuBTyISsBjhJmDjykcybmMVt/zNjZVEygxtOvaOOI8yFaZ MZQksI24r1PF4xAF12pZVcA4IbpefNWFRTBDy0ruq/ZF+JweCulKT/Nl7FUlqtfYVvlF 89AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223464; x=1795828264; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0IrAGyQNQ+9vmexJ3HX+RGvKm7PP0ZR37lEcYjBayK8=; b=iqvkk8orFUupzaja1j8GRMlcI4QofwwVJ5M1+W9vLJNzQKcFTDojvNOQPZf1Gyocp7 01Qi8uj/QEAzcUvdLMJi9Sg/Zz8YYSJ9x89RADxbzBRDmLi64+OIVc23+J7hoEvpg4GE P8NzT0/0xhJ+h+/iR3roZJ/zO1WuHOeEsGcyZGo0zO+4iFbSIp0J5xLlm4xQXjLrM2/8 JI7bC1t0AU10QGGEoMWvpotbGxullIP3O6bABOkPaE9Yf9pY86/TjPbdiQnL7KRbZ9fR ILg0o4JBEuOMYtMc9o5Jxc3iz5fb1zwJf8o+NhxR1uhCtalrMbniXfV9bpmjq2wL2Z6c 0xIg== X-Forwarded-Encrypted: i=1; AL+hErH8d4xKaZrgcfk7w0Bm4CyGbvEA6mAENFvIEMKUvm8eQnr9us2JrVuo5td7m/3439EZAjL6eQ7iT3Bf+uk=@vger.kernel.org X-Gm-Message-State: APuU4Z8PD5lrOnii9vK7VDtRSSe2AdQVh47wOyhBqEHbeE7ngQuX3KUP z06nUX3BLCSn0EWJa2Dhu8++/KVuKvN6dd6LvsJOERgw1IDVJsiVKjJg X-Gm-Gg: AYBFou2Vx1tXE1uzp90n6qr4N/OO1C0ZQuHbIDdyPXa9DGAGwcRfHm+8ZstlTWr7NK2 ZzqvNPyEOwuMyhX/GPxUGsPE5CU9vBDUgZeHCYKhh4cF9BThFleipeuEJSJe6CuNH5EB+zhabb5 QvD0hdPnREyFMFIJ/tvv2gGbeLAimW7cg8v3azuc8+vDOEOO+EyYU7XyFNN4b7xBgQ2BWP3IkRd ssXvQ4aYurT4C8aw2znW3/JbogpdWFsxeuPxzanQUXaYhj/s9wTl009wtYg5bk8WRStBMeKzPFS wJuYuYoM/ZCiSc/HrAkdqg+q1ErhUm8I/dLCOjSwP/D/AUXEkmXH6pjEo/SNlgZl5W9204EI780 HCTlrFJOCDz1VpRXHljIZilzLlh2YJdotbilEnYp96TWjuR/XF1F0vkqaaVtlZgpcS6U4xgRXVL LxElHiXVLbdrjWsSZiDrIDwp6uCRFfetaoGm9Pk3qs5qKkSHkjyJOdbQ7N5G1AKBVRhD6LzPszE QsBsiRcK1TqpeNGpbSRmM8XEypehsQQ7kCjhMEk5lpGUB+nGbdHBgYzkxjBKXWLbBmr3dsRqyg1 eZz8ONhCPtw0zdnBR/wSgONWt4fuT4+aQt1J2bIrJJldROaKBGOKo9P82MKfGSgIH6oondO8Psy Pk5STw3DiWh3xIojnW0g+Ubh9MPk9JojvpR47sbxJMW4vzqNKjmj2CHUz+q9JtKetRTlnJ1xjEl 1h/kWI54pKOX4P4jiXkc4BP/nNXcS+XTNJbvCatoDrJ9H7g0/3dwsr X-Received: by 2002:a05:6808:6d93:b0:571:4e99:7942 with SMTP id 5614622812f47-57a0b65aeb8mr5797462b6e.48.1795223464361; Fri, 20 Nov 2026 17:11:04 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:03 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:29 -0700 Subject: [PATCH v11 06/26] mtd: rawnand: sunxi: use page reads to reposition small-page NAND X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-6-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org, Sashiko X-Mailer: b4 0.17-dev On a chip with 512-byte pages, an ECC read can fetch bytes from the wrong column. The driver uses nand_change_read_column_op() to move between main data and OOB and to reread a possibly erased chunk. That helper rejects small pages because it uses large-page random-output commands. Some callers then continue without repositioning the chip. Use nand_read_page_op() to select the requested small-page column. The NAND core chooses READ0, READ1 or READOOB and sends the page address again. Keep the random-column command on larger pages. Use PIO for full-page ECC reads and writes on small pages: the DMA sequencer uses large-page random-column commands. Sequential small-page writes need no change-column command. This fixes the command sequence for an otherwise supported layout. On 8-bit small-page NAND the factory marker at byte 5 still lies outside the reserved marker bytes. On 16-bit NAND the core uses byte 0, but the driver does not program the controller for a 16-bit bus. Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Reported-by: Sashiko Closes: https://lore.kernel.org/r/20260913041642.E28F81F000FF@smtp.kernel.o= rg Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 086618dee999..9d7e3e6f22b2 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1028,6 +1028,16 @@ static void sunxi_nfc_hw_ecc_update_stats(struct nan= d_chip *nand, } } =20 +static int sunxi_nfc_read_column(struct nand_chip *nand, int page, + unsigned int column, void *buf, unsigned int len) +{ + /* Small-page NAND needs a new READ0/READ1/READOOB and the page address. = */ + if (nand_to_mtd(nand)->writesize <=3D 512) + return nand_read_page_op(nand, page, column, buf, len); + + return nand_change_read_column_op(nand, column, buf, len, false); +} + /* Shared across a read's transfers; buf remains the full-page buffer base= . */ struct sunxi_nfc_ecc_read { u8 *buf; @@ -1111,10 +1121,10 @@ static int sunxi_nfc_hw_ecc_read_error(struct nand_= chip *nand, =20 /* Check the physical representation for bitflips in erased pages. */ if (nand->options & NAND_NEED_SCRAMBLING) - nand_change_read_column_op(nand, data_off, data, ecc->size, false); + sunxi_nfc_read_column(nand, read->page, data_off, data, ecc->size); =20 - nand_change_read_column_op(nand, nand_to_mtd(nand)->writesize + oob_off, - oob, oob_len, false); + sunxi_nfc_read_column(nand, read->page, nand_to_mtd(nand)->writesize + oo= b_off, + oob, oob_len); =20 ret =3D nand_check_erased_ecc_chunk(data, ecc->size, oob, oob_len, NULL, = 0, ecc->strength); @@ -1141,8 +1151,8 @@ static void sunxi_nfc_hw_ecc_read_extra_oob(struct na= nd_chip *nand, return; =20 if (!cur_off || *cur_off !=3D (offset + mtd->writesize)) - nand_change_read_column_op(nand, mtd->writesize + offset, - NULL, 0, false); + sunxi_nfc_read_column(nand, page, mtd->writesize + offset, + NULL, 0); =20 if (!randomize) sunxi_nfc_read_buf(nand, oob + offset, len); @@ -1200,11 +1210,12 @@ static int sunxi_nfc_oob_read_batch(struct nand_chi= p *nand, if (read->oob_required) { /* Keep the existing PIO and DMA representations of parity. */ if (read->dma) { - nand_change_read_column_op(nand, mtd->writesize + oob_off, - oob, ecc->bytes + user_data_sz, false); + sunxi_nfc_read_column(nand, read->page, + mtd->writesize + oob_off, + oob, ecc->bytes + user_data_sz); } else { - nand_change_read_column_op(nand, mtd->writesize + oob_off, - NULL, 0, false); + sunxi_nfc_read_column(nand, read->page, + mtd->writesize + oob_off, NULL, 0); sunxi_nfc_randomizer_read_buf(nand, oob, ecc->bytes + user_data_sz, true, read->page); @@ -1260,12 +1271,12 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_= chip *nand, int ret; =20 if (*cur_off !=3D data_off) - nand_change_read_column_op(nand, data_off, NULL, 0, false); + sunxi_nfc_read_column(nand, page, data_off, NULL, 0); =20 sunxi_nfc_randomizer_read_buf(nand, NULL, ecc->size, false, page); =20 if (data_off + ecc->size !=3D oob_off) - nand_change_read_column_op(nand, oob_off, NULL, 0, false); + sunxi_nfc_read_column(nand, page, oob_off, NULL, 0); =20 ret =3D sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) @@ -2105,7 +2116,8 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_ch= ip *nand, ecc->write_oob =3D sunxi_nfc_hw_ecc_write_oob; mtd_set_ooblayout(mtd, &sunxi_nand_ooblayout_ops); =20 - if (nfc->dmac || nfc->use_mdma) { + /* The DMA page sequencer uses large-page random-column commands. */ + if (mtd->writesize > 512 && (nfc->dmac || nfc->use_mdma)) { ecc->read_page =3D sunxi_nfc_hw_ecc_read_page_dma; ecc->read_subpage =3D sunxi_nfc_hw_ecc_read_subpage_dma; ecc->write_page =3D sunxi_nfc_hw_ecc_write_page_dma; --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223471; b=DiHK5MppdK26ZvmJ9IzS0Yta0cd62AIDqCla2Tu41aGOTcohF0AaMRE/A596uGECGj3O PmbP32AyQt5RBkU52xEpO2TSG/wqMRugRviBkELHfjq1q5fgFB0NdQ8N0uw2lxV4ITQVV NfAdwUxBVH1yeoy5yC/zwP8xvYdEBT5ix8YN2XM8IQPvzJCbJhIzg0ZVMAXGuzvT8ypUv Kguo6wHOGU/edyGWA+edJMnn7o2G40Thj3jvUlGkwrYL8PV4E62HeYn30dXNzHdbxHBnI N+4agXyRPFpziwAxJmp7y/d3s/tHJF/14ilvATGYcI0vrgoFGe/Lat9wc+NtWEsUIPQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223471; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=tDxDnDKQmgOhb7t9CqFuoW8PN9zlg37X4nU+lrooV8U=; b=duy9n6bftBqUepahSkKFh8H8vaK6fSJUDzmCA7jyBMTIBldpRqlVwNSVDqmtbAnwQpsG SpG39Z6OEX4iKkmACHOP2dzBfmAy5bsjqF2EuLQ0VTB/QpkNbDrMkRj3FTWR+1muEe1xo M7Hy4MtsqjxMcbBuqFQLAuXMyLXr+WUCC/8r4jSGN9f5ZMZaFfZe/2BIANkzywyHlLwSJ x75Iu5lGvBGeStk8ddcKPFhW2YUJCy88dwwwxDlwH3SgyVgaC6V5j3z5BtCUW9paD/fG/ KQ0IfYQzzO/avq6a2xttp+SibxQxoxKB8dC52jQCYGs0uz07J1X0eTweJKiG4aUs2Rw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yx5gheen; arc=none smtp.remote-ip=209.85.167.180 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C599D60A2625 for ; Sat, 21 Nov 2026 01:11:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C599D60A2625 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yx5gheen Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-4a451915d8aso1058761b6e.2 for ; Fri, 20 Nov 2026 17:11:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223466; x=1795828266; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=tDxDnDKQmgOhb7t9CqFuoW8PN9zlg37X4nU+lrooV8U=; b=yx5gheenrepbzKlY6Zc758JhtUoa27vxVHp6l2Dj+Nk65HcFNRkrroyys3ZK+FR76t lAqpw2Ak6QhnWujbws5tJbIXpgJ1T/9gir9C3lJijMuPJnPuGbEhILWihsBMjXHaTsly KrjUw4gS4nZvvSmXYufKzmFWQSNBf9KIZBnmvZAhJRxD1514PL/gSJI2tgsdyncO2jYG KeOn+yxOXNVw+eH1GTgvs7MZwx0kcuGLzBmZETtB0usZ61lSwaBaiIHNjMqIo3og+8jH Dl/+xNmg+r2C4OpnA07VUqt+6E/OFP7J0mp5HErff/jDHWagNAEagTKgqEspU7ydLGht lhAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223466; x=1795828266; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=tDxDnDKQmgOhb7t9CqFuoW8PN9zlg37X4nU+lrooV8U=; b=VAtpkThU1+xc/x0ngWLXOxoSZ+XnMj5p31clF2tJpsPBka6z8gR1Un4Tp1NfhVoUSP sz5uvsvpl6gZf0AfX/Gaa19vSOynhaxlMAR1Kj9Ci2mexLa/wG7IEzwSt+/OcBXxZJeJ 9mpuJzt72p/e32klhZbZNa6eX2XIf25soCJWW+ZkQey94fNeGK4BP8B2o8i/sQRBYJ36 YRKmvedXJ6L5khbNsFSlAYOr7As640C/NK+cOTayykTXAUMoZDgXOFUKdSd1BoirJEUE Z+HYCFcvLtCxQ2q8VW0jnxV7et2HhwW2klifPnuJzRvEzsDZLG5qQJIK3fhd32FseDYv ZKPA== X-Forwarded-Encrypted: i=1; AL+hErGHkPGp/j5BwkZpCjCEVZj97OVobdPo07YNiD1lOIOa1PBH8FxaCNFcaLcG+b9AZ5kSUolmonWh/Qvg8I0=@vger.kernel.org X-Gm-Message-State: APuU4Z9fWh3NHXjbSoWlDM3PyDHng8bdsnPr0A33GjQAoU1eHKC+C6iD bQwlK31UCVRVAnCB99g6zGAS7bvk/ErFAvdXX4vMlWgtgbxcEn0tKDmp X-Gm-Gg: AYBFou3TuymjpmOFyQLFizEM4YFfmo/N7cQuZ6/6La4XGAqpzEqT7xG5Xd3nO0OwOoH eBN6mf+O1/8tbAhkEc6Fe/sXS8S3EUj8CAaPs5xkvazcC8CHUslF+EXpprPjjRKfIP3GOlJfW1j AA3uy/n6XXd2w1t9peG6PJbdwFjARhIeckCGmsqfhUXH04Gz/SrYKl4HYF5B/cdPX5cZTrrhNRA xcfL9PT6QLhGyf+9NhpoVqmCE775yGqP+Ru3LUojBuSRlpBNzb4/icsddqvWeOO09MgzUpq7m5j n1JR68hYDqgfhM0FK3Ad3V8IuZXDsG5LRSWk/Q2erm7oC5YEv/Q3M40t5T3NTmNWiwNDOzDZIPI aK1iGBOXUG3WvkHDl9ZRwSzXfKr/TpZ1EiW+/lQY3faMAlan0WbmCJzyEX32npXVrZO2z6tNF31 vU3QN3fZn267NipolbAZh6VfrNWUPePlDi61Tz884OVMgx6j/xj1t6UtnFi47aVReMWYdzCjiaO Od9NVA1j8re8uskKp6lRgBsZx21q7kqdoMGUwGE1ZzKpSyr00qRr8+RGb5bbsFOGwCzwIpj7mk/ 1GUWr9nj/etGilkVMzy8ybky+I9oOogJduzU4qxjWpkR+NTtVDFtjPn0SmrmCaHRdRWfZ5YSV1o hcFcpm0zqbecpsJS6obF2I7VWwHdSQewsAXBJDPXX8WGd9P53ba2rzLk8TT/i/3B1U1w9LWY2YB A3990zLYGz7U54vxQDr9tVbPHSPOTckTrp+lxBAuZE4MqJDCcnqFui X-Received: by 2002:a05:6808:244c:b0:557:4340:4d47 with SMTP id 5614622812f47-57a09400d0amr6720622b6e.35.1795223465752; Fri, 20 Nov 2026 17:11:05 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:05 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:30 -0700 Subject: [PATCH v11 07/26] mtd: rawnand: sunxi: propagate page-setup and erased-check errors X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-7-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev If the NAND read command or ready wait times out, an ECC read can report success with stale data: the callbacks ignore the error from nand_read_page_op() and continue with the page transfer. Return the setup error before starting PIO or DMA. After an ECC error, the driver checks the physical data and OOB for an erased chunk. It rereads main data if scrambling was enabled and always rereads OOB. If either reread fails, propagate that error instead of checking stale data or counting a transport failure as an ECC result. Leave uncorrectable media errors in the ECC statistics for the NAND core's normal retry handling. Route PIO read errors through ECC disable. DMA has already released its transfer resources before interpreting the results, and its caller retries a failed read in PIO. Restore the corrected/failed counters from before that DMA attempt so earlier steps are not counted again by the retry; leave bad-block counters unchanged. Fixes: 97d90da8a886 ("mtd: nand: provide several helpers to do common NAND = operations") Fixes: 25f815f66a14 ("mtd: nand: force drivers to explicitly send READ/PROG= commands") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 45 ++++++++++++++++++++++++++++++-----= ---- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 9d7e3e6f22b2..c5e429318de2 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1120,11 +1120,16 @@ static int sunxi_nfc_hw_ecc_read_error(struct nand_= chip *nand, int ret; =20 /* Check the physical representation for bitflips in erased pages. */ - if (nand->options & NAND_NEED_SCRAMBLING) - sunxi_nfc_read_column(nand, read->page, data_off, data, ecc->size); + if (nand->options & NAND_NEED_SCRAMBLING) { + ret =3D sunxi_nfc_read_column(nand, read->page, data_off, data, ecc->siz= e); + if (ret) + return ret; + } =20 - sunxi_nfc_read_column(nand, read->page, nand_to_mtd(nand)->writesize + oo= b_off, - oob, oob_len); + ret =3D sunxi_nfc_read_column(nand, read->page, nand_to_mtd(nand)->writes= ize + oob_off, + oob, oob_len); + if (ret) + return ret; =20 ret =3D nand_check_erased_ecc_chunk(data, ecc->size, oob, oob_len, NULL, = 0, ecc->strength); @@ -1308,6 +1313,7 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct na= nd_chip *nand, u8 *buf, { struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); + struct mtd_info *mtd =3D nand_to_mtd(nand); struct nand_ecc_ctrl *ecc =3D &nand->ecc; struct sunxi_nfc_ecc_read read =3D { .buf =3D buf, @@ -1315,6 +1321,8 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct na= nd_chip *nand, u8 *buf, .oob_required =3D oob_required, .dma =3D true, }; + unsigned int corrected =3D mtd->ecc_stats.corrected; + unsigned int failed =3D mtd->ecc_stats.failed; struct scatterlist sg; int ret, i; u32 status, pattern_found, wait; @@ -1366,9 +1374,19 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct n= and_chip *nand, u8 *buf, ret =3D sunxi_nfc_oob_read_batch(nand, &read, status, pattern_found, 0, nchunks); if (ret) - return ret; + goto err_stats; =20 - return sunxi_nfc_oob_finish_read(nand, &read, NULL); + ret =3D sunxi_nfc_oob_finish_read(nand, &read, NULL); + if (ret < 0) + goto err_stats; + + return ret; + +err_stats: + /* The caller retries the whole read in PIO mode. */ + mtd->ecc_stats.corrected =3D corrected; + mtd->ecc_stats.failed =3D failed; + return ret; } =20 static int sunxi_nfc_hw_ecc_write_chunk(struct nand_chip *nand, @@ -1453,7 +1471,9 @@ static int sunxi_nfc_hw_ecc_read_chunks_pio(struct na= nd_chip *nand, u8 *buf, }; int ret, step, cur_off =3D 0; =20 - nand_read_page_op(nand, page, 0, NULL, 0); + ret =3D nand_read_page_op(nand, page, 0, NULL, 0); + if (ret) + return ret; =20 sunxi_nfc_hw_ecc_enable(nand); =20 @@ -1461,10 +1481,11 @@ static int sunxi_nfc_hw_ecc_read_chunks_pio(struct = nand_chip *nand, u8 *buf, for (step =3D first_step; step < end_step; step++) { ret =3D sunxi_nfc_hw_ecc_read_chunk(nand, &read, step, &cur_off); if (ret < 0) - return ret; + goto out; } =20 ret =3D sunxi_nfc_oob_finish_read(nand, &read, &cur_off); +out: sunxi_nfc_hw_ecc_disable(nand); =20 return ret; @@ -1482,7 +1503,9 @@ static int sunxi_nfc_hw_ecc_read_page_dma(struct nand= _chip *nand, u8 *buf, { int ret; =20 - nand_read_page_op(nand, page, 0, NULL, 0); + ret =3D nand_read_page_op(nand, page, 0, NULL, 0); + if (ret) + return ret; =20 ret =3D sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, oob_required, page, nand->ecc.steps); @@ -1510,7 +1533,9 @@ static int sunxi_nfc_hw_ecc_read_subpage_dma(struct n= and_chip *nand, int nchunks =3D DIV_ROUND_UP(data_offs + readlen, nand->ecc.size); int ret; =20 - nand_read_page_op(nand, page, 0, NULL, 0); + ret =3D nand_read_page_op(nand, page, 0, NULL, 0); + if (ret) + return ret; =20 ret =3D sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, false, page, nchunks); if (ret >=3D 0) --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223479; b=dCr8aT/8SPn2Th5ECSpRgVvi67o1RBc3uimfa5IAVYGCNAcRZOqNngunTl8D1n87d1u0 wAdsnWzWBunGr5wwXe+eH6QpAhK3S32Qyv7aMqVAPSnFzii4xCq3AmYxN2hwswJa3BSwd xcEnbMkdcyI/oW3R1MRLCMjMcgOvqBrG0GOv642thwK6HKUVN7Kwh1Bc08t5LE54Z+l8z SVJU677o5hfWwZhgTZ1hKjd/43VGz+MfsjdXx5xcvPUcnL2sVQOkakzgFsCS6dtBMqp8r hdG506bmA0tOsbk3FkTI6JX35mHFQwIpp6ep4kj0VR1K/gpmanKI6q/29DIP2aqXB1Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223479; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=ykELsWqv0rr01vGMcfJTxNz9WxlFG0XTipq7Ly2y7EA=; b=1SvjPJnI0Fq3hyj+KAtvA3N98tFpUFKZdSPpCMUQy+T2V6Dhd1zU+cIO8b5to8X5/23T vLG8NLYGtfoqu/OFqSrlLgCihU+TX1s+sHw+mPyMUI973v/JaYOnvYoIRV26n/pJwy7s8 ui0Gf1O3mkNW1Liw0eoMz8GQnh7ODG+qTGTIYnVGeekw766HQ4bMgJVf+S9I2vQ5eQWPb yz7NgcB66jJ1qvYaBS2+SbfrOUt1lCrigT7p6nQ0Zfu+RzIiST+GQilMbYdH6AHwz9zUp 5NT3rQdQWr+FZSvyFCO95KuM4E3Bf2qz09cpeICDlvAWg0OyA0rkd1CftOhWyDk3ZnQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=b0cpWJu8; arc=none smtp.remote-ip=209.85.167.174 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3642C606A6A5 for ; Sat, 21 Nov 2026 01:11:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3642C606A6A5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=b0cpWJu8 Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-53dbe9b8d6eso1163560b6e.1 for ; Fri, 20 Nov 2026 17:11:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223467; x=1795828267; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ykELsWqv0rr01vGMcfJTxNz9WxlFG0XTipq7Ly2y7EA=; b=b0cpWJu8oKq/eQxIY9Z4OLn040voVe5kncYAI5VgPjj3msw8MExiRl8qojO1bzAM8O WHqkC7x+rqv5t0LAEqN+fv3A7pEG/JSON0sBvY85uQT5tFsgKpvDWut14HnY+eqxBRI8 SJHGtPvCmyk9+ak5lB7k4yiFV/1DEqAPsjMcMSmNgJ9hCmqGGFJskT8Qwi14MocX1m1d KEnMkBwGSUOv8gqZSBPmGs4Hx0qMtA9u5biU1ICakLskTzdf9jgxT2+RBNDt7DLLYA+i eAMsMjHF7gPvzFPejvewNgScLDwNdCkqdeZbf9j5hc1NJCMphXw8cworRFbH1vdqxDji D1Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223467; x=1795828267; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ykELsWqv0rr01vGMcfJTxNz9WxlFG0XTipq7Ly2y7EA=; b=tOGgTyfkw+FIchkC2WJLm/S+QPUasqzpaWkRwI3HltBrEoIkgGEkergwltBqQzkvEK PDBnFbg0Q7IVQZPTYLWo5sNJn0OR3/vnpU+lDHY5VFLTenA533mfPmQHKwUZRjFRWyNh LDwBqzHHbCMgqzNKM+JMmxtsyAvq44g7jUMVLhUUzpurTLtXK74aWNvotaH2Om8kFBQU vI4dv8Jex/HUDaVHDzoSn5zWP5hJW0TapbpBvfsRjOUFa/YfWtIcYsvz30HefUoGynQI 5bmz2qD88h/Pu4HuaHoDVf7N4hLeTACSqH9UaSfoEXMJwFj4K1YvMM8LQ+4xTCCZpoYt u0jA== X-Forwarded-Encrypted: i=1; AL+hErGrLnqZMRNnY8ISS/TxqQqdFjssi6ZoYNG+FUtMp9UwcXUw/x11oACS6wipmP3OlbQFQHh4CwVLKYxWmwU=@vger.kernel.org X-Gm-Message-State: APuU4Z+c79GEtuP6n4ugrK3ey/dLTVkrswVWnhZJ/lmFsl5OUZ7vfUYQ o71vGXefXHzMZazDNZYhEaf3DgoqtD0BFZCxh/nMC7A6fwp+oFhmzeg7 X-Gm-Gg: AYBFou0pSIO1OyaYT7UsXCNbixFu0SJuxFTbGuqS/KyHN8rxKHGr3FUqT7laZYZGwSi WOBs7qgtCvhDwK6VCoFZ+eRx/FR5fBAsCVLcz5A3Bh7EFj7E7DwLpGFNptydQ0iz0h9lI/4kB4i Xa+EJTM0wM9puU8wsgwmIrStfxLnXQ/L83EEkWkX5Hu76MQAh8SPtS9+ko6QiUc3UcVb35CvtUp wbiJb476TB5JcCGXBNq+nvx2sQDCuZK25FePnawv2+f/GN44qJZtx6CjfCE4WfXQFzsVzpQJ8fK 8Y3C1V69+1xX6RYW/3ohYU/GhjGOtPg3Rtwhjr1c7tgnhV+7oCCsUUGy7py4JnkDI4kpdUlukl0 xyhdlgyxx0QSUwLkl6Dn3KOnjLgSZTGT/Dt7rkaaKEHSwnUWXWD0Z4RG4hcPDsrb4p19e5qyCZz vxCQ4CcPAEgCAmUaeAEYPrZZt0NrKkN1INK21O+g1fUHOR5iDi+eTybCcc+21ZW5mfvfL+hLhUh ZVXgvkjHIPflwP2Jyo5LdXqYAXlQEDZIxY9ux0dHcQKhzyKcCbbU/S/XlfYOhrxjRuBW4dHQPQB aJyS9/k1N4qZI98norE790n0sZg7L605DSC8IXd4GGa9FlNOYNLVjeyxBqvbk86EWLwtKNluNVK hBjgCXCXxe2W4kQ2VKJA+BXjSFGPJEGE2SFJzrPC/XOv/HJh7AaGymesXRV2TOhwJUnRzUY6KEl N2TDERZVR2V6+1dDmjwPbmCP7kAz1jIsRtS45t6YuFUozBl7WmthTU X-Received: by 2002:a05:6808:3a19:b0:4f1:a3ac:a637 with SMTP id 5614622812f47-57a0b6533e2mr3933225b6e.27.1795223467204; Fri, 20 Nov 2026 17:11:07 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:06 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:31 -0700 Subject: [PATCH v11 08/26] mtd: rawnand: sunxi: drain interrupts before reusing the completion X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-8-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org, Sashiko X-Mailer: b4 0.17-dev Back-to-back NAND transfers can time out or appear to complete early if the previous IRQ handler changes the interrupt mask or signals the controller's completion after the next transfer starts. On success, acknowledge the events and update the mask before calling complete(). On timeout, masking the device alone is not enough: on PREEMPT_RT the IRQ thread can be preempted after reading the old status and mask, then resume after the next wait is armed. Initialize the completion once at probe and use reinit_completion() for each wait. On timeout, drain the handler with disable_irq() before clearing state. Recheck status against the events still enabled after the handler has drained. Command and DMA completion can arrive separately; the handler has already acknowledged and masked any events it handled. An empty remaining mask therefore means the transfer completed. Flush the mask and acknowledgment before re-enabling the IRQ. Normal NAND I/O waits in process context. The IRQ is not shared, and the handler needs no lock held by the waiter. Only timeout cleanup needs to drain the handler. Its latency is not bounded on PREEMPT_RT: there is no priority inheritance if the IRQ thread is starved. Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Reported-by: Sashiko Closes: https://lore.kernel.org/r/20260909085434.C8F201F00A3A@smtp.kernel.o= rg Reviewed-by: Sebastian Andrzej Siewior Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 38 +++++++++++++++++++++++++++++++----= --- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index c5e429318de2..6d7384aac917 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -378,6 +378,7 @@ struct sunxi_nfc_caps { * @chips: a list containing all the NAND chips attached to this NAND * controller * @complete: a completion object used to wait for NAND controller events + * @irq: NAND controller interrupt * @dmac: the DMA channel attached to the NAND controller * @use_mdma: use an internal MBUS DMA backend * @mdma_desc: H6-style MBUS DMA descriptor @@ -397,6 +398,7 @@ struct sunxi_nfc { unsigned long clk_rate; struct list_head chips; struct completion complete; + int irq; struct dma_chan *dmac; bool use_mdma; struct sunxi_nfc_mdma_desc *mdma_desc; @@ -418,18 +420,20 @@ static irqreturn_t sunxi_nfc_interrupt(int irq, void = *dev_id) if (!(ien & st)) return IRQ_NONE; =20 - if ((ien & st) =3D=3D ien) - complete(&nfc->complete); - + /* Finish updating the interrupt state before waking the next operation. = */ writel(st & NFC_INT_MASK, nfc->regs + NFC_REG_ST); writel(~st & ien & NFC_INT_MASK, nfc->regs + NFC_REG_INT); =20 + if ((ien & st) =3D=3D ien) + complete(&nfc->complete); + return IRQ_HANDLED; } =20 static int sunxi_nfc_wait_events(struct sunxi_nfc *nfc, u32 events, bool use_polling, unsigned int timeout_ms) { + bool irq_disabled =3D false; int ret; =20 if (events & ~NFC_INT_MASK) @@ -439,16 +443,28 @@ static int sunxi_nfc_wait_events(struct sunxi_nfc *nf= c, u32 events, timeout_ms =3D NFC_DEFAULT_TIMEOUT_MS; =20 if (!use_polling) { - init_completion(&nfc->complete); + reinit_completion(&nfc->complete); =20 writel(events, nfc->regs + NFC_REG_INT); =20 ret =3D wait_for_completion_timeout(&nfc->complete, msecs_to_jiffies(timeout_ms)); - if (!ret) - ret =3D -ETIMEDOUT; - else + if (!ret) { + u32 pending, status; + + /* Drain the handler before it can restore an old IRQ mask. */ + disable_irq(nfc->irq); + irq_disabled =3D true; + /* + * The handler removes acknowledged events from the mask. + * An empty mask means all requested events were acknowledged. + */ + pending =3D readl(nfc->regs + NFC_REG_INT) & events; + status =3D readl(nfc->regs + NFC_REG_ST); + ret =3D (status & pending) =3D=3D pending ? 0 : -ETIMEDOUT; + } else { ret =3D 0; + } =20 writel(0, nfc->regs + NFC_REG_INT); } else { @@ -461,6 +477,12 @@ static int sunxi_nfc_wait_events(struct sunxi_nfc *nfc= , u32 events, =20 writel(events & NFC_INT_MASK, nfc->regs + NFC_REG_ST); =20 + if (irq_disabled) { + /* Flush the mask and acknowledgment before re-enabling the IRQ. */ + readl(nfc->regs + NFC_REG_INT); + enable_irq(nfc->irq); + } + if (ret) dev_err(nfc->dev, "wait interrupt timedout\n"); =20 @@ -2559,6 +2581,7 @@ static int sunxi_nfc_probe(struct platform_device *pd= ev) nfc->dev =3D dev; nand_controller_init(&nfc->controller); INIT_LIST_HEAD(&nfc->chips); + init_completion(&nfc->complete); =20 nfc->regs =3D devm_platform_get_and_ioremap_resource(pdev, 0, &r); if (IS_ERR(nfc->regs)) @@ -2567,6 +2590,7 @@ static int sunxi_nfc_probe(struct platform_device *pd= ev) irq =3D platform_get_irq(pdev, 0); if (irq < 0) return irq; + nfc->irq =3D irq; =20 nfc->caps =3D of_device_get_match_data(dev); if (!nfc->caps) --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223478; b=pfGJ3wgsZYnrWpcczNrQWqpmV8bXdZ4lnj/T6PTrQ0RO+vd8UOt4796z6+C1OWmYUCpR EsPCjx6PYWTM0BMoSPyU5J+wXNQSUIMyOMyzkDbKtH8VnDEB7JabKauC7U7JkOOD0BCXX EA/LhgTExpUjiraOTAj7ExEYQO4epRI9NXqzFDfd6+6XS4WzxucrvP8xr3qo4Ga+DWqvf +HeB3wnOD7/p84CwiUP8k5fgHBkSX3y70QUCwRmQJvWn22VPtlJFlZVrH8wSd0wf/zfSC pp7Pmsgqdm0+JOQ8Adm0YXHAFwRqS5xKAiyN6IoGn1mElQmtubI9l58HzO1oAqL29Fg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223478; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=q43OtFOdNFKAPwH+oRkUo2vplhtOIciQt2V0N0tE52g=; b=2ONL8jr8tdonnT1InqJ8ix87u3aUV9NY3db61C3wrOmZtzhXXQP0WkD7bwrEPlN69Ced RrxGLZ694507pnAqIw5vHWl2TPAd3/VByOv1ZG0tSiqEXpdgqUTb1ex+oCjZsEugY2gLB NtNfslIe4nL6ijXI8JKdOFCJZa0rhlDeSqP6CRcDMhV6Z0Vj1FhQ/Us5RDeiryQ8Gk8CA tY3cHkT8ol/gQXue7HVgybvqpPFSs5FoTHUEPoXY28tZhpze25YjDtkOJf3dHL52Aduo+ TB3URLAgZKCv9tYDgGdx2bFfga3vTIpkZuF4fbhP0I3AEeRpVbX7Tk4Q2b5N2ImW/Ew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=BGgaD8Wg; arc=none smtp.remote-ip=209.85.160.52 Received: from mail-oa1-f52.google.com (mail-oa1-f52.google.com [209.85.160.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8094E60A380B for ; Sat, 21 Nov 2026 01:11:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8094E60A380B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=BGgaD8Wg Received: by mail-oa1-f52.google.com with SMTP id 586e51a60fabf-483d290f398so909443fac.2 for ; Fri, 20 Nov 2026 17:11:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223468; x=1795828268; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=q43OtFOdNFKAPwH+oRkUo2vplhtOIciQt2V0N0tE52g=; b=BGgaD8WgiBeyw57h1wjj+17CzfgitgeZ1ndw7lTEr+MChWZ5KvVH4kJ4SuaP6seaED VjID66TCK9/4DClQfuFcMKg+KrvHWPNrzpkDpotP/QEF/JoqEtgU4ZsMc3z+028fQLNv nYNK0Rn7Y5q0u7PGvc/RX1RpEooEZPUX6QqU2ISFee7c0WpqPQfkGTxQ5w4oLFn7V3MY 6TPu7/jmlEmi4/tWNB+lslT1bIV0ic2d5tluhKwYC15wMQeOKlP4RlOoWE6bkw8fk5Pa VoqcBy+lp7MEZNpDNd7LegEWpev+YxLs/Jl8GRJ6PbDLKdT7Fk9VBazbficn7q10g8aG PyVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223468; x=1795828268; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=q43OtFOdNFKAPwH+oRkUo2vplhtOIciQt2V0N0tE52g=; b=GaIswETh1/8dGTh2aSof644f0yF8h3O27y1hSXHlAUq7xxCDM8YSAKRAvxDd9PtcS+ MRPQEgWXUF4619hPOecdZyTNIM3Z7rA9G/orQpe+bzjIS0H7lhD/nh1YvJaWg/nQIQhb s8DcSOApE7yWXJpLF0Mri1VDovJRdnGtXdqhnGpU1jjmMyDY90H9wBWOYtFJaUM4tntX EndkiOYKuorNpqHvmkZ0t3HzVqsN+hjpQjRw0KgOlzWYp24K8eLTQ822Orfr3uzseK3b zo1SHTHRZWKdFNdU/5MdHF0coJXShwu2hMcT5opfD3Cb27xKWTpWBL6on3kPONTlkxyZ xuNg== X-Forwarded-Encrypted: i=1; AL+hErGfi+XVngjAPF1Sw8obsKE96JCXcxOtV8jwCQ7bybz0LbyaFTRhgft+B4mmH3oQyFMiaTargLHYZdxVFhI=@vger.kernel.org X-Gm-Message-State: APuU4Z/hLhNybijO5hRfMNOXiYdaRxBf12iUdyXRkgBKf0aVIjHk3J7C iM5zJjL7XHOZ7O04IgSW/gFFOEeuAwYiDXMeFUQmvfXrqBGWJmHdMBgo X-Gm-Gg: AYBFou2t9Wbs9Tcke0WNQb9DrLKbfCVJUVdBH2fg17MgNNneIIO6Qus/tDYAqHZCUmb rPqviwDd2kbJR9lq3mJ92a5uNVgc+iVxJH1BgGAMgvTvStEz664z+2t4cL+cvE//6pMsD6jEve5 xqHENSo+q/n3W4OZnVGy2DhaWAm42F9HJAm1nhPUZ9EtH6n0TKtJKyTQVOP6lmjhhG27zAVR6xK 4cIme6seRJrE8LBuRY6RXQRr26o5TrOaqD+W/Vgu9lTOV+iw/EpcF4G5I+JxEOis/4ncComPnZQ mE7RdqRDpBiv1F0Ge8T3Xeb3cyWWZIgRl2rtjhCAmnWFg/WMVl2lgGqTUv9xIRfXvweFbEcfzH2 EeaqTDM5Tvnzbzu51nNaQG5xXNWRcL/8aTXlm7CjUoPaW/1f+R7AeR6ZyDhDGkrZdmEZR6DBH/H c0+YyGb3b3XwdI8YC7wr97HMAxaAmtLKYOTWD1sgVCQPnwLC6Ubhry1WyEodxcuEabJXHAgpaXn soOJBkQIdbIwRQTfuuBPIiBkXCtt5NPnYkAUFC1in8VBA49IMw3SfsGASBaBITGbJLoNk7w0UT6 6VIyuW8YP0PEptmVQLztG14j/UYmi0mPH56wX/GKXx+5zITtQfIfo7N5HWOJsePTWM9futRZsXx FKc6GWBkx1awCkwCIJgVHKiVSEMlwWdzrPBcIrkNpEpQvD7GD0fvQnSRkcrLr6SxvIb09g4WU0X 4P89Li4aYKfbbTLFlA0Ek/LGXG1x/UQUYbU8uL1znEeqDQgcF0AX15lA== X-Received: by 2002:a05:6808:4f6a:b0:572:75e6:1d0e with SMTP id 5614622812f47-57a06d1a870mr5691634b6e.5.1795223468341; Fri, 20 Nov 2026 17:11:08 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:08 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:32 -0700 Subject: [PATCH v11 09/26] mtd: rawnand: sunxi: stop failed program operations and disable ECC X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-9-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev A page or subpage write can issue PAGEPROG and report success even though sending the setup command or address timed out. The PIO and DMA writers ignore errors from nand_prog_page_begin_op(), transfer the data and send the program confirm as if setup had succeeded. Check setup before enabling ECC or transferring data. DMA preparation occurs before setup and may already have queued a descriptor and mapped the buffer, so use its existing abort and cleanup helpers before returning that error. The PIO writers also return directly when a chunk reports failure, leaving ECC enabled for the next controller operation. Route those exits through ECC disable, preserve the reported error and skip program-end. Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Fixes: 25f815f66a14 ("mtd: nand: force drivers to explicitly send READ/PROG= commands") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 6d7384aac917..76f60fde7a86 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1578,7 +1578,9 @@ static int sunxi_nfc_hw_ecc_write_page(struct nand_ch= ip *nand, struct nand_ecc_ctrl *ecc =3D &nand->ecc; int ret, i, cur_off =3D 0; =20 - nand_prog_page_begin_op(nand, page, 0, NULL, 0); + ret =3D nand_prog_page_begin_op(nand, page, 0, NULL, 0); + if (ret) + return ret; =20 sunxi_nfc_hw_ecc_enable(nand); =20 @@ -1593,14 +1595,17 @@ static int sunxi_nfc_hw_ecc_write_page(struct nand_= chip *nand, oob_off + mtd->writesize, &cur_off, i, page); if (ret) - return ret; + goto out; } =20 if (oob_required || (nand->options & NAND_NEED_SCRAMBLING)) sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi, &cur_off, page); =20 +out: sunxi_nfc_hw_ecc_disable(nand); + if (ret) + return ret; =20 return nand_prog_page_end_op(nand); } @@ -1616,7 +1621,9 @@ static int sunxi_nfc_hw_ecc_write_subpage(struct nand= _chip *nand, struct nand_ecc_ctrl *ecc =3D &nand->ecc; int ret, i, cur_off =3D 0; =20 - nand_prog_page_begin_op(nand, page, 0, NULL, 0); + ret =3D nand_prog_page_begin_op(nand, page, 0, NULL, 0); + if (ret) + return ret; =20 sunxi_nfc_hw_ecc_enable(nand); =20 @@ -1632,10 +1639,13 @@ static int sunxi_nfc_hw_ecc_write_subpage(struct na= nd_chip *nand, oob_off + mtd->writesize, &cur_off, i, page); if (ret) - return ret; + goto out; } =20 +out: sunxi_nfc_hw_ecc_disable(nand); + if (ret) + return ret; =20 return nand_prog_page_end_op(nand); } @@ -1676,7 +1686,12 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct na= nd_chip *nand, reg_index +=3D user_data_sz / 4; } =20 - nand_prog_page_begin_op(nand, page, 0, NULL, 0); + ret =3D nand_prog_page_begin_op(nand, page, 0, NULL, 0); + if (ret) { + sunxi_nfc_dma_op_abort(nfc); + sunxi_nfc_dma_op_cleanup(nfc, DMA_TO_DEVICE, &sg); + return ret; + } =20 sunxi_nfc_hw_ecc_enable(nand); sunxi_nfc_randomizer_config(nand, page, false); --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223473; b=WcZOspvDca1Qq8Ix75+/HDpr9O5UUG0CfS+DVPDFf3tmMjEQkvX5f1d4jFYVLKjghxCS HnAJw8dvcYLivNDO2kjPpVWZCozx+8ChHyDaV1GtBX2gZ0ZaTE5SyxuGPULwFh0El0q1w nDsJGztsnPwEy6P32seNs4hzp1b9Ni/6O5EISVVlg5btP83Jre/zmoKNTcsRdCv5jRlCh m3wX00lCVLciaJMCz2xeBb0ZINZ+h8NMUM/lvcudlw+22m/0TRhR3+UmTNdgCeYm5j4o5 f0tk+ox535wNNIwOwDrlszSj6DeWJ9VYbqrl91COJ8lQLkAnVMhUTwXLtuBpr+yXkQA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223473; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=T83jSZtlzKtrASqdJI86cD7q3EhrQGMc7SvJoDp9Zl0=; b=IOrl7Nge0EVOoZbIqOYd4q5FNDlowbwpUqGBTG67rFi1VYoPkXucTAYTXUAdDsEt55NW vnxq0tv9MgU5iC4FimRbDKyh4imsdyOQKY4BXOxsllXkpO7GYttVSwOtTi824O72Yl2IM MlAF4v6SGM+nLPlFeE6k6YKafctKz/BHooloW1DVIAJOMGJlNgPlz+P9XBRyP4UPeDaiQ 5PhWlZVQtkxRanJIcBF+TFCVT8NmxfsmSE1f5Lrdj4fQwjCQrqnSDbLqRcTEBmt0bDugT DuWpZv0MWtUGWLl3ZyCOVdkHkVuV4h4Uk6z6kyFXadSKs/Odye3NyWKGVz7dBEKpSCQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=J3Fv0Fqc; arc=none smtp.remote-ip=209.85.167.174 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1200760A3802 for ; Sat, 21 Nov 2026 01:11:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1200760A3802 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=J3Fv0Fqc Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-55e02e89f78so587020b6e.0 for ; Fri, 20 Nov 2026 17:11:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223470; x=1795828270; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=T83jSZtlzKtrASqdJI86cD7q3EhrQGMc7SvJoDp9Zl0=; b=J3Fv0Fqc33LZ9TLsmirU2vflkgqL6Or7BuyACOzmZvXLwBLLei/PliL27zMfOLMU1h ggatctoMnjLrKbdKvStEU32PpBMWLx9dr9vljzyNqZ1AByffuQ83Y1TU4hTcgmAdxrol a4aVSQHUV2UZ1yv5vbTys3+bkeFOXuxHZrk7vv9jlzuCYqc8LsfsZVJmlKLglWeILlrg nGjwmNIZ0QFjb1A+mAvvbyehvRKwOmiX7y8mhZS5bQ33K6YI79Mof2QrOYP1zu90s6vH QtGhGQdiaZbTwhZ4RIEvpWbZoTWfhm5EJY5klqa7bVbepvFlOfNQO2iUAdx46HCITujy R1bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223470; x=1795828270; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=T83jSZtlzKtrASqdJI86cD7q3EhrQGMc7SvJoDp9Zl0=; b=yaLU1JDA+sxCSS20H4HO56Po9aVw/a3EWBaMfz3ptCNNuf2waHS5T654lbDiVO6Gsn 4mxnN0BBP1zEp9QdXUYV1vZ+LLwpKqvG87oIIYauQZzUgi3dKDjw0hG49agEk79w8Hea J34S95SNCwidScXxhnXyP4OWXedt+3B/5FZsi8M6AjAn/6XfP2V2QbkjI9yavxRWvdKL wngdBIzGin2RDwBCJrAVLUnjAX2nHt/GwoOlDgzPTCEV6hj98iuCj9DeIyRhhquLrj2J 1PMwKb77h45MyKlnjeVoJgIBQcSQPDnMPVWmPq3zwKWQx8Nk7Lxvp50lu9qsXXwYNF+l XKrQ== X-Forwarded-Encrypted: i=1; AL+hErGiCgkJhc1maS67nz2FioCHa/IVrVln5Sdaqu9pPiFNBy5tfZ7swJ7TQEw2NnovlB/+lPt1XpCFW2IVfTQ=@vger.kernel.org X-Gm-Message-State: APuU4Z/PredNlfDMj6PqEwEGvY45xeqD6q/du4T8yyGWeQ7yXSPz4w7a rV9a81arjx2H/chhwt9IHBRB9q+L001DI4/q2fmco+tY/0kwt6xWb8C2 X-Gm-Gg: AYBFou2BxSwGdDN6BIQwuTLPxTRFbfmFWveKbGmxUu893XNX+hpGwZdlaRnpW3K18/9 IZ8xkYrQyhKrzx3Q+Wuzj3V1Oo6sIq1aIoMpVx5Ny4fkp+gLDtrZ9x3WLcImfE6NPcA0EVlsY2z f3FCwFqhAnf7DiqwcgbWH2oTi1IxmE50h6u/6mpiMXqX56+pQWsPhSa2i4VC4ljjuu+Vn6iRFUo RNRSuD8gpjaMUCKjeSeDn97N+XcJtnNEeafR5RbtAoRTIdYSjkVmjLxcrQ+Va222xcmnait8l3a N9t9BZyNdjWpwssgBgoFkd4N1sWFf7SsRjkeOidxiap+v/n9+NjJhIdA14v8IRCiQOAjCHBgXHN zMhrBVL9MAGeGq3S78bvrKZXw6nDHBMo9FeJfzoH0mWQIX3dz/tCSQzACyFyfPsQARq8ntGBAUv 74/BVzQIoBcxzY8J7WspxzOW31JjycsdKMF4XnanyeY3M4oxR8ak51TETUceO1vJbPBZ/ruh5l4 Twn4TW8ktxmyQwejwAyMV87QdQ72VhrJb0Wac7w3TP+dkxphjicfHIA/iXOlHlDWt0oCnEo++kp ITTOmcqJKi+m3DYEF7c2W8bn5TL95C9yQafr4k2P3mcZqgOOkFJBsVv+b0uth4mNbu71PgTTHyH kU1wNJxPywVSi9ACi1A2Bzm+2HLxqaGP8FSnmecBHGtqDX8WY9+ye2wMA2oGkfckkRv8SCVyGoS +CZVvJznkPnBn4H+qXzlm0+HTfGv62pvKLL5cMmwRbilwf8ZbIMdBn X-Received: by 2002:a05:6808:19a7:b0:55c:844:98b3 with SMTP id 5614622812f47-57a0bb53de5mr6320056b6e.50.1795223469671; Fri, 20 Nov 2026 17:11:09 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:09 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:33 -0700 Subject: [PATCH v11 10/26] mtd: rawnand: sunxi: select the pattern ID for the current ECC step X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-10-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev A DMA read with scrambling enabled can report success but return zeros for an all-ones ECC step, or all ones for an all-zero step. Requested OOB can also be filled with the wrong pattern. The controller reports a pattern-found bit and a pattern-ID bit for each hardware slot. The driver tests the current slot's pattern-found bit but uses slot zero's ID to choose between zero and 0xff. PIO only uses slot zero. DMA can report several slots in one transfer, and their patterns need not match. Use the pattern-ID bit for the same slot as the pattern-found bit. Fixes: 614049a8d904 ("mtd: nand: sunxi: add support for DMA assisted operat= ions") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 76f60fde7a86..43c0796d953a 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1086,7 +1086,7 @@ static int sunxi_nfc_hw_ecc_correct(struct nand_chip = *nand, u8 *data, u8 *oob, if (pattern_found & BIT(step)) { u8 pattern; =20 - if (unlikely(!(readl(nfc->regs + NFC_REG_PAT_ID(nfc)) & 0x1))) { + if (unlikely(!(readl(nfc->regs + NFC_REG_PAT_ID(nfc)) & BIT(step)))) { pattern =3D 0x0; } else { pattern =3D 0xff; --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223481; b=2q/5avl2rMkX7TPQiSQgLgRSRYlcK01/LNpes0x9iJX/yyMRgSTIs5obDnKPe/Nk7zTU k+PoQ3mlM3oeRejw82DYbHYO53df5MVzxYwdswhG6nBy9Ip1G0iBvVXtVlHiF5ZunVjCH H6VfXgm5T+IiQa2O3CbTXhadtyCAcxY0kMfgT/rXuEuOltsisbgBwRsLCVGz2BWpT/2zY eNLCXgQdjYxAMdXMAb00SwHhdBKeqhjUY9iHGgnyqmsDPYiOycLtiqZafuNHkxvKviTyd aI2hWQRVWkWqWzRmGaS9I6fxCxrma1G1sHhK3miI3l5rUtirNznTu18f2bKXrQlccMw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223481; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=u89IqnoAKi5kjnWBIZSz6wZn1oqd6Ypo53SPsotyUk8=; b=BNozRoOBtv/3gqjRXpPDvoVSxWt9XVJN7YevlGUnCxnZ4xFunxrVNVbEaDrT4g6TrmX0 92dCVgkc1zOrmTwYa1C8Qz/iv95UGBZiXSgHXOWFDpMgI9DNBjryFyZmk/yfshbblCG7w wjIg2mT9OdODOaVyFiTkK2ob4iSVKe41KDTayOTaB4gllxTlMkI78/jUNF+Umq3a0p6Zp WHqWMDSP6i1mzx08epWGIs9t1RNw6se8jNed/E8bCvMza2o9mF/S+x41xUNDabbjmAd2R XXwtI+gleFaVN7GDsqlmKZNNdKZp4ee7CRoTcEW7ewsX9BpBkrO3pH+4Wofrf4yQfDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=lqhDf7C9; arc=none smtp.remote-ip=209.85.160.51 Received: from mail-oa1-f51.google.com (mail-oa1-f51.google.com [209.85.160.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 372E260A3835 for ; Sat, 21 Nov 2026 01:11:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 372E260A3835 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=lqhDf7C9 Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-483a66818edso872851fac.0 for ; Fri, 20 Nov 2026 17:11:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223471; x=1795828271; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=u89IqnoAKi5kjnWBIZSz6wZn1oqd6Ypo53SPsotyUk8=; b=lqhDf7C9hkmi61yRGPwOVZuyBci1NjYmFnJzMTUZWv1M9o/P6oHtODRYky3eaLiNkH iNo4KaQU90sIJF1K7dQIxkFH9eyVVctV7vF2i2FSzy38cInHMvjhV7b5prr4Js1rUQev GXUZL3KBEdNulOdic15NndBbLGqPjhoxbu5a5brHeNdzMaszYP5H5RaHSs3dUwJIrNvl OHRGmcwW/kxNJG02dgsCWMtAeARzWdvr4k5MvgRd+dyH8SshVZDNYbVpIn+WpIUtiXED 3KIsM6i+ZCY+Feybdl1wi1QLr//SFQCCmifKiR5RZlYkLDKEwZXtTDvn8SXtOSJuAk/b ZEMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223471; x=1795828271; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=u89IqnoAKi5kjnWBIZSz6wZn1oqd6Ypo53SPsotyUk8=; b=eWOB/VnpywHr/2mXUnx4iVT3q+hEE4sNVjdySdUQMvjd4twT5fjCK1W+8stCqNP4r8 BURRA31iyFfzT5zGq9FfuG2Ocx5saPia86+paf2F/oUAfU8ENEJ2PBspkWRuwLqPMYbt 7oeGeX0s7jpX1JlNUjWW2SpTtvsTmdXx5BpSZgWv8N32HGbD47hVgBQpfY1vDMJisStN I+8L3wxjzlxZxsyMXHsBiopkpv1xj6NbB0iviLR5JPC4U0s0fAOcNxLrL/pOIHTtaM/+ 4ILWFHjproxsGNOxPRN2PvuZKJmr2RD+iALRdWcAfHWFEZmEXA6cJOD2KmxrU9aEYJtB wy/g== X-Forwarded-Encrypted: i=1; AL+hErHl+yLRJAqyujooD/TwBZtm2CjAHurwLotB19VnmHxAf2B/AP/Woogc8ifwp4TH7xEmsm3qyvLEeCt/OE4=@vger.kernel.org X-Gm-Message-State: APuU4Z+ZluOxIadY4EA2kGCZEl0TTbV+5gXya9yzkWX0FT07aSfgMadg kRPs0L2hP4LO7u2CCKU5C/ZVLmpB8luyzwqPRlYvCsuBhzDBarkLE+69 X-Gm-Gg: AYBFou05OeJK3IsJhs6joSwHGfoYtAbockoG1HPF2t1J4tOUXfpELTnO5ymnRdCBBz3 PRIZj/mBBT6Afi3X5DFObZ+CL8WHBKQirBsreXJEZgmlw9T3lOPdkQyk0dVlRE/NFf+ow61W3WG vgvzUZMts6bXqSUuDhT1OCRv/4NEBt0M8te4nNgHolUJKr2wHpsTsbjL/5l/6AWTTfmsaPePg6z rrRmvliPGk++s/+tl0qhmHfHRYayKOPeByejLCHiLF9s1SpMYyJKQC6H7lrBDqAz9jhHlBhU1w/ 3TwlX+b0bMfSFXKithRDaZ/AB6UwSNaNBqO0i4V38OjznXlGIfu86p12ipsyXTrrnNgVs8GwiSZ SVWuVHvMJIGvScW+WER+6JCw/DSf3LaKSeaOizzfPJJXDZQ++NMXDVcTpPDkcyzqLaMA4AfTpmo 0nqKddxWEIDArVTv9EHikYsKMStIRy11B/y5PmsxHar+hMyH5kymTfi8SBonnO8ZhgYIDQ5Gz7e orDw+WkxQIXnBZaHJh7x2pHB+aBLqr05EDqAuMpKSxMyBR7LOhwN2KxW/0kxqHV7VRzYxmPDicW 7Zpfi52JRZ7FSQURcupKGGVX14LDaIzUmsJqniFOn7LkMUrltdubcn0xUAJguFh96rFsHjnr8Kz ys9joxLSxeq5LP69KGqYk6wah9EZs+YTG5AFLT6JVYJEkFTsa1x+hrZAZmfsZayV1ae7toIQzTf KIYUCmWpNAiQu6OHSo9dpa3aqeZLoVxV26PgOiOeTwprGi9n8WBI1dQyo8Oq90Yn214wPKOYbIt A== X-Received: by 2002:a05:6808:244e:b0:574:6f37:671d with SMTP id 5614622812f47-57a056c81c5mr5959981b6e.5.1795223471048; Fri, 20 Nov 2026 17:11:11 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:10 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:34 -0700 Subject: [PATCH v11 11/26] mtd: rawnand: sunxi: preserve synthesized zero-pattern data and OOB X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-11-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org, Sashiko X-Mailer: b4 0.17-dev With scrambling enabled, a PIO read can report success for a physical all-zero chunk but return descrambled SRAM data instead of zeros. Both PIO and DMA can also reload the requested OOB after filling it with the zero pattern. The ECC helper fills the buffers for either hardware-detected pattern, but the caller skips normal buffer retrieval only for an all-ones chunk, the pattern it treats as erased. Skip normal buffer retrieval for either pattern when there is no ECC error. Only an all-ones chunk selects a raw read for trailing OOB; a later all-zero chunk must not undo that choice. Keep the physical reread and erased-chunk check for ECC errors. Fixes: cc6822fb756b ("mtd: nand: sunxi: move some ECC related operations to= their own functions") Reported-by: Sashiko Closes: https://lore.kernel.org/r/sashiko-outbox-172123@kernel.org Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 43c0796d953a..538ffcc79108 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1226,8 +1226,9 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip = *nand, continue; } =20 - if (erased) { - read->has_erased_chunk =3D true; + /* Both patterns are already filled; only all-ones is erased. */ + if (pattern_found & BIT(i)) { + read->has_erased_chunk |=3D erased; continue; } =20 --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223477; b=GwqcSXM02/yDUTYyTVTUq1dmhATTziXApiD6K5qBPfDXZHrLnds+6OpLz4p5P5FTSnnT OXn17eF+OoEVfx+O6OLBKdB9F/vc7S4VXUytm+pkD7yR/hgMr2oOEKRgCpMjLywsi2jlR QvGURlCPxk/gWCHBPUNn2QqFQIrruv1LA7GoHa+Hg8DBUhTCtEcx+2K88aKqGX+jptrba iKqU4Yc9NqbH8mpUxzHfktnMnAfSih524jb7Kswe1np9gRzQTCbtuy4G6t0UwHG771Zez MraOHZ43xda0/xGYeJQr4Pqfydu/i3XUiQeuB5ZVSoVtdqoxeFv4ZKuMOoz/jSFC6Jw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223477; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=25Y0T/EWWqPPUndC1dVyA3/WPrprnkSUm6qbYkkV3TY=; b=Ra4IHVSED479dbQmNOCP6vSRKqiqbmG44uEfrxDZm9usRNxfDzK0liDlT8nIDfM3ui8e Aj1vGfru/nuGDnVW6owtkNF3ZetOfJCc8VeDGKKGN0s/gBMf4TbE2RQBot4rJWBcACIbB gI2kdc2y6Y5MloJQ3SVzOJdNbzhjqkAnPjsfyqpNHUOGb3VT+KT4EAsDw7UT2vxdxuCG+ qb5qNfB4d9vcjiF2K7FNnNrzHvksq3JwxT8DHXlukOAATL8GytMcyU7b7HXNMhSf17NuG ZoKUJZZ6suQyP/iuo/tD10WvYgmcNdQ2t+7L1InTd6eFiSRdZRqS3kcoiQVcGullVLA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=tbBMK6hs; arc=none smtp.remote-ip=209.85.210.47 Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD609606A6AC for ; Sat, 21 Nov 2026 01:11:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AD609606A6AC Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=tbBMK6hs Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-8629c7cc36eso935517a34.3 for ; Fri, 20 Nov 2026 17:11:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223473; x=1795828273; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=25Y0T/EWWqPPUndC1dVyA3/WPrprnkSUm6qbYkkV3TY=; b=tbBMK6hsykZzOn8nGxxts1/4QvCTntAVabwomZjvuvTmSDoqSqWZB2D2ga/HSmhUkx kTiQp5NPbRHGv1xLK4G5g8TiqECnDYyFmq06ptwcxDgHWw6guKgw5GZhjEg2ZzIWDdeX ijzcujcTNakTIrG186wpQoJpjnRGRewI/YtJow4o4mF1g8RFYMrSP2wOllkuPfJACl4r Fk6IqfCThg3h1aOcNyLEckkKWFAjPdqgToyj3RO+STw8IXG5qWj7pW2obq6LB9j2EGNE CmM3A2ARROcnoCJjKURiyXCON+UXbMYMX2iD0xFJahr2NCkhMHmE55vTA1Y5iddz/W0l zIQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223473; x=1795828273; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=25Y0T/EWWqPPUndC1dVyA3/WPrprnkSUm6qbYkkV3TY=; b=NGv3EGbs9aMWIJggOZIBaa7q1US9RHoHOvekXMIk8c/LErqZSJ+TtKA6Dz3YyX1TKd RRGGhvyIpktnfh7z7VQ7G1bk5QiOITCv1rZVpgClbp++WM33K8HxbYVTqsXUTojOzUZU qeT99sOE59O2zVHXrLjUp7v55yDySokjCsHJB0P1UT3hdvVo2ByNKdGrEx2aUFMrPP1B ocaa6POt3caPjO/7yq24vvUPxSoX0QEWh1LOSAwEOEWuJCOc7N6FWoyf0Xj56bClIwQy 1gAxoYLfaV7woCgBwyQEgPvoNuJBaWYprHI8klF1SwBZYkhknWacXDK6QjZnsZkLy+xy gEdQ== X-Forwarded-Encrypted: i=1; AL+hErFnp8BpUWOqjnagwvZ879GTrwk0ZTFkwOslMhMjRonQDdQRLaw38uMGtyYxXC6raORvING253YOBsKXrpU=@vger.kernel.org X-Gm-Message-State: APuU4Z+i77csg+UheoqLsH/uI2nbMv9oHGyoCa+vmT5LkjpLzV8zVPXw Fl2QgtA+YwOlLoLba+65yqfzN7xSqmeEilP6UPnMR0oNg4ggZ7lHnJhl X-Gm-Gg: AZFdTZfh7AL9oCwfCWg7qblN1+589/yRYiZLLqwcqWp1zjX6UWQ2iNHrcGmFRWc4qAQ jmPaZJYsGGizD1Ae2AjJwv300a1hvllEwdHdAa//aaMzBuvihtvxD4378BjkZv/bYPEQzzLQnCX fRfHkUpM8bzqnjFSHngjk9Tsalh5wTmNEA21UOf83AkeicjitVVmHC17kmCaDvvc+9u6KFXutsK upPnQnSKhJaBK657UedbK7sXSZ9yDR62Qab9UG2DQ1LFNQlpQEZaAIFbhttTmMWXms+2NM/G47Y 9jwXOjivS+xkRykT0FJJmCOCVtdxD8zvGten9h4jEFlh/MePXBBjVfrVwblvHM4ZNrchqiNteuA hrCxNPVG0Aje1a0SqRqT3ghP2bThG4coJwThl22H75BIvVGmNMV6HxZpJrNOEFEhTPO7r+HTaQY lWJTH/QCx8B+U/ABa2yYbp0Fv2rCuTvwDh/F6UxtQablx6EohLVtmsnSAz3HppZy1hXtXmjq8vI CfDcHW1+NrTqURe+GqbwPTuKt/55qgkCtxXsVpv5+4TQ6/fTvzSUkIvFMlqd/eNLlADAauqH8Py Ak4kqRTEpUYCW0oyBgmib294LWxhJdjwpvRBAAz2CGc/GoYDjFWVq7tuCrsuAftDYIMqIjXMikn PAAsswfBWLrq33n+4YHm/UlJ8p7UnGftGxT4lWp8pwCrQo+ykR45mkSqZ4O9tUORqSTTuCjEV2S 2ldeTXPBG8KjIZbHRYLCTvLJWdqeK5WnSaK3mGoZ91SyWEqJn66mqz X-Received: by 2002:a05:6808:1986:b0:572:72d4:9ac9 with SMTP id 5614622812f47-57a09e0d7c4mr6351251b6e.27.1795223472625; Fri, 20 Nov 2026 17:11:12 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:12 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:35 -0700 Subject: [PATCH v11 12/26] mtd: rawnand: sunxi: handle ECC results in the batch reader X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-12-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev The batch reader must know whether the corrected bytes are ready to use, need to be filled with a hardware-detected pattern, or need a raw reread to distinguish an erased chunk from an uncorrectable one. The correction helper returns zero both for a pattern and for data with no bitflips, so its caller tests the pattern bit a second time to avoid overwriting synthesized bytes. Handle the three outcomes in the batch reader. When a slot reports both an ECC error and a pattern, keep the existing error-first ordering. Preserve the data for the raw erased-chunk check and run that check after collecting corrected OOB for the batch. For a pattern without an error, fill the applicable buffers once; only an all-ones pattern marks the chunk erased. Read the correction count only for an ordinary step. Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 70 ++++++++++++-----------------------= ---- 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 538ffcc79108..e76f7cc67081 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1070,41 +1070,12 @@ struct sunxi_nfc_ecc_read { bool has_erased_chunk; }; =20 -static int sunxi_nfc_hw_ecc_correct(struct nand_chip *nand, u8 *data, u8 *= oob, - int step, u32 status, u32 pattern_found, - unsigned int user_data_sz, bool *erased) +static unsigned int sunxi_nfc_hw_ecc_read_count(struct nand_chip *nand, in= t slot) { struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); - struct nand_ecc_ctrl *ecc =3D &nand->ecc; - u32 tmp; - - *erased =3D false; - - if (status & NFC_ECC_ERR(step)) - return -EBADMSG; - - if (pattern_found & BIT(step)) { - u8 pattern; - - if (unlikely(!(readl(nfc->regs + NFC_REG_PAT_ID(nfc)) & BIT(step)))) { - pattern =3D 0x0; - } else { - pattern =3D 0xff; - *erased =3D true; - } + u32 count =3D readl(nfc->regs + NFC_REG_ECC_ERR_CNT(nfc, slot)); =20 - if (data) - memset(data, pattern, ecc->size); - - if (oob) - memset(oob, pattern, ecc->bytes + user_data_sz); - - return 0; - } - - tmp =3D readl(nfc->regs + NFC_REG_ECC_ERR_CNT(nfc, step)); - - return NFC_ECC_ERR_CNT(step, tmp); + return NFC_ECC_ERR_CNT(slot, count); } =20 /* @@ -1203,35 +1174,38 @@ static int sunxi_nfc_oob_read_batch(struct nand_chi= p *nand, struct nand_ecc_ctrl *ecc =3D &nand->ecc; bool randomized =3D nand->options & NAND_NEED_SCRAMBLING; unsigned int reg_index =3D 0, user_data_sz; - int i, ret; + int slot, ret; =20 - for (i =3D 0; i < nsteps; i++, reg_index +=3D user_data_sz / 4) { - int step =3D first_step + i; + for (slot =3D 0; slot < nsteps; slot++, reg_index +=3D user_data_sz / 4) { + int step =3D first_step + slot; int oob_off =3D sunxi_get_oob_offset(sunxi_nand, ecc, step); u8 *data =3D read->buf + step * ecc->size; u8 *oob =3D nand->oob_poi + oob_off; - bool erased; int bitflips; =20 user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, step); - bitflips =3D sunxi_nfc_hw_ecc_correct(nand, - !read->dma || randomized ? data : NULL, - read->oob_required ? oob : NULL, - i, status, pattern_found, - user_data_sz, &erased); - if (bitflips < 0) { + if (status & NFC_ECC_ERR(slot)) { /* Preserve PIO data before the raw erased-page check. */ if (!read->dma && !randomized) memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, ecc->size); continue; } =20 - /* Both patterns are already filled; only all-ones is erased. */ - if (pattern_found & BIT(i)) { - read->has_erased_chunk |=3D erased; + if (pattern_found & BIT(slot)) { + u32 pattern_id =3D readl(nfc->regs + NFC_REG_PAT_ID(nfc)); + u8 pattern =3D pattern_id & BIT(slot) ? 0xff : 0; + + if (!read->dma || randomized) + memset(data, pattern, ecc->size); + if (read->oob_required) + memset(oob, pattern, ecc->bytes + user_data_sz); + if (pattern =3D=3D 0xff) + read->has_erased_chunk =3D true; continue; } =20 + bitflips =3D sunxi_nfc_hw_ecc_read_count(nand, slot); + if (!read->dma) memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, ecc->size); =20 @@ -1260,10 +1234,10 @@ static int sunxi_nfc_oob_read_batch(struct nand_chi= p *nand, return 0; =20 /* Finish consuming the batch's corrected OOB before raw error rereads. */ - for (i =3D 0; i < nsteps; i++) { - int step =3D first_step + i; + for (slot =3D 0; slot < nsteps; slot++) { + int step =3D first_step + slot; =20 - if (!(status & NFC_ECC_ERR(i))) + if (!(status & NFC_ECC_ERR(slot))) continue; =20 ret =3D sunxi_nfc_hw_ecc_read_error(nand, read, step); --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223480; b=mkPyk6c95fEwd0JyxWfKg2iGEk+KXD/+RZ5HLre6DXp0Urnkpm3LiLj+56D5OaEnwg2M EOYKuV59hsY2QPPQh0WQ48wb/6fj3gL3wHsu6Yxtqp+44Ic8AbbqrMu4S5yvGAtUcs0qV 37N5DP4rsPj+lFZbmOShtxXs4xgXivckPtdAVVqWJzvzAo7e0de8uGvcTx1jHpqQBCH4v 2kZBMG7c/bBvTRp1HxnNN/l+WniL8ty/HdAhLJ9WXWwxkW3TMuysCUjPLpQzMyLb8jkuu KESpX0csuuOqRgnMS8eOLfJG0MDsoeOZDddSJ1CyzwVj6EjW07gJYBXXingpmwfvMXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223480; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=V/ZOEZdBIX9Ht5ZtaAIcNRRvXcoTuAbgmishigtjssc=; b=f/6QDqSuP3JuTgMWKYcG2wFMYX37QvEXNI8HXaL4iI5Zm7qPA9jrYKW+Boy4Sdoo7IFV ujYMLoICN3wxmZ+Y9tvvvXbhVu/DQ6dSaXa5H6cDhDVV9PlgJXMScaQRPwYYGl9DYS0BI 5yXBxkugS5TEDcwYDWnynursJwoDIXsmm40z9uoIT9eva9mAnhAzPstAxWYkn/qrvawXS WVFfLPhIa0CBSyVUyCJBct2gBSPwXtw+J6T8g7JPtPk8dflOd/LJW6cs6rqCZKyZQJe9G 3jKK0h/unEkRtb9Mwp3+AuWNKvIQtx81kHoTMij//PG4uKQBiDMY4VYPcqIBE41dZfw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qqXc0xhq; arc=none smtp.remote-ip=209.85.167.172 Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EDDE60A261B for ; Sat, 21 Nov 2026 01:11:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5EDDE60A261B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qqXc0xhq Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-53c156ba662so884517b6e.1 for ; Fri, 20 Nov 2026 17:11:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223474; x=1795828274; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=V/ZOEZdBIX9Ht5ZtaAIcNRRvXcoTuAbgmishigtjssc=; b=qqXc0xhqFvOrz+emUqcN50LcyxA/hdj19c9/d3ED+FnXynpC2MziW3rvSCPpPSdxHz jVNAIn3jfcWZl3roiF1TgWJseGquJQX3I5f870z6DJt41sX3SQMa8uysQxD1SQFsEqq4 DGwv2MqjjNqEgchHT5ArCT8pE/WFrf+grTxlSxcBnwAe4mcyB0ZXs+MrqITvH/oVHrl/ 0Uh2+kO7Urn4H1AcQ0Zp4cmE9CDg0T7bXoLEgSGjUhSD5lnZ1/z8AWX9P4NEIuFiYKfQ 9JSgMvgICxYJSmnrmxAQtfWYYAonBNe24ynX/Ow8Q3rVplLCDwUVvmfLc9AuCHskBDUF idOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223474; x=1795828274; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=V/ZOEZdBIX9Ht5ZtaAIcNRRvXcoTuAbgmishigtjssc=; b=fGltLNz8TFJnH5DHw+cj/2roAjXMuFPN19YlcJftlQaXv2kIQZwzjE8yIg2l6ZkM1q k6UmoRcGyjw/tStLhLA3HQ+S/2eV2KcvcUurmC2L2hpYPL4rWiTKbPs7nluWbYs2KQxu ZyejFcLjZtummzyPNjjaNTVJLmRm8Z23UcQrsqZx+ZubXnAdBjT4ejFdwkcDt1M6vyu/ mIbC74S52bcz6/MIBSTNARnnLFrVqrjeHUKRMjXDAAiKaB+2mmxOa+rup1iZ73f952Ry 5AqhrjXReNg3ME68471mo2Ij11g4KnVQl/+wfZoRtt0bUHO6c+gHUTShDIYEKOhrKIRU gcdA== X-Forwarded-Encrypted: i=1; AL+hErGYyUzXOIMDICYDB2DZpmwB2C1laCl8m66xMwyaorvBBLJyFcbor6DZssDH3Naxs/3K5d8bjpxzs6qDOVw=@vger.kernel.org X-Gm-Message-State: APuU4Z8f0Y/m9TcTHkWWAHpwOuOCw4TNN6DXSvM/WKeJDiv8RNCPs0sB hhBSitDh4Wsw4O8a8KWYC1Sbt6TL0W2L/aVKoG02X1b71i6gwcxfFcL6 X-Gm-Gg: AYBFou0iygA9rJfr9YR4GBebqZDgsmIbc/7c/VTY2jeT1evkjxbKPchFwJv/LgIHvlI 1Q4bAaOetSHzEV2+1b/pZGKmIz85TwDWn+s2zUFo+Qrsr2lNxX5NNxtcO/MXMdGPV8uIv8LxNvS rlluLHqco3HwU/z33y5C6x2pzFLGxtcJN0OuvDCWetKNQ6eKSzQ2p8ZCgYLpLqP03/u0TQp11aI DMZCrFcApHjXyJ8E5Al+P3XxT+w+BnLgVt2DukT+mFAkmXQY7QCLt6QU0LbzWjJ6wL/HSiFLdG/ klHIH4K7WfHFaXivSZ6yNPbM8fhTLv7Y0QnS1+UEhyFROvbleeRf0NfsyNEoeXR1vgZsPDISZcQ 3VyD52NpHZpkenNaOZWTn7Jj036osySAQoO1pFRkbYn0JtYgr4+uhP+zKSPNn9QhVFeHG0YDcrL +UZawed7DWGomMUe64a32znZP5I5tRI9RIqUHi/FxDM1mSRc9m/zr5Fvo7bhQQzJ0RzEg1rbeTc KBYFHER24XPPA2xIU1ukZcK0MkmXwmFURD+q8VhW7GnaZZ30f/gUJc3BrE61fjJDadSXaWuTC7j GQNf5aAZ/1F6T+5ZxzGdpVEnP/ULyXEJsPJu7W8eGfKCKLGFiTPOE/zb/CSx4eO1mSXSVWsNg5a CxVl8n1TeZ4ALR2Tr4as+HJ5V2noA8RWx4bsTUsR0WHX+e7BipeA8X6iBAXB0+hIiMwEhsfqmpa Ngj0NHintI8GcEaaVQDJ0fPnrougOTEE4NAOFATWHSvZ/C3wM08dn5 X-Received: by 2002:a05:6808:130a:b0:573:7a6b:f32c with SMTP id 5614622812f47-57a0c4b923bmr5275123b6e.50.1795223474187; Fri, 20 Nov 2026 17:11:14 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:13 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:36 -0700 Subject: [PATCH v11 13/26] mtd: rawnand: sunxi: propagate buffer and column transfer errors X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-13-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev A NAND read can report success with missing bytes or bytes from the wrong column. A write can send PAGEPROG after transferring only part of the intended data. The SRAM transfer helpers stop on a FIFO or completion timeout but return no status, and the hardware-ECC paths ignore some column-change errors, including when fetching OOB after DMA. Return the transfer status through the randomizer and OOB helpers to the page callbacks. A read with a NULL destination still fills controller SRAM for ECC and must report errors even though it does not copy to memory. Disable the randomizer after either transfer outcome, and use the page callbacks' error exits to disable ECC and skip program-end. Update a tracked OOB column only after the requested transfer succeeds. Keep transport status separate from the maximum corrected-bit count: zero from a successful OOB read must not erase a positive correction result. If an OOB read after DMA fails, restore that attempt's corrected/failed counters before the caller retries the page in PIO. Compare the tracked write column against the absolute column of the OOB tail. Otherwise a small-page PIO write that has already reached the right column would now fail on an unnecessary change-column command. Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 175 +++++++++++++++++++++++++---------= ---- 1 file changed, 117 insertions(+), 58 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index e76f7cc67081..712648864407 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -663,7 +663,7 @@ static int sunxi_nfc_buf_chunk_size(struct sunxi_nfc *n= fc, int len) return min(len, nfc->caps->sram_size); } =20 -static void sunxi_nfc_read_buf(struct nand_chip *nand, uint8_t *buf, int l= en) +static int sunxi_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len) { struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct sunxi_nfc *nfc =3D to_sunxi_nfc(sunxi_nand->nand.controller); @@ -679,7 +679,7 @@ static void sunxi_nfc_read_buf(struct nand_chip *nand, = uint8_t *buf, int len) =20 ret =3D sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) - break; + return ret; =20 writel(cnt, nfc->regs + NFC_REG_CNT); tmp =3D NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD; @@ -691,17 +691,19 @@ static void sunxi_nfc_read_buf(struct nand_chip *nand= , uint8_t *buf, int len) =20 ret =3D sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, poll, 0); if (ret) - break; + return ret; =20 if (buf) memcpy_fromio(buf + offs, nfc->regs + NFC_RAM0_BASE, cnt); offs +=3D cnt; } + + return 0; } =20 -static void sunxi_nfc_write_buf(struct nand_chip *nand, const uint8_t *buf, - int len) +static int sunxi_nfc_write_buf(struct nand_chip *nand, const u8 *buf, + int len) { struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct sunxi_nfc *nfc =3D to_sunxi_nfc(sunxi_nand->nand.controller); @@ -717,7 +719,7 @@ static void sunxi_nfc_write_buf(struct nand_chip *nand,= const uint8_t *buf, =20 ret =3D sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) - break; + return ret; =20 writel(cnt, nfc->regs + NFC_REG_CNT); memcpy_toio(nfc->regs + NFC_RAM0_BASE, buf + offs, cnt); @@ -731,10 +733,12 @@ static void sunxi_nfc_write_buf(struct nand_chip *nan= d, const uint8_t *buf, =20 ret =3D sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, poll, 0); if (ret) - break; + return ret; =20 offs +=3D cnt; } + + return 0; } =20 /* These seed values have been extracted from Allwinner's BSP */ @@ -884,23 +888,31 @@ static void sunxi_nfc_randomize_bbm(struct nand_chip = *nand, int page, u8 *bbm) bbm[1] ^=3D sunxi_nfc_randomizer_step(state, 8); } =20 -static void sunxi_nfc_randomizer_write_buf(struct nand_chip *nand, - const uint8_t *buf, int len, - bool ecc, int page) +static int sunxi_nfc_randomizer_write_buf(struct nand_chip *nand, + const u8 *buf, int len, + bool ecc, int page) { + int ret; + sunxi_nfc_randomizer_config(nand, page, ecc); sunxi_nfc_randomizer_enable(nand); - sunxi_nfc_write_buf(nand, buf, len); + ret =3D sunxi_nfc_write_buf(nand, buf, len); sunxi_nfc_randomizer_disable(nand); + + return ret; } =20 -static void sunxi_nfc_randomizer_read_buf(struct nand_chip *nand, uint8_t = *buf, - int len, bool ecc, int page) +static int sunxi_nfc_randomizer_read_buf(struct nand_chip *nand, u8 *buf, + int len, bool ecc, int page) { + int ret; + sunxi_nfc_randomizer_config(nand, page, ecc); sunxi_nfc_randomizer_enable(nand); - sunxi_nfc_read_buf(nand, buf, len); + ret =3D sunxi_nfc_read_buf(nand, buf, len); sunxi_nfc_randomizer_disable(nand); + + return ret; } =20 static void sunxi_nfc_hw_ecc_enable(struct nand_chip *nand) @@ -1135,31 +1147,39 @@ static int sunxi_nfc_hw_ecc_read_error(struct nand_= chip *nand, return 0; } =20 -static void sunxi_nfc_hw_ecc_read_extra_oob(struct nand_chip *nand, - u8 *oob, int *cur_off, - bool randomize, int page) +static int sunxi_nfc_hw_ecc_read_extra_oob(struct nand_chip *nand, + u8 *oob, int *cur_off, + bool randomize, int page) { struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct mtd_info *mtd =3D nand_to_mtd(nand); struct nand_ecc_ctrl *ecc =3D &nand->ecc; int offset =3D sunxi_get_oob_offset(sunxi_nand, ecc, ecc->steps); int len =3D mtd->oobsize - offset; + int ret; =20 if (len <=3D 0) - return; + return 0; =20 - if (!cur_off || *cur_off !=3D (offset + mtd->writesize)) - sunxi_nfc_read_column(nand, page, mtd->writesize + offset, - NULL, 0); + if (!cur_off || *cur_off !=3D (offset + mtd->writesize)) { + ret =3D sunxi_nfc_read_column(nand, page, mtd->writesize + offset, + NULL, 0); + if (ret) + return ret; + } =20 if (!randomize) - sunxi_nfc_read_buf(nand, oob + offset, len); + ret =3D sunxi_nfc_read_buf(nand, oob + offset, len); else - sunxi_nfc_randomizer_read_buf(nand, oob + offset, len, - false, page); + ret =3D sunxi_nfc_randomizer_read_buf(nand, oob + offset, len, + false, page); + if (ret) + return ret; =20 if (cur_off) *cur_off =3D mtd->oobsize + mtd->writesize; + + return 0; } =20 /* Interpret one PIO step or a completed DMA batch before reusing its stat= us. */ @@ -1212,15 +1232,22 @@ static int sunxi_nfc_oob_read_batch(struct nand_chi= p *nand, if (read->oob_required) { /* Keep the existing PIO and DMA representations of parity. */ if (read->dma) { - sunxi_nfc_read_column(nand, read->page, - mtd->writesize + oob_off, - oob, ecc->bytes + user_data_sz); + ret =3D sunxi_nfc_read_column(nand, read->page, + mtd->writesize + oob_off, + oob, ecc->bytes + user_data_sz); + if (ret) + return ret; } else { - sunxi_nfc_read_column(nand, read->page, - mtd->writesize + oob_off, NULL, 0); - sunxi_nfc_randomizer_read_buf(nand, oob, - ecc->bytes + user_data_sz, - true, read->page); + ret =3D sunxi_nfc_read_column(nand, read->page, + mtd->writesize + oob_off, NULL, 0); + if (ret) + return ret; + + ret =3D sunxi_nfc_randomizer_read_buf(nand, oob, + ecc->bytes + user_data_sz, + true, read->page); + if (ret) + return ret; } =20 sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, reg_index, !step, @@ -1251,9 +1278,14 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip= *nand, static int sunxi_nfc_oob_finish_read(struct nand_chip *nand, struct sunxi_nfc_ecc_read *read, int *cur_off) { - if (read->oob_required) - sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi, cur_off, - !read->has_erased_chunk, read->page); + int ret; + + if (read->oob_required) { + ret =3D sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi, cur_off, + !read->has_erased_chunk, read->page); + if (ret) + return ret; + } =20 return read->max_bitflips; } @@ -1272,13 +1304,21 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_= chip *nand, u32 pattern_found; int ret; =20 - if (*cur_off !=3D data_off) - sunxi_nfc_read_column(nand, page, data_off, NULL, 0); + if (*cur_off !=3D data_off) { + ret =3D sunxi_nfc_read_column(nand, page, data_off, NULL, 0); + if (ret) + return ret; + } =20 - sunxi_nfc_randomizer_read_buf(nand, NULL, ecc->size, false, page); + ret =3D sunxi_nfc_randomizer_read_buf(nand, NULL, ecc->size, false, page); + if (ret) + return ret; =20 - if (data_off + ecc->size !=3D oob_off) - sunxi_nfc_read_column(nand, page, oob_off, NULL, 0); + if (data_off + ecc->size !=3D oob_off) { + ret =3D sunxi_nfc_read_column(nand, page, oob_off, NULL, 0); + if (ret) + return ret; + } =20 ret =3D sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) @@ -1401,13 +1441,21 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct nand= _chip *nand, /* From the controller point of view, we are at step 0 */ const int nfc_step =3D 0; =20 - if (data_off !=3D *cur_off) - nand_change_write_column_op(nand, data_off, NULL, 0, false); + if (data_off !=3D *cur_off) { + ret =3D nand_change_write_column_op(nand, data_off, NULL, 0, false); + if (ret) + return ret; + } =20 - sunxi_nfc_randomizer_write_buf(nand, data, ecc->size, false, page); + ret =3D sunxi_nfc_randomizer_write_buf(nand, data, ecc->size, false, page= ); + if (ret) + return ret; =20 - if (data_off + ecc->size !=3D oob_off) - nand_change_write_column_op(nand, oob_off, NULL, 0, false); + if (data_off + ecc->size !=3D oob_off) { + ret =3D nand_change_write_column_op(nand, oob_off, NULL, 0, false); + if (ret) + return ret; + } =20 ret =3D sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) @@ -1433,27 +1481,35 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct nand= _chip *nand, return 0; } =20 -static void sunxi_nfc_hw_ecc_write_extra_oob(struct nand_chip *nand, - u8 *oob, int *cur_off, - int page) +static int sunxi_nfc_hw_ecc_write_extra_oob(struct nand_chip *nand, + u8 *oob, int *cur_off, + int page) { struct mtd_info *mtd =3D nand_to_mtd(nand); struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct nand_ecc_ctrl *ecc =3D &nand->ecc; int offset =3D sunxi_get_oob_offset(sunxi_nand, ecc, ecc->steps); int len =3D mtd->oobsize - offset; + int ret; =20 if (len <=3D 0) - return; + return 0; =20 - if (!cur_off || *cur_off !=3D offset) - nand_change_write_column_op(nand, offset + mtd->writesize, - NULL, 0, false); + if (!cur_off || *cur_off !=3D offset + mtd->writesize) { + ret =3D nand_change_write_column_op(nand, offset + mtd->writesize, + NULL, 0, false); + if (ret) + return ret; + } =20 - sunxi_nfc_randomizer_write_buf(nand, oob + offset, len, false, page); + ret =3D sunxi_nfc_randomizer_write_buf(nand, oob + offset, len, false, pa= ge); + if (ret) + return ret; =20 if (cur_off) *cur_off =3D mtd->oobsize + mtd->writesize; + + return 0; } =20 static int sunxi_nfc_hw_ecc_read_chunks_pio(struct nand_chip *nand, u8 *bu= f, @@ -1574,8 +1630,8 @@ static int sunxi_nfc_hw_ecc_write_page(struct nand_ch= ip *nand, } =20 if (oob_required || (nand->options & NAND_NEED_SCRAMBLING)) - sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi, - &cur_off, page); + ret =3D sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi, + &cur_off, page); =20 out: sunxi_nfc_hw_ecc_disable(nand); @@ -1698,10 +1754,13 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct n= and_chip *nand, if (ret) return ret; =20 - if (oob_required || (nand->options & NAND_NEED_SCRAMBLING)) + if (oob_required || (nand->options & NAND_NEED_SCRAMBLING)) { /* TODO: use DMA to transfer extra OOB bytes ? */ - sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi, - NULL, page); + ret =3D sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi, + NULL, page); + if (ret) + return ret; + } =20 return nand_prog_page_end_op(nand); =20 --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223482; b=n/H9T2wgA3xIJoS/LH0Yx6KKiBF630Hslp+dRlRP15SxKcRV9KsStt4mVvKXp9v+Vn2S wjIGLTOffYtGLfyxhHJWSI/Dpf3ga/ANvmVPSZFMq+FAFmQCvCZ2muR1R6OiUL7QvJT7y VnLDL1f7afJ3lo8zD6H8I7XKSs+5s6RoE1uZS47+o8RJbXy3kNccO6HKVaUxWrGjv+Lhg RxQEcBGVVnEsEiGEoe7PCil3KXnNL9BsmAD3XN7MCTQ90j5fmtOCC2LkwCp8ONXoe8ABn UdmlFNPT0+s7A/hzF2ImX8vs5EjjcXQ/wDA+DYjjmQtWk8nkUzvzqP84YRYmzZGZiaQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223482; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=CgxsAtXFuwPIOpoqITa/yCw7bucmWGSvP7CHXYFl5l4=; b=DtgnQwIPl+iNopZEL0+VSQyXrWCZcy6xXpbgICKYmNIkYbTHG8pbz/IfsiPqy14JNTre HphtVyXGVq1Hsn8VSvEATP9T0jesopv7laYc+vSsEcJrGDkXpfeK4iERm1U/4Sdnh9Ixh RcVeEwae2JA3fQXKlppOztGQHObLouGaQL/qUMfUOT5iezUWnXeZRi9Ee+7cVrBLRf3Oa pCObJyG7nbN/nRcFrWXhy4LLO2vqGwl2Yayex9tKaDDwnyJlo/PfXSzdRnXbUqq8L0WpX CNu279SF7S92XRsvrDdONnU0K2jUxjkUEMCpFlO4QB4Hv6ygJkgwnGawjxeOaMlbt8w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xLlkzqVr; arc=none smtp.remote-ip=209.85.210.49 Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CFA660A3833 for ; Sat, 21 Nov 2026 01:11:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8CFA660A3833 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xLlkzqVr Received: by mail-ot1-f49.google.com with SMTP id 46e09a7af769-843cf077f10so1967021a34.1 for ; Fri, 20 Nov 2026 17:11:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223475; x=1795828275; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=CgxsAtXFuwPIOpoqITa/yCw7bucmWGSvP7CHXYFl5l4=; b=xLlkzqVrwIvQ/Aq4hZS25GlBJqOwghvMTImGsrw4s4VdZqerCIRCIRX/EeNmBJlRbQ x/u6646LcMJIvq30v6Q+U+RDlgNe7roBsE6UYr2qxE5iblqnzpN4tdPmJ+lg45kpvV7F 5lfIQGMrBY3FyoSdZmV4HOgRjYcypLsHxSkqkux5/ioOQWaXVcMzhWwNfhwLJOpzoH4I ukvdTTNOt4NdrJ90yuMs8WvTTHD9JPSkL755U7uyjOsqpaRGyGtK2JItCVrdAeTvpYWS DmRrh/ZnvJqkBnQ3X3gbZrFIvP3KUNPs04JEonrCc4Lk12x0SOeXf1sqcEwRB2xXL9oI 1fdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223475; x=1795828275; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=CgxsAtXFuwPIOpoqITa/yCw7bucmWGSvP7CHXYFl5l4=; b=N4UBqnF/tbDMHFUWi3QdxUUNn0NGKavq5SHFX/El7inrcygoormn16/9UAqj1fNtTB GA+Xq8wBIsqUfQUsJuLMdBr+1DBeQ63vOstB6swlKeMK6OK7oCRSrrsNiGYrqjjjbXlX S0Si8VSXwnzspGTfSanCwyD3NHI6QRMmSg0gkqGV1bM3HIY4EZXH9VLEDboinVlhF4hH y5s3zJCCDi1F1sPbtVNzUsgqgb7hIhqNoG/Fpfdhe9h009sFiI+lyW3GCwPWqc6IeuLg Xndg3rCeAZ3AAhRl7TObA1c4WMk//DlkFzIaNNc5XEXaCsZj9yrNtC/M4Lweu+B5FMXa KVJA== X-Forwarded-Encrypted: i=1; AL+hErE5oaWYLECHbImuhWEqZMImDhkYu9GF69rrSKaG8KTwh/y7A1sxHJFvoejE+PKeCYpo+pqbM/deo7wJ88Y=@vger.kernel.org X-Gm-Message-State: APuU4Z9vxYN/zu8jvMDzr6+ZTYYvruOQu9HF78vSdP7THv8luq9ST43p HwxCZZ+HUBUCc1qHPgTQHDNc0F/hg/b/pN8fGatRbZSMCZ8u0J04BR1F X-Gm-Gg: AYBFou3qSpnWfTaSSoaXM9GDhsR9UeqmhSLne/mHbvwh2zh6JMVaGxKQ5aBixHOU86A c6883Uf5ZgLeKcVFW8leqE+O3hd7Y2oc14/GFc1J9lwqkQgPjRsJoOk9nIVS4ShGLjHO2a+bHLj 6Oxbm/X80dWEJ3i4d7Q6phkAAWy0fnMzRzUBd7HrRmrB+OJIzMMX2Of7jfwhTfgYeg8VeBC0+Fw v1jyiDM0r+9mc4uPv1EUbAZgsH9renKlbfE8JMlibFtWf/W/Dfk420S/UuVCnbaJga4PLWYEJty lnHLToI527z+pK5VDP0D4tY4GAxDkSLwJZORKbks1eryh0iP7AReQ5GNUCocFnKA0FAJpLC4IiY c4ghFKY2xbS58HrE3kHT38vRpc76yhwB9UowxGTtvSJFke8+2JpJnDFs08ZFCaeSZt2oV8I1CCv EXcPVHCYm/iuGKTngbyNb54IO+ksouSPJdY+wzNauxA/MzSkEtf+tUSpKWuWsqrQngxcZxwxcmZ wWuy9zH/VPMxAIYns8AbItrunEVp2hTOeD2kiaMpC2GUzNs3+Cs8UO4iXPEMwWWGGB8+LPSf8EX 3bbLb0byjRQegtpYTWrlvQ1yO8bjlFeqt3CgQCQtBzE/rpNi5tUsEbP9+fcyddAYouEESgK3Erk LDFgYRZR2tRYxNngcbVXq8WBKiHleIuEV3FabCGSBFdYrOwWah8QzVyFwNDtrbEO3d9uSzSVkta 5IhI6AZ9FH9KcA4ixb/ZCRyyEZd1x03NSppXnDd1EovPMifUZV1QJJ X-Received: by 2002:a05:6808:23c3:b0:567:f5d0:741c with SMTP id 5614622812f47-57a0b959e91mr6046198b6e.34.1795223475472; Fri, 20 Nov 2026 17:11:15 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:15 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:37 -0700 Subject: [PATCH v11 14/26] mtd: rawnand: sunxi: avoid a second program confirm for OOB writes X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-14-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev An OOB-only write can report failure after the NAND has already programmed the page. Both the PIO and DMA page writers issue PAGEPROG, wait for completion and check the status. The OOB wrapper then issues the same command without another program setup or data transfer. If that second confirm fails, its error masks the successful write. Return the page writer's result directly. It remains responsible for the single program confirm and status check, including on the bad-block-marker write path. Raw OOB writes use separate callbacks and are unchanged. Fixes: 25f815f66a14 ("mtd: nand: force drivers to explicitly send READ/PROG= commands") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 712648864407..7f9bc0237cea 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1779,15 +1779,10 @@ static int sunxi_nfc_hw_ecc_write_oob(struct nand_c= hip *nand, int page) { struct mtd_info *mtd =3D nand_to_mtd(nand); u8 *buf =3D nand_get_data_buf(nand); - int ret; =20 memset(buf, 0xff, mtd->writesize); - ret =3D nand->ecc.write_page(nand, buf, 1, page); - if (ret) - return ret; =20 - /* Send command to program the OOB data */ - return nand_prog_page_end_op(nand); + return nand->ecc.write_page(nand, buf, 1, page); } =20 static const struct sunxi_nfc_timings sun4i_a10_nfc_timings =3D { --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223489; b=xKLBbpy5mEaZdCsmk050F33AxN+eFHVazxUY3DuwGbVjwMjVwlVs2/mqtNj1ZKNPVdsw bmBPSaS0BpKElLQuihvIMY8Dcq12URoZThMsx4n5WJBTN/ztQqcRg9csSswBBDtR1trLL wQMoJlQy1QpN7yfH7ZZ3G3lINxqHOBDJgo6QWyKqYIidCPYMEtbuc2fh3lz/XaBwv+2/8 GwE4j6DxA1TC32QqLgRtvUWb8h0ae0uYOlbTkQjxG03cWx0eATho3fDeI4MItqSkrux6h DalbYZOK7xCGO1qdKHd2d/IErkE0AP8SECcwC6vL/2nvry94eMBTIEzqZ3cJB/sFJjw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223489; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=nC4NCaRVx/W369O2JGd3M3QVKSAL0tyZU8r4HK4S9iE=; b=rDfANh+aWgVczFtOfU4Q1eVhak2faerSmsly9Ns3r8KI2AfRV4Mq8nDe7k0TWbwOty9v Aen+JKP23QbIgBXaZBuCEz1COjHCv3+IYGf0PRVlxVtt1wJmu1ehDFjvJ8ddzo/F7sWfn LqB0ax0Dd2L5FdLzFsuzYoNxH49O9o5wUKIrVWXT9y0QM7UPZg1l++RUldqIx4NVJmkA3 nCPDQX+O9Sdc9kan2A1hCuDKtFAqtwcI+B2vV23hBHTq1/046P2Ax2EkD4pevo+RckIHg Ybu8x1N9SbJD1B5jk9gOt1DpWNo4OQ4oNpgj621qYU191D404RCpHE2YN3Z1u6bUmAQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=keaVGA8N; arc=none smtp.remote-ip=209.85.210.48 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4234560A5BD7 for ; Sat, 21 Nov 2026 01:11:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4234560A5BD7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=keaVGA8N Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-7f84a55e31aso1013448a34.2 for ; Fri, 20 Nov 2026 17:11:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223477; x=1795828277; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nC4NCaRVx/W369O2JGd3M3QVKSAL0tyZU8r4HK4S9iE=; b=keaVGA8NABBtcCp9nGEza/T+C53VRHAm0qC1bd7ULSYtCrkZ9iU+I6Z6u9+cAp5dPJ tzQGHnIfeGSSYwAJ9WZivNCKW12ONd0Y29AN11PAXretiqFKiKHzNVvo9w5051cIHQlm 3KPQN8nQpiG2MRxXfWKNo7IOGeJSWYvzo0qVHt2Y9IKWNvTI8uh2goiN8N19zutwOj1a GBf662CdXj7Hv+kV+1wFn4GN0Ucn8G6GrtY8qUSlo9N+SDRMINI00ZWtbn3rZxhIv94y GHJb1VFXagXl9OdPtKIOWbVi8yGLkUxTJL6ricHTYurBzr5upzJNTDXe61Z//qJx+R6L 6Q4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223477; x=1795828277; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=nC4NCaRVx/W369O2JGd3M3QVKSAL0tyZU8r4HK4S9iE=; b=EUuThcMAUe915yBC79neO3adPWRFtWpkauXOj8t5ZOrWrz3BVlZP/aKU5WVS8iQHoJ ChU0goVVKnOTJ7d+JzVVA18+eNpzSE1xJeZm4oTMpMnOY4HHH49nPYW3q3Jy2TM2FHXH 6cnaLkFxsFrKu9SeHOUvYHefzXflXTLhxoVQev4s9QgZonmBiDpiWzFmijv9E6e0FStx aopt0EXGmMaDjhRd0S0fXzDrqRK7SloYYRBUu9uCS2yU+46WvNZFZsDLI7KfeNU878TB L9AWsRPOwEBOk9H3QK7DaooIHgtpoXLzvqCeagVfwzR+0j1tfv0lvbQCaGVwDRS2qEgp pMcw== X-Forwarded-Encrypted: i=1; AL+hErGFJwoIn+gKlxh/t6ct0HvtO10hX+9n9MB47RGEvlXMlfpmjlUdeRACjEkVxsfjrMmcnbPYzMmneaNqopc=@vger.kernel.org X-Gm-Message-State: APuU4Z9nAWBslF1UoYOz2FQ0X4nc+gAHgEQp7yX5q2wudni+W4ioOFs0 cLzCgxqQBCYGCEUT2ZB2VqR1xTHxOsepqNri1E7NxkVOiywjPZPj6P9V X-Gm-Gg: AZFdTZc8q9JW2VWH05aIeRF/opq/YgqUgqnRUd5RSgDBczOWVqnR2Ke1uGOUQVSpsST wTKc2eMUmhrd9ZXo2yr8s8wnUicBExWIBthZJeEt34570B8/yYjIultDUNvU7u+EVNb3EhTeTym 9gDME0Id1YLVfy0B0JMvEpe4dW8fAJqBwBgSXNRlAALT2ATNPnxA9AmEb4IdtMAtZT8kHRcRjsH 0/baeUecPyrpP5LYYcdJmW7aRuKBy6aVJGPnrSmnzu4yE1okbmyzvkF14fNr+A/sI64xTH2TuEs Rvt0/WJ564ggcrmRSBYmZpx2slcFuTT9l0e64vT4as1Noc9HtsZxHCEHt1/pzZecD/wEzblGbl9 Fgq8bY0Sed/oHBkU9tEg3lYMub0lu7NJ9xlRLQ6DjERvT9JMzEwemtxgdHL9kQVIXXP1OOScizJ 0bekVhVz7r6YGoeiHsiVgO52sOYykKBDFkDQK5eKOtDWDIsvjIQDIgTaN/ZJBtRVzFnFcOWBSc1 bNcgQMRRnoi/fhzCjqcKMKxFLSWtFKeq1mDHwcLtERdUlBEKLS2LMba10TiWjknHxQxA0X87pnw H2WwTuRDJTXITca+PQfLfZP/83gneahcyxWXSXFIZDD+sLPOAGVY1bAA6zJFYyMfA92Wi4OlzNf zMENj1Ogn+LLg9UvCsY2e1APRpsV7JfXYqb5AjBuEhb+GkdoQYcu+9akWuukvKFmIcnfTkMA2Q2 ZKcFUsp7Qyg/DydSlmBLopJY1b0jTM4kLXrwkkLJAAW5P0lWFGHiBh X-Received: by 2002:a05:6808:2384:b0:539:ad19:d0ca with SMTP id 5614622812f47-57a0ba5523emr5887168b6e.39.1795223477137; Fri, 20 Nov 2026 17:11:17 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:16 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:38 -0700 Subject: [PATCH v11 15/26] mtd: rawnand: sunxi: bound DMA batches by the user-data register bank X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-15-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org, Sashiko X-Mailer: b4 0.17-dev A whole-page DMA transfer on H6/H616 can run past the 128-byte bank of registers holding ECC-protected OOB data. For example, a 16 KiB page with BCH40/1024 and 1280 OOB bytes uses 160 bytes of protected data. A page with 1664 OOB bytes uses 512. The on-flash layout allows up to 32 protected bytes per ECC step, but the register bank is shared by all steps in one DMA transfer. PIO can handle these layouts because it reuses register zero for each step. Capping the page's allocation would instead move parity offsets on flash and break compatibility with pages written through PIO. Split DMA transfers without changing that allocation or the logical main-data and OOB offsets. Fill the first batch up to the 128-byte limit. Transfer each remaining step in a separate batch, using hardware slot and user-data register zero after explicitly selecting its main column and spare-area base. PAGE_OP generates later main-data columns from hardware slot numbers, not relative to the selected initial column. A multi-slot batch starting partway through a page would therefore revisit an earlier column. Single-slot later batches avoid those generated column changes. Pages that already fit keep one DMA batch. Program length fields from the batch's logical starting step, and consume its protected OOB and ECC status before reusing the registers. Keep erased state, correction counts and trailing OOB handling page-wide. On a failed DMA read, discard all partial statistics before the existing PIO retry. Use one page-read setup or program-begin for the whole page, and send program-end only after every batch and any trailing OOB succeed. A write may fall back to PIO only if DMA preparation fails before its first batch; never retry a write after part of the page has been transferred. Raw access and the OOB layout reported to MTD remain unchanged. Fixes: 54dcd6aa69db ("mtd: rawnand: sunxi: introduce maximize variable user= data length") Reported-by: Sashiko Closes: https://lore.kernel.org/r/20260909085138.9A98A1F00A3D@smtp.kernel.o= rg Closes: https://lore.kernel.org/r/20260914031929.2E7091F000FF@smtp.kernel.o= rg Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 201 ++++++++++++++++++++++++++--------= ---- 1 file changed, 138 insertions(+), 63 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 7f9bc0237cea..7f93ce226f24 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -54,6 +54,7 @@ #define NFC_REG_H6_RDATA_1 0x004C #define NFC_REG_A10_USER_DATA 0x0050 #define NFC_REG_H6_USER_DATA 0x0080 +#define NFC_H6_USER_DATA_REGS 32 #define NFC_REG_USER_DATA(nfc, x) (nfc->caps->reg_user_data + ((x) * 4)) #define NFC_REG_H6_USER_DATA_LEN 0x0070 /* A USER_DATA_LEN register can hold the length of 8 USER_DATA registers */ @@ -960,7 +961,36 @@ static u8 sunxi_nfc_user_data_sz(struct sunxi_nand_chi= p *sunxi_nand, int step) sunxi_nfc_user_data_before(sunxi_nand, step); } =20 -/* PIO uses register zero; DMA concatenates user data within each transfer= . */ +/* Keep the on-flash layout, but fit each DMA batch in the user-data bank.= */ +static int sunxi_nfc_dma_batch_steps(struct nand_chip *nand, + int first_step, int end_step) +{ + struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); + struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); + unsigned int user_data_sz =3D 0; + int i; + + if (!nfc->caps->reg_user_data_len) + return end_step - first_step; + + /* + * PAGE_OP generates main-data columns from hardware slot zero, not + * from the initial column. Use only slot zero after the first batch, + * so the explicit column change selects each remaining logical step. + */ + if (first_step) + return 1; + + for (i =3D first_step; i < end_step; i++) { + user_data_sz +=3D sunxi_nfc_user_data_sz(sunxi_nand, i); + if (user_data_sz > NFC_H6_USER_DATA_REGS * sizeof(u32)) + break; + } + + return i - first_step; +} + +/* PIO uses register zero; DMA concatenates user data within each batch. */ static void sunxi_nfc_hw_ecc_get_prot_oob_bytes(struct nand_chip *nand, u8= *oob, unsigned int reg_index, bool bbm, int page, unsigned int user_data_sz) @@ -1345,30 +1375,32 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_= chip *nand, pattern_found, step, 1); } =20 -static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *bu= f, - int oob_required, int page, int nchunks) +static int sunxi_nfc_hw_ecc_read_batch_dma(struct nand_chip *nand, + struct sunxi_nfc_ecc_read *read, + int first_step, int nchunks) { struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); struct mtd_info *mtd =3D nand_to_mtd(nand); struct nand_ecc_ctrl *ecc =3D &nand->ecc; - struct sunxi_nfc_ecc_read read =3D { - .buf =3D buf, - .page =3D page, - .oob_required =3D oob_required, - .dma =3D true, - }; - unsigned int corrected =3D mtd->ecc_stats.corrected; - unsigned int failed =3D mtd->ecc_stats.failed; struct scatterlist sg; + int page =3D read->page; int ret, i; u32 status, pattern_found, wait; =20 + if (first_step) { + ret =3D sunxi_nfc_read_column(nand, page, first_step * ecc->size, + NULL, 0); + if (ret) + return ret; + } + ret =3D sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) return ret; =20 - ret =3D sunxi_nfc_dma_op_prepare(nfc, buf, ecc->size, nchunks, + ret =3D sunxi_nfc_dma_op_prepare(nfc, read->buf + first_step * ecc->size, + ecc->size, nchunks, DMA_FROM_DEVICE, &sg); if (ret) return ret; @@ -1376,7 +1408,12 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct n= and_chip *nand, u8 *buf, sunxi_nfc_hw_ecc_enable(nand); sunxi_nfc_reset_user_data_len(nfc); for (i =3D 0; i < nchunks; i++) - sunxi_nfc_set_user_data_len(nfc, sunxi_nfc_user_data_sz(sunxi_nand, i), = i); + sunxi_nfc_set_user_data_len(nfc, + sunxi_nfc_user_data_sz(sunxi_nand, first_step + i), i); + /* exec_op() restores the page's spare base during column changes. */ + if (first_step) + writel(mtd->writesize + sunxi_get_oob_offset(sunxi_nand, ecc, first_step= ), + nfc->regs + NFC_REG_SPARE_AREA(nfc)); sunxi_nfc_randomizer_config(nand, page, false); sunxi_nfc_randomizer_enable(nand); =20 @@ -1408,10 +1445,31 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct = nand_chip *nand, u8 *buf, status =3D readl(nfc->regs + NFC_REG_ECC_ST); pattern_found =3D readl(nfc->regs + nfc->caps->reg_pat_found); pattern_found =3D field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); - ret =3D sunxi_nfc_oob_read_batch(nand, &read, status, pattern_found, - 0, nchunks); - if (ret) - goto err_stats; + + return sunxi_nfc_oob_read_batch(nand, read, status, pattern_found, + first_step, nchunks); +} + +static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *bu= f, + int oob_required, int page, int nchunks) +{ + struct mtd_info *mtd =3D nand_to_mtd(nand); + struct sunxi_nfc_ecc_read read =3D { + .buf =3D buf, + .page =3D page, + .oob_required =3D oob_required, + .dma =3D true, + }; + unsigned int corrected =3D mtd->ecc_stats.corrected; + unsigned int failed =3D mtd->ecc_stats.failed; + int first_step, batch_steps, ret; + + for (first_step =3D 0; first_step < nchunks; first_step +=3D batch_steps)= { + batch_steps =3D sunxi_nfc_dma_batch_steps(nand, first_step, nchunks); + ret =3D sunxi_nfc_hw_ecc_read_batch_dma(nand, &read, first_step, batch_s= teps); + if (ret) + goto err_stats; + } =20 ret =3D sunxi_nfc_oob_finish_read(nand, &read, NULL); if (ret < 0) @@ -1688,71 +1746,88 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct n= and_chip *nand, { struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); + struct mtd_info *mtd =3D nand_to_mtd(nand); struct nand_ecc_ctrl *ecc =3D &nand->ecc; struct scatterlist sg; - unsigned int reg_index =3D 0; u32 wait; - int ret, i; + int first_step, batch_steps, ret, i; =20 sunxi_nfc_select_chip(nand, nand->cur_cs); =20 - ret =3D sunxi_nfc_wait_cmd_fifo_empty(nfc); - if (ret) - return ret; + for (first_step =3D 0; first_step < ecc->steps; first_step +=3D batch_ste= ps) { + unsigned int reg_index =3D 0; =20 - ret =3D sunxi_nfc_dma_op_prepare(nfc, buf, ecc->size, ecc->steps, - DMA_TO_DEVICE, &sg); - if (ret) - goto pio_fallback; + batch_steps =3D sunxi_nfc_dma_batch_steps(nand, first_step, ecc->steps); + ret =3D sunxi_nfc_wait_cmd_fifo_empty(nfc); + if (ret) + return ret; =20 - sunxi_nfc_reset_user_data_len(nfc); - for (i =3D 0; i < ecc->steps; i++) { - unsigned int user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, i); - int oob_off =3D sunxi_get_oob_offset(sunxi_nand, ecc, i); - const u8 *oob =3D nand->oob_poi + oob_off; + ret =3D sunxi_nfc_dma_op_prepare(nfc, buf + first_step * ecc->size, + ecc->size, batch_steps, DMA_TO_DEVICE, &sg); + if (ret) { + /* Only retry before any part of the page has been transferred. */ + if (first_step) + return ret; + goto pio_fallback; + } =20 - sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, reg_index, !i, page, - user_data_sz); - sunxi_nfc_set_user_data_len(nfc, user_data_sz, i); - reg_index +=3D user_data_sz / 4; - } + sunxi_nfc_reset_user_data_len(nfc); + for (i =3D first_step; i < first_step + batch_steps; i++) { + unsigned int user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, i); + int oob_off =3D sunxi_get_oob_offset(sunxi_nand, ecc, i); + const u8 *oob =3D nand->oob_poi + oob_off; =20 - ret =3D nand_prog_page_begin_op(nand, page, 0, NULL, 0); - if (ret) { - sunxi_nfc_dma_op_abort(nfc); - sunxi_nfc_dma_op_cleanup(nfc, DMA_TO_DEVICE, &sg); - return ret; - } + sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, reg_index, !i, + page, user_data_sz); + sunxi_nfc_set_user_data_len(nfc, user_data_sz, i - first_step); + reg_index +=3D user_data_sz / 4; + } =20 - sunxi_nfc_hw_ecc_enable(nand); - sunxi_nfc_randomizer_config(nand, page, false); - sunxi_nfc_randomizer_enable(nand); + if (first_step) + ret =3D nand_change_write_column_op(nand, first_step * ecc->size, + NULL, 0, false); + else + ret =3D nand_prog_page_begin_op(nand, page, 0, NULL, 0); + if (ret) { + sunxi_nfc_dma_op_abort(nfc); + sunxi_nfc_dma_op_cleanup(nfc, DMA_TO_DEVICE, &sg); + return ret; + } =20 - writel((NAND_CMD_RNDIN << 8) | NAND_CMD_PAGEPROG, - nfc->regs + NFC_REG_WCMD_SET); + /* exec_op() restores the page's spare base during column changes. */ + if (first_step) + writel(mtd->writesize + sunxi_get_oob_offset(sunxi_nand, ecc, first_ste= p), + nfc->regs + NFC_REG_SPARE_AREA(nfc)); + sunxi_nfc_hw_ecc_enable(nand); + sunxi_nfc_randomizer_config(nand, page, false); + sunxi_nfc_randomizer_enable(nand); =20 - wait =3D NFC_CMD_INT_FLAG; + writel((NAND_CMD_RNDIN << 8) | NAND_CMD_PAGEPROG, + nfc->regs + NFC_REG_WCMD_SET); =20 - if (nfc->use_mdma) - wait |=3D NFC_DMA_INT_FLAG; - else - dma_async_issue_pending(nfc->dmac); + wait =3D NFC_CMD_INT_FLAG; =20 - writel(NFC_PAGE_OP | NFC_DATA_SWAP_METHOD | - NFC_DATA_TRANS | NFC_ACCESS_DIR, - nfc->regs + NFC_REG_CMD); + if (nfc->use_mdma) + wait |=3D NFC_DMA_INT_FLAG; + else + dma_async_issue_pending(nfc->dmac); =20 - ret =3D sunxi_nfc_wait_events(nfc, wait, false, 0); - if (ret) - sunxi_nfc_dma_op_abort(nfc); + writel(NFC_PAGE_OP | NFC_DATA_SWAP_METHOD | + NFC_DATA_TRANS | NFC_ACCESS_DIR, + nfc->regs + NFC_REG_CMD); =20 - sunxi_nfc_randomizer_disable(nand); - sunxi_nfc_hw_ecc_disable(nand); + ret =3D sunxi_nfc_wait_events(nfc, wait, false, 0); + if (ret) + sunxi_nfc_dma_op_abort(nfc); =20 - sunxi_nfc_dma_op_cleanup(nfc, DMA_TO_DEVICE, &sg); + sunxi_nfc_randomizer_disable(nand); + sunxi_nfc_hw_ecc_disable(nand); =20 - if (ret) - return ret; + sunxi_nfc_dma_op_cleanup(nfc, DMA_TO_DEVICE, &sg); + + if (ret) + return ret; + } =20 if (oob_required || (nand->options & NAND_NEED_SCRAMBLING)) { /* TODO: use DMA to transfer extra OOB bytes ? */ --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223482; b=NwTBmpo7Kme+TaFR/NsBzduF2CbqnYoWGsNQhxaFTnR0+oxVwM4TGTFCTAL2ozVL5u5z oVwEWV+COGmW0lQhHu26WMvqZU0RjVpZ8AwPtz/AHQGnasBo3p9iBo9JYAeErsBLJPJaz gMCnugLLjeQGNet3f1nymKCoVl1+Rmoofvh3tLg8oFXD6PFiJFxeujy52XY067iLp3oij 5G62F5mmcfNx0MyXypTnkuPiL9/2XnZhM2cDxYbHDKO0yVj268mJaWSeJiPKj0LXfMJL0 4sgupI/MBN7Pl5gkhB5t44AP64iFgBFIcltJaZOkkrQSsj97Z5UlkFJPxT83R9pUOXQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223482; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=9EEb5bdabVEoMSRLLJqgNbBs659DuSJGBxR5aYGgxzc=; b=IEIs1uxgXLOajumDK23npSlptRfOh6NdkNTc9Io2OYIZobGKnU5kDzUkyPMx6/roK5zp VGpwZ7aY/P3DAEFwfVXc5jfNXulQIR5in/THkpgUGV8307VkaeK495yyymMSTOH9b5Wh1 GA09W8Kzu9H4/2q+5whN2nVlpsHQBV6oYYGKLING8aqc/lr8NN+cOgMEKjcbEzBYFW+l4 5Hj9+GjNzGsRcx8XYlS//uPV1xLDJHaY5+HU7gx/UFMA6rW/v8dk4N+Vx2oSz6GPUhUZe joMQSKgB+4EvsSDj8y3tE3kfK2u5UVleqINUOrmhhggblNdAgRA7DsYqoSvVA7bSVPQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=znugP4EE; arc=none smtp.remote-ip=209.85.167.182 Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 885CC60A5BFD for ; Sat, 21 Nov 2026 01:11:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 885CC60A5BFD Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=znugP4EE Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-571888655f1so565443b6e.0 for ; Fri, 20 Nov 2026 17:11:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223478; x=1795828278; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=9EEb5bdabVEoMSRLLJqgNbBs659DuSJGBxR5aYGgxzc=; b=znugP4EEWaZd213fx3PrvnJuMx6s7G058ioZ+DOESVCtuUF8JECDL3ho4kBIzIc+kE wBn92LPLuVT8SZsvXTO6CPk6c87hk8qfgTvcFWW30ucmJxSyK13bz17gnRM7yzmp9g7w f34dvrndWu7B2wiCGvFqynhfnHQdglI7ba7AlNf5/VUskrC3YTGyIOrbwTzySHAfKEuS w97M5I/ZjTKtu141iEr+ezyJfkpDYgqhFOaW6qeJmC0WqPEa9ASuc35Sv0mv/0Lb7Eu+ Bv5sCfM28y9XtWpCtlL8SXvfYKYrKSCTCR6sF47gk6VpncgSKj0AOIGiCHdZ56xqGHjF CmLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223478; x=1795828278; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9EEb5bdabVEoMSRLLJqgNbBs659DuSJGBxR5aYGgxzc=; b=zw0ZcpT32O/7OBnoJAgIUjI2+ZetYGWQtp14FnM0pyQlvzmoCVdQ4fHRt7Z5r6qhIy zl4dVMj6m+Z82+1lhC7ueGnEczxDoTP+NvnZqL2CoLWYAgtSl3V0vqkh5AP1fHHWvR1k qez+0kdalN3uj5mDe5SRdJhn2ChcP3kevV9FMp+SjPNOokclPUrwtgOesntZmdntekmc 2b3M4ClR6dZdkz6nPZJGWxzm8jRKVjTO+ujL/z6fQkvuv/VnAG9asAO+75RfQNC7xl8n XjseR7YfiqlHbqRg4fmDIqfKXwWJKM9qXjgxv1KWfGirB4bqNf8H0dflI1kF8dixVF2Q YvBg== X-Forwarded-Encrypted: i=1; AL+hErGontQpXCrj9Z7X8DkjeJQ1+y9K32OT0q+dF9nBr16ht3QF0PSJHA5xzdxyrp2s/sRD9Ge79VZ1cxXu/go=@vger.kernel.org X-Gm-Message-State: APuU4Z8YqXDBYmUAo5WISEPFMOv6MEg9x/QpvrVyRePOh2Plgr2ZnHnK eSTSdq9WswWe2r82cGu8SCOty6GVMYmetfbMAqisUCGRfR2J/HQLc//k X-Gm-Gg: AYBFou0RzkDxGFOwGyhWfS46jlAjen3hx6SDIThOPqHLXoYTybh6ieKw1v3iaJEgvXm 8h2xc0T9eun5hpDkVGfaYrktYrCUE3eFJUENB6J5ehnC9XdIwI9RikW2QDMslCsXCj5usGaSCny yj4thMQ8Ibethz5yHaYZ2h/XNaXS/jC5QkabuCj3tUNJcJtzRVbeLFvUGjM1g08GpsxkT4VqSMz 7JKzkzFTMyU7HmfdcxHjBA9TrcQjehDJhjnRFMZJfOHY/N6LBxWzVzAcgdSTgAPkrQ6tjLL9ncx eGJkMawJqAkV2IhF7sSrCKCxNO6aWZ1F+xS+CXCRM2E4CCorTqGW3IKVC1+MqSu7daJVrqgSAXl 0K+Vt4k59QxQej2uALkSlYMhc+MCtL96MVAXNV+EiBzklHLKAw4qYihY879V7NIGrXuVn9NiECl Eof43AyqaweS86DtbQ0e8hvLUS3YhD85w4UuUWwR1yKx4dUC2tsVvBIoozSK96Bx3YhSajWDi+l Q0HbKy9yXqS+1p9q6eaVoPv1/0pcpXFIBn5JBEOXCcdwnrGZDJkyq3mLu8y8kQZPAoY9W4iqV04 0GY/ramIDTyt1uu85BQPyfmMMXFTfz0Yj+R5+ibyp8esCzxcaXH+SR/wi7t9qO46I3k7kpDolde Iv+CHF+fJTxJZKFgmSTfDHAVT2ArAORN5z/flz23l8esvf5M0EKx8wBzNhMwlELJNI3bEINrZ2N FfXrhgfIKGDvnf2ugP/J+kf9MX75cy5lbIDRQ61rSBjNKPiEd7/LV1 X-Received: by 2002:a05:6808:4f06:b0:53a:9d3c:caad with SMTP id 5614622812f47-57a0a4079a5mr6188187b6e.25.1795223478418; Fri, 20 Nov 2026 17:11:18 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:17 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:39 -0700 Subject: [PATCH v11 16/26] mtd: rawnand: sunxi: limit DMA subpage ECC results to the requested range X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-16-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev A read of part of a NAND page can return -EBADMSG even when every ECC step covering the requested bytes is readable. The DMA path transfers from the start of the page and accounts for errors in that entire prefix. An uncorrectable error in an earlier step therefore increments the failure count that the NAND core checks for this read. Corrections in earlier steps can likewise inflate the reported bitflip count. Keep the DMA transfer unchanged, but only process ECC results and perform raw erased-chunk checks for steps overlapping the request. Keep hardware slots and user-data register indices relative to the start of each transferred batch. Fixes: 2de85e733601 ("mtd: nand: sunxi: Actually use DMA for subpage reads") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 7f93ce226f24..5415ac6960b4 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1106,6 +1106,7 @@ static int sunxi_nfc_read_column(struct nand_chip *na= nd, int page, struct sunxi_nfc_ecc_read { u8 *buf; int page; + int first_req_step; unsigned int max_bitflips; bool oob_required; bool dma; @@ -1234,6 +1235,9 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip = *nand, int bitflips; =20 user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, step); + if (step < read->first_req_step) + continue; + if (status & NFC_ECC_ERR(slot)) { /* Preserve PIO data before the raw erased-page check. */ if (!read->dma && !randomized) @@ -1294,7 +1298,7 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip = *nand, for (slot =3D 0; slot < nsteps; slot++) { int step =3D first_step + slot; =20 - if (!(status & NFC_ECC_ERR(slot))) + if (step < read->first_req_step || !(status & NFC_ECC_ERR(slot))) continue; =20 ret =3D sunxi_nfc_hw_ecc_read_error(nand, read, step); @@ -1451,12 +1455,14 @@ static int sunxi_nfc_hw_ecc_read_batch_dma(struct n= and_chip *nand, } =20 static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *bu= f, - int oob_required, int page, int nchunks) + int oob_required, int page, + int first_req_step, int end_step) { struct mtd_info *mtd =3D nand_to_mtd(nand); struct sunxi_nfc_ecc_read read =3D { .buf =3D buf, .page =3D page, + .first_req_step =3D first_req_step, .oob_required =3D oob_required, .dma =3D true, }; @@ -1464,8 +1470,9 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct na= nd_chip *nand, u8 *buf, unsigned int failed =3D mtd->ecc_stats.failed; int first_step, batch_steps, ret; =20 - for (first_step =3D 0; first_step < nchunks; first_step +=3D batch_steps)= { - batch_steps =3D sunxi_nfc_dma_batch_steps(nand, first_step, nchunks); + /* PAGE_OP transfers a prefix; only the requested steps contribute ECC re= sults. */ + for (first_step =3D 0; first_step < end_step; first_step +=3D batch_steps= ) { + batch_steps =3D sunxi_nfc_dma_batch_steps(nand, first_step, end_step); ret =3D sunxi_nfc_hw_ecc_read_batch_dma(nand, &read, first_step, batch_s= teps); if (ret) goto err_stats; @@ -1618,7 +1625,7 @@ static int sunxi_nfc_hw_ecc_read_page_dma(struct nand= _chip *nand, u8 *buf, if (ret) return ret; =20 - ret =3D sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, oob_required, page, + ret =3D sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, oob_required, page, 0, nand->ecc.steps); if (ret >=3D 0) return ret; @@ -1641,14 +1648,15 @@ static int sunxi_nfc_hw_ecc_read_subpage_dma(struct= nand_chip *nand, u32 data_offs, u32 readlen, u8 *buf, int page) { - int nchunks =3D DIV_ROUND_UP(data_offs + readlen, nand->ecc.size); + int first_step =3D data_offs / nand->ecc.size; + int end_step =3D DIV_ROUND_UP(data_offs + readlen, nand->ecc.size); int ret; =20 ret =3D nand_read_page_op(nand, page, 0, NULL, 0); if (ret) return ret; =20 - ret =3D sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, false, page, nchunks); + ret =3D sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, false, page, first_st= ep, end_step); if (ret >=3D 0) return ret; =20 --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223491; b=lfp6HoZ3ochtaBU7AZoi8sTioxBeZVDujFpuac6s85fj7ZrVrIK4LVcHOfts7L1M6bj5 MftvqPoPlOop7PQj8TWDba5jLyJ72ClYQ1xVMiHnGQ/oKgIHgnVGcfVkVeXAt1cNbjcPd 1zyOnOLKVsi8nBR1bX1CatjRDiz3Mtt3LHwgwc9aQxge+bpRezSQ8h4cxhBlsSUIxwvOJ PiOl+f7lliANhJj3ks+ToWEJDF4pJcfHatzjvKv2qE4DhWC6PS+yDoZp4H8FfzSzmKJ5n jiKh/oKKE9hoctR5lx5rgCNY6rd9+HcwKkXqDZszS8uhKMxI8lia+JOV7DNhoH8W4Hg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223491; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=Rd+OJrfYC05spJgrrPaaw8Or0kLWD6WKtcmuDL8E++0=; b=C9k1if45AT1LljG38YdqZ3DKCC9oZd6rTQeyMuVuVe8lGzHmhzczftaMgVmBpmSXSo7m KYVoT2YJNfm7oqI1jU5BASuB4gEuu12KdHRiRaOBj6W66XGAfIE9uq64weKcLzXq/bt34 ovTo0pGuwgUz2J6pd43UDXkhKDH4pyS/WdpJymWpTQpAPOvUCEyHRlrp5Uzhlj2xbOdhM FIWstrbleETItsf1nZZARi/VAmsYqakwJuhqzUaOuTg95ZfLgEXCx3IzyT2byNNC/8AAC hf4BHMubWKOvVIg8+4VaS93IfkxafSRWyRjBeLT+09oX7wb7G/eJiAU/gDkxIs6/zyA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ldYMPKEl; arc=none smtp.remote-ip=209.85.160.42 Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com [209.85.160.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4D5F60A6F4E for ; Sat, 21 Nov 2026 01:11:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C4D5F60A6F4E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ldYMPKEl Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-4911df1e196so894451fac.1 for ; Fri, 20 Nov 2026 17:11:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223480; x=1795828280; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Rd+OJrfYC05spJgrrPaaw8Or0kLWD6WKtcmuDL8E++0=; b=ldYMPKElWhbs0fukl2KiGDSnyLaUOTrgeMCcvfSieEcuAYO2ECMlj/vIwwAzrganVe LDzqs3dzhn58+XXKh8GMfij1+SGs0NtuNJU/6ml4ccbd8a1OsyPHVGIQI7oSYjy9f3zK hB8CfvU6HCqka3H5pYx2TtOYDfOh+ktqswQiAv+JOKz7f0p7bHZf6DihY460+bQ8aTkq E0GP1t/QQowKmfyDwLU6HQdk/rMtaAj0DgRKGgY3+aE8W1U9XdG1FIjwHKmblk4hELmT hqfrE4Hn7WwsEaqbgghbC+y92r2cNqAYLuKdgPjoB+ONm5y9c1nhbRjXvv/IVFcE+aZW EHqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223480; x=1795828280; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Rd+OJrfYC05spJgrrPaaw8Or0kLWD6WKtcmuDL8E++0=; b=oxjDKhAKbO//QEAp9cfn2Xx7p2MoF0Kl1ktRws/xn5VP9SspfuDeknWhiqpcmFcote nPhwrDS6M1wf2WaBisEjbhNJBYqybEoXaZ8ia59K/8AsEzRZUBrb4+zCqa51d5Zkog1t 74uFnWyO8etB3ccvF376UQQYeGGVqJti3WQiF5LY9qwKgR6uKjotzwGYS2fR0BHp4dRQ cc9F5CDiOTHV0JL9oH/5VNnrOF9FaENaIxy8hePqqi0zFxEHz4v2x68+Ctn/dNVW7IsK IZxCLYFkGr/hm9s615mWqLuo9JftVG2DFsXZEhdjdOF4dsyLlkKrH4dv/glD/NpCiEj2 e8xw== X-Forwarded-Encrypted: i=1; AL+hErGKWpnt1WE1ZCrtYqRJcjjXOgSyuR/6DfljXYXnAS9kxSBcV3hEGoPptNwsL6H6D2JTvCdzsU/ryNIZLeY=@vger.kernel.org X-Gm-Message-State: APuU4Z9W0IV7Gqv156MZXaD3cQgC/ZpUUw2LRjQhX/tAVuRGp2hkgQWQ kU8hn0AUIKK/pEohkEnrJHJoVfmpQgLzJeNdPNIBBDK2WEUHvUx6r595GXilHG5W X-Gm-Gg: AYBFou0cSKOWdfFRm/QZer6Xl6vGhRxS8qj3S4IrEuJ+sUNaDRCr6541mJfyt2m/D+D JpGzTvD579rbExF7hguIkuHD+5CgRtfuMo6fVan2sK59kmuuMRwvHv4MvHBjHop+BciCW7gl28I 8brfmemiI/vVE1JukaHV+p2RIiGAC2F7LDuOuIuVRGdDn5Lv0CPJulIxuIJhrTIvy5Y65WO12I9 KpPBXRqzZhdzqMB82dnUzt+5M44M25yTkvxuY0gDvW5vhtG423E1kpn40ejmLT57G1mpjzJH7PV SmlnbCqoTm48x6nX7PLOGMb8kDLjEEUQvzfwMSrLA5DeTTIZ1Mucsg+8b2CXaB594scALkRoX+1 928IYIPJK7xTKyCtqIdbGwKuRbeT6qGKCG1yrEyHu2spg+ropSHppzroOumlyIN1bcIR49MurkD 5f581isqU/5Cs1yYLLL85bKlSEWSf5k7DW/2vmcgC1/X7j82jhFZhhNrDZpZf2ln0OPQGAweSbQ H2Y/bvKCiignI38D46ocRrPR2UAcNDpMGEionPk6mT+xes+W+V72NtysFhcq8PU4W4WlJwDmmCk naOb9iYPPdKduli5agUs5xXl+pCTs843K4V0IuhRpTmfT4FLHdhPaT0ONXQ0G0nVdwEhN6ymuGS 3iRkjXMlW0J5CvmJ43ZX/Zg5PmtUBe7+Vzm+2KT1pZGxSsPFTUZ97M0yw1GMrYleNYa2Y59NR7C Evhtf54QMkIbdrvX8FW0av/a5h3G5yU1BH1CqPQqoTjY3slsRL13Ha X-Received: by 2002:a05:6808:4f0e:b0:54e:7cf0:c0b9 with SMTP id 5614622812f47-57a0d2f1a5emr5946703b6e.64.1795223479754; Fri, 20 Nov 2026 17:11:19 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:19 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:40 -0700 Subject: [PATCH v11 17/26] mtd: rawnand: sunxi: preserve bad-block markers on erased OOB reads X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-17-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev A bad block can appear good if its marker is the only programmed byte in an otherwise erased ECC step. If the controller reports that step as uncorrectable, the erased-page check counts a 0x00 marker as eight bitflips. With BCH16 it replaces the marker with 0xff in the OOB buffer that the NAND core uses to check the block. Leave the reserved marker bytes untouched when checking the physical first step for erased data. If a hardware pattern supplied the OOB contents instead, read those marker bytes from flash after the OOB tail. This preserves the column for sequential reads and leaves the normal corrected path and data-only read traffic unchanged. Fixes: 146b503e1027 ("mtd: nand: sunxi: fix bitflips in erased pages") Fixes: 4be4e03efc7f ("mtd: nand: sunxi: add randomizer support") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 5415ac6960b4..f8bc6e3c3ac9 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1111,6 +1111,7 @@ struct sunxi_nfc_ecc_read { bool oob_required; bool dma; bool has_erased_chunk; + bool read_raw_bbm; }; =20 static unsigned int sunxi_nfc_hw_ecc_read_count(struct nand_chip *nand, in= t slot) @@ -1167,6 +1168,12 @@ static int sunxi_nfc_hw_ecc_read_error(struct nand_c= hip *nand, if (ret) return ret; =20 + /* A factory bad-block marker is not an erased-page bitflip. */ + if (!step) { + oob +=3D SUNXI_NFC_BBM_SIZE; + oob_len -=3D SUNXI_NFC_BBM_SIZE; + } + ret =3D nand_check_erased_ecc_chunk(data, ecc->size, oob, oob_len, NULL, = 0, ecc->strength); =20 @@ -1251,8 +1258,11 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip= *nand, =20 if (!read->dma || randomized) memset(data, pattern, ecc->size); - if (read->oob_required) + if (read->oob_required) { memset(oob, pattern, ecc->bytes + user_data_sz); + if (!step) + read->read_raw_bbm =3D true; + } if (pattern =3D=3D 0xff) read->has_erased_chunk =3D true; continue; @@ -1321,6 +1331,14 @@ static int sunxi_nfc_oob_finish_read(struct nand_chi= p *nand, return ret; } =20 + /* The pattern supplied no marker bytes. Read them after the OOB tail. */ + if (read->read_raw_bbm) { + ret =3D sunxi_nfc_read_column(nand, read->page, nand_to_mtd(nand)->write= size, + nand->oob_poi, SUNXI_NFC_BBM_SIZE); + if (ret) + return ret; + } + return read->max_bitflips; } =20 --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223484; b=HcZAPSrpcxD3vJB/x3FGfNITusprdEYPzNqiFr7IbTAdkD4Ta6G4YuJyZkJEI1jAclfw PY5mxq+4ZOSnuHjIS36Me3z4VDdzWgOvTDP8O7DxwU4W1UolKzgqDlo575JuFSkK+DJ1p Lm6jnefHZa9UuazM2VSUu6Yf9yJbmG6BNzVyJzpqbaYr/mzegKd84QQU3Sw5SRvKMPDYB 8XCPclh4FdQTHgRJURY3GoV2ij0hXK2wwkux+FZyDJa2bTZXbq5X3fs1PwCWi95e7KwpE MH53nLVF+19l/B6OqM0MqGE7CFLPHtn31PnBpPwup4Pa4PzEQ4lxo2BmyBQu2QF5Wzg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223484; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=KCmwAi76omzV3Ocey3RKQm8GgxKEzZYW/hAI8TU8mC4=; b=hN4ZwLTOvMZXsrdojYTZo600mtM3dipDXf7GAjjy0Vn8RiDU1sGVE7wP1oBg9ns1KKam VrpEEPjf0efyJbgf5+NHs/AjVBAFhl+wwO3VjfzzY67IHF4znjpBoJU2F5jEQWaviHKkT j83oHXiAIA62fzD91jGgXWGUkY3hoTITBKzp0LFw8enZ0UpoMOscelXsc3zQg0cm61C5d VKBqWvYK+q40EYeOgzcJ7NaFV868KwEMJE5jkDxR22yzdYktVaep2zwgZ3MJL8vz+rKwj hnYst8r9jfG6Vcgxu3PaCWAC9GGevnYh1J6vZDa9kZBOoInxXJOdqHr/WRZGAlAHfPA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=vbEpg+3g; arc=none smtp.remote-ip=209.85.167.176 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6260660A6F5A for ; Sat, 21 Nov 2026 01:11:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6260660A6F5A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=vbEpg+3g Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-53dda625f63so913208b6e.1 for ; Fri, 20 Nov 2026 17:11:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223481; x=1795828281; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=KCmwAi76omzV3Ocey3RKQm8GgxKEzZYW/hAI8TU8mC4=; b=vbEpg+3g4jekdTHkPmtrwhQLE/eyJNgkmQOR6nfJD59QnllJNelKloF+7dumVGj+SS A/C/55NWWzD0XPSlHaRHb8BqTB1Ap3SJHcTNyOimn0WymYFd73Q3vukeXtX/Z13ebpYh U2UQWGNKLKIlN/ZHPtZEyvtJDZQgbfwePkDQRk0wMTl0i920kspNKG50EQdJYctqO54F lzFYKCFW0pcoffYZpQ9o+ZZ7JY58io55iLLYhLFZUSeh2WwE2eyInyGDfTvDzHbCzgHT /WENzKHLV7DUG696NACwUQ2I4Yr+895RgQtmUNXDYflyznKUAca1ITmHLtTZMyEJbNSG KxEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223481; x=1795828281; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=KCmwAi76omzV3Ocey3RKQm8GgxKEzZYW/hAI8TU8mC4=; b=OJw754cY+MvXuXpv4Pm7HtO17z+J004MLThLs4oJ9vyhUCaFH0T5BhosKEPwBdM30S /V0viCVBjieF5VOuzkSvKeLiJI4iPh+kA0YOKl+X6olrgxuRQvEHPwX8qVQUjaI4lWiv oTPjP6nNqmwdiQy4uga+UFOs7C+XoNPh1cs2tcxKItRjTG9ZkPyMaKVH2HDE0ty864Va fBSD+qIL4cTsOD2ySVsOfAHuGupkeaQl7HMLeK8QnLDVUJ1exSO6a20axOfp3cqwHFKk cVySeXFxP/Jm5tqTasaZTWiRuxmCw5voHZQ4Ia29tTRFtiqo8KTgTwFgGS0QvKMLpQ0v M6sQ== X-Forwarded-Encrypted: i=1; AL+hErFcJCMglgUMs7NmGQizUPqVYAx6XxqtTRJrGxdYf2+ixqXUgn2MPJspR5NnYtSqMjx8MCwRV/YWcood6q8=@vger.kernel.org X-Gm-Message-State: APuU4Z+x7Sp9n908Q3/jI46bTX9/jL0baM6/D2T9MaP7ik5eMmOn5C0F 3yR3e8Z9AJmWLW0T4Y9BM+5v1kZF6mUDjiwLlwdG05F6iYIUsGIDB/W8 X-Gm-Gg: AYBFou2rsUskKdCHbttX0o4svgEg2w7emNNqE6q/9VtDjrhe1/fRZ5zfqs7ti3AWeyW JunlvloQp2gi529rEp5hy1YgQFq0pNJSG342qUI7xMOtd/wb6CqE5M3QMBi7r4Ix1ENReV34+bx cpsCzH6eYpmQBxkNjql9i3AxX3QWqnCFaGODbZf6TExqf8bwh0aAooNDwBgj2oFdXp/RUr0Arl1 44UPMyhN2G/fu0uA/YFaMhuB1IlDsmQ/iFZlUfr2WnyarsoMQpgkRXHLMmPhEosZe9FtTKjw1JC dDOn4atLESlkoHiUxeGlNCZXByiHTL6eZPGmxi0LURV8aJNH/TEiam9Pp/cnlZPK3KsQadPavQS 7TtfeOsXE1rDtkDWHouGwL4oe+kow0I2ReajwQ9RLxoI7AoHZbmmVObA0NFbJB5shUsV3Qdx2ef XtSSZ2h+msbVTtwOVfwDu7dl6HkhzZYszDTLURn5xGHyYa+b6TW+cs2KELzvZuL1cq1ycT6VVzB p/VnudYPF2cNYMDHRDArmCwQ3gHG0FCb+l/DD7Y9+uvuyJcC7Iid/yNr/tQ4eZufGd7EYTnk8ZW 5Gzy747cV8nYRitMuDoZtZluZDPaJ/Ums+DWZWCN+u2F1n8j/m1K0RadRRaKVBhAzAgNIlWQcVH TdR3V46+oVJhMlP5YrxpUuiRRqNDdM7wrzpjYhhCZ2JIYAAE/CUOaK543rLOS6xFwjxmjauF8jE aCmko4Lk7KPy6JNP81jFImKsWIY4tCyW1ctfxJyFH1MIVuEL81vFJ/TC8jIkb+XpRNXVlYfTFVF Q== X-Received: by 2002:a05:6808:152b:b0:53c:156b:a16d with SMTP id 5614622812f47-57a0a70b0d0mr5784172b6e.56.1795223481233; Fri, 20 Nov 2026 17:11:21 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:20 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:41 -0700 Subject: [PATCH v11 18/26] mtd: rawnand: sunxi: send all address cycles in split operations X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-18-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev When an address instruction exceeds the controller's eight-cycle limit, the driver can report success without sending all of the requested address. The parser splits the instruction; nand_subop_get_num_addr_cyc() returns a count for the current part, but the driver treats it as an end offset in the original instruction. For example, an instruction with ten address cycles is accepted by the parser and split into eight cycles followed by two. The second suboperation starts at offset eight, so the old loop sends no address at all while reporting success. Use the returned count as the loop bound and retain the start offset only when indexing the original address buffer. The parser limits each suboperation to the eight cycles supported by the address registers. Fixes: df5057999f8c ("mtd: rawnand: sunxi: Migrate to ->exec_op()") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index f8bc6e3c3ac9..ee68ef9bba33 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -2410,7 +2410,7 @@ static int sunxi_nfc_exec_subop(struct nand_chip *nan= d, case NAND_OP_ADDR_INSTR: remaining =3D nand_subop_get_num_addr_cyc(subop, i); start =3D nand_subop_get_addr_start_off(subop, i); - for (j =3D 0; j < 8 && j + start < remaining; j++) { + for (j =3D 0; j < remaining; j++) { u32 addr =3D instr->ctx.addr.addrs[j + start]; =20 addrs[j / 4] |=3D addr << (j % 4) * 8; --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223484; b=UIDMMPv1ensyML6ut8euBglQlX2lsgJIAFm4EgxgEr0nTHF/breZa0W5iXSn1Dz4t8h6 xc/XJtqCFKYQWOi2dudrh7EnGds9jDoZ4N24NjARgLYGnCEKEuOcUbKuR8XKpW1KXZFtS 0EWxJMgV+uEI18HHKkcb7b+tBDUOR88V4MMNOunkZaBSk9mVjPun5b6sP4VxzwcrB7zIe GzUbD62eNN7xGJaFuWuKe465kK4je2GOLJHdH7kzcaxQvLB87bpr71fQhwUTIRB/94vuq ikTGILQxzbHpaJU4JGW33fqTdyDFm5CdGZy+WI/YrFQr6ATHwHGyv0yGVaJPyIRya1Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223484; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=9R93eLtRuVCsdbuGEdtd6/wt6t26wDnU5PW4NiI4F68=; b=eXkY4/o7TNlOLDm27zidf7MSu93fX6PQfCtvpO6PVUHtgUf2oCK2TrMzUFGLuWqsWZfH Eym5CpWzx7Dr2Y79uMXvcWxgOhrUviPLHw2NofTfcGD24PFnLQcGa6Al3eOvgkyRvo6e9 uOtGQoMHW5nSZ9D3ULhxpVX8ng5HlwCJjaOtw4jSgtcZnqCkH0JFXP2RUuwmcTHBOB2IS Ej6g17pmu2dV/TY1klia/VgGAmH3aMYWCYo6hDCHw5N18o4ddGY5OpVgUInrr7SdNBUxT EB+e3scE3YrkCZkJy9EmqTqxWRmi28HcVTpZUJhEOWENIqabLVWW6Mb82sY9+J21WeQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=e5TgMMm7; arc=none smtp.remote-ip=209.85.167.182 Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C6B660A6F6B for ; Sat, 21 Nov 2026 01:11:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6C6B660A6F6B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=e5TgMMm7 Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-4b28d7c729fso1188039b6e.0 for ; Fri, 20 Nov 2026 17:11:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223482; x=1795828282; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=9R93eLtRuVCsdbuGEdtd6/wt6t26wDnU5PW4NiI4F68=; b=e5TgMMm7+jQ8ffDKlXHHAXuEjTo4RJVZHVunPTHGE1LYtShLGSVfkURaaAAypnmbrG kaYDSwM1oi604+FYpctk6iFbjlIcD7n6VjdWpc4r1da1atEf1orbHyQzK1HXr/Y8wHAU TStIula0ruCnYI39A++ThrwUdZogQjXU21dKrLR4nY4hhvQE6hPddg3eV9YuOCgZp/VK vuj1qM6QH1h8P5cVDLgxoKkg73iL3oX8l8MUeVgbdqXH61KKt3coCtLtfW3b4lCcIiR5 r9Kjt3Ii8zPONhALXGhmIxA5hUls9+Dp9YgnSjWXQMQd8C/q7ZgCQ+3Ua30zoHWuGbCT 1aeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223482; x=1795828282; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9R93eLtRuVCsdbuGEdtd6/wt6t26wDnU5PW4NiI4F68=; b=ntWY6J4TN/ty8H+sOILdiU1PHpbjB4HRYfjWzwZiv+ux/28LdBWiMC7vqDIg5ZfOpk HiDhWEbzMKR5ho/IbEIgoe1/Nt1O0aD0z08YGiPjzGxcLyiX6xW+XS7jw3onfbC4evCG fKan6redkbF+Pmar1CdMm3rumsxfjrshyAr9T17rfzLQHF2qADSspuAQ3dQloRqOB7uP 88wfX3wJAqMRxUuuDfX0pDZCrapNK+/Rttb+uE6waJkXXed7uIbfFRTbO9XAqp1qXnsK bJg/YmHlmu581yGfDXOzljuCD7N+mI5LHTDvuvbb7YCqXJL3PcHJE/XBYiwePRB+dbzV w2rw== X-Forwarded-Encrypted: i=1; AL+hErGnLZDCYNKFeCXs5rclPpLWmyLEmfjd446tey5NfDLyXWP5x7hPsh2z4oOfIyog5M68SEWe98oYGbtGsb4=@vger.kernel.org X-Gm-Message-State: APuU4Z9xVGnY4t3E5PoSXaF9/71Rj85hHp/6o1SzL5fKWSwm3cQDfiUy 9XETfbIn/gXwczeqyXQIaHWVTwJccU2slMLVhtXj/02xp++Ad4Sx5uDa X-Gm-Gg: AYBFou1/8D0EwDaJKLDfWXeWtnWTC4xGzwNjQQbE69pFl08vJ/IKAaVkC85eA1efqY3 r8q3clRvZG9SVnPuSmFSYz34GlVNUDZfLOPTDZKC/YB8ayZPTKlocijtt21rgJXuNtTKZnayiZd JZk25nmJhlmfh/cjx9DBHXRgnzxQ8Wd5zfd7lHz9qzYixoCxlSHpiKf+OiVl9HebU/w3dbqI7Pc iR5rA0hHOn2eHTOsz/s+oYf/saUdRB/3xH4BfyQ4q5U7wRCT5STFCTKs6j0bdF6H2BG/5lh52jX LHgD4DoXS7ij/ycFk5o2n17nbLdfqogln9ZwjGsvrDaQu7zpjrK0BRya9haG/kn5vtlH8D7rbfm /O7/0RuGK6EdYt1KiCBJgaWVk3fM4dDjFYgU/AxYRftYewNENdwZAwqq4BLZ7QNe+Qb1JZRyjM8 bZtc0pxYHP+ahOZnzhqCSpNjelpWTLDeQNNBub0PwjbP9jrfSuf3Yt1xHZ8sLLpGAj9Oe5nVKN3 jlFLSzpMl7TNgqTZaU9maV8zNQeQ9rawV6nlvfUmQBigkpnTV0XcUlxWzIbt9f70RjFz2o5yWOs OkCqjG7So9r/WqlKNpNfNjMaqWXJ1HsF+PzrtukoyW/NjVnD7Cg8/gcUr09aGaP16/0sdaLqymK gmIof2s5hTX/AlrcbvKwgdwwK0Hhu/zQ4AFClJsD2aETPb8OEuxOtd7VZ26hcwdDUzyhk+eR9Cd oqqT+B0FG4kod8ehhsiQvgvmrVyYM2WFL83Tjt/31hzTUmYjtrbTXu X-Received: by 2002:a05:6808:13c5:b0:573:52b1:bb00 with SMTP id 5614622812f47-57a09910c41mr6373784b6e.39.1795223482353; Fri, 20 Nov 2026 17:11:22 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:22 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:42 -0700 Subject: [PATCH v11 19/26] mtd: rawnand: sunxi: propagate chip clock setup errors X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-19-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev If clk_set_rate() fails during chip selection, the next NAND command can run with timings calculated for a clock rate that was never set. The driver also caches the requested rate, so selecting the chip again does not retry the change. Return the clock error before programming the timings or updating the cache. Propagate it through exec_op() and the DMA page writer so neither starts a command at the wrong rate. Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index ee68ef9bba33..37cc023db74e 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -628,16 +628,25 @@ static void sunxi_nfc_dma_op_abort(struct sunxi_nfc *= nfc) dmaengine_terminate_all(nfc->dmac); } =20 -static void sunxi_nfc_select_chip(struct nand_chip *nand, unsigned int cs) +static int sunxi_nfc_select_chip(struct nand_chip *nand, unsigned int cs) { struct mtd_info *mtd =3D nand_to_mtd(nand); struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct sunxi_nfc *nfc =3D to_sunxi_nfc(sunxi_nand->nand.controller); struct sunxi_nand_chip_sel *sel; u32 ctl; + int ret; =20 if (cs >=3D sunxi_nand->nsels) - return; + return -EINVAL; + + if (nfc->clk_rate !=3D sunxi_nand->clk_rate) { + ret =3D clk_set_rate(nfc->mod_clk, sunxi_nand->clk_rate); + if (ret) + return ret; + + nfc->clk_rate =3D sunxi_nand->clk_rate; + } =20 ctl =3D readl(nfc->regs + NFC_REG_CTL) & ~(NFC_PAGE_SHIFT_MSK | NFC_CE_SEL_MSK | NFC_RB_SEL_MSK | NFC_EN); @@ -649,14 +658,11 @@ static void sunxi_nfc_select_chip(struct nand_chip *n= and, unsigned int cs) =20 writel(mtd->writesize, nfc->regs + NFC_REG_SPARE_AREA(nfc)); =20 - if (nfc->clk_rate !=3D sunxi_nand->clk_rate) { - clk_set_rate(nfc->mod_clk, sunxi_nand->clk_rate); - nfc->clk_rate =3D sunxi_nand->clk_rate; - } - writel(sunxi_nand->timing_ctl, nfc->regs + NFC_REG_TIMING_CTL); writel(sunxi_nand->timing_cfg, nfc->regs + NFC_REG_TIMING_CFG); writel(ctl, nfc->regs + NFC_REG_CTL); + + return 0; } =20 static int sunxi_nfc_buf_chunk_size(struct sunxi_nfc *nfc, int len) @@ -1778,7 +1784,9 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct nan= d_chip *nand, u32 wait; int first_step, batch_steps, ret, i; =20 - sunxi_nfc_select_chip(nand, nand->cur_cs); + ret =3D sunxi_nfc_select_chip(nand, nand->cur_cs); + if (ret) + return ret; =20 for (first_step =3D 0; first_step < ecc->steps; first_step +=3D batch_ste= ps) { unsigned int reg_index =3D 0; @@ -2519,9 +2527,13 @@ static int sunxi_nfc_exec_op(struct nand_chip *nand, { struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); const struct nand_op_parser *parser; + int ret; =20 - if (!check_only) - sunxi_nfc_select_chip(nand, op->cs); + if (!check_only) { + ret =3D sunxi_nfc_select_chip(nand, op->cs); + if (ret) + return ret; + } =20 if (sunxi_nand->sels[op->cs].rb >=3D 0) parser =3D &sunxi_nfc_op_parser; --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223486; b=uDLY13K/vBDWlsY7p2KrSIT6I6ZrdycBPdaX+cQPQOof/dGmX/nc+g0Vqa7UNfO8dW65 AqkTRiiJIYMTr1w2UDa51sSUY0MVXTgFoGH9oyp7hgxuXu5l0s5KDq7Jz5bP1g8FyVb88 yV1D3c5CYCpW+VqmWz/8/A5w91maTvqU9nF/vobGlhjAWgL8+5XZVLCOugyekMkPOfzNs RZgA2k9FDx1gyJwRARfKL38YxPYak19tRVoyjIULd0RD+K6Moa/IyHZILveo+RN2VRgqo Z/RN/anmy5fPV+lkO4EgcVwdpFbFke7CysJSTLUoW8LzTAgW6Kca/qN6XqPT9pXMSfA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223486; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=dWkb9R9dFJf53WgY0/fb7qetN7PVplL4lJbH2mVBctQ=; b=4la7CZfPuRZE9OY2QzdGRvWrv2TlVwZIF2H33ZexF/PV9Gkya8/ir4eX7/MjrjeUrF02 71F0XPg/0SH+Xy3akjxS6dSn9VIh8GJAJvN311VS73/w6nYhzX2hfiyKwgA2CLc88tZIM /GDdhUUSzxRsOqITtpPD6IqwheJI/+N/CrlKDcv+shz5oDVmurc7jo7gLgKe2QwNcPBaq 1IIjwWcPx44scCDj2kP1kolHVu69Wvj6SOjMOjbOMsznrHP+uC5z6DV2kWSkHu0U9wUVs a/spzFg5vPrO7tRcRzw9AxeFfcDjIMDP5R0yEFTo+CbV6QQFe3v/9pqOjz+8bE1kg4w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="CLt/7c2D"; arc=none smtp.remote-ip=209.85.167.181 Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF19A606ACC3 for ; Sat, 21 Nov 2026 01:11:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AF19A606ACC3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=CLt/7c2D Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-53ec92375d2so924194b6e.1 for ; Fri, 20 Nov 2026 17:11:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223484; x=1795828284; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=dWkb9R9dFJf53WgY0/fb7qetN7PVplL4lJbH2mVBctQ=; b=CLt/7c2D9bgcj1VCDJD/Yx9MziudHQSEBWpHHhHw8bDVn+e+sJu6zChF9D19FvYIZy K/LXd35F8IJt3f1TryrwwBkAmOXUV0jttvhBLSuW+JJyaBG5Gf3uxe9brV1ANpwkLNa1 V84SILZhe0vO8U4nj9w84AYtvc/gOwL9cADHaVNNi1DuUjGNZfT+k4q+4QNV8wzqm54P uaGdIta7yIH4iKLtpkQRNkvKLB4o0QEQ6j1TnyUNGQ7RJWugw9ZGDPq/52vPS3J55/Xl A4Z+Suiw9OvroDWKW/rEuJjZ2rG6/aP62VlWrWZzg9pkMA9DJgdWjmCV6gQdeNN7VpfG o0jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223484; x=1795828284; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=dWkb9R9dFJf53WgY0/fb7qetN7PVplL4lJbH2mVBctQ=; b=I+qiHelPF2HuQDgaFh2bKvcUot6BpQHrEIeBIKWA1eapjUVvQAFMe8wuvQ3vGye6Us 3MlAU1pg3hitCo3BxGHQzSM2KbQqrs76sLYWu3hdT+7dwXUDzvueupJduKl0wwnG3O/S 6E/Nu5f1AVHMnKSJFXRDqUr0+zh8asdZjIYILMhnTlD6VQ2B4eNns0/Gvk0pvNZ98Qq+ gkDbMt1ButQvE5U4mHGCQvDWjzjAPnwjKcmt8lXcaARtZfRHtl79gBJvRCGu0FL5D343 YxJp2fPeGHLtGwhw1/r33jDyYJJuK2R8yyDb/8F7v78SOcf8sIZIkH3+hZ5x1SE+iGJE puwA== X-Forwarded-Encrypted: i=1; AL+hErFF11nivLK1++tNwBYHHjbLxXA1fb/jEyShvk5xiUzm7v28NQUOuqgXRiJn5c25ff8fHvikh6L4OAnHaME=@vger.kernel.org X-Gm-Message-State: APuU4Z8imTUmbxiLg0YZt1SzQxDqeJgTgyxyGnDME6FpNUKOIhL1hNWx Zo9Q6UBZM+XwlfTnmXKg9YCr9+4SkeQIjVPVmQXX7/OWjlYI1Mhpo+0d X-Gm-Gg: AYBFou2VRa0Lhf1zTxw+jZ4MVcjkS42q+uszDVPn99fCEmSEyden1QzIKuAkkRaM2Y9 KZ3CQQ05MvOQ6WwyYU9Fys3ZpsvTiKjITTSLa+YC4sGt5VoahMW/8s/roEEjTGbZaVdnhvbfk5/ k6wMfHkocKhw5ZvvpEgGmFt6QExXH5UarfJatFUl5XfyyGQ6HRFmW3HEkOBYOxJO5F3ttn4VHxx tyFN65nmJmR9LAnIyQ535lJs2f9Q1F6fVUOd2ttCIq/M3mB9ITYPtZHRY0ERHt6OfcZhGjghNjJ oN2GxOjb/+TRgUoH+K4cD2uWj+9dVW9+LlptHXh1rTosnyXk+wTIYXPhKeshThilnucPn9msCkw uVK4vxH1I4gScK/aZ9Up2p4m/dvwbvWI7g4Nnh5DsKGQeFMdlCoFDTzPscPk7Z/h1zBND2Sszrj +Kqi3STuPFCGPgfSaweiyEsKWH60+j+Mot8QDQ+DL9VS6hRFuHTjtwE9s5jkAkZJYTNuz+p0lTC I6n9pfUdaT+QkK0kkbvs5w90q1HTIsVsgBTsfns6C9eEYe+gcXxRC2lkpTQUwCBmEUgKTOsVdEo N/pqOIuSGteu/XabHIghJGTh/VKc0ZJWrXYmk5JdfA5h7a8Jp9wc4JN9lTUvhwubydxhQGFOjPT DACpKZpdzDR4jVqvcthhPg+B46K0uUavxslc+mkqIB11UcoZUmoaHDOwGsqV1uVIskE6HUTo9jQ SwjUgPmLa5dhmfium/VdXgRdiSYQ7yJQx8ruN1MvG+kLTSVeAEmtj0 X-Received: by 2002:a05:6808:4fdf:b0:571:b166:3d77 with SMTP id 5614622812f47-57a0af33b0amr6477590b6e.27.1795223483689; Fri, 20 Nov 2026 17:11:23 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:23 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:43 -0700 Subject: [PATCH v11 20/26] mtd: rawnand: sunxi: limit buffer transfers to the command byte count X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-20-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev On H616 a page operation can report success after reading or writing only part of a large unprotected OOB tail. The controller has 8 KiB of SRAM, but its normal-command byte count has only ten bits, with zero encoding 1024 bytes. The buffer helpers use the SRAM size as their limit and advance by the requested length, even when the controller transfers fewer bytes. The operation parser already splits data transfers at 1024 bytes, but the extra-OOB helpers call the buffer helpers directly. Share the parser's byte-count limit with the buffer helpers and keep each chunk within the controller's SRAM. Larger buffers are transferred in successive commands; controllers with 1 KiB of SRAM keep their existing chunk size. Fixes: 88fd4e4deae8 ("mtd: rawnand: sunxi: Add support for H616 nand contro= ller") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 37cc023db74e..4478189bf920 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -89,6 +89,9 @@ #define NFC_RAM0_BASE 0x0400 #define NFC_RAM1_BASE 0x0800 =20 +/* Maximum byte count for a normal data-transfer command. */ +#define NFC_MAX_BYTE_COUNT 1024 + /* define bit use in NFC_CTL */ #define NFC_EN BIT(0) #define NFC_RESET BIT(1) @@ -667,7 +670,7 @@ static int sunxi_nfc_select_chip(struct nand_chip *nand= , unsigned int cs) =20 static int sunxi_nfc_buf_chunk_size(struct sunxi_nfc *nfc, int len) { - return min(len, nfc->caps->sram_size); + return min3(len, nfc->caps->sram_size, NFC_MAX_BYTE_COUNT); } =20 static int sunxi_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len) @@ -2498,11 +2501,11 @@ static const struct nand_op_parser sunxi_nfc_op_par= ser =3D NAND_OP_PARSER( NAND_OP_PARSER_PAT_ADDR_ELEM(true, 8), NAND_OP_PARSER_PAT_CMD_ELEM(true), NAND_OP_PARSER_PAT_WAITRDY_ELEM(true), - NAND_OP_PARSER_PAT_DATA_IN_ELEM(true, 1024)), + NAND_OP_PARSER_PAT_DATA_IN_ELEM(true, NFC_MAX_BYTE_COUNT)), NAND_OP_PARSER_PATTERN(sunxi_nfc_exec_subop, NAND_OP_PARSER_PAT_CMD_ELEM(true), NAND_OP_PARSER_PAT_ADDR_ELEM(true, 8), - NAND_OP_PARSER_PAT_DATA_OUT_ELEM(true, 1024), + NAND_OP_PARSER_PAT_DATA_OUT_ELEM(true, NFC_MAX_BYTE_COUNT), NAND_OP_PARSER_PAT_CMD_ELEM(true), NAND_OP_PARSER_PAT_WAITRDY_ELEM(true)), ); @@ -2512,11 +2515,11 @@ static const struct nand_op_parser sunxi_nfc_norb_o= p_parser =3D NAND_OP_PARSER( NAND_OP_PARSER_PAT_CMD_ELEM(true), NAND_OP_PARSER_PAT_ADDR_ELEM(true, 8), NAND_OP_PARSER_PAT_CMD_ELEM(true), - NAND_OP_PARSER_PAT_DATA_IN_ELEM(true, 1024)), + NAND_OP_PARSER_PAT_DATA_IN_ELEM(true, NFC_MAX_BYTE_COUNT)), NAND_OP_PARSER_PATTERN(sunxi_nfc_exec_subop, NAND_OP_PARSER_PAT_CMD_ELEM(true), NAND_OP_PARSER_PAT_ADDR_ELEM(true, 8), - NAND_OP_PARSER_PAT_DATA_OUT_ELEM(true, 1024), + NAND_OP_PARSER_PAT_DATA_OUT_ELEM(true, NFC_MAX_BYTE_COUNT), NAND_OP_PARSER_PAT_CMD_ELEM(true)), NAND_OP_PARSER_PATTERN(sunxi_nfc_soft_waitrdy, NAND_OP_PARSER_PAT_WAITRDY_ELEM(false)), --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223487; b=QSMDvec2I69JT2VGFbtuuCvZBrOZcYjjO4aYP7STsddRmXy3NwCDybncJYq8Ub+wYMSR hjkhNPDepp/UWWTIUwAIgmyFrbq6cBrGcIpKTyOps7Ojtffx08VqHEUX+y4Zn239D4hBi FDNqO4crCoBrPHbEEb1xgYWi09Qd/xro9fvQ5f6xEOivnte0Gd4ED0NWTEGPyjLZSB2ep 49U9UJBWXpCHsTHG0enOCpZNdrSC3wENAqMPlRXNLfPOeGSLwVu6KunUYZobl8Tmwh1XZ Yjh6r3FJs83Zbnw3XPZsIFsns53TmZ5IqHiNOZyxTo7OJCHmwgnHzOt4d6quT09/cgg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223487; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=1uJoG142fYCuU8vw67QDp3rEWq4mupCEBikzvmy4Exg=; b=mPwuSpTnnMBGnLmt83Mt0R27phU7Ohyp8iTuyFjXnbdbDA4zbuvz8yK7zlMrCeIxugco GRGG1pFblmhx8fsFiw0Wx12/v1yqAc19mIWjVj25f+qniUZwSqpwRe+o0TI64/dGu1ZLQ hCpTJ1ZRHhYIo5P9hHfVsivPn03TyC/HXnk4JqA/IKhJMBiT+lgG6GpGawnprbAfaRxoL CrXS2JV/9ntk8JbRpcSnM4fGc7kxim+JsMQdiETzepwvTC5RMp6gpP+TWqjhpGsPwDxAs SRE051YbWQpmpA96c4ZIYI/4K/8nxNY8gILvdCk1CAFEsOMgmPk2wjUXRWqLwwhvN9g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=mVHIq2XC; arc=none smtp.remote-ip=209.85.167.177 Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EA54606ACF0 for ; Sat, 21 Nov 2026 01:11:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0EA54606ACF0 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=mVHIq2XC Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-4c5d8c7f326so664233b6e.1 for ; Fri, 20 Nov 2026 17:11:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223485; x=1795828285; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=1uJoG142fYCuU8vw67QDp3rEWq4mupCEBikzvmy4Exg=; b=mVHIq2XCT3WjrztVHPg8vVCUXUbHdEH/1VKb6z41SGdHKRI/p7AoWxyd4YNFXbmB9h Ay3uBvXx13gcG22PjCEtn+T2KwPRFMyvSa1upNHBvd1br+dgNTyhghWEg4pUe48upORR zavCPtmvytHTLnrhlUiITak/ZligpZJE7TGkm5DeIMsG3Xugn/VublR8Q0Nx2gW05l+3 tF34RajjMtUi/DdRHD/wm/QS57f8qsLnBZKZEVX6wKsB+s0g6pzmQ54IW9A/Tmr/8ZiM /Zv30Ad11tzAn2GAumq902v2ZT0WPdPWxnzAgjhJYxZY/1ZmGrVaIYR2AvEqM/puYtkv VKnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223485; x=1795828285; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1uJoG142fYCuU8vw67QDp3rEWq4mupCEBikzvmy4Exg=; b=LtWM+ZNyA6o7ANRCblIVe2hPOM0Tjo690ow6WqqJUOTFFnrGMMZ2QqNG6KLAtsmOte DdoaXhelq0meb7WsN/26GsvCOVgQB3zhyTWRjNJeMI/Z01sgxmMzFAp7geus34lif0nl HfCKGLOko7g29e9ij2BPlJVTfNeOewu8cqRuAahDzdEZd8+JFCzFcIaOO8KXY8nalXd5 rpx9B/PplxlIv25g8Ux1aHpHGPvf+nB+ymHfuBIa2iFcCP81C6V3FQuPGNvJeAizBzng lZShQtBGF5QluwnIeL1RWX3vMPFDRDxVMHt5BQJHFzKO4w/ibciTOjBs9mzdRveUCFKg pdnA== X-Forwarded-Encrypted: i=1; AL+hErEMmH6ArgrpKMkKW8LGZdf4qCruD/nZ/VqlGO0ho0kqvN/SGVN+ZcNAXz7EC4qK5Hqf2oLkS1fJYnZ+3uI=@vger.kernel.org X-Gm-Message-State: APuU4Z8erR06ViZQ08cjiOQe0nliE/3N2KsBq7P7BhnIbN4joH8mQsSi W3hQY94SBTQjyNTVXfHq/nhsgMfMskzS5I5/CzgbrZaTrs34SlehvOqf X-Gm-Gg: AYBFou24qV6vf55WPChaZmnq/RDuoo4Je6GwTBR4APhEAi/khS906R3zo75cRwqKUm8 vHwQGxnUU7sDO9VoZwo9xKm7f/K0vnBHEL4q3e3/aYq3LqngJCrVh0KRIY7S6B1H8hc9BoyvKix QTam1NpAWVT3ITT9lqyB8XloaQNWaiCnJ4g9o4b73dPZoh4stpfcaZe75CSo9kxPTILsYyYPRdx oRH/1kyUwOI59YbVCG26r+l57gYcgV96tfiQtvBAhP5Bmec9VfH2TzPVpP1UukszaLwP7zGZQpg w9juJZq+WmS8ctxyVlf8ppY8GiVlsjbEsIn6lU25sFbAl5exl/z+ePNSYugLSrlq5SwZW2Fp7En 6AtzwuqNjBPAqZFsP4vbMn4QveNkOGIpf1wkNmbjIOZBDky3yI0ZZQrjuFTMkNUbESd7gt7Ozuv VTLrSTTpXz5dXUtriqSpFMOFEkXB5YgQRMxPGoRNf6KNc9gfUfCqNIowr80ihB4mQ2p/9dStOnI 43Z1PWuHTxacWZiyhrwvpB9Lyn18AXedepZClSKRfEEchWNrqNDTkIY0ylNN3tdYxVFG+2Siupy t5GzcdRePf+FaHLSOEA4oCdpYTlK6CIkNHFwtF2FSSHHkV5PqK+Yxz+w4+bBGfRnArrf+fiA7VX V0+Top/or1PzceBNUXl1BhACps1k4o/wvG/bpMBp53PtcZEGLKrB6nyRObsZEI0bGyCzuqyrpHd cMZECAcWN36y6BvI/iAJbmqVwQoVtRXQ0BT6JkYCmQ3hxmgE1EdOxl X-Received: by 2002:a05:6808:1915:b0:4f7:867a:1136 with SMTP id 5614622812f47-57a0c7bef2emr6229820b6e.64.1795223484984; Fri, 20 Nov 2026 17:11:24 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:24 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:44 -0700 Subject: [PATCH v11 21/26] mtd: rawnand: sunxi: skip unavailable NAND child nodes X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-21-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev A disabled NAND child can prevent usable chips on the same controller from appearing if there is no chip at its address. The driver scans every child, even those marked disabled or reserved, and aborts probe on a scan failure. If the chip does respond, it is registered despite being marked unavailable. Iterate over available children so unavailable nodes are skipped before claiming their chip selects or issuing NAND commands. Keep the scoped iterator so node references are released on both normal and error exits. Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 4478189bf920..73d6cd89ca19 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -2661,7 +2661,7 @@ static int sunxi_nand_chips_init(struct device *dev, = struct sunxi_nfc *nfc) struct device_node *np =3D dev->of_node; int ret; =20 - for_each_child_of_node_scoped(np, nand_np) { + for_each_available_child_of_node_scoped(np, nand_np) { ret =3D sunxi_nand_chip_init(dev, nfc, nand_np); if (ret) { sunxi_nand_chips_cleanup(nfc); --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223488; b=1NmHUiq3R/XEHLN4v06ERv0dUmRGwe4iMJTY9PGml+yvZrwE04CnkbjzTK4dJIgVStkm TmCSiYP0jFjVrX8f10zuLdNPoUEjNQiNHskRUa1DIGBw6N9z6KSBPLVHavMobbwWDwbE3 n8Upna9BllXyWSt2hJFaV5koUu2rq5tsBeImcdaODOUYxmHWG//j0N0mf6klAcUceuO2X d0SPU2UWqXQadZ38A+iuf15kU+hMeSl4CcEN0yY3cOnljZzqTsuzM4LOUbZhf/1MeCMkl xKKhGFfKK1x//4lnZ7CB1st2Mgl9ttPGCUfc+FNDjGvW1+bPkyoolB+uo6A6Nqn5JMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223488; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=jCsma9jNkefw5HpS61LewWc4mQKxmVwW9euoTiUjDLY=; b=GVM7lXqvAfLrPPx03oXoVsoXvFSmOcN6bSmG04emrIeqbkOCPbsoTRfpjlePUJDCyNtP i0cYTvEZ9r0fVCWCZZXZZ1r7pBbvhOqM6ChdOf4b06szD5+TiUFYp4uJfRfSJ6B/s5NpW fPzg41jzQQOZEuRJ/Ea59dq62sV0/t/FITidFmOb6PSV8iCSERF5Rkzfp+3ILYu/CVRXI UtCLeaY9KaYBWe+hqpmgRXcAhFj8nLlQ9zUJTygD6/LbeuqEFMPM2nxiOGthCqEb5wkQA /PAhidHMJtu4oMiLoSA5x7LT20sdq1cf9CXDv3N93p+lgwD9vqI8dZkJujr8J6Yhnkg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="luI/6nAO"; arc=none smtp.remote-ip=209.85.167.174 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CA0060A3816 for ; Sat, 21 Nov 2026 01:11:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6CA0060A3816 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=luI/6nAO Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-57728d87699so651373b6e.2 for ; Fri, 20 Nov 2026 17:11:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223486; x=1795828286; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=jCsma9jNkefw5HpS61LewWc4mQKxmVwW9euoTiUjDLY=; b=luI/6nAOx+GMAFSJv4JqoZ7Yjv5jSrxg/QM00a6dreIqmuDhVfbO2Gi5M5vS0WA7MV FVYX1uG+214mgMjRI6RHU0yZWSVmEm0ci7b0S8q/eTyISaNJbt9Tv0H/C/OoJ+sdFXNB zew2ac9YFhk3tIvMCEjSi45nO26RaPPGHxrrLhnJmtJrk/HcYr4oTJ3rQmGUO+o17cOG Y+zQ7JEJJFO4dsC8GSg1f65CdEMyzbXhtT35tXNV9SgOzyp3jnmuL3O3L8YkDqZ8gE7b YvhYs7mlqrb1DoLnG+GO+BCc6nAvMsnzC/g7qQSjXShkeNiKA8SOXaf6SGi2Y8b+yTTU fgTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223486; x=1795828286; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=jCsma9jNkefw5HpS61LewWc4mQKxmVwW9euoTiUjDLY=; b=dvydBQ4tyQE2jmrsJYiMH6q2ugwqsV19KUtpTGGfY2Z48QCK7qiaFXL/mZ+dRczKzV 8QLScxWLRpXcpbIveKCtxDaR0RmLAz9QmRw/qEg/TWgvKRDkP1Yr14+0tCX/WBg/wmMl svUxOvHXCkyiAe8KDJhftbdYslppf5Qo3wGjnWf0WweJStL8cPgortw3qdnduDi0ea5f 5qwNtctW6w1d9TtapHwNGPwtPUAi6RG4xqTYvgzADMx9oe6ani6DEP4bIfbH1Thz+/oe A4Q+ZOoQe2arrHpbg1nIwRKDeS9KVNSMYMgGhJn5lXMZILg5NSzcfz54l1hPJsCkLQxm L1gw== X-Forwarded-Encrypted: i=1; AL+hErFOXRW7jw24a9qGhK8r7ufC/F5uz+g9VKIK2Smkom2mpEGzgR1uv8va+INeXW5b4slLkhuQvyRommME5/I=@vger.kernel.org X-Gm-Message-State: APuU4Z8k/YozTWZGmo6YrsPIZ9tgFz4M06LtWQ5HenX4jPbytrEYFkIZ M5BEtsCPIxfELqO5FK+XdRLuFNjn0ns+37kCw2PgTF5jjXLLP7qku58R X-Gm-Gg: AYBFou3/WNbqueHBVeARXAGG7S/3Qn5l0rQMtFAUHpMbWzd/JMmaARkp9Uk5Wodox3Z SnAPCuYGlClFX/DHyulb/9BdYpPzC2hnWRA9OJ0XzkDdfyyCJZSnSp3qZVcsIT0KWhdMB+1Pcf7 WysOSADiaYhigHmxe7EVVuJ64ewR9x9GHlsMCDkTiwt9SW4psU9oThd9+pQntNY/FkbXaeoEWYw 1jpOn4AmteheisFfBul7tf0V8s6UW8pxORZv/UwTgqIN6pt7jItjPtLFeSEqxa340BC9enjD/KD b6KYKyGvv4DtTCdSUJjDYAfZbTND7CqDklUMDtKZCXntMI5qNLsnKlo6Gvzd+OY5T8hS8kGmE7P MAqOmwPpdVY0o6dN9Tbp29Cg78A/6ATndpW3d/F0VqYcNq21k38TjjwBBwtrh4Lw3UK25N8pqNY hFWDBgBZSMq/ozo2owLHsFiqCoAWLwzwYkTXrtTFWSzO3uzOTZKhIgL/hrzabIX5FOSHO4uCyWk iEVv3+SeRPk4+U4/QegEkPQTz1fYLPHw3xeem4sOvdv8xTXXSQjfl25iZOp4s9fRRWaUaEZW1Gq 0334yhh8nO0by0PiUrx9e6mKntm+54m1boevdwDqpEhc8kw8EJiFyYSCCb5YVQfM1h0qoHiz2Ev +7wQPnAlPrau6YYrO37aRE4xuKjQYdIeWt1Bs99uKMDtNVLlbeQRBcmqX6pzZLap3FKjnKV5m5H GOiBk4rz0/cl0WA+HK7+/s7hafjaugQxryWWL4ORxfF4xWpkZitTy+ X-Received: by 2002:a05:6808:6410:b0:574:16ef:89c6 with SMTP id 5614622812f47-57a0ab2e12amr5993188b6e.35.1795223486363; Fri, 20 Nov 2026 17:11:26 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:26 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:45 -0700 Subject: [PATCH v11 22/26] mtd: rawnand: sunxi: scan all chips before registering MTD devices X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-22-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev On a controller with several NAND chips, I/O to the first chip can overlap identification of the next one. The driver registers each MTD device as soon as it has scanned that chip. Normal I/O holds the controller mutex, but nand_scan_ident() does not: its RESET and READ ID operations can change the chip select and timings under the active transfer. The transfer can also interfere with identification. Scan all chips before registering the first MTD device. Track which scanned chips have been registered so that a failure in either phase cleans up every scanned chip and unregisters only published devices. Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 73d6cd89ca19..abea2ab0cc42 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -274,6 +274,7 @@ struct sunxi_nfc_timings { * @sels: array of CS lines descriptions * @user_data_total: protected user bytes in a programmable layout * @user_data_step: maximum bytes assigned to each step, zero for a fixed = layout + * @registered: whether the MTD device has been registered */ struct sunxi_nand_chip { struct list_head node; @@ -284,6 +285,7 @@ struct sunxi_nand_chip { u32 timing_ctl; u16 user_data_total; u8 user_data_step; + bool registered; int nsels; struct sunxi_nand_chip_sel sels[] __counted_by(nsels); }; @@ -2563,8 +2565,10 @@ static void sunxi_nand_chips_cleanup(struct sunxi_nf= c *nfc) struct sunxi_nand_chip, node); chip =3D &sunxi_nand->nand; - ret =3D mtd_device_unregister(nand_to_mtd(chip)); - WARN_ON(ret); + if (sunxi_nand->registered) { + ret =3D mtd_device_unregister(nand_to_mtd(chip)); + WARN_ON(ret); + } nand_cleanup(chip); list_del(&sunxi_nand->node); } @@ -2644,13 +2648,6 @@ static int sunxi_nand_chip_init(struct device *dev, = struct sunxi_nfc *nfc, if (ret) return ret; =20 - ret =3D mtd_device_register(mtd, NULL, 0); - if (ret) { - dev_err(dev, "failed to register mtd device: %d\n", ret); - nand_cleanup(nand); - return ret; - } - list_add_tail(&sunxi_nand->node, &nfc->chips); =20 return 0; @@ -2658,6 +2655,7 @@ static int sunxi_nand_chip_init(struct device *dev, s= truct sunxi_nfc *nfc, =20 static int sunxi_nand_chips_init(struct device *dev, struct sunxi_nfc *nfc) { + struct sunxi_nand_chip *sunxi_nand; struct device_node *np =3D dev->of_node; int ret; =20 @@ -2669,6 +2667,18 @@ static int sunxi_nand_chips_init(struct device *dev,= struct sunxi_nfc *nfc) } } =20 + /* NAND identification must finish before MTD users can access the NFC. */ + list_for_each_entry(sunxi_nand, &nfc->chips, node) { + ret =3D mtd_device_register(nand_to_mtd(&sunxi_nand->nand), NULL, 0); + if (ret) { + dev_err(dev, "failed to register mtd device: %d\n", ret); + sunxi_nand_chips_cleanup(nfc); + return ret; + } + + sunxi_nand->registered =3D true; + } + return 0; } =20 --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223490; b=rHEoo1u+Zu7ug+SlZGsS07r9XdoLMUpvmANX7TLUpEQ5WyZAPDe+XlsvNM7UCgzyUo7s UzFBSkJ2MrK8FRTcPW6j7T0REcDU6zQvZm/XBzKjPxXznDWKYojKd5Wc5l46fTef9WLLK +Z45BwcrXaMnWm6Qa8XNcr+Zv62ftL7JMrg3/u6na/KzAizSbFWzKEqHimHkfgoobN7IR R0VUBC0VSKzGMN35qIVN8kdoO8P+MjtgkvU66Y/5prn5NyXLnZc/8o/BIf0+qJ0RiI8yk RA5slLphyBC5sKrFyqhtBW02Y+qe4YftjV5hosPG2ohKMBlybvCR/jFLUaXA6J/6cyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223490; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=8wmwptSly1/jnXieQYc5MDUwaGqVqpFqBShPCzacVyA=; b=hoq5dakty/BZ6iplxtnDE9hLlWmARTstVGY7MwjGs15URasapw7dgMxqYlU4Ug/gxm84 c5RnXPfitHsae6xyzxE1mi9qS6qJepp+dyCTof17CNVQSOJsVE6gFJQu8yjbVcuARrxJc /VfHcr/yDCvik8f5kLokYSynlnMENO/jhkpQ2/hBlvAM2IT2sUH3NJZNdB9Aj9TB2y8cc Usa20uB9rGfFbT1TJiOcpt+LgjSrnSKumLPZealgY+E1z3Lr0iVUrNt8V+U5wyBfTZl5J 2XzOGJxJfdE+fXBgnxgMlSKpaQNIrJ50XtzEJVD3GXW5hQBevrD9F5+iSBs7k+DiEDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=HFEqmXol; arc=none smtp.remote-ip=209.85.210.45 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A62DB60A6F7F for ; Sat, 21 Nov 2026 01:11:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A62DB60A6F7F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=HFEqmXol Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-8631e07b756so608898a34.3 for ; Fri, 20 Nov 2026 17:11:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223488; x=1795828288; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8wmwptSly1/jnXieQYc5MDUwaGqVqpFqBShPCzacVyA=; b=HFEqmXol7+asPcoNseI+jxKp0GwSh3YBIw/yac5Dna0WcUaUQIp5/WOl/eXE/xjiq6 KD96QHmz++ooZHw+Dn7GJzVuW4il8Zu8n+JPLbpfXUjAS/pGF1jtK/GrBgyPT9LAjOAm dtUcBRNt9wn+FQpxg31xHyEyK8w234DrCxC0PdmRxgJiFFWst6HxgxaO8OkH7b+CbqC6 IzzieWsup2RsKr1gcVaFfQkRbyq/Rt3kdj7yR/KkwQ5VvyNe+6D3D7v2koavYEJBZ20q thlfDb4OHeSivMVkr6PYIryZfTMmEMH/3YLgnbm17pkNbFaN8UUlHvFqUxjcILJ3NNSF aA6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223488; x=1795828288; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=8wmwptSly1/jnXieQYc5MDUwaGqVqpFqBShPCzacVyA=; b=wk8Qh0O/IvaxyfmcS3jikuM0TUch4TmrFbJxtw/rkXbuYLFzQNQ6v8K5YVwghWVEOw kT5VDTgT5VIFWdKF+cgT4Z4EZplESjvTRy1tyFwkZyOfyY5lijVAga6swDyIierW415C VCHUm7hoGRgGgWDVs8c1Hxdvj2Fo4lcFRToutrxlbfwukdTrR11V5ErR306zj7zG+L7O cxSznoA/BduyqF0SkoBU0hmMk6Yd6EdPLqJj2gj8dHFhder60DAzL1tD+DueWh9nzEuy Wi2bNVPuFfF65Y7Mu0fqzJVoJ9T1kPf89OwBcDFfy3Gi2/vym1/m4WQnThQo8ae0KHgQ s+WQ== X-Forwarded-Encrypted: i=1; AL+hErHHNiKi4n8i5g/N2HGhr4v8hcQYn0Ruo1lYXroSZWEdLoa+z2ScVyvl49f+nX7rYxOm6cd54xZmfcn+RnE=@vger.kernel.org X-Gm-Message-State: APuU4Z/NDN4W2mGYW6rhgmD0RKBf92g9C7AssTrIjk8sKjHFYpkU2B+M IrRh/ManXQOHdh+h3SIxljmzzE8xRHrZTYnmoUWddUKH1cKQQaR7sT5i X-Gm-Gg: AYBFou3X6fvMewCwMFtE0UsnHBb3ZKfnqHLb6Fu71Lh1r8WBNZVY+LO6+hHfzsG6lyS vg/JJGVO7yk8iZuO7Kitr1ifWKURHfGW9lXOGsOZc6U59UMcZ2ZeRzRc6xjJuF+O/l6v7mJD2n8 eMvHwPge36ARuQH3NT0prAB6ebLQK6vXgP77U9X92fxASep5ugYcsvjF8gpG8Aa5/6SypOzneMv 38u8iDxWYPAkAROxXnhWF2Bb8zD131BagfndEi32L8QBejTNQC4ysotEmcwGCS+mA6WOGmk3cdG cED9onIuQGUxqWMH/RAoOGFFmYjaVGX48LTtcMqgJ7pMTuRr6qZ3LuTDpSsfX0d+e/xg4BweACa iXr07MoG8ja0skquxQyoezg6P9wX+ZoE82Y8yQubuj7T4WSn6MR8K+KpdM2lxCmooEwopIGJBtv ShkKtUK45XQt0SInoMkpxk/xieiurrpKwJutDI/HWgg0bUBDQQrB/ns+aBIDZ317t5VB14C2yQL ndcUp5ypqre2pgCFUG67xEp46TboECCdysqnrDmzqPAyDPPqrAl93y40wMLfq7ioch1UsMunzpg ikoWn3rd1Q3hiM0b9xhOzHDv1JpxeZHf9PYgXkcl8KIcSAUdbLKE8deVkSnClCtpKhJgZrhRkTn n0IEVBzYq6mhxuJqeuqmZbpINfbdLGp5vug35kHYMDgbeR4FcVxisohlFtyiP8c//uTpsT+vqew N7wwW8wUVdT3bQAp2ADL1F7xZ+Y3mfYmVBgdWxl35iJM/AVMVa+utu X-Received: by 2002:a05:6808:2220:b0:572:e8eb:36a6 with SMTP id 5614622812f47-57a0bc9d273mr5655190b6e.56.1795223487680; Fri, 20 Nov 2026 17:11:27 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:27 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:46 -0700 Subject: [PATCH v11 23/26] dt-bindings: mtd: sunxi: require the H616 AHB reset X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-23-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev Normal NAND reads and writes worked on H616. Fault injection exposed a failure when recovering from an aborted internal DMA transfer: the controller's soft reset could leave the first subsequent read displaced, sometimes without an ECC error. This was not observed during ordinary I/O. The controller needs its AHB reset to stop internal DMA and restore data ordering after an aborted transfer. Require resets and reset-names for the H616 compatible so the binding describes the reset needed for recovery. The in-tree H616 SoC description already supplies the named reset. Older descriptions that omit it were valid under the previous binding and do not describe the reset needed after a DMA abort. Signed-off-by: James Hilliard Acked-by: Krzysztof Kozlowski --- Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand= .yaml b/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml index 9d061e2216cb..ccf616fabc91 100644 --- a/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml +++ b/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml @@ -119,6 +119,9 @@ allOf: minItems: 4 clock-names: minItems: 4 + required: + - resets + - reset-names =20 examples: - | --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223495; b=RCUGS94OPR7ncAGGvJFePBMugldYFboK6rdNExUZlBkXH4dri0AMmFdXqG54ARrSwIa8 XTXkep7J7FuVwTGQel0hRsb9gSzxdJSIsrT0I6QzRvevBX9xSg6Km3kSn1Bvntqc32r+W y+LPOOfKRkgMxfYI7XZDdXUvA1kGv1SrAi88iAMWaxG5nLd9az1oFWlLnQ5JKcyhqEsfO vcwsa8IoaTj8V0Ji+EGqZs4qvwTI+J6zDzX+3SJxMEy1+bna4P2UZN1RqB5Md69S//Zoe h25bJWLEmLwc/L8skVlx/KJP/QKsBUyw7Txg6+UbpcPfeJYKLzl4WKUuDcrcyQL71jA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223495; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=0eYZ3HbDY5x5zovptu6rAgNNSCJghwXhmaa/sCZVI9o=; b=4x5dPNcyynOGSdjsCkw122dLeys1keer6vv4ibMcrGOAcwB7UNZCGtTxqQdNdYoOOMpQ DyGwZUTh28djN+LeXQ0EJLz10EW9mG6yB2unXk3/htoTvBnjRK2dJzRCm0AlELLySUYm2 iGrCbvMqg4bLh/ucXe7CE5bxnyhAMDaCzp56DfB7X63ai0Rx5Cs/CY1p6eagr+TbfOQ84 PeTG9R6FrtS7hS6hiUHVXiF4aaAUO/9btE60QvOAIR0DxeMHidZLEnVzZjiXYtegRqvdG CVygDFqe7Dtc6vuOL/R6U119B+ESlgo3my3pRAFYjkhtBzSOVYH+p8Se5i0BGLJOtTA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=YNIJWlNY; arc=none smtp.remote-ip=209.85.167.180 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6EB19606AA3C for ; Sat, 21 Nov 2026 01:11:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6EB19606AA3C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=YNIJWlNY Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-5642e0910a3so742054b6e.0 for ; Fri, 20 Nov 2026 17:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223489; x=1795828289; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0eYZ3HbDY5x5zovptu6rAgNNSCJghwXhmaa/sCZVI9o=; b=YNIJWlNYrZWMgThgHVAkvnAx6pGKGCaMz6jSW4hSVycXtY7uP1wmnPN5QamROLVjWu NgHLGAm+KwdKOACZLrS4GUmNA5gQUEfTqFiL/aYjCaZjM8cMmW0Hgz3Q3EuGG378OS3b bV8Zww7ReJBmEIJagsUBjEtLBIN9RMgTY9tZ/heVnql3yoOKG1ge11Ix3NOEScWqksIY r0e0bI0ml70ibaCMVyU2J7NUV0QWUzXBUeFnHoppaWU4HCdYM4GDBOeItAXsULltrvIS mBfbTYAw9MevtRfFgb1kyyNXuiEjb3XTDE4k1k/LrUJ0KVb7leQcBafjZdYeoPdKyyKh jGsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223489; x=1795828289; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0eYZ3HbDY5x5zovptu6rAgNNSCJghwXhmaa/sCZVI9o=; b=VnC1shU0l/w2+7JCZIYg+CDq0Ts0SEAx1sR7NoJVIjpU5U1EqaOH8KfRLD31CWxnvh zIpF/PM0uB5LNyJPzuRww3sRvbyQLAWBYH6gbKmINHPCk+Un1q+3WypxV5SMQpo3QxB5 tPIbarQ8dWvbu9GpIAn9A69SqDQWYNPycdOQUf2VwymxurAhMGHJKcZNQ+Mh9p1iF+h2 jvi5LsHbT4O7LWfzPJKV7L6jVgqCQHYyP+6a+Xn4BhKmmP+lZ3omsCSW9JQHBI/01s1M GfAR43FVP3Dg7yQY1513bQQbwSVuUcmMoIIzrICNL3x06/UYmhdS5bVKogqp1SFDU6zQ hLug== X-Forwarded-Encrypted: i=1; AL+hErEG3/IiRybhP+CVzjTbHbzI/ReEx/qk/NxjLRkyVmm/y7EfIRc7xEItgxj1KaKEuK9nVphJUeX78ZgNaQU=@vger.kernel.org X-Gm-Message-State: APuU4Z9ARUyofaQmiCqHKLQrf0MH+orizwUx3U9U00cSruVn2Mocse0o JpnL3ta0IWamKxhuhpphOR25BurieDyMopVMv9s9CIQZ0lKXLapEGIfx X-Gm-Gg: AYBFou0zZYnSHLAL7YkwcCOvdsRxFJ9nimie9/TiDOD6hn2xFoWQOSNTeXXJ7ChA/Jn 9ZDKdoZtN8hI4AK3tRHxsKEeRU3ZR6V4EyTL1YihDdnZUfuS+ftk7f17ok+MMOuAgFN3UtxdXqr YdvRRFshvFxqDB+cN+B4heTaVtTD94VO2AP6QoelfCd8FFmmyL3XqVknf4aUNNmgieIW1MUhYT8 owKIN9EczcR1Pqplq8R9HeB1wsHqpOQPrBwBOmZn7P+izJx4f3Zagj2hvtVXOif+ChxYEyCFIGq l1lUtdBIHbITmvxf/VP7DIJND4rELK19U8cDtdpAtLXkDhCM7LrtZB76idPqyOfGp80fmF+miLO Fa1wOfcYvc4lfWae2am9Pygr4rxyQf6sN2PZ9++TE3zCKarWvSeGkMYS1B9As1kzlIy3cD732iR nnpviEDWizoyZrQ+MH6hDlxaPX2wihdvUhriQbVOUpNwOrsdVkhiQFsB7jCjq2OyisNma39bHc0 byiVAz2VorYQNizb18wNkrwCboKz3rinmhz1Qba6mPVdx4TeK4HZE/+4+FLaQ52BIuKtmJwsKG3 Wwg3jcc/zsYulCzSJqEZewQHTD4UZQlSakbj7a32sOLlOFlVnk1KFkxExI5kFle4cET4sf0MtH6 Nvcr9sONYiWx1dLlMsNII341GNldGroglWuj9R9SE1wO/osBxRnxHMip3ixKNjGEqHDGyG/dmde /V5Ei/L98XBThnIOkbVJ9mM5McFjULDro+nReGCpfrzZSvn/gAru7r X-Received: by 2002:a05:6808:4f1f:b0:4bc:fbd4:2a43 with SMTP id 5614622812f47-57a0bb6eea6mr5839190b6e.41.1795223489248; Fri, 20 Nov 2026 17:11:29 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:28 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:47 -0700 Subject: [PATCH v11 24/26] mtd: rawnand: sunxi: reset the H616 data path after DMA aborts X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-24-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev Resetting an active H616 MDMA read with NFC_CTL.RESET can leave the first 1 KiB of the next read displaced. Both raw and ECC reads are affected, including reads for which ECC reports success. Reissuing the NAND read command and restoring the visible controller configuration do not correct the internal data-path state. The DMA read error path can therefore return incorrect data when it retries through PIO. Pulse the controller's exclusive AHB reset after stopping an H616 DMA operation. Drain interrupts before resetting the registers and clear the pending events before accepting another command. The next operation selects its chip and restores the page layout and timings; reads retry from a fresh whole-page setup, while interrupted writes return an error. Require the AHB reset at probe and exercise it before accepting transfers. An H616 device tree that omits the named reset will no longer probe, including for PIO reads and writes. Perform the AHB reset before releasing the DMA mapping. This relies on the H616 CCU reset callback, which asserts and deasserts the reset through register updates and returns success. The reset handle pins the provider module, and the CCU driver suppresses sysfs unbinding. If recovery fails, return the reset error without retrying the read in PIO. Leave the IRQ disabled and reject subsequent NAND commands before accessing the registers. Error propagation is not a substitute for stopping DMA if the supported reset provider contract is violated. Select the stronger recovery through H616 capability data, leaving older controllers' abort sequences unchanged. Fixes: 5ee37db34637 ("mtd: rawnand: sunxi: add H616 MBUS DMA support") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 98 ++++++++++++++++++++++++++++++++---= ---- 1 file changed, 81 insertions(+), 17 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index abea2ab0cc42..a722636f2e15 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -318,6 +318,7 @@ struct sunxi_nfc_user_data_layout { * @has_ecc_block_512: If the ECC can handle 512B or only 1024B chunks * @has_ecc_clk: If the controller needs an ECC clock. * @has_mbus_clk: If the controller needs a mbus clock. + * @needs_bus_reset: Aborted DMA needs an AHB reset to restore data orderi= ng * @layout: protected user-data layout for the controller * @reg_io_data: I/O data register * @reg_ecc_err_cnt: ECC error counter register @@ -346,6 +347,7 @@ struct sunxi_nfc_caps { bool has_ecc_block_512; bool has_ecc_clk; bool has_mbus_clk; + bool needs_bus_reset; const struct sunxi_nfc_user_data_layout *layout; unsigned int reg_io_data; unsigned int reg_ecc_err_cnt; @@ -389,6 +391,7 @@ struct sunxi_nfc_caps { * @use_mdma: use an internal MBUS DMA backend * @mdma_desc: H6-style MBUS DMA descriptor * @mdma_desc_dma: DMA address of @mdma_desc + * @recovery_failed: reject further operations after unsuccessful recovery * @caps: NAND Controller capabilities */ struct sunxi_nfc { @@ -409,6 +412,7 @@ struct sunxi_nfc { bool use_mdma; struct sunxi_nfc_mdma_desc *mdma_desc; dma_addr_t mdma_desc_dma; + bool recovery_failed; const struct sunxi_nfc_caps *caps; }; =20 @@ -621,16 +625,50 @@ static void sunxi_nfc_dma_op_cleanup(struct sunxi_nfc= *nfc, struct scatterlist *sg) { dma_unmap_sg(nfc->dev, sg, 1, ddir); + /* Do not access controller registers after failed recovery. */ + if (nfc->recovery_failed) + return; + writel(readl(nfc->regs + NFC_REG_CTL) & ~NFC_RAM_METHOD, nfc->regs + NFC_REG_CTL); } =20 -static void sunxi_nfc_dma_op_abort(struct sunxi_nfc *nfc) +static int sunxi_nfc_dma_op_abort(struct sunxi_nfc *nfc) { - if (nfc->use_mdma) - sunxi_nfc_rst(nfc); - else - dmaengine_terminate_all(nfc->dmac); + int ret; + + if (!nfc->caps->needs_bus_reset) { + if (nfc->use_mdma) + sunxi_nfc_rst(nfc); + else + dmaengine_terminate_all(nfc->dmac); + return 0; + } + + /* Drain the handler before resetting its registers. */ + disable_irq(nfc->irq); + writel(0, nfc->regs + NFC_REG_INT); + readl(nfc->regs + NFC_REG_INT); + + /* A soft reset alone can leave the first subsequent read displaced. */ + sunxi_nfc_rst(nfc); + ret =3D reset_control_reset(nfc->reset); + if (ret) + goto failed; + + writel(0, nfc->regs + NFC_REG_INT); + writel(NFC_INT_MASK, nfc->regs + NFC_REG_ST); + readl(nfc->regs + NFC_REG_INT); + enable_irq(nfc->irq); + + /* The next operation selects the chip and restores its timing and layout= . */ + return 0; + +failed: + /* Keep the IRQ disabled and reject commands after failed recovery. */ + nfc->recovery_failed =3D true; + dev_err(nfc->dev, "NAND controller recovery failed: %d\n", ret); + return ret; } =20 static int sunxi_nfc_select_chip(struct nand_chip *nand, unsigned int cs) @@ -642,6 +680,9 @@ static int sunxi_nfc_select_chip(struct nand_chip *nand= , unsigned int cs) u32 ctl; int ret; =20 + if (nfc->recovery_failed) + return -EIO; + if (cs >=3D sunxi_nand->nsels) return -EINVAL; =20 @@ -1464,8 +1505,14 @@ static int sunxi_nfc_hw_ecc_read_batch_dma(struct na= nd_chip *nand, nfc->regs + NFC_REG_CMD); =20 ret =3D sunxi_nfc_wait_events(nfc, wait, false, 0); - if (ret) - sunxi_nfc_dma_op_abort(nfc); + if (ret) { + int abort_ret =3D sunxi_nfc_dma_op_abort(nfc); + + if (abort_ret) { + sunxi_nfc_dma_op_cleanup(nfc, DMA_FROM_DEVICE, &sg); + return abort_ret; + } + } =20 sunxi_nfc_randomizer_disable(nand); sunxi_nfc_hw_ecc_disable(nand); @@ -1514,7 +1561,7 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct na= nd_chip *nand, u8 *buf, return ret; =20 err_stats: - /* The caller retries the whole read in PIO mode. */ + /* A PIO retry must not count completed DMA batches twice. */ mtd->ecc_stats.corrected =3D corrected; mtd->ecc_stats.failed =3D failed; return ret; @@ -1648,6 +1695,7 @@ static int sunxi_nfc_hw_ecc_read_page(struct nand_chi= p *nand, u8 *buf, static int sunxi_nfc_hw_ecc_read_page_dma(struct nand_chip *nand, u8 *buf, int oob_required, int page) { + struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); int ret; =20 ret =3D nand_read_page_op(nand, page, 0, NULL, 0); @@ -1656,7 +1704,7 @@ static int sunxi_nfc_hw_ecc_read_page_dma(struct nand= _chip *nand, u8 *buf, =20 ret =3D sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, oob_required, page, 0, nand->ecc.steps); - if (ret >=3D 0) + if (ret >=3D 0 || nfc->recovery_failed) return ret; =20 /* Fallback to PIO mode */ @@ -1677,6 +1725,7 @@ static int sunxi_nfc_hw_ecc_read_subpage_dma(struct n= and_chip *nand, u32 data_offs, u32 readlen, u8 *buf, int page) { + struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); int first_step =3D data_offs / nand->ecc.size; int end_step =3D DIV_ROUND_UP(data_offs + readlen, nand->ecc.size); int ret; @@ -1686,7 +1735,7 @@ static int sunxi_nfc_hw_ecc_read_subpage_dma(struct n= and_chip *nand, return ret; =20 ret =3D sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, false, page, first_st= ep, end_step); - if (ret >=3D 0) + if (ret >=3D 0 || nfc->recovery_failed) return ret; =20 /* Fallback to PIO mode */ @@ -1828,9 +1877,10 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct na= nd_chip *nand, else ret =3D nand_prog_page_begin_op(nand, page, 0, NULL, 0); if (ret) { - sunxi_nfc_dma_op_abort(nfc); + int abort_ret =3D sunxi_nfc_dma_op_abort(nfc); + sunxi_nfc_dma_op_cleanup(nfc, DMA_TO_DEVICE, &sg); - return ret; + return abort_ret ?: ret; } =20 /* exec_op() restores the page's spare base during column changes. */ @@ -1856,8 +1906,14 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct na= nd_chip *nand, nfc->regs + NFC_REG_CMD); =20 ret =3D sunxi_nfc_wait_events(nfc, wait, false, 0); - if (ret) - sunxi_nfc_dma_op_abort(nfc); + if (ret) { + int abort_ret =3D sunxi_nfc_dma_op_abort(nfc); + + if (abort_ret) { + sunxi_nfc_dma_op_cleanup(nfc, DMA_TO_DEVICE, &sg); + return abort_ret; + } + } =20 sunxi_nfc_randomizer_disable(nand); sunxi_nfc_hw_ecc_disable(nand); @@ -2794,11 +2850,18 @@ static int sunxi_nfc_probe(struct platform_device *= pdev) } } =20 - nfc->reset =3D devm_reset_control_get_optional_exclusive(dev, "ahb"); + if (nfc->caps->needs_bus_reset) + nfc->reset =3D devm_reset_control_get_exclusive(dev, "ahb"); + else + nfc->reset =3D devm_reset_control_get_optional_exclusive(dev, "ahb"); if (IS_ERR(nfc->reset)) - return PTR_ERR(nfc->reset); + return dev_err_probe(dev, PTR_ERR(nfc->reset), "failed to get AHB reset\= n"); =20 - ret =3D reset_control_deassert(nfc->reset); + /* Exercise the recovery reset operation before accepting DMA transfers. = */ + if (nfc->caps->needs_bus_reset) + ret =3D reset_control_reset(nfc->reset); + else + ret =3D reset_control_deassert(nfc->reset); if (ret) { dev_err(dev, "reset err %d\n", ret); return ret; @@ -2908,6 +2971,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_h616_cap= s =3D { .has_mdma_desc =3D true, .has_ecc_clk =3D true, .has_mbus_clk =3D true, + .needs_bus_reset =3D true, .reg_io_data =3D NFC_REG_A23_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_H6_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_H6_USER_DATA, --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223494; b=hoZtnkRjooYGSl53/ehECyzIHQDHrdGKs2hh/hm3z2FDsAF9j3tnLtrLO6wQ4rCWiHVF 53UXI3ULdGZYh6TGnH+YoaAJmvY2lSrsvzY8R+LSyCaB0tBtBOnyHzhT44eTobdqtj7tz HORw3ssrkhVOAsb6pRzpBQT+MInw+8vh/T+wEuive/6J5JAe1B9DEYlXMQpyItgo57IOx EtCfTQ72z/Xf3YeyUyy+bfcZWH9TftgMs3alOoScqfwLR8DPqFrEXfHrWAWPV3uffxHjN FwDSh9BUF8BjGmHbJC8kvdOgDiu6Bri/hQZjmAqEnGQAex7qsg9Bsaf9T6JK0VJgd+g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223494; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=J6dsf3PUVYR2e83j22FZDt4Y383GBQ5T4kYYqbMeWQw=; b=VR+o/nmbeU5kU6GI/JQCWdQqYLejc7xkgVP1b6/t5tWHp9kbsOxojl+kqW02f3pJZMqM zVGJM7+HSrMAl6fguHlHfuZVCad891IlAjJSKMFxjN/InhqATC5eS3vyd+v5PBv3Yks/Z HqbgLQeNeUgHZthJMxTFsjGzCCrp+Ek7Xd5tGTbX4xhaM1jQ4o4YhkhvfQqgG/8HGB58+ VjmF0XCxHdA+CgdwzkjM6ei1lkIX/xe/98+oy8Blx0t3QICS1+ONzHJXZkeEJQBWQWfoS CsfOZVku1OibcpauXtV8iBcKTSg1YjSy4/m3zEsF0aEJAYDyxtDR2La9rhSwutsyhRQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=M6GFfhyL; arc=none smtp.remote-ip=209.85.160.45 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40F01606C504 for ; Sat, 21 Nov 2026 01:11:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 40F01606C504 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=M6GFfhyL Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-4911df1e196so894501fac.1 for ; Fri, 20 Nov 2026 17:11:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223491; x=1795828291; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=J6dsf3PUVYR2e83j22FZDt4Y383GBQ5T4kYYqbMeWQw=; b=M6GFfhyLFW8DfjOvMdmqy3bxHtPqmLNc1P/sPXfNpid+YMsXYXx2W6kwsHGz/s14bJ 90m3+0VN453mvcXZZYPC1QM+vvgEmh8iyRS+nyoNlq8V8K2PJlr6NP8/rfrf9wMER4dT JOdIV4mMvw2csNul0wmJB05rF+SCskD2TyD6BM8oEiK1+FbNZFvILijq31mrFnl8LqjP UAB/4GFznlBBUiVRR/wjFqDvE1G3VoTgtRhAkbtqLZlZbJQtC46cBz8v4EW5JYQlASUb IdQAw9YO9XRXsBZ5a6KTQpJU8RMiMGyOrwseXxxOVY+kNb3nApwzhzu+ix59tNTWFOKl C0Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223491; x=1795828291; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=J6dsf3PUVYR2e83j22FZDt4Y383GBQ5T4kYYqbMeWQw=; b=cmJC0CyRGNiccXR1VJaJD3aZAGX5xAY7TcMfLXErTFIRrDxTxuMF3sr9PHcJrT6ihO Ub1BATdvzEohotiVZlmEHTvZO/NpqCADVMsf9Kr3pmcWOPfndwjjTqE6N56N5r45nraq NK/+kTPqbDHUlOZlq0AA+0TeFdIv/130IzTyW37VKHS2JeujubqQnt19PGGJ5pn8sWhS 0eJlWv93+s0jz2kepkNtypsqPb2EHMD6MCENigrpe/Dh9RH3sv7a8LiSNvsmpjcVJEBa rlpeQlh5uA99mmZpg189eMb67aiNqXfGcThyk7aX82dK9yQk3VuU0z+Nr9WQw/9OM7B3 ej3w== X-Forwarded-Encrypted: i=1; AL+hErHrJ+CkpKuHTDmUVCmDQj5CHpvVyzxnZ7Rmv7wrO9wfSyian6Or0s5f+3RD7msZTp0NPi5Bo0PLxq7q2CA=@vger.kernel.org X-Gm-Message-State: APuU4Z9uD4LCNzRNrt7QPPgFHLKnQuwdk9PU1pfAUqXw924HX0Gngpmg MaOPCdjR+HksoUtSrgkJYrSkbCcf5RZR0ZpYCKgQ32NnW60GZAW0JMjc X-Gm-Gg: AYBFou3PPqd8vYho6CCUcOx9lBrEVugO2nr5kyIbQFq1zS3p49jtxhxWykQ/EgYqZD9 L3r1Jb/WhcHY5tZeJtwcQ2YteBLBC9I74xGlj8aKF3jlN7Qqj8/6EnORW+lZC3cr/Y2bzSu2MIn liLKMpgeRZBPmWvfvxc8fNWG2X7RgW9H4XPJ3ewZkK09NCt47yztsUNFOWwDiSloFT1r1rWM9BM 6DH7XfcU8TAgHL2taJmi/8fknGJRsU6mt1jEBUKfUEbsqu8TEXRf9jGEa5CU7UP78ZJ/gws+0KP eQ1dSPwPOASgPC96hkz5NwCx6an2DWi24BjL7bqVqDuaJlt+MbnkaC9Jhr1iY+ABQ6opI16+Ev0 9MnGEu1JqFhaR4egfnMTvyZ03ghO6IgBm+nUulvnAw1FirrlFTrTqkD1OIMeDj6xlCLsK8vQKgu lzdFipfGJNBWZzzk8WODtTkpLRi2Tgdn5qgIMTePa96GgLeMyAhOGA9I7Kiu2jLRHbI/CXAp8Dv nxQJbKkdvPoI1qJoNR7RHf5sWM+qZwFOkKzVkOkDvM4JwUsHJlZp/yONPkpH+ghzJ2uZVq6hNac UobEP2ed7tT8kfHUJw98ui1RypDnFe7OpgbKjW4/5pFEBLPDMkLYD95f6f4+eusok/Ix/XcXFcD Q0IEcJmWmh50rgCjETwYeT3tAVF5FFbQctWdj++D0aCnmsnm7lxWl7yYmPkWFt9f/qsE7N2ZbMD pGpctWDooOzOHsLK/ZzQqeVIIzG3IYbPQmcd9hDcT+aOUUI5vzFJaPgNyphDw4DadRPPGk6+3Xc g== X-Received: by 2002:a05:6808:f07:b0:571:846e:6f08 with SMTP id 5614622812f47-57a06c1b05bmr5537864b6e.5.1795223490849; Fri, 20 Nov 2026 17:11:30 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:30 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:48 -0700 Subject: [PATCH v11 25/26] mtd: rawnand: sunxi: reuse ECC status within each transfer X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-25-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev The pattern ID register describes all slots in a completed transfer, but the driver rereads it for each matching step. Four consecutive hardware slots also share one correction-counter register, which the driver rereads for each ordinary step in that group. Take a fresh snapshot for each PIO step or DMA batch. When the controller places the pattern-found bits in the ECC status register, use the same read for both. Read the pattern ID at most once per batch if any slot reports a pattern without an ECC error. Read each packed counter word only when a slot needs it and reuse it for the other slots in that group of four. Consume the results before starting the next ECC transfer. Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 87 ++++++++++++++++++++++++++++-------= ---- 1 file changed, 64 insertions(+), 23 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index a722636f2e15..37f01801cf48 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1166,12 +1166,56 @@ struct sunxi_nfc_ecc_read { bool read_raw_bbm; }; =20 -static unsigned int sunxi_nfc_hw_ecc_read_count(struct nand_chip *nand, in= t slot) +/* + * Transfer-local ECC results. Consume the pattern ID and correction counts + * before issuing another ECC transfer. + */ +struct sunxi_nfc_ecc_snapshot { + u32 status; + u32 pattern_found; + u32 pattern_id; + u32 count_reg; + u32 count; +}; + +static void sunxi_nfc_hw_ecc_read_pattern_id(struct nand_chip *nand, + struct sunxi_nfc_ecc_snapshot *snapshot) +{ + struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); + + snapshot->pattern_id =3D readl(nfc->regs + NFC_REG_PAT_ID(nfc)); +} + +static void sunxi_nfc_hw_ecc_read_status(struct nand_chip *nand, + struct sunxi_nfc_ecc_snapshot *snapshot) +{ + struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); + u32 pattern_found; + + pattern_found =3D readl(nfc->regs + nfc->caps->reg_pat_found); + snapshot->pattern_found =3D field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern= _found); + if (nfc->caps->reg_pat_found =3D=3D NFC_REG_ECC_ST) + snapshot->status =3D pattern_found; + else + snapshot->status =3D readl(nfc->regs + NFC_REG_ECC_ST); + /* A new operation, including every PIO step, invalidates the count word.= */ + snapshot->count_reg =3D ~0U; +} + +static unsigned int +sunxi_nfc_hw_ecc_read_count(struct nand_chip *nand, + struct sunxi_nfc_ecc_snapshot *snapshot, int slot) { struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); - u32 count =3D readl(nfc->regs + NFC_REG_ECC_ERR_CNT(nfc, slot)); + u32 reg =3D NFC_REG_ECC_ERR_CNT(nfc, slot); =20 - return NFC_ECC_ERR_CNT(slot, count); + /* Four consecutive DMA steps share one error-counter register. */ + if (snapshot->count_reg !=3D reg) { + snapshot->count =3D readl(nfc->regs + reg); + snapshot->count_reg =3D reg; + } + + return NFC_ECC_ERR_CNT(slot, snapshot->count); } =20 /* @@ -1275,7 +1319,7 @@ static int sunxi_nfc_hw_ecc_read_extra_oob(struct nan= d_chip *nand, /* Interpret one PIO step or a completed DMA batch before reusing its stat= us. */ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand, struct sunxi_nfc_ecc_read *read, - u32 status, u32 pattern_found, + struct sunxi_nfc_ecc_snapshot *snapshot, int first_step, int nsteps) { struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); @@ -1286,6 +1330,9 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip = *nand, unsigned int reg_index =3D 0, user_data_sz; int slot, ret; =20 + if (snapshot->pattern_found & ~snapshot->status) + sunxi_nfc_hw_ecc_read_pattern_id(nand, snapshot); + for (slot =3D 0; slot < nsteps; slot++, reg_index +=3D user_data_sz / 4) { int step =3D first_step + slot; int oob_off =3D sunxi_get_oob_offset(sunxi_nand, ecc, step); @@ -1297,16 +1344,15 @@ static int sunxi_nfc_oob_read_batch(struct nand_chi= p *nand, if (step < read->first_req_step) continue; =20 - if (status & NFC_ECC_ERR(slot)) { + if (snapshot->status & NFC_ECC_ERR(slot)) { /* Preserve PIO data before the raw erased-page check. */ if (!read->dma && !randomized) memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, ecc->size); continue; } =20 - if (pattern_found & BIT(slot)) { - u32 pattern_id =3D readl(nfc->regs + NFC_REG_PAT_ID(nfc)); - u8 pattern =3D pattern_id & BIT(slot) ? 0xff : 0; + if (snapshot->pattern_found & BIT(slot)) { + u8 pattern =3D snapshot->pattern_id & BIT(slot) ? 0xff : 0; =20 if (!read->dma || randomized) memset(data, pattern, ecc->size); @@ -1320,7 +1366,7 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip = *nand, continue; } =20 - bitflips =3D sunxi_nfc_hw_ecc_read_count(nand, slot); + bitflips =3D sunxi_nfc_hw_ecc_read_count(nand, snapshot, slot); =20 if (!read->dma) memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, ecc->size); @@ -1353,14 +1399,14 @@ static int sunxi_nfc_oob_read_batch(struct nand_chi= p *nand, sunxi_nfc_hw_ecc_update_stats(nand, &read->max_bitflips, bitflips); } =20 - if (!(status & NFC_ECC_ERR_MSK(nfc))) + if (!(snapshot->status & NFC_ECC_ERR_MSK(nfc))) return 0; =20 /* Finish consuming the batch's corrected OOB before raw error rereads. */ for (slot =3D 0; slot < nsteps; slot++) { int step =3D first_step + slot; =20 - if (step < read->first_req_step || !(status & NFC_ECC_ERR(slot))) + if (step < read->first_req_step || !(snapshot->status & NFC_ECC_ERR(slot= ))) continue; =20 ret =3D sunxi_nfc_hw_ecc_read_error(nand, read, step); @@ -1402,10 +1448,10 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_= chip *nand, unsigned int user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, step); struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); struct nand_ecc_ctrl *ecc =3D &nand->ecc; + struct sunxi_nfc_ecc_snapshot snapshot; int data_off =3D step * ecc->size; int oob_off =3D nand_to_mtd(nand)->writesize + sunxi_get_oob_offset(sunxi= _nand, ecc, step); int page =3D read->page; - u32 pattern_found; int ret; =20 if (*cur_off !=3D data_off) { @@ -1441,12 +1487,9 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_c= hip *nand, =20 *cur_off =3D oob_off + ecc->bytes + user_data_sz; =20 - pattern_found =3D readl(nfc->regs + nfc->caps->reg_pat_found); - pattern_found =3D field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); + sunxi_nfc_hw_ecc_read_status(nand, &snapshot); =20 - return sunxi_nfc_oob_read_batch(nand, read, - readl(nfc->regs + NFC_REG_ECC_ST), - pattern_found, step, 1); + return sunxi_nfc_oob_read_batch(nand, read, &snapshot, step, 1); } =20 static int sunxi_nfc_hw_ecc_read_batch_dma(struct nand_chip *nand, @@ -1457,10 +1500,11 @@ static int sunxi_nfc_hw_ecc_read_batch_dma(struct n= and_chip *nand, struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); struct mtd_info *mtd =3D nand_to_mtd(nand); struct nand_ecc_ctrl *ecc =3D &nand->ecc; + struct sunxi_nfc_ecc_snapshot snapshot; struct scatterlist sg; int page =3D read->page; int ret, i; - u32 status, pattern_found, wait; + u32 wait; =20 if (first_step) { ret =3D sunxi_nfc_read_column(nand, page, first_step * ecc->size, @@ -1522,12 +1566,9 @@ static int sunxi_nfc_hw_ecc_read_batch_dma(struct na= nd_chip *nand, if (ret) return ret; =20 - status =3D readl(nfc->regs + NFC_REG_ECC_ST); - pattern_found =3D readl(nfc->regs + nfc->caps->reg_pat_found); - pattern_found =3D field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); + sunxi_nfc_hw_ecc_read_status(nand, &snapshot); =20 - return sunxi_nfc_oob_read_batch(nand, read, status, pattern_found, - first_step, nchunks); + return sunxi_nfc_oob_read_batch(nand, read, &snapshot, first_step, nchunk= s); } =20 static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *bu= f, --=20 2.53.0 From nobody Tue Nov 24 16:51:21 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223497; b=haSAwaBc0J0DwIdzwmdGKqrQFuMCLSUQsrq5GAI6EgG5XTvd4rQKBfYTNtwJcTwV4zD4 SRJWBaRtrLNKlGgBD0UQf2BRRgGL8c36tg4xugLchNFjWnogdCL9FxSQHxoDmIUDoxXOG X8JtLlEtDfgC+YRCc/qKL3fZZJpGdZ31A503hwUhzKb7BYQNTyARRoO6h1LOMwVd+aLbI v9DkI/Xh6O7GfqcuyWirCdvNs31FgWL/5u6psjIZMtWmXNjf1iEPwyHINb1Ttrfrx49EY XOYoD1Zp3dt0gv7jdWUCFlCKVcB1vYfqHT45e2ckPoYJ0TpmPSFF9cVoYF8UL7/wuQA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223497; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=3n0HsVfrCilvrywczliXObPQ3Hlxg0mpvZCNssFAoKg=; b=C/7EBNaDqyVkASHhoRvvdrei8eCF/lFT2+jRmz3jcbfsUMUjE5dvW1fBYSRrWX/IbAZD 7k3aLOvo3cMjqNFCkhHgwpauIi4lZg1yMJ6IDOWWliHZ/P+7b9rjN+VTUF6aaF/akX4iO 8NcP1BxsUaT452xZ/doDZF6xEmIuZoleUh5lY/UeAV4g6NH3D3h6UanGkAlRnsGRuE9Ms eh87yq+hqLNo+I1kWkceeag0yt4fDkhS09r3puA0IDQtoDwQEthj8pwbaw048nJ423mnV TgSYLG/0g+BzKcF63HijZnmHi+Um5SOMvBkWzFRxwiiztTfJRTbExrHhL00PKOG2GZw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=kXsb1HRm; arc=none smtp.remote-ip=209.85.167.172 Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 879E9606C51A for ; Sat, 21 Nov 2026 01:11:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 879E9606C51A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=kXsb1HRm Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-57728d859e9so756088b6e.1 for ; Fri, 20 Nov 2026 17:11:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795223492; x=1795828292; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3n0HsVfrCilvrywczliXObPQ3Hlxg0mpvZCNssFAoKg=; b=kXsb1HRm0z+DeTVpYv6IhvZkuBux7zkDW0H+eyUhG3WPdO2pLBZgRi+Y1sT+hZFGBJ khShRCN+z37iHVI6UYNV1hC+UQ31kK8pdFXY9yBPBVxnjT7fojGV641RO/RfYElC9apO D9fkHivqmDxXSzcgQ+GDUA6/9zLpJ5ud5VNeJryzsn/wWXq4eU1xYPizKhrNvaPQAVIy sHltgbROh3SG6u+LRjpP4YtjGYuDel9nkuVJTg7LQIKijmzyU+6JIjsh69fwbVrVvV91 Pzljix0PiF7yV1aHfmuMT2dlqTUB97TQfpIE7LSI5VeyjtwjeLvncBizDAoL1FygAHa2 mhBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795223492; x=1795828292; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=3n0HsVfrCilvrywczliXObPQ3Hlxg0mpvZCNssFAoKg=; b=k2k31IH3Q+7bkbZnXnOs4WQlW6ntzty7bsh0lWmfuTVZbG0RoM8mVp2UVbECQ6LE2K S/EaU63V2fXRUznv0gcob+AjVFO7HjD/zIpOlhwHij8bGECaX+UIwJzZldUX+Iowci6Y ll1+umHGjpX/TDcrOVWFrENlOtn+LahfcavLCPkwjRAIITa6owddMIz+K6odAEqD0jZP UQ2yA9ihyEYjv2i6J6R2J5JfH90TI8TNjoqDdm6/cBbehgByxmFVr9CdBvqwuwRc0gxX OzD+LtAV3141LG0zfsDh8OHM/cowCrJBk8fV7/P8NWnjELxKRKUmmOLlZdtA2s3Ds5lI tIRw== X-Forwarded-Encrypted: i=1; AL+hErHh9jQBFgDalvCVfYK/4Bs5NPvMA656ua4RG7HcDdgJt1wxBr0Q4aRd3qDwync/GM8MomhG26swqx4kjHg=@vger.kernel.org X-Gm-Message-State: APuU4Z844HCxyNKzdXaJ8cZbXIlUxZtjARcKxW48dfnal9QRd0f3PRLH hiW9bdhaOuUqLg8QMBmfm7VZofHLLyHc6XaCWUaiQxcC2RHA6OYy63KQ X-Gm-Gg: AYBFou3+VVayTguvP1nSM42BqW2A4MExshexbbtwEIfhdUSe510S4CGILH0uIvv6ifm VbUhHaYSspsWKayUIVJGtWhGdNagNgUv9SmI3I9omGz3dkmu6oW6pL7mKxJ9L+fHbUpkrbXm86o SSjme2jobySaDfkJydBKNCVzWlT8fKKGGAIfV8ZkyND3B63RMHAdhKxQNRQeT5kZvDHtcHOwy/Z 2y559zpoQwjmYoclUqg/bXmA3I7215opbn0+/LsgFBsjDnatD5i31/kxhBbHigw6EHFFjp0Nft2 4Gv87F1fVFompNK+4uuTFqN+qnRVjolnZG8xWHNxzxB0irDBsWEvAEutpSk3hRvy1BWZMBl0XRJ Zl7U2EdiPaeKDZCuTMipTjswWbflc8ryxN0Hln/NU2aTGGTNYSHpKQZTmSkKk5Y3sDa+MJInvTr 0qqhZgkzr6p6ytnLRBSXxQmvjJpDwaj2cpsRV+xGC54/oiTx1UlP3cMmNRCPBU+2NZrkM0taiNS gl74e8Aew/EdMWGrAW2VnYCtWlLdfwrWnal+fEnAskMwzUtB/xZrhrQ2OprkRAHuoUtCpzAL6pv sLbBaO8vT4zDhEYXVeU0b08Rkbpb52IHcNe/JQk1f7vfO4LRIggfbnnm21hzq/NJtlW4pLI+qMj /vj8EdVkQxMjYB53lg16qnYl1iTPRSo2r0WFMI+VwD0ElFEnSdebkRTnczDNZSR6dhtrWM+nuRV 6yZY3bvg5wXoVCxXebBrahcja08Z+IPGtcj56oAYezc9apCUlVAYWS X-Received: by 2002:a05:6808:508f:b0:576:1161:cfeb with SMTP id 5614622812f47-57a0d4ed405mr6123275b6e.66.1795223492380; Fri, 20 Nov 2026 17:11:32 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a3485e3ecsm3291532b6e.9.2026.11.20.17.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 17:11:31 -0800 (PST) From: James Hilliard Date: Fri, 20 Nov 2026 18:10:49 -0700 Subject: [PATCH v11 26/26] mtd: rawnand: sunxi: reduce user-data length register accesses X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-26-9721b1905ef4@gmail.com> References: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> In-Reply-To: <20261120-submit-sunxi-nand-vendor-oob-layout-v1-v11-0-9721b1905ef4@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , James Hilliard Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.17-dev H6/H616 pack eight ECC steps' user-data length codes into each 32-bit register. DMA currently clears all these registers, then read-modify-writes one field per step, repeatedly accessing the same words. Each code counts four-byte words; zero means no user data. Build each packed value in memory and write it once per DMA batch, including zeros for unused slots. Take each length from the batch's logical step but encode it in the corresponding batch-local hardware slot. Rewrite every register on each batch rather than caching values across resets or changes of chip. Use the same encoder for PIO. Each step writes the first packed word with only slot zero set, so page setup only needs to clear the other words. This also clears stale DMA slots before PIO uses the registers. The lengths and on-flash layout do not change. Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 59 ++++++++++++++++++++++++-----------= ---- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 37f01801cf48..31f995a1f5d8 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -57,7 +57,7 @@ #define NFC_H6_USER_DATA_REGS 32 #define NFC_REG_USER_DATA(nfc, x) (nfc->caps->reg_user_data + ((x) * 4)) #define NFC_REG_H6_USER_DATA_LEN 0x0070 -/* A USER_DATA_LEN register can hold the length of 8 USER_DATA registers */ +/* Each USER_DATA_LEN register holds eight 4-bit ECC-step user-data length= codes. */ #define NFC_REG_USER_DATA_LEN_CAPACITY 8 #define NFC_REG_USER_DATA_LEN(nfc, step) \ (nfc->caps->reg_user_data_len + \ @@ -1061,10 +1061,7 @@ static void sunxi_nfc_hw_ecc_get_prot_oob_bytes(stru= ct nand_chip *nand, u8 *oob, sunxi_nfc_randomize_bbm(nand, page, oob); } =20 -/* - * On H6/H6 the user_data length has to be set in specific registers - * before writing. - */ +/* The first PIO step overwrites the first packed word; clear the rest. */ static void sunxi_nfc_reset_user_data_len(struct sunxi_nfc *nfc) { int loop_step =3D NFC_REG_USER_DATA_LEN_CAPACITY; @@ -1073,7 +1070,7 @@ static void sunxi_nfc_reset_user_data_len(struct sunx= i_nfc *nfc) if (!nfc->caps->reg_user_data_len) return; =20 - for (int i =3D 0; i < nfc->caps->max_ecc_steps; i +=3D loop_step) + for (int i =3D loop_step; i < nfc->caps->max_ecc_steps; i +=3D loop_step) writel(0, nfc->regs + NFC_REG_USER_DATA_LEN(nfc, i)); } =20 @@ -1088,10 +1085,8 @@ static int sunxi_nfc_user_data_len_code(struct sunxi= _nfc *nfc, int len) return len / USER_DATA_SZ; } =20 -static void sunxi_nfc_set_user_data_len(struct sunxi_nfc *nfc, - int len, int step) +static void sunxi_nfc_set_user_data_len_pio(struct sunxi_nfc *nfc, int len) { - u32 val; int code; =20 /* not all SoCs have this register */ @@ -1102,11 +1097,35 @@ static void sunxi_nfc_set_user_data_len(struct sunx= i_nfc *nfc, if (code < 0) return; =20 - val =3D readl(nfc->regs + NFC_REG_USER_DATA_LEN(nfc, step)); + /* PIO uses only slot zero. */ + writel(FIELD_PREP(NFC_USER_DATA_LEN_MSK(0), code), + nfc->regs + NFC_REG_USER_DATA_LEN(nfc, 0)); +} + +static void sunxi_nfc_set_user_data_len_dma(struct nand_chip *nand, + int first_step, int nchunks) +{ + struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); + struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); + int first, step, len, code; + u32 val; + + if (!nfc->caps->reg_user_data_len) + return; =20 - val &=3D ~NFC_USER_DATA_LEN_MSK(step); - val |=3D field_prep(NFC_USER_DATA_LEN_MSK(step), code); - writel(val, nfc->regs + NFC_REG_USER_DATA_LEN(nfc, step)); + /* Write each packed register once, including zeroes for unused slots. */ + for (first =3D 0; first < nfc->caps->max_ecc_steps; + first +=3D NFC_REG_USER_DATA_LEN_CAPACITY) { + val =3D 0; + for (step =3D first; step < nchunks && + step < first + NFC_REG_USER_DATA_LEN_CAPACITY; step++) { + len =3D sunxi_nfc_user_data_sz(sunxi_nand, first_step + step); + code =3D sunxi_nfc_user_data_len_code(nfc, len); + if (code >=3D 0) + val |=3D field_prep(NFC_USER_DATA_LEN_MSK(step), code); + } + writel(val, nfc->regs + NFC_REG_USER_DATA_LEN(nfc, first)); + } } =20 static void sunxi_nfc_hw_ecc_set_prot_oob_bytes(struct nand_chip *nand, @@ -1474,7 +1493,7 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_ch= ip *nand, if (ret) return ret; =20 - sunxi_nfc_set_user_data_len(nfc, user_data_sz, 0); + sunxi_nfc_set_user_data_len_pio(nfc, user_data_sz); sunxi_nfc_randomizer_config(nand, page, false); sunxi_nfc_randomizer_enable(nand); writel(NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD | NFC_ECC_OP, @@ -1503,7 +1522,7 @@ static int sunxi_nfc_hw_ecc_read_batch_dma(struct nan= d_chip *nand, struct sunxi_nfc_ecc_snapshot snapshot; struct scatterlist sg; int page =3D read->page; - int ret, i; + int ret; u32 wait; =20 if (first_step) { @@ -1524,10 +1543,7 @@ static int sunxi_nfc_hw_ecc_read_batch_dma(struct na= nd_chip *nand, return ret; =20 sunxi_nfc_hw_ecc_enable(nand); - sunxi_nfc_reset_user_data_len(nfc); - for (i =3D 0; i < nchunks; i++) - sunxi_nfc_set_user_data_len(nfc, - sunxi_nfc_user_data_sz(sunxi_nand, first_step + i), i); + sunxi_nfc_set_user_data_len_dma(nand, first_step, nchunks); /* exec_op() restores the page's spare base during column changes. */ if (first_step) writel(mtd->writesize + sunxi_get_oob_offset(sunxi_nand, ecc, first_step= ), @@ -1645,7 +1661,7 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct nand_c= hip *nand, =20 sunxi_nfc_randomizer_config(nand, page, false); sunxi_nfc_randomizer_enable(nand); - sunxi_nfc_set_user_data_len(nfc, user_data_sz, nfc_step); + sunxi_nfc_set_user_data_len_pio(nfc, user_data_sz); sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, nfc_step, bbm, page, user_data_sz); =20 @@ -1900,7 +1916,7 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct nan= d_chip *nand, goto pio_fallback; } =20 - sunxi_nfc_reset_user_data_len(nfc); + sunxi_nfc_set_user_data_len_dma(nand, first_step, batch_steps); for (i =3D first_step; i < first_step + batch_steps; i++) { unsigned int user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, i); int oob_off =3D sunxi_get_oob_offset(sunxi_nand, ecc, i); @@ -1908,7 +1924,6 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct nan= d_chip *nand, =20 sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, reg_index, !i, page, user_data_sz); - sunxi_nfc_set_user_data_len(nfc, user_data_sz, i - first_step); reg_index +=3D user_data_sz / 4; } =20 --=20 2.53.0