diff mbox series

[net] ptp: Add mock device

Message ID 20250203-ptp-mock-dev-v1-1-f84c56fd9e45@weissschuh.net (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series [net] ptp: Add mock device | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 47 this patch: 47
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: 10 this patch: 10
netdev/checkpatch warning WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
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
netdev/contest warning net-next-2025-02-03--21-00 (tests: 81)

Commit Message

Thomas Weißschuh Feb. 3, 2025, 7:50 p.m. UTC
While working on the PTP core or userspace components,
a real PTP device is not always available.
Introduce a tiny module which creates a mock PTP device.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/ptp/Kconfig        | 10 ++++++++++
 drivers/ptp/Makefile       |  1 +
 drivers/ptp/ptp_mock_dev.c | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)


---
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
change-id: 20250122-ptp-mock-dev-a8cd3d37d9e9

Best regards,

Comments

Andrew Lunn Feb. 3, 2025, 8:07 p.m. UTC | #1
On Mon, Feb 03, 2025 at 08:50:46PM +0100, Thomas Weißschuh wrote:
> While working on the PTP core or userspace components,
> a real PTP device is not always available.
> Introduce a tiny module which creates a mock PTP device.

What does this add which netdevsim does not provide?

     Andrew
Thomas Weißschuh Feb. 3, 2025, 8:15 p.m. UTC | #2
On 2025-02-03 21:07:29+0100, Andrew Lunn wrote:
> On Mon, Feb 03, 2025 at 08:50:46PM +0100, Thomas Weißschuh wrote:
> > While working on the PTP core or userspace components,
> > a real PTP device is not always available.
> > Introduce a tiny module which creates a mock PTP device.
> 
> What does this add which netdevsim does not provide?

Nothing. I did not know this existed.
Thanks for the hint.


Thomas
Jakub Kicinski Feb. 3, 2025, 9:34 p.m. UTC | #3
On Mon, 03 Feb 2025 20:50:46 +0100 Thomas Weißschuh wrote:
> While working on the PTP core or userspace components,
> a real PTP device is not always available.
> Introduce a tiny module which creates a mock PTP device.

FTR we (netdev) do not accept mock devices unless there are selftests
which exercise them in a meaningful way. Otherwise we get a stream
of impossible to judge patches for such devices :(
Andrew Lunn Feb. 3, 2025, 9:51 p.m. UTC | #4
On Mon, Feb 03, 2025 at 08:50:46PM +0100, Thomas Weißschuh wrote:
> While working on the PTP core or userspace components,
> a real PTP device is not always available.
> Introduce a tiny module which creates a mock PTP device.

Since netdevsim already has this functionality, lets drop this patch.

    Andrew

---
pw-bot: rejected
diff mbox series

Patch

diff --git a/drivers/ptp/Kconfig b/drivers/ptp/Kconfig
index 07bf7f9aae019ca26aa6d39a3c19b9dd0420f9bb..f0bbf0cbf13fb89c8cbf8934f6f2f0b81e622466 100644
--- a/drivers/ptp/Kconfig
+++ b/drivers/ptp/Kconfig
@@ -195,6 +195,16 @@  config PTP_1588_CLOCK_MOCK
 	  To compile this driver as a module, choose M here: the module
 	  will be called ptp_mock.
 
+config PTP_1588_CLOCK_MOCK_DEV
+	tristate "Mock-up PTP clock device"
+	depends on PTP_1588_CLOCK_MOCK
+	help
+	  Instantiante a dummy PTP clock device derived from the system
+	  monotonic time.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called ptp_mock_dev.
+
 config PTP_1588_CLOCK_VMW
 	tristate "VMware virtual PTP clock"
 	depends on ACPI && HYPERVISOR_GUEST && X86
diff --git a/drivers/ptp/Makefile b/drivers/ptp/Makefile
index 25f846fe48c9f0406a02c75d83027a0e6cfa10bf..216065f68e152963b35c55594ec1fd0b33db097a 100644
--- a/drivers/ptp/Makefile
+++ b/drivers/ptp/Makefile
@@ -19,6 +19,7 @@  obj-$(CONFIG_PTP_1588_CLOCK_IDTCM)	+= ptp_clockmatrix.o
 obj-$(CONFIG_PTP_1588_CLOCK_FC3W)	+= ptp_fc3.o
 obj-$(CONFIG_PTP_1588_CLOCK_IDT82P33)	+= ptp_idt82p33.o
 obj-$(CONFIG_PTP_1588_CLOCK_MOCK)	+= ptp_mock.o
+obj-$(CONFIG_PTP_1588_CLOCK_MOCK_DEV)	+= ptp_mock_dev.o
 obj-$(CONFIG_PTP_1588_CLOCK_VMW)	+= ptp_vmw.o
 obj-$(CONFIG_PTP_1588_CLOCK_OCP)	+= ptp_ocp.o
 obj-$(CONFIG_PTP_DFL_TOD)		+= ptp_dfl_tod.o
diff --git a/drivers/ptp/ptp_mock_dev.c b/drivers/ptp/ptp_mock_dev.c
new file mode 100644
index 0000000000000000000000000000000000000000..3423e2f0c45a4082875c2e031883735388d27b64
--- /dev/null
+++ b/drivers/ptp/ptp_mock_dev.c
@@ -0,0 +1,32 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2025 Thomas Weißschuh <linux@weissschuh.net>
+ *
+ * Mock-up PTP Hardware Clock device
+ *
+ * Create a PTP device which offers PTP time manipulation operations
+ * using a timecounter/cyclecounter on top of CLOCK_MONOTONIC_RAW.
+ */
+
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/ptp_mock.h>
+
+static struct mock_phc *phc;
+
+static int __init ptp_mock_dev_init(void)
+{
+	phc = mock_phc_create(NULL);
+	return PTR_ERR_OR_ZERO(phc);
+}
+module_init(ptp_mock_dev_init);
+
+static void __exit ptp_mock_dev_exit(void)
+{
+	mock_phc_destroy(phc);
+}
+module_exit(ptp_mock_dev_exit);
+
+MODULE_DESCRIPTION("Mock-up PTP Hardware Clock device");
+MODULE_AUTHOR("Thomas Weißschuh <linux@weissschuh.net>");
+MODULE_LICENSE("GPL");