History

ptp: introduce PTP_CLOCK_EXTOFF event for the measured external offset

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.

Min Li committed 2 years ago

Commit ea1cc3e1 parent cf8e51e3 files · +28 −4Browse files

Unified · Split

3 files
  1. drivers/ptp/ptp_clock.c +15 −1
  2. include/linux/ptp_clock_kernel.h +3 −0
  3. include/uapi/linux/ptp_clock.h +10 −3
drivers/ptp/ptp_clock.c+15−1
@@ -44,18 +44,31 @@ static void enqueue_external_timestamp(struct timestamp_event_queue *queue, · 43 unmodified lines
4444 struct ptp_clock_event *src)
4545 {
4646 struct ptp_extts_event *dst;
47+ struct timespec64 offset_ts;
4748 unsigned long flags;
4849 s64 seconds;
4950 u32 remainder;
5051
51− seconds = div_u64_rem(src->timestamp, 1000000000, &remainder);
52+ if (src->type == PTP_CLOCK_EXTTS) {
53+ seconds = div_u64_rem(src->timestamp, 1000000000, &remainder);
54+ } else if (src->type == PTP_CLOCK_EXTOFF) {
55+ offset_ts = ns_to_timespec64(src->offset);
56+ seconds = offset_ts.tv_sec;
57+ remainder = offset_ts.tv_nsec;
58+ } else {
59+ WARN(1, "%s: unknown type %d\n", __func__, src->type);
60+ return;
61+ }
5262
5363 spin_lock_irqsave(&queue->lock, flags);
5464
5565 dst = &queue->buf[queue->tail];
5666 dst->index = src->index;
67+ dst->flags = PTP_EXTTS_EVENT_VALID;
5768 dst->t.sec = seconds;
5869 dst->t.nsec = remainder;
70+ if (src->type == PTP_CLOCK_EXTOFF)
71+ dst->flags |= PTP_EXT_OFFSET;
5972
6073 /* Both WRITE_ONCE() are paired with READ_ONCE() in queue_cnt() */
6174 if (!queue_free(queue))
@@ -417,6 +430,7 @@ void ptp_clock_event(struct ptp_clock *ptp, struct ptp_clock_event *event) · 355 unmodified lines
417430 break;
418431
419432 case PTP_CLOCK_EXTTS:
433+ case PTP_CLOCK_EXTOFF:
420434 /* Enqueue timestamp on selected queues */
421435 spin_lock_irqsave(&ptp->tsevqs_lock, flags);
422436 list_for_each_entry(tsevq, &ptp->tsevqs, qlist) {
include/linux/ptp_clock_kernel.h+3−0
@@ -200,6 +200,7 @@ struct ptp_clock; · 199 unmodified lines
200200 enum ptp_clock_events {
201201 PTP_CLOCK_ALARM,
202202 PTP_CLOCK_EXTTS,
203+ PTP_CLOCK_EXTOFF,
203204 PTP_CLOCK_PPS,
204205 PTP_CLOCK_PPSUSR,
205206 };
@@ -210,6 +211,7 @@ enum ptp_clock_events { · 4 unmodified lines
210211 * @type: One of the ptp_clock_events enumeration values.
211212 * @index: Identifies the source of the event.
212213 * @timestamp: When the event occurred (%PTP_CLOCK_EXTTS only).
214+ * @offset: When the event occurred (%PTP_CLOCK_EXTOFF only).
213215 * @pps_times: When the event occurred (%PTP_CLOCK_PPSUSR only).
214216 */
215217
@@ -218,6 +220,7 @@ struct ptp_clock_event { · 2 unmodified lines
218220 int index;
219221 union {
220222 u64 timestamp;
223+ s64 offset;
221224 struct pps_event_time pps_times;
222225 };
223226 };
include/uapi/linux/ptp_clock.h+10−3
@@ -32,6 +32,7 @@ · 31 unmodified lines
3232 #define PTP_RISING_EDGE (1<<1)
3333 #define PTP_FALLING_EDGE (1<<2)
3434 #define PTP_STRICT_FLAGS (1<<3)
35+#define PTP_EXT_OFFSET (1<<4)
3536 #define PTP_EXTTS_EDGES (PTP_RISING_EDGE | PTP_FALLING_EDGE)
3637
3738 /*
@@ -40,7 +41,8 @@ · 2 unmodified lines
4041 #define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FEATURE | \
4142 PTP_RISING_EDGE | \
4243 PTP_FALLING_EDGE | \
43− PTP_STRICT_FLAGS)
44+ PTP_STRICT_FLAGS | \
45+ PTP_EXT_OFFSET)
4446
4547 /*
4648 * flag fields valid for the original PTP_EXTTS_REQUEST ioctl.
@@ -50,6 +52,11 @@ · 3 unmodified lines
5052 PTP_RISING_EDGE | \
5153 PTP_FALLING_EDGE)
5254
55+/*
56+ * flag fields valid for the ptp_extts_event report.
57+ */
58+#define PTP_EXTTS_EVENT_VALID (PTP_ENABLE_FEATURE)
59+
5360 /*
5461 * Bits of the ptp_perout_request.flags field:
5562 */
@@ -228,9 +235,9 @@ struct ptp_pin_desc { · 172 unmodified lines
228235 #define PTP_MASK_EN_SINGLE _IOW(PTP_CLK_MAGIC, 20, unsigned int)
229236
230237 struct ptp_extts_event {
231− struct ptp_clock_time t; /* Time event occured. */
238+ struct ptp_clock_time t; /* Time event occurred. */
232239 unsigned int index; /* Which channel produced the event. */
233− unsigned int flags; /* Reserved for future use. */
240+ unsigned int flags; /* Event type. */
234241 unsigned int rsv[2]; /* Reserved for future use. */
235242 };
236243

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t