linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Tokunori Ikegami <ikegami_to@yahoo.co.jp>
To: Boris Brezillon <boris.brezillon@bootlin.com>
Cc: Boris Brezillon <boris.brezillon@free-electrons.com>,
	stable@vger.kernel.org,
	Joakim Tjernlund <Joakim.Tjernlund@infinera.com>,
	Tokunori Ikegami <ikegami_to@yahoo.co.jp>,
	linux-mtd@lists.infradead.org,
	Chris Packham <chris.packham@alliedtelesis.co.nz>,
	Felix Fietkau <nbd@nbd.name>
Subject: [RESEND v4 01/11] mtd: cfi_cmdset_0002: Use chip_good() to retry in do_write_oneword()
Date: Tue,  5 Feb 2019 03:14:55 +0900	[thread overview]
Message-ID: <20190204181505.29841-2-ikegami_to@yahoo.co.jp> (raw)
In-Reply-To: <20190204181505.29841-1-ikegami_to@yahoo.co.jp>

As reported by the OpenWRT team, write requests sometimes fail on some
platforms.
Currently to check the state chip_ready() is used correctly as described by
the flash memory S29GL256P11TFI01 datasheet.
Also chip_good() is used to check if the write is succeeded and it was
implemented by the commit fb4a90bfcd6d8 ("[MTD] CFI-0002 - Improve error
checking").
But actually the write failure is caused on some platforms and also it can
be fixed by using chip_good() to check the state and retry instead.
Also it seems that it is caused after repeated about 1,000 times to retry
the write one word with the reset command.
By using chip_good() to check the state to be done it can be reduced the
retry with reset.
It is depended on the actual flash chip behavior so the root cause is
unknown.

Signed-off-by: Tokunori Ikegami <ikegami_to@yahoo.co.jp>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Co-Developed-by: Hauke Mehrtens <hauke@hauke-m.de>
Co-Developed-by: Koen Vandeputte <koen.vandeputte@ncentric.com>
Reported-by: Fabio Bettoni <fbettoni@gmail.com>
Cc: Chris Packham <chris.packham@alliedtelesis.co.nz>
Cc: Joakim Tjernlund <Joakim.Tjernlund@infinera.com>
Cc: Boris Brezillon <boris.brezillon@free-electrons.com>
Cc: linux-mtd@lists.infradead.org
Cc: stable@vger.kernel.org
---
Changes since v3:
- Update the commit message for the comments.
- Drop the addition of blanks lines around xip_enable().
- Delete unnecessary setting the ret variable to -EIO.
- Change the email address of Tokunori Ikegami to ikegami_to@yahoo.co.jp.

Changes since v2:
- Just update the commit message for the comment.

Changes since v1:
- Just update the commit message.

Background:
This is required for OpenWrt Project to result the flash write issue as
below patche.
<https://git.openwrt.org/?p=openwrt/openwrt.git;a=commitdiff;h=ddc11c3932c7b7b7df7d5fbd48f207e77619eaa7>

Also the original patch in OpenWRT is below.
<https://github.com/openwrt/openwrt/blob/v18.06.0/target/linux/ar71xx/patches-4.9/403-mtd_fix_cfi_cmdset_0002_status_check.patch>

The reason to use chip_good() is that just actually fix the issue.
And also in the past I had fixed the erase function also as same way by the
patch below.
  <https://patchwork.ozlabs.org/patch/922656/>
    Note: The reason for the patch for erase is same.

In my understanding the chip_ready() is just checked the value twice from
flash.
So I think that sometimes incorrect value is read twice and it is depended
on the flash device behavior but not sure..

So change to use chip_good() instead of chip_ready().

 drivers/mtd/chips/cfi_cmdset_0002.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
 mode change 100644 => 100755 drivers/mtd/chips/cfi_cmdset_0002.c

diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
old mode 100644
new mode 100755
index 72428b6..91a491b
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -1627,29 +1627,31 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
 			continue;
 		}
 
