Skip to contentSkip to conversation

add phy shared storage

PATCH In review Michael Walle 2 participants 5 messages May 6, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 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 v2:
- restore page to standard after reading the base address in the mscc driver, thanks Antoine.

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
#1 lore raw

PATCH v3 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
index 3e79b96fa344..255fdfcc13a6 100644
@@ -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
#2 lore raw

PATCH v3 2/3 net: phy: bcm54140: use phy_package_shared

In reply to Michael Walle

Use 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
index 400d7c3c405a..9ef37a3bc2bb 100644
@@ -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
#3 lore raw

PATCH v3 3/3 net: phy: mscc: use phy_package_shared

In reply to Michael Walle

Use 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, 32 insertions(+), 70 deletions(-)
drivers/net/phy/mscc/mscc.h +0 -1
index 030bf8b600df..acdd8ee61a39 100644
@@ -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 +32 -69

202 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer
#4 lore raw
In reply to Michael Walle

From: Michael Walle <[email protected]>
Date: Wed, 6 May 2020 16:53:12 +0200

Quoted 13 lines

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 v2:
- restore page to standard after reading the base address in the mscc driver, thanks Antoine.

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

Quoted 5 lines

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.

Series applied, thank you.