Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'net-stmmac-allow-generation-of-flexible-pps-relative-to-mac-time'

Gatien Chevallier says:

====================
net: stmmac: allow generation of flexible PPS relative to MAC time

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
====================

Link: https://patch.msgid.link/20250901-relative_flex_pps-v4-0-b874971dfe85@foss.st.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+34 -1
+33 -1
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
··· 10 10 #include "stmmac.h" 11 11 #include "stmmac_ptp.h" 12 12 13 + #define PTP_SAFE_TIME_OFFSET_NS 500000 14 + 13 15 /** 14 16 * stmmac_adjust_freq 15 17 * ··· 173 171 u32 acr_value; 174 172 175 173 switch (rq->type) { 176 - case PTP_CLK_REQ_PEROUT: 174 + case PTP_CLK_REQ_PEROUT: { 175 + struct timespec64 curr_time; 176 + u64 target_ns = 0; 177 + u64 ns = 0; 178 + 177 179 /* Reject requests with unsupported flags */ 178 180 if (rq->perout.flags) 179 181 return -EOPNOTSUPP; ··· 186 180 187 181 cfg->start.tv_sec = rq->perout.start.sec; 188 182 cfg->start.tv_nsec = rq->perout.start.nsec; 183 + 184 + /* A time set in the past won't trigger the start of the flexible PPS generation for 185 + * the GMAC5. For some reason it does for the GMAC4 but setting a time in the past 186 + * should be addressed anyway. Therefore, any value set it the past is considered as 187 + * an offset compared to the current MAC system time. 188 + * Be aware that an offset too low may not trigger flexible PPS generation 189 + * if time spent in this configuration makes the targeted time already outdated. 190 + * To address this, add a safe time offset. 191 + */ 192 + if (!cfg->start.tv_sec && cfg->start.tv_nsec < PTP_SAFE_TIME_OFFSET_NS) 193 + cfg->start.tv_nsec += PTP_SAFE_TIME_OFFSET_NS; 194 + 195 + target_ns = cfg->start.tv_nsec + ((u64)cfg->start.tv_sec * NSEC_PER_SEC); 196 + 197 + stmmac_get_systime(priv, priv->ptpaddr, &ns); 198 + if (ns > TIME64_MAX - PTP_SAFE_TIME_OFFSET_NS) 199 + return -EINVAL; 200 + 201 + curr_time = ns_to_timespec64(ns); 202 + if (target_ns < ns + PTP_SAFE_TIME_OFFSET_NS) { 203 + cfg->start = timespec64_add_safe(cfg->start, curr_time); 204 + if (cfg->start.tv_sec == TIME64_MAX) 205 + return -EINVAL; 206 + } 207 + 189 208 cfg->period.tv_sec = rq->perout.period.sec; 190 209 cfg->period.tv_nsec = rq->perout.period.nsec; 191 210 ··· 221 190 priv->systime_flags); 222 191 write_unlock_irqrestore(&priv->ptp_lock, flags); 223 192 break; 193 + } 224 194 case PTP_CLK_REQ_EXTTS: { 225 195 u8 channel; 226 196
+1
kernel/time/time.c
··· 858 858 859 859 return res; 860 860 } 861 + EXPORT_SYMBOL_GPL(timespec64_add_safe); 861 862 862 863 /** 863 864 * get_timespec64 - get user's time value into kernel space