net: macb: Add support for 1588 for Zynq Ultrascale+ MPSoC
Cadence GEM in Zynq Ultrascale+ MPSoC supports 1588 and provides a
102 bit time counter with 48 bits for seconds, 30 bits for nsecs and
24 bits for sub-nsecs. The timestamp is made available to the SW through
registers as well as (more precisely) through upper two words in
an extended BD.
This patch does the following:
- Adds MACB_CAPS_TSU in zynqmp_config.
- Registers to ptp clock framework (after checking for timestamp support in
IP and capability in config).
- TX BD and RX BD control registers are written to populate timestamp in
extended BD words.
- Timer initialization is done by writing time of day to the timer counter.
- ns increment register is programmed as NS_PER_SEC/TSU_CLK.
For a 24 bit subns precision, the subns increment equals
remainder of (NS_PER_SEC/TSU_CLK) * (2^24).
TSU (Time stamp unit) clock is obtained by the driver from devicetree.
- HW time stamp capabilities are advertised via ethtool and macb ioctl is
updated accordingly.
- For all PTP event frames, nanoseconds and the lower 5 bits of seconds are
obtained from the BD. This offers a precise timestamp. The upper bits
(which dont vary between consecutive packets) are obtained from the
TX/RX PTP event/PEER registers. The timestamp obtained thus is updated
in skb for upper layers to access.
- The drivers register functions with ptp to perform time and frequency
adjustment.
- Time adjustment is done by writing to the 1558_ADJUST register.
The controller will read the delta in this register and update the timer
counter register. Alternatively, for large time offset adjustments,
the driver reads the secs and nsecs counter values, adds/subtracts the
delta and updates the timer counter. In order to be as precise as possible,
nsecs counter is read again if secs has incremented during the counter read.
- Frequency adjustment is not directly supported by this IP.
addend is the initial value ns increment and similarly addendesub.
The ppb (parts per billion) provided is used as
ns_incr = addend +/- (ppb/rate).
Similarly the remainder of the above is used to populate subns increment.
In case the ppb requested is negative AND subns adjustment greater than
the addendsub, ns_incr is reduced by 1 and subns_incr is adjusted in
positive accordingly.