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
44 struct ptp_clock_event *src)44 struct ptp_clock_event *src)
45{45{
46 struct ptp_extts_event *dst;46 struct ptp_extts_event *dst;
47 struct timespec64 offset_ts;
47 unsigned long flags;48 unsigned long flags;
48 s64 seconds;49 s64 seconds;
49 u32 remainder;50 u32 remainder;
50 51
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 }
52 62
53 spin_lock_irqsave(&queue->lock, flags);63 spin_lock_irqsave(&queue->lock, flags);
54 64
55 dst = &queue->buf[queue->tail];65 dst = &queue->buf[queue->tail];
56 dst->index = src->index;66 dst->index = src->index;
67 dst->flags = PTP_EXTTS_EVENT_VALID;
57 dst->t.sec = seconds;68 dst->t.sec = seconds;
58 dst->t.nsec = remainder;69 dst->t.nsec = remainder;
70 if (src->type == PTP_CLOCK_EXTOFF)
71 dst->flags |= PTP_EXT_OFFSET;
59 72
60 /* Both WRITE_ONCE() are paired with READ_ONCE() in queue_cnt() */73 /* Both WRITE_ONCE() are paired with READ_ONCE() in queue_cnt() */
61 if (!queue_free(queue))74 if (!queue_free(queue))
@@ -417,6 +430,7 @@ void ptp_clock_event(struct ptp_clock *ptp, struct ptp_clock_event *event) · 355 unmodified lines
417 break;430 break;
418 431
419 case PTP_CLOCK_EXTTS:432 case PTP_CLOCK_EXTTS:
433 case PTP_CLOCK_EXTOFF:
420 /* Enqueue timestamp on selected queues */434 /* Enqueue timestamp on selected queues */
421 spin_lock_irqsave(&ptp->tsevqs_lock, flags);435 spin_lock_irqsave(&ptp->tsevqs_lock, flags);
422 list_for_each_entry(tsevq, &ptp->tsevqs, qlist) {436 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
200enum ptp_clock_events {200enum ptp_clock_events {
201 PTP_CLOCK_ALARM,201 PTP_CLOCK_ALARM,
202 PTP_CLOCK_EXTTS,202 PTP_CLOCK_EXTTS,
203 PTP_CLOCK_EXTOFF,
203 PTP_CLOCK_PPS,204 PTP_CLOCK_PPS,
204 PTP_CLOCK_PPSUSR,205 PTP_CLOCK_PPSUSR,
205};206};
@@ -210,6 +211,7 @@ enum ptp_clock_events { · 4 unmodified lines
210 * @type: One of the ptp_clock_events enumeration values.211 * @type: One of the ptp_clock_events enumeration values.
211 * @index: Identifies the source of the event.212 * @index: Identifies the source of the event.
212 * @timestamp: When the event occurred (%PTP_CLOCK_EXTTS only).213 * @timestamp: When the event occurred (%PTP_CLOCK_EXTTS only).
214 * @offset: When the event occurred (%PTP_CLOCK_EXTOFF only).
213 * @pps_times: When the event occurred (%PTP_CLOCK_PPSUSR only).215 * @pps_times: When the event occurred (%PTP_CLOCK_PPSUSR only).
214 */216 */
215 217
@@ -218,6 +220,7 @@ struct ptp_clock_event { · 2 unmodified lines
218 int index;220 int index;
219 union {221 union {
220 u64 timestamp;222 u64 timestamp;
223 s64 offset;
221 struct pps_event_time pps_times;224 struct pps_event_time pps_times;
222 };225 };
223};226};
include/uapi/linux/ptp_clock.h+10−3
@@ -32,6 +32,7 @@ · 31 unmodified lines
32#define PTP_RISING_EDGE (1<<1)32#define PTP_RISING_EDGE (1<<1)
33#define PTP_FALLING_EDGE (1<<2)33#define PTP_FALLING_EDGE (1<<2)
34#define PTP_STRICT_FLAGS (1<<3)34#define PTP_STRICT_FLAGS (1<<3)
35#define PTP_EXT_OFFSET (1<<4)
35#define PTP_EXTTS_EDGES (PTP_RISING_EDGE | PTP_FALLING_EDGE)36#define PTP_EXTTS_EDGES (PTP_RISING_EDGE | PTP_FALLING_EDGE)
36 37
37/*38/*
@@ -40,7 +41,8 @@ · 2 unmodified lines
40#define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FEATURE | \41#define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FEATURE | \
41 PTP_RISING_EDGE | \42 PTP_RISING_EDGE | \
42 PTP_FALLING_EDGE | \43 PTP_FALLING_EDGE | \
43 PTP_STRICT_FLAGS)44 PTP_STRICT_FLAGS | \
45 PTP_EXT_OFFSET)
44 46
45/*47/*
46 * flag fields valid for the original PTP_EXTTS_REQUEST ioctl.48 * flag fields valid for the original PTP_EXTTS_REQUEST ioctl.
@@ -50,6 +52,11 @@ · 3 unmodified lines
50 PTP_RISING_EDGE | \52 PTP_RISING_EDGE | \
51 PTP_FALLING_EDGE)53 PTP_FALLING_EDGE)
52 54
55/*
56 * flag fields valid for the ptp_extts_event report.
57 */
58#define PTP_EXTTS_EVENT_VALID (PTP_ENABLE_FEATURE)
59
53/*60/*
54 * Bits of the ptp_perout_request.flags field:61 * Bits of the ptp_perout_request.flags field:
55 */62 */
@@ -228,9 +235,9 @@ struct ptp_pin_desc { · 172 unmodified lines
228#define PTP_MASK_EN_SINGLE _IOW(PTP_CLK_MAGIC, 20, unsigned int)235#define PTP_MASK_EN_SINGLE _IOW(PTP_CLK_MAGIC, 20, unsigned int)
229 236
230struct ptp_extts_event {237struct ptp_extts_event {
231 struct ptp_clock_time t; /* Time event occured. */238 struct ptp_clock_time t; /* Time event occurred. */
232 unsigned int index; /* Which channel produced the event. */239 unsigned int index; /* Which channel produced the event. */
233 unsigned int flags; /* Reserved for future use. */240 unsigned int flags; /* Event type. */
234 unsigned int rsv[2]; /* Reserved for future use. */241 unsigned int rsv[2]; /* Reserved for future use. */
235};242};
236 243

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