net: dsa: sja1105: Switch to hardware operations for PTP
Vladimir Oltean
maintainerPATCH v2 1/1 net: dsa: sja1105: Switch to hardware operations for PTP
Adjusting the hardware clock (PTPCLKVAL, PTPCLKADD, PTPCLKRATE) is a requirement for the auxiliary PTP functionality of the switch (TTEthernet, PPS input, PPS output).
Therefore we need to switch to using these registers to keep a synchronized time in hardware, instead of the timecounter/cyclecounter implementation, which is reliant on the free-running PTPTSCLK.
---
This patch deletes the timecounter/cyclecounter implementation of a free-running PHC and replaces it with actual hardware corrections of the PTP timestamping clock.
It has been broken out of the "tc-taprio offload for SJA1105 DSA" series:
https://lore.kernel.org/netdev/[email protected]/
As such I have marked it as v2.
Changes in v2:
- Rebased on top of the new SPI API: sja1105_xfer_u32, sja1105_xfer_u64, sja1105_xfer_buf.
- Rebased on top of the PTP structures migration from sja1105_private to sja1105_ptp_data.
- Renamed ptpclk to ptpclkval, which is the register's name in UM10944.pdf.
- Do not discard SPI errors in sja1105_ptpclkval_read.
- Changed the 2nd paragraph of the commit message.
drivers/net/dsa/sja1105/sja1105.h | 3 +- drivers/net/dsa/sja1105/sja1105_ptp.c | 218 +++++++++++++------------- drivers/net/dsa/sja1105/sja1105_ptp.h | 25 ++- drivers/net/dsa/sja1105/sja1105_spi.c | 6 +- 4 files changed, 128 insertions(+), 124 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +1 -2
@@ -33,9 +33,8 @@ struct sja1105_regs {u64 config;u64 rmii_pll1;u64 ptp_control; -u64 ptpclk; +u64 ptpclkval;u64 ptpclkrate; -u64 ptptsclk;u64 ptpegr_ts[SJA1105_NUM_PORTS ];u64 pad_mii_tx[SJA1105_NUM_PORTS ];u64 pad_mii_id[SJA1105_NUM_PORTS ];
drivers/net/dsa/sja1105/sja1105_ptp.c +107 -111
359 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_ptp.h +18 -7
@@ -6,21 +6,32 @@#if IS_ENABLED (CONFIG_NET_DSA_SJA1105_PTP ) +/* Timestamps are in units of 8 ns clock ticks (equivalent to +* a fixed 125 MHz clock). +*/ +#define SJA1105_TICK_NS 8 + +static inline s64 ns_to_sja1105_ticks (s64 ns) +{ +return ns /SJA1105_TICK_NS ; +} + +static inline s64 sja1105_ticks_to_ns (s64 ticks) +{ +return ticks *SJA1105_TICK_NS ; +} +struct sja1105_ptp_cmd {u64 resptp;/* reset */ +u64 corrclk4ts;/* use the corrected clock for timestamps */ +u64 ptpclkadd;/* enum sja1105_ptp_clk_mode */ };struct sja1105_ptp_data {struct ptp_clock_info caps;struct ptp_clock *clock;struct sja1105_ptp_cmd cmd; -/* The cycle counter translates the PTP timestamps (based on -* a free-running counter) into a software time domain. -*/ -struct cyclecounter tstamp_cc; -struct timecounter tstamp_tc; -struct delayed_work refresh_work; -/* Serializes all operations on the cycle counter */ +/* Serializes all operations on the PTP hardware clock */ struct mutex lock; };
drivers/net/dsa/sja1105/sja1105_spi.c +2 -4
@@ -516,9 +516,8 @@ static struct sja1105_regs sja1105et_regs = { .rmii_ext_tx_clk = {0x100018, 0x10001F, 0x100026, 0x10002D, 0x100034}, .ptpegr_ts = {0xC0, 0xC2, 0xC4, 0xC6, 0xC8}, .ptp_control = 0x17, - .ptpclk = 0x18, /* Spans 0x18 to 0x19 */ + .ptpclkval = 0x18, /* Spans 0x18 to 0x19 */ .ptpclkrate = 0x1A, - .ptptsclk = 0x1B, /* Spans 0x1B to 0x1C */ }; static struct sja1105_regs sja1105pqrs_regs = {
@@ -547,9 +546,8 @@ static struct sja1105_regs sja1105pqrs_regs = { .qlevel = {0x604, 0x614, 0x624, 0x634, 0x644}, .ptpegr_ts = {0xC0, 0xC4, 0xC8, 0xCC, 0xD0}, .ptp_control = 0x18, - .ptpclk = 0x19, + .ptpclkval = 0x19, .ptpclkrate = 0x1B, - .ptptsclk = 0x1C, }; struct sja1105_info sja1105e_info = {
Signature · 1 line
2.17.1
From: Vladimir Oltean <[email protected]>
Date: Wed, 16 Oct 2019 21:41:02 +0300
Quoted 9 lines
Adjusting the hardware clock (PTPCLKVAL, PTPCLKADD, PTPCLKRATE) is a requirement for the auxiliary PTP functionality of the switch (TTEthernet, PPS input, PPS output).
Therefore we need to switch to using these registers to keep a synchronized time in hardware, instead of the timecounter/cyclecounter implementation, which is reliant on the free-running PTPTSCLK.
Signed-off-by Vladimir Oltean <[email protected]>
Applied, thanks.