[v1] net/ice: initialize PHC time with current time of day

Message ID 20240812051716.3763713-1-soumyadeep.hore@intel.com (mailing list archive)
State New
Delegated to: Bruce Richardson
Headers
Series [v1] net/ice: initialize PHC time with current time of day |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS

Commit Message

Soumyadeep Hore Aug. 12, 2024, 5:17 a.m. UTC
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.hore@intel.com>
---
 drivers/net/ice/ice_ethdev.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
  

Patch

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));