forked from Minki/linux
Merge branch 'mdiobus_nested_read_write'
Neil Armstrong says: ==================== Refactor nested mdiobus read/write functions In order to avoid locked signal false positive for nested mdiobus read/write calls, nested code was introduced in mv88e6xxx and mdio-mux. But mv88e6060 also needs such nested mdiobus read/write calls. For sake of refactoring, introduce nested variants of mdiobus read/write and make them used by mv88e6xxx and mv88e6060. In a next patch, mdio-mux should also use these variant calls. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
commit
654c9c543a
@ -26,7 +26,7 @@ static int reg_read(struct dsa_switch *ds, int addr, int reg)
|
||||
if (bus == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
return mdiobus_read(bus, ds->pd->sw_addr + addr, reg);
|
||||
return mdiobus_read_nested(bus, ds->pd->sw_addr + addr, reg);
|
||||
}
|
||||
|
||||
#define REG_READ(addr, reg) \
|
||||
@ -47,7 +47,7 @@ static int reg_write(struct dsa_switch *ds, int addr, int reg, u16 val)
|
||||
if (bus == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
return mdiobus_write(bus, ds->pd->sw_addr + addr, reg, val);
|
||||
return mdiobus_write_nested(bus, ds->pd->sw_addr + addr, reg, val);
|
||||
}
|
||||
|
||||
#define REG_WRITE(addr, reg, val) \
|
||||
|
@ -24,34 +24,6 @@
|
||||
#include <net/switchdev.h>
|
||||
#include "mv88e6xxx.h"
|
||||
|
||||
/* MDIO bus access can be nested in the case of PHYs connected to the
|
||||
* internal MDIO bus of the switch, which is accessed via MDIO bus of
|
||||
* the Ethernet interface. Avoid lockdep false positives by using
|
||||
* mutex_lock_nested().
|
||||
*/
|
||||
static int mv88e6xxx_mdiobus_read(struct mii_bus *bus, int addr, u32 regnum)
|
||||
{
|
||||
int ret;
|
||||
|
||||
mutex_lock_nested(&bus->mdio_lock, SINGLE_DEPTH_NESTING);
|
||||
ret = bus->read(bus, addr, regnum);
|
||||
mutex_unlock(&bus->mdio_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mv88e6xxx_mdiobus_write(struct mii_bus *bus, int addr, u32 regnum,
|
||||
u16 val)
|
||||
{
|
||||
int ret;
|
||||
|
||||
mutex_lock_nested(&bus->mdio_lock, SINGLE_DEPTH_NESTING);
|
||||
ret = bus->write(bus, addr, regnum, val);
|
||||
mutex_unlock(&bus->mdio_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* If the switch's ADDR[4:0] strap pins are strapped to zero, it will
|
||||
* use all 32 SMI bus addresses on its SMI bus, and all switch registers
|
||||
* will be directly accessible on some {device address,register address}
|
||||
@ -66,7 +38,7 @@ static int mv88e6xxx_reg_wait_ready(struct mii_bus *bus, int sw_addr)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
ret = mv88e6xxx_mdiobus_read(bus, sw_addr, SMI_CMD);
|
||||
ret = mdiobus_read_nested(bus, sw_addr, SMI_CMD);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@ -82,7 +54,7 @@ int __mv88e6xxx_reg_read(struct mii_bus *bus, int sw_addr, int addr, int reg)
|
||||
int ret;
|
||||
|
||||
if (sw_addr == 0)
|
||||
return mv88e6xxx_mdiobus_read(bus, addr, reg);
|
||||
return mdiobus_read_nested(bus, addr, reg);
|
||||
|
||||
/* Wait for the bus to become free. */
|
||||
ret = mv88e6xxx_reg_wait_ready(bus, sw_addr);
|
||||
@ -90,8 +62,8 @@ int __mv88e6xxx_reg_read(struct mii_bus *bus, int sw_addr, int addr, int reg)
|
||||
return ret;
|
||||
|
||||
/* Transmit the read command. */
|
||||
ret = mv88e6xxx_mdiobus_write(bus, sw_addr, SMI_CMD,
|
||||
SMI_CMD_OP_22_READ | (addr << 5) | reg);
|
||||
ret = mdiobus_write_nested(bus, sw_addr, SMI_CMD,
|
||||
SMI_CMD_OP_22_READ | (addr << 5) | reg);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@ -101,7 +73,7 @@ int __mv88e6xxx_reg_read(struct mii_bus *bus, int sw_addr, int addr, int reg)
|
||||
return ret;
|
||||
|
||||
/* Read the data. */
|
||||
ret = mv88e6xxx_mdiobus_read(bus, sw_addr, SMI_DATA);
|
||||
ret = mdiobus_read_nested(bus, sw_addr, SMI_DATA);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@ -145,7 +117,7 @@ int __mv88e6xxx_reg_write(struct mii_bus *bus, int sw_addr, int addr,
|
||||
int ret;
|
||||
|
||||
if (sw_addr == 0)
|
||||
return mv88e6xxx_mdiobus_write(bus, addr, reg, val);
|
||||
return mdiobus_write_nested(bus, addr, reg, val);
|
||||
|
||||
/* Wait for the bus to become free. */
|
||||
ret = mv88e6xxx_reg_wait_ready(bus, sw_addr);
|
||||
@ -153,13 +125,13 @@ int __mv88e6xxx_reg_write(struct mii_bus *bus, int sw_addr, int addr,
|
||||
return ret;
|
||||
|
||||
/* Transmit the data to write. */
|
||||
ret = mv88e6xxx_mdiobus_write(bus, sw_addr, SMI_DATA, val);
|
||||
ret = mdiobus_write_nested(bus, sw_addr, SMI_DATA, val);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* Transmit the write command. */
|
||||
ret = mv88e6xxx_mdiobus_write(bus, sw_addr, SMI_CMD,
|
||||
SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
|
||||
ret = mdiobus_write_nested(bus, sw_addr, SMI_CMD,
|
||||
SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
|
@ -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
|
||||
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user