linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Grant Likely <grant.likely@secretlab.ca>
To: Richard Cochran <richardcochran@gmail.com>
Cc: netdev@vger.kernel.org, devicetree-discuss@lists.ozlabs.org,
	Thomas Gleixner <tglx@linutronix.de>,
	linuxppc-dev@lists.ozlabs.org,
	linux-arm-kernel@lists.infradead.org,
	Krzysztof Halasa <khc@pm.waw.pl>
Subject: Re: [PATCH 05/12] phylib: Allow reading and writing a mii bus from atomic context.
Date: Tue, 15 Jun 2010 10:43:08 -0600	[thread overview]
Message-ID: <AANLkTikeae2t4KmnawOCo2LqfSI57BKjNnUayY09DfEC@mail.gmail.com> (raw)
In-Reply-To: <1b8219e7d7993d0e8204b94e959477e3007534ce.1276615626.git.richard.cochran@omicron.at>

On Tue, Jun 15, 2010 at 10:08 AM, Richard Cochran
<richardcochran@gmail.com> wrote:
> In order to support hardware time stamping from a PHY, it is necessary to
> read from the PHY while running in_interrupt(). This patch allows a mii
> bus to operate in an atomic context. An mii_bus driver may declare itself
> capable for this mode. Drivers which do not do this will remain with the
> default that bus operations may sleep.
>
> Signed-off-by: Richard Cochran <richard.cochran@omicron.at>

Last I checked, the MDIO bus is very slow.  Is this really a good
idea?  How much latency does MDIO access have on the hardware you are
working with?

I also don't like the idea of taking a spin lock during MDIO
operations, and the dual locking mode in the core code.

I'd rather see separate atomic context hooks that doesn't obtain the
mutex under the assumption that the caller has already done so.  If
the bus doesn't support atomic access, then it won't implement the
hooks and the core code should return an error.

I've cc'd Thomas Gleixner.  He might have a better idea about how to
implement what you're trying to do.

g.

> ---
> =A0drivers/net/phy/mdio_bus.c | =A0 35 ++++++++++++++++++++++++++++------=
-
> =A0include/linux/phy.h =A0 =A0 =A0 =A0| =A0 13 +++++++++++--
> =A02 files changed, 39 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index 6a6b819..441be7d 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -36,6 +36,22 @@
> =A0#include <asm/irq.h>
> =A0#include <asm/uaccess.h>
>
> +static inline void mdiobus_lock(struct mii_bus *bus)
> +{
> + =A0 =A0 =A0 if (MDIOBUS_SLEEPS_RW =3D=3D bus->locktype)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 mutex_lock(&bus->mdio_lock.m);
> + =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_lock(&bus->mdio_lock.s);
> +}
> +
> +static inline void mdiobus_unlock(struct mii_bus *bus)
> +{
> + =A0 =A0 =A0 if (MDIOBUS_SLEEPS_RW =3D=3D bus->locktype)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 mutex_unlock(&bus->mdio_lock.m);
> + =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_unlock(&bus->mdio_lock.s);
> +}
> +
> =A0/**
> =A0* mdiobus_alloc - allocate a mii_bus structure
> =A0*
> @@ -107,7 +123,10 @@ int mdiobus_register(struct mii_bus *bus)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return -EINVAL;
> =A0 =A0 =A0 =A0}
>
> - =A0 =A0 =A0 mutex_init(&bus->mdio_lock);
> + =A0 =A0 =A0 if (MDIOBUS_SLEEPS_RW =3D=3D bus->locktype)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 mutex_init(&bus->mdio_lock.m);
> + =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_lock_init(&bus->mdio_lock.s);
>
> =A0 =A0 =A0 =A0if (bus->reset)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0bus->reset(bus);
> @@ -212,11 +231,12 @@ int mdiobus_read(struct mii_bus *bus, int addr, u32=
 regnum)
> =A0{
> =A0 =A0 =A0 =A0int retval;
>
> - =A0 =A0 =A0 BUG_ON(in_interrupt());
> + =A0 =A0 =A0 if (MDIOBUS_SLEEPS_RW =3D=3D bus->locktype)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 BUG_ON(in_interrupt());
>
> - =A0 =A0 =A0 mutex_lock(&bus->mdio_lock);
> + =A0 =A0 =A0 mdiobus_lock(bus);
> =A0 =A0 =A0 =A0retval =3D bus->read(bus, addr, regnum);
> - =A0 =A0 =A0 mutex_unlock(&bus->mdio_lock);
> + =A0 =A0 =A0 mdiobus_unlock(bus);
>
> =A0 =A0 =A0 =A0return retval;
> =A0}
> @@ -237,11 +257,12 @@ int mdiobus_write(struct mii_bus *bus, int addr, u3=
2 regnum, u16 val)
> =A0{
> =A0 =A0 =A0 =A0int err;
>
> - =A0 =A0 =A0 BUG_ON(in_interrupt());
> + =A0 =A0 =A0 if (MDIOBUS_SLEEPS_RW =3D=3D bus->locktype)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 BUG_ON(in_interrupt());
>
> - =A0 =A0 =A0 mutex_lock(&bus->mdio_lock);
> + =A0 =A0 =A0 mdiobus_lock(bus);
> =A0 =A0 =A0 =A0err =3D bus->write(bus, addr, regnum, val);
> - =A0 =A0 =A0 mutex_unlock(&bus->mdio_lock);
> + =A0 =A0 =A0 mdiobus_unlock(bus);
>
> =A0 =A0 =A0 =A0return err;
> =A0}
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 7a8caac..352b030 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -98,11 +98,20 @@ struct mii_bus {
> =A0 =A0 =A0 =A0int (*write)(struct mii_bus *bus, int phy_id, int regnum, =
u16 val);
> =A0 =A0 =A0 =A0int (*reset)(struct mii_bus *bus);
>
> + =A0 =A0 =A0 /* Indicates whether bus may be used from an atomic context=
. */
> + =A0 =A0 =A0 enum {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 MDIOBUS_SLEEPS_RW,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 MDIOBUS_ATOMIC_RW
> + =A0 =A0 =A0 } locktype;
> +
> =A0 =A0 =A0 =A0/*
> - =A0 =A0 =A0 =A0* A lock to ensure that only one thing can read/write
> + =A0 =A0 =A0 =A0* A lock or mutex to ensure that only one thing can read=
/write
> =A0 =A0 =A0 =A0 * the MDIO bus at a time
> =A0 =A0 =A0 =A0 */
> - =A0 =A0 =A0 struct mutex mdio_lock;
> + =A0 =A0 =A0 union {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct mutex m;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 spinlock_t s;
> + =A0 =A0 =A0 } mdio_lock;
>
> =A0 =A0 =A0 =A0struct device *parent;
> =A0 =A0 =A0 =A0enum {
> --
> 1.6.3.3
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>



--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

  reply	other threads:[~2010-06-15 16:43 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-15 16:06 [PATCH v4 00/12] ptp: IEEE 1588 clock support Richard Cochran
2010-06-15 16:07 ` [PATCH 01/12] phylib: preserve ifreq parameter when calling generic phy_mii_ioctl() Richard Cochran
2010-06-15 16:07 ` [PATCH 02/12] phylib: do not filter phy_mii_ioctl() Richard Cochran
2010-06-15 16:26   ` Grant Likely
2010-06-15 16:08 ` [PATCH 03/12] phylib: add a driver method for the SIOCSHWTSTAMP ioctl Richard Cochran
2010-06-15 16:27   ` Grant Likely
2010-06-15 16:34     ` Richard Cochran
2010-06-15 16:49       ` Grant Likely
2010-06-15 16:53         ` Grant Likely
2010-06-15 16:08 ` [PATCH 04/12] phylib: add a way to make PHY time stamps possible Richard Cochran
2010-06-15 16:33   ` Grant Likely
2010-06-16  5:40     ` Richard Cochran
2010-06-16  6:29   ` Richard Cochran
2010-06-17  1:03   ` David Miller
2010-06-15 16:08 ` [PATCH 05/12] phylib: Allow reading and writing a mii bus from atomic context Richard Cochran
2010-06-15 16:43   ` Grant Likely [this message]
2010-06-15 17:08     ` Richard Cochran
2010-06-15 18:29       ` Grant Likely
2010-06-16  6:20         ` Richard Cochran
2010-06-15 16:09 ` [PATCH 06/12] ptp: add a BPF to help drivers detect PTP packets Richard Cochran
2010-06-15 16:09 ` [PATCH 07/12] phylib: support the National Semiconductor DP83640 PHY Richard Cochran
2010-06-15 16:09 ` [PATCH 08/12] ptp: Added a brand new class driver for ptp clocks Richard Cochran
2010-06-15 17:00   ` Grant Likely
2010-06-16 14:22     ` Richard Cochran
2010-06-15 19:11   ` Grant Likely
2010-08-13  9:34     ` Richard Cochran
2010-08-13 23:54       ` Grant Likely
2010-06-15 16:09 ` [PATCH 09/12] ptp: Added a clock that uses the Linux system time Richard Cochran
2010-06-15 16:10 ` [PATCH 10/12] ptp: Added a clock that uses the eTSEC found on the MPC85xx Richard Cochran
2010-06-15 17:20   ` Grant Likely
2010-06-16  6:45     ` Richard Cochran
2010-06-15 16:10 ` [PATCH 11/12] ptp: Added a clock driver for the IXP46x Richard Cochran
2010-06-15 18:41   ` Grant Likely
2010-06-16  6:54     ` Richard Cochran
2010-06-15 16:10 ` [PATCH 12/12] ptp: Added a clock driver for the National Semiconductor PHYTER Richard Cochran
2010-06-15 18:49   ` Grant Likely
2010-06-16 10:05     ` Richard Cochran
2010-06-16 15:10       ` Grant Likely

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=AANLkTikeae2t4KmnawOCo2LqfSI57BKjNnUayY09DfEC@mail.gmail.com \
    --to=grant.likely@secretlab.ca \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=khc@pm.waw.pl \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).