blob: 773f3d59a0005538ed7b201c859a0307e57d975f [file] [log] [blame]
Stefan Sørensenb88a6f82014-01-31 12:01:01 +01001#include "defs.h"
2#include <sys/ioctl.h>
3#include <linux/ptp_clock.h>
4
5static const struct xlat ptp_flags_options[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +00006 XLAT(PTP_ENABLE_FEATURE),
7 XLAT(PTP_RISING_EDGE),
8 XLAT(PTP_FALLING_EDGE),
Dmitry V. Levin59452732014-02-05 02:20:51 +00009 XLAT_END
Stefan Sørensenb88a6f82014-01-31 12:01:01 +010010};
11
12
13int ptp_ioctl(struct tcb *tcp, long code, long arg)
14{
15 if (!verbose(tcp))
16 return 0;
17
18 switch (code) {
19 case PTP_CLOCK_GETCAPS: /* decode on exit */
20 {
21 struct ptp_clock_caps caps;
22
23 if (entering(tcp) || syserror(tcp) ||
24 umove(tcp, arg, &caps) < 0)
25 return 0;
26
27 tprintf(", {max_adj=%d, n_alarm=%d, n_ext_ts=%d, n_per_out=%d, pps=%d}",
28 caps.max_adj, caps.n_alarm, caps.n_ext_ts,
29 caps.n_per_out, caps.pps);
30 return 1;
31 }
32
33 case PTP_EXTTS_REQUEST: /* decode on enter */
34 {
35 struct ptp_extts_request extts;
36
37 if (exiting(tcp))
38 return 1;
39 if (umove(tcp, arg, &extts) < 0) {
40 tprintf(", %#lx", arg);
41 return 0;
42 }
43 tprintf(", {index=%d, flags=", extts.index);
44 printflags(ptp_flags_options, extts.flags, "PTP_???");
45 tprints("}");
46 return 1;
47 }
48
49 case PTP_PEROUT_REQUEST: /* decode on enter */
50 {
51 struct ptp_perout_request perout;
52
53 if (exiting(tcp))
54 return 1;
55 if (umove(tcp, arg, &perout) < 0) {
56 tprintf(", %#lx", arg);
57 return 0;
58 }
59
60 tprintf(", {start={%" PRId64 ", %" PRIu32 "}"
61 ", period={%" PRId64 ", %" PRIu32 "}"
62 ", index=%d, flags=",
63 (int64_t)perout.start.sec, perout.start.nsec,
64 (int64_t)perout.period.sec, perout.period.nsec,
65 perout.index);
66 printflags(ptp_flags_options, perout.flags, "PTP_???");
67 tprints("}");
68 return 1;
69 }
70
71 case PTP_ENABLE_PPS: /* decode on enter */
72 if (entering(tcp))
73 tprintf(", %ld", arg);
74 return 1;
75
76 case PTP_SYS_OFFSET: /* decode on exit */
77 {
78 struct ptp_sys_offset sysoff;
79 unsigned int i;
80
81 if (entering(tcp) || umove(tcp, arg, &sysoff) < 0)
82 return 0;
83
84 tprintf(", {n_samples=%u, ts={", sysoff.n_samples);
85 if (syserror(tcp)) {
86 tprints("...}}");
87 return 1;
88 }
89 if (sysoff.n_samples > PTP_MAX_SAMPLES)
90 sysoff.n_samples = PTP_MAX_SAMPLES;
91 tprintf("{%" PRId64 ", %" PRIu32 "}",
92 (int64_t)sysoff.ts[0].sec, sysoff.ts[0].nsec);
93 for (i = 1; i < 2*sysoff.n_samples+1; ++i)
94 tprintf(", {%" PRId64 ", %" PRIu32 "}",
95 (int64_t)sysoff.ts[i].sec, sysoff.ts[i].nsec);
96 tprints("}}");
97 return 1;
98 }
99
100 default: /* decode on exit */
101 return 0;
102 }
103}