* [PATCH net-next 0/2] net: stmmac: correctly populate ptp_clock_ops.getcrosststamp
@ 2025-09-03 14:00 Russell King (Oracle)
2025-09-03 14:00 ` [PATCH net-next 1/2] net: stmmac: ptp: conditionally populate getcrosststamp() method Russell King (Oracle)
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Russell King (Oracle) @ 2025-09-03 14:00 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Richard Cochran
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Coquelin,
netdev, Paolo Abeni
Hi,
While reviewing code in the stmmac PTP driver, I noticed that the
getcrosststamp() method is always populated, irrespective of whether
it is implemented or not by the stmmac platform specific glue layer.
Where a platform specific glue layer does not implement it, the core
stmmac driver code returns -EOPNOTSUPP. However, the PTP clock core
code uses the presence of the method in ptp_clock_ops to determine
whether this facility should be advertised to userspace (see
ptp_clock_getcaps()).
Moreover, the only platform glue that implements this method is the
Intel glue, and for it not to return -EOPNOTSUPP, the CPU has to
support X86_FEATURE_ART.
This series updates the core stmmac code to only provide the
getcrosststamp() method in ptp_clock_ops when the platform glue code
provides an implementation, and then updates the Intel glue code to
only provide its implementation when the CPU has the necessary
X86_FEATURE_ART feature.
As I do not have an Intel card to test with, these changes are
untested, so if anyone has such a card, please test. Thanks.
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c | 7 +++----
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c | 10 ++++------
2 files changed, 7 insertions(+), 10 deletions(-)
--
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] 4+ messages in thread
* [PATCH net-next 1/2] net: stmmac: ptp: conditionally populate getcrosststamp() method
2025-09-03 14:00 [PATCH net-next 0/2] net: stmmac: correctly populate ptp_clock_ops.getcrosststamp Russell King (Oracle)
@ 2025-09-03 14:00 ` Russell King (Oracle)
2025-09-03 14:00 ` [PATCH net-next 2/2] net: stmmac: intel: only populate plat->crosststamp when supported Russell King (Oracle)
2025-09-03 18:38 ` [PATCH net-next 0/2] net: stmmac: correctly populate ptp_clock_ops.getcrosststamp Simon Horman
2 siblings, 0 replies; 4+ messages in thread
From: Russell King (Oracle) @ 2025-09-03 14:00 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Richard Cochran
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Coquelin,
netdev, Paolo Abeni
drivers/char/ptp_chardev.c::ptp_clock_getcaps() uses the presence of
the getcrosststamp() method to indicate to userspace whether
rosststamping is supported or not. Therefore, we should not provide
this method unless it is functional. Only set this method pointer
in stmmac_ptp_register() if the platform glue provides the
necessary functionality.
This does not mean that it will be supported (see intel_crosststamp(),
which is the only implementation that may have support) but at least
we won't be suggesting that it is supported on many platforms where
there is no hope.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
index 3767ba495e78..8b4cf1a31633 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
@@ -247,10 +247,7 @@ static int stmmac_get_syncdevicetime(ktime_t *device,
{
struct stmmac_priv *priv = (struct stmmac_priv *)ctx;
- if (priv->plat->crosststamp)
- return priv->plat->crosststamp(device, system, ctx);
- else
- return -EOPNOTSUPP;
+ return priv->plat->crosststamp(device, system, ctx);
}
static int stmmac_getcrosststamp(struct ptp_clock_info *ptp,
@@ -278,7 +275,6 @@ const struct ptp_clock_info stmmac_ptp_clock_ops = {
.gettime64 = stmmac_get_time,
.settime64 = stmmac_set_time,
.enable = stmmac_enable,
- .getcrosststamp = stmmac_getcrosststamp,
};
/* structure describing a PTP hardware clock */
@@ -296,7 +292,6 @@ const struct ptp_clock_info dwmac1000_ptp_clock_ops = {
.gettime64 = stmmac_get_time,
.settime64 = stmmac_set_time,
.enable = dwmac1000_ptp_enable,
- .getcrosststamp = stmmac_getcrosststamp,
};
/**
@@ -332,6 +327,9 @@ void stmmac_ptp_register(struct stmmac_priv *priv)
if (priv->plat->ptp_max_adj)
priv->ptp_clock_ops.max_adj = priv->plat->ptp_max_adj;
+ if (priv->plat->crosststamp)
+ priv->ptp_clock_ops.getcrosststamp = stmmac_getcrosststamp;
+
rwlock_init(&priv->ptp_lock);
mutex_init(&priv->aux_ts_lock);
--
2.47.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net-next 2/2] net: stmmac: intel: only populate plat->crosststamp when supported
2025-09-03 14:00 [PATCH net-next 0/2] net: stmmac: correctly populate ptp_clock_ops.getcrosststamp Russell King (Oracle)
2025-09-03 14:00 ` [PATCH net-next 1/2] net: stmmac: ptp: conditionally populate getcrosststamp() method Russell King (Oracle)
@ 2025-09-03 14:00 ` Russell King (Oracle)
2025-09-03 18:38 ` [PATCH net-next 0/2] net: stmmac: correctly populate ptp_clock_ops.getcrosststamp Simon Horman
2 siblings, 0 replies; 4+ messages in thread
From: Russell King (Oracle) @ 2025-09-03 14:00 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Richard Cochran
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Coquelin,
netdev, Paolo Abeni
To allow the ptp_chardev code to correctly detect whether crosststamps
are supported, we need to conditionally populate the .getcrosststamp()
method. As the previous patch implements that functionality by
detecting whether the platform glue provides a crosststamp() method,
arrange for the dwmac-intel code to only populate this if the X86
ART feature is present, rather than testing for it at runtime in
intel_crosststamp().
This reflects what other x86 PTP clock drivers do, e.g.
ice_ptp_set_funcs_e830(), e1000e_ptp_init(), idpf_ptp_set_caps() etc.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
index d900b93f46ce..e74d00984b88 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
@@ -371,9 +371,6 @@ static int intel_crosststamp(ktime_t *device,
u32 acr_value;
int i;
- if (!boot_cpu_has(X86_FEATURE_ART))
- return -EOPNOTSUPP;
-
intel_priv = priv->plat->bsp_priv;
/* Both internal crosstimestamping and external triggered event
@@ -756,7 +753,9 @@ static int intel_mgbe_common_data(struct pci_dev *pdev,
plat->int_snapshot_num = AUX_SNAPSHOT1;
- plat->crosststamp = intel_crosststamp;
+ if (boot_cpu_has(X86_FEATURE_ART))
+ plat->crosststamp = intel_crosststamp;
+
plat->flags &= ~STMMAC_FLAG_INT_SNAPSHOT_EN;
/* Setup MSI vector offset specific to Intel mGbE controller */
--
2.47.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next 0/2] net: stmmac: correctly populate ptp_clock_ops.getcrosststamp
2025-09-03 14:00 [PATCH net-next 0/2] net: stmmac: correctly populate ptp_clock_ops.getcrosststamp Russell King (Oracle)
2025-09-03 14:00 ` [PATCH net-next 1/2] net: stmmac: ptp: conditionally populate getcrosststamp() method Russell King (Oracle)
2025-09-03 14:00 ` [PATCH net-next 2/2] net: stmmac: intel: only populate plat->crosststamp when supported Russell King (Oracle)
@ 2025-09-03 18:38 ` Simon Horman
2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2025-09-03 18:38 UTC (permalink / raw)
To: Russell King (Oracle)
Cc: Andrew Lunn, Heiner Kallweit, Richard Cochran, Alexandre Torgue,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
linux-arm-kernel, linux-stm32, Maxime Coquelin, netdev,
Paolo Abeni
On Wed, Sep 03, 2025 at 03:00:16PM +0100, Russell King (Oracle) wrote:
> Hi,
>
> While reviewing code in the stmmac PTP driver, I noticed that the
> getcrosststamp() method is always populated, irrespective of whether
> it is implemented or not by the stmmac platform specific glue layer.
>
> Where a platform specific glue layer does not implement it, the core
> stmmac driver code returns -EOPNOTSUPP. However, the PTP clock core
> code uses the presence of the method in ptp_clock_ops to determine
> whether this facility should be advertised to userspace (see
> ptp_clock_getcaps()).
>
> Moreover, the only platform glue that implements this method is the
> Intel glue, and for it not to return -EOPNOTSUPP, the CPU has to
> support X86_FEATURE_ART.
>
> This series updates the core stmmac code to only provide the
> getcrosststamp() method in ptp_clock_ops when the platform glue code
> provides an implementation, and then updates the Intel glue code to
> only provide its implementation when the CPU has the necessary
> X86_FEATURE_ART feature.
>
> As I do not have an Intel card to test with, these changes are
> untested, so if anyone has such a card, please test. Thanks.
Hi Russell,
Although not strictly related to stmmac,
I am wondering if similar treatment is appropriate for:
* drivers/virtio/virtio_rtc_ptp.c:viortc_ptp_getcrosststamp
* drivers/net/ethernet/intel/ice/ice_ptp.c:ice_ptp_getcrosststamp
And if some sort of documentation of the behaviour you describe is
appropriate. Say in the Kernel doc for struct ptp_clock_info.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-03 18:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-03 14:00 [PATCH net-next 0/2] net: stmmac: correctly populate ptp_clock_ops.getcrosststamp Russell King (Oracle)
2025-09-03 14:00 ` [PATCH net-next 1/2] net: stmmac: ptp: conditionally populate getcrosststamp() method Russell King (Oracle)
2025-09-03 14:00 ` [PATCH net-next 2/2] net: stmmac: intel: only populate plat->crosststamp when supported Russell King (Oracle)
2025-09-03 18:38 ` [PATCH net-next 0/2] net: stmmac: correctly populate ptp_clock_ops.getcrosststamp Simon Horman
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).