Skip to content

Commit

Permalink
net: phy: Add nested variants of mdiobus read/write
Browse files Browse the repository at this point in the history
Since nested variants of mdiobus_read/write are used in multiple
drivers, add nested variants in the mdiobus core.

Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Neil Armstrong authored and David S. Miller committed Oct 23, 2015
1 parent 6fb3b6b commit 21dd19f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
55 changes: 55 additions & 0 deletions drivers/net/phy/mdio_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,33 @@ struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
}
EXPORT_SYMBOL(mdiobus_scan);

/**
* mdiobus_read_nested - Nested version of the mdiobus_read function
* @bus: the mii_bus struct
* @addr: the phy address
* @regnum: register number to read
*
* In case of nested MDIO bus access avoid lockdep false positives by
* using mutex_lock_nested().
*
* NOTE: MUST NOT be called from interrupt context,
* because the bus read/write functions may wait for an interrupt
* to conclude the operation.
*/
int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum)
{
int retval;

BUG_ON(in_interrupt());

mutex_lock_nested(&bus->mdio_lock, SINGLE_DEPTH_NESTING);
retval = bus->read(bus, addr, regnum);
mutex_unlock(&bus->mdio_lock);

return retval;
}
EXPORT_SYMBOL(mdiobus_read_nested);

/**
* mdiobus_read - Convenience function for reading a given MII mgmt register
* @bus: the mii_bus struct
Expand All @@ -395,6 +422,34 @@ int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum)
}
EXPORT_SYMBOL(mdiobus_read);

/**
* mdiobus_write_nested - Nested version of the mdiobus_write function
* @bus: the mii_bus struct
* @addr: the phy address
* @regnum: register number to write
* @val: value to write to @regnum
*
* In case of nested MDIO bus access avoid lockdep false positives by
* using mutex_lock_nested().
*
* NOTE: MUST NOT be called from interrupt context,
* because the bus read/write functions may wait for an interrupt
* to conclude the operation.
*/
int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val)
{
int err;

BUG_ON(in_interrupt());

mutex_lock_nested(&bus->mdio_lock, SINGLE_DEPTH_NESTING);
err = bus->write(bus, addr, regnum, val);
mutex_unlock(&bus->mdio_lock);

return err;
}
EXPORT_SYMBOL(mdiobus_write_nested);

/**
* mdiobus_write - Convenience function for writing a given MII mgmt register
* @bus: the mii_bus struct
Expand Down
2 changes: 2 additions & 0 deletions include/linux/phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev)
void devm_mdiobus_free(struct device *dev, struct mii_bus *bus);
struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);


#define PHY_INTERRUPT_DISABLED 0x0
Expand Down

0 comments on commit 21dd19f

Please sign in to comment.