blob: f6cc1ab5dfafe08c35602179efc0a95c96e0e69f [file] [log] [blame]
Stefan Sørensenb88a6f82014-01-31 12:01:01 +01001#include "defs.h"
Dmitry V. Levin317d19e2015-07-07 12:47:18 +03002#include <linux/ioctl.h>
Stefan Sørensenb88a6f82014-01-31 12:01:01 +01003#include <linux/ptp_clock.h>
4
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00005#include "xlat/ptp_flags_options.h"
Stefan Sørensenb88a6f82014-01-31 12:01:01 +01006
Dmitry V. Levinc7afb482015-01-19 18:44:21 +00007int
Dmitry V. Levin317d19e2015-07-07 12:47:18 +03008ptp_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
Stefan Sørensenb88a6f82014-01-31 12:01:01 +01009{
10 if (!verbose(tcp))
Dmitry V. Levin317d19e2015-07-07 12:47:18 +030011 return RVAL_DECODED;
Stefan Sørensenb88a6f82014-01-31 12:01:01 +010012
13 switch (code) {
Dmitry V. Levin317d19e2015-07-07 12:47:18 +030014 case PTP_EXTTS_REQUEST: {
15 struct ptp_extts_request extts;
Stefan Sørensenb88a6f82014-01-31 12:01:01 +010016
Dmitry V. Levin317d19e2015-07-07 12:47:18 +030017 tprints(", ");
18 if (umove_or_printaddr(tcp, arg, &extts))
19 break;
Stefan Sørensenb88a6f82014-01-31 12:01:01 +010020
Dmitry V. Levin317d19e2015-07-07 12:47:18 +030021 tprintf("{index=%d, flags=", extts.index);
22 printflags(ptp_flags_options, extts.flags, "PTP_???");
23 tprints("}");
24 break;
25 }
26
27 case PTP_PEROUT_REQUEST: {
28 struct ptp_perout_request perout;
29
30 tprints(", ");
31 if (umove_or_printaddr(tcp, arg, &perout))
32 break;
33
34 tprintf("{start={%" PRId64 ", %" PRIu32 "}"
35 ", period={%" PRId64 ", %" PRIu32 "}"
36 ", index=%d, flags=",
37 (int64_t)perout.start.sec, perout.start.nsec,
38 (int64_t)perout.period.sec, perout.period.nsec,
39 perout.index);
40 printflags(ptp_flags_options, perout.flags, "PTP_???");
41 tprints("}");
42 break;
43 }
44
45 case PTP_ENABLE_PPS:
46 tprintf(", %ld", arg);
47 break;
48
49 case PTP_SYS_OFFSET: {
50 struct ptp_sys_offset sysoff;
51
52 if (entering(tcp)) {
53 tprints(", ");
54 if (umove_or_printaddr(tcp, arg, &sysoff))
55 break;
56
57 tprintf("{n_samples=%u", sysoff.n_samples);
Stefan Sørensenb88a6f82014-01-31 12:01:01 +010058 return 1;
Dmitry V. Levin317d19e2015-07-07 12:47:18 +030059 } else {
60 unsigned int n_samples, i;
Stefan Sørensenb88a6f82014-01-31 12:01:01 +010061
Stefan Sørensenb88a6f82014-01-31 12:01:01 +010062 if (syserror(tcp)) {
Dmitry V. Levin317d19e2015-07-07 12:47:18 +030063 tprints("}");
64 break;
65 }
66
67 tprints(", ");
68 if (umove(tcp, arg, &sysoff) < 0) {
69 tprints("???}");
70 break;
71 }
72
73 tprints("ts=[");
74 n_samples = sysoff.n_samples > PTP_MAX_SAMPLES ?
75 PTP_MAX_SAMPLES : sysoff.n_samples;
76 for (i = 0; i < 2 * n_samples + 1; ++i) {
77 if (i > 0)
78 tprints(", ");
79 tprintf("{%" PRId64 ", %" PRIu32 "}",
80 (int64_t)sysoff.ts[i].sec,
81 sysoff.ts[i].nsec);
Stefan Sørensenb88a6f82014-01-31 12:01:01 +010082 }
83 if (sysoff.n_samples > PTP_MAX_SAMPLES)
Dmitry V. Levin317d19e2015-07-07 12:47:18 +030084 tprints(", ...");
85 tprints("]}");
86 break;
Stefan Sørensenb88a6f82014-01-31 12:01:01 +010087 }
Stefan Sørensenb88a6f82014-01-31 12:01:01 +010088 }
Dmitry V. Levin317d19e2015-07-07 12:47:18 +030089 case PTP_CLOCK_GETCAPS: {
90 struct ptp_clock_caps caps;
91
92 if (entering(tcp))
93 return 0;
94
95 tprints(", ");
96 if (umove_or_printaddr(tcp, arg, &caps))
97 break;
98
99 tprintf("{max_adj=%d, n_alarm=%d, n_ext_ts=%d, n_per_out=%d, pps=%d}",
100 caps.max_adj, caps.n_alarm, caps.n_ext_ts,
101 caps.n_per_out, caps.pps);
102 break;
103 }
104
105 default:
106 return RVAL_DECODED;
107 }
108
109 return RVAL_DECODED | 1;
Stefan Sørensenb88a6f82014-01-31 12:01:01 +0100110}