All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johan Gunnarsson <johan.gunnarsson@axis.com>
To: "dedekind1@gmail.com" <dedekind1@gmail.com>,
	Brian Norris <computersforpeace@gmail.com>
Cc: "linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>,
	Jesper Nilsson <jespern@axis.com>
Subject: RE: [PATCH 2/2] mtd: nand: use hrtimer to measure timeout in nand_wait{_ready, }
Date: Tue, 22 May 2012 10:52:22 +0200	[thread overview]
Message-ID: <A612847CFE53224C91B23E3A5B48BAC7534B129D18@xmail3.se.axis.com> (raw)
In-Reply-To: <1337673190.2483.115.camel@sauron.fi.intel.com>



> -----Original Message-----
> From: Artem Bityutskiy [mailto:dedekind1@gmail.com]
> Sent: den 22 maj 2012 09:53
> To: Johan Gunnarsson; Brian Norris
> Cc: linux-mtd@lists.infradead.org; Jesper Nilsson
> Subject: Re: [PATCH 2/2] mtd: nand: use hrtimer to measure timeout in
> nand_wait{_ready, }
> 
> On Mon, 2012-05-21 at 10:42 +0200, Johan Gunnarsson wrote:
> > @@ -533,19 +541,29 @@ static void panic_nand_wait_ready(struct
> mtd_info *mtd, unsigned long timeo)
> >  void nand_wait_ready(struct mtd_info *mtd)
> >  {
> >  	struct nand_chip *chip = mtd->priv;
> > -	unsigned long timeo = jiffies + 2;
> > +	struct hrtimer timer;
> >
> >  	/* 400ms timeout */
> >  	if (in_interrupt() || oops_in_progress)
> >  		return panic_nand_wait_ready(mtd, 400);
> >
> >  	led_trigger_event(nand_led_trigger, LED_FULL);
> > +
> > +	/* Arm timeout timer for 20ms timeout */
> > +	hrtimer_init(&timer, CLOCK_REALTIME, HRTIMER_MODE_REL);
> > +	timer.function = nand_wait_timeout_callback;
> > +	hrtimer_start(&timer, ns_to_ktime(20 * 1000 * 1000),
> > +	              HRTIMER_MODE_REL);
> > +
> >  	/* Wait until command is processed or timeout occurs */
> >  	do {
> >  		if (chip->dev_ready(mtd))
> >  			break;
> >  		touch_softlockup_watchdog();
> > -	} while (time_before(jiffies, timeo));
> 
> Si this function waits for the chip, but if we cannot access the
> "ready"
> pin - it waits for 400msecs? Where this number 400 comes from? Why not
> 500? How many chips we have which do not provide "dev_ready()"
> function?

Not an expert on the MTD framework -- but I believe the 400 comes from the comment above nand_wait(): "Wait for command done. This applies to erase and program only. Erase can take up to 400ms and program up to 20ms according to general NAND and SmartMedia specs."

> Can we simplify this function and assume everyone has "dev_ready()" and
> add BUG_ON(!chip->dev_ready) - could you make a small research ? Or can

The drivers/mtd/nand/h1910.c driver sets dev_ready to NULL on init. The others seem to have dev_ready implementations.

> we do like this:
> 
> if (!dev_ready()) {
> 	msleep(400);
> 	return
> }
> 
> do {
> } while
> 
> Why should we iterate if "dev_ready" is NULL?

Actually, it's worse than that. If dev_ready is NULL (as in the h1910.c case) we'll crash the kernel, right?

> 
> My point is that this stuff ancient horror which needs love and
> cleaning
> up. Your does not make it less scary. I'd prefer to first clean the
> whole thing up, and then fix it.
> 
> I'm CCing Brian who spent a lot of time digging nand_base.c recently,
> he
> has probably got some ideas.
> 
> --
> Best Regards,
> Artem Bityutskiy

  reply	other threads:[~2012-05-22  8:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-21  8:42 [PATCH 0/2] use hrtimer in nand_wait Johan Gunnarsson
2012-05-21  8:42 ` [PATCH 1/2] mtd: nand: panic_nand_wait expects timeout in ms Johan Gunnarsson
2012-05-21  8:42 ` [PATCH 2/2] mtd: nand: use hrtimer to measure timeout in nand_wait{_ready, } Johan Gunnarsson
2012-05-22  7:53   ` Artem Bityutskiy
2012-05-22  8:52     ` Johan Gunnarsson [this message]
2012-05-22 10:25       ` Artem Bityutskiy
2012-05-22 14:24         ` Johan Gunnarsson
2012-05-22 17:10       ` Ivan Djelic
2012-05-22 18:21         ` Artem Bityutskiy
2012-05-23  6:39         ` Brian Norris
2012-05-23  8:36           ` Ivan Djelic
2012-05-23  8:14         ` Johan Gunnarsson
2012-05-22  7:23 ` [PATCH 0/2] use hrtimer in nand_wait Artem Bityutskiy
2012-05-22  8:37   ` Johan Gunnarsson

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=A612847CFE53224C91B23E3A5B48BAC7534B129D18@xmail3.se.axis.com \
    --to=johan.gunnarsson@axis.com \
    --cc=computersforpeace@gmail.com \
    --cc=dedekind1@gmail.com \
    --cc=jespern@axis.com \
    --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.