Skip to contentSkip to conversation

ptp: add Alibaba CIPU PTP clock driver

PATCH Superseded Wen Gu 2 participants 3 messages Jul 17, 2025 – Jul 23, 2025

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Wen Gu

author
#0 lore raw

PATCH v3 1/1 ptp: add Alibaba CIPU PTP clock driver

This adds a driver for Alibaba CIPU PTP clock. The CIPU, an underlying infrastructure of Alibaba Cloud, synchronizes time with reference clocks continuously and provides PTP clocks for VMs and bare metals on cloud.

User space e.g. chrony, in VMs or bare metals can get the value of CIPU clock time through the ptp device exposed by this driver.

---
v3->v2:
- follow the sysfs convention of one value per file;
- rename enum constants for brevity;
- improve macros for printing;
- add more comments;
v2->v1:
https://lore.kernel.org/netdev/[email protected]/
- add Kconfig dependency on CONFIG_PCI to fix kernel test robot's complaint.
v1:
https://lore.kernel.org/netdev/[email protected]/

---
 MAINTAINERS            |   7 +
 drivers/ptp/Kconfig    |  13 +
 drivers/ptp/Makefile   |   1 +
 drivers/ptp/ptp_cipu.c | 947 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 968 insertions(+)
 create mode 100644 drivers/ptp/ptp_cipu.c
MAINTAINERS +7 -0
index 3887d5906786..4473368390cd 100644
@@ -786,6 +786,13 @@ S:	Maintained
 F:	Documentation/i2c/busses/i2c-ali1563.rst
 F:	drivers/i2c/busses/i2c-ali1563.c
 
+ALIBABA CIPU PTP DRIVER
+M:	Wen Gu <[email protected]>
+M:	Xuan Zhuo <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	drivers/ptp/ptp_cipu.c
+
 ALIBABA ELASTIC RDMA DRIVER
 M:	Cheng Xu <[email protected]>
 M:	Kai Shen <[email protected]>
drivers/ptp/Kconfig +13 -0
index 204278eb215e..5811e569a077 100644
@@ -252,4 +252,17 @@ config PTP_S390
 	  driver provides the raw clock value without the delta to
 	  userspace. That way userspace programs like chrony could steer
 	  the kernel clock.
+
+config PTP_1588_CLOCK_CIPU
+	tristate "Alibaba CIPU PTP clock"
+	depends on PTP_1588_CLOCK
+	depends on 64BIT
+	depends on PCI
+	help
+	  This driver adds support for using Alibaba CIPU clock device
+	  as a PTP clock. This is only useful in Alibaba Cloud CIPU
+	  infrastructure.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called ptp_cipu.
 endmenu
drivers/ptp/Makefile +1 -0
index 25f846fe48c9..a168254d3c35 100644
@@ -23,3 +23,4 @@ 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
 obj-$(CONFIG_PTP_S390)			+= ptp_s390.o
+obj-$(CONFIG_PTP_1588_CLOCK_CIPU)	+= ptp_cipu.o
drivers/ptp/ptp_cipu.c new file +947 -0

947 lines not on this page · raw message

Signature · 1 line
2.43.5
maintainer
#1 lore raw

drivers/ptp/ptp_cipu.c line 73

Quoted 3 lines · Wen Gu
drivers/ptp/ptp_cipu.c new file +3 -0
+#define PTP_CIPU_BAR_0	0
+#define PTP_CIPU_REG(reg) \
+	offsetof(struct ptp_cipu_regs, reg)

Minor nit: no need to use a multiple line macro above

[...]

drivers/ptp/ptp_cipu.c line 629

Quoted 5 lines
drivers/ptp/ptp_cipu.c new file +5 -0
+static void ptp_cipu_clear_context(struct ptp_cipu_ctx *ptp_ctx)
+{
+	cancel_delayed_work_sync(&ptp_ctx->gen_timer);
+	cancel_delayed_work_sync(&ptp_ctx->mt_timer);
+	cancel_work_sync(&ptp_ctx->sync_work);

You need to use the 'disable_' variant of the above helper, to avoid the work being rescheduled by the last iteration.

Other than that LGTM, thanks.

Paolo

author
#2 lore raw
Quoted 7 lines · Paolo Abeni

drivers/ptp/ptp_cipu.c line 73

Quoted 3 lines · Wen Gu
drivers/ptp/ptp_cipu.c new file +3 -0
+#define PTP_CIPU_BAR_0	0
+#define PTP_CIPU_REG(reg) \
+	offsetof(struct ptp_cipu_regs, reg)

Minor nit: no need to use a multiple line macro above

Ok, will fix it.

Quoted 10 lines

[...]

drivers/ptp/ptp_cipu.c line 629

Quoted 5 lines
drivers/ptp/ptp_cipu.c new file +5 -0
+static void ptp_cipu_clear_context(struct ptp_cipu_ctx *ptp_ctx)
+{
+	cancel_delayed_work_sync(&ptp_ctx->gen_timer);
+	cancel_delayed_work_sync(&ptp_ctx->mt_timer);
+	cancel_work_sync(&ptp_ctx->sync_work);

You need to use the 'disable_' variant of the above helper, to avoid the work being rescheduled by the last iteration.

Ok, will use new helpers.

Thanks!
Wen Gu

Quoted 3 lines

Other than that LGTM, thanks.

Paolo