diff options
| author | Jakub Kicinski <kuba@kernel.org> | 2026-02-03 19:35:40 -0800 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2026-02-03 19:35:40 -0800 |
| commit | e9a1a28af9d2da3f3e6a489f6a9fbfba8fb9fa1a (patch) | |
| tree | d3453dd60ed3b39e5af30d1daa3faf842ecfe31f | |
| parent | 6dfa3df797bbea7ae2527c21eaff58de5ae8c580 (diff) | |
| parent | 9c2f568eb236032071b73666ccd7715ddacc1fca (diff) | |
Merge branch 'net-ethernet-renesas-rcar_gen4_ptp-hide-private-data'
Niklas Söderlund says:
====================
net: ethernet: renesas: rcar_gen4_ptp: Hide private data
The R-Car Gen4 PTP module started out as an exclusive feature of a
single driver, but have since been extended to cover both R-Car Switch
and TSN driver implementations on Gen4.
The feature have already been extended to be built as its own module
with an interface exposed thru a local header file. The header file
however also exposes the modules private data structure. The two
existing users have already started to poke at members of the struct.
The exposed private data being manipulated by users makes refactoring
and future rework hard as the interface for the module becomes to
chaotic. This small series aims to create two helpers to hide the
private data.
This is done as a small preparation before a third, new, users of the
Gen4 PTP will be added in a follow up series.
====================
Link: https://patch.msgid.link/20260201183745.1075399-1-niklas.soderlund+renesas@ragnatech.se
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
| -rw-r--r-- | drivers/net/ethernet/renesas/rcar_gen4_ptp.c | 34 | ||||
| -rw-r--r-- | drivers/net/ethernet/renesas/rcar_gen4_ptp.h | 18 | ||||
| -rw-r--r-- | drivers/net/ethernet/renesas/rswitch_main.c | 11 | ||||
| -rw-r--r-- | drivers/net/ethernet/renesas/rtsn.c | 30 |
4 files changed, 57 insertions, 36 deletions
diff --git a/drivers/net/ethernet/renesas/rcar_gen4_ptp.c b/drivers/net/ethernet/renesas/rcar_gen4_ptp.c index d0979abd36de..27a6f0492097 100644 --- a/drivers/net/ethernet/renesas/rcar_gen4_ptp.c +++ b/drivers/net/ethernet/renesas/rcar_gen4_ptp.c @@ -9,6 +9,7 @@ #include <linux/kernel.h> #include <linux/module.h> #include <linux/platform_device.h> +#include <linux/ptp_clock_kernel.h> #include <linux/slab.h> #include "rcar_gen4_ptp.h" @@ -23,6 +24,15 @@ #define PTPGPTPTM10_REG 0x0054 #define PTPGPTPTM20_REG 0x0058 +struct rcar_gen4_ptp_private { + void __iomem *addr; + struct ptp_clock *clock; + struct ptp_clock_info info; + spinlock_t lock; /* For multiple registers access */ + s64 default_addend; + bool initialized; +}; + #define ptp_to_priv(ptp) container_of(ptp, struct rcar_gen4_ptp_private, info) static int rcar_gen4_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) @@ -168,7 +178,8 @@ int rcar_gen4_ptp_unregister(struct rcar_gen4_ptp_private *ptp_priv) } EXPORT_SYMBOL_GPL(rcar_gen4_ptp_unregister); -struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev) +struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev, + void __iomem *addr) { struct rcar_gen4_ptp_private *ptp; @@ -178,10 +189,31 @@ struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev) ptp->info = rcar_gen4_ptp_info; + ptp->addr = addr; + return ptp; } EXPORT_SYMBOL_GPL(rcar_gen4_ptp_alloc); +int rcar_gen4_ptp_clock_index(struct rcar_gen4_ptp_private *priv) +{ + if (!priv->initialized) + return -1; + + return ptp_clock_index(priv->clock); +} +EXPORT_SYMBOL_GPL(rcar_gen4_ptp_clock_index); + +void rcar_gen4_ptp_gettime64(struct rcar_gen4_ptp_private *priv, + struct timespec64 *ts) +{ + if (!priv->initialized) + return; + + priv->info.gettime64(&priv->info, ts); +} +EXPORT_SYMBOL_GPL(rcar_gen4_ptp_gettime64); + MODULE_AUTHOR("Yoshihiro Shimoda"); MODULE_DESCRIPTION("Renesas R-Car Gen4 gPTP driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/net/ethernet/renesas/rcar_gen4_ptp.h b/drivers/net/ethernet/renesas/rcar_gen4_ptp.h index 9a9c232c854e..6abaa7cc6b77 100644 --- a/drivers/net/ethernet/renesas/rcar_gen4_ptp.h +++ b/drivers/net/ethernet/renesas/rcar_gen4_ptp.h @@ -7,19 +7,15 @@ #ifndef __RCAR_GEN4_PTP_H__ #define __RCAR_GEN4_PTP_H__ -#include <linux/ptp_clock_kernel.h> - -struct rcar_gen4_ptp_private { - void __iomem *addr; - struct ptp_clock *clock; - struct ptp_clock_info info; - spinlock_t lock; /* For multiple registers access */ - s64 default_addend; - bool initialized; -}; +struct rcar_gen4_ptp_private; int rcar_gen4_ptp_register(struct rcar_gen4_ptp_private *ptp_priv, u32 rate); int rcar_gen4_ptp_unregister(struct rcar_gen4_ptp_private *ptp_priv); -struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev); +struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev, + void __iomem *addr); + +int rcar_gen4_ptp_clock_index(struct rcar_gen4_ptp_private *priv); +void rcar_gen4_ptp_gettime64(struct rcar_gen4_ptp_private *priv, + struct timespec64 *ts); #endif /* #ifndef __RCAR_GEN4_PTP_H__ */ diff --git a/drivers/net/ethernet/renesas/rswitch_main.c b/drivers/net/ethernet/renesas/rswitch_main.c index e14b21148f27..433eb2b00d10 100644 --- a/drivers/net/ethernet/renesas/rswitch_main.c +++ b/drivers/net/ethernet/renesas/rswitch_main.c @@ -1891,7 +1891,7 @@ static int rswitch_get_ts_info(struct net_device *ndev, struct kernel_ethtool_ts { struct rswitch_device *rdev = netdev_priv(ndev); - info->phc_index = ptp_clock_index(rdev->priv->ptp_priv->clock); + info->phc_index = rcar_gen4_ptp_clock_index(rdev->priv->ptp_priv); info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_TX_HARDWARE | SOF_TIMESTAMPING_RX_HARDWARE | @@ -2150,17 +2150,16 @@ static int renesas_eth_sw_probe(struct platform_device *pdev) if (attr) priv->etha_no_runtime_change = true; - priv->ptp_priv = rcar_gen4_ptp_alloc(pdev); - if (!priv->ptp_priv) - return -ENOMEM; - platform_set_drvdata(pdev, priv); priv->pdev = pdev; priv->addr = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(priv->addr)) return PTR_ERR(priv->addr); - priv->ptp_priv->addr = priv->addr + RSWITCH_GPTP_OFFSET_S4; + priv->ptp_priv = + rcar_gen4_ptp_alloc(pdev, priv->addr + RSWITCH_GPTP_OFFSET_S4); + if (!priv->ptp_priv) + return -ENOMEM; ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40)); if (ret < 0) { diff --git a/drivers/net/ethernet/renesas/rtsn.c b/drivers/net/ethernet/renesas/rtsn.c index fdb1e7b7fb06..85052b47afb9 100644 --- a/drivers/net/ethernet/renesas/rtsn.c +++ b/drivers/net/ethernet/renesas/rtsn.c @@ -104,13 +104,6 @@ static void rtsn_ctrl_data_irq(struct rtsn_private *priv, bool enable) } } -static void rtsn_get_timestamp(struct rtsn_private *priv, struct timespec64 *ts) -{ - struct rcar_gen4_ptp_private *ptp_priv = priv->ptp_priv; - - ptp_priv->info.gettime64(&ptp_priv->info, ts); -} - static int rtsn_tx_free(struct net_device *ndev, bool free_txed_only) { struct rtsn_private *priv = netdev_priv(ndev); @@ -133,7 +126,7 @@ static int rtsn_tx_free(struct net_device *ndev, bool free_txed_only) struct skb_shared_hwtstamps shhwtstamps; struct timespec64 ts; - rtsn_get_timestamp(priv, &ts); + rcar_gen4_ptp_gettime64(priv->ptp_priv, &ts); memset(&shhwtstamps, 0, sizeof(shhwtstamps)); shhwtstamps.hwtstamp = timespec64_to_ktime(ts); skb_tstamp_tx(skb, &shhwtstamps); @@ -1197,7 +1190,7 @@ static int rtsn_get_ts_info(struct net_device *ndev, { struct rtsn_private *priv = netdev_priv(ndev); - info->phc_index = ptp_clock_index(priv->ptp_priv->clock); + info->phc_index = rcar_gen4_ptp_clock_index(priv->ptp_priv); info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_TX_HARDWARE | SOF_TIMESTAMPING_RX_HARDWARE | @@ -1227,6 +1220,7 @@ static int rtsn_probe(struct platform_device *pdev) { struct rtsn_private *priv; struct net_device *ndev; + void __iomem *ptpaddr; struct resource *res; int ret; @@ -1239,12 +1233,6 @@ static int rtsn_probe(struct platform_device *pdev) priv->pdev = pdev; priv->ndev = ndev; - priv->ptp_priv = rcar_gen4_ptp_alloc(pdev); - if (!priv->ptp_priv) { - ret = -ENOMEM; - goto error_free; - } - spin_lock_init(&priv->lock); platform_set_drvdata(pdev, priv); @@ -1288,9 +1276,15 @@ static int rtsn_probe(struct platform_device *pdev) goto error_free; } - priv->ptp_priv->addr = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(priv->ptp_priv->addr)) { - ret = PTR_ERR(priv->ptp_priv->addr); + ptpaddr = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(ptpaddr)) { + ret = PTR_ERR(ptpaddr); + goto error_free; + } + + priv->ptp_priv = rcar_gen4_ptp_alloc(pdev, ptpaddr); + if (!priv->ptp_priv) { + ret = -ENOMEM; goto error_free; } |
