linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Tokunori Ikegami <ikegami.t@gmail.com>
To: Vignesh Raghavendra <vigneshr@ti.com>
Cc: Tokunori Ikegami <ikegami.t@gmail.com>,
	Hauke Mehrtens <hauke@hauke-m.de>,
	stable@vger.kernel.org,
	Joakim Tjernlund <Joakim.Tjernlund@infinera.com>,
	Chris Packham <chris.packham@alliedtelesis.co.nz>,
	linux-mtd@lists.infradead.org, Felix Fietkau <nbd@nbd.name>
Subject: [PATCH v8 1/9] mtd: cfi_cmdset_0002: Use chip_good() to retry in do_write_oneword()
Date: Tue,  6 Aug 2019 04:03:18 +0900	[thread overview]
Message-ID: <20190805190326.28772-2-ikegami.t@gmail.com> (raw)
In-Reply-To: <20190805190326.28772-1-ikegami.t@gmail.com>

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.t@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Reported-by: Fabio Bettoni <fbettoni@gmail.com>
Cc: Chris Packham <chris.packham@alliedtelesis.co.nz>
Cc: Joakim Tjernlund <Joakim.Tjernlund@infinera.com>
Cc: linux-mtd@lists.infradead.org
Cc: stable@vger.kernel.org
---
Changes since v7:
Rebased on top of polling status register support in master.

Changes since v6:
- Change the tag of Hauke Mehrtens to Signed-off-by as confirmed with him.
- Removed the tag of Koen Vandeputte as confirmed with him.
- Address the ./scripts/checkpatch.pl issues.
- Fix to remain the file type as 100644.

Changes since v5:
- Rebased on top of Liu Jian's fixes in master.
- Change to follow Liu Jian's fixes in master for the write buffer.
- Change the email address of Tokunori Ikegami to ikegami.t@gmail.com.

Changes since v4:
- None.

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 | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index f4da7bd552e9..19787a14350b 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -1717,31 +1717,36 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
 			continue;
 		}
 
-		if (time_after(jiffies, timeo) &&
-		    !chip_ready(map, chip, adr)) {
+		/*
+		 * We check "time_after" and "!chip_good" before checking
+		 * "chip_good" to avoid the failure due to scheduling.
+		 */
+		if (time_after(jiffies, timeo) && !chip_good(map, chip, adr, datum)) {
 			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, chip, adr))
+		if (chip_good(map, chip, adr, datum))
 			break;
 
 		/* Latency issues. Drop the lock, wait a while and retry */
 		UDELAY(map, chip, adr, 1);
 	}
+
 	/* Did we succeed? */
-	if (!chip_good(map, chip, adr, datum)) {
+	if (ret) {
 		/* reset on all failures. */
 		cfi_check_err_status(map, chip, adr);
 		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-08-05 19:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-05 19:03 [PATCH v8 0/9] mtd: cfi_cmdset_0002: Fix flash write issue for OpenWrt Project Tokunori Ikegami
2019-08-05 19:03 ` Tokunori Ikegami [this message]
2019-08-06  0:43   ` [PATCH v8 1/9] mtd: cfi_cmdset_0002: Use chip_good() to retry in do_write_oneword() Sasha Levin
2019-08-06 14:30     ` Tokunori Ikegami
2019-09-17 18:04       ` Tokunori Ikegami
2019-09-18  5:29         ` Vignesh Raghavendra
2019-09-18 13:40           ` Tokunori Ikegami
2019-08-05 19:03 ` [PATCH v8 2/9] mtd: cfi_cmdset_0002: Remove goto statement from do_write_buffer() Tokunori Ikegami
2019-08-05 19:03 ` [PATCH v8 3/9] mtd: cfi_cmdset_0002: Split do_write_oneword() to reduce function size Tokunori Ikegami
2019-08-05 19:03 ` [PATCH v8 4/9] mtd: cfi_cmdset_0002: Split do_write_oneword() op_done goto statement Tokunori Ikegami
2019-08-05 19:03 ` [PATCH v8 5/9] mtd: cfi_cmdset_0002: Remove op_done goto statement from do_write_oneword() Tokunori Ikegami
2019-08-05 19:03 ` [PATCH v8 6/9] mtd: cfi_cmdset_0002: Split write-to-buffer-reset sequence Tokunori Ikegami
2019-08-05 19:03 ` [PATCH v8 7/9] mtd: cfi_cmdset_0002: Split to wait write buffer to check if completed Tokunori Ikegami
2019-08-05 19:03 ` [PATCH v8 8/9] mtd: cfi_cmdset_0002: Split do_write_oneword() to reduce exit paths Tokunori Ikegami
2019-08-05 19:03 ` [PATCH v8 9/9] mtd: cfi_cmdset_0002: Disable write buffer functions if FORCE_WORD_WRITE is 1 Tokunori Ikegami
2019-09-17  4:20 ` [PATCH v8 0/9] mtd: cfi_cmdset_0002: Fix flash write issue for OpenWrt Project Vignesh Raghavendra

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=20190805190326.28772-2-ikegami.t@gmail.com \
    --to=ikegami.t@gmail.com \
    --cc=Joakim.Tjernlund@infinera.com \
    --cc=chris.packham@alliedtelesis.co.nz \
    --cc=hauke@hauke-m.de \
    --cc=linux-mtd@lists.infradead.org \
    --cc=nbd@nbd.name \
    --cc=stable@vger.kernel.org \
    --cc=vigneshr@ti.com \
    /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).