The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH net-next] octeontx2-af: return tsc value along with PTP clock
@ 2026-08-06 16:16 nshettyj
  2026-08-06 23:00 ` Vadim Fedorenko
  0 siblings, 1 reply; 2+ messages in thread
From: nshettyj @ 2026-08-06 16:16 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: Harman Kalra, Nitin Shetty J, Sunil Goutham, Ratheesh Kannoth,
	Geetha sowjanya, Subbaraya Sundeep, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran

From: Harman Kalra <hkalra@marvell.com>

This patch updates the existing PTP_OP_GET_CLOCK mbox message to
return the timestamp counter value, tsc (cntvct_el0 or pmccntr_el0)
along with the PTP HI clock value.

In some debugging scenarios, a user might need to read the PTP HI
clock value in the fastpath to know how many ticks have been spent
since the reception of the packet (as the packet reception tick value
is already appended to the packet by CGX). If the PTP_OP_GET_CLOCK
mbox message is sent every time the user wants to record the PTP HI
clock value, it will bring down performance to a great extent as mbox
communication is a very expensive process.

To handle this, the PTP HI clock can be derived from the timestamp
counter (tsc, which could be running at 100MHz or system freq) using
two parameters: freq multiplier (ratio of frequencies of PTP HI clock
and tsc) and clock delta (by how much tsc is lagging from PTP HI
clock).

By returning both the PTP_HI value and the tsc value simultaneously
via PTP_OP_GET_CLOCK, the consumer can calculate these parameters
without being affected by mbox propagation delay:
     freq_mult = (freq of PTP HI clock) / (freq of tsc counter)
     clk_delta = (PTP_HI clock value / freq_mult) - (tsc val)

Now, whenever the user wants to know the PTP HI clock in the fastpath,
it can be derived from the local tsc counter:
     PTP_HI val = (tsc value + clk_delta) * freq_mult

Signed-off-by: Harman Kalra <hkalra@marvell.com>
Signed-off-by: Nitin Shetty J <nshettyj@marvell.com>
---
 .../net/ethernet/marvell/octeontx2/af/mbox.h  |  1 +
 .../net/ethernet/marvell/octeontx2/af/ptp.c   | 26 ++++++++++++++++---
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/mbox.h b/drivers/net/ethernet/marvell/octeontx2/af/mbox.h
index 73f743e4a83d..21c3d3d5018e 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/mbox.h
+++ b/drivers/net/ethernet/marvell/octeontx2/af/mbox.h
@@ -2010,6 +2010,7 @@ struct ptp_req {
 	struct mbox_msghdr hdr;
 	u8 op;
 	s64 scaled_ppm;
+	u8 is_pmu;
 	u64 thresh;
 	u64 period;
 	int pps_on;
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/ptp.c b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c
index 58e62e955554..0b66a86246b6 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/ptp.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c
@@ -356,10 +356,27 @@ static int ptp_adjfine(struct ptp *ptp, long scaled_ppm)
 	return 0;
 }
 
-static int ptp_get_clock(struct ptp *ptp, u64 *clk)
+static inline u64 get_tsc(bool is_pmu)
 {
-	/* Return the current PTP clock */
-	*clk = ptp->read_ptp_tstmp(ptp);
+#if defined(CONFIG_ARM64)
+	return is_pmu ? read_sysreg(pmccntr_el0) : read_sysreg(cntvct_el0);
+#else
+	return 0;
+#endif
+}
+
+static int ptp_get_clock(struct ptp *ptp, bool is_pmu, u64 *clk, u64 *tsc)
+{
+	u64 end, start;
+	u8 retries = 0;
+
+	do {
+		start = get_tsc(0);
+		*tsc = get_tsc(is_pmu);
+		*clk = ptp->read_ptp_tstmp(ptp);
+		end = get_tsc(0);
+		retries++;
+	} while (((end - start) > 50) && retries < 5);
 
 	return 0;
 }
@@ -636,7 +653,8 @@ int rvu_mbox_handler_ptp_op(struct rvu *rvu, struct ptp_req *req,
 		err = ptp_adjfine(rvu->ptp, req->scaled_ppm);
 		break;
 	case PTP_OP_GET_CLOCK:
-		err = ptp_get_clock(rvu->ptp, &rsp->clk);
+		err = ptp_get_clock(rvu->ptp, req->is_pmu, &rsp->clk,
+				    &rsp->tsc);
 		break;
 	case PTP_OP_GET_TSTMP:
 		err = ptp_get_tstmp(rvu->ptp, &rsp->clk);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-06 23:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-06 16:16 [PATCH net-next] octeontx2-af: return tsc value along with PTP clock nshettyj
2026-08-06 23:00 ` Vadim Fedorenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox