net: stmmac: Add support for coarse timestamping
Subsystems (6)
Maxime Chevallier
maintainerv2 cover net: stmmac: Add support for coarse timestamping
Hello everyone,
This is V2 for coarse timetamping support in stmmac. This version uses a dedicated devlink param "ts_coarse" to control this mode.
This doesn't conflict with Russell's cleanup of hwif.
Maxime
[1] : https://lore.kernel.org/netdev/[email protected]/
Changes in V2:
- Use devlink intead of tsconfig
- Rebase on top of Russell's rework of has_xxx flags
V1: https://lore.kernel.org/netdev/[email protected]/
Maxime Chevallier (2):
net: stmmac: Move subsecond increment configuration in dedicated
helper
net: stmmac: Add a devlink attribute to control timestamping mode
Documentation/networking/devlink/index.rst | 1 + Documentation/networking/devlink/stmmac.rst | 31 ++++ drivers/net/ethernet/stmicro/stmmac/Kconfig | 1 + drivers/net/ethernet/stmicro/stmmac/stmmac.h | 3 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 163 +++++++++++++++--- 5 files changed, 176 insertions(+), 23 deletions(-) create mode 100644 Documentation/networking/devlink/stmmac.rst
Signature · 1 line
2.49.0
Maxime Chevallier
maintainerPATCH v2 1/2 net: stmmac: Move subsecond increment configuration in dedicated helper
In preparation for fine/coarse support, let's move the subsecond increment and addend configuration in a dedicated helper.
--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +28 -20
@@ -464,6 +464,33 @@ static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, struct dma_desc *p, } } +static void stmmac_update_subsecond_increment (struct stmmac_priv *priv) +{ +bool xmac =dwmac_is_xmac (priv->plat->core_type); +u32 sec_inc =0 ; +u64 temp =0 ; + +stmmac_config_hw_tstamping (priv, priv->ptpaddr, priv->systime_flags); + +/* program Sub Second Increment reg */ +stmmac_config_sub_second_increment (priv, priv->ptpaddr, + priv->plat->clk_ptp_rate, + xmac, &sec_inc); + temp =div_u64 (1000000000ULL , sec_inc); + +/* Store sub second increment for later use */ + priv->sub_second_inc = sec_inc; + +/* calculate default added value: +* formula is : +* addend = (2^32)/freq_div_ratio; +* where, freq_div_ratio = 1e9ns/sec_inc +*/ + temp = (u64)(temp <<32 ); + priv->default_addend =div_u64 (temp, priv->plat->clk_ptp_rate); +stmmac_config_addend (priv, priv->ptpaddr, priv->default_addend); +} +/** * stmmac_hwtstamp_set - control hardware timestamping. * @dev: device pointer.
@@ -697,10 +724,7 @@ static int stmmac_hwtstamp_get(struct net_device *dev,static int stmmac_init_tstamp_counter (struct stmmac_priv *priv,u32 systime_flags) { -bool xmac =dwmac_is_xmac (priv->plat->core_type);struct timespec64 now; -u32 sec_inc =0 ; -u64 temp =0 ;if (!priv->plat->clk_ptp_rate) {netdev_err (priv->dev,"Invalid PTP clock rate" );
@@ -710,23 +734,7 @@ static int stmmac_init_tstamp_counter(struct stmmac_priv *priv,stmmac_config_hw_tstamping (priv, priv->ptpaddr, systime_flags); priv->systime_flags = systime_flags; -/* program Sub Second Increment reg */ -stmmac_config_sub_second_increment (priv, priv->ptpaddr, - priv->plat->clk_ptp_rate, - xmac, &sec_inc); - temp =div_u64 (1000000000ULL , sec_inc); - -/* Store sub second increment for later use */ - priv->sub_second_inc = sec_inc; - -/* calculate default added value: -* formula is : -* addend = (2^32)/freq_div_ratio; -* where, freq_div_ratio = 1e9ns/sec_inc -*/ - temp = (u64)(temp <<32 ); - priv->default_addend =div_u64 (temp, priv->plat->clk_ptp_rate); -stmmac_config_addend (priv, priv->ptpaddr, priv->default_addend); +stmmac_update_subsecond_increment (priv);/* initialize system time */ ktime_get_real_ts64 (&now);
Signature · 1 line
2.49.0
Re: [PATCH net-next v2 1/2] net: stmmac: Move subsecond increment configuration in dedicated helper
Quoted 4 lines · Maxime Chevallier
In preparation for fine/coarse support, let's move the subsecond increment and addend configuration in a dedicated helper.
Signed-off-by Maxime Chevallier <[email protected]>
Thanks!
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Maxime Chevallier
maintainerPATCH v2 2/2 net: stmmac: Add a devlink attribute to control timestamping mode
In reply to Maxime ChevallierThe DWMAC1000 supports 2 timestamping configurations to configure how frequency adjustments are made to the ptp_clock, as well as the reported timestamp values.
There was a previous attempt at upstreaming support for configuring this mode by Olivier Dautricourt and Julien Beraud a few years back [1]
In a nutshell, the timestamping can be either set in fine mode or in coarse mode.
In fine mode, which is the default, we use the overflow of an accumulator to trigger frequency adjustments, but by doing so we lose precision on the timetamps that are produced by the timestamping unit. The main drawback is that the sub-second increment value, used to generate timestamps, can't be set to lower than (2 / ptp_clock_freq).
The "fine" qualification comes from the frequent frequency adjustments we are able to do, which is perfect for a PTP follower usecase.
In Coarse mode, we don't do frequency adjustments based on an accumulator overflow. We can therefore have very fine subsecond increment values, allowing for better timestamping precision. However this mode works best when the ptp clock frequency is adjusted based on an external signal, such as a PPS input produced by a GPS clock. This mode is therefore perfect for a Grand-master usecase.
Introduce a driver-specific devlink parameter "ts_coarse" to enable or disable coarse mode, keeping the "fine" mode as a default.
This can then be changed with:
devlink dev param set <dev> name ts_coarse value true cmode runtime
The associated documentation is also added.
[1] : https://lore.kernel.org/netdev/[email protected]/
--- Documentation/networking/devlink/index.rst | 1 + Documentation/networking/devlink/stmmac.rst | 31 +++++ drivers/net/ethernet/stmicro/stmmac/Kconfig | 1 + drivers/net/ethernet/stmicro/stmmac/stmmac.h | 3 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 115 +++++++++++++++++- 5 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 Documentation/networking/devlink/stmmac.rst
Documentation/networking/devlink/index.rst +1 -0
@@ -99,5 +99,6 @@ parameters, info versions, and other features it supports. prestera qed sfc + stmmac ti-cpsw-switch zl3073x
Documentation/networking/devlink/stmmac.rst new file +31 -0
@@ -0,0 +1,31 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================================= +stmmac (synopsys dwmac) devlink support +======================================= + +This document describes the devlink features implemented by the ``stmmac`` +device driver. + +Parameters +========== + +The ``stmmac`` driver implements the following driver-specific parameters. + +.. list-table:: Driver-specific parameters implemented + :widths: 5 5 5 85 + + * - Name + - Type + - Mode + - Description + * - ``ts_coarse`` + - Boolean + - runtime + - Enable the Coarse timestamping mode. In Coarse mode, the ptp clock is + expected to be updated through an external PPS input, but the subsecond + increment used for timestamping is set to 1/ptp_clock_rate. In Fine mode + (i.e. Coarse mode == false), the ptp clock frequency is adjusted more + frequently, but the subsecond increment is set to 2/ptp_clock_rate. + Coarse mode is suitable for PTP Grand Master operation. If unsure, leave + the parameter to False.
drivers/net/ethernet/stmicro/stmmac/Kconfig +1 -0
@@ -10,6 +10,7 @@ config STMMAC_ETH select PHYLINK select CRC32 select RESET_CONTROLLER + select NET_DEVLINK help This is the driver for the Ethernet IPs built around a Synopsys IP Core.
drivers/net/ethernet/stmicro/stmmac/stmmac.h +3 -0
@@ -259,6 +259,7 @@ struct stmmac_priv {u32 sarc_type;u32 rx_riwt[MTL_MAX_RX_QUEUES ];int hwts_rx_en; +bool tsfupdt_coarse;void __iomem *ioaddr;struct net_device *dev;
@@ -368,6 +369,8 @@ struct stmmac_priv {/* XDP BPF Program */ unsigned long *af_xdp_zc_qps;struct bpf_prog *xdp_prog; + +struct devlink *devlink; };enum stmmac_state {
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +112 -3
169 lines not on this page · raw message
Signature · 1 line
2.49.0
Re: [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode
Quoted 31 lines · Maxime Chevallier
The DWMAC1000 supports 2 timestamping configurations to configure how frequency adjustments are made to the
ptp_clock, as well as the reported timestamp values.There was a previous attempt at upstreaming support for configuring this mode by Olivier Dautricourt and Julien Beraud a few years back [1]
In a nutshell, the timestamping can be either set in fine mode or in coarse mode.
In fine mode, which is the default, we use the overflow of an accumulator to trigger frequency adjustments, but by doing so we lose precision on the timetamps that are produced by the timestamping unit. The main drawback is that the sub-second increment value, used to generate timestamps, can't be set to lower than (2 /
ptp_clock_freq).The "fine" qualification comes from the frequent frequency adjustments we are able to do, which is perfect for a PTP follower usecase.
In Coarse mode, we don't do frequency adjustments based on an accumulator overflow. We can therefore have very fine subsecond increment values, allowing for better timestamping precision. However this mode works best when the ptp clock frequency is adjusted based on an external signal, such as a PPS input produced by a GPS clock. This mode is therefore perfect for a Grand-master usecase.
Introduce a driver-specific devlink parameter "
ts_coarse" to enable or disable coarse mode, keeping the "fine" mode as a default.This can then be changed with:
Quoted 7 lines
devlink dev param set <dev> name
ts_coarsevalue true cmode runtimeThe associated documentation is also added.
[1] : https://lore.kernel.org/netdev/[email protected]/
Signed-off-by Maxime Chevallier <[email protected]>
Thanks!
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode
In reply to Maxime ChevallierQuoted 29 lines · On Fri, 24 Oct 2025 09:07:18 +0200 Maxime Chevallier…
The DWMAC1000 supports 2 timestamping configurations to configure how frequency adjustments are made to the
ptp_clock, as well as the reported timestamp values.There was a previous attempt at upstreaming support for configuring this mode by Olivier Dautricourt and Julien Beraud a few years back [1]
In a nutshell, the timestamping can be either set in fine mode or in coarse mode.
In fine mode, which is the default, we use the overflow of an accumulator to trigger frequency adjustments, but by doing so we lose precision on the timetamps that are produced by the timestamping unit. The main drawback is that the sub-second increment value, used to generate timestamps, can't be set to lower than (2 /
ptp_clock_freq).The "fine" qualification comes from the frequent frequency adjustments we are able to do, which is perfect for a PTP follower usecase.
In Coarse mode, we don't do frequency adjustments based on an accumulator overflow. We can therefore have very fine subsecond increment values, allowing for better timestamping precision. However this mode works best when the ptp clock frequency is adjusted based on an external signal, such as a PPS input produced by a GPS clock. This mode is therefore perfect for a Grand-master usecase.
Introduce a driver-specific devlink parameter "
ts_coarse" to enable or disable coarse mode, keeping the "fine" mode as a default.
Quoted 8 lines
This can then be changed with:
devlink dev param set <dev> name
ts_coarsevalue true cmode runtimeThe associated documentation is also added.
Thank you!
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Jakub Kicinski
maintainerRe: [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode
In reply to Maxime ChevallierSorry didn't get to review this in time.
Quoted 1 line · On Fri, 24 Oct 2025 09:07:18 +0200 Maxime Chevallier wrote:
+ * - ``ts_coarse``
This is not a great name IMHO. Is "coarse" from the PRM? It's the increment that's coarse, right? Not the timestamp This naming confuses me greatly.
Documentation/networking/devlink/stmmac.rst line 26
Quoted 4 lines
Documentation/networking/devlink/stmmac.rst new file +4
-0+ - Boolean + - runtime + - Enable the Coarse timestamping mode. In Coarse mode, the ptp clock is + expected to be updated through an external PPS input, but the subsecond
I guess the definition of "PPS input" got diluted but technically it means Pulse Per Second, right? Here IIUC we need an actual 50MHz clock fed in?
Documentation/networking/devlink/stmmac.rst line 31
Quoted 5 lines
Documentation/networking/devlink/stmmac.rst new file +5
-0+ increment used for timestamping is set to 1/ptp_clock_rate. In Fine mode + (i.e. Coarse mode == false), the ptp clock frequency is adjusted more + frequently, but the subsecond increment is set to 2/ptp_clock_rate. + Coarse mode is suitable for PTP Grand Master operation. If unsure, leave + the parameter to False.
My understanding based on your previous explanation is that basically in one of the modes the frequency cannot be adjusted. It's only usable if a very stable reference clock is fed into the device (or otherwise we "trust" the clock that's fed in). So that's why Grand Master.
In the other mode we can tweak the frequency more accurately. But it comes at a cost of the HW time incrementing 2x larger step.
If that's the case I think we should update the documentation and rename the knob to indicate that it's the frequency adjustment that's coarse.
Maxime Chevallier
maintainerRe: [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode
Hi Jakub,
Quoted 6 lines · Jakub Kicinski
Sorry didn't get to review this in time.
Quoted 1 line · On Fri, 24 Oct 2025 09:07:18 +0200 Maxime Chevallier wrote:
+ * - ``ts_coarse``
This is not a great name IMHO. Is "coarse" from the PRM?
Yes, it uses "fine/coarse"
Quoted 2 lines
It's the increment that's coarse, right? Not the timestamp This naming confuses me greatly.
That is true, the ts_ was added as this configuration is done based on the timestamping control registers, and is refered to as "timestamping control fine update" in the register defs :(
So you are correct that in the end the clock frequency is coarsely adjusted.
The patch was applied, should we revert or add another patch to rename that parameter ?
Quoted 9 lines
Documentation/networking/devlink/stmmac.rst line 26
Quoted 5 lines
Documentation/networking/devlink/stmmac.rst new file +4
-0+ - Boolean + - runtime + - Enable the Coarse timestamping mode. In Coarse mode, the ptp clock is + expected to be updated through an external PPS input, but the subsecondI guess the definition of "PPS input" got diluted but technically it means Pulse Per Second, right? Here IIUC we need an actual 50MHz clock fed in?
For GM, yes indeed. I can update the doc accordingly.
Quoted 12 lines
Documentation/networking/devlink/stmmac.rst line 31
Quoted 6 lines
Documentation/networking/devlink/stmmac.rst new file +5
-0+ increment used for timestamping is set to 1/ptp_clock_rate. In Fine mode + (i.e. Coarse mode == false), the ptp clock frequency is adjusted more + frequently, but the subsecond increment is set to 2/ptp_clock_rate. + Coarse mode is suitable for PTP Grand Master operation. If unsure, leave + the parameter to False.My understanding based on your previous explanation is that basically in one of the modes the frequency cannot be adjusted. It's only usable if a very stable reference clock is fed into the device (or otherwise we "trust" the clock that's fed in). So that's why Grand Master.
Quoted 6 lines
In the other mode we can tweak the frequency more accurately. But it comes at a cost of the HW time incrementing 2x larger step.
If that's the case I think we should update the documentation and rename the knob to indicate that it's the frequency adjustment that's coarse.
That's fine by me, just let me know abut the exact process, I can followup on that :)
Maxime
Jakub Kicinski
maintainerRe: [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode
Quoted 2 lines · On Wed, 29 Oct 2025 07:59:10 +0100 Maxime Chevallier wrote:
The patch was applied, should we revert or add another patch to rename that parameter ?
I think an incremental patch is best here. You're using the register naming in the driver code so I suppose you won't even have to make many changes there.
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Fri, 24 Oct 2025 09:07:16 +0200 you wrote:
Hello everyone,
This is V2 for coarse timetamping support in stmmac. This version uses a dedicated devlink param "
ts_coarse" to control this mode.This doesn't conflict with Russell's cleanup of hwif.
[...]
Here is the summary with links:
- [net-next,v2,1/2] net: stmmac: Move subsecond increment configuration in dedicated helper
https://git.kernel.org/netdev/net-next/c/792000fbcd0c - [net-next,v2,2/2] net: stmmac: Add a devlink attribute to control timestamping mode https://git.kernel.org/netdev/net-next/c/6920fa0c764d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html