From: Mahesh Bandewar <maheshb@google.com>
To: Netdev <netdev@vger.kernel.org>,
Linux <linux-kernel@vger.kernel.org>,
David Miller <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>,
John Stultz <jstultz@google.com>, Don Hatchett <hatch@google.com>,
Yuliang Li <yuliangli@google.com>,
Mahesh Bandewar <mahesh@bandewar.net>,
Mahesh Bandewar <maheshb@google.com>,
Richard Cochran <richardcochran@gmail.com>
Subject: [PATCHv2 next 1/3] ptp: add ptp_gettimex64any() support
Date: Mon, 2 Oct 2023 21:17:01 -0700 [thread overview]
Message-ID: <20231003041701.1745953-1-maheshb@google.com> (raw)
add support for TS sandwich of the user preferred timebase. The options
supported are PTP_TS_REAL (CLOCK_REALTIME), PTP_TS_MONO (CLOCK_MONOTONIC),
and PTP_TS_RAW (CLOCK_MONOTONIC_RAW)
Option of PTP_TS_REAL is equivalent of using ptp_gettimex64().
Signed-off-by: Mahesh Bandewar <maheshb@google.com>
CC: Richard Cochran <richardcochran@gmail.com>
CC: "David S. Miller" <davem@davemloft.net>
CC: netdev@vger.kernel.org
---
include/linux/ptp_clock_kernel.h | 51 ++++++++++++++++++++++++++++++++
include/uapi/linux/ptp_clock.h | 7 +++++
2 files changed, 58 insertions(+)
diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h
index 1ef4e0f9bd2a..fd7be98e7bba 100644
--- a/include/linux/ptp_clock_kernel.h
+++ b/include/linux/ptp_clock_kernel.h
@@ -102,6 +102,15 @@ struct ptp_system_timestamp {
* reading the lowest bits of the PHC timestamp and the second
* reading immediately follows that.
*
+ * @gettimex64any: Reads the current time from the hardware clock and
+ optionally also any of the MONO, MONO_RAW, or SYS clock.
+ * parameter ts: Holds the PHC timestamp.
+ * parameter sts: If not NULL, it holds a pair of timestamps from
+ * the clock of choice. The first reading is made right before
+ * reading the lowest bits of the PHC timestamp and the second
+ * reading immediately follows that.
+ * parameter type: any one of the TS opt from ptp_timestamp_types.
+ *
* @getcrosststamp: Reads the current time from the hardware clock and
* system clock simultaneously.
* parameter cts: Contains timestamp (device,system) pair,
@@ -180,6 +189,9 @@ struct ptp_clock_info {
int (*gettime64)(struct ptp_clock_info *ptp, struct timespec64 *ts);
int (*gettimex64)(struct ptp_clock_info *ptp, struct timespec64 *ts,
struct ptp_system_timestamp *sts);
+ int (*gettimex64any)(struct ptp_clock_info *ptp, struct timespec64 *ts,
+ struct ptp_system_timestamp *sts,
+ enum ptp_ts_types type);
int (*getcrosststamp)(struct ptp_clock_info *ptp,
struct system_device_crosststamp *cts);
int (*settime64)(struct ptp_clock_info *p, const struct timespec64 *ts);
@@ -464,4 +476,43 @@ static inline void ptp_read_system_postts(struct ptp_system_timestamp *sts)
ktime_get_real_ts64(&sts->post_ts);
}
+static inline void ptp_read_any_prets(struct ptp_system_timestamp *sts,
+ enum ptp_ts_types type)
+{
+ if (sts) {
+ switch (type) {
+ case PTP_TS_REAL:
+ ktime_get_real_ts64(&sts->pre_ts);
+ break;
+ case PTP_TS_MONO:
+ ktime_get_ts64(&sts->pre_ts);
+ break;
+ case PTP_TS_RAW:
+ ktime_get_raw_ts64(&sts->pre_ts);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+static inline void ptp_read_any_postts(struct ptp_system_timestamp *sts,
+ enum ptp_ts_types type)
+{
+ if (sts) {
+ switch (type) {
+ case PTP_TS_REAL:
+ ktime_get_real_ts64(&sts->post_ts);
+ break;
+ case PTP_TS_MONO:
+ ktime_get_ts64(&sts->post_ts);
+ break;
+ case PTP_TS_RAW:
+ ktime_get_raw_ts64(&sts->post_ts);
+ break;
+ default:
+ break;
+ }
+ }
+}
#endif
diff --git a/include/uapi/linux/ptp_clock.h b/include/uapi/linux/ptp_clock.h
index 05cc35fc94ac..dc44e34f8146 100644
--- a/include/uapi/linux/ptp_clock.h
+++ b/include/uapi/linux/ptp_clock.h
@@ -69,6 +69,13 @@
*/
#define PTP_PEROUT_V1_VALID_FLAGS (0)
+enum ptp_ts_types {
+ PTP_TS_REAL = 0,
+ PTP_TS_MONO,
+ PTP_TS_RAW,
+ PTP_TS_MAX,
+};
+
/*
* struct ptp_clock_time - represents a time value
*
--
2.42.0.582.g8ccd20d70d-goog
next reply other threads:[~2023-10-03 4:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-03 4:17 Mahesh Bandewar [this message]
2023-10-03 14:20 ` [PATCHv2 next 1/3] ptp: add ptp_gettimex64any() support Simon Horman
2023-10-04 4:29 ` Richard Cochran
2023-10-05 23:12 ` Mahesh Bandewar (महेश बंडेवार)
2023-10-06 4:35 ` Richard Cochran
2023-10-06 5:11 ` Richard Cochran
2023-10-04 4:38 ` Richard Cochran
2023-10-05 23:23 ` Mahesh Bandewar (महेश बंडेवार)
2023-10-06 5:14 ` Richard Cochran
2023-10-06 22:24 ` John Stultz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231003041701.1745953-1-maheshb@google.com \
--to=maheshb@google.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hatch@google.com \
--cc=jstultz@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mahesh@bandewar.net \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=yuliangli@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).