Skip to contentSkip to conversation

Broadcom PTP PHY support

PATCH Superseded Jonathan Lemon 2 participants 6 messages May 4, 2022 – May 6, 2022

Subsystems (4)

v3 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v3 cover Broadcom PTP PHY support

This adds PTP support for the Broadcom PHY BCM54210E (and the specific variant BCM54213PE that the rpi-5.15 branch uses).

This has only been tested on the RPI CM4, which has one port.

There are other Broadcom chips which may benefit from using the same framework here, although with different register sets.

v2->v3:
Rearrange patches so they apply in order
Use ERR_CAST

v1->v2:
Squash Kconfig into main patch
Move config checks into bcm-phy-lib.h
Fix delta_ns calculations in adjtime
Uppercase mode selector macros
Only use NSE_INIT when necessary
Remove the inserted Broadcom RX timestamp from the PTP packet Add perout (chip generated) and fsync out (timer generated) Remove PHY_ID_BCM54213PE special casing (needed for rpi tree)

Thanks to Lasse Johnsen <[email protected]> for pointing out that the chip's periodic output generation isn't sync'd to any time base.

Jonathan Lemon (3):
net: phy: broadcom: Add Broadcom PTP hooks to bcm-phy-lib
net: phy: broadcom: Hook up the PTP PHY functions
net: phy: broadcom: Add PTP support for some Broadcom PHYs.

 drivers/net/phy/Kconfig       |  10 +
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/bcm-phy-lib.h |  14 +
 drivers/net/phy/bcm-phy-ptp.c | 869 ++++++++++++++++++++++++++++++++++
 drivers/net/phy/broadcom.c    |  23 +-
 5 files changed, 913 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/phy/bcm-phy-ptp.c
Signature · 1 line
2.31.1
#1 lore raw

PATCH v3 1/3 net: phy: broadcom: Add Broadcom PTP hooks to bcm-phy-lib

Add the public bcm_ptp_probe() and bcm_ptp_config_init() functions to the bcm-phy library. The PTP functions are contained in a separate file for clarity, and also to simplify the PTP clock dependencies.

---
 drivers/net/phy/bcm-phy-lib.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/net/phy/bcm-phy-lib.h +14 -0
index c3842f87c33b..c2cc3c2766a1 100644
@@ -87,4 +87,18 @@ int bcm_phy_cable_test_start_rdb(struct phy_device *phydev);
 int bcm_phy_cable_test_start(struct phy_device *phydev);
 int bcm_phy_cable_test_get_status(struct phy_device *phydev, bool *finished);
 
+#if IS_ENABLED(CONFIG_BCM_NET_PHYPTP)
+struct bcm_ptp_private *bcm_ptp_probe(struct phy_device *phydev);
+void bcm_ptp_config_init(struct phy_device *phydev);
+#else
+static inline struct bcm_ptp_private *bcm_ptp_probe(struct phy_device *phydev)
+{
+	return NULL;
+}
+
+static inline void bcm_ptp_config_init(struct phy_device *phydev)
+{
+}
+#endif
+
 #endif /* _LINUX_BCM_PHY_LIB_H */
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH net-next v3 1/3] net: phy: broadcom: Add Broadcom PTP hooks to bcm-phy-lib

Quoted 5 lines · Jonathan Lemon

Add the public bcm_ptp_probe() and bcm_ptp_config_init() functions to the bcm-phy library. The PTP functions are contained in a separate file for clarity, and also to simplify the PTP clock dependencies.

This could really be squashed into the next patch since you do not introduce the ability to build that code until patch #3.

I would also re-order patches #2 and #3 thus making it ultimately a 2 patch series only.

Signature · 1 line
Florian
#3 lore raw

Re: [PATCH net-next v3 1/3] net: phy: broadcom: Add Broadcom PTP hooks to bcm-phy-lib

Quoted 5 lines · Florian Fainelli
Quoted 4 lines · Jonathan Lemon

Add the public bcm_ptp_probe() and bcm_ptp_config_init() functions to the bcm-phy library. The PTP functions are contained in a separate file for clarity, and also to simplify the PTP clock dependencies.

Quoted 7 lines
Quoted 1 line

This could really be squashed into the next patch since you do not introduce the ability to build that code until patch #3.

I would also re-order patches #2 and #3 thus making it ultimately a 2 patch series only.

Okay, squash #1 and #2 into one patch, then swap ordering so the main patch comes first.

Will repost in a bit.

Signature · 1 line
Jonathan
#4 lore raw

PATCH v3 2/3 net: phy: broadcom: Hook up the PTP PHY functions

In reply to Jonathan Lemon

Add 'struct bcm_ptp_private' to bcm54xx_phy_priv which points to an optional PTP structure attached to the PHY. This is allocated on probe, if PHY PTP support is configured, and if the PHY has a PTP supported by the driver.

