[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240104212439.3276458-1-maheshb@google.com>
Date: Thu, 4 Jan 2024 13:24:39 -0800
From: Mahesh Bandewar <maheshb@...gle.com>
To: Netdev <netdev@...r.kernel.org>, Linux <linux-kernel@...r.kernel.org>,
David Miller <davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>,
Eric Dumazet <edumazet@...gle.com>, Paolo Abeni <pabeni@...hat.com>
Cc: Jonathan Corbet <corbet@....net>, John Stultz <jstultz@...gle.com>, Don Hatchett <hatch@...gle.com>,
Yuliang Li <yuliangli@...gle.com>, Mahesh Bandewar <mahesh@...dewar.net>,
Mahesh Bandewar <maheshb@...gle.com>, Richard Cochran <richardcochran@...il.com>,
Willem de Bruijn <willemb@...gle.com>
Subject: [PATCHv3 net-next 2/3] ptp: add ioctl interface for ptp_gettimex64any()
add an ioctl op PTP_SYS_OFFSET_ANY to support newly added
ptp_gettimex64any() method
Signed-off-by: Mahesh Bandewar <maheshb@...gle.com>
CC: Richard Cochran <richardcochran@...il.com>
CC: "David S. Miller" <davem@...emloft.net>
CC: John Stultz <jstultz@...gle.com>
CC: Jakub Kicinski <kuba@...nel.org>
CC: "Willem de Bruijn" <willemb@...gle.com>
CC: netdev@...r.kernel.org
---
drivers/ptp/ptp_chardev.c | 37 ++++++++++++++++++++++++++++++++++
include/uapi/linux/ptp_clock.h | 14 +++++++++++++
2 files changed, 51 insertions(+)
diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index 7513018c9f9a..f20d43c34aec 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -161,6 +161,7 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
struct ptp_clock *ptp =
container_of(pccontext->clk, struct ptp_clock, clock);
struct ptp_sys_offset_extended *extoff = NULL;
+ struct ptp_sys_offset_any *anyoff = NULL;
struct ptp_sys_offset_precise precise_offset;
struct system_device_crosststamp xtstamp;
struct ptp_clock_info *ops = ptp->info;
@@ -378,6 +379,42 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
err = -EFAULT;
break;
+ case PTP_SYS_OFFSET_ANY:
+ if (!ptp->info->gettimex64any) {
+ err = -EOPNOTSUPP;
+ break;
+ }
+ anyoff = memdup_user((void __user *)arg, sizeof(*anyoff));
+ if (IS_ERR(anyoff)) {
+ err = PTR_ERR(anyoff);
+ anyoff = NULL;
+ break;
+ }
+ if (anyoff->n_samples > PTP_MAX_SAMPLES
+ || anyoff->rsv[0] || anyoff->rsv[1]
+ || (anyoff->clockid != CLOCK_REALTIME
+ && anyoff->clockid != CLOCK_MONOTONIC
+ && anyoff->clockid != CLOCK_MONOTONIC_RAW)) {
+ err = -EINVAL;
+ break;
+ }
+
+ for (i = 0; i < anyoff->n_samples; i++) {
+ err = ptp->info->gettimex64any(ptp->info, &ts, &sts,
+ anyoff->clockid);
+ if (err)
+ goto out;
+ anyoff->ts[i][0].sec = sts.pre_ts.tv_sec;
+ anyoff->ts[i][0].nsec = sts.pre_ts.tv_nsec;
+ anyoff->ts[i][1].sec = ts.tv_sec;
+ anyoff->ts[i][1].nsec = ts.tv_nsec;
+ anyoff->ts[i][2].sec = sts.post_ts.tv_sec;
+ anyoff->ts[i][2].nsec = sts.post_ts.tv_nsec;
+ }
+ if (copy_to_user((void __user *)arg, anyoff, sizeof(*anyoff)))
+ err = -EFAULT;
+ break;
+
case PTP_SYS_OFFSET:
case PTP_SYS_OFFSET2:
sysoff = memdup_user((void __user *)arg, sizeof(*sysoff));
diff --git a/include/uapi/linux/ptp_clock.h b/include/uapi/linux/ptp_clock.h
index da700999cad4..a3143df8de2b 100644
--- a/include/uapi/linux/ptp_clock.h
+++ b/include/uapi/linux/ptp_clock.h
@@ -158,6 +158,18 @@ struct ptp_sys_offset_extended {
struct ptp_clock_time ts[PTP_MAX_SAMPLES][3];
};
+struct ptp_sys_offset_any {
+ unsigned int n_samples; /* Desired number of measurements. */
+ clockid_t clockid; /* One of the supported ClockID */
+ unsigned int rsv[2]; /* Reserved for future use. */
+ /*
+ * Array of [TS, phc, TS] time stamps. The kernel will provide
+ * 3*n_samples time stamps.
+ * TS is any of the ts_type requested.
+ */
+ struct ptp_clock_time ts[PTP_MAX_SAMPLES][3];
+};
+
struct ptp_sys_offset_precise {
struct ptp_clock_time device;
struct ptp_clock_time sys_realtime;
@@ -226,6 +238,8 @@ struct ptp_pin_desc {
_IOWR(PTP_CLK_MAGIC, 18, struct ptp_sys_offset_extended)
#define PTP_MASK_CLEAR_ALL _IO(PTP_CLK_MAGIC, 19)
#define PTP_MASK_EN_SINGLE _IOW(PTP_CLK_MAGIC, 20, unsigned int)
+#define PTP_SYS_OFFSET_ANY \
+ _IOWR(PTP_CLK_MAGIC, 21, struct ptp_sys_offset_any)
struct ptp_extts_event {
struct ptp_clock_time t; /* Time event occured. */
--
2.43.0.195.gebba966016-goog
Powered by blists - more mailing lists