-		if (time_after(jiffies, timeo) && !chip_ready(map, adr)){
+		if (chip_good(map, adr, datum))
+			break;
+
+		if (time_after(jiffies, timeo)){
 			xip_enable(map, chip, adr);
 			printk(KERN_WARNING "MTD %s(): software timeout\n", __func__);
 			xip_disable(map, chip, adr);
+			ret = -EIO;
 			break;
 		}
 
-		if (chip_ready(map, adr))
-			break;
-
 		/* Latency issues. Drop the lock, wait a while and retry */
 		UDELAY(map, chip, adr, 1);
 	}
+
 	/* Did we succeed? */
-	if (!chip_good(map, adr, datum)) {
+	if (ret) {
 		/* reset on all failures. */
 		map_write(map, CMD(0xF0), chip->start);
 		/* FIXME - should have reset delay before continuing */
 
-		if (++retry_cnt <= MAX_RETRIES)
+		if (++retry_cnt <= MAX_RETRIES) {
+			ret = 0;
 			goto retry;
-
-		ret = -EIO;
+		}
 	}
 	xip_enable(map, chip, adr);
  op_done:
-- 
2.11.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2019-02-04 18:15 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-04 18:14 [RESEND v4 00/11] mtd: cfi_cmdset_0002: Fix flash write issue for OpenWrt Project Tokunori Ikegami
2019-02-04 18:14 ` Tokunori Ikegami [this message]
2019-02-04 18:14 ` [RESEND v4 02/11] mtd: cfi_cmdset_0002: Remove chip_ready() from do_write_buffer() Tokunori Ikegami
2019-02-04 18:14 ` [RESEND v4 03/11] mtd: cfi_cmdset_0002: Remove goto statement " Tokunori Ikegami
2019-02-04 18:14 ` [RESEND v4 04/11] mtd: cfi_cmdset_0002: Call xip_enable() once only in do_write_buffer() Tokunori Ikegami
2019-02-04 18:14 ` [RESEND v4 05/11] mtd: cfi_cmdset_0002: Split do_write_oneword() to reduce function size Tokunori Ikegami
2019-02-04 18:15 ` [RESEND v4 06/11] mtd: cfi_cmdset_0002: Split do_write_oneword() op_done goto statement Tokunori Ikegami
2019-02-04 18:15 ` [RESEND v4 07/11] mtd: cfi_cmdset_0002: Remove op_done goto statement from do_write_oneword() Tokunori Ikegami
2019-02-04 18:15 ` [RESEND v4 08/11] mtd: cfi_cmdset_0002: Remove retry " Tokunori Ikegami
2019-02-04 18:15 ` [RESEND v4 09/11] mtd: cfi_cmdset_0002: Split write-to-buffer-reset sequence Tokunori Ikegami
2019-02-04 18:15 ` [RESEND v4 10/11] mtd: cfi_cmdset_0002: Split to wait write buffer to check if completed Tokunori Ikegami
2019-02-04 18:15 ` [RESEND v4 11/11] mtd: cfi_cmdset_0002: Split do_write_oneword() to reduce exit paths Tokunori Ikegami
2019-02-04 18:19 [RESEND v4 00/11] mtd: cfi_cmdset_0002: Fix flash write issue for OpenWrt Project Tokunori Ikegami
2019-02-04 18:19 ` [RESEND v4 01/11] mtd: cfi_cmdset_0002: Use chip_good() to retry in do_write_oneword() Tokunori Ikegami
2019-02-04 18:24   ` Tokunori Ikegami
2019-02-05 11:57     ` Vignesh R
2019-02-05 12:33       ` Tokunori Ikegami

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190204181505.29841-2-ikegami_to@yahoo.co.jp \
    --to=ikegami_to@yahoo.co.jp \
    --cc=Joakim.Tjernlund@infinera.com \
    --cc=boris.brezillon@bootlin.com \
    --cc=boris.brezillon@free-electrons.com \
    --cc=chris.packham@alliedtelesis.co.nz \
    --cc=linux-mtd@lists.infradead.org \
    --cc=nbd@nbd.name \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).