net: fec: fix some PTP related issues
Wei Fang
maintainercover net: fec: fix some PTP related issues
There are some issues which were introduced by the commit 350749b909bf ("net: fec: Add support for periodic output signal of PPS"). See each patch for more details.
Wei Fang (4):
net: fec: cancel perout_timer when PEROUT is disabled
net: fec: do not update PEROUT if it is enabled
net: fec: do not allow enabling PPS and PEROUT simultaneously
net: fec: do not register PPS event for PEROUT
drivers/net/ethernet/freescale/fec.h | 1 + drivers/net/ethernet/freescale/fec_ptp.c | 64 +++++++++++++++++++----- 2 files changed, 53 insertions(+), 12 deletions(-)
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH 1/4 net: fec: cancel perout_timer when PEROUT is disabled
The PEROUT allows the user to set a specified future time to output the periodic signal. If the future time is far from the current time, the FEC driver will use hrtimer to configure PEROUT one second before the future time. However, the hrtimer will not be canceled if the PEROUT is disabled before the hrtimer expires. So the PEROUT will be configured when the hrtimer expires, which is not as expected. Therefore, cancel the hrtimer in fec_ptp_pps_disable() to fix this issue.
--- drivers/net/ethernet/freescale/fec_ptp.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/freescale/fec_ptp.c +2 -0
@@ -497,6 +497,8 @@ static int fec_ptp_pps_disable(struct fec_enet_private *fep, uint channel) {unsigned long flags; +hrtimer_cancel (&fep->perout_timer); +spin_lock_irqsave (&fep->tmreg_lock, flags);writel (0 , fep->hwp +FEC_TCSR (channel));spin_unlock_irqrestore (&fep->tmreg_lock, flags);
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH 2/4 net: fec: do not update PEROUT if it is enabled
In reply to Wei FangIf the previously set PEROUT is already active, updating it will cause the new PEROUT to start immediately instead of at the specified time. This is because fep->reload_period is updated whithout check whether the PEROUT is enabled, and the old PEROUT is not disabled. Therefore, the pulse period will be updated immediately in the pulse interrupt handler fec_pps_interrupt().
Currently, the driver does not support directly updating PEROUT and it will make the logic be more complicated. To fix the current issue, add a check before enabling the PEROUT, the driver will return an error if PEROUT is enabled. If users wants to update a new PEROUT, they should disable the old PEROUT first.
--- drivers/net/ethernet/freescale/fec.h | 1 + drivers/net/ethernet/freescale/fec_ptp.c | 43 ++++++++++++++++++------ 2 files changed, 34 insertions(+), 10 deletions(-)
drivers/net/ethernet/freescale/fec.h +1 -0
@@ -687,6 +687,7 @@ struct fec_enet_private {unsigned int reload_period;int pps_enable;unsigned int next_counter; +bool perout_enable;struct hrtimer perout_timer;u64 perout_stime;
drivers/net/ethernet/freescale/fec_ptp.c +33 -10
81 lines not on this page · raw message
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH 3/4 net: fec: do not allow enabling PPS and PEROUT simultaneously
In reply to Wei FangIn the current driver, PPS and PEROUT use the same channel to generate the events, so they cannot be enabled at the same time. Otherwise, the later configuration will overwrite the earlier configuration. Therefore, when configuring PPS, the driver will check whether PEROUT is enabled. Similarly, when configuring PEROUT, the driver will check whether PPS is enabled.
--- drivers/net/ethernet/freescale/fec_ptp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/net/ethernet/freescale/fec_ptp.c +12 -0
@@ -128,6 +128,12 @@ static int fec_ptp_enable_pps(struct fec_enet_private *fep, uint enable)spin_lock_irqsave (&fep->tmreg_lock, flags); +if (fep->perout_enable) { +spin_unlock_irqrestore (&fep->tmreg_lock, flags); +dev_err (&fep->pdev->dev,"PEROUT is running" ); +return -EBUSY ; + } +if (fep->pps_enable == enable) {spin_unlock_irqrestore (&fep->tmreg_lock, flags);return 0 ;
@@ -571,6 +577,12 @@ static int fec_ptp_enable(struct ptp_clock_info *ptp, }spin_lock_irqsave (&fep->tmreg_lock, flags); +if (fep->pps_enable) { +dev_err (&fep->pdev->dev,"PPS is running" ); + ret = -EBUSY ; + goto unlock; + } +if (fep->perout_enable) {dev_err (&fep->pdev->dev,"PEROUT has been enabled\n" );
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH 4/4 net: fec: do not register PPS event for PEROUT
In reply to Wei FangThere are currently two situations that can trigger the PTP interrupt, one is the PPS event, the other is the PEROUT event. However, the irq handler fec_pps_interrupt() does not check the irq event type and directly registers a PPS event into the system, but the event may be a PEROUT event. This is incorrect because PEROUT is an output signal, while PPS is the input of the kernel PPS system. Therefore, add a check for the event type, if pps_enable is true, it means that the current event is a PPS event, and then the PPS event is registered.
--- drivers/net/ethernet/freescale/fec_ptp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/ethernet/freescale/fec_ptp.c +5 -2
@@ -718,8 +718,11 @@ static irqreturn_t fec_pps_interrupt(int irq, void *dev_id) fep->next_counter = (fep->next_counter + fep->reload_period) & fep->cc.mask; - event.type =PTP_CLOCK_PPS ; -ptp_clock_event (fep->ptp_clock, &event); +if (fep->pps_enable) { + event.type =PTP_CLOCK_PPS ; +ptp_clock_event (fep->ptp_clock, &event); + } +return IRQ_HANDLED ; }
Signature · 1 line
2.34.1
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Tue, 25 Nov 2025 16:52:06 +0800 you wrote:
There are some issues which were introduced by the commit
350749b909bf("net: fec: Add support for periodic output signal of PPS"). See each patch for more details.Wei Fang (4):
net: fec: cancelperout_timerwhen PEROUT is disabled
net: fec: do not update PEROUT if it is enabled
net: fec: do not allow enabling PPS and PEROUT simultaneously
net: fec: do not register PPS event for PEROUT[...]
Here is the summary with links:
- [net,1/4] net: fec: cancel perout_timer when PEROUT is disabled
https://git.kernel.org/netdev/net/c/50caa744689e - [net,2/4] net: fec: do not update PEROUT if it is enabled https://git.kernel.org/netdev/net/c/e97faa0c20ea - [net,3/4] net: fec: do not allow enabling PPS and PEROUT simultaneously https://git.kernel.org/netdev/net/c/c0a1f3d7e128 - [net,4/4] net: fec: do not register PPS event for PEROUT https://git.kernel.org/netdev/net/c/9a060d0fac9e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html