public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Arnaud Mouiche <arnaud.mouiche@gmail.com>
Cc: Marek Vasut <marex@denx.de>, Peter Pan <peterpandong@micron.com>,
	richard@nod.at, computersforpeace@gmail.com,
	thomas.petazzoni@free-electrons.com, cyrille.pitchen@atmel.com,
	linux-mtd@lists.infradead.org, peterpansjtu@gmail.com,
	linshunquan1@hisilicon.com
Subject: Re: [PATCH v4 4/9] nand: spi: add basic blocks for infrastructure
Date: Thu, 30 Mar 2017 14:52:01 +0200	[thread overview]
Message-ID: <20170330145201.4a36ad5b@bbrezillon> (raw)
In-Reply-To: <d5bb74fa-a049-1116-ad9a-485496233d88@gmail.com>

On Thu, 30 Mar 2017 14:25:41 +0200
Arnaud Mouiche <arnaud.mouiche@gmail.com> wrote:

> On 23/03/2017 17:33, Marek Vasut wrote:
> > On 03/23/2017 04:40 PM, Boris Brezillon wrote:  
> >> On Thu, 23 Mar 2017 12:29:58 +0100
> >> Marek Vasut <marex@denx.de> wrote:
> >>
> >>  
> >>>> +
> >>>> +/*
> >>>> + * spinand_read_status - get status register value
> >>>> + * @chip: SPI NAND device structure
> >>>> + * @status: buffer to store value
> >>>> + * Description:
> >>>> + *   After read, write, or erase, the NAND device is expected to set the
> >>>> + *   busy status.
> >>>> + *   This function is to allow reading the status of the command: read,
> >>>> + *   write, and erase.
> >>>> + */
> >>>> +static int spinand_read_status(struct spinand_device *chip, uint8_t *status)
> >>>> +{
> >>>> +	return spinand_read_reg(chip, REG_STATUS, status);
> >>>> +}
> >>>> +
> >>>> +/*
> >>>> + * spinand_wait - wait until the command is done
> >>>> + * @chip: SPI NAND device structure
> >>>> + * @s: buffer to store status register value (can be NULL)
> >>>> + */
> >>>> +static int spinand_wait(struct spinand_device *chip, u8 *s)
> >>>> +{
> >>>> +	unsigned long timeo = msecs_to_jiffies(400);
> >>>> +	u8 status;
> >>>> +
> >>>> +	do {
> >>>> +		spinand_read_status(chip, &status);
> >>>> +		if ((status & STATUS_OIP_MASK) == STATUS_READY)
> >>>> +			goto out;
> >>>> +	} while (time_before(jiffies, timeo));
> >>>> +
> >>>> +	/*
> >>>> +	 * Extra read, just in case the STATUS_READY bit has changed
> >>>> +	 * since our last check
> >>>> +	 */  
> >>> Is this likely to happen ? Probably not ... so in case you reach this
> >>> place here, timeout happened.  
> >> If the timeout is big enough, no. But it does not hurt to do one last
> >> check.  
> > 400 mSec is not big enough ? It's huge ... this seems like a duplication
> > to me. btw the ad-hoc 400 mSec delay value should be replaced with a macro.
> >  
> In fact, there is a bug:
> 
> > unsigned long timeo = msecs_to_jiffies(400);
> > [...]
> > do { } while (time_before(jiffies, timeo));  
> 
> The condition is almost true except during the 5 minutes following the boot (before jiffies wrap around).
> So, only one status read is done, which give a high chance of returning a timeout status.
> I guess you should do : 	
> 
> 	unsigned long timeo = jiffies + msecs_to_jiffies(400);
> 
> I also suspect that this is the reason why you have an additional status read.

Oh, nice catch!

  reply	other threads:[~2017-03-30 12:52 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-23  9:43 [PATCH v4 0/9] Introduction to SPI NAND framework Peter Pan
2017-03-23  9:43 ` [PATCH v4 1/9] mtd: nand: add oob iterator in nand_for_each_page Peter Pan
2017-03-23 11:13   ` Marek Vasut
2017-03-28  1:35     ` Peter Pan
2017-03-29 19:34   ` Boris Brezillon
2017-03-30  8:01     ` Peter Pan
2017-03-30  8:34       ` Boris Brezillon
2017-03-23  9:43 ` [PATCH v4 2/9] mtd: nand: make sure mtd_oob_ops consistent in bbt Peter Pan
2017-03-29 19:48   ` Boris Brezillon
2017-03-23  9:43 ` [PATCH v4 3/9] mtd: nand: add more helpers in nand.h Peter Pan
2017-03-23 11:19   ` Marek Vasut
2017-03-29 19:57   ` Boris Brezillon
2017-03-30  8:04     ` Peter Pan
2017-03-30  8:40       ` Boris Brezillon
2017-03-23  9:43 ` [PATCH v4 4/9] nand: spi: add basic blocks for infrastructure Peter Pan
2017-03-23 11:29   ` Marek Vasut
2017-03-23 15:40     ` Boris Brezillon
2017-03-23 16:33       ` Marek Vasut
2017-03-30 12:25         ` Arnaud Mouiche
2017-03-30 12:52           ` Boris Brezillon [this message]
2017-03-29 22:28   ` Cyrille Pitchen
2017-03-30 12:38   ` Arnaud Mouiche
2017-03-30 12:51     ` Boris Brezillon
2017-03-23  9:43 ` [PATCH v4 5/9] nand: spi: add basic operations support Peter Pan
2017-03-23  9:43 ` [PATCH v4 6/9] nand: spi: Add bad block support Peter Pan
2017-03-23  9:43 ` [PATCH v4 7/9] nand: spi: add Micron spi nand support Peter Pan
2017-03-30 12:31   ` Arnaud Mouiche
2017-03-30 12:57     ` Boris Brezillon
2017-03-23  9:43 ` [PATCH v4 8/9] nand: spi: Add generic SPI controller support Peter Pan
2017-03-23 11:33   ` Marek Vasut
2017-03-28  1:38     ` Peter Pan
2017-03-29 21:37   ` Cyrille Pitchen
2017-03-30  8:28     ` Peter Pan
2017-03-23  9:43 ` [PATCH v4 9/9] MAINTAINERS: Add SPI NAND entry Peter Pan
2017-03-30 12:17 ` [PATCH v4 0/9] Introduction to SPI NAND framework Arnaud Mouiche
2017-04-10  7:33   ` Peter Pan

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=20170330145201.4a36ad5b@bbrezillon \
    --to=boris.brezillon@free-electrons.com \
    --cc=arnaud.mouiche@gmail.com \
    --cc=computersforpeace@gmail.com \
    --cc=cyrille.pitchen@atmel.com \
    --cc=linshunquan1@hisilicon.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marex@denx.de \
    --cc=peterpandong@micron.com \
    --cc=peterpansjtu@gmail.com \
    --cc=richard@nod.at \
    --cc=thomas.petazzoni@free-electrons.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