Broadcom PTP PHY support
Subsystems (4)
v2 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.
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 PTP support for some Broadcom PHYs.
net: phy: broadcom: Add Broadcom PTP hooks to bcm-phy-lib
net: phy: broadcom: Hook up the PTP PHY functions
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
PATCH v2 1/3 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
@@ -101,6 +101,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
@@ -46,6 +46,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
Andrew Lunn
maintainerRe: [PATCH net-next v2 1/3] net: phy: broadcom: Add PTP support for some Broadcom PHYs.
Quoted 11 lines
drivers/net/phy/bcm-phy-ptp.c new file +11
-0+struct bcm_ptp_private *bcm_ptp_probe (struct phy_device *phydev) +{ +struct bcm_ptp_private *priv; +struct ptp_clock *clock; + +switch (BRCM_PHY_MODEL (phydev)) { +case PHY_ID_BCM54210E : +break ; +default : +return NULL ; + }
drivers/net/phy/bcm-phy-ptp.c line 859
Quoted 10 lines
drivers/net/phy/bcm-phy-ptp.c new file +10
-0+ + priv =devm_kzalloc (&phydev->mdio.dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return ERR_PTR (-ENOMEM ); + + priv->ptp_info = bcm_ptp_clock_info; + + clock =ptp_clock_register (&priv->ptp_info, &phydev->mdio.dev); +if (IS_ERR (clock)) +return (void *)clock;
nit-pick:
You could use ERR_CAST() here.
Andrew
Paolo Abeni
maintainerRe: [PATCH net-next v2 1/3] net: phy: broadcom: Add PTP support for some Broadcom PHYs.
In reply to Jonathan LemonHello,
Quoted 5 lines · 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.
Signed-off-by Jonathan Lemon <[email protected]>
Another nit-pick, sorry ;)
This introduces a few compiler warnings for undeclared functions (bcm_ptp_config_init and bcm_ptp_probe), see:
https://patchwork.hopto.org/static/nipa/637209/12833026/build_allmodconfig_warn/summary
The warnings could be addressed e.g. re-ordering patch 1/3 and 2/3.
Thanks!
Paolo
PATCH v2 2/3 net: phy: broadcom: Add Broadcom PTP hooks to bcm-phy-lib
In reply to Jonathan LemonAdd 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
@@ -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
PATCH v2 3/3 net: phy: broadcom: Hook up the PTP PHY functions
In reply to Jonathan LemonAdd '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
@@ -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