Skip to contentSkip to conversation

Broadcom PTP PHY support

PATCH Superseded Jonathan Lemon 3 participants 6 messages May 6, 2022 – May 18, 2022

Subsystems (4)

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v4 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.

v3->v4:
Squash bcm-phy-lib.h and broadcom.c changes into one patch Reorder so the main patch shows up first.

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 (2):
net: phy: broadcom: Add PTP support for some Broadcom PHYs.
net: phy: broadcom: Add Broadcom PTP hooks to bcm-phy-lib

 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 · 18 lines
2.34.3


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

-- 
2.31.1
#1 lore raw

PATCH v4 1/2 net: phy: broadcom: Add PTP support for some Broadcom PHYs.

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.34.3
maintainer
#2 lore raw

Re: [PATCH net-next v4 1/2] net: phy: broadcom: Add PTP support for some Broadcom PHYs.

Quoted 1 line · On Fri, 6 May 2022 15:42:09 -0700 Jonathan Lemon wrote:

+struct bcm_ptp_private *bcm_ptp_probe(struct phy_device *phydev)

The prototype for probe and init needs to get added in patch 1:

drivers/net/phy/bcm-phy-ptp.c:803:6: warning: no previous prototype for function 'bcm_ptp_config_init' [-Wmissing-prototypes] void bcm_ptp_config_init(struct phy_device *phydev)

     ^
drivers/net/phy/bcm-phy-ptp.c:839:25: warning: no previous prototype for function 'bcm_ptp_probe' [-Wmissing-prototypes]
struct bcm_ptp_private *bcm_ptp_probe(struct phy_device *phydev)
                        ^
#3 lore raw

PATCH v4 2/2 net: phy: broadcom: Add Broadcom PTP hooks to bcm-phy-lib

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 driver supports PTP for the specified PHY.

Add the bcm_ptp_probe() and bcm_ptp_config_init() API functions to the bcm-phy library.

---
 drivers/net/phy/bcm-phy-lib.h | 14 ++++++++++++++
 drivers/net/phy/broadcom.c    | 23 +++++++++++++++++++----
 2 files changed, 33 insertions(+), 4 deletions(-)
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 */
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.34.3
#4 lore raw
In reply to Jonathan Lemon
Quoted 7 lines · Jonathan Lemon

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.

Jonathan, any chance you could repost this before net-next closes? Thanks

Signature · 1 line
Florian
#5 lore raw
Quoted 10 lines · Florian Fainelli
Quoted 7 lines · Jonathan Lemon

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.

Jonathan, any chance you could repost this before net-next closes? Thanks

Sure, let me rebuild today and submit.
—
Jonathan