From e8bfdd91469c9668d11427a30f8ba0396f9aa92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:28 +0200 Subject: [PATCH 01/10] net: ethernet: ravb: Remove gPTP control from WoL setup and restore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 resuming the system. Signed-off-by: Niklas Söderlund Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-2-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- 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]); From d9519789d0989ab47355b30fe1bc35f2c327e6dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:29 +0200 Subject: [PATCH 02/10] net: ethernet: ravb: Move programming of gPTP timer interval MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-3-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- 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..ac91a6813368 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 by checking there are no requests. */ ravb_wait(ndev, GCCR, GCCR_TCR, GCCR_TCR_NOREQ); + ravb_modify(ndev, GCCR, GCCR_TCSS, GCCR_TCSS_ADJGPTP); spin_unlock_irqrestore(&priv->lock, flags); From b9c1216c01560c2603af4c3ca42755ead3cdb4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:30 +0200 Subject: [PATCH 03/10] net: ethernet: ravb: Simplify gPTP start and stop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-4-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/renesas/ravb_main.c | 36 +++++++++++------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index a89f6fe7866f..42d208e6b8ec 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 */ @@ -1975,7 +1981,7 @@ static int ravb_open(struct net_device *ndev) out_ptp_stop: /* Stop PTP Clock driver */ - if (info->gptp || info->ccc_gac) + if (info->ccc_gac) ravb_ptp_stop(ndev); ravb_stop_dma(ndev); out_set_reset: @@ -2020,10 +2026,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 +2058,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 +2372,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 */ From b784f9ed2e3bcc1f632401307057e47f71d4d7ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:31 +0200 Subject: [PATCH 04/10] net: ethernet: ravb: Remove redundant argument to ravb_ptp_init() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-5-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- 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 42d208e6b8ec..1dfe905832a0 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 ac91a6813368..6817e94721b5 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; From 121cc8a3acf8d8e31daec4e564eff32e39c00446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:32 +0200 Subject: [PATCH 05/10] net: ethernet: ravb: Propagate error from ptp_clock_register() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-6-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/renesas/ravb.h | 3 +-- drivers/net/ethernet/renesas/ravb_main.c | 5 ++--- drivers/net/ethernet/renesas/ravb_ptp.c | 27 +++++++++++------------- 3 files changed, 15 insertions(+), 20 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 1dfe905832a0..db3ef87f0991 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -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 (priv->ptp.clock && (hw_info->gptp || hw_info->ccc_gac)) { info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_TX_HARDWARE | @@ -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; @@ -2937,7 +2937,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 6817e94721b5..407ae97b76bb 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,12 @@ 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); + priv->ptp.clock = NULL; + } } From 14bf0091dd0d47204f761125d65b102bebcb6001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:33 +0200 Subject: [PATCH 06/10] net: ethernet: ravb: Replace gPTP flags with callbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-7-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/renesas/ravb.h | 24 ++++++- drivers/net/ethernet/renesas/ravb_main.c | 87 +++++++++++++++--------- 2 files changed, 78 insertions(+), 33 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 db3ef87f0991..b558e9f5611e 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 (priv->ptp.clock && (hw_info->gptp || hw_info->ccc_gac)) { + if (priv->ptp.clock && 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); @@ -1981,8 +1974,8 @@ static int ravb_open(struct net_device *ndev) out_ptp_stop: /* Stop PTP Clock driver */ - if (info->ccc_gac) - ravb_ptp_stop(ndev); + if (info->ptp && info->ptp->ndev_close) + info->ptp->ndev_close(ndev); ravb_stop_dma(ndev); out_set_reset: ravb_set_opmode(ndev, CCC_OPC_RESET); @@ -2190,7 +2183,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) { @@ -2372,8 +2365,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) @@ -2381,7 +2374,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); @@ -2663,6 +2656,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, @@ -2681,12 +2694,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, @@ -2705,11 +2730,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, }; @@ -2736,7 +2761,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, }; @@ -2761,7 +2786,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, From 9a85f9dfbc3f6fea346044fecf0a0c637a4ad213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:34 +0200 Subject: [PATCH 07/10] net: ethernet: ravb: Add callback for gPTP probe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-8-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- 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 b558e9f5611e..77e66a9870ab 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; @@ -2656,6 +2649,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; @@ -2671,6 +2671,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, @@ -2707,6 +2708,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, @@ -2766,6 +2768,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, @@ -2786,8 +2806,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, }; @@ -2979,12 +2998,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"); @@ -3037,10 +3054,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 */ From 931770c1995f6fa188f488700c22ad99fff1abfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:35 +0200 Subject: [PATCH 08/10] net: ethernet: ravb: Add callback for gPTP clock index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-9-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/renesas/ravb.h | 2 ++ drivers/net/ethernet/renesas/ravb_main.c | 22 ++++++++++++++++++++-- 2 files changed, 22 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 77e66a9870ab..2dff47c2a125 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 (priv->ptp.clock && 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; @@ -2656,6 +2661,16 @@ 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); + + if (!priv->ptp.clock) + return -ENODEV; + + return ptp_clock_index(priv->ptp.clock); +} + static int ravb_gen2_ptp_set_config_mode(struct net_device *ndev) { int ret; @@ -2672,6 +2687,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, @@ -2709,6 +2725,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, @@ -2781,6 +2798,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, From ef488a9da66d0f9fb296ffdbaa2bbb1602e65496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:36 +0200 Subject: [PATCH 09/10] dt-bindings: net: renesas,etheravb: Add optional gPTP phandle for Gen4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Sergey Shtylyov Reviewed-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20260921175037.4084310-10-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- .../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 From 2b240cfc6de4a6ca7779323e0f1ffdf0d7f99add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 21 Sep 2026 19:50:37 +0200 Subject: [PATCH 10/10] net: ethernet: ravb: Add gPTP support for Gen4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Sergey Shtylyov Link: https://patch.msgid.link/20260921175037.4084310-11-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski --- 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 2dff47c2a125..5a07cc0180d8 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -2758,6 +2758,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, @@ -2780,7 +2831,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, }; @@ -3194,6 +3245,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);