All of lore.kernel.org
 help / color / mirror / Atom feed
From: Russell King - ARM Linux admin <linux@armlinux.org.uk>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org
Subject: Re: [PATCH net-next 1/3] net: mdiobus: add APIs for modifying a MDIO device register
Date: Mon, 16 Mar 2020 09:12:07 +0000	[thread overview]
Message-ID: <20200316091207.GM25745@shell.armlinux.org.uk> (raw)
In-Reply-To: <20200314215728.GG8622@lunn.ch>

On Sat, Mar 14, 2020 at 10:57:28PM +0100, Andrew Lunn wrote:
> On Sat, Mar 14, 2020 at 10:31:24AM +0000, Russell King wrote:
> > Add APIs for modifying a MDIO device register, similar to the existing
> > phy_modify() group of functions, but at mdiobus level instead.  Adapt
> > __phy_modify_changed() to use the new mdiobus level helper.
> > 
> > Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
> > ---
> >  drivers/net/phy/mdio_bus.c | 55 ++++++++++++++++++++++++++++++++++++++
> >  drivers/net/phy/phy-core.c | 31 ---------------------
> >  include/linux/mdio.h       |  4 +++
> >  include/linux/phy.h        | 19 +++++++++++++
> >  4 files changed, 78 insertions(+), 31 deletions(-)
> > 
> > diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> > index 3ab9ca7614d1..b33d1e793686 100644
> > --- a/drivers/net/phy/mdio_bus.c
> > +++ b/drivers/net/phy/mdio_bus.c
> > @@ -824,6 +824,38 @@ int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val)
> >  }
> >  EXPORT_SYMBOL(__mdiobus_write);
> >  
> > +/**
> > + * __mdiobus_modify_changed - Unlocked version of the mdiobus_modify function
> > + * @bus: the mii_bus struct
> > + * @addr: the phy address
> > + * @regnum: register number to modify
> > + * @mask: bit mask of bits to clear
> > + * @set: bit mask of bits to set
> > + *
> > + * Read, modify, and if any change, write the register value back to the
> > + * device. Any error returns a negative number.
> > + *
> > + * NOTE: MUST NOT be called from interrupt context.
> > + */
> > +int __mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum,
> > +			     u16 mask, u16 set)
> > +{
> > +	int new, ret;
> > +
> > +	ret = __mdiobus_read(bus, addr, regnum);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	new = (ret & ~mask) | set;
> > +	if (new == ret)
> > +		return 0;
> > +
> > +	ret = __mdiobus_write(bus, addr, regnum, new);
> > +
> > +	return ret < 0 ? ret : 1;
> > +}
> > +EXPORT_SYMBOL_GPL(__mdiobus_modify_changed);
> > +
> >  /**
> >   * mdiobus_read_nested - Nested version of the mdiobus_read function
> >   * @bus: the mii_bus struct
> > @@ -928,6 +960,29 @@ int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val)
> >  }
> >  EXPORT_SYMBOL(mdiobus_write);
> >  
> > +/**
> > + * mdiobus_modify - Convenience function for modifying a given mdio device
> > + *	register
> > + * @bus: the mii_bus struct
> > + * @addr: the phy address
> > + * @regnum: register number to write
> > + * @mask: bit mask of bits to clear
> > + * @set: bit mask of bits to set
> > + */
> > +int mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask, u16 set)
> > +{
> > +	int err;
> > +
> > +	BUG_ON(in_interrupt());
> 
> Hi Russell
> 
> There seems to be growing push back on using BUG_ON and its
> variants. If should only be used if the system is so badly messed up,
> going further would only cause more damage. What really happens here
> if it is called in interrupt context? The mutex lock probably won't
> work, and we might corrupt the state of the PCS. That is not the end
> of the world. So i would suggest a WARN_ON here.

Do we even need these checks? (phylib has them scattered throughout
on the bus accessors.)  Aren't the might_sleep() checks that are
already in the locking functions already sufficient?

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 10.2Mbps down 587kbps up

  reply	other threads:[~2020-03-16  9:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-14 10:31 [PATCH REPOST3 net-next 0/3] net: add phylink support for PCS Russell King - ARM Linux admin
2020-03-14 10:31 ` [PATCH net-next 1/3] net: mdiobus: add APIs for modifying a MDIO device register Russell King
2020-03-14 21:57   ` Andrew Lunn
2020-03-16  9:12     ` Russell King - ARM Linux admin [this message]
2020-03-17 14:09       ` Andrew Lunn
2020-03-14 10:31 ` [PATCH net-next 2/3] net: phylink: pcs: add 802.3 clause 22 helpers Russell King
2020-03-14 10:31 ` [PATCH net-next 3/3] net: phylink: pcs: add 802.3 clause 45 helpers Russell King
2020-03-14 21:48   ` Andrew Lunn
2020-03-14 22:00 ` [PATCH REPOST3 net-next 0/3] net: add phylink support for PCS Andrew Lunn
2020-03-14 22:44   ` Russell King - ARM Linux admin
2020-03-17 14:18     ` Andrew Lunn
2020-03-17 15:26       ` Russell King - ARM Linux admin

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=20200316091207.GM25745@shell.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=netdev@vger.kernel.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.