From patchwork Sat Nov 21 01:10:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4201 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 974CB1C5D65 for ; Sat, 21 Nov 2026 02:11:13 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-27940-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-27940-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 9A36D31051 for ; Sat, 21 Nov 2026 01:11:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223462; b=vQ6I9Ivh/hWibkOMl07raTl579SEJCYDWnRGHL+CnYVM01C6ugpeCLgEvU9bFOqAEVWT WOi+sMMCJnvg57qC5Jh9NhWaZXQG83tvlCEqs5ukG2liFvzI6HHkS20h9duFHuCKBAXpB 40z5uDr1RMzCtfIc2S2X6yEe70yKDcsXDnJQi7gARoWu5jrpbeck5MVHrMBp3GDLnSay1 lDv48/PBUCk4/gb7ILdOftZNtYRr+DVku5BylAVU5zIle/q7khpF8EtvjJpHnJsl90aBG inqvxbrYg69YW6M+gHMxSSjmLTgE+u7lDCbXWZtQ18NA2muugIV5fOwpo0ypCtN9kJQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223462; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=SRAIIk9U6fp4Kf8B545qVrRs6kaxTJjBXvTeCKe8iRc=; b=xX0Ws1wTOqKp+6y0Eb+waQFHgQW1L6rQ4w93fqh/AiTjXvxe3K+7gZGVbTpd0TenD+rm Pe9Gdv59XLU14z60KEuHZfIdJan2l+Ux804jP4BytqDlj4VtRp93VUbXyrRaXH/yZNFfX IEeBrdiWzlPyc/AMALuX89V8nMV2OEGH5Y4C99IbUFSi7IOJYR0bd8vb5NnCtr/LhnjIM vrm0f11q343BTgEtGlGiQO9BITYH3/4ataSSSxmiFTjUg3hjl2+6WgzViD5E2eZ5CfHSs CH3vkYrjnj5+f43dxmMopfn8mtuP2KggI12lQ/jyy9Re05KF0rmHgOg9YXcIQUYgIXA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KTx+2wHS; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86F5160A2606; Sat, 21 Nov 2026 01:11:02 +0000 (UTC) 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=KTx+2wHS X-Original-To: linux-sunxi@lists.linux.dev 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=1795223462; b=D6z3s3ckaGhGZpqaqsGwyszdpHrx1skeQUqx0XdEOyob7QHPZSSTfiA9LVSiYDkg37bZ aTL4ktDDQoSOLoabKODUyw3tVhNJwJOel92CW6voASafeuZkEH3AfMxlZN1LUW5GGaC/6 mdbXdf4O3TyOODHwy2y1Ac/fCWzn0daKaYp/h9pxM460TDoqNXndrW/IQZTZGSiRYndFL 16PBosFnKGE8KFpdJ1XmxpiVrUy26yVo2GaSwukgeQW0fMWWvOQMXotD8O8Ez6SaJeYeS SrKzQQqOiLYsW3kZDqKAdn+7vTebLT1hChGyiLJ8M30AOzfa3shbDk4YLbQlpONEVgg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223462; 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=Tf/TRhheATRgp+TztVLSfsT5gC6zs1Eum6imbmEJnYB/ru4OZoNryuLE1qBRUTP7Kunm wyDa0xba7zxda6Z4nKJb8LZaKnYmNGwOTiHGlTbmpJmIQFtC7AbOIPJiB8BBQU0WimgIf vg1z6x+1Uz8ipxUUiIep7/H5DpLitCz8/WMO99OQFbkhu3oINanKVpMbzja0GfMbjIJxM eR6Yx4yT0FDxAONvKhvY2quWatVh0jFukpWoI5GKNI2RFEvv8JZhq1cwpgSswURX3+5wv 3sKPXa62Tx1aA1nSOFRMtj2iTVtsRIBW3KsA/4rkpplXaHruM98U8iDalFBlkrdtkvg== 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=KTx+2wHS; 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 938D560A2602 for ; Sat, 21 Nov 2026 01:10:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 938D560A2602 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 Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-49429181ce9so962259fac.0 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=lists.linux.dev; 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=KTx+2wHS+6ar3aiNpQTLPjpCpwYr56+ArPxMzC8izjXBOf8XtyfdpAnT6yXZRUR6Rh B4cBRjJB93irqUQGADV8cJEXwEbmvKFpuV9g/s1WwybRqlkDtfPOsnyDfI70xRlgy6F8 L86rwGA44sXfEjyGC86wrjN3QTN05tAW+0ivwuE+8inoHaBQCmc3qUQ17tvnli1/bfej iYVhsK8HgrJKLIjme1whpL1qIH5FB9nXFRSM+xCUbfM6tg0vtyb/U23myuwlWrSbCKwU Jvf8exLChR7quoYUpX7NuLOMJiD5useXZE9rQpDJxQO3KOhO7lgqXT/RHEBxhxZMPwHx Aw7Q== 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=gIwHC0/Di37mXrKCDl3KcZqRWSjpkvBZifI7JqBptM5xwlW7zWYoKyLeOOV+OyCRQ9 nXJpz3lpzZeaD4zgYUE4ZSWWjCeUxFBv1Ew8jJKf7Vg96sqHimG1n+e/neuKICIZopc+ jl0Qg2D9PrGaLf943M7reNyqMUM9ozOFJd4r6tZIDojFpw11P5ACuQjEdE7FtWO/UkMX BW4EPmuRybF/wFQLTb6gBdXFBpKoUOcqMAlncc9IFRXs9Dh7MAGA7vH2/JPV4xWqotq/ ZC1wqwEy/8qEopsI5SY601g3ZeYZ4TTonqdWa0CVGxHMqvX5iULxGeXdDH0Twtyxv9/Q a7zg== X-Forwarded-Encrypted: i=1; AL+hErGWKBWlpF2Nx8F7oi5yp8x1yFCOYOKsnmT1pC8RLY/ARDpJUNfIGFekl6RMAQWGLchMMuY5SEEiyd6A0Q==@lists.linux.dev X-Gm-Message-State: APuU4Z/7lnykk4OwmufuZ+x6F+KfEScsxiVS6AdPLZy5nfjdOm5IVC0M 4dwRGrFgJ6p/RjmGr5tCNdqKSKz8Ijh6UdwcCMn3qwbcHpTayb4d/b09 X-Gm-Gg: AYBFou3wIo7wMx8YAnatwHUAKrUfZwJIXgiN9aJD75Bh3vlqIJenh8bwkzRAM9UU2vc IypOKeo9T7eJX6wMt0tLJ1fE86Va14QjVYUoq4JCv7lx19Kh4OiOxuUHa83o+jFTtWlKbPgLRmo JbRGmW8l4Fh4sO9v+LHOdNcyHv6tV+FxzMFxUtUcuR6rzg2I5m55tdaDR3NLBslB7qvb9IzVepO cpr11ZWamrBHWgWzETWqa7ZHvGx96g+cTNOcHPBt+bhi85eRl6O+fHVOYW3v1lVoaGpIfyVl8hB sIqEhRCJjCQR1/h9YoNEbhppGwZf6Bxy/Xq3X848Ys+xJInKLyC4K1ednKMDbrWbBjXBFwLvFnW 5VsvoZjyr3uXsdvs+P3JfnsbpDP1jdPLNtPyeJBxUyEQ1ZjHyuB/h5keetJKED9DGulrjSvxZ30 l3tFyMUJOYeZ6znPy8x/IbiONCqAWAzyBE+uH4bpBQ0y+5C+X1MHgU9Aw/cieVfe8LlaV6itS/R 8CO2UycP5q5B5+Cc1WnEblXb7jsMPGXQhmWuLV+CbO+AEOJfzickj4LikgZbL9J6aqj8NxnWEvR HlTFERAPdqqJa4yJNEb7R0daSJMgbVNW9dBchsMFEqoC8hUeAnA6Pw/HtqizRnpCsBBUWDIwXzb 8RdS3Wcm8hyzormkNvDaNCmC3AIsoPB56ZfikiBF8oLUsEcXFEQ7JduRR5HTViNsjiURcJiumaw 7vRUksyNynR5MOGfd7YusZfZBKeRJIUKiUnbfZX+yg6fiAlPqLTDy2 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [4.31 / 15.00]; RBL_SENDERSCORE(2.00)[172.105.105.114:from]; SUSPICIOUS_RECIPS(1.50)[]; ARC_REJECT(1.00)[signature check failed: fail, {[1] = sig:subspace.kernel.org:dns request to arc20261015._domainkey.subspace.kernel.org failed: query timed out}]; MAILLIST(-0.18)[generic]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; TAGGED_RCPT(0.00)[dt]; BLOCKLISTDE_FAIL(0.00)[209.85.160.44:query timed out]; RCPT_COUNT_TWELVE(0.00)[25]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; DMARC_DNSFAIL(0.00)[gmail.com : query timed out]; FORGED_SENDER_MAILLIST(0.00)[]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; FROM_HAS_DN(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[174.29.1.49:received,100.77.114.92:received,209.85.160.44:received]; RCVD_COUNT_FIVE(0.00)[6]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; MIME_TRACE(0.00)[0:+]; TAGGED_FROM(0.00)[bounces-27940-noreply=patchwork.local]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from] X-Rspamd-Queue-Id: 974CB1C5D65 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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); +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 capabilities * 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 bytes - * 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 = NULL; } -static int sunxi_nfc_maximize_user_data(struct nand_chip *nand, uint32_t oobsize, - 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 nsteps) { struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); const struct sunxi_nfc_caps *c = nfc->caps; - int remaining_bytes = oobsize - (ecc_bytes * nsectors); + int remaining_bytes = nand_to_mtd(nand)->oobsize - nand->ecc.bytes * nsteps; int i, step; - if (nsectors <= 0) + if (nsteps <= 0) return -EINVAL; - sunxi_nand->user_data_bytes = devm_kzalloc(nfc->dev, nsectors, + sunxi_nand->user_data_bytes = devm_kzalloc(nfc->dev, nsteps, GFP_KERNEL); if (!sunxi_nand->user_data_bytes) return -ENOMEM; - for (step = 0; (step < nsectors) && (remaining_bytes > 0); step++) { + for (step = 0; (step < nsteps) && (remaining_bytes > 0); step++) { for (i = 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; } +static const struct sunxi_nfc_user_data_layout sunxi_nfc_fixed_layout = { + .min_user_data = sunxi_nfc_fixed_min_user_data, +}; + +static const struct sunxi_nfc_user_data_layout sunxi_nfc_variable_layout = { + .min_user_data = sunxi_nfc_variable_min_user_data, + .init_user_data = 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 = to_sunxi_nand(nand); struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); + const struct sunxi_nfc_user_data_layout *layout = nfc->caps->layout; const u8 *strengths = nfc->caps->ecc_strengths; struct mtd_info *mtd = nand_to_mtd(nand); struct nand_device *nanddev = mtd_to_nanddev(mtd); @@ -2083,33 +2109,7 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, ecc->size = 1024; nsectors = mtd->writesize / ecc->size; - 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 = 0; i < nsectors; i++) - total_user_data_sz += 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 -= 2; - - bytes -= 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 -= USER_DATA_SZ; - } + bytes -= layout->min_user_data(nsectors); /* * 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; } - /* - * 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 = sunxi_nfc_maximize_user_data(nand, mtd->oobsize, - ecc->bytes, nsectors); + if (layout->init_user_data) { + ret = layout->init_user_data(nand, nsectors); if (ret) return ret; } - if (total_user_data_sz == 0) - for (i = 0; i < nsectors; i++) - total_user_data_sz += sunxi_nfc_user_data_sz(sunxi_nand, i); + for (i = 0; i < nsectors; i++) + total_user_data_sz += sunxi_nfc_user_data_sz(sunxi_nand, i); 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 *nand) const struct nand_ecc_props *requirements = nanddev_get_ecc_requirements(&nand->base); struct nand_ecc_ctrl *ecc = &nand->ecc; - struct device_node *np = nand_get_flash_node(nand); int ret; if (nand->bbt_options & NAND_BBT_USE_FLASH) @@ -2254,7 +2247,7 @@ static int sunxi_nand_attach_chip(struct nand_chip *nand) switch (ecc->engine_type) { case NAND_ECC_ENGINE_TYPE_ON_HOST: - ret = sunxi_nand_hw_ecc_ctrl_init(nand, ecc, np); + ret = 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[] = { static const struct sunxi_nfc_caps sunxi_nfc_a10_caps = { .has_ecc_block_512 = true, - .legacy_max_strength = true, + .layout = &sunxi_nfc_fixed_layout, .reg_io_data = NFC_REG_A10_IO_DATA, .reg_ecc_err_cnt = NFC_REG_A10_ECC_ERR_CNT, .reg_user_data = NFC_REG_A10_USER_DATA, @@ -2748,7 +2741,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_caps = { static const struct sunxi_nfc_caps sunxi_nfc_a23_caps = { .has_mdma = true, .has_ecc_block_512 = true, - .legacy_max_strength = true, + .layout = &sunxi_nfc_fixed_layout, .reg_io_data = NFC_REG_A23_IO_DATA, .reg_ecc_err_cnt = NFC_REG_A10_ECC_ERR_CNT, .reg_user_data = NFC_REG_A10_USER_DATA, @@ -2769,6 +2762,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a23_caps = { }; static const struct sunxi_nfc_caps sunxi_nfc_h616_caps = { + .layout = &sunxi_nfc_variable_layout, .has_mdma_desc = true, .has_ecc_clk = true, .has_mbus_clk = true, From patchwork Sat Nov 21 01:10:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4202 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 4B0741C7AFD for ; Sat, 21 Nov 2026 02:11:22 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27939-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27939-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 049BC46F7A for ; Sat, 21 Nov 2026 01:11:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223461; b=oEK2X+8GaANnBbLHEX7yJOP2HWwtipb6HVJcWX1Fj24J5IZaYoISCYzGofWcYTlNcHE2 TQR5yRlWklwK1448U/q4t5rMzRcM5BCHM4zU5wr6eRJnqESFy8jL+Ge+r3l7lhRj/t02K r7MjFXFj9MqbRNi+LgG2eNaHvAKU7CKPDvIPm9DFZkgAIWG5rkMcp6fgXAoGByCK8PQuk gO/h4FBAtKZcPnsX2Vd0FoyglADqPRjsoinuAmOAvQVwaYTAtzvYNrAZ+dsa+RuE0Yknj mOowz3hhRAnNJWjFywRwfSZWUbPguvb9UW4fC07oBAzSuz8/VCaleKwVfAyZaUQaJaw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223461; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=8/B8gGukZxMNCk9kG+bQ03cwup62u0VomkG0JFdqRS0=; b=xACCiBJnayPnFEeb3pXW7JXOhc+qtIjCAmbx8tiKeUJhgMZNGrjReDPhrS5ZPW9/TyrO ngRJOHNXXN8YC28opIbNNEkMotLyCzqqG+8o5/izIS69gG4BNM/dp9ZO8EWuBkH1dSuSg XglGDxCVFphLD+D3CM2UvQRnpCQxPF7zzRDdwDPPorlyEq5oRTdXUMUC+RX21jV3cbFM1 GDrvdb/uBwc+deK4iroBQHIDSlTQ+WqOOnLOBw+y2XJ1H8gEIWP3S7067XvyOVEEWtvML 2awshJgxdjkIgeKseG+Fqvf+m7B2wRfuwUjsOJgk+uDwycXFPKCvPeSRr0FvsPfmItw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=lxYFEE2Q; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E2D860A2604; Sat, 21 Nov 2026 01:11:01 +0000 (UTC) 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=lxYFEE2Q X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223461; b=cnIy02a1fXBDRwabiHZRlXGr44DdKywGFrg1EtmpueAB0/GUElHP2C24VCBYy1Cboeev DZgpBu4T90woHld37zQBf1bo5W/PkJfyMg3G8lBSv9lVN6KnFqj5HJGX6eoPnBjyp/MaF 2q3NfipflbWJzt6Gsm3fMOaNr2UVBmHiPFoDSN6NalRQZCng2UmMHg4t8vHFpr7ZnSN5E uWc6DjSM3uYFfndeXsVOpmwpRJ6F4jVlV/EEartJXZm+suybCe1BAVcAGJBV7c0NiVsn3 LfSehMlMUUofYD/vjEVAMRjnpcF4d+vYIsn4yKJgLl1LLYGNtOXpfOI/6Fyqz1+yZqw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223461; 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=ui/QOCsjouF5oS9xt2KNoN3iWTUt2q99bOH0BIFfNiGH/tyE/6FlC3Nk8/SJMRWb4D/F i7ZqPM4ZZAZSlcNqQVTYyjtuPIcImufxyluIFJaE7Rt+FIOmDZZrl51Ihqc6qvJlco3ef 7sOsyEggmg35AXT5s8kuDPmIHN9Bkp9a8iCVc9cSFSV2wKPurhk548xw+343ofHLaUOLs pobwfb5fw1FZ6Sb1xTP8ZNxg+eYD2GkdNagatJsT9izIS3MTHlXMAtfr+cBdMRLZVg/fV ifdDd5wmkrkbC0TAnMLDh7ZoE9SMgYJyg+01bhfFkDIv3eefj+OkWVJjzQcSR2UCLtw== 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=lxYFEE2Q; arc=none smtp.remote-ip=209.85.210.41 Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (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 3C036606A6B9 for ; Sat, 21 Nov 2026 01:10:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3C036606A6B9 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 Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-862a19300b7so583563a34.2 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=lists.linux.dev; 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=lxYFEE2QTJ0dop1GVTr3RgEd5lXVpIeJDxoQ4PsMmjH4fds1kZFx4wL/j4utqfXR2u dXIRSUV4Fro/Qx3WQ1PQ6L3tqGsMicRtxvu7xc1n0CxYNry3heVsXN/3gI00r6hzJsEw d1FESDDnKgAl1Khxn3w1QQBc312y9cscYkR7wbJSJpaWBY0Q9VmgBj4UHL5kmOehttZe OrN8tk64XJG7xV7JHNPOXR/NmIWxFnBkajplLnkb3aABJYyuWwz50TaX+IWadAiQj/1M Hp/yQUs4ydGKr1Z6/v27BnP8bbXm95TV7qsAoFO1JMzxZ0QkYu5uyKbVc/TxvaBQEJqR T1mw== 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=ZQ4xuFhSuw36Q8eiSMK4Hm9uGoevZ1Fcj39pHkpOpqhcIM9BmWypo4MmSlb1Eni4e8 LY5nJ5RUqPXs7a1FWEt9/SZxPuth2a4/5Hf2kbgrNnUKQ+4p7IseWExlHGAFx+E2tRqr XXKILgS+xPnog4a0g5hHvRa3cxxQWeMaJDUavurEznxVxSVkViHdLKZcBB6tP0nXJ6ic 9zSDvfE4IGAl9g9a+70RjRviOdO0wQZD9O27cjq+8086tuBWvgaRoINFjf3kvY6/q6hq GcufIvpT/puBDrw5FfQGFX/iK4Tor2nS/XpC8Ht45SVDwARjDAfZ5B07kCesWgnQCQdV xOTg== X-Forwarded-Encrypted: i=1; AL+hErEQkT1xTPi52MwTbQsXiZ5y7wVTi++HFYKvPT9QY3/TyqLaPPlv8Twt5Rls74anLCEoqq9bCqjvFz5WpA==@lists.linux.dev X-Gm-Message-State: APuU4Z+wYn9zMZSn3rpAbfU8zZaJHQjavINbSKBjGRoWchdUh4MV89Ji aFacOPOcgeh6fmBU4aCodc8Nhv5rvu2YZkO14go575zHjr5cxSBnWQEJ X-Gm-Gg: AYBFou3nuM9yXzqQzFLOlqZscVMpqLhsZioR7KCfLmEdjpoXuIAfqgdIsijBWER+u0e 5fGNp20Bdosyh6DpYRRYlrMP9sK09jCWw3mkTZ/r4UxkIP8LpiTuz7QckKmmEIfdgornbk7l/t1 GXZtVwhWmhoRQNtzYtJ2XZaQ8MW/8N3/wtCxaxo0xZGgKaFfdB4jVoupCrlY60p97kyrqNwUkNO Tr8ZjqA7Rk3iK4XUmm3TJIR2dTBl9t7Kr8rnhOYchyFLxCsg3fx/Z+2A5VMZmgT0hqq90SLpdIJ nUiXSgxd18nkfYTHcxVX96wQ8cFjbvUsAcma1tKmbAgMsqn+HhJIdTRrdOtjm/TuQMBhWcN31PZ fBuZjbNuvU4RwS6wyLkrpRGgMWtvDAVK6mGjNVWMo9L9W7N7ICjeuBsj/QCKaMzTN8KpQIY+CQr wrrm6SmAVzATPXNlEt+6Em/A7jcDfEiZDOrIRjb7AYm3lwyphOGPe4CGaqsjZUFxfldqa/UaElP WvSff9ufexXYx01GvgWP/Gl1J0bTg4jsgR2FIWctMS88AoGA5RCDybfto/H6iMojARBp41cC/IU khJ0fInxXu69eFj3WRpgdh8lBDdZjKv6IhcIwztc78jZjASgViVGHfFqC6KoIZ+ymVvTJgpp3uy Xl4wUVUs2wM6WYvw1JoVudwPOoocZs599b5Jbe1bBFxh3Mj71jWTd7rD0wlug/pXO5BTEGVnDjC I+KFrabek6wLj/YHYxxWnFnydo9Cg+XD98DisH8dKl0CPGjxXD4lt2FUAYLWJ90XUmfVMmz3kaN Q== 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FROM_HAS_DN(0.00)[]; TAGGED_RCPT(0.00)[dt]; RCPT_COUNT_TWELVE(0.00)[25]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FORGED_SENDER_MAILLIST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10:c]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,174.29.1.49:received,209.85.210.41:received]; RCVD_COUNT_FIVE(0.00)[6]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; MIME_TRACE(0.00)[0:+]; TAGGED_FROM(0.00)[bounces-27939-noreply=patchwork.local]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from] X-Rspamd-Queue-Id: 4B0741C7AFD X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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 register - * 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); } -static u8 sunxi_nfc_user_data_sz(struct sunxi_nand_chip *sunxi_nand, int step) +/* Earlier ECC steps take their full share before later steps use any bytes. */ +static unsigned int sunxi_nfc_user_data_before(struct sunxi_nand_chip *sunxi_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); +} - return sunxi_nand->user_data_bytes[step]; +static u8 sunxi_nfc_user_data_sz(struct sunxi_nand_chip *sunxi_nand, int step) +{ + return sunxi_nfc_user_data_before(sunxi_nand, step + 1) - + sunxi_nfc_user_data_before(sunxi_nand, step); } 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 sunxi_nfc *nfc) writel(0, nfc->regs + NFC_REG_USER_DATA_LEN(nfc, i)); } +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, USER_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 = false; u32 val; - int i; + int code; /* not all SoCs have this register */ if (!nfc->caps->reg_user_data_len) return; - for (i = 0; i < nfc->caps->nuser_data_tab; i++) { - if (len == nfc->caps->user_data_len_tab[i]) { - found = true; - break; - } - } - - if (!found) { - dev_warn(nfc->dev, - "Unsupported length for user data reg: %d\n", len); + code = sunxi_nfc_user_data_len_code(nfc, len); + if (code < 0) return; - } val = readl(nfc->regs + NFC_REG_USER_DATA_LEN(nfc, step)); val &= ~NFC_USER_DATA_LEN_MSK(step); - val |= field_prep(NFC_USER_DATA_LEN_MSK(step), i); + val |= field_prep(NFC_USER_DATA_LEN_MSK(step), code); writel(val, nfc->regs + NFC_REG_USER_DATA_LEN(nfc, step)); } @@ -1204,13 +1211,7 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_chip *nand, static int sunxi_get_oob_offset(struct sunxi_nand_chip *sunxi_nand, struct nand_ecc_ctrl *ecc, int step) { - int ecc_off = step * ecc->bytes; - int i; - - for (i = 0; i < step; i++) - ecc_off += sunxi_nfc_user_data_sz(sunxi_nand, i); - - return ecc_off; + return step * ecc->bytes + sunxi_nfc_user_data_before(sunxi_nand, step); } /* @@ -1221,8 +1222,7 @@ static int sunxi_get_oob_offset(struct sunxi_nand_chip *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); } 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 = to_sunxi_nand(nand); unsigned int user_data_sz; - /* - * 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 >= ecc->steps) return -ERANGE; @@ -2023,15 +2020,6 @@ static const struct mtd_ooblayout_ops sunxi_nand_ooblayout_ops = { .free = sunxi_nand_ooblayout_free, }; -static void sunxi_nand_detach_chip(struct nand_chip *nand) -{ - struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); - struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); - - devm_kfree(nfc->dev, sunxi_nand->user_data_bytes); - sunxi_nand->user_data_bytes = 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 = to_sunxi_nand(nand); struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); - const struct sunxi_nfc_caps *c = nfc->caps; - int remaining_bytes = nand_to_mtd(nand)->oobsize - nand->ecc.bytes * nsteps; - int i, step; + const struct sunxi_nfc_caps *caps = nfc->caps; + unsigned int oobsize = nand_to_mtd(nand)->oobsize; + unsigned int parity = nsteps * nand->ecc.bytes; + unsigned int available; - if (nsteps <= 0) - return -EINVAL; - - sunxi_nand->user_data_bytes = devm_kzalloc(nfc->dev, nsteps, - GFP_KERNEL); - if (!sunxi_nand->user_data_bytes) - return -ENOMEM; - - for (step = 0; (step < nsteps) && (remaining_bytes > 0); step++) { - for (i = 0; i < c->nuser_data_tab; i++) { - if (c->user_data_len_tab[i] > remaining_bytes) - break; - sunxi_nand->user_data_bytes[step] = c->user_data_len_tab[i]; - } - remaining_bytes -= sunxi_nand->user_data_bytes[step]; - if (sunxi_nand->user_data_bytes[step] == 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; + /* Use as many complete words as fit after parity. */ + available = min(oobsize - parity, nsteps * caps->max_user_data_len); + sunxi_nand->user_data_step = caps->max_user_data_len; + sunxi_nand->user_data_total = round_down(available, USER_DATA_SZ); return 0; } @@ -2094,7 +2070,6 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, const u8 *strengths = nfc->caps->ecc_strengths; struct mtd_info *mtd = nand_to_mtd(nand); struct nand_device *nanddev = mtd_to_nanddev(mtd); - int total_user_data_sz = 0; int nsectors; int ecc_mode; int ret; @@ -2179,10 +2154,7 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, return ret; } - for (i = 0; i < nsectors; i++) - total_user_data_sz += 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; ecc->read_oob = sunxi_nfc_hw_ecc_read_oob; @@ -2413,7 +2385,6 @@ static int sunxi_nfc_exec_op(struct nand_chip *nand, static const struct nand_controller_ops sunxi_nand_controller_ops = { .attach_chip = sunxi_nand_attach_chip, - .detach_chip = sunxi_nand_detach_chip, .setup_interface = sunxi_nfc_setup_interface, .exec_op = sunxi_nfc_exec_op, }; @@ -2712,10 +2683,6 @@ static const u8 sunxi_ecc_strengths_h6[] = { 16, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80 }; -static const u8 sunxi_user_data_len_h6[] = { - 0, 4, 8, 12, 16, 20, 24, 28, 32 -}; - static const struct sunxi_nfc_caps sunxi_nfc_a10_caps = { .has_ecc_block_512 = true, .layout = &sunxi_nfc_fixed_layout, @@ -2781,8 +2748,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_h616_caps = { .dma_maxburst = 8, .ecc_strengths = sunxi_ecc_strengths_h6, .nstrengths = ARRAY_SIZE(sunxi_ecc_strengths_h6), - .user_data_len_tab = sunxi_user_data_len_h6, - .nuser_data_tab = ARRAY_SIZE(sunxi_user_data_len_h6), + .max_user_data_len = 32, .max_ecc_steps = 32, .sram_size = 8192, .timings = &sun50i_h616_nfc_timings, From patchwork Sat Nov 21 01:10:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4204 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mxe881.netcup.net (Postfix) with ESMTPS id 1092A1C7AF2 for ; Sat, 21 Nov 2026 02:11:28 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 104.64.211.4) smtp.mailfrom=linux-sunxi+bounces-27941-noreply=patchwork.local@lists.linux.dev smtp.helo=sin.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 104.64.211.4 as permitted sender) client-ip=104.64.211.4; envelope-from=linux-sunxi+bounces-27941-noreply=patchwork.local@lists.linux.dev; helo=sin.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id F34D4A270B for ; Sat, 21 Nov 2026 01:11:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223465; b=u/EgwUEI6wehuly/KY3KXeCPnvTRzhB36/99Wvsj908WviXFhGUrKi3YNqJJDuMW07Bx 6PfrGzp5HWeDO+ZU6tM6VZYXDnYw4XOFCgdPynvle3J6jKbj3/+h59yje4RqXeqTlIAuN LJBODcUaCgtbUI0EcA15jG5BdIawS62mMJqQH00hICMuIByB6oYepLqqVow21ilMHT9yU nzbtXkOgQBInLQAzrUHZODUqhlRNSoA8xqKqsh4dNWeMCvCG8B1t753LMVC7aB+gSB+eq gQfRuyUR6KpH4osPLing9WF0luiVdxWMFZnD8uH1FFtE4xcZDg9xx3JJLnzG0hRuPAw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223465; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=jSA/8+JIJhXyIE6wPAaPD1PdPonBWuUoA8eu4aZnEWs=; b=ej97iqfLK8/tcKiE0fyXN6meEmAKGwIQCbq/Ol7tGdqdXzTiAosY5QlhqJfPq0CBWdTU du61EBJpLAqEFHed/ZmVqV4eak2jTMSpM2YSF2SNvITJBTmcfQEaEDtJyZwrEYwG8vNxm gG9q5pC5DJ6tfqefPLkV34EelxEDzx0cgMAXT7wRl9ppeYlNBK1I7TEFi5v8zFJm9fz5c DCY8Qh2ag3sAC89v1SKT2o3AIu8Qzjr1k4CgMotPdscmhMuXlbnVuDCPsLmJD7F+6hl9O n7M5CqWKt2m8hf4B20nMWP54q8PwhoHCe57DA69FSBupNrxmeWeto9UfLK7HTgEAuMg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=m1As4qpf; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8C7D606A6B7; Sat, 21 Nov 2026 01:11:04 +0000 (UTC) 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=m1As4qpf X-Original-To: linux-sunxi@lists.linux.dev 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=1795223464; b=Biwoauh4QzzkY6/GEhzqEfXNWADNb+31763j4kbuxJ8Z6VOzudAPO6tBdqzebNdvY3Eq IIferY9c5Its/AJuJts0ShJWgORzcGGVYjBibsL9cSFXa7R7ApXFAs+BwrqYfnlPlvgyI kkw1JDgeqSu86Bwq1tEymgdr3uhZpm0A4+Sv0T3zz0ZNIkSkTxgbvzXLBiiFLyXBq6v5p 2l0WoTH3HBbOaOEfWu4PvJHjdHiB6OeMScTk7cxLJ9PZ5rKYiz8A/Wk285cPR94Vf1Wd+ DQHHTw4erud6n3tpo/x39BnFb2ob4pk5soaBxvYmiZuweQXpb6vsXWa9lEtF0hkktzg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223464; 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=U2LscvXQqaKGQnnTm4LS3dNmllK0XsVQxUppv/w/6mXN005H/VILyuLLbCV/Fe9aqFW4 WNKlRJW1dhBuaYAw4LuWEQyAX/P/4czq1c9vJamB6bvchSuoz71OFaxUPT5OCwwLSPu3V 1nam1amx02Sbv4p50dLD8S4357/G/LwdUf+zQjXTuUhUeY9T+KjoWa7XkMHxt+IH+iBWq BsRz0HW98zeyVc4GfCcqxF0SmuLbQShfIw0yhQVYbm4uvF28fEpndZCBoCbvYRz5Qeb/j 5KwAdaw4wiwvLaTZ+8iupdkCJ51xTPAmYI6tT1Y6jrKshlrRZnvdEr/f+b77TTCDPEA== 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=m1As4qpf; 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 E35B060A2618 for ; Sat, 21 Nov 2026 01:11:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E35B060A2618 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 Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-862b98b2e47so603907a34.2 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=lists.linux.dev; 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=m1As4qpflJ+C3sZEvBJEBV6xIJ+rWlUmqlaux1GbYpARafBuvNsCjf6xHJFPGlZO0Z E2ARTXJ73HH9r+/wRUBLeTWdQ2Eyl91YK8MupQNP7xJQLNIjVGjm44CQiehp46YzRDX3 WrAcxCjekaZdStGaefmOhWMe7xrbQaYjf+G52GkTQkFAZBXZQK7zSzwlyd2Tx8keC7G1 bqFsR4iOVINh7RzfRLTXPe9Ihx0T6UWeyKJ4UjdFTjqPWT/2SpN6AA60dEgqI0fD05Pc DuALUAqGDaKuG4M2hRkdrz7qo15gi5/wvm44a1FVbLej2OJAc6Wv23P3kYCJ55NXP1DX 8pAA== 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=LpMFzpIT+JdU/AFiX8jSM7717avGPvH2sEmaVzgDvL1dpjV0kvoqDyiPv2CLmEH7Em U46C5rIyiDaK39/EtrTRbmdnBAgvh9Cerchvv3LpkT18t4OPFAJdgDqDJMgFlvglSrET KLdy5yA1vKA05HA8DwngLlpqKeLHWryIMJW2I7zVsURGanq2qutE1AsGBaGFbzzQGkuy Xm5dmpgMGDlsqo1Lrr2TDRt/K+MD4gOvcETcOvQBGzHHDwdVvSbO5GrgDDGf4/2f/DeX TwgF1UeKKsojKlQxo8beWx83qVA2MET1FoxzJnoCgXIDoZxfr3t6atccqkKc3rjb01x2 xqkg== X-Forwarded-Encrypted: i=1; AL+hErFP2pBnbY/duSJwK9bVSwA/i074Qh7yyk/5NFckuH3qXZyI3lldk962iGK+K7er3ol9bVTzqETuDUaAyQ==@lists.linux.dev X-Gm-Message-State: APuU4Z+Z+wkO44d9C1S/UC3LwIt4EMNXksKJ6YbO6dY6tvxIVj8+12nS CT0GvdNMSU0n9G8cbM4ccMvW+6dtLIQ1veDbXxw8qHjejO56FOeN1UAG X-Gm-Gg: AYBFou2T2JK3fQT8QCfRbVnv7l8DxnL/mc76J40iHqfrgZDF214z8BRPCbUP6T2wFCE HiTD50pmJ01DmRmNK36vR0in8goZ85bjHDkb5ujc2kWFA69fShPLTi9aX59f4DgwcXcov62wNmG +AFKGcZhOXTjVUDkWYVzmPKJ+aJe6uXhApodweJaBvzhJ4Qr6Rwcrf5++Gyv0iIDBFtCzV/Y5XL DPJ244KAciQVYLOFa7tvmlgr7G4Vo5IBS+BzG35JNWU/WsUtcb9uWUt+VaJLr3AZFBcdkyaf24G Kpvm4L80ujhYoD+hiDl4nig78zShHKjH6pswvn+YxWGNPZArCEZneqi7YWban2PfAoKHQ1oZOa0 YhQKxDwcCUzAuQ0nf0m4TC1bS2joUsw5AKKSdDdo1vXaIjLFbwnJvIurJPRH/hcgsIUl/I5CXqG qUBBPvwQUnwuJqY45VBNL8+J6uAfWmTQgoNvN0njeUOFUZCwAMEk06eeuGD/SzII+dj+/suuEMy 8D0YqbVN5Uu1nMbroXjU5zUDLYofAKKcJgEvEsZiGwTWwiohlDRVuAmFyyyUbkyJm9fpBDfoSAI G7Uqscukpv+momy8IUz4Ts2DyKGMWqKU9UhxD76JSGEtTzLAFAPzgFo4/brzHmbkBf35DiwSMGN YhNX4APMoEyqbxa2K2X+IW68ZLDzLhBOr4aHmirRGXQwuja/pLQU1WEepOcRE57MmRLZfNn0FrH E5eTHZcDIBAR4kJCfWmHsQNog2oFvfAzv1cfUBj3mNV1rzW2mtAKbh 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[104.64.211.4:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; TAGGED_RCPT(0.00)[dt]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; RCPT_COUNT_TWELVE(0.00)[25]; DBL_BLOCKED_OPENRESOLVER(0.00)[sin.lore.kernel.org:helo,sin.lore.kernel.org:rdns]; RCVD_COUNT_FIVE(0.00)[6]; ASN(0.00)[asn:63949, ipnet:104.64.192.0/19, country:SG]; R_SPF_ALLOW(0.00)[+ip4:104.64.211.4:c]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,174.29.1.49:received,209.85.210.47:received]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; MIME_TRACE(0.00)[0:+]; TAGGED_FROM(0.00)[bounces-27941-noreply=patchwork.local]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 1092A1C7AF2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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); } +/* 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 nand_chip *nand, } } +/* 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); } -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 = to_sunxi_nfc(nand->controller); - struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); - unsigned int user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, step); - struct nand_ecc_ctrl *ecc = &nand->ecc; - int raw_mode = 0; - u32 pattern_found; - bool bbm = !step; - bool erased; - int ret; - /* From the controller point of view, we are at step 0 */ - const int nfc_step = 0; - - if (*cur_off != 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 != oob_off) - nand_change_read_column_op(nand, oob_off, NULL, 0, false); - - ret = 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 = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, false, 0); - sunxi_nfc_randomizer_disable(nand); - if (ret) - return ret; - - *cur_off = oob_off + ecc->bytes + user_data_sz; - - pattern_found = readl(nfc->regs + nfc->caps->reg_pat_found); - pattern_found = field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); - - ret = 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 = nand_check_erased_ecc_chunk(data, ecc->size, oob, - ecc->bytes + user_data_sz, - NULL, 0, ecc->strength); - if (ret >= 0) - raw_mode = 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_chip *sunxi_nand, return step * ecc->bytes + sunxi_nfc_user_data_before(sunxi_nand, step + 1); } +/* 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 = to_sunxi_nand(nand); + struct nand_ecc_ctrl *ecc = &nand->ecc; + int data_off = step * ecc->size; + int oob_off = sunxi_get_oob_offset(sunxi_nand, ecc, step); + unsigned int oob_len = ecc->bytes + sunxi_nfc_user_data_sz(sunxi_nand, step); + u8 *data = read->buf + data_off; + u8 *oob = 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 = 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 >= 0) + read->has_erased_chunk = 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 = mtd->oobsize + mtd->writesize; } -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 status. */ +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 = nand->options & NAND_NEED_SCRAMBLING; struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); struct mtd_info *mtd = nand_to_mtd(nand); struct nand_ecc_ctrl *ecc = &nand->ecc; - unsigned int max_bitflips = 0; - int ret, i, raw_mode = 0; + bool randomized = nand->options & NAND_NEED_SCRAMBLING; + unsigned int user_data_sz; + int i, ret; + + for (i = 0; i < nsteps; i++) { + int step = first_step + i; + int oob_off = sunxi_get_oob_offset(sunxi_nand, ecc, step); + u8 *data = read->buf + step * ecc->size; + u8 *oob = nand->oob_poi + oob_off; + bool erased; + int bitflips; + + user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, step); + bitflips = 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 = 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 = 0; i < nsteps; i++) { + int step = first_step + i; + + if (!(status & NFC_ECC_ERR(i))) + continue; + + ret = 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 = to_sunxi_nand(nand); + unsigned int user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, step); + struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); + struct nand_ecc_ctrl *ecc = &nand->ecc; + int data_off = step * ecc->size; + int oob_off = nand_to_mtd(nand)->writesize + sunxi_get_oob_offset(sunxi_nand, ecc, step); + int page = read->page; + u32 pattern_found; + int ret; + + if (*cur_off != 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 != oob_off) + nand_change_read_column_op(nand, oob_off, NULL, 0, false); + + ret = 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 = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, false, 0); + sunxi_nfc_randomizer_disable(nand); + if (ret) + return ret; + + *cur_off = oob_off + ecc->bytes + user_data_sz; + + pattern_found = readl(nfc->regs + nfc->caps->reg_pat_found); + pattern_found = 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 *buf, + int oob_required, int page, int nchunks) +{ + struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); + struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); + struct nand_ecc_ctrl *ecc = &nand->ecc; + struct sunxi_nfc_ecc_read read = { + .buf = buf, + .page = page, + .oob_required = oob_required, + .dma = true, + }; struct scatterlist sg; + int ret, i; u32 status, pattern_found, wait; ret = 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 = readl(nfc->regs + NFC_REG_ECC_ST); pattern_found = readl(nfc->regs + nfc->caps->reg_pat_found); pattern_found = field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); + ret = sunxi_nfc_oob_read_batch(nand, &read, status, pattern_found, + 0, nchunks); + if (ret) + return ret; - for (i = 0; i < nchunks; i++) { - int data_off = i * ecc->size; - unsigned int user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, i); - int oob_off = sunxi_get_oob_offset(sunxi_nand, ecc, i); - u8 *data = buf + data_off; - u8 *oob = nand->oob_poi + oob_off; - bool erased; - - ret = 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 = 1; - - sunxi_nfc_hw_ecc_update_stats(nand, &max_bitflips, ret); - } - - if (status & NFC_ECC_ERR_MSK(nfc)) { - for (i = 0; i < nchunks; i++) { - int data_off = i * ecc->size; - unsigned int user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, i); - int oob_off = sunxi_get_oob_offset(sunxi_nand, ecc, i); - u8 *data = buf + data_off; - u8 *oob = 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 = nand_check_erased_ecc_chunk(data, ecc->size, oob, - ecc->bytes + user_data_sz, - NULL, 0, - ecc->strength); - if (ret >= 0) - raw_mode = 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); } 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 = mtd->oobsize + mtd->writesize; } -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 *buf, + int oob_required, int page, + int first_step, int end_step) { struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); - struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); - struct mtd_info *mtd = nand_to_mtd(nand); - struct nand_ecc_ctrl *ecc = &nand->ecc; - unsigned int max_bitflips = 0; - int ret, i, cur_off = 0; - bool raw_mode = false; + struct sunxi_nfc_ecc_read read = { + .buf = buf, + .page = page, + .oob_required = oob_required, + }; + int ret, step, cur_off = 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 = 0; i < ecc->steps; i++) { - int data_off = i * ecc->size; - int oob_off = sunxi_get_oob_offset(sunxi_nand, ecc, i); - u8 *data = buf + data_off; - u8 *oob = nand->oob_poi + oob_off; - - ret = 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 = first_step; step < end_step; step++) { + ret = sunxi_nfc_hw_ecc_read_chunk(nand, &read, step, &cur_off); if (ret < 0) return ret; - else if (ret) - raw_mode = true; } - if (oob_required) - sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi, &cur_off, - !raw_mode, page); - + ret = sunxi_nfc_oob_finish_read(nand, &read, &cur_off); sunxi_nfc_hw_ecc_disable(nand); - 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); } 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 nand_chip *nand, u8 *buf, 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 = to_sunxi_nfc(nand->controller); - struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); - struct mtd_info *mtd = nand_to_mtd(nand); - struct nand_ecc_ctrl *ecc = &nand->ecc; - int ret, i, cur_off = 0; - unsigned int max_bitflips = 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 = data_offs / ecc->size; - i < DIV_ROUND_UP(data_offs + readlen, ecc->size); i++) { - int data_off = i * ecc->size; - int oob_off = sunxi_get_oob_offset(sunxi_nand, ecc, i); - u8 *data = bufpoi + data_off; - u8 *oob = nand->oob_poi + oob_off; - - ret = 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 = data_offs / nand->ecc.size; + int end_step = DIV_ROUND_UP(data_offs + readlen, nand->ecc.size); - return max_bitflips; + return sunxi_nfc_hw_ecc_read_chunks_pio(nand, buf, false, page, first_step, end_step); } static int sunxi_nfc_hw_ecc_read_subpage_dma(struct nand_chip *nand, From patchwork Sat Nov 21 01:10:27 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4203 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mxe881.netcup.net (Postfix) with ESMTPS id 99B521C50E2 for ; Sat, 21 Nov 2026 02:11:25 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 104.64.211.4) smtp.mailfrom=linux-sunxi+bounces-27942-noreply=patchwork.local@lists.linux.dev smtp.helo=sin.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 104.64.211.4 as permitted sender) client-ip=104.64.211.4; envelope-from=linux-sunxi+bounces-27942-noreply=patchwork.local@lists.linux.dev; helo=sin.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 29B2668843 for ; Sat, 21 Nov 2026 01:11:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223465; b=BrwYeqbc+g/RPPH4DqTreNbK6iWttJxH5WHYw2xzBLrEvNnH5w9DClr6y5UVqp5LsaA4 z927y3nBoeU6ONQSXvSBX8PZ2nMOHT3hs1pE4HTPfIRqQXi+ejwvR1kvdMrtGWu0cYYeM dNS+hY4buLcl3ICxgC+TU16tVgRBo9TVk/pIA2yDePh8VCY+r9OxZKAiQfehRVV1tMfJJ cSio0Rv4T+DnTN/PdiIHALPJIE8AsYWEgLO0mM4Rpr70MdNoKHc7jjH7JBAE5iWR66NuS fBtl4dP1m+JyvoHZZJDSz7L7rA/1rcerAJ2YI0ECXx4aVZg8+MtXuSJtn6dqnK/lxhw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223465; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=DQGkpSAcUEldrefS3FgTooTEIoCcU3OOOCqakdoP+Go=; b=Hd1C6m/INfhRePb69YuVrz9PIPqGMMxYsbYuwXrLg9SOxw9oBf0yw6ltwY8Aeh1Gz9QW hbqmkKlvmmeKDYdKvukUTdFzucKXNIJ0U3CZ6/dBFgXRJInNsxKXgFrO4E21Uotl37heH LxS2jDQCMHJYnB0ZoYDv3X0TP5IIaHaOkovISyZ6pwenOy9c07hizEm4Dgg2YQJavVxqx A2N0C0uBwJYaXLv570dsPQ3Wcmo7vYog3faQqJooC2E1PSPnVkKazu3GXw99eXXMc0Jvc Q/ggR2ctSmCwIc2vCn5ORlLCPicYskv7ER2Gc0sfgouHqrRM8NJ8Nfz9UbcEGbp9/pA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=BDnDx97j; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9ADA606A6A0; Sat, 21 Nov 2026 01:11:05 +0000 (UTC) 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=BDnDx97j X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223465; b=0BekNX8EWJY+mGRpD+5xh975TUUq6Zw+VEzR/ZIlOUEw9aWn87T3sWHelTc6935yC8B9 YC7/njV9JUQZOy2wjuL3uxFUrBVK9vz7jjH051WwEeCmjB8EZefp1uDLlqCKlIGYcgLQj i9fziRriw4YQ7jCNb0gxMvZN3ChTvQczmEawmDKIzfymWS1wuzd6bwo9SX/cH2n5aalAR ea6tkKaUkSfanI00E1pAbeym1FI6iDtu/G2oNwkOBKLxYHzBRK8BcRekJZ+GAd0k9EQKX sGexr5IEDC78rUQLPgq+QHgT/ARdWeXdU7HMkp9MV8asq4oeLN3exl5adof04a0jKKg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223465; 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=ChkmI0Fv2nAxENF4DGVZkb3wpVANmTW6at9fyf4/EAuecyjvbn9ToOmDDP54JpW+pXEs rzaS8OYKDlXlZMS+urvQNk8nPM6JBrEVJFcpK+PGaoD9Q57qZvZqUC+6oofUaQCMt7aax skibjr4VJpUUDT/nh/ravBc43BqiMxablhLzoaY7/sjS4fuZH0dsn0cd2jfExKSKe+fLO jiNlC+Ujn8qvHpxLcZWiY7u8XMYHIGuohWjJp36MfkEGf3OslkrVSu6ZRf4Frw+PTbzdt XcfPdEAL0xWSALX+fxdVnxwFHGBRinn3Yt0GwgzbG3V3jfK9LgvJ093GF2esnYUC8tw== 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=BDnDx97j; arc=none smtp.remote-ip=209.85.160.50 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.50]) (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 51AD360A2601 for ; Sat, 21 Nov 2026 01:11:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 51AD360A2601 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 Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-4a77dcc4ca0so905565fac.2 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=lists.linux.dev; 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=BDnDx97jsImBpA/kctCdcclzbZrkXXj8PYEzyZuIYyGkH6/InrC1qCh9KKDy/xGPTg p04kfDSObfkOzuX0l9V/9g78e96i7dsLT5vuHoq39EfNvCf+x7vvTGHLaQMUxpDnJxsh 9HFIJaHW1reqEejm/miia+oWOVa++b6nFxi6qL4Ty7GxCg2CDcy90VUtK4Zildfa62lq pdFnOnM6w3Lru3+vuG/UlkJ2pViNV96HM9N53hUVpXjME77wgj7ppVPNIedZB8RAF4BW OADZ39nZr9mpB48dPftsdSRguxy8/8pMdgBqZKLNnJaKvmfMSdoaAY4hUqqNFzZC97Vw lq6g== 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=lFdJg36T/BGwyWtVNiMHWX6IJR0icTsC1KJQa+YjqZ84ACF+dVdTBNw1w0eYBuhLWJ Vh7/LG3vD91TyEADQyXPmerRRTGIi3aQ3r2yr/+4qcNfHO85aU3HbRDnJ6y0DxKmjt4t DZAe8OUdy0dUuFtGxw4qCUSS+9gL45AL0f4TtrpxyTevcG9FuNcx70yw1j7w2b8HaoQ0 lBPzmlX+96LLm7iXjl3+CUHyQ5IkoG0E/OMcDoYCBll7431BZuPiD6klEvyOEw/+DZyA GeX/9aG5LaHbnHTRqL/LGkSkKBRM4RgHKrn5F22gHNUH4VrcBB0wFze/nugg1JFdUboM /p1Q== X-Forwarded-Encrypted: i=1; AL+hErGQQNBXvZOn9V0HY/oIixGNjusMALcVKfDidsDIEXfirZMPfGuVItispM4gyEboku2yWxIutnN+NwrN4w==@lists.linux.dev X-Gm-Message-State: APuU4Z+gCP4VCGmSF+cqV/ZzbEcsj4GLrQubh2m0kWZIeQk+ho3kKAXx p/gRq0wfUYdQjj87rBHGuFuzyijwmbYMabrR39qddLHf6fkEohEzRszD X-Gm-Gg: AYBFou2jzrtZHe1Jmv2Dp9LflUpgcNLqSAZmefi7W4SEF1MoHz1nMDTrDNoFGBOv66D jvrccsk8qdL83Oz+JW/bnbfHrDXp51Zj6Ma9aOM2y+PqmpxsdG9M+q4SccGaPYa0lEsRD5wZEAK hY6HzSE49G/wJ2MG8A3UOMHsQsBM17zq8LnrCcE/ruUl/jLQStCP+tUbBQnwIqfWhvvZOYN3zEx wpTPf6yGVFXD8e8fFK1jeL9TFysD3C6eF1HpiINBQwssVbeNHfoDgdX4W6l39CpqbjtLmNiZXcn /gA3ARUF5LCQWmrfmHvZiKZoMHBCZZr2Az9aH0HceDeS9JpoHeSChEn5fNotorio4Tw0rqed5ui RlR4lw/BJaO4s+6UvoDgZtXpUyHdB2F5Aj5oI5hfZaAY5Hp59V6b/ZgA4urYfu9e7LGhVx5aWUU 77S/F/fpjAMcgR8F8KBU/kmuxI3sUxSI6lWuE1vOClDF2VnXyyUt+Yk6NCX10D9yR4sdcooyXFp Nx6DUVE2Kvb6ogsM/2Hg/+hDzKezQ7Kq0DYooHX0K1Ce6tFw20FsePpwskxj/iuXICP9InuqyKF tZABd+8s1YiXC/TIyeh5KavC9rsr9/c9zyZYCgl+1GGrqJUxJYF7dtVJtgJfOlyO5thORvpb7I8 /WOA2sUg6cu2WEvHdyt3gRDZvK5leknjy4oCIxuLMHG4d3HvbKcd5fV/c917DOAYoIFMz0otlxN zqbapQgFp23+UJRDxmsZzXQOWRy9Fks7J3OVac9JcjJGhQ+rvvVweL 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[104.64.211.4:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; TAGGED_RCPT(0.00)[dt]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; RCPT_COUNT_TWELVE(0.00)[25]; DBL_BLOCKED_OPENRESOLVER(0.00)[sin.lore.kernel.org:helo,sin.lore.kernel.org:rdns]; RCVD_COUNT_FIVE(0.00)[6]; ASN(0.00)[asn:63949, ipnet:104.64.192.0/19, country:SG]; R_SPF_ALLOW(0.00)[+ip4:104.64.211.4:c]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,174.29.1.49:received]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; MIME_TRACE(0.00)[0:+]; TAGGED_FROM(0.00)[bounces-27942-noreply=patchwork.local]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 99B521C50E2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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_chip *sunxi_nand, int step) /* 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 = to_sunxi_nand(nand); struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); u32 user_data; + unsigned int i; - if (!nfc->caps->reg_user_data_len) { - /* - * For A10, the user data for step n is in the nth - * REG_USER_DATA - */ - user_data = 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 = 0; - unsigned int reg_off; - u8 *ptr = oob; - unsigned int i; - - for (i = 0; i < step; i++) - user_data_off += sunxi_nfc_user_data_sz(sunxi_nand, i); - - user_data_off /= 4; - for (i = 0; i < user_data_sz / 4; i++, ptr += 4) { - reg_off = NFC_REG_USER_DATA(nfc, user_data_off + i); - user_data = readl(nfc->regs + reg_off); - sunxi_nfc_user_data_to_buf(user_data, ptr); - } + for (i = 0; i < user_data_sz / 4; i++) { + user_data = readl(nfc->regs + NFC_REG_USER_DATA(nfc, reg_index + i)); + sunxi_nfc_user_data_to_buf(user_data, oob + i * 4); } - /* 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, } 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 = to_sunxi_nfc(nand->controller); - struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); - unsigned int user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, step); u8 user_data[SUNXI_NFC_MAX_USER_DATA_SZ] = {}; + unsigned int i; - /* 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 = user_data; } - 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 = 0; - const u8 *ptr = oob; - unsigned int i; - - for (i = 0; i < step; i++) - user_data_off += sunxi_nfc_user_data_sz(sunxi_nand, i); - - user_data_off /= 4; - for (i = 0; i < user_data_sz / 4; i++, ptr += 4) { - writel(sunxi_nfc_buf_to_user_data(ptr), - nfc->regs + NFC_REG_USER_DATA(nfc, user_data_off + i)); - } + for (i = 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)); } - } static void sunxi_nfc_hw_ecc_update_stats(struct nand_chip *nand, @@ -1086,11 +1039,9 @@ struct sunxi_nfc_ecc_read { 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 = to_sunxi_nfc(nand->controller); - struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); - unsigned int user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, step); struct nand_ecc_ctrl *ecc = &nand->ecc; u32 tmp; @@ -1213,10 +1164,10 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand, struct mtd_info *mtd = nand_to_mtd(nand); struct nand_ecc_ctrl *ecc = &nand->ecc; bool randomized = nand->options & NAND_NEED_SCRAMBLING; - unsigned int user_data_sz; + unsigned int reg_index = 0, user_data_sz; int i, ret; - for (i = 0; i < nsteps; i++) { + for (i = 0; i < nsteps; i++, reg_index += user_data_sz / 4) { int step = first_step + i; int oob_off = sunxi_get_oob_offset(sunxi_nand, ecc, step); u8 *data = read->buf + step * ecc->size; @@ -1228,7 +1179,8 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand, bitflips = 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); } - 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); } @@ -1437,7 +1389,8 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct nand_chip *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); 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 nand_chip *nand, struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); struct nand_ecc_ctrl *ecc = &nand->ecc; struct scatterlist sg; + unsigned int reg_index = 0; u32 wait; int ret, i; @@ -1657,8 +1611,10 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct nand_chip *nand, int oob_off = sunxi_get_oob_offset(sunxi_nand, ecc, i); const u8 *oob = nand->oob_poi + oob_off; - 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 += user_data_sz / 4; } nand_prog_page_begin_op(nand, page, 0, NULL, 0); From patchwork Sat Nov 21 01:10:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4205 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mxe881.netcup.net (Postfix) with ESMTPS id 596221C50E2 for ; Sat, 21 Nov 2026 02:11:33 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 104.64.211.4) smtp.mailfrom=linux-sunxi+bounces-27943-noreply=patchwork.local@lists.linux.dev smtp.helo=sin.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 104.64.211.4 as permitted sender) client-ip=104.64.211.4; envelope-from=linux-sunxi+bounces-27943-noreply=patchwork.local@lists.linux.dev; helo=sin.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 01A24A39C8 for ; Sat, 21 Nov 2026 01:11:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223469; b=GDHUDmkeBOWTcY0SPWDUYintZkxSFs5E81LVK/6PpHs1xf8xIGBdBy3DM1Q65Q0qbUpL idA4IzRhUp/64k2c9ADTPw1fgS7iBaTlFvwW0klHyoed4r01DGhVotxB658+mAhb7OOAx IYltXQ+2AuOWuNrCdWX1XgGu2a+AHBsZ/s22UOceofE+4Mm/k4Cu1d4zj95mNly7zs9vi d3184+7jgIuU3gFXQs0ccQWU2u2DuL/tn+q1etfa4Huy5MUAa3Be9keqXcpujjnJd7vC6 LndM86cmqjMC5fvY9HcG1eK48b8OLRoSFp7Uri3/dWbLAk7GPLa6GQaXXHsQwkNPIjA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223469; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=qRrftGPwx46kokq6Qlnqorb+rnqytcdDxCR8IL9gaTA=; b=486yupOcHfo/Nr+BNU1i7Uwy5qMtDfML3D5tFa06hOEIZRCnyfV/Han53a+Vt23jOY82 UPjg6E0DVADVWguY4gjYPNyT9CEmXX40OEnAZWmAmZpTn+HdJksfGepvrBi3xZqEr4V0j zB0kTx2d5HG9toIBri3NDiPQrX1hQIq354OhC1WJtk5DwBd17I0EOtsH6fQ2bCqLKo3T1 nX9Us/sNJlfo8L0FjNe0eYcT9cAD2fSRBgovuX1CC7iymjvWHz9bc+5LOJSShIJxTH/QF 0q839HSznG1NLFonIClF4bxpmZIkd1QnQFT2KMik7PTTip6lwq60byN8mml2u/NFd3Q== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=um3HcWoC; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 62B3660A262C; Sat, 21 Nov 2026 01:11:09 +0000 (UTC) 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=um3HcWoC X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223469; b=FWN/aPUJcJNClL7kNLDrfeU7BQC5d3ocyVIYL1hWz28hbtXh64zLPu/gZaic8KpwD7BT mFnbd+qzYTsyKWXrlfyCmQiR3nRVlSkt/R5/cSsJ/dzaiHFQzUm+VgRnkUEkcyrDYOuID PEzRooWta8RD/u1y+zQQ1afs2qJUIISk9UCawfEe3fsQoqdu6HajZJYE27r/jyaCWo4QP k6Fek+/Pz/8BbEd670mDXMujh6aI1Yf6/4evlVxBSMSVsWF5io+P2P6PzcrravxXVpGIV 6BiIYX58YTid6bJzeQCmXftW1BvA+VwnxcsLP0Zl/RexIQw2mRrTCZ87RVfpAvZ5lSw== 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=qRrftGPwx46kokq6Qlnqorb+rnqytcdDxCR8IL9gaTA=; b=sLbNQS7jj3oP/W/UVhbl0giYkxZTWAlfa39Y4Hazn50D+5xhG05dwas2TKFO/A524GW6 j5Hz9R5snAIJwzDdSEsyyvYjzZtCHsbtVrAcV3gJc/8xesVzgaRwp2M7etRV9gwy2j/dj MqYlx5aYU+UEYoAXU3OhXOFD1xjcisn2xEAtlt9+ERFJJWQP2GkOAxE48uruEXC+uZjB1 zbOZRXj8/gDxQzrljS/AXiHeT1iThwkJTdifmfb2fmIXZUE3GF4Um4++v7+eo5vVxPrXf 2ocd7tDGsiLYoBnOmwBb3EaaCN6KPCDetEU0wAueHFxQfc6e2svHy0yrzrc37klJY/Q== 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=um3HcWoC; arc=none smtp.remote-ip=209.85.160.48 Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.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 B693760A2631 for ; Sat, 21 Nov 2026 01:11:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B693760A2631 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 Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-48ed188ee81so910569fac.1 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=lists.linux.dev; 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=um3HcWoCEZgwEYxokmTwCjxSnfzEutc1z7gUCQrVykFGjjRD/f29c9cpOdfNGdAMtl tty8ynBBCcRozV4WgUZrAuQ4wBaPI9XIVwvppE0EwrfOSBcnVd81Q1Q/nFwyEPJwH/y/ 6FDOci7gAHa1cD4mD3UgKeIOp1SgbfIWbIAz+346dvOP4FGQ1Vpz9q3S5Y9rxqaTX7fK qw9Mimz0Mg67f6mZ+qfc/vDAnbV6uDUIb7JRmyniYHtKywFpIvGjEGAxlTJ7ZLqwXfiU tuNsdnK0Pp/C8dF0yRojTaHSjBBiRmlQiyjKGnDW40lFnw0EQT4q6/bsVG5ja5mSNHgd F+KA== 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=EFc+WoYtHiw5fD2OgXC5N3KSb81QP6RdTUJinvscuc7q2Zw60ij+5nL9dWxP/kRT/2 aFcpkd0xCRr6v85fqIGyAR76qTqPDQJl5638M63ftPGUEhCGcInm6roXeGJjIx9i43+s lZe3r9xm1bPd3Vj+pD+jtClXg7GSPCSt1d321hIgp4V5emkWSra589XJFdXaoQUSrmcE Sy/cRBfGYvYEeeRfL2loFyzNlH0vgEKyGUX5l7d/2Z4a0NpkPGXN+lB061C1MK6Qhcoj 9AhGDAgFM6N/LTAXm6+zY/t+2DMRoaxlQx2AEXra0ZEmNcMNKpEa9oI5/ZoxlhFrwkc9 5BpQ== X-Forwarded-Encrypted: i=1; AL+hErFTaQEfdwaJYgAT7brwNqT1o96LYV39PvkJ9Ph9JLy91R6MrttZjk/bSBLYBgi89dWKt6f/8bHDnvQCjQ==@lists.linux.dev X-Gm-Message-State: APuU4Z+Hb+aovA7e6OHIQQYaLB0Ibf+JJUijTNZSXcMjMo3RIcR2W13x KKPZXMDzlqy++TKMrrvXb0F1Dp0FeKKCmM+NMEEXJPuO1lidBAiWhnjB X-Gm-Gg: AYBFou1LsunC5x/XL+RUyaLG+fLtP6ZynmLG51Vknaao00SC4hjnTcOmh6YS1BO+beJ 4ZpEgx6Q96QbqsTSQTv/0mf6cSg7cqtmemc0wACWBaly1Gsxj8BL7K9vo2CpQfotpVZkEPLna3l yes4S7Yz0VHqv5UW6hZvhZ/mQSGU10s9JGQIwIACPpztB7YPqjMrT5cWW99JdBZEADioC7CH0Bd s3yeJdykdyhjATnIRPMdMdBh1gFMlmQAcNBwEh39coK4RuyLFvIW+/TZRdOdaK0l3L6pXr7hwBt sYd2itxNZQ8w9Wy6cIn9bafPtrKjnXEOGMP3S7R1sKQLtCF2wlxYw+dfwiP1iemxVT3T9cn8egb SsIs9b8l3cwzJvrYdGOulELshK0mJ+qcHDLsd7P4Rxw+IrYKurVxtREwUSQDaOVqL7BifI1Rc1I 6LlqJoY+sImnpGsg8tLHs7kJiGIlEzOuaiugvt1SIXTEaiVOsi1XsmGLophv2NvFDZNsVUf1MzZ MV+IYxNYoKRFQ5I/vNZgeQQU9BoBPfjfBG+QowjGZ7y5EdzSN8vsZpeWe5mZNDmrtY/vVStI4VL EGwsan9kioLc4FKleuMRjm2d4VKtMwJnppQV4168PiUQZM+AckakNIZSGIs/PINFl/+SsahbRsV 1cZwB6UPXO1YHSlrp8Wke7Mdo3AH0wakPrYh1kNO2gtIMPutBnk1VUZpFphcm/sUdwtaeXVwiAA W8B0uGq409ZbNKK5T73Jnr9GBs7xnlt180v9ON1qHS2AxjQLhAv77Q 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[104.64.211.4:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sin.lore.kernel.org:helo,sin.lore.kernel.org:rdns]; FORGED_SENDER_MAILLIST(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; RCPT_COUNT_TWELVE(0.00)[25]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; TAGGED_RCPT(0.00)[dt]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; ASN(0.00)[asn:63949, ipnet:104.64.192.0/19, country:SG]; MID_RHS_MATCH_FROM(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[209.85.160.48:received,174.29.1.49:received,100.77.114.92:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[104.64.211.4:from]; TAGGED_FROM(0.00)[bounces-27943-noreply=patchwork.local]; R_SPF_ALLOW(0.00)[+ip4:104.64.211.4]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 596221C50E2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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 @@ -1939,14 +1940,9 @@ static int sunxi_nand_ooblayout_free(struct mtd_info *mtd, int section, user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, section); - /* - * 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 == 0) { - oobregion->offset = 2; - oobregion->length = user_data_sz > 2 ? user_data_sz - 2 : 0; + oobregion->offset = SUNXI_NFC_BBM_SIZE; + oobregion->length = user_data_sz - SUNXI_NFC_BBM_SIZE; return 0; } @@ -2099,6 +2095,12 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, if (mtd->oobsize < sunxi_get_oob_offset(sunxi_nand, ecc, nsectors)) return -EINVAL; + if (nand->badblockpos >= 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 = sunxi_nfc_hw_ecc_read_oob; ecc->write_oob = sunxi_nfc_hw_ecc_write_oob; mtd_set_ooblayout(mtd, &sunxi_nand_ooblayout_ops); From patchwork Sat Nov 21 01:10:29 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4208 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 750A11C5D65 for ; Sat, 21 Nov 2026 02:11:50 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27950-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27950-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 4F9366463C for ; Sat, 21 Nov 2026 01:11:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223476; b=qTNmPo7QTl4VFwcyOfbx3fbjpEIt0kARZG0c1kXat4N8SWRwu81pQwBGHukchoqUpo7p 3b7rZtiE1MIHAlBWggA2kjADnKJmPJyFYrBzOYzK54XRRH2+ykG5dw3QMuutRSImlYiGD Av2SExjN/NY51h7OhyNj2GRkjIGvhvOJFmfyIjefM6RSgdGQcw29ucATMClu0oV7N70tw U8aJTD3XgoaDQuA8Sl7pbzb1N42+ZG0CvRQYKdsC4UD0qThNgfgB3K6KGNrSY7u3j7Cf9 S+gvCmc7R53dO9Imy/M25BAsgHmLHWmA048z33qMEk/t9gbbKHd9tbjhqcjK/+AAkCg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223476; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=0IrAGyQNQ+9vmexJ3HX+RGvKm7PP0ZR37lEcYjBayK8=; b=wrYy6N/8SjfVu8yBWSvSndSs5r3q9kQxQ/706NN/uyMyWbcetFuTqoKr+dFglUjc29zx jkAg/8zRf72EBB7xfHKQKlNM9297CnCoOhwLKGNZDIlhR2PvNX1+R5TZj1dMzWZKsL6pi ETAFqm4ExsYKvin4EcrII0LgM2aW13byUU0zQ5uR3fxj6ag7m2WifazvfvipL7CGAXggL ax8xVEEhldZ/7r+LGQ86okxL0PcrKjiGzsMmdNR/WSaJrJK3kyDd2xQF31lzDI4gBRFat Fy1EGzPJ9FRtMGmdvKZ/aSmRO8y3nJ58liYPP+g5QbYNHIiyA55yKOK1QqcZItdkQPw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Jk4sMuO6; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 55D0C606A68F; Sat, 21 Nov 2026 01:11:16 +0000 (UTC) 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=Jk4sMuO6 X-Original-To: linux-sunxi@lists.linux.dev 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=1795223476; b=meyuu30eHtIzJrnRsXsIOXarQIWk6nErfwjbLPzdOSgUZSrKjAYg28u1isanGuQh121G wFaONpg8uCDLr7+/yr2sqXTpWT4uHkvLDCg+Z3u5rxyBvNOi6WFY6rHnI6Agwa3bKvmCW QEXmWRKypUjtNJF52K3YeCYGiYO3WGqtI6RunnVqGzPMeJoPP4jOUyF1iXHAmdsoZK6tI Cg+t3wq2Dhkss8V+XUW3fAgyS/rpa79OUy7EI2C8auW19rBgzHQE/9UET3UkOY6gVtfsu 0kULP5L/wA8QF7q9Jtt+0qL7XQ0+9aC4KC1xXME08jB7Sfy7XuPViUzAS+oTO9GTFOg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223476; 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=ZT7Tq/nJkjGmd4WCJQvWrpOYSc8Kx7pFbBHhm2xm1VhhYqHNwFZYuwezG1FRijd5ozhN lwLsgeV87zlbUOySxZgNUo/h6g0/PnKEffUQFHvkqkfglnk8BkysWL+0HmNSKc3qLSw/r cNLmITjvlOLYbQ05o//mA1c+uMROt5TgKyafldh4BpalUQhwdsi4iQh/LFrN6Ji67PQuv K23DrBzPvfv67g+oVYMtpEmNbQ8s8Fx+DrQIvafAyz2YcdprbuupRvbjNSwywu0j0pyfN dWDlZ5iFwtwYAxWebWIjMfScxUl7FDv+eD3R6ALjotHToNTxJyGfuFXw1YkNIIJqmLQ== 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=Jk4sMuO6; 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 9B77B60A261E for ; Sat, 21 Nov 2026 01:11:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9B77B60A261E 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 Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-53ec2cc397aso981254b6e.1 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=lists.linux.dev; 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=Jk4sMuO65cf+WkxByHKVgx9u5D4IjgeiTaOxGVA59AWVi08g6KYWuOnIJ1yVjN3X9F KFQVtNHnBPZccuZ8OXrI4FTGuwo3ufCUko6BC4KWreCXRak8FhggyfmqxYp4D6bo12l2 FiJouxRvSGDYn/hNShLzQ30YWS5VbBmv/9iRD9F31TPbyQfVGhd9tZLfiFZt3kzZPrqH t7wLzgdX1Om0a6o5d1/pLfFQStpiJ3daFt28Oh70FOG12CMpet5OSVyPYzpPzeDOcGLl D7F79EhU/28QzSOq6zm6v2xFtOCl9/HTWAO3HClZQceeySqra5yzkzOS29+R0oRdxT8o yTxw== 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=nm7gTNGOUC1QOIM5BpaLsZESXyWuB69BRex8Suf+6I4XOGiL0O3eCo1kkzf47gVG3m HMS76ULwsvR4I+JXa9L/LhsqGl4YITFCFeZEHe/u9d4M3eYnQ8a06pPvyUdqs6ubdI2n bh8Ssyn4q1goWWD1lc6RcifGszIvbcbCPup9+CH7rvI2qHn63o6KBNAQwjVqh729Wk75 XDYL/y4EGouNsez4D0tXyNWzjOiv7Ld4ydR3zQx4FDQkQ1YUrFivjPNYA4IEgzyJBZwt ls5Xg1zZHIJu1xOXo+j8x+ARdr21lN7958ZFNo86sArkl++JsoV6+vUSycaz2j5mz7lF daJg== X-Forwarded-Encrypted: i=1; AL+hErFsX3c7hf/HKraZIiuhTwIhZ5/Jm8QnTYJaTAxUjnmYR9ns+tUHWK02d77Z0QdrbWkjytftrYC+/tob4w==@lists.linux.dev X-Gm-Message-State: APuU4Z9mmF4BVZASUzhRmEp0C6jHBaJu4hgSdOkYuAAJIcCRBJF625vN DqhR954lE+dDgjbQ+k/5vUJEivJyx+XOu+8B8xrlG1tY+zPwNULYvdJK X-Gm-Gg: AYBFou2tj5gS9+IsfPgHSQBFDZjoqOWaXA6BSAHayf+g2OV98zuIg4OwiwQxCE6Sk13 aRJkBorbFMUMlF0sTSGiUs3jQKsr4xqLxcEEhqYhEcjxfY5R5r/XRfeJ6u6UTKTRAEi5yo423mC pKGejclBdpE9zrolldiEcGEG37DiKqD6YdVZMwSKQ07K13hSAAetKDaHJfmuCZ8EIgimKShYv0T XT6rXhbanOKfI6DjS+vmjRvsACdf2AsoRTb4SCz24fqby7qfAB2J6mQESffqECiQ6aP5gS52uIF R5qfdMC3rHJV7wCyoAYcE9uXQQYLxHotXfylQEgD0+6ziBbBjRHGXDQ96oVpUidnVMnJlgbEPp6 7Xw1lvxE8ALduCc4m2d01G9sh82//Nrxc9NLFnvEGIo1o63aJWtIEFD99P2OOaBvcXXS56GYRfd DII7/2nhoQxtP9dPrvBCDlGqMYcPT1U4gFcvo5Pk/uFA+VKfHZ30g+rdSATkt8G+8Y7eS9C3fym eiqiLZYWb0HMS403hFidhmlt4z4LqY6vDmALVmOX4CoFhZKqMIhRwM8kAqafWXHxTRVvmQ2WSst wjWQGcLzxyZi1pjJaKYk4um25eXO5u+YcjI7uZNyRXT/9K6vNfrT4FOT+1hTHzq0JEErNxVXhpA ogn3ui+5eopAV82YmPmDyw1TiT2c0VpJ4dDcc2edgmcsJixUjZDxfHRSdFMUwRnc++kNw2Y2gLN fpndQKZGxKeU6inmVcg79+nxkJUgV8XGyokWsnxRXC96PpaXAOB2qO 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[26]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; TAGGED_RCPT(0.00)[dt]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27950-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[174.29.1.49:received,100.77.114.92:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 750A11C5D65 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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.org 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 nand_chip *nand, } } +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 <= 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, /* 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); - 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 + oob_off, + oob, oob_len); ret = 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 nand_chip *nand, return; if (!cur_off || *cur_off != (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); if (!randomize) sunxi_nfc_read_buf(nand, oob + offset, len); @@ -1200,11 +1210,12 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *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; if (*cur_off != data_off) - nand_change_read_column_op(nand, data_off, NULL, 0, false); + sunxi_nfc_read_column(nand, page, data_off, NULL, 0); sunxi_nfc_randomizer_read_buf(nand, NULL, ecc->size, false, page); if (data_off + ecc->size != oob_off) - nand_change_read_column_op(nand, oob_off, NULL, 0, false); + sunxi_nfc_read_column(nand, page, oob_off, NULL, 0); ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) @@ -2105,7 +2116,8 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, ecc->write_oob = sunxi_nfc_hw_ecc_write_oob; mtd_set_ooblayout(mtd, &sunxi_nand_ooblayout_ops); - 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 = sunxi_nfc_hw_ecc_read_page_dma; ecc->read_subpage = sunxi_nfc_hw_ecc_read_subpage_dma; ecc->write_page = sunxi_nfc_hw_ecc_write_page_dma; From patchwork Sat Nov 21 01:10:30 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4207 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mxe881.netcup.net (Postfix) with ESMTPS id 7C3591C50E2 for ; Sat, 21 Nov 2026 02:11:46 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 104.64.211.4) smtp.mailfrom=linux-sunxi+bounces-27944-noreply=patchwork.local@lists.linux.dev smtp.helo=sin.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 104.64.211.4 as permitted sender) client-ip=104.64.211.4; envelope-from=linux-sunxi+bounces-27944-noreply=patchwork.local@lists.linux.dev; helo=sin.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 6D993A3380 for ; Sat, 21 Nov 2026 01:11:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223469; b=44WQasJV6fpVTy4zDqT5zyQibzAdyoIxkXv3groTRD54XoZE5L9WOnVmwCiCkxN7R7qK SCrP4GmQVqMIHgkeHEV6/8JNhU2WY4yrQOlA1qZ2azPLh5iGYEK0ulzqsbcW1jX/kmbZ1 o1Of2N+s2y3GFRevCddPZ5Rt53Wp5FlQfImYD4AlsXT+X3CEncbmlUSbA59sldMe6kDkj UScp4UfcTUrf3FH+gtFrONt/BE1/p7be6WbXbJMNT913RnJgYTafy20PjMdVZTAu/7wOe Jz+wfgRC+bSp3S9yR9bQPI910+a2mNSm1Q7XvbKOJPbdOihPP9r1de8WNaktDu36hHQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223469; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=tDxDnDKQmgOhb7t9CqFuoW8PN9zlg37X4nU+lrooV8U=; b=ONco1H7g8esIr7YLRmw2gO0hKS/RCKOQmRGWEukyoAwPgapeCJ/AtqzhIWf/bIQVYU/q BBa7gUhMenst9WmqErCwXFB5z/9BMr59M2Pnlo90Kc1SjQ8G1SQKXvb6yr1UfWLPI/bZh 3kXLOJgB/CBqMvilBOBhlMEAakFHYKA0HSlJydNn8oskgWcbKWnQtmYz5h7Dj2c2PntQ5 g5OBFmqPdqYnaangmFjUgKa/E+PdTy2/OvtHMLRHZFWn3ZUPh4AIZZfAb1UW0J9qekuno qf9lGB7f+4eg8YjM+8OFSSljI2oMtE7RZg8C/QoMP6S9q+gIqBrJiu1vgc5+L5xT3qQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=SMFVrnH9; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 72DBF606A33E; Sat, 21 Nov 2026 01:11:09 +0000 (UTC) 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=SMFVrnH9 X-Original-To: linux-sunxi@lists.linux.dev 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=1795223469; b=JFrRPJwpmHzXS0Pgp9a0nGgN3v6jKY0mxQtih1+TIXJ55g06J4hVRYPYbECvjEnbCqgD B86yexwZx9oluZfB5SJdoh5wR43ss6uk7wZ/9w2BsAlt1w5c5sZBmIb8uHsisSR8Yc9Vu w570R/tKyufJ4aPe59hBQVzSNF8CdWESt9XtIBygF51dpQfoI1fSprdJSFPzi8B1AM5Ks 6cn0UuA340O9AxeY5NbkVwr410EMA3gDV6H81dPOGv8OsZzVPJEx4uJnx7QLYwSmZGwRv MgfyUSluvHHZtXMcBcmB0YbHFGjJ6nNfCRtiwX5NzHR39p7GndCTy/J5c2tStCtLgsA== 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=tDxDnDKQmgOhb7t9CqFuoW8PN9zlg37X4nU+lrooV8U=; b=D6eeHFKx8YcESF57O2m8tetJxL6LsrwjCE4PWjFdHGIgXXaA5td8upJDURBd5LAfZGP7 7pXii97x6mOt6PANV2dJ/067rbEOzT562EwSTtm+hT7iqH27CZ+HYvXV673ktF9tPKfx3 XIIgwHSQm6PR5ZEkOHEwP98F91xVP/yDlfid1Rh485irl5M2CBQMz2t7DcmUMPm3ucCeQ ee9iAnXqcgPgOX9St+rUyMc2y0iWuQzobVbqc3NAyskkCC1aG/cTQkaV4hp+V4/riJh/0 8JlFhBlY1EZAbxt06yho7UkumdaSyDNgelg4bT4Hpu1juiXxB1vcFlo7i3oG7IzeMjg== 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=SMFVrnH9; 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 E238E60A2636 for ; Sat, 21 Nov 2026 01:11:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E238E60A2636 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 Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-53dda625f63so913085b6e.1 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=lists.linux.dev; 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=SMFVrnH9geXlGcUq9vlrHJItm1hCYOoU4tgyw1Qo5RhbX71LsTlR0GlPNHS+LMTwVo ckWcvuSwjWXOl0lfcGXzriG1BjfYgbWpUFJDSJHV7/hCC3Dp931ceImxAMfq+V/2ZLOa umgUAn9gAh3RJRMJDLZf+1zGGpImPOLjGf6TmWVywLUJ3mIOijoDzVT7rVWSvwyDcWf7 d0hzQeclAq4KNO+A5iTt0ld2csiHQWeA10jTTvIj/XR1IfhpIaQo77sYmcfWal1vJ8lV WxTn05S20gdfMCGwBu/yhHBAO9KUNwKdDo7luqbvaEEV5CTShlnjy+UvfHn7XcX1xcb/ Cq3A== 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=lg9XYDwpbANUMfK/FUqeIwGb0lZ12xBwHFMxWmsUZ8Bi9gVSGb2yEX1G1IuxawbchV qC6xiffw5CLePedPkxR6+wNTiy0sqaiYyWyRpQwEx38jxqm5SUtoKGuoa6GyiUHVbbJ5 M05HvlCH6OctFQZkaiezUKXq74FDRZ7KD6QSMnu5cHI/alaoAiD2I18H9OPcGtJG5rfw ///ubP2FZ7mBXaaOwpFSQerWEqqeXmuarH7MRsznSlM6YjDQUPFbsUiTaYxQfzln6X0k t9fhsjPo239sRDv/3Uo0TTzErpnm6wNv/dWV/ccEAJzxfwgp8l01AyTUbZb3x852s7Fx VzqA== X-Forwarded-Encrypted: i=1; AL+hErHvdlENFOKbvCVfMrTFOnyQN6M38JjfOwAnRpvX1Uo0kxCmhqm4iIgawLRG+y1y4XQOwCMMhmeW9vcusg==@lists.linux.dev X-Gm-Message-State: APuU4Z/Hu40xq2L+XZeWAKR9nX2QCUy7keLr/G7nmPBHlNSmYOe21nKO R/Q8P6MzKacIBYxq498MbetcPzFFGtcUotyvjZavuBa7n595svnsGXlO X-Gm-Gg: AYBFou2JGLSYLvPbR75vUEa3AG2+RBy2Fm7S5tI5DvGO7GYmL53kTOUvUqlomfBc3ex vj1tlEUs6qrfpnHUdOFxPTJFTt2y2UTLKrHE7RoGMAmKfi3HvJkTt1If3SaX8Z/0cg4IL2jSKzm 056zP6qxWr2sLidax3u9567JCyW1X/ea60iGLXcYNgVEuKJx0N32gFZdBILJUxHcMAisUJ2RoZ+ Y6m5cvYlOKmobUnbuJZ+LWmwOtPiULhnshoUrcJQkZMgM6P9tpgA22HesBfjj0786rzHR9ngKqf 7zzuADCX7N89q/aBif7yPu+pYqqKmc8o50weJK4fXsifI+wf20XORActT5rTmzbuJwAtPZ4FZD7 tQmFClKYwKdnfEhyZDErQhO9qWoUKPVxuM0vZIsG4SxDneyTJs/S6RWwLKrRxP+UO7cF/YarqK7 0A5Qb6p03aacDhFSQju/2+74vsIi49Ligbnnn8bMQYXmcUjdDBwcXwXwB+NdxbWHC9DPAZohDv6 RWJf+1T16FaxfVHQ2ctN99pFM6X9vqlJNubw3i/aVEUoor+iMNPfCdphj+alOPBzSl58u4+GJd6 NGPILoG0BOCZ6iydIkZ+nprsJBJ1U8WcxRxyHEBFHfylKY9J4jbExTCjcZr26xQX1VgUKjmJAYS CDXM2mf6rX+NVMsSJ99QQ62FICXL8yhqA+Y0R1WIeZgAfz6TZGLCd8t/2OekY2bNFTdYg3mjvuR zUD+0d3FDmnLIoQ1ipgo44JIaSMyhVqQMuu0Qu5CY8//QSoYvmSP+x 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[104.64.211.4:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sin.lore.kernel.org:helo,sin.lore.kernel.org:rdns]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; TAGGED_RCPT(0.00)[dt]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27944-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:104.64.211.4:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,174.29.1.49:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[104.64.211.4:from]; ASN(0.00)[asn:63949, ipnet:104.64.192.0/19, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 7C3591C50E2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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; /* 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 = sunxi_nfc_read_column(nand, read->page, data_off, data, ecc->size); + if (ret) + return ret; + } - sunxi_nfc_read_column(nand, read->page, nand_to_mtd(nand)->writesize + oob_off, - oob, oob_len); + ret = sunxi_nfc_read_column(nand, read->page, nand_to_mtd(nand)->writesize + oob_off, + oob, oob_len); + if (ret) + return ret; ret = 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 nand_chip *nand, u8 *buf, { struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); + struct mtd_info *mtd = nand_to_mtd(nand); struct nand_ecc_ctrl *ecc = &nand->ecc; struct sunxi_nfc_ecc_read read = { .buf = buf, @@ -1315,6 +1321,8 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *buf, .oob_required = oob_required, .dma = true, }; + unsigned int corrected = mtd->ecc_stats.corrected; + unsigned int failed = 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 nand_chip *nand, u8 *buf, ret = sunxi_nfc_oob_read_batch(nand, &read, status, pattern_found, 0, nchunks); if (ret) - return ret; + goto err_stats; - return sunxi_nfc_oob_finish_read(nand, &read, NULL); + ret = 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 = corrected; + mtd->ecc_stats.failed = failed; + return ret; } 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 nand_chip *nand, u8 *buf, }; int ret, step, cur_off = 0; - nand_read_page_op(nand, page, 0, NULL, 0); + ret = nand_read_page_op(nand, page, 0, NULL, 0); + if (ret) + return ret; sunxi_nfc_hw_ecc_enable(nand); @@ -1461,10 +1481,11 @@ static int sunxi_nfc_hw_ecc_read_chunks_pio(struct nand_chip *nand, u8 *buf, for (step = first_step; step < end_step; step++) { ret = sunxi_nfc_hw_ecc_read_chunk(nand, &read, step, &cur_off); if (ret < 0) - return ret; + goto out; } ret = sunxi_nfc_oob_finish_read(nand, &read, &cur_off); +out: sunxi_nfc_hw_ecc_disable(nand); return ret; @@ -1482,7 +1503,9 @@ static int sunxi_nfc_hw_ecc_read_page_dma(struct nand_chip *nand, u8 *buf, { int ret; - nand_read_page_op(nand, page, 0, NULL, 0); + ret = nand_read_page_op(nand, page, 0, NULL, 0); + if (ret) + return ret; ret = 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 nand_chip *nand, int nchunks = DIV_ROUND_UP(data_offs + readlen, nand->ecc.size); int ret; - nand_read_page_op(nand, page, 0, NULL, 0); + ret = nand_read_page_op(nand, page, 0, NULL, 0); + if (ret) + return ret; ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, false, page, nchunks); if (ret >= 0) From patchwork Sat Nov 21 01:10:31 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4210 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 3C5901C5D65 for ; Sat, 21 Nov 2026 02:11:58 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27946-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27946-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 39DB666FCC for ; Sat, 21 Nov 2026 01:11:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223471; b=0pn7f+wr63KeH5DclAVhA5dBjeNC2ihUxaR1OKtQoFwyHCBySyCFL/psmSxqFUUhBgiZ cF5bSdN9DtnZPj2mOiXaOZq5K+Ibe5URcIH1htsl3jvNebM2mk6mm3DUFg21serJjfYTE FH0WOeJF9lrKy1t8MgLLGF8gwatigag1JQedJZmhnXbExrAV45BcXYhjHLB2vuZir46nR cc5iKNYwrQ5vrayRd/LmUsQWjo50MPeE2jdWx+AF4X89JCs9ivUH53TqEP2NXIpegFyvY umG2JgJRHTGDFflsWW6YYix1MsNROKYojAYocoKvzXEdqYo4MBSwNcgQ1ML8iM7KbTA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223471; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=ykELsWqv0rr01vGMcfJTxNz9WxlFG0XTipq7Ly2y7EA=; b=TXHMF1twCSkxiQoBOzMMy2+BBbB9NsglvmDNBrCBFFZkn9Aebbu/dZb1GX1c/2Ag80ny QhaFDWB9t9xOpRQqEjWp1EWFtvPTcZl+ha4MeELVHXZiid4TPCVZdUnbd4hr2FoajDxMJ BNHqQM3ORib9k8ye946btJsIgM9FoYYTb6sqiLy1MbeDCKti8lxi3L9sCn1vEE+jnzg+Y yJJGfBuM3oGeAxyzLtOTaAIyC2nMPcnlVOJ5o9KcJTUsa0n83uFwyAO66kl/bz8EidUr0 ycGsx+Pnpr6mmaK9Vsbu37uusxN/LEgT06+8PWxIOEF9Tzwf6vMOjaEc2/YNTgEJvLA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Vr1DAGPb; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96B6B606A338; Sat, 21 Nov 2026 01:11:11 +0000 (UTC) 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=Vr1DAGPb X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223471; b=v0bhht/ggpkoITqfcgq4lnPXVQScqzBZix2RWBK3gYWBbIf05+sD4xHfTiRGpwdIr+tY e5a6oU+TxxWfUGZClR+56MnRhEsoDQ8Pf1GpmL2i88qirGOUSQNmCg2d8OPENQeJhUami wMo0sdGlW0YA1y/MRMVSJbb0WFuR0+C8/ZgpSAmwftX4x0mUz9YXA4HbDLgcoZNgzu3RK F10kv81doMaYB0O9IIfGkC+AHlFIsbNjGwiNoRMlIFTPTwjMYDqOwbEp4Ql2/P6KZbGAL f0Gh4J01tFnt95QRsMpmnETHkb65v48r65/dTtosL8TaAWiIx6VZRDmPgvvVrBDjdxA== 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=ykELsWqv0rr01vGMcfJTxNz9WxlFG0XTipq7Ly2y7EA=; b=3d8rN2jfSNwUuAV5QH0ULwB6c0rulKDCWPonAWfgHdibDetU4j3CdYCnLkwT26a5axAC ExoeOPAE+WHPwUUVDcHunB48ozX/GjzchnywwqFz23khfEihyLf59flDRugwY8aIfobmd 5OW+mt96N4d1Dpl0KGSlTXZvNEBXFm9cdRqCwNa1tQ5WQxaH6mA/+ftCqxHZS5Td19CnG TRq+ZcGx5Ko1W2y3/zPv0yUO1xymg9HK4PCiX7Iz+CT/eoOfYAlqOtPUqn6XX9Pnrmsz6 XzjBjxJWsLUay1TyvnI2w/6KfjZDVqw2+XYfbZXsfKu3ZiCyK+yswLEboCHDUGfswHA== 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=Vr1DAGPb; arc=none smtp.remote-ip=209.85.160.49 Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.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 6CB5A60A260A for ; Sat, 21 Nov 2026 01:11:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6CB5A60A260A 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 Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-4b5138f0991so1430360fac.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=lists.linux.dev; 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=Vr1DAGPbFZL7K0QQzoBgAT1kK1Pbr034Kmz49NCZTPKzwozHj3sJ2Qwg87z+Pf3Yz1 fdq+yQN4JoON1leba2RJTcHoFEhBzIfiztyz+VyVU/SVbm87ayBv6S3BOXhn9V7se7WY 06IkT+CcFujHekJqxpXUCFxdPodp1LlolVyuhd0PfQwLLIcmsEZh4AqTOSMbVARfBFEj 2jqXR7QAapAHzyZ0lLFTkz3V6a5TKPgDEgcjuxhEi892oukj9tkfmh+/t0vdWbOdtUV3 ZS9iG2ch45xlJKNRfYxjpQcsXiTcCMDaymjCYHeQu6ponwkxAhEKOfCCa1Lxy40+EIQ0 3N7A== 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=VJk51e3ElBR0p/1fywhtR89S0OLGlEEAUi/NzMSuKRZ9A1IDBGBazUx+jQvxePqjny jSIcvAiuhFPSQmW8upnSXe+54EfhLwQWHEt+AS3HV0wGQNSJOKFID6cni+IQcPyfGe6g W8Jyg8RjGmB00eilP9oeZ1Ofr5OWnwTYUk9XNkYmfZPEKNxquBz/MIlvxdF9Pc/Amie8 /dNrQUmKzdfluYb3uPBUM8U8mkJTd7GDTiVb+wmc9tWVGmqlA3QH0pTHu5ElZWyF/g8a 1caZB2erATtPdRt6TWq5RDyB4hwEcZyVAotC/zFmjspLWoUDzmCqIDaqqJOLENlK6qzk 6SGA== X-Forwarded-Encrypted: i=1; AL+hErHD1rPHJMX5TiPmYUTAlHUIAF50zA54IlANFqYDIe7h1xnzDivJ0HK/1kjFALbVsi0GXF0Maw3P2lj/Lg==@lists.linux.dev X-Gm-Message-State: APuU4Z9lRnpg2Z2PrxgETcyWDbB+mp80W0O4nzBRUbMuz0liYSfr9NXn pYZ1hhWpoWxxRtGMsun0nGbUe59DKLszWaX7stXZq4c5WIvHLXcVZoeM X-Gm-Gg: AYBFou2Nw86VMNnDTukiwGtrXFyqOTCA/dF0RILnnmGL+9Pt+ft1iGIJNsXQXukQffz RUB4Bn7et4a2Sw0Dc/V712syjaRtgyAdPLxVDJfKBDItkaJQ0OPka9Jw+1WL3QP0iJz095Fm0eT amGqUoDDywSbHeFT51CrOCWGLybN1G9ZMZnGVPi3jRbClxnSSuj4mjPjE36D5Bl3kVcjtjOpbTX QJe7+RerlGgaqfvorqiPwYB21d3M72eUCsUUtocIex7J/0SEWS1FDiWuBK0FxxO2d4d4p6uWi59 DytOORQG/xRIE99vfpyFVCsYqa1YUYwN3vErTT3J5VA4BromEoJ7+A0MPvmUyu+C4KGt58UndHc oI7mCckzXHAzqwf1dgRRYSNN8PQIMQ3G+iS9EEXk75/gQASloMsUBbMFiJE8NWVL11WUzhbWoeW NIHkDxfJHmh5oRl796dQ9GAF3L0bf8u4ZqYRr9kwBXWjsnD5qIckHVEM15yMokHR4RQRK2ZLV9o iS0DmAu4u6x/+nMWHdGrtf3z3vAneaJA8b747YSahGNH0ISVAWwr2ZHQSggTtQObS08tqAhVn5R OdsT9tc2z9Z1ok2v9Gzm0bL9oUNLrA042HiRUXJg90Y8oe60s+y28E/rVsuAQM8J+dWWMcp5Apu mW+aNwpQepkPW1WgzWbZUNMpymXRqcrZL7tvNNhTRnxOTwvjtnNXgfKwzoe1K87wyQUarLyEGp7 MjAa/qoiVJAHlNyRMbjffDpj4eyppgXAjy4/1VTYlRm5u+piKhitbS 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns,linutronix.de:email]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[26]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; TAGGED_RCPT(0.00)[dt]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27946-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[174.29.1.49:received,100.77.114.92:received,209.85.160.49:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 3C5901C5D65 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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.org 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; - if ((ien & st) == 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); + if ((ien & st) == ien) + complete(&nfc->complete); + return IRQ_HANDLED; } static int sunxi_nfc_wait_events(struct sunxi_nfc *nfc, u32 events, bool use_polling, unsigned int timeout_ms) { + bool irq_disabled = false; int ret; if (events & ~NFC_INT_MASK) @@ -439,16 +443,28 @@ static int sunxi_nfc_wait_events(struct sunxi_nfc *nfc, u32 events, timeout_ms = NFC_DEFAULT_TIMEOUT_MS; if (!use_polling) { - init_completion(&nfc->complete); + reinit_completion(&nfc->complete); writel(events, nfc->regs + NFC_REG_INT); ret = wait_for_completion_timeout(&nfc->complete, msecs_to_jiffies(timeout_ms)); - if (!ret) - ret = -ETIMEDOUT; - else + if (!ret) { + u32 pending, status; + + /* Drain the handler before it can restore an old IRQ mask. */ + disable_irq(nfc->irq); + irq_disabled = true; + /* + * The handler removes acknowledged events from the mask. + * An empty mask means all requested events were acknowledged. + */ + pending = readl(nfc->regs + NFC_REG_INT) & events; + status = readl(nfc->regs + NFC_REG_ST); + ret = (status & pending) == pending ? 0 : -ETIMEDOUT; + } else { ret = 0; + } writel(0, nfc->regs + NFC_REG_INT); } else { @@ -461,6 +477,12 @@ static int sunxi_nfc_wait_events(struct sunxi_nfc *nfc, u32 events, writel(events & NFC_INT_MASK, nfc->regs + NFC_REG_ST); + 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"); @@ -2559,6 +2581,7 @@ static int sunxi_nfc_probe(struct platform_device *pdev) nfc->dev = dev; nand_controller_init(&nfc->controller); INIT_LIST_HEAD(&nfc->chips); + init_completion(&nfc->complete); nfc->regs = 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 *pdev) irq = platform_get_irq(pdev, 0); if (irq < 0) return irq; + nfc->irq = irq; nfc->caps = of_device_get_match_data(dev); if (!nfc->caps) From patchwork Sat Nov 21 01:10:32 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4215 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id ABD8E1C5D65 for ; Sat, 21 Nov 2026 02:12:15 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27949-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27949-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 124E862146 for ; Sat, 21 Nov 2026 01:11:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223475; b=hQofQ/LVTEc7SOX+feqJoA+Rlft7iYudYc7S0haAhHs23D5iCB62j1TdcO/dKtxH67P1 AKuxgE+sW+taJrYJDBeYKJNjSciK5RPFnvlHyl0ZI7EEfRu+Ru2X0uQ1NcGB9rvRAxj4t X3fFY/5vFxC4kzP7vadXqfuiSqMy0FiWFu76hirkQNYyidREsGuGagpZxV8BYe6jHJQbq QejRTiTIMFf3D1kadukTJjN1K7xD6zf6XdiwwGvX3NN/a+zJkMbCPeFzR9/bNBfwi1CRB IZFepHLKKX5liHTSc6OUbvbD/RLIHjDBh6ITHC3JxKvivuHmIQEAefs+gb4FutPePQg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223475; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=q43OtFOdNFKAPwH+oRkUo2vplhtOIciQt2V0N0tE52g=; b=Iy8115Xr+UX8uWyfhFjTAMbK9Yg3xDBErUW75Pz1CViQAlNKvMzkfSIW+Ov1tJaDlrfn Bi/a3ReWnQZoYXjgBYhN+MokywdMTxd0BgP6abZlaXwUq+WpDYuiWtKkIkXRMmd3+e+tM wOmF8xTT9NLr2meh63SS7DmeIROV0H2I9ds0QBfrTSMmm1/EtUkpANn3sWOYGiR2+wil5 QEQMTRhC14EnnDND4FRTcc5LlmqufTF9w594UyJSUH+4cJ8E4vHgKhJmd1VjUD2Zc2gd5 594FxLdTzKN5bhR3kiv4p7YIZLJAMeh/et6sGBmR68idQ8t3MGimcUbpB2+f7vyNq6A== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=l3k0ylQY; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D212E60A383F; Sat, 21 Nov 2026 01:11:15 +0000 (UTC) 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=l3k0ylQY X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223475; b=Hs36n6YVkteX03Pb2K7WcxnjDOvu4AktnY5ZTexRWjjVA4aPnvj6O+rFyRSdj1VXt1my 1w+Lri1SGLrC0PLO4t3b9HQtEt2fxqi9e1Fc/23KGLw03MzIqPByik6F0nrkxWCjr8TSP jKko4iNUg/HqAXTIcQSjtO3sdKbP8d9v5u3WU6TgN1I7JYBdowkrxyc0EKhZe5t9mFzsb ARyBzTM8O0kZMwvjuc96/qKEzM52o+xJ9B+qUK5shf2upx2I3hsYQTjKe1SMvDgBO9fNi v90xuncY3hRSwII2KMosKsgP7kQNp3X3+O0rW7RUdV3/SdO59WH+cfMnSU9s+21HPWg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223475; 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=kFF1Vt+O12GyFOYyQdrKur9tD9moRGv9O7eLzdOYqSTGHK6p2xOCNzL3mjgeRhSdnhOi hWkObI9d1qRb3gMtGD5viS5fo4d+SMsfJ+Ulvd6DHJamyJPuCPDIdoyUUU+Chzb83Bn+L fGZ596l/DsfW+2ws/f2neb1HBymM+ytciuYekS+DLo489/eHB1g8u+CqcgA9m3jJ4jf2z GvQ3D1J8+VO9DEQ0589IfmMzq/Z8iFkBik7zK83OQPTBAsmK8Omu7pbEVXi39ZO8RQpJw cQepD0CMCAC5PgZUWyjzvRGNoIqnXaprVlfIfE/uhjhWLnpXV7lANqt2Y20nX4GQmTw== 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=l3k0ylQY; arc=none smtp.remote-ip=209.85.160.53 Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) (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 9F29D60A380D for ; Sat, 21 Nov 2026 01:11:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9F29D60A380D 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 Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-483d290f398so909444fac.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=lists.linux.dev; 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=l3k0ylQYNt+RjrC/CfafjggpM+6tZ1pAumluBHy4eNGxB1anG+KtpzOwHbIehJXFa4 DEVsspwN9HAHHEe+2tjzB363R2Cboyw54MilRtuLQkHXC9b56LsmvOBM9Vve8nezy1OG sePetdDwYpMup8tx5W42iOyQN3yY23PexRf7iu8u6ZP3Rk3kr5zjrzR70HWsjvowI0J+ wzM4uqnJIwb3wQJ5TTEvNK9VWvrBWSgEyT3WlkrHw4BapnfSPozgKgumMVXOtG2EG/wF UmjhejV1FHIJoBaQBJY61UY1klAt3riS6jsWNYJGUSCiZelfozFkbqciBJNVQuZBETEl HryA== 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=HEvPCh+/MF7nhJvX/MdaknkW4BOAroyYIPpf7GuQo3AB/g4aTGK9CmkjaRsB3nJbmH 2idykh6xnXM9UlGCoVNQWLZadTZlKdwEfOTa+9kZbE61dCEpOrG5mEB/0JhfO1bWTt5m z3+nR/clhnQbnDzhEvBqSFBTjr5gwaqGIh/5vjJn/F1nqFM5aYGmQ/oQKgT1g/PzghKi m+UNh2vNAGgfs/5ptP3WZgpqqts7JIp6e90H3mcUFj8IjjdPyPrSqhumFFXpCeeu9XW/ mRzMw8v5F+Rt1u27mu6pieVKQkDkK0bPhiDFXsae+9wpxPwt6Y5DVnT7e97ajfyF0Vpb FqmQ== X-Forwarded-Encrypted: i=1; AL+hErGH8WBMFVr102qwnQC35JUuzOX7kHQouYXfl+eycTUz4zX/HIicy70C/roYWuVLF4z553MSdTtUcf5OTg==@lists.linux.dev X-Gm-Message-State: APuU4Z+gc3vRK75coL4/7VrO8PKReYAEezDNkhpHEZeOvfC3q+JKr278 q3OWJ8RMwN5IWlxlptDQIS2dHwcR7mHrnIPcx9+lYPNHe3jqoNE/kUNN X-Gm-Gg: AYBFou0ILVdHa+dG5PIoCQYSFvVb/D7HyCof6JcfwhdLfT+RAIY1Xa6+BS6stIKIy6J lEw5SjGQeEBNk3dX9ox3EFB5ETSaWpA7nAZnu8fPmJCwRPeNQwq05gozUbNyN7KvmXdx3WiWxJu UTuu06qZtBkK1VxpcXti3jR5Jahjx0nL38CMNIoArU9mmtpdppvcJaq/nwxHgDQ8haJ0KfrO2jq XvxNlVWwdPxmm5jiX9n9ldavJQFtrtzvsU21TOMuzfk9ye60AjW1mWS/w8BXwTlf2a+OQ1gzkg3 wkbsm3BOmcXyOcY3njDcVNL1uX2a8UQoF2JhwXa2+mRSy1a5nlTHhghIDbNmP1vTjbduJBP9/ZT Mj18BZU0Apv43UH0r1M87w/Stq0kk6HDylbYfqra2jspFD6YMKN16a/TQ7ZNDxt7K+xwryU9SOL O3xbk1awxr3u/7fEC4PpoVXUU445fJrdJ5dyh7vqgjw9U6aOyzfJi9bwHjaFBWbnBK/4os12Rjl vmnp+uaA/WIR77xC39wB0oVQHR5oav24WymLcnTJ3121SVMn7ySt07kf2Pw3BwXUMgd22agYL8n riWfgy52+xfNRnGv4JflBfAyWoFUGqdBvA4d9FoMb+BJjh3ezUcrEpUq2upGo/rNV9eZUnId8uz 8qTmOot7/oA0bR7YVgxi32kIMHpaJQazvVFngaTk1R/qCY0C20/TZ5Yeifny/X4YOG+Jlf5tqhU TJSXzFYUOZbkT9iFC0gRtOiibsr47+FCFlgqhvtODKWgWVMaKqMIm9KQ== 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; BLOCKLISTDE_FAIL(0.00)[209.85.160.53:query timed out,172.234.253.10:query timed out]; RBL_SEM_FAIL(0.00)[172.234.253.10:query timed out]; FORGED_SENDER_MAILLIST(0.00)[]; TAGGED_RCPT(0.00)[dt]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; RCPT_COUNT_TWELVE(0.00)[25]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; SPAMHAUS_FAIL(0.00)[209.85.160.53:query timed out]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10:c]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[174.29.1.49:received,100.77.114.92:received]; RCVD_COUNT_FIVE(0.00)[6]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; TAGGED_FROM(0.00)[bounces-27949-noreply=patchwork.local]; RCVD_TLS_LAST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: ABD8E1C5D65 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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_chip *nand, struct nand_ecc_ctrl *ecc = &nand->ecc; int ret, i, cur_off = 0; - nand_prog_page_begin_op(nand, page, 0, NULL, 0); + ret = nand_prog_page_begin_op(nand, page, 0, NULL, 0); + if (ret) + return ret; sunxi_nfc_hw_ecc_enable(nand); @@ -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; } if (oob_required || (nand->options & NAND_NEED_SCRAMBLING)) sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi, &cur_off, page); +out: sunxi_nfc_hw_ecc_disable(nand); + if (ret) + return ret; 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 = &nand->ecc; int ret, i, cur_off = 0; - nand_prog_page_begin_op(nand, page, 0, NULL, 0); + ret = nand_prog_page_begin_op(nand, page, 0, NULL, 0); + if (ret) + return ret; sunxi_nfc_hw_ecc_enable(nand); @@ -1632,10 +1639,13 @@ static int sunxi_nfc_hw_ecc_write_subpage(struct nand_chip *nand, oob_off + mtd->writesize, &cur_off, i, page); if (ret) - return ret; + goto out; } +out: sunxi_nfc_hw_ecc_disable(nand); + if (ret) + return ret; return nand_prog_page_end_op(nand); } @@ -1676,7 +1686,12 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct nand_chip *nand, reg_index += user_data_sz / 4; } - nand_prog_page_begin_op(nand, page, 0, NULL, 0); + ret = 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_enable(nand); sunxi_nfc_randomizer_config(nand, page, false); From patchwork Sat Nov 21 01:10:33 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4209 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mxe881.netcup.net (Postfix) with ESMTPS id 0E2691C5D67 for ; Sat, 21 Nov 2026 02:11:51 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 104.64.211.4) smtp.mailfrom=linux-sunxi+bounces-27948-noreply=patchwork.local@lists.linux.dev smtp.helo=sin.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 104.64.211.4 as permitted sender) client-ip=104.64.211.4; envelope-from=linux-sunxi+bounces-27948-noreply=patchwork.local@lists.linux.dev; helo=sin.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 3A138A6D2E for ; Sat, 21 Nov 2026 01:11:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223475; b=UECzeNjIajbP7L8gavftALsizG3rNURDYzaNY7G7g4J/WUH4aEw03vYSWfxM1XN099ef q4ncsMyoN54zYFhTcg2yDU85ygxViEjnwMdMz3ui8HE/d6c8LOSNh+R4R406cuRVUahAJ 4IzmizKF9lhPBXpRa1Y3VOxUFYldap7TyadNOkRBNtS61Otz9bX2bplr9+YJAtQnrKwFZ oJU4o7bsdEFnR7joxdN+twAAAxfuN9xggBEJ7B1FTIn5acdwWSGQ3GT/onbN0vbWxYlJd cLsJuqwATaBx31o1MMpCG+tv2yOEyPeBvjTehPg7xUXAGl+XCYNgjCq1EwJDpX+ZA4A== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223475; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=T83jSZtlzKtrASqdJI86cD7q3EhrQGMc7SvJoDp9Zl0=; b=oiB9DOVL8YE3Gt6m9SSqG2c/LJIGiUWkr8GB5x5O1ykc8QsiBJdi8J5x+POC7Yd2Kc0q 2a3TbGb341vgZ2b6ThwO++1GyQdcoBKJyMpic4kfSOLH60pSC0TXQChnaZpL3hjdn+YsD sO/veLipvWSYudhlZIPGD0eB0eU0EaY/LMsCiGV8gNRWEkTL9HHJ+NglkM/DXUylOKXI5 SttC8n/5p2UIBEvHGUed9AuEzaUwS0XZio/kHBT8qKetZi/B1dtt/b2e7ewWM4h3rZIQS 9V6qfqnnb0bEuojSAb3bT+7R/62o4Fx44DpJN7XA2QykVJu6YGeZRIVBGnS0mZfmDFg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Wn2S4Zk6; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CDCC1606A6A2; Sat, 21 Nov 2026 01:11:15 +0000 (UTC) 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=Wn2S4Zk6 X-Original-To: linux-sunxi@lists.linux.dev 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=1795223475; b=RZnxgQL1ye3WSA34Fla6vPhXfuGThFzyG+05PiWTPqcrAAqpDw9DiX3HCsVFE1+831bE 77y9QjrUUjhKnNW3bPih78YGX3m+QOhMJ17wnaDWRCzyoKfAVQaRWxazVMWvs2OgkyWfY hL4ZiHPFOZdg5hUfnATzt0ooUyZEVQAeUvjmUPn8ob+Qh7TgRMpmIAMX3QtujYuotVEFS BR7C/5TfhGUC6Bka5JW1hSTDSQc3dDS4BgepTEUeFuzdxRjSJYiVB286veazCAt29u3i2 E01RmJpJcOzhqrM8xySlpUq8tkaRqj3sCg+36M0z7VIUVCPiE0ZvZdwhVTOVp3RYK/Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223475; 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=rE2QZfYL647V0oedr6NMO3/OB1nP+fTmAg35pLeZ2/uluRTxxGWQ9U4ykxTTAh9S8sF2 qWTJ1EzheNY0Q2hVxPB7uI9MLl57EGg/+7qW+OxeE27BvkqgtdVMS1QSMrUlnucKJ+RXZ jvv72JFvqL/QaAKjrHzFNhBEcZYERbLJApj0pnZidSub2LdPzQM1xQmc+JYUEmUVjMQqi 1WTbKZMR7E6qwRCanPZ3m9vb4Ks2GgpOxHtvrdH2YVsYUSjEx4edemC84H+V1ajXLVYwJ 3H7c3GpdHJEH82o42mad+KlIUi9alAIFB1DXD9wugYhjV4wMRf4rM9kLauOMvgCu2Tw== 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=Wn2S4Zk6; 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 B6CA360A3817 for ; Sat, 21 Nov 2026 01:11:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B6CA360A3817 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 Received: by mail-ot1-f49.google.com with SMTP id 46e09a7af769-862b76e3c8cso679959a34.1 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=lists.linux.dev; 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=Wn2S4Zk6Qj3woLe1216iSseJ2TO4r1ssJY8XMuWB3jx7T+8UvWey5AI+1JvMJDTYxc S9zWXq1GCMIVbumFXyTVA3X+Xw2nZqAOfRzRAdFtDFv/D4fybsU7FBxp8vdAZ72gt+aF J0QRG+cgPNp/ODhpnbedw0xnNBT9MhaJRxXrjS+8YJLtj8Hvn9LXh2CLL7OaAMAqhKZV fSW2kyOq4VvPTuThuUtNeRbUa7hDNmaZ+6XKs0r+wVy+rrv23f8ronyz1DqdzswQBAPl X1wNiKJVJkAYg5LiRUOJzx8W94tKdMt1Z6s4a0QSNyvlbQXuWuYAzJDB0uWRpIMCUDQF J24A== 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=M6eiGIx34Sed8Y9iBT0EgizrFarqWKeE+D2yWAf4Ds6gMDjj55CDgfyCEZv+kPpbfD 3K3M7U1qyV5awHoxIDbmclsTcd5e3AW+gxWGGqgrJqt6zhj4bqdGfhW4oNE+gV+VXYHc HHbsSPzi/VIHlhfoDpcU3+1XJlUO+zMOP/tEEaT17b3ZzdNVbXP/TKwcsXjaUaKAETAe xUQIR42OFKJIWV17y4IMgRKi0PQd5mg/I87Hur4yip+bSd3wt4z0IA1MqlEYADfdc0+6 txSzZsyPmywpcBAEDbxi+oLO6jhgwNQD8HNTq+oTkhlHwtKAPLtPn/DXSFlRgPIZXLlt FjBA== X-Forwarded-Encrypted: i=1; AL+hErHo2cUtNb33aYxlONNkgFL2Sb/w4v4+UGMhl5Hl7zWs5jTxkfFZ16RxqoFr+LzwIDyg0bIPjpf1nxYXbg==@lists.linux.dev X-Gm-Message-State: APuU4Z+Bcox7DxGVfncO0qrQId52ewgtNvoLtxqncXnifuwCqkCibADZ O8V56eUhiIhckpv0rAmLum9zSwbjf3vPAntAdfza1KiSPozZEmIcC369 X-Gm-Gg: AYBFou1UtawlPCFipRGngohBXyd/TBDupr6hMildJJaQZlGZ0MVctzx4Cs3NEw4kegL hEHJujsn4SZ+NO7gyRiAf51WBjX/M86kgEJ9LiQ81nLanGD0uUBcPxVR9IO5HqVVO3mfRa0zLSs DELNH2DUUCr+54kIrJ6p/X3AlNq6QNXMxQqn6J8f8mQoDtd/Qb9/sUrZxbEuTD8BAlb5HNnQSbY sLUcWv4oIEpCRhYGjMt61NJVyM+S4mZXGNWOAkRum1bjmkDHmuPDNCI46qxCzp+SffYq8ILe5RA JBvcg2ZNhEodqPGtYkUCe/mlDiWM1AJb76MsfFFnoIrtepXa69iY7g7Ifu5UAN1I7OgmamGRlUl 6mrcsjjH3TKyjNXxlPhqcl/uwGKsZT+8Swzgxalq3QSuZVe0pMHWzbCYe0gggCJ9hoWDTYOQezL 9jsyBZUXjosgGToMamtB6ZPAroXyU7gJSk7if98wuFk1LI9AtTDfRCcZGArgQUTUG/CtaaIHJUt SpHALN6u+a7BYyur2j96nc9TvAWFHTKqfT8JZhtZZ1YwIq6a55LXEvPsXoLsBnZZ7/dlw5MfngA dcGlqq3geb9CQ9DWlBiHEJNBo6XQUzRYGiiQSr89atq0JkSx9R+6IVhZ0D7ZwyZvKwBHpRY3rvO /JliKNTA5CX0qz4cNN8BtoakMGewWFAm6OQjy8GykxiUlKzNEb+nCFrBbojEvN+miTsQ1kawmG0 L6rQfUj5xrBdotFN64kfxk+827gBbQKoSed/iHnUuttOAN5Vt7TzKw 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[104.64.211.4:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sin.lore.kernel.org:helo,sin.lore.kernel.org:rdns]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; TAGGED_RCPT(0.00)[dt]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27948-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:104.64.211.4:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[174.29.1.49:received,100.77.114.92:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[104.64.211.4:from]; ASN(0.00)[asn:63949, ipnet:104.64.192.0/19, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 0E2691C5D67 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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 operations") 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; - if (unlikely(!(readl(nfc->regs + NFC_REG_PAT_ID(nfc)) & 0x1))) { + if (unlikely(!(readl(nfc->regs + NFC_REG_PAT_ID(nfc)) & BIT(step)))) { pattern = 0x0; } else { pattern = 0xff; From patchwork Sat Nov 21 01:10:34 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4206 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id BF44E1C50E2 for ; Sat, 21 Nov 2026 02:11:41 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-27947-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-27947-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 4CB143FED1 for ; Sat, 21 Nov 2026 01:11:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223474; b=Bz+WQFBJQ8z7b4UWWCwpRE80wSPGgRmTujnLsfAcZjObBa+u9SdH5KS07Dd2oKNtTGcj zqZumfGGz3X96l6xRyP7bBQ9A/eq3Kv2rAvmj2erNvcLkdZmYnFXpNrOjMMbW0ouFI1zI R8xdTpAvBGnQEtZZLplO1Lwe+REGik7qBFdQd86F1PPk35ZE5b6daZMGmdPIVUnsiHRVq Ek2pIyDaejfNFFRR5+IEUVuhuszhAMMNNYuhoJmL5kqVbua+cTaLeduUI+UV51AtjPcdV 7Hgmpx88qqhe1Fbbhe21QdupIZGJqmIB4IRRx/RYzies7Xh/Qz4ycw0rdwtGYowawuQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223474; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=u89IqnoAKi5kjnWBIZSz6wZn1oqd6Ypo53SPsotyUk8=; b=tkoH92hLreqRt2u92pTMyTEy976pTM6C+EjGrlHv6cz6O5/bKKSN58Rl5jJQa38Cn2cS p6ZSPX1dAv+9IK6UgmtbA7pR8JE7r41bpoLOGvurl8Qk67jJ1c61KardHbE0fIt9D7KRR ToOGESnQm3DNoAKXLPdlIMksF7J9HULEr/jXaHboCnOtwXfGHk/fwzHqplO3/dtxyapul CbfJXMkiOkWDNhFpEUZYo39mOmfOZrvnTrtk0GbWgpO2noRPZA4uEgQLzz1UvKVpQbomB Jq974LiQg9uUVHSHHZD0L/pHVeHmQnBJMObFTYs/o5ndEL4mKP/hOVTpUUXzJNutpig== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=AcOn6EqE; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB5EB60A2604; Sat, 21 Nov 2026 01:11:14 +0000 (UTC) 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=AcOn6EqE X-Original-To: linux-sunxi@lists.linux.dev 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=1795223474; b=oClNAyWqpqTDCyspJdrnpCsVXISGRL4i+rP/ZAfR96jWraJwtrKfmphpawC3/qexwoMk dTJAo9Tx8u224XYNBO3Vo6WGBBJbj7Hn/Qyo5S/1XZ6tLHoj0DKlAfIDmh7VdiGV0V6+9 akETofRMGCw9ERZxugT138TKELAmccdxI/ZFY7Xv0vlZb/is1VKnPGp88M62m9xNgYFbm y7QZjhDXEsKo+ZiTHR8BG8hIBIuexrrop6OKZmnn4tBGzoQkfU9tEHv0vBgMfT7NX7EEg yoC9aLiO5Ag79i4Fbub22KUFWleodYfHJYJgl+D9dUFlu9tRH7ZuHi840z/eYZJ50EQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223474; 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=1GLQbHL9OKiC/ld2pqa6jZTZUgOwObu8+EFPOG7t+X+dRB1o9sx2CeaQqG0J0yX2LY0V dWp/+W79vhkBz7bGglKei37nWlruH8AkSZPh3DvLQFPS1CpeLZtDfSsmhA238YpkE2K4n LLFNlpepsgU6t3BFBNEntpLDZKRnflA+faSHWj9hAyKp7HE9VFfahs/p0SyfMfLMwIlH/ DY3+GScL7KNn1OOOGMPVBgPWlFX+WRb0H6hrKM5b717KEOiv8YCkViz6ZvzbcvFIfdAF+ uCHA30vVznuuLR27Pp7S04aP9mG1ukoap8TTxgft7BXWjjUptw31IZQPHlBkfj4GvUg== 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=AcOn6EqE; 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 3DD0760A2629 for ; Sat, 21 Nov 2026 01:11:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3DD0760A2629 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 Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-4b28d7c729fso1187915b6e.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=lists.linux.dev; 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=AcOn6EqEuTrh46YRUAgHrxCIOXmaP4c2vGk73HZlRKB7bxD++wLNCuP1dsPEnyQNEY /b9iKKjkjZyRnmzpbzveTzAdI20pmH/g+7VRk0Yt5jb3o4nqXLGn8Ca44LZP6Z3jOsWU zKPmBePmmqs+sxXaPBHzKy60dx+64c+ief9sv5d+Nr3DfMcnfC/HycHFcdlSiICBymuC 4n9ZzwE39xExQgiuJvq9D8rYfXd6zFdZiQNZgZh+Z0ZE4ANY0x/xLzDVyCcHMfrJbJUQ uQgi8cEvCDpNDFn/Tnh3I7BUYoGed6CmlvVSc5VdIBwjlmNb5y5iXJn/weQ+ITtJUO18 JeDg== 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=fTB4+njBrReHcPcH6IblSYCRgmIlNAcwVHcS0seznuUJrzhFvLeDHAOkHIFMdb9Ct4 IXnt4OJW37pcQiOHzBOdwFl/lSNAENHrNIgdF0hq0oasP4L5UX0Gpe0bdEPhrqcGdayC Tthlpz8Cwb/NrMBdTX+krE9lkHIfVFGHCUXoRNOAw8wBV2xe8G6PhXuB3s/NoaMmkL6e ioRNTWeQZ5xdVsvLO4Sue26VdqMelau7JKoN0KW+94NOSSvXTnXTIfej+RMTyigS14ND Fg1p1HAtnvZycqxxMQv2qPJM3/OoQez+V5mOSawJRCFtghe87EHV0uHx6trN0WF3v59u J45Q== X-Forwarded-Encrypted: i=1; AL+hErE+ySehsKlpefmFuVkrGoGWfd+QO5+ploiTeCSD8/Pj4JbtJChLAjZ08w9oMQGwGsQ+6e0P/UywVxJPvw==@lists.linux.dev X-Gm-Message-State: APuU4Z/KbEzd6jk4B4PK+pNpIEnZqtRIk1qtR0eHkukz7PqFs/fL425p d7bNRs7PiUMvFt/yjv8B5yrKxTJ3Zc1LKop6dvvNZEOBV6RxTCy53YkG X-Gm-Gg: AYBFou3l5jbvTGXVXZRgnbO1LIIYy0L2Dm40gukUOKUh2ZTuZQNsseS2gjGLcb6B8WL 1SFdk5+hUk/Fjwv/MriF5qLSvhluD60zecWkF+l1fKQKrBlt6fslKaU4Rre8/5gTE45BVgAIeT7 RMabjHG15rQO3/jot7k0x66hv6DSPTuxw4GOTd8mT/Q978HHAzdVhPYmeiI66nhLDAeGSbV00sN /6b9HtG1RjtUCzhk3ar1oOVln4/L6kqEG7dFUn1bzu6mX0IK3fWvxnEYurf0wuZiGOF9QMtoBZq qmJaZnnyU7lHK0WcurajQ/1kiKkXn2Wp+7VAOOxAAXDBKftk9PNa8pSmVQC+5S7wW+wvyfQ3dxF WgtTdI5UYcgXavpllsptGUzdzSCUfWRbXkTeybIMGLHT05iQbQoYLGNM5AN0SuaJy/cdlf15lYW 9TZ2ksa929Ankvv56ocrU45cjT5D4jYjMkqSshquJctGKxVjJxSW5an5uNIdAfPUs59ucFx2Bnc TQU1l2gogla32T5mL0mSTSaWAAFsEh35VX+Gq41ZuNMxrgqvboVymtkonKK67DU/1y799QFMF75 AQq3GK6xQRWSGRyIWoKVQojGa3BNwuT9YD8mu1cDOAmyCI1AEcsaA2YCmLwQDI5hA1tssCUxcE+ Dtq5LX2l44im090u7tDgL56mSzcTJcmFqm6Z5eJYwzDC4dRIoZ3XceoSTE+0t3bkMIzQhxEOs7j M1O1U0CXMOJX+F3R4ZCc2JIEy7WdX2Qw/bii6OM0hRZrFmvZ1OgdzkDZsst23v3r5Vig/yJHAm6 Q== 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.105.105.114:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[26]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; TAGGED_RCPT(0.00)[dt]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27947-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,174.29.1.49:received,209.85.167.172:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: BF44E1C50E2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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; } - if (erased) { - read->has_erased_chunk = true; + /* Both patterns are already filled; only all-ones is erased. */ + if (pattern_found & BIT(i)) { + read->has_erased_chunk |= erased; continue; } From patchwork Sat Nov 21 01:10:35 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4214 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id C3BA41C50E2 for ; Sat, 21 Nov 2026 02:12:05 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-27952-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-27952-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 43D5643983 for ; Sat, 21 Nov 2026 01:11:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223480; b=ocJl5wci4Xr4ceVWCvEL+CUjzYw6pIQE6s3+Wpg86uvJ4xcDdQ/k1y/iKlovD6cR4RlH ybJzHqleRhJftU4RGNo4bNQGpPiVxBSLVg4oJWgsjnxaZfGmaTtaSCtjjxSWefEfWH6jU utGJLc4nQdNt583gQxlsUGUWxmm+EpI4PR5F5hiIH3UicUoiZIWrdr+cTFRpbGc3CxLvS I6NYPJh6hZh3UyDxN60W0Czw3KDdfwHlU8iprI9mXJ+HPcaIKx7Zc43Fqtc+KCCcO3YQ3 Dy8whWBmnDYvaArgkNzyXDNOrbQqg+5WxgXkn0cWecidiqk1biQYsDcWz5LewxqTW/g== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223480; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=25Y0T/EWWqPPUndC1dVyA3/WPrprnkSUm6qbYkkV3TY=; b=YsU2GZC1ke6/gz9JLcx31wLLYu2yDvvWsBbQ3syEkhyFXTtM6gJB8ogj0IoaRWAgyyil lIx0cRSbFoXWytCP2Q4XbNUsoF+71NdsKE0XBnQdxs2GCsrL9UfVcBjz6uy5qZY0O9dSH jHZOoH9jeVEQds4GTZLEnNkFgDReSHty5Hs86gEBSM8lgToqHo2gKUyh1G9uW9x3xx7dM Am5/0//9iEexDCHzqyCBTAWjNMUKSfl8tEw1V7mGGyYHTKO5lsHbOpbOBSddOgjEd9Rwh Er6HsfyGSAMNTJSLWNZOuV0WA0D7O6zjQaU7ByHDX45BjWsFZNBl2dJKYehOhvXDOrA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=izAJxhhg; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2AFC860A5BD3; Sat, 21 Nov 2026 01:11:20 +0000 (UTC) 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=izAJxhhg X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223480; b=KadX0x1KuTaFzUhaRIE6xFt5xqcRVWCszPOi4S032G1BJmH+JrVvv1stj9LRj+0oJ64s mr/feUovg1oOl2t0LRQbBw82E5Ajr4uBdvfrCThB0k4hyC2u+ba8OzMdRI8SMJpiTqmI3 SmYEmemcfnxgelM/T6y6L6oX6pvKc8l+F3YC9vdGTNhttysJxuCiDDWtXt0/XwByQBU8K Mp+tqpguFcQ3qr/z2fp7bkAM3qkGbUfT8yqV7qH2kQR4f54vww2phclgd+l6VeqB63GXq CDIxdzlvgMMxRNJb/fBxte/nBhAOcSqTB339bo4ft10IJbC1M19a6Ic/Py0WDuAG2tA== 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=25Y0T/EWWqPPUndC1dVyA3/WPrprnkSUm6qbYkkV3TY=; b=eHd4xKrScTNVqAIo2ORcoIUMNI1kSJcob8Z9CpWixE0Qcna5t0eRSve66O9BQULEM6p+ nky2RTo4CBAuwK9iqpEK440pu2iQStMvOLDuH5UQo1xhzNy4tV1qVIo6tmtilVgdKETXT PDSiNpMqi8PiundOPg+VmRlFldM9kd+XZtHxj9fckoI6eT3C79rUygmGURGEyusbKbYzQ gGD8dXml6OGnbjYFClUz/Q6gFNyD5BymomUD2TIwX7EKH8QsXahYuCCjCiQylu+qQlwsj L6momoHxLgFVMViKArWglYfIYa3cX2jv9gcjl3ER94I76xBUXlEMN14n43KteybO6QA== 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=izAJxhhg; arc=none smtp.remote-ip=209.85.160.48 Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.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 A1681606A69F for ; Sat, 21 Nov 2026 01:11:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A1681606A69F 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 Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-4a85c656c58so1032393fac.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=lists.linux.dev; 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=izAJxhhg/HCeHqTeGMwPXz+N63Rg/0mQUeBVuAZ/AqkGv5Jyg8zgiGaGPUJyjcSBsq XYVOM2NnWtOTk1uY57M0MAguKaL/yOFd7ZcPboy5gLXtB9/0mD5Z9feu14IxE5C8P3w9 LGWeUzJBKME6/APlDb00wN+UBDXXJLljKlrs2sUOp0kKz/0RWnOr2IFZfQ+uvPV3dO21 dHT3I0PhoSyYx4aygHQBLGPUfN6A7iUvM9j1RilLCdEE4Vd7fC42IMVyH16sfxbIL3Zo uVkLqMMjvdsPSTVB+2e900HBH6JtauA6KBp6/g8+44UTNXcVgSn1yPkygoM/K7w7Jzlm 9wOw== 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=XA9y2ScmdGYllTSEUE3+ZLS4ns/lMjE+MWfYzeAaOzJhyWtzpcIs9O93Mj2GnVTBcm mKKBlMppPjbeWpnQgTPOwZVvUmlLT6EU6/4ALHtoSNxxaGCbijJp3VY470DBvlEMxM+K ChsTBDwnQDLClg2FMhS5YRjsdbBIt+GoyC16rumdyuwoQYStHyo0+3YeGh8H+LFOd5CZ FoxkaM8ET2hyhb43h3hJZJtgZhB0rTO0xmWrAZFuZTfroxmybd05doMZ+jT7Ggw+K9Kk 0AdHq5eKHJbPgr6BMQBxRc48ad3kA/tVONgZMtATY6H2avAWs2e9SPQxB82B14SsXkVO juxA== X-Forwarded-Encrypted: i=1; AL+hErGM1U+IbB5NHapFwONsGRiWajV8RXmsa0hzprGFBzHjAJgSeGiC38RfiCCaeYJMObshRlHQyDim5+ypvg==@lists.linux.dev X-Gm-Message-State: APuU4Z9wcvFotfxsuxNhezugB8YT5jswx754OZvWwtlH9ebM/9v18BXb dxwkcucKr4kRUi6SqUseCtdGYX0J9K2cg2P2KCCdX3d+Q0RLOgARC4fc X-Gm-Gg: AZFdTZfDEUnTW2nSO4BVfxBVxS/LYqd7Uka5qDJItdaIEu69TIC+UsWtSHnLgkCmKIh Om/p8xAlkc60d3gMImAWGsViKUL/Ri3fCRiUf7sI5xMoAJA0QgzbkZJF+AUBHo/TuwYP8Ih+ZYH F6m/22RmhufKKzB2A+7erTZ0lrmwY/IraDKHaiPGJHp9IQtokgvgLjvXXPnmEhdeHfT+q2MXdkb dtGY9WvWP7LmFqmnPB/mv3HxNqO0Bxw3iD2Y/+8bOYSvHAZ85rYirUAWM9Ief8GfONu/cCWagPC lnDzQGYB7BesFsAJwA28t9V69Drbg8tm6mALj+8SNd/rzSQPPjDp5YWLcotCSR7DVyi74L97ynV lkTOddGn3wBZaLrOdZg+my9svVyTADtVp9oytnGI79ZjNdxezy2UGwIBhPmxcXMEQMPeMTfjVLx TyXejZX4HjLsPqmVibcsSHndKjzsvRutWRSrrZVQamTiGN7oFL+hz2N0T71gduM2ctORK9jc3Nl qhcpMr2OpdoPGXzXU6ofSE9q+eoRlAAMaqdKTbE7ee9DYZ6qSzN8m/2sZO9FZOgCm30yXRZm5M8 7X4j0EufjMwDCbzpSG/+kfOfvcrZVOCojOCPONJKBWtl5AWldYsHhBYjDbP5hY8A9Qll2nviYMC VRPPPByFJUbHlXN542PZAWfMjjLpLu/ZL1/VHAppSkqxu146P75pJtDmgwxWu8a+oGsekZGOGp3 Bg72EmEfw6edrOMMiTAdvg4N5wEhGuYOwyc7oT9JBr/2IkMzAEuSgo 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [1.01 / 15.00]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; ARC_ALLOW(-1.00)[subspace.kernel.org:s=arc20261015:i=2]; R_SPF_ALLOW(-0.20)[+ip4:172.105.105.114:c]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; FORGED_SENDER_MAILLIST(0.00)[]; TAGGED_RCPT(0.00)[dt]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; RCPT_COUNT_TWELVE(0.00)[25]; BLOCKLISTDE_FAIL(0.00)[100.77.114.92:query timed out,172.105.105.114:query timed out]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; MID_RHS_MATCH_FROM(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[174.29.1.49:received,209.85.160.48:received,100.77.114.92:received]; TO_DN_SOME(0.00)[]; RBL_SENDERSCORE_FAIL(0.00)[172.105.105.114:query timed out]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from]; TAGGED_FROM(0.00)[bounces-27952-noreply=patchwork.local]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: C3BA41C50E2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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; }; -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, int slot) { struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); - struct nand_ecc_ctrl *ecc = &nand->ecc; - u32 tmp; - - *erased = 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 = 0x0; - } else { - pattern = 0xff; - *erased = true; - } + u32 count = readl(nfc->regs + NFC_REG_ECC_ERR_CNT(nfc, slot)); - if (data) - memset(data, pattern, ecc->size); - - if (oob) - memset(oob, pattern, ecc->bytes + user_data_sz); - - return 0; - } - - tmp = readl(nfc->regs + NFC_REG_ECC_ERR_CNT(nfc, step)); - - return NFC_ECC_ERR_CNT(step, tmp); + return NFC_ECC_ERR_CNT(slot, count); } /* @@ -1203,35 +1174,38 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand, struct nand_ecc_ctrl *ecc = &nand->ecc; bool randomized = nand->options & NAND_NEED_SCRAMBLING; unsigned int reg_index = 0, user_data_sz; - int i, ret; + int slot, ret; - for (i = 0; i < nsteps; i++, reg_index += user_data_sz / 4) { - int step = first_step + i; + for (slot = 0; slot < nsteps; slot++, reg_index += user_data_sz / 4) { + int step = first_step + slot; int oob_off = sunxi_get_oob_offset(sunxi_nand, ecc, step); u8 *data = read->buf + step * ecc->size; u8 *oob = nand->oob_poi + oob_off; - bool erased; int bitflips; user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, step); - bitflips = 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; } - /* Both patterns are already filled; only all-ones is erased. */ - if (pattern_found & BIT(i)) { - read->has_erased_chunk |= erased; + if (pattern_found & BIT(slot)) { + u32 pattern_id = readl(nfc->regs + NFC_REG_PAT_ID(nfc)); + u8 pattern = 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 == 0xff) + read->has_erased_chunk = true; continue; } + bitflips = sunxi_nfc_hw_ecc_read_count(nand, slot); + if (!read->dma) memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, ecc->size); @@ -1260,10 +1234,10 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand, return 0; /* Finish consuming the batch's corrected OOB before raw error rereads. */ - for (i = 0; i < nsteps; i++) { - int step = first_step + i; + for (slot = 0; slot < nsteps; slot++) { + int step = first_step + slot; - if (!(status & NFC_ECC_ERR(i))) + if (!(status & NFC_ECC_ERR(slot))) continue; ret = sunxi_nfc_hw_ecc_read_error(nand, read, step); From patchwork Sat Nov 21 01:10:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4211 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 14AF81C50E2 for ; Sat, 21 Nov 2026 02:12:03 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27951-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27951-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id D030C879BC for ; Sat, 21 Nov 2026 01:11:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223479; b=kYx61WFtMt/PkkrmtZ9HFGOxHlUX3Jp9gv8YO096PaOC0qyjhbdGJpNqYupHSq3ahRVv pCOafhOj+wBQqUwr6bZC/lht9nlux1m97tpFKsdHP3AHUu1nM66WfT4MwPiD/7H5zBu4q Jmo6EBOBhx8clz1FUOBsL3hhXNeJxLRwE0tPHdpivp1g6TpqdnGKIkdUoA9Ijq9AOG1QG BSafOv3a18FvX1UfQ7I1qDpbIAI+uUFXSxH+ELwyYa2RrDX+UFx6IHvU8OeOS2hAQUKzW wkQRJe2nq/wqB5sPQdij4PBHvIohiHxD7RnKHLB4R9aeIiS3HK2oQa96vrA7RnU0UEQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223479; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=V/ZOEZdBIX9Ht5ZtaAIcNRRvXcoTuAbgmishigtjssc=; b=PtX7jfvoKZmd5t7ot6R6C6ZfbY/iDRzkacc0DFLByrIPvzXxXQH4lzmLEijJyIIFoKxH EGzxDMQ4sKkZHFhN+vsjZK9mqhble/oR8Aq5BFrx1Oo3ZGR1ZDqcKSiWMHQKk8aMF/UzQ KpvRyqKYCgM8Us5EkqpRBkDLamaR3pIDYM4XlVj/DD2cK82vO1TUKDG5j5UX48ejnoCj4 ma6fa+LSIrimET1ZFqbx3EovD5ZwolzBdg6+wGBelxMv0Ei8e32RbmK0o+GA4LHeO+imK byt10v4SHBQD+JZP/azIA347Et1KoJRieGKsAVRssurFcIlN7DsDkMUapAF7m6RJwyQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=v4aJI0Jc; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9955860A6F43; Sat, 21 Nov 2026 01:11:19 +0000 (UTC) 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=v4aJI0Jc X-Original-To: linux-sunxi@lists.linux.dev 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=1795223479; b=xGHIWCWLm61dsiAnzQcrHauMkHajvynj5nMznjAI2vbNeo6D8+zrwwFAPxQYJDPjKjpI GqgqSNztlzrJBekG0IEM7tVRMfVtJ8bSdXd30fql/McSDrbMRUkTs7Ut+9QyoPHBMfm4D co3VFzjRNKzursl1G5sefZ6HStDJDJrF6cPqLRVLErXnowQtK435HMnOEuRrGjybN4bN9 EtLjf5kuriSi2WPY8ZaYoxllzWumwW0qye99fTisxaMp4xccqbiyjbBmP77L0Lzjfxowq eUcL0eFoh5kY8Le9rocOg62h8p5JbyulckS9V1EqMWpQZIuzmHLaNTGRzSSvuF61Yng== 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=V/ZOEZdBIX9Ht5ZtaAIcNRRvXcoTuAbgmishigtjssc=; b=V0boMNuEsg8z/S91ny/WxMHd+JJC2VsKURryuCQaQaffJj7mziUaKohCQE+HJhdpLMRH cQfmVgySZmngFRDs4myjcoS+BKJ/hFQq5S0Mq8q147lKmI6OQhQmb5kjsScGbEDC91WMr 07/vMa+jF2tvFLoiW1YXuwXyz6dl4ZyXdWX6aJ5sRKALSXWRbslH98CZWBIatPWQb5es2 Mwy8MXXolksciv/bllzgK2x00a7INSGy4KwF3nDCIm/kjgRl5YNV0BWU9h5MLNNKMc/XA hhHZkJZMZjF/Je3jmD6cRkIj5vt5AomG/+0umhPFfxQcf8jp3UmUbB+2pRkvYBueU4g== 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=v4aJI0Jc; 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 6ACC360A263C for ; Sat, 21 Nov 2026 01:11:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6ACC360A263C 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 Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-5642e0910a3so741984b6e.0 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=lists.linux.dev; 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=v4aJI0JcfuEB8CsSkCsuUjD3GgUkXBC0u/cHK6Mwl+TgrdNiQMG/iriB1SoWIGzDMD +dXGvTtLb+pEWw4ms2U/ko+fua2BSTXMV0P8pl8roVyiMjlTorIEfDrzqr6JxQ5n7JWS H8kKiAPMzN2FyophA5BNTV9FQRoyJM2YL5a4FDn+7xBwvIL2zmPj1vbK6PR8sxgodvxc TSDZcHesNUcDUgeB+Gon6jAQOKcBBZoKAtcPQDGI+ZTpRK6HYYnpaXYj2m6TBgSfc0tI p/HAcrKmgRrFzCEOEioyyF2LT+QetIw+i+dibLGPVEsmqUwDFQ2UxLFxa/eJ2dvKHe8C m+Rw== 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=fQZY4dD0DAdEsIM8zEpv4OC01LIybWwQYl0R87F0vgitpr5ltdCxPbpi4SEMWusVa2 U9uKgKUQWTkbKb/3zCvjAXdOV3Dr0Hu4BLOnub+Z0N4/14F3mo2i6v7S5zfTrLG4RKGO q6IEW08wyNWbfO+g2Q/ygtSunmjjfNKs0HBZ2Lm3VOtdcr5OmqW7/l44dgGB6jSbe+YE HdckPsBz/0GUR+t2T64qbTQt+dAIBsP8DYVpF8z5bZ8/uUw3yex9927tEAN5V5B86swe moKmhj9Z4iSkAi/abH+FFM1B8G0lDJagiBe21OUQYTrRBFg1F6CBFCVsP3i8y+CnPeRJ wECg== X-Forwarded-Encrypted: i=1; AL+hErEcq9mPs3FLybcyamREX+c5PaeLroK2ssWoAHZPuD3ImfvMAN80CQRaFdvobQW7R5NVX1YtRIqSTVFlSA==@lists.linux.dev X-Gm-Message-State: APuU4Z/pcTd8WtilIHkIXrmYrHIPa6wjbq5MaosX9zkq+o+vh+UpJ4ML O1tZPwhCGMJ57Xq2w4vnNMsMH8htOy8qJ8EnxO6lTE1qTIigPmD27juT X-Gm-Gg: AYBFou0bt/dNCYjalVbK2oYcFUhavcWyuDkTFtJ0yZlWEumpb+uTSOejDKDDAaZLo5s XF8OnLBo7DEKQcztnRsSWoZPsPsj18Ro6wNOIooiBvauoVNCnlP9y+ZH50h6WQU1ros34kL+gCM aeenO5qesppWYyIuhhArWe/5wQVQys5UgUq8SFBmpNfdP3kQfRtBBAd9wLemi7RKEwiuLKejjdh F9l8RPR5F3EFtkwmGYjLVd3tzyzQa8pUe9559yjRmn7+cK3N2/j9Pf99ZCK4IY+ONm+VsshTVVG oAUb06GsEJLyWGolOD4dg9xA78Czy1jGsH1U7i/hC/BCWsZGQTbIvTWGDSbF41vW8uYJUvOWNcY juEJOS8lJ4co5fs0BC89aS3/L/Psrbd+xT5GoYx9D9JKh9E5AXfcG09BiR8Oes6GRMk6DUaE1Vq Ai4jtSuBHn23UzPCPiF9kYQ/ooUTlfjFJTOvycFEWW1h9O6Bgx9VPnhQkUKOoEiUUaAUvtvyrSS UBbahyJOGEeaix/E8rEHotPt1BaZNFt3ArIaBUcGfgJ+8tQMH+IExmvWGZPAmFr4s7DfQmwXj8c eZsUtAOQwcgK7SVDby5dK7FPWOGkK4bsiXTgKN5wnKdoZoVd+W2VtXOBzM+zR4nDOhiIcESkNLn gBIYb6pllOUwQbRwV1t5RSEnYaBiB1IMbePDnns97twCoBk6Wdm09jj/vDcWzpZbtRTcjjwFYdA 9CRPOHXKWnAtM+hbl9a2TGWYkt/mMSWTdzR44H8t30Evxu7LSIvqeA 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [4.31 / 15.00]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; RCVD_COUNT_FIVE(0.00)[6]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; TAGGED_RCPT(0.00)[dt]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FORGED_SENDER_MAILLIST(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27951-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,209.85.167.180:received,174.29.1.49:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 14AF81C50E2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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 *nfc, int len) return min(len, nfc->caps->sram_size); } -static void sunxi_nfc_read_buf(struct nand_chip *nand, uint8_t *buf, int len) +static int sunxi_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len) { struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); struct sunxi_nfc *nfc = 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) ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) - break; + return ret; writel(cnt, nfc->regs + NFC_REG_CNT); tmp = 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) ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, poll, 0); if (ret) - break; + return ret; if (buf) memcpy_fromio(buf + offs, nfc->regs + NFC_RAM0_BASE, cnt); offs += cnt; } + + return 0; } -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 = to_sunxi_nand(nand); struct sunxi_nfc *nfc = 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, ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) - break; + return ret; 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 *nand, const uint8_t *buf, ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, poll, 0); if (ret) - break; + return ret; offs += cnt; } + + return 0; } /* 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] ^= sunxi_nfc_randomizer_step(state, 8); } -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 = sunxi_nfc_write_buf(nand, buf, len); sunxi_nfc_randomizer_disable(nand); + + return ret; } -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 = sunxi_nfc_read_buf(nand, buf, len); sunxi_nfc_randomizer_disable(nand); + + return ret; } 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; } -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 = to_sunxi_nand(nand); struct mtd_info *mtd = nand_to_mtd(nand); struct nand_ecc_ctrl *ecc = &nand->ecc; int offset = sunxi_get_oob_offset(sunxi_nand, ecc, ecc->steps); int len = mtd->oobsize - offset; + int ret; if (len <= 0) - return; + return 0; - if (!cur_off || *cur_off != (offset + mtd->writesize)) - sunxi_nfc_read_column(nand, page, mtd->writesize + offset, - NULL, 0); + if (!cur_off || *cur_off != (offset + mtd->writesize)) { + ret = sunxi_nfc_read_column(nand, page, mtd->writesize + offset, + NULL, 0); + if (ret) + return ret; + } if (!randomize) - sunxi_nfc_read_buf(nand, oob + offset, len); + ret = sunxi_nfc_read_buf(nand, oob + offset, len); else - sunxi_nfc_randomizer_read_buf(nand, oob + offset, len, - false, page); + ret = sunxi_nfc_randomizer_read_buf(nand, oob + offset, len, + false, page); + if (ret) + return ret; if (cur_off) *cur_off = mtd->oobsize + mtd->writesize; + + return 0; } /* Interpret one PIO step or a completed DMA batch before reusing its status. */ @@ -1212,15 +1232,22 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *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 = 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 = sunxi_nfc_read_column(nand, read->page, + mtd->writesize + oob_off, NULL, 0); + if (ret) + return ret; + + ret = sunxi_nfc_randomizer_read_buf(nand, oob, + ecc->bytes + user_data_sz, + true, read->page); + if (ret) + return ret; } 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 = sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi, cur_off, + !read->has_erased_chunk, read->page); + if (ret) + return ret; + } 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; - if (*cur_off != data_off) - sunxi_nfc_read_column(nand, page, data_off, NULL, 0); + if (*cur_off != data_off) { + ret = sunxi_nfc_read_column(nand, page, data_off, NULL, 0); + if (ret) + return ret; + } - sunxi_nfc_randomizer_read_buf(nand, NULL, ecc->size, false, page); + ret = sunxi_nfc_randomizer_read_buf(nand, NULL, ecc->size, false, page); + if (ret) + return ret; - if (data_off + ecc->size != oob_off) - sunxi_nfc_read_column(nand, page, oob_off, NULL, 0); + if (data_off + ecc->size != oob_off) { + ret = sunxi_nfc_read_column(nand, page, oob_off, NULL, 0); + if (ret) + return ret; + } ret = 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 = 0; - if (data_off != *cur_off) - nand_change_write_column_op(nand, data_off, NULL, 0, false); + if (data_off != *cur_off) { + ret = nand_change_write_column_op(nand, data_off, NULL, 0, false); + if (ret) + return ret; + } - sunxi_nfc_randomizer_write_buf(nand, data, ecc->size, false, page); + ret = sunxi_nfc_randomizer_write_buf(nand, data, ecc->size, false, page); + if (ret) + return ret; - if (data_off + ecc->size != oob_off) - nand_change_write_column_op(nand, oob_off, NULL, 0, false); + if (data_off + ecc->size != oob_off) { + ret = nand_change_write_column_op(nand, oob_off, NULL, 0, false); + if (ret) + return ret; + } ret = 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; } -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 = nand_to_mtd(nand); struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); struct nand_ecc_ctrl *ecc = &nand->ecc; int offset = sunxi_get_oob_offset(sunxi_nand, ecc, ecc->steps); int len = mtd->oobsize - offset; + int ret; if (len <= 0) - return; + return 0; - if (!cur_off || *cur_off != offset) - nand_change_write_column_op(nand, offset + mtd->writesize, - NULL, 0, false); + if (!cur_off || *cur_off != offset + mtd->writesize) { + ret = nand_change_write_column_op(nand, offset + mtd->writesize, + NULL, 0, false); + if (ret) + return ret; + } - sunxi_nfc_randomizer_write_buf(nand, oob + offset, len, false, page); + ret = sunxi_nfc_randomizer_write_buf(nand, oob + offset, len, false, page); + if (ret) + return ret; if (cur_off) *cur_off = mtd->oobsize + mtd->writesize; + + return 0; } static int sunxi_nfc_hw_ecc_read_chunks_pio(struct nand_chip *nand, u8 *buf, @@ -1574,8 +1630,8 @@ static int sunxi_nfc_hw_ecc_write_page(struct nand_chip *nand, } if (oob_required || (nand->options & NAND_NEED_SCRAMBLING)) - sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi, - &cur_off, page); + ret = sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi, + &cur_off, page); out: sunxi_nfc_hw_ecc_disable(nand); @@ -1698,10 +1754,13 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct nand_chip *nand, if (ret) return ret; - 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 = sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi, + NULL, page); + if (ret) + return ret; + } return nand_prog_page_end_op(nand); From patchwork Sat Nov 21 01:10:37 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4217 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 4CFFC1C50E2 for ; Sat, 21 Nov 2026 02:12:29 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27956-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27956-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 7428A6260C for ; Sat, 21 Nov 2026 01:12:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223485; b=Q15UUiO4yPRvuDtGIyu++DjTEsTlbFw9fxtKTdUf27F7OvsOWFmHlCgRNAyHlvtM9aat /1q9ixStHZpRQZNCyJHGhixTehDn+7lyF3hZ/BvPEmyd2xbm/S/YhomMeVp7znS2oxkz9 QneJ58OP1skJ0IOXaySuJ1ys7Yv1MKHubbV5nrdcD8S81C0PF8HmOxLweTDdVpOv+YM4T KDd6HcWaJAQhdWVl4W137/ofXbvbueeqikiLqCZwNFQ4ke+HWEOGrb0xi6S5J8OuMOp7n K+2tBt2Q28DE6vwIQtneXIjLN6KDd4JLyqWDmpJteKyQjTsIbNNodmGw2gx9SP95+UA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223485; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=CgxsAtXFuwPIOpoqITa/yCw7bucmWGSvP7CHXYFl5l4=; b=zBwFRVdKpjmqhuuVb3oDFysuiXusA+MPnUTITRAzhsPf7WQS5sLzcgvjvMOtVcslq/SU A+vSRbedOxbGi6LHMSekgQOtDOq6kcqWDfkvUBRwnHPaQUKJt0gFalbi4Z1vuaXsbMDrg CwG3WV5KxJVeT1+58sVoydEauyvqCG5EhHRko4mdbbiL2f5NOKJCPV1nQC0lFcFhvOKgt QDoW+k0mMz1F+aTIPGSC9Kv172NN7LZ9HRZBp5GzZGVFnbMi2OxWc4A965Sod42mml5xm vmsbGMbwoHQOxloP4tTB50KYPbn8XuC+WxniNMSXw57jg3KlI/3SA32WWSUzbfkqvgQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=TH3CWbiC; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F0E3606A6A6; Sat, 21 Nov 2026 01:11:25 +0000 (UTC) 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=TH3CWbiC X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223485; b=BhT0JYATItIJy8i7x0F+k8u72zu2JLr97a9U6wl9pAVCMO+R7E/xAX9xGtlWrfeCGzN9 XsH90ZLWRCfmDJUIICLgONj3i1DvsuI2VmUUZQ9VBMF0c3G9G7SGTFlUWwJAuWk5rjfx4 lDlWanhHb9+S7c0u3F61EVbNX8+mRSaj82wLNNtgQUSzBKRpg+wNTCIt9wpa0OCa9OTXr F0gVASORBaqe+3LtwmEXaClmykFQpOrjj6vRak7lQBw2EKJQmnYNDSs8Ya9KBz2rzC+KB ZRnwn1zyQIrpiZ8ca265RSipVFWEe5/RfivEJ3CaXu7H0MCswIfJIQFUHlvnLPfFRaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223485; 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=EbiB3aPOTOdHebIu/3ij4hjYh3VALLHI0KNMIiUbIO/ql7I63xb5G11kB7i49gQ7Jg3n lY6PfI+aPcgtyfMl3qe4YSwSCIG8/vKm69bvNZUnfZalcEw9x842YO8mYyIscd7Q7efhX pVaO6RgqH4YOx0/FXM30H6+ROu29gxeGdyGkA1CHexwKAZC5uNy2hK9+MIlUPnNoC1B2q 9Io2jZWU3FO9lMLaQ2wb4xoWpMygscB5tKIa4yBUchx1fap74xMb9JsCEfnHIyUmQcbYw 9j50/hoDcWFEGZO7irLRvyOEE8nnKnQk8si1j6JlJPV/3FMDkmTbuiDq6hM9Rpak88Q== 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=TH3CWbiC; arc=none smtp.remote-ip=209.85.210.50 Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) (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 A02BD60A3834 for ; Sat, 21 Nov 2026 01:11:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A02BD60A3834 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 Received: by mail-ot1-f50.google.com with SMTP id 46e09a7af769-833e671ee9fso1455054a34.0 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=lists.linux.dev; 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=TH3CWbiCrMbCZNyUW0OMS3B+p1NMxJvpNBa2USUEN7+V6soCc4bDk1CnydoeGUgVn4 +6GgS0z9AZAtgLN+Og4qcFyvlZrfnj6EQEt18V14L3x7eDjxu8QGP2g7PZQ5KVJTv/6D Q/wYwf1O3x4WyzjUfUr7R6BFjWOXfMM8XKs/RMYA41XzXCOoIegkWJRhm68edXs8sT/3 KZb6cKLol4bcaYU1Eyrb+BsR8halSUHLhgXnV3be8Rs79tchpRRA/Kfs0hWFHYa87C4M m9MEN+FVd+sQlTx49E33sYfHYreSsgdWz6Os7b35FOX4vfnkH5RQlIVhWk2qQn83+C3y BB4A== 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=uw+ei17KMNPWSGrsjZQwCG2+vnQO6pprCUvkx0YEct8Uwbxao69j8PR7g4uXfGzMf6 6whg9kYwsdSFKN/l+J6pzcTri9iyvaFAM6POy7FEh6GlQZWBuv8kjlrNwnOxctpNwpLb hrzTtvsTTva9hL5+OLnVfnOVHgjyW+YibDvssscLoD42G4988QW8I6/roYDAdVu+3wJm 4GJdKYTcLK2fDTUucJbCZ7uT7Hhj8cTkpJrCnvfz3Y2kQ2Njpol/HIU7Vg8Krg7E3+7t yyRt+Y9EB3XP043bINZngJsGNTZIaJ7gkNsFATIPttOfM6D1/tlSzbn5uYucvkIxTBoW 6Rig== X-Forwarded-Encrypted: i=1; AL+hErGiXjtrR/j0CAlE4FE+7Hh519x9q7rGNxG5NE8lHW5UHX/ImcpZu6LpsdMVO8od6livQa5iKn0y+d5/EQ==@lists.linux.dev X-Gm-Message-State: APuU4Z8SQ/JdtVkaWfiitKCQICyzIMFvVNKjht7ChDqE6cDiVDAgXPgH /yfHRqA34S3/6Gslh7QWhXrQIZcfjZrTA+2Cd+2C7yukbeV6ZOweKwz8 X-Gm-Gg: AYBFou3KI5emryNS8VPcSuKfrW6dqB5F3ZMu3skS8XOqLHCeC2EnjKidLeMgDQ7hQOq omode5l87OhmFTWFnGGWoDeeRbbPLsocIWgHsfZHzAkCcFdqZqTdDmyMmJigBFzTCpt1P8UYSQE Px+u1TxPWMu49FVEZEMabyoVcy223BlO8+YhosqgMVrlsIhoP9bnOT2SftnOyaA28ujZevgK4mW NaPIBHhFXGsLOZiV+3ycgdewU3sAd9fa9TXp4JSft5IXVp3JBYckzyDQGGmZJtliCYNGC2L989H dyEDkanlpQw3BlgyCk9Di6kBdmUSm68CwC6FRBZSMljjX3yM0Xb3AMJID7FscvwbvJTRk/glA/s AOv+aet+Uh7amUuP4Piks7NtQLra4dzPtg8tt74khIXj9mpoyawj4X5UqRu7Q/XdU4ZAZ2topCh s+jtjSNeq8lHEAFjPna/LdbXLpsfjoTkJj8UVVVQWQ7mStlFDaWZpGzkQFK864yIhpR5bqyIErb yXdO4wlCM9lesqVSLP3zrfU/0EOIbZX+Cu3GTL6jkXtqPzqudyaFtcoGI9nKm1Mq8pkgOZu1uQ1 OfWqGd4KiEbznGpUNex1ucU/sqILwv3tAF0uzmH63b2ZH88yNPncD6O3w/EzlN1jnb9V+OKnhyJ OzAh1KbeCc2KWhR2jraCM5jC4f1eI0fFxyJnuRA97ZqNgDGfXoUgQXpvzdQX/ytBcEus6GOGxxo OuMQs6PvtdBnZDcMvF8PFedr/VfBxQaB5pc2lujeo2xLvF3A6xcMkX 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FROM_HAS_DN(0.00)[]; TAGGED_RCPT(0.00)[dt]; RCPT_COUNT_TWELVE(0.00)[25]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FORGED_SENDER_MAILLIST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10:c]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[174.29.1.49:received,100.77.114.92:received,209.85.210.50:received]; RCVD_COUNT_FIVE(0.00)[6]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; MIME_TRACE(0.00)[0:+]; TAGGED_FROM(0.00)[bounces-27956-noreply=patchwork.local]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from] X-Rspamd-Queue-Id: 4CFFC1C50E2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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_chip *nand, int page) { struct mtd_info *mtd = nand_to_mtd(nand); u8 *buf = nand_get_data_buf(nand); - int ret; memset(buf, 0xff, mtd->writesize); - ret = nand->ecc.write_page(nand, buf, 1, page); - if (ret) - return ret; - /* Send command to program the OOB data */ - return nand_prog_page_end_op(nand); + return nand->ecc.write_page(nand, buf, 1, page); } static const struct sunxi_nfc_timings sun4i_a10_nfc_timings = { From patchwork Sat Nov 21 01:10:38 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4213 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 1394E1C7AF2 for ; Sat, 21 Nov 2026 02:12:11 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27953-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27953-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 9109C818B4 for ; Sat, 21 Nov 2026 01:11:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223482; b=EVJpP5MNoEDhdXVqAaU/fBa90maulTkBknrOwZ5vVHBWnsHr5Iwl3Tc+fcN/RzrGkWTF KpNGtiVmYjC9XyB4TGAE+3NBXSQi55oIvlT7lW6fH7rudz0R2OFFkScwd06kea015BOet s5tKLQ7+mVtbQIHHDeXhvGwmwTbDcWvT0HIOppkKojDuFXTPztLEd7NcZWVWWyhTYuAQu zHpBDSj4R5Cze98t0RIrO0rhIscaKlGm2D7rgMgOPqNOD3dC+pVfHQistUuNy3GUNb/1D m7Xk6TuZDuHBKPtWtQ1XZJlYZJrvrjoUMxR/qoLa96gzBba1JTg6AM+hK7HeTvQpYtw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223482; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=nC4NCaRVx/W369O2JGd3M3QVKSAL0tyZU8r4HK4S9iE=; b=1KOmM12S5ZmSi73kTyptfLfe4yskJ3tDuQla5OujN/DWrRreNuhIQIkEb61iFbCyLyTb 3C18CdlDu1ZItA3nVaD8MVaothdEZEifxhYji4hxoIXFR+RuI7HJ5xPtL8eWp97dWEhet h+r/xrwDdqpTG/Z8R93vL0mjB9XM1XHrX+Wi7ip9i7kjF5CEX0Obz+wWBmTmVjgz9vOog lT8urV8OJSDYCRIRpoLSkDRrbceNAa6kRR91X/vnB15yZrapvcBOgUC7HGGbnQcD7PtB4 6Wx5/KG/JRDRNOT0y//9F6unby+asr60WY1onwRgBsAkOWvKTGZWs32DUM0qa6U6xZw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=vblEqTpT; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 90D1E60A5BD2; Sat, 21 Nov 2026 01:11:22 +0000 (UTC) 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=vblEqTpT X-Original-To: linux-sunxi@lists.linux.dev 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=1795223482; b=0u1va0cP1nIPwEzPr15l3xCjzUCAHt5QmMphpS3WI5/vCQAtZHvlSMVwdq2bFUMtX6+P TfOXdE3GBiPGFB89wXAsIZ/SPhmBRcaKllDi7lCRfNKcMGCU9H3VBZD6QhKs6BIHRoVjE SHWMjRqC3+7Mci1CriSxAmZ/nuPPvzqq0OQ+GOku6fKHtnNsCIwY9oVvSmoJzL+9wlcn0 JQFEKsjzAGvb4r8ZrF2XcII3L4OkNeAKn3V2h/EFDDODKuUzL+5UnVQBkkh31aDUthPL2 oi3OfQpNH50jtkhfCLKbsU2FoHBAlgjJB0NKxXfOepWi4jMyme8SFDrsZ1PN+p7MsaQ== 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=nC4NCaRVx/W369O2JGd3M3QVKSAL0tyZU8r4HK4S9iE=; b=2daj5X43ALcKJpi/D4/61J/ScR/eiA9CGGNRJ2BrJkmPsalvj20jn+gypYxFr+OSbINh ZpZcMhsrDcZqxHeAqlkJWiv9WMdy50Ss0KGoEneIsioHJEunT5/7J0GquyDR53iCHGNyH Db94XD1sL0Z3sY7u+VbXNSCctZ78e5V/9FfeL5qwO1xB4rJu/Le5ITd9nylneBhPiuzzD KrPO+gJW1aPN/9cs714g9HLqqOrZ5vFQ5M1eJNfg88i5Gd74UlGC7okyecQ9e9+r/uT9P J2VxEFsCNmieCMIJDWg4BmMc0OVD38jKzPtPrcR1yN5dJVfyO6RJv1irmffp+Wqq4Ug== 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=vblEqTpT; 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 417DA60A5BD5 for ; Sat, 21 Nov 2026 01:11:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 417DA60A5BD5 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 Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-4ab8cb2a6e4so1028993b6e.0 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=lists.linux.dev; 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=vblEqTpTUXFgMEseKWf1vdmaRae2w7nCCEFATkiJrQXQbRypL1HsmDGh6s2zFssmlX 4tKzWkMd4IFRYYCy/6HGbCq4SUOwtHb95UAEBOkrs4wmB73/BhbvkmrQph+NZb3e3cXf Q+2f4mAdNEUdqZ6zFpOiGATVpacCirzyk7ioR2praCWWYx6Rg+6CWDuVGiZK3tpKxNyM N36vGPnYkVacBnjeuZHW2p/CMhIfWbElUm8r5GSAkVysS8v1xbsbdu6knw4liQItP1SO XAc0kyxM1Re6LoYZexrnHIgw6u+gEkKpnXpo6fctoQ35GgPItI8UdDw2wtt6mMUU+pBo N1Xg== 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=o5c3pKroBAeKGckX/ycebf40lbs3RqloM1DmL5Wkx9TnKc7FWJONmqmEJycSombfqC RnyI2gnZ5aAUfkoEL1WFs5Qhj6afF4/vI8oGyW07RvXk6IWaA5D2OdGXIoW/83GaF/FN CmntuIhYICd5R9h3YQ4AMw8fTHwLcYPU8BLW2Na8pOyg2o/YLUTikeURI+XKrJs9etOg YkhX+S3ST1lNy2k9KqQc57W33ENq7E6S5OktBZg/QIVn7q85dBgCk8HjO6/NTGN8TtNo AJ8mraq6vxUDyXulSwNc72mwYmwghBxuEaaVFfCZg0eOEgP5QDKZ6VHd+qKroXeH81Wx YSiA== X-Forwarded-Encrypted: i=1; AL+hErHIRRlhbSKK/v9NSRMD2mpZy8K+0+93cMLYn68McpBBRbvAzZEsDRmk9onq9Db6y1tn3U3F2geL1ul2ag==@lists.linux.dev X-Gm-Message-State: APuU4Z98XwUpTTAwJrO9tRkBwHhzCkEXoEnMc6JlF1N0j6TQ+Bledv3R 9xxeGRMZIb/ZNosRQmUfRwUx2UzyHyR73bER0mgQfdditknOkx2kLvxQ X-Gm-Gg: AZFdTZfBujXYojyk/YOGtJS13FDu4GzpFUfuawvUlsd5Rt04RSiIPGkqfDCsQZgD1BP /66T24pN/l49GvtZ4yxLEiYbAJOrQVEmiL9rVi8MISG1715tFomZJPV3nnNeLvBwjKpFRL4KtBU 2T+I2R26nFjymN6XkMI68ynPM7Ph0sgmjTKYpjPbZCbHVe+rOE90TjIKwPxhTPVgSfgyarn7m31 5BbBYQ+3nW3bVm4aGuHkg6Tyv6+CJbNXdk38FVZdJ3n0xLTKWaxC9mu4Fmvpb7hlxLZ3ekJuXwr AAqA9OL+W9kyhSiiJAkIEWFtUhhLLxCQqxqrrEw/Zx9MeqcO6ehD6To5aRE8i9iq1ifdHOnv9Dm jACcdbsC/HqqA1MvrD/+1kWSGeTXFtck0gKCglLNePRowdAABGsdqHQZS+ds5iY4ah7AhTHoA9/ AUYT23+FRG9Z9YQsGZSAYr3QwCrN6n4xRW/hRMm6+B4hFnwzrLSyHpMgycyHwOdfPXD9mZs8Qen rJjAFmcS4n9zuTXKw5/o3C/yrF5a/s6SBqbf/AIVZxTH9xfmBex/mvHcrd+xEyvb1TT1EFEGDiI ugHcU/OU3C2f48s7ri3y++DHBV5JZulKG7yYkB710HHGlIpywP6aqtkVnBs4+jUX3UG+A6EzPGM z4tJtND5lwngnaRCjCsO9eCND84E9GE+YlUBgWJbYlJdBWNgUiBV2cD3Nf+Dc37eoni4+W+LV+E vrKwWKsunJlyDr5Fz/4oD/Sy2s2H3xzB8yfp+aOpLCvuiHiexZqIQn 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [4.31 / 15.00]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; TAGGED_RCPT(0.00)[dt]; FROM_HAS_DN(0.00)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_TWELVE(0.00)[26]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FORGED_SENDER_MAILLIST(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27953-noreply=patchwork.local]; FREEMAIL_FROM(0.00)[gmail.com]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[174.29.1.49:received,100.77.114.92:received,209.85.167.176:received]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; MIME_TRACE(0.00)[0:+]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from] X-Rspamd-Queue-Id: 1394E1C7AF2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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.org Closes: https://lore.kernel.org/r/20260914031929.2E7091F000FF@smtp.kernel.org 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_chip *sunxi_nand, int step) sunxi_nfc_user_data_before(sunxi_nand, step); } -/* 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 = to_sunxi_nand(nand); + struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); + unsigned int user_data_sz = 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 = first_step; i < end_step; i++) { + user_data_sz += 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); } -static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *buf, - 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 = to_sunxi_nand(nand); struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); struct mtd_info *mtd = nand_to_mtd(nand); struct nand_ecc_ctrl *ecc = &nand->ecc; - struct sunxi_nfc_ecc_read read = { - .buf = buf, - .page = page, - .oob_required = oob_required, - .dma = true, - }; - unsigned int corrected = mtd->ecc_stats.corrected; - unsigned int failed = mtd->ecc_stats.failed; struct scatterlist sg; + int page = read->page; int ret, i; u32 status, pattern_found, wait; + if (first_step) { + ret = sunxi_nfc_read_column(nand, page, first_step * ecc->size, + NULL, 0); + if (ret) + return ret; + } + ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) return ret; - ret = sunxi_nfc_dma_op_prepare(nfc, buf, ecc->size, nchunks, + ret = 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 nand_chip *nand, u8 *buf, sunxi_nfc_hw_ecc_enable(nand); sunxi_nfc_reset_user_data_len(nfc); for (i = 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); @@ -1408,10 +1445,31 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *buf, status = readl(nfc->regs + NFC_REG_ECC_ST); pattern_found = readl(nfc->regs + nfc->caps->reg_pat_found); pattern_found = field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); - ret = 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 *buf, + int oob_required, int page, int nchunks) +{ + struct mtd_info *mtd = nand_to_mtd(nand); + struct sunxi_nfc_ecc_read read = { + .buf = buf, + .page = page, + .oob_required = oob_required, + .dma = true, + }; + unsigned int corrected = mtd->ecc_stats.corrected; + unsigned int failed = mtd->ecc_stats.failed; + int first_step, batch_steps, ret; + + for (first_step = 0; first_step < nchunks; first_step += batch_steps) { + batch_steps = sunxi_nfc_dma_batch_steps(nand, first_step, nchunks); + ret = sunxi_nfc_hw_ecc_read_batch_dma(nand, &read, first_step, batch_steps); + if (ret) + goto err_stats; + } ret = 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 nand_chip *nand, { struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); + struct mtd_info *mtd = nand_to_mtd(nand); struct nand_ecc_ctrl *ecc = &nand->ecc; struct scatterlist sg; - unsigned int reg_index = 0; u32 wait; - int ret, i; + int first_step, batch_steps, ret, i; sunxi_nfc_select_chip(nand, nand->cur_cs); - ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); - if (ret) - return ret; + for (first_step = 0; first_step < ecc->steps; first_step += batch_steps) { + unsigned int reg_index = 0; - ret = sunxi_nfc_dma_op_prepare(nfc, buf, ecc->size, ecc->steps, - DMA_TO_DEVICE, &sg); - if (ret) - goto pio_fallback; + batch_steps = sunxi_nfc_dma_batch_steps(nand, first_step, ecc->steps); + ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); + if (ret) + return ret; - sunxi_nfc_reset_user_data_len(nfc); - for (i = 0; i < ecc->steps; i++) { - unsigned int user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, i); - int oob_off = sunxi_get_oob_offset(sunxi_nand, ecc, i); - const u8 *oob = nand->oob_poi + oob_off; + ret = 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; + } - 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 += user_data_sz / 4; - } + sunxi_nfc_reset_user_data_len(nfc); + for (i = first_step; i < first_step + batch_steps; i++) { + unsigned int user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, i); + int oob_off = sunxi_get_oob_offset(sunxi_nand, ecc, i); + const u8 *oob = nand->oob_poi + oob_off; - ret = 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 += user_data_sz / 4; + } - sunxi_nfc_hw_ecc_enable(nand); - sunxi_nfc_randomizer_config(nand, page, false); - sunxi_nfc_randomizer_enable(nand); + if (first_step) + ret = nand_change_write_column_op(nand, first_step * ecc->size, + NULL, 0, false); + else + ret = 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; + } - 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_step), + 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); - wait = NFC_CMD_INT_FLAG; + writel((NAND_CMD_RNDIN << 8) | NAND_CMD_PAGEPROG, + nfc->regs + NFC_REG_WCMD_SET); - if (nfc->use_mdma) - wait |= NFC_DMA_INT_FLAG; - else - dma_async_issue_pending(nfc->dmac); + wait = NFC_CMD_INT_FLAG; - writel(NFC_PAGE_OP | NFC_DATA_SWAP_METHOD | - NFC_DATA_TRANS | NFC_ACCESS_DIR, - nfc->regs + NFC_REG_CMD); + if (nfc->use_mdma) + wait |= NFC_DMA_INT_FLAG; + else + dma_async_issue_pending(nfc->dmac); - ret = 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); - sunxi_nfc_randomizer_disable(nand); - sunxi_nfc_hw_ecc_disable(nand); + ret = sunxi_nfc_wait_events(nfc, wait, false, 0); + if (ret) + sunxi_nfc_dma_op_abort(nfc); - sunxi_nfc_dma_op_cleanup(nfc, DMA_TO_DEVICE, &sg); + sunxi_nfc_randomizer_disable(nand); + sunxi_nfc_hw_ecc_disable(nand); - if (ret) - return ret; + sunxi_nfc_dma_op_cleanup(nfc, DMA_TO_DEVICE, &sg); + + if (ret) + return ret; + } if (oob_required || (nand->options & NAND_NEED_SCRAMBLING)) { /* TODO: use DMA to transfer extra OOB bytes ? */ From patchwork Sat Nov 21 01:10:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4216 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 1196A1C5D67 for ; Sat, 21 Nov 2026 02:12:19 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-27955-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-27955-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id D594148177 for ; Sat, 21 Nov 2026 01:12:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223484; b=2xCD1/sJz14eBjbA/HpSyUIr7XOeMLqn3vnspkPaz+dufwHv0L08kt/sCqjr1ohUVsgj y117ghsWnmzoUzFQB4Qn/MfRYQiC7/ApiVXRS7oPhYD3xk4KRyGtN18P/nO5j9sBlhfKO zK03fKGjekXvGFbeEiP8/axS9ZnWMVA6KULWM8+/uYfh3uwnSASigmAfU+JCzOnAlNYCE 4oNmAPnZ1nfEz27YbBcmDqjJWoo31ahRcL6d0jCT7/tqtEIYTXnRv535T2XuXW8CZszgw PxOVQRtr1znC2xdCH5ZVJNwn/bDyh2LfbhBX90h6P3BmeLqYBCzYPPK5VnurQFBKzfw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223484; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=9EEb5bdabVEoMSRLLJqgNbBs659DuSJGBxR5aYGgxzc=; b=uqSqaD62Hi3Q+MiHxNIHmQWGK8FWqJ9ICw9ZzBfsq8xKDUyLSWlcoPRpllADBh7sBflO QGXj9Ha0cZJH3Dh6OGg8HyG8zexdvZiP0Z+IVycJGRsTh3a9aJNacKkJ81ruSTqWHcun4 ZmJr649+4bivd+MySYcoRfkEMsH7oS4m9T7RZgllb/t1GcFgLUb/f2vtrTSQfHgu50uJa SDn7kJxy4bgey3YqFxGkRadcGkxUnZML2vJolgb8z4gltBQ8n2QkTMVoGhNmzvY4bDCsb B7d/ehtlR2yH+hpMQpyR7ON/JJdrJqHe6C+YMb1yJ/mym9NsfNvnSEweWYfr+SaUvMQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=SmH7VPWq; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD84260A5BDF; Sat, 21 Nov 2026 01:11:23 +0000 (UTC) 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=SmH7VPWq X-Original-To: linux-sunxi@lists.linux.dev 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=1795223483; b=gBGgNbhJM1xdeKyGErJVCPgRzAmmXna7FELdCwmXAJIQkCj/7Vwl0T/ibfr9sl/c/Us1 ZDcN2R9CMWtEarkL0GYAWGC/jstNdbK946l7DzLo0jBpaxr8bDn9N0ftbLoYhlqzTHRS5 wYgPc8mojzU7UO2fVVGSwpYNE/yLRpOlKGjJAvZLD2oV2eq4RmtF8MCMKDRda/c+GrrOX ID0nE2VTL64JdC8aicQ53GbmscjyueA0XGksxFjIpPmFjTgIzbumKh2pZTpVLhODo44dC S+7u8O7cMzk+r0N1Sm+AY5trSbde8homqdQnQAi6BEUQUsYGaI21AGoWZEQLcrTlCUA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223483; 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=ruusbzFk6/kglRSF5u6Ubo+185hCelnwINT1xIpnM+m8TTwpBoYXKUEO2np5kYwD5NSe AWeyEHW74OHJ4WrmgBy8thOchRCapDdpxDqjchBiwflN7NgvNmgJJO5aiKRClS5zImyrc bQbCfFj/UDWZ0sOTR8mXy7qgXFD4l3AywfIW4JbEL0///OKwsMxnokdIoVuMzL8jLRPSE JlRbTSr9rT1aS0tAiTigLRaS9eFlZ+j45SXDFLZ59tUhhYe79X+AvBK+Ce1NKOPw81eVF IeOzllsf8W56y1Lmlm7DzjYc4cagh5JndHazbDzNZzPReSvtTHbQR1SmyxxvoCpKU2A== 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=SmH7VPWq; 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 8619C60A5BFC for ; Sat, 21 Nov 2026 01:11:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8619C60A5BFC 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 Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-843b6f8e2c7so1154382a34.1 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=lists.linux.dev; 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=SmH7VPWq3yajKfahPou/akdqOJPLf+ZquBJdORd61zI3kjtZX0R3U2ndD3j6VccdwT jgGTcC4SYcGEG9MKxyyWOBcZQI+Yy+ccMvL4JMYvYmmDfLXJBVZziVCYSgNpy6lFEcCO FglYxGhlJF+bkWXuZnHiWvBsuN69zOM0Oi6HqkFVUVTVBaeQwXhzmvbBrw9rjwfxK968 swVCiyAV++gDramaIVmod/sXP38TY5u34BHlXju2HvgbAtUM9YLflGRU5bbXs4ML2hMn cWC6mm1H/XTXVRpMO1HNFdgHxMiVaeHa+OhENKF1vs30L4SHLhwCHT23NVBC2Us3u+xj ejgQ== 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=pG1fRxXhXgolVH7Uqqrm8ZVXS15Rq1F5OEyKzJcNIUhhYut+G3Ow0Gr6mBHfXuVq4h /KkEndgoxtOLX9StO1PHORndykNeTM9SUSV0GwSyB1jNV4XIDsij0G+ZRoi0d4Npgz1Q 5rJZBp2ubejY5JOmfE02cYJTd5u5OXZpGWN2UFRiTexiKD79DZDW1PaJoqrsWEYwd5J0 5L8gL8EUA+kv0gXGizkAPHoWGgCBs0PA4TwIKwnFZHRe70d+zTYBiZJn9jqUxiYIoUwU yzSrL5idK1F1OPFjZ9gWPWcCbXrsnG3qOorMZg0mtC6HlwxO2+/aDjHnqUA84fLbFOBH JyVg== X-Forwarded-Encrypted: i=1; AL+hErHL+dS+GpfRoppXCHD47GGYNUwIiHrYVA+VtZwdX77NDO2p9X53Cds539mHGcFz7PH0F1YNHH7xdzorcw==@lists.linux.dev X-Gm-Message-State: APuU4Z8juDdNTgXHNWRmuPhraA7w9uyJvSFl6DBbioxQaRB5B7Mt+x9n xf34Qtalv3hmTZ4RCebDeihnVJ8HlecHidgWZi0c3I+hI55y/JT+q6/t X-Gm-Gg: AYBFou1lObny36p8HcLm/o9IOHVrfOUwhh90Z+3WZXGwcQ19OQSzhJ6qOKdkqLFxyqi nFsSVWl81mowaPI2WUoWrIDxAi/Vuaa1VMUrQEdw3wtbsr6pnmQKzBeK3FYu/cIfqHIrC+JytC4 hf1ihH3a3M1Uk5fYunksvuhont+5B5dNBL+32i09wGAQwapdYxwWG7/HE4ALibuym4ERgn7kPXw 3c+R1e6mFDxnbvXlqD7vSzkjldK+Gv8ykHl0mtwrFa+PHLV0vkIOdjxZF0H7qUEBYo50UFiz4Px XG69AlUnLUZjboarKCxzZIiacV3wbjlNXs5vlqfP1z1T5RG/t3sls3b/NK07tB+NFR8AMqM80lk McrQQcnvRWTcs6P/oqBgjkREso7MlANWrs0ra55hFKwrZrZAU8aBmGc1VJYwGQnEkpEDArOxvzc DNjprFdCCpuMgq/Mox9R9zU7dleU2luK69A+G9TFXRhXSz05nVMi8i81kKwW2SsNhu4Ij4BVVB/ e1V/Rw5qb4CgIQvQ+nIaGUHHPA6zaO9Q0kIlvuupgTJ92s7CDtiBllQBD3oqBHfzewYAFqhpRfK fvL057X2aKqXbpjgFV0jQU1fMPvmOK570lJm7orWJFQkokJpiBbIbrDV9ls5gAciqCYP5bFzk7S /sW3JwId4++IKWwrTFOzuCZ5VE945FW/7l19EXhnU3Qj+Z2ohGIz2aICgF92BXorNy7s27akLXW /sBirm9ytnoszTioVbB9Up8FHPvf80J25mRLGg3egjUXJjEHnQtGm+ 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-4.49 / 15.00]; BAYES_HAM(-5.50)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; ARC_ALLOW(-1.00)[subspace.kernel.org:s=arc20261015:i=2]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; R_SPF_ALLOW(-0.20)[+ip4:172.105.105.114:c]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; BLOCKLISTDE_FAIL(0.00)[100.77.114.92:query timed out,209.85.210.45:query timed out,174.29.1.49:query timed out,172.105.105.114:query timed out]; RBL_SEM_FAIL(0.00)[172.105.105.114:query timed out]; FROM_HAS_DN(0.00)[]; DBL_FAIL(0.00)[tor.lore.kernel.org:query timed out]; FORGED_SENDER_MAILLIST(0.00)[]; TAGGED_RCPT(0.00)[dt]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; RCPT_COUNT_TWELVE(0.00)[25]; SPAMHAUS_FAIL(0.00)[172.105.105.114:query timed out,209.85.210.45:query timed out,100.77.114.92:query timed out,174.29.1.49:query timed out]; RCVD_COUNT_FIVE(0.00)[6]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; RBL_VIRUSFREE_UNKNOWN_FAIL(0.00)[172.105.105.114:query timed out]; TO_DN_SOME(0.00)[]; RBL_SENDERSCORE_FAIL(0.00)[172.105.105.114:query timed out]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; MIME_TRACE(0.00)[0:+]; TAGGED_FROM(0.00)[bounces-27955-noreply=patchwork.local]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 1196A1C5D67 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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 *nand, 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; user_data_sz = 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 = 0; slot < nsteps; slot++) { int step = first_step + slot; - if (!(status & NFC_ECC_ERR(slot))) + if (step < read->first_req_step || !(status & NFC_ECC_ERR(slot))) continue; ret = sunxi_nfc_hw_ecc_read_error(nand, read, step); @@ -1451,12 +1455,14 @@ static int sunxi_nfc_hw_ecc_read_batch_dma(struct nand_chip *nand, } static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *buf, - int oob_required, int page, int nchunks) + int oob_required, int page, + int first_req_step, int end_step) { struct mtd_info *mtd = nand_to_mtd(nand); struct sunxi_nfc_ecc_read read = { .buf = buf, .page = page, + .first_req_step = first_req_step, .oob_required = oob_required, .dma = true, }; @@ -1464,8 +1470,9 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *buf, unsigned int failed = mtd->ecc_stats.failed; int first_step, batch_steps, ret; - for (first_step = 0; first_step < nchunks; first_step += batch_steps) { - batch_steps = sunxi_nfc_dma_batch_steps(nand, first_step, nchunks); + /* PAGE_OP transfers a prefix; only the requested steps contribute ECC results. */ + for (first_step = 0; first_step < end_step; first_step += batch_steps) { + batch_steps = sunxi_nfc_dma_batch_steps(nand, first_step, end_step); ret = sunxi_nfc_hw_ecc_read_batch_dma(nand, &read, first_step, batch_steps); 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; - ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, oob_required, page, + ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, oob_required, page, 0, nand->ecc.steps); if (ret >= 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 = DIV_ROUND_UP(data_offs + readlen, nand->ecc.size); + int first_step = data_offs / nand->ecc.size; + int end_step = DIV_ROUND_UP(data_offs + readlen, nand->ecc.size); int ret; ret = nand_read_page_op(nand, page, 0, NULL, 0); if (ret) return ret; - ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, false, page, nchunks); + ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, false, page, first_step, end_step); if (ret >= 0) return ret; From patchwork Sat Nov 21 01:10:40 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4212 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 56F951C5D65 for ; Sat, 21 Nov 2026 02:12:04 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-27954-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-27954-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 97C9D43A46 for ; Sat, 21 Nov 2026 01:12:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223483; b=T1ocGegWMdVAD8M7pkq0qCO8EEH34xquW4BrAm8crBpqv+ZG+8VCLX3c9zVUf14sF0ae HypB0SpxvyEKyDWIXTsOCmH4kkp6fIgZhLfTeMcJuQAIzgqCNfixyT+4d+Fk4+UYc/Tql c+tYBOUIxs59+R3+Vx/0FdLxsky6uBAuzWcqpGcxrZJJGtysYer3RTJkZ5XdaLgYnjAXr q6eQ8MyLwOtbAf/cMrPrhtlIKMo34s47wS/2rKfGX8yEu7oiyDzOVzsZJCZz0OkeM9l9G qrg+tbFl+gzcbTKZFMUej+sWiLXwNxnWtPUu/kzchy9c7VXSkSG3H7oKjErhI88Kgyw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223483; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=Rd+OJrfYC05spJgrrPaaw8Or0kLWD6WKtcmuDL8E++0=; b=YBtFAXL1/7rbao8+QASnZe7ClrLFbs/4R4HkgtHQimVDKovwuwFb9+78GEliWmb3zrzy 1WsajpS+jq3jdynnzFhMPCsifRj6R2qIt9potpgMTS7O+qzHIfyBcrwRWXrqmWrsHET6U dWuEpnB5fvjvNkPt/0VE7P6xKd818qBZXQKRSBM+rCnJOA6xkB/c9Dle8IF2Y6I4fSU1H 4jnnapctoKxU4QNb7Hr2XS3TOF0pD9D7AZIT19EH9rMLWW5fBuT3wEgN+IvQWb1GLK/NK xBs64BkybHsuSILLblnBH5dvVaQQLYCazBLf15tJ/G8+L4erNDzAgfq5DeX1zMiLb2g== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Ww+yVDRk; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1EFDA606A69D; Sat, 21 Nov 2026 01:11:23 +0000 (UTC) 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=Ww+yVDRk X-Original-To: linux-sunxi@lists.linux.dev 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=1795223483; b=Tm+niRkscrIYWAOk2jhHm63oD6+I14jKvC3zLGK2tbRAfBH6iKb5FXEa2VSQsuKQpcQv oWaV8BvbYcqrDFmeKf5y7C12EICBe7HSPdqQBpksJAAn2rxfy2wJtbTG0jowgPJ5n78XV I5HKTy79qnscld7Qs7Uvtc+RS0FZgY3V/MLRSrid9cj0rWZmsaD1TOg/LjqcnHG2FbbAL w4FbBOGwvPnnEbSRKx1cqpWOoMd+7cE0sM1l3tgtR24DZMFjZS/8NM2aZnPHaDnxfYwEx o1jmChBn/aujMaUJOKtu4JbfAqbvCwfOoEMqJwr3v6UoF0c+MsTvh+q5A5mUwhn6g/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223483; 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=leJzNXj8z8ZvlnfhRr3uSWQY5jRtXd5roj096xsfjntBIjrH5nXPbCw/sJwTNfa2Smut RqqspOo58jEB//i+YPi3gKxfvf7H3reWye5Z4UXadagfQwyNH9t3jN5vSzwZMjW4thEtE EIsyvMoHkCfVylMQNj350BYQQD/fTGEIXbXY+J6iK96hvKyb7dVL9ydjrtowGR0bCgTbY bZYILaAukPgFFhW2AjRxDMlurD6doXM20GwRHwaC3siYNx8wSLJvM9bkCetP6U6mEraQ9 kvpPBt9i5B28Rg1BAdDkyriOErfQ4Gmq++ML+/J8lNcHduIQ3OCzLUF75QOqWd2+PLA== 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=Ww+yVDRk; 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 AF31A60A5BC1 for ; Sat, 21 Nov 2026 01:11:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AF31A60A5BC1 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 Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-57297329b3eso894725b6e.0 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=lists.linux.dev; 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=Ww+yVDRkJAR8dYKd9Nh1Z3+YJy6yvbaBcM8/PeRoMPWm/Y1vHcIi6R4SG4C1+gag4/ 35iaOvYhWR7kTS4LMJYm2S4OIgWKJp68fmQyMF1+0Urf/cU9IJKcqjfJlAYHfm240iWL bCcsv+R51Js7STF+MYXqAr/hz+Qv06btIy1JrbP72hhh1xUuE4nunflX62QeO2mSGbrH PGWAXG0zpwM2c4toVDAPlEz5JbIo87BBJB8IciK87SazHmVhURFOs3Vu0EN05xQTvXXA +fpXvT1S33Xii9T8xlmJ+WFp2CizviB6JvirKqKZBtDo2u1zNE8GMo9LZZ2nJc9Rfx4N L5Bw== 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=sYDvhIdhyv9sVFXUIwLrvfoqxj4jEZ6krB2ZS7bZokfM3YanKx3+aHWfQ64RuZAd02 oOjCAjYpDFgKh40tdjhtV23gLNdLnEx+z7WONccvyEQuTtQ99E9dozAOtZH77BiNJw0W MLj7IsMZ6JV+p3TgcRhhlIr/c71ijdemiq8K6E6HJMjPi61DUdRlqSDOHWgBgUn7b3CQ jDcm59p0MnKwQpLihaPOfDfdYM1NeM3xWc8dMDd+hrCIeKFlG9Cbjv3VI+jw/MZvMESd 87smoRo14/XYpio7N8jk8Wcbs/eXOpczEeM0eud3YNGs8xwHEsYxpIeTrE4zc5AEjRMY Yk9w== X-Forwarded-Encrypted: i=1; AL+hErFE1LMeAgXJfCScTI9bgKSk5v6kFR2a8w1bsilk/dLDxtm7LVTfhmn4Q+MXHw67HyxPnWih6yDfrAL+JQ==@lists.linux.dev X-Gm-Message-State: APuU4Z+I6PEg2xFnadtrUr4Ab/lhVCWdgmTTkJrDP7ypUlC6XGXE8A7A HQY3YqteZTnqoB7sK7+ZbKnCfRdug7SnLurFHEUnCDZBFHk+BVLvErKb X-Gm-Gg: AYBFou3Eibr0MuEqQcDnF3pd8dEC5LmpaUF6EzIjhWv6IBHxxJaoH+2BFts7uCwR+uj 56b2qzJB8zNklOevonIE1Ge8JHKvZTTtvi62ukPw2H3e/xl/SHJFwRjvdcDLRAi+z7j/UtyrcY4 RY6vH6eXs8QYD5+JF9HGqRQAchbtz3SZl2zPxoH1HY40v0sL3we/w3aVYVQiIGyUfV1jkxHnevt 3Bkh27xsJGDzKo73DCSUHfy2fJlkzeH6lyWfalFsIv6AnGvNdXEWEo1u3kiEWbRi5YidYVChv1j Ix4J9nDKYKKc1+xMsCTKPyvJBMolEmf4D4gqwqgkikbePBUd7x3hm7xf32CKx4H/IfkrITmRjt1 QkMJfsVBJF7DLf17HE0tRYeNFhaU06ZCMFnooQ54CySYPPp2Elov3TVPajrMeQKHIfZbXkH8CDk qnDci3FRG+uvQLAmr2Td6gWyu+rpnX5q/Xwc67LqwPBrg03z+ihYYfmthm73vONCYskIVSvBUIG ZDp5xIhLqiejILBzaq/Sm1pM9sKminpgXc3/6urJQUoj9wO7DbVkT7MTrw5Ra43qOE17J/xoSam cO8PgJhAVojZGR9o4XoPbeKf8wnriENZVNT1HABHP1L1xhlk5g7BX1mTQ3/U072vL5z4YJrdPiB 9/Cp5pOd6l4n1zw9hwrupRBJMNC3mVt0G/YaJih3i0nO4o1WvEv+LxYBtt6ZTaP3O0otfVu3TP+ Mbo+qi7wNtQx9wI09rTEg7UyGkyq433p4dIlx2pDy4dw5RTle9rBEy 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [4.31 / 15.00]; RBL_SENDERSCORE(2.00)[172.105.105.114:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; RCVD_COUNT_FIVE(0.00)[6]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; TAGGED_RCPT(0.00)[dt]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; FORGED_SENDER_MAILLIST(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27954-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,174.29.1.49:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 56F951C5D65 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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; }; static unsigned int sunxi_nfc_hw_ecc_read_count(struct nand_chip *nand, int slot) @@ -1167,6 +1168,12 @@ static int sunxi_nfc_hw_ecc_read_error(struct nand_chip *nand, if (ret) return ret; + /* A factory bad-block marker is not an erased-page bitflip. */ + if (!step) { + oob += SUNXI_NFC_BBM_SIZE; + oob_len -= SUNXI_NFC_BBM_SIZE; + } + ret = nand_check_erased_ecc_chunk(data, ecc->size, oob, oob_len, NULL, 0, ecc->strength); @@ -1251,8 +1258,11 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand, 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 = true; + } if (pattern == 0xff) read->has_erased_chunk = true; continue; @@ -1321,6 +1331,14 @@ static int sunxi_nfc_oob_finish_read(struct nand_chip *nand, return ret; } + /* The pattern supplied no marker bytes. Read them after the OOB tail. */ + if (read->read_raw_bbm) { + ret = sunxi_nfc_read_column(nand, read->page, nand_to_mtd(nand)->writesize, + nand->oob_poi, SUNXI_NFC_BBM_SIZE); + if (ret) + return ret; + } + return read->max_bitflips; } From patchwork Sat Nov 21 01:10:41 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4219 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 8DB901C50E2 for ; Sat, 21 Nov 2026 02:12:50 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-27962-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-27962-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id A29096781C for ; Sat, 21 Nov 2026 01:12:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223493; b=Y/q5Ji7hVKg0v3ln8Ced1qsdHOkUyanydxT42zDzsJFa/6hApWK1cwWcsdwkroB2+DPK cAaXr3iQ003Vf6oUwM2M9C2G5+F7lTZ+BryspjA/80eHVbBOvskai8d5f7hn9Sd+8pNrz Kmqa3Eukafbsla6MHXKeXH1HwV8E4ZdytX1vIECLPLxSH5XweBCrJSZXFpxbj4UbLKfus ftmsTDrhG9euaTTIJ7lzeN/YQ6r2F6hbXLUFhJOg2I0hKWT33UGsXkTzhO4ksAwQVDFCu 8brWlu39+6TQybWIrjk0pgcdXweLi52sVDGLuI442OzLticvEKHcCjeM30wDwCYFfJQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223493; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=KCmwAi76omzV3Ocey3RKQm8GgxKEzZYW/hAI8TU8mC4=; b=kWJQ1zqd/wJo3HGMFKV7QBmWn/JHZ/o7PKpXwuc+teqz3eD2PR1v7bCF+mUWeNS8JQ1y qEOd5JDzw2fxe/jjcoN7TsRoXqx8tI9nuQPi4V40yUGz8lS66ShzrcfAcCJj0KHTGM3h8 3DOAr5e3ZaEPQoRichmyzEXGgsQnmmm20sih66d0QaC+UJ3TQUuYOtGy269OwPC1zgMa9 qX6PgA3iAV08DTDhSxPqM3gEc+uY0Bhb/pv1fIGCmam7WE7TywYI1/R057CIGd9eTQiph JDqwKqAuGDtMgY9mRLQ+bLjcRn/i3akQtOBPkqjhO8wWNc3GXh4jWV4amhGqW8uzR0g== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dUfJKR5C; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E4865606AA2E; Sat, 21 Nov 2026 01:11:32 +0000 (UTC) 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=dUfJKR5C X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223492; b=0B6t83QVGyj2HYtSC4A7gKoEssJsf5Qhwd6XrQriJ2xXkD2EjtfqIb3SG/wVkLQJ+rfC Y3S6Hyd5rlTd2jVKmOdGclVffedWagSK+balY049vccaVpVzR8d43fPgT2spLn7YtF3Cy B9GN6MIqeV3OqwaqifUHHwzfcvuu+e78Pv0VDL6I34X0fPyHBNM+EKMXmMYC99MoWXzX8 6+AvuR4a5GjDFu1R0agO1/ORcL0uL6jGaa/FHF5nDCQtTJNzZQTWGi9koXAX4n2WuheTz l0GILVRy4zQtuoH9DH6hDUZeIIQpt/JlOHImof0Uw+eZ7r4dpapnzS1WfNvQ/TBKGiA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223492; 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=4S/98532+COD9JNwMmQ+oaPr2DtXHedpHmTsruHcBsMkiPGbh8jmtX0+Tubub9hlWsE7 yjdvMLTz286egTWHtGDTwdyxTDwV8Lj1e9+bAQwfp0kf7mk6iTXOFYBqcj/TEJ59ZKkgF 8ahW9fU0kiTWeqCiqBGcRtS8KluRVOqll9y0rFj1f54P5q0MKTMDklYnk8E+bttzci1pb 7010DlNlDLuqixFajz8x1fdQvu5B9U3Sg3LFrb2VqGzVIhIDPth8NUzl50IhoyGIIMlHu m9lXr1BzMdyjA0jpZXc48kKG5nj/t0WC38qzVzkdESUv1eiU3ZOEHNIXj0mVtIrFXMg== 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=dUfJKR5C; arc=none smtp.remote-ip=209.85.167.178 Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) (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 4E3B7606A332 for ; Sat, 21 Nov 2026 01:11:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4E3B7606A332 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 Received: by mail-oi1-f178.google.com with SMTP id 5614622812f47-4a451915d8aso1058877b6e.2 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=lists.linux.dev; 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=dUfJKR5Co0HiNlns/knQqGqHSozCwHpvG5LIOoYKAgJKRpenRopNjyZmK7xCG8ERwI PAq8bVsgzkkPG5MVyhXwwDoN7ZQbWdpVXDJ7cma16N9BXU3PrItES3SfQxltxJP+/Jst VPVVOGNyn65VuPFRqCxZFpZD5WgkQq9fYBl4u62jzRDBwepvZnZhblOMUvtvHb6HWerz PlkBNvrwYx/g4+RTAP1dZJJBKa6iuV1y2ZTkLbZXhDnQMZSejcX7QlT7ZFq1gTIOJ1jz uVCUn9NwDEeca3HSQSQtc5I7WgJTnNJExQ12q3cmFRd9jAmo+MMv84Q0BpezbzLN6Vjs jVzg== 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=w4f8PoW0b57SIPWdqyLbT5224hdpWejZLiM9TH5dwFYDuOqekC7Pj/wUZSdGHsI27t 0LAAmMakiQOvNYkK34XACbcsHeyfZL8WRNuCjB+3iJF/Tjnl8nG5uVz2y2a0UryKYax+ JNL25xGoKlL1jDaPy5hJ7zMJ0OvMeBTzvV+DM4TNxcaes2x9wj5gvkv9G7bqqa/VV5h4 76d9CQB/ZIsN7kCnwZLqBeNp3P2nmGqFtKkFOqM9Y+CJTjs27Z5E/Mam4VgYiPiXSLjU wnl9mLunqZN8qQK157GotYYwj243vOILC1AcXT8j1t6+WuGOSBtcMBmS7iC5RCRNDBDF OVHg== X-Forwarded-Encrypted: i=1; AL+hErEYnxODdUpPdv8s94wAfNAR5JQRSyLaX1ukgfyyHpdoErLua3DxA+JxD62GlL6mKRzaO/rmrXBBVVJUBA==@lists.linux.dev X-Gm-Message-State: APuU4Z/0XZs5wCNMmHqxSq4SemDEy6H9192LmbNetaXJ6Vxc8S8Z3w+G o9U1SBHtY8ySM2QblYUOZxg71huB1Jtz3x+GE6SGwg4CdbU4fwt3wLBE X-Gm-Gg: AYBFou0egTJcIVtB73uqbti+p/0pxPzCo/HIFRHm3NJFKqV6FOPhkFyG3hC7pqGzt8f wDrYv71q1s1ZTl219S5Ie3XhIIKp1wcC/JyNAINVoYH/UDxa+gwSztJM4T/wmXcDJdvYxHv8vff VnTMvV660UhyxjK/MwIlqJce3DE0i7Khl2QD0R82/DaWk8/kjBqewP7W+3I1oCxBr4b/Gyj5opV SnCQm3ofZil9LskCMMUmfAB/MmHVPP74AL0ZG/Q0eL9v+j1cUxg7y9rUazmHxJHCamUXq66vNBp VmT0JJ//7pD8lx9u1YDITN3rwZfjIU8dlFQDM4ZjMXSf9+2rBbXRU2CNivwFwTbzlio+4qAGwl/ zfs3nPKyU8MlmDg3RtkeuhyaeTJoqU41N12tZCutXBENe0GPe6PmSLcAQ271roSqQu8vFg27kPa i6ONzBnZCBDpINti1mtJQcQGyFvt2+kDBnAJ4sojToQK3CIPrh7eJ7MwgzIeN1W9gLT6Oe/QPWV dNlL1zM5C+uv2XkyaXx5Ekq42BKgNIYPMtPeNNKmC0ks5XCctcaY84dPPCL9qvnPBDoXLR+dv5A /UkoRIq5FffJauUzdE5l9TwOI6IAk6+WwhS8l0FDrD5kdnjpadGY8yrWkKNEhPxCB0Uyu7Wy6Ml 6mx4gJtGGVRlyY/lewTPxIux9qAB83rAp4kyMO4z9mf5fvtJgK/ve/ZIsrZmIeoqVxhAE/OWqVD V+oCOQtK4p7JIu1sA+K+i732YPXWipkg4X6nWIP6byGkOh/oS8leZHtYTX7sxscyNNH5gNiV5b/ A== 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.105.105.114:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; TAGGED_RCPT(0.00)[dt]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27962-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,209.85.167.178:received,174.29.1.49:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 8DB901C50E2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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 *nand, case NAND_OP_ADDR_INSTR: remaining = nand_subop_get_num_addr_cyc(subop, i); start = nand_subop_get_addr_start_off(subop, i); - for (j = 0; j < 8 && j + start < remaining; j++) { + for (j = 0; j < remaining; j++) { u32 addr = instr->ctx.addr.addrs[j + start]; addrs[j / 4] |= addr << (j % 4) * 8; From patchwork Sat Nov 21 01:10:42 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4226 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 7DD371C5D65 for ; Sat, 21 Nov 2026 02:13:48 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27959-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27959-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id CB126E4D07 for ; Sat, 21 Nov 2026 01:12:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223489; b=G092Svr8GUbr+hWqnxIKtO9/qC5oSOk305JWrZ+dpjw1N7b3TQcV7QwBJZlFQ7sg/Vda Sk7kgIZ/ZA7c6euyMd4GKnfjkxEZ1MSB+ZZynJoFqbF8XCd2pdwrgR8WFp71haVj8IS8E POudtGSpV5DTNcDysfn8oPz8PNwIQZOBZQ2m2XopgDorzngi6gR9RXnjUqMJJii30VK7c rUP+bwzSeOutOf509F+0TPSaRXZkdSnxPA8ySOhxbsbOuaEqYsVGPAu6qHDMlpAL9yYJ6 nztHynXPRg77rtE+FkoUoCOrmHaZV0KofPDIRMWB3A5HJMhqZieeqSohBy5/rGmMEBw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223489; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=9R93eLtRuVCsdbuGEdtd6/wt6t26wDnU5PW4NiI4F68=; b=TiDZ6lm6JxjfYKpqqc7JR+rti5u2u1AkO42a1UculOMAJLUxOm8pDGtPOGNzQzvEmqVX MtG6infvFNH/dHrQqW7iClWt5geDw7CWEZYNkBKI22/jY7NesmKI3PIbZ4M3iqGu4n7gm vFuQjjQ5f/BXYmZv7yxuGK3iGNN8CEs1LGWso121VCWOH0mENEkYEdPf9PhkK9bfadh9N qMchwJcswaWMo6py8QZ6BdGGLZZGSO6IS3bYSN5HCkI/OdMme2/28o1gB8wT1fTPw/oT9 QQ/6ENMu+3pGXr5MekOhm9SNn62zCbGdnfZzrcaERPzWG6FfQ2QUAU2whR5DwBB3ssQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KDZeBMxV; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 669AA606AA1A; Sat, 21 Nov 2026 01:11:29 +0000 (UTC) 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=KDZeBMxV X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223489; b=mUIlxSAgdVTw4qDHz4t0Ki46PIXQscqBA53JYX/8t/c0+mxUbnN/Lp0Pz1x6RK+LBeo/ 7fSHgCbSEusz7dCARhuQ+tXkoGnb3bq1lUIa6arZiper9DFwmvaGBHxzwVF0vEL543ACv R/bzoGF/+RbbQznjhTBFdJomjMlDrn3bS0QMSFteIRgc5o53F/BSlsqdPAMQ9ulunESVD 5chD1JcEw3NyQPhF2NPzZHeh4uU4aQe0U3CUA8cQIgswO+p5vbtcL/Som83GzHe9nhiNm RlYk7Zi12cO0PbQFi6xwtAjBirmWH/R2kkgFFqHxP1bXp7bk3haPt6w7/DfiqKE1oaQ== 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=9R93eLtRuVCsdbuGEdtd6/wt6t26wDnU5PW4NiI4F68=; b=dbCxpKlT0p/mfAI/oAbGYWWsS+slX8EhuvpitXpUmaRll1IG3Zk3TG/NdENOAG3Cdw3y QDl6meeSP27piWBl4+m/Tl9jSl0OkA3K5yv0+Yp14K7yBDFssPxq87YI2ydgY92zRKghC 3o9LPAGVEAhqqS0eNR56d5/cO11iTho/RvSYRgrV5wlHuyQWvmbqXwX2iXSWw1y69snRW erby2klSWTc4onE8qW+gb3rb36w2JNeFXwHXdPuYO97vsO/uM7OvjQ5nBUqmDI31pTOsX jsv+8ExlmbH0SXqN01vN43vonN1DZInmIYbQfPGdnp+zKn0OU061i7K3qdxANbjgvoA== 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=KDZeBMxV; arc=none smtp.remote-ip=209.85.160.50 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.50]) (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 773F160A6F6C for ; Sat, 21 Nov 2026 01:11:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 773F160A6F6C 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 Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-451a49abd8aso1569538fac.3 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=lists.linux.dev; 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=KDZeBMxVEx4HoN7YujL7aEiUWU7miU0Un2hTrwuZn4evmr7NYmxTM/gSP+okWfRpy7 bAfO2EKdMy7g5taV0Bfzzu1Q6xGaJWwUzZl/neUD79g4CKK5iCMD7gN/0ZWlkaiV9bqF /iW0UhKTbtHD45LOyikM5BtkuTLaNnpaGZeAvhtSbt2JNBui2QmtNz1+VsdwV2N6Kb3d EUGBntHm77Sk9RWC5tu0r8ymblFHFzocnNWofDeqx14T7iiQ/QHuIcIshsgRhmSL8TSS 6wNsdj8lKDiTaxxkAeQ8rQBXx8a9tawmWrXER1R3s73iXQuIe83Hl3oxJ5kKZICgUFfE C0dg== 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=QrSD1VLRVYoqfTK5FidBbUEHYojpsqH9BFY+n4kSnaEPlW586K6p/NQueYAFVOfMzW /VccYB+j9igbbbLNtlZ5j8LkkBPospvdJ2wxYNhrnSdu3isYYout7/mEg+rWp+QiMJf/ iF+U8rVwvE1tAAjROP6fQMKp9bGtjuZijgDihydeexwuuWliG04lDZJNd1/Yl9KXtjLM IptvR+WOExswEE7C9xarwNRcC/lwNT/p6sFLGiUTS+wNdaH6DFZmmacyEQy3MIehrNn7 w/zEKwGwyKqGYho+RWTfWR7yVABXCFEVDgk80Hioe+sqsp7Q/7Obbes1tE/zi66aJYX+ fMgQ== X-Forwarded-Encrypted: i=1; AL+hErHVTWpb102rR/fAO3HmvUJ71ozwPJidvEptfr2wnoJoeoMn3wXpaU3RFZ95eHlxyJ+ZafJzxsr0ylL0PA==@lists.linux.dev X-Gm-Message-State: APuU4Z9AUqx/hbvJYb7epQ52efeLXZK4Z/qSG50iTocbuCM/8I2H2m6N o5rV67G+AkHzPP/fjmyW/2RKv1YsGb9xSSGp30BXZH7/tjWwyFk4vywu X-Gm-Gg: AYBFou1mDzeQfj5qFXIagrZAJwrb81+R8Rqiz96lVsMuS8s1WtXFLP6a14i9MK8PvkA GrOjN1PRWNpn6/gmyl9vBf5jNwyKhm+9RholBtR1sM+KjsAc3Hp3OMFzLrX98q63ljtUEg+Yl7L O/3fvTAYTY5Vsf65rsadvKUMFXzni2v1g7vg6ja4l+LRlCrxdDoW08kXhdOJWYxYKW7HI6MByYd SrY7xe3CFoeQ88cJf6qP8/joo9srJVDlANE178nMvIeZEMjyWy2nK3Lqncbh1Ml0lnb6kMLndQp tuqWeZPy39FTMJkfNKVYF79xwKDkPXlujfKPmgJzsxKEWblZ4aYVysa3c8+S8NRXM/YzvVu7TzZ wmphQHeKo5jYSGFmTDc0Qf9Oyw37GOCt+2jLprzTrX0lAelHQ0IaTfDj38BdveoKjdCW+Xw8S7h 7OPkIAKzifd/KCtdUHjTrLtXrVkNmhqF8hhNxrNoItS6cCF0fulJIPxS6hlzYIw9e1Q0XsNWqQ/ L7PznCGabO/+2jqmZYBRO5PnisUq1cVMEn3hwNDIQKYhMatYeicBqQRX6nJSitt5ynyBnfWTQI+ QP+Tc8A0xLe+zcT9EaRNTBVO3MP9OpRPD5Y3l13tKATvOLnV3xPgOUKY6TzCGIgu9nME3F8yNSe xocjKL8teCjEDegODgHhxJ+QIC6W28fh4yF79/FVGhEIHCGmPLQMF2WCdOw3U2VdU+cbRhZanK3 traz+uOpS6pBXYTLivFO61b2jHT4GgGsCNAmnnuObgYQm51C5q9A0f 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; TAGGED_RCPT(0.00)[dt]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27959-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[174.29.1.49:received,100.77.114.92:received,209.85.160.50:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 7DD371C5D65 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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); } -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 = nand_to_mtd(nand); struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); struct sunxi_nand_chip_sel *sel; u32 ctl; + int ret; if (cs >= sunxi_nand->nsels) - return; + return -EINVAL; + + if (nfc->clk_rate != sunxi_nand->clk_rate) { + ret = clk_set_rate(nfc->mod_clk, sunxi_nand->clk_rate); + if (ret) + return ret; + + nfc->clk_rate = sunxi_nand->clk_rate; + } ctl = 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 *nand, unsigned int cs) writel(mtd->writesize, nfc->regs + NFC_REG_SPARE_AREA(nfc)); - if (nfc->clk_rate != sunxi_nand->clk_rate) { - clk_set_rate(nfc->mod_clk, sunxi_nand->clk_rate); - nfc->clk_rate = 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; } 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 nand_chip *nand, u32 wait; int first_step, batch_steps, ret, i; - sunxi_nfc_select_chip(nand, nand->cur_cs); + ret = sunxi_nfc_select_chip(nand, nand->cur_cs); + if (ret) + return ret; for (first_step = 0; first_step < ecc->steps; first_step += batch_steps) { unsigned int reg_index = 0; @@ -2519,9 +2527,13 @@ static int sunxi_nfc_exec_op(struct nand_chip *nand, { struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); const struct nand_op_parser *parser; + int ret; - if (!check_only) - sunxi_nfc_select_chip(nand, op->cs); + if (!check_only) { + ret = sunxi_nfc_select_chip(nand, op->cs); + if (ret) + return ret; + } if (sunxi_nand->sels[op->cs].rb >= 0) parser = &sunxi_nfc_op_parser; From patchwork Sat Nov 21 01:10:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4220 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 1F7161C5D65 for ; Sat, 21 Nov 2026 02:12:54 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-27960-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-27960-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id EF151668CC for ; Sat, 21 Nov 2026 01:12:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223489; b=UeVSlpLqV7aoaf0hLiStYcX1C8+QzpYrmWEyvbPddXrNBL1oto8rGy8NtCWNa4NafrLq kYKRpbQro1VkYM3aWEUgKG3RGjsiQzkHi8YbwPsG5k+6KcTuZgwTPIZ8QFq6TtvP/Y33m 8UpjD0RpqYX/GwvSunJ8l0vUgjNKrDILIijODeQj3mgQWiYsOcQ4traYSGCzXqJiTO1DU bDcHbSI2uela2u3ywPdKu/1VSehQCPPiH9zxxIw/q6nyAOTxuj65CDicYrQyb66DxS4rO 0SQMbMeCSYUMlD/2Uf+YJJ58iBQMU/F0tPKuhvDZLHy8fRY0ajZQa47qQvIOUTFPf/g== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223489; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=dWkb9R9dFJf53WgY0/fb7qetN7PVplL4lJbH2mVBctQ=; b=VUtZlfEvF6dDvjPVVBjPJq4TZYxp9uIDCSpvO67XZRYrfGwiwTK4s+XhMvKtudlQ4UWL hMHUgJVscsi6zJ7KecpHTGXvqoFjYi9K12CFDpPK+dgDVqRSlmREilGRS0gmY6yUe+V+z G/PXc2e8QMpsXXb7JpTw0G5n+jUOe3oE+8sQ2HlCZwrGrYs5XnR2L2H+VLchus+rAWhdj /eHdGBJrs1DHzsUEL22WC52zKVUoqwdnxEatv0RvoiE8hOwmvFUJtOFr9714dqwJNe7H3 QZpBDSKJ47PPb7Jgy1YQ0ciWoPynUMgD2IE9TRSoQjM64RcGLY9ijLGwyaioUJBpcjA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=o4dNc7KP; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B895A606AA27; Sat, 21 Nov 2026 01:11:29 +0000 (UTC) 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=o4dNc7KP X-Original-To: linux-sunxi@lists.linux.dev 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=1795223489; b=KD9eK5zsjDn/15HT//hBC+7/xtxIuTqXviG0cOEmZTg8aTykWkLPRpnyVU5NQeQQq+Xx D6C6QutAvUoBdumdMyJs8z3R9DuPiFlxXVYqInrow+tGglnmuXJlc/FkPn8xWOEdciZHU CgDEwZ26CEEmpGs1JTp4VrwyeRqMHPT/nWOkXj2I6nEZynKFXoIr+qQfrtVbPTrTp4RR9 og3ZVfXSqoaV8dGuIEMjZHQCW/NPUt1MLpFKLSxJfgan3fAqc1RSqHZSzy6C23vK0daN/ 4iRGa+b4OcWxtLPXEsYrbUlqMXt3a5qR5h1/PaAiLdhBVike3tqU+9gB6M8ijaPUhWg== 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=dWkb9R9dFJf53WgY0/fb7qetN7PVplL4lJbH2mVBctQ=; b=vUvLYOrJAF561Jrr4dU5e0U5G3EvWg32YyrPIOMgIZ855OdtuTpEhoHhKpg3zMZuB187 r6fEiEkuSIzKl23OEb381hxvZGFALVMk79Nsjo9lakqmynxnqwG7kVurdCvIyHTJ+ndyW riLOSR59SVf4c2jym3I8TXFTYiU+lXgbi2vHEfrGNPUIB8usiQATpuVcZh8e7lfVzbkO8 czdXlnlg4JAefGBxs67QAzkc+32EXNwxdW6or4Pc33eB7eUEZCwj0IqCQSr/D9+sK0Bd6 Llh+prP5Ux7n3BCgndmlLOOFfftdIeZmg4/fUknWhRIBpYeM3D2giqABs/+/h0bFFYg== 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=o4dNc7KP; 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 C44E0606ACC6 for ; Sat, 21 Nov 2026 01:11:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C44E0606ACC6 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 Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-4adae187d94so987942fac.3 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=lists.linux.dev; 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=o4dNc7KP7hrqB5AW0L07UCEdUqWPT9AJ+74zVETvVBAsPGdILQ/TODJ2NShKJK0UYw gQ2m2uJnt07V+F1Z4og3gDtNIz64CDJ9UJJbWx0Q5Vlwvr5WL28RrVY5wY3gJL5jIxkD 1CMxEEpHg/tzQRXlwEJgPm8QicowwhufmDdxXYtr0uB1s42d5zx1IM8EatPu9bBK8Rtn uvzpe0X0uQC8DzcHnSu6dGfWs0WM+Gm2jYuWbesOXyRObQ8mvT5ma+i3FktILj3LKQdU DrXwhcXhIJva4MX/DMCk8KSmmmlyklD9yPUdEpk32uAf7fuKEwIhTzUtyuGGVgjsBI7e 7AKw== 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=FyRlqQ2lmfMZB2JD7tf37gXuJkerA9SJ1hGY73M82twGDlmGeq5alkk3AT9fagsvka YxgQ+RTSfxHimt1ckwUrheszIezHjiBUHgAhxZ1+fqwj8y9MYcCD8sOoMrxX3qJYoEie p3QJp0WeTiv6TYJ7PqiKayNl1tlpHRjPO8oQs7YQLZPEHMtl4E65a3Lv/chXIoCxfrce +/qIJ/ttNM6J9RuS+CbDJXwucosfdBrA/r6hSOompjcX3UGkQJjGxDpqWU5UPADYXjBH ZkUaNcSCzqOuSCrTxXqzTnX1uGM6Zjuft7hdrAUmvCpC63mtna0zpTtcAu7KOmcRX121 JhDg== X-Forwarded-Encrypted: i=1; AL+hErEfeBn7d0bxxKuCOmtujAR36kP51Rk57qcrM0qse2ySR0JDkYoeH47adK1zQpfnNjJh5tuctbPzUQEamQ==@lists.linux.dev X-Gm-Message-State: APuU4Z8XKJdn6p9ot6F7M5JQtqEiuvTEfbjFQCqYWj23jowMn7aCNKZi nqdzHKTBMmKvyMD2QiuNSGWSoLT+fKyi9U6hLpc1YzQdMpcTD5vM9fyD X-Gm-Gg: AYBFou1V6ghXvIvdNhv/lru9Ato9qFv6aHRs+ExvXqLUqjqX77RGjvjt1btnu/mt11M 9AwABw5piqIkHqjFuBWvDRM1T8SKvh+ub9TpEXSTVYaizixC2N5NFWwstWVjB4LCMNwwI3237N6 Ok+BODP6N5DhWl3sh/ED+HLoWMU+JuSQ0t8jApB7+GybuDU5yOq3GS7j6sB7Av1H6Uw+EoN49WJ E5qJoauMFnH/zS0HlZLm59zQweWQMSe/WJi2XYEWVWaR2hu8SJgbVMdTSHDfnwMdLlMfcOxpGRO Bc0kbf++XWAgA4ABOXSu2zf7gHrYoc010S/WhIrwMCsANGi/cwtT0+Y30/JK1oBPLX5nt9eh8Gi dK2aFHI1YUAJ7/b5Ix33LUyWv/FWKQs/gBQstOyTN1YmBSpmXze5Rk/4i8d0AWOyvEE+ANzW2AF E5Qahf5/ET2KAh+9mbFn6H3biNI9Zxi2C0zdHPK1U7Opuhvcg5t/DclGByymr67PISCXaFFRH3d qMbjMwM5UhM3o1oFKL9DKEcU1wQTfxZRJtaXXypGvmIuotaqBFHixPHXL9+XkPqwMz1StvoV0YF o/9BJ0EZhj/TQlg99CmOBkH7MYHE9b3cfMML0bdkn2URm3mG6/E0nD5Vi5vA9hMO7G2xekCvkql gly2smxRXzXRBaapPvkNAJ1+jL8a5SCmB7f/MQCYUqA9FgrOXSlvXL78+vS9+u7kJGiXz43IrYA IBnukTQV2JY03Mhn+e9HGvxlVZ37cGL2z5Wa9swU0qOiqdIfsW6o+Q 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.105.105.114:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; TAGGED_RCPT(0.00)[dt]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27960-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[174.29.1.49:received,100.77.114.92:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 1F7161C5D65 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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 controller") 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 +/* 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) 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); } 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_parser = 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_op_parser = 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)), From patchwork Sat Nov 21 01:10:44 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4223 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 7344E1C50E2 for ; Sat, 21 Nov 2026 02:13:16 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27957-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27957-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 50238624B8 for ; Sat, 21 Nov 2026 01:12:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223488; b=JV/gIfVc70cgflcXrfJCoy/K0F2VPUuPgdLv7KDjMXhfHGkYV1pDTM73/dXO5R2DMDz8 hAG9k2DTLZo8EPupFq50xAqZvXFSfscHZb7NL92kcs8RpkZ/tSbYYK1EASIuLMsvNKDlV p7Df7Lxr6MkQWd3uFObEsFFYsgRcYTxlfaiM+u8uS9LqcFUOpFXgGMq4rvt7zsD38KFFO e6EOAMNdlGnp4i/IUIi9hFcFkynxqS5alLNK5L7o5+J08JlA6+/c75lnhYXj9mgBWS73C eh9hCBe99AE2qvKYBzsssUrPbpSCExPCr7KA8U9REZjSoM/mQ1Q9cNqebwT5Q45azsQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223488; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=1uJoG142fYCuU8vw67QDp3rEWq4mupCEBikzvmy4Exg=; b=z1ej5C3/lq1OSIS8kovc9droamXEPGJl+5t/ORuspXTvPdBgotHAo7SIHHtBZI1L5J8F 9tJTNmqzedjaWh9ZyU/nf+vmbatgLjo6fPZ47GGy6R31cStEto+6ynmZDYUi0J1RCrjAO PE6tzb8P9q5Ho9hHqa4yMVQSt7Mu8bMkJJePwTs1f1wdXCORRH75Afx/FLcj52YL9fFKW xylIN8zipUpECViAli4YrD4xR8GDslSFxJH9d0U1ZG0SDbj7kUdXfzy2EN6D6aHt5v2O+ o/rQ5XOZkweiv7lzR6+cNcfIgR4cU48559PXIWsAostAiC81wcw/Hm/bArzCjmWkbhg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=cFleb2QW; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0ADC060A5BFC; Sat, 21 Nov 2026 01:11:28 +0000 (UTC) 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=cFleb2QW X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.175 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223487; b=u+f7HldWONCag46E4v2vLgr5Xkdg3L3y7rULPdLBRbwRS8N+27JAW9MfwV2sG9rPek8+ he0staPm3G3Vk5Vmv2pEKCE8cJ5HTePybUTK/omLalewIcXQbeBx2JgL7i8POuqE5brwa YuFjKWEy2an1Vv8ppwU0kGJcRFy4a/C9rh8GzgXA0vsw7QvB0/ZN49MQ1do5e+uPxPpUL w7t6M5XZdKLrAokv/7/1fsZHSfRavqGUgofYIGHN6tTtZ7BDgWB5HUZrUn5zf6l37j8aw H+ilJsuEJEkXDLzBORSsS8CIKwcvVLd91hA5TSyJXJbqHpZhEOkC44/sK90NDoGqrrw== 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=g6E/GIMFDGemmE0p1b9JlLMaGo4+I0R+0uvbRaY0jV96ylTkclYgKybqEAvACqmI26c4 A8ZKhLM81Jnsao05c0tbYNlqLp317vB3wyKXhnTUanR4TAyUuv3ht/MHgDufj29/dOr58 8BkxY97ZKNnABfvq/gv9ipy7kYJ5DyyvjbVe2FqAHgrfocPVxKTZ5aTp5gigcyKYn+OnY hedxBX8EOBqx1Umnls2EH85UkQsOFGaE6JleTYe5SUN/pHz5k+sqADFjOuYQ8Yb2Pq7o0 jV4+UB+URPh2LLH3kXiQ/bASTKRyTh1ClZ2DnW0prmBWRWNhiR350oV4ZX9pQdVmRZQ== 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=cFleb2QW; arc=none smtp.remote-ip=209.85.167.175 Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) (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 23F83606ACF3 for ; Sat, 21 Nov 2026 01:11:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 23F83606ACF3 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 Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-56431524c22so678555b6e.0 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=lists.linux.dev; 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=cFleb2QWZnIY6JP1tnav001EFHGR3tEZslNIKBYF078lRfmiRWVEfcceTUw09ocQlt aVxJ8n/QiBuQd8mach1eJmU+jhT9nPwkEAAqcGPPtdcIeNyMRmAvlhFSsczsUFj03m6I f5uq7sdfAuyrBSa/FniEeaxPMqkKen0X6XUO2WxoZ+6J83sHJL7X7CzSyKeAW9LpV6ZR jicbVonCIKt/LoUvXObjDiwXpbnLF8LO7/90+7MPTQ084tysRylfbrEXP2htG/v5Dino xTF98bQcOZl5+LlMT8Tzgjp5lCqvzD840Ii+UKnpNS7Akc+EJyPHG0Wr3t6+LIQf4pdk MxQQ== 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=rMlvACXAxitojjiN5+TS0f68VwfgJI63sJu7EbFcTNIZyxp58x5FUoLa8fZ4LhT7px JL86d7qsMkBdPmXo4o39/NVEYL5L0wLeJFyuosgqtR1MtCD4vMsGWGZabOky7CfknFr1 lxIkzwKXwpfhA6EphMwgt6YeDNzvPyKpl4VtfSK7Esv2dqT2bBFLboJmtvEinGmPnlP8 +2NVuFHJ9YfBrZS7m8i8W3ihaw/6K4UWUhf2Jr7G8pS2+9eDZzEfmU26VBN/ZEcpzvlt Jtr+hxTjnSEzZ9h93gEdRTw2b5C4o1dQ32KCIMoeqBzBJzaTgA8lMHfmCi1A5KDK25vQ CqTw== X-Forwarded-Encrypted: i=1; AL+hErF9k/+vrtW8IayxsAmQNqTLz/cRLKnd1CNTmqPiqF8kVpGVl9JihuqK2awv258y2F2rvfV4qZ1QJTdFGg==@lists.linux.dev X-Gm-Message-State: APuU4Z/AnHtbmcdaW0Cr3ID76uXkMdq8+fM02sV+8jtZ2/h/mkkHi8B0 Czh6NwdcmTjuImfiA5vO7FQxeF53wdf5wnRsqMmL/jgwDBTIZHkC2gEn X-Gm-Gg: AYBFou3A/kUIIQ73QWpY1lDOn1J6VGQNwDMqXGe01GgLItz48rD2sW+4YLC/6y5e0bh 0nvStdVgs4GrxutO+9u8NLE8g8bdjVYLM89LS4EKrgdjVfmrFWS5ZimaAQjaHSP1XC3tO3i/2FY RqEVeubPn7G3owVDMGrvANV+L8xXeitZzoVKiqluLs8JadTzP4RQMrQPtcDMAoE3WE9Nzh1IHLl 9tX5XFKXJQrB+0xuYVieXfT/Y+USPkxfLWFWxuTrV7CuYHaY7w3d6c+CCvUDWg3aaG0g9/kskVz sSz4KPjq0DMviamwv+fOJBH8BQW66mCNn8yJvY+8zFCBth6WGYqJpc92I5YV/5koOG5lCCf0iI2 F85eNSkDgawpEstYIb8JU9D0R2CVbAjYwPGWQRZhNh/O4ZVHnS4mMpn8D2NbxUjhxtbvhKXQk1J p+Q/ajsbpiOFSJxbiFV33A7XkRDiRKE3CNtz/1xrIohip2RSgKcIYmre6jFaE7WcfC7oeXNIvkW TebGdSoZUhHVJMfOvTYDlzzYphcl84rdxmKJN9ZR6SRvCSOPafkBdv2R1dg2wDFI90DFFEVYVOR gIDJL9tC3c2grREwx5GLySEyb/zuFBzbB0kM/Gbk5utU/R9eyoBrgAY9UTheZAzrWh5FJSJC1my VfhwVn2VgEMcFolOlxJwWtUxI8t1grcnGCS4E32bsU9/tEown8COCp9izF+MJjvf4NcsgPR1eMK 7fYFV0npvZktbISOQ/bl0aT1NY9QzsBRj5kHnJz+5guYjsEm5hmLgC 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [4.31 / 15.00]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; RCPT_COUNT_TWELVE(0.00)[25]; TAGGED_RCPT(0.00)[dt]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FORGED_SENDER_MAILLIST(0.00)[]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; MID_RHS_MATCH_FROM(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,174.29.1.49:received,209.85.167.175:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from]; TAGGED_FROM(0.00)[bounces-27957-noreply=patchwork.local]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 7344E1C50E2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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 = dev->of_node; int ret; - for_each_child_of_node_scoped(np, nand_np) { + for_each_available_child_of_node_scoped(np, nand_np) { ret = sunxi_nand_chip_init(dev, nfc, nand_np); if (ret) { sunxi_nand_chips_cleanup(nfc); From patchwork Sat Nov 21 01:10:45 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4224 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 2B64B1C50E2 for ; Sat, 21 Nov 2026 02:13:30 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27958-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27958-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id C823DE4C80 for ; Sat, 21 Nov 2026 01:12:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223489; b=YzQmFEChr7w+KYD29oMkul/tN7nGMqpMnRCCKhOlv+2vrH6cKKOr24iBuosUDr/vJy4I wA4BxxaDrjMi1BWDOAB5BW7D/Lh+LmgUHGrHet/jcZwstR3f+6T0zJXDPVGscvzFTvl6q /gNBvVBZU2dbUCq80ZP3yO19KOB+fsqIY8xDCFmU3bkBtkrd4GIVYdWvQG3PoeSWl1egy roM0cRAfLGUSoPFoS4cY00alV3BLQS/7HG9enajj5U5KpT+K2/ARKAMRHpEDMJDrvi7ux I9A2J1TNdUcGxmHS66tndJSvga4yHxWke9aVHnusIj0P1Bryv40rgYJ81crA2F9+79w== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223489; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=jCsma9jNkefw5HpS61LewWc4mQKxmVwW9euoTiUjDLY=; b=YR8trmccK1MSZwAONedEVgn4+JZtZiL9sqk8msBVt3o9QrZ9M4VN0OTuXifcJmFRD1PF GOGe6gMGYN+q/iOp6X9DFPCY+Yy7ihMx/7kDhhVUYSVunkSVkmxtXuiufqrazaWhOPe0r BJ28tpfz55ZnfkCBkpVEqjK07UYnCWYJ6Bjw26cGsm68eFrTIbDenGJhXrQbzFmtlphqI V6nOhIlvN2TNiP0mmm1CqjNjEr5h4sPI0bHshoW3fOTqJNE4ZCTkQCbIrWgySSBJ2P65O tZSw9gTjl3rwAYgEdZ1Q7eyEw/DyhP5Jx3jmlr8RwDTXm9OL0MK32SgRxon8JWkwVkw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=XfzFZQbZ; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64CC8606AA19; Sat, 21 Nov 2026 01:11:29 +0000 (UTC) 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=XfzFZQbZ X-Original-To: linux-sunxi@lists.linux.dev 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=1795223489; b=xBHvLg2djGWitU9MbNbuClDKwtUq2mU0KisVooe5QsPHQRtNnYQZlRadq3Jm+qiSwER9 pdauyIxeKs/Aoka765RRz1jh6NppXSDz2hUC40CB1UAKRhWA+xc+UTURk2y16/XMRk/hY Ol4JLnNtrSWUiv+FsO+GvP2QMxijQi58mobL210YnJgr8vtdrMm8BFC5L8KcQ9qPQrQud WrZ2T4lZhGEp7dxp4rI7YUVjCSR3SyEjLsxaZ/ci7iO6jdYAuvKXjxENOgZTDXw4ZiMTG n8BRUyQFJ9do3Gyq99s+bFvlT82nu5Wms51HsM8xYJAL24mi2Aad6BZ2k5Z8zMMacBQ== 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=jCsma9jNkefw5HpS61LewWc4mQKxmVwW9euoTiUjDLY=; b=tRLEhOGDgxHT1ovd7kYynyPRAj5H4QLKzGGpaFMhaofotLBcXLJdxfVJxf7FqfsK7ZDE 9TE/r9hjWVM/sX6cSIYPs1RMIchHtdCjl4GQLqT1BiYmSh+QkeCj1lcVnz7EhoLdf9aTs 1RfOtQ1MDwxHm+u9OoBCUyarYwNiPuJEG7i71hn5LN3Y71AZzG23c7yZNogULN4IXF1gI gE7UCcUa3Axkym3zE408VS/8pzRxxHv+yeJ5n5z7uNlItvtCSkxwxNfYHR6L+L0Ujz12B DmaFXYoMrZYBpNk0veIqI+zq7fDojCU+JGlcneFF76BGxGeLxl6TmywdHhJ0XN2xb0A== 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=XfzFZQbZ; 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 7845F60A381C for ; Sat, 21 Nov 2026 01:11:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7845F60A381C 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 Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-56431524c22so678564b6e.0 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=lists.linux.dev; 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=XfzFZQbZQZrlLOfTcbJE0Hw2F5L7PqJsihgSYiU24rGgjKovNe/5LaOFb4l1wmvh4c KiF5PnjavU6PQHhES3uXJsQszfAmOcCfBUUEAUjx9gPU5N4hB71yxH8pIsrbhsNZ1t6o raXhTZkPchKVxOXy9Qa9FK/TBeQYSYxlH49PGnQEqNwnQTK4C/F5QMc8Wu0AjBmk/S+8 qY5dXqbihY5sPGX+4Kq0w0yNli96vsj5e0d3SVcp0YdwoXehNG/eHUa4t846z5wwr3UB 3WCBMzgnft7yHqJ+4iJnu7fHXt3/ks10womgTP0qvXvIb/snQziEVCSEMJWu6laqXf27 vOOg== 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=EJrY4E+/1djI4+gHt/XVWLRvQyLWwNjPACMozbXEkXpej5NlsQbOsbSZQm8iUKMo+4 N0Y46/wkZay40VVYbfFBgE5s9SQe66dzp9CcpHeaaSEjfj/EFKwiuoiPr8J2yCK6FBRv rJIG60RxMVnhXybW9GfX6NG87GRdXZzXqwHRL9TnIHvFnSxXX9+QFFynKZZaeGzuL1GF rvisV63/qT82lOu+LAL/S9suSCtkk5m9P0schKDbTF5brJUEXVYiCr4+WzLR1UVgnvS7 hoFaR/TUJUg1ZW8457PLqYbcxuJhnVdcVLio94uyBSX3Vn2rdwKAXrtEAyg+XRUz+GyF JqfA== X-Forwarded-Encrypted: i=1; AL+hErFkgeWBHQlNJXSaaiLzZQHpdmeHbuRCSQ3iqCrJZVCtSGwgjHo5cRnCtie7GtsWwOIcLzoW3PNzpISDXA==@lists.linux.dev X-Gm-Message-State: APuU4Z8vmjrn5/wH/4/G5iAtxF7leDX5gYUuqUQGCU55w8PLViS8l4Ci 6XUYgHnMUO7dDlmsDvPL3T+9a4VTQ0F84XuAYK2njHnRP4gTAdEYwfzG X-Gm-Gg: AYBFou04AXfx63eUjFcuk+pUEA1Av6nZYsVjMPkUWQ5VgHRplUKKDiFusS/wnpIFGT6 x5veZwneR8ZkIgZF4kzBX061DEH0l0YwwMca4AA6lpjAFjtzrWSdq2NoP1FlbnmbqqZzqPpTOMs rREoXqXfxf91RjXy5rLgn+RefFu46fRAia2tHghTAyhyOn+q1RCnTYtaeHcimg+YaHYSNgXs7hj QVizJgmALBMfuZV7Ap/OS2z22m+w3+QFn9nnTnXnIn4dHQjHvB+ZiMfrEuYggGjspKse9POzckV Y2ufCSk7u+00Hc0CAhuA2k7jQKsKZ8LudKRbToEcmk6xZrvXoMqrktXwoEVavlp/hXrsWA28M2q qz57nBeKMWIfcA71ARvPddlNsBuYl5lEox5QuphlJNHTANGr2UYiFuST7LOkUmzAAxObVBh91Yp Ub+CA9cjCbxvYRx+7r6gDu22+i2e2xIClOWsStRxXq4Oduz8dJIO0+ig4u5pnD1Wz5RgVactXXp n2wrxmamwn/JYvF2xHNuYYsftDuu59oYTC7Rs4fqRF8A55/CMgL3/wlyzUkfDgMf5ehN3ffFw0c YE6UlUP9G0CMybTzhBVITbUVFcziF//KNuvGVhyYqLTHyPtrhpIh1ZxGzxgeBZ5mTUeAJP9Nj1L x4JlzISnFFyHSnWr1peOxo4/arPXZbuEpkRsIm1Hud7ekTIMZ1W6y3l/sDdNlRgStCVWiMVEXRH KOhagCRoJNVcrATcFmdtmfjYYU1rqsmuQoW4xK2/GHeUgSzOwn0qek 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; TAGGED_RCPT(0.00)[dt]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27958-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[174.29.1.49:received,209.85.167.181:received,100.77.114.92:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 2B64B1C50E2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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_nfc *nfc) struct sunxi_nand_chip, node); chip = &sunxi_nand->nand; - ret = mtd_device_unregister(nand_to_mtd(chip)); - WARN_ON(ret); + if (sunxi_nand->registered) { + ret = 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; - ret = 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); return 0; @@ -2658,6 +2655,7 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc, static int sunxi_nand_chips_init(struct device *dev, struct sunxi_nfc *nfc) { + struct sunxi_nand_chip *sunxi_nand; struct device_node *np = dev->of_node; int ret; @@ -2669,6 +2667,18 @@ static int sunxi_nand_chips_init(struct device *dev, struct sunxi_nfc *nfc) } } + /* NAND identification must finish before MTD users can access the NFC. */ + list_for_each_entry(sunxi_nand, &nfc->chips, node) { + ret = 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 = true; + } + return 0; } From patchwork Sat Nov 21 01:10:46 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4218 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 96B731C5D65 for ; Sat, 21 Nov 2026 02:12:47 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-27961-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-27961-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id DBBD166CDF for ; Sat, 21 Nov 2026 01:12:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223490; b=saSiriBkX1Ls3bEL4sKtOHHQ0iwvNddmjuzqI6abg+RSrsgaVQ52Qa4EAwBmS42UFxhp oriUa+phmzZ9itIaQbZL7Nn7ye9s9M1IvoGi6Zi41fNKiv0ibC9fqYF1F7GBTrFwzsgz0 cAaUKUW5CBlYdasaqLiETIUFeXiWoNFRWoy65ywJ44CnG6wCZyR1nyk9uafABeFBs0o8p hVxx38WBFht9//rYAHhlitr/eBDG34dMb5eXpAgnAeyCV+LlOhdZv2JcfSVdPATnMyUfN bdoUND8rMwSGqG6VnIsPjsiidsa30vcP8ilWATXvbr9+U8yGt+qg57SffaLwyBuQhZA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223490; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=8wmwptSly1/jnXieQYc5MDUwaGqVqpFqBShPCzacVyA=; b=PjmA/v9elGRYDpKP2QokDSQqXE7IZuc+njVGWegmj040W+KVRCk7f29ad6Dj1ACQWJcU ZW+MzbzDh/HtnR+FGppYWQ7wdLe5r52724xbS39J2ypaNV2c3q/Nl5l+Oz4r0AG0y3YyH Gjpfm+gVHVyLoHRstUMl67UNuMM6ZHtxDCnES1feGknY4QxGum0WCPdwl3nhIs9bGe7gA PJngJlHVOyaha4iMTPYYYtowa9SoNaHXKJRHAZS0o7j6nCxQ6BChSCXXxRR50ZNvFi5G6 WVUP7scv2e1UO9vqMoZRHs+eLCYunQokhfOzqk/patISG5hGzZv9BBlfvEsyH4QwFXQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=oRFXLhvY; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78460606A680; Sat, 21 Nov 2026 01:11:30 +0000 (UTC) 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=oRFXLhvY X-Original-To: linux-sunxi@lists.linux.dev 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=1795223490; b=k59dc9qEOAZ95D/lkVSXKbjd63xakgC1gYCTmUh9ugL0yGq5fJx/ZLfZhwHRfMkOawXB /VMizzHQOMaKC5WJJ2lYd5LRJ7NLT1R/z5ipo+mAHaWqavkf6umJi8yjcDbJ5tgvqUCW+ HgRvdqGrfcrreuUi+ENYI4QSPFIM8fDj1uorHtDyddP/I+K7ciR7gHNMFql+uTjwqwnk7 NXnK8XG5B5gfwGnVU97AMCzQfLD9ziu8tGgeNa079AeWShyHI/Zzz6cBRQ+Vk5fu5qm8m LTd6kHmYKm1Ib7IdCiJEn9+n876pybPNslxPWpid5VQd50zdy7Mblc+Cu4G5eriHoow== 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=LjDawBXKw/VCkhkI2IPOz6owoHxM8zC1o4zXV/3NN4Nr0UNAZ9q5FOt9igtlfBHng+j4 PuQCBkwJ8h602/+7AGTBfaMS/87Z7NLHIjz3cjoqZIHKMcvEtjtS1Y1dyh+EJm+sPCjND HwEmYt5DCMQwzRtWAuiq+MGQwHXGKzJc0o48v8M7rgJY4BRvJVd6qiLf6+e3VpH1O41ve mLJwrOclAdgtGcl4FHYhzeQzfebmbZ/k1FlqSkk82DREmw6vjv6tuhl48X2GGTt54WsgM uGBFtVdHHTfvWVrk0/W9K0YSVky3o0ARpl9uNjt1hzsm1sGnCnRJeaP8nd2zpW50BVQ== 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=oRFXLhvY; 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 C2CF060A263E for ; Sat, 21 Nov 2026 01:11:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C2CF060A263E 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 Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-55650fe1f0dso924896b6e.2 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=lists.linux.dev; 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=oRFXLhvYkpJHHWopAfhW6I2PVzmZrjGr6MmnClk0OaD04hxy5uo5fyDN1dFHzbTtOs HY1f34bHm/7Eyq+SR2R9s5IR7eC53O9RCbPEuIzkKSQVOtgHd6frcY/1FIaMTVY+954v TLl5NM8+6MmlWEge+ifoauuw4LDFw4Doc/buWDxL7/ADUJ9qu8zLqJY/HSpdaMg+HLdv 0gkdoKocANCwp3ELflQG+iuBlU7z6+Z9i5927yss+Y4bFngF2Ow9R5Z/rVPzqqKxC7wc 4FaCJUVy41GjBI6scYpOAERSMhLyOKg5AH6SWQf/UJxu7IZeb3ncHrxKZQqV/poFOTZj 9oyg== 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=DCVkmeho4mg4KuWHLkbcpVNGlpmGYKZSP1cSuh6apc7/bWpv1WuOxaHMBK9a1MqCg/ fhchNoj8q8jqAIfVXigjd4xd/LCoNldNrAivm6tUtFz0j9N3NqmpOtXMtEcYVIBQOS0G tP3IVZ9x+F66QIGdOZ0eWqdb7ZZlaKxAg49dinPN2wI5fCM9qaiw8lH0ZVh2B9KyjWe0 A0kB/Rn0yrw6Mm/ougn3T8uwANFwFQ644sPgjrwKLdpZ1p5hP2bPm1rutxwFrNNeaBQz JvdTXX2UE5RxNI1aaSJrrb+ZBPd2tw2GMl/KDzjTwHqRjerTYb60SAMq9eekzTcllfBo Ht+w== X-Forwarded-Encrypted: i=1; AL+hErE1JGKR84yi+hhrrylznl5VUMferC7kR3Z05zb/ikSTcOmSZFDzWt/dXBCbkCz8GDPN++jc3+UwjyLcWg==@lists.linux.dev X-Gm-Message-State: APuU4Z+Av4sB4twj/rhrqa/jo5L+yx2EslvZ4a+ZISDW/9XkIW1mYA55 WitnZnBySrfZGqDQUqVy7Y7jC1+kvUkCuPudRdDxXRospG89h7xBc/z+ X-Gm-Gg: AYBFou1HFuWv6yXoqo4s+oBCN3WHiZqcXTZjds1iBfAaI0RA6YihBAIZHVzBvGuPwN3 0nc8NrUiOd7/CqNxkqpmWGoy69Rn3Jie4W4CEhF0qE2ph4jnqWPOrkpKGlWO/m5m5LRdNRsJoeG JAPtc5r8C9xE16F/coHfd9z6ZuO6POkWKM/180uGeaAxAkE2tktHyINsZpTvRV9/zK7Un5BvllW +qmt8b7lxpJPCLl6GyOWRyoL8pE+DTTDriq3DO6kYpSmPzV2yvFwKy1EK0oUTXMYZvmp5fi7TNb 5by1/BEWUdcQaVl23zk84L9bxjD20hkQMKciOL6hVodJE4aNd9EQMJ7Hp0yHAdcknl0RH3QLxdK Q6yxuHRrUiEbU0AZUQGPUnlOVrUGprindcMCJcIkrQLFaG7oEprFWjJ1lUi07ygDyGVkO47Hwnr pGHqfFl3T76RQoBgQJBMqlqI9sPISydJve9PFF9HBItJYCZD0dXI4F2xw4N5NQMHJPRrJWM4LfO 4RvxNFXsMW2Sbw5E3Dd7ki7BHChgrHEHj+x6XA9bGwq267uELEZW7xM8g2c3ioxu7GC/CKMP2a6 mtgnemre6X9P4oDmcdFel0Et1rT7lPTv8sedHfMCFSFMA3V2hSsyfYqDOw43EWiyGsq2Pb0v+VM gCPB1yehr9z7F6Q3uDcgS5klGuQmjUYaQiEoDjro+FZfz5DkVJD5cBic2iG0mzJqFvdvuY4reeE EMVwbBiedrWlgTJchRv1310TWrzqMw8fDiRJJF0GiHgNg27gs3oRpB 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.105.105.114:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; TAGGED_RCPT(0.00)[dt]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27961-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,209.85.167.180:received,174.29.1.49:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 96B731C5D65 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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 examples: - | From patchwork Sat Nov 21 01:10:47 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4225 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 812991C50E2 for ; Sat, 21 Nov 2026 02:13:44 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27964-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27964-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 0B9FDE4F70 for ; Sat, 21 Nov 2026 01:12:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223497; b=1NjhUkaLW+d+uUwlzxafaSV+Iu36tskKnB1GXdiPKn4tZ9c7IA+twwSTTNzn5m79qlPj Ut41kypPuZjhuqF92nk26pwhP5jerPViD++dZUENwbETxhLokwUDlrhvu5LnvBR3kM9rs Qv8WGe/ydrb5FmMJ50cpmKv36+UQXlRWgYVcSdyK0Brpu1+f2RWUyy4+58YQWGPL9u7t2 Py/Ly2kSBvUDmCuy1dhWM2H1c4f1m1XSJhRN7kZE5kWtPyRRTpmU2BZmwEnvdtM8iq+rY 10Hf3oDGtgBdSIER91DwJQQLD7do5piLo1Vm32BUdTPQvcrSS03vGtEmsjbZlQlEypA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223497; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=0eYZ3HbDY5x5zovptu6rAgNNSCJghwXhmaa/sCZVI9o=; b=fqeRlW4RMJJKa5QVpWRH+v2H2tMTK1yk6IKVPJi87PFU2UOgOrjZPzm1ZFVAkcnJMba9 PMIY0YylClIQ8F6E1HJmSvEGCSemAJBoChuX/mqlGAijYhIIkbyep7/nnvIViTatD86fy 8ZNZUwVm9UR7JbG/B5tavYsvai/p4m4Zsu+IW7WDFWKMc2ofHB6ykkg49X9cVdQfBCz4m fmt4fx6xtVS1Zb7vQvp7qMoE+pwPWr3ycU7nD86OJhov9a/9QXEreGu885Tx4e04EI2v9 bLsDZUZqUxWo7Nb64H/1zgTVPk4I+380TS8PQnRdZgaJOUtKAklecODLDfK6T4S2dJw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="rnNiRU9/"; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DBA56606AA01; Sat, 21 Nov 2026 01:11:37 +0000 (UTC) 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=rnNiRU9/ X-Original-To: linux-sunxi@lists.linux.dev 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=1795223497; b=htQ939zJkXmh3vHjpOA0iRFMvnBw8KCTjp76wUYNEOUh6maIWcZcfvCcHcax2inIT1Nz ZIkjG4iA8MKuQ+rfvUhJR2fGIJurD3EVzN3s5/xoJXJOQkwR8Y9ZBg7tEpY6FhZX6IAoe qJ7kWLozevboKFY3iRnHD/p0uMhr8PMn6PEj+V/K0Wd/bjNN+l4pX8YjE2k42w/nUI06S whn+354MOxfc5JqxQ6qTa0LOtWXQTVB6WJQN+BQRI5Zok7G0hWMT6kIH8+CLymEYUAbXg xu5VzKZgyKUUiiKez1xDjsq403IletGlJJwQ6ak7DnXo4jDbtnXAckIFOgclrWfZHaA== 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=0eYZ3HbDY5x5zovptu6rAgNNSCJghwXhmaa/sCZVI9o=; b=uNDFJ4bds56CC9oE3+aPTrp55h6Zw2nVBcqf8Wvljs2LeVFqYJWxKywm5HGPvgtXErlI ud6H1HRtlqb4bmL8t0PkujsRRBPEoRHLKFvWIlNd4OYXOnwxYJLCB6h0vaVq6JbXEyoax 0fB+j1nSKsIEDYB9TsjdsKsEcj+CygcMfv+bY/ELPmZwjFFBNnzGF7/mUTMi/eQs3bBFC nl7tb4FDuTT/Uces03JyefoPFLEmiiClsZCnQL0vcLn7sRG2ibBjQFpM6RjkuMgeXzytG 167SMm2gSDfA2im+B9DM9cxOzIdB37flxTfYHFjqvewqrs93psgaHquWjqno1zowoXw== 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="rnNiRU9/"; 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 6CC39606AA3B for ; Sat, 21 Nov 2026 01:11:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6CC39606AA3B 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 Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-5642e0910a3so742056b6e.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=lists.linux.dev; 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=rnNiRU9/bQq8ttzpXzYTOT0K5xMiEj8c7A3MEjhSLOqnPgyie34QMqiAFco0/hJpDT pdBIN7Zch8zBO3tIkzcevG+pwlKRjeQxQyJtdkOTY2ysHRHvpGPPQZYedeYp01vJoMZJ ydvL4u9MLmAWpaT3854HwKTSKOJ2+lqU+53KCuU+UrhlevV4oY+YIwLgStoz9N0ONQCx vh/H62DEwPjxFxX8qLDUoiFBjMAIf2OB9S8SiLH+/+VIFe5AJsRW6AJDQTPjnELeQt5g qoQSQyTcJ07qwFI9+ApwyIAxR5BtWQrdIHhedcnRzKjqwFi8nL0Kk+5nazYXtV/G3LFh VKpg== 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=xTWAlrdOvpk83udvUIcVQK6kmb8wScJp1EaJ3GP5s/pKIvqySxt03x9nz5/kv0YLKo RrkaZmyM3+d7iaRK2nO1R8sCXFd6r228meg5noGm1E8Ne73L3vKjcRxSDO0q5tj+DO+c fW0g+b34rqHs7cN3JGx5LlsEmQb9HqL6KwDFyWp2ucJLY80qcIkNy7A4VLuBdPZnQtlC N4zUS4soqK57J9p89NcQFwkaOlbcXEqcdgkc2S+9aQ7PTneOKgj1hDoAtP0qFwmSpvTI 7bHsnpivIwRg/UnvbUOGwDHoZQrwkJYGYYBcvKfR7aUkUvi7FXmgpq/ZV5EaTWTQKChE EZ1g== X-Forwarded-Encrypted: i=1; AL+hErFwSiav1s9SoAoGlS2nSzF/5ZBrrAkGVcabg/uLJA8YqcPXwFCqaws4fe1k52Vqgx8kGv3Ds1FQqRO3zw==@lists.linux.dev X-Gm-Message-State: APuU4Z9N61I8QPxiKsDF5pQgWCw9jlgPqhdHNgOQGaLhYEH8+0or/DW+ 75sV7UNH0Mlqe8WEsnjFJ3HTRjHgjtR11OwJi5bGOA/14TRb//9SE5D4 X-Gm-Gg: AYBFou1ZE/mZg9bt0HM3D5cqgbNkQuW3kICf27GRUgBNZdR4/Bq6UHWC5XrWHve4JQX Qo0qkJFnyNMWhSsPd4OArskSUrpmJ016s4t/QaDe7yXoVUwWH45PjZMncp71jb3BX7vc/WQxpWq 9U2dkphV2y0rQrrYA9uEeITy5FZ7sRN+cG7lewBTpA27Bnoi4hRYhIpyNKOOhnKNoas7XVtb4Yx WEAt2/10hedgTppqLSk48dn10/f8yTb95QsTJteyyWovKgRS2B73ufYb8eKrUoDWa/+S+YHhGzu zq5kyevm03PXyYJMvuvsvZsBLmFa/Tb80W8A+Z0h0k/7APu6BJlBr5MDmvAB6Ir4ezvXNL/GPOm 0RTw06CIDGIyvDj8O5dlLUEnHrBIjCfav0M7mXnn1qYLTEcOE/7Eo+kcg3wtCrMReiEYkjyoTbQ g6/XwPb1pSVcvkN06E2T4Bu6GP8ygMK9QbrXww3t1/07RPVNFY/OcyAzP3J5wQK+kNqANmMGnLy LVZBlAfHPgZJOD0CHtUcLL1Of4VJ5foENDqrxz0mhT+MB1vCdZs9OlzgvGKy7QdMNt/Vda9IoJ2 icV+4xQ/YtpLH0dChQPyGTQFsmdMi4ifqBStj6S2s/RGuGZlOJimlTqZJpPeQR5bh1iBYlsjJsM KccG4hsGr7dmuKsR/X40JmxvyudjEq6sY4NGIrVmfFfrLqw/a1aRlg9MGSxRX4WYAD9zRHl+srf vktbc/i20JFMdnbOAxcpmhiKacLOj9avePaVKHI03KdfrDNoIk2wqt 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; TAGGED_RCPT(0.00)[dt]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27964-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,174.29.1.49:received,209.85.167.182:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 812991C50E2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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 ordering * @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; }; @@ -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); } -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 = 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 = true; + dev_err(nfc->dev, "NAND controller recovery failed: %d\n", ret); + return ret; } 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; + if (nfc->recovery_failed) + return -EIO; + if (cs >= sunxi_nand->nsels) return -EINVAL; @@ -1464,8 +1505,14 @@ static int sunxi_nfc_hw_ecc_read_batch_dma(struct nand_chip *nand, nfc->regs + NFC_REG_CMD); ret = sunxi_nfc_wait_events(nfc, wait, false, 0); - if (ret) - sunxi_nfc_dma_op_abort(nfc); + if (ret) { + int abort_ret = sunxi_nfc_dma_op_abort(nfc); + + if (abort_ret) { + sunxi_nfc_dma_op_cleanup(nfc, DMA_FROM_DEVICE, &sg); + return abort_ret; + } + } 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 nand_chip *nand, u8 *buf, return ret; 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 = corrected; mtd->ecc_stats.failed = failed; return ret; @@ -1648,6 +1695,7 @@ static int sunxi_nfc_hw_ecc_read_page(struct nand_chip *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 = to_sunxi_nfc(nand->controller); int ret; ret = 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, ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, oob_required, page, 0, nand->ecc.steps); - if (ret >= 0) + if (ret >= 0 || nfc->recovery_failed) return ret; /* Fallback to PIO mode */ @@ -1677,6 +1725,7 @@ static int sunxi_nfc_hw_ecc_read_subpage_dma(struct nand_chip *nand, u32 data_offs, u32 readlen, u8 *buf, int page) { + struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); int first_step = data_offs / nand->ecc.size; int end_step = 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 nand_chip *nand, return ret; ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, false, page, first_step, end_step); - if (ret >= 0) + if (ret >= 0 || nfc->recovery_failed) return ret; /* Fallback to PIO mode */ @@ -1828,9 +1877,10 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct nand_chip *nand, else ret = nand_prog_page_begin_op(nand, page, 0, NULL, 0); if (ret) { - sunxi_nfc_dma_op_abort(nfc); + int abort_ret = sunxi_nfc_dma_op_abort(nfc); + sunxi_nfc_dma_op_cleanup(nfc, DMA_TO_DEVICE, &sg); - return ret; + return abort_ret ?: ret; } /* 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 nand_chip *nand, nfc->regs + NFC_REG_CMD); ret = sunxi_nfc_wait_events(nfc, wait, false, 0); - if (ret) - sunxi_nfc_dma_op_abort(nfc); + if (ret) { + int abort_ret = sunxi_nfc_dma_op_abort(nfc); + + if (abort_ret) { + sunxi_nfc_dma_op_cleanup(nfc, DMA_TO_DEVICE, &sg); + return abort_ret; + } + } sunxi_nfc_randomizer_disable(nand); sunxi_nfc_hw_ecc_disable(nand); @@ -2794,11 +2850,18 @@ static int sunxi_nfc_probe(struct platform_device *pdev) } } - nfc->reset = devm_reset_control_get_optional_exclusive(dev, "ahb"); + if (nfc->caps->needs_bus_reset) + nfc->reset = devm_reset_control_get_exclusive(dev, "ahb"); + else + nfc->reset = 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"); - ret = reset_control_deassert(nfc->reset); + /* Exercise the recovery reset operation before accepting DMA transfers. */ + if (nfc->caps->needs_bus_reset) + ret = reset_control_reset(nfc->reset); + else + ret = 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_caps = { .has_mdma_desc = true, .has_ecc_clk = true, .has_mbus_clk = true, + .needs_bus_reset = true, .reg_io_data = NFC_REG_A23_IO_DATA, .reg_ecc_err_cnt = NFC_REG_H6_ECC_ERR_CNT, .reg_user_data = NFC_REG_H6_USER_DATA, From patchwork Sat Nov 21 01:10:48 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4221 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 003D91C50E2 for ; Sat, 21 Nov 2026 02:13:06 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-27963-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-27963-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id A736267B62 for ; Sat, 21 Nov 2026 01:12:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223495; b=IxwQeVOFP3Px2JInMeQjCjad7XJy1iZUSiouA2oSsFV8QIE3s8Ey2TRZngcssZa/zwJp M0s2I6dKy5nTwArPuKe/HoMoExZ3hGUjXOWXi5MPLYKhlzB+4q/jlke37gXCm4Ec+h67R MAsNt9egpV4BYfl8LveRskvWRxeEFB8aOu1TxYM5PfE78p5P8e6MXPt9bq4dGLPoi2Smr 4QxLroRKXnsI6Yk5Ehz+gL/foy89m4i9v9qznZNf9ArSTJ6esrel5rNn/YCm8nanX9/ZL QBzriwitTZj1GAblqgbqfPEnYKSREWO6/KytcY2fjaqz+tfjdbajt6fdOPgw7SqoD3A== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223495; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=J6dsf3PUVYR2e83j22FZDt4Y383GBQ5T4kYYqbMeWQw=; b=3ziPXHwLSEApUdMXfhXuYMGNj2ynqZanhW0yhQu+JmH273/3vLCW/5d03SHlTRh/MuVq lYujqtN9z1nmlT77Ho2gfkyuvLVo6DYbcVFuFc0DF1qpOXtJ+Z2Za765i1efX73l50il3 DX/xZFVgUKlI5luCh7KJdn/G+wH+ZZW263W7cJbVBoQnNDWy+CxT6bLiLKksscuuT6w+z FWxp+cveSelDkT7bIHk6e8ym7xhiqi+WotYkybNCkWGZbDvecuN23k1yEvH/RP9qumKiW NFkBfi83/Pqo5eFVZBgMXUX4rDYcJlO3Tjq2WutnjHSdk9H/z+6Jr0mcT9uaol4KcSQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="fW/UDt6z"; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03E14606C522; Sat, 21 Nov 2026 01:11:35 +0000 (UTC) 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=fW/UDt6z X-Original-To: linux-sunxi@lists.linux.dev 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=1795223494; b=3FreAElO47mPPWR6ab5Ky+pcv/mQIcXEmdgXk/ELuh3COJWy990gisEJnsr1DOGn02q9 qVcj2GWFCUxbHKhCt92V5H0NUYK9uaY5kubTWsRCyYtxrjrtGr7D5+ZyqbwRy4ZaCIxPZ gc7AIx19ry44oVTJvS5cbiDl/lQVbWaPTVUwKnPxp8mK2UlMFyQkEC1tKnlOW4ASSetoA 1klgXsNin5UFJs+CmdGv6fIXRFg3DpPCzo7HG+nLhKM39srwczzBDvcv9iXBzI+Gy5aIo kh1d9ppMIdM/M9W0EIrIBc1sNCPMGcKgoJsgosXOdZ856o588HMt/pH5w1Co6sJEeYw== 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=QaswfyPNA9ZtkCzuhWEePB3Q6ON815iz2k7cjVydHAgE1IIUVaC0Aq3VfyFDqgUtFL2E XYoqbMYcjqL0YMH3L6jGTU2GlFkARqU5dEFJ6rhfWGC8ItVsd4lMiYu2qEI7QdA+CYKsk +3s5SY0PTx1uI9MMpcjZGQKyrIfWSAkCY9UIoDpnD2Oyd7xEMwqfIIa8BYEt4KzwWltzx l8GftIfR9PISeiZsO66Dab4U8PYD8RHQFv9hrv3vEdH9O08LKx5JCBS9YnDldBRbNc9/E gwMPhqA++jsDGLk544hgwtTHU+7DRek4dy0OVOGlUabcVz4Q0Mj3UwVDohY5h5M+aNg== 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="fW/UDt6z"; 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 DB03A60A6F5B for ; Sat, 21 Nov 2026 01:11:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DB03A60A6F5B 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 Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-57728d859e9so756071b6e.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=lists.linux.dev; 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=fW/UDt6zEp7j4AozyPwSYfCz50b27XmC9T+y+KXJQF2h0y/elkynywzTzAzyAhDWuU eAn3tvgy2AvCNfL5VebDNxnR3jjEKP2skKG+BuqyE+f3qVgXHk9Eox3FFmspee2MoxFk ucdggwdz0q+DYQ0K5MLHmZzJtmGXwBqAUWM5nYNvBe6K3US6xIKUmIcepDz6c7n2E+Rj 7e45KZdbzsJD2UEz6xopYmQgt1CPhKqpyVaH2XzH8EhQPcJNH9/xgVvpOnfgHgY2X1Xx v5eNJNmsf2Ys62963TbzhsEt9THgnKjJEi35Ya192cPsnYCN2IRDrD1pNBg+4MdSr1VY qYsg== 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=tGbWx/dVWuwH8e8nJ4TSuZGOPKy4drqm1gPm3zpDJZSKEua3c3JMFEH++BHHene7uJ +pkL3at7NszENzLL3bX3b4qZOMPIEDR4SOfo9VCt2HSqg8+IjrRgC3k8lK1tg7QIRMiJ VAsA8YEIB/fCzn0B+Lf8echwSCbV+VlUApdJYf0G9phBW04WNQh2lktteykT/b5Wmuj/ GnISL4bLkAt6YzuOX35jwpl8xSkfoXCj5bNmiABn/yVy+2B2N2L18lSKYNFT72Hr6oEc Bu5n0NZmS3wfSpTzWr0fh1e9FKgTCNiNaAkXKURDMaS5rs6djDgA2wz/xlcDldr8hqnG Efdw== X-Forwarded-Encrypted: i=1; AL+hErHMcFjJZxYiChnmq0Dv0breofvZp0HkduMWeTaG2xm7hvr0ioGMhZr/H9t/QA98gDDF0YS+0okO1GPfdw==@lists.linux.dev X-Gm-Message-State: APuU4Z9BOZwNZvigIMWKjzFcExKzmvPpl8Mf6KvEMNT6voNYPLxIpVfm jD3bb9A5TFgovGeJr04/5AKlkhGVZFWFzgLh1EhX7tNpDoxnKOSON0dI X-Gm-Gg: AYBFou39/O2uDScjW/L9E71V9HlExuUPwqx4OCFS6fsYZgFc59hW5hhu+eykyd7fOJ/ uo7z6DXyi8WBcMUqI2gxLV7aV5VNWxxzhQl542XqEkLepA/lM5ymtWs2lWC6tSXdECemGRpDVoG AwnTGdRM99fDYc48O0JEMggHAnQfXa8FI3JqAmhDPoQmeHGV3E5rnvvy6+wDO8K7bGwM36IQBgF byFD7ib3bmFs/7E4ZNhgb2xxTBa49wafeQCaNs3C81aguEBTIEkrGJ2lEChru0ezVr5JSVLfiPK PILQNuPT3uJpWCgEfwC+HMZr1iCTMpaaQa3D4L7s7T8LbFMLEXShgqd5dOCPGmSFRBH+uVijU6m rU9s4f7g3iDFVLcd4yk/AhUu7ZkG4BAfGJSMopA5M9BVVD5ltIMQRyG2xytGU9y+cqP2FE9xMDj sxzvJm3ayyeTjI3bYLBhoYKv9v2tFQVsLU3Z84k6vRR6MgIyPojvPFL97oHpX8Km1zCkHtY9q0h BXGT1uaaKJt5VKAx5QOK5fS42VdTRM1i+QDUxdn3qChTinGtthukmV5dxh0mlsxvpVm/dKqM5oe 1qB/AUF3PsNWGcsTDWpD4OQ00D4ohHkLPR9m1FwGDhukwj2a1X2KZRV6J5MwRZPqHAuaCCiLFk5 nSqZpWCxD0hfZSfbEA/+/wNkCDDTXP+S2L1rVGir7V0Zdrp6EN4UpLQ52jc4Eh3G0p5gJVG8Jci QrLt/ys3mKdd22w667T1sB2VMVo6uJ8uURkIGZMFFCiyVvohpxjS+ExwFBiHAg5YR633k7XCglR Q== 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [4.31 / 15.00]; RBL_SENDERSCORE(2.00)[172.105.105.114:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; RCVD_COUNT_FIVE(0.00)[6]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; TAGGED_RCPT(0.00)[dt]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; FORGED_SENDER_MAILLIST(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27963-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,209.85.167.174:received,174.29.1.49:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 003D91C50E2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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; }; -static unsigned int sunxi_nfc_hw_ecc_read_count(struct nand_chip *nand, int 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 = to_sunxi_nfc(nand->controller); + + snapshot->pattern_id = 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 = to_sunxi_nfc(nand->controller); + u32 pattern_found; + + pattern_found = readl(nfc->regs + nfc->caps->reg_pat_found); + snapshot->pattern_found = field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); + if (nfc->caps->reg_pat_found == NFC_REG_ECC_ST) + snapshot->status = pattern_found; + else + snapshot->status = readl(nfc->regs + NFC_REG_ECC_ST); + /* A new operation, including every PIO step, invalidates the count word. */ + snapshot->count_reg = ~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 = to_sunxi_nfc(nand->controller); - u32 count = readl(nfc->regs + NFC_REG_ECC_ERR_CNT(nfc, slot)); + u32 reg = NFC_REG_ECC_ERR_CNT(nfc, slot); - return NFC_ECC_ERR_CNT(slot, count); + /* Four consecutive DMA steps share one error-counter register. */ + if (snapshot->count_reg != reg) { + snapshot->count = readl(nfc->regs + reg); + snapshot->count_reg = reg; + } + + return NFC_ECC_ERR_CNT(slot, snapshot->count); } /* @@ -1275,7 +1319,7 @@ static int sunxi_nfc_hw_ecc_read_extra_oob(struct nand_chip *nand, /* Interpret one PIO step or a completed DMA batch before reusing its status. */ 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 = to_sunxi_nand(nand); @@ -1286,6 +1330,9 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand, unsigned int reg_index = 0, user_data_sz; int slot, ret; + if (snapshot->pattern_found & ~snapshot->status) + sunxi_nfc_hw_ecc_read_pattern_id(nand, snapshot); + for (slot = 0; slot < nsteps; slot++, reg_index += user_data_sz / 4) { int step = first_step + slot; int oob_off = sunxi_get_oob_offset(sunxi_nand, ecc, step); @@ -1297,16 +1344,15 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand, if (step < read->first_req_step) continue; - 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; } - if (pattern_found & BIT(slot)) { - u32 pattern_id = readl(nfc->regs + NFC_REG_PAT_ID(nfc)); - u8 pattern = pattern_id & BIT(slot) ? 0xff : 0; + if (snapshot->pattern_found & BIT(slot)) { + u8 pattern = snapshot->pattern_id & BIT(slot) ? 0xff : 0; 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; } - bitflips = sunxi_nfc_hw_ecc_read_count(nand, slot); + bitflips = sunxi_nfc_hw_ecc_read_count(nand, snapshot, slot); 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_chip *nand, sunxi_nfc_hw_ecc_update_stats(nand, &read->max_bitflips, bitflips); } - if (!(status & NFC_ECC_ERR_MSK(nfc))) + if (!(snapshot->status & NFC_ECC_ERR_MSK(nfc))) return 0; /* Finish consuming the batch's corrected OOB before raw error rereads. */ for (slot = 0; slot < nsteps; slot++) { int step = first_step + slot; - if (step < read->first_req_step || !(status & NFC_ECC_ERR(slot))) + if (step < read->first_req_step || !(snapshot->status & NFC_ECC_ERR(slot))) continue; ret = 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 = sunxi_nfc_user_data_sz(sunxi_nand, step); struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); struct nand_ecc_ctrl *ecc = &nand->ecc; + struct sunxi_nfc_ecc_snapshot snapshot; int data_off = step * ecc->size; int oob_off = nand_to_mtd(nand)->writesize + sunxi_get_oob_offset(sunxi_nand, ecc, step); int page = read->page; - u32 pattern_found; int ret; if (*cur_off != data_off) { @@ -1441,12 +1487,9 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_chip *nand, *cur_off = oob_off + ecc->bytes + user_data_sz; - pattern_found = readl(nfc->regs + nfc->caps->reg_pat_found); - pattern_found = field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); + sunxi_nfc_hw_ecc_read_status(nand, &snapshot); - 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); } 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 nand_chip *nand, struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); struct mtd_info *mtd = nand_to_mtd(nand); struct nand_ecc_ctrl *ecc = &nand->ecc; + struct sunxi_nfc_ecc_snapshot snapshot; struct scatterlist sg; int page = read->page; int ret, i; - u32 status, pattern_found, wait; + u32 wait; if (first_step) { ret = sunxi_nfc_read_column(nand, page, first_step * ecc->size, @@ -1522,12 +1566,9 @@ static int sunxi_nfc_hw_ecc_read_batch_dma(struct nand_chip *nand, if (ret) return ret; - status = readl(nfc->regs + NFC_REG_ECC_ST); - pattern_found = readl(nfc->regs + nfc->caps->reg_pat_found); - pattern_found = field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); + sunxi_nfc_hw_ecc_read_status(nand, &snapshot); - 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, nchunks); } static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *buf, From patchwork Sat Nov 21 01:10:49 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4222 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 1A9581C5D65 for ; Sat, 21 Nov 2026 02:13:09 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-27965-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-27965-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 2167B801C5 for ; Sat, 21 Nov 2026 01:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795223500; b=wsD2djohCkMGbeTZfIrlS4ouSLWHJ+IJLTx7CaWJV55tWS5qAhq70X1JQvesrTDbuY0z Z7MYg8V5hLdgD8BCRmuikgNoqAMWyMdXf5isN756JyVQzWRlS8PIiGpRgkyoNL4fcRRhg 6o9hm9gbMYdP6JCUjqvJE8sRyBEwAVVx6Zt/1fbg4wT71xMech5JAKRPi17trbi2ujrL0 MeBgRaB1fislp4XWdAO2nf0nehVKGE99Lb1dDwCsYkkgp8MeytqZRW4t/PZq3VZwxson+ /jOCYdWaovfEu4V+ea/KWauTjro6Bob4pjfDA4rMvD4xGBCXxpcnUYyJP0k16PQH4fA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223500; h=X-Original-To:Received: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:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=3n0HsVfrCilvrywczliXObPQ3Hlxg0mpvZCNssFAoKg=; b=jgFD79ZU0AESN1DxNj3/sUTzPY38peXlUnMhPX5KcT5kLcdQDd1bbjfNFN3bZirIB62u Ch1MFMC7k334XfHtdl6FjEYZjVhP/GNfeu96/D4a+lRbymtWUyHGKhBimWLNxozxmThHz zpyPRH9LajPQhZLZ9lU/gH9jEC0w4Jjzf00cvcox+TEgZ81ebtp39cvjnEv7oOwuwBHBu e3xl8ZSwpEM4+qYUEA+6lzC9c8deS0FfOaG6QbRpmFY+b1wFyhSud1mzMb4S90PrTkDDX FxB8OTkTVyYOCW0VwbCmVpBBrME6lHfgI0Ug35yyYaYuRI1WVNDWpGwC9/DG73gNeLw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="c/6qSJIa"; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2CE2460A2609; Sat, 21 Nov 2026 01:11:40 +0000 (UTC) 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=c/6qSJIa X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795223500; b=3GgtI9NzfsFNr4GHqSN3CKZszKKU0XVKdlCdNBwC2xReJim6YMY3C9F6cge4nErWfeOI eFQCQo9T4G+ZH4Xi3OEdfvxs2tCT8vn8zqpsVFt3I712hcAz4i/U7eXjIB/zQzlPIMizr KUVUyt6pRwe+GdAZ9Yj1jS/N49KDEJAOP32r4aVunRHa5uJFwdiZD6Lm+NAWEgpckI4Cr /BXdAmfaUO/ZQK2rkIClUYMA7aZzmJPmXlMu0vgHZUTxCRWXknBWkjPlzbmIVM8Pga8R0 83gxqhetKc3vGMXQ6C/tdVMEpJ1fSvzVRSGHWmJcLmL5TVjwuXHlxE09y5FjM6s96rQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795223500; 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=DoksfQhQKCWIjtIdkZHCwkskS9L7IcSpf8jPdoRi0+NtoAVrzdZGdrijaXJbtBIPESq/ XTMj8ouLSVioBDsqp/i10glizhDNtupK30LnCMvvrzVwL+4QqB9nW0Nvk0x3I8MBmo0lD JWW8y0d/gT+RH9x63TuxoscFHq8vcD5NL2FgonBm0HRoCju+fOwBz2eR0tFpcUSh1AicH HwUFAIm9mToYa3z5Nq8IORyuOkLQ64rSUylyiSxuAj5lVZUewOgrDldltRbk4UZVctgUM UaushQNWyxo6bP1SQIqTEdhNy8MXPQOtfwDNXLodB8fFoZUhbCIY2+2UdFgIdTOIANg== 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="c/6qSJIa"; arc=none smtp.remote-ip=209.85.167.170 Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) (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 81212606C518 for ; Sat, 21 Nov 2026 01:11:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 81212606C518 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 Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-57728d859e9so756084b6e.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=lists.linux.dev; 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=c/6qSJIaA1m3ElVZwZ1AP7RuG5lHj/3VH+jeSCq3iEzpVZ3D0fEO3/28iBpkWXlGKo 8aVeaH6SHj/XN3kZ8mXrg9L5bh1sPjMQnxAEcpXEd7OYXM5vrUz0TcKsJc599NCvjCrd Un/ZT9o0eqj/CVZq+Z1UgWKzd+5KAF+3Cr5AUxqH7ccjyOB/sITF1gRjiX8lY15abXYn 0dunSI6oCdU2mSVT+IlQZn+14GX3FGKqfvVSsHs42nxtlNFA8AgFjhCe0uK0VufZ3VaZ WqV6jT/r8HBNo1IXibGp9+SEMfJKSJa5zP7sehzlQiTbICSjJq9EmK6D1zIUiVVAiEhQ jI5w== 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=YCXfL+nOE3RmM+TCrq45vwKZt+WHVhF7HeHGgit1n5+ckGq6Js2iW11+kwY5WncucC hJFKRQY++FjndDt//B07m50J/MyFSwUz1FGdVJ81qp2RJFSFcZXM6j/8odqsugXgnfjd yItf/1nwfDa2p9/8pHPKGUPCqnbHm/sl9bUeeXFKMOQoujDWV4rDa6vRYht+3AZOoGI/ 6fUd/grXlVIA866BUpmSDMb12HlAXUCwykB2XWPo9GAi70YOZ0FZMIR3XFwDqyhkW+uy ra8+bKlIbMZ4SRSEKDDc30KHQmAWKGdzs2IJiLJIxF0m9iW7a00TAPNkWSU5UhaiTUVT gWVQ== X-Forwarded-Encrypted: i=1; AL+hErEAKJ3ILE3SYdHlYh0iRsk7GWQv1XDGMitfXXR9eaDxgBaewHAk3sZA8gagLoYcwASxu4QuBEm8YasCZQ==@lists.linux.dev X-Gm-Message-State: APuU4Z8DOIZChNpZ0KXtfzraaV3hy5zJkfzcRzJNUcQUC5dqZlawCph4 uXHCqHPkhiO742mV3xegHdbPWGaCZGt+phfiL5ykHBAXWFpO9EEmhaTD X-Gm-Gg: AYBFou1zpSwFKEXBCF0SENoVvO/jlZ9mVC3QbCDqETBpRZowj9km2raIZLmYYXZ4ZPe fIyrmK0RcKNTCMTdzezBgCOM8N4F5wMoTkZT40y+lZs72NUFH1ANUNGMf0k5ehnogh1UP63kmUF hFWI2ifCAVX7QQUZDCdehBVuTsfPMnhJnTHLuZ5omK9RzQdvVTJrlFtz3F/lzewvMFFDQ6zxyar LFGglp75fHp3aDXz0ban1OAHSwQxWB/2VCAP+F3fK6+2PzvDxtPqF2ewUAWzLble7T86g9zta6t gyzJ0LgqmxCNe1qLadWa2kxM4fWKMP3O6zFmFDUdIG6l6l0fPDMd+nnjwUslGztT42OwHY8yfrK IA2VO7sktOz38WFYLe7CKMBsSp/SP8MLg7L3y7izVvTSKAyeGDO1P/2D/dp5W1beFWD5YZlQj04 MGjX22WvPJxiw1GbOT7L5leLSSek6u+v1zQ4Pk/CL2abD29ri+ZIPAozt2VIAyz3kIa8R7tD3wS VzsMSO6hX12XjQwg17X9glaswmm0x1oI/tRUqft3fwtaJ35IBNG2V4unT3zb0XimsUJUBcndNgs se2+4+/OVomuPKVG4hTk6bP9F5FI9qL1SMxfaAOw8pRgTTxc4iMSPUoaVTBNyg14sQ77cBeNsYb UhdXbCkuXp+6LwImgigr64DCA+9XNQ+qC8hlwPgl5vS1fq41Y23FQAsN2594K5ZFpaXd1Hr6Idf I04kNeHZB6EiISttcU0Ms7OWvP6cy9Ncm2b4/cdBIuZexAd9AsT+j2 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-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [4.31 / 15.00]; RBL_SENDERSCORE(2.00)[172.105.105.114:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; TAGGED_RCPT(0.00)[dt]; FROM_HAS_DN(0.00)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; FORGED_SENDER_MAILLIST(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27965-noreply=patchwork.local]; FREEMAIL_FROM(0.00)[gmail.com]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,174.29.1.49:received,209.85.167.170:received]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; FREEMAIL_TO(0.00)[bootlin.com,nod.at,ti.com,linutronix.de,kernel.org,goodmis.org,pengutronix.de,gmail.com]; MIME_TRACE(0.00)[0:+]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from] X-Rspamd-Queue-Id: 1A9581C5D65 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX 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(struct nand_chip *nand, u8 *oob, sunxi_nfc_randomize_bbm(nand, page, oob); } -/* - * 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 = NFC_REG_USER_DATA_LEN_CAPACITY; @@ -1073,7 +1070,7 @@ static void sunxi_nfc_reset_user_data_len(struct sunxi_nfc *nfc) if (!nfc->caps->reg_user_data_len) return; - for (int i = 0; i < nfc->caps->max_ecc_steps; i += loop_step) + for (int i = loop_step; i < nfc->caps->max_ecc_steps; i += loop_step) writel(0, nfc->regs + NFC_REG_USER_DATA_LEN(nfc, i)); } @@ -1088,10 +1085,8 @@ static int sunxi_nfc_user_data_len_code(struct sunxi_nfc *nfc, int len) return len / USER_DATA_SZ; } -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; /* not all SoCs have this register */ @@ -1102,11 +1097,35 @@ static void sunxi_nfc_set_user_data_len(struct sunxi_nfc *nfc, if (code < 0) return; - val = 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 = to_sunxi_nand(nand); + struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); + int first, step, len, code; + u32 val; + + if (!nfc->caps->reg_user_data_len) + return; - val &= ~NFC_USER_DATA_LEN_MSK(step); - val |= 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 = 0; first < nfc->caps->max_ecc_steps; + first += NFC_REG_USER_DATA_LEN_CAPACITY) { + val = 0; + for (step = first; step < nchunks && + step < first + NFC_REG_USER_DATA_LEN_CAPACITY; step++) { + len = sunxi_nfc_user_data_sz(sunxi_nand, first_step + step); + code = sunxi_nfc_user_data_len_code(nfc, len); + if (code >= 0) + val |= field_prep(NFC_USER_DATA_LEN_MSK(step), code); + } + writel(val, nfc->regs + NFC_REG_USER_DATA_LEN(nfc, first)); + } } 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_chip *nand, if (ret) return ret; - 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 nand_chip *nand, struct sunxi_nfc_ecc_snapshot snapshot; struct scatterlist sg; int page = read->page; - int ret, i; + int ret; u32 wait; if (first_step) { @@ -1524,10 +1543,7 @@ static int sunxi_nfc_hw_ecc_read_batch_dma(struct nand_chip *nand, return ret; sunxi_nfc_hw_ecc_enable(nand); - sunxi_nfc_reset_user_data_len(nfc); - for (i = 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_chip *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_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); @@ -1900,7 +1916,7 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct nand_chip *nand, goto pio_fallback; } - sunxi_nfc_reset_user_data_len(nfc); + sunxi_nfc_set_user_data_len_dma(nand, first_step, batch_steps); for (i = first_step; i < first_step + batch_steps; i++) { unsigned int user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, i); int oob_off = sunxi_get_oob_offset(sunxi_nand, ecc, i); @@ -1908,7 +1924,6 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct nand_chip *nand, 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 += user_data_sz / 4; }