* [PATCH net-next v3 00/10] ravb: Add gPTP support for Gen4
@ 2026-09-02 8:46 Niklas Söderlund
2026-09-02 8:46 ` [PATCH net-next v3 01/10] net: ethernet: ravb: Remove gPTP control from WoL setup and restore Niklas Söderlund
` (9 more replies)
0 siblings, 10 replies; 21+ messages in thread
From: Niklas Söderlund @ 2026-09-02 8:46 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Geert Uytterhoeven, Magnus Damm, Richard Cochran, Andrew Lunn,
DavidS. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vadim Fedorenko, Sergey Shtylyov, linux-renesas-soc, devicetree,
linux-kernel, netdev
Cc: Niklas Söderlund
Hello,
This series is the second part cleaning up how PTP timer support is
implemented on R-Car Gen4. Currently there is partial support for it in
some of the Ethernet devices that can use it, but not all.
On Gen2 and Gen3 each RAVB instance have it's own private PTP clock as
part of the RAVB register space. For this reason the PTP functionally
was implemented directly in the RAVB driver. For Gen4 however there is a
system-wide PTP clock shared by all RAVB instances, and on some Gen4
platforms with other Ethernet devices.
The RAVB Gen4 driver currently advertise PTP support to user-space, but
the support is in fact completely broken. It tries to use RAVB private
PTP clock, which do not exist on Gen4.
Further more the PTP clock behaved slightly different on Gen2 and Gen3.
These decencies have been handled by adding platform specific flags
inside the driver.
The usage of these flags have grown organically and been extended all
over the driver as it gained new features. Adding a new third set of
flags for Gen4 would be messy and add to the confusion.
Therefore patches 1/10 thru 8/10 refactors the usage of the PTP flags
into optional callbacks and untangles the usage. This allows adding Gen4
support easy as it can just implement it's own set of Gen4 specific
callbacks without altering the driver logic.
Patch 9/10 is a small DT binding addition adding an optional phandle to
link a RAVB device to the external PTP clock. Ideally this property
should be mandatory, but for backward comp ability is is made optional.
If the phandle is not set, or the PTP clock not enabled, the RAVB driver
will continue to faction as before, but no longer advertise PTP support
to user space.
Finally patch 10/10 adds the Gen4 specific PTP callbacks which allows
the driver to use the external PTP clock.
For part one of this work see [1]. The two series are independent of
each other but both are needed before a third series liking the RAVB to
the PTP clock in the platforms device tree. I will hold posting the
third series until all dependencies are merged. For this reason there is
no user of the new renesas,gptp device tree property added in this
series.
The work is tested on both Gen3 and Gen4 R-Car devices (with [1] and
appropriate DTS). I do however not have access to any Gen2 device where
the RAVB IP is wired to a MAC, so the small rework of the flags for Gen2
to callbacks have only been compiled tested. If anybody have a RZ device
where RAVB is wired and uses the Gen2 method of starting/stopping the
PTP timer together with the DMAC please test this.
1. https://lore.kernel.org/all/20260803095232.3527111-1-niklas.soderlund+renesas@ragnatech.se/
Niklas Söderlund (10):
net: ethernet: ravb: Remove gPTP control from WoL setup and restore
net: ethernet: ravb: Move programming of gPTP timer interval
net: ethernet: ravb: Simplify gPTP start and stop
net: ethernet: ravb: Remove redundant argument to ravb_ptp_init()
net: ethernet: ravb: Propagate error from ptp_clock_register()
net: ethernet: ravb: Replace gPTP flags with callbacks
net: ethernet: ravb: Add callback for gPTP probe
net: ethernet: ravb: Add callback for gPTP clock index
dt-bindings: net: renesas,etheravb: Add optional gPTP phandle for Gen4
net: ethernet: ravb: Add gPTP support for Gen4
.../bindings/net/renesas,etheravb.yaml | 11 +
drivers/net/ethernet/renesas/ravb.h | 35 ++-
drivers/net/ethernet/renesas/ravb_main.c | 249 ++++++++++++------
drivers/net/ethernet/renesas/ravb_ptp.c | 36 +--
4 files changed, 224 insertions(+), 107 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH net-next v3 01/10] net: ethernet: ravb: Remove gPTP control from WoL setup and restore
2026-09-02 8:46 [PATCH net-next v3 00/10] ravb: Add gPTP support for Gen4 Niklas Söderlund
@ 2026-09-02 8:46 ` Niklas Söderlund
2026-09-03 8:47 ` sashiko-bot
2026-09-02 8:46 ` [PATCH net-next v3 02/10] net: ethernet: ravb: Move programming of gPTP timer interval Niklas Söderlund
` (8 subsequent siblings)
9 siblings, 1 reply; 21+ messages in thread
From: Niklas Söderlund @ 2026-09-02 8:46 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Geert Uytterhoeven, Magnus Damm, Richard Cochran, Andrew Lunn,
DavidS. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vadim Fedorenko, Sergey Shtylyov, linux-renesas-soc, devicetree,
linux-kernel, netdev
Cc: Niklas Söderlund
Since commit a6a85ba36fd0 ("net: ravb: Move PTP initialization in the
driver's ndo_open API for ccc_gac platorms") the gPTP clock (if
supported) is stopped and started by opening and closing the ndev.
This makes the special case to stop and start it when resuming from WoL
redundant. As the ndev will always be closed and re-opened when
suspending and resuming the system.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Sergey Shtylyov <sergei.shtylyov@gmail.com>
---
drivers/net/ethernet/renesas/ravb_main.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index ea1c7e536791..36173a09e2fd 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -3182,9 +3182,6 @@ static int ravb_wol_setup(struct net_device *ndev)
/* Enable MagicPacket */
ravb_modify(ndev, ECMR, ECMR_MPDE, ECMR_MPDE);
- if (priv->info->ccc_gac)
- ravb_ptp_stop(ndev);
-
return enable_irq_wake(priv->emac_irq);
}
@@ -3204,9 +3201,6 @@ static int ravb_wol_restore(struct net_device *ndev)
if (error)
return error;
- if (priv->info->ccc_gac)
- ravb_ptp_init(ndev, priv->pdev);
-
if (info->nc_queues)
napi_enable(&priv->napi[RAVB_NC]);
napi_enable(&priv->napi[RAVB_BE]);
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v3 02/10] net: ethernet: ravb: Move programming of gPTP timer interval
2026-09-02 8:46 [PATCH net-next v3 00/10] ravb: Add gPTP support for Gen4 Niklas Söderlund
2026-09-02 8:46 ` [PATCH net-next v3 01/10] net: ethernet: ravb: Remove gPTP control from WoL setup and restore Niklas Söderlund
@ 2026-09-02 8:46 ` Niklas Söderlund
2026-09-03 8:47 ` sashiko-bot
2026-09-02 8:46 ` [PATCH net-next v3 03/10] net: ethernet: ravb: Simplify gPTP start and stop Niklas Söderlund
` (7 subsequent siblings)
9 siblings, 1 reply; 21+ messages in thread
From: Niklas Söderlund @ 2026-09-02 8:46 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Geert Uytterhoeven, Magnus Damm, Richard Cochran, Andrew Lunn,
DavidS. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vadim Fedorenko, Sergey Shtylyov, linux-renesas-soc, devicetree,
linux-kernel, netdev
Cc: Niklas Söderlund
Commit f384ab481cab ("net: ravb: Split GTI computation and set
operations") broke apart the operations of computing the timer interval
and programming of it. However it kept the programming of the interval
in the RAVB main logic.
Having split the two apart this can be improved further by moving the
programming to the gPTP initialization function, as the first action of
the gPTP init function is to wait for the timer interval programming to
be acknowledge by the hardware.
As an added bonus the interaction with the gPTP registers for the
programming can then also be done while holding the gPTP registers lock.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Sergey Shtylyov <sergei.shtylyov@gmail.com>
---
drivers/net/ethernet/renesas/ravb_main.c | 16 ----------------
drivers/net/ethernet/renesas/ravb_ptp.c | 11 ++++++++++-
2 files changed, 10 insertions(+), 17 deletions(-)
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 36173a09e2fd..a89f6fe7866f 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -1846,20 +1846,6 @@ static int ravb_set_config_mode(struct net_device *ndev)
return error;
}
-static void ravb_set_gti(struct net_device *ndev)
-{
- struct ravb_private *priv = netdev_priv(ndev);
- const struct ravb_hw_info *info = priv->info;
-
- if (!(info->gptp || info->ccc_gac))
- return;
-
- ravb_write(ndev, priv->gti_tiv, GTI);
-
- /* Request GTI loading */
- ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
-}
-
static int ravb_compute_gti(struct net_device *ndev)
{
struct ravb_private *priv = netdev_priv(ndev);
@@ -1974,8 +1960,6 @@ static int ravb_open(struct net_device *ndev)
ravb_emac_init(ndev);
- ravb_set_gti(ndev);
-
/* Initialise PTP Clock driver */
if (info->gptp || info->ccc_gac)
ravb_ptp_init(ndev, priv->pdev);
diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c
index 43218bc15b15..157fb78209c7 100644
--- a/drivers/net/ethernet/renesas/ravb_ptp.c
+++ b/drivers/net/ethernet/renesas/ravb_ptp.c
@@ -321,11 +321,20 @@ void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev)
priv->ptp.info = ravb_ptp_info;
- priv->ptp.default_addend = ravb_read(ndev, GTI);
+ priv->ptp.default_addend = priv->gti_tiv;
priv->ptp.current_addend = priv->ptp.default_addend;
spin_lock_irqsave(&priv->lock, flags);
+
+ /* Set gPTP Timer Increment Value. */
+ ravb_write(ndev, priv->ptp.default_addend, GTI);
+
+ /* Request GTI loading. */
+ ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
+
+ /* Wait for GIT loading to complete. */
ravb_wait(ndev, GCCR, GCCR_TCR, GCCR_TCR_NOREQ);
+
ravb_modify(ndev, GCCR, GCCR_TCSS, GCCR_TCSS_ADJGPTP);
spin_unlock_irqrestore(&priv->lock, flags);
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v3 03/10] net: ethernet: ravb: Simplify gPTP start and stop
2026-09-02 8:46 [PATCH net-next v3 00/10] ravb: Add gPTP support for Gen4 Niklas Söderlund
2026-09-02 8:46 ` [PATCH net-next v3 01/10] net: ethernet: ravb: Remove gPTP control from WoL setup and restore Niklas Söderlund
2026-09-02 8:46 ` [PATCH net-next v3 02/10] net: ethernet: ravb: Move programming of gPTP timer interval Niklas Söderlund
@ 2026-09-02 8:46 ` Niklas Söderlund
2026-09-03 8:47 ` sashiko-bot
2026-09-02 8:46 ` [PATCH net-next v3 04/10] net: ethernet: ravb: Remove redundant argument to ravb_ptp_init() Niklas Söderlund
` (6 subsequent siblings)
9 siblings, 1 reply; 21+ messages in thread
From: Niklas Söderlund @ 2026-09-02 8:46 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Geert Uytterhoeven, Magnus Damm, Richard Cochran, Andrew Lunn,
DavidS. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vadim Fedorenko, Sergey Shtylyov, linux-renesas-soc, devicetree,
linux-kernel, netdev
Cc: Niklas Söderlund
For devices that do not support the gPTP clock in config mode the
somewhat oddly named flag gptp is set, compared to devices that do
support the gPTP clock in config and operation mode where the flag
ccc_gac is set instead. The two flags are mutually exclusive.
For the gptp-flag devices (Gen2) the clock is tied to the AVB-DMAC, when
it is stopped so is the gPTP clock. For ccc_gac-flag devices (Gen3) the
gPTP clock is available whenever the ndev is open.
Prepare to add Gen4 support which will add a third way by cleaning the
Gen2 and Gen3 cases up a bit.
Fold the gptp-flag start and stop calls into ravb_dmac_init() and
ravb_stop_dma(), which start and stop the AVB-DMAC. There are no
functional change as all call sites to the construct:
if (info->gptp)
ravb_ptp_init(ndev, priv->pdev);
are always just after a call to into ravb_dmac_init() and all call sites
to the construct:
if (info->gptp)
ravb_ptp_stop(ndev);
are always directly followed by a call to ravb_stop_dma().
There are two special cases where the calling construct covers both the
gptp-flag and info->ccc_gac devices, one for start and one for stop. The
condition that it is preceded by a call to ravb_dmac_init(), or followed
by a call to ravb_stop_dma() are however true for them too. Reworked the
two special cases to drop the check of info->gptp.
The end result is that the gPTP clock will be started or stopped for the
gptp-flag devices in tandem with the AVB-DMAC, while the info->ccc_gac
devices will be controlled, as before, when the ndev is opened or
closed.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Sergey Shtylyov <sergei.shtylyov@gmail.com>
---
* Changes since v1
- Improve spelling in commit message.
---
drivers/net/ethernet/renesas/ravb_main.c | 37 ++++++++++--------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index a89f6fe7866f..2d0022a4f85c 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -707,7 +707,15 @@ static int ravb_dmac_init(struct net_device *ndev)
return error;
/* Setting the control will start the AVB-DMAC process. */
- return ravb_set_opmode(ndev, CCC_OPC_OPERATION);
+ error = ravb_set_opmode(ndev, CCC_OPC_OPERATION);
+ if (error)
+ return error;
+
+ /* Initialise PTP Clock driver */
+ if (info->gptp)
+ ravb_ptp_init(ndev, priv->pdev);
+
+ return 0;
}
static void ravb_get_tx_tstamp(struct net_device *ndev)
@@ -1115,6 +1123,10 @@ static int ravb_stop_dma(struct net_device *ndev)
netdev_err(ndev, "failed to stop AXI BUS\n");
}
+ /* Stop PTP Clock driver */
+ if (info->gptp)
+ ravb_ptp_stop(ndev);
+
/* Stop AVB-DMAC process */
return ravb_set_opmode(ndev, CCC_OPC_CONFIG);
}
@@ -1719,9 +1731,7 @@ static int ravb_set_ringparam(struct net_device *ndev,
if (netif_running(ndev)) {
netif_device_detach(ndev);
- /* Stop PTP Clock driver */
- if (info->gptp)
- ravb_ptp_stop(ndev);
+
/* Wait for DMA stopping */
error = ravb_stop_dma(ndev);
if (error) {
@@ -1752,10 +1762,6 @@ static int ravb_set_ringparam(struct net_device *ndev,
ravb_emac_init(ndev);
- /* Initialise PTP Clock driver */
- if (info->gptp)
- ravb_ptp_init(ndev, priv->pdev);
-
netif_device_attach(ndev);
}
@@ -1961,7 +1967,7 @@ static int ravb_open(struct net_device *ndev)
ravb_emac_init(ndev);
/* Initialise PTP Clock driver */
- if (info->gptp || info->ccc_gac)
+ if (info->ccc_gac)
ravb_ptp_init(ndev, priv->pdev);
/* PHY control start */
@@ -1974,9 +1980,6 @@ static int ravb_open(struct net_device *ndev)
return 0;
out_ptp_stop:
- /* Stop PTP Clock driver */
- if (info->gptp || info->ccc_gac)
- ravb_ptp_stop(ndev);
ravb_stop_dma(ndev);
out_set_reset:
ravb_set_opmode(ndev, CCC_OPC_RESET);
@@ -2020,10 +2023,6 @@ static void ravb_tx_timeout_work(struct work_struct *work)
netif_tx_stop_all_queues(ndev);
- /* Stop PTP Clock driver */
- if (info->gptp)
- ravb_ptp_stop(ndev);
-
/* Wait for DMA stopping */
if (ravb_stop_dma(ndev)) {
/* If ravb_stop_dma() fails, the hardware is still operating
@@ -2056,10 +2055,6 @@ static void ravb_tx_timeout_work(struct work_struct *work)
ravb_emac_init(ndev);
out:
- /* Initialise PTP Clock driver */
- if (info->gptp)
- ravb_ptp_init(ndev, priv->pdev);
-
netif_tx_start_all_queues(ndev);
out_unlock:
@@ -2374,7 +2369,7 @@ static int ravb_close(struct net_device *ndev)
}
/* Stop PTP Clock driver */
- if (info->gptp || info->ccc_gac)
+ if (info->ccc_gac)
ravb_ptp_stop(ndev);
/* Set the config mode to stop the AVB-DMAC's processes */
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v3 04/10] net: ethernet: ravb: Remove redundant argument to ravb_ptp_init()
2026-09-02 8:46 [PATCH net-next v3 00/10] ravb: Add gPTP support for Gen4 Niklas Söderlund
` (2 preceding siblings ...)
2026-09-02 8:46 ` [PATCH net-next v3 03/10] net: ethernet: ravb: Simplify gPTP start and stop Niklas Söderlund
@ 2026-09-02 8:46 ` Niklas Söderlund
2026-09-02 8:46 ` [PATCH net-next v3 05/10] net: ethernet: ravb: Propagate error from ptp_clock_register() Niklas Söderlund
` (5 subsequent siblings)
9 siblings, 0 replies; 21+ messages in thread
From: Niklas Söderlund @ 2026-09-02 8:46 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Geert Uytterhoeven, Magnus Damm, Richard Cochran, Andrew Lunn,
DavidS. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vadim Fedorenko, Sergey Shtylyov, linux-renesas-soc, devicetree,
linux-kernel, netdev
Cc: Niklas Söderlund
There is no need to explicitly pass the struct platform_device pointer
to ravb_ptp_init(), it can retrieve it directly from the private data
structure.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Sergey Shtylyov <sergei.shtylyov@gmail.com>
---
drivers/net/ethernet/renesas/ravb.h | 2 +-
drivers/net/ethernet/renesas/ravb_main.c | 4 ++--
drivers/net/ethernet/renesas/ravb_ptp.c | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h
index 3ee4c6108189..aa45f5466001 100644
--- a/drivers/net/ethernet/renesas/ravb.h
+++ b/drivers/net/ethernet/renesas/ravb.h
@@ -1163,7 +1163,7 @@ void ravb_modify(struct net_device *ndev, enum ravb_reg reg, u32 clear,
int ravb_wait(struct net_device *ndev, enum ravb_reg reg, u32 mask, u32 value);
void ravb_ptp_interrupt(struct net_device *ndev);
-void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev);
+void ravb_ptp_init(struct net_device *ndev);
void ravb_ptp_stop(struct net_device *ndev);
#endif /* #ifndef __RAVB_H__ */
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 2d0022a4f85c..e44d065f77cc 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -713,7 +713,7 @@ static int ravb_dmac_init(struct net_device *ndev)
/* Initialise PTP Clock driver */
if (info->gptp)
- ravb_ptp_init(ndev, priv->pdev);
+ ravb_ptp_init(ndev);
return 0;
}
@@ -1968,7 +1968,7 @@ static int ravb_open(struct net_device *ndev)
/* Initialise PTP Clock driver */
if (info->ccc_gac)
- ravb_ptp_init(ndev, priv->pdev);
+ ravb_ptp_init(ndev);
/* PHY control start */
error = ravb_phy_start(ndev);
diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c
index 157fb78209c7..f70b616ac847 100644
--- a/drivers/net/ethernet/renesas/ravb_ptp.c
+++ b/drivers/net/ethernet/renesas/ravb_ptp.c
@@ -313,7 +313,7 @@ void ravb_ptp_interrupt(struct net_device *ndev)
ravb_write(ndev, ~(gis | GIS_RESERVED), GIS);
}
-void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev)
+void ravb_ptp_init(struct net_device *ndev)
{
struct ravb_private *priv = netdev_priv(ndev);
struct ptp_clock *clock;
@@ -338,7 +338,7 @@ void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev)
ravb_modify(ndev, GCCR, GCCR_TCSS, GCCR_TCSS_ADJGPTP);
spin_unlock_irqrestore(&priv->lock, flags);
- clock = ptp_clock_register(&priv->ptp.info, &pdev->dev);
+ clock = ptp_clock_register(&priv->ptp.info, &priv->pdev->dev);
if (IS_ERR(clock)) {
netdev_err(ndev, "failed to register PTP clock: %pe\n", clock);
clock = NULL;
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v3 05/10] net: ethernet: ravb: Propagate error from ptp_clock_register()
2026-09-02 8:46 [PATCH net-next v3 00/10] ravb: Add gPTP support for Gen4 Niklas Söderlund
` (3 preceding siblings ...)
2026-09-02 8:46 ` [PATCH net-next v3 04/10] net: ethernet: ravb: Remove redundant argument to ravb_ptp_init() Niklas Söderlund
@ 2026-09-02 8:46 ` Niklas Söderlund
2026-09-03 8:47 ` sashiko-bot
2026-09-02 8:46 ` [PATCH net-next v3 06/10] net: ethernet: ravb: Replace gPTP flags with callbacks Niklas Söderlund
` (4 subsequent siblings)
9 siblings, 1 reply; 21+ messages in thread
From: Niklas Söderlund @ 2026-09-02 8:46 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Geert Uytterhoeven, Magnus Damm, Richard Cochran, Andrew Lunn,
DavidS. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vadim Fedorenko, Sergey Shtylyov, linux-renesas-soc, devicetree,
linux-kernel, netdev
Cc: Niklas Söderlund
If the PTP clock registration failed the error is silently ignored.
Before reworking all callers of ravb_ptp_init() handle and propagate the
error so it can be used.
Link: https://sashiko.dev/#/patchset/20260610102432.3538432-2-niklas.soderlund+renesas@ragnatech.se?part=1
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Sergey Shtylyov <sergei.shtylyov@gmail.com>
---
* Changes since v2
- Rework to remove the caching of phc_index added by LLM without access
to hardware.
* Changes since v1
- New in v2.
---
drivers/net/ethernet/renesas/ravb.h | 3 +--
drivers/net/ethernet/renesas/ravb_main.c | 3 +--
drivers/net/ethernet/renesas/ravb_ptp.c | 25 ++++++++++--------------
3 files changed, 12 insertions(+), 19 deletions(-)
diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h
index aa45f5466001..0c122a815840 100644
--- a/drivers/net/ethernet/renesas/ravb.h
+++ b/drivers/net/ethernet/renesas/ravb.h
@@ -1028,7 +1028,6 @@ struct ravb_ptp_perout {
struct ravb_ptp {
struct ptp_clock *clock;
struct ptp_clock_info info;
- int phc_index;
u32 default_addend;
u32 current_addend;
int extts[N_EXT_TS];
@@ -1163,7 +1162,7 @@ void ravb_modify(struct net_device *ndev, enum ravb_reg reg, u32 clear,
int ravb_wait(struct net_device *ndev, enum ravb_reg reg, u32 mask, u32 value);
void ravb_ptp_interrupt(struct net_device *ndev);
-void ravb_ptp_init(struct net_device *ndev);
+int ravb_ptp_init(struct net_device *ndev);
void ravb_ptp_stop(struct net_device *ndev);
#endif /* #ifndef __RAVB_H__ */
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index e44d065f77cc..7c7b3ac81e5d 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -1785,7 +1785,7 @@ static int ravb_get_ts_info(struct net_device *ndev,
(1 << HWTSTAMP_FILTER_NONE) |
(1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
(1 << HWTSTAMP_FILTER_ALL);
- info->phc_index = READ_ONCE(priv->ptp.phc_index);
+ info->phc_index = ptp_clock_index(priv->ptp.clock);
}
return 0;
@@ -2934,7 +2934,6 @@ static int ravb_probe(struct platform_device *pdev)
priv->rstc = rstc;
priv->ndev = ndev;
priv->pdev = pdev;
- priv->ptp.phc_index = -1;
priv->num_tx_ring[RAVB_BE] = BE_TX_RING_SIZE;
priv->num_rx_ring[RAVB_BE] = BE_RX_RING_SIZE;
if (info->nc_queues) {
diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c
index f70b616ac847..19d039b9d24a 100644
--- a/drivers/net/ethernet/renesas/ravb_ptp.c
+++ b/drivers/net/ethernet/renesas/ravb_ptp.c
@@ -313,11 +313,11 @@ void ravb_ptp_interrupt(struct net_device *ndev)
ravb_write(ndev, ~(gis | GIS_RESERVED), GIS);
}
-void ravb_ptp_init(struct net_device *ndev)
+int ravb_ptp_init(struct net_device *ndev)
{
struct ravb_private *priv = netdev_priv(ndev);
- struct ptp_clock *clock;
unsigned long flags;
+ int ret = 0;
priv->ptp.info = ravb_ptp_info;
@@ -338,15 +338,14 @@ void ravb_ptp_init(struct net_device *ndev)
ravb_modify(ndev, GCCR, GCCR_TCSS, GCCR_TCSS_ADJGPTP);
spin_unlock_irqrestore(&priv->lock, flags);
- clock = ptp_clock_register(&priv->ptp.info, &priv->pdev->dev);
- if (IS_ERR(clock)) {
- netdev_err(ndev, "failed to register PTP clock: %pe\n", clock);
- clock = NULL;
+ priv->ptp.clock = ptp_clock_register(&priv->ptp.info, &priv->pdev->dev);
+ if (IS_ERR(priv->ptp.clock)) {
+ ret = PTR_ERR(priv->ptp.clock);
+ priv->ptp.clock = NULL;
+ ravb_ptp_stop(ndev);
}
- WRITE_ONCE(priv->ptp.clock, clock);
- if (clock)
- WRITE_ONCE(priv->ptp.phc_index, ptp_clock_index(clock));
+ return ret;
}
static void ravb_ptp_disable(struct net_device *ndev)
@@ -369,14 +368,10 @@ static void ravb_ptp_sync_irqs(struct net_device *ndev)
void ravb_ptp_stop(struct net_device *ndev)
{
struct ravb_private *priv = netdev_priv(ndev);
- struct ptp_clock *clock;
-
- WRITE_ONCE(priv->ptp.phc_index, -1);
- clock = xchg(&priv->ptp.clock, NULL);
ravb_ptp_disable(ndev);
ravb_ptp_sync_irqs(ndev);
- if (clock)
- ptp_clock_unregister(clock);
+ if (priv->ptp.clock)
+ ptp_clock_unregister(priv->ptp.clock);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v3 06/10] net: ethernet: ravb: Replace gPTP flags with callbacks
2026-09-02 8:46 [PATCH net-next v3 00/10] ravb: Add gPTP support for Gen4 Niklas Söderlund
` (4 preceding siblings ...)
2026-09-02 8:46 ` [PATCH net-next v3 05/10] net: ethernet: ravb: Propagate error from ptp_clock_register() Niklas Söderlund
@ 2026-09-02 8:46 ` Niklas Söderlund
2026-09-03 8:47 ` sashiko-bot
2026-09-02 8:47 ` [PATCH net-next v3 07/10] net: ethernet: ravb: Add callback for gPTP probe Niklas Söderlund
` (3 subsequent siblings)
9 siblings, 1 reply; 21+ messages in thread
From: Niklas Söderlund @ 2026-09-02 8:46 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Geert Uytterhoeven, Magnus Damm, Richard Cochran, Andrew Lunn,
DavidS. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vadim Fedorenko, Sergey Shtylyov, linux-renesas-soc, devicetree,
linux-kernel, netdev
Cc: Niklas Söderlund
Prepare for adding Gen4 support which will add a third and new way to
interact with the gPTP clock by replacing the flags for Gen2 behavior
(info->gptp) and Gen3 behavior (info->ccc_gac) with callbacks.
This will make adding Gen4 support cleaner as the code will not have "if
else if else" sprinkled all over to handle each generations special
cases.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Sergey Shtylyov <sergei.shtylyov@gmail.com>
---
* Changes since v1
- Handle error from starting the PTP clock.
---
drivers/net/ethernet/renesas/ravb.h | 24 ++++++-
drivers/net/ethernet/renesas/ravb_main.c | 83 +++++++++++++++---------
2 files changed, 76 insertions(+), 31 deletions(-)
diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h
index 0c122a815840..6603f90b19e1 100644
--- a/drivers/net/ethernet/renesas/ravb.h
+++ b/drivers/net/ethernet/renesas/ravb.h
@@ -1034,6 +1034,27 @@ struct ravb_ptp {
struct ravb_ptp_perout perout[N_PER_OUT];
};
+/**
+ * struct ravb_gptp_info - Platform specific gPTP behavior
+ *
+ * Each generation of RAVB have slightly different behaviors when interacting
+ * with the gPTP clock. This struct provides the callbacks to be called at
+ * critical points in the RAVB driver.
+ *
+ * @set_config_mode: Enter config mode
+ * @dmac_start: Called when the DMAC starts
+ * @dmac_stop: Called when the DMAC stops
+ * @ndev_open: Called when the ndev is opened
+ * @ndev_close: Called when the ndev is closed
+ */
+struct ravb_gptp_info {
+ int (*set_config_mode)(struct net_device *ndev);
+ int (*dmac_start)(struct net_device *ndev);
+ void (*dmac_stop)(struct net_device *ndev);
+ int (*ndev_open)(struct net_device *ndev);
+ void (*ndev_close)(struct net_device *ndev);
+};
+
struct ravb_hw_info {
int (*receive)(struct net_device *ndev, int budget, int q);
void (*set_rate)(struct net_device *ndev);
@@ -1052,6 +1073,7 @@ struct ravb_hw_info {
u32 rx_buffer_size;
u32 rx_desc_size;
u32 dbat_entry_num;
+ const struct ravb_gptp_info *ptp; /* Callbacks to handle gPTP interactions. */
unsigned aligned_tx: 1;
unsigned coalesce_irqs:1; /* Needs software IRQ coalescing */
@@ -1062,8 +1084,6 @@ struct ravb_hw_info {
unsigned multi_irqs:1; /* AVB-DMAC and E-MAC has multiple irqs */
unsigned irq_en_dis:1; /* Has separate irq enable and disable regs */
unsigned err_mgmt_irqs:1; /* Line1 (Err) and Line2 (Mgmt) irqs are separate */
- unsigned gptp:1; /* AVB-DMAC has gPTP support */
- unsigned ccc_gac:1; /* AVB-DMAC has gPTP support active in config mode */
unsigned gptp_ref_clk:1; /* gPTP has separate reference clock */
unsigned nc_queues:1; /* AVB-DMAC has RX and TX NC queues */
unsigned magic_pkt:1; /* E-MAC supports magic packet detection */
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 7c7b3ac81e5d..5d5b9c0e2f45 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -712,8 +712,8 @@ static int ravb_dmac_init(struct net_device *ndev)
return error;
/* Initialise PTP Clock driver */
- if (info->gptp)
- ravb_ptp_init(ndev);
+ if (info->ptp && info->ptp->dmac_start)
+ return info->ptp->dmac_start(ndev);
return 0;
}
@@ -1124,8 +1124,8 @@ static int ravb_stop_dma(struct net_device *ndev)
}
/* Stop PTP Clock driver */
- if (info->gptp)
- ravb_ptp_stop(ndev);
+ if (info->ptp && info->ptp->dmac_stop)
+ info->ptp->dmac_stop(ndev);
/* Stop AVB-DMAC process */
return ravb_set_opmode(ndev, CCC_OPC_CONFIG);
@@ -1774,7 +1774,7 @@ static int ravb_get_ts_info(struct net_device *ndev,
struct ravb_private *priv = netdev_priv(ndev);
const struct ravb_hw_info *hw_info = priv->info;
- if (hw_info->gptp || hw_info->ccc_gac) {
+ if (hw_info->ptp) {
info->so_timestamping =
SOF_TIMESTAMPING_TX_SOFTWARE |
SOF_TIMESTAMPING_TX_HARDWARE |
@@ -1835,21 +1835,11 @@ static int ravb_set_config_mode(struct net_device *ndev)
{
struct ravb_private *priv = netdev_priv(ndev);
const struct ravb_hw_info *info = priv->info;
- int error;
- if (info->gptp) {
- error = ravb_set_opmode(ndev, CCC_OPC_CONFIG);
- if (error)
- return error;
- /* Set CSEL value */
- ravb_modify(ndev, CCC, CCC_CSEL, CCC_CSEL_HPB);
- } else if (info->ccc_gac) {
- error = ravb_set_opmode(ndev, CCC_OPC_CONFIG | CCC_GAC | CCC_CSEL_HPB);
- } else {
- error = ravb_set_opmode(ndev, CCC_OPC_CONFIG);
- }
+ if (info->ptp && info->ptp->set_config_mode)
+ return info->ptp->set_config_mode(ndev);
- return error;
+ return ravb_set_opmode(ndev, CCC_OPC_CONFIG);
}
static int ravb_compute_gti(struct net_device *ndev)
@@ -1860,7 +1850,7 @@ static int ravb_compute_gti(struct net_device *ndev)
unsigned long rate;
u64 inc;
- if (!(info->gptp || info->ccc_gac))
+ if (!info->ptp)
return 0;
if (info->gptp_ref_clk)
@@ -1967,8 +1957,11 @@ static int ravb_open(struct net_device *ndev)
ravb_emac_init(ndev);
/* Initialise PTP Clock driver */
- if (info->ccc_gac)
- ravb_ptp_init(ndev);
+ if (info->ptp && info->ptp->ndev_open) {
+ error = info->ptp->ndev_open(ndev);
+ if (error)
+ goto out_ptp_stop;
+ }
/* PHY control start */
error = ravb_phy_start(ndev);
@@ -2187,7 +2180,7 @@ static netdev_tx_t ravb_start_xmit(struct sk_buff *skb, struct net_device *ndev)
desc->dptr = cpu_to_le32(dma_addr);
/* TX timestamp required */
- if (info->gptp || info->ccc_gac) {
+ if (info->ptp) {
if (q == RAVB_NC) {
ts_skb = kmalloc_obj(*ts_skb, GFP_ATOMIC);
if (!ts_skb) {
@@ -2369,8 +2362,8 @@ static int ravb_close(struct net_device *ndev)
}
/* Stop PTP Clock driver */
- if (info->ccc_gac)
- ravb_ptp_stop(ndev);
+ if (info->ptp && info->ptp->ndev_close)
+ info->ptp->ndev_close(ndev);
/* Set the config mode to stop the AVB-DMAC's processes */
if (ravb_stop_dma(ndev) < 0)
@@ -2378,7 +2371,7 @@ static int ravb_close(struct net_device *ndev)
"device will be stopped after h/w processes are done.\n");
/* Clear the timestamp list */
- if (info->gptp || info->ccc_gac) {
+ if (info->ptp) {
list_for_each_entry_safe(ts_skb, ts_skb2, &priv->ts_skb_list, list) {
list_del(&ts_skb->list);
kfree_skb(ts_skb->skb);
@@ -2660,6 +2653,26 @@ static int ravb_mdio_release(struct ravb_private *priv)
return 0;
}
+static int ravb_gen2_ptp_set_config_mode(struct net_device *ndev)
+{
+ int ret;
+
+ ret = ravb_set_opmode(ndev, CCC_OPC_CONFIG);
+ if (ret)
+ return ret;
+
+ /* gPTP Clock Select High-speed peripheral bus clock. */
+ ravb_modify(ndev, CCC, CCC_CSEL, CCC_CSEL_HPB);
+
+ return 0;
+}
+
+static const struct ravb_gptp_info ravb_gen2_ptp_info = {
+ .set_config_mode = ravb_gen2_ptp_set_config_mode,
+ .dmac_start = ravb_ptp_init,
+ .dmac_stop = ravb_ptp_stop,
+};
+
static const struct ravb_hw_info ravb_gen2_hw_info = {
.receive = ravb_rx_rcar,
.set_rate = ravb_set_rate_rcar,
@@ -2678,12 +2691,24 @@ static const struct ravb_hw_info ravb_gen2_hw_info = {
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)),
.rx_desc_size = sizeof(struct ravb_ex_rx_desc),
.dbat_entry_num = 22,
+ .ptp = &ravb_gen2_ptp_info,
.aligned_tx = 1,
- .gptp = 1,
.nc_queues = 1,
.magic_pkt = 1,
};
+static int ravb_gen3_ptp_set_config_mode(struct net_device *ndev)
+{
+ /* Enable gPTP Clock and Select High-speed peripheral bus clock. */
+ return ravb_set_opmode(ndev, CCC_OPC_CONFIG | CCC_GAC | CCC_CSEL_HPB);
+}
+
+static const struct ravb_gptp_info ravb_gen3_ptp_info = {
+ .set_config_mode = ravb_gen3_ptp_set_config_mode,
+ .ndev_open = ravb_ptp_init,
+ .ndev_close = ravb_ptp_stop,
+};
+
static const struct ravb_hw_info ravb_gen3_hw_info = {
.receive = ravb_rx_rcar,
.set_rate = ravb_set_rate_rcar,
@@ -2702,11 +2727,11 @@ static const struct ravb_hw_info ravb_gen3_hw_info = {
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)),
.rx_desc_size = sizeof(struct ravb_ex_rx_desc),
.dbat_entry_num = 22,
+ .ptp = &ravb_gen3_ptp_info,
.internal_delay = 1,
.tx_counters = 1,
.multi_irqs = 1,
.irq_en_dis = 1,
- .ccc_gac = 1,
.nc_queues = 1,
.magic_pkt = 1,
};
@@ -2733,7 +2758,7 @@ static const struct ravb_hw_info ravb_gen4_hw_info = {
.tx_counters = 1,
.multi_irqs = 1,
.irq_en_dis = 1,
- .ccc_gac = 1,
+ .ptp = &ravb_gen3_ptp_info,
.nc_queues = 1,
.magic_pkt = 1,
};
@@ -2758,7 +2783,7 @@ static const struct ravb_hw_info ravb_rzv2m_hw_info = {
.dbat_entry_num = 22,
.multi_irqs = 1,
.err_mgmt_irqs = 1,
- .gptp = 1,
+ .ptp = &ravb_gen2_ptp_info,
.gptp_ref_clk = 1,
.nc_queues = 1,
.magic_pkt = 1,
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v3 07/10] net: ethernet: ravb: Add callback for gPTP probe
2026-09-02 8:46 [PATCH net-next v3 00/10] ravb: Add gPTP support for Gen4 Niklas Söderlund
` (5 preceding siblings ...)
2026-09-02 8:46 ` [PATCH net-next v3 06/10] net: ethernet: ravb: Replace gPTP flags with callbacks Niklas Söderlund
@ 2026-09-02 8:47 ` Niklas Söderlund
2026-09-03 8:47 ` sashiko-bot
2026-09-02 8:47 ` [PATCH net-next v3 08/10] net: ethernet: ravb: Add callback for gPTP clock index Niklas Söderlund
` (2 subsequent siblings)
9 siblings, 1 reply; 21+ messages in thread
From: Niklas Söderlund @ 2026-09-02 8:47 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Geert Uytterhoeven, Magnus Damm, Richard Cochran, Andrew Lunn,
DavidS. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vadim Fedorenko, Sergey Shtylyov, linux-renesas-soc, devicetree,
linux-kernel, netdev
Cc: Niklas Söderlund
Different generations of the RAVB IP have different needs when it probes
the gPTP timer clock. Add a callback in the PTP information to allow
each generation to probe its own way.
With this the last gPTP specific flag (gptp_ref_clk) can be removed.
However the primary motivation for the change is to prepare for Gen4
support, which compared to other generations with gPTP support does not
have the clock as part of the IP itself.
Gen4 will not need to compute GTI value as it have nowhere to write it,
as the gPTP clock is external. For this reason move the computation of
it into the newly gPTP probe specific callbacks for the RAVB IP's that
support it.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Sergey Shtylyov <sergei.shtylyov@gmail.com>
---
* Changes since v1
- Improve spelling in commit message.
---
drivers/net/ethernet/renesas/ravb.h | 3 +-
drivers/net/ethernet/renesas/ravb_main.c | 53 +++++++++++++++---------
2 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h
index 6603f90b19e1..b788e8f5260d 100644
--- a/drivers/net/ethernet/renesas/ravb.h
+++ b/drivers/net/ethernet/renesas/ravb.h
@@ -1041,6 +1041,7 @@ struct ravb_ptp {
* with the gPTP clock. This struct provides the callbacks to be called at
* critical points in the RAVB driver.
*
+ * @probe: Probe the gPTP clock
* @set_config_mode: Enter config mode
* @dmac_start: Called when the DMAC starts
* @dmac_stop: Called when the DMAC stops
@@ -1048,6 +1049,7 @@ struct ravb_ptp {
* @ndev_close: Called when the ndev is closed
*/
struct ravb_gptp_info {
+ int (*probe)(struct net_device *ndev);
int (*set_config_mode)(struct net_device *ndev);
int (*dmac_start)(struct net_device *ndev);
void (*dmac_stop)(struct net_device *ndev);
@@ -1084,7 +1086,6 @@ struct ravb_hw_info {
unsigned multi_irqs:1; /* AVB-DMAC and E-MAC has multiple irqs */
unsigned irq_en_dis:1; /* Has separate irq enable and disable regs */
unsigned err_mgmt_irqs:1; /* Line1 (Err) and Line2 (Mgmt) irqs are separate */
- unsigned gptp_ref_clk:1; /* gPTP has separate reference clock */
unsigned nc_queues:1; /* AVB-DMAC has RX and TX NC queues */
unsigned magic_pkt:1; /* E-MAC supports magic packet detection */
unsigned half_duplex:1; /* E-MAC supports half duplex mode */
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 5d5b9c0e2f45..7e53eca5327f 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -1842,21 +1842,14 @@ static int ravb_set_config_mode(struct net_device *ndev)
return ravb_set_opmode(ndev, CCC_OPC_CONFIG);
}
-static int ravb_compute_gti(struct net_device *ndev)
+static int ravb_compute_gti(struct net_device *ndev, struct clk *clk)
{
struct ravb_private *priv = netdev_priv(ndev);
- const struct ravb_hw_info *info = priv->info;
struct device *dev = ndev->dev.parent;
unsigned long rate;
u64 inc;
- if (!info->ptp)
- return 0;
-
- if (info->gptp_ref_clk)
- rate = clk_get_rate(priv->gptp_clk);
- else
- rate = clk_get_rate(priv->clk);
+ rate = clk_get_rate(clk);
if (!rate)
return -EINVAL;
@@ -2653,6 +2646,13 @@ static int ravb_mdio_release(struct ravb_private *priv)
return 0;
}
+static int ravb_gen2_ptp_probe(struct net_device *ndev)
+{
+ struct ravb_private *priv = netdev_priv(ndev);
+
+ return ravb_compute_gti(ndev, priv->clk);
+}
+
static int ravb_gen2_ptp_set_config_mode(struct net_device *ndev)
{
int ret;
@@ -2668,6 +2668,7 @@ static int ravb_gen2_ptp_set_config_mode(struct net_device *ndev)
}
static const struct ravb_gptp_info ravb_gen2_ptp_info = {
+ .probe = ravb_gen2_ptp_probe,
.set_config_mode = ravb_gen2_ptp_set_config_mode,
.dmac_start = ravb_ptp_init,
.dmac_stop = ravb_ptp_stop,
@@ -2704,6 +2705,7 @@ static int ravb_gen3_ptp_set_config_mode(struct net_device *ndev)
}
static const struct ravb_gptp_info ravb_gen3_ptp_info = {
+ .probe = ravb_gen2_ptp_probe,
.set_config_mode = ravb_gen3_ptp_set_config_mode,
.ndev_open = ravb_ptp_init,
.ndev_close = ravb_ptp_stop,
@@ -2763,6 +2765,24 @@ static const struct ravb_hw_info ravb_gen4_hw_info = {
.magic_pkt = 1,
};
+static int ravb_rzv2m_ptp_probe(struct net_device *ndev)
+{
+ struct ravb_private *priv = netdev_priv(ndev);
+
+ priv->gptp_clk = devm_clk_get(&priv->pdev->dev, "gptp");
+ if (IS_ERR(priv->gptp_clk))
+ return PTR_ERR(priv->gptp_clk);
+
+ return ravb_compute_gti(ndev, priv->gptp_clk);
+}
+
+static const struct ravb_gptp_info ravb_rzv2m_ptp_info = {
+ .probe = ravb_rzv2m_ptp_probe,
+ .set_config_mode = ravb_gen2_ptp_set_config_mode,
+ .dmac_start = ravb_ptp_init,
+ .dmac_stop = ravb_ptp_stop,
+};
+
static const struct ravb_hw_info ravb_rzv2m_hw_info = {
.receive = ravb_rx_rcar,
.set_rate = ravb_set_rate_rcar,
@@ -2783,8 +2803,7 @@ static const struct ravb_hw_info ravb_rzv2m_hw_info = {
.dbat_entry_num = 22,
.multi_irqs = 1,
.err_mgmt_irqs = 1,
- .ptp = &ravb_gen2_ptp_info,
- .gptp_ref_clk = 1,
+ .ptp = &ravb_rzv2m_ptp_info,
.nc_queues = 1,
.magic_pkt = 1,
};
@@ -2976,12 +2995,10 @@ static int ravb_probe(struct platform_device *pdev)
goto out_reset_assert;
}
- if (info->gptp_ref_clk) {
- priv->gptp_clk = devm_clk_get(&pdev->dev, "gptp");
- if (IS_ERR(priv->gptp_clk)) {
- error = PTR_ERR(priv->gptp_clk);
+ if (info->ptp && info->ptp->probe) {
+ error = info->ptp->probe(ndev);
+ if (error)
goto out_reset_assert;
- }
}
priv->refclk = devm_clk_get_optional(&pdev->dev, "refclk");
@@ -3034,10 +3051,6 @@ static int ravb_probe(struct platform_device *pdev)
ndev->netdev_ops = &ravb_netdev_ops;
ndev->ethtool_ops = &ravb_ethtool_ops;
- error = ravb_compute_gti(ndev);
- if (error)
- goto out_rpm_put;
-
ravb_parse_delay_mode(np, ndev);
/* Allocate descriptor base address table */
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v3 08/10] net: ethernet: ravb: Add callback for gPTP clock index
2026-09-02 8:46 [PATCH net-next v3 00/10] ravb: Add gPTP support for Gen4 Niklas Söderlund
` (6 preceding siblings ...)
2026-09-02 8:47 ` [PATCH net-next v3 07/10] net: ethernet: ravb: Add callback for gPTP probe Niklas Söderlund
@ 2026-09-02 8:47 ` Niklas Söderlund
2026-09-03 8:47 ` sashiko-bot
2026-09-02 8:47 ` [PATCH net-next v3 09/10] dt-bindings: net: renesas,etheravb: Add optional gPTP phandle for Gen4 Niklas Söderlund
2026-09-02 8:47 ` [PATCH net-next v3 10/10] net: ethernet: ravb: Add gPTP support " Niklas Söderlund
9 siblings, 1 reply; 21+ messages in thread
From: Niklas Söderlund @ 2026-09-02 8:47 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Geert Uytterhoeven, Magnus Damm, Richard Cochran, Andrew Lunn,
DavidS. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vadim Fedorenko, Sergey Shtylyov, linux-renesas-soc, devicetree,
linux-kernel, netdev
Cc: Niklas Söderlund
Prepare for adding Gen4 support which have an optional external gPTP
clock. Add a callback to get the clock index and use it to determine if
the device shall report gPTP support.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Sergey Shtylyov <sergei.shtylyov@gmail.com>
---
drivers/net/ethernet/renesas/ravb.h | 2 ++
drivers/net/ethernet/renesas/ravb_main.c | 19 +++++++++++++++++--
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h
index b788e8f5260d..27e2b31955ba 100644
--- a/drivers/net/ethernet/renesas/ravb.h
+++ b/drivers/net/ethernet/renesas/ravb.h
@@ -1042,6 +1042,7 @@ struct ravb_ptp {
* critical points in the RAVB driver.
*
* @probe: Probe the gPTP clock
+ * @clock_index: Get the PTP clock index, if any
* @set_config_mode: Enter config mode
* @dmac_start: Called when the DMAC starts
* @dmac_stop: Called when the DMAC stops
@@ -1050,6 +1051,7 @@ struct ravb_ptp {
*/
struct ravb_gptp_info {
int (*probe)(struct net_device *ndev);
+ int (*clock_index)(struct net_device *ndev);
int (*set_config_mode)(struct net_device *ndev);
int (*dmac_start)(struct net_device *ndev);
void (*dmac_stop)(struct net_device *ndev);
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 7e53eca5327f..402370e1be63 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -1773,8 +1773,13 @@ static int ravb_get_ts_info(struct net_device *ndev,
{
struct ravb_private *priv = netdev_priv(ndev);
const struct ravb_hw_info *hw_info = priv->info;
+ int index = -1;
- if (hw_info->ptp) {
+ if (hw_info->ptp && hw_info->ptp->clock_index)
+ index = hw_info->ptp->clock_index(ndev);
+
+ /* Only advertise ptp clock if present. */
+ if (index >= 0) {
info->so_timestamping =
SOF_TIMESTAMPING_TX_SOFTWARE |
SOF_TIMESTAMPING_TX_HARDWARE |
@@ -1785,7 +1790,7 @@ static int ravb_get_ts_info(struct net_device *ndev,
(1 << HWTSTAMP_FILTER_NONE) |
(1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
(1 << HWTSTAMP_FILTER_ALL);
- info->phc_index = ptp_clock_index(priv->ptp.clock);
+ info->phc_index = index;
}
return 0;
@@ -2653,6 +2658,13 @@ static int ravb_gen2_ptp_probe(struct net_device *ndev)
return ravb_compute_gti(ndev, priv->clk);
}
+static int ravb_gen2_ptp_clock_index(struct net_device *ndev)
+{
+ struct ravb_private *priv = netdev_priv(ndev);
+
+ return ptp_clock_index(priv->ptp.clock);
+}
+
static int ravb_gen2_ptp_set_config_mode(struct net_device *ndev)
{
int ret;
@@ -2669,6 +2681,7 @@ static int ravb_gen2_ptp_set_config_mode(struct net_device *ndev)
static const struct ravb_gptp_info ravb_gen2_ptp_info = {
.probe = ravb_gen2_ptp_probe,
+ .clock_index = ravb_gen2_ptp_clock_index,
.set_config_mode = ravb_gen2_ptp_set_config_mode,
.dmac_start = ravb_ptp_init,
.dmac_stop = ravb_ptp_stop,
@@ -2706,6 +2719,7 @@ static int ravb_gen3_ptp_set_config_mode(struct net_device *ndev)
static const struct ravb_gptp_info ravb_gen3_ptp_info = {
.probe = ravb_gen2_ptp_probe,
+ .clock_index = ravb_gen2_ptp_clock_index,
.set_config_mode = ravb_gen3_ptp_set_config_mode,
.ndev_open = ravb_ptp_init,
.ndev_close = ravb_ptp_stop,
@@ -2778,6 +2792,7 @@ static int ravb_rzv2m_ptp_probe(struct net_device *ndev)
static const struct ravb_gptp_info ravb_rzv2m_ptp_info = {
.probe = ravb_rzv2m_ptp_probe,
+ .clock_index = ravb_gen2_ptp_clock_index,
.set_config_mode = ravb_gen2_ptp_set_config_mode,
.dmac_start = ravb_ptp_init,
.dmac_stop = ravb_ptp_stop,
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v3 09/10] dt-bindings: net: renesas,etheravb: Add optional gPTP phandle for Gen4
2026-09-02 8:46 [PATCH net-next v3 00/10] ravb: Add gPTP support for Gen4 Niklas Söderlund
` (7 preceding siblings ...)
2026-09-02 8:47 ` [PATCH net-next v3 08/10] net: ethernet: ravb: Add callback for gPTP clock index Niklas Söderlund
@ 2026-09-02 8:47 ` Niklas Söderlund
2026-09-02 8:47 ` [PATCH net-next v3 10/10] net: ethernet: ravb: Add gPTP support " Niklas Söderlund
9 siblings, 0 replies; 21+ messages in thread
From: Niklas Söderlund @ 2026-09-02 8:47 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Geert Uytterhoeven, Magnus Damm, Richard Cochran, Andrew Lunn,
DavidS. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vadim Fedorenko, Sergey Shtylyov, linux-renesas-soc, devicetree,
linux-kernel, netdev
Cc: Niklas Söderlund, Krzysztof Kozlowski
The RAVB module on Gen4 have no gPTP clock as part of the RAVB module
itself, instead it relies on an external system wide gPTP clock. The
gPTP clock is shared with RTSN on V4H and RSWITCH on S4.
Add an optional phandle so that the RAVB driver can find and use the
gPTP clock. Ideally this should have been a mandatory property but for
backward compatible it is optional. The RAVB module is capable of
functioning without it, but can in such cases not provided PTP
functionality.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Sergey Shtylyov <sergei.shtylyov@gmail.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
* Changes since v1
- Use generic ptp-timer property instead of vendor specific one.
- Improve spelling in commit message.
---
.../devicetree/bindings/net/renesas,etheravb.yaml | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/Documentation/devicetree/bindings/net/renesas,etheravb.yaml b/Documentation/devicetree/bindings/net/renesas,etheravb.yaml
index 1e00ef5b3acd..fad002492421 100644
--- a/Documentation/devicetree/bindings/net/renesas,etheravb.yaml
+++ b/Documentation/devicetree/bindings/net/renesas,etheravb.yaml
@@ -97,6 +97,8 @@ properties:
phy-handle: true
+ ptp-timer: true
+
'#address-cells':
description: Number of address cells for the MDIO bus.
const: 1
@@ -305,6 +307,15 @@ allOf:
items:
- const: fck
- const: refclk
+ - if:
+ not:
+ properties:
+ compatible:
+ contains:
+ const: renesas,etheravb-rcar-gen4
+ then:
+ properties:
+ ptp-timer: false
additionalProperties: false
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH net-next v3 10/10] net: ethernet: ravb: Add gPTP support for Gen4
2026-09-02 8:46 [PATCH net-next v3 00/10] ravb: Add gPTP support for Gen4 Niklas Söderlund
` (8 preceding siblings ...)
2026-09-02 8:47 ` [PATCH net-next v3 09/10] dt-bindings: net: renesas,etheravb: Add optional gPTP phandle for Gen4 Niklas Söderlund
@ 2026-09-02 8:47 ` Niklas Söderlund
2026-09-03 8:48 ` sashiko-bot
9 siblings, 1 reply; 21+ messages in thread
From: Niklas Söderlund @ 2026-09-02 8:47 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Geert Uytterhoeven, Magnus Damm, Richard Cochran, Andrew Lunn,
DavidS. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Vadim Fedorenko, Sergey Shtylyov, linux-renesas-soc, devicetree,
linux-kernel, netdev
Cc: Niklas Söderlund
While driver advertises gPTP support on Gen4 platforms it is in fact
completely broken. On R-Car Gen4 devices the RAVB module have no
internal gPTP clock as generations before it. Instead it utilizes a
system-wide gPTP clock.
This change utilizes the refactoring of the RAVB gPTP code to add
support for a system-wide clock and stops the Gen4 devices trying to use
the non-existing internal gPTP clock.
To remain backward compatible the ptp-timer property is optional.If not
present, or not enabled, the RAVB driver will no longer advertise gPTP
support to user-space.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Sergey Shtylyov <sergei.shtylyov@gmail.com>
---
* Changes since v2
- Use full 100 character width instead of breaking at 80.
- Remove superfluous return statement.
* Changes since v1
- Use the standard generic ptp-timer property from
ethernet-controller.yaml instead of a vendor specific one.
- Improve spelling in commit message.
---
drivers/net/ethernet/renesas/ravb.h | 3 ++
drivers/net/ethernet/renesas/ravb_main.c | 54 +++++++++++++++++++++++-
2 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h
index 27e2b31955ba..5d35b40d7c58 100644
--- a/drivers/net/ethernet/renesas/ravb.h
+++ b/drivers/net/ethernet/renesas/ravb.h
@@ -249,6 +249,8 @@ enum APSR_BIT {
APSR_RDM = 0x00002000,
APSR_TDM = 0x00004000,
APSR_MIISELECT = 0x01000000, /* R-Car V4M only */
+ APSR_GPTPTIMER_SOURCE = BIT(25), /* Gen4 */
+ APSR_GPTPCLOCK = BIT(29), /* Gen4 */
};
/* RCR */
@@ -1132,6 +1134,7 @@ struct ravb_private {
struct list_head ts_skb_list;
u32 ts_skb_tag;
struct ravb_ptp ptp;
+ struct device_node *of_gptp; /* Reference to external gPTP clock, if any. */
spinlock_t lock; /* Register access lock */
u32 cur_rx[NUM_RX_QUEUE]; /* Consumer ring indices */
u32 dirty_rx[NUM_RX_QUEUE]; /* Producer ring indices */
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 402370e1be63..66c9cd15a19e 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -2752,6 +2752,57 @@ static const struct ravb_hw_info ravb_gen3_hw_info = {
.magic_pkt = 1,
};
+static int ravb_gen4_ptp_probe(struct net_device *ndev)
+{
+ struct ravb_private *priv = netdev_priv(ndev);
+
+ priv->of_gptp = of_parse_phandle(priv->pdev->dev.of_node, "ptp-timer", 0);
+ if (!priv->of_gptp)
+ return 0;
+
+ if (!of_device_is_available(priv->of_gptp)) {
+ of_node_put(priv->of_gptp);
+ priv->of_gptp = NULL;
+ }
+
+ return 0;
+}
+
+static int ravb_gen4_ptp_clock_index(struct net_device *ndev)
+{
+ struct ravb_private *priv = netdev_priv(ndev);
+
+ /* If no clock, mimic ptp_clock_index_by_of_node() fail and return -1 */
+ if (!priv->of_gptp)
+ return -1;
+
+ return ptp_clock_index_by_of_node(priv->of_gptp);
+}
+
+static int ravb_gen4_ptp_set_config_mode(struct net_device *ndev)
+{
+ struct ravb_private *priv = netdev_priv(ndev);
+ int ret;
+
+ /* Enable gPTP Clock and Select High-speed peripheral bus clock. */
+ ret = ravb_set_opmode(ndev, CCC_OPC_CONFIG | CCC_GAC | CCC_CSEL_HPB);
+ if (ret)
+ return ret;
+
+ /* Set PTP source to GPTP module, only option on Gen4. */
+ if (priv->of_gptp)
+ ravb_modify(ndev, APSR, APSR_GPTPTIMER_SOURCE | APSR_GPTPCLOCK,
+ APSR_GPTPTIMER_SOURCE | APSR_GPTPCLOCK);
+
+ return 0;
+}
+
+static const struct ravb_gptp_info ravb_gen4_ptp_info = {
+ .probe = ravb_gen4_ptp_probe,
+ .clock_index = ravb_gen4_ptp_clock_index,
+ .set_config_mode = ravb_gen4_ptp_set_config_mode,
+};
+
static const struct ravb_hw_info ravb_gen4_hw_info = {
.receive = ravb_rx_rcar,
.set_rate = ravb_set_rate_rcar,
@@ -2774,7 +2825,7 @@ static const struct ravb_hw_info ravb_gen4_hw_info = {
.tx_counters = 1,
.multi_irqs = 1,
.irq_en_dis = 1,
- .ptp = &ravb_gen3_ptp_info,
+ .ptp = &ravb_gen4_ptp_info,
.nc_queues = 1,
.magic_pkt = 1,
};
@@ -3188,6 +3239,7 @@ static void ravb_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
pm_runtime_dont_use_autosuspend(dev);
clk_unprepare(priv->refclk);
+ of_node_put(priv->of_gptp);
reset_control_assert(priv->rstc);
free_netdev(ndev);
platform_set_drvdata(pdev, NULL);
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v3 05/10] net: ethernet: ravb: Propagate error from ptp_clock_register()
2026-09-02 8:46 ` [PATCH net-next v3 05/10] net: ethernet: ravb: Propagate error from ptp_clock_register() Niklas Söderlund
@ 2026-09-03 8:47 ` sashiko-bot
2026-09-03 11:35 ` Niklas Söderlund
0 siblings, 1 reply; 21+ messages in thread
From: sashiko-bot @ 2026-09-03 8:47 UTC (permalink / raw)
To: Niklas Söderlund; +Cc: devicetree, wsa+renesas, conor+dt, robh
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Calling `ptp_clock_index()` with a NULL pointer causes a deterministic kernel panic when querying ethtool timestamp info.
- [Critical] Failing to clear `priv->ptp.clock` in `ravb_ptp_stop()` leaves a dangling pointer, leading to a Use-After-Free during ethtool queries.
--
commit 8ab377468104948ff315e1ab381238bac1a1783e
Author: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
net: ethernet: ravb: Propagate error from ptp_clock_register()
If the PTP clock registration failed the error is silently ignored.
Before reworking all callers of ravb_ptp_init() handle and propagate the
error so it can be used.
Link: https://sashiko.dev/#/patchset/20260610102432.3538432-2-niklas.soderlund+renesas@ragnatech.se?part=1
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index e44d065f77cc8..7c7b3ac81e5d6 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -1785,7 +1785,7 @@ static int ravb_get_ts_info(struct net_device *ndev,
> (1 << HWTSTAMP_FILTER_NONE) |
> (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
> (1 << HWTSTAMP_FILTER_ALL);
> - info->phc_index = READ_ONCE(priv->ptp.phc_index);
> + info->phc_index = ptp_clock_index(priv->ptp.clock);
[Severity: Critical]
Can this code trigger a NULL pointer dereference if priv->ptp.clock is NULL?
If the interface is not brought up yet, or if PTP registration failed during
initialization, priv->ptp.clock will be NULL. When querying ethtool for
timestamping information, ravb_get_ts_info() invokes
ptp_clock_index(priv->ptp.clock).
Since ptp_clock_index() unconditionally dereferences the pointer, it seems
this could result in a crash.
> }
>
> return 0;
[ ... ]
> diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c
> index f70b616ac847c..19d039b9d24a5 100644
> --- a/drivers/net/ethernet/renesas/ravb_ptp.c
> +++ b/drivers/net/ethernet/renesas/ravb_ptp.c
[ ... ]
> @@ -369,14 +368,10 @@ static void ravb_ptp_sync_irqs(struct net_device *ndev)
> void ravb_ptp_stop(struct net_device *ndev)
> {
> struct ravb_private *priv = netdev_priv(ndev);
> - struct ptp_clock *clock;
> -
> - WRITE_ONCE(priv->ptp.phc_index, -1);
> - clock = xchg(&priv->ptp.clock, NULL);
>
> ravb_ptp_disable(ndev);
> ravb_ptp_sync_irqs(ndev);
>
> - if (clock)
> - ptp_clock_unregister(clock);
> + if (priv->ptp.clock)
> + ptp_clock_unregister(priv->ptp.clock);
[Severity: Critical]
Does this leave priv->ptp.clock as a dangling pointer?
The original code used xchg() to set priv->ptp.clock to NULL before
unregistering it. With this change, when the interface is brought down,
ravb_ptp_stop() unregisters and frees the PTP clock but leaves the pointer
pointing to freed memory.
If an unprivileged user or system daemon queries ethtool while the interface
is down, ravb_get_ts_info() will pass this dangling pointer to
ptp_clock_index(), potentially causing a use-after-free read. Should
priv->ptp.clock be explicitly set to NULL here?
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260902084703.3228504-1-niklas.soderlund+renesas@ragnatech.se?part=5
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v3 01/10] net: ethernet: ravb: Remove gPTP control from WoL setup and restore
2026-09-02 8:46 ` [PATCH net-next v3 01/10] net: ethernet: ravb: Remove gPTP control from WoL setup and restore Niklas Söderlund
@ 2026-09-03 8:47 ` sashiko-bot
2026-09-03 11:11 ` Niklas Söderlund
0 siblings, 1 reply; 21+ messages in thread
From: sashiko-bot @ 2026-09-03 8:47 UTC (permalink / raw)
To: Niklas Söderlund; +Cc: robh, wsa+renesas, devicetree, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch erroneously removes `ravb_ptp_stop()` from `ravb_wol_setup()`, leaving the gPTP hardware active during a WoL-enabled suspend.
--
commit bbd624fcad5eb4869638d985be16666aae0f0ca2
Author: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
net: ethernet: ravb: Remove gPTP control from WoL setup and restore
This commit removes explicit gPTP stop/init calls from the Wake-on-LAN setup
and restore paths. The commit message states this is redundant as the device
is always closed and re-opened during suspend and resume.
> net: ethernet: ravb: Remove gPTP control from WoL setup and restore
>
> Since commit a6a85ba36fd0 ("net: ravb: Move PTP initialization in the
> driver's ndo_open API for ccc_gac platorms") the gPTP clock (if
> supported) is stopped and started by opening and closing the ndev.
>
> This makes the special case to stop and start it when resuming from WoL
> redundant. As the ndev will always be closed and re-opened when
> suspending and resuming the system.
[Severity: High]
Is this description accurate when Wake-on-LAN is enabled?
Looking at ravb_suspend() in drivers/net/ethernet/renesas/ravb_main.c,
ravb_close() is explicitly bypassed when wol_enabled is true:
if (priv->wol_enabled) {
ret = ravb_wol_setup(ndev);
rtnl_unlock();
return ret;
}
ret = ravb_close(ndev);
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> Reviewed-by: Sergey Shtylyov <sergei.shtylyov@gmail.com>
>
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index ea1c7e536791e..36173a09e2fdb 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -3182,9 +3182,6 @@ static int ravb_wol_setup(struct net_device *ndev)
> /* Enable MagicPacket */
> ravb_modify(ndev, ECMR, ECMR_MPDE, ECMR_MPDE);
>
> - if (priv->info->ccc_gac)
> - ravb_ptp_stop(ndev);
> -
> return enable_irq_wake(priv->emac_irq);
> }
[Severity: High]
Since ravb_close() is not called during a WoL-enabled suspend, doesn't removing
ravb_ptp_stop() here leave the gPTP hardware active during suspend?
>
> @@ -3204,9 +3201,6 @@ static int ravb_wol_restore(struct net_device *ndev)
> if (error)
> return error;
>
> - if (priv->info->ccc_gac)
> - ravb_ptp_init(ndev, priv->pdev);
> -
> if (info->nc_queues)
> napi_enable(&priv->napi[RAVB_NC]);
> napi_enable(&priv->napi[RAVB_BE]);
[Severity: High]
If the PTP clock remains active during suspend, won't it be abruptly torn down
by the ravb_close(ndev) call that occurs later in this ravb_wol_restore()
function?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260902084703.3228504-1-niklas.soderlund+renesas@ragnatech.se?part=1
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v3 07/10] net: ethernet: ravb: Add callback for gPTP probe
2026-09-02 8:47 ` [PATCH net-next v3 07/10] net: ethernet: ravb: Add callback for gPTP probe Niklas Söderlund
@ 2026-09-03 8:47 ` sashiko-bot
0 siblings, 0 replies; 21+ messages in thread
From: sashiko-bot @ 2026-09-03 8:47 UTC (permalink / raw)
To: Niklas Söderlund; +Cc: wsa+renesas, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Dangling pointer in `priv->ptp.clock` leads to double free and use-after-free on error recovery paths.
- [High] Early shared IRQ registration in `ravb_probe` leads to Use-After-Free and NULL pointer dereferences.
--
commit 252e91f926cfc67c49e9dd06194245579401d492
Author: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
net: ethernet: ravb: Add callback for gPTP probe
This commit introduces a gPTP probe callback to accommodate different
generations of the RAVB IP and removes the gptp_ref_clk flag. It also
moves GTI computation into the callbacks to prepare for Gen4 support
where the clock is external.
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
[ ... ]
> @@ -2976,12 +2995,10 @@ static int ravb_probe(struct platform_device *pdev)
> goto out_reset_assert;
> }
>
> - if (info->gptp_ref_clk) {
> - priv->gptp_clk = devm_clk_get(&pdev->dev, "gptp");
> - if (IS_ERR(priv->gptp_clk)) {
> - error = PTR_ERR(priv->gptp_clk);
> + if (info->ptp && info->ptp->probe) {
> + error = info->ptp->probe(ndev);
> + if (error)
> goto out_reset_assert;
[Severity: High]
This is a pre-existing issue, but does adding this new failure point expand
a hazard window with the shared interrupt handler?
In ravb_probe(), devm_request_irq() is called to register a shared IRQ
before priv->addr is mapped. If a premature IRQ is delivered, could it force
a panic by accessing an unmapped register?
Additionally, if info->ptp->probe() fails here, the error path jumps to
out_reset_assert and eventually out_free_netdev:
out_free_netdev:
free_netdev(ndev);
return error;
Could this leave a live devm-managed IRQ handler targeting freed memory if
the IRQ fires before the devm cleanup removes the handler?
[Severity: Critical]
This is a pre-existing issue, but is there a risk of a double free in the
error recovery paths related to the ptp clock?
When ravb_tx_timeout_work() initiates a reset, it can fail to re-initialize
the DMA. If it takes the error path without neutralizing the clock pointer:
ravb_tx_timeout_work() {
...
error = ravb_dmac_init(ndev);
if (error) {
...
goto out_unlock;
}
}
The error path leaves the device up, and a secondary teardown in
ravb_ptp_stop() (such as during ravb_close) will attempt to unregister the
clock again:
ravb_ptp_stop() {
...
if (priv->ptp.clock)
ptp_clock_unregister(priv->ptp.clock);
}
Since the pointer is freed during the initial timeout recovery but not
set to NULL, could this result in a use-after-free and double free when
ravb_close() is subsequently executed?
> - }
> }
>
> priv->refclk = devm_clk_get_optional(&pdev->dev, "refclk");
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260902084703.3228504-1-niklas.soderlund+renesas@ragnatech.se?part=7
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v3 03/10] net: ethernet: ravb: Simplify gPTP start and stop
2026-09-02 8:46 ` [PATCH net-next v3 03/10] net: ethernet: ravb: Simplify gPTP start and stop Niklas Söderlund
@ 2026-09-03 8:47 ` sashiko-bot
0 siblings, 0 replies; 21+ messages in thread
From: sashiko-bot @ 2026-09-03 8:47 UTC (permalink / raw)
To: Niklas Söderlund; +Cc: conor+dt, devicetree, wsa+renesas, robh
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Missing PTP clock unregistration for `ccc_gac` (Gen3) devices on the `ravb_open()` error path leads to a Use-After-Free.
- [High] Missing PTP clock driver teardown for `gptp` (Gen2) devices on hardware timeout leads to a Use-After-Free.
- [Medium] Silent loss of PTP clock functionality during TX timeout recovery for `gptp` devices.
--
commit 13e73cf3cf26d2c226a9c19d3728cc27d5cffb72
Author: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
net: ethernet: ravb: Simplify gPTP start and stop
This commit simplifies the gPTP start and stop logic by folding the gptp flag
handling directly into ravb_dmac_init() and ravb_stop_dma(). It aims to
control the clock for gptp devices in tandem with the AVB-DMAC, while leaving
ccc_gac devices tied to device open/close operations. However, this
refactoring appears to introduce regressions in error handling and timeout
recovery paths.
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index a89f6fe7866fe..2d0022a4f85c3 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
[ ... ]
> @@ -1115,6 +1123,10 @@ static int ravb_stop_dma(struct net_device *ndev)
> netdev_err(ndev, "failed to stop AXI BUS\n");
> }
>
> + /* Stop PTP Clock driver */
> + if (info->gptp)
> + ravb_ptp_stop(ndev);
> +
> /* Stop AVB-DMAC process */
> return ravb_set_opmode(ndev, CCC_OPC_CONFIG);
> }
[Severity: High]
Can a hardware timeout cause a use-after-free by skipping the PTP clock
teardown?
Earlier in ravb_stop_dma(), there are multiple ravb_wait() hardware polling
loops. If any of these wait loops time out, the function returns an error
immediately, bypassing this new ravb_ptp_stop() call. During a module unload
or interface close, if ravb_stop_dma() fails, teardown continues but the PTP
clock remains registered. Does this leave the /dev/ptp* device pointing to
freed memory?
[ ... ]
> @@ -1974,9 +1980,6 @@ static int ravb_open(struct net_device *ndev)
> return 0;
>
> out_ptp_stop:
> - /* Stop PTP Clock driver */
> - if (info->gptp || info->ccc_gac)
> - ravb_ptp_stop(ndev);
> ravb_stop_dma(ndev);
> out_set_reset:
> ravb_set_opmode(ndev, CCC_OPC_RESET);
[Severity: High]
Does this error path leak the PTP clock driver for ccc_gac (Gen3) devices?
When ravb_ptp_init() is called successfully but a subsequent step like
ravb_phy_start() fails, the code jumps here to out_ptp_stop. Since
ravb_stop_dma() only stops the clock for gptp devices, the clock remains
registered for ccc_gac devices. If the network device is subsequently freed
by a module unload, could this lead to a use-after-free when userspace
accesses the dangling PTP device?
[ ... ]
> @@ -2056,10 +2055,6 @@ static void ravb_tx_timeout_work(struct work_struct *work)
> ravb_emac_init(ndev);
>
> out:
> - /* Initialise PTP Clock driver */
> - if (info->gptp)
> - ravb_ptp_init(ndev, priv->pdev);
> -
> netif_tx_start_all_queues(ndev);
>
> out_unlock:
[Severity: Medium]
Does removing this initialization cause a silent loss of PTP clock
functionality during TX timeout recovery?
If ravb_stop_dma() successfully stops the PTP clock but fails at its final
step (ravb_set_opmode()), it returns an error. The error path in
ravb_tx_timeout_work() jumps to the out label, re-enables queues, and
aborts full re-initialization.
Since ravb_ptp_init() is no longer called at the out label, does the PTP
clock remain permanently stopped and unregistered until the interface is
manually brought down and up again?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260902084703.3228504-1-niklas.soderlund+renesas@ragnatech.se?part=3
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v3 06/10] net: ethernet: ravb: Replace gPTP flags with callbacks
2026-09-02 8:46 ` [PATCH net-next v3 06/10] net: ethernet: ravb: Replace gPTP flags with callbacks Niklas Söderlund
@ 2026-09-03 8:47 ` sashiko-bot
0 siblings, 0 replies; 21+ messages in thread
From: sashiko-bot @ 2026-09-03 8:47 UTC (permalink / raw)
To: Niklas Söderlund; +Cc: devicetree, conor+dt, wsa+renesas, robh
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Medium] ravb_dmac_init leaves the hardware in CCC_OPC_OPERATION mode if dmac_start fails.
Pre-existing issues:
- [High] Calling ethtool -T when the interface is down will trigger a NULL pointer dereference or a Use-After-Free in ravb_get_ts_info().
--
commit eb974310ac24dea7fe34514d8fd0eeeea0662742
Author: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
net: ethernet: ravb: Replace gPTP flags with callbacks
Prepare for adding Gen4 support which will add a third and new way to
interact with the gPTP clock by replacing the flags for Gen2 behavior
(info->gptp) and Gen3 behavior (info->ccc_gac) with callbacks.
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index 7c7b3ac81e5d6..5d5b9c0e2f450 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -712,8 +712,8 @@ static int ravb_dmac_init(struct net_device *ndev)
> return error;
>
> /* Initialise PTP Clock driver */
> - if (info->gptp)
> - ravb_ptp_init(ndev);
> + if (info->ptp && info->ptp->dmac_start)
> + return info->ptp->dmac_start(ndev);
[Severity: Medium]
If dmac_start() (e.g. PTP initialization) fails during operations like setting
ring parameters or recovering from a TX timeout, ravb_dmac_init() returns the
error immediately.
Does this leave the hardware in CCC_OPC_OPERATION mode without rolling back
the hardware state to CCC_OPC_CONFIG?
Could this leave the device in an inconsistent state where the DMA is running
but the EMAC is disabled and driver queues are detached, causing a local
DoS until the interface is manually restarted?
>
> return 0;
> }
[ ... ]
> @@ -1774,7 +1774,7 @@ static int ravb_get_ts_info(struct net_device *ndev,
> struct ravb_private *priv = netdev_priv(ndev);
> const struct ravb_hw_info *hw_info = priv->info;
>
> - if (hw_info->gptp || hw_info->ccc_gac) {
> + if (hw_info->ptp) {
[Severity: High]
This is a pre-existing issue, but calling ethtool -T when the interface is
down can trigger a NULL pointer dereference or a Use-After-Free here in
ravb_get_ts_info().
If a local unprivileged user queries timestamping info via SIOCETHTOOL while
the interface is administratively down, ravb_get_ts_info() eventually passes
priv->ptp.clock to ptp_clock_index(), which unconditionally dereferences it:
ravb_get_ts_info()
info->phc_index = ptp_clock_index(priv->ptp.clock);
If the device is probed but not yet opened, priv->ptp.clock is NULL,
resulting in a NULL pointer dereference.
Furthermore, when the device is closed, ravb_ptp_stop() unregisters the
clock but does not clear the pointer:
ravb_ptp_stop()
if (priv->ptp.clock)
ptp_clock_unregister(priv->ptp.clock);
Calling ethtool -T in this state triggers a Use-After-Free. Could this
pointer be cleared on stop, and checked before use in ravb_get_ts_info()?
> info->so_timestamping =
> SOF_TIMESTAMPING_TX_SOFTWARE |
> SOF_TIMESTAMPING_TX_HARDWARE |
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260902084703.3228504-1-niklas.soderlund+renesas@ragnatech.se?part=6
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v3 08/10] net: ethernet: ravb: Add callback for gPTP clock index
2026-09-02 8:47 ` [PATCH net-next v3 08/10] net: ethernet: ravb: Add callback for gPTP clock index Niklas Söderlund
@ 2026-09-03 8:47 ` sashiko-bot
0 siblings, 0 replies; 21+ messages in thread
From: sashiko-bot @ 2026-09-03 8:47 UTC (permalink / raw)
To: Niklas Söderlund; +Cc: conor+dt, wsa+renesas, robh, devicetree
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Calling ethtool -T (get_ts_info) when the interface is down causes a kernel panic due to a NULL pointer dereference in ptp_clock_index().
--
commit 861424103c229fb3c19f621c9c92a3cf127c7143
Author: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
net: ethernet: ravb: Add callback for gPTP clock index
This patch prepares for adding Gen4 support which has an optional external
gPTP clock. It adds a callback to get the clock index and uses it to
determine if the device should report gPTP support.
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index 7e53eca5327f5..402370e1be634 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -1773,8 +1773,13 @@ static int ravb_get_ts_info(struct net_device *ndev,
> {
> struct ravb_private *priv = netdev_priv(ndev);
> const struct ravb_hw_info *hw_info = priv->info;
> + int index = -1;
>
> - if (hw_info->ptp) {
> + if (hw_info->ptp && hw_info->ptp->clock_index)
> + index = hw_info->ptp->clock_index(ndev);
[Severity: High]
This is a pre-existing issue, but does this safely handle an absent clock
when the interface is down?
If userspace queries timestamping capabilities (e.g., via ethtool -T) while
the interface is down, ravb_get_ts_info() will call the clock_index callback.
However, priv->ptp.clock is only initialized when the interface is brought up
in ravb_ptp_init().
[ ... ]
> @@ -2653,6 +2658,13 @@ static int ravb_gen2_ptp_probe(struct net_device *ndev)
> return ravb_compute_gti(ndev, priv->clk);
> }
>
> +static int ravb_gen2_ptp_clock_index(struct net_device *ndev)
> +{
> + struct ravb_private *priv = netdev_priv(ndev);
> +
> + return ptp_clock_index(priv->ptp.clock);
[Severity: High]
This isn't a bug introduced by this patch, but will this crash if
priv->ptp.clock is NULL?
Because ptp_clock_index() dereferences the passed pointer without validation,
calling it when the interface is down and the clock hasn't been initialized
appears to lead to a NULL pointer dereference.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260902084703.3228504-1-niklas.soderlund+renesas@ragnatech.se?part=8
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v3 02/10] net: ethernet: ravb: Move programming of gPTP timer interval
2026-09-02 8:46 ` [PATCH net-next v3 02/10] net: ethernet: ravb: Move programming of gPTP timer interval Niklas Söderlund
@ 2026-09-03 8:47 ` sashiko-bot
0 siblings, 0 replies; 21+ messages in thread
From: sashiko-bot @ 2026-09-03 8:47 UTC (permalink / raw)
To: Niklas Söderlund; +Cc: wsa+renesas, conor+dt, robh, devicetree
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The wait condition intended to synchronize GTI (gPTP Timer Increment) loading completion checks the wrong register bit (GCCR_TCR instead of GCCR_LTI), leading to a tight race condition and potential hardware state corruption.
--
commit 9509ae0d35af26310454ae24d344c98a9575f582
Author: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
net: ethernet: ravb: Move programming of gPTP timer interval
This patch moves the programming of the gPTP timer interval from the RAVB
main logic directly into the gPTP initialization function, ensuring it is
done under the gPTP registers lock.
> diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c
> index 43218bc15b151..157fb78209c78 100644
> --- a/drivers/net/ethernet/renesas/ravb_ptp.c
> +++ b/drivers/net/ethernet/renesas/ravb_ptp.c
> @@ -321,11 +321,20 @@ void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev)
>
> priv->ptp.info = ravb_ptp_info;
>
> - priv->ptp.default_addend = ravb_read(ndev, GTI);
> + priv->ptp.default_addend = priv->gti_tiv;
> priv->ptp.current_addend = priv->ptp.default_addend;
>
> spin_lock_irqsave(&priv->lock, flags);
> +
> + /* Set gPTP Timer Increment Value. */
> + ravb_write(ndev, priv->ptp.default_addend, GTI);
> +
> + /* Request GTI loading. */
> + ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI);
> +
> + /* Wait for GIT loading to complete. */
> ravb_wait(ndev, GCCR, GCCR_TCR, GCCR_TCR_NOREQ);
> +
> ravb_modify(ndev, GCCR, GCCR_TCSS, GCCR_TCSS_ADJGPTP);
[Severity: Medium]
Are we polling the wrong register bit to wait for GTI loading to complete?
The comment says "Wait for GIT loading to complete", but the wait polls
GCCR_TCR instead of GCCR_LTI which was just set. Because GCCR_TCR is
likely already 0 (NOREQ), the wait returns immediately.
If the hardware is still processing the LTI load when the read-modify-write
on GCCR executes on the next line, could it read GCCR_LTI as 1 and
inadvertently write it back as 1?
By moving the GTI loading directly above this incorrect wait, does this
create a tight race window that might corrupt the hardware state?
> spin_unlock_irqrestore(&priv->lock, flags);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260902084703.3228504-1-niklas.soderlund+renesas@ragnatech.se?part=2
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v3 10/10] net: ethernet: ravb: Add gPTP support for Gen4
2026-09-02 8:47 ` [PATCH net-next v3 10/10] net: ethernet: ravb: Add gPTP support " Niklas Söderlund
@ 2026-09-03 8:48 ` sashiko-bot
0 siblings, 0 replies; 21+ messages in thread
From: sashiko-bot @ 2026-09-03 8:48 UTC (permalink / raw)
To: Niklas Söderlund; +Cc: conor+dt, wsa+renesas, robh, devicetree
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing `of_node_put()` in the error paths of `ravb_probe()` causes a memory leak of the `ptp-timer` device node reference acquired by `ravb_gen4_ptp_probe()`.
--
commit d2e45518cd8b99519759a683fe36054ff2cdc88d
Author: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
net: ethernet: ravb: Add gPTP support for Gen4
This commit adds gPTP support for RAVB Gen4 platforms by utilizing a
system-wide clock rather than an internal one. It updates the RAVB gPTP
driver code to parse and use an optional "ptp-timer" device tree property
for Gen4 devices.
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -2752,6 +2752,57 @@ static const struct ravb_hw_info ravb_gen3_hw_info = {
[ ... ]
> +static int ravb_gen4_ptp_probe(struct net_device *ndev)
> +{
> + struct ravb_private *priv = netdev_priv(ndev);
> +
> + priv->of_gptp = of_parse_phandle(priv->pdev->dev.of_node, "ptp-timer", 0);
> + if (!priv->of_gptp)
> + return 0;
[ ... ]
> @@ -3188,6 +3239,7 @@ static void ravb_remove(struct platform_device *pdev)
> pm_runtime_disable(&pdev->dev);
> pm_runtime_dont_use_autosuspend(dev);
> clk_unprepare(priv->refclk);
> + of_node_put(priv->of_gptp);
> reset_control_assert(priv->rstc);
> free_netdev(ndev);
> platform_set_drvdata(pdev, NULL);
[Severity: Medium]
Since priv->of_gptp acquires a node reference via of_parse_phandle() in
ravb_gen4_ptp_probe(), and is correctly released here in ravb_remove(), do the
error paths in ravb_probe() also need to call of_node_put(priv->of_gptp)?
If an initialization step fails in ravb_probe() in
drivers/net/ethernet/renesas/ravb_main.c after info->ptp->probe(ndev)
successfully acquires the node reference, the error paths jump to these labels:
out_rpm_disable:
pm_runtime_disable(&pdev->dev);
pm_runtime_dont_use_autosuspend(&pdev->dev);
clk_unprepare(priv->refclk);
out_reset_assert:
reset_control_assert(rstc);
out_free_netdev:
free_netdev(ndev);
return error;
Will this leak the device node reference if probe fails here?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260902084703.3228504-1-niklas.soderlund+renesas@ragnatech.se?part=10
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v3 01/10] net: ethernet: ravb: Remove gPTP control from WoL setup and restore
2026-09-03 8:47 ` sashiko-bot
@ 2026-09-03 11:11 ` Niklas Söderlund
0 siblings, 0 replies; 21+ messages in thread
From: Niklas Söderlund @ 2026-09-03 11:11 UTC (permalink / raw)
To: sashiko-reviews; +Cc: robh, wsa+renesas, devicetree, conor+dt
On 2026-09-03 08:47:55 +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] The patch erroneously removes `ravb_ptp_stop()` from `ravb_wol_setup()`, leaving the gPTP hardware active during a WoL-enabled suspend.
This is a non-issue as the module clock is the same, ignore.
> --
>
> commit bbd624fcad5eb4869638d985be16666aae0f0ca2
> Author: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
>
> net: ethernet: ravb: Remove gPTP control from WoL setup and restore
>
> This commit removes explicit gPTP stop/init calls from the Wake-on-LAN setup
> and restore paths. The commit message states this is redundant as the device
> is always closed and re-opened during suspend and resume.
>
> > net: ethernet: ravb: Remove gPTP control from WoL setup and restore
> >
> > Since commit a6a85ba36fd0 ("net: ravb: Move PTP initialization in the
> > driver's ndo_open API for ccc_gac platorms") the gPTP clock (if
> > supported) is stopped and started by opening and closing the ndev.
> >
> > This makes the special case to stop and start it when resuming from WoL
> > redundant. As the ndev will always be closed and re-opened when
> > suspending and resuming the system.
>
> [Severity: High]
> Is this description accurate when Wake-on-LAN is enabled?
>
> Looking at ravb_suspend() in drivers/net/ethernet/renesas/ravb_main.c,
> ravb_close() is explicitly bypassed when wol_enabled is true:
>
> if (priv->wol_enabled) {
> ret = ravb_wol_setup(ndev);
> rtnl_unlock();
> return ret;
> }
>
> ret = ravb_close(ndev);
>
> >
> > Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> > Reviewed-by: Sergey Shtylyov <sergei.shtylyov@gmail.com>
> >
> > diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> > index ea1c7e536791e..36173a09e2fdb 100644
> > --- a/drivers/net/ethernet/renesas/ravb_main.c
> > +++ b/drivers/net/ethernet/renesas/ravb_main.c
> > @@ -3182,9 +3182,6 @@ static int ravb_wol_setup(struct net_device *ndev)
> > /* Enable MagicPacket */
> > ravb_modify(ndev, ECMR, ECMR_MPDE, ECMR_MPDE);
> >
> > - if (priv->info->ccc_gac)
> > - ravb_ptp_stop(ndev);
> > -
> > return enable_irq_wake(priv->emac_irq);
> > }
>
> [Severity: High]
> Since ravb_close() is not called during a WoL-enabled suspend, doesn't removing
> ravb_ptp_stop() here leave the gPTP hardware active during suspend?
>
> >
> > @@ -3204,9 +3201,6 @@ static int ravb_wol_restore(struct net_device *ndev)
> > if (error)
> > return error;
> >
> > - if (priv->info->ccc_gac)
> > - ravb_ptp_init(ndev, priv->pdev);
> > -
> > if (info->nc_queues)
> > napi_enable(&priv->napi[RAVB_NC]);
> > napi_enable(&priv->napi[RAVB_BE]);
>
> [Severity: High]
> If the PTP clock remains active during suspend, won't it be abruptly torn down
> by the ravb_close(ndev) call that occurs later in this ravb_wol_restore()
> function?
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260902084703.3228504-1-niklas.soderlund+renesas@ragnatech.se?part=1
--
Kind Regards,
Niklas Söderlund
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH net-next v3 05/10] net: ethernet: ravb: Propagate error from ptp_clock_register()
2026-09-03 8:47 ` sashiko-bot
@ 2026-09-03 11:35 ` Niklas Söderlund
0 siblings, 0 replies; 21+ messages in thread
From: Niklas Söderlund @ 2026-09-03 11:35 UTC (permalink / raw)
To: sashiko-reviews; +Cc: devicetree, wsa+renesas, conor+dt, robh
On 2026-09-03 08:47:54 +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [Critical] Calling `ptp_clock_index()` with a NULL pointer causes a deterministic kernel panic when querying ethtool timestamp info.
> - [Critical] Failing to clear `priv->ptp.clock` in `ravb_ptp_stop()` leaves a dangling pointer, leading to a Use-After-Free during ethtool queries.
> --
>
> commit 8ab377468104948ff315e1ab381238bac1a1783e
> Author: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
>
> net: ethernet: ravb: Propagate error from ptp_clock_register()
>
> If the PTP clock registration failed the error is silently ignored.
> Before reworking all callers of ravb_ptp_init() handle and propagate the
> error so it can be used.
>
> Link: https://sashiko.dev/#/patchset/20260610102432.3538432-2-niklas.soderlund+renesas@ragnatech.se?part=1
>
> > diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> > index e44d065f77cc8..7c7b3ac81e5d6 100644
> > --- a/drivers/net/ethernet/renesas/ravb_main.c
> > +++ b/drivers/net/ethernet/renesas/ravb_main.c
> > @@ -1785,7 +1785,7 @@ static int ravb_get_ts_info(struct net_device *ndev,
> > (1 << HWTSTAMP_FILTER_NONE) |
> > (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
> > (1 << HWTSTAMP_FILTER_ALL);
> > - info->phc_index = READ_ONCE(priv->ptp.phc_index);
> > + info->phc_index = ptp_clock_index(priv->ptp.clock);
>
> [Severity: Critical]
> Can this code trigger a NULL pointer dereference if priv->ptp.clock is NULL?
>
> If the interface is not brought up yet, or if PTP registration failed during
> initialization, priv->ptp.clock will be NULL. When querying ethtool for
> timestamping information, ravb_get_ts_info() invokes
> ptp_clock_index(priv->ptp.clock).
>
> Since ptp_clock_index() unconditionally dereferences the pointer, it seems
> this could result in a crash.
Please check patch 9 in this series. The change is an effect of the LLM
driven fix merged a head of this series with tried to correct this issue
in a way to complicated way by using the READ_ONCE and caching the
value...
>
> > }
> >
> > return 0;
>
> [ ... ]
>
> > diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c
> > index f70b616ac847c..19d039b9d24a5 100644
> > --- a/drivers/net/ethernet/renesas/ravb_ptp.c
> > +++ b/drivers/net/ethernet/renesas/ravb_ptp.c
> [ ... ]
> > @@ -369,14 +368,10 @@ static void ravb_ptp_sync_irqs(struct net_device *ndev)
> > void ravb_ptp_stop(struct net_device *ndev)
> > {
> > struct ravb_private *priv = netdev_priv(ndev);
> > - struct ptp_clock *clock;
> > -
> > - WRITE_ONCE(priv->ptp.phc_index, -1);
> > - clock = xchg(&priv->ptp.clock, NULL);
> >
> > ravb_ptp_disable(ndev);
> > ravb_ptp_sync_irqs(ndev);
> >
> > - if (clock)
> > - ptp_clock_unregister(clock);
> > + if (priv->ptp.clock)
> > + ptp_clock_unregister(priv->ptp.clock);
>
> [Severity: Critical]
> Does this leave priv->ptp.clock as a dangling pointer?
>
> The original code used xchg() to set priv->ptp.clock to NULL before
> unregistering it. With this change, when the interface is brought down,
> ravb_ptp_stop() unregisters and frees the PTP clock but leaves the pointer
> pointing to freed memory.
>
> If an unprivileged user or system daemon queries ethtool while the interface
> is down, ravb_get_ts_info() will pass this dangling pointer to
> ptp_clock_index(), potentially causing a use-after-free read. Should
> priv->ptp.clock be explicitly set to NULL here?
>
> > }
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260902084703.3228504-1-niklas.soderlund+renesas@ragnatech.se?part=5
--
Kind Regards,
Niklas Söderlund
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2026-09-03 11:35 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02 8:46 [PATCH net-next v3 00/10] ravb: Add gPTP support for Gen4 Niklas Söderlund
2026-09-02 8:46 ` [PATCH net-next v3 01/10] net: ethernet: ravb: Remove gPTP control from WoL setup and restore Niklas Söderlund
2026-09-03 8:47 ` sashiko-bot
2026-09-03 11:11 ` Niklas Söderlund
2026-09-02 8:46 ` [PATCH net-next v3 02/10] net: ethernet: ravb: Move programming of gPTP timer interval Niklas Söderlund
2026-09-03 8:47 ` sashiko-bot
2026-09-02 8:46 ` [PATCH net-next v3 03/10] net: ethernet: ravb: Simplify gPTP start and stop Niklas Söderlund
2026-09-03 8:47 ` sashiko-bot
2026-09-02 8:46 ` [PATCH net-next v3 04/10] net: ethernet: ravb: Remove redundant argument to ravb_ptp_init() Niklas Söderlund
2026-09-02 8:46 ` [PATCH net-next v3 05/10] net: ethernet: ravb: Propagate error from ptp_clock_register() Niklas Söderlund
2026-09-03 8:47 ` sashiko-bot
2026-09-03 11:35 ` Niklas Söderlund
2026-09-02 8:46 ` [PATCH net-next v3 06/10] net: ethernet: ravb: Replace gPTP flags with callbacks Niklas Söderlund
2026-09-03 8:47 ` sashiko-bot
2026-09-02 8:47 ` [PATCH net-next v3 07/10] net: ethernet: ravb: Add callback for gPTP probe Niklas Söderlund
2026-09-03 8:47 ` sashiko-bot
2026-09-02 8:47 ` [PATCH net-next v3 08/10] net: ethernet: ravb: Add callback for gPTP clock index Niklas Söderlund
2026-09-03 8:47 ` sashiko-bot
2026-09-02 8:47 ` [PATCH net-next v3 09/10] dt-bindings: net: renesas,etheravb: Add optional gPTP phandle for Gen4 Niklas Söderlund
2026-09-02 8:47 ` [PATCH net-next v3 10/10] net: ethernet: ravb: Add gPTP support " Niklas Söderlund
2026-09-03 8:48 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox