All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel@savoirfairelinux.com,
	"David S. Miller" <davem@davemloft.net>,
	Florian Fainelli <f.fainelli@gmail.com>
Subject: Re: [PATCH net-next 5/6] net: dsa: mv88e6xxx: add helper for switch ready
Date: Thu, 1 Dec 2016 00:38:10 +0100	[thread overview]
Message-ID: <20161130233810.GT21645@lunn.ch> (raw)
In-Reply-To: <20161130225930.25510-6-vivien.didelot@savoirfairelinux.com>

> +static int mv88e6xxx_wait_switch_ready(struct mv88e6xxx_chip *chip)
> +{
> +	const unsigned long timeout = jiffies + 1 * HZ;
> +	bool ready;
> +	int err;
> +
> +	/* Wait up to 1 second for switch to be ready.
> +	 * The switch is ready when all units inside the device (ATU, VTU, etc.)
> +	 * have finished their initialization and are ready to accept frames.
> +	 */
> +	while (time_before(jiffies, timeout)) {
> +		err = mv88e6xxx_g1_init_ready(chip, &ready);
> +		if (err)
> +			return err;
> +
> +		if (ready)
> +			break;
> +
> +		usleep_range(1000, 2000);
> +	}
> +
> +	if (time_after(jiffies, timeout))
> +		return -ETIMEDOUT;

As we have seen in the past, this sort of loop is broken if we end up
sleeping for a long time. Please take the opportunity to replace it
with one of our _wait() helpers, e.g. mv88e6xxx_g1_wait()

> +int mv88e6xxx_g1_init_ready(struct mv88e6xxx_chip *chip, bool *ready)
> +{
> +	u16 val;
> +	int err;
> +
> +	/* Check the value of the InitReady bit 11 */
> +	err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &val);
> +	if (err)
> +		return err;
> +
> +	*ready = !!(val & GLOBAL_STATUS_INIT_READY);

I would actually do the wait here.

> +
> +	return 0;
> +}
> +

Thanks

  Andrew

  reply	other threads:[~2016-11-30 23:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-30 22:59 [PATCH net-next 0/6] net: dsa: mv88e6xxx: rework reset and PPU code Vivien Didelot
2016-11-30 22:59 ` [PATCH net-next 1/6] net: dsa: mv88e6xxx: add helper to disable ports Vivien Didelot
2016-11-30 23:20   ` Andrew Lunn
2016-11-30 22:59 ` [PATCH net-next 2/6] net: dsa: mv88e6xxx: add helper to hardware reset Vivien Didelot
2016-11-30 23:21   ` Andrew Lunn
2016-11-30 22:59 ` [PATCH net-next 3/6] net: dsa: mv88e6xxx: add a software reset op Vivien Didelot
2016-11-30 23:26   ` Andrew Lunn
2016-12-01 20:41     ` Vivien Didelot
2016-12-02 15:43       ` Andrew Lunn
2016-12-02 17:30         ` Vivien Didelot
2016-12-02 17:23   ` David Miller
2016-11-30 22:59 ` [PATCH net-next 4/6] net: dsa: mv88e6xxx: add a PPU polling op Vivien Didelot
2016-11-30 22:59 ` [PATCH net-next 5/6] net: dsa: mv88e6xxx: add helper for switch ready Vivien Didelot
2016-11-30 23:38   ` Andrew Lunn [this message]
2016-12-01 20:31     ` Vivien Didelot
2016-11-30 22:59 ` [PATCH net-next 6/6] net: dsa: mv88e6xxx: add PPU enable/disable ops Vivien Didelot

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=20161130233810.GT21645@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=kernel@savoirfairelinux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=vivien.didelot@savoirfairelinux.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 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.