From: Wei Fang The NETC Switch does not have its own time registers and must obtain the current PTP time from the NETC Timer bound to it. Since the two are separate PCIe functions with independent drivers, add netc_timer_get_current_time() to the Timer driver and export it via EXPORT_SYMBOL_GPL(). The function takes the Timer's pci_dev pointer, acquires the per-device spinlock to protect against concurrent register access, and reads TMR_CUR_TIME via netc_timer_cur_time_read(). It returns 0 if the Timer driver has not yet probed or has already been removed, allowing the caller to handle the unavailable case gracefully. Declare the function in include/linux/fsl/netc_global.h guarded by CONFIG_PTP_NETC_V4_TIMER, with a stub returning 0 for the disabled case, so the Switch driver can call it unconditionally without introducing a hard dependency on the Timer driver. Signed-off-by: Wei Fang --- drivers/ptp/ptp_netc.c | 17 +++++++++++++++++ include/linux/fsl/netc_global.h | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/ptp/ptp_netc.c b/drivers/ptp/ptp_netc.c index 6fd62e708fdd..f2b77bd5af01 100644 --- a/drivers/ptp/ptp_netc.c +++ b/drivers/ptp/ptp_netc.c @@ -165,6 +165,23 @@ static u64 netc_timer_cur_time_read(struct netc_timer *priv) return netc_timer_rd64(priv, NETC_TMR_CUR_TIME_L); } +u64 netc_timer_get_current_time(struct pci_dev *pdev) +{ + struct netc_timer *priv = pci_get_drvdata(pdev); + unsigned long flags; + u64 cur_time; + + if (!priv) + return 0; + + spin_lock_irqsave(&priv->lock, flags); + cur_time = netc_timer_cur_time_read(priv); + spin_unlock_irqrestore(&priv->lock, flags); + + return cur_time; +} +EXPORT_SYMBOL_GPL(netc_timer_get_current_time); + static void netc_timer_alarm_write(struct netc_timer *priv, u64 alarm, int index) { diff --git a/include/linux/fsl/netc_global.h b/include/linux/fsl/netc_global.h index 5b8ff528d369..91441cb35bc2 100644 --- a/include/linux/fsl/netc_global.h +++ b/include/linux/fsl/netc_global.h @@ -22,4 +22,13 @@ static inline u64 netc_read64(void __iomem *reg) return ioread64(reg); } +#if IS_ENABLED(CONFIG_PTP_NETC_V4_TIMER) +u64 netc_timer_get_current_time(struct pci_dev *timer_dev); +#else +static inline u64 netc_timer_get_current_time(struct pci_dev *timer_dev) +{ + return 0; +} +#endif + #endif -- 2.34.1