All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Niebel <list-09_linux_mtd@tqsc.de>
To: linux-mtd@lists.infradead.org
Subject: [PATCH 2.6.34 2/2] cfi_cmdset_0002.c: Use maxtimeouts for erase and program instead of hardcoded values
Date: Fri, 25 Mar 2011 08:56:04 +0100	[thread overview]
Message-ID: <4D8C4A94.3030309@tqsc.de> (raw)

Maximum timeouts are read from the CFI query structure and stored in the
chips structure table. Use the timeouts for erase and program instead of
fixed values.

Signed-off-by: Markus Niebel <markus.niebel@tqs.de>
---

  drivers/mtd/chips/cfi_cmdset_0002.c |   47 
+++++++++++++++++------------------
  1 files changed, 23 insertions(+), 24 deletions(-)


diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c 
b/drivers/mtd/chips/cfi_cmdset_0002.c
index 1eb8bfa..d64939f 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -1074,17 +1074,13 @@ static int cfi_amdstd_secsi_read (struct 
mtd_info *mtd, loff_t from, size_t len,
  static int __xipram do_write_oneword(struct map_info *map, struct 
flchip *chip, unsigned long adr, map_word datum)
  {
  	struct cfi_private *cfi = map->fldrv_priv;
-	unsigned long timeo = jiffies + HZ;
-	/*
-	 * We use a 1ms + 1 jiffies generic timeout for writes (most devices
-	 * have a max write time of a few hundreds usec). However, we should
-	 * 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.
+	unsigned long timeo;
+
+	/* use the max timeout read from cfi, increase by one to make sure it's
+	 * not zero
  	 */
-	unsigned long uWriteTimeout = ( HZ / 1000 ) + 1;
+	unsigned long write_timeout = 
usecs_to_jiffies(chip->word_write_time_max) + 1;
+
  	int ret = 0;
  	map_word oldd;
  	int retry_cnt = 0;
@@ -1129,7 +1125,7 @@ static int __xipram do_write_oneword(struct 
map_info *map, struct flchip *chip,
  				chip->word_write_time);

  	/* See comment above for timeout value. */
-	timeo = jiffies + uWriteTimeout;
+	timeo = jiffies + write_timeout;
  	for (;;) {
  		if (chip->state != FL_WRITING) {
  			/* Someone's suspended the write. Sleep */
@@ -1140,7 +1136,7 @@ static int __xipram do_write_oneword(struct 
map_info *map, struct flchip *chip,
  			spin_unlock(chip->mutex);
  			schedule();
  			remove_wait_queue(&chip->wq, &wait);
-			timeo = jiffies + (HZ / 2); /* FIXME */
+			timeo = jiffies + write_timeout;
  			spin_lock(chip->mutex);
  			continue;
  		}
@@ -1329,9 +1325,9 @@ static int __xipram do_write_buffer(struct 
map_info *map, struct flchip *chip,
  				    int len)
  {
  	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;
+	unsigned long timeo;
+	/* see comments in do_write_oneword() regarding write_timeout. */
+	unsigned long write_timeout = 
usecs_to_jiffies(chip->buffer_write_time_max) + 1;
  	int ret = -EIO;
  	unsigned long cmd_adr;
  	int z, words;
@@ -1387,9 +1383,9 @@ static int __xipram do_write_buffer(struct 
map_info *map, struct flchip *chip,

  	INVALIDATE_CACHE_UDELAY(map, chip,
  				adr, map_bankwidth(map),
-				chip->word_write_time);
+				chip->buffer_write_time);

-	timeo = jiffies + uWriteTimeout;
+	timeo = jiffies + write_timeout;

  	for (;;) {
  		if (chip->state != FL_WRITING) {
@@ -1401,7 +1397,7 @@ static int __xipram do_write_buffer(struct 
map_info *map, struct flchip *chip,
  			spin_unlock(chip->mutex);
  			schedule();
  			remove_wait_queue(&chip->wq, &wait);
-			timeo = jiffies + (HZ / 2); /* FIXME */
+			timeo = jiffies + write_timeout;
  			spin_lock(chip->mutex);
  			continue;
  		}
@@ -1523,7 +1519,8 @@ static int cfi_amdstd_write_buffers(struct 
mtd_info *mtd, loff_t to, size_t len,
  static int __xipram do_erase_chip(struct map_info *map, struct flchip 
*chip)
  {
  	struct cfi_private *cfi = map->fldrv_priv;
-	unsigned long timeo = jiffies + HZ;
+	unsigned long wait_time = msecs_to_jiffies(chip->erase_time_max) + 1;
+	unsigned long timeo;
  	unsigned long int adr;
  	DECLARE_WAITQUEUE(wait, current);
  	int ret = 0;
@@ -1559,7 +1556,7 @@ static int __xipram do_erase_chip(struct map_info 
*map, struct flchip *chip)
  				adr, map->size,
  				chip->erase_time*500);

-	timeo = jiffies + (HZ*20);
+	timeo = jiffies + wait_time;

  	for (;;) {
  		if (chip->state != FL_ERASING) {
@@ -1575,7 +1572,7 @@ static int __xipram do_erase_chip(struct map_info 
*map, struct flchip *chip)
  		if (chip->erase_suspended) {
  			/* This erase was suspended and resumed.
  			   Adjust the timeout */
-			timeo = jiffies + (HZ*20); /* FIXME */
+			timeo = jiffies + wait_time;
  			chip->erase_suspended = 0;
  		}

@@ -1613,7 +1610,8 @@ static int __xipram do_erase_chip(struct map_info 
*map, struct flchip *chip)
  static int __xipram do_erase_oneblock(struct map_info *map, struct 
flchip *chip, unsigned long adr, int len, void *thunk)
  {
  	struct cfi_private *cfi = map->fldrv_priv;
-	unsigned long timeo = jiffies + HZ;
+	unsigned long timeo;
+	unsigned long wait_time = msecs_to_jiffies(chip->erase_time_max) + 1;
  	DECLARE_WAITQUEUE(wait, current);
  	int ret = 0;

@@ -1644,11 +1642,12 @@ static int __xipram do_erase_oneblock(struct 
map_info *map, struct flchip *chip,
  	chip->erase_suspended = 0;
  	chip->in_progress_block_addr = adr;

+	/* FIXME: erase time is in msec, so timeout is half of the typical 
erase time? */
  	INVALIDATE_CACHE_UDELAY(map, chip,
  				adr, len,
  				chip->erase_time*500);

-	timeo = jiffies + (HZ*20);
+	timeo = jiffies + wait_time;

  	for (;;) {
  		if (chip->state != FL_ERASING) {
@@ -1664,7 +1663,7 @@ static int __xipram do_erase_oneblock(struct 
map_info *map, struct flchip *chip,
  		if (chip->erase_suspended) {
  			/* This erase was suspended and resumed.
  			   Adjust the timeout */
-			timeo = jiffies + (HZ*20); /* FIXME */
+			timeo = jiffies + wait_time;
  			chip->erase_suspended = 0;
  		}
  		if (time_after(jiffies, timeo) && !chip_good(map, adr, 
map_word_ff(map))) {

                 reply	other threads:[~2011-03-25  7:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4D8C4A94.3030309@tqsc.de \
    --to=list-09_linux_mtd@tqsc.de \
    --cc=linux-mtd@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.