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-simplify-register-layout'

Niklas Söderlund says:

====================
net: ethernet: renesas: rcar_gen4_ptp: Simplify register layout

The daughter driver rcar_gen4_ptp used by both rswitch and rtsn where
upstreamed with support for possible different memory layouts on
different users. With all Gen4 boards upstream no such setup is
documented.

There are other issues related to how the rcar_gen4_ptp driver is shared
between multiple useres that needs to be cleaned up. But that will be a
larger work. So before that get some simple fixes done.

Patch 1/3 and 2/3 removes the support to allow different register
layouts on different SoCs by looking up offsets at runtime with a much
simpler interface. The new interface computes the offsets at compile
time.

While patch 3/3 is a drive-by patch taking a spurs comment and making a
lockdep check of it.

There is no intentional functional change in this series just cleaning
up in preparation of larger works to follow.
====================

Link: https://patch.msgid.link/20250908154426.3062861-1-niklas.soderlund+renesas@ragnatech.se
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+32 -83
+29 -47
drivers/net/ethernet/renesas/rcar_gen4_ptp.c
··· 12 12 #include <linux/slab.h> 13 13 14 14 #include "rcar_gen4_ptp.h" 15 - #define ptp_to_priv(ptp) container_of(ptp, struct rcar_gen4_ptp_private, info) 16 15 17 - static const struct rcar_gen4_ptp_reg_offset gen4_offs = { 18 - .enable = PTPTMEC, 19 - .disable = PTPTMDC, 20 - .increment = PTPTIVC0, 21 - .config_t0 = PTPTOVC00, 22 - .config_t1 = PTPTOVC10, 23 - .config_t2 = PTPTOVC20, 24 - .monitor_t0 = PTPGPTPTM00, 25 - .monitor_t1 = PTPGPTPTM10, 26 - .monitor_t2 = PTPGPTPTM20, 27 - }; 16 + #define PTPTMEC_REG 0x0010 17 + #define PTPTMDC_REG 0x0014 18 + #define PTPTIVC0_REG 0x0020 19 + #define PTPTOVC00_REG 0x0030 20 + #define PTPTOVC10_REG 0x0034 21 + #define PTPTOVC20_REG 0x0038 22 + #define PTPGPTPTM00_REG 0x0050 23 + #define PTPGPTPTM10_REG 0x0054 24 + #define PTPGPTPTM20_REG 0x0058 25 + 26 + #define ptp_to_priv(ptp) container_of(ptp, struct rcar_gen4_ptp_private, info) 28 27 29 28 static int rcar_gen4_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 30 29 { ··· 37 38 diff = div_s64(addend * scaled_ppm_to_ppb(scaled_ppm), NSEC_PER_SEC); 38 39 addend = neg_adj ? addend - diff : addend + diff; 39 40 40 - iowrite32(addend, ptp_priv->addr + ptp_priv->offs->increment); 41 + iowrite32(addend, ptp_priv->addr + PTPTIVC0_REG); 41 42 42 43 return 0; 43 44 } 44 45 45 - /* Caller must hold the lock */ 46 46 static void _rcar_gen4_ptp_gettime(struct ptp_clock_info *ptp, 47 47 struct timespec64 *ts) 48 48 { 49 49 struct rcar_gen4_ptp_private *ptp_priv = ptp_to_priv(ptp); 50 50 51 - ts->tv_nsec = ioread32(ptp_priv->addr + ptp_priv->offs->monitor_t0); 52 - ts->tv_sec = ioread32(ptp_priv->addr + ptp_priv->offs->monitor_t1) | 53 - ((s64)ioread32(ptp_priv->addr + ptp_priv->offs->monitor_t2) << 32); 51 + lockdep_assert_held(&ptp_priv->lock); 52 + 53 + ts->tv_nsec = ioread32(ptp_priv->addr + PTPGPTPTM00_REG); 54 + ts->tv_sec = ioread32(ptp_priv->addr + PTPGPTPTM10_REG) | 55 + ((s64)ioread32(ptp_priv->addr + PTPGPTPTM20_REG) << 32); 54 56 } 55 57 56 58 static int rcar_gen4_ptp_gettime(struct ptp_clock_info *ptp, ··· 73 73 { 74 74 struct rcar_gen4_ptp_private *ptp_priv = ptp_to_priv(ptp); 75 75 76 - iowrite32(1, ptp_priv->addr + ptp_priv->offs->disable); 77 - iowrite32(0, ptp_priv->addr + ptp_priv->offs->config_t2); 78 - iowrite32(0, ptp_priv->addr + ptp_priv->offs->config_t1); 79 - iowrite32(0, ptp_priv->addr + ptp_priv->offs->config_t0); 80 - iowrite32(1, ptp_priv->addr + ptp_priv->offs->enable); 81 - iowrite32(ts->tv_sec >> 32, ptp_priv->addr + ptp_priv->offs->config_t2); 82 - iowrite32(ts->tv_sec, ptp_priv->addr + ptp_priv->offs->config_t1); 83 - iowrite32(ts->tv_nsec, ptp_priv->addr + ptp_priv->offs->config_t0); 76 + iowrite32(1, ptp_priv->addr + PTPTMDC_REG); 77 + iowrite32(0, ptp_priv->addr + PTPTOVC20_REG); 78 + iowrite32(0, ptp_priv->addr + PTPTOVC10_REG); 79 + iowrite32(0, ptp_priv->addr + PTPTOVC00_REG); 80 + iowrite32(1, ptp_priv->addr + PTPTMEC_REG); 81 + iowrite32(ts->tv_sec >> 32, ptp_priv->addr + PTPTOVC20_REG); 82 + iowrite32(ts->tv_sec, ptp_priv->addr + PTPTOVC10_REG); 83 + iowrite32(ts->tv_nsec, ptp_priv->addr + PTPTOVC00_REG); 84 84 } 85 85 86 86 static int rcar_gen4_ptp_settime(struct ptp_clock_info *ptp, ··· 130 130 .enable = rcar_gen4_ptp_enable, 131 131 }; 132 132 133 - static int rcar_gen4_ptp_set_offs(struct rcar_gen4_ptp_private *ptp_priv, 134 - enum rcar_gen4_ptp_reg_layout layout) 135 - { 136 - if (layout != RCAR_GEN4_PTP_REG_LAYOUT) 137 - return -EINVAL; 138 - 139 - ptp_priv->offs = &gen4_offs; 140 - 141 - return 0; 142 - } 143 - 144 133 static s64 rcar_gen4_ptp_rate_to_increment(u32 rate) 145 134 { 146 135 /* Timer increment in ns. ··· 140 151 return div_s64(1000000000LL << 27, rate); 141 152 } 142 153 143 - int rcar_gen4_ptp_register(struct rcar_gen4_ptp_private *ptp_priv, 144 - enum rcar_gen4_ptp_reg_layout layout, u32 rate) 154 + int rcar_gen4_ptp_register(struct rcar_gen4_ptp_private *ptp_priv, u32 rate) 145 155 { 146 - int ret; 147 - 148 156 if (ptp_priv->initialized) 149 157 return 0; 150 158 151 159 spin_lock_init(&ptp_priv->lock); 152 160 153 - ret = rcar_gen4_ptp_set_offs(ptp_priv, layout); 154 - if (ret) 155 - return ret; 156 - 157 161 ptp_priv->default_addend = rcar_gen4_ptp_rate_to_increment(rate); 158 - iowrite32(ptp_priv->default_addend, ptp_priv->addr + ptp_priv->offs->increment); 162 + iowrite32(ptp_priv->default_addend, ptp_priv->addr + PTPTIVC0_REG); 159 163 ptp_priv->clock = ptp_clock_register(&ptp_priv->info, NULL); 160 164 if (IS_ERR(ptp_priv->clock)) 161 165 return PTR_ERR(ptp_priv->clock); 162 166 163 - iowrite32(0x01, ptp_priv->addr + ptp_priv->offs->enable); 167 + iowrite32(0x01, ptp_priv->addr + PTPTMEC_REG); 164 168 ptp_priv->initialized = true; 165 169 166 170 return 0; ··· 162 180 163 181 int rcar_gen4_ptp_unregister(struct rcar_gen4_ptp_private *ptp_priv) 164 182 { 165 - iowrite32(1, ptp_priv->addr + ptp_priv->offs->disable); 183 + iowrite32(1, ptp_priv->addr + PTPTMDC_REG); 166 184 167 185 return ptp_clock_unregister(ptp_priv->clock); 168 186 }
+1 -32
drivers/net/ethernet/renesas/rcar_gen4_ptp.h
··· 11 11 12 12 #define RCAR_GEN4_GPTP_OFFSET_S4 0x00018000 13 13 14 - enum rcar_gen4_ptp_reg_layout { 15 - RCAR_GEN4_PTP_REG_LAYOUT 16 - }; 17 - 18 14 /* driver's definitions */ 19 15 #define RCAR_GEN4_RXTSTAMP_ENABLED BIT(0) 20 16 #define RCAR_GEN4_RXTSTAMP_TYPE_V2_L2_EVENT BIT(1) ··· 19 23 20 24 #define RCAR_GEN4_TXTSTAMP_ENABLED BIT(0) 21 25 22 - #define PTPRO 0 23 - 24 - enum rcar_gen4_ptp_reg { 25 - PTPTMEC = PTPRO + 0x0010, 26 - PTPTMDC = PTPRO + 0x0014, 27 - PTPTIVC0 = PTPRO + 0x0020, 28 - PTPTOVC00 = PTPRO + 0x0030, 29 - PTPTOVC10 = PTPRO + 0x0034, 30 - PTPTOVC20 = PTPRO + 0x0038, 31 - PTPGPTPTM00 = PTPRO + 0x0050, 32 - PTPGPTPTM10 = PTPRO + 0x0054, 33 - PTPGPTPTM20 = PTPRO + 0x0058, 34 - }; 35 - 36 - struct rcar_gen4_ptp_reg_offset { 37 - u16 enable; 38 - u16 disable; 39 - u16 increment; 40 - u16 config_t0; 41 - u16 config_t1; 42 - u16 config_t2; 43 - u16 monitor_t0; 44 - u16 monitor_t1; 45 - u16 monitor_t2; 46 - }; 47 26 48 27 struct rcar_gen4_ptp_private { 49 28 void __iomem *addr; 50 29 struct ptp_clock *clock; 51 30 struct ptp_clock_info info; 52 - const struct rcar_gen4_ptp_reg_offset *offs; 53 31 spinlock_t lock; /* For multiple registers access */ 54 32 u32 tstamp_tx_ctrl; 55 33 u32 tstamp_rx_ctrl; ··· 31 61 bool initialized; 32 62 }; 33 63 34 - int rcar_gen4_ptp_register(struct rcar_gen4_ptp_private *ptp_priv, 35 - enum rcar_gen4_ptp_reg_layout layout, u32 rate); 64 + int rcar_gen4_ptp_register(struct rcar_gen4_ptp_private *ptp_priv, u32 rate); 36 65 int rcar_gen4_ptp_unregister(struct rcar_gen4_ptp_private *ptp_priv); 37 66 struct rcar_gen4_ptp_private *rcar_gen4_ptp_alloc(struct platform_device *pdev); 38 67
+1 -2
drivers/net/ethernet/renesas/rswitch_main.c
··· 2090 2090 if (err < 0) 2091 2091 goto err_fwd_init; 2092 2092 2093 - err = rcar_gen4_ptp_register(priv->ptp_priv, RCAR_GEN4_PTP_REG_LAYOUT, 2094 - clk_get_rate(priv->clk)); 2093 + err = rcar_gen4_ptp_register(priv->ptp_priv, clk_get_rate(priv->clk)); 2095 2094 if (err < 0) 2096 2095 goto err_ptp_register; 2097 2096
+1 -2
drivers/net/ethernet/renesas/rtsn.c
··· 1330 1330 1331 1331 device_set_wakeup_capable(&pdev->dev, 1); 1332 1332 1333 - ret = rcar_gen4_ptp_register(priv->ptp_priv, RCAR_GEN4_PTP_REG_LAYOUT, 1334 - clk_get_rate(priv->clk)); 1333 + ret = rcar_gen4_ptp_register(priv->ptp_priv, clk_get_rate(priv->clk)); 1335 1334 if (ret) 1336 1335 goto error_pm; 1337 1336