Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'ptp-driver-for-s390-clocks'

Sven Schnelle says:

====================
PtP driver for s390 clocks

these patches add support for using the s390 physical and TOD clock as ptp
clock. To do so, the first patch adds a clock id to the s390 TOD clock,
while the second patch adds the PtP driver itself.
====================

Link: https://patch.msgid.link/20241023065601.449586-1-svens@linux.ibm.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+162
+6
MAINTAINERS
··· 20204 20204 F: arch/s390/pci/ 20205 20205 F: drivers/pci/hotplug/s390_pci_hpc.c 20206 20206 20207 + S390 PTP DRIVER 20208 + M: Sven Schnelle <svens@linux.ibm.com> 20209 + L: linux-s390@vger.kernel.org 20210 + S: Supported 20211 + F: drivers/ptp/ptp_s390.c 20212 + 20207 20213 S390 SCM DRIVER 20208 20214 M: Vineeth Vijayan <vneethv@linux.ibm.com> 20209 20215 L: linux-s390@vger.kernel.org
+1
arch/s390/include/asm/stp.h
··· 94 94 int stp_sync_check(void); 95 95 int stp_island_check(void); 96 96 void stp_queue_work(void); 97 + bool stp_enabled(void); 97 98 98 99 #endif /* __S390_STP_H */
+6
arch/s390/include/asm/timex.h
··· 93 93 #define PTFF_QAF 0x00 /* query available functions */ 94 94 #define PTFF_QTO 0x01 /* query tod offset */ 95 95 #define PTFF_QSI 0x02 /* query steering information */ 96 + #define PTFF_QPT 0x03 /* query physical clock */ 96 97 #define PTFF_QUI 0x04 /* query UTC information */ 97 98 #define PTFF_ATO 0x40 /* adjust tod offset */ 98 99 #define PTFF_STO 0x41 /* set tod offset */ ··· 249 248 static __always_inline unsigned long tod_to_ns(unsigned long todval) 250 249 { 251 250 return ((todval >> 9) * 125) + (((todval & 0x1ff) * 125) >> 9); 251 + } 252 + 253 + static __always_inline u128 eitod_to_ns(u128 todval) 254 + { 255 + return (todval * 125) >> 9; 252 256 } 253 257 254 258 /**
+7
arch/s390/kernel/time.c
··· 255 255 .shift = 24, 256 256 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 257 257 .vdso_clock_mode = VDSO_CLOCKMODE_TOD, 258 + .id = CSID_S390_TOD, 258 259 }; 259 260 260 261 struct clocksource * __init clocksource_default_clock(void) ··· 468 467 stp_online = false; 469 468 } 470 469 } 470 + 471 + bool stp_enabled(void) 472 + { 473 + return test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags) && stp_online; 474 + } 475 + EXPORT_SYMBOL(stp_enabled); 471 476 472 477 static void stp_timeout(struct timer_list *unused) 473 478 {
+11
drivers/ptp/Kconfig
··· 237 237 To compile this driver as a module, choose M here: the module 238 238 will be called ptp_dfl_tod. 239 239 240 + config PTP_S390 241 + tristate "S390 PTP driver" 242 + depends on PTP_1588_CLOCK 243 + depends on S390 244 + help 245 + This driver adds support for S390 time steering via the PtP 246 + interface. This works by adding a in-kernel clock delta value, 247 + which is always added to time values used in the kernel. The PtP 248 + driver provides the raw clock value without the delta to 249 + userspace. That way userspace programs like chrony could steer 250 + the kernel clock. 240 251 endmenu
+1
drivers/ptp/Makefile
··· 22 22 obj-$(CONFIG_PTP_1588_CLOCK_VMW) += ptp_vmw.o 23 23 obj-$(CONFIG_PTP_1588_CLOCK_OCP) += ptp_ocp.o 24 24 obj-$(CONFIG_PTP_DFL_TOD) += ptp_dfl_tod.o 25 + obj-$(CONFIG_PTP_S390) += ptp_s390.o
+129
drivers/ptp/ptp_s390.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * s390 PTP clock driver 4 + * 5 + */ 6 + 7 + #include "ptp_private.h" 8 + #include <linux/time.h> 9 + #include <asm/stp.h> 10 + 11 + static struct ptp_clock *ptp_stcke_clock, *ptp_qpt_clock; 12 + 13 + static int ptp_s390_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 14 + { 15 + return -EOPNOTSUPP; 16 + } 17 + 18 + static int ptp_s390_adjtime(struct ptp_clock_info *ptp, s64 delta) 19 + { 20 + return -EOPNOTSUPP; 21 + } 22 + 23 + static struct timespec64 eitod_to_timespec64(union tod_clock *clk) 24 + { 25 + return ns_to_timespec64(eitod_to_ns(clk->eitod - TOD_UNIX_EPOCH)); 26 + } 27 + 28 + static struct timespec64 tod_to_timespec64(unsigned long tod) 29 + { 30 + return ns_to_timespec64(tod_to_ns(tod - TOD_UNIX_EPOCH)); 31 + } 32 + 33 + static int ptp_s390_stcke_gettime(struct ptp_clock_info *ptp, 34 + struct timespec64 *ts) 35 + { 36 + union tod_clock tod; 37 + 38 + if (!stp_enabled()) 39 + return -EOPNOTSUPP; 40 + 41 + store_tod_clock_ext(&tod); 42 + *ts = eitod_to_timespec64(&tod); 43 + return 0; 44 + } 45 + 46 + static int ptp_s390_qpt_gettime(struct ptp_clock_info *ptp, 47 + struct timespec64 *ts) 48 + { 49 + unsigned long tod; 50 + 51 + ptff(&tod, sizeof(tod), PTFF_QPT); 52 + *ts = tod_to_timespec64(tod); 53 + return 0; 54 + } 55 + 56 + static int ptp_s390_settime(struct ptp_clock_info *ptp, 57 + const struct timespec64 *ts) 58 + { 59 + return -EOPNOTSUPP; 60 + } 61 + 62 + static int s390_arch_ptp_get_crosststamp(ktime_t *device_time, 63 + struct system_counterval_t *system_counter, 64 + void *ctx) 65 + { 66 + union tod_clock clk; 67 + 68 + store_tod_clock_ext(&clk); 69 + *device_time = ns_to_ktime(tod_to_ns(clk.tod - TOD_UNIX_EPOCH)); 70 + system_counter->cycles = clk.tod; 71 + system_counter->cs_id = CSID_S390_TOD; 72 + return 0; 73 + } 74 + 75 + static int ptp_s390_getcrosststamp(struct ptp_clock_info *ptp, 76 + struct system_device_crosststamp *xtstamp) 77 + { 78 + if (!stp_enabled()) 79 + return -EOPNOTSUPP; 80 + return get_device_system_crosststamp(s390_arch_ptp_get_crosststamp, NULL, NULL, xtstamp); 81 + } 82 + 83 + static struct ptp_clock_info ptp_s390_stcke_info = { 84 + .owner = THIS_MODULE, 85 + .name = "s390 STCKE Clock", 86 + .max_adj = 0, 87 + .adjfine = ptp_s390_adjfine, 88 + .adjtime = ptp_s390_adjtime, 89 + .gettime64 = ptp_s390_stcke_gettime, 90 + .settime64 = ptp_s390_settime, 91 + .getcrosststamp = ptp_s390_getcrosststamp, 92 + }; 93 + 94 + static struct ptp_clock_info ptp_s390_qpt_info = { 95 + .owner = THIS_MODULE, 96 + .name = "s390 Physical Clock", 97 + .max_adj = 0, 98 + .adjfine = ptp_s390_adjfine, 99 + .adjtime = ptp_s390_adjtime, 100 + .gettime64 = ptp_s390_qpt_gettime, 101 + .settime64 = ptp_s390_settime, 102 + }; 103 + 104 + static __init int ptp_s390_init(void) 105 + { 106 + ptp_stcke_clock = ptp_clock_register(&ptp_s390_stcke_info, NULL); 107 + if (IS_ERR(ptp_stcke_clock)) 108 + return PTR_ERR(ptp_stcke_clock); 109 + 110 + ptp_qpt_clock = ptp_clock_register(&ptp_s390_qpt_info, NULL); 111 + if (IS_ERR(ptp_qpt_clock)) { 112 + ptp_clock_unregister(ptp_stcke_clock); 113 + return PTR_ERR(ptp_qpt_clock); 114 + } 115 + return 0; 116 + } 117 + 118 + static __exit void ptp_s390_exit(void) 119 + { 120 + ptp_clock_unregister(ptp_qpt_clock); 121 + ptp_clock_unregister(ptp_stcke_clock); 122 + } 123 + 124 + module_init(ptp_s390_init); 125 + module_exit(ptp_s390_exit); 126 + 127 + MODULE_AUTHOR("Sven Schnelle <svens@linux.ibm.com>"); 128 + MODULE_DESCRIPTION("s390 Physical/STCKE Clock PtP Driver"); 129 + MODULE_LICENSE("GPL");
+1
include/linux/clocksource_ids.h
··· 6 6 enum clocksource_ids { 7 7 CSID_GENERIC = 0, 8 8 CSID_ARM_ARCH_COUNTER, 9 + CSID_S390_TOD, 9 10 CSID_X86_TSC_EARLY, 10 11 CSID_X86_TSC, 11 12 CSID_X86_KVM_CLK,