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,