add phy shared storage
Subsystems (4)
v2 cover add phy shared storage
Introduce the concept of a shared PHY storage which can be used by some QSGMII PHYs to ease initialization and access to global per-package registers.
Changes since v1:
- fix typos and add a comment, thanks Florian.
- check for "addr < 0" in phy_package_join()
- remove multiple blank lines and make "checkpatch.pl --strict" happy
Changes since RFC:
- check return code of kzalloc()
- fix local variable ordering (reverse christmas tree)
- add priv_size argument to phy_package_join()
- add Tested-by tag, thanks Vladimir.
Michael Walle (3):
net: phy: add concept of shared storage for PHYs
net: phy: bcm54140: use phy_package_shared
net: phy: mscc: use phy_package_shared
drivers/net/phy/bcm54140.c | 57 +++---------- drivers/net/phy/mdio_bus.c | 1 + drivers/net/phy/mscc/mscc.h | 1 - drivers/net/phy/mscc/mscc_main.c | 101 +++++++--------------- drivers/net/phy/phy_device.c | 138 +++++++++++++++++++++++++++++++ include/linux/phy.h | 90 ++++++++++++++++++++ 6 files changed, 271 insertions(+), 117 deletions(-)
Signature · 1 line
2.20.1
PATCH v2 1/3 net: phy: add concept of shared storage for PHYs
There are packages which contain multiple PHY devices, eg. a quad PHY transceiver. Provide functions to allocate and free shared storage.
Usually, a quad PHY contains global registers, which don't belong to any PHY. Provide convenience functions to access these registers.
--- drivers/net/phy/mdio_bus.c | 1 + drivers/net/phy/phy_device.c | 138 +++++++++++++++++++++++++++++++++++ include/linux/phy.h | 89 ++++++++++++++++++++++ 3 files changed, 228 insertions(+)
drivers/net/phy/mdio_bus.c +1 -0
@@ -614,6 +614,7 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner) }mutex_init (&bus->mdio_lock); +mutex_init (&bus->shared_lock);/* de-assert bus level PHY GPIO reset */ gpiod =devm_gpiod_get_optional (&bus->dev,"reset" ,GPIOD_OUT_LOW );
drivers/net/phy/phy_device.c +138 -0
144 lines not on this page · raw message
include/linux/phy.h +89 -0
125 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH net-next v2 1/3] net: phy: add concept of shared storage for PHYs
Quoted 7 lines · Michael Walle
There are packages which contain multiple PHY devices, eg. a quad PHY transceiver. Provide functions to allocate and free shared storage.
Usually, a quad PHY contains global registers, which don't belong to any PHY. Provide convenience functions to access these registers.
Signed-off-by Michael Walle <[email protected]>
Andrew
Re: [PATCH net-next v2 1/3] net: phy: add concept of shared storage for PHYs
In reply to Michael WalleQuoted 7 lines · Michael Walle
There are packages which contain multiple PHY devices, eg. a quad PHY transceiver. Provide functions to allocate and free shared storage.
Usually, a quad PHY contains global registers, which don't belong to any PHY. Provide convenience functions to access these registers.
Signed-off-by Michael Walle <[email protected]>
Signature · 1 line
Florian
PATCH v2 2/3 net: phy: bcm54140: use phy_package_shared
In reply to Michael WalleUse the new phy_package_shared common storage to ease the package initialization and to access the global registers.
--- drivers/net/phy/bcm54140.c | 57 ++++++++------------------------------ 1 file changed, 11 insertions(+), 46 deletions(-)
drivers/net/phy/bcm54140.c +11 -46
@@ -132,7 +132,6 @@ struct bcm54140_priv {int port;int base_addr;#if IS_ENABLED (CONFIG_HWMON ) -bool pkg_init;/* protect the alarm bits */ struct mutex alarm_lock;u16 alarm;
@@ -407,36 +406,6 @@ static int bcm54140_enable_monitoring(struct phy_device *phydev)return bcm_phy_modify_rdb (phydev,BCM54140_RDB_MON_CTRL , mask, set); } -/* Check if one PHY has already done the init of the parts common to all PHYs -* in the Quad PHY package. -*/ -static bool bcm54140_is_pkg_init (struct phy_device *phydev) -{ -struct bcm54140_priv *priv = phydev->priv; -struct mii_bus *bus = phydev->mdio.bus; -int base_addr = priv->base_addr; -struct phy_device *phy; -int i; - -/* Quad PHY */ -for (i =0 ; i <4 ; i++) { - phy =mdiobus_get_phy (bus, base_addr + i); -if (!phy) -continue ; - -if ((phy->phy_id & phydev->drv->phy_id_mask) != - (phydev->drv->phy_id & phydev->drv->phy_id_mask)) -continue ; - - priv = phy->priv; - -if (priv && priv->pkg_init) -return true; - } - -return false; -} -static int bcm54140_probe_once (struct phy_device *phydev) {struct device *hwmon;
@@ -457,38 +426,34 @@ static int bcm54140_probe_once(struct phy_device *phydev)static int bcm54140_base_read_rdb (struct phy_device *phydev,u16 rdb) { -struct bcm54140_priv *priv = phydev->priv; -struct mii_bus *bus = phydev->mdio.bus;int ret; -mutex_lock (&bus->mdio_lock); - ret =__mdiobus_write (bus, priv->base_addr,MII_BCM54XX_RDB_ADDR , rdb); +phy_lock_mdio_bus (phydev); + ret =__phy_package_write (phydev,MII_BCM54XX_RDB_ADDR , rdb);if (ret <0 ) goto out; - ret =__mdiobus_read (bus, priv->base_addr,MII_BCM54XX_RDB_DATA ); + ret =__phy_package_read (phydev,MII_BCM54XX_RDB_DATA ); out: -mutex_unlock (&bus->mdio_lock); +phy_unlock_mdio_bus (phydev);return ret; }static int bcm54140_base_write_rdb (struct phy_device *phydev,u16 rdb,u16 val) { -struct bcm54140_priv *priv = phydev->priv; -struct mii_bus *bus = phydev->mdio.bus;int ret; -mutex_lock (&bus->mdio_lock); - ret =__mdiobus_write (bus, priv->base_addr,MII_BCM54XX_RDB_ADDR , rdb); +phy_lock_mdio_bus (phydev); + ret =__phy_package_write (phydev,MII_BCM54XX_RDB_ADDR , rdb);if (ret <0 ) goto out; - ret =__mdiobus_write (bus, priv->base_addr,MII_BCM54XX_RDB_DATA , val); + ret =__phy_package_write (phydev,MII_BCM54XX_RDB_DATA , val); out: -mutex_unlock (&bus->mdio_lock); +phy_unlock_mdio_bus (phydev);return ret; }
@@ -618,16 +583,16 @@ static int bcm54140_probe(struct phy_device *phydev)if (ret)return ret; +devm_phy_package_join (&phydev->mdio.dev, phydev, priv->base_addr,0 ); +#if IS_ENABLED (CONFIG_HWMON )mutex_init (&priv->alarm_lock); -if (!bcm54140_is_pkg_init (phydev)) { +if (phy_package_init_once (phydev)) { ret =bcm54140_probe_once (phydev);if (ret)return ret; } - - priv->pkg_init = true;#endif phydev_dbg(phydev, "probed (port %d, base PHY address %d)\n",
Signature · 1 line
2.20.1
Re: [PATCH net-next v2 2/3] net: phy: bcm54140: use phy_package_shared
Quoted 4 lines · Michael Walle
Use the new
phy_package_sharedcommon storage to ease the package initialization and to access the global registers.Signed-off-by Michael Walle <[email protected]>
Andrew
Re: [PATCH net-next v2 2/3] net: phy: bcm54140: use phy_package_shared
In reply to Michael WalleQuoted 4 lines · Michael Walle
Use the new
phy_package_sharedcommon storage to ease the package initialization and to access the global registers.Signed-off-by Michael Walle <[email protected]>
Signature · 1 line
Florian
PATCH v2 3/3 net: phy: mscc: use phy_package_shared
In reply to Michael WalleUse the new phy_package_shared common storage to ease the package initialization and to access the global registers.
--- drivers/net/phy/mscc/mscc.h | 1 - drivers/net/phy/mscc/mscc_main.c | 101 ++++++++++--------------------- 2 files changed, 31 insertions(+), 71 deletions(-)
drivers/net/phy/mscc/mscc.h +0 -1
@@ -353,7 +353,6 @@ struct vsc8531_private {const struct vsc85xx_hw_stat *hw_stats;u64 *stats;int nstats; -bool pkg_init;/* For multiple port PHYs; the MDIO address of the base PHY in the * package. */
drivers/net/phy/mscc/mscc_main.c +31 -70
201 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH net-next v2 3/3] net: phy: mscc: use phy_package_shared
Quoted 5 lines · Michael Walle
Use the new
phy_package_sharedcommon storage to ease the package initialization and to access the global registers.Signed-off-by Michael Walle <[email protected]>Tested-by Vladimir Oltean <[email protected]>
Andrew
Re: [PATCH net-next v2 3/3] net: phy: mscc: use phy_package_shared
In reply to Michael WalleQuoted 5 lines · Michael Walle
Use the new
phy_package_sharedcommon storage to ease the package initialization and to access the global registers.Signed-off-by Michael Walle <[email protected]>Tested-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Re: [PATCH net-next v2 3/3] net: phy: mscc: use phy_package_shared
In reply to Michael WalleHello Michael,
Quoting Michael Walle (2020-05-04 23:31:36)
Quoted 32 lines
drivers/net/phy/mscc/mscc_main.c +4
-21-static bool vsc8584_is_pkg_init (struct phy_device *phydev,bool reversed) +static void vsc8584_get_base_addr (struct phy_device *phydev) { -struct mii_bus *bus = phydev->mdio.bus; -struct vsc8531_private *vsc8531; -struct phy_device *phy; -int i, addr; - -/* VSC8584 is a Quad PHY */ -for (i =0 ; i <4 ; i++) { - vsc8531 = phydev->priv; - -if (reversed) - addr = vsc8531->base_addr - i; -else - addr = vsc8531->base_addr + i; - - phy =mdiobus_get_phy (bus, addr); -if (!phy) -continue ; +struct vsc8531_private *vsc8531 = phydev->priv; +u16 val, addr; -if ((phy->phy_id & phydev->drv->phy_id_mask) != - (phydev->drv->phy_id & phydev->drv->phy_id_mask)) -continue ; +mutex_lock (&phydev->mdio.bus->mdio_lock);
drivers/net/phy/mscc/mscc_main.c static int vsc8584_config_pre_init(struct phy_device *phydev) · line 1297
Quoted 10 lines
drivers/net/phy/mscc/mscc_main.c +4
-4+__phy_write (phydev,MSCC_EXT_PAGE_ACCESS ,MSCC_PHY_PAGE_EXTENDED ); - vsc8531 = phy->priv; + addr =__phy_read (phydev,MSCC_PHY_EXT_PHY_CNTL_4 ); + addr >>=PHY_CNTL_4_ADDR_POS ; -if (vsc8531 && vsc8531->pkg_init) -return true; - } + val =__phy_read (phydev,MSCC_PHY_ACTIPHY_CNTL );
You should restore the page to MSCC_PHY_PAGE_STANDARD here.
drivers/net/phy/mscc/mscc_main.c static int vsc8584_config_pre_init(struct phy_device *phydev) · line 1304
Quoted 8 lines
drivers/net/phy/mscc/mscc_main.c +5
-1+mutex_unlock (&phydev->mdio.bus->mdio_lock); -return false; +if (val &PHY_ADDR_REVERSED ) + vsc8531->base_addr = phydev->mdio.addr + addr; +else + vsc8531->base_addr = phydev->mdio.addr - addr; }
Thanks for the series!
Antoine
Signature · 3 lines
Antoine Ténart, Bootlin Embedded Linux and Kernel engineering https://bootlin.com