* [PATCH net-next v2 0/2] net: stmmac: Add support for coarse timestamping
@ 2025-10-24 7:07 Maxime Chevallier
2025-10-24 7:07 ` [PATCH net-next v2 1/2] net: stmmac: Move subsecond increment configuration in dedicated helper Maxime Chevallier
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Maxime Chevallier @ 2025-10-24 7:07 UTC (permalink / raw)
To: Alexandre Torgue, Jose Abreu, Andrew Lunn, davem, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Richard Cochran,
Russell King, Köry Maincent
Cc: Maxime Chevallier, Vadim Fedorenko, Alexis Lothoré,
Thomas Petazzoni, netdev, linux-stm32, linux-arm-kernel,
linux-kernel
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/20200514102808.31163-1-olivier.dautricourt@orolia.com/
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/20251015102725.1297985-1-maxime.chevallier@bootlin.com/
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
--
2.49.0
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH net-next v2 1/2] net: stmmac: Move subsecond increment configuration in dedicated helper 2025-10-24 7:07 [PATCH net-next v2 0/2] net: stmmac: Add support for coarse timestamping Maxime Chevallier @ 2025-10-24 7:07 ` Maxime Chevallier 2025-10-24 12:43 ` Russell King (Oracle) 2025-10-24 7:07 ` [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode Maxime Chevallier 2025-10-28 14:50 ` [PATCH net-next v2 0/2] net: stmmac: Add support for coarse timestamping patchwork-bot+netdevbpf 2 siblings, 1 reply; 10+ messages in thread From: Maxime Chevallier @ 2025-10-24 7:07 UTC (permalink / raw) To: Alexandre Torgue, Jose Abreu, Andrew Lunn, davem, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Richard Cochran, Russell King, Köry Maincent Cc: Maxime Chevallier, Vadim Fedorenko, Alexis Lothoré, Thomas Petazzoni, netdev, linux-stm32, linux-arm-kernel, linux-kernel In preparation for fine/coarse support, let's move the subsecond increment and addend configuration in a dedicated helper. Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com> --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 9fa3c221a0c3..8922c660cefa 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -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); -- 2.49.0 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v2 1/2] net: stmmac: Move subsecond increment configuration in dedicated helper 2025-10-24 7:07 ` [PATCH net-next v2 1/2] net: stmmac: Move subsecond increment configuration in dedicated helper Maxime Chevallier @ 2025-10-24 12:43 ` Russell King (Oracle) 0 siblings, 0 replies; 10+ messages in thread From: Russell King (Oracle) @ 2025-10-24 12:43 UTC (permalink / raw) To: Maxime Chevallier Cc: Alexandre Torgue, Jose Abreu, Andrew Lunn, davem, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Richard Cochran, Köry Maincent, Vadim Fedorenko, Alexis Lothoré, Thomas Petazzoni, netdev, linux-stm32, linux-arm-kernel, linux-kernel On Fri, Oct 24, 2025 at 09:07:17AM +0200, Maxime Chevallier wrote: > In preparation for fine/coarse support, let's move the subsecond increment > and addend configuration in a dedicated helper. > > Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com> Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Thanks! -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last! ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode 2025-10-24 7:07 [PATCH net-next v2 0/2] net: stmmac: Add support for coarse timestamping Maxime Chevallier 2025-10-24 7:07 ` [PATCH net-next v2 1/2] net: stmmac: Move subsecond increment configuration in dedicated helper Maxime Chevallier @ 2025-10-24 7:07 ` Maxime Chevallier 2025-10-24 12:44 ` Russell King (Oracle) ` (2 more replies) 2025-10-28 14:50 ` [PATCH net-next v2 0/2] net: stmmac: Add support for coarse timestamping patchwork-bot+netdevbpf 2 siblings, 3 replies; 10+ messages in thread From: Maxime Chevallier @ 2025-10-24 7:07 UTC (permalink / raw) To: Alexandre Torgue, Jose Abreu, Andrew Lunn, davem, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Richard Cochran, Russell King, Köry Maincent Cc: Maxime Chevallier, Vadim Fedorenko, Alexis Lothoré, Thomas Petazzoni, netdev, linux-stm32, linux-arm-kernel, linux-kernel 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: devlink dev param set <dev> name ts_coarse value true cmode runtime The associated documentation is also added. [1] : https://lore.kernel.org/netdev/20200514102808.31163-1-olivier.dautricourt@orolia.com/ Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com> --- 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 diff --git a/Documentation/networking/devlink/index.rst b/Documentation/networking/devlink/index.rst index 0c58e5c729d9..35b12a2bfeba 100644 --- a/Documentation/networking/devlink/index.rst +++ b/Documentation/networking/devlink/index.rst @@ -99,5 +99,6 @@ parameters, info versions, and other features it supports. prestera qed sfc + stmmac ti-cpsw-switch zl3073x diff --git a/Documentation/networking/devlink/stmmac.rst b/Documentation/networking/devlink/stmmac.rst new file mode 100644 index 000000000000..e8e33d1c7baf --- /dev/null +++ b/Documentation/networking/devlink/stmmac.rst @@ -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. diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig index 716daa51df7e..87c5bea6c2a2 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig @@ -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. diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index aaeaf42084f0..bea0ce86c718 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -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 { diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 8922c660cefa..0b15c90b67f7 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -40,6 +40,7 @@ #include <linux/phylink.h> #include <linux/udp.h> #include <linux/bpf_trace.h> +#include <net/devlink.h> #include <net/page_pool/helpers.h> #include <net/pkt_cls.h> #include <net/xdp_sock_drv.h> @@ -58,8 +59,7 @@ * with fine resolution and binary rollover. This avoid non-monotonic behavior * (clock jumps) when changing timestamping settings at runtime. */ -#define STMMAC_HWTS_ACTIVE (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | \ - PTP_TCR_TSCTRLSSR) +#define STMMAC_HWTS_ACTIVE (PTP_TCR_TSENA | PTP_TCR_TSCTRLSSR) #define STMMAC_ALIGN(x) ALIGN(ALIGN(x, SMP_CACHE_BYTES), 16) #define TSO_MAX_BUFF_SIZE (SZ_16K - 1) @@ -148,6 +148,15 @@ static void stmmac_exit_fs(struct net_device *dev); #define STMMAC_COAL_TIMER(x) (ns_to_ktime((x) * NSEC_PER_USEC)) +struct stmmac_devlink_priv { + struct stmmac_priv *stmmac_priv; +}; + +enum stmmac_dl_param_id { + STMMAC_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX, + STMMAC_DEVLINK_PARAM_ID_TS_COARSE, +}; + /** * stmmac_set_clk_tx_rate() - set the clock rate for the MAC transmit clock * @bsp_priv: BSP private data structure (unused) @@ -675,6 +684,8 @@ static int stmmac_hwtstamp_set(struct net_device *dev, priv->hwts_tx_en = config->tx_type == HWTSTAMP_TX_ON; priv->systime_flags = STMMAC_HWTS_ACTIVE; + if (!priv->tsfupdt_coarse) + priv->systime_flags |= PTP_TCR_TSCFUPDT; if (priv->hwts_tx_en || priv->hwts_rx_en) { priv->systime_flags |= tstamp_all | ptp_v2 | @@ -765,7 +776,8 @@ static int stmmac_init_timestamping(struct stmmac_priv *priv) return -EOPNOTSUPP; } - ret = stmmac_init_tstamp_counter(priv, STMMAC_HWTS_ACTIVE); + ret = stmmac_init_tstamp_counter(priv, STMMAC_HWTS_ACTIVE | + PTP_TCR_TSCFUPDT); if (ret) { netdev_warn(priv->dev, "PTP init failed\n"); return ret; @@ -7383,6 +7395,95 @@ static const struct xdp_metadata_ops stmmac_xdp_metadata_ops = { .xmo_rx_timestamp = stmmac_xdp_rx_timestamp, }; +static int stmmac_dl_ts_coarse_set(struct devlink *dl, u32 id, + struct devlink_param_gset_ctx *ctx, + struct netlink_ext_ack *extack) +{ + struct stmmac_devlink_priv *dl_priv = devlink_priv(dl); + struct stmmac_priv *priv = dl_priv->stmmac_priv; + + priv->tsfupdt_coarse = ctx->val.vbool; + + if (priv->tsfupdt_coarse) + priv->systime_flags &= ~PTP_TCR_TSCFUPDT; + else + priv->systime_flags |= PTP_TCR_TSCFUPDT; + + /* In Coarse mode, we can use a smaller subsecond increment, let's + * reconfigure the systime, subsecond increment and addend. + */ + stmmac_update_subsecond_increment(priv); + + return 0; +} + +static int stmmac_dl_ts_coarse_get(struct devlink *dl, u32 id, + struct devlink_param_gset_ctx *ctx) +{ + struct stmmac_devlink_priv *dl_priv = devlink_priv(dl); + struct stmmac_priv *priv = dl_priv->stmmac_priv; + + ctx->val.vbool = priv->tsfupdt_coarse; + + return 0; +} + +static const struct devlink_param stmmac_devlink_params[] = { + DEVLINK_PARAM_DRIVER(STMMAC_DEVLINK_PARAM_ID_TS_COARSE, "ts_coarse", + DEVLINK_PARAM_TYPE_BOOL, + BIT(DEVLINK_PARAM_CMODE_RUNTIME), + stmmac_dl_ts_coarse_get, + stmmac_dl_ts_coarse_set, NULL), +}; + +/* None of the generic devlink parameters are implemented */ +static const struct devlink_ops stmmac_devlink_ops = {}; + +static int stmmac_register_devlink(struct stmmac_priv *priv) +{ + struct stmmac_devlink_priv *dl_priv; + int ret; + + /* For now, what is exposed over devlink is only relevant when + * timestamping is available and we have a valid ptp clock rate + */ + if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp) || + !priv->plat->clk_ptp_rate) + return 0; + + priv->devlink = devlink_alloc(&stmmac_devlink_ops, sizeof(*dl_priv), + priv->device); + if (!priv->devlink) + return -ENOMEM; + + dl_priv = devlink_priv(priv->devlink); + dl_priv->stmmac_priv = priv; + + ret = devlink_params_register(priv->devlink, stmmac_devlink_params, + ARRAY_SIZE(stmmac_devlink_params)); + if (ret) + goto dl_free; + + devlink_register(priv->devlink); + return 0; + +dl_free: + devlink_free(priv->devlink); + + return ret; +} + +static void stmmac_unregister_devlink(struct stmmac_priv *priv) +{ + if (!priv->devlink) + return; + + devlink_unregister(priv->devlink); + devlink_params_unregister(priv->devlink, stmmac_devlink_params, + ARRAY_SIZE(stmmac_devlink_params)); + devlink_free(priv->devlink); +} + /** * stmmac_dvr_probe * @device: device pointer @@ -7656,6 +7757,10 @@ int stmmac_dvr_probe(struct device *device, goto error_phy_setup; } + ret = stmmac_register_devlink(priv); + if (ret) + goto error_devlink_setup; + ret = register_netdev(ndev); if (ret) { dev_err(priv->device, "%s: ERROR %i registering the device\n", @@ -7678,6 +7783,8 @@ int stmmac_dvr_probe(struct device *device, return ret; error_netdev_register: + stmmac_unregister_devlink(priv); +error_devlink_setup: phylink_destroy(priv->phylink); error_phy_setup: stmmac_pcs_clean(ndev); @@ -7714,6 +7821,8 @@ void stmmac_dvr_remove(struct device *dev) #ifdef CONFIG_DEBUG_FS stmmac_exit_fs(ndev); #endif + stmmac_unregister_devlink(priv); + phylink_destroy(priv->phylink); if (priv->plat->stmmac_rst) reset_control_assert(priv->plat->stmmac_rst); -- 2.49.0 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode 2025-10-24 7:07 ` [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode Maxime Chevallier @ 2025-10-24 12:44 ` Russell King (Oracle) 2025-10-28 10:16 ` Kory Maincent 2025-10-28 22:19 ` Jakub Kicinski 2 siblings, 0 replies; 10+ messages in thread From: Russell King (Oracle) @ 2025-10-24 12:44 UTC (permalink / raw) To: Maxime Chevallier Cc: Alexandre Torgue, Jose Abreu, Andrew Lunn, davem, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Richard Cochran, Köry Maincent, Vadim Fedorenko, Alexis Lothoré, Thomas Petazzoni, netdev, linux-stm32, linux-arm-kernel, linux-kernel On Fri, Oct 24, 2025 at 09:07:18AM +0200, Maxime Chevallier wrote: > 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: > > devlink dev param set <dev> name ts_coarse value true cmode runtime > > The associated documentation is also added. > > [1] : https://lore.kernel.org/netdev/20200514102808.31163-1-olivier.dautricourt@orolia.com/ > > Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com> Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Thanks! -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last! ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode 2025-10-24 7:07 ` [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode Maxime Chevallier 2025-10-24 12:44 ` Russell King (Oracle) @ 2025-10-28 10:16 ` Kory Maincent 2025-10-28 22:19 ` Jakub Kicinski 2 siblings, 0 replies; 10+ messages in thread From: Kory Maincent @ 2025-10-28 10:16 UTC (permalink / raw) To: Maxime Chevallier Cc: Alexandre Torgue, Jose Abreu, Andrew Lunn, davem, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Richard Cochran, Russell King, Vadim Fedorenko, Alexis Lothoré, Thomas Petazzoni, netdev, linux-stm32, linux-arm-kernel, linux-kernel On Fri, 24 Oct 2025 09:07:18 +0200 Maxime Chevallier <maxime.chevallier@bootlin.com> wrote: > 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: > > devlink dev param set <dev> name ts_coarse value true cmode runtime > > The associated documentation is also added. > > [1] : > https://lore.kernel.org/netdev/20200514102808.31163-1-olivier.dautricourt@orolia.com/ Reviewed-by: Kory Maincent <kory.maincent@bootlin.com> Thank you! -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode 2025-10-24 7:07 ` [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode Maxime Chevallier 2025-10-24 12:44 ` Russell King (Oracle) 2025-10-28 10:16 ` Kory Maincent @ 2025-10-28 22:19 ` Jakub Kicinski 2025-10-29 6:59 ` Maxime Chevallier 2 siblings, 1 reply; 10+ messages in thread From: Jakub Kicinski @ 2025-10-28 22:19 UTC (permalink / raw) To: Maxime Chevallier Cc: Alexandre Torgue, Jose Abreu, Andrew Lunn, davem, Eric Dumazet, Paolo Abeni, Maxime Coquelin, Richard Cochran, Russell King, Köry Maincent, Vadim Fedorenko, Alexis Lothoré, Thomas Petazzoni, netdev, linux-stm32, linux-arm-kernel, linux-kernel Sorry didn't get to review this in time. 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. > + - 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? > + 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. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode 2025-10-28 22:19 ` Jakub Kicinski @ 2025-10-29 6:59 ` Maxime Chevallier 2025-10-29 22:50 ` Jakub Kicinski 0 siblings, 1 reply; 10+ messages in thread From: Maxime Chevallier @ 2025-10-29 6:59 UTC (permalink / raw) To: Jakub Kicinski Cc: Alexandre Torgue, Jose Abreu, Andrew Lunn, davem, Eric Dumazet, Paolo Abeni, Maxime Coquelin, Richard Cochran, Russell King, Köry Maincent, Vadim Fedorenko, Alexis Lothoré, Thomas Petazzoni, netdev, linux-stm32, linux-arm-kernel, linux-kernel Hi Jakub, On 28/10/2025 23:19, Jakub Kicinski wrote: > Sorry didn't get to review this in time. > > 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" > 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 ? > >> + - 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? For GM, yes indeed. I can update the doc accordingly. > >> + 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. That's fine by me, just let me know abut the exact process, I can followup on that :) Maxime ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode 2025-10-29 6:59 ` Maxime Chevallier @ 2025-10-29 22:50 ` Jakub Kicinski 0 siblings, 0 replies; 10+ messages in thread From: Jakub Kicinski @ 2025-10-29 22:50 UTC (permalink / raw) To: Maxime Chevallier Cc: Alexandre Torgue, Jose Abreu, Andrew Lunn, davem, Eric Dumazet, Paolo Abeni, Maxime Coquelin, Richard Cochran, Russell King, Köry Maincent, Vadim Fedorenko, Alexis Lothoré, Thomas Petazzoni, netdev, linux-stm32, linux-arm-kernel, linux-kernel 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. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v2 0/2] net: stmmac: Add support for coarse timestamping 2025-10-24 7:07 [PATCH net-next v2 0/2] net: stmmac: Add support for coarse timestamping Maxime Chevallier 2025-10-24 7:07 ` [PATCH net-next v2 1/2] net: stmmac: Move subsecond increment configuration in dedicated helper Maxime Chevallier 2025-10-24 7:07 ` [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode Maxime Chevallier @ 2025-10-28 14:50 ` patchwork-bot+netdevbpf 2 siblings, 0 replies; 10+ messages in thread From: patchwork-bot+netdevbpf @ 2025-10-28 14:50 UTC (permalink / raw) To: Maxime Chevallier Cc: alexandre.torgue, joabreu, andrew+netdev, davem, edumazet, kuba, pabeni, mcoquelin.stm32, richardcochran, linux, kory.maincent, vadim.fedorenko, alexis.lothore, thomas.petazzoni, netdev, linux-stm32, linux-arm-kernel, linux-kernel Hello: This series was applied to netdev/net-next.git (main) by Paolo Abeni <pabeni@redhat.com>: 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! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-10-29 22:50 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-10-24 7:07 [PATCH net-next v2 0/2] net: stmmac: Add support for coarse timestamping Maxime Chevallier 2025-10-24 7:07 ` [PATCH net-next v2 1/2] net: stmmac: Move subsecond increment configuration in dedicated helper Maxime Chevallier 2025-10-24 12:43 ` Russell King (Oracle) 2025-10-24 7:07 ` [PATCH net-next v2 2/2] net: stmmac: Add a devlink attribute to control timestamping mode Maxime Chevallier 2025-10-24 12:44 ` Russell King (Oracle) 2025-10-28 10:16 ` Kory Maincent 2025-10-28 22:19 ` Jakub Kicinski 2025-10-29 6:59 ` Maxime Chevallier 2025-10-29 22:50 ` Jakub Kicinski 2025-10-28 14:50 ` [PATCH net-next v2 0/2] net: stmmac: Add support for coarse timestamping patchwork-bot+netdevbpf
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).