diff mbox series

[RFC,2/3] ptp: Implement support for esterror in ptp_mock

Message ID 20240813125602.155827-3-maciek@machnikowski.net (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series ptp: Add esterror support | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 29 this patch: 29
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: vladimir.oltean@nxp.com
netdev/build_clang success Errors and warnings before: 29 this patch: 29
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 29 this patch: 29
netdev/checkpatch warning WARNING: line length of 84 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Maciek Machnikowski Aug. 13, 2024, 12:56 p.m. UTC
Implement basic example of handling the esterror using
getesterror/setesterror functions of the ptp_clock_info

Signed-off-by: Maciek Machnikowski <maciek@machnikowski.net>
---
 drivers/ptp/ptp_mock.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
diff mbox series

Patch

diff --git a/drivers/ptp/ptp_mock.c b/drivers/ptp/ptp_mock.c
index e7b459c846a2..1786da790f82 100644
--- a/drivers/ptp/ptp_mock.c
+++ b/drivers/ptp/ptp_mock.c
@@ -35,10 +35,13 @@ 
 
 struct mock_phc {
 	struct ptp_clock_info info;
+	struct timespec64 sys_ts;
+	struct timespec64 hw_ts;
 	struct ptp_clock *clock;
 	struct timecounter tc;
 	struct cyclecounter cc;
 	spinlock_t lock;
+	long esterror;
 };
 
 static u64 mock_phc_cc_read(const struct cyclecounter *cc)
@@ -100,6 +103,31 @@  static int mock_phc_gettime64(struct ptp_clock_info *info, struct timespec64 *ts
 	return 0;
 }
 
+static int mock_phc_getesterror(struct ptp_clock_info *info, long *esterror,
+				struct timespec64 *hw_ts, struct timespec64 *sys_ts)
+{
+	struct mock_phc *phc = info_to_phc(info);
+
+	*esterror = phc->esterror;
+	if (hw_ts)
+		*hw_ts = phc->hw_ts;
+	if (sys_ts)
+		*sys_ts = phc->sys_ts;
+
+	return 0;
+}
+
+static int mock_phc_setesterror(struct ptp_clock_info *info, long esterror)
+{
+	struct mock_phc *phc = info_to_phc(info);
+
+	phc->esterror = esterror;
+	phc->hw_ts = ns_to_timespec64(timecounter_read(&phc->tc));
+	phc->sys_ts = ns_to_timespec64(ktime_get_raw_ns());
+
+	return 0;
+}
+
 static long mock_phc_refresh(struct ptp_clock_info *info)
 {
 	struct timespec64 ts;
@@ -134,6 +162,8 @@  struct mock_phc *mock_phc_create(struct device *dev)
 		.adjtime	= mock_phc_adjtime,
 		.gettime64	= mock_phc_gettime64,
 		.settime64	= mock_phc_settime64,
+		.getesterror	= mock_phc_getesterror,
+		.setesterror	= mock_phc_setesterror,
 		.do_aux_work	= mock_phc_refresh,
 	};