---
 drivers/net/phy/broadcom.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/net/phy/broadcom.c +19 -4
index e36809aa6d30..a7722599b5f9 100644
@@ -27,6 +27,11 @@ MODULE_DESCRIPTION("Broadcom PHY driver");
 MODULE_AUTHOR("Maciej W. Rozycki");
 MODULE_LICENSE("GPL");
 
+struct bcm54xx_phy_priv {
+	u64	*stats;
+	struct bcm_ptp_private *ptp;
+};
+
 static int bcm54xx_config_clock_delay(struct phy_device *phydev)
 {
 	int rc, val;
@@ -313,6 +318,14 @@ static void bcm54xx_adjust_rxrefclk(struct phy_device *phydev)
 		bcm_phy_write_shadow(phydev, BCM54XX_SHD_APD, val);
 }
 
+static void bcm54xx_ptp_config_init(struct phy_device *phydev)
+{
+	struct bcm54xx_phy_priv *priv = phydev->priv;
+
+	if (priv->ptp)
+		bcm_ptp_config_init(phydev);
+}
+
 static int bcm54xx_config_init(struct phy_device *phydev)
 {
 	int reg, err, val;
@@ -390,6 +403,8 @@ static int bcm54xx_config_init(struct phy_device *phydev)
 		bcm_phy_write_exp(phydev, BCM_EXP_MULTICOLOR, val);
 	}
 
+	bcm54xx_ptp_config_init(phydev);
+
 	return 0;
 }
 
@@ -741,10 +756,6 @@ static irqreturn_t brcm_fet_handle_interrupt(struct phy_device *phydev)
 	return IRQ_HANDLED;
 }
 
-struct bcm54xx_phy_priv {
-	u64	*stats;
-};
-
 static int bcm54xx_phy_probe(struct phy_device *phydev)
 {
 	struct bcm54xx_phy_priv *priv;
@@ -761,6 +772,10 @@ static int bcm54xx_phy_probe(struct phy_device *phydev)
 	if (!priv->stats)
 		return -ENOMEM;
 
+	priv->ptp = bcm_ptp_probe(phydev);
+	if (IS_ERR(priv->ptp))
+		return PTR_ERR(priv->ptp);
+
 	return 0;
 }
 
Signature · 1 line
2.31.1
#5 lore raw

PATCH v3 3/3 net: phy: broadcom: Add PTP support for some Broadcom PHYs.

In reply to Jonathan Lemon

This adds PTP support for BCM54210E Broadcom PHYs, in particular, the BCM54213PE, as used in the Rasperry PI CM4. It has only been tested on that hardware.

---
 drivers/net/phy/Kconfig       |  10 +
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/bcm-phy-ptp.c | 869 ++++++++++++++++++++++++++++++++++
 3 files changed, 880 insertions(+)
 create mode 100644 drivers/net/phy/bcm-phy-ptp.c
drivers/net/phy/Kconfig +10 -0
index bbbf6c07ea53..67c4d4c2410c 100644
@@ -108,6 +108,16 @@ config BROADCOM_PHY
 	  Currently supports the BCM5411, BCM5421, BCM5461, BCM54616S, BCM5464,
 	  BCM5481, BCM54810 and BCM5482 PHYs.
 
+config BCM_NET_PHYPTP
+	tristate "Broadcom PHY PTP support"
+	depends on NETWORK_PHY_TIMESTAMPING
+	depends on PHYLIB
+	depends on PTP_1588_CLOCK
+	depends on BROADCOM_PHY
+	depends on NET_PTP_CLASSIFY
+	help
+	  Supports PTP timestamping for certain Broadcom PHYs.
+
 config BCM54140_PHY
 	tristate "Broadcom BCM54140 PHY"
 	depends on PHYLIB
drivers/net/phy/Makefile +1 -0
index b82651b57043..1dc14fbdff12 100644
@@ -47,6 +47,7 @@ obj-$(CONFIG_BCM84881_PHY)	+= bcm84881.o
 obj-$(CONFIG_BCM87XX_PHY)	+= bcm87xx.o
 obj-$(CONFIG_BCM_CYGNUS_PHY)	+= bcm-cygnus.o
 obj-$(CONFIG_BCM_NET_PHYLIB)	+= bcm-phy-lib.o
+obj-$(CONFIG_BCM_NET_PHYPTP)	+= bcm-phy-ptp.o
 obj-$(CONFIG_BROADCOM_PHY)	+= broadcom.o
 obj-$(CONFIG_CICADA_PHY)	+= cicada.o
 obj-$(CONFIG_CORTINA_PHY)	+= cortina.o
drivers/net/phy/bcm-phy-ptp.c new file +869 -0

869 lines not on this page · raw message

Signature · 1 line
2.31.1