net: dsa: hellcreek: Add support for hardware timestamping
authorKamil Alkhouri <kamil.alkhouri@hs-offenburg.de>
Tue, 3 Nov 2020 07:10:58 +0000 (08:10 +0100)
committerJakub Kicinski <kuba@kernel.org>
Thu, 5 Nov 2020 22:04:49 +0000 (14:04 -0800)
commitf0d4ba9eff75a79fccb7793f4d9f12303d458603
treea429e4c4e9c6b3828be46d2a4f8086419981d24c
parentddd56dfe52c987d82964595902db0600970ef406
net: dsa: hellcreek: Add support for hardware timestamping

The switch has the ability to take hardware generated time stamps per port for
PTPv2 event messages in Rx and Tx direction. That is useful for achieving needed
time synchronization precision for TSN devices/switches. So add support for it.

There are two directions:

 * RX

   The switch has a single register per port to capture a timestamp. That
   mechanism is not used due to correlation problems. If the software processing
   is too slow and a PTPv2 event message is received before the previous one has
   been processed, false timestamps will be captured. Therefore, the switch can
   do "inline" timestamping which means it can insert the nanoseconds part of
   the timestamp directly into the PTPv2 event message. The reserved field (4
   bytes) is leveraged for that. This might not be in accordance with (older)
   PTP standards, but is the only way to get reliable results.

 * TX

   In Tx direction there is no correlation problem, because the software and the
   driver has to ensure that only one event message is "on the fly". However,
   the switch provides also a mechanism to check whether a timestamp is
   lost. That can only happen when a timestamp is read and at this point another
   message is timestamped. So, that lost bit is checked just in case to indicate
   to the user that the driver or the software is somewhat buggy.

Signed-off-by: Kamil Alkhouri <kamil.alkhouri@hs-offenburg.de>
Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/dsa/hirschmann/Makefile
drivers/net/dsa/hirschmann/hellcreek.c
drivers/net/dsa/hirschmann/hellcreek.h
drivers/net/dsa/hirschmann/hellcreek_hwtstamp.c [new file with mode: 0644]
drivers/net/dsa/hirschmann/hellcreek_hwtstamp.h [new file with mode: 0644]
drivers/net/dsa/hirschmann/hellcreek_ptp.c
drivers/net/dsa/hirschmann/hellcreek_ptp.h