Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Time of day based timer functions. |
| 3 | * |
| 4 | * S390 version |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 5 | * Copyright IBM Corp. 1999, 2008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Author(s): Hartmut Penner (hp@de.ibm.com), |
| 7 | * Martin Schwidefsky (schwidefsky@de.ibm.com), |
| 8 | * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com) |
| 9 | * |
| 10 | * Derived from "arch/i386/kernel/time.c" |
| 11 | * Copyright (C) 1991, 1992, 1995 Linus Torvalds |
| 12 | */ |
| 13 | |
Martin Schwidefsky | feab650 | 2008-12-25 13:39:38 +0100 | [diff] [blame] | 14 | #define KMSG_COMPONENT "time" |
| 15 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 16 | |
Heiko Carstens | 052ff46 | 2011-01-05 12:47:28 +0100 | [diff] [blame] | 17 | #include <linux/kernel_stat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/errno.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/sched.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/param.h> |
| 23 | #include <linux/string.h> |
| 24 | #include <linux/mm.h> |
| 25 | #include <linux/interrupt.h> |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 26 | #include <linux/cpu.h> |
| 27 | #include <linux/stop_machine.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/time.h> |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 29 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/delay.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/smp.h> |
| 33 | #include <linux/types.h> |
| 34 | #include <linux/profile.h> |
| 35 | #include <linux/timex.h> |
| 36 | #include <linux/notifier.h> |
John Stultz | 189374a | 2012-09-04 15:27:48 -0400 | [diff] [blame] | 37 | #include <linux/timekeeper_internal.h> |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 38 | #include <linux/clockchips.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 39 | #include <linux/gfp.h> |
Martin Schwidefsky | 860dba4 | 2011-01-05 12:47:25 +0100 | [diff] [blame] | 40 | #include <linux/kprobes.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <asm/uaccess.h> |
Martin Schwidefsky | 4027789 | 2016-05-31 10:16:24 +0200 | [diff] [blame] | 42 | #include <asm/facility.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <asm/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <asm/div64.h> |
Martin Schwidefsky | b020632 | 2008-12-25 13:38:36 +0100 | [diff] [blame] | 45 | #include <asm/vdso.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <asm/irq.h> |
Heiko Carstens | 5a489b9 | 2006-10-06 16:38:35 +0200 | [diff] [blame] | 47 | #include <asm/irq_regs.h> |
Martin Schwidefsky | 27f6b41 | 2012-07-20 11:15:08 +0200 | [diff] [blame] | 48 | #include <asm/vtimer.h> |
Martin Schwidefsky | fd5ada0 | 2016-05-31 15:06:51 +0200 | [diff] [blame] | 49 | #include <asm/stp.h> |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 50 | #include <asm/cio.h> |
Martin Schwidefsky | 638ad34 | 2011-10-30 15:17:13 +0100 | [diff] [blame] | 51 | #include "entry.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | /* change this if you have some constant time drift */ |
| 54 | #define USECS_PER_JIFFY ((unsigned long) 1000000/HZ) |
| 55 | #define CLK_TICKS_PER_JIFFY ((unsigned long) USECS_PER_JIFFY << 12) |
| 56 | |
Martin Schwidefsky | b6112cc | 2009-04-14 15:36:28 +0200 | [diff] [blame] | 57 | u64 sched_clock_base_cc = -1; /* Force to data section. */ |
Heiko Carstens | 05e7ff7 | 2009-09-11 10:28:31 +0200 | [diff] [blame] | 58 | EXPORT_SYMBOL_GPL(sched_clock_base_cc); |
Martin Schwidefsky | b6112cc | 2009-04-14 15:36:28 +0200 | [diff] [blame] | 59 | |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 60 | static DEFINE_PER_CPU(struct clock_event_device, comparators); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Fan Zhang | fdf0365 | 2015-05-13 10:58:41 +0200 | [diff] [blame] | 62 | ATOMIC_NOTIFIER_HEAD(s390_epoch_delta_notifier); |
| 63 | EXPORT_SYMBOL(s390_epoch_delta_notifier); |
| 64 | |
Martin Schwidefsky | 4027789 | 2016-05-31 10:16:24 +0200 | [diff] [blame] | 65 | unsigned char ptff_function_mask[16]; |
| 66 | unsigned long lpar_offset; |
Martin Schwidefsky | 936cc85 | 2016-05-31 12:47:03 +0200 | [diff] [blame] | 67 | unsigned long initial_leap_seconds; |
Martin Schwidefsky | 4027789 | 2016-05-31 10:16:24 +0200 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * Get time offsets with PTFF |
| 71 | */ |
| 72 | void __init ptff_init(void) |
| 73 | { |
| 74 | struct ptff_qto qto; |
Martin Schwidefsky | 936cc85 | 2016-05-31 12:47:03 +0200 | [diff] [blame] | 75 | struct ptff_qui qui; |
Martin Schwidefsky | 4027789 | 2016-05-31 10:16:24 +0200 | [diff] [blame] | 76 | |
| 77 | if (!test_facility(28)) |
| 78 | return; |
| 79 | ptff(&ptff_function_mask, sizeof(ptff_function_mask), PTFF_QAF); |
| 80 | |
| 81 | /* get LPAR offset */ |
| 82 | if (ptff_query(PTFF_QTO) && ptff(&qto, sizeof(qto), PTFF_QTO) == 0) |
| 83 | lpar_offset = qto.tod_epoch_difference; |
Martin Schwidefsky | 936cc85 | 2016-05-31 12:47:03 +0200 | [diff] [blame] | 84 | |
| 85 | /* get initial leap seconds */ |
| 86 | if (ptff_query(PTFF_QUI) && ptff(&qui, sizeof(qui), PTFF_QUI) == 0) |
| 87 | initial_leap_seconds = (unsigned long) |
| 88 | ((long) qui.old_leap * 4096000000L); |
Martin Schwidefsky | 4027789 | 2016-05-31 10:16:24 +0200 | [diff] [blame] | 89 | } |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* |
| 92 | * Scheduler clock - returns current time in nanosec units. |
| 93 | */ |
Heiko Carstens | 7a5388d | 2014-10-22 12:42:38 +0200 | [diff] [blame] | 94 | unsigned long long notrace sched_clock(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 96 | return tod_to_ns(get_tod_clock_monotonic()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
Heiko Carstens | 7a5388d | 2014-10-22 12:42:38 +0200 | [diff] [blame] | 98 | NOKPROBE_SYMBOL(sched_clock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Jan Glauber | 32f65f2 | 2006-02-01 03:06:33 -0800 | [diff] [blame] | 100 | /* |
| 101 | * Monotonic_clock - returns # of nanoseconds passed since time_init() |
| 102 | */ |
| 103 | unsigned long long monotonic_clock(void) |
| 104 | { |
| 105 | return sched_clock(); |
| 106 | } |
| 107 | EXPORT_SYMBOL(monotonic_clock); |
| 108 | |
Xunlei Pang | 689911c | 2015-04-09 09:04:41 +0800 | [diff] [blame] | 109 | void tod_to_timeval(__u64 todval, struct timespec64 *xt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
| 111 | unsigned long long sec; |
| 112 | |
| 113 | sec = todval >> 12; |
| 114 | do_div(sec, 1000000); |
John Stultz | b1e2ba8 | 2010-03-08 12:25:19 +0100 | [diff] [blame] | 115 | xt->tv_sec = sec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | todval -= (sec * 1000000) << 12; |
John Stultz | b1e2ba8 | 2010-03-08 12:25:19 +0100 | [diff] [blame] | 117 | xt->tv_nsec = ((todval * 1000) >> 12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
Christof Schmitt | b592e89 | 2009-08-18 15:43:31 +0200 | [diff] [blame] | 119 | EXPORT_SYMBOL(tod_to_timeval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 121 | void clock_comparator_work(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 123 | struct clock_event_device *cd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 125 | S390_lowcore.clock_comparator = -1ULL; |
Christoph Lameter | eb7e7d7 | 2014-08-17 12:30:45 -0500 | [diff] [blame] | 126 | cd = this_cpu_ptr(&comparators); |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 127 | cd->event_handler(cd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | /* |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 131 | * Fixup the clock comparator. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | */ |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 133 | static void fixup_clock_comparator(unsigned long long delta) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 135 | /* If nobody is waiting there's nothing to fix. */ |
| 136 | if (S390_lowcore.clock_comparator == -1ULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | return; |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 138 | S390_lowcore.clock_comparator += delta; |
| 139 | set_clock_comparator(S390_lowcore.clock_comparator); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Martin Schwidefsky | 8adbf78 | 2013-11-22 12:04:18 +0100 | [diff] [blame] | 142 | static int s390_next_event(unsigned long delta, |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 143 | struct clock_event_device *evt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
Martin Schwidefsky | 8adbf78 | 2013-11-22 12:04:18 +0100 | [diff] [blame] | 145 | S390_lowcore.clock_comparator = get_tod_clock() + delta; |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 146 | set_clock_comparator(S390_lowcore.clock_comparator); |
| 147 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 150 | /* |
| 151 | * Set up lowcore and control register of the current cpu to |
| 152 | * enable TOD clock and clock comparator interrupts. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | */ |
| 154 | void init_cpu_timer(void) |
| 155 | { |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 156 | struct clock_event_device *cd; |
| 157 | int cpu; |
| 158 | |
| 159 | S390_lowcore.clock_comparator = -1ULL; |
| 160 | set_clock_comparator(S390_lowcore.clock_comparator); |
| 161 | |
| 162 | cpu = smp_processor_id(); |
| 163 | cd = &per_cpu(comparators, cpu); |
| 164 | cd->name = "comparator"; |
Martin Schwidefsky | 8adbf78 | 2013-11-22 12:04:18 +0100 | [diff] [blame] | 165 | cd->features = CLOCK_EVT_FEAT_ONESHOT; |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 166 | cd->mult = 16777; |
| 167 | cd->shift = 12; |
| 168 | cd->min_delta_ns = 1; |
| 169 | cd->max_delta_ns = LONG_MAX; |
| 170 | cd->rating = 400; |
Rusty Russell | 320ab2b | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 171 | cd->cpumask = cpumask_of(cpu); |
Martin Schwidefsky | 8adbf78 | 2013-11-22 12:04:18 +0100 | [diff] [blame] | 172 | cd->set_next_event = s390_next_event; |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 173 | |
| 174 | clockevents_register_device(cd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 176 | /* Enable clock comparator timer interrupt. */ |
| 177 | __ctl_set_bit(0,11); |
| 178 | |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 179 | /* Always allow the timing alert external interrupt. */ |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 180 | __ctl_set_bit(0, 4); |
| 181 | } |
| 182 | |
Heiko Carstens | fde15c3 | 2012-03-11 11:59:31 -0400 | [diff] [blame] | 183 | static void clock_comparator_interrupt(struct ext_code ext_code, |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 184 | unsigned int param32, |
| 185 | unsigned long param64) |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 186 | { |
Heiko Carstens | 420f42e | 2013-01-02 15:18:18 +0100 | [diff] [blame] | 187 | inc_irq_stat(IRQEXT_CLK); |
Heiko Carstens | d3d238c | 2008-10-03 21:54:59 +0200 | [diff] [blame] | 188 | if (S390_lowcore.clock_comparator == -1ULL) |
| 189 | set_clock_comparator(S390_lowcore.clock_comparator); |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 190 | } |
| 191 | |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 192 | static void stp_timing_alert(struct stp_irq_parm *); |
| 193 | |
Heiko Carstens | fde15c3 | 2012-03-11 11:59:31 -0400 | [diff] [blame] | 194 | static void timing_alert_interrupt(struct ext_code ext_code, |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 195 | unsigned int param32, unsigned long param64) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 196 | { |
Heiko Carstens | 420f42e | 2013-01-02 15:18:18 +0100 | [diff] [blame] | 197 | inc_irq_stat(IRQEXT_TLA); |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 198 | if (param32 & 0x00038000) |
| 199 | stp_timing_alert((struct stp_irq_parm *) ¶m32); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 200 | } |
| 201 | |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 202 | static void stp_reset(void); |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 203 | |
Xunlei Pang | 689911c | 2015-04-09 09:04:41 +0800 | [diff] [blame] | 204 | void read_persistent_clock64(struct timespec64 *ts) |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 205 | { |
Martin Schwidefsky | 936cc85 | 2016-05-31 12:47:03 +0200 | [diff] [blame] | 206 | __u64 clock; |
| 207 | |
| 208 | clock = get_tod_clock() - initial_leap_seconds; |
| 209 | tod_to_timeval(clock - TOD_UNIX_EPOCH, ts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Xunlei Pang | 689911c | 2015-04-09 09:04:41 +0800 | [diff] [blame] | 212 | void read_boot_clock64(struct timespec64 *ts) |
Martin Schwidefsky | 23970e3 | 2009-08-14 15:47:32 +0200 | [diff] [blame] | 213 | { |
Martin Schwidefsky | 936cc85 | 2016-05-31 12:47:03 +0200 | [diff] [blame] | 214 | __u64 clock; |
| 215 | |
| 216 | clock = sched_clock_base_cc - initial_leap_seconds; |
| 217 | tod_to_timeval(clock - TOD_UNIX_EPOCH, ts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Magnus Damm | 8e19608 | 2009-04-21 12:24:00 -0700 | [diff] [blame] | 220 | static cycle_t read_tod_clock(struct clocksource *cs) |
Martin Schwidefsky | dc64bef | 2006-10-06 16:38:48 +0200 | [diff] [blame] | 221 | { |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 222 | return get_tod_clock(); |
Martin Schwidefsky | dc64bef | 2006-10-06 16:38:48 +0200 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static struct clocksource clocksource_tod = { |
| 226 | .name = "tod", |
Christian Borntraeger | d2cb0e6 | 2007-11-05 11:10:14 +0100 | [diff] [blame] | 227 | .rating = 400, |
Martin Schwidefsky | dc64bef | 2006-10-06 16:38:48 +0200 | [diff] [blame] | 228 | .read = read_tod_clock, |
| 229 | .mask = -1ULL, |
| 230 | .mult = 1000, |
| 231 | .shift = 12, |
Thomas Gleixner | cc02d80 | 2007-02-16 01:27:39 -0800 | [diff] [blame] | 232 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
Martin Schwidefsky | dc64bef | 2006-10-06 16:38:48 +0200 | [diff] [blame] | 233 | }; |
| 234 | |
Martin Schwidefsky | f1b8274 | 2009-08-14 15:47:21 +0200 | [diff] [blame] | 235 | struct clocksource * __init clocksource_default_clock(void) |
| 236 | { |
| 237 | return &clocksource_tod; |
| 238 | } |
Martin Schwidefsky | dc64bef | 2006-10-06 16:38:48 +0200 | [diff] [blame] | 239 | |
Martin Schwidefsky | 79c74ec | 2013-11-22 10:04:53 +0100 | [diff] [blame] | 240 | void update_vsyscall(struct timekeeper *tk) |
Martin Schwidefsky | b020632 | 2008-12-25 13:38:36 +0100 | [diff] [blame] | 241 | { |
Martin Schwidefsky | 79c74ec | 2013-11-22 10:04:53 +0100 | [diff] [blame] | 242 | u64 nsecps; |
| 243 | |
Peter Zijlstra | 876e788 | 2015-03-19 10:09:06 +0100 | [diff] [blame] | 244 | if (tk->tkr_mono.clock != &clocksource_tod) |
Martin Schwidefsky | b020632 | 2008-12-25 13:38:36 +0100 | [diff] [blame] | 245 | return; |
| 246 | |
| 247 | /* Make userspace gettimeofday spin until we're done. */ |
| 248 | ++vdso_data->tb_update_count; |
| 249 | smp_wmb(); |
Peter Zijlstra | 876e788 | 2015-03-19 10:09:06 +0100 | [diff] [blame] | 250 | vdso_data->xtime_tod_stamp = tk->tkr_mono.cycle_last; |
Martin Schwidefsky | 79c74ec | 2013-11-22 10:04:53 +0100 | [diff] [blame] | 251 | vdso_data->xtime_clock_sec = tk->xtime_sec; |
Peter Zijlstra | 876e788 | 2015-03-19 10:09:06 +0100 | [diff] [blame] | 252 | vdso_data->xtime_clock_nsec = tk->tkr_mono.xtime_nsec; |
Martin Schwidefsky | 79c74ec | 2013-11-22 10:04:53 +0100 | [diff] [blame] | 253 | vdso_data->wtom_clock_sec = |
| 254 | tk->xtime_sec + tk->wall_to_monotonic.tv_sec; |
Peter Zijlstra | 876e788 | 2015-03-19 10:09:06 +0100 | [diff] [blame] | 255 | vdso_data->wtom_clock_nsec = tk->tkr_mono.xtime_nsec + |
| 256 | + ((u64) tk->wall_to_monotonic.tv_nsec << tk->tkr_mono.shift); |
| 257 | nsecps = (u64) NSEC_PER_SEC << tk->tkr_mono.shift; |
Martin Schwidefsky | 79c74ec | 2013-11-22 10:04:53 +0100 | [diff] [blame] | 258 | while (vdso_data->wtom_clock_nsec >= nsecps) { |
| 259 | vdso_data->wtom_clock_nsec -= nsecps; |
| 260 | vdso_data->wtom_clock_sec++; |
| 261 | } |
Martin Schwidefsky | b7eacb5 | 2014-08-29 12:31:45 +0200 | [diff] [blame] | 262 | |
| 263 | vdso_data->xtime_coarse_sec = tk->xtime_sec; |
| 264 | vdso_data->xtime_coarse_nsec = |
Peter Zijlstra | 876e788 | 2015-03-19 10:09:06 +0100 | [diff] [blame] | 265 | (long)(tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift); |
Martin Schwidefsky | b7eacb5 | 2014-08-29 12:31:45 +0200 | [diff] [blame] | 266 | vdso_data->wtom_coarse_sec = |
| 267 | vdso_data->xtime_coarse_sec + tk->wall_to_monotonic.tv_sec; |
| 268 | vdso_data->wtom_coarse_nsec = |
| 269 | vdso_data->xtime_coarse_nsec + tk->wall_to_monotonic.tv_nsec; |
| 270 | while (vdso_data->wtom_coarse_nsec >= NSEC_PER_SEC) { |
| 271 | vdso_data->wtom_coarse_nsec -= NSEC_PER_SEC; |
| 272 | vdso_data->wtom_coarse_sec++; |
| 273 | } |
| 274 | |
Peter Zijlstra | 876e788 | 2015-03-19 10:09:06 +0100 | [diff] [blame] | 275 | vdso_data->tk_mult = tk->tkr_mono.mult; |
| 276 | vdso_data->tk_shift = tk->tkr_mono.shift; |
Martin Schwidefsky | b020632 | 2008-12-25 13:38:36 +0100 | [diff] [blame] | 277 | smp_wmb(); |
| 278 | ++vdso_data->tb_update_count; |
| 279 | } |
| 280 | |
| 281 | extern struct timezone sys_tz; |
| 282 | |
| 283 | void update_vsyscall_tz(void) |
| 284 | { |
| 285 | /* Make userspace gettimeofday spin until we're done. */ |
| 286 | ++vdso_data->tb_update_count; |
| 287 | smp_wmb(); |
| 288 | vdso_data->tz_minuteswest = sys_tz.tz_minuteswest; |
| 289 | vdso_data->tz_dsttime = sys_tz.tz_dsttime; |
| 290 | smp_wmb(); |
| 291 | ++vdso_data->tb_update_count; |
| 292 | } |
| 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | /* |
| 295 | * Initialize the TOD clock and the CPU timer of |
| 296 | * the boot cpu. |
| 297 | */ |
| 298 | void __init time_init(void) |
| 299 | { |
Martin Schwidefsky | b6112cc | 2009-04-14 15:36:28 +0200 | [diff] [blame] | 300 | /* Reset time synchronization interfaces. */ |
Martin Schwidefsky | b6112cc | 2009-04-14 15:36:28 +0200 | [diff] [blame] | 301 | stp_reset(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | /* request the clock comparator external interrupt */ |
Thomas Huth | 1dad093 | 2014-03-31 15:24:08 +0200 | [diff] [blame] | 304 | if (register_external_irq(EXT_IRQ_CLK_COMP, clock_comparator_interrupt)) |
| 305 | panic("Couldn't request external interrupt 0x1004"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 307 | /* request the timing alert external interrupt */ |
Thomas Huth | 1dad093 | 2014-03-31 15:24:08 +0200 | [diff] [blame] | 308 | if (register_external_irq(EXT_IRQ_TIMING_ALERT, timing_alert_interrupt)) |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 309 | panic("Couldn't request external interrupt 0x1406"); |
| 310 | |
John Stultz | f893598 | 2015-03-11 21:16:37 -0700 | [diff] [blame] | 311 | if (__clocksource_register(&clocksource_tod) != 0) |
Martin Schwidefsky | ab96e79 | 2009-04-14 15:36:29 +0200 | [diff] [blame] | 312 | panic("Could not register TOD clock source"); |
| 313 | |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 314 | /* Enable TOD clock interrupts on the boot cpu. */ |
| 315 | init_cpu_timer(); |
Martin Schwidefsky | ab96e79 | 2009-04-14 15:36:29 +0200 | [diff] [blame] | 316 | |
Martin Schwidefsky | c185b78 | 2008-12-25 13:39:25 +0100 | [diff] [blame] | 317 | /* Enable cpu timer interrupts on the boot cpu. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | vtime_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 321 | /* |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 322 | * The time is "clock". old is what we think the time is. |
| 323 | * Adjust the value by a multiple of jiffies and add the delta to ntp. |
| 324 | * "delay" is an approximation how long the synchronization took. If |
| 325 | * the time correction is positive, then "delay" is subtracted from |
| 326 | * the time difference and only the remaining part is passed to ntp. |
| 327 | */ |
| 328 | static unsigned long long adjust_time(unsigned long long old, |
| 329 | unsigned long long clock, |
| 330 | unsigned long long delay) |
| 331 | { |
| 332 | unsigned long long delta, ticks; |
| 333 | struct timex adjust; |
| 334 | |
| 335 | if (clock > old) { |
| 336 | /* It is later than we thought. */ |
| 337 | delta = ticks = clock - old; |
| 338 | delta = ticks = (delta < delay) ? 0 : delta - delay; |
| 339 | delta -= do_div(ticks, CLK_TICKS_PER_JIFFY); |
| 340 | adjust.offset = ticks * (1000000 / HZ); |
| 341 | } else { |
| 342 | /* It is earlier than we thought. */ |
| 343 | delta = ticks = old - clock; |
| 344 | delta -= do_div(ticks, CLK_TICKS_PER_JIFFY); |
| 345 | delta = -delta; |
| 346 | adjust.offset = -ticks * (1000000 / HZ); |
| 347 | } |
Christian Borntraeger | 8107d82 | 2008-11-27 11:05:56 +0100 | [diff] [blame] | 348 | sched_clock_base_cc += delta; |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 349 | if (adjust.offset != 0) { |
Martin Schwidefsky | feab650 | 2008-12-25 13:39:38 +0100 | [diff] [blame] | 350 | pr_notice("The ETR interface has adjusted the clock " |
| 351 | "by %li microseconds\n", adjust.offset); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 352 | adjust.modes = ADJ_OFFSET_SINGLESHOT; |
| 353 | do_adjtimex(&adjust); |
| 354 | } |
| 355 | return delta; |
| 356 | } |
| 357 | |
| 358 | static DEFINE_PER_CPU(atomic_t, clock_sync_word); |
Martin Schwidefsky | 8283cb4 | 2009-03-26 15:24:21 +0100 | [diff] [blame] | 359 | static DEFINE_MUTEX(clock_sync_mutex); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 360 | static unsigned long clock_sync_flags; |
| 361 | |
| 362 | #define CLOCK_SYNC_HAS_ETR 0 |
| 363 | #define CLOCK_SYNC_HAS_STP 1 |
| 364 | #define CLOCK_SYNC_ETR 2 |
| 365 | #define CLOCK_SYNC_STP 3 |
| 366 | |
| 367 | /* |
Martin Schwidefsky | 4027789 | 2016-05-31 10:16:24 +0200 | [diff] [blame] | 368 | * The get_clock function for the physical clock. It will get the current |
| 369 | * TOD clock, subtract the LPAR offset and write the result to *clock. |
| 370 | * The function returns 0 if the clock is in sync with the external time |
| 371 | * source. If the clock mode is local it will return -EOPNOTSUPP and |
| 372 | * -EAGAIN if the clock is not in sync with the external reference. |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 373 | */ |
Martin Schwidefsky | 4027789 | 2016-05-31 10:16:24 +0200 | [diff] [blame] | 374 | int get_phys_clock(unsigned long long *clock) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 375 | { |
| 376 | atomic_t *sw_ptr; |
| 377 | unsigned int sw0, sw1; |
| 378 | |
| 379 | sw_ptr = &get_cpu_var(clock_sync_word); |
| 380 | sw0 = atomic_read(sw_ptr); |
Martin Schwidefsky | 4027789 | 2016-05-31 10:16:24 +0200 | [diff] [blame] | 381 | *clock = get_tod_clock() - lpar_offset; |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 382 | sw1 = atomic_read(sw_ptr); |
Heiko Carstens | bd119ee | 2009-12-07 12:52:14 +0100 | [diff] [blame] | 383 | put_cpu_var(clock_sync_word); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 384 | if (sw0 == sw1 && (sw0 & 0x80000000U)) |
| 385 | /* Success: time is in sync. */ |
| 386 | return 0; |
| 387 | if (!test_bit(CLOCK_SYNC_HAS_ETR, &clock_sync_flags) && |
| 388 | !test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags)) |
Heiko Carstens | a8f6db4 | 2012-09-06 15:13:34 +0200 | [diff] [blame] | 389 | return -EOPNOTSUPP; |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 390 | if (!test_bit(CLOCK_SYNC_ETR, &clock_sync_flags) && |
| 391 | !test_bit(CLOCK_SYNC_STP, &clock_sync_flags)) |
| 392 | return -EACCES; |
| 393 | return -EAGAIN; |
| 394 | } |
Martin Schwidefsky | 4027789 | 2016-05-31 10:16:24 +0200 | [diff] [blame] | 395 | EXPORT_SYMBOL(get_phys_clock); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 396 | |
| 397 | /* |
| 398 | * Make get_sync_clock return -EAGAIN. |
| 399 | */ |
| 400 | static void disable_sync_clock(void *dummy) |
| 401 | { |
Christoph Lameter | eb7e7d7 | 2014-08-17 12:30:45 -0500 | [diff] [blame] | 402 | atomic_t *sw_ptr = this_cpu_ptr(&clock_sync_word); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 403 | /* |
| 404 | * Clear the in-sync bit 2^31. All get_sync_clock calls will |
| 405 | * fail until the sync bit is turned back on. In addition |
| 406 | * increase the "sequence" counter to avoid the race of an |
| 407 | * etr event and the complete recovery against get_sync_clock. |
| 408 | */ |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 409 | atomic_andnot(0x80000000, sw_ptr); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 410 | atomic_inc(sw_ptr); |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * Make get_sync_clock return 0 again. |
| 415 | * Needs to be called from a context disabled for preemption. |
| 416 | */ |
| 417 | static void enable_sync_clock(void) |
| 418 | { |
Christoph Lameter | eb7e7d7 | 2014-08-17 12:30:45 -0500 | [diff] [blame] | 419 | atomic_t *sw_ptr = this_cpu_ptr(&clock_sync_word); |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 420 | atomic_or(0x80000000, sw_ptr); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 421 | } |
| 422 | |
Martin Schwidefsky | 8283cb4 | 2009-03-26 15:24:21 +0100 | [diff] [blame] | 423 | /* |
| 424 | * Function to check if the clock is in sync. |
| 425 | */ |
| 426 | static inline int check_sync_clock(void) |
| 427 | { |
| 428 | atomic_t *sw_ptr; |
| 429 | int rc; |
| 430 | |
| 431 | sw_ptr = &get_cpu_var(clock_sync_word); |
| 432 | rc = (atomic_read(sw_ptr) & 0x80000000U) != 0; |
Heiko Carstens | bd119ee | 2009-12-07 12:52:14 +0100 | [diff] [blame] | 433 | put_cpu_var(clock_sync_word); |
Martin Schwidefsky | 8283cb4 | 2009-03-26 15:24:21 +0100 | [diff] [blame] | 434 | return rc; |
| 435 | } |
| 436 | |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 437 | /* Single threaded workqueue used for etr and stp sync events */ |
| 438 | static struct workqueue_struct *time_sync_wq; |
| 439 | |
| 440 | static void __init time_init_wq(void) |
| 441 | { |
Heiko Carstens | 179cb81 | 2009-01-23 16:40:26 +0100 | [diff] [blame] | 442 | if (time_sync_wq) |
| 443 | return; |
| 444 | time_sync_wq = create_singlethread_workqueue("timesync"); |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 445 | } |
| 446 | |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 447 | struct clock_sync_data { |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 448 | atomic_t cpus; |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 449 | int in_sync; |
| 450 | unsigned long long fixup_cc; |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 451 | int etr_port; |
| 452 | struct etr_aib *etr_aib; |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 453 | }; |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 454 | |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 455 | static void clock_sync_cpu(struct clock_sync_data *sync) |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 456 | { |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 457 | atomic_dec(&sync->cpus); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 458 | enable_sync_clock(); |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 459 | /* |
| 460 | * This looks like a busy wait loop but it isn't. etr_sync_cpus |
| 461 | * is called on all other cpus while the TOD clocks is stopped. |
| 462 | * __udelay will stop the cpu on an enabled wait psw until the |
| 463 | * TOD is running again. |
| 464 | */ |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 465 | while (sync->in_sync == 0) { |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 466 | __udelay(1); |
Heiko Carstens | 6c732de | 2007-02-21 10:55:15 +0100 | [diff] [blame] | 467 | /* |
| 468 | * A different cpu changes *in_sync. Therefore use |
| 469 | * barrier() to force memory access. |
| 470 | */ |
| 471 | barrier(); |
| 472 | } |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 473 | if (sync->in_sync != 1) |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 474 | /* Didn't work. Clear per-cpu in sync bit again. */ |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 475 | disable_sync_clock(NULL); |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 476 | /* |
| 477 | * This round of TOD syncing is done. Set the clock comparator |
| 478 | * to the next tick and let the processor continue. |
| 479 | */ |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 480 | fixup_clock_comparator(sync->fixup_cc); |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 481 | } |
| 482 | |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 483 | /* |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 484 | * Server Time Protocol (STP) code. |
| 485 | */ |
Kees Cook | 4cc7ecb7 | 2016-03-17 14:23:00 -0700 | [diff] [blame] | 486 | static bool stp_online; |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 487 | static struct stp_sstpi stp_info; |
| 488 | static void *stp_page; |
| 489 | |
| 490 | static void stp_work_fn(struct work_struct *work); |
Martin Schwidefsky | 0b3016b | 2008-12-25 13:38:38 +0100 | [diff] [blame] | 491 | static DEFINE_MUTEX(stp_work_mutex); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 492 | static DECLARE_WORK(stp_work, stp_work_fn); |
Martin Schwidefsky | 0436230 | 2009-04-14 15:36:19 +0200 | [diff] [blame] | 493 | static struct timer_list stp_timer; |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 494 | |
| 495 | static int __init early_parse_stp(char *p) |
| 496 | { |
Kees Cook | 4cc7ecb7 | 2016-03-17 14:23:00 -0700 | [diff] [blame] | 497 | return kstrtobool(p, &stp_online); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 498 | } |
| 499 | early_param("stp", early_parse_stp); |
| 500 | |
| 501 | /* |
| 502 | * Reset STP attachment. |
| 503 | */ |
Heiko Carstens | 8f84700 | 2008-08-01 16:39:19 +0200 | [diff] [blame] | 504 | static void __init stp_reset(void) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 505 | { |
| 506 | int rc; |
| 507 | |
Heiko Carstens | d7d1104 | 2009-06-22 12:08:03 +0200 | [diff] [blame] | 508 | stp_page = (void *) get_zeroed_page(GFP_ATOMIC); |
Martin Schwidefsky | 2f82f57 | 2016-05-31 09:09:57 +0200 | [diff] [blame] | 509 | rc = chsc_sstpc(stp_page, STP_OP_CTRL, 0x0000, NULL); |
Martin Schwidefsky | 4a672cf | 2008-10-10 21:33:29 +0200 | [diff] [blame] | 510 | if (rc == 0) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 511 | set_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags); |
| 512 | else if (stp_online) { |
Joe Perches | baebc70 | 2016-03-03 20:49:57 -0800 | [diff] [blame] | 513 | pr_warn("The real or virtual hardware system does not provide an STP interface\n"); |
Heiko Carstens | d7d1104 | 2009-06-22 12:08:03 +0200 | [diff] [blame] | 514 | free_page((unsigned long) stp_page); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 515 | stp_page = NULL; |
| 516 | stp_online = 0; |
| 517 | } |
| 518 | } |
| 519 | |
Martin Schwidefsky | 0436230 | 2009-04-14 15:36:19 +0200 | [diff] [blame] | 520 | static void stp_timeout(unsigned long dummy) |
| 521 | { |
| 522 | queue_work(time_sync_wq, &stp_work); |
| 523 | } |
| 524 | |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 525 | static int __init stp_init(void) |
| 526 | { |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 527 | if (!test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags)) |
| 528 | return 0; |
Martin Schwidefsky | 0436230 | 2009-04-14 15:36:19 +0200 | [diff] [blame] | 529 | setup_timer(&stp_timer, stp_timeout, 0UL); |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 530 | time_init_wq(); |
| 531 | if (!stp_online) |
| 532 | return 0; |
| 533 | queue_work(time_sync_wq, &stp_work); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | arch_initcall(stp_init); |
| 538 | |
| 539 | /* |
| 540 | * STP timing alert. There are three causes: |
| 541 | * 1) timing status change |
| 542 | * 2) link availability change |
| 543 | * 3) time control parameter change |
| 544 | * In all three cases we are only interested in the clock source state. |
| 545 | * If a STP clock source is now available use it. |
| 546 | */ |
| 547 | static void stp_timing_alert(struct stp_irq_parm *intparm) |
| 548 | { |
| 549 | if (intparm->tsc || intparm->lac || intparm->tcpc) |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 550 | queue_work(time_sync_wq, &stp_work); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | /* |
| 554 | * STP sync check machine check. This is called when the timing state |
| 555 | * changes from the synchronized state to the unsynchronized state. |
| 556 | * After a STP sync check the clock is not in sync. The machine check |
| 557 | * is broadcasted to all cpus at the same time. |
| 558 | */ |
Heiko Carstens | 29b0a82 | 2015-10-09 13:48:03 +0200 | [diff] [blame] | 559 | int stp_sync_check(void) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 560 | { |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 561 | disable_sync_clock(NULL); |
Heiko Carstens | 29b0a82 | 2015-10-09 13:48:03 +0200 | [diff] [blame] | 562 | return 1; |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | /* |
| 566 | * STP island condition machine check. This is called when an attached |
| 567 | * server attempts to communicate over an STP link and the servers |
| 568 | * have matching CTN ids and have a valid stratum-1 configuration |
| 569 | * but the configurations do not match. |
| 570 | */ |
Heiko Carstens | 29b0a82 | 2015-10-09 13:48:03 +0200 | [diff] [blame] | 571 | int stp_island_check(void) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 572 | { |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 573 | disable_sync_clock(NULL); |
Heiko Carstens | 29b0a82 | 2015-10-09 13:48:03 +0200 | [diff] [blame] | 574 | return 1; |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 575 | } |
| 576 | |
Heiko Carstens | 29b0a82 | 2015-10-09 13:48:03 +0200 | [diff] [blame] | 577 | void stp_queue_work(void) |
| 578 | { |
| 579 | queue_work(time_sync_wq, &stp_work); |
| 580 | } |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 581 | |
| 582 | static int stp_sync_clock(void *data) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 583 | { |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 584 | static int first; |
Fan Zhang | fdf0365 | 2015-05-13 10:58:41 +0200 | [diff] [blame] | 585 | unsigned long long old_clock, delta, new_clock, clock_delta; |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 586 | struct clock_sync_data *stp_sync; |
Martin Schwidefsky | 4027789 | 2016-05-31 10:16:24 +0200 | [diff] [blame] | 587 | struct ptff_qto qto; |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 588 | int rc; |
| 589 | |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 590 | stp_sync = data; |
| 591 | |
| 592 | if (xchg(&first, 1) == 1) { |
| 593 | /* Slave */ |
| 594 | clock_sync_cpu(stp_sync); |
| 595 | return 0; |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 596 | } |
| 597 | |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 598 | /* Wait until all other cpus entered the sync function. */ |
| 599 | while (atomic_read(&stp_sync->cpus) != 0) |
| 600 | cpu_relax(); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 601 | |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 602 | enable_sync_clock(); |
| 603 | |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 604 | rc = 0; |
| 605 | if (stp_info.todoff[0] || stp_info.todoff[1] || |
| 606 | stp_info.todoff[2] || stp_info.todoff[3] || |
| 607 | stp_info.tmd != 2) { |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 608 | old_clock = get_tod_clock(); |
Martin Schwidefsky | 2f82f57 | 2016-05-31 09:09:57 +0200 | [diff] [blame] | 609 | rc = chsc_sstpc(stp_page, STP_OP_SYNC, 0, &clock_delta); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 610 | if (rc == 0) { |
Martin Schwidefsky | 2f82f57 | 2016-05-31 09:09:57 +0200 | [diff] [blame] | 611 | new_clock = old_clock + clock_delta; |
Fan Zhang | fdf0365 | 2015-05-13 10:58:41 +0200 | [diff] [blame] | 612 | delta = adjust_time(old_clock, new_clock, 0); |
Martin Schwidefsky | 4027789 | 2016-05-31 10:16:24 +0200 | [diff] [blame] | 613 | if (ptff_query(PTFF_QTO) && |
| 614 | ptff(&qto, sizeof(qto), PTFF_QTO) == 0) |
| 615 | /* Update LPAR offset */ |
| 616 | lpar_offset = qto.tod_epoch_difference; |
Fan Zhang | fdf0365 | 2015-05-13 10:58:41 +0200 | [diff] [blame] | 617 | atomic_notifier_call_chain(&s390_epoch_delta_notifier, |
| 618 | 0, &clock_delta); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 619 | fixup_clock_comparator(delta); |
| 620 | rc = chsc_sstpi(stp_page, &stp_info, |
| 621 | sizeof(struct stp_sstpi)); |
| 622 | if (rc == 0 && stp_info.tmd != 2) |
| 623 | rc = -EAGAIN; |
| 624 | } |
| 625 | } |
| 626 | if (rc) { |
| 627 | disable_sync_clock(NULL); |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 628 | stp_sync->in_sync = -EAGAIN; |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 629 | } else |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 630 | stp_sync->in_sync = 1; |
| 631 | xchg(&first, 0); |
| 632 | return 0; |
| 633 | } |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 634 | |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 635 | /* |
| 636 | * STP work. Check for the STP state and take over the clock |
| 637 | * synchronization if the STP clock source is usable. |
| 638 | */ |
| 639 | static void stp_work_fn(struct work_struct *work) |
| 640 | { |
| 641 | struct clock_sync_data stp_sync; |
| 642 | int rc; |
| 643 | |
Martin Schwidefsky | 0b3016b | 2008-12-25 13:38:38 +0100 | [diff] [blame] | 644 | /* prevent multiple execution. */ |
| 645 | mutex_lock(&stp_work_mutex); |
| 646 | |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 647 | if (!stp_online) { |
Martin Schwidefsky | 2f82f57 | 2016-05-31 09:09:57 +0200 | [diff] [blame] | 648 | chsc_sstpc(stp_page, STP_OP_CTRL, 0x0000, NULL); |
Martin Schwidefsky | 0436230 | 2009-04-14 15:36:19 +0200 | [diff] [blame] | 649 | del_timer_sync(&stp_timer); |
Martin Schwidefsky | 0b3016b | 2008-12-25 13:38:38 +0100 | [diff] [blame] | 650 | goto out_unlock; |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 651 | } |
| 652 | |
Martin Schwidefsky | 2f82f57 | 2016-05-31 09:09:57 +0200 | [diff] [blame] | 653 | rc = chsc_sstpc(stp_page, STP_OP_CTRL, 0xb0e0, NULL); |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 654 | if (rc) |
Martin Schwidefsky | 0b3016b | 2008-12-25 13:38:38 +0100 | [diff] [blame] | 655 | goto out_unlock; |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 656 | |
| 657 | rc = chsc_sstpi(stp_page, &stp_info, sizeof(struct stp_sstpi)); |
| 658 | if (rc || stp_info.c == 0) |
Martin Schwidefsky | 0b3016b | 2008-12-25 13:38:38 +0100 | [diff] [blame] | 659 | goto out_unlock; |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 660 | |
Martin Schwidefsky | 8283cb4 | 2009-03-26 15:24:21 +0100 | [diff] [blame] | 661 | /* Skip synchronization if the clock is already in sync. */ |
| 662 | if (check_sync_clock()) |
| 663 | goto out_unlock; |
| 664 | |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 665 | memset(&stp_sync, 0, sizeof(stp_sync)); |
| 666 | get_online_cpus(); |
| 667 | atomic_set(&stp_sync.cpus, num_online_cpus() - 1); |
KOSAKI Motohiro | 0f1959f | 2011-05-23 10:24:36 +0200 | [diff] [blame] | 668 | stop_machine(stp_sync_clock, &stp_sync, cpu_online_mask); |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 669 | put_online_cpus(); |
Martin Schwidefsky | 0b3016b | 2008-12-25 13:38:38 +0100 | [diff] [blame] | 670 | |
Martin Schwidefsky | 0436230 | 2009-04-14 15:36:19 +0200 | [diff] [blame] | 671 | if (!check_sync_clock()) |
| 672 | /* |
| 673 | * There is a usable clock but the synchonization failed. |
| 674 | * Retry after a second. |
| 675 | */ |
| 676 | mod_timer(&stp_timer, jiffies + HZ); |
| 677 | |
Martin Schwidefsky | 0b3016b | 2008-12-25 13:38:38 +0100 | [diff] [blame] | 678 | out_unlock: |
| 679 | mutex_unlock(&stp_work_mutex); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | /* |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 683 | * STP subsys sysfs interface functions |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 684 | */ |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 685 | static struct bus_type stp_subsys = { |
| 686 | .name = "stp", |
| 687 | .dev_name = "stp", |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 688 | }; |
| 689 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 690 | static ssize_t stp_ctn_id_show(struct device *dev, |
| 691 | struct device_attribute *attr, |
Andi Kleen | c9be0a3 | 2010-01-05 12:47:58 +0100 | [diff] [blame] | 692 | char *buf) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 693 | { |
| 694 | if (!stp_online) |
| 695 | return -ENODATA; |
| 696 | return sprintf(buf, "%016llx\n", |
| 697 | *(unsigned long long *) stp_info.ctnid); |
| 698 | } |
| 699 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 700 | static DEVICE_ATTR(ctn_id, 0400, stp_ctn_id_show, NULL); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 701 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 702 | static ssize_t stp_ctn_type_show(struct device *dev, |
| 703 | struct device_attribute *attr, |
Andi Kleen | c9be0a3 | 2010-01-05 12:47:58 +0100 | [diff] [blame] | 704 | char *buf) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 705 | { |
| 706 | if (!stp_online) |
| 707 | return -ENODATA; |
| 708 | return sprintf(buf, "%i\n", stp_info.ctn); |
| 709 | } |
| 710 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 711 | static DEVICE_ATTR(ctn_type, 0400, stp_ctn_type_show, NULL); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 712 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 713 | static ssize_t stp_dst_offset_show(struct device *dev, |
| 714 | struct device_attribute *attr, |
Andi Kleen | c9be0a3 | 2010-01-05 12:47:58 +0100 | [diff] [blame] | 715 | char *buf) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 716 | { |
| 717 | if (!stp_online || !(stp_info.vbits & 0x2000)) |
| 718 | return -ENODATA; |
| 719 | return sprintf(buf, "%i\n", (int)(s16) stp_info.dsto); |
| 720 | } |
| 721 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 722 | static DEVICE_ATTR(dst_offset, 0400, stp_dst_offset_show, NULL); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 723 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 724 | static ssize_t stp_leap_seconds_show(struct device *dev, |
| 725 | struct device_attribute *attr, |
Andi Kleen | c9be0a3 | 2010-01-05 12:47:58 +0100 | [diff] [blame] | 726 | char *buf) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 727 | { |
| 728 | if (!stp_online || !(stp_info.vbits & 0x8000)) |
| 729 | return -ENODATA; |
| 730 | return sprintf(buf, "%i\n", (int)(s16) stp_info.leaps); |
| 731 | } |
| 732 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 733 | static DEVICE_ATTR(leap_seconds, 0400, stp_leap_seconds_show, NULL); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 734 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 735 | static ssize_t stp_stratum_show(struct device *dev, |
| 736 | struct device_attribute *attr, |
Andi Kleen | c9be0a3 | 2010-01-05 12:47:58 +0100 | [diff] [blame] | 737 | char *buf) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 738 | { |
| 739 | if (!stp_online) |
| 740 | return -ENODATA; |
| 741 | return sprintf(buf, "%i\n", (int)(s16) stp_info.stratum); |
| 742 | } |
| 743 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 744 | static DEVICE_ATTR(stratum, 0400, stp_stratum_show, NULL); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 745 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 746 | static ssize_t stp_time_offset_show(struct device *dev, |
| 747 | struct device_attribute *attr, |
Andi Kleen | c9be0a3 | 2010-01-05 12:47:58 +0100 | [diff] [blame] | 748 | char *buf) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 749 | { |
| 750 | if (!stp_online || !(stp_info.vbits & 0x0800)) |
| 751 | return -ENODATA; |
| 752 | return sprintf(buf, "%i\n", (int) stp_info.tto); |
| 753 | } |
| 754 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 755 | static DEVICE_ATTR(time_offset, 0400, stp_time_offset_show, NULL); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 756 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 757 | static ssize_t stp_time_zone_offset_show(struct device *dev, |
| 758 | struct device_attribute *attr, |
Andi Kleen | c9be0a3 | 2010-01-05 12:47:58 +0100 | [diff] [blame] | 759 | char *buf) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 760 | { |
| 761 | if (!stp_online || !(stp_info.vbits & 0x4000)) |
| 762 | return -ENODATA; |
| 763 | return sprintf(buf, "%i\n", (int)(s16) stp_info.tzo); |
| 764 | } |
| 765 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 766 | static DEVICE_ATTR(time_zone_offset, 0400, |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 767 | stp_time_zone_offset_show, NULL); |
| 768 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 769 | static ssize_t stp_timing_mode_show(struct device *dev, |
| 770 | struct device_attribute *attr, |
Andi Kleen | c9be0a3 | 2010-01-05 12:47:58 +0100 | [diff] [blame] | 771 | char *buf) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 772 | { |
| 773 | if (!stp_online) |
| 774 | return -ENODATA; |
| 775 | return sprintf(buf, "%i\n", stp_info.tmd); |
| 776 | } |
| 777 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 778 | static DEVICE_ATTR(timing_mode, 0400, stp_timing_mode_show, NULL); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 779 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 780 | static ssize_t stp_timing_state_show(struct device *dev, |
| 781 | struct device_attribute *attr, |
Andi Kleen | c9be0a3 | 2010-01-05 12:47:58 +0100 | [diff] [blame] | 782 | char *buf) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 783 | { |
| 784 | if (!stp_online) |
| 785 | return -ENODATA; |
| 786 | return sprintf(buf, "%i\n", stp_info.tst); |
| 787 | } |
| 788 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 789 | static DEVICE_ATTR(timing_state, 0400, stp_timing_state_show, NULL); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 790 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 791 | static ssize_t stp_online_show(struct device *dev, |
| 792 | struct device_attribute *attr, |
Andi Kleen | c9be0a3 | 2010-01-05 12:47:58 +0100 | [diff] [blame] | 793 | char *buf) |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 794 | { |
| 795 | return sprintf(buf, "%i\n", stp_online); |
| 796 | } |
| 797 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 798 | static ssize_t stp_online_store(struct device *dev, |
| 799 | struct device_attribute *attr, |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 800 | const char *buf, size_t count) |
| 801 | { |
| 802 | unsigned int value; |
| 803 | |
| 804 | value = simple_strtoul(buf, NULL, 0); |
| 805 | if (value != 0 && value != 1) |
| 806 | return -EINVAL; |
| 807 | if (!test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags)) |
| 808 | return -EOPNOTSUPP; |
Martin Schwidefsky | 8283cb4 | 2009-03-26 15:24:21 +0100 | [diff] [blame] | 809 | mutex_lock(&clock_sync_mutex); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 810 | stp_online = value; |
Martin Schwidefsky | 8283cb4 | 2009-03-26 15:24:21 +0100 | [diff] [blame] | 811 | if (stp_online) |
| 812 | set_bit(CLOCK_SYNC_STP, &clock_sync_flags); |
| 813 | else |
| 814 | clear_bit(CLOCK_SYNC_STP, &clock_sync_flags); |
Heiko Carstens | 750887d | 2008-12-25 13:38:37 +0100 | [diff] [blame] | 815 | queue_work(time_sync_wq, &stp_work); |
Martin Schwidefsky | 8283cb4 | 2009-03-26 15:24:21 +0100 | [diff] [blame] | 816 | mutex_unlock(&clock_sync_mutex); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 817 | return count; |
| 818 | } |
| 819 | |
| 820 | /* |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 821 | * Can't use DEVICE_ATTR because the attribute should be named |
| 822 | * stp/online but dev_attr_online already exists in this file .. |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 823 | */ |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 824 | static struct device_attribute dev_attr_stp_online = { |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 825 | .attr = { .name = "online", .mode = 0600 }, |
| 826 | .show = stp_online_show, |
| 827 | .store = stp_online_store, |
| 828 | }; |
| 829 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 830 | static struct device_attribute *stp_attributes[] = { |
| 831 | &dev_attr_ctn_id, |
| 832 | &dev_attr_ctn_type, |
| 833 | &dev_attr_dst_offset, |
| 834 | &dev_attr_leap_seconds, |
| 835 | &dev_attr_stp_online, |
| 836 | &dev_attr_stratum, |
| 837 | &dev_attr_time_offset, |
| 838 | &dev_attr_time_zone_offset, |
| 839 | &dev_attr_timing_mode, |
| 840 | &dev_attr_timing_state, |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 841 | NULL |
| 842 | }; |
| 843 | |
| 844 | static int __init stp_init_sysfs(void) |
| 845 | { |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 846 | struct device_attribute **attr; |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 847 | int rc; |
| 848 | |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 849 | rc = subsys_system_register(&stp_subsys, NULL); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 850 | if (rc) |
| 851 | goto out; |
| 852 | for (attr = stp_attributes; *attr; attr++) { |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 853 | rc = device_create_file(stp_subsys.dev_root, *attr); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 854 | if (rc) |
| 855 | goto out_unreg; |
| 856 | } |
| 857 | return 0; |
| 858 | out_unreg: |
| 859 | for (; attr >= stp_attributes; attr--) |
Kay Sievers | 3fbacff | 2011-12-21 15:09:50 -0800 | [diff] [blame] | 860 | device_remove_file(stp_subsys.dev_root, *attr); |
| 861 | bus_unregister(&stp_subsys); |
Martin Schwidefsky | d2fec59 | 2008-07-14 09:58:56 +0200 | [diff] [blame] | 862 | out: |
| 863 | return rc; |
| 864 | } |
| 865 | |
| 866 | device_initcall(stp_init_sysfs); |