1 From 6709752e7233afd929a130ac4f3645348be94c1f Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Tue, 2 Jan 2018 10:58:37 +0000
4 Subject: [PATCH 294/454] net: phy: add unlocked accessors
6 commit 788f9933db6172801336d0ae2dec5bdc7525389f upstream.
8 Add unlocked versions of the bus accessors, which allows access to the
9 bus with all the tracing. These accessors validate that the bus mutex
10 is held, which is a basic requirement for all mii bus accesses.
12 Also added is a read-modify-write unlocked accessor with the same
15 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
16 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
17 Signed-off-by: David S. Miller <davem@davemloft.net>
19 drivers/net/phy/phy-core.c | 25 +++++++++++++++++++++++++
20 include/linux/phy.h | 28 ++++++++++++++++++++++++++++
21 2 files changed, 53 insertions(+)
23 --- a/drivers/net/phy/phy-core.c
24 +++ b/drivers/net/phy/phy-core.c
25 @@ -280,3 +280,28 @@ int phy_write_mmd(struct phy_device *phy
28 EXPORT_SYMBOL(phy_write_mmd);
31 + * __phy_modify() - Convenience function for modifying a PHY register
32 + * @phydev: a pointer to a &struct phy_device
33 + * @regnum: register number
34 + * @mask: bit mask of bits to clear
35 + * @set: bit mask of bits to set
37 + * Unlocked helper function which allows a PHY register to be modified as
38 + * new register value = (old register value & mask) | set
40 +int __phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set)
44 + ret = __phy_read(phydev, regnum);
46 + res = __phy_write(phydev, regnum, (ret & ~mask) | set);
53 +EXPORT_SYMBOL_GPL(__phy_modify);
54 --- a/include/linux/phy.h
55 +++ b/include/linux/phy.h
56 @@ -726,6 +726,18 @@ static inline int phy_read(struct phy_de
60 + * __phy_read - convenience function for reading a given PHY register
61 + * @phydev: the phy_device struct
62 + * @regnum: register number to read
64 + * The caller must have taken the MDIO bus lock.
66 +static inline int __phy_read(struct phy_device *phydev, u32 regnum)
68 + return __mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);
72 * phy_write - Convenience function for writing a given PHY register
73 * @phydev: the phy_device struct
74 * @regnum: register number to write
75 @@ -741,6 +753,22 @@ static inline int phy_write(struct phy_d
79 + * __phy_write - Convenience function for writing a given PHY register
80 + * @phydev: the phy_device struct
81 + * @regnum: register number to write
82 + * @val: value to write to @regnum
84 + * The caller must have taken the MDIO bus lock.
86 +static inline int __phy_write(struct phy_device *phydev, u32 regnum, u16 val)
88 + return __mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum,
92 +int __phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set);
95 * phy_interrupt_is_valid - Convenience function for testing a given PHY irq
96 * @phydev: the phy_device struct