net: phy: add PHY package locking helpers

The PHY package API provides private data shared by all PHYs in a
package. Drivers are responsible for synchronizing access to this data,
but the API does not provide a lock for that purpose.

Add phy_package_lock() and phy_package_unlock() for drivers to serialize
access to package-private data, including its initialization.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
Link: https://patch.msgid.link/20260811151345.73582-2-xuanqiang.luo@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Xuanqiang Luo
2026-08-11 23:13:42 +08:00
committed by Jakub Kicinski
parent 3da8c3c8b8
commit ebb16fca01
2 changed files with 25 additions and 0 deletions

View File

@@ -52,6 +52,29 @@ void *phy_package_get_priv(struct phy_device *phydev)
}
EXPORT_SYMBOL_GPL(phy_package_get_priv);
/**
* phy_package_lock - acquire the PHY package lock
* @phydev: PHY device that has joined the package
*
* Use this to serialize access to package-private data. Release the lock
* with phy_package_unlock().
*/
void phy_package_lock(struct phy_device *phydev)
{
mutex_lock(&phydev->mdio.bus->shared_lock);
}
EXPORT_SYMBOL_GPL(phy_package_lock);
/**
* phy_package_unlock - release the PHY package lock
* @phydev: PHY device that has joined the package
*/
void phy_package_unlock(struct phy_device *phydev)
{
mutex_unlock(&phydev->mdio.bus->shared_lock);
}
EXPORT_SYMBOL_GPL(phy_package_unlock);
static int phy_package_address(struct phy_device *phydev,
unsigned int addr_offset)
{

View File

@@ -12,6 +12,8 @@ struct mii_bus;
struct device_node *phy_package_get_node(struct phy_device *phydev);
void *phy_package_get_priv(struct phy_device *phydev);
void phy_package_lock(struct phy_device *phydev);
void phy_package_unlock(struct phy_device *phydev);
int __phy_package_read(struct phy_device *phydev, unsigned int addr_offset,
u32 regnum);
int __phy_package_write(struct phy_device *phydev, unsigned int addr_offset,