Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+57 -36
+33 -1
drivers/net/ethernet/renesas/rcar_gen4_ptp.c
··· 9 9 #include <linux/kernel.h> 10 10 #include <linux/module.h> 11 11 #include <linux/platform_device.h> 12 + #include <linux/ptp_clock_kernel.h> 12 13 #include <linux/slab.h> 13 14 14 15 #include "rcar_gen4_ptp.h" ··· 23 22 #define PTPGPTPTM00_REG 0x0050 24 23 #define PTPGPTPTM10_REG 0x0054 25 24 #define PTPGPTPTM20_REG 0x0058 25 + 26 + struct rcar_gen4_ptp_private { 27 + void __iomem *addr; 28 + struct ptp_clock *clock; 29 + struct ptp_clock_info info; 30 + spinlock_t lock; /* For multiple registers access */ 31 + s64 default_addend; 32 + bool initialized; 33 + }; 26 34 27 35 #define ptp_to_priv(ptp) container_of(ptp, struct rcar_gen4_ptp_private, info) 28 36 ··· 178 168 } 179 169 EXPORT_SYMBOL_GPL(rcar_gen4_ptp_unregister); 180 170 181 - struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev) 171 + struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev, 172 + void __iomem *addr) 182 173 { 183 174 struct rcar_gen4_ptp_private *ptp; 184 175 ··· 189 178 190 179 ptp->info = rcar_gen4_ptp_info; 191 180 181 + ptp->addr = addr; 182 + 192 183 return ptp; 193 184 } 194 185 EXPORT_SYMBOL_GPL(rcar_gen4_ptp_alloc); 186 + 187 + int rcar_gen4_ptp_clock_index(struct rcar_gen4_ptp_private *priv) 188 + { 189 + if (!priv->initialized) 190 + return -1; 191 + 192 + return ptp_clock_index(priv->clock); 193 + } 194 + EXPORT_SYMBOL_GPL(rcar_gen4_ptp_clock_index); 195 + 196 + void rcar_gen4_ptp_gettime64(struct rcar_gen4_ptp_private *priv, 197 + struct timespec64 *ts) 198 + { 199 + if (!priv->initialized) 200 + return; 201 + 202 + priv->info.gettime64(&priv->info, ts); 203 + } 204 + EXPORT_SYMBOL_GPL(rcar_gen4_ptp_gettime64); 195 205 196 206 MODULE_AUTHOR("Yoshihiro Shimoda"); 197 207 MODULE_DESCRIPTION("Renesas R-Car Gen4 gPTP driver");
+7 -11
drivers/net/ethernet/renesas/rcar_gen4_ptp.h
··· 7 7 #ifndef __RCAR_GEN4_PTP_H__ 8 8 #define __RCAR_GEN4_PTP_H__ 9 9 10 - #include <linux/ptp_clock_kernel.h> 11 - 12 - struct rcar_gen4_ptp_private { 13 - void __iomem *addr; 14 - struct ptp_clock *clock; 15 - struct ptp_clock_info info; 16 - spinlock_t lock; /* For multiple registers access */ 17 - s64 default_addend; 18 - bool initialized; 19 - }; 10 + struct rcar_gen4_ptp_private; 20 11 21 12 int rcar_gen4_ptp_register(struct rcar_gen4_ptp_private *ptp_priv, u32 rate); 22 13 int rcar_gen4_ptp_unregister(struct rcar_gen4_ptp_private *ptp_priv); 23 - struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev); 14 + struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev, 15 + void __iomem *addr); 16 + 17 + int rcar_gen4_ptp_clock_index(struct rcar_gen4_ptp_private *priv); 18 + void rcar_gen4_ptp_gettime64(struct rcar_gen4_ptp_private *priv, 19 + struct timespec64 *ts); 24 20 25 21 #endif /* #ifndef __RCAR_GEN4_PTP_H__ */
+5 -6
drivers/net/ethernet/renesas/rswitch_main.c
··· 1891 1891 { 1892 1892 struct rswitch_device *rdev = netdev_priv(ndev); 1893 1893 1894 - info->phc_index = ptp_clock_index(rdev->priv->ptp_priv->clock); 1894 + info->phc_index = rcar_gen4_ptp_clock_index(rdev->priv->ptp_priv); 1895 1895 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | 1896 1896 SOF_TIMESTAMPING_TX_HARDWARE | 1897 1897 SOF_TIMESTAMPING_RX_HARDWARE | ··· 2150 2150 if (attr) 2151 2151 priv->etha_no_runtime_change = true; 2152 2152 2153 - priv->ptp_priv = rcar_gen4_ptp_alloc(pdev); 2154 - if (!priv->ptp_priv) 2155 - return -ENOMEM; 2156 - 2157 2153 platform_set_drvdata(pdev, priv); 2158 2154 priv->pdev = pdev; 2159 2155 priv->addr = devm_ioremap_resource(&pdev->dev, res); 2160 2156 if (IS_ERR(priv->addr)) 2161 2157 return PTR_ERR(priv->addr); 2162 2158 2163 - priv->ptp_priv->addr = priv->addr + RSWITCH_GPTP_OFFSET_S4; 2159 + priv->ptp_priv = 2160 + rcar_gen4_ptp_alloc(pdev, priv->addr + RSWITCH_GPTP_OFFSET_S4); 2161 + if (!priv->ptp_priv) 2162 + return -ENOMEM; 2164 2163 2165 2164 ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40)); 2166 2165 if (ret < 0) {
+12 -18
drivers/net/ethernet/renesas/rtsn.c
··· 104 104 } 105 105 } 106 106 107 - static void rtsn_get_timestamp(struct rtsn_private *priv, struct timespec64 *ts) 108 - { 109 - struct rcar_gen4_ptp_private *ptp_priv = priv->ptp_priv; 110 - 111 - ptp_priv->info.gettime64(&ptp_priv->info, ts); 112 - } 113 - 114 107 static int rtsn_tx_free(struct net_device *ndev, bool free_txed_only) 115 108 { 116 109 struct rtsn_private *priv = netdev_priv(ndev); ··· 126 133 struct skb_shared_hwtstamps shhwtstamps; 127 134 struct timespec64 ts; 128 135 129 - rtsn_get_timestamp(priv, &ts); 136 + rcar_gen4_ptp_gettime64(priv->ptp_priv, &ts); 130 137 memset(&shhwtstamps, 0, sizeof(shhwtstamps)); 131 138 shhwtstamps.hwtstamp = timespec64_to_ktime(ts); 132 139 skb_tstamp_tx(skb, &shhwtstamps); ··· 1190 1197 { 1191 1198 struct rtsn_private *priv = netdev_priv(ndev); 1192 1199 1193 - info->phc_index = ptp_clock_index(priv->ptp_priv->clock); 1200 + info->phc_index = rcar_gen4_ptp_clock_index(priv->ptp_priv); 1194 1201 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | 1195 1202 SOF_TIMESTAMPING_TX_HARDWARE | 1196 1203 SOF_TIMESTAMPING_RX_HARDWARE | ··· 1220 1227 { 1221 1228 struct rtsn_private *priv; 1222 1229 struct net_device *ndev; 1230 + void __iomem *ptpaddr; 1223 1231 struct resource *res; 1224 1232 int ret; 1225 1233 ··· 1232 1238 priv = netdev_priv(ndev); 1233 1239 priv->pdev = pdev; 1234 1240 priv->ndev = ndev; 1235 - 1236 - priv->ptp_priv = rcar_gen4_ptp_alloc(pdev); 1237 - if (!priv->ptp_priv) { 1238 - ret = -ENOMEM; 1239 - goto error_free; 1240 - } 1241 1241 1242 1242 spin_lock_init(&priv->lock); 1243 1243 platform_set_drvdata(pdev, priv); ··· 1276 1288 goto error_free; 1277 1289 } 1278 1290 1279 - priv->ptp_priv->addr = devm_ioremap_resource(&pdev->dev, res); 1280 - if (IS_ERR(priv->ptp_priv->addr)) { 1281 - ret = PTR_ERR(priv->ptp_priv->addr); 1291 + ptpaddr = devm_ioremap_resource(&pdev->dev, res); 1292 + if (IS_ERR(ptpaddr)) { 1293 + ret = PTR_ERR(ptpaddr); 1294 + goto error_free; 1295 + } 1296 + 1297 + priv->ptp_priv = rcar_gen4_ptp_alloc(pdev, ptpaddr); 1298 + if (!priv->ptp_priv) { 1299 + ret = -ENOMEM; 1282 1300 goto error_free; 1283 1301 } 1284 1302