From patchwork Mon Jul 17 19:42:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 1809634 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=2YvBjVYV; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=SiN/ld3K; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=UZlw3ThI; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R5QBj2L9gz20Cs for ; Wed, 19 Jul 2023 15:59:41 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HBIecpYyG1keNHOzmOEWLWylMiCmKijfZoOZA+P5LWo=; b=2YvBjVYVYIubcW OJ7y+au6mr/gotZzvN2boB1I40KuYQQTwQdmbVEU+vEqEZl/sMFEsfRxrrJNXQWvF04C5ONScg3ML fFEM4cUp/jWCs0q3nN5Cb6cMHngWDYsMIOKqKSkiR72THD4It+HrcplsrNZqQejCk/TRsTnbsE03V gEBVZWwSddTKxzMtYNPJTMOStrojz1Vs9iV4/HaKSv+kHoSEzAx+XSsGZxBJEtgsPZDoDZv7O2Mx4 o2lCpN9vdjvd094hfC8o5lAeN0XnCPvMMHzp0zNHn/c15S6wA2nXcoMuQMFUhBZcSz3wmL2exviy4 QfL4C7SOAidNdqPEqNiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM0DR-005Uf3-1d; Wed, 19 Jul 2023 05:59:13 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM0DJ-005Ua9-20 for linux-mtd@bombadil.infradead.org; Wed, 19 Jul 2023 05:59:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=XBN2hYgkZC+vX2/vBakjoME0dxps0dBkBhnZWQPKiLs=; b=SiN/ld3K/A6l5Gm+9hcqFbrMvH 0lYYQep8PynR94Vjdw4Ou4CTv62udrm+ay9CKZC4yPB2nB2XungDlxK0BV54MMvKlZE8Ihvn8+O5R 5I3tTzpCmY8thKG5RPNUleCvULyaKo/6lbNEJXw/4ItaYlfi/bcQ8Jbk4OvJXRhKJ8dr5JL6XNKfV Z1K6jQgOdriEQPlHWPkNMzz27rhrH8kInlkl5GIF7v0Csm1SYQxVCLIoj7KfZzwnYUEJpQKI7sKeS eGdcZWblAbu6lCgIOsClmDTbmT6HE9DtduZ1mcFY5ziPEpqNYUDnDFO4i8t1B4b7rMd4G13ZjYx+u w7rI6ARg==; Received: from relay8-d.mail.gandi.net ([2001:4b98:dc4:8::228]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLU7i-009FWt-1t for linux-mtd@lists.infradead.org; Mon, 17 Jul 2023 19:43:14 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id D659E1BF206; Mon, 17 Jul 2023 19:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1689622948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XBN2hYgkZC+vX2/vBakjoME0dxps0dBkBhnZWQPKiLs=; b=UZlw3ThIPhfB0CmBrpMhZwVxCED6vFYJJwuDlhoSqA8tLKVL7D/rPCapNN98zleSbsa6As vlZJsgm6+QsyQpAymX5t2KImlJfSFd5UTSBMJpUjhljQ4hTfD/pppYPrA8N9R9kpiuUTHe F4hF873Jzzg2TqZcFlVQYleaC8T5BMs/kSPvjPrI/aq0llu3nnDuh2X1yZcyBPHPR1RSJT UzSblPMTFC3WVIp+oRwDDbm13rIi8PtqJRch9XRN8op340K/tdDTdxBli3fYH2fgHlW9i6 1vlF+vT9kQ377Gj/l3cDr9J9PWRiWFO7nMdM7ZGqENgZrhd5rpIccGZGTYb8nw== From: Miquel Raynal To: Richard Weinberger , Vignesh Raghavendra , Tudor Ambarus , Pratyush Yadav , Michael Walle , Cc: Thomas Petazzoni , Miquel Raynal , Michal Simek , stable@vger.kernel.org Subject: [PATCH 3/3] mtd: rawnand: pl353: Ensure program page operations are successful Date: Mon, 17 Jul 2023 21:42:21 +0200 Message-Id: <20230717194221.229778-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717194221.229778-1-miquel.raynal@bootlin.com> References: <20230717194221.229778-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230717_204312_717336_3A2D9AAF X-CRM114-Status: GOOD ( 14.31 ) X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The NAND core complies with the ONFI specification, which itself mentions that after any program or erase operation, a status check should be performed to see whether the operation was finished *and* [...] Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [2001:4b98:dc4:8:0:0:0:228 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The NAND core complies with the ONFI specification, which itself mentions that after any program or erase operation, a status check should be performed to see whether the operation was finished *and* successful. The NAND core offers helpers to finish a page write (sending the "PAGE PROG" command, waiting for the NAND chip to be ready again, and checking the operation status). But in some cases, advanced controller drivers might want to optimize this and craft their own page write helper to leverage additional hardware capabilities, thus not always using the core facilities. Some drivers, like this one, do not use the core helper to finish a page write because the final cycles are automatically managed by the hardware. In this case, the additional care must be taken to manually perform the final status check. Let's read the NAND chip status at the end of the page write helper and return -EIO upon error. Cc: Michal Simek Cc: stable@vger.kernel.org Fixes: 08d8c62164a3 ("mtd: rawnand: pl353: Add support for the ARM PL353 SMC NAND controller") Signed-off-by: Miquel Raynal --- Hello Michal, Same as for the Arasan controller, this is not tested, but I believe it is required. Let me know how testing goes. Thanks, Miquèl --- drivers/mtd/nand/raw/pl35x-nand-controller.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/mtd/nand/raw/pl35x-nand-controller.c b/drivers/mtd/nand/raw/pl35x-nand-controller.c index 28b7bd7e22eb..9dd06eeb021e 100644 --- a/drivers/mtd/nand/raw/pl35x-nand-controller.c +++ b/drivers/mtd/nand/raw/pl35x-nand-controller.c @@ -513,6 +513,7 @@ static int pl35x_nand_write_page_hwecc(struct nand_chip *chip, u32 addr1 = 0, addr2 = 0, row; u32 cmd_addr; int i, ret; + u8 status; ret = pl35x_smc_set_ecc_mode(nfc, chip, PL35X_SMC_ECC_CFG_MODE_APB); if (ret) @@ -565,6 +566,14 @@ static int pl35x_nand_write_page_hwecc(struct nand_chip *chip, if (ret) goto disable_ecc_engine; + /* Check write status on the chip side */ + ret = nand_status_op(chip, &status); + if (ret) + goto disable_ecc_engine; + + if (status & NAND_STATUS_FAIL) + ret = -EIO; + disable_ecc_engine: pl35x_smc_set_ecc_mode(nfc, chip, PL35X_SMC_ECC_CFG_MODE_BYPASS);