From patchwork Thu Nov 5 18:55:17 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 3887 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 F04E51C241D for ; Thu, 5 Nov 2026 19:59:18 +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-27260-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-27260-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 6C3A92FACE for ; Thu, 5 Nov 2026 18:55: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=1793904933; b=RuJAQjL1xowFQP7FnsELxkzZRUeFbyjb3Z8uIGUY71o11KguX1RgvOzoBWaSjY/rOIL3 0DmpmUZIQxNKUW06a9ui+kSZycXogtU0vswISPOO0Z7cRvJt6U6h1eH7CrjNWc5dNmuyc K/6LQ/5CCZNC3t002Dt8LyCnoeia4F7C7UG3WNkN6FO0tT+y+UNoVxYRfOe3yMoDHM3oL i7wvg5NB3So7DUgGTPCEEgtko/hm/TXWUnb4SvHcGvYXgLNZByDEju03HMkg2rRi/6sqN 1Q2x2wtfO5hwTRTTv3VbU6hMci/JE4wiDlT4AHyUEBpGlpoirBsOVDZhp0z4nzpUcUA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904933; 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=8FLK5L4m7kGeWnbYjP4uSPNLUtTL4HW4u70VBTQSqv4=; b=wT0Jl527N7rZnTi1LwNfW7TNwvzI1dIABt0ozykCtD3DruOLyoi9/aH00OsGwF7vJ1oX Evi+MbLQr762yp/2GwDxdxvDeJFw+hFV8vHk8L3287lbqlEaFKlSAm/HAPf0CxG3VJHBJ KYKJvqsiA3FBRQeC6fonVVLvw2zgK8awaFC3gbvrCDZUnskQnE8hSrU3Gtuy0osQsk/Yv ITB3rzm/RzWE+DV0P9WtRCOnxzQtTjh/McENf+jC3MsFuMXVadm04hu0bDWgNbrXcx3EV DcN4qQpVPn3p9/P9nBxkEPnZlB9YivmQjejLaRgokpVptdx2pi+EfTHk0MUx5cgiEiw== 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=DGxTOrXN; 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 440A4606A330; Thu, 5 Nov 2026 18:55:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=DGxTOrXN X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904933; b=yBFxZlyJGyi9A45Hmjmpq+ZgLCgbjnLlT+ISouUmrxESlZLQiMXvuABLURU8VPoRBwtK 0eKYsdO15iKqz4ffnPuFCpQjCkrod48axwl8XshPdSXR+jUiqDdIzFsKfalkicaaaAk2a ZN2JnwggH6oABYFLU7Dugdr+P1zEXX58N9rEg6/3fGVlCCOE/GUMEOxQeE9bXQ5robjT2 W0djjBvbiI5ZhDNZt+NXKy2tgxZRnjTjWsg9EZIs/UuhtbewRc9/lv90iU/5ZbGPC1lik ZRUEhRvT4ZQO/RUkAZWwJ15A95b21FIZw9G3QW+jP4qX3uYkgo2mLAJxnPBykx1irQg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904933; 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=8FLK5L4m7kGeWnbYjP4uSPNLUtTL4HW4u70VBTQSqv4=; b=ETc9KRzAbCDlc596pFQbUY5zdmqzmjvrpL/tTFkeVnCTUymNI41zPQUwIkJiEyUWqCFt zXJyIpW0G0JIlc8n3EDGK1Bifj2zuDCtNA+kNRy7zm6hEhCELdzy7mLFyaG4Nl0Ak1+f3 w18W+Q0FpEQnp0WKvl+PsLrlL5xrFueivQMZnLkPPIJtxp4GrGJPy6vWhf/o4vGM23v4N Jwsqk+EEvBfQQaKVYZ7AFKHAKCRkQovdNq72vare16lX2bAFmxqJsXHsiy9E2/1y8MpbJ STdFqlUSGNha2108Tgem/DvJ6RS47wmENxWV5xLdr07jCkY0CN8MtePgMsHYzOqPoqQ== 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=DGxTOrXN; arc=none smtp.remote-ip=209.85.161.49 Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.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 D779F606A337 for ; Thu, 5 Nov 2026 18:55:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D779F606A337 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-oo1-f49.google.com with SMTP id 006d021491bc7-6d68de53053so1244651eaf.0 for ; Thu, 05 Nov 2026 10:55:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904931; x=1794509731; 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=8FLK5L4m7kGeWnbYjP4uSPNLUtTL4HW4u70VBTQSqv4=; b=DGxTOrXN7pZdFYl8BLXHwfvtI9IFbhiemu3hPK6CoM1yVsTl0npJ7QMr5rpPgIS+uN K/ZVJFDfELBH/FKLwO2LYoXJPZvUR6oQy2PUI3RZMrL3FH+stE6MSvVCFMFvTTt2B8Kv ideA9uYUM7qfVGwEHYn45spM8+OmcEe56AuVSDFU7nAidp/Mr5oa0qrpmzbVjbVCtdOe OxhmhnmtrWcwq08E43qRyYxVeUKIU9tLLEm8ie/z4dz8QnMkeOE2q5rNoaGg6jn61Qy7 +aAMWtsxXbPqZ5/C4a/+CijkdUN8BtcECOQk4zKQRyC6Z7PUTEejGOBttqAw984FPl66 qcSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904931; x=1794509731; 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=8FLK5L4m7kGeWnbYjP4uSPNLUtTL4HW4u70VBTQSqv4=; b=e0pyu8GK0AQS2QCBghN9cJQEezKWLze0Lxh+qStTNJb2aQoGDYXMPYz7FMIbQsFTBn voo78iyJ4oIoqDHAuFe7pu4EBy6dFU1BIDgodz+V74bj3dCLofuE4O8gcOekejbAigZO GIqMR2JS3N7rTzOWOX1BuCfEoKMUX9RR1r2dKBuUCWnqIFTQMveL+PkMo3397BbSuAFh kdYxjfiphMMt0P1K0kRCvMLOcmro8qQQcFTGPkvCeTgokTPnZbrHhBP3kvb9YK+chzc1 bk1lfDTIvDV6hheMY/v1CU050ITV6cy3MMD2DcXKfAuJDZiB6oAEDQE45FbuyyUw6NhL 4U9g== X-Forwarded-Encrypted: i=1; AKwUvBxwOR1ffXVjffDRJ68KzO5hQ+mDSsviJfqBdMRsPNFmH0M2PqyJMO0h4XFwLMaDGLKtpkn7ZoUKZeG6Eg==@lists.linux.dev X-Gm-Message-State: APuU4Z+YwJ4u6mfTK5krwGOGxQ1B0A6r7vKhxME6F98UEai8Ywak9u8w TS9vPjmPt+tBoYDtzVuFtQ+d9tMGeJAzx0MBuLMOPLxi+13ca0optTm6 X-Gm-Gg: AYBFou1ElfMNWOg3fVEcCsh39sNHK3ytGyiPTMFl57LC/sRN2Bndd0tFYOuC1emhV0y vSBrbQ+2Uo7mG3mkSKoShs4EoHevvr2F5iQXh85t1bxPnBPvfG+mPVmQspNauRjtJ4qNqrSwlwi 83eHa6FNX50fMAoGjN8tWBXVtgIZtjRU+WC/AYYw69ZEYs05hhlLn6WdEhbH8CmB+gsipqZBY8K JkSt3h3pc+KtvMJWR1oNKovkCiMvjWBhBRvXowJVK8mzMfoVtQq3rbTueTRs2BUF3ZxcMxlPVMZ xirDb3OZUpSU5J+uKomRsZ+tH223KMt8DbMEeboqckMyzb0W6kKJbUSJSu27/e13aZx0bHSIEuO n5aW1sJtiCfgJf46B0cfYM69GqlHNrGavPncfZMuOW72PQfSGXu6+PrACBtEdrmLlb85s5hZx6V FMuf/BVkhBw2fSAHShMRGrT/227ZKjX40t5d7eHdJ+rajAJ+CxU00mUXHHI/+G5VGgT3lMLUW/+ Qj3sswkKqwZ9njEPZHfSIgkakgsG1A6iy4doDWe16Bk94k9YXdEwUcANkRu7YYqVQPzktfg8io7 yNLpgUEdfV51036GicSh3igTAprOFBnXnGak4CJXaT2LUsAaX7dAt4LL5uDq0L09Ot9EiT1uoPi B2Svb8G5md5mQ25N/dEAA4eQEQ354CeYcogzChthZqsTP7vSqaO1jYu/WjwBpYvU93PVJJU9kPs JYeibYDLsPhW0Ipai7KviwAEkicwykNZIJIhdH0UtoA1P1H4eI7/D/ X-Received: by 2002:a05:6820:1387:b0:716:c3a0:48db with SMTP id 006d021491bc7-716e78c0135mr318160eaf.25.1793904930446; Thu, 05 Nov 2026 10:55: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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:30 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:17 -0700 Subject: [PATCH v10 01/26] mtd: rawnand: sunxi: centralize OOB handling 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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-1-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; RCPT_COUNT_TWELVE(0.00)[25]; FROM_HAS_DN(0.00)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; TAGGED_RCPT(0.00)[dt]; FORGED_SENDER_MAILLIST(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; 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)[209.85.161.49:received,100.77.114.92: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-27260-noreply=patchwork.local]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; 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: F04E51C241D 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 interpret the same hardware-ECC results, retrieve protected OOB bytes and check unreadable chunks for erased data in separate paths. Keeping that policy in both transfer paths makes fixes easy to apply to one path but miss in the other. Share the processing through per-chip OOB operations selected at attach. A read callback consumes one PIO step or a completed DMA batch. A finish callback handles the OOB tail and returns the largest correction count. Keep primary ECC-transfer sequencing and DMA ownership in the transfer functions. Interpretation callbacks may issue supplementary OOB reads or raw erased-page rereads. Carry the full-page buffer, page, correction count and whether any chunk was erased in a per-read context. Move user-data reservation and layout setup behind the same operations. The existing plain and scrambled-with-plain-BBM modes share geometry and read handling. Only the scrambled mode transforms the first two user bytes to compensate hardware randomization and keep the on-flash marker plain. Preserve fixed and variable user-data allocation, including the older controllers' extra two-byte reservation when maximizing ECC strength. This preserves the existing register accesses, transfer ordering, OOB length selection, error handling and ECC accounting. In particular, retain DMA's two passes: consume corrected OOB before raw erased-page rereads. PIO keeps its current parity representation and physical reread behavior. Spell out the PIO and DMA OOB-read branches so their different parity reads remain visible. OOB-length fixes, read-error handling and register-read caching are separate changes. Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 554 +++++++++++++++++++++----------------- 1 file changed, 303 insertions(+), 251 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index f41feebe4257..80006d1a33d6 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -256,12 +256,38 @@ struct sunxi_nfc_timings { s32 tRHW[SUNXI_NFC_TIMING_STEPS]; }; +struct sunxi_nfc_ecc_read; + +/* OOB geometry and interpretation; callbacks may issue supplementary reads. */ +struct sunxi_nfc_oob_ops { + /* Reserve OOB bytes for nsteps before ecc->steps is initialized. */ + unsigned int (*min_user_data)(struct nand_chip *nand, int nsteps); + /* Install the user-data layout for the selected ECC geometry. */ + int (*init_user_data)(struct nand_chip *nand, int nsteps); + /* Optional symmetric conversion of the on-flash bad-block marker. */ + void (*transform_bbm)(struct nand_chip *nand, int page, u8 *bbm); + /* + * first_step is page-relative; status bits use transfer-local slots. + * PIO uses slot zero even when first_step is nonzero. + * Return zero on success or a negative I/O error. + */ + int (*read_batch)(struct nand_chip *nand, struct sunxi_nfc_ecc_read *read, + u32 status, u32 pattern_found, int first_step, int nsteps); + /* + * Finish remaining OOB; return max bitflips or a negative I/O error. + * cur_off is an absolute NAND column, or NULL if unknown. + */ + int (*finish_read)(struct nand_chip *nand, struct sunxi_nfc_ecc_read *read, + int *cur_off); +}; + /** * struct sunxi_nand_chip - stores NAND chip device related information * * @node: used to store NAND chips into a list * @nand: base NAND chip structure * @ecc: ECC controller structure + * @oob_ops: OOB geometry and ECC-result interpretation * @clk_rate: clk_rate required for this NAND chip * @timing_cfg: TIMING_CFG register value for this NAND chip * @timing_ctl: TIMING_CTL register value for this NAND chip @@ -273,6 +299,7 @@ struct sunxi_nand_chip { struct list_head node; struct nand_chip nand; struct sunxi_nand_hw_ecc ecc; + const struct sunxi_nfc_oob_ops *oob_ops; unsigned long clk_rate; u32 timing_cfg; u32 timing_ctl; @@ -908,6 +935,7 @@ static u8 sunxi_nfc_user_data_sz(struct sunxi_nand_chip *sunxi_nand, int step) return sunxi_nand->user_data_bytes[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) @@ -946,8 +974,8 @@ static void sunxi_nfc_hw_ecc_get_prot_oob_bytes(struct nand_chip *nand, u8 *oob, } /* De-randomize the Bad Block Marker. */ - if (bbm && (nand->options & NAND_NEED_SCRAMBLING)) - sunxi_nfc_randomize_bbm(nand, page, oob); + if (bbm && sunxi_nand->oob_ops->transform_bbm) + sunxi_nand->oob_ops->transform_bbm(nand, page, oob); } /* @@ -1007,9 +1035,9 @@ static void sunxi_nfc_hw_ecc_set_prot_oob_bytes(struct nand_chip *nand, u8 user_data[SUNXI_NFC_MAX_USER_DATA_SZ] = {}; /* Randomize the Bad Block Marker. */ - if (bbm && (nand->options & NAND_NEED_SCRAMBLING)) { + if (bbm && sunxi_nand->oob_ops->transform_bbm) { memcpy(user_data, oob, user_data_sz); - sunxi_nfc_randomize_bbm(nand, page, user_data); + sunxi_nand->oob_ops->transform_bbm(nand, page, user_data); oob = user_data; } @@ -1055,6 +1083,41 @@ static void sunxi_nfc_hw_ecc_update_stats(struct nand_chip *nand, } } +/* Return whether the chunk is erased, and account for its ECC result. */ +static int sunxi_nfc_hw_ecc_read_error(struct nand_chip *nand, + u8 *data, int data_off, + u8 *oob, int oob_off, + unsigned int user_data_sz, + unsigned int *max_bitflips) +{ + struct nand_ecc_ctrl *ecc = &nand->ecc; + unsigned int oob_len = ecc->bytes + user_data_sz; + 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, 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, max_bitflips, ret); + + return ret >= 0; +} + +/* 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) @@ -1094,98 +1157,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.) @@ -1241,18 +1212,166 @@ 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; + int data_off, oob_off; + + if (!(status & NFC_ECC_ERR(i))) + continue; + + data_off = step * ecc->size; + oob_off = sunxi_get_oob_offset(sunxi_nand, ecc, step); + user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, step); + ret = sunxi_nfc_hw_ecc_read_error(nand, read->buf + data_off, data_off, + nand->oob_poi + oob_off, + mtd->writesize + oob_off, user_data_sz, + &read->max_bitflips); + if (ret < 0) + return ret; + if (ret) + read->has_erased_chunk = true; + } + + 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_nand->oob_ops->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); @@ -1299,83 +1418,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_nand->oob_ops->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_nand->oob_ops->finish_read(nand, &read, NULL); } static int sunxi_nfc_hw_ecc_write_chunk(struct nand_chip *nand, @@ -1452,11 +1500,13 @@ static int sunxi_nfc_hw_ecc_read_page(struct nand_chip *nand, uint8_t *buf, { 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; + struct sunxi_nfc_ecc_read read = { + .buf = buf, + .page = page, + .oob_required = oob_required, + }; int ret, i, cur_off = 0; - bool raw_mode = false; sunxi_nfc_select_chip(nand, nand->cur_cs); @@ -1466,28 +1516,15 @@ static int sunxi_nfc_hw_ecc_read_page(struct nand_chip *nand, uint8_t *buf, 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); + ret = sunxi_nfc_hw_ecc_read_chunk(nand, &read, i, &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_nand->oob_ops->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_dma(struct nand_chip *nand, u8 *buf, @@ -1513,11 +1550,12 @@ static int sunxi_nfc_hw_ecc_read_subpage(struct nand_chip *nand, u8 *bufpoi, 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; + struct sunxi_nfc_ecc_read read = { + .buf = bufpoi, + .page = page, + }; int ret, i, cur_off = 0; - unsigned int max_bitflips = 0; sunxi_nfc_select_chip(nand, nand->cur_cs); @@ -1528,23 +1566,15 @@ static int sunxi_nfc_hw_ecc_read_subpage(struct nand_chip *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); + ret = sunxi_nfc_hw_ecc_read_chunk(nand, &read, i, &cur_off); if (ret < 0) return ret; } + ret = read.max_bitflips; sunxi_nfc_hw_ecc_disable(nand); - return max_bitflips; + return ret; } static int sunxi_nfc_hw_ecc_read_subpage_dma(struct nand_chip *nand, @@ -2066,6 +2096,58 @@ static int sunxi_nfc_maximize_user_data(struct nand_chip *nand, uint32_t oobsize return 0; } +static unsigned int sunxi_nfc_oob_min_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); + unsigned int size = 0; + int i; + + /* Variable lengths reserve the first word, which contains the BBM. */ + if (nfc->caps->reg_user_data_len) + return USER_DATA_SZ; + + for (i = 0; i < nsteps; i++) + size += sunxi_nfc_user_data_sz(sunxi_nand, i); + + /* Preserve the older platforms' extra BBM reservation and ECC strength. */ + if (nfc->caps->legacy_max_strength) + size += 2; + + return size; +} + +static int sunxi_nfc_oob_init_user_data(struct nand_chip *nand, int nsteps) +{ + struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); + + if (!nfc->caps->reg_user_data_len) + return 0; + + /* Prioritize ECC strength, then use the remaining space for user data. */ + return sunxi_nfc_maximize_user_data(nand, nand_to_mtd(nand)->oobsize, + nand->ecc.bytes, nsteps); +} + +/* + * Both modes use the same layout and ECC policy. Scrambled transfers also + * compensate the first two user bytes to keep the on-flash BBM unmodified. + */ +static const struct sunxi_nfc_oob_ops sunxi_nfc_plain_oob_ops = { + .min_user_data = sunxi_nfc_oob_min_user_data, + .init_user_data = sunxi_nfc_oob_init_user_data, + .read_batch = sunxi_nfc_oob_read_batch, + .finish_read = sunxi_nfc_oob_finish_read, +}; + +static const struct sunxi_nfc_oob_ops sunxi_nfc_scrambled_plain_bbm_oob_ops = { + .min_user_data = sunxi_nfc_oob_min_user_data, + .init_user_data = sunxi_nfc_oob_init_user_data, + .transform_bbm = sunxi_nfc_randomize_bbm, + .read_batch = sunxi_nfc_oob_read_batch, + .finish_read = sunxi_nfc_oob_finish_read, +}; + static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, struct nand_ecc_ctrl *ecc, struct device_node *np) @@ -2090,33 +2172,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 -= sunxi_nand->oob_ops->min_user_data(nand, nsectors); /* * Once all user data has been subtracted, the rest can be used @@ -2175,20 +2231,12 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, nsectors = mtd->writesize / ecc->size; - /* - * 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 (ret) - return ret; - } + ret = sunxi_nand->oob_ops->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; @@ -2232,6 +2280,7 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, static int sunxi_nand_attach_chip(struct nand_chip *nand) { + struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); const struct nand_ecc_props *requirements = nanddev_get_ecc_requirements(&nand->base); struct nand_ecc_ctrl *ecc = &nand->ecc; @@ -2254,6 +2303,9 @@ static int sunxi_nand_attach_chip(struct nand_chip *nand) if (!ecc->size || !ecc->strength) return -EINVAL; + sunxi_nand->oob_ops = nand->options & NAND_NEED_SCRAMBLING ? + &sunxi_nfc_scrambled_plain_bbm_oob_ops : &sunxi_nfc_plain_oob_ops; + switch (ecc->engine_type) { case NAND_ECC_ENGINE_TYPE_ON_HOST: ret = sunxi_nand_hw_ecc_ctrl_init(nand, ecc, np); From patchwork Thu Nov 5 18:55:18 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 3886 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 27A8A1C5396 for ; Thu, 5 Nov 2026 19:59: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-27261-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-27261-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 8B7F12FBEA for ; Thu, 5 Nov 2026 18:55: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=1793904933; b=cp2FeAqlSVae9dma12NvfvuDN72qrmgI9KNTLldC/cDfBrNlddSfMUVKGxXx+aJdIX1T XT5k6t6VFRvwYj3+jJFwxHg9epL/KvAPS66A5J8NgR4Odvs4+eLc5C74CtOO1A2OyZzku uAjsLv5rFCF5O6UQ6LTbUggHR7KOtvi7K+RUA7YbsTeFxnU+gDZOoZlYPTT2yLrXpghvk AUKlEwHviS9gTG0s7UZBgV6pY+4JW08bgAN4RahWrtfc5CMMLh40L/0r2JI4KC0fXUQ5T kA/uZCmZeOzsOTrjnQUDjr/VaTMj1192S9RuvPCrPQZXgJ2TCa4zAQsdNTMmXwoDmFw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904933; 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=ex3VtA9PGW+lx4Jwo9zXOKsJ7tUqHQi29kWPU0YYtkI=; b=VavKugQiitvQnJoCnOzeiDBRx0zfJqHP2t2KOA+W+9PI/qZRzpyiBe8I7a3sHSFSFh/i BHZLRXLIhYDbA25JuH8vZMO7pmGgYj8co6fARjq+v6FAwOMnwacTkjNsHQbKpk2sLxYHY c+g8d8o2Z11zDY8E9e554b4Q4t161/cg++EFmtzFhdtjvREV6IcK3uEZFiC9iaG1v7jqD 7y2xSZ1b099Y124d1SaOAlBlV0npPTyhnURVLtiHfrBLEMSVui9EmFV04rzREt3lUhBDy nMpoehRsJOOAc859FWbo6Q2Laf3i5YEeRiale/rUZRF5zhJsVJd/5OG1HJ7jO6WuR7Q== 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=xSH96Eqn; 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 62A28606A331; Thu, 5 Nov 2026 18:55:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xSH96Eqn X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904933; b=g4BrXlfjuOaRdAm+1K/+1gzZHDgobmqTis59D5LbNHr9iBhhB08rJ8ZlnHtHNcEHUzZt 6Q3ta5jQWhbW4KngHzVbexeMFlzJ4HcSzL6VkNvQJVtsBC/Ce4I+4HHHdWOboGljrTNDi 5UZDEUAYysRItsj5YtQDA1mUhfCYiQPDrMLDDwwNniPfuan2d+cEc97toWkwTZiUC9Oe1 fUgm9w4ikN3vDgc7upQYPK/KUK4wbmzwYcupQX4FuAcHgUtYDNfLxrZ06PoPFFsbaG9M7 Bg9AwFs4j4QlPM69Tnm3PbxL5KOFz5TwJvLZW8xQi8G7a5c9wbwB93VbC6Jfh8yuIpg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904933; 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=ex3VtA9PGW+lx4Jwo9zXOKsJ7tUqHQi29kWPU0YYtkI=; b=AYwPRm2jdGsNqbzSnKa/wmYVCibT6KxRyyCN/R+ZdbpJKcGcuBE1jKAJF2FpClapnJkj KtXBaS2DcIh7R8iMwnnKu9msjtS9XmBxRV5ZMqyL93/MgnUeNSxvnLt42TfztV9TZ/Mi7 lertuCPjhdJLEHMYRFbhIzJ2HROyit3Y+JX4VXy0yzNJwd76NDTUz0qEmMB5Ls8esvJ2i zL/+Iwb9mhQcnMDDwjdTOMS7AeLHqssVkXbC01rNXzM8fr8Et5K9bb4Gt9/Y9cy5EKwMZ ZiKNvH1YF1KjAGD6quHEHTPD6HpegN7LmJ++eEhleVJkxWit8Na/WET4zloX13sVaiA== 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=xSH96Eqn; arc=none smtp.remote-ip=209.85.161.43 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (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 DDC49606A33C for ; Thu, 5 Nov 2026 18:55:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DDC49606A33C 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-oo1-f43.google.com with SMTP id 006d021491bc7-704597ef1d8so982287eaf.3 for ; Thu, 05 Nov 2026 10:55:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904932; x=1794509732; 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=ex3VtA9PGW+lx4Jwo9zXOKsJ7tUqHQi29kWPU0YYtkI=; b=xSH96EqnUtZq4/OLZtxBnMFDEanWN7BqopfSDQxulxuYUsyx2yGItshFpi6H5MqdHs XVJgwiTU0p6vPwa3gn/RsxEVXV4YqXiFjOY/PNTRMsWUWk5zzcxRCubYeKeVZieStWJ2 TSAzrrf4GoC91CfgC08BxpjakNddXUZ7wJ21Aza1EFvaZ83uCYr/zhPev2jED6HlOVYv g++CER6Rl3t2BX3lFodKrCdXc6cShsIFbe4rOjK/3LCIRHJ8dSJZ/lxrG4gtvzqHBApj 1nKdrt6dIlPJNV1SUvTsENj3d2KhKPvuJ/Jy6cFagycL+gyhE8lJ03bVssvGpboXxcEe tVDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904932; x=1794509732; 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=ex3VtA9PGW+lx4Jwo9zXOKsJ7tUqHQi29kWPU0YYtkI=; b=EjV8ieBBCXLs4Ue8598K4N8LrdsAcfOvxlvu+UtRBQOXKudnJmmJ0gQxH0ysHwP1Yt JUNt5LbmKUirSfNV5fB8RhEn4tqGe7EFdLZi979EEFK++M/K0Kc7+USCS5MhZbh3p+qw YOCdn/ZvTFUutujVPGGP0NXYmxdkfTQA48sm2aBHKBtb4TkzDtXmqI8JG/ewWUBUq2X5 jLtBQN0FO1/FW+4GLictSUM7KGBlTizo/Z5UI2Vvyv1eYs+Pvnl2q6L14IDAN6bv2Gtj OhvfWf+00kiNZXNyozd8Hs9Fjt///BLLRIUsZcOKS65FyrXepyYMRXHDJfMXPa/8K++M +WyQ== X-Forwarded-Encrypted: i=1; AKwUvBy4dOAzTIixAfFgnX2W2mH+e4uOvPLPL8mYzMD9DwG0qZbmr8oUiJKgQYEfmk43Hkn/Uu9ez02BhWApfg==@lists.linux.dev X-Gm-Message-State: APuU4Z9yssApLiKnexL7Zm571aBStfPt+GQXM8RoAnJi/PwMoy819FeF CjPo56Ld4O9QgwXS6uS1fiqbWNOxsbbO72VJHF/fE3mSzcttOyfyzzmW X-Gm-Gg: AYBFou2OViMbxWFeTLJAT4zzMXT9tQ/lLyJ4bQllmpv2WAblHTJoWQnLvn/eh+7zp6r skX00V1D8haja4CJ7wvrQQedR/c+T0wX/KT0dTIer4q9ilCSJjqfiA2Qa4QxRBmEfDwD11IK/RZ l5icH57fGGVIeNeosc/Qk4lAnCE3l1d/FVIHoNprZQKqYf5CnICgTzMs23rwtuzCS8Omy2WxFyF VIYQCjgOR1lLtah6jsOYLU7jZB7N38FFYc0k/sDnmavMvx5ZcRu88Vkj0yOulsmPMtz47A0S31H IDc8PXYgYGtYjR0w7xV/KRTag26Vb29fnfh4Voq3zVqmhB/OgA6D/ylasBKGzxENSvW0mJ3gjQ3 LL2MlAtKXB1MB6Cn8hVxiM918qE2k9p67Zv6WBPxUqVB/6MwOq6a9pD0/2u0yF+z1pnbDw0suXT n2l63XAiwTD1JFUrxKYDby9N3aOoCVjGMhxSs+EFQxT6uTntD+iXw9xSusPacCq9o0wkR2c1sCv IDBaLglhvghxUIeXy7kWrRpqBGw3gm2QazbpMZO54mT5GjrWidDYsOcJ1BHN+GFifTMgZzRX7hV YMRM0LRxXtDqxc1y5i8WxMS5NytJ6ei6Sww5VXyhVhBBk0r/Cxd6a/RhG2TLKYJRp90ah6qlIOa rB2K4WjuEuf8dNXjGyZMZePnWOYMvEh48HuSZHBTsEp1iW+6YWt/0LkHC9OflxFd0PG6A4Q656X JUtZMBpramNrnOGX5byE0d4wk7z5R/iuwq51NAvrPfa8Tv6NbHZVK+WdCJXHgldBn81YQ3AUELI Q== X-Received: by 2002:a05:6820:2484:b0:6dd:bc51:888d with SMTP id 006d021491bc7-716e79f15c7mr263473eaf.87.1793904931737; Thu, 05 Nov 2026 10:55:31 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:31 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:18 -0700 Subject: [PATCH v10 02/26] mtd: rawnand: sunxi: share the buffer transfer chunk size 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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-2-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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)[]; RCVD_COUNT_FIVE(0.00)[6]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; FORGED_RECIPIENTS_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]; TAGGED_RCPT(0.00)[dt]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27261-noreply=patchwork.local]; FREEMAIL_FROM(0.00)[gmail.com]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10]; TO_DN_SOME(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[209.85.161.43:received,100.77.114.92: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:+]; MID_RHS_MATCH_FROM(0.00)[]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; RCVD_TLS_LAST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 27A8A1C5396 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX Use one helper to determine how many bytes a buffer read or write can transfer in a single normal command. Keep the existing SRAM-size limit and command sequencing unchanged. Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index 80006d1a33d6..b75984961699 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -659,6 +659,11 @@ static void sunxi_nfc_select_chip(struct nand_chip *nand, unsigned int cs) writel(ctl, nfc->regs + NFC_REG_CTL); } +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) { struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); @@ -671,7 +676,7 @@ static void sunxi_nfc_read_buf(struct nand_chip *nand, uint8_t *buf, int len) while (len > offs) { bool poll = false; - cnt = min(len - offs, nfc->caps->sram_size); + cnt = sunxi_nfc_buf_chunk_size(nfc, len - offs); ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) @@ -709,7 +714,7 @@ static void sunxi_nfc_write_buf(struct nand_chip *nand, const uint8_t *buf, while (len > offs) { bool poll = false; - cnt = min(len - offs, nfc->caps->sram_size); + cnt = sunxi_nfc_buf_chunk_size(nfc, len - offs); ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) From patchwork Thu Nov 5 18:55:19 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 3903 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 269C31C5396 for ; Thu, 5 Nov 2026 20:40:01 +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-27264-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-27264-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 6EAF62F09A for ; Thu, 5 Nov 2026 18:55: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=1793904940; b=PjJDl9yC2uNmQKSHL1V3gUhS8XShoMXm3fZX6zOn5hXahJPGKnkyNeaammctzt+dkMQs lmWo8eIqbuxHjvtTbWkLonHnbA1xndy6MPsDfmkIrRv3/W99LaHFTXBEwgwyf8DNUHQCH cGeNTf99ZB6Kh1lyS/LRmJyAEBKVpQOs/8gT48dS/kSioToKE4sdz/OwLJqEsMjkgo8nI wdP9asomzdNNEHl1F6KLwBM6VyJbiDJ8Y08dgNnrowEcnIIBg278a8SWqc587BzS/82cd eMbJu+k8d+bR1CKqrDzcO9X53mtOBbNE2yGhdYYu+qEX5V6M0YJz2OMxk0nVoRZpoIA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904940; 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=UPvgTlYh271ksxX8dw0Tb6RYwBWSB/xct0guWKo1nsA=; b=0UmKjcs613Fe+TcqmUkVEv4O3XYUFZAQGpPIlyPn0YjGYtgnlFJH76nRe9k7Z9/LVWr0 DQ3LoSQKePebPme6VsEpS/y6v44SIlHO3hMP6e7PMc8QD9JMgxLxOCRTaKfWY3DbSAp67 I59cZHiOx5oN2zI/Xqgx55oKU+Z7JHVECcKF11WhAYS6ir8AN9y2pAWBtedmxBPw8O2Hy xRFlE78rOBcp2Mcsw/4VvyYA4EmNKp52aw2zAPksRZqHUZy4EkOCd3P3rCDpC28NmY4rd LH6wefeCzoc19/61riEoG9sEAjt2dnQOLhM+GGqnUBHWoEzgsCqXCai5Gt0wY7EDg4A== 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=rjkFtusj; 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 E4812606A336; Thu, 5 Nov 2026 18:55:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rjkFtusj X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904939; b=EimoxS7iPkVxOMIKPChpjZ9Af1wJwfKcdgTvvatypY0Bv7De3BpICgW/sw28VzduTSSw iHFNQFl/3dK+X+G8i3MGlQMBQV1jKvNJaqbfQMuzwl1+3JVXLsnK3VDNCh6YtAghfaR0t Z0jHI8cT1NjmViJgiWxDb2gSk8eHc3DP5g6Np7AQoQKPqwJY1ly5e1PPfb/ZN6pwsiT8R JZTYggEcT43mBxu0jJf69jtKA74Av6PJvFKZS3NZ7pJPsUdOhDjfN5JiwauALWPkGBPQO cA3TR/sxualw5g27HAKq2MRQ7PhgEuuzQFRNpD+gLMfzTJKlTctaF4EGG2M08sXhYOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904939; 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=UPvgTlYh271ksxX8dw0Tb6RYwBWSB/xct0guWKo1nsA=; b=FldMIPR/1uvgOJ7vxGvKAPruKTNDxaIaKUctqqg3YqPGQg3hjUI8p8VlrWlE8f/5Y4I1 bb4a/yYJyWS7uSLI25nE6eQY4sf1cG3+J/SMHLVoU4BJYCBNk6LMdMnWmIZdV0A0a7na9 TgUtkPOFoELBR4Gy00jU5GDuwVd2ONv2LXUmjlMrzrOolUL/U7gvp1N0wl9Q1DInHTTaj 8XvifcIxIiuYQquB9X22kS7Wml325Rah9Mt9KkCISeKRK+W1a8f1XTtHZZdWFdiSylQpU VUR9yfnVQIYPtXhNyI4dD2lsq/j4Ug0ZV0f7zzDavJJgVKgzdPmDCOZzGeHH8eJvN8Q== 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=rjkFtusj; arc=none smtp.remote-ip=209.85.161.52 Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 739F8606D805 for ; Thu, 5 Nov 2026 18:55:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 739F8606D805 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-oo1-f52.google.com with SMTP id 006d021491bc7-70bf1671c21so1459137eaf.1 for ; Thu, 05 Nov 2026 10:55:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904933; x=1794509733; 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=UPvgTlYh271ksxX8dw0Tb6RYwBWSB/xct0guWKo1nsA=; b=rjkFtusjOAHNq/ned4J5LW6Ltz7bAVhWQ2g6+jkXBmNOCqEv7W6P4YKN9CD4jaZ6O+ 5JSqOySdMCoT0IkiINMaNcc/vzgtd8lIdvVzpYOGiV0E+PO3tiYBu2m5fuSRNJ7gKSjD 30dn1MlB97IX5mMPgUc4dYxeDHze9AkGorNyHC9mqlQMYUdeodFpNbx3OTGZf+IIH5H2 cu/uJuctPoLvij1Sfn3TDkIorcQpF5Xp7SjsbeZ3vOUndtYcJXN5FE/kdGydpW+sS/VI D3wmibbHOP77LUnEkHsmrBk841ylCbM4SVGwD46SQtVPwSO42rQwmNTfAZg5Q8ytQ6lM RrvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904933; x=1794509733; 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=UPvgTlYh271ksxX8dw0Tb6RYwBWSB/xct0guWKo1nsA=; b=Tt9nRh0/wf8AdHlXbfyWxiyMDUlBW9pMGwq44XIgEk+mULZanB/HsHm4lfYXd0S/uI JjRDdBuEoH8m0zXvTOPvJgjnElADR0Fs6+fGfyT/P0SUclmTXKhzKQ5SPIt+cfyjJWN/ E0N8baZwqgK13Kmb4QWTM0zwI5nnkn+J7LiB3af5lVeGmGKm8cFxss3Ys89ktqAnymlZ AuPkwsNy6TmGRRZpVwkEPeTS4RWQAGJNF3yfGVmSYX3hfz7gqsXDhAN63epKjG7iXLZh tqVKVgIUvctEVRqMTnnPKYjsdfUcMBGihVTjdFhKbHmAMeZ95XF6CnfM541D3PnCddCn MvFw== X-Forwarded-Encrypted: i=1; AKwUvBy79BTTBROYLRsdsnMX++rwvs25C8Ciw9lRVhwh4GqcLtCQxXMgfwD/8l3Pc7T3XM/t9il2CAFfao1r4A==@lists.linux.dev X-Gm-Message-State: APuU4Z+xjKbSyGcVMca+dezF2F09O8/V2LuZCl3UjiVE3XO5d5FZDc4Q gqDFNqK0zLTt3OOwZWEOVIqtKNQ508+sl3fPpKTlvfvH2H6j+DBeW160 X-Gm-Gg: AYBFou0+HrZ/6H/T5UO7A6U1sKbSfJvuX5a33zVUBmZJ3hfGf7qTWxAQRPkJfJI/BsC sooZYA7UjbV4c4TWjX3Y2rz/bv+cHD0MjZlJAnCWO5FZ3ndTPXqj3rR/CZrJeoaAC7CdtY+KtdR 1+SQD1LzbQpR38fs6/t7NymWGSj96esfdqWCdCPX5kSdEy2I4pRPtYODlLjYatqBzNK3d6kWQGB pZD9b5dEvoaE5jsWlX/XULW+ujlrBmLyYUDwiPkMYADH+HbMmxrSZLeqlbj39nDUAjEXzcsQAhn tt43BYTp0utFSwPcx7L2yvfKQYIrNIxEXysCtGXWw2UYbgauM5rq1ySF4/bykIpEUlruO/JU8vn SeXzgmskuDFBs0Lj7joivq2k7LS96NlMTrLqREHrXgtlS92DWZKSLcdulPNSjORNyTpdTDr/c4u lJFNSXgDJutlp60fKo9iFwIgOgNX1h5xxbfnJraaoQNwJGyAqxRR29iXt3Rzen8iAfTKasAS6k0 aj1TI+KR+Q6PVk9uw5A1BXpoEVtXxGN6j6pPkoWcNR4E0TgU8Qy29GmtXjKxmmbbWvuJTI7Dtj7 6Rz4TXxWvp0TySLcJUU/Nsrf2iAKWhRkTXvtAAxgVPOqrDZ75O/Muejau5a9a6tJu+W0AumNanH HVyPA2W3ZN1AFDlUJ+Afe1v7XvmBHNITpkIE7dlraqVdqPXxChH85bvzbU0IaCIEQxPb+2hIe1M oz3nTPG9EXLyIsHbs+8o4t7sxOIbii+1ldLgTI83E/M1EtwXVcQ3h47Ia237dsEuIOCMzNTdUJ8 Q== X-Received: by 2002:a05:6820:7048:b0:6f8:2346:cd89 with SMTP id 006d021491bc7-716e73a98famr324182eaf.13.1793904933325; Thu, 05 Nov 2026 10:55:33 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:32 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:19 -0700 Subject: [PATCH v10 03/26] mtd: rawnand: sunxi: avoid duplicate chip setup before page commands 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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-3-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX sunxi_nfc_select_chip() programs chip selection, timing and the spare-area base. The page-read callbacks and PIO page/subpage writers call it directly, then immediately call nand_read_page_op() or nand_prog_page_begin_op(). Those helpers dispatch through sunxi_nfc_exec_op(), which performs the same selection before executing the command. No controller access between the two selections needs the first one. Remove the duplicate calls from those callbacks. Keep selection in the DMA writer: it accesses registers and prepares DMA before program-begin, so it cannot rely on the later exec_op() call. This removes redundant setup only; selection still runs for each executed operation, with no new cached state to invalidate after resets or chip switches. Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index b75984961699..662d96fc2535 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1513,8 +1513,6 @@ static int sunxi_nfc_hw_ecc_read_page(struct nand_chip *nand, uint8_t *buf, }; int ret, i, cur_off = 0; - sunxi_nfc_select_chip(nand, nand->cur_cs); - nand_read_page_op(nand, page, 0, NULL, 0); sunxi_nfc_hw_ecc_enable(nand); @@ -1537,8 +1535,6 @@ static int sunxi_nfc_hw_ecc_read_page_dma(struct nand_chip *nand, u8 *buf, { int ret; - sunxi_nfc_select_chip(nand, nand->cur_cs); - nand_read_page_op(nand, page, 0, NULL, 0); ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, oob_required, page, @@ -1562,8 +1558,6 @@ static int sunxi_nfc_hw_ecc_read_subpage(struct nand_chip *nand, }; int ret, i, cur_off = 0; - sunxi_nfc_select_chip(nand, nand->cur_cs); - nand_read_page_op(nand, page, 0, NULL, 0); sunxi_nfc_hw_ecc_enable(nand); @@ -1589,8 +1583,6 @@ 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; - sunxi_nfc_select_chip(nand, nand->cur_cs); - nand_read_page_op(nand, page, 0, NULL, 0); ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, false, page, nchunks); @@ -1612,8 +1604,6 @@ 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; - sunxi_nfc_select_chip(nand, nand->cur_cs); - nand_prog_page_begin_op(nand, page, 0, NULL, 0); sunxi_nfc_hw_ecc_enable(nand); @@ -1652,8 +1642,6 @@ 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; - sunxi_nfc_select_chip(nand, nand->cur_cs); - nand_prog_page_begin_op(nand, page, 0, NULL, 0); sunxi_nfc_hw_ecc_enable(nand); From patchwork Thu Nov 5 18:55:20 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 3879 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 CE7191C53B3 for ; Thu, 5 Nov 2026 19:55:44 +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-27262-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-27262-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 96C6E27A01 for ; Thu, 5 Nov 2026 18:55: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=1793904937; b=zwhBnq0GI3+/iTGH9/STzuzE7Xy5zuK/3PmBOjlScCZ66lX4KHznvjjU6NZFJSvBFNq+ Y0KmGBkUNnj5PcBtXyO+vtv2keGoWkqJQtsujX8P7qS/puIcO6UJOHAiH8paE/vp5bc8M TKO2aJPGRYnnxG/wrw+CTRZsyc989pOYZ4JHtriRQwH8UhSX6E3gdAPQ4QGo0nIGXVZlX Oad2tkDZwzJ+q0vcmIT58Moh3Viq9EUO8yT/iz7o8HGdOTE7E702pG5DuXFTpb/aOrvnn 81QNTjOMTUOBpryRUEoH8WtKF39+MiL9e9iiu4AXqAW1CNl+NG+ThhWH7R6L2Eeo2dg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904937; 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=3diKjpt3Hplj9bun3k4VWxlSuPRXvr0bzFEfcX1wVKA=; b=sN0NGORXrXLiLxnuqEvIKYDwYXdNbem+ADL0Glly/nd4ETz9SwMdXmRKDLi7v9Ae/Mtw k84hTN8XqHGkYFWpP1XWsvf8BlNZWXIcEzKBQ51KLW56FQW8iXouebHc/vHcdlh0HBtnS 6U7fWcsKcVH4n7i1DPF9B6TkzKaFmmHQN+rK2g1QO1bZ+gOwSn2+0OrLpaBZVQXboOjKZ yeCIPKhw/7+GCLKjSRWdXaeP3hOkHiZkHrVo4fsh0d62K2Bn0jVlUb6ySC329tiiA/Ur8 p1Wnp83iZaU6EMjJSvJt9Kl2RqUEaZkvnjK1uiUd7r+mt+GMJtfrxC47keZfr13M3DQ== 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=tCrfKKod; 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 40F5C606A33E; Thu, 5 Nov 2026 18:55:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=tCrfKKod X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904937; b=mkWBnhkdCwvBLpPsFeLZbusYqxxB2xvH0IRXQIcGH6/9N2AZq4iL0bP9o5xZdJ8qM9wA QosPtkktpbfS1QWVZr7AoSDxHBj5GEy++o1Ue6OtjOSG9FgxjCB9xqwfZ9H9lPZNDvSsr Bk5n/redM+Gxt0aJ8AVMSkjJ0Z/ccomf3Q11zWtmPHmTXOsgB3xkDtXlzQc6hCXQEuBvz MYMC8LVkVEcgC10Ao2R+n1DAEkMaxah3Iadf5WdF6fh3Z1lD524kF+0P4GOinJoocPnjE lWJwX3d8Hd1bF/jx72USBzUn0mpgpp9QBH73xGk7rs8YK/pQKBC3wKxnN4n0LBEivEw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904937; 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=3diKjpt3Hplj9bun3k4VWxlSuPRXvr0bzFEfcX1wVKA=; b=DtMlbZNb6cICzFwJq3ecx1wJI5ifWpTL70t1hpRLokqYdWAl6wAaE5Hg+Jq1xNMss0IM ViKNYwiJHbobqjtG8hJcbbBvOkdmPDr+u1hcxSR5/er9HOuilpl+OkNYrK6tSo5aqKozK 9+JjjMDrKbQr7hoP5mxbH+yqSB3DE/xRmzrYiXgnVu73SgQIRaoyVcvgIVda9Y2ar7+yG R4NDXGm4Ezm/vjOBp0eorTX/WXtTU4ps4LRrZhO3Jyqvty5duM3cgHrqY0iDiyO3MmqyW HOXNxfYv8/oU0KyKhmDxxMtveCMqyhr/YXxBojAcCEN04kxjt/z4zAK3oQfG9eZyzQg== 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=tCrfKKod; arc=none smtp.remote-ip=209.85.161.50 Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.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 C614E606A326 for ; Thu, 5 Nov 2026 18:55:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C614E606A326 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-oo1-f50.google.com with SMTP id 006d021491bc7-704597ef1d8so982320eaf.3 for ; Thu, 05 Nov 2026 10:55:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904936; x=1794509736; 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=3diKjpt3Hplj9bun3k4VWxlSuPRXvr0bzFEfcX1wVKA=; b=tCrfKKod4VfzUiFz3JbY2ZmVXQJcOHZYSDyOh+Ud7QHp5CteWXLGuOi1o171eqDFM1 8dP6NXqOh+v9OrWjM9vaUr5bdBwTt4/3j0b2dAqfNYocE0bZ0bzZ9+L4GToMt+ntF2rC tdRc+Z5pmMwHcqD1as1jtQ1wIIg1vnagmVPQ3lQJYgcHWvNpl8aDTbcDTLiW4oq0JGY8 Z+czamxHriSexWJqV5zXzkuFRPM449C6CohBPa/XpUDvhG+cKecHjq3FV5SJ9FFSaokA u6uFj9CwUDLe2Wd1vZ3+nZYc4Rv4avcizf/lD6Y2NHkuZPmMkEmrBbwP9MzRljnEmVMe oJ8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904936; x=1794509736; 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=3diKjpt3Hplj9bun3k4VWxlSuPRXvr0bzFEfcX1wVKA=; b=YeeyCqSyGh1cJptv+235t9K8Z308ZmPrRjp2ReRYYJba0Y+Q2/rwNJ8/BWcNh3A8si jBM0NhG1fWcP4oxo0qRSRua8JG8i23eGBUSf5emZx5bZW0RydbbdPg2nvYN3GnE2sWGC PihRZpuaIvo6rb7fOIHVfdB5TGTC8dgN+FPiuwQcyssLXrh6OuXZpEikfawef2i5OAPd 4ortnw9h0ZBWrhRfMl9/fusgL61qmPpyXpu7aVS2ZIq2EYsninfbv5lJmruvHZbLNX5t qKzE0rjjLuO+fghSuAtqc8d0iEb2S8vb6kFbfytcXO8i6j2TQmg1+kY1bkCcxmx7gndL 0uYw== X-Forwarded-Encrypted: i=1; AKwUvBzNPMh841tp3OvX1gN0VIK38mTULhZR3RJvfPxFnVEBb7OHrvHl3jrUXdt4KHMdp3VwpKR92vOoO6B/fQ==@lists.linux.dev X-Gm-Message-State: APuU4Z+d1AqOT6uDvEE1wXLFvCa2UsU95bVWd56GVCGxZUGik7r+lUwY jIA9du6N/GxcEFlpFtAKf3eCQWZbGEQkbBP7dUlT2/ea9+Wrpz+yfzJF X-Gm-Gg: AYBFou0XmTFPIfL6bwQsSFdEF8DT3IFFbhSolF4vKb9Z81mwxkhsKhswfHVbMEZ6FVX 8grtoghST20ixzjRu7jJ/mR3Z6/DNdGI+pRB1sNSbed6KEJFxnX3ZXrjLSUUv55fVF86jDSTvjT 7siosgUB2zUpuMzoZDyy7xN/66Ulj17GmoaeET8CY2MqIaKmXSXzoWzDOBLRYBaly9a+LJBQgN2 JXXyfpHIs46yKDCeqnTlq5rBU1htZ+VvTB+sip8PQgxos3qJ2nqn/wtLXdPOQan8RQDq8Ozm/63 GaNBwGJl/k9pIu8YAKm3Vqr5qdfeTcAmudiG+KdWQA0MDisMO2pRV2BCHCnPSL8tFaEdJf6AhRu UrnIyAHT0/6JBoX+/lCobYKkHIKGJAZ28/wghCo64Iv6jfjPYUy4y0LzXjeVL8Giz3Hi2xi1H6z aADiUBf5liZMU3di4HW0nfAJWzpMFfiKv+zDSiIIiQGHalU8umPj5zRdftWG8essM7WRhkPwyeA 19CRGL6lGamXcoYXoc8/JlBPJE1ECveYxcNFfFtuLemCgWO+09VxkA9nLjVhZWvf+N6XKo0+i33 4FcEkC7hbgt4s10GhG0eLtwMB+pRoJYQU/pUjTiMVhH0nBfxJUOEuVuyU5Y7kuskfxh+tWMvgR9 vVCAzP5kdfMGY21/grLiODlPF11Llf2z645Rh1SnUzdU75C1Kx5ZoR1lvdZnu9bbE5xg8q23hCQ f3H9PabP7F7AJSiSHJ75LcFlkTSwOD/3EW4bLQqvmH6Nm4LYiVr14b X-Received: by 2002:a05:6820:7408:b0:6d9:8a4a:7114 with SMTP id 006d021491bc7-716e790c5fdmr232093eaf.48.1793904935633; Thu, 05 Nov 2026 10:55:35 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:34 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:20 -0700 Subject: [PATCH v10 04/26] mtd: rawnand: sunxi: reject pages exceeding the ECC step limit 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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-4-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; FORGED_SENDER_MAILLIST(0.00)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[26]; FORGED_RECIPIENTS_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]; TAGGED_RCPT(0.00)[dt]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; RCVD_COUNT_FIVE(0.00)[6]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114:c]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92: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-27262-noreply=patchwork.local]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: CE7191C53B3 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX The controller has 16 ECC status slots on A10/A23 and 32 on H6/H616. Hardware-ECC setup checks the strength and available OOB space, but does not check that the page fits those slots. NAND identification can supply a larger page size, and the NAND core does not enforce this controller-specific limit. If enough OOB space is available, an unsupported geometry can pass attach and reach DMA code that indexes status and user-data registers by ECC step. H6/H616 also represent enabled data blocks with a 32-bit mask. The number of steps must fit the controller even when their user data fits the register bank. Reject excessive step counts before allocating user-data lengths or installing the hardware-ECC callbacks. Check the final step size, after strength maximization and the conversion from 512-byte to 1-KiB steps, so valid geometries retain their existing layout. This also keeps PIO fallback from accepting a page that the controller cannot handle. Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Reported-by: Sashiko Closes: https://lore.kernel.org/r/sashiko-outbox-173724@kernel.org Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index 662d96fc2535..1a61f608ad91 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -2223,6 +2223,11 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, ecc->bytes = ALIGN(ecc->bytes, 2); nsectors = mtd->writesize / ecc->size; + if (nsectors > nfc->caps->max_ecc_steps) { + dev_err(nfc->dev, "unsupported number of ECC steps: %d (max %u)\n", + nsectors, nfc->caps->max_ecc_steps); + return -EINVAL; + } ret = sunxi_nand->oob_ops->init_user_data(nand, nsectors); if (ret) From patchwork Thu Nov 5 18:55:21 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 3890 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 10DAE1C241D for ; Thu, 5 Nov 2026 20:00:13 +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-27263-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-27263-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 F118F31140 for ; Thu, 5 Nov 2026 18:55:39 +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=1793904939; b=tERqhnYuMjp1sVZZ8eBBmavk3EYPPvHWvGBsWOn3D3/wc8XLrZ9r/6qFw0k3Ob1EllYx 03kFoGsFPs2lizQNjR6/MgKdUhHFmvg955tCsSrvtVqwpaacWfIP2s0+xogbLB6yU55fJ ZWNBQTp34AKu6UamlFWzcUPJSJni1LCW3qiT/3Wsmh2Gd6R4GYg7AHj2sqOzCRzWVmIOl uK3UpMELC+cysIffoXeCMG7kFjjCVzLG0ChK9CanMtleqf9XUI+ty6AGJopsxQdttu975 P+ygLV7hP8QKXCm8FadAh0o5vhAPrGZbmx5XaWLE42Pq1Aldo0VdNJGPisWHng2lKVw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904939; 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=riAAQMfBLq8mpLK4f+nQf7CL76Wru2zCVjChEptNvYo=; b=OOMWKeaI3iwBY5BKrFlu87fmLR1EW907vFOlEGhBzb6ZjHW6EzfcYztl0H9KpcB4Q+zz YsRWvdO6dbGe+Pu7Wrp/IsrfsJoYxj0FZvM8eb3BauRrMwOOmDiC4I4ujUY/Fk60YYBKP 8fsqDfsqI46GH9ztLD0ykVkA+nTI5gDdKTFLsNr/X2VulMTGjgkxECRFU9leS2VXOmlnY P8mHKJ+Feoq3J8o6VH2E2KpoqkLgKMvbkVk30IS4VPWRzlyrCVcm0qkCDwNpGMzdqKmtY /2qspPJOKf8CbrYek0GJNfFkKpfP8eQxsKiCuvf03O/Ptx1VdFL4SB0CueTksIksajg== 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=lO5UEGTr; 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 C478D606D814; Thu, 5 Nov 2026 18:55:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=lO5UEGTr X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904939; b=rKR2N1k3RxfNpYcw2v2CXonhsED8xQO+7Uxbmk+5qKzQL2eWPh/TSNN60eYYmq045b6/ 7vAW0r+2v0gOsPGAigey+qz8p5E5A0EQf7pOPCK9NdED2v0MPKgsIIYWlyGBz1j92qJRt 1LJqfiv8mwx40Y6EiX7BqCeAyyrBZg1OQoziwWWxhlDVUazhMTP3ySNJiv3jKvH3JFrwx a9VJ4b/qYrF3o04DMMT2IBOouEWioefDiDMzCi5wdG/6ECBf5u5mfuLN6h+NWf3ugVikm u2I1wHgFh3bs6ZETXGNYYTbfXRtmNcH9kneelQnHCaLVMxD0gf+4qTTYtPEAkCAu3sA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904939; 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=riAAQMfBLq8mpLK4f+nQf7CL76Wru2zCVjChEptNvYo=; b=4vPwfz1M7W8XbkC9cwOguTzneoHkS2SImikQKTI8whC6Au4ubYwLqYPaoJBmfvND4AMY 9L3KoQvKApv32iP03aKQD5GguNJUQ2raN+qfU7qmqHAN9L/v7Np/R3kgr60o++6I/I6ZW KGB3VWuJ6A9a8At5kcjYnvePUrvcLKXyeqlKnbcYVEiQa8T+22enFbvwP6/sIDSn6OcPm QdAEawMDw4N4+M6GcluPUHzRrj/UfYetaZWYpT0tTMI4QdeWgllpOFCn78+mYP2PSjVAU J8bMceIWLbEgqyMStWEwbYmmIrtG1oT6TH0LDbM//XtOI9wqZKG6VIUEInwXG3ugSeQ== 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=lO5UEGTr; arc=none smtp.remote-ip=209.85.161.52 Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59AA7606D809 for ; Thu, 5 Nov 2026 18:55:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 59AA7606D809 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-oo1-f52.google.com with SMTP id 006d021491bc7-6f5a0893610so1619021eaf.1 for ; Thu, 05 Nov 2026 10:55:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904938; x=1794509738; 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=riAAQMfBLq8mpLK4f+nQf7CL76Wru2zCVjChEptNvYo=; b=lO5UEGTr5D9GR0HmnKuAMcnBPJjISptM/b2BU7njfYMZyJyii/+HHiIwhPltBZUthk ghsOwUAVmKa1WdfhFkZY7we4/8QhsKZrLPPa0vayx32Gcyyt/+vvwSKQwCy2IOJ7Xzns kTAFzm7SkFqy4KgncZ1yipQjuNXu0z61ecRl5xwyrXHn8UkQvGOnWPIyEYcMpxY4m4Uq vek+OQsetNHmsND4nWsHgJzLoyfsv3O+OCOm3AumnRmrOGktV5Lhdp4gb0DyUb33ljrM YjqcGU3UabycdqyW44XeUrtE/mz8yGfLDauzd7FYpvtSnLEPx6ENv0vd7iE/oS6JY916 a9gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904938; x=1794509738; 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=riAAQMfBLq8mpLK4f+nQf7CL76Wru2zCVjChEptNvYo=; b=b9t8LF+tvIXHVqrcgaR8YtpBanZU7/K5v+SOUWBiBDA5feft8XlN4Be6Z7lHRkK7Y7 CYyycJJvSTp4hbmhBi5UagffBlq3fl7xvVRA/lMYlGNnXC+i1pjQ205kYRo/MLqZOp1D BYH66iBWrJAi+E5d7CSsVDz/aN5h3hmC4KTcKdZrjF5ugIpGeTjxqwmOdxEGZsJVlDB2 wQfjwIu8uyb6zh3NmsuyzS/Xni3YnpAUCYzLY/oASYPMW2m+cynZilTXeohisUGrqvxQ 3bJksw2Sj0H5O+dMVHKFBCQK0ywwvqCRrnBfbOxeWud+JEI8tNLgAJuG/GvfCrb9+mYD BOKA== X-Forwarded-Encrypted: i=1; AKwUvBxDoBY6kBK/lO2pKun4qivIUD3D7mdcw0wkso+HXtcuYtu6+fQrywFxUJGamDfQpYYVQ4KK79EdMiN0JA==@lists.linux.dev X-Gm-Message-State: APuU4Z8MuMjvQqfQ9X0Cs/Mdg6zAgKxAqo2abNDsmlAf1k2lvzs9YJ9j L7UoRdNAb6vfUcfO8UrrPUHaSAzk5AYCV4mxJkxWfGqtZOquY6oy5GJ/ X-Gm-Gg: AYBFou2VAj4fKNEYtpu3E8aXRpxtjZf1bkL3zVk0jnoEqZa2Bp3BSqhmnLUK4ZBbuUn a9Y0NbIJWL6R5LcWPu5w2XBrx+cVKPY/L7rx88ezFmJj8BpMw6XkT5hmRhti9uU+4yEfDB/sDpu dRqfgAiKXjDMfOBnUKQRLKlRhyc5IC8lmfP39Vm8F1tJBKK59ADqstPULvz8KNxXaIpeDefPXcL Au7JosQlMTp8ilXuNXIUA7rH8EKP0jUwzJQ2VPQ1s46owJIUKxH3zeccUTT2YRy2/+IliMyEtTg qQgAjfYwVNZggP+3HXOF0EJ8uslrjgmpQL/WLirgqc2+Py9YTopeFeAwERxcfryRlMWMvP17KOL Ww/S8ihECzhzE9OnBP1GHU/1Frlm8YTs18oChKEBL/SZve/+0EaKbyJtLGguyM+H/Z3S9IjAqmr UDxNI1Es+dtqAs41wLjEpKWqVYWlB1LwZcCbSnc1IChiW3oZkWAGazzksUzy+vN6ACIjq3zIlAa hwAZQWxaRWYip9KCAOwd4jEtYruCChVXAYQXsizPhIM4bKNIYU4tirI5kvHfDZwFE77vefwLSsM JilYeEaXGgIfYmliYwY0jS+9as0y/WRr4UAG0Yh8oA0D+Fm3/8K7yYgmHESzkJx1Id199aAWhhN Y1N3Op67/Cq7keJiXnea5phcIY5/8IJinIRA0AXtfH5R/kUcuYB7UMuRp6LMMz1jv5CAe+HSW8f sCggDTO8H++s9hhCy+2e5t5x8BZrD6Y4gmcTnJqjm1FyDiTOzng3Zu X-Received: by 2002:a05:6820:2484:b0:716:bb14:b806 with SMTP id 006d021491bc7-716e7abb94fmr268521eaf.75.1793904938216; Thu, 05 Nov 2026 10:55:38 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:36 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:21 -0700 Subject: [PATCH v10 05/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-5-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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.234.253.10:c]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; BLOCKLISTDE_FAIL(0.00)[174.29.1.49:query timed out,209.85.161.52:query timed out,100.77.114.92:query timed out,172.234.253.10:query timed out]; RBL_SEM_FAIL(0.00)[172.234.253.10:query timed out]; FROM_HAS_DN(0.00)[]; DBL_FAIL(0.00)[sea.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.234.253.10:query timed out,100.77.114.92:query timed out,174.29.1.49:query timed out,209.85.161.52:query timed out]; RCVD_COUNT_FIVE(0.00)[6]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; RBL_VIRUSFREE_UNKNOWN_FAIL(0.00)[172.234.253.10:query timed out]; TO_DN_SOME(0.00)[]; RBL_SENDERSCORE_FAIL(0.00)[172.234.253.10: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-27263-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: 10DAE1C241D X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX PIO transfers each logical ECC step through hardware slot zero. On H6/H616, user-data lengths can differ between logical steps: step zero can have 32 bytes while a later step has only 16 or none. sunxi_nfc_hw_ecc_correct() uses the hardware slot to select that length when filling pattern data. A pattern detected in a later PIO step can therefore overwrite the following OOB region with step zero's longer length. The protected-OOB write helper makes the same mistake when loading slot zero, reading bytes beyond the current step's user data. Pass the logical step's user-data length explicitly to both helpers. Separate that length from the user-data register offset: PIO always starts at register zero, while DMA advances by each preceding step's length in four-byte words. Update both DMA callers with the helper contract so variable-length steps continue to use the same registers. Fixed four-byte layouts and the on-flash geometry are unchanged. The mismatched logical and hardware indices were found by code inspection while consolidating the PIO and DMA OOB paths. Fixes: 54dcd6aa69db ("mtd: rawnand: sunxi: introduce maximize variable user data length") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 106 ++++++++++++-------------------------- 1 file changed, 32 insertions(+), 74 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index 1a61f608ad91..ae18a7fbca77 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -942,45 +942,22 @@ 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); + const struct sunxi_nfc_oob_ops *ops = to_sunxi_nand(nand)->oob_ops; 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. */ - if (bbm && sunxi_nand->oob_ops->transform_bbm) - sunxi_nand->oob_ops->transform_bbm(nand, page, oob); + /* Undo hardware de-randomization of the plain on-flash BBM. */ + if (bbm && ops->transform_bbm) + ops->transform_bbm(nand, page, oob); } /* @@ -1031,48 +1008,26 @@ 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) { + const struct sunxi_nfc_oob_ops *ops = to_sunxi_nand(nand)->oob_ops; 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. */ - if (bbm && sunxi_nand->oob_ops->transform_bbm) { + /* Compensate hardware randomization so the BBM stays plain on flash. */ + if (bbm && ops->transform_bbm) { memcpy(user_data, oob, user_data_sz); - sunxi_nand->oob_ops->transform_bbm(nand, page, user_data); + ops->transform_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, @@ -1125,11 +1080,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; @@ -1228,10 +1181,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; @@ -1243,7 +1196,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) @@ -1272,7 +1226,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); } @@ -1461,7 +1415,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, @@ -1675,6 +1630,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; @@ -1695,8 +1651,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 Thu Nov 5 18:55:22 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 3880 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 128401C53A6 for ; Thu, 5 Nov 2026 19:56:03 +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-27265-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-27265-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 75E3028D50 for ; Thu, 5 Nov 2026 18:55:44 +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=1793904943; b=spFjnSjzEQ+uYVzUzvkG7Hjgd4enQsAld6i5NtnwVslSYATV6Kvnp/p2HnhADt1qvkg+ 2PVRPbLH0oHtvwbxkdq4cN758Kq1GxJNVGgqhqWcsTPhS66s2a9TpntXp+24EOUQDKv1S dzslEG9HMvReWpEGN88U8hsP29YHdYOlSBDzC9uzh7ZsgDysmP+Y8cyvrA4gAivkrOjrE hVN7GL+pMT2c1KcsD70VWjE1X87WNs1NXUoo+VwEO0GvyMukxNYT/xnxRYko7AThZ3J5a LwyGC5vN9bhgCnLImEG5aVkKBkHXrGnZGHAB1wnWNHsYS8NNSmtfUPkVY4ChOmRWZ+Q== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904943; 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=Qc1K6dw8YZ5zOMaIssAlpVtWAd8Vswo/yLcW5TaoQ6c=; b=P+Mt89RTK3d3j+yzGpK8+lNdn/RiKnEnlrfT2lUNH6rOd5r/0LQJrBAzWSxXeK3E0R5x e0c5Kq73Z1qMpgIDT2s3wZ4PTt3qxs2EL4fXapS3p37GSMqjPWIt/nAIE6PxU/sruLcbw oLe8sMs5yQvzk8RtQ1WiUZ5f3tuDGWfP9c5P52PGT60g1Q0kuMAvYEaBBZiZtIJosBSvN jdBXzNbaNJmAe7Wbf9ET3MuJrhnWc354FZfAdAMXvnrim31jU2TSoH4iX25QhBCTGSldg yiUME32tnSyLDLwtCX5uz5PCcsmO9CfAeSGjk9VmDfVHWYOYmi37CtX+6gO4em5wrGA== 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=URd4whpt; 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 E6E3F606D830; Thu, 5 Nov 2026 18:55:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=URd4whpt X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904942; b=Jsngxi64Gpq73uJoX/41rLj8IvQdT4ARYIt4WWq5ZOCuCQukIztmZyAdT/WmCqttgmOv CBH3rn8Rspm8ws1sxn5ejgiH/ZLQg9MSPqoSgc0LW1VwNSxDTt1GgmB9pbBTtk/H9l0Gp zTPL+bCgzP7HIsYli9fT7WrbJPldmP7z2WTm3Kp3F0CiFLmfexJsLjHbpc46qhcy8hK8+ +Gw4fWtqEp4BD6Fp55O3KquYsMbTfyLyoxGOmttKKPMyhYGcyYA/tVIn/p9Xld54JDpC8 2z+UrMyeGGXQPD56ZYIKkp41pXjYHenexAxIYLhNijJN7qkGeEnJFaafZFHg0cMFeaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904942; 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=Qc1K6dw8YZ5zOMaIssAlpVtWAd8Vswo/yLcW5TaoQ6c=; b=1LEDkEYblN3i1biUWKTMuFakanCBL8XLVohkQwShK9h9VzYEiEFVKSeU1M5NXIcsUL75 Ml9WPEcf9xKWRouQv+gyAaNSQDIOqGwP/pAGtC4L0Cttv+0vJt3ljefHjHT+NT1xJC/d6 zzzldrCfkZGz+beol77rH4/Axm19Ey5Yt7gp3LyHm2Nr3fw2BsB+zq5QoFWhu80d5jOWZ CXpka4zvcomv/xzhNgW+1mwI9bduCGjH2+i0hoVNbbMfT8a2WZg6cr4Ozpn/qKfIzcr+P Y6uByGUOYBAc+44zQpLAmF3XdGO+gH0q6Zxf3mTw0CwKnP5J6bK1BhXw6oPHQBrXt/w== 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=URd4whpt; arc=none smtp.remote-ip=209.85.161.42 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7668F606D824 for ; Thu, 5 Nov 2026 18:55:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7668F606D824 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-oo1-f42.google.com with SMTP id 006d021491bc7-716c0217635so977519eaf.0 for ; Thu, 05 Nov 2026 10:55:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904941; x=1794509741; 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=Qc1K6dw8YZ5zOMaIssAlpVtWAd8Vswo/yLcW5TaoQ6c=; b=URd4whptvDBUUPfaYFqlSqtPoqO5OEoMk3hhCIOuXGqCe1cd/hMgrhCJRtp+6EB8hv tOXfd/HUdazEBbRcuVJr/0aAay9b0h+o/FXTXfHhZPnJ1vgn+fD4VHlhhdoMRPRJudZG tOOksMCjUI79K79l/zMrqN4vosWmbN+oLqi6RLaxE6KOkJeASyX4oEHOqhsv0M3/XxhG fL9U7FC2YFwU9sQ3NauDhY8nQwBO2VFouEZKiE6ELGqXBI/Z+1lMKs6FPwqF9gGxa8vT hptX76pr67uDHUGp1W376lkAxFvBOfB9JJP9tezDaLG5LtqxwWAxc59IwXH4PYd8yVXw xTAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904941; x=1794509741; 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=Qc1K6dw8YZ5zOMaIssAlpVtWAd8Vswo/yLcW5TaoQ6c=; b=s2ih0t9xNMXbVvnpnhyCAErvHs17sHarg8XiGPYPMnvrH3je/BZ5HueAqMfW5Kh0dB OhtPnpH4HxWvkqi5m9QMfEP6pal75pyiplbcpZTfBD1+VmjG5nPuZnfZFB0gi9IK35jS oU231Lj2HZ2GnS69lE9Xph8xtZr21wvrJY6wxlXnBwdLwsHL4IW3VEaTYpcHixu6+wqj 7giBNIMJCseWQwpeYlAQ4aYsLDBt8ToagLlRnjhNVGMIym03d5clSIP8n+Tn6+QWn+a1 17izOVvzH9HqgmQPNdCC8yXZ9S2uLv/vew2T/5pIes3sycMqNbcC/sPV7ztinpIqSf72 UBcQ== X-Forwarded-Encrypted: i=1; AKwUvBxU0gzG+tdSrS8Q0xWGUX2cECgF0Xs/sbGFOtbfQFBHAsa5ZrEmqAR4aFd19W6Q6pLTHAqXUbKaqHrXtQ==@lists.linux.dev X-Gm-Message-State: APuU4Z91K/++Vy1nFPNdQuNCJ/ePSfZ5pLXM2IDc4M7sApzW2ygSa0r9 NZtWbcI0L+5vCovsegra1ntFhrpiC/dF8Vrv/AiAE87AKZco6pUmV052 X-Gm-Gg: AYBFou2Mp+dAIXy3OiFPg8DJKP/MdaDyimm4rMaqD4aXFzzkIC6gmFMJgJk4y4zDwXY CQeqdroS1bzbYWeSSKVnbrG6PkawdNrBFqm2BLOBQJ8OC8PqnmU2TEFycdtciOkSzkZbMLlgVYO dYZm/r+j1QM2Gf3p9dG0EiI/9JD2ljmjbtE02nLA55Yx0avnmnXJGLCPy9KYBzFsRYPFRvViFdw krKRzmRIkB7shGUbXK2w+6xTzp+HZzDeh4h91Jlw8PXb7z+EIU40apeM0OVpaotPD1cX45a0d6C 9jATHpnD9TGLlGhBOl6KhJY+liESL3pWgywKhufAZOMeWYstPy7+41KSFdYbqOrLugiCZWeinXK M/TGJUPvryuELNIY0bbgeHysRNK2uNP6M/gUKtahdi0SqgxUQN7USkhDybglgZ+Mn0q8L3f175P 2K5YYWq0Waqg0FIdA0E/RGHdcOeyLmnDQd6hdEkGBu+WsBxq2Gu+7QGk/1rULc3c8hdOjpJGT8J 0ibIBWnFSDSuDzr4v+5WrqkLqsGJ+broFnlLKT8tLThkw317NVgcqle0E6Z76gtBblWgDJNnLOd EbAmKvm21AdsXeVACKPJEU2cNYfSpyMEPXxuntMJScBio+8/Q7QL271/qajd1+0kkOZRgNJt4hG Myz6PFeLAWXeVuJ/xq20vq9iqoHJOpZXEtKHSJEcftVfHqfcZ15V9OtvIH5JSXTNBEOnnL0Y1JE 28Gz1B+fiJBpJTRZ4C4kWGGfBDdAPUUxSUjQgsU5xVJgIAMZNI2UaT X-Received: by 2002:a05:6820:c5ce:10b0:716:b936:7cf6 with SMTP id 006d021491bc7-716e73763e0mr260411eaf.4.1793904941072; Thu, 05 Nov 2026 10:55:41 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:39 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:22 -0700 Subject: [PATCH v10 06/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-6-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; 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]; FORGED_SENDER_MAILLIST(0.00)[]; BLOCKLISTDE_FAIL(0.00)[100.77.114.92:query timed out]; SPAMHAUS_FAIL(0.00)[209.85.161.42: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]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114]; TO_DN_SOME(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received]; TAGGED_FROM(0.00)[bounces-27265-noreply=patchwork.local]; 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:+]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 128401C53A6 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 read callbacks ignore nand_read_page_op() failures. A command or ready timeout can therefore leave the requested page unselected, yet the driver continues with data transfers and can report success for stale data. Return the setup error before starting PIO or DMA. After an ECC error, the driver rereads the physical data and OOB with randomization disabled to distinguish an erased chunk from corrupt data. Those rereads can also fail. Do not pass stale buffers to nand_check_erased_ecc_chunk() or count a transport failure as an ECC result: return the reread error instead. Successful erased checks retain their existing statistics and correction-count behavior. 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. These unchecked returns were found by inspecting the read callbacks and their NAND-operation helpers. 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 | 56 ++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index ae18a7fbca77..9a7b365e998e 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1043,7 +1043,10 @@ static void sunxi_nfc_hw_ecc_update_stats(struct nand_chip *nand, } } -/* Return whether the chunk is erased, and account for its ECC result. */ +/* + * Return 1 for an erased chunk or 0 for an uncorrectable chunk, with ECC + * statistics updated in either case. Negative values report transport errors. + */ static int sunxi_nfc_hw_ecc_read_error(struct nand_chip *nand, u8 *data, int data_off, u8 *oob, int oob_off, @@ -1055,10 +1058,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) - nand_change_read_column_op(nand, data_off, data, ecc->size, false); + if (nand->options & NAND_NEED_SCRAMBLING) { + ret = nand_change_read_column_op(nand, data_off, data, + ecc->size, false); + if (ret) + return ret; + } - nand_change_read_column_op(nand, oob_off, oob, oob_len, false); + ret = nand_change_read_column_op(nand, oob_off, oob, oob_len, false); + if (ret) + return ret; ret = nand_check_erased_ecc_chunk(data, ecc->size, oob, oob_len, NULL, 0, ecc->strength); @@ -1322,6 +1331,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, @@ -1329,6 +1339,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; @@ -1380,9 +1392,19 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *buf, ret = sunxi_nand->oob_ops->read_batch(nand, &read, status, pattern_found, 0, nchunks); if (ret) - return ret; + goto err_stats; + + ret = sunxi_nand->oob_ops->finish_read(nand, &read, NULL); + if (ret < 0) + goto err_stats; + + return ret; - return sunxi_nand->oob_ops->finish_read(nand, &read, NULL); +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, @@ -1468,7 +1490,9 @@ static int sunxi_nfc_hw_ecc_read_page(struct nand_chip *nand, uint8_t *buf, }; int ret, i, 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); @@ -1476,10 +1500,11 @@ static int sunxi_nfc_hw_ecc_read_page(struct nand_chip *nand, uint8_t *buf, for (i = 0; i < ecc->steps; i++) { ret = sunxi_nfc_hw_ecc_read_chunk(nand, &read, i, &cur_off); if (ret < 0) - return ret; + goto out; } ret = sunxi_nand->oob_ops->finish_read(nand, &read, &cur_off); +out: sunxi_nfc_hw_ecc_disable(nand); return ret; @@ -1490,7 +1515,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); @@ -1513,7 +1540,9 @@ static int sunxi_nfc_hw_ecc_read_subpage(struct nand_chip *nand, }; int ret, i, 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); @@ -1522,10 +1551,11 @@ static int sunxi_nfc_hw_ecc_read_subpage(struct nand_chip *nand, i < DIV_ROUND_UP(data_offs + readlen, ecc->size); i++) { ret = sunxi_nfc_hw_ecc_read_chunk(nand, &read, i, &cur_off); if (ret < 0) - return ret; + goto out; } ret = read.max_bitflips; +out: sunxi_nfc_hw_ecc_disable(nand); return ret; @@ -1538,7 +1568,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 Thu Nov 5 18:55:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 3881 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 CC9101C53A6 for ; Thu, 5 Nov 2026 19:56:16 +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-27266-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-27266-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 86A5D292D3 for ; Thu, 5 Nov 2026 18:55: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=1793904945; b=b8Qz0cWvdWB4Fz2MkEAlTrnp3hRUTfn8YOOTUMO74aMlPQOS5DO4No1Pit/b5TyW2bbg IUoyaWXouKeWB9Swi17fOtt9rNLbTp6pdceHS9kCb6gyHGssvuv9t4izwfZWJs1oVU15g H6h9HNJlfnx/VK9blQvvFqueiLOXdzLWTDfXkAn9tHtE5vhbjGZeBhv64RMjOAojFY9PC NOd6vLi5cmT0QIiPlD/xnKWmH1vxrf4UkSzaLVkAmPh7lXBfAHHSf8vNOOZEDr4NQdsMm UwwDBqTo6fP75tFvXtsQLzr1R2gACCu0rmfUN3m601r/jZ3TWXjdNSvWSkwYxo7iY9w== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904945; 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=nG4n6RbhRtbsAmKm5luV95OTsd5m2vOsTQEC1Oq46ng=; b=PrfHWzUh+g4rgze8uZt+h5eXytOiLN6o4uPz60IMvfMnAEMZESdX72lPInlvqzTsXNss GSLNsAvtR59bNoev8Rzg5rai0aKZElLJQfOEPtgKxxS1pT2IyDYqQoAfZ3Bxd7MZTasJw dVh6T0hlqRX1FsMwrThC2XQ2fUndGHDlK+Dwv2QGdC1IYKY551KDczqw8cp7WM8PPRBSg d5BxM9WrDpa0Uch0jomu4StHn0bmbjtv5YwBPy++jFy7FfmVZS9uypWzLE2P8TMPpexHv 9El+BUFMRiw0+VLpLGqmVBL7h4BFb0W3nmaABioh+BgwrdiyT+r2xAdYmMOrOjDAZvw== 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=aECHn9uP; 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 7D674606D803; Thu, 5 Nov 2026 18:55:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=aECHn9uP X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904945; b=JH+DX1ZG2X2hkO3fjm1BOtE8atbrvm1zd0GZnDn3iTOKJ4wRl/5LJrBH7b6dLqE9l7j6 OZNvgabnL/PRgupQxIGZnoJvrSzCtVcQfa/N3BvXUkl/CxYZHrz/1KmHPAylBJtl4YCxR diHZCaZwjgORmjxvx8Ou48fLJvrRsHdEK57VecWbhZ/jkwjIpnwR45KvLi9ePFvJvTObb 3UjCC/pzK84kXUjyML0fwKtPknFla8NdKZnfj1+tfPasJ/bmouArhDGxgk7n+fplBOBcG Dr4eIUGTG1zoZle3Av/h6Z4ThpgTMvEegrymWk/cCtrSCsIs0BGrwH3YQcoc+rpcfqw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904945; 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=nG4n6RbhRtbsAmKm5luV95OTsd5m2vOsTQEC1Oq46ng=; b=uqcnj/yetFcwdKHKHMSDTG5GMLjaLCJarKvdVZN6e563Gbf6HhddRACdoikRECR4I2qc AP556cYZk1cR9JGAOrraO9VFGaWFk8aTddpByuKpAJ2zPv06941U9j/SRk1SQlpHINYY1 RM+BTUewbaxS0xb46Nu0NKALq7fpbJIl8nDNzaHEalxACwJRYtjKFValoN26lTK9cgacE J8HYWOP8Ump6dMGzBN4oUUtOAQ8qBl1nzzk+OeAstpTl3XF9hPF1sj5CIDxzB82klyPXf ife4vSQPrrids8lamBOa0LHMtA4IKL7sBAECQgtTqr3DCxfAOLw5TteqVtR4GBl31/g== 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=aECHn9uP; arc=none smtp.remote-ip=209.85.161.44 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.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 05629606A336 for ; Thu, 5 Nov 2026 18:55:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 05629606A336 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-oo1-f44.google.com with SMTP id 006d021491bc7-6b1afdf5196so932753eaf.2 for ; Thu, 05 Nov 2026 10:55:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904944; x=1794509744; 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=nG4n6RbhRtbsAmKm5luV95OTsd5m2vOsTQEC1Oq46ng=; b=aECHn9uPqcMl6BPYhSbBc37J2aOe+PLlf7Bv85jLqU+ylqYVWmFSitgM6XxExH3yD2 GdbstRhWCgojIS0cuishvFTiv4a1P6iKN92SPDvDPdNmlSzm9c7s4kEDL6lGwMNF1N8L ZZ+4sDwrBJrKW0BaiYm1vnKXqnEkNufXcEwqbmpJTDATgydmgfbgTiZ5Ja6GxzuKVW7L keudZG+ne+mawNaGDD+H3qROnKhpxJB+H81LF5CMZEcPQApVKNf7q+EZUb8Llho3L3Ce JUu7RnW7mRHPd7JRqrsbXhX0hlzSEtqGyajESNSY1kstfxQhgqe+InRoCazaGCljhJoO +8fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904944; x=1794509744; 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=nG4n6RbhRtbsAmKm5luV95OTsd5m2vOsTQEC1Oq46ng=; b=dBrAujgsiv9Y255C4IM45RawW4pzLGEqgli23guBl3bzk08d1f93HNA1fxp495ZSh4 /0QJoyFx43RJRHzBXXd+AmEeHqxVoAyWOyj+bjMdpXh2OkHanrEGROOmjDZxtqFWRpvA VQY3OSntS4B1sRIdLsDfvqO/TwV2vVAHEpnz8EvdGgwAh0GeDd4yKr71uhNhN/7b/G1X xtx4efcHYJvkhMRgEOTMxAC1sIsp1wDb/ZOCf8UmZHA4cwGZzmxtkc9RFZUBE3zG6okP 27Pbi69HVJ8YTu7NSCB4qVHMonvye5D/Sywyla3T47dyFAHHNxzHSTP0jKBc7SHw/eGk 2lVw== X-Forwarded-Encrypted: i=1; AKwUvBy4Ps12s/dppFqMljPEY41UcO8g0t8T735Tr6anGjjH8A/PqfdPe80Bf/Ph9pZz3WBo9s5lC1T4Obquqg==@lists.linux.dev X-Gm-Message-State: APuU4Z+KhGcGL6/VRZHnEgwxQGiq9NL3BS4U9Gj09ycyrMG5mEwEguIf dqcurxmSYYHdVp96fN0e2KioF4fsuTUMDHo6h6Ef1HXLZySy0h512dL8 X-Gm-Gg: AYBFou07T4Y1S9FLxEIZM1AUFHNHySKADs6rHFyKJy4BvCBVtJmW6jNjlISFIvEIzSI kUdgyVUykNG+zFNXigbugmGNqg+LFdzYemY6xCak6/ps+dEms6IkEIoOk65QJlo4oH36EP1eLtv 4EcsLVmpqFyGF8U6kB9fgHpu0iVFxZfW78u4peA+BABi/+/W7zvccxnlvQuxYerLqVZjBVs0Ka4 5sKSCmM4ieRBqgW4pZWPIYrzPGMqoyOczlAAD53SSSegYVhdVrEchPZLomCBN4SG/PmNJVFBYAr 4sXbYN6vUZmeuKSaVq3HkcU3q2QdBnTXwcFeAOKlqTclkX4pcEjTDZUxCuvjOApzVsStLkd5fWd 95djxFZFVnmfsjb1O5kuP+ymdA39wolTdkbiKMiUBIt3saGkHbR3awr5ZFkvRvvPiwX6yWLoohB iKCwEhQXZJVRPL0rL7k4X/vFBMFNUe7HWEyVGbWkxAcF89DVEaUl57VMKy2TjIXPZA/fvJgaYiF OKp4FJ65sYi2k8PUMIaBgXeS4Az9UCIhHfRlrWYOAzBnNw26UEbjVmh12BdRDAM/YvT5xbHAWgf PWOpmFhcdltyIjA2W+hyize6JFvtxokbMj0SZgtU7pm5pdj6drocUqXjHUgpnH1d2JLOkKHbL/R 11ZrQeMDR1fHk18xxL3TnpxfZeleE6Hp9QnCPGR3ZgCnswbLlCouTUd7at7xO3iqBZbAEQZCxe9 8YjNNrh6Pdc1n2nC55aBQlJalm0CNGvRBACc2k8gLdeL1/qSqFCRa/ X-Received: by 2002:a05:6820:1c8b:b0:712:c751:22eb with SMTP id 006d021491bc7-716e73dea8fmr352195eaf.11.1793904943944; Thu, 05 Nov 2026 10:55:43 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:42 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:23 -0700 Subject: [PATCH v10 07/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-7-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; 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)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns,linutronix.de:email]; FORGED_SENDER_MAILLIST(0.00)[]; FROM_HAS_DN(0.00)[]; TAGGED_FROM(0.00)[bounces-27266-noreply=patchwork.local]; 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)[100.77.114.92:received,209.85.161.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:+]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; 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: CC9101C53A6 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX The controller uses one completion for successive interrupt-driven waits. Some transfers wait for both command completion and DMA completion. The handler acknowledges each event and masks it, leaving any outstanding event enabled; it calls complete() when all requested events have arrived. sunxi_nfc_interrupt() currently calls complete() before updating those registers. A successful waiter can wake on another CPU and start the next operation before the old handler acknowledges status or rewrites the mask. Move complete() after those updates so waking the waiter cannot precede the handler's last controller access. A timeout also needs to exclude an unfinished handler. With PREEMPT_RT, the flags-zero IRQ request is forced threaded. Near the timeout boundary, that thread can be preempted after reading status and enable bits while the waiter times out, clears the device mask and rearms the next wait. The saved snapshot can then restore an obsolete remaining-event mask or, if it satisfies the old wait, complete the new wait. Masking the device does not invalidate the running handler's local values. Repeating init_completion() can also reset its waitqueue lock during complete(). This lifetime problem was identified by code inspection during review. Initialize the completion once in probe and use reinit_completion() for each wait. On timeout, call disable_irq() before clearing controller state so existing handling finishes and no new handler can enter during cleanup. The hardware may have finished before the delayed handler runs, or the handler may complete the wait while disable_irq() drains it. Recheck status against the remaining enabled events before clearing either register. Events already acknowledged by the handler no longer appear in that mask; if none remain, the wait has completed. This also handles command and DMA events arriving separately without requiring an already acknowledged status bit to be set again. Then mask and acknowledge the events, read back the mask to flush those writes, and re-enable the IRQ line even if the recheck changed the timeout to success. Keep partial-event handling in the IRQ handler and leave polling and controller/DMA abort handling unchanged. This keeps additional synchronization on the timeout path, without a driver lock in every interrupt and wait. The caller can sleep, this IRQ is not registered as shared, and the handler does not acquire the controller mutex held by the caller. The tradeoff is unbounded cleanup latency and no priority inheritance: a starved IRQ thread can prevent timeout cleanup from returning and block other operations on the controller. This is a handler-lifetime boundary, not an RT recovery-latency guarantee. 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 9a7b365e998e..111094b1c64c 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -401,6 +401,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 @@ -420,6 +421,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; @@ -441,18 +443,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) @@ -462,16 +466,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 { @@ -484,6 +500,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"); @@ -2657,6 +2679,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)) @@ -2665,6 +2688,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 Thu Nov 5 18:55: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: 3894 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 2C6D81C5396 for ; Thu, 5 Nov 2026 20:01:25 +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-27267-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-27267-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 428EF33428 for ; Thu, 5 Nov 2026 18:55:56 +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=1793904948; b=p21rKAKntm2PRgcLxdoxE+h9f5j/DR/2Df2UqPXXMiVf2fVrLH5uKibR9PGqKeI8OLqG n5pHNDJqSQWCcbXxd6ziD07Bp85fU1vXm90Ri1+y1kOo1AowgKA5eOeqjZzV990DPXcdn r/7nPtyU4WWdD/sG2e+jRYDXUzkNNk0N3loXh3TcrLC/qSQfZMDTLVK4V6R6GIK3cBti3 D4FG5k664u5vIgDC+AMVkMGU7psR6Dy/nJEMazOQZy902q7mgA+tnkE9v8d6187IIKiYz Abo5R8kehExD+bMMgD8G/17IQrTeQZLP5PD8Bn/NUaCDp7/3XNYeo8W7HHa0n9dSYDw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904948; 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=Km1F4VU7EFf3gMbcR27k+iCcZ4YJytvSjdEZeNVUaRo=; b=PEOxGfxEsJucsbXzN7T8Iw4r8lXIMn71QodwBwbQFyeqZGzOnqBUYs3gBio46ZP57CsP xAKtWDsimgqs9KQB83l6t44ICF8PqinexBfrZrlo2n7twZTSO82vxkw9zKNveUh6b/pUh qynBQIXTZKsMixJ5SpcWvarRddtnLhipOT8wtqQAWx63iPoGN/D3FmACCgUInTOTPkfCQ hFlzGAE7ve/qPMnN5jH4fvsTFhXpDwBTlVO1pMgc99PsOcwQxhCG9E30PeaFw3f4m/o+N ZJEYWTDl73NjyXNgwlTOSrsrWgPmN1YbZ4kXvb8tVySEMGcLzx7MxVkoXeBix0pAA0Q== 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=YEzWca7y; 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 02E59606EE9C; Thu, 5 Nov 2026 18:55:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=YEzWca7y X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904947; b=N/2VY+JQEw75YbFj2Hxor2G1vIB9w7HPj5ZDRQuM6j7zcUvPx4Hjz2RKtDVF2VULGZCN bcjUr0MXDdRMDUfHNHtsKv4vt9qPNq3+yFU23dvvSSGXDVsuMA/A62fACBsvIysA/EMvS aAaRB5WWOExlIHaDuDBHjYABKrFvyfIllI7ub2bWsKBYesYzyWYNFRy/ByxGbUZeS27+t FYYAMxkXdMRce17EDukn6pv0p25pNDkWKUtTq8ur51+QDolfPDnlcN8zigfgfBPclRX5N fmKVKrlycGFoiDzYJTP5CCoWizZ02GQamxUzPGd5CxdDuuAKYcRY3JWW37UxDXGXtcg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904947; 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=Km1F4VU7EFf3gMbcR27k+iCcZ4YJytvSjdEZeNVUaRo=; b=YqFXcRjItsmmQINEfFUsBMXRiFTAkMVJg7uoWEN8FPqumHp8q9bxy5Y3uGMN3LOEflXV bKHtT9CIEL92nEWLETjwgOlcPuYYIY92qJV68UGZrhHVTVulEJ4QgxXsZkzswS8ydqbEC Wbb4SZIUWxchzrLYymScEb1T8ScdvifSjF2jqrEwjltA/FvMiWj1g2/kgN8dxyjKAc8x5 trxQssaO3kz+WQFok6kdjP+P9s5tbScrBiXY7PyMODoFK58fX4HRBih4PA4kUwj2LBjAS l3pgef/2+NcJ4WFw69A++WsMrUESHhtI5vS43fP3F8xQWm7VYGbNX+I4FH5C7I/pQYQ== 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=YEzWca7y; arc=none smtp.remote-ip=209.85.161.51 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22EF7606A33A for ; Thu, 5 Nov 2026 18:55:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 22EF7606A33A 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-oo1-f51.google.com with SMTP id 006d021491bc7-6df5e315bd1so1891444eaf.2 for ; Thu, 05 Nov 2026 10:55:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904946; x=1794509746; 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=Km1F4VU7EFf3gMbcR27k+iCcZ4YJytvSjdEZeNVUaRo=; b=YEzWca7yu+tGs5DLO9SRzo6hjdNmHmzhWQzVdFXpkkTf9Dfm9cuh8kEdJZ85/c9XX+ qKZ3lxGhuxHbuhPjJtsWEMLXzqMY3g0sMNKNKJMPYZYxzLD6xUen6m8qoi1c7LWHnXhg /MPwiRllLRm8AzYIkn2KpxlEa3gbju4UiW+vlsJ049gXqk75ymRhuRwggG7kNJPqkapG izMY/rykNjWIwyZWZ5eoQbWAp0eDcB0tmJRdo+/7fv0OWHmYADapCb1VmZIDIpYgElq8 pZE5fzeDBCn49unJkcFkAYwvKpaOsi6LHwxbu1KxYPWWW7lHsmJCuQCWLWSiM1O83m6W V20A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904946; x=1794509746; 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=Km1F4VU7EFf3gMbcR27k+iCcZ4YJytvSjdEZeNVUaRo=; b=jG036V5hjCgxnvlx6NLbV9zAQFZnaTwVFBUdAye1Zw2usTCL08LGu08bkTnCMHRg1Q SJEQSs/R3+1HrPPi7GhO3gjCmaxZ7J7IiO6KkL61RfiIVwJhNGA9AY6LsNMBjPiJZ8Nc w5ht45ZypkbXH6sHORef+TGmX0YoCK5PyoY96h2F2m5Sb3FkvW4TMjWOnPwb8gdzkLVk L8opO90TBBh109e2zJ7mhbIrdUsqpl5CENEtnTXeca30dNJE3g+y0uhiy9RBAlZ6gi9e v4OYY2ikdK8d8+nbUw05PFW/wITZC8BbpIbrTgQFRSL+fqQWf8ciLrADrtBjRXXgaeIV 8/2Q== X-Forwarded-Encrypted: i=1; AKwUvBxXCgQqNnkl7balddsjJRZDMwY3Lvf8ti8V24DQyAQcuhy27bEOjytTBLxPdF+mFrkPx6YVx198VJkjkg==@lists.linux.dev X-Gm-Message-State: APuU4Z9mxH8rBIVAKDsZmkFe3+CPhoTSl/ooEixN9ExqVP0bE3g8JhEV W7XjdoWcC3QIy3E28BAj5H4EO6qSSztAyYzW2ZKdFe8hohdQgyLQeYXi X-Gm-Gg: AYBFou3et4fLFitqxZup0aMS2KwYYHTn6PQuFp2avKdIaHA2KLL2FQZwJGnOdovffP6 qq6pOtu4pW+dEvJZYjcVg5AzEMJlf133D8ALhg7FNFuQSc4pwkRmRwi6p0SMA/XbnIfPqdDZHhD WizK9OFDO3IvZe9vuiHYokdmezJPiORnmLF6dg7m0e+vyaV+ipE3c3Zi7kDNqCxQWk8RRtx2Y+L 8JfXiwPCofqz5alDoM7mAn8RhMszKyb9BXYJWZ+zSfwLHZDGI+tvRw/yvyrRzpDfKyXvFnGPDrW n6wOva5JF7m/qwuuKM55KsHo3cgYXkO2jeSPk5IXsBQPNHrKgVy8F8sL+Fpiv2L5ixj9zRLu3bw ZOIm1+2FgHDavcy6Dduige/imsScj8nshRcjp8HtmGk+mtvjpidEB5vMBupVfYmAmoophVJX5RT CcnNKMPvkTDjKLLzwx7pK/p6lwfDOifDNbRMxLnoajfGNq+VTlNWLEm6C2S2+PHfrEBIVbeQowr gj5M00PjumwStbooHpHxjhku+Ln5lnRHt67vj6h5+N2xKoOKAY1nARIDrxDm+UBO5qnY9OmCbO4 5F9zLTeGaeMltvhMkvdyyJxNA9dD/Evo7KPSNtqHtydHOIII+dy8l5gUpQHFEGz2fccuRhmuyft VOLpCU/N4aj27bJ7uCj/OviYjDR//eNCih0cfHha1hMacQiAcxLgh4sPLiAOFrhuuKHtY/NnIMB EH/QED8H66/YRJwWHORRGP+jm5QV/ZzyK8Ku0VrHj0895YD+KF6HjE X-Received: by 2002:a05:6820:2d04:b0:716:cbdc:4fa8 with SMTP id 006d021491bc7-716e796f91fmr333364eaf.41.1793904946065; Thu, 05 Nov 2026 10:55:46 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:45 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:24 -0700 Subject: [PATCH v10 08/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-8-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-3.49 / 15.00]; BAYES_HAM(-5.50)[100.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]; HFILTER_HELO_IP_A(1.00)[sea.lore.kernel.org]; R_SPF_ALLOW(-0.20)[+ip4:172.234.253.10:c]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; MSBL_EBL_FAIL(0.00)[jameshilliard1@gmail.com:query timed out]; 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]; RSPAMD_EMAILBL_FAIL(0.00)[jameshilliard1.gmail.com:query timed out]; RCVD_COUNT_FIVE(0.00)[6]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; TAGGED_FROM(0.00)[bounces-27267-noreply=patchwork.local]; FREEMAIL_FROM(0.00)[gmail.com]; MAILSPIKE_FAIL(0.00)[172.234.253.10:query timed out]; TO_DN_SOME(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; 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:+]; 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: 2C6D81C5396 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 program has three stages: send the setup command and address, transfer the data with ECC, then send PAGEPROG to commit it and check the NAND status. The PIO page/subpage and DMA page writers ignore the return from nand_prog_page_begin_op(). A FIFO or command-completion timeout can therefore be followed by data transfers and PAGEPROG, with a later success hiding the original setup failure. 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. Keep the successful setup/transfer/confirm sequence unchanged; this patch does not add a new controller-reset or NAND-abort policy. 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 | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index 111094b1c64c..02aa02d2cdb9 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1611,9 +1611,11 @@ static int sunxi_nfc_hw_ecc_write_page(struct nand_chip *nand, 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; + int ret = 0, 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); @@ -1628,14 +1630,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); } @@ -1649,9 +1654,11 @@ static int sunxi_nfc_hw_ecc_write_subpage(struct nand_chip *nand, 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; + int ret = 0, 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); @@ -1667,10 +1674,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); } @@ -1711,7 +1721,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 Thu Nov 5 18:55: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: 3896 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 E82651C5396 for ; Thu, 5 Nov 2026 20:01:42 +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-27268-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-27268-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 877833363B for ; Thu, 5 Nov 2026 18:55: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=1793904949; b=xrc1QuBI0X2kQLabSZmJvpFXkRlcu6A/b38/t3/KCAbMCmIfOw9WjFBd6WFMdPvBkogy 36Pl+z3qLo7bGpoEUM3rBzpiLEzkE30GoISjFatvFuYwbrHAToUNK3rLKRSmlNILr+Fa7 Ut/RaQtXILcL7rekmeVcM4O6NVL9C1KGWUDGdIWpqKmIanS27OFQ7qIy6iW20w+Aijv2F zaYSwTHcysxABBXkDPB1z3ZbLZ3FLqVY6coQUD6XVX4TpLZEI6pxnyNVLodd1hYXu42XP AkGfgNWu+V5nU+VRp25WuCbIYmluezm30voL25dREUahmhW5sfcxDiikyvGpchjoIOw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904949; 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=kjkwKej/qk52hMyec5U0ZIa7X3INzm/Y08ET6LW7Wyg=; b=H/3UXymG2+zc4IfB/wTPVBF/aqYXg+qVrM8TFHF8mTrLTu2f2alR7Akx8leIB8wiLt3w O9RsKUjc/nw3GcKrOgi5VcVHm63BWIICk5ZicaCOnwevWtCpV+0V3HkjWFXii2NkFpbcr D0kg6pRWaCJC7oFtaUvzSw0wTFleKhHzsvoNo5KNmvN3bRvysWjQN891ry2jwwzf7nvjt LpIveUVT1V7lyWYVFuRuhAkhOoM6llmOx2hDz5dHFXwcNWv6aOi5CMBj4drTFAbOrnDoH /4C7b3m5epsfQCSWg3vlT+DFqKu1A4TyO+MQ/uj48cf/HtLp/PkQJRbgdHBuymQQkMQ== 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="rF/qN3Mn"; 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 AAFE2606A32C; Thu, 5 Nov 2026 18:55:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rF/qN3Mn X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904949; b=OAOC44y7T39na0iEVt95g0hzKEC9SuBT3nqzK2UwlCC7kVAU/Uj8C6TIKpf91aA257MP Y8pGJyQwt8xBMk1hcGK8Q/BeJkbYTYi5F6UdkMYxbrSXHz6tIGAlj0P8quZVkqLBfrfIQ uIHLoDcaNmHuX5bySEymuMQEB6PoMmbzvNkSd80QqJmTUJDORqj7QDajYjzukh3acoMlh WQYX1m5I8YQJQTcC2y5j1TBwN0rHO7i3WS2Z5PI3DYxGk69xPLGzGodmIf5DfpWYHIhEA kpu3583h25/ZeOeSaBLYfcyJe1EqzD57cl0bqRIEM7zbet0KeaIQk8oB+DcomFeyrZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904949; 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=kjkwKej/qk52hMyec5U0ZIa7X3INzm/Y08ET6LW7Wyg=; b=N54q/mAXjfQr/LwlDATdIcMf+JKH/jMOok/DIrqfgJvQbtsGKYN0oyjMhKMKP6S9zuWl MycBWhHwzxDD2gOT/DzdBwWPSQj//f46QxZRamtgUgwnHKKhy3TaXFszvSatJ6StAEvqI uBf/X/HV6mihwP9SnHOSd7f8Y95yRLqGK1phQJHza/MEu9HhxHaNVz5k1CJHg0nKGSGha WXUFcdJqX5zZl16+ycclsJYJepDko4fIY3e+nYigFTXoisNXJ2m/3YgWTutoWBqO4Q9fC akobFncM3/Vk5cHQhG3+fh6ATsdrqEZvcXSQ8cdBShJMXZla71B46R55k8qseeUyqjg== 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="rF/qN3Mn"; arc=none smtp.remote-ip=209.85.161.45 Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.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 62DA0606A330 for ; Thu, 5 Nov 2026 18:55:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 62DA0606A330 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-oo1-f45.google.com with SMTP id 006d021491bc7-6f8a519e215so1084206eaf.1 for ; Thu, 05 Nov 2026 10:55:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904947; x=1794509747; 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=kjkwKej/qk52hMyec5U0ZIa7X3INzm/Y08ET6LW7Wyg=; b=rF/qN3MnuFpHWAY+cClqvLEhlfpt3Wtow8s2iNBZbzdZ4U7JBx2bnzWGZTmWe6Jf9E jBIYaL2Zf0A0LoMoE++jtPGqA+36y1+/5HBHkbSLtPPtPsDtcufMDwCMujda7nkUKY8H LOPeup1Npb52DQTPPDsVNRX/dCW/BBlGqe/dmfFBAOKtGHQ3iHsK2JP39YjrpzpiE8GX iA3mXYC5p3EQK24lYR/cxPdUZWvcPOFVJV2m3oSC4srJXvtx+wURJx/SWqxFAn3hXnkk 5n4uzCfsmnWBrRDs0U22wNDwdDG02mSeaqNumVI/oH58tmoU2PQvcEbmXwDwEB08CNsI iGpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904947; x=1794509747; 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=kjkwKej/qk52hMyec5U0ZIa7X3INzm/Y08ET6LW7Wyg=; b=jZ950TvTaxL28zKmKcsRiq8pekoQNwgB2EDMRvVcS3nTfR0YriF0lmXipqzsVv4KZq etBQ6Zb/nbdpKYeQYRmlz8HjBjdmwrVcy+BN9PvZCkt2vX1v5rKquc+Q9c/WyfoFaeNj LNFODs5FUONqkOEog6lk9Uebdg+Srl/u4bQp0Qiw5pniSXxMv3eMCE7sdCY2ZxCaCofa 5lMSXwZZ1JlIPnakFrBKZXrQ8c8Moh479MR43+E9bCtpXDKfFUhgtY40vmQY0OiX3j6E 1VuImhcyjvYSuUtyxgsdWFg8id9aJWc/dGFoIImp2bDk7eeU772t8dQlND5fMI/LH8vu 2u8A== X-Forwarded-Encrypted: i=1; AKwUvBw8Pz2mnuwPsf3VSzZ5N3Yhsxr1bKeT20P3i9A46jIB1NmJyDxY+rx4g/ehPtPdllaXG6TAGYDG0b7UVA==@lists.linux.dev X-Gm-Message-State: APuU4Z/dTce9cCYmjWt378V3wdYQdwGJjfHSwgKVWlwwFUOUvFPyqlyo LxM46KghFyWfrgtYTQUf55oqZhb5sa5SMMjo7Nn2y9Ww+wYHKywIsu1t X-Gm-Gg: AYBFou3KI3QeXdSPixOih1VQu++5drMiSPQAPv1dlGlXsM3APOpNMaueStJBCXIUStA RrYddkquyx/9Pm7oPcYWWMaFy3+9DOSaTjTmMuSm2hHUc5CLLAPZQgrQfXLm/qjHJTUV6L8rpn2 xIOZNDHXPahXx7WBiDiTOa+iBSrOwRR+lR/2xz8lsqruXJcq/0O+S1c3ePVbG9rCu4K6nVI8TUl PegSINy6FdsyF47QXXQMs5G+QjeVLAXrXzvtjRhec4MM125dzhEX7yeRLgFY3Ayejupnh1Xftvc LWsk7m5PFHpB+pUEO0B6sP9dzGfu5UiseFhRETYQWlBjlatuKyljRTkkEchtY8oNQWeyH0viuud NB6nRg5M9dnplaZ5GDNrwgQZk0MZU0nUQSnIyrJRlm9WpqvuOxfb8MoP6t9yF8ieYPOJJrCWjdG bEA7iNxJHgpiBtZTpxPVFcX4rn6D90k6JvBaTYRSxOYackOju8pKSbV85NbwUINs+sdjGMSATnl Up++p6DSqNMufRK6L0rRAJbRi6kUfOBCWgmRJJunkXwSSrCtKNbVFjRc00CeM5UJbOIylGiQMYm V3oM/1LXwAgEDYEPsbe+AyHLd4yB3ULNlIyyridMfEYPXZHU3CxCtrshukjW/hWNQWkG/GidIa0 9UfJMxWncom21iKAYbYm7acIWlFDX4Elgsf94qKZPy+ADfPFhP7/ffB+sPOeLxRkjziMFwJq0rY wAHNqMvfmPnRrwxo7tEzktMfe6E2FY0EgQ+7uOINeXEMm2qzYSDBps X-Received: by 2002:a05:6820:2308:b0:70e:177b:eafd with SMTP id 006d021491bc7-716e78881b2mr244556eaf.16.1793904947324; Thu, 05 Nov 2026 10:55:47 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:46 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:25 -0700 Subject: [PATCH v10 09/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-9-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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]; HFILTER_HELO_IP_A(1.00)[sea.lore.kernel.org]; R_SPF_ALLOW(-0.20)[+ip4:172.234.253.10:c]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; FROM_HAS_DN(0.00)[]; RSPAMD_EMAILBL_FAIL(0.00)[jameshilliard1.gmail.com:query timed out]; 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]; TAGGED_RCPT(0.00)[dt]; RCVD_COUNT_FIVE(0.00)[6]; DMARC_DNSFAIL(0.00)[gmail.com : query timed out]; 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]; TAGGED_FROM(0.00)[bounces-27268-noreply=patchwork.local]; FREEMAIL_FROM(0.00)[gmail.com]; MAILSPIKE_FAIL(0.00)[172.234.253.10:query timed out]; TO_DN_SOME(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; MSBL_EBL_FAIL(0.00)[jameshilliard1@gmail.com:query timed out]; 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)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: E82651C5396 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX ECC exception mode recognizes physical all-zero and all-ones data blocks. For each hardware ECC step, a pattern-found bit says whether this happened and the corresponding pattern-ID bit distinguishes zero from 0xff. The correction helper checks the current step's pattern-found bit but always reads pattern-ID bit zero. PIO processes one step at a time in hardware slot zero, so it is unaffected. DMA processes several steps at once. For example, if step one is all 0xff but pattern-ID bit zero is clear, the helper treats step one as all zero. On scrambled DMA reads it fills that step's main data with zeros and reports success. Requested OOB is also filled using the wrong pattern. Conversely, a zero step can be classified as erased when bit zero is set. Test BIT(step) in the pattern-ID register, matching the error and pattern-found bits already selected for that hardware step. 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 02aa02d2cdb9..e952d7f6abef 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1125,7 +1125,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 Thu Nov 5 18:55: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: 3882 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 B381B1C241D for ; Thu, 5 Nov 2026 19:57:23 +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-27269-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-27269-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 3D07A28AFE for ; Thu, 5 Nov 2026 18:55: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=1793904950; b=PoVa9xAXbay4d3xkRtd/isL/Bra0yjo+XmhBfDkyAdcSdA3TwdOEIMbownLqVTyU3V5g FTiZ+KPaJfj4cFRALHX6ajVQXMpv1kGdfwYS5+0UwmxjK8MttmveRtFCP1SVhE4sw4dGs zbRMcuzvG6zCrPvj/hc6fTCS3AfC70fMw7NH84i/QZm9t34zflLa1HvOmkdIIDqaGC7sL ohWqO6MyJlZ5cnYNhVfWG2djRR+WaP4rjzttZy6x8LbGZGTP/Ddr4drcHbLb5a+2OcU5M BHnMHAiV4KnBZpAPEfXVCYC/PyaguhqV5RLalROXkE34h1cSCaxMkhutU0Dtk/mTfmQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904950; 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=BTl2XZPhy5va2LFZZWNF4agNgxit/6PdmaEnjIQ29V4=; b=2wwpKy5RajDdAYAHey9UuUiwbeefgaxJijpmagnJGJ7CL5aXe4sJNGQwmAZk5f6Zk+vF nuh0D2+K5WBpu2fJQwfcDZ2NioTTutR0QWaXKF0v0p2On6gNeYpFP9sJHK3V0G6ZBEQMV l6D53NFURNHTCCA72ysq8SZTBbGu3D39yISOf7KDP2RyRVbDWlMlLI2XBWhavMtQcxjwP 6Vxs/3pDVQWS3ENtZkhskoEzglO7vaJziNRA5ZUCdk/yLA/v1taM5uQbr8FQP0qz1j55u aoBQF8QRoIqohpC7Pxk4/KJfozhtsXoWINGnup9csazOFG9jDlFLhr5EqdyZQ8lDNJA== 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="h6/FWWi9"; 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 22087606D811; Thu, 5 Nov 2026 18:55:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=h6/FWWi9 X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904950; b=Wq07KBT46pts609ICRWv33JmWmuwYVXJBWWNoPWEVUP8myw1XgE03oKxaAYWxUvE2H38 fVE6wXwxwvdhDCb1M6nA6K0WNxADMNmrxmfWkxYH7tpfOL9B9U591fDny56GsoLnQOtV5 sNebz6q+EH/FcVPoZvC73FckXoMvHSXqYWaGmW1xnPXY49uQsB110+n/J8B4ah/Ap62jU Yqr/P2cNCpjihxHndEfWQq6oZanreS7CvfwU7gqjEQsZLISxuGTm1bP7x84cm39aUCOrX wF7+Whg8FBO7GSfRGar8XMlONJ3AHm7jLE6kktJ4hHNCxjPJhBNAv9NyLmIVbr9b82Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904950; 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=BTl2XZPhy5va2LFZZWNF4agNgxit/6PdmaEnjIQ29V4=; b=QifKbcTyGwhkpqFJN4juoWQnEI7mZHw1vu5qylJNuQKXrCr8j2yE2xFqTECrrQR0HH7l A2osvTkooyv2eDnaBiCv2IzvcaUj/gdA5eUhK7uDGgazhkPmqCRbMcyUbRku1ySf7JPim qI2TKpOp45fTD6oH59svr2vpCG7jO9/HF5fscfMnWA7Lb1CE4NHR2+0hbGDZy7azdG0xe HVk1bKPToj4U/cB/6JaOot+GhAHWHSO86QL+91Zjmaeya9eIdOHL6b2Z1nwom5IqrdeC3 nP+zHbvSVLxwV8ckb0TzaovJ/VFLyFqIsnQ+Pi5eYn+7OGmjFpLW/C6irNaseGtoS5A== 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="h6/FWWi9"; arc=none smtp.remote-ip=209.85.161.43 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (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 AB393606A336 for ; Thu, 5 Nov 2026 18:55:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AB393606A336 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-oo1-f43.google.com with SMTP id 006d021491bc7-6df5e315bd1so1891499eaf.2 for ; Thu, 05 Nov 2026 10:55:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904949; x=1794509749; 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=BTl2XZPhy5va2LFZZWNF4agNgxit/6PdmaEnjIQ29V4=; b=h6/FWWi9gCrCgPwyDgHERAragFEu8ncd1Un3n354F4ueu1Wa447bY+bfWwnVD9b9yI f6iaHDHvnJtYzX38F1SmgxSV2EFfqsWFvv09TZOhYfkqCy5X+l/64q2U+HKtH/blk+EC uHj46uoqGB5OR4YpAXEeft0++drfR8Tff5sBTnNx74Xl8dOO/gEoz3cffIMQT3TzIZ4W pQV0mc1xHsYtE+hqtdhY0fvzZ2hFoU1karCzcvNZf0pMDWN0l7+hcm7iK2rcYqtqYZn5 zwq0slkTxe3PtoZGdl00N2QTjqx8klgUpqYxAx189A5mYESoiO+XpokGtY+tozyczv4o IDqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904949; x=1794509749; 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=BTl2XZPhy5va2LFZZWNF4agNgxit/6PdmaEnjIQ29V4=; b=VYY0kWlTqBxgeqJwL0hSaD5n5p21+hUUVeepOp56QKA2HLw311GAbmLjcMG0jK69GJ Ff9aJvko9fhECW+PwgEu8IaRMFure60V7qMsSbtHI7q5LKX8pQGfLQgIFJdt7Aa7OzkQ GESyGawi61w8HwYf2MO55kcUzmOKSiE1SKL3lTUs7Dy6HkOdfaURQBI9Ab6KqT6W6wC3 x4jJy4fwk+QleZMh7SxtOlR407T4DIxnwo9t7W5mqRwYQVSlCKL6zFvMz0huFzLqQYgS 2Tqh3D5G7t9P8cYKwQUgYVF8845uUqBBXgcyhGkgE2NQJbI6V2i0GCk6z2YS3VLAXaZp bCpA== X-Forwarded-Encrypted: i=1; AKwUvBz1ICzM1xA3qfTrIlDsEIlFEVAdoxARwimAQ2fRCleXEDDR2hL3kNGDnPX9oyqPAlndKQTGw6j55xdVnA==@lists.linux.dev X-Gm-Message-State: APuU4Z9UKqsUyI0XuObODcxDeJa9stK5UAXfIUhGTXpPJjm15S9TzDX1 pqEG+7rotREDHrAl1d5WkGhuGE76IEMeDGdzYdZSaSYasjIgAnSeoJIT X-Gm-Gg: AYBFou0y96u5VnTo9ncMEjpFiP/XLUC22IYtOshoWc+HLUHche2VpmaszWG4u3Q/GsS iMJ+tNFe3F+8q+pIo2pz35UHCK/RslmLUNiqnd/brhZr6CsKyrMFM7sh7tMfixkoyYo8PllWvtN icpu2rZ39wn8kV0wueSQpu04EmW7fkbAMmzZDPySYbTZ8r7caX8XMkolrZJeht0jm80eXeErPaa +ppKIvQRUxt5CgIHsQaFPmB50U5hUOMtPTUstTa1gJuHxRibavZ7p3o0yqtU3ctd26eeK2+h1Ah s+iZVH1aCpQe5+Y2RYdJIKRE6fMOALpQnUsnjsibxXU7CfFbNT15Jsu5Bpsw9D1bvuc1OyvE4Ex W3yziw2OvoaortalJeR5VpFQbhmBjw8xrHJWB2A7Ay7IIQg5JyJw3b+4E2Lj31uOmWut7zzBIaC TKqf1a1EvgUOqLCyLCVKvJZ7CsEZbYbEot6Pu0q6vUzPVQyv/qpjJyEYr+kaF0crEmcMJiIOice iWKRhnV+U10vtapJyBU/YMjC9VaDh4AlGuJxAQarcLLOnf7S/E0em3Poo7ko/pM59GGLJelg5Vs 9Sc0cNteIdhmqYHqoT4LCBWlWEwsMSfFtruU19aA7OCKTmexWeEsvXyfsxCwxWXJc/FVcMWFAt2 ubDDEUFwDfduMe2PSN76PTxxtlxQmNh0XZvG3wUEwH4u/he/ENdBdOK6JZ/FqZxw0iCBnBUGPEG D1pOtVzycIwQdDeTMljtgSltTjMj+kWem5KtWvrBZknDoTdgJtALcn X-Received: by 2002:a05:6820:824:b0:6e0:fb60:d5c1 with SMTP id 006d021491bc7-716e744f8bfmr419274eaf.11.1793904948781; Thu, 05 Nov 2026 10:55:48 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:48 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:26 -0700 Subject: [PATCH v10 10/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-10-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; RCPT_COUNT_TWELVE(0.00)[26]; FROM_HAS_DN(0.00)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; TAGGED_RCPT(0.00)[dt]; FORGED_SENDER_MAILLIST(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; 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]; 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,209.85.161.43:received]; TAGGED_FROM(0.00)[bounces-27269-noreply=patchwork.local]; 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:+]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; 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: B381B1C241D X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX ECC exception mode recognizes physical all-zero and all-ones chunks. sunxi_nfc_hw_ecc_correct() fills their data and requested OOB buffers with the detected pattern, but sets its erased flag only for all-ones chunks. The caller skips normal buffer retrieval only when that flag is set. For an all-zero chunk, PIO therefore overwrites the synthesized zeros with SRAM contents. With scrambling enabled, those contents are descrambled data rather than the physical zero pattern, yet the read reports success. Requested OOB is also reloaded after synthesis, in both PIO and DMA. After checking for ECC errors, skip buffer retrieval for either detected pattern. Keep the erased flag separate: only all-ones chunks may set the page's has_erased_chunk state, which controls randomization when reading the trailing OOB. Preserve that state if an earlier chunk was erased. ECC-error steps still take the existing raw reread and erased-page check. 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 e952d7f6abef..e79fe46926d8 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1236,8 +1236,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 Thu Nov 5 18:55: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: 3899 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 C19A81C53A6 for ; Thu, 5 Nov 2026 20:02:40 +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-27270-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-27270-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 49DB2339A4 for ; Thu, 5 Nov 2026 18:56: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=1793904952; b=iP+lYE2/HLlIDhuUcw9gcEhH/UB1hncIfqcXnCnSn51+HvRU6wgQCKknmh145IbxbBNj 8lb5El4HWoZFsXmyV3VTTD6xjYER5XPjDTP31MjwlfX0R+XJlIwg1n9xjWsNGRlNs4qIt hrl88QX3VBfRw4RyxKNHv0NILd4BX8sc1wlBUB5NNNq5dtIn7X6GLQgGI3CwEPYhZaV40 N74z/7+ED1Dx0DV8SlclkYdEG3s9b4SmwngVSdCYoryzKvPgAPD7OsuFbq6sNDsRdHXjm RGCZm95pSQtDLC2bXqscy7wjVP9vkVisW3cl5W49tUt3foIh6ysrBu1MHJPh14BlHqg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904952; 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=XYkHyl3rBwV5M1+CmvsGlLn17fsAmB7eIAXV0ePPEaQ=; b=sWcdL2V8pTumFouOgqz9odKqCuyCIBN3QpGlVpJSHy/EvJb+Z9xxrn9rJ8IrKhTiJmN/ faYGAbfpNz09eDaHDSVrqlSk1vbcEu7sRcvmHJnwXqNAfXmKY8a4pfp5why4iJvUP61QW t0NNE1fx6MGB7wEMRyHbjmMPmEwF66ueZ0MEXhN3jVDUyhEk1/pEb+N7h/SUDk8cBkM0F 3CbSq0L7lTD7eeHycshcfznv50TKxVrffroMW+ra1KOr+sZW5bNAHgAp8sYN7/on/thFk /sK1BM5MJB1bxcrr145MF4AbY0fCdE4ft+vAaS/c/52AA2Ec4O/nHfVG85t/dy1lvpA== 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=qvRS0+wH; 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 EBEE1606A31B; Thu, 5 Nov 2026 18:55:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qvRS0+wH X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904951; b=fszrF/c6HA+J6YZJvvpkC1rIq/kuw5f8iucn9PfymPBZ4AT/++canGacLYeeDZTNK6kq Qha3GE35w2CQ/0w5KGt5lgV6Sh9r4WZCxoeghDD/gLdcrk+NmbsQTOC/Yod18PZWRGDUW nEY95zB01GQr0j9MwzWf2o2y3vkf1C989x1S4bteEpwehvd86MHWA+0QD1q13lK8RRFyO iQEMxby/rks4/6nj/nRvmoI36ejv14f+6+Zp8MEwQvG08TLkTktZtA5VjyWl6uXtB9DTP VzO4Z0F+vHgETz23pvEIIfmAGeesS/381QGfn3tTcg3aT7Ra8Y4PBtPrnhmlQpOjkhg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904951; 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=XYkHyl3rBwV5M1+CmvsGlLn17fsAmB7eIAXV0ePPEaQ=; b=AvVkdpHhIusINgKmnw4lkBrLLtH9zCsfbFTnrJLnkSMtjnrxEFXI9JHujcxeeriDAfXw /DZ7LGEfs5W5EfWNe0byi6dOwWDA18EiarkrO9R3pFPaPVGqSFTDBAAmp/LmqDkmvjJGt +QVsPu9EaqC02ZLNxmTTOM2XEghk9DUYUZXnMZFcnkl6wJLExrTSDcR2vF7cah9Z/eALf JjNC6LZuAlLsiUhyLKEtT6mVQAt9C3fWkI6vmHb1slnKWZAZZVjrkCd7G+kq87uS71oNo zhTLKyTjLBpffNFYUJGz7H9Rt1tkl4KiP7D+kwUfuuP16TSXOl40Vvd2CNLbR3bs4LQ== 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=qvRS0+wH; arc=none smtp.remote-ip=209.85.161.47 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.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 66D8D606EEA4 for ; Thu, 5 Nov 2026 18:55:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 66D8D606EEA4 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-oo1-f47.google.com with SMTP id 006d021491bc7-6deb848ddd7so1606175eaf.0 for ; Thu, 05 Nov 2026 10:55:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904950; x=1794509750; 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=XYkHyl3rBwV5M1+CmvsGlLn17fsAmB7eIAXV0ePPEaQ=; b=qvRS0+wHdgerhESLbmjnPb9Q/LzM+YAR+EDqcst+8FS7VR3d+umxJPoCU+TSahqze3 9o0sBCqM+ncSxqTSI5an38vIbfl0do9oeIxaRjpu1uXXxgN6RTCltzh24PFscuL+R0DJ L7nhSK+RpzgI0RCu3CCntyujWqpfJE87WUUjCAkt6urrpVx6EqqWRT33S5LBTQUYAv1a yWRQAT15No4szv/7ynqP00L+KlE3eOv6O8224uB/vCednE0fcu/FyZcbUJ5454/zdNci PQLXDU7gSnAgWpdjwjKY4/9JE4Z1/YscBxFqj9mMFhoqf4SXzILOuzRnEOEDsRahJeov htBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904950; x=1794509750; 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=XYkHyl3rBwV5M1+CmvsGlLn17fsAmB7eIAXV0ePPEaQ=; b=CRjnQvhK7j79meNvFvWUx9oENI56mS7yZmDYaHI6Sf2sXurhJJpFuL15ghd7pt/FLF dWjc0cPRUl6SL24oBd/RJ9PckVght1EOBLq5YUx77h/uB/XRb2d9TJrPlzqeqTzrki8+ jl8SAgQWT+WBF2wSrku5Gb7wppxrmKEp6vSlT6m2DWLNvGDrTh+jMAsJapcx5oe4rKrF R49jlkf9pudmjNglSx/6ddldm52CHUdVg6TUWfiv9P3v4UxZIZ7KGP7D4vHDpI+vLFHk f/AdVa6Gdfu0dZpDkMSDzbZ2+MkfItcmT4ZbNLNofGooOTn46ohznXhBLWlvLpsf2SVk KcEA== X-Forwarded-Encrypted: i=1; AKwUvBzhysqcGNLI6zoQVT66W/kKNISIw+sjnsmGFOcU0QRDW17JV2/jfwGx0fIOMmLVQxXz+wyuqRyt6vT/0g==@lists.linux.dev X-Gm-Message-State: APuU4Z8Xo5YBCEmfWBETFGKwf9yZyscY9Y+UnHFdXalLRzxXbDnDfN2P sLNE8cb4/jm+cGtOmgKYU0eNI6hu6KKBLCzInFbBkktD7Wet3KxpczMK X-Gm-Gg: AYBFou1rObqs4BT7kpVabGWpJcFBkfcK0GysvZrieCev1VAUAHuaXaFmnlleMwmMugi E3wikSEGeYLNKg16Jd+CfnDDCX3JSw4kdT9UtiNdHCvaMqYtHfywhqJEWorQ1M/vaxNEujkokfU Fra/mv5psE8T8rR63bp6pJI5pBymvftOWesrReSCRs/Uwx6QcVlhng1IT4HiaHjZOiM0utoJFF1 76iC9IjIUzpJAIZLtCMh0aHhPo2cGYNQFvCbEk4k+M4AY8sgjo+BVSXErt0W1hsljI2Q2iisdDe hcIekLVU8fLYQjFGqcd72agSuuaKDiSe9Cxr0wXQpFnyCGMBI0IH29QTZRCuwNPpzDDNyUwLo3Y EKiUJB/UxzFD8/MGnTOgKstxxu0CX6YFk9HSFCWj6ASC/XWzHr/M/tp3VIsytIo1yhljGHhVJVV K/ntEQbgw1pG3XbsFCjncVulG1VqHyJ9U+dFCFIo7yOpoW6LB09ZlWFScYqs5r2ytf8gHcu9GmB OEmZf33iA4n3wGNFr86fu5oWGjSBRBsEfQJx9ZMOWrzuJCq4xQACncJ4uydc//5PBxGCu7JtqOQ dU/MnweFcwhkfBvnatpHVaFgL+H8Jj75rfa0+ct0Iv8pfu322cfFUJhTOyBmquBvkoFvfwc0yCU 7Q/tdJGeOa3sVP/jKHm/9RpZL/nUdSSiubOopK06M2v1mQVoVtIZen1M/9h8S/QDPZWhYCtcNcw pc+eBuKTPogAFO7KYzcxAq5YcIWLzINJWSwPtj1PiaNnUd1oDCy+Dd X-Received: by 2002:a05:6820:428a:b0:716:d1ff:2c68 with SMTP id 006d021491bc7-716e78a2bf2mr306176eaf.22.1793904950284; Thu, 05 Nov 2026 10:55:50 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:49 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:27 -0700 Subject: [PATCH v10 11/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-11-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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-27270-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]; 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: C19A81C53A6 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX sunxi_nfc_read_buf() and sunxi_nfc_write_buf() move data through controller SRAM, waiting for FIFO space and transfer completion. On timeout they stop their loop but return void, so their callers cannot distinguish a complete transfer from a partial one. The hardware-ECC paths also ignore some NAND column-change errors, including extra-OOB transfers performed after DMA. Reads can thus succeed with incomplete data or bytes from the wrong column; writes can issue PAGEPROG after failing to transfer all the intended bytes. 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. Leave successful command sequences and the returned OOB representation unchanged. Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 174 +++++++++++++++++++++++++------------- 1 file changed, 117 insertions(+), 57 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index e79fe46926d8..f003da59cbe7 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -686,7 +686,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); @@ -702,7 +702,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; @@ -714,17 +714,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); @@ -740,7 +742,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); @@ -754,10 +756,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 */ @@ -907,23 +911,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) @@ -1174,31 +1186,39 @@ static int sunxi_get_ecc_offset(struct sunxi_nand_chip *sunxi_nand, sunxi_nfc_user_data_sz(sunxi_nand, step); } -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)) - nand_change_read_column_op(nand, mtd->writesize + offset, - NULL, 0, false); + if (!cur_off || *cur_off != (offset + mtd->writesize)) { + ret = nand_change_read_column_op(nand, mtd->writesize + offset, + NULL, 0, false); + 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. */ @@ -1248,14 +1268,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) { - nand_change_read_column_op(nand, mtd->writesize + oob_off, - oob, ecc->bytes + user_data_sz, false); + ret = nand_change_read_column_op(nand, mtd->writesize + oob_off, + oob, ecc->bytes + user_data_sz, + false); + if (ret) + return ret; } 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); + ret = nand_change_read_column_op(nand, mtd->writesize + oob_off, + NULL, 0, false); + 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, @@ -1295,9 +1323,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; } @@ -1316,13 +1349,21 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_chip *nand, u32 pattern_found; int ret; - if (*cur_off != data_off) - nand_change_read_column_op(nand, data_off, NULL, 0, false); + if (*cur_off != data_off) { + ret = nand_change_read_column_op(nand, data_off, NULL, 0, false); + 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) - nand_change_read_column_op(nand, oob_off, NULL, 0, false); + if (data_off + ecc->size != oob_off) { + ret = nand_change_read_column_op(nand, oob_off, NULL, 0, false); + if (ret) + return ret; + } ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) @@ -1445,13 +1486,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) @@ -1477,27 +1526,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) { + 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_page(struct nand_chip *nand, uint8_t *buf, @@ -1635,8 +1692,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); @@ -1759,10 +1816,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 Thu Nov 5 18:55: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: 3883 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 DA9101C241D for ; Thu, 5 Nov 2026 19:58:08 +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-27271-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-27271-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 BF9552B8E6 for ; Thu, 5 Nov 2026 18:56:05 +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=1793904953; b=Gxcs4SO6mM1Szzs0/VOiF12HmK3FH/V1cwnSNfDsa7uTkrWA1/+omRv+TURfWoGgKaqc su1SGdjO2cLHl2gYSOU9uJFuqKdYzTRXzpwBt+JuGqvlisZEiI08km11yKtbHrQjnMHAe kZZwbZfaVz9jSY3ujk78yW1FmokVxbMk4/FphqKxXAyEC7IoW/YOyqMwT2wOAkEXOXxue UNklI1vXqHz1g+uVL3jlz5P0CiR8g603G2lhuRbeNOKnKF4U+AVj2hBlZJKpe81D8bzUj mC7jJUTVgKzTmPH/ppVTry0IkhzWydWGKyw+IcLaPV9HjzsuRldu3OaAOvt6Zs+AVMg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904953; 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=9vgROzYjn2zK6ttGrhZKySS2hmoJVCYg6HGqDUPiUOs=; b=yOii7luuag6QHYqTHaPoJSauJTKuAaMlCcEf3OQVav5tDv7AqfG0HYP+qNL65ZQunjwE 6TI1ntoNm+5xxScB0fEnf/8zFBpwA6rLbpBZJ9K3SPiDjEVlTGxo/v2ocDvatnNOdFHeu qqY9mveGW+CUMcTD7EW9q3AJlNIURqGWnlwlwV9B9XLclK3o3Ygdzz4do7N+YBbWTSBda aYWMDvsBWXQsKj4HD8lFHczUgzgLyNLU1xvUkfQeMPQEUeARzmlYucTprK7qkxicbFMQV GKqRt+eiRKQybFXjV95KiBZkV3un+gQOVB+NSA8j/Qoqg+/xkyzDyeXfDL0ZK0OAx1g== 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=PgAYxEsY; 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 70A34606EEB9; Thu, 5 Nov 2026 18:55:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=PgAYxEsY X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904953; b=mgVplFFpFZ1JaUkl4j9J65/CTxkw1nsgRUT3PFrLtl/BbkEZx/YHqIF1PGCr/5pQQBw0 K1JUk91scCDGAU/pp11nVcPLNB6syy9HWmq+KQ19Ou1uA1BJzQP3llgKmEOGV0DKcuDgl Obb6Fv7GSMHDZMOO0dUoqxEebu+mvFUTBASWnCgH5IaT0FJNAF9zHrafEXR8lkPFH3bHh 58Y0R/8cwwtzAmNCnHhz4hkmQJRYvz6HlblkVJwZxb3z25FmXykBNhmVGNAeJ75N34vQ/ 37Q3WYHlH8heUO3ID6tLv9K3uEfF/IAtr/d4Qj2XfYysBgUXe4ZU5QjMc4PLnhnpI0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904953; 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=9vgROzYjn2zK6ttGrhZKySS2hmoJVCYg6HGqDUPiUOs=; b=e7VCUb6YR3eQx6u/ecSlql2t9cv/H88epA6zsWGkLqai0GBg5SUqvs4jAOzlXYf/z9Tj 7b0G1blvD6m67xZwTajgnm6miVGJxybInYH9X9B17biCfGZ0/BA+JNVDmauXm64egi3gC Ea+QR9ElQcAdvLU1BJKaDBmuBCI6KRZ3wo1Kudd5TWpK9mC3lLKXU97qY6HF5LGyuGL4E S8+PiwipSssVD7KqiT+AcmVsLXHNx33pfgb/JB6573hHYssglUcIOCK9TUD4Cq3IBRwzA PhWtm/mCJuRxka/yxS+MywCFICM2/8NqK4FA08yzBKVL4cvTK2gkdDRKooyKEAm2GHQ== 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=PgAYxEsY; arc=none smtp.remote-ip=209.85.161.53 Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.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 06681606EEB2 for ; Thu, 5 Nov 2026 18:55:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 06681606EEB2 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-oo1-f53.google.com with SMTP id 006d021491bc7-702dedeb70dso1295935eaf.1 for ; Thu, 05 Nov 2026 10:55:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904952; x=1794509752; 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=9vgROzYjn2zK6ttGrhZKySS2hmoJVCYg6HGqDUPiUOs=; b=PgAYxEsY5Bct9+wGOMlt0Pvut5S4ufy/lPmP9te5amLdODBz0PzB6Jy9A04ARnvr2p Tq/TelkJgWWL0XFGxhRznJkXis/NVUbDE60XrVKCsQ6cNueFCHP1YuBXs4yyxMztRULT sJlp+sjZ1HRAGWkjZfNoevNOKXGdBnnGTfXmlYqnsx/p50Y24NNpCT1A5UoK5KTh7zIz GUQJmOEh0wB6Nk2QGQcE8VBI29DrCBalMwr0l0BzvpD4zBmxNXAKeWP3sVUfGyeFZSeq eumzZJEgsg1WlifNgDC/q0dl22CIeuKXIKQwpjpmpVv7F4aKH8xXqUDtHBNveF/pVOV4 WktA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904952; x=1794509752; 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=9vgROzYjn2zK6ttGrhZKySS2hmoJVCYg6HGqDUPiUOs=; b=nsbMTl06UQno92rDEQnIMDKVn8XlPyV2gPo/z13pzRjJ1407RFb+/yXTikON/cVJ8B 12AkPehOqzmp99pC/ip+45em3WMcEdZOt8AzSpKQC/yu7+3KU3akxcT+YUlHWTxYE4yp 3eSZZ+VDrmr/Sqy8hfViBPvf9J1zbY1xRh4kW1vUOs0XIaf8443PNUAS4uekPLER2Pz0 7q9tbUIBzIOUaDFLjqLu+Odb6uv+yaj5cGyPxW/qoZi4VMuHpjqqBjUuEX/BI6RJwf/G e0hfEoEqqT2ZomxtQdKNqMKmpsRT3oVc52fHNPU5msVIckeBggVhT3RsLRp+u6JQqqBy ri/A== X-Forwarded-Encrypted: i=1; AKwUvBws3j3gyidW3kwspMpSBFP8SDZoa/TJ6ULiuL/k4cgIzWjMBRDtCTOuKmeP1RF1XqF4iVLqur6olLwfPQ==@lists.linux.dev X-Gm-Message-State: APuU4Z8cYfaA94XC1r44bjeLlPvu//TbpVWnLkx6kx0MfMG1XM+qGsKA BY16o/d1+EEZLc5Qullo4r/0iSt+8Irl3OxW2VUpxOIxAOXiohrAxFUj X-Gm-Gg: AYBFou00Phppbbw/ZdD5jnqKzYwDetNmPIdFfjVc+PD0fC5Z+sauG0gZ0ooKKDKU6Iw f5Ahqv4Mq9IjvUaNNFwFHg4ULcn6VqgQhPvrm98qtvaM50eded8oWrxnJyVk7Fjn+sgN1nzw+AV b/aFsiaACDBw8jbk4lCd8CMHu3/RCofR+tmBhnwK2jLp7ZfAsS+2SSSyz8ZyGCZacwPI2J1nBNu XZaCcqBKKCvXE0UhivSivfzAeFpGeCXnfbf/QBItpJZdV+3avPqIpVvb5eyK32twFMQjySlpsF4 dX8i/NUCuQTY2SgeMqTopurlLEhI6zbEAFJrGY5GnSSPwvPKz6onM7ZL3vqtem3n09OkhdmlcMS uJlA3CSwTVA/Ujb9AyKBtmhNCId6j1gpq8sKA7TH9bz73H6CVY36QM6j9jEHvUbtoCmVXJmCsDU hlrSyORiX8ESGMV9KR2X8RCOe/Zows6uuxVLpAnm0rvJ67luABqoS98uAoU58iTsTcM6ZLlPVOA rpzKkQ3FjLLSsVNq4V0NulzABi6J6mUr07iiOsiZKU0Ct6IaJZpXuii9spD+OnI4aiEaB0GrPs9 ATBlTt0uxZLk1kNX5gUBuqjxkH1YP72D/puH9sUS0W1OdbT8t6TQU4Q/HqvdzekTIVIhzLFSIw0 +O6tTX6yLHkPyemzvl6IMCgDrV3EqOSWxoOW5zx1FtYtoqFoPUs1e/aRrwSDx/s8oN23ZC29BAO DIffiom4BJ3QYL9Lb6gMDhOsdXEBqRP7cizxsvY7/qQLFBQuhLSYzulQ== X-Received: by 2002:a05:6820:c30b:b0:716:deda:97a4 with SMTP id 006d021491bc7-716e790f945mr252144eaf.48.1793904951958; Thu, 05 Nov 2026 10:55:51 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:51 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:28 -0700 Subject: [PATCH v10 12/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-12-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; RCVD_COUNT_FIVE(0.00)[6]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; TAGGED_RCPT(0.00)[dt]; FORGED_SENDER_MAILLIST(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]; 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)[]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,209.85.161.53:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from]; TAGGED_FROM(0.00)[bounces-27271-noreply=patchwork.local]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; 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: DA9101C241D X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX The hardware-ECC OOB writer fills the main-data buffer with 0xff and calls the selected page writer to program it together with the requested OOB. Both the PIO and DMA page writers already finish with nand_prog_page_end_op(), which sends PAGEPROG, waits and checks NAND status. The OOB wrapper then calls that helper again, sending a second program confirm without another setup or data transfer. A failure of that extra command is returned even though the actual write has already succeeded. 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 f003da59cbe7..5f57c5998f03 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1841,15 +1841,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 Thu Nov 5 18:55: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: 3888 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 5D82B1C241D for ; Thu, 5 Nov 2026 19:59:46 +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-27272-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-27272-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 7ED6D2DA86 for ; Thu, 5 Nov 2026 18:56:22 +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=1793904955; b=0BM4e/A1nqahikdbwePxv+onjn+y4qyl/HtW2zR/hYnk7J3/qBE+rAtqNa7zqKxtPaIO l4PKoukgQzdFyoc5afhq1xX35BxEXAfVWlIoszCmRb81z8IE1SAMJNpGr/BX0ro5NOq1j KPBqFMwGL6pU7ks6yB6WjME7Oxa6Xdf/Sv7DUOkrR8XJZph4/oAIOOjsQ6dKEvaWidp87 PTbhiu1FL5SG3c6ar5ZjhUynwSZ+qAOETPsb7iEItNbZrK+UheWpQf9z1K2icxBB8Jvpz G+k+P56As25P54ljwsJbKM8pCLd6ZDhuf4ZwmGSegGuRkptbtdW0RP4N1xKPshcyaHQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904955; 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=TewWxDRlBExCimd2doTjt5ku/ZOc7YaK3BqCExDTIIk=; b=tBnFp7YDh0rlzPwE00ZoTRQu2MOucTa8suY5oGYRcTC8F+FgSt6pgIvxm+xJ8BoCRhOR +y0pOqS3WrN+EBixHAe4iTz6i6QcTxtFG1kpCrZJIJ5EUTgb3RgALw9AXyA9+AQdwoW7W PCi+jZo3X79OTKtPLCifCzOPlPQ//3Q341BYGP/Y8vC/2kjRfNywNNucMEuLxqeZCdNVd tYa1evT4KeZpIWQrt2i9i7p5o5p0mPh9NkEMpqt3A6rNl/QKCVbBxF0y8YAn73cD1u24f FgvkVPe+5J+sJO76tD+IvHMejZnC8SfeUMWHFcJc1joMqz6ooWS3IpnnUFY+0zfuktA== 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="d/v+FahZ"; 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 0B1A3606D820; Thu, 5 Nov 2026 18:55:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=d/v+FahZ X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904954; b=TcRDC+pEjdrQOMJ0onYUNrjC0dvPpSIjglyGMGTTJMDXRUD5YrfNjh3FIzS1kO80FJBF Km9MhZobrfMjLd2UrFWnMxxL99ZxUXcCPsj5zPQYd/lC5RF07okdnuPBNNs2KkNqXAe88 mMksYTT3+HniT4cnCYPFS6MJXc0lWl9f6f85D6bvpoz8jwl8a1CUkfHirjW4Vx5csTs/9 X+0ArAKyC8PG1m0w0G/fX0w038YLV4OWhw14da3lL7PiHru8U3cgNP7q7Tc1bt7G3TBu7 hZPmYRKsyJ1lO8G38rMKCnX8QAUHgN7pv95tfB8nGUioE9L59dBvTaXjgdLPBZxj7EA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904954; 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=TewWxDRlBExCimd2doTjt5ku/ZOc7YaK3BqCExDTIIk=; b=wgcHMv8EwpYrhg55ZwR92rWw2lZYIlLwKj6foV2qbd/JKbgynemPfc50cQM7qrRypy/h N7mNcFwiDLXecFjSm4r9luwzOrKcAbLf6qLhbSVJjhomk07vzwFCR5reYVZ4K+QcU/I4D CuFyuw15lyju1+DiAjjbwvsGdDzWoAAsaS4q4ebwvmXQxthkCby6QoW6LAPW78H1UWN0V 6XndVG4HRTqbL7Mi5eSMI6JkMyrBLsV3HVzBTEjHu3gXv1vyZsGq1swIXrwQyCl0xZUVt 7xIVOMXXW+PGvfthF7SYN6Zn5GdjRntOIs/NwhPF9cKR3gouJFfgPru07CUa5OA/qlg== 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="d/v+FahZ"; arc=none smtp.remote-ip=209.85.161.53 Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.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 91E716082BCC for ; Thu, 5 Nov 2026 18:55:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 91E716082BCC 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-oo1-f53.google.com with SMTP id 006d021491bc7-6de2f213b7aso1047859eaf.0 for ; Thu, 05 Nov 2026 10:55:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904953; x=1794509753; 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=TewWxDRlBExCimd2doTjt5ku/ZOc7YaK3BqCExDTIIk=; b=d/v+FahZhW7GnTuC+eaQgIu7UwPOo0PzDvbDOVLaFlajd4m7mrc2e3CgxZHRWv4j/I aJRodNTm/zRQl1bKhpHnpBHy06fmSkAymLCDBf9YSzdcDCJ3oEfUYin/1HOiYaOrkjuP H8EmyKxP2oTPtmBcTneOd2mljwmU1xWNP04ViOYeSWm5RmNZYAJF32N8mkdgZQ73uv5Y 7G/QlhvS2nG+31uNgp3YnMm49Ha6uzJmsoL+yXiphs2InmYw8OrRdwlqjYRrUHddBA7S XNxkNfesz2HOtA80Ey4HF36bDhV9OFr1Y1wRocgwTjrLLgQfd91yqxVK0b2iLGOGQMgP nKfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904953; x=1794509753; 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=TewWxDRlBExCimd2doTjt5ku/ZOc7YaK3BqCExDTIIk=; b=1z+7J1sosGC+NB0V041/GL+vfTFK/T6KO9R/3ycmBKKx6O/8SBSb+oHwM8D6zB+psg hc9HVPw7WtCbb0A98x6f78mxEpmC/1a6pX8inCYxUHg7V0PRKXLYCfzjEVWDybRbWlwC 1DbyJDnI3x5usUDJQGLPYVulWedgqMd1/OZro/Yu82t7YsfRMUvcieHbIes6kPNiMAdw 5AN4HJDKGMK5CAXMEGKBIKzoTj1l/wt+7eKXgmCWwiWaGfmKqyuRpNNy4k/nRtx7uqNn hW09eotBr/l7S3ZLiFa0sBfKc8sBzPddJIhQ8RVXfKR++8GcWHtcYXymVcch8rk+jxjL YN/Q== X-Forwarded-Encrypted: i=1; AKwUvBzPRGKG7f9N/mMhd1GJkCXE2MdCOOGf7fGFTbjDpUeF/ueK6fJdVNH/8d1p2XE9DV0ZzTSM7/PswvCxeg==@lists.linux.dev X-Gm-Message-State: APuU4Z8ZNvI4XKE9Q2vFy3v9+itxfW3NFXtq4hvot5GDkJhNbSPzQeKH nmYlcc6OSRKlK+f3qxxOgJsQDvVFg0+odvgj02uLk7PoxeP1Yxxaq/G2 X-Gm-Gg: AYBFou0rFbHWruQ1cO6fomGQ9uHMFtiuhv9/OzjTEG1a5nVpXpsFqxGL89or20NWovA nL8zFIws7p7atDQZltyEF6oc5uBxBNRcBrdcqdZRIG8Z66cibhhvgyYN6hr+YmZiqfKX9sD/17b Dd+7uXCQkEppf720k3FcIWYbAoNJtQ/aQDb2ndH4gOB26AVRqeGmc37Y0yd+FauT1wii/zqMBvr fXU7ZmeyKAfF1Hy3brnIALJqIJJdlPLtV/kv4ORYJEzMOC5fhLCxAzhgNhpTJNnqf67gr8iaJ9F A/xNGwk1d++y1y9WvKPrVAVAU7OYsazOTJWc68pjC2tf0nD/+6bFnwC/xG/+q2BfrW91EIVLgEk /c+sm6YKRf/+FZryi8fT7lBi3D8FLa4bIzqt1vJNm5Yq92aEBt6LW/3n+2wP14EUjN6B+s8pzub tsIVz4Fbo3EQpR7f7yZ3o5naijzUZhlbNH+oiAtD68o8LvxrpjlIYVMk8EPTBfjfhVg2cfZ2kq9 EiSvp/H0MArRrZJsSl/KAR70HmV4XyCyoK3hAPViCsSjxraWV6dHB3aL3TcSKJPbdGtotrnXdsi rrZbe6J8uQvjHgAfnYTmXRTRZtJx/pADRIvCKFqg3TpZuQUuOorV1HS8vH7wLk3CbnybNbz5zQp 0dnN/SJ2vmxnNOeQivIcdY/R4K0rHbp6ULIwGctfIo5A80xc9LVwN7HNONAHn4MfZmTQKQ1Hybs X28IrDv1bFhDKvii3Og0nGLEndfqEHbXroPDUvRAXb+poaj17a7SsI X-Received: by 2002:a05:6820:340b:20b0:708:ccf9:886b with SMTP id 006d021491bc7-716e79e8540mr267932eaf.84.1793904953478; Thu, 05 Nov 2026 10:55:53 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:53 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:29 -0700 Subject: [PATCH v10 13/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-13-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; RCPT_COUNT_TWELVE(0.00)[26]; FROM_HAS_DN(0.00)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; TAGGED_RCPT(0.00)[dt]; FORGED_SENDER_MAILLIST(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; 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]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[209.85.161.53:received,100.77.114.92: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-27272-noreply=patchwork.local]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; 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: 5D82B1C241D X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX The hardware-ECC reader moves between main data and OOB, and rereads raw bytes when checking a possibly erased ECC step. It uses nand_change_read_column_op(), which sends large-page random-output commands and rejects NAND pages of 512 bytes or less. For a small-page geometry accepted by hardware-ECC setup, these reads therefore fail when they need to reposition, rather than using the small-page read commands. Add a read-column helper that uses nand_read_page_op() on small pages. The core selects READ0, READ1 or READOOB for the requested column and sends the row address again. Pass the page number through the erased-check path as well, and preserve errors from the resulting operation. Keep the existing random-column operation for larger pages. Select PIO for small pages even when DMA is available: the DMA PAGE_OP sequencer uses large-page random-column commands internally. This corrects read-side repositioning only; the write-column helper still rejects small pages. Software-ECC and raw callbacks are unchanged. This is a command-path correction found by inspection, not a claim that ordinary 512+16 NAND becomes supported. The existing controller-ECC limits still apply: it needs 512-byte ECC support and at least 28 parity bytes plus four user-data bytes, so 512+16 remains rejected. No small-page hardware validation is claimed. 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 | 40 ++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index 5f57c5998f03..931d437e196b 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1077,6 +1077,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); +} + /* * Return 1 for an erased chunk or 0 for an uncorrectable chunk, with ECC * statistics updated in either case. Negative values report transport errors. @@ -1085,7 +1095,7 @@ static int sunxi_nfc_hw_ecc_read_error(struct nand_chip *nand, u8 *data, int data_off, u8 *oob, int oob_off, unsigned int user_data_sz, - unsigned int *max_bitflips) + unsigned int *max_bitflips, int page) { struct nand_ecc_ctrl *ecc = &nand->ecc; unsigned int oob_len = ecc->bytes + user_data_sz; @@ -1093,13 +1103,12 @@ 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) { - ret = nand_change_read_column_op(nand, data_off, data, - ecc->size, false); + ret = sunxi_nfc_read_column(nand, page, data_off, data, ecc->size); if (ret) return ret; } - ret = nand_change_read_column_op(nand, oob_off, oob, oob_len, false); + ret = sunxi_nfc_read_column(nand, page, oob_off, oob, oob_len); if (ret) return ret; @@ -1201,8 +1210,8 @@ static int sunxi_nfc_hw_ecc_read_extra_oob(struct nand_chip *nand, return 0; if (!cur_off || *cur_off != (offset + mtd->writesize)) { - ret = nand_change_read_column_op(nand, mtd->writesize + offset, - NULL, 0, false); + ret = sunxi_nfc_read_column(nand, page, mtd->writesize + offset, + NULL, 0); if (ret) return ret; } @@ -1268,14 +1277,14 @@ 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) { - ret = nand_change_read_column_op(nand, mtd->writesize + oob_off, - oob, ecc->bytes + user_data_sz, - false); + ret = sunxi_nfc_read_column(nand, read->page, + mtd->writesize + oob_off, + oob, ecc->bytes + user_data_sz); if (ret) return ret; } else { - ret = nand_change_read_column_op(nand, mtd->writesize + oob_off, - NULL, 0, false); + ret = sunxi_nfc_read_column(nand, read->page, + mtd->writesize + oob_off, NULL, 0); if (ret) return ret; @@ -1310,7 +1319,7 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand, ret = sunxi_nfc_hw_ecc_read_error(nand, read->buf + data_off, data_off, nand->oob_poi + oob_off, mtd->writesize + oob_off, user_data_sz, - &read->max_bitflips); + &read->max_bitflips, read->page); if (ret < 0) return ret; if (ret) @@ -1350,7 +1359,7 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_chip *nand, int ret; if (*cur_off != data_off) { - ret = nand_change_read_column_op(nand, data_off, NULL, 0, false); + ret = sunxi_nfc_read_column(nand, page, data_off, NULL, 0); if (ret) return ret; } @@ -1360,7 +1369,7 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_chip *nand, return ret; if (data_off + ecc->size != oob_off) { - ret = nand_change_read_column_op(nand, oob_off, NULL, 0, false); + ret = sunxi_nfc_read_column(nand, page, oob_off, NULL, 0); if (ret) return ret; } @@ -2326,7 +2335,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 Thu Nov 5 18:55: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: 3884 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 BE26B1C241D for ; Thu, 5 Nov 2026 19:58:56 +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-27273-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-27273-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 C13FE290E4 for ; Thu, 5 Nov 2026 18:56:13 +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=1793904957; b=m7oyEpp+tzOB4yT8IieQPlDR9azujL/pnDLMHozU9nbIpMWphIyF92RHpJnEn0tm87ST vN+cG1isDl9nXKbow3cSRxQtgsDAzdTnEV35dPWJ+J6L1cP9+Bn2/ku1asg2ec2X6eYO4 OJH36NBNjM8CTtCM3iViSSKOIijF+fA8126QmgZB1v5mNwMJQafTVlxQTvQnK+LixsxLB lkK9erkI+aJRxXbxaxftsIZtTCCjtr18E7TtzMtnPHySmsdB4cMEdRsnHCERy/mPyL/9+ 1uiLTRBEBFkEml+9j7g9Umtk/4cCw/8EeUOl0cB3QiK88h84OWTv83FxBAogQjnddYw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904957; 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=7DY6WV3WiEqgQ7F1kqyxxajA1TPjQeQG9vUjtpleF34=; b=Z5W1BFyPgNh9NtWdbNrOycie0DxhT7yrIhde2EyLgk17cnUKHDQM8dnHFsYvqjfd/Tq9 xl6p1rdBxuCAKImX6Wk/p5wBgut48YD1ow+Qyh7yoTjIuzQFlgnwilm106I1kBttgL9JE Nxfp/cLKTktsejr+66CDRzLyLOhD0IVnB946XI+HfpcxpepRPfjrHMVndr76j/CeL6RgU vDr2UjHlgOc6X+N3JXCj4Xm2JxMh0f/C7QRBzG0YWtBtBoQ4hWXtLRL9CqX/X+RF0Z7aC HwdIMAXoIZYrkyICtSn8kt71a4mPp/yeJQHHOqD4ZLCmjrWGMQmPa1Ir+lRWMNtL5QA== 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=BrRSFAk7; 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 EE83B606EE83; Thu, 5 Nov 2026 18:55:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=BrRSFAk7 X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904956; b=wf/nIp9OeGB6y7SjYDl5g4oq2xtEse8l2hY4oN6Cb9skWtWtrYMgWGwxKcjgmCb1y67E YJjcUX1ACw7Ot0+o4vlVNQH01siRuLh1ZmBVNBfPEHJCEY0xq3dTAompTNxc9f7k9OF9S FHm0HgNk9Kz1dJIg3NZixpUZyr9y1Pkmu6+/G+TbDzV/pYYzIdnp6WUCvD0X19uI9RBFQ mzm0+vPti/ZADuPYXw7axKHGiaCl0XCtL/qb4F4LEe3diSYvLLHRDqEnWJBiho5Di8x0P hinG02adnDegwwNK3mNa2tbJI2GlxDamkZB++r4iSFAcCVE29HeXXUy7/YotZvf9MBQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904956; 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=7DY6WV3WiEqgQ7F1kqyxxajA1TPjQeQG9vUjtpleF34=; b=tPPb4/cRcGua9NIeRqNzIMQ5YAxBL9oPk6FZHzzZqu6syE8GL46pDNMbcSgL8slFd+lX 7z9acwsv0msFnfRzxNRlexb111R7kxZYWbmF3dl3wjQg2jLpTpfAKVx7k3COOgEP70ddN voJg6W0WezAbIhevR9Tue7CUAn7YB9q9Ek0ALlqHs4KBmwQMB0ds8+4ns2RAXZaTyYxA5 ZAsKD02j46nX4j4uwbWfc5B6DP+gG6yNXMRKczEdBLenu0UKDbXVrfCvXR9XV3x/IG7p2 +lr7zgPGr2oIjRs2OuVp5+LoB0UnUiDYjnfPiXHJjviwC7lXw8LzYKAIZlVnbkK50fA== 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=BrRSFAk7; arc=none smtp.remote-ip=209.85.161.52 Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 006186082BD7 for ; Thu, 5 Nov 2026 18:55:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 006186082BD7 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-oo1-f52.google.com with SMTP id 006d021491bc7-6de2f213b7aso1047878eaf.0 for ; Thu, 05 Nov 2026 10:55:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904955; x=1794509755; 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=7DY6WV3WiEqgQ7F1kqyxxajA1TPjQeQG9vUjtpleF34=; b=BrRSFAk7eivpfY3y5vvZk0WX2jfbHkcOogYZQeJxp1s6eR8JsSJ2syU8UDANjcWGYS cxCAFwczJNpMRZdyA5cOaFLBhKPm6yuc3N8G6+BZCsnQdou/M26zLAw1b1gpaJqiSASD g9n1YRyqM5gtdCyZxHQFQ/f/PdPK+qSR1vQ31ySZJ66uDC2FwosGl8ENtCm+wE/3tGf+ gj0AxWu4XJ1tcJw0wPwtssUdnjIJ1prmKzvOM/4q4A2Y828rfq+fdnlLWb9nCVPSnO2W yLiJwNM/FW+0Tklq3HmmLxUwwh9sMwUvHPS0gekM6DJbG8jrbF1wKzEPhMQGQ3YRu+Uv SBoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904955; x=1794509755; 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=7DY6WV3WiEqgQ7F1kqyxxajA1TPjQeQG9vUjtpleF34=; b=wTvZ0mv0G3KFkxiCcLqXKJsHuquAumb/2yEvsirAkETpcc3XpDj4QknU680WZnXqbq V+GGmpGuKk5/ZaxMAKccx0OLyzvSAQaQulnOxcruv4DCLcVGq579cUaCUG4IPEJvcC2U wprMRdAIc6fx0X3+NEWeMn7p+a0O9Txy4cJSxeqWpue9A/i+KD4LSb/HJy2SAdGHxuWs Dth4LDF9eRzAmIzf6tXbKGaXKV2zfu5bgMzPHJ1ING93fSdZowuSyXTzGelkmJo1TF4+ Osj+en5YCVLyNX2g9GRNqsPdt0lNQpIFYtKK6SgKhlVP7bh4Yht8npPjqblwCQyfKHEF /HiQ== X-Forwarded-Encrypted: i=1; AKwUvBzktujew0ynWbWP8ke6+hGczzguJmoI0tu5ohNn3nv+WTRqJolY0nZd2H+9oOUs9XE2RxLsdbKFG1ym0Q==@lists.linux.dev X-Gm-Message-State: APuU4Z9Izkwzl1V2SWim2FaA1zx9ypBZpsiqrAp5orEERVRlGIIdtsOQ oiwLXejVf9Twk8B2QbzHKdfZxrehuLveCgH+JXqh7t5phjfahtV4mjbu X-Gm-Gg: AYBFou3n7MEF3h4J5WjsCMh4cFoj1sn6L/I6W1F7JM2RPXHVFXSbiIidEiwYD5JMO+V bIJNSMXFIxYcaBDs+Of1LeZC3mX++nmwBiznonTBTLZUDRbER3rJvnxEWv/8a5XfLZ3JQr3+rDB HN6ElZKnhe2BcmfYMbNhSBlYHI5qe9esZarWW4p69c55BwyYhf4B5S4yPWqc/63FwLXmmE9mqpW KOgsZr8bhditXe485HZXYRU4dgLy6hhkBubJ4BkHK7rjUlgNiXMtprAMRmK6PuE00mAyETJpfgA siTk+vj2CYLcAyCKYfVAx9QKDkyH+epiFkfW8v9sxX7K87lIPSOzZ9WHawt89qNdLwL0hmnBOpD XGyaxeVyCcrj2FIO4ZdQhqA0T9sgPfta+AFAh0mpiX2jT9Vtgf1DT2VBDj4nw8bk8TU6oXlrLWF aw4Z0CkI8gKwlw1ZRS2YF5bjAj+hACbxBW8AE8v8q8NVOLqkhp+lHYgjksWopD38/Ft1cw0J+sR hJfiq21SSJhXLjEEOpABB/ouMpLBHl2i9uzEAVrQNuV9iMgIxpBmCIhE8IMKG8vWDosyMCyVtIA 2TNgPp60NEr9DWj8cvaoKjxeiGw9MqQ1Ld05szR+egaNIfrD7MSRCxXEfZI8O9+QogCZqrRbiJw 31rP6zttuWQV0rcS7sI1TmH6yFGwt1Hi89zKpYgjRmnzz7HLXlyvrWAb67hBt19JXPvQDgvx4wv g5pVr5aTlAkb3n+MZePJP6UnNkLqXyyAv74AgcRB/77SOeezUCWe6O X-Received: by 2002:a05:6820:2484:b0:716:cea4:5adb with SMTP id 006d021491bc7-716e796d2eamr247094eaf.68.1793904954871; Thu, 05 Nov 2026 10:55:54 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:54 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:30 -0700 Subject: [PATCH v10 14/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-14-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; 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)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; FORGED_SENDER_MAILLIST(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; TAGGED_FROM(0.00)[bounces-27273-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,209.85.161.52: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:+]; MID_RHS_MATCH_FROM(0.00)[]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; RCVD_TLS_LAST(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from] X-Rspamd-Queue-Id: BE26B1C241D 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 store ECC-protected OOB metadata, called user data, in 32 four-byte registers. The fields for successive ECC steps are concatenated in that 128-byte bank. However, the existing allocator fills the OOB space left after parity, allowing up to 32 user-data bytes per step without limiting the page total. A whole-page DMA transfer can exceed the bank. For example, 16 KiB main data plus 1280 OOB bytes with BCH40/1024 leaves 160 user-data bytes; with 1664 OOB bytes it allocates 512. Register accesses then extend beyond the user-data bank. 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 | 202 ++++++++++++++++++++++++++------------ 1 file changed, 139 insertions(+), 63 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index 931d437e196b..54377f1789a3 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 */ @@ -974,7 +975,36 @@ static u8 sunxi_nfc_user_data_sz(struct sunxi_nand_chip *sunxi_nand, int step) return sunxi_nand->user_data_bytes[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) @@ -1399,30 +1429,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; @@ -1430,7 +1462,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); @@ -1462,10 +1499,32 @@ 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_nand->oob_ops->read_batch(nand, &read, status, pattern_found, - 0, nchunks); - if (ret) - goto err_stats; + + return sunxi_nand->oob_ops->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 sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); + 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_nand->oob_ops->finish_read(nand, &read, NULL); if (ret < 0) @@ -1759,71 +1818,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 Thu Nov 5 18:55: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: 3885 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 3F3D91C241D for ; Thu, 5 Nov 2026 19:59: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-27274-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-27274-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 498962CC83 for ; Thu, 5 Nov 2026 18:56: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=1793904957; b=VLT88Yj/y0F2Uhr0hK6SBhLEr+v0eUcd+l/YNJhADpCnm9CjAfb8eqPoxuLXafFl+pEz P25pi96miiwP7MACDmzcxhGpHd+C0ZBl11qOjQY6/jhocnkbLRdnysxE+AHlXJskh72jR E+lFLNhvoRJK9VQZsUgSa3kE/frF4Gx3TGU1fC32AUKAlJjowdf4nHR999d64fqZkMTKo 6asWDNJZYB5sJjSj0tzB16p8Ufnk6qQFAM1dzr6w9rREF5lnyKGqIwNiT+51fzuaoaBXH rikO0hgTbxDcfnz04oRCAjVH2pT8HVK/1Wq2SizkhcbVukc0nxx3UY+FMpFIRwZXm5g== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904957; 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=GNH0XGnfrH2iAn+70wl7xaYoYGRxFKFBAJ40rbga/P8=; b=gDmL7e3b48YuKGqC0stOAuIik/63vaMzmXJzj0SLr69wCmWn8lpfMzraw1td9htQH+VP OxEZi3ykAx11N6gGzmeSq7rgIAyXlEIgJ5ZbNagGAXVSptAn8tSSaSLKY2rUQCUcoestJ 074VmYPrR07qJbT5z5qiaTXO8+zsU1osKDnfyr26lNc2xQZ7b/BEO5HHh9bLCqlmedN9T HRTzXf+IuZcQnodu4QLAb2qKjn5pYB/65hFMY2jeZIEyfu0ebIroyASt5abYk/KOwms7S EgKLhMqD69PBkB9d6+NRdx7dBAkCyw99Y2B7zXiVc+vwqeKGqSTgo01dnho8CsE9GcQ== 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=qDZfSlXK; 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 9F3006082BD7; Thu, 5 Nov 2026 18:55:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qDZfSlXK X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904957; b=Lq66QujaKoDJ4qdIHAE6z7jdKKJSOpmVdOSSE9Or0fHMdgKl0ymqIl3h9ETa66qvc40j 8yLyNb5bZHstB8O0Ky44fIZIudJdX1MhFhRyG7wxo6QoDWf7HeXrPR3kgthIUxGybaED4 OpwsK+GR6veViNPOl5oFnYnw9qjHP15LOfnIU1bVFLezcj76Po5jMUyDH5Y6xLo4pZO/+ LxNOI9jywUhUFecBYqDevrH5+UO33vlRakZ4WRR674Q+zGV6kMBMP0H71H0K4aosddLll KLn1OkALoL6Ij+QCb18nBbvqMp98Qs3DYI2jOLiKI73g9XZBMwb4AfXVc/HWZbooL1Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904957; 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=GNH0XGnfrH2iAn+70wl7xaYoYGRxFKFBAJ40rbga/P8=; b=CocGS93PAOBnk3P/3DsKaYlAilLWthTGks2tXnXxXz436I53cx+8vh/e4NXy2N9sLjP2 AbrR0kcMCsDTplUXKxog+5sNwOvDhHyNA00H7eeyzepByFr/7TJCIPlQcigPUvIDZXvy8 e2OUUBafxuiV8DsvMlAT5NPXhkZxn470QUBMPVOP5UZ7EFLj7AqlWoD54ySpHnQnL+pcQ 4KDm6qgOG9wOgDOpozS2MJADZ8PUY7K2PScXxkzt0k/aXcSJcVi3mh7DnYgMwgWR+sxkR opKaQxxc5+XeF6nh4Fq9nOXEWaJblq+mmUroSFrrYNPWj4L0zcEcxsSGOqfX4SAUnjw== 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=qDZfSlXK; arc=none smtp.remote-ip=209.85.161.41 Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.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 39DB4606EE98 for ; Thu, 5 Nov 2026 18:55:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 39DB4606EE98 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-oo1-f41.google.com with SMTP id 006d021491bc7-6f8a519e215so1084371eaf.1 for ; Thu, 05 Nov 2026 10:55:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904956; x=1794509756; 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=GNH0XGnfrH2iAn+70wl7xaYoYGRxFKFBAJ40rbga/P8=; b=qDZfSlXKRudkyRHXJO1iZR00RQuH1Azytw9SL+Qj68Ax4q7PibUEnLWizaqVP7z/Ud l7uJakMe6uWH2XOW+HEUq9I5V3jovLF6gErkE24ZWmt8QcURMKNqwOMKfhrrF2Dx7g9v Oa+S19AsnMUomOfQVyUur3smISopI5B5is69dy4uH+jhYSI6sxbr7mes18vXL4QMDvJl wzG0d9QuMm7FLnX08OvXkvDZPQGk5sryzPxzgj5XiWr4IFj2g8EYJzTA5dr9naIwevzY 429G4CFLrJnoVy0hXVYAbtYWTVqovJaySMqcwSd8W/oeG+krAGTh8/umvkwqqYtB4zJZ tMtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904956; x=1794509756; 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=GNH0XGnfrH2iAn+70wl7xaYoYGRxFKFBAJ40rbga/P8=; b=CS29donDgZC5Dq5HU6qpAYT/VIKaRYRj8XxpergWlKawHjav6658Eo8bW60mmLbpKk HNw5iHBN29IitSGb5MLyEJeLc4C/BszZYXx/CcnHHrv01xOoOH23fs1tHK42jVu6hi9o GjAPIiGZuBBLQOthk6/85JGIr3ryVxZw1hepcWw2xSKNO9MOBUi7P4RQbwOMhQ7Iq9Id HFeS/rO+6r0zj5IKYw/6d+YY3+XpiYA5TbIIFd9eOWTPIK1MMQZiVducEqPsNqUIvjGu eLQzmmh/U4zaiA/MiptWlyqGuXuFOkZbPjz4qSGbBxRl9KHs7zPNCdS/LCXlfdIHV1pF DWYQ== X-Forwarded-Encrypted: i=1; AKwUvBxZY6k6txQmIbAKAA8L5WUnj84qaVf8RCjfIwW9fQocKVJ1Cn7IXkiqNc7nm1FT5YkXFkGcxUXZDQqjXw==@lists.linux.dev X-Gm-Message-State: APuU4Z+YNSQCURfVK9TFPn2UDU5pLIXBujEOC8XPoI/0sIzmRgXvQXhs SdkupHu3pEBqdFbuBnqZhKQAKR56TT+y21eCRf13OSFL+VfMsy55nxZW X-Gm-Gg: AYBFou2Y3TOd7/C0PtLm6WQV1vgVo0aSTH6+kJRkpj5jv5lLKKAs4qsphKV5vlm32w3 mt97O6tj7FtHsvK53r0Gzvw+emPPMNKEcaCf0i0kPVWST4CL4HTtQkxLbTLYLgG6OffNqkaxB0f awGaqTKFPNJXM6XDoEqcrv50c7iAVLPIbU96Kz+Zr18nTxqDCZb9atI/hPJ3Qi1EH3kBAfF20oA +8Ri3OHLPL0yAipY3yAxFMZU4dVwnnhqpC0my7gkM3KVmg4KOsT3xcf1So1Z8CK3ZhJibEtVjlm kBqe7iBg4LPWrI4dk/XOI4A5qwVmB6JtvJIEjBIFjsaJLjsCBOZjs00g3vdrVH2Q54bNmCJpslm GJYKwQQEmZuCzLPxTftx0nOJ7l0/w5up28qZrEjSt4Axg8kdT9Tc//5RAnWXwdbpy9frRvxPO75 G6hNsEb3KBQypWHTXJl+Y9q62SjbpgI6+5TFBA9PvWtcUfDR6Z0W3CJwCYRxqLwbXaHO3nAhIe+ J2p/jBEAsgczInnc+mUL20fPV2XN4ifd0cZ21jWcmXOYiZ2CVwj5Y/X6HUnCf3bOiKY9EBnm6yr 02A0DTVMSI+EJYDYG47NXJQHdBy5CSvs1RYyFJKiMOogsTC+Mekg7yam3dr/Wu0R64Pw699BTik KGlD134TEvPiXC/bN3eCSZOnlJ9pyV8vRCtynLnq3Uxu6+vn11Lw/7E96T48aO3Nl0PNr+yyI0k njp8yN1uHyYQWkso0XTyv5zt13/mOsY789GORv5rZT7x394erOVVdwJA== X-Received: by 2002:a05:6820:a03:b0:6cd:3fdc:2669 with SMTP id 006d021491bc7-716e79e8336mr261121eaf.42.1793904956099; Thu, 05 Nov 2026 10:55: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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:55 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:31 -0700 Subject: [PATCH v10 15/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-15-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; FROM_HAS_DN(0.00)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; TAGGED_RCPT(0.00)[dt]; FORGED_SENDER_MAILLIST(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]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27274-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)[209.85.161.41: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]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; 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: 3F3D91C241D X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX nand_subop_get_num_addr_cyc() returns the number of cycles in the current suboperation, not the end offset in the original address instruction. Comparing that count with the start offset plus the loop index drops cycles when the parser splits an address 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 54377f1789a3..0b92bbe19c0a 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -2518,7 +2518,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 Thu Nov 5 18:55: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: 3898 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 C2C2A1C53A6 for ; Thu, 5 Nov 2026 20:02:31 +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-27275-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-27275-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 12DF734905 for ; Thu, 5 Nov 2026 18:56:20 +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=1793904959; b=fsSp8/ooNuLF1O/qaIu6mZA/2oszmjUlfSCYk29+PDGRQSjhBLhcbssZXC12j9f79B0n Cvhfr3hqaKnDUxJWhMek7Y2UsagYwUoGl/2rLxE6k0BEdtFSBd4/U7tKUtqJYU467GV37 tVyd1XBNJ4eWIY1F4UwdHlTe9wJZdwNmaqQeW7Ya+RvNO76Fpv/ZFcowYMwPlW2iyA3bw D55yhyCyj3qv8t4kULC4uubKqINaQ0LOTGk6D7x6kRdQFQnbeFL0rJTiRSaXSedn5Dguq lIGy/7k5Fyclk4YPT43fUho4pZnYZ39cV13Hb67hPwY7h3ExIhWj0dmx096JKfkm3hw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904959; 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=Du4EE64glD0wtWCQ+qs5atx2KYOu7ZM2ZnRx2xMlHc8=; b=AcCtz+D6VY0wOo+qBlRhXlOcCWexQ0056RbD/vDjAUDAaoX1xcSNzCRAGxLvpC/j4GuO 4ZxymvkG1NlFWIul1sOxLAGIAWPPf4Q6Q02W0CAPX1nMde/jBmBGlzGevPCmlCKB5KckG dvHMdMDRXzrr4NE7QHJ2Qm3J9vVsQhmgAkaW5ddwUdP2wSD3mup5s3R3wC17VrAMgZg/2 TRhe8LNmox4v26NsqBIvj6FWiGNwoIfwzTNIDg0BXwRB7mTI9UI4mfhk8BM0UlIbsaD1s ltLrR6o4nf2jV83lUkIpxc2Ef8vjnihFREfDxXiF48mnbMbm7o1ROPIBZog9VCYVn0g== 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=UqJyOG6c; 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 4E88E6082BF0; Thu, 5 Nov 2026 18:55:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=UqJyOG6c X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904959; b=Gn++xGgEiAsjXMP9l8DDcvE1VN13MU1yu96BTQXOM3VQS3bGfkxw1nIYGermU/lRM9Vu LO1Ietq8eB1kK0IAeePz64I+HWxEB0fXNZM0G38Tw6TwJKOZQ3yFEdVFx0xLbXFSM1LHJ 6JIdN40TGqbIDs9pDEwmp5dg4/4QoRVBPn9UvfaOpAo7OkcEk7no6ENl9uxWZTlCCI2QB 6KLmVB+R4unxxx5O9miiFaSSdru3EeEujyo+VSM5GpHwkdthXPjTsyyo+u+dL8JE/LMsg sM/QzFrJ1b5iHuqfMcmYYUAnnSFdjkB2NV7lFNhrEwZWlpeWcsa16FagBTXOpo6aGbA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904959; 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=Du4EE64glD0wtWCQ+qs5atx2KYOu7ZM2ZnRx2xMlHc8=; b=WxK991zdiYuLOsAQqmXueI++MyW51ui6hIUrVYAdOG5tf13oEBLvVoN9ozm59ZYjS8Hl 1BlbY3/+m9cNL/8nPZsgfy5IyCtNGgKys2OzTXJ/GFaIJhmr9FuzWMu5yBjWRwTiL6BBb NF0X7Qsl5lAXG83ocycD0sWElxF3nu3IjOPCD4HZVfUa1GbmnGlfXnaRUFxM8McfnYfY0 5UmEDe1ZKM9UKC7ILdBFV2/6PsKemhyQP51jWW8FquaHBiBqn99ti6YpXY9nzRIS/drY8 Xq8d3SFXDg0ftjspcCUCdzzSjoIoGVxuxj5T29ClA0yP/2WO6VswHrl15ha4lmpDHwQ== 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=UqJyOG6c; arc=none smtp.remote-ip=209.85.161.42 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE51B6082BE9 for ; Thu, 5 Nov 2026 18:55:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DE51B6082BE9 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-oo1-f42.google.com with SMTP id 006d021491bc7-705cb6ceebaso1493640eaf.3 for ; Thu, 05 Nov 2026 10:55:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904957; x=1794509757; 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=Du4EE64glD0wtWCQ+qs5atx2KYOu7ZM2ZnRx2xMlHc8=; b=UqJyOG6cD19OXImSymO2Q7BQFqNKOWl1H5Qf/4LuJcHj36Mj5SmOxHdlB3A7C/T3oV GhWa9zcu60NabvGy/C7VtVI7QNvmHQiF1Nb9dmNc9frvOsMlrirFEcbNv0ZqReIC/KtI rVzpDWQgZ6eSwRCuLNR1315PC0btnxFRJJicA2Y4mzEgs6k4oTI5yx9OZUznnaahehzP aTlquLjQa+x4+0KHzXbSWUsBonGB2snHmLgEfcR8VZejPdPBj5UKQypFnd/3AuNzHJ/g e1I0W/LjiaCDFNX2b238Me968OcAqXF5+IAKXolsC4WFfefbKUD15sDt+tNR2NO9n4ja lIxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904957; x=1794509757; 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=Du4EE64glD0wtWCQ+qs5atx2KYOu7ZM2ZnRx2xMlHc8=; b=Dgs0K1IHayMgbvnXKBfnycQ/5/e6cVVySFNKDGGW6M8A/GKfPEr0/2KzojuOSLBxcC 8Gogjm3/RAuySYmXf/exep+mRg9X5C7hvaU9+NnJ8itvIhELdgmMiK8N/K1SYWCZKD+k 5fiaosECD9mpZvH4DCKCt2BNtk60uXbtHBlRcGQGWRRXtIt7Pjd9kJykWxBxQ3SDke39 9z5V7xg/wXicbB3f5cUMC5qCpZSs/hgaGkyDqlycpTyvtWQfWyKvXg/wIjJukyNO1nDU D17Pf6PfNfBLdRkVcMmm8auGx6nmMwiE0r+eLFmbXMBQMixbTeR3WeM6IjYC0Sksy75H i//Q== X-Forwarded-Encrypted: i=1; AKwUvBwIPAFtAUpzMlonezhGQBxIBU0WPtP1jCnyv8l+3feC750PtGFSGYKbDgkEmRpb7UT525Z62D4lhS/cLA==@lists.linux.dev X-Gm-Message-State: APuU4Z/fwdsDIgWbzvfwspSwtlKmbWgA5x+yFSHJ7gJIO+d+jzVLDWiU ojo1JWP0YBWOSa9DTuF2AaA9EgZCg3VHb6WNVQ8wAjo/he+R9P9fITDJ X-Gm-Gg: AYBFou0WEsTdoerQ69HfOR46PG53+r7+LhU9KEuZt1UU5AZ07zRCS9FIxyN+saDKZb3 utRtfK5ds3jPYIJRQKAeaYXEVS+Be4UaOwL850hhf6Rz+NFAL73I+7G9q3U0t5SP21ra2jA0enP qAvMyF911RmkzYhKkzgurR1j1Aav8AC8mdS7twA+8Yoo+p74jwDZNRZx6M58jOLg+0PfQBxg706 1GpJGGvq4HmxlQlbw1udJ94fgLyqNQ8BCALrQt14UqFR+KsVy/f8qIavPxGsbfBiF9HqVZFHP4O eKNkiIhu1ejKDxP+zVHlKfRHlIlcUSrnpmdiRsxhcRyPA7kg9rSoXHgMWSTIN3ccexlxJStNBxz f7FStgBnTdrUrwxyvMCETBWMe/wce3vcaf/XNxrkIFEnHEkz74kKwpadO+w78CTBJkzl40mty3C eTKFpQvL/n2gYF6MTvD7hIuwYil+vcb3+Mj9+Tk2OMaHnazf4HtWC/T2Pn6NTg2T9RjzjaPGzuP 0jyDlhiv3AQFwue9QrvuXRiOM6h0ETTxiOW+Ha5zUqLShuelUWsTyQHaRiXJHzMHXX0OpjD9oKP bmu17qOz6yKKs/FiNcI0XAMey4UZMIySvee2OiFUi+jNWve0tmUt0FwZDqsg5qRKRnekmCHPYx5 7u6I56EYiJspAMgx8kKETYrTO9rdRcZR7Xqb3hYKddp/iDeDKUTAaSTTm2hkSWjaePa7jKWvURw NlVPajckMYSdRxNbe8VznDdiyLRxny2YVzGqZjaW1Bhgd8gsTdBUJU X-Received: by 2002:a05:6820:a513:20b0:6fc:4051:d2d7 with SMTP id 006d021491bc7-716e78ed246mr305545eaf.38.1793904957427; Thu, 05 Nov 2026 10:55:57 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:56 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:32 -0700 Subject: [PATCH v10 16/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-16-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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-27275-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)[209.85.161.42:received,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: C2C2A1C53A6 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX Chip selection ignores clk_set_rate() failures and caches the requested rate anyway. It then installs timing registers calculated for that rate and proceeds with the NAND operation. Subsequent selections do not retry the rate change because the cache already matches the requested rate. Return the clock error before changing the controller configuration and update the cached rate only after a successful clock change. Propagate the error through exec_op() and the DMA page-write path so neither issues a command with timings for a clock rate that was not installed. 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 0b92bbe19c0a..7c80f52c517d 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -651,16 +651,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); @@ -672,14 +681,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) @@ -1824,7 +1830,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; @@ -2627,9 +2635,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 Thu Nov 5 18:55: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: 3889 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 1C0641C241D for ; Thu, 5 Nov 2026 19:59: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-27276-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-27276-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 EBCC92DD1A for ; Thu, 5 Nov 2026 18:56:23 +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=1793904960; b=39FENQ21PKnqRJuK/9MTgeMcwEuWWob1MrBWhMmRqCWusaB8VBcz7OnckuZY9BqQeEz6 y7xFKjrZpDQ+4nsTM6rQG4TK7PX5QV9H56ru7EB/Q1o/KnGEsqtx8bPVa3GUTiNfnZK14 p9ZcxErwGyjDsOlaq3gTrfnqX4rYpzV1+9EaG6gI3JLDPybLv26+bTND86+FmPAmIh8l7 LIMFbBKVGGeKtn3anL8HqBCVO/DlDCVfRGtCTBKaCEQG8PCEOSleEw7yLbNjxDFDHW6/M RJqOv8FpR6qFiK1JngRIiEDVfY7YalKainGvuRdEIQfMFOBqkumV2uE4HtlQz/lb/vw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904960; 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=r8+AfGGSzvw+hGNMBk3uLeKXHLvj2EOr91SQHPXuh2g=; b=ZwH9ROrQsHLyWgwjm5wUNjKA5bSE2Q8B/h/PiLWcvLgKMzTohag2NEcIFM+qyM6yoTzt 7lP+Oi59HVxg/sCCk5+/xEStw34P0k6hkESL4Pis1Mwkoz9rhKhCzHEB/6fS5FMoQmlbC 6BctfiZTi2dQ3LLHwOVqaWugTFmEOmB/O17OXTCX7m8MIVUqH+aF/37FLG1n8keiz8xbX x9UMqU/QsYR1M7byD1QmcVlEfgIh0KDUfWHar5ObD23LlNTqj/xQxOjj8IpUYD0IlKK42 b9dQ4eLM9ZTuBx56gzbcIlYu8rufeblkQI82KpA8tspVBpHgOQlb4/huxjIAuDfaXrQ== 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="TP4VM6/4"; 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 53EC96082BFC; Thu, 5 Nov 2026 18:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=TP4VM6/4 X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904960; b=KdzLQGCkmPd9PLk6l0YBwm/PNbLS/blOrvYoIW1HasUe8asEDRkrsqHbj4xylhp1JKWj 6Itzesv9cSXCtb8lS0dy77Z1VkIiqa59m0WgHAuW2dfTkCMAB4eW29yHunLT4mwgoz/me tHjgWfP3jg6MbO6ljG6c7W1GFz+MkBwDK7x5G3oB1TbZZy4fKoeErDTaU/hcVfAyChy2/ OzxqX71xNN9aKqJFxmKUhftvfvj08eDBN7yxPaaBcj72o3H6ItbENvN6zVLtZiL/Yrjtx Cr8e8bdI6N1QPOW/ribkHi2wwKUCjgvAdpSB6HljQqePQpLR2n5cXA+Fl4l6PwMltKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904960; 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=r8+AfGGSzvw+hGNMBk3uLeKXHLvj2EOr91SQHPXuh2g=; b=P8EM1grvj002tj7Ou8wV0Ly1ifrGCzf5iG98cLJ9SvqXORXbG45JRCMEzao+mKXxEAkz KuSMwppt5gcldPXj9A1PFuh211iia2LEmpiq1jM9bcKt2vhBbgnttWNiskWkY+WL/jcLx H+OWsB1KkcrtCTUz2KdasXmoRMtkLw22aXEnUTkp7yGTkAXGd9Oj/4CL3gfnddsCHuv2N 4maNCiuVb7+L5gDgSAggOwefWVEu9za/VBLjSKRaWza73YC5WXGQh9wUZuKrQqTtAtcpG kPMrpl6llPSeGGCwX/4Q1Jqnnxxiv/OqUYqOVUoZlDBMF0XhrdevGoYotfu+UvxeIsw== 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="TP4VM6/4"; arc=none smtp.remote-ip=209.85.161.45 Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.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 E254A6082BF3 for ; Thu, 5 Nov 2026 18:55:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E254A6082BF3 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-oo1-f45.google.com with SMTP id 006d021491bc7-6f8a519e215so1084430eaf.1 for ; Thu, 05 Nov 2026 10:55:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904959; x=1794509759; 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=r8+AfGGSzvw+hGNMBk3uLeKXHLvj2EOr91SQHPXuh2g=; b=TP4VM6/4Nc/Icr5K78I9ChfFj67CyvBJ3NqkudUwFzgqxE1HZ+xEzPe/5nWf12BLVU QxiPVj/L8SEpUiU07wfQnJ/8+k0+7p1uqYs+cqJCzy7MpJIs7lXCKfgVRn+Vh9XAFeKF qsf/rs1Kn+9aWt5WkYIcyI+sflOAC/vDA2DEEwnX2UVs2yWIC7ClNsuCydBR/Ynie8VF 1SF0kF5fLwZgntiRMkshx+32oC7bIvnz/sylaXKJ5vJ9GY5PDykfASQhubHYA0jVe98X 290HAvGxGvOukYgCB2EB9JlmDPMO9KKvuG1JDV6wYGTRZ63XRopSK+NoUuzoq+TociVl 21GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904959; x=1794509759; 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=r8+AfGGSzvw+hGNMBk3uLeKXHLvj2EOr91SQHPXuh2g=; b=o3bTJ9z/ucDpdduwc4iUZvY9iO67LYnSrtd3BJp+IZddhmtNrzLMLGQTsoCu5L5EeG I4Fr9JAUanwk67m8bMGkAo0hQ8m73bKPv+l3kWY2C+pDCryhsxc0aXuBWMRmqRiF7V9q iBaZqviMLXrioUUMQ+1HU6HHZ9V91SZLkc+cIrP7hO4Y+n/5uJIh0j59LBmCegjaNK23 pevEAEw8Jr8RnpDSaQRXpgDK4smCqn4nRjYVpGEORFQjzBPzQsWCv8Bs7Qu2OLv+n+cW PvZhb6GFk4Pfl/brwzpxGgvt1F5ODnMq8tu7bP1diokXQBcWa4IcpLWsHz/lS4hNmtvg +4bg== X-Forwarded-Encrypted: i=1; AKwUvBz/1gLDujnkJ9IrEVf21OZkqKSca6LVlxwD4Mcy4bWma5OI6vXm/Jrp2OTqZnB6A0Cm5i2kXXCvWCQTZg==@lists.linux.dev X-Gm-Message-State: APuU4Z9MBM39EqpxoZ72/We3KYq80wrnLsI2NylVIVUPFs/E6s5SWNYX l7X7SQ0hu0npgLcL+zrYJ/T05WRCx2xYadM1Ow4/g1KMCwAZBp1YTaFN X-Gm-Gg: AYBFou0g4m94IHClN2d7TtkLoDvPxZq3Kw19w6hbeDEDf0rduSU3ZlnQquQ7gLtxgl3 pOQAcIaTOBWehFUmNZDBcemwTuZwdRdnepn0Mzl8iK4K7AZnWUU+l6eF/im1OjWWlIXNVjoaG/V Klgc401prPlue4f8G7ZJO/E6eL6NzK+LLgzUY+1D5oONkokFKbT11JHU3drqAsYEEMWXCQMCF0x yBhet2Tv/EQHOvKR7ws66+vSWAd9aulb3jALsrCfWNkmwEUNYAKUDk9d3qYAls+k8ydc/zIVUBB y0VhqXpcxPmsp+QPYgdhHwihVlJbrS3YD6H7I+Zjj9GABsJdx49uR+OjayfIMdffFe6rq0s0mWR ppstaIgDS3Gwj2SBLciFjpCm7koBb2NbzpqsoDYKyKfaLZ8s0ZXwl7YCyr+DdI0ig5KFZhVd0Gg BdwjXQYS91pyCDTKFIT9MtnIahnAwUhKrYl76M+7iSsn7ziryF/IzNyqsTWQ+IBS+Br9drWXk6x VBlilglOb7WrJbwx9v9dKWkfV88rh7kNb7RfhWi0+kO3uGP1zFgLIg8yVdaRV1xzPJxgm+eLZ/5 OPI9OPIy78vfhihnDGO2KfTJSNF9a9c4jhc4p1fuiSxeXQdzuiwoQzzFtvO17UNJ7bzkcTCISjL qg/mvWeDCROwiHuzwZEU7Iu677VfGBMVfL4lsBiFhpn6mK/6bBihTAb5142yczyi/pHpxg8oz8a v5CEKOwdQ1txvektORypz+a0gKj8xNpIIF5MuH8K/craYS3VKHNhAC X-Received: by 2002:a05:6820:609:b0:70d:53f5:e5fb with SMTP id 006d021491bc7-716e7374b3cmr330726eaf.2.1793904958904; Thu, 05 Nov 2026 10:55: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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:58 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:33 -0700 Subject: [PATCH v10 17/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-17-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; FORGED_SENDER_MAILLIST(0.00)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; FORGED_RECIPIENTS_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]; TAGGED_RCPT(0.00)[dt]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; RCVD_COUNT_FIVE(0.00)[6]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114:c]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,209.85.161.45: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-27276-noreply=patchwork.local]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 1C0641C241D X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX The H616 capabilities advertise an 8 KiB SRAM size, but the normal-command byte counter still holds only ten bits, with zero encoding 1024 bytes. sunxi_nfc_read_buf() and sunxi_nfc_write_buf() use the SRAM size as their chunk limit and advance the buffer offset by the requested count. A count above 1024 therefore transfers fewer bytes than the helpers account for. The operation parser already splits data transfers at 1024 bytes, but the extra-OOB helpers call the buffer helpers directly. A sufficiently large unprotected OOB tail can thus be read or written incompletely while the page operation returns success. Limit each buffer transfer to both the SRAM size and the command byte count. Share that limit with the operation parser. Existing 1 KiB SRAM controllers retain their chunking, and larger buffers are transferred using successive commands. 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 7c80f52c517d..636a04f49418 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) @@ -690,7 +693,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) @@ -2606,11 +2609,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)), ); @@ -2620,11 +2623,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 Thu Nov 5 18:55: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: 3902 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 599811C5393 for ; Thu, 5 Nov 2026 20:11:27 +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-27277-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-27277-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 8F13929D85 for ; Thu, 5 Nov 2026 18:57:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1793904962; b=1jMAnz8gWXij1H3yZDJBXuxUXv/1UGkKSGcAwCIgoI4tKwXaW6BIFzvjD9PmbVlEDZ3j Uc9L9gyDAcUx2tQDdUavVAAaCRhQHtlHuFomU6enPUG2QZqcJBNcdM5fbhBe2D8tEhYeu WGjmZB43ElwdaarA4ucH1D2ch8EPaTBO2WSCYAVux/ei13fuQmcgvFFVBEQVvOTnK8Wu+ sNJv9aYby/GK6+D9J16X4iwQVr0isdgXmO3rFg+CBCfY2CRbrwVFVpCraMAcJoYOUPcIy /EHjdqGodv8RwyRNVLFsRPzut0QPSh/sbbsEXgm/t4s8LG60GBLSdBe8lB8LNUOtBUg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904962; 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=RwjIT0DqDPAYZ6NuHVGHzHM6/S203rMIqUTfEYiNenQ=; b=Exsm2HTHM++xQmT7EJptOC9K5piETE6G+wZj0SPu84GWKXhXRBRgJsriuO+pYAKsSfh3 I99wxzJ7wYKATBK5geJhyW1cYLUR1C1gONgBKpqtRxcDSodVvzJd6cScnhTPI08btfc8h XWNjlftnUJXxt1oUlRXfOAoUaHkusExNbODFyaAj3NK2Vovjvk3zh2HHyoqKXS7m4W+m7 D+MqvfcFg+mqEzIh+kyuPUQi68JUM5KbZlNPx3aVLY12cxs9GHDn+ea/1l4DWJyY6yQO0 YD/pBiomTC+EG44ljVdPPv2hu6xgHtpLQGosTZwS/8neS545MYiuoG5frbe9XwbOwPw== 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="zIRj/E08"; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=fail 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 208A1606EE85; Thu, 5 Nov 2026 18:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=zIRj/E08 X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904962; b=rQIuXxfPNr7DxgawBkMhw6Q0wdx1CnkShgiSdkySBWGTx1w2UPbXZsTdiSvFd7HK+BWJ 9CjC1ioVVsYtPcghhYmjagiaWmp2Z2c5uEFY4yvLtCJVB3S/QH8rv0K5OgIP9vsSJKKTQ egiLJ7Kr0TEuz4uSu6IaSoxBySGdb+2T00YF6u/uwYtFUt5UaCF3G3N9q19qhhXKWdHvn n2hA26NnQITqyt4cS352NpsfGzRRNDOsmMJLDH8tStmhKcVdOSoTfvdyg0hMgxsBhuQv1 FV66ygSbL5Qxu5A3P5mjbPFiNxvgLpze/d8uLWDVl0PiVqLwF9/I9G+TvcLLMSMRppA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904962; 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=RwjIT0DqDPAYZ6NuHVGHzHM6/S203rMIqUTfEYiNenQ=; b=aye0zNIZ0a5osAgdmS3A7HaQes5+IqmAydHDMaeXsvwXoyTY3GgmSeb2GMXFX8GCelZM a0rYAK994xWk+HsVUuUom1sQBoftxLxOn1VTV6aq2ibNYCm6iGAjevCQmXuhBoUrDXz5M MLSCp8zB32FuYQnTzQEMW2vm+ZCY6ebyvf9rGfbPTJklJI7g1Elf6KcXYbTCADF97OgAs uyzy+Q5aWVSB1qIt1JIYgnpNJ/j/s2aXFb2g7k38rUfsjn5dGIiuhKFy0LQa3aSTgfllv hTolL9FAoD+8VQW+ll3BB7yZP0i6T6UPHkVyzpEaDNOAHguwDxr4pujepHf2r9Y29GQ== 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="zIRj/E08"; arc=none smtp.remote-ip=209.85.161.45 Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.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 122A4608360F for ; Thu, 5 Nov 2026 18:56:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 122A4608360F 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-oo1-f45.google.com with SMTP id 006d021491bc7-6d68de53053so1245015eaf.0 for ; Thu, 05 Nov 2026 10:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904960; x=1794509760; 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=RwjIT0DqDPAYZ6NuHVGHzHM6/S203rMIqUTfEYiNenQ=; b=zIRj/E08pjKn64f3WiWZk5F/KdV1uO7o4wzwaUcaOY9f8oPJRAqrQ+EAusfnTwqcDc wD1xljIdCJc7YnwKD2ATfC0IP7VfHAPM0ybK1QmUad1Bpo1w0TIPe70eMJo2bQeztHIU 1Ox+vh6jvjOcDqJAhqcvDaVYLLZK2bXjTJ4VmSm3lpm08OFfpuDHuYtwzqVChVvP9Sgj NgS5kz881bo1wWHx6/+1OGy2OX43KkwwjZOaqn362Pf0SwJSBRjR5yLBIMjtHPkSRShj a3lepH3v+oP395J02uJikvs44Wggp6W/2guYHgN9gJ2DyFnvY5qJYcGDdcrUBqPAVtLX cUqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904960; x=1794509760; 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=RwjIT0DqDPAYZ6NuHVGHzHM6/S203rMIqUTfEYiNenQ=; b=j8GktFUVz6B6RuhsMbaDm9g4CZIThwMuUNPdpi4JB6K50YzspsDw89MgevnFO9UIM5 gYvy8idxJYI5OyKEwLvLcN+vBPMBuy+jJ0bWqYip7xuNQpzQAt8IWr6kL84iOhTxTzOT TwZOoa5wfAJinFG8TAKi9Kwi9HT3yURe7qeIcTWY9ipBs9SW72OOF77FzHaPtdqKBzH9 r0Qqs7vbPVGIPLmR7QzRHlvat58TdrmeHcojAcp/MH5f7n1504c48oOKvRI21lWpWqdQ 6KcbD5UTvGA1GKa2GnSiAfLPaA+JitTzy/WaO1PBiiz64X3Y032zBlylf1qBl86VAbx7 6OaA== X-Forwarded-Encrypted: i=1; AKwUvBzU/j/zBaurdtBIHsmcKPw2X16Ykqh1kFrpacEwHyC1WOV9/NA7AZyH+mADWjiuR0cYzE0lH6J7N0VJdA==@lists.linux.dev X-Gm-Message-State: APuU4Z/VcBGEWAgVnT+++vexbAI8nCAaXjAfI7DhLV76qEbEseic6K5A tT9O03mmbAswPlKpzoPra/V54GDVnHVcDDQR54Ebo7sUv8MkOA72zoch X-Gm-Gg: AYBFou39BuSh1jdmlEAq4w5z3hElBy+nmGZa5XTA65m2AiC/1X4lrtDGfKIUgi4CmMv GFMSWow/lSG61LmMru4vMpoRi0TmVwKoY6CjrzMPNqK0jHFksC1gvanOFYnjKL76f7jG6yPW6bb X/1mnhiUikEuBcmzpW+4pZyNgWaq6Q+boY4A1hYY4xCekYJrdKmtJ9dXuWSGzoWRxUDDVIyUIel K7FIqoQUEFI+52lYwN9Xd3DRtCkjKAQivulq8V3c0PO4sVp6DBlnmz0jZ9COmaH1valL5mpFcau SNyfDhvy44TYaJUceDNwcHnI5106of12HGCgls1vnZcyCUdArw6OcFe4X7/jSrcF5m8fBbLeerF Sc8rO6+TTIOutlF80QoKLnkCoZqlY8un3CiGlQeav0qAg0WnIU3jh6WbDadtTHLsrKrUKffVqJe m4vEYro4aGXZnzun8ZdzS2mInnKIARxwqjmtaXnr41dXt3QJmbpN6h3ouDtA2G1a6/TDwbTgAk6 4x7FVqsjwzTaUb3xJSMbzxuq8W/gRd6XPSe+gRE9Wmq5y5JFDgEOhwla7rsRa24+/Wgq5OhQJ9p zTxmSkMRfX65mblpJ8Oaa4oUVzxTS37W2PA87HYXoDNZ83gZNySxfFmZ0NJyiTx5ZsNeRzy9Eu5 5RadDQ4hApWIh8WOQ1RH7+69UOtAGS9vi74fBYlIcD9g2Jp8+kAMy6Dl4sMrJppHp86ShQ0PIaf FDFvb5/+dz27/lKvSJkddVtpflKdhV7x6GXrvG07gJ/WlgqTim9fm8 X-Received: by 2002:a05:6820:160f:b0:70b:9b1f:e8a2 with SMTP id 006d021491bc7-716e73de95bmr322359eaf.3.1793904960035; Thu, 05 Nov 2026 10:56:00 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:55:59 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:34 -0700 Subject: [PATCH v10 18/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-18-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-0.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]; ARC_REJECT(1.00)[cv is fail on i=2]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; FORGED_SENDER_MAILLIST(0.00)[]; FROM_HAS_DN(0.00)[]; TAGGED_RCPT(0.00)[dt]; DBL_BLOCKED_OPENRESOLVER(0.00)[sin.lore.kernel.org:helo,sin.lore.kernel.org:rdns]; 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]; RCVD_COUNT_FIVE(0.00)[6]; ASN(0.00)[asn:63949, ipnet:104.64.192.0/19, country:SG]; TAGGED_FROM(0.00)[bounces-27277-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,209.85.161.45:received,174.29.1.49:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[104.64.211.4:from]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; R_SPF_ALLOW(0.00)[+ip4:104.64.211.4]; 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: 599811C5393 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX sunxi_nand_chips_init() scans every child of the controller node, including those marked disabled or reserved. Neither the chip setup nor the NAND scan path checks availability, so these children are still probed and registered. If an unavailable child describes an absent chip, its scan failure can also prevent the other chips from being used. 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 636a04f49418..3de9ed6795fe 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -2771,7 +2771,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 Thu Nov 5 18:55: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: 3891 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 4F00D1C241D for ; Thu, 5 Nov 2026 20:00:31 +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-27278-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-27278-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 668052E85B for ; Thu, 5 Nov 2026 18:56:30 +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=1793904962; b=Skqt/bPNLBLWFU0scp+CFvy5UOGjwGd/i+I+di0D48RAgNVLMLByYcj22HKtRljUFWm7 oIU1PW68I7Xog9d5DcsG/SuAm8lkRYMOZnijum9F9j2fevVhHtZ3Mfivcf+1ElgLYluyE JWh9bTi/KjLkxuhtmyzxMwrQcsfSJW9Tl0FdF4C9RxLqPzue7eU4Eh8QtwtysDfsUyHHk 9Ef/Rtr6o08xnX1whiMK/L0sv5q/qofZfGHDzB9ZW82VhlSxWxz3d0XfHmMJGbiKtasBI 263gpGmDyygETVTu4EJ5WzHwSN3KwRr0LOrlOezRxdvpTWBQfO/LR0PH4PTHg34bywg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904962; 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=0o9Q25n23ckZBCXpljiM9GoL2XJxqzEiWbXDgW42slQ=; b=ETRJyuG2mRtEJXnpUDb+yluntsSY0LGoUTzhXqHkliiBULSQssjYZTnbKqEx06BCljKl +VMHLAxf9gz/Tbs9C2bLgYFy+GW0Mdg6K4dIqgFR9iH9ljtXCgEzcx0pW2Z2dYhKXaLun asOd45wfVo60Bt85ZzR+INzbBOVtEQ+f6dK4gPeSAFiHrV7e2e+r0c6G724fk12Id4hhG X7mlMM9PW7y5RQ3TeYQzQF6D6crKBzbHsl8v3iHi5HpqFb7sOMXwJWGi27dyhoHkzxkD5 7J4+OZ5Ho84Gib2XvVQgDncmDaww1WFCb6gSynkQwZE36IgthQ3i3auVBzUj0+IkXog== 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=vW13S7nZ; 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 A1CF2606D81B; Thu, 5 Nov 2026 18:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=vW13S7nZ X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904962; b=ra1IobgxkwN8TFy8ao1Ft8xI83JI8gV/PfoxGoAtaTw8siR9/gCIRXLSWf4gaQ//JzRD 10gGwV0bYfS7MRy1MipaDLP11ZMBSdm/LRbKCZRfdsmFiEyWuuynmSo2mtRk0R2dKOi2C 2TiKB0lBeRTa4Wr6k1o0gKT/vGIJUD15FnkuUSI8HVk8PiIoRG1y0eKuM7JbApJS7TbmB UbnEYHUCEb+tRpaLPT7eDuTQP4x7U68Y7tVlk1yW3sctUewDdmVTEmOXWJ+8bOPjJ1mGT DdaljPJThgbgtipS1cj1C4Q9HNnKH/4qysWRfN1r7xenJ9UefRYYeyVLoBDUQyGWXzA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904962; 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=0o9Q25n23ckZBCXpljiM9GoL2XJxqzEiWbXDgW42slQ=; b=t6ay5RMPZUgIbrzyqeR0YaGdoxQq51MadK7vHQsyNwWVqr9V1aVcKlkgUeOs1bI/HEWH e8n2rgoV8Ri/AIlbA/6vUTnIKA0+G5udvXMrlWOfHeO82yRGKOe0PsGRYYnW/G+aIAe50 n3EN/zMB7DjNmMmnVQvP/mQ0yJqKFaWmdP9Z1dFgD7W7tQQX+7Zt3lKPMiRfRKhh3hWjq uFFFNQFwz5oyKy3TnbljQUn/qXRuygBZO+H3yhjmwoVg5sbOF5QZogFBdPp5pb9DgQFbu mqiN7cOG3RsqbrVY+vyxScOxpsRUdilEuoBd55IOtvqM5Q3iwZaowYWBHgB5tGEqZrA== 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=vW13S7nZ; arc=none smtp.remote-ip=209.85.161.45 Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.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 3B634608360A for ; Thu, 5 Nov 2026 18:56:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3B634608360A 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-oo1-f45.google.com with SMTP id 006d021491bc7-6d68de53053so1245035eaf.0 for ; Thu, 05 Nov 2026 10:56:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904961; x=1794509761; 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=0o9Q25n23ckZBCXpljiM9GoL2XJxqzEiWbXDgW42slQ=; b=vW13S7nZtE5OC+TEc9iUsQh0H3bSAH8TlJYKF/J+n8ISE4/eZz4u8FR7A5nZKyIPIO VPvEIfUnXVrHPV5opobNN/EnH3VfgF7pixPGp/E9VY6AvUTF/jSyLtLULQNyTLXp7P/l aZNCQp2YX/IfZHCkv8P9lov2eVOs7uYKET8CqANLP6d9D/tntwaYWAvdztQBcEOQMhAO /7E+IrItKyKOXzGk10wRyVPQW6DnKz3B0IKlm+W5RGDyKmtcZysXeDWy3j5LiKZvGWv8 Fxw2lDqvqbIWHb5207rHeu63AnNnkZlVZOMMslPZpUDhC0+o4TFqOqD0bxZdRwLylm3C tA1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904961; x=1794509761; 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=0o9Q25n23ckZBCXpljiM9GoL2XJxqzEiWbXDgW42slQ=; b=PQGjvVlSmi+dXhO4HeCPVb82HYVkjEIe+mEoKlb6TaUCbSdSe9NJVts+F7mp7RFqk8 HnmK8jweNWQgA8xunFKdOOXBhS3KF4IddtRe8nPDD4OCB5JehvlrzdqmXbUMVAUf7v8F RdONuLE8QvsgGgAMv5hLSd+UrWX1C4o9aoh/111dAKqoiZoqkzeCfeJAfHLeXpxivCjX UsmfpO+0x45B9dqwDK53XOuC7B99ccupDetF4P6VGNgDsvbMEhoiKfjuo7xh9iQRYVIH xujUuvmw0cwJCJD/SBPWvUHqEH0gOcNVe5cqjyP8wp6JT5Cb3tMX+la/OScxILI4HA0z GnlA== X-Forwarded-Encrypted: i=1; AKwUvBxv6HJ8BzhO8vJxc6+J7JFJNjKUcTAowc/NSNwK+eD52OHAUZogie1psuSKUl8FXFY0Zj2QLvEjqz3vVg==@lists.linux.dev X-Gm-Message-State: APuU4Z8kd7nHNJnn2iiYhXk7FfBWmgm9OK4KxPJIdF2QtCk1r78x60K9 6uTnKwmzQ5vMd6eMw8pgZcatP0p6CUx0dUUcBf3asex+aHZwWtuXkTD+ X-Gm-Gg: AYBFou3IyaghMQ/asfpotGvKofEzhrRcRDnATuoaFsLekk/Ajpg5Cqv6xst+SBRLFJ3 IK/VS6+zvhGAhqYpixllf1HZiI+b067nrCUCnh0Fo5LySk3XDprSJ7h16q/4kLldueXGR09/VN6 4e7NAhUKSuqoeuDn151dHxdAjGuy0/z4TDQUKmHAwXJAmxMyL+OBnp3iRUWdpgNsf0HK0pmnNFQ TbFlRBQNGJQIJrZdrIaLMLeXwvGybVDARnxpn0UZp4yX5QCatDVkWFZcsidIp2xvAmepdAEYJtn vOH94dxMIYINIPxwyRfP14A9lUMJucy6h5zeDRVdmQjOvhixBAAQJyc+gV+eUcL9J2L06pQKqIv YjTIO9VvGWwI45BBv/6hWzqbmEWCyOJUY9IWbyAyKmTOg+ESsAd8dieOV4I00fsKiVQNPc+AZCl keQMRQotezaeXDkTC4GEsoAjeWoS2BJ1VwIX5yrLgDjdfx1aEoDbA+j3ByGzOOLu+wAMHInNAzb 4UnE4inswXjQVsWWdg7eHNoNQYyeWJB5mHHuy87Z5413C+ij3WHHRYh3Hc5a30c9xk5Yu9dPu08 hf5i19HmjQFVjy/pl9waslARLULZeoXHNsqMYHDac6YR4lcUuuD+g57GhsR+LHU1EhunPy/hhoI uGzYzyLRSVnlZzu0YHJBi1LDWgzMdmkW1iQumrvGEiIKfwPEUvWV143jqQAoBTKHiCQzEo2gNNE OgxSB4+tJ7A9UpOPwitYqwta+aHHKDsjw+c9AxZMjWlJazbeyqVhV5 X-Received: by 2002:a05:6820:4812:b0:713:da3b:901e with SMTP id 006d021491bc7-716e794cfa5mr279031eaf.48.1793904961203; Thu, 05 Nov 2026 10:56: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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:56:00 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:35 -0700 Subject: [PATCH v10 19/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-19-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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.161.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)[100.77.114.92:query timed out,172.105.105.114:query timed out,174.29.1.49:query timed out,209.85.161.45: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-27278-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: 4F00D1C241D X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX sunxi_nand_chips_init() scans and registers each NAND child before starting the next one. Registering the first MTD device allows users to access it while the next child is being identified on the same NFC. Normal NAND I/O holds the controller mutex, but nand_scan_ident() does not take it. Its RESET and READ ID operations can therefore change the shared chip select and timing while an operation on an already registered chip is in progress. The normal I/O can likewise interfere with identification. Scan all chips before registering any MTD devices. Add each successfully scanned chip to the controller's list and track whether its MTD has been registered, so a scan or registration failure cleans up every scanned chip and unregisters only the devices that were successfully registered. 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 3de9ed6795fe..e1306d14ab3a 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -298,6 +298,7 @@ struct sunxi_nfc_oob_ops { * @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 + * @registered: whether the MTD device has been registered */ struct sunxi_nand_chip { struct list_head node; @@ -308,6 +309,7 @@ struct sunxi_nand_chip { u32 timing_cfg; u32 timing_ctl; u8 *user_data_bytes; + bool registered; int nsels; struct sunxi_nand_chip_sel sels[] __counted_by(nsels); }; @@ -2672,8 +2674,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); } @@ -2754,13 +2758,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; @@ -2768,6 +2765,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; @@ -2779,6 +2777,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 Thu Nov 5 18:55: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: 3892 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 0F92E1C5396 for ; Thu, 5 Nov 2026 20:00:36 +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-27279-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-27279-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 0299E2E95D for ; Thu, 5 Nov 2026 18:56:31 +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=1793904963; b=vs9IGTeQQXNpOL5X0oKTcrE3U8YT1Tv6eagTap1ToWcVl4qe+70/rby/sdzVkO25RnKj 6dROW9K1/ASicRcGwV4Ro9u7Jk4eBtlFzvG3rruDyFGBTbyIgAngdKDL/s0ZE9DgAqiak Ao6VYwsRVUZziV8bDfILLeOAvDS4IsYqAI5S3ZqE5Q4CHlVeekq/rzzfUyDdXa3zfumnk c7YR0TbsKk86cYqc1KdxuOVvI5tdp/Fc/7MZuIeVYZdn0WDaR6LBEpYoqB644iutXSGh5 FKMeu2GIZf98Lh0MlekMx/hlIEKtQ8nrn9gJ4A0eTjZ8WYQswZb9Gyq75yI+Y/sORww== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904963; 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=fuAnLXLxkTRIWi+f3sZBwdM4q2MUL37Wpqf++mUfWMk=; b=oMPYryKSrcU3NDPGuogTQ8AssV4NxdmnethhapOShNg3BIhgHPCtAh9wOhOCS7aWjzs3 ZmjCUIepcl5B18yOfxMtZUZ2G6n6X+hCK4IaBB57stZEJ/UevRcl/hu8Vc+4DxgH8O03g n+nTmrSsLr0F7oC50pYk6tcQTWSkBQrX1r2teL1BY7jQTqMcLYVayqi4JA3om3KKH8Uoh m2lv/p7spoVE63ijndiKEZ3u0bxRAMTHAxbCkE46/Al2FMBl9mwvW7yJHbAV1/NUc+yze 9LViphKaI+Ll36sle5wkyV/f6v5rJtWrIk3lLsdVoSQZ11ECLssMQGKTE5UMouzfH3A== 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=i2EjzxmN; 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 D35AB606D82E; Thu, 5 Nov 2026 18:56:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=i2EjzxmN X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904963; b=aYZlIcFUk/5rFjTtCbWQsxq6+s19gk8sakt5Y8Nfp/3so90AkRgelgCLO/+wQoTzsuq8 4+B5IPD3BGtQAGkByeTAmCpVB8aT1B94pEbf2cpaUmsVdm7hyzoYVJ8b9X7slGdPinwa8 za7JDf1HdfUSBS1jo+ejaDsE49CHaBmuEHRHZTjl177y4JP/KDlzrAVJVPjKpxTBuKpC0 k+mP+cWOGB9qj4uMovSsw0qaXRilXitp/42A1C187OkgnCE49UzgYlq0MFWHA+UvtmT7k tb9zWKcDgKvc7jsTU65iZa2XCum5Zomw3LVIhZ4brpObyLvttWxYablJRkU1ZT2Mngw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904963; 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=fuAnLXLxkTRIWi+f3sZBwdM4q2MUL37Wpqf++mUfWMk=; b=3pmYrMaI5Vt/hEeVmFS+G9KEGWKIA7A7fYYSmfcw61oj6LE29jFTo3zLfeCSGcMyo9fL S1f3G0DJQZwTfJsEA3W87yBLbPavPTFhnkmkgXr3RSemvaEpz7UkfDtR/WSBxWlsdL+dS Jj85jD693f4C4lWWxVcX1rSPllv4XA4/y40eRQ9+VP9IR9LEpN3NcXViAz83w/FVOzAmn WoJ+gf4wLFt+sWC+VsasftWITKmvzQED2s1DlCWb9RUUe549fSLqI/FdyOuCTPKCP8NK7 u2Iz+vG+Ojh/V3q2nLqWw2w2dLjjI4U4P8UxyPuiCdjSQ5M4+ALlNikINMWlViyVghQ== 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=i2EjzxmN; arc=none smtp.remote-ip=209.85.161.50 Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.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 6908F606A339 for ; Thu, 5 Nov 2026 18:56:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6908F606A339 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-oo1-f50.google.com with SMTP id 006d021491bc7-70b875f6f1fso2047578eaf.2 for ; Thu, 05 Nov 2026 10:56:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904962; x=1794509762; 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=fuAnLXLxkTRIWi+f3sZBwdM4q2MUL37Wpqf++mUfWMk=; b=i2EjzxmNhmlyLorG7VwLdqDMz5uk2LAnTwkEQu514gNAH6I5/dyrXBOSCIpXROByIw s6NJCgB7zkDh0ntj0JvhQ03tv4R0zZRsxNg8tdvnO4dAL8NC8+VGKwy8NV1O2xGMwogR SRwFuE9v0i4ApPLNyWcrzsUmS6bai4MOfLVOn9xrLlzVU4QBTe27cXmiHOmG0as/3Dd1 RH3Da5v2c83tELiKbO0zwHvwBiiNnD7OYuDf0sEtopvLZ8sSK1dQfGfnqgyJY0SoNvpM B+dve21J7/OtBTqooJIqWpqZ+mbApsXB5C3XPZPUD+8A434VF/z/b3jOKfeetlcUVg61 b2CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904962; x=1794509762; 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=fuAnLXLxkTRIWi+f3sZBwdM4q2MUL37Wpqf++mUfWMk=; b=w80VKhWf0Sowh793/ZU50F0NbAtYHAF0PZOF3YtYUEGm0suyWiJsQuo8ZFzl+wOknF 9MZ5T5AoYCP8lgduymLfRFRpPiFWwQuHihuZ7tA6ihtCj4XzmRV3d2ewaFhapVsHhNvn bvNKj4PNxGgdFzetwgrkj+X9QjsoZH0WRrnR0iDzWlXlN++7mi3Xpk6ImLdHuGLmJ95t KM4XJMLw2F5/Ov4WPIwtVHSIEGiXz9VRencPXMXOSB92UYCVLX3WCi7q7/TmGyLlM2KL 0LM3C/6TeCp/fG6HHelsjvzAwd3mp43lm1oP4orsGKc98wnVaY6fpv9K5+E/0F+kEJ8a YZVA== X-Forwarded-Encrypted: i=1; AKwUvBx6jwZo/JOZKEQKovPR1NjHGYYqoKFC8kJQDEG2vTALSprtxyn91MTiS9ItkFXMk/OFdpPydtzjMLA0Yg==@lists.linux.dev X-Gm-Message-State: APuU4Z+Qag3qT249PbcpxjP6FSmlauWqzaftL3mcUDDGadsAHu6YyVLM ALCN0YiVQnFKjBznTsTOtvXcuOvlaNCt3ZCcQjpph6TQtzqpXphFEun6 X-Gm-Gg: AYBFou1e5miZ6JEfL4zGXpqCz2Mm5CUeCjGLdyBiFbsWtZcY6botGJsn2vsGPQZ65D2 CR94dQXNGrwMCEDpbjolWn3Q1MN/eptoKA79e77tMnQuUoxUf+ru454QIrJvdl9j9pH1lI+73CF EJEFNcQtRtuoM8SrvuUPV0RI+olOLH/raTE62Z4Bpx6BBOih7IfH4zpI2fjs/44EbW7LPEWGZ20 D0BOHfKLX5XeXI28owViHEV8z+yNNPvxg4VprSN5n0FrfSV5aOl3GpyNkddDwbSAIhPTM+tM6/0 k6fCai3X8RKvwWdTLxsFqZ39YCwVKn/Q9Mu04jP8Tec8TcrJyIWX3fNqmtDJfEp+hTMeNHoHUUD yyErc9QGxKLQco45fZ0q0MMa3BqD3Dv1L5DVDNCQvSqgN3Sb3UwKqi+r+6LPaKcCXGWrVywWk5x /Ox0rITi+eKD5JPDzYI0qCIx9SHla8Sj4sw+cPLtwHKHNtsR0yynuf7jZWgVHspQUvl+ejyjx76 NL4DMNHMn0iuynhA54bkO0ROC2BlPKLToI6qvhaeYvJw2KGv1oSeaUBYGw63Q6/k1qjpYD3IpLN PGZHV5l0QB4DoygQzh9j4Qk8k3OnbkPtHudkLuqv4a0hSX3Z0nQO4J9S9RNkjFcinW2Lif1OCXo Ey+Q46sDakd1rrtj+RFSos1GYs6oW6qyMRyUkzJYt1AqilYdvhV6UPoxp0wKJl2Zh6KcJBkSQZe uru/ASIx7is4gdegg6CJJcrK3R5ELY7XpF9fND/PRyDRS5oZISlVcg X-Received: by 2002:a05:6820:c91:b0:706:50ad:fd7f with SMTP id 006d021491bc7-716e7b33226mr291273eaf.87.1793904962431; Thu, 05 Nov 2026 10:56: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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.56.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:56:02 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:36 -0700 Subject: [PATCH v10 20/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-20-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; DBL_FAIL(0.00)[tor.lore.kernel.org:query timed out]; FROM_HAS_DN(0.00)[]; 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]; BLOCKLISTDE_FAIL(0.00)[172.105.105.114:query timed out,209.85.161.50:query timed out,174.29.1.49:query timed out,100.77.114.92:query timed out]; RCPT_COUNT_TWELVE(0.00)[25]; SPAMHAUS_FAIL(0.00)[174.29.1.49:query timed out,172.105.105.114: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]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received]; TO_DN_SOME(0.00)[]; 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-27279-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: 0F92E1C5396 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX The H616 NAND controller needs its AHB reset to stop internal DMA and restore data ordering after an aborted transfer. The controller's soft reset alone can leave the next read displaced. Require resets and reset-names for the H616 compatible so the binding describes the reset needed for recovery. The existing H616 SoC description already provides the named AHB reset. Signed-off-by: James Hilliard --- 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 Thu Nov 5 18:55: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: 3893 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 879231C5396 for ; Thu, 5 Nov 2026 20:01:08 +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-27280-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-27280-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 D36242F2AE for ; Thu, 5 Nov 2026 18:56:35 +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=1793904965; b=hNJimvC4pIEjzl21VL7E2MEViyS/c6r/gwovxLE/wbS8CdAP3tfg6F/NRxh1wMHEjIhs wLsd2FH52g/NX9L8Z14rPIfaHxsAXAlDVUDl1REjSqskT2SHIUcHzcIj4g3JA2IIU+ztX +DfT5SIdfo1oqHc2zbqPuUXmb6BSs+Ls3SDdEi/hjtRKF4Y71x7wqYnTusbTAbXzsif/e JSnR92wTDLXH6D9OG70PpwulOIcqy1X+aEuRopzHgb4fCIYlZ5/WBPgfeEyo0mn0yWc2e 4yZt7HJAhMnfg5N5Gc1GRS2OOz6VbEIySvdu/bqp+RU12avMV7Wyllt0SV6YV5qN1zA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904965; 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=4VfFDNUuLZDxL4knEKt4xHIe8trG1WlypP2b2NwnIZI=; b=0b74ZE6GMS4RRv56Db3tVp4PCHSnt7sfIB1aoq5ERQyeXntxjW/g0T0AtJqrFPA0rOyY NDBYWF/jajtMgmawz7cdLSAOlypsbAoJmI/aIfHMRyhJdTUbOfZ1Jl/xaP8WrqkLAb9oo DTrRtA/P2fTi96AFZ/Pr/MbggXyKmDyxCJkW+V6r4nAGdGoB49aIxY11M3fzL/nYmJiht nDeY2SF/0V1KYfLXx7+TLHBA23fMZDzIIMPf8hoH7WpWqSI/CKgWVADfGBO3pcsbuPXMo tCrO5IS6Cz0wOwQo50sj0YuqjFb8Y7r0ed8OmHHNvox8MdNNsB7zMFN9DlQierGsAfA== 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="tkYkCU/7"; 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 C3743606A334; Thu, 5 Nov 2026 18:56:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=tkYkCU/7 X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904965; b=OhS8PvNiwKGm9brl3bThZ0QoeH9kK+IQOQILChBkUOJzEBgO1B4fAvg6QSLTVuHneEp9 YaA4BIN9cUxQq0KFsbF+zspLKiuZQRaQdzvLj2MR/2/PZ237qfjEKaEqg5dFrbq0+mg+O 8N6HRh/oOoyXD0yspaZh3MMoZMYc57RV8u3qUpC72lYrWE/r6yZrdhJm5K5KRNL/58f10 Zym4ZYw+wxW9v6xVN/YKczdMUy7/GKEhaVp+/xmyZpwaeaQNTwAnTJDeTbTU3Sd5AluV1 7Wmg6ivyJpg706eNor/OsyS3aab6O/veSV0uNnq1S6rYrUmjIBxyxOVuiqTfeyc/TMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904965; 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=4VfFDNUuLZDxL4knEKt4xHIe8trG1WlypP2b2NwnIZI=; b=1lg5VN2/Y6+5DLSX0ZBv8+hTJI2BlX1hKuLFtJUOHSKFVoQTm0YPs6ShrxLMWz8U9N1o tbIYl0ZklIEvyTUgUU4Wi1cnORZ6PoH9//WiB3++NEZoRpb/njvdOxydX5lO8INYmFUhy D4YTSuZYNf89E1Wn1IytYl4smn4BZr9EZ2IGtlhYX5hI28ZVsYwEPu9WvoZxoQHHV0EW1 9Cj+lfndojGqDGFVepRWWGDKIp8sFCNtHhjrDGBP2cTUdoNe9e2JHzMDWnCTRaKsyK/4s JHXtE2smF9kw2s9+XVcgnHxLqQH97BWJXY3fSERl1tsKGU/2RuEvoA7m/VdS0Ymc38g== 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="tkYkCU/7"; arc=none smtp.remote-ip=209.85.161.43 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (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 AF72B606EE93 for ; Thu, 5 Nov 2026 18:56:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AF72B606EE93 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-oo1-f43.google.com with SMTP id 006d021491bc7-7143451981fso1504531eaf.3 for ; Thu, 05 Nov 2026 10:56:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904964; x=1794509764; 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=4VfFDNUuLZDxL4knEKt4xHIe8trG1WlypP2b2NwnIZI=; b=tkYkCU/7r0FzQCs+uZdUYFqthe3BRjtDbxt3LFEjUZ5/oeApjl67/pqfFhW0sLra9C 5CDAcwL6C828JNSYkHxLnJpDxmel18v0B9IrObjKvbIbIjC+A1xaxlZNJU30kttAEKL/ kc/we8tWI2k3jiI3TeuPnWfq9SgbZmfGayOlNq9kGT52KsypIXLzUZYc7TmiJBNFEXW/ lDH/yS7uTmmhyrUyPHMpswgw7dF6bntQpJN0J1s/pdh1Yf8rWz11ab4d714NaGX3Q/ms CeOrLQ8fMFduuFG2q5WUei2uGmaDfi+p+zYd0ezixSqsjiWRa6OK5HgThzqrU4Qlq67N 3qhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904964; x=1794509764; 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=4VfFDNUuLZDxL4knEKt4xHIe8trG1WlypP2b2NwnIZI=; b=nOxNKtBOz9Izv6+q/aKACL3lS/T/gSC5SUzgV2+cVCO4Szix7Aap1K9vCCsfnB+sy4 JFKmxBUTi0V9Ayn2nIYEpgQPtwzF2lpKuVXGIyqkd5tSsgU3RRds3zBmJZx/ZdqutWoA T32yIzd6gDNIzgNdxzeWiaIypNUk93W3Et50BaxSuHl0ABKZ3qLTD8pIhwKgQEsW3lty 9DppQjHnwsHe4EUXZME4pcYjkhM5iM2Rx7mYj/h3eAUisH9tjFAHOnbmFsI0MeRLL02D +hoc+dM0l6J/Z2gywZ+CN1UDOea2hp/8ek+CugnjLMic4gX03J136bZBBgccl3DkwxGH e1sA== X-Forwarded-Encrypted: i=1; AKwUvByouWu20MutT0IRdhQo+Qk0nMMx2jL1E0kLCoUSGvSFwbRqSxkPXU/iI6Wsyp7e/S1lmLrShEKSIX9auQ==@lists.linux.dev X-Gm-Message-State: APuU4Z+ZSS+H18hoqPzoHPoVv4fQKW/zmM11EGqIJT36b586th/1oL5h 0zkXArtt8Twh4ERcUBPncwbz/iqICuFQp92IAUdDdj0Fo3vWzaj/mvtA X-Gm-Gg: AYBFou3r8UlxdmMmijwjCzBd5pwPdRPredOL2cH89K3YZW8bBoRAVI4CGV3w7KDc9bo mwBf2IqzGkxqHT5ycU+CSQxprBLCrdjyTtTiqeh5xFz8H+1ABN/PybkEU0FpmqW+iSIQvNKM0rf ER8gO2bZN3wf8Oz5k4wrrcU6UR+r++FoouFOw7Qy6KBWuBjH/acIPyzdhAjckB1yk7Y9fPpbQbr lpMCORblcm0kzg1Ctjr1tBbLxaXr6lC5KeVQUhStnsMVNfCmAeMdfGR7iFnwYymwnRG+cB8+oZh akOKUZH+RXybax3cBEb6djdxonfBEavk6u+XYCyz49ZRx+MDy1YimJt9okbZc6y6O7szB+cBz6d v6sGq5wuRTSZkN3wYkWv7F7sIOPUjRikd4+BWEg0Lz3m2Mvm2+aVqsFh8dEB6P/oSqH5Exngtpf KLt7O3x0R53nJwj3PmLnluwjfCvyjDcqR1tsCv5/wEeP/cRHz3Xq3lN0Clpk3ajJIR/Wpr8LDWl 9OZrsk+iZ0a3AlX558jtsXpkyvgAhwRGq/h1jUdjiaX9cdV+iwqPaXwGsDhbt0OD4TzMZO4Sx++ KD3u4X6NPYQmfiNEQT+r21uM2od6C/LD7Wk/2v2IKzhPsLz3ATAALwMsWbe7Esti7ODYeI+54PC GhKD+PN6TlJvrucyEhYRJ1WbkAyEi30MQsqww/HKrRs2jqONvzOFLaRjuzAfCuNgVjt39jmlwnc KPO5jmMZ0JxONjoGkAdPrH65vs++MS64v8eg/YakZH6FGRnA/NN22L X-Received: by 2002:a05:6820:4481:b0:703:10f3:89e4 with SMTP id 006d021491bc7-716e78a0258mr317119eaf.42.1793904963622; Thu, 05 Nov 2026 10:56:03 -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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:56:03 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:37 -0700 Subject: [PATCH v10 21/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-21-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [1.01 / 15.00]; SUSPICIOUS_RECIPS(1.50)[]; HFILTER_HELO_IP_A(1.00)[tor.lore.kernel.org]; 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)[]; 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)[]; TAGGED_RCPT(0.00)[dt]; RCPT_COUNT_TWELVE(0.00)[25]; RCVD_COUNT_FIVE(0.00)[6]; DMARC_DNSFAIL(0.00)[gmail.com : query timed out]; RSPAMD_EMAILBL_FAIL(0.00)[jameshilliard1.gmail.com:query timed out]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27280-noreply=patchwork.local]; MSBL_EBL_FAIL(0.00)[jameshilliard1@gmail.com:query timed out]; FREEMAIL_FROM(0.00)[gmail.com]; MAILSPIKE_FAIL(0.00)[172.105.105.114:query timed out]; TO_DN_SOME(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; 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)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 879231C5396 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 the same reset operation before accepting transfers. 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. Propagate unexpected reset errors, leave the IRQ disabled and reject subsequent commands. Avoid register access after failed recovery. 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 | 90 +++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 14 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index e1306d14ab3a..e8286dc360ac 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -335,6 +335,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. + * @needs_bus_reset: Aborted DMA needs an AHB reset to restore data ordering * @legacy_max_strength:If the maximize strength function was off by 2 bytes * NB: this should not be used in new controllers * @reg_io_data: I/O data register @@ -368,6 +369,7 @@ struct sunxi_nfc_caps { bool has_ecc_block_512; bool has_ecc_clk; bool has_mbus_clk; + bool needs_bus_reset; bool legacy_max_strength; unsigned int reg_io_data; unsigned int reg_ecc_err_cnt; @@ -412,6 +414,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 { @@ -432,6 +435,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; }; @@ -644,16 +648,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) @@ -665,6 +703,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; @@ -1496,8 +1537,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); @@ -1874,9 +1921,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. */ @@ -1902,8 +1950,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); @@ -2904,11 +2958,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; @@ -3021,6 +3082,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 Thu Nov 5 18:55: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: 3897 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 232641C53A6 for ; Thu, 5 Nov 2026 20:02: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-27281-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-27281-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 E92B235E93 for ; Thu, 5 Nov 2026 18:56:36 +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=1793904966; b=u5jyF9j+aHGpCxK+LRFi6yn0DduuQEG5eY3X+MQ+124Om3OgXMeP0qR1u8f4esLM3W3z JiaWl6+u6aFpZHIp/gs/x5WNe641WpMNzWY+Be4/i5rSyBS5gnma+xzAvy5xhwyhVkimk UvAl9X2v7zQCSBpJ8ixoaMRVaowyXw1+QDlmsSz2S/hjGxL+ulvaal6CT0mF5k9Lq6jXF vqAqKuKJ3z2oKNELOXRF3nr4VJ71xeyCLyPBk2VMrzMECH9vYLUJH4KHJXwwroOMuok5Z 7vcjHany4+aL1zo6bOx8WfSEzk0rQqnmVKE5WB9r6CWEZxy+9kHkIZ3qJOClosD/PzA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904966; 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=DQAy4dqYs7TjtXxWS4cbH8B9UiQeX+sxPX5st3d37Tg=; b=vlnQVoKuIM5lVBdr6IAtq9N0zI5quHZDTFdftdYJXgUk2uqhRPjBMos/9Z88mLQBWmeE BJyCRxCu9mvKChvapYjK0szFvXtc2sSFAaT1V2dqknYQnaTKJtfvV6uOZGMJ5eFxKtpNO cg8+9u177B9NTVCOign/iy2MpE1npUENIUYyOT2gv1sMxnXX3kAh0/3DG2ZAGiLQdivb+ Y+WD7qXqKb2GsSjdHV4n4mujob9SYRzo6n1ZfOxbksHp+dKPtgyPtd+SA58Z4ilUzqF6B V7JNpjHr5VrGsmC+M4PZ/FSaa88z70UrjLjwQ6/mPAfhSS4fz//hkZHBsXmb8BUZYBg== 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=d7epUc7z; 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 5FF686083621; Thu, 5 Nov 2026 18:56:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=d7epUc7z X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904966; b=PgRhVxJAn1t0hxDvnXwh2RTNQB4ZSlpdQq3Fapvv9UgXCm4cXpo8hf8tGcp1IB+6OM5v Ry5uGj9AOj5X64V/Prq05TBp/GrDoBYuGn5o7zuHygIi+VL4U2/NuWb6UJIIjmucUKd0B gj5bbNhhvlWf5EOV2JT6QUCyi3J/Hpqy+VCHMeATxl0xUxAyUouWC/AiBf7zK66oTCeRX 0tZGTZuFnWuomDzbRWz7YgKwfHxLNXCfgb2PBilSfRIhCybDD1nnz7NZAAPa07FG6qdWI acc4cbRUM3RMXzmG9M1ih2s+dQDZO72ZMQCphl2mXEX8VA1MOYG0e3exqPnin4zwPCg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904966; 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=DQAy4dqYs7TjtXxWS4cbH8B9UiQeX+sxPX5st3d37Tg=; b=nI2mmkLppop0MgKt09v3sycPiIYP7CcIW5IsemSOkqr01jQYlxld4syjQxDOxuQIVtp/ vBT8x2D2MWrPVzUdaxIc0okXi7WiqZLxZZOeAxPshDgnhA3oNr5jfVf7BfhfJ6q6gOnnu xwOl7GwrRB63nnccP8jdlyLZycV9ete8umAlF4an6HNfCbGBdUFD3GrX3grX9wdFHvTQN EQ0Lisp3TQ2a4sjCwRpId+X0gHvnmbEtOseiH8no4gtV9KWX1b9e1o8iOTH5qC0fb39xP RFkfcR/3OoPIn2iaVAKFUnbdpMzoyXIieqkJdYmOB8vMgq+yh/DHQM4SliUk0ZvJ2uw== 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=d7epUc7z; arc=none smtp.remote-ip=209.85.161.44 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.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 E29E2606EEAF for ; Thu, 5 Nov 2026 18:56:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E29E2606EEAF 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-oo1-f44.google.com with SMTP id 006d021491bc7-6b1afdf5196so932923eaf.2 for ; Thu, 05 Nov 2026 10:56:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904965; x=1794509765; 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=DQAy4dqYs7TjtXxWS4cbH8B9UiQeX+sxPX5st3d37Tg=; b=d7epUc7zW68BdhOLN0bGJfpZTehqHTKbp98tORuKKs1fgvYxY4mlP+/ZuNjlGAK7BC BCl/v5XxWvJTwQ3ugO2GgSbnCk50rcwPtEzOscRNFjvLyq1LpIyWTIN+Rz1+8HXJiD3X 0Us3uOcEFIruLsmZt9hSLaPlAHrkQ4r797Ce+budAAtL7h/Z7SEAQ1yUhBEIlUDrqhhX kEPbyPyv4DD9lTKriCg8dHw0fGhSQ+8D0qR8NwLVFdF5BvRAepeAsd5IaXCqxHrY8eSk MMPTkjba4zuczKT71eIPs82KtO9RK2e3pdAQzNcbaEpQJAgG0viE6VQIHwwHhRCdHjPV LGFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904965; x=1794509765; 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=DQAy4dqYs7TjtXxWS4cbH8B9UiQeX+sxPX5st3d37Tg=; b=eUyXQ3/VHmc8/FmCYxUXRKmLvH0OB4Iej1QgUdDtw9YOZgSGKDHW06lZVQGMXabE+d jC8Aa2twXy05kczwi7l3hVrFzPx+DG0NuD7T3tItPZQqYghueqmfEIwKINHvqeaAtyTv djNxIoK3Y78ZKt+wTY8WsWHaRlIhnr5z5yQGQO9az0RuR3efXjuGz3bO7SVfg72zwIWm NLZsynaCGUeQF9zLn0xrCexSI+jCn8a8lH2KDIyvmgk9jpNk5pXCmZbmucMe0QjMq0LP hoinqkF5GwyX3nL6L+jVOzJLwBjeUa8Ndc+zZaijoxrOhGB7Wany4MtoautVbMFL+v3I KTPA== X-Forwarded-Encrypted: i=1; AKwUvBwwAofHjH8i5qS3jC8crTHWO7CsqxhUdSXjPCkHYomVkUxgRb6flK41c977HPuR9+X/uL7LfwqIwKl4rw==@lists.linux.dev X-Gm-Message-State: APuU4Z95TGPA3p2DCB812NBkIKaTYn/ur/kt4Mp7Ugkqehaj57COl7ed iw92PcbXfOR8lHufSG9e+h+S87V6PZH3u3J5NcClAEhHMbb9igJWzdF7 X-Gm-Gg: AYBFou2idlGJKrZjFkfsz0rmbDp29YEMfgPg5OZ34Cqg2wrYOgGBsZ9oe/6jpvkm5SD 3e4cpe+8NjRS99IfvyNs8StmI5cFlH9tjzY+U91tkoEqhYlyKV5kHhy2OlErrH/ui9iX7xZpe8r 8jjBI/u/uBWwxh4/Bb/bhjj557eaq79M2mu8kS07CwO6rBbAa6nJezLf1RwD7jRIyk3qxxe7qwo GCZXMQO7sqqdf+tSiZn3JrsiwlYpdCahkCMU1nyA6upf7Xz9U9yK1FYF5bP/2NDk8DXqQ4r/Eq1 NfbgeI6P6nEyjP5kIfAOldgoUcU2gB4+/RdAhfO1veVrmWKVT2y91mWxlKly533tXNAwrg4fqaU tmoo1mrhqwb/hHCJ7L2OMFyVX7g98ePypjzsf8WftpLYkryTjBuR8yjT7BO0r1S/yXBODVB7nH5 qKUS1mY4pJZVE7IUM4PKRJp7Bbh7SGOtg5+czd9uMtcnTrI1XQSTFAigCkjhGckHdkRhRxGm9Mv pNVS3DtHwnvGit3L7UJHhdIsXefaTadAdxDTE1l/DHAEZQVOOlvWYSkveOINcb2KKvJUsFWyVAR y3Wkk6nwFKbW11D3GTmERprklSKFgeK3jkt7nWTxOWf+2NRxGVKXk2X+gw1woh0Bzv4jLSzWytW NhFcppCYnls3cyJZgndc3mA79cKrgsRt5a1+z8IDTeDoLxtZTIRpap8mcfZ2IHjxcqEqT1SKuFk kP/WiXPrpqVjmS1FQQRPoEnnwADoqLPIAiUx5OFELQJzQu0MfoWqNY X-Received: by 2002:a05:6820:340b:10b0:716:d710:3f2f with SMTP id 006d021491bc7-716e79b789cmr261602eaf.64.1793904964805; Thu, 05 Nov 2026 10:56: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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:56:04 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:38 -0700 Subject: [PATCH v10 22/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-22-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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-27281-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.161.44: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: 232641C53A6 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX A completed DMA batch leaves one ECC status bitmap and one pattern bitmap for all its steps. Four consecutive steps also share a packed correction-counter register. Reading the pattern ID for every matching step and the counter word for every corrected step repeats MMIO accesses to the same completed result. Snapshot status and pattern information once per completed transfer. Reuse the status read when the controller places pattern-found bits in the same register, and read the pattern ID only when a non-error step needs it. Use a cached accessor so a reader can request pattern IDs without knowing whether the initial snapshot already fetched them. Cache each packed counter word while consuming its steps. Keep the snapshot local to a single transfer and invalidate the cached counter before processing it. Consume lazily read fields before starting another ECC transfer; each PIO step and DMA batch gets a fresh snapshot. The ECC decisions and returned correction counts are unchanged, as is the page layout; only redundant register reads are removed. Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 108 ++++++++++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 28 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index e8286dc360ac..11fdc10c7f14 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -261,6 +261,7 @@ struct sunxi_nfc_timings { }; struct sunxi_nfc_ecc_read; +struct sunxi_nfc_ecc_snapshot; /* OOB geometry and interpretation; callbacks may issue supplementary reads. */ struct sunxi_nfc_oob_ops { @@ -276,7 +277,7 @@ struct sunxi_nfc_oob_ops { * Return zero on success or a negative I/O error. */ int (*read_batch)(struct nand_chip *nand, struct sunxi_nfc_ecc_read *read, - u32 status, u32 pattern_found, int first_step, int nsteps); + struct sunxi_nfc_ecc_snapshot *snapshot, int first_step, int nsteps); /* * Finish remaining OOB; return max bitflips or a negative I/O error. * cur_off is an absolute NAND column, or NULL if unknown. @@ -1212,23 +1213,82 @@ struct sunxi_nfc_ecc_read { bool has_erased_chunk; }; +/* + * Transfer-local ECC result cache. Pattern IDs and correction counts may be + * read lazily, so finish consuming them before the next ECC transfer. + */ +struct sunxi_nfc_ecc_snapshot { + u32 status; + u32 pattern_found; + u32 pattern_id; + u32 count_reg; + u32 count; + bool pattern_id_valid; +}; + +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); + + /* Zero is a valid pattern ID, so track whether it has been read. */ + if (snapshot->pattern_id_valid) + return; + + snapshot->pattern_id = readl(nfc->regs + NFC_REG_PAT_ID(nfc)); + snapshot->pattern_id_valid = true; +} + +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); + snapshot->pattern_id_valid = false; + if (snapshot->pattern_found & ~snapshot->status) + sunxi_nfc_hw_ecc_read_pattern_id(nand, snapshot); + /* 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 step) +{ + struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); + u32 reg = NFC_REG_ECC_ERR_CNT(nfc, step); + + /* 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(step, snapshot->count); +} + static int sunxi_nfc_hw_ecc_correct(struct nand_chip *nand, u8 *data, u8 *oob, - int step, u32 status, u32 pattern_found, + int step, struct sunxi_nfc_ecc_snapshot *snapshot, unsigned int user_data_sz, bool *erased) { - 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)) + if (snapshot->status & NFC_ECC_ERR(step)) return -EBADMSG; - if (pattern_found & BIT(step)) { + if (snapshot->pattern_found & BIT(step)) { u8 pattern; - if (unlikely(!(readl(nfc->regs + NFC_REG_PAT_ID(nfc)) & BIT(step)))) { + if (unlikely(!(snapshot->pattern_id & BIT(step)))) { pattern = 0x0; } else { pattern = 0xff; @@ -1244,9 +1304,7 @@ static int sunxi_nfc_hw_ecc_correct(struct nand_chip *nand, u8 *data, u8 *oob, return 0; } - tmp = readl(nfc->regs + NFC_REG_ECC_ERR_CNT(nfc, step)); - - return NFC_ECC_ERR_CNT(step, tmp); + return sunxi_nfc_hw_ecc_read_count(nand, snapshot, step); } /* @@ -1315,7 +1373,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); @@ -1338,8 +1396,7 @@ 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, - user_data_sz, &erased); + i, snapshot, user_data_sz, &erased); if (bitflips < 0) { /* Preserve PIO data before the raw erased-page check. */ if (!read->dma && !randomized) @@ -1348,7 +1405,7 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand, } /* Both patterns are already filled; only all-ones is erased. */ - if (pattern_found & BIT(i)) { + if (snapshot->pattern_found & BIT(i)) { read->has_erased_chunk |= erased; continue; } @@ -1384,7 +1441,7 @@ 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. */ @@ -1392,7 +1449,7 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand, int step = first_step + i; int data_off, oob_off; - if (!(status & NFC_ECC_ERR(i))) + if (!(snapshot->status & NFC_ECC_ERR(i))) continue; data_off = step * ecc->size; @@ -1434,10 +1491,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) { @@ -1473,12 +1530,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_nand->oob_ops->read_batch(nand, read, - readl(nfc->regs + NFC_REG_ECC_ST), - pattern_found, step, 1); + return sunxi_nand->oob_ops->read_batch(nand, read, &snapshot, step, 1); } static int sunxi_nfc_hw_ecc_read_batch_dma(struct nand_chip *nand, @@ -1489,10 +1543,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, @@ -1554,12 +1609,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_nand->oob_ops->read_batch(nand, read, status, pattern_found, - first_step, nchunks); + return sunxi_nand->oob_ops->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 Thu Nov 5 18:55: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: 3895 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 8F6F41C241D for ; Thu, 5 Nov 2026 20:01:36 +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-27282-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-27282-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 973C72F720 for ; Thu, 5 Nov 2026 18:56: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=1793904967; b=WP9k4OPvLZiQcbey8Ne56qiRf+2ZqRrKqqByVLLYuTXAWgfzYP4MxgI7A8ppDcCDQ2AR k+A6UsgRqzic1CJwA5ayBpNEZ1GCI/14V5tEmTkf+V+V6IbsQ++3QP0jMnOjyxF9QzERk DXxVhijAjfz+X4u/hUOMioQGtJlZuK9doptatkA3HeRDJ3/2luvF9kEqO/uiMQv92WrHf ZKZ7bq1eHR/uxjhLHoNLQh4U59CZNknBGpWnw7e2lopYOmgx3v6kj92VoDN2AqYUK3WGT TdUQuGWnup+6BELk2ySr2a1zaXyB+nd7zPzWoyYy3OaR8JRjjKeNl9Zr2ucsjyFBolA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904967; 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=F8PJ7Wj/MurY/COKSMskXdHgUwbyiv0TEDO/uX+R0bU=; b=4qfDKSnLZ79BFsZJe0/1e6ZLIL0wpgTkoMMcBZ7uZgbu6sJY//WirjfJDkb9KgMmcD6O Cp/iCQ68kjHUAUiY3LcRNL1sPURu3uAeKjXJp0aQbSBeDNqw+PfUDw2LrfLF9PR5Tf0M3 +dAud+W7qD7cO4g7/P2NWJ2dZ94WQ07XrtODQG6fSGWdduSc/zE8+XZIFkbvzTfGdMyRd B5DL4802RuqIz8uY9mtFBF2xsyGb5SyHAVscPgtdy8a4MtlTz1EpRxIdGLWBcXIzp0Mue krJVYu1cS/HYTBZyL2nlyPxmCt0wpkkF8+2c1lM49DQsxILKc4F3LnvR2Qz0kOAy05Q== 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=ePbfsBne; 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 7FDEA608363A; Thu, 5 Nov 2026 18:56:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ePbfsBne X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904967; b=f9+8Vmj9ovWUls5zJIS9c55wUSo509hTsJjdZDzqQBsFD3Anw1bagnHQxB6NZ8Q75T6v FZqAXLVRiFm3rkj+332OtNw3I9dRiF0eez79rl/AZdnu7r43lj8y/wcKZctTlzLur9CaY ExhO+KpowvQgfRiu09fwMa+qzXpXTnYhUAdep4tFbP6Q3dcrt5locd5qrM+x742MsYmwb SKkpvnnOs6lDXuNDTckTseMvqSsUXEI4c0NFsWojrCccLYL2NyKLBb67igB3txXg5JHpz B+fR70mxWNDT3GLzfZeLIBRVCqThiXn3C5w/zv/GEyAfowx+lYFEetuXS/lrJXlVdjA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904967; 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=F8PJ7Wj/MurY/COKSMskXdHgUwbyiv0TEDO/uX+R0bU=; b=qmf4m7v1N3Qc4ohsWTQA9xVJ8YQ8+JL3DqogaRiYNYETpGuh9pzmLZ5lXuLWsB86n8Ar UvVJBZAASo/kEeYy248/IbdIriNZWurxsjupYA+BExgzkaVXFvLmQ/7BLU9VYLxjvLiKD 0WcEyJlerUvRf9jl+WU3S9kH+Z17RpcCd9PIwDxdnVvm4WUeR2rcygSH38yUALx3DGjGq BhI7mzWWWRFNcRJJY1xSaDw+Lk4U0i8vFwQjtDhEVIVJMldhX3PYcYi4hfVbSkajiheoR GhhSYlYoIFT5iBKyP7g6/0zd2xYjlXbqhspVUIvS5hwSxOZ3+ZkRY/3wkHYCm++HyPw== 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=ePbfsBne; arc=none smtp.remote-ip=209.85.161.46 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (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 1712D606A337 for ; Thu, 5 Nov 2026 18:56:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1712D606A337 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-oo1-f46.google.com with SMTP id 006d021491bc7-6f8a519e215so1084573eaf.1 for ; Thu, 05 Nov 2026 10:56:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904966; x=1794509766; 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=F8PJ7Wj/MurY/COKSMskXdHgUwbyiv0TEDO/uX+R0bU=; b=ePbfsBneSS7MF2ambGNIoEm+8UHP+fFAHXDCZzy43alE3/ICmiCHflZQ1EinMrYiXN 2xo8XkFVpXBkpJD2bcUJ72i+w0Hjz2do/ueu0rhrLr5F6yPUAezcva3XfzWCt8BV+j8D ah/qojfXyAsVLAAZqZsSeEci7XCOjjt9pPdD3Gn+pqwwfbWQPpcs/mHRpXZQZGGT+yvF 6xtdcyAjY1WEaBVTYpXdh2T2zMdrEo2VgUi8tBpaqshzRiC+n/YPTPuQCwiVZ/GVJ4WO Tflu74lTY1ydGkONd2KRzU2627k2Wjfs0r9DE2XTQAb2RUtid7rSvygAS1YOVPDm/fP6 sPhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904966; x=1794509766; 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=F8PJ7Wj/MurY/COKSMskXdHgUwbyiv0TEDO/uX+R0bU=; b=cGrPw5whVBwGKGDDtU4LkWwphKmkBPhgh3GmzoUV9Mb7qYCXZWIKn7lEz3wHyJC4mZ jRsst3KAHSWy+M3QFlFD31V4uDam3hWy3MZe1pB8xQJq0h0DzutY3yxMZvwq541WDlLZ 4ScotEuvMD21fc7F2Ue1AoijeRZbB9VfWzt5vQpG4Ew5VifhytQoFDnB9rIHbQ4SHQ03 IKBEFNb9jhZO5k3DNsIlddVZElA98eqqu3HwE4+JqehmWNqlpW+76mQBOBmlkzr5rMzq Z0rOc9DH8L+cbyzmSS5IBkc3BWSsIU/kVWOG4iGKYl1bz+qvc2PHntJLp7lDwzPFssao RnlQ== X-Forwarded-Encrypted: i=1; AKwUvBxUhV7V5w6mAahL76dZIjnG9F5bpUqnTygO6XwVuvEnrSr7OOufEYGxWCMV7M0NH4BqiCmBVkIR6SE1oQ==@lists.linux.dev X-Gm-Message-State: APuU4Z9zmEQ4594NkcBsaM3J6P/JDoOFefu/qOVqiJe4QRcsx3twQ8Qz EQLb0cHvhdJaBdN0fvYId3OYxFfFdPGh1JG7WEAN2R1FLm2Zvj7/MiyU X-Gm-Gg: AYBFou0kVTwQ9B8Sdre25zMTlnhxicKkQBhefjwlAIDrLT3gJM9LL0KmL7lJk5rOcdz uHoqgd6N1TfXz3V46XeqicR3y4dSo9Bgd4dd6FB/WUo7F3H7JvmVyEQ55sILz135ZZ15MI8mk9x bPjq0O+yrjpV489IYrxTt2OJP+Yk1MK01r96nMFw1KY0zGXAb5SXn9q2iO8kVfRmUoa3WSgL+vt BtwjCs6AD9pNMNFkXc322LYi/vJctgAqbSaeinNUsLbSS8GlH0Y94iRX+HpoNoe5UJXG2YGaIs0 XTTkui4VFQ9dcpl4AkaEesH2JLmopUO5x2vK+RxaejbELPLX2ZPx7tXC/TpNjV2gxnoJNDg5QGk QC2GRQu5B2UDJrElOcF0BuM92S4tNxpfY5TJTTeogtHSGwd9+6iTas9YRJJI/NCGcXNFe+ckJmS hXXvXS+MSf36wNuNqehtgvH0jzsgCT1d6w2qO52Ee6nCfj4Y8ubPhss/YXXa6Kee4JeiTUpST9d v2bHLHHacNyWCrN1zg7lFYs9AJTmE0Cw3I1tWhChWu6cJfUqZhuPsFYLQRWI4pLCgbRfbRLH3xF Gc1WFFZHA49SMtrIQ5DiFHFvsarmaJAwaeMNrVcXWlsE2ia1sgoVY5WafVu5tIDreS3bIBRY24C SkKZrmkBfB6hMTdVM5HvnThfp84Zy3P6Rjjvoly2H4eL0VpZTenlmNEUS2K1A2NRAun7YIMwql2 xCH8482oEjnJ23LpMN9VMv5Iso/RTrkyLHYgrD6v2Ncf9ABbRsbhVYcLrTIBgKqgl0pN7Win0Zd g== X-Received: by 2002:a05:6820:151b:b0:716:e9e0:543f with SMTP id 006d021491bc7-716e9e05899mr67251eaf.11.1793904965992; Thu, 05 Nov 2026 10:56: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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:56:05 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:39 -0700 Subject: [PATCH v10 23/26] mtd: rawnand: sunxi: avoid redundant column changes for extra 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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-23-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-3.29 / 15.00]; BAYES_HAM(-5.50)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; HFILTER_HELO_IP_A(1.00)[tor.lore.kernel.org]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; RCVD_COUNT_FIVE(0.00)[6]; RSPAMD_EMAILBL_FAIL(0.00)[jameshilliard1.gmail.com:query timed out]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; TAGGED_RCPT(0.00)[dt]; 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]; TAGGED_FROM(0.00)[bounces-27282-noreply=patchwork.local]; MID_RHS_MATCH_FROM(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; R_SPF_DNSFAIL(0.00)[temporary DNS error]; FORGED_SENDER_MAILLIST(0.00)[]; MSBL_EBL_FAIL(0.00)[jameshilliard1@gmail.com:query timed out]; MAILSPIKE_FAIL(0.00)[172.105.105.114:query timed out]; 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: 8F6F41C241D X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX Extra OOB is the spare-area tail after the last ECC step's protected user data and parity. The PIO write loop tracks cur_off as an absolute NAND column, starting at zero in the main-data area. The extra-OOB helper instead compares it with an offset relative to the OOB start. It therefore requests a column change even when the last step has already reached the tail. Add mtd->writesize to the comparison, as the read helper already does. The comparison and the column-change command then refer to the same byte. Keep the command when the cursor differs or is unknown, including the DMA path, which passes no cursor. No transferred data or OOB layout changes. 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 11fdc10c7f14..c9135c8abf54 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -1718,7 +1718,7 @@ static int sunxi_nfc_hw_ecc_write_extra_oob(struct nand_chip *nand, if (len <= 0) return 0; - if (!cur_off || *cur_off != offset) { + if (!cur_off || *cur_off != (offset + mtd->writesize)) { ret = nand_change_write_column_op(nand, offset + mtd->writesize, NULL, 0, false); if (ret) From patchwork Thu Nov 5 18:55: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: 3901 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 E515D1C53B8 for ; Thu, 5 Nov 2026 20:06:09 +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-27283-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-27283-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 65DB92D2F7 for ; Thu, 5 Nov 2026 18:56: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=1793904968; b=1/V9but7DSF8cqUn5H6tWrg8dokT5R4HEmoSEzM50JEOBZoxALkJIg7xFW2+O8ZEfae8 BSfG/gr/7UgxEHsS2dnyx0RuamG6dhJf48W5m5cNPsaXsHWJaxiSYjvNSeXUznavxxvr+ 3R3+xLTZxeha84+yzG114x9eVJhN4LjYXJZSrdk77xJ0PYPzV5eai3GMNR0TFLXrn5Q2+ 6JO/F82Wrwe27okSB4NO1G0W2Nbede7ygkpQ6e7bAaDsDvY17C08vNpsKGirKeQA9KWqI xmb3j1eqPrh2hZab7bhyM3KwzeNHepr6nZDFjnnRv6hQVVE2lGoMubpD5ZVAMpBwuZg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904968; 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=Kyb9Vh//GYgUYYgsTf0Rac6RrMspxNg0WSg6hXKbfA4=; b=o6UV0hvjyXkBB0SgkzUGtF7r76dw1r/BkfDJU48silGxW7ZEPj6UQ/KhCoAeko0QWYLS wjDEILGp8ZECtyfz50f43G0Nnop7RKJouvx04FeMLx1+sFDD++TjtcL70ctIR85IYZbyV YORO8VWQ3WtDzYSwA0/4utQDFmRQHSCmAPaEOPoO5HyA8Xrw18Ck6xWJPSo1/e0tZkVbf MDtCxDFriYAIRmLGRy8BdWDau1inIYb/k4O/1edF6kLiNzRFNO1un5SU5Goe1C4QF8qfs PoZRPxAJNLpY9VpAyrnY4k9eOPbiTv1teXVlVyysLL6GuS9ZoH6h6k+B5ufUYBWILFA== 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=AJ+qVKXA; 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 CADFE606D805; Thu, 5 Nov 2026 18:56:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=AJ+qVKXA X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904968; b=5h2zuPXVRcRWJUVCtNLs6JqxDmtjnGtD4Sp3jLSENMQuB3YAfbCRtYMUTY2ySQwvnvnf TRgMbGprOkn4HhTtn0Pzw5h0olZOBqfBNLGI5qQpMlRxiB6jqdsD3Lxw1nayMLEvlausw bfkmcaedIHJCxUjdbVKJ2qtyYlILAFXJ2B8dZyOPtcilla2KUdAYrqfC+9gPEWTzxhQCo Vjimd6SCs25pkSNgt8skhpjmSf4jzBm0hGeHvZie2BLqkIps4HPwSBDcDTCipWgGtI0mx iop67xr6HqvcJjnd3QYuv6ismV+BVVkX34iXUzqo3GcEEe0/DCmegCYgpLU8V497nOg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904968; 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=Kyb9Vh//GYgUYYgsTf0Rac6RrMspxNg0WSg6hXKbfA4=; b=R3W/BrKRIZH593WLVL05Hr097xtyjIbhd1VDUCmEvjfNF75t9yRCa2M/E+WoTcVNIceM eB3IKBGj0WnWMB9yWgwTXb9K3/TRoADuTptxi3MTLGa5WgovTX4RKyXwagwMB+2xHasJE 9tn+wAdEo1PpknS+n6kbV9Yn1HhRFP1SQ70fseWBBHpkUwmobdxNk/yLPlItE/QPwfj9N hvVBJQDMVZeFtpB5qyuaVaUQu1uyjzHmaTA7MASxFy9g5vOeOumtrEgtp5kUaNKUnp+YY F1t1n3ljPVP4whJZp2T3TkiUtpU5eq/rtRu7UQD6Fdcv8+68a1AlyePm4CP8FsGvZpQ== 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=AJ+qVKXA; arc=none smtp.remote-ip=209.85.161.47 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.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 638CE60A260F for ; Thu, 5 Nov 2026 18:56:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 638CE60A260F 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-oo1-f47.google.com with SMTP id 006d021491bc7-6e560e00a86so1474724eaf.1 for ; Thu, 05 Nov 2026 10:56:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904967; x=1794509767; 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=Kyb9Vh//GYgUYYgsTf0Rac6RrMspxNg0WSg6hXKbfA4=; b=AJ+qVKXAUrj+khNAk5Bz/7tp5erSiWVPU4PafTfe6CnulI520rC8keZjqYe4LGqIJU 6aSfMHB7JxAXFD1cYI9qbk4UqIXCqzfthJoHjCkxpz9cz4pKJ3UzpQ9sBltQWgbY3j1y RztHpHDtl6F1MURINYn/AMzF5FOVSzf8WXKoUJEI7M4u+V4XKS/9tI4QXJgMvbUgirww xWmZ7wD0KNB5eDFgQY6hcwk/kUlM/9YUfdQIL0X5g8BapywaaegilqtqQy1FOolDg18R 87zLF5Da92pDl+n6PjgMs7UhVRP1BfTJeTIn2+wPWIq0PEDI/5e54jQPaKwSokRrI1ZZ 7oCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904967; x=1794509767; 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=Kyb9Vh//GYgUYYgsTf0Rac6RrMspxNg0WSg6hXKbfA4=; b=tMuQR5fwveVKL+AyjtzK5zXuXfH4jcQekAydqiVPxld4wXN9LE+tZiZeJxHQ6skoAz 7LafHGkkoFzFkdQpoHQkU1A0AQJ4WYtpvPOEHvavyBcVzOGv33e/qFVYVmjIF+guNbok hthzsGukrQdBklibirQs5uo1TZOFC2fYI1uCvybynlUuXkNi7h0AhfZD3MTasZp0EFed eX3uFumM9QwI73/Aua6S+pqbTrgRso+LTRdYApPdH6ldRiEEaUSSZ9CBmj8hVMDCM/bA FttaIjDVp4NAmleymkp09XBBFJgucTTCngWhkopf1MDI1U5u1BkAcHdpVVc6hieS/3y4 NHtw== X-Forwarded-Encrypted: i=1; AKwUvBxVd72lEOqoiaL6szR8ubEz44wxsGG87HjgUpZsGxiZalsD7e7BtY/r2IeDGFjB8zM+NDOOd9qVpUU5BQ==@lists.linux.dev X-Gm-Message-State: APuU4Z/R/fvEXspkzMU0IWqyxoKSG0lA+gf912ykTBGJDiC5TQbcHUIH moddDi2/tcFJhwpka5ETuj4EzvCgI8Tn24BPtFDMloeGpmSEC3dXGtIs X-Gm-Gg: AYBFou0o1q5hfKiIlo3vES5Gr/3Df75p4qZxbs5UHbsHQCElyWkoNdSCJd/WIaBz7W2 7nPUDmi1DjIv099K+cECZT1IVfqjzeBla5kTd/o8DIfFaM/f7zeVR1DaA8NKJ+YNozfaS2L19Gs vRvIToFVcu4azCO2uxeznTAGlbocZvIH6haGhN97Guyjup+DDANeyDcdPwRssBLcHlvhMOS/Mqa b/zG7dRf+M9CYrPKdO15qLDDspPtk/mRTlT7rj+zw4f6oKOGpNsLwfLcKfAvFnfcCIwKqZPZtCd mrApqxo+U0rtrI4Fn2E1mh8X6I8PReUYCgZxvTtoddl64P7YFx2wy+jF1/+E0CQfd3k4xdDWii1 SM128RiGrt0n94owItL8B/QrdYct87qEGPMGao+ex2+sewF2urV0E45NuaN0XpyEsvCiWKaL3bA +K71gCMSO2xQEbhMEjLfoW9oBlfSNd3HEe7dhU2uO9fVsJUFwSKG7lvTiTQfHvDQGSFQ+UFcDwo gKSAqZTRr54MfGLdnYG/hZdfGWK7mlttrZDM/B4vl4SvEpwYdwmMUxcecDar3/R+KYh96gGZPpR 89CGY5GvAJQ1NIh6LL52PLFJJu1z0NbWKz1v4vXwA3Syg+366A5g5Z9n63C4sF1HUqUEZkHEEc8 dJ1cEAL6FiFMWTXGFWNmqYTDH0lnrEkoDbW9TO/bEq5auO+mxEZSaVra+xk4UZuxsbaAJvIRpe9 jcdj3YXokfpLhd2AStx05OTQaO5+hA1bBlnL0h2E3I2UHVZbO2cQtPIxySiWTf6WrQ1CJhy0bL+ A== X-Received: by 2002:a05:6820:7408:b0:6dd:4f30:258f with SMTP id 006d021491bc7-716e79ad995mr250479eaf.56.1793904967200; Thu, 05 Nov 2026 10:56: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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.56.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:56:06 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:40 -0700 Subject: [PATCH v10 24/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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-24-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; 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)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FORGED_SENDER_MAILLIST(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; TAGGED_FROM(0.00)[bounces-27283-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)[100.77.114.92:received,209.85.161.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:+]; MID_RHS_MATCH_FROM(0.00)[]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; RCVD_TLS_LAST(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from] X-Rspamd-Queue-Id: E515D1C53B8 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. Code zero means no user data; the other codes select lengths from the controller's table. 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. Share the encoding with a PIO setter. PIO always uses hardware slot zero, and its page callbacks clear all length registers before the chunk loop. It can therefore write the slot-zero code directly, without a read-modify-write. Keep the page-level clearing so unused slots are also cleared after a DMA-to-PIO fallback. Older controllers without length registers remain unaffected, and the chosen lengths and on-flash layout do not change. Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 79 +++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index c9135c8abf54..814331e16bce 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 + \ @@ -1093,35 +1093,60 @@ static void sunxi_nfc_reset_user_data_len(struct sunxi_nfc *nfc) writel(0, nfc->regs + NFC_REG_USER_DATA_LEN(nfc, i)); } -static void sunxi_nfc_set_user_data_len(struct sunxi_nfc *nfc, - int len, int step) +static int sunxi_nfc_user_data_len_code(struct sunxi_nfc *nfc, int len) { - bool found = false; - u32 val; int i; + for (i = 0; i < nfc->caps->nuser_data_tab; i++) { + if (len == nfc->caps->user_data_len_tab[i]) + return i; + } + + dev_warn(nfc->dev, "Unsupported length for user data reg: %d\n", len); + return -EINVAL; +} + +static void sunxi_nfc_set_user_data_len_pio(struct sunxi_nfc *nfc, int len) +{ + 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)); + /* PIO uses slot zero; the page callback clears all other slots. */ + 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), i); - 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, @@ -1517,7 +1542,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, @@ -1546,7 +1571,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) { @@ -1567,10 +1592,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), @@ -1686,7 +1708,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); @@ -1955,7 +1977,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); @@ -1963,7 +1985,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; } From patchwork Thu Nov 5 18:55: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: 3904 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 A82C71C53BA for ; Thu, 5 Nov 2026 20:40:45 +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-27284-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-27284-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 1DCEB2D5B1 for ; Thu, 5 Nov 2026 18:57:03 +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=1793904970; b=17R/dGLTVQcVhOpd0/wYxp2MjXiHaDYCaT1DWJtXE9GH5Gy7PKlXFwY7dt9NDH7q144P /GBYXGgetSX+A4Av+Nw1ir7HpfxoCCPkFyFzx24in5f3y21NFabMQT/O0ItB9lNAeYZ/e aloIIMK4eMVE4mAnn4e3nBUEu69aRzvy+/dzI+tEYZ5EvMhUWc6u5kILSVMSlUdQ4TPdM UPMNNcVd0pqhFIAHsgSlcH2UnZG7+UrE99wac+HruopZwmnf8OnAlF7/oexdDDvi/o2gg KExGhEdq5WyKQXBtFNFyA6wjlkQyhfphsuGRO2nfoaaPEEj9djM+0p6l5h3nlZPYJEg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904970; 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=KWxxvC68veJE9vLqTWwy/EexVQuI9OEnPBoyBsJoQls=; b=0YBdah2Ww97yfi7j3q1ehXrfqJPFM+M7AMw3RR2SC5+HjYJmdbmOs9VkwQlVXH26Zrkj h0Jt8sClgJ4kfwITMW9O7u6r34TlsQOXp3rg0zV2J34JiPYb52delmd2wiT88XqGmRxzY bT3zf8nOj2UYFi7yL+D4pveIEN1g6FJyVlEfevX2Zs3OX1z9YkLBhe2mQSwvGUzCzbRc4 e5aK+JazFR3Bon15e/OPL3g4YAgGilhj9ZEgWQctlUzWvCsd0RVbSd1ZqFdrexM44C8em rmIirTSTOYnu7lN1JkMDYHBv5wHuEdJ6ZoyqyLMMgtuWGlsJZFWhJF3tlWuJJ4Dzaug== 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=rrhoRe3x; 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 EC20D60A262A; Thu, 5 Nov 2026 18:56:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rrhoRe3x X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904969; b=Q0OYfs+Y8gvOPq5RTn0CjB42Wx0M+2uC2tojGp4OHYLNU//bb+f5tCd7KlxK5qi0c3Ze mdFkF8h51OFRJvvnPpvs/RoElqQ2xfFOHXezZ1PmJfUXUlMcMiQisTrtUAL8fczPrrrAM 4k5McjHDPsNE/YCAv7w81Jep2BWpgxjiQJpFtQIZYrEb05cTys+9orbhgHWij5+nCX49w VKi9D3C1lMt536Ie0qaegZcoDTyxsCaJjC7GW/LpvsJHIiDYgz+Kd8BdRORyXZEZBL81Q KY5U9jnm7N2QkwrYfJLoHrw2NaU2Zf8nydKGHuTlIYWJ93nYFq4Iqvc4+rJrs0Jlzaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904969; 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=KWxxvC68veJE9vLqTWwy/EexVQuI9OEnPBoyBsJoQls=; b=zm2dy1IHBu3qFFxe9q1XdSWVD/+NRSViAW0qRoYerDUxVj69oSDP/Ai818a85n4sTFjX StkIv1gckaRUioNM2FkNn2Sjraj3Km3w98wKscjXkIGIoRZyMEkDVTdkgwpZA8ZvZMvee j0+qX+whNY3xHIPukHU9eBC9aZtpUqhgd4UN5ZF7I1I3UdAfTrz4g2YbLRX/V5nJXbW0p 66HySql/PCIlc/7cyvje2nzyQaMVk3/YV9QsPhd6IjUqCzczov4S/eE+7pK503m28/vSv UPnOpLsqKnk33vUARXyptsA6rba87xb5QtXAFr/3wG3LokpMF5lVEbEQ2FtoDs7doBg== 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=rrhoRe3x; arc=none smtp.remote-ip=209.85.161.48 Received: from mail-oo1-f48.google.com (mail-oo1-f48.google.com [209.85.161.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 85B3A60A2623 for ; Thu, 5 Nov 2026 18:56:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 85B3A60A2623 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-oo1-f48.google.com with SMTP id 006d021491bc7-6dde81a6820so1436781eaf.2 for ; Thu, 05 Nov 2026 10:56:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904968; x=1794509768; 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=KWxxvC68veJE9vLqTWwy/EexVQuI9OEnPBoyBsJoQls=; b=rrhoRe3xHyLEH79PBGX5xQiaaMGyNqL4RFnSvz/cVpflO1VAKVJXIgy1QJYyEKKvLr Ehu+teISzIeG1fe3nm1aCk+iRYtMXAZkUuYTujCjp1hVq2pXEf2aEDVIi953q352XioN 7z3StCggsPamR6Npeiqj08eVt+J7iRsuQZ3Po34eg7/gEIyivO+HIQ8MWYPDD41ZHdVm cmzuYPk6WAjD/j+s0zd2nWZsKCsubKHfSh+KgOhldry0NJkaOi9DzcZngN6NM58afHG1 Tvyna5EaIK9vttmTyWxOgkxti0bkz9T7nUNs8fDiu4VGKoKwna7Pam63D5qzH7lJ3dwg QQJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904968; x=1794509768; 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=KWxxvC68veJE9vLqTWwy/EexVQuI9OEnPBoyBsJoQls=; b=Z9D1XRGx5mzg6fRyDqB1/twL4AYs2SarM1nHYMBzOwna39i/sbtlAep2uyB1E8fSf9 UjItHcVZMm59bn7wmryj1WJyfYtXyG66h267lMr+Rzx0KW4NG//GyFIA+JEEUi5ICMm+ r0oU+OPypipDPVybpz4SEWvtNAqxzt2SSTo/vFcWXKFlCugLoEFfsOT8dd3mC7MntnSv F+u7tuct0Ht+yPxWtmxsCKpNML3izkm+jrN8zOEEaYHht/2hvqYo6nuylHVdIgmXKgsZ YSBtAJaaULro0STml+1aCPahJil9RhbGVwFuWSdH1lzsJ8YuBBSwtEQ6Il6TqcP8LlMy WBRw== X-Forwarded-Encrypted: i=1; AKwUvBzXAStifxctqZp6zaWnhbUYYrBnLrwil8/cvIBU1YvMII29iRcnMa0cNmGtIoU1jYTimfgDD+/1mOTXiA==@lists.linux.dev X-Gm-Message-State: APuU4Z9i8jiomPQxd1sJo0BFbDnJneRRxojdzNYYNjkqBOXeggYWYbh2 s47xz8Nh3OYi5GA7rtGnHUXuqJpQNPqGWVeqXbNIt2yIfu/u7EPonJJb X-Gm-Gg: AYBFou3q2kdNihozCo4WQVV8YY8+I0i3nVpDNthPDMoIAdGXe0tyzZkGLvbuP5C+QEd haAC6oGBcxkW4dKyILcnKEqp+Pqj1G7bKMD7J4k03WWsnP4n0cH7Q0IfTiCdxn5urZg2vuGH+xS dKrdTkZE2eE0jOz3KASJomaPMP84nu6dxwiTJfqI3DzhAyPtASY0AfwImlmemtYqXkQDDO37wE/ v2MBrlY9q5UgSieJVzdgtxts9X0+MF2PURMgZ6mYuf9b57TlruGN/QHigKVALUK39bf8l0Zd8n+ 5K3HlQ/dXUdq76QDJMD504KxMEX7sA6l1xHYhyewK/0+ADCeseOkXvjGr2ITpypLcoLLJ2oGifq GPmI/gSG4naidAB/pcTddorBHodIAbX+t9K6MXGvVeXQ8qmm17+1WwFBmOfO9NODt3qi27qmcL3 IFXKLsn0IfuE7EYV134DJIewFRvpf2RuBC3OOJ+/2OP8BGuToQN8cN6pNZEfLsBVapckkbDHuhs hlDgcigO2LBi71/kzo8Ys+dmTWaBz8T0qrFCO/o+fiH2otslKqLZASoRQV/hrxwWiD7YN4/l+wq U7/ZxndqfDlRwlgwJiCwj3uD7FHEjLv3zHAwy5OEygH6k6rWWXYxKy827jMRRkV7BFHjSbuQpVX mHcidmtuONCEoaqiQI2+imM4ZXhpCGEnt4QwRzuiG4pNOQMbvj0bYi/k6B4A1nugOP1DPJXBgZq MCX26EKRa9rXpFF0hGXXnwEIkCClneY0qegArcRjhbdKculf9OvT4C X-Received: by 2002:a05:6820:16a9:b0:6f6:3762:5f9c with SMTP id 006d021491bc7-716e73de6d9mr410801eaf.11.1793904968458; Thu, 05 Nov 2026 10:56: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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.56.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:56:08 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:41 -0700 Subject: [PATCH v10 25/26] dt-bindings: mtd: sunxi: Add randomized OOB flag 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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-25-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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, Conor Dooley X-Mailer: b4 0.15.2 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,microchip.com:email]; FORGED_SENDER_MAILLIST(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; RCPT_COUNT_TWELVE(0.00)[26]; 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,microchip.com]; 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.161.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-27284-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: A82C71C53BA X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX Allwinner NAND firmware writes the bad-block marker as part of the controller's randomizer stream. The mainline driver compensates those two bytes so that the physical marker instead remains plain, even when the rest of the page is scrambled. On H6/H616, the firmware also places a fixed amount of ECC-protected user data before the first parity region, whereas mainline distributes available OOB space among the ECC steps. Add an opt-in property selecting that firmware page format for the configured controller hardware-ECC geometry. It identifies how existing flash contents must be interpreted, rather than changing the format of all NAND attached to a controller compatible. Without it, retain the mainline marker representation and protected-OOB placement. The property applies to normal ECC transfers. Raw operations still bypass ECC and randomization and expose physical main and OOB bytes, including the physical randomized marker. Acked-by: Conor Dooley Signed-off-by: James Hilliard --- .../devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml b/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml index ccf616fabc91..4ed99054a8ab 100644 --- a/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml +++ b/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml @@ -79,6 +79,16 @@ patternProperties: minimum: 0 maximum: 1 + allwinner,randomized-oob: + type: boolean + description: + Select the normal-page format used by Allwinner NAND firmware for + the configured controller hardware-ECC geometry. Normal page + transfers use the controller randomizer, the bad block marker remains + in its data stream instead of being compensated to stay plain on + flash, and protected user data uses the controller-specific placement + expected by the firmware. + unevaluatedProperties: false required: From patchwork Thu Nov 5 18:55: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: 3900 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 749871C53B9 for ; Thu, 5 Nov 2026 20:04:51 +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-27285-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-27285-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 5D439298ED for ; Thu, 5 Nov 2026 18:57:11 +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=1793904971; b=WvIW336BM7q/TE01w6ehuZZkr1uXRrrfle5wxcqS6zC+wi2XGq5g5iRFWKkzUMA8Spvo LVc302C8X5lH9dDhtyxZ0KivvSdgiCvnqI7cBm7ndkfCajRWBS28ZF8aEyHsMWk674xI+ UrXOdfRhUoWs8EXLi2khBBAIXR8GEp/uAfZoAoyx4eCdIRYxETWWiSCyzOyJiLMr+erBl 0Q4Y95zzDkZzcLOFMElJch15wILyOqQILuLVVGaVX6SjXs1Pq9UqskobkISDaA/L2Z0tg fD4NjLh4n7yaNpC4h0D954BSLCGofgMIjOwiSjwbsNi4XcyNpx83UFO34HBUOU2ebaw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904971; 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=SY8/zBBH31Z4xeTKh1G3WAmJ8jx5gZX0gp+n7MKkLrE=; b=TLJHnAJ3oLZJT0Tsst62oyyln1UhJXEXxG3i3MGVogrLua2qHcNKl9Ojwxj6u/syHTXN O82/42WIO+HUoxij8TxMhUhezxIhanF0M/YAUWl+nKXiv0B9yt/5sx+8cixSufov4QNMe 5SKPKZNuO1CLLOYeP3+zOs891+OUWg2/O9b/9/wl61XHB8DUDwnfGxAolFpuLvYB1VGmf PcjpxORY2O8rDcKiZX1kjzE7JvgJUCng/7vOYI8li2002t6GHB5jxGAJhqIFoyd+rmmPm k7qjhodDCtmJjEldlQyrbwKt22UuNZo5B1uM/9sSki8OMbE0KsxxqBdp4gNKGciCxJg== 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=geJFOW+w; 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 7D18E60A263D; Thu, 5 Nov 2026 18:56:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=geJFOW+w X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793904971; b=q5B+uFdEY+F8J+u5anNZHeVWvH4fBMFBPqjIsA3KWgnpCl/pzwj7zGs8EqsJemRPrQvz wjmSVVGlVwRbukBYEafQ0N86VcqrLf6rlLiH7irtf09oDqeiXyzpzEsnrma+6GOrN4+Up t9Vz8DhbOjbp8lhGU7IYuEJDgtuvjM620kfImQ3kyh+L8yHqKi0JCQilM/+YtGtDO9Wk/ RYsQUAUblzENNq3aWIuFjnPPRBpi+I6yc5bJlUA57eD7ha8jBa1198ZXzzPkfCmN48SIv xXfXlbUrBbIbcpfq39q9+lJGam5/mrdBmql/AU5LFhYr9xAcfNYSUNVIV9Et2rUitcw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793904971; 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=SY8/zBBH31Z4xeTKh1G3WAmJ8jx5gZX0gp+n7MKkLrE=; b=h4Y6KMdzP5HI31SWJDa1vEHf/Yfx5ZqojAbC+BX8kRR4c8QK/Jd0xBAm5u11i4Kmjcla 53N4HyybwEx1sUlq9MeVqX2p6g04AXBnx4johF0kaTNKagQH9s9eeGeU4QG3oU8wsWzhg TvB9iqXh9Qa8Nfq2FvrnbE59lc+WbN//31FEAFainDi0VF2HY+l7SgUBmvhM/gvT6Rxh/ PqwhGk8HXDHjRBtF1lVZM9HTa4JxgOKfz+1wlqY/ws57LcMEL7RJt41w/B7kWmBgB1EH3 oaHUXd+eEitxmX3ZbgLCBeiWXeh3/2UnZ4237L2cArl88+1cFG9NK//W/HUm9gXkzyQ== 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=geJFOW+w; arc=none smtp.remote-ip=209.85.161.46 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (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 CF54F60A2636 for ; Thu, 5 Nov 2026 18:56:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CF54F60A2636 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-oo1-f46.google.com with SMTP id 006d021491bc7-6f8a519e215so1084655eaf.1 for ; Thu, 05 Nov 2026 10:56:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793904970; x=1794509770; 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=SY8/zBBH31Z4xeTKh1G3WAmJ8jx5gZX0gp+n7MKkLrE=; b=geJFOW+wyEk9dGoluqUTKa954Rs8LmSd3JtMvA8XBXELAP+aDaXy96mdkhl0EfLP1Z HnlAdRRjv4NmMs9brYPuzmDEdrl4QwKwuVGea1+Xb3NJXgsgvRlp+5iLMkWcqSeCXRSY Bu+btg0gqXCPvvxXGfWyWaXDAY6Qo9SjtYwydYW9E8R+sbYKMevIr57HZkdu2d5yfLNE t7ZgdyE9Gh18PV0qaMAUORp+AUTvrNFlxCSyL2KXVPtDjemeIvFYbM/DhreJH6TuY8Bf PJm/y2b+o7l3Oyd1k45JzOCBfhgZ5KxDpZKxQqTd8KbaLs52fhYZNvANNrH9lnrqCZ44 B1mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793904970; x=1794509770; 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=SY8/zBBH31Z4xeTKh1G3WAmJ8jx5gZX0gp+n7MKkLrE=; b=aZ3esHeP6O9mS+sqHrWV/e0mMKyFI8VR2XyhTC/richku1aOLIRtJF2ln2I81XdFmJ VmWJymvU5UuFqqJ+l/auRUng4iky3A81hl0Ud1Fx6wOg3P08hv3th0RIt59wX5keLmH9 U0h+rf7QHlrEoYyseZQr9q2ZhDnaiu9TRFi8yU0adkCcY6ONrNLCVYq+fVyMsZ6S8iSq 3J9dKGSqrnEvXl+6jE0UTKSLi1zp3goMI/92qiF1A4irv7oY2qN+1u6OCoj2q1yobfLJ rfRahEwEdJ78tb8iO3EkIVjU1jjbMmBOyITH496qp1TAGLFw4FKaEFHSJpNTnXCmtjac EFRg== X-Forwarded-Encrypted: i=1; AKwUvByMYncJv0oCp5SK9HQ98q4DJ4iwdZubcXELxI+OGjqI1eXnZ0jpNxauxKN4zHhJdeThx25OgSOX4LRcJg==@lists.linux.dev X-Gm-Message-State: APuU4Z+IBH+DoGgCbdrvsGqP50bsad/hC+zj0H/q/h9T4ac/bTGG2tPA Eb5rvBuwBE2bM+oj6kdplVlJH2EEKHl7jZdThFfpkvBrHYK0XJ8aXJXF X-Gm-Gg: AYBFou2LlI9SDPY2JUujE4LPwzQIdZt6O844s+lxRyDE+tYp06czNynijNSAKhFYOWm 8aiyCgjRHcoFNqQMAbxcGcvxVX//CtIM2yy+SBgjvFiaSJ/xirNxRjUgxLPepc3xWfGCl3sRxKp G+WDwbCX9JR1M9MN20sv+AZ5Ycoqkaey5c+i/iYWBvKI8gI/EhTHBFLG64KcL7+SsMt+vCq/78v gwQY27fkMIzeia7qbBk8d0frq49y41xPa+vLe+EKhPC/jfRDQ6tOfIJgaYarqa+GezSx14S1seJ 3QEkKud59vereyfxzvNTJ29ENZN97Kcp7G27hGgx29xaNX8ZG+/qT4LtbIxUQcUIMHcBbgOZZiu JQ63b+1z7knuJGfosLuYFttE3phRLb0drll4whg2/4W+OJkA1xHJQIfsqUfyIgEMEiTVpa55uIE 1ZafUhT7szY2dBSpBOBn+XV38QebP7Of1Ti/G0EiHdrFZFnkHddJLkFE9/q3h+rXalHYTdivdFT JJlxk796KCEHo0/EEMCGt3ES9W7jht2LOL1in1p6PAyzLNWiZ3QPtvjLjhMebOxokf+ACNiHrqY VQgdYTdFlb9XBdWX5ENNh/56U2GVuaLEG+6y3PAPUZRRcjg1yT2MHhilaUfYlCHgcEkhbUuUBqS VW+rCbIDiQ18OqcJKETtZGZCBJXvcBP4CJakaVtbf72Fjj+ee39T02aRfuqVY7hZY7mTWXjspVP kNzjrJ3OoUAQu7osfWJ2o8cOqIPzCieYdN5UNfSV/MqkhhSVf4BNXC X-Received: by 2002:a05:6820:c5ce:10b0:716:b936:7cf6 with SMTP id 006d021491bc7-716e73763e0mr260858eaf.4.1793904969681; Thu, 05 Nov 2026 10:56: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 006d021491bc7-716e99465dbsm115897eaf.0.2026.11.05.10.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 10:56:09 -0800 (PST) From: James Hilliard Date: Thu, 05 Nov 2026 11:55:42 -0700 Subject: [PATCH v10 26/26] mtd: rawnand: sunxi: support the Allwinner randomized OOB format 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: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-26-dca1f6ed29a8@gmail.com> References: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@gmail.com> In-Reply-To: <20261105-submit-sunxi-nand-vendor-oob-layout-v1-v10-0-dca1f6ed29a8@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.15.2 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)[]; RCVD_COUNT_FIVE(0.00)[6]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; FORGED_RECIPIENTS_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]; TAGGED_RCPT(0.00)[dt]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27285-noreply=patchwork.local]; FREEMAIL_FROM(0.00)[gmail.com]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10]; TO_DN_SOME(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,209.85.161.46: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:+]; MID_RHS_MATCH_FROM(0.00)[]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; RCVD_TLS_LAST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 749871C53B9 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX Normal hardware-ECC reads also decode protected OOB, including the bad-block marker and metadata used in bad-block-table scans. Allwinner firmware leaves the marker in the randomizer stream, but the existing driver compensates it to keep a plain physical marker. On H6/H616, firmware also packs protected user data before the first parity region rather than maximizing its allocation across the page. Those mismatches prevent normal ECC reads from interpreting firmware-formatted pages and their markers. Honor allwinner,randomized-oob through a separate operations table selected by an opt-in attach helper. Enable scrambling for normal controller-ECC transfers and omit marker compensation. Reject software or disabled ECC, and reject a step larger than the page before the core can fall back to software ECC. Without the property, keep the existing operations and geometry, including the plain marker on otherwise scrambled NAND. For H6/H616, reserve four user-data bytes per ECC step, capped at 16 bytes per page, and put the entire reservation in step zero. Later steps have only parity. For a two-step page, eight user-data bytes precede both steps' parity, instead of four bytes before each step's parity. This is the stored format, not the controller's user-data capacity: increasing the reservation would move parity and prevent decoding existing pages. Apply the same reservation when maximizing ECC strength so strength selection and actual layout agree. Older controllers retain their fixed four-byte user-data field per step. An erased page physically contains 0xff, which the randomizer turns into non-0xff decoded bytes. Select the Allwinner firmware's controller-specific erased-page predicate instead of the generic bit-count check. Apply it to ECC-decoded protected bytes re-encoded with the OOB randomizer stream. This is not a raw reread: bytes corrected by ECC retain their corrected values. Older controllers require eight exact 0xff bytes, with a four-byte shortcut at block page zero and pages 127 modulo 128 for 1 KiB steps. The H6-generation predicate requires byte zero and at least nine of ten bytes to be 0xff. This tolerates one non-0xff byte among bytes one through nine, but never the marker byte. These are byte-based format rules, not a count of erased-page bitflips against the ECC strength. Replacing them with the generic test would change which pages are accepted as erased. ECC exception mode can suppress errors for uniform physical data. Include pattern-found steps in classification even without an ECC-error bit, and ignore their correction counters. Keep decoded bytes until the page-wide decision: an all-zero physical page takes precedence over the spare check and returns zeroed data/OOB with ECC failures; an accepted erased page returns all 0xff. Other failures retain decoded main and protected OOB so bad-block and table scans can still inspect the marker or signature. Read complete pages for subpage requests because these checks classify a whole page. Collect status during each PIO step or DMA batch, and defer statistics until requested OOB reads succeed. Read unprotected OOB only when requested, combining adjacent parity/tail ranges without crossing protected user data. Preserve each step's randomizer phase and the existing PIO/DMA representation of parity. Decode the unprotected tail with the page seed restarted at each NORMAL write-command boundary, using the same chunk-size helper as the writer. Raw reads may combine parity and tail bytes, so their command boundaries do not determine the tail's stored randomizer phase. Raw callbacks remain unchanged. All format policy is in the new callbacks and attach helper. Apart from the opt-in dispatch, existing functions are unchanged: geometry allocation, marker compensation, status collection and PIO/DMA transfer sequencing continue to serve the existing operations tables as before. Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 338 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 338 insertions(+) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index 814331e16bce..a91edea879d2 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -363,6 +363,8 @@ struct sunxi_nfc_mdma_desc { * @nuser_data_tab: Size of @user_data_len_tab * @sram_size: Size of the NAND controller SRAM * @timings: Controller timing characteristics + * @spare_is_erased: Allwinner randomized-OOB erased-page check on + * re-encoded protected OOB bytes */ struct sunxi_nfc_caps { bool has_mdma; @@ -392,6 +394,7 @@ struct sunxi_nfc_caps { unsigned int max_ecc_steps; int sram_size; const struct sunxi_nfc_timings *timings; + bool (*spare_is_erased)(struct nand_chip *nand, const u8 *spare, int page); }; /** @@ -1228,8 +1231,16 @@ static int sunxi_nfc_hw_ecc_read_error(struct nand_chip *nand, return ret >= 0; } +struct sunxi_nfc_allwinner_oob_status { + u32 error_steps; + u32 zero_steps; + unsigned int corrected; + unsigned int max_bitflips; +}; + /* Shared across a read's transfers; buf remains the full-page buffer base. */ struct sunxi_nfc_ecc_read { + struct sunxi_nfc_allwinner_oob_status allwinner_oob; u8 *buf; int page; unsigned int max_bitflips; @@ -2449,6 +2460,305 @@ static const struct sunxi_nfc_oob_ops sunxi_nfc_scrambled_plain_bbm_oob_ops = { .finish_read = sunxi_nfc_oob_finish_read, }; +/* Allwinner randomized-OOB format, selected only by allwinner,randomized-oob. */ +/* Firmware metadata limit, not the controller's user-data register capacity. */ +#define SUNXI_NFC_H6_ALLWINNER_OOB_MAX_USER_DATA_SZ 16 + +static void sunxi_nfc_randomize_buf(u16 state, u8 *buf, unsigned int len) +{ + while (len--) { + *buf++ ^= state; + state = sunxi_nfc_randomizer_step(state, 8); + } +} + +static void +sunxi_nfc_allwinner_oob_record_status(struct nand_chip *nand, + struct sunxi_nfc_allwinner_oob_status *result, + int logical_step, int hw_step, + struct sunxi_nfc_ecc_snapshot *snapshot) +{ + u32 count; + + if ((snapshot->pattern_found & BIT(hw_step)) && + !(snapshot->pattern_id & BIT(hw_step))) + result->zero_steps |= BIT(logical_step); + + /* + * Exception mode can suppress the ECC error for a physical pattern. + * Classify these steps with the Allwinner randomized-OOB page check too, + * and do not use their correction counters. Keep their decoded data until + * then. + */ + if ((snapshot->status & NFC_ECC_ERR(hw_step)) || + (snapshot->pattern_found & BIT(hw_step))) { + result->error_steps |= BIT(logical_step); + return; + } + + count = sunxi_nfc_hw_ecc_read_count(nand, snapshot, hw_step); + result->corrected += count; + result->max_bitflips = max(result->max_bitflips, count); +} + +static bool sun4i_a10_nfc_spare_is_erased(struct nand_chip *nand, + const u8 *spare, int page) +{ + struct mtd_info *mtd = nand_to_mtd(nand); + unsigned int block_page = page % mtd_div_by_ws(mtd->erasesize, mtd); + + /* + * Older Allwinner firmware recognizes exact four-byte erased + * signatures on page zero and pages 127 modulo 128. With their + * 1 KiB ECC steps these correspond to four physical 0xff bytes. + * Other pages require all eight spare bytes to be 0xff. + */ + if (nand->ecc.size == 1024 && + (!block_page || block_page % 128 == 127) && + !memchr_inv(spare, 0xff, USER_DATA_SZ)) + return true; + + return !memchr_inv(spare, 0xff, 8); +} + +static bool sun50i_h6_nfc_spare_is_erased(struct nand_chip *nand, + const u8 *spare, int page) +{ + unsigned int erased = 0; + int i; + + /* Keep the marker byte erased; tolerate one other non-0xff byte. */ + for (i = 0; i < 10; i++) + erased += spare[i] == 0xff; + + return spare[0] == 0xff && erased >= 9; +} + +static bool sunxi_nfc_allwinner_oob_spare_is_erased(struct nand_chip *nand, + int page) +{ + 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; + u16 state = sunxi_nfc_randomizer_state(nand, page, true); + u8 spare[10]; + unsigned int len, pos = 0; + int i, off; + + /* + * Re-encode ECC-decoded protected OOB for the firmware's spare check. + * This is not a raw reread: ECC-corrected bytes stay corrected. Each + * step restarts the OOB randomizer; H6/H616 pack the entire prefix in + * step zero. Pad unavailable bytes with 0xff. + */ + memset(spare, 0xff, sizeof(spare)); + for (i = 0; i < ecc->steps && pos < sizeof(spare); i++) { + len = min_t(unsigned int, sunxi_nfc_user_data_sz(sunxi_nand, i), + sizeof(spare) - pos); + off = sunxi_get_oob_offset(sunxi_nand, ecc, i); + memcpy(spare + pos, nand->oob_poi + off, len); + sunxi_nfc_randomize_buf(state, spare + pos, len); + pos += len; + } + + return nfc->caps->spare_is_erased(nand, spare, page); +} + +static int sunxi_nfc_allwinner_oob_read_unprotected(struct nand_chip *nand, + bool dma, int page) +{ + 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 len, off; + u16 state; + int ret, i; + + for (i = 0; i < ecc->steps; i++) { + off = sunxi_get_ecc_offset(sunxi_nand, ecc, i); + len = ecc->bytes; + /* Keep decoded user data, but combine adjacent parity regions. */ + while (i + 1 < ecc->steps && + !sunxi_nfc_user_data_sz(sunxi_nand, i + 1)) { + len += ecc->bytes; + i++; + } + if (i + 1 == ecc->steps) + len = mtd->oobsize - off; + + ret = sunxi_nfc_read_column(nand, page, mtd->writesize + off, + nand->oob_poi + off, len); + if (ret) + return ret; + } + + /* Preserve each path's normal representation of ECC bytes. */ + if (!dma) { + for (i = 0; i < ecc->steps; i++) { + len = sunxi_nfc_user_data_sz(sunxi_nand, i); + off = sunxi_get_ecc_offset(sunxi_nand, ecc, i); + state = sunxi_nfc_randomizer_state(nand, page, true); + state = sunxi_nfc_randomizer_step(state, len * 8 + 15); + sunxi_nfc_randomize_buf(state, nand->oob_poi + off, + ecc->bytes); + } + } + + off = sunxi_get_oob_offset(sunxi_nand, ecc, ecc->steps); + len = mtd->oobsize - off; + if (len) { + /* Each NORMAL write command restarts the tail's randomizer. */ + state = sunxi_nfc_randomizer_state(nand, page, false); + state = sunxi_nfc_randomizer_step(state, 15); + while (len) { + unsigned int cnt = sunxi_nfc_buf_chunk_size(nfc, len); + + sunxi_nfc_randomize_buf(state, nand->oob_poi + off, cnt); + off += cnt; + len -= cnt; + } + } + + return 0; +} + +static int sunxi_nfc_allwinner_oob_read_batch(struct nand_chip *nand, + struct sunxi_nfc_ecc_read *read, + struct sunxi_nfc_ecc_snapshot *snapshot, + int first_step, int nsteps) +{ + 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; + unsigned int reg_index = 0, user_data_sz; + int i; + + /* Page classification also needs pattern IDs for steps with ECC errors. */ + if (snapshot->pattern_found) + sunxi_nfc_hw_ecc_read_pattern_id(nand, snapshot); + + 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 *oob = nand->oob_poi + oob_off; + + user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, step); + sunxi_nfc_allwinner_oob_record_status(nand, &read->allwinner_oob, + step, i, snapshot); + if (!read->dma) + memcpy_fromio(read->buf + step * ecc->size, + nfc->regs + NFC_RAM0_BASE, ecc->size); + /* Page classification needs protected OOB even for data-only reads. */ + sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, reg_index, !step, + read->page, user_data_sz); + } + + return 0; +} + +static int sunxi_nfc_allwinner_oob_finish_read(struct nand_chip *nand, + struct sunxi_nfc_ecc_read *read, + int *cur_off) +{ + struct sunxi_nfc_allwinner_oob_status *result = &read->allwinner_oob; + u8 *buf = read->buf; + bool oob_required = read->oob_required; + bool dma = read->dma; + int page = read->page; + struct mtd_info *mtd = nand_to_mtd(nand); + struct nand_ecc_ctrl *ecc = &nand->ecc; + int ret; + + /* + * Allwinner firmware treats an all-zero physical page as bad, even without + * ECC errors. This takes precedence over the spare-byte heuristic. + */ + if (result->zero_steps == GENMASK(ecc->steps - 1, 0)) { + memset(buf, 0, mtd->writesize); + memset(nand->oob_poi, 0, mtd->oobsize); + mtd->ecc_stats.failed += ecc->steps; + return 0; + } + + if (result->error_steps && sunxi_nfc_allwinner_oob_spare_is_erased(nand, page)) { + memset(buf, 0xff, mtd->writesize); + memset(nand->oob_poi, 0xff, mtd->oobsize); + return 0; + } + + /* + * Keep the original decoded main and protected OOB bytes on ECC failure. + * BBT pattern scans inspect them even when an ECC error is reported. + * Read the remaining OOB only when requested, not to classify the page. + */ + if (oob_required) { + ret = sunxi_nfc_allwinner_oob_read_unprotected(nand, dma, page); + if (ret) + return ret; + } + + mtd->ecc_stats.corrected += result->corrected; + mtd->ecc_stats.failed += hweight32(result->error_steps); + + return result->max_bitflips; +} + +static int sunxi_nfc_allwinner_oob_read_subpage(struct nand_chip *nand, + u32 data_offs, u32 readlen, + u8 *buf, int page) +{ + return nand->ecc.read_page(nand, buf, false, page); +} + +static unsigned int sunxi_nfc_h6_allwinner_oob_user_data_sz(int nsectors) +{ + return min(nsectors * USER_DATA_SZ, + SUNXI_NFC_H6_ALLWINNER_OOB_MAX_USER_DATA_SZ); +} + +static unsigned int sunxi_nfc_allwinner_oob_min_user_data(struct nand_chip *nand, + int nsteps) +{ + struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); + + if (!nfc->caps->reg_user_data_len) + return sunxi_nfc_oob_min_user_data(nand, nsteps); + + return sunxi_nfc_h6_allwinner_oob_user_data_sz(nsteps); +} + +static int sunxi_nfc_allwinner_oob_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); + + /* Do not let the core fall back to software ECC for this format. */ + if (nsteps <= 0) + return -EINVAL; + + if (!nfc->caps->reg_user_data_len) + return 0; + + sunxi_nand->user_data_bytes = devm_kzalloc(nfc->dev, nsteps, GFP_KERNEL); + if (!sunxi_nand->user_data_bytes) + return -ENOMEM; + + /* + * H6/H616 pack all protected user data before step-zero parity. + * This prefix fixes the parity offsets on firmware-written pages. + */ + sunxi_nand->user_data_bytes[0] = sunxi_nfc_h6_allwinner_oob_user_data_sz(nsteps); + return 0; +} + +static const struct sunxi_nfc_oob_ops sunxi_nfc_allwinner_oob_ops = { + .min_user_data = sunxi_nfc_allwinner_oob_min_user_data, + .init_user_data = sunxi_nfc_allwinner_oob_init_user_data, + .read_batch = sunxi_nfc_allwinner_oob_read_batch, + .finish_read = sunxi_nfc_allwinner_oob_finish_read, +}; + static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, struct nand_ecc_ctrl *ecc, struct device_node *np) @@ -2585,6 +2895,28 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, return 0; } +static int sunxi_nfc_allwinner_oob_attach_chip(struct nand_chip *nand, + struct device_node *np) +{ + struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); + struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); + int ret; + + if (nand->ecc.engine_type != NAND_ECC_ENGINE_TYPE_ON_HOST) + return dev_err_probe(nfc->dev, -EINVAL, + "Allwinner OOB format requires controller ECC\n"); + + sunxi_nand->oob_ops = &sunxi_nfc_allwinner_oob_ops; + nand->options |= NAND_NEED_SCRAMBLING | NAND_NO_SUBPAGE_WRITE; + ret = sunxi_nand_hw_ecc_ctrl_init(nand, &nand->ecc, np); + if (ret) + return ret; + + /* This format's spare and all-zero checks classify the whole page. */ + nand->ecc.read_subpage = sunxi_nfc_allwinner_oob_read_subpage; + return 0; +} + static int sunxi_nand_attach_chip(struct nand_chip *nand) { struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); @@ -2610,6 +2942,9 @@ static int sunxi_nand_attach_chip(struct nand_chip *nand) if (!ecc->size || !ecc->strength) return -EINVAL; + if (of_property_read_bool(np, "allwinner,randomized-oob")) + return sunxi_nfc_allwinner_oob_attach_chip(nand, np); + sunxi_nand->oob_ops = nand->options & NAND_NEED_SCRAMBLING ? &sunxi_nfc_scrambled_plain_bbm_oob_ops : &sunxi_nfc_plain_oob_ops; @@ -3126,6 +3461,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_caps = { .max_ecc_steps = 16, .sram_size = 1024, .timings = &sun4i_a10_nfc_timings, + .spare_is_erased = sun4i_a10_nfc_spare_is_erased, }; static const struct sunxi_nfc_caps sunxi_nfc_a23_caps = { @@ -3149,6 +3485,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a23_caps = { .max_ecc_steps = 16, .sram_size = 1024, .timings = &sun4i_a10_nfc_timings, + .spare_is_erased = sun4i_a10_nfc_spare_is_erased, }; static const struct sunxi_nfc_caps sunxi_nfc_h616_caps = { @@ -3176,6 +3513,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_h616_caps = { .max_ecc_steps = 32, .sram_size = 8192, .timings = &sun50i_h616_nfc_timings, + .spare_is_erased = sun50i_h6_nfc_spare_is_erased, }; static const struct of_device_id sunxi_nfc_ids[] = {