The PHC main timer for ice pmd enabled drivers should be initialised to current time of day on enabling timesync else it will be initialized to 0 giving wrong timestamps.
Signed-off-by: Soumyadeep Hore <soumyadeep.h...@intel.com> --- drivers/net/ice/ice_ethdev.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/net/ice/ice_ethdev.c b/drivers/net/ice/ice_ethdev.c index 304f959b7e..da5a5eb5d6 100644 --- a/drivers/net/ice/ice_ethdev.c +++ b/drivers/net/ice/ice_ethdev.c @@ -6437,6 +6437,22 @@ ice_dev_udp_tunnel_port_del(struct rte_eth_dev *dev, return ret; } +/** + * ice_ptp_write_init - Set PHC time to provided value + * @hw: Hardware private structure + * + * Set the PHC time to CLOCK_REALTIME + */ +static int ice_ptp_write_init(struct ice_hw *hw) +{ + uint64_t ns; + struct timespec sys_time; + clock_gettime(CLOCK_REALTIME, &sys_time); + ns = rte_timespec_to_ns(&sys_time); + + return ice_ptp_init_time(hw, ns, true); +} + static int ice_timesync_enable(struct rte_eth_dev *dev) { @@ -6466,6 +6482,16 @@ ice_timesync_enable(struct rte_eth_dev *dev) } } + if (!ice_ptp_lock(hw)) { + ice_debug(hw, ICE_DBG_PTP, "Failed to acquire PTP semaphore\n"); + return ICE_ERR_NOT_READY; + } + + ret = ice_ptp_write_init(hw); + ice_ptp_unlock(hw); + if (ret) + PMD_INIT_LOG(ERR, "Failed to set current system time to PHC timer\n"); + /* Initialize cycle counters for system time/RX/TX timestamp */ memset(&ad->systime_tc, 0, sizeof(struct rte_timecounter)); memset(&ad->rx_tstamp_tc, 0, sizeof(struct rte_timecounter)); -- 2.43.0