* [PATCH net-next v3 0/2] net: stmmac: allow generation of flexible PPS relative to MAC time @ 2025-08-27 11:04 Gatien Chevallier 2025-08-27 11:04 ` [PATCH net-next v3 1/2] drivers: net: stmmac: handle start time set in the past for flexible PPS Gatien Chevallier 2025-08-27 11:04 ` [PATCH net-next v3 2/2] ARM: dts: stm32: add missing PTP reference clocks on stm32mp13x SoCs Gatien Chevallier 0 siblings, 2 replies; 7+ messages in thread From: Gatien Chevallier @ 2025-08-27 11:04 UTC (permalink / raw) To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue, Richard Cochran, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: netdev, linux-stm32, linux-arm-kernel, linux-kernel, devicetree, Gatien Chevallier When doing some testing on stm32mp2x platforms(MACv5), I noticed that the command previously used with a MACv4 for genering a PPS signal: echo "0 0 0 1 1" > /sys/class/ptp/ptp0/period did not work. This is because the arguments passed through this command must contain the start time at which the PPS should be generated, relative to the MAC system time. For some reason, a time set in the past seems to work with a MACv4. Because passing such an argument is tedious, consider that any time set in the past is an offset regarding the MAC system time. This way, this does not impact existing scripts and the past time use case is handled. Edit: But maybe that's not important and we can just change the default behavior to this. Example to generate a flexible PPS signal that has a 1s period 3s relative to when the command was entered: echo "0 3 0 1 1" > /sys/class/ptp/ptp0/period Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com> --- Changes in v3: - Fix warning on braces for the switch case. - Link to v2: https://lore.kernel.org/r/20250729-relative_flex_pps-v2-0-3e5f03525c45@foss.st.com Changes in v2: - Drop STMMAC_RELATIVE_FLEX_PPS config switch - Add PTP reference clock in stm32mp13x SoCs - Link to v1: https://lore.kernel.org/r/20250724-relative_flex_pps-v1-0-37ca65773369@foss.st.com --- Gatien Chevallier (2): drivers: net: stmmac: handle start time set in the past for flexible PPS ARM: dts: stm32: add missing PTP reference clocks on stm32mp13x SoCs arch/arm/boot/dts/st/stm32mp131.dtsi | 2 ++ arch/arm/boot/dts/st/stm32mp133.dtsi | 2 ++ drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c | 35 +++++++++++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) --- base-commit: 242041164339594ca019481d54b4f68a7aaff64e change-id: 20250723-relative_flex_pps-faa2fbcaf835 Best regards, -- Gatien Chevallier <gatien.chevallier@foss.st.com> ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net-next v3 1/2] drivers: net: stmmac: handle start time set in the past for flexible PPS 2025-08-27 11:04 [PATCH net-next v3 0/2] net: stmmac: allow generation of flexible PPS relative to MAC time Gatien Chevallier @ 2025-08-27 11:04 ` Gatien Chevallier 2025-08-28 2:31 ` Jakub Kicinski 2025-08-28 9:32 ` kernel test robot 2025-08-27 11:04 ` [PATCH net-next v3 2/2] ARM: dts: stm32: add missing PTP reference clocks on stm32mp13x SoCs Gatien Chevallier 1 sibling, 2 replies; 7+ messages in thread From: Gatien Chevallier @ 2025-08-27 11:04 UTC (permalink / raw) To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue, Richard Cochran, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: netdev, linux-stm32, linux-arm-kernel, linux-kernel, devicetree, Gatien Chevallier In case the time arguments used for flexible PPS signal generation are in the past, consider the arguments to be a time offset relative to the MAC system time. This way, past time use case is handled and it avoids the tedious work of passing an absolute time value for the flexible PPS signal generation while not breaking existing scripts that may rely on this behavior. Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com> --- drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c | 35 +++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c index 3767ba495e78d210b0529ee1754e5331f2dd0a47..0de10a309e1e945fddfcda39a6c388f3dfff7c92 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c @@ -10,6 +10,8 @@ #include "stmmac.h" #include "stmmac_ptp.h" +#define PTP_SAFE_TIME_OFFSET_NS 500000 + /** * stmmac_adjust_freq * @@ -171,7 +173,11 @@ static int stmmac_enable(struct ptp_clock_info *ptp, u32 acr_value; switch (rq->type) { - case PTP_CLK_REQ_PEROUT: + case PTP_CLK_REQ_PEROUT: { + struct timespec64 curr_time; + u64 target_ns = 0; + u64 ns = 0; + /* Reject requests with unsupported flags */ if (rq->perout.flags) return -EOPNOTSUPP; @@ -180,6 +186,31 @@ static int stmmac_enable(struct ptp_clock_info *ptp, cfg->start.tv_sec = rq->perout.start.sec; cfg->start.tv_nsec = rq->perout.start.nsec; + + /* A time set in the past won't trigger the start of the flexible PPS generation for + * the GMAC5. For some reason it does for the GMAC4 but setting a time in the past + * should be addressed anyway. Therefore, any value set it the past is considered as + * an offset compared to the current MAC system time. + * Be aware that an offset too low may not trigger flexible PPS generation + * if time spent in this configuration makes the targeted time already outdated. + * To address this, add a safe time offset. + */ + if (!cfg->start.tv_sec && cfg->start.tv_nsec < PTP_SAFE_TIME_OFFSET_NS) + cfg->start.tv_nsec += PTP_SAFE_TIME_OFFSET_NS; + + target_ns = cfg->start.tv_nsec + ((u64)cfg->start.tv_sec * NSEC_PER_SEC); + + stmmac_get_systime(priv, priv->ptpaddr, &ns); + if (ns > TIME64_MAX - PTP_SAFE_TIME_OFFSET_NS) + return -EINVAL; + + curr_time = ns_to_timespec64(ns); + if (target_ns < ns + PTP_SAFE_TIME_OFFSET_NS) { + cfg->start = timespec64_add_safe(cfg->start, curr_time); + if (cfg->start.tv_sec == TIME64_MAX) + return -EINVAL; + } + cfg->period.tv_sec = rq->perout.period.sec; cfg->period.tv_nsec = rq->perout.period.nsec; @@ -190,6 +221,8 @@ static int stmmac_enable(struct ptp_clock_info *ptp, priv->systime_flags); write_unlock_irqrestore(&priv->ptp_lock, flags); break; + } + case PTP_CLK_REQ_EXTTS: { u8 channel; -- 2.25.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v3 1/2] drivers: net: stmmac: handle start time set in the past for flexible PPS 2025-08-27 11:04 ` [PATCH net-next v3 1/2] drivers: net: stmmac: handle start time set in the past for flexible PPS Gatien Chevallier @ 2025-08-28 2:31 ` Jakub Kicinski 2025-08-29 10:51 ` Gatien CHEVALLIER 2025-08-28 9:32 ` kernel test robot 1 sibling, 1 reply; 7+ messages in thread From: Jakub Kicinski @ 2025-08-28 2:31 UTC (permalink / raw) To: Gatien Chevallier Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni, Maxime Coquelin, Alexandre Torgue, Richard Cochran, Rob Herring, Krzysztof Kozlowski, Conor Dooley, netdev, linux-stm32, linux-arm-kernel, linux-kernel, devicetree On Wed, 27 Aug 2025 13:04:58 +0200 Gatien Chevallier wrote: > + curr_time = ns_to_timespec64(ns); > + if (target_ns < ns + PTP_SAFE_TIME_OFFSET_NS) { > + cfg->start = timespec64_add_safe(cfg->start, curr_time); Is there a strong reason to use timespec64_add_safe()? It's not exported to modules: ERROR: modpost: "timespec64_add_safe" [drivers/net/ethernet/stmicro/stmmac/stmmac.ko] undefined! -- pw-bot: cr ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v3 1/2] drivers: net: stmmac: handle start time set in the past for flexible PPS 2025-08-28 2:31 ` Jakub Kicinski @ 2025-08-29 10:51 ` Gatien CHEVALLIER 2025-08-30 0:15 ` Jakub Kicinski 0 siblings, 1 reply; 7+ messages in thread From: Gatien CHEVALLIER @ 2025-08-29 10:51 UTC (permalink / raw) To: Jakub Kicinski Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni, Maxime Coquelin, Alexandre Torgue, Richard Cochran, Rob Herring, Krzysztof Kozlowski, Conor Dooley, netdev, linux-stm32, linux-arm-kernel, linux-kernel, devicetree On 8/28/25 04:31, Jakub Kicinski wrote: > On Wed, 27 Aug 2025 13:04:58 +0200 Gatien Chevallier wrote: >> + curr_time = ns_to_timespec64(ns); >> + if (target_ns < ns + PTP_SAFE_TIME_OFFSET_NS) { >> + cfg->start = timespec64_add_safe(cfg->start, curr_time); > > Is there a strong reason to use timespec64_add_safe()? > It's not exported to modules: > ERROR: modpost: "timespec64_add_safe" [drivers/net/ethernet/stmicro/stmmac/stmmac.ko] undefined! Hello Jakub, you're absolutely right. I don't know how I did not encounter the build error while performing some tests, that I'm getting now as well. The handling of overflows is already done in that function. Either I can make a patch to export the symbol or handle the computation in the driver. What do you think is best? Cheers, Gatien ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v3 1/2] drivers: net: stmmac: handle start time set in the past for flexible PPS 2025-08-29 10:51 ` Gatien CHEVALLIER @ 2025-08-30 0:15 ` Jakub Kicinski 0 siblings, 0 replies; 7+ messages in thread From: Jakub Kicinski @ 2025-08-30 0:15 UTC (permalink / raw) To: Gatien CHEVALLIER Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni, Maxime Coquelin, Alexandre Torgue, Richard Cochran, Rob Herring, Krzysztof Kozlowski, Conor Dooley, netdev, linux-stm32, linux-arm-kernel, linux-kernel, devicetree On Fri, 29 Aug 2025 12:51:40 +0200 Gatien CHEVALLIER wrote: > On 8/28/25 04:31, Jakub Kicinski wrote: > > On Wed, 27 Aug 2025 13:04:58 +0200 Gatien Chevallier wrote: > >> + curr_time = ns_to_timespec64(ns); > >> + if (target_ns < ns + PTP_SAFE_TIME_OFFSET_NS) { > >> + cfg->start = timespec64_add_safe(cfg->start, curr_time); > > > > Is there a strong reason to use timespec64_add_safe()? > > It's not exported to modules: > > ERROR: modpost: "timespec64_add_safe" [drivers/net/ethernet/stmicro/stmmac/stmmac.ko] undefined! > > Hello Jakub, > > you're absolutely right. I don't know how I did not encounter the build > error while performing some tests, that I'm getting now as well. > > The handling of overflows is already done in that function. Either > I can make a patch to export the symbol or handle the computation in the > driver. What do you think is best? The odds of me being right about time related code are only slightly better than 50/50, and I don't know what "flexible PPS" is :) But in principle, if the reason you need to check for overflow is valid -- add the export. The time maintainers will tell us if they don't want it. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v3 1/2] drivers: net: stmmac: handle start time set in the past for flexible PPS 2025-08-27 11:04 ` [PATCH net-next v3 1/2] drivers: net: stmmac: handle start time set in the past for flexible PPS Gatien Chevallier 2025-08-28 2:31 ` Jakub Kicinski @ 2025-08-28 9:32 ` kernel test robot 1 sibling, 0 replies; 7+ messages in thread From: kernel test robot @ 2025-08-28 9:32 UTC (permalink / raw) To: Gatien Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue, Richard Cochran, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: llvm, oe-kbuild-all, netdev, linux-stm32, linux-arm-kernel, linux-kernel, devicetree, Gatien Chevallier Hi Gatien, kernel test robot noticed the following build errors: [auto build test ERROR on 242041164339594ca019481d54b4f68a7aaff64e] url: https://github.com/intel-lab-lkp/linux/commits/Gatien-Chevallier/drivers-net-stmmac-handle-start-time-set-in-the-past-for-flexible-PPS/20250827-190905 base: 242041164339594ca019481d54b4f68a7aaff64e patch link: https://lore.kernel.org/r/20250827-relative_flex_pps-v3-1-673e77978ba2%40foss.st.com patch subject: [PATCH net-next v3 1/2] drivers: net: stmmac: handle start time set in the past for flexible PPS config: x86_64-rhel-9.4-rust (https://download.01.org/0day-ci/archive/20250828/202508281615.ExryCwiA-lkp@intel.com/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) rustc: rustc 1.88.0 (6b00bc388 2025-06-23) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250828/202508281615.ExryCwiA-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202508281615.ExryCwiA-lkp@intel.com/ All errors (new ones prefixed by >>, old ones prefixed by <<): >> ERROR: modpost: "timespec64_add_safe" [drivers/net/ethernet/stmicro/stmmac/stmmac.ko] undefined! -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net-next v3 2/2] ARM: dts: stm32: add missing PTP reference clocks on stm32mp13x SoCs 2025-08-27 11:04 [PATCH net-next v3 0/2] net: stmmac: allow generation of flexible PPS relative to MAC time Gatien Chevallier 2025-08-27 11:04 ` [PATCH net-next v3 1/2] drivers: net: stmmac: handle start time set in the past for flexible PPS Gatien Chevallier @ 2025-08-27 11:04 ` Gatien Chevallier 1 sibling, 0 replies; 7+ messages in thread From: Gatien Chevallier @ 2025-08-27 11:04 UTC (permalink / raw) To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue, Richard Cochran, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: netdev, linux-stm32, linux-arm-kernel, linux-kernel, devicetree, Gatien Chevallier ETH1/2 miss their PTP reference clock in the SoC device tree. Add them as the fallback is not correctly handled for PPS generation and it seems there's no reason to not add them. Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com> --- arch/arm/boot/dts/st/stm32mp131.dtsi | 2 ++ arch/arm/boot/dts/st/stm32mp133.dtsi | 2 ++ 2 files changed, 4 insertions(+) diff --git a/arch/arm/boot/dts/st/stm32mp131.dtsi b/arch/arm/boot/dts/st/stm32mp131.dtsi index ace9495b9b062e9f96437681cc526fed7f9eac5e..b88953485e597dc89c48ea2e3ffd382d1de5de92 100644 --- a/arch/arm/boot/dts/st/stm32mp131.dtsi +++ b/arch/arm/boot/dts/st/stm32mp131.dtsi @@ -1602,11 +1602,13 @@ ethernet1: ethernet@5800a000 { "mac-clk-tx", "mac-clk-rx", "ethstp", + "ptp_ref", "eth-ck"; clocks = <&rcc ETH1MAC>, <&rcc ETH1TX>, <&rcc ETH1RX>, <&rcc ETH1STP>, + <&rcc ETH1PTP_K>, <&rcc ETH1CK_K>; st,syscon = <&syscfg 0x4 0xff0000>; snps,mixed-burst; diff --git a/arch/arm/boot/dts/st/stm32mp133.dtsi b/arch/arm/boot/dts/st/stm32mp133.dtsi index 49583137b5972572d1feaa699c0c3a822a1b6f6d..053fc669120513c7d2812a0aabe8186fe1f4fe58 100644 --- a/arch/arm/boot/dts/st/stm32mp133.dtsi +++ b/arch/arm/boot/dts/st/stm32mp133.dtsi @@ -81,11 +81,13 @@ ethernet2: ethernet@5800e000 { "mac-clk-tx", "mac-clk-rx", "ethstp", + "ptp_ref", "eth-ck"; clocks = <&rcc ETH2MAC>, <&rcc ETH2TX>, <&rcc ETH2RX>, <&rcc ETH2STP>, + <&rcc ETH2PTP_K>, <&rcc ETH2CK_K>; st,syscon = <&syscfg 0x4 0xff000000>; snps,mixed-burst; -- 2.25.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-08-30 0:15 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-08-27 11:04 [PATCH net-next v3 0/2] net: stmmac: allow generation of flexible PPS relative to MAC time Gatien Chevallier 2025-08-27 11:04 ` [PATCH net-next v3 1/2] drivers: net: stmmac: handle start time set in the past for flexible PPS Gatien Chevallier 2025-08-28 2:31 ` Jakub Kicinski 2025-08-29 10:51 ` Gatien CHEVALLIER 2025-08-30 0:15 ` Jakub Kicinski 2025-08-28 9:32 ` kernel test robot 2025-08-27 11:04 ` [PATCH net-next v3 2/2] ARM: dts: stm32: add missing PTP reference clocks on stm32mp13x SoCs Gatien Chevallier
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).