public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] [MTD] Adjust the NOR CFI flash timeouts to round better
@ 2012-10-05 18:32 Jason Gunthorpe
  2012-10-15 13:42 ` Artem Bityutskiy
  0 siblings, 1 reply; 10+ messages in thread
From: Jason Gunthorpe @ 2012-10-05 18:32 UTC (permalink / raw)
  To: linux-mtd, David Woodhouse

Using jiffies for timeout could have significant rounding, ie if we
start at jiffie 1.9 and timeout at 2 then we may only get .1 jiffies
of timeout, which is not nearly enough. With a Hz of 250 I've seen
random bogus timeouts from this code.

Add a +1 to the HZ calculations to ensure a guaranteed minimum
timeout period.

This also increases the write_buffer timeout to 1.5us since I have
flashes in use that have a datasheet max of over 1 us.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
---
 drivers/mtd/chips/cfi_cmdset_0002.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index 22d0493..46a1dde 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -1150,10 +1150,10 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
 	 * use the maximum timeout value given by the chip at probe time
 	 * instead.  Unfortunately, struct flchip does have a field for
 	 * maximum timeout, only for typical which can be far too short
-	 * depending of the conditions.	 The ' + 1' is to avoid having a
-	 * timeout of 0 jiffies if HZ is smaller than 1000.
+	 * depending of the conditions.	 The ' + 2' is to ensure we get
+	 * *at least* 1000us of timeout.
 	 */
-	unsigned long uWriteTimeout = ( HZ / 1000 ) + 1;
+	unsigned long uWriteTimeout = (HZ / 1000) + 2;
 	int ret = 0;
 	map_word oldd;
 	int retry_cnt = 0;
@@ -1382,8 +1382,11 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
 {
 	struct cfi_private *cfi = map->fldrv_priv;
 	unsigned long timeo = jiffies + HZ;
-	/* see comments in do_write_oneword() regarding uWriteTimeo. */
-	unsigned long uWriteTimeout = ( HZ / 1000 ) + 1;
+	/* see comments in do_write_oneword() regarding uWriteTimeo.
+	   Note: write_buffer commands take longer so we use a higher
+	   time. The AMD 29LV256M for instance has a datasheet max
+	   of 1.2ms for page and 600us for byte */
+	unsigned long uWriteTimeout = (HZ / 1500) + 2;
 	int ret = -EIO;
 	unsigned long cmd_adr;
 	int z, words;
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-10-15 20:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-05 18:32 [PATCH] [MTD] Adjust the NOR CFI flash timeouts to round better Jason Gunthorpe
2012-10-15 13:42 ` Artem Bityutskiy
2012-10-15 16:09   ` David Woodhouse
2012-10-15 16:57     ` Jason Gunthorpe
2012-10-15 17:31       ` David Woodhouse
2012-10-15 17:49         ` Jason Gunthorpe
2012-10-15 18:32           ` David Woodhouse
2012-10-15 19:08             ` Jason Gunthorpe
2012-10-15 19:28     ` Artem Bityutskiy
2012-10-15 20:00       ` David Woodhouse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox