Skip to content

Commit 7d7e7bc

Browse files
mwalledavem330
authored andcommitted
net: phy: broadcom: add exp register access methods without buslock
Add helper to read and write expansion registers without taking the mdio lock. Please note, that this changes the semantics of the read and write. Before there was no lock between selecting the expansion register and the actual read/write. This may lead to access failures if there are parallel accesses. Instead take the bus lock during the whole access cycle. Signed-off-by: Michael Walle <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ea13d71 commit 7d7e7bc

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

drivers/net/phy/bcm-phy-lib.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,57 @@
1414
#define MII_BCM_CHANNEL_WIDTH 0x2000
1515
#define BCM_CL45VEN_EEE_ADV 0x3c
1616

17-
int bcm_phy_write_exp(struct phy_device *phydev, u16 reg, u16 val)
17+
int __bcm_phy_write_exp(struct phy_device *phydev, u16 reg, u16 val)
1818
{
1919
int rc;
2020

21-
rc = phy_write(phydev, MII_BCM54XX_EXP_SEL, reg);
21+
rc = __phy_write(phydev, MII_BCM54XX_EXP_SEL, reg);
2222
if (rc < 0)
2323
return rc;
2424

25-
return phy_write(phydev, MII_BCM54XX_EXP_DATA, val);
25+
return __phy_write(phydev, MII_BCM54XX_EXP_DATA, val);
26+
}
27+
EXPORT_SYMBOL_GPL(__bcm_phy_write_exp);
28+
29+
int bcm_phy_write_exp(struct phy_device *phydev, u16 reg, u16 val)
30+
{
31+
int rc;
32+
33+
phy_lock_mdio_bus(phydev);
34+
rc = __bcm_phy_write_exp(phydev, reg, val);
35+
phy_unlock_mdio_bus(phydev);
36+
37+
return rc;
2638
}
2739
EXPORT_SYMBOL_GPL(bcm_phy_write_exp);
2840

29-
int bcm_phy_read_exp(struct phy_device *phydev, u16 reg)
41+
int __bcm_phy_read_exp(struct phy_device *phydev, u16 reg)
3042
{
3143
int val;
3244

33-
val = phy_write(phydev, MII_BCM54XX_EXP_SEL, reg);
45+
val = __phy_write(phydev, MII_BCM54XX_EXP_SEL, reg);
3446
if (val < 0)
3547
return val;
3648

37-
val = phy_read(phydev, MII_BCM54XX_EXP_DATA);
49+
val = __phy_read(phydev, MII_BCM54XX_EXP_DATA);
3850

3951
/* Restore default value. It's O.K. if this write fails. */
40-
phy_write(phydev, MII_BCM54XX_EXP_SEL, 0);
52+
__phy_write(phydev, MII_BCM54XX_EXP_SEL, 0);
4153

4254
return val;
4355
}
56+
EXPORT_SYMBOL_GPL(__bcm_phy_read_exp);
57+
58+
int bcm_phy_read_exp(struct phy_device *phydev, u16 reg)
59+
{
60+
int rc;
61+
62+
phy_lock_mdio_bus(phydev);
63+
rc = __bcm_phy_read_exp(phydev, reg);
64+
phy_unlock_mdio_bus(phydev);
65+
66+
return rc;
67+
}
4468
EXPORT_SYMBOL_GPL(bcm_phy_read_exp);
4569

4670
int bcm54xx_auxctl_read(struct phy_device *phydev, u16 regnum)

drivers/net/phy/bcm-phy-lib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#define AFE_HPF_TRIM_OTHERS MISC_ADDR(0x3a, 0)
2828

2929

30+
int __bcm_phy_write_exp(struct phy_device *phydev, u16 reg, u16 val);
31+
int __bcm_phy_read_exp(struct phy_device *phydev, u16 reg);
3032
int bcm_phy_write_exp(struct phy_device *phydev, u16 reg, u16 val);
3133
int bcm_phy_read_exp(struct phy_device *phydev, u16 reg);
3234

0 commit comments

Comments
 (0)