mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] ptp: Add mock device
@ 2025-02-03 19:50 Thomas Weißschuh
  2025-02-03 20:07 ` Andrew Lunn
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2025-02-03 19:50 UTC (permalink / raw)
  To: Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: linux-kernel, netdev, Thomas Weißschuh

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(+)

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");

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

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] ptp: Add mock device
  2025-02-03 19:50 [PATCH net] ptp: Add mock device Thomas Weißschuh
@ 2025-02-03 20:07 ` Andrew Lunn
  2025-02-03 20:15   ` Thomas Weißschuh
  2025-02-03 21:34 ` Jakub Kicinski
  2025-02-03 21:51 ` Andrew Lunn
  2 siblings, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2025-02-03 20:07 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-kernel, netdev

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] ptp: Add mock device
  2025-02-03 20:07 ` Andrew Lunn
@ 2025-02-03 20:15   ` Thomas Weißschuh
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2025-02-03 20:15 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-kernel, netdev

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] ptp: Add mock device
  2025-02-03 19:50 [PATCH net] ptp: Add mock device Thomas Weißschuh
  2025-02-03 20:07 ` Andrew Lunn
@ 2025-02-03 21:34 ` Jakub Kicinski
  2025-02-03 21:51 ` Andrew Lunn
  2 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2025-02-03 21:34 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
	Paolo Abeni, linux-kernel, netdev

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 :(

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] ptp: Add mock device
  2025-02-03 19:50 [PATCH net] ptp: Add mock device Thomas Weißschuh
  2025-02-03 20:07 ` Andrew Lunn
  2025-02-03 21:34 ` Jakub Kicinski
@ 2025-02-03 21:51 ` Andrew Lunn
  2 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2025-02-03 21:51 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-kernel, netdev

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-02-03 21:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-03 19:50 [PATCH net] ptp: Add mock device Thomas Weißschuh
2025-02-03 20:07 ` Andrew Lunn
2025-02-03 20:15   ` Thomas Weißschuh
2025-02-03 21:34 ` Jakub Kicinski
2025-02-03 21:51 ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®