netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 1/2] ptp: introduce PTP_CLOCK_EXTOFF event for the measured external offset
@ 2023-11-27 20:01 Min Li
  2023-11-29  3:58 ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Min Li @ 2023-11-27 20:01 UTC (permalink / raw)
  To: richardcochran, lee; +Cc: linux-kernel, netdev, Min Li

From: Min Li <min.li.xe@renesas.com>

This change is for the PHC devices that can measure the phase offset
between PHC signal and the external signal, such as the 1PPS signal of
GNSS. Reporting PTP_CLOCK_EXTOFF to user space will be piggy-backed to
the existing ptp_extts_event so that application such as ts2phc can
poll the external offset the same way as extts. Hence, ts2phc can use
the offset to achieve the alignment between PHC and the external signal
by the help of either SW or HW filters.

Signed-off-by: Min Li <min.li.xe@renesas.com>
---
 drivers/ptp/ptp_clock.c          | 12 +++++++++---
 include/linux/ptp_clock_kernel.h |  3 +++
 include/uapi/linux/ptp_clock.h   |  9 +++++++--
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index 3134568af622..17aacdf37561 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -48,14 +48,19 @@ static void enqueue_external_timestamp(struct timestamp_event_queue *queue,
 	s64 seconds;
 	u32 remainder;
 
-	seconds = div_u64_rem(src->timestamp, 1000000000, &remainder);
+	if (src->type != PTP_CLOCK_EXTOFF)
+		seconds = div_u64_rem(src->timestamp, 1000000000, &remainder);
 
 	spin_lock_irqsave(&queue->lock, flags);
 
 	dst = &queue->buf[queue->tail];
 	dst->index = src->index;
-	dst->t.sec = seconds;
-	dst->t.nsec = remainder;
+	if (src->type != PTP_CLOCK_EXTOFF) {
+		dst->t.sec = seconds;
+		dst->t.nsec = remainder;
+	} else {
+		dst->offset_ns = src->offset;
+	}
 
 	if (!queue_free(queue))
 		queue->head = (queue->head + 1) % PTP_MAX_TIMESTAMPS;
@@ -416,6 +421,7 @@ void ptp_clock_event(struct ptp_clock *ptp, struct ptp_clock_event *event)
 		break;
 
 	case PTP_CLOCK_EXTTS:
+	case PTP_CLOCK_EXTOFF:
 		/* Enqueue timestamp on selected queues */
 		spin_lock_irqsave(&ptp->tsevqs_lock, flags);
 		list_for_each_entry(tsevq, &ptp->tsevqs, qlist) {
diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h
index 1ef4e0f9bd2a..6e4b8206c7d0 100644
--- a/include/linux/ptp_clock_kernel.h
+++ b/include/linux/ptp_clock_kernel.h
@@ -200,6 +200,7 @@ struct ptp_clock;
 enum ptp_clock_events {
 	PTP_CLOCK_ALARM,
 	PTP_CLOCK_EXTTS,
+	PTP_CLOCK_EXTOFF,
 	PTP_CLOCK_PPS,
 	PTP_CLOCK_PPSUSR,
 };
@@ -210,6 +211,7 @@ enum ptp_clock_events {
  * @type:  One of the ptp_clock_events enumeration values.
  * @index: Identifies the source of the event.
  * @timestamp: When the event occurred (%PTP_CLOCK_EXTTS only).
+ * @offset:    When the event occurred (%PTP_CLOCK_EXTOFF only).
  * @pps_times: When the event occurred (%PTP_CLOCK_PPSUSR only).
  */
 
@@ -218,6 +220,7 @@ struct ptp_clock_event {
 	int index;
 	union {
 		u64 timestamp;
+		s64 offset;
 		struct pps_event_time pps_times;
 	};
 };
diff --git a/include/uapi/linux/ptp_clock.h b/include/uapi/linux/ptp_clock.h
index da700999cad4..17ecbe755f26 100644
--- a/include/uapi/linux/ptp_clock.h
+++ b/include/uapi/linux/ptp_clock.h
@@ -32,6 +32,7 @@
 #define PTP_RISING_EDGE    (1<<1)
 #define PTP_FALLING_EDGE   (1<<2)
 #define PTP_STRICT_FLAGS   (1<<3)
+#define PTP_EXT_OFFSET     (1<<4)
 #define PTP_EXTTS_EDGES    (PTP_RISING_EDGE | PTP_FALLING_EDGE)
 
 /*
@@ -40,7 +41,8 @@
 #define PTP_EXTTS_VALID_FLAGS	(PTP_ENABLE_FEATURE |	\
 				 PTP_RISING_EDGE |	\
 				 PTP_FALLING_EDGE |	\
-				 PTP_STRICT_FLAGS)
+				 PTP_STRICT_FLAGS |	\
+				 PTP_EXT_OFFSET)
 
 /*
  * flag fields valid for the original PTP_EXTTS_REQUEST ioctl.
@@ -228,7 +230,10 @@ struct ptp_pin_desc {
 #define PTP_MASK_EN_SINGLE  _IOW(PTP_CLK_MAGIC, 20, unsigned int)
 
 struct ptp_extts_event {
-	struct ptp_clock_time t; /* Time event occured. */
+	union {
+		struct ptp_clock_time t; /* Time event occured. */
+		__s64 offset_ns;         /* Offset event occured */
+	};
 	unsigned int index;      /* Which channel produced the event. */
 	unsigned int flags;      /* Reserved for future use. */
 	unsigned int rsv[2];     /* Reserved for future use. */
-- 
2.39.2


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

* Re: [PATCH net-next 1/2] ptp: introduce PTP_CLOCK_EXTOFF event for the measured external offset
  2023-11-27 20:01 [PATCH net-next 1/2] ptp: introduce PTP_CLOCK_EXTOFF event for the measured external offset Min Li
@ 2023-11-29  3:58 ` Jakub Kicinski
  2023-11-29 16:59   ` Min Li
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2023-11-29  3:58 UTC (permalink / raw)
  To: Min Li; +Cc: richardcochran, lee, linux-kernel, netdev, Min Li

On Mon, 27 Nov 2023 15:01:29 -0500 Min Li wrote:
> This change is for the PHC devices that can measure the phase offset
> between PHC signal and the external signal, such as the 1PPS signal of
> GNSS. Reporting PTP_CLOCK_EXTOFF to user space will be piggy-backed to
> the existing ptp_extts_event so that application such as ts2phc can
> poll the external offset the same way as extts. Hence, ts2phc can use
> the offset to achieve the alignment between PHC and the external signal
> by the help of either SW or HW filters.

Does not apply to net-next.
-- 
pw-bot: cr

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

* RE: [PATCH net-next 1/2] ptp: introduce PTP_CLOCK_EXTOFF event for the measured external offset
  2023-11-29  3:58 ` Jakub Kicinski
@ 2023-11-29 16:59   ` Min Li
  2023-11-29 17:52     ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Min Li @ 2023-11-29 16:59 UTC (permalink / raw)
  To: Jakub Kicinski, Min Li
  Cc: richardcochran@gmail.com, lee@kernel.org,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org

> -----Original Message-----
> From: Jakub Kicinski <kuba@kernel.org>
> Sent: November 28, 2023 10:58 PM
> To: Min Li <lnimi@hotmail.com>
> Cc: richardcochran@gmail.com; lee@kernel.org; linux-
> kernel@vger.kernel.org; netdev@vger.kernel.org; Min Li
> <min.li.xe@renesas.com>
> Subject: Re: [PATCH net-next 1/2] ptp: introduce PTP_CLOCK_EXTOFF event
> for the measured external offset
> 
> On Mon, 27 Nov 2023 15:01:29 -0500 Min Li wrote:
> > This change is for the PHC devices that can measure the phase offset
> > between PHC signal and the external signal, such as the 1PPS signal of
> > GNSS. Reporting PTP_CLOCK_EXTOFF to user space will be piggy-backed to
> > the existing ptp_extts_event so that application such as ts2phc can
> > poll the external offset the same way as extts. Hence, ts2phc can use
> > the offset to achieve the alignment between PHC and the external
> > signal by the help of either SW or HW filters.
> 
> Does not apply to net-next.

Hi Jakub

I submitted an RFC last week and Richard was asking me to submit it together with a driver change as an example to implement it. Below is
Richard's quote

"Yes, the new option must wait for a driver that implements it.  Can you make a patch series where the driver change appears in the second patch?"

But the driver that I submitted is a brand new PHC driver. So I don't know if it is appropriate to separate them to net and net-next? Because the driver
change depends on the this patch.

Min


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

* Re: [PATCH net-next 1/2] ptp: introduce PTP_CLOCK_EXTOFF event for the measured external offset
  2023-11-29 16:59   ` Min Li
@ 2023-11-29 17:52     ` Jakub Kicinski
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2023-11-29 17:52 UTC (permalink / raw)
  To: Min Li
  Cc: Min Li, richardcochran@gmail.com, lee@kernel.org,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org

On Wed, 29 Nov 2023 16:59:38 +0000 Min Li wrote:
> But the driver that I submitted is a brand new PHC driver. So I don't
> know if it is appropriate to separate them to net and net-next?
> Because the driver change depends on the this patch.

What's in your tree? What I'm saying is that the diff context does not
match net-next:

$ git checkout net-next/main
$ git pw series apply 804642
Applying: ptp: introduce PTP_CLOCK_EXTOFF event for the measured external offset
Using index info to reconstruct a base tree...
M	drivers/ptp/ptp_clock.c
Falling back to patching base and 3-way merge...
Auto-merging drivers/ptp/ptp_clock.c
Applying: ptp: add FemtoClock3 Wireless as ptp hardware clock


Do you have any intermediate commits in your local branch? 
Or perhaps the patches are based on some other tree, not net-next?

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

end of thread, other threads:[~2023-11-29 17:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-27 20:01 [PATCH net-next 1/2] ptp: introduce PTP_CLOCK_EXTOFF event for the measured external offset Min Li
2023-11-29  3:58 ` Jakub Kicinski
2023-11-29 16:59   ` Min Li
2023-11-29 17:52     ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).