• Jonathan Lemon's avatar
    ptp: ocp: Add timestamp window adjustment · 1acffc6e
    Jonathan Lemon authored
    The following process is used to read the PHC clock and correlate
    the reading with the "correct" system time.
    
    - get starting timestamp
    - issue PCI write command
    - issue PCI read command
    - get ending timestamp
    - read latched sec/nsec registers
    
    The write command is posted to PCI bus and returns.  When the write
    arrives at the FPGA, the PHC time is latched into the sec/nsec registers,
    and a flag is set indicating the registers are valid.  The read command
    returns this flag, and the time retrieval proceeds.
    
    Below is a non-scaled picture of the timing diagram involved.  The
    PHC time corresponds to some SYS time between [start, end].  Userspace
    usually uses the midpoint between [start, end] to estimate the PCI
    delay and match this with the PHC time.
    
     [start] |                |
       write |-------+        |
    	 |        \       |
        read |----+    +----->|
    	 |     \          * PHC time latched into register
    	 |      \         |
    midpoint |       +------->|
    	 |                |
    	 |                |
    	 |           +----|
    	 |          /     |
    	 |<--------+      |
       [end] |                |
    
    As the diagram indicates, the PHC time is latched before the midpoint,
    so the system clock time is slightly off the real PHC time.  This shows
    up as a phase error with an oscilliscope.
    
    The workaround here is to provide a tunable which reduces (shrinks)
    the end time in the above diagram.  This in turn moves the calculated
    midpoint so the system time and PHC time are in agreemment.
    
    Currently, the adjustment reduces the end time by 3/16th of the entire
    window.  E.g.:  [start, end] ==> [start, (end - (3/16 * end)], which
    produces reasonably good results.
    
    Also reduce delays by just writing to the clock control register
    instead of performing a read/modify/write sequence, as the contents
    of the control register are known.
    Signed-off-by: default avatarJonathan Lemon <jonathan.lemon@gmail.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    1acffc6e
ptp_ocp.c 56.4 KB