2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Time of day based timer functions.
|
|
|
|
*
|
|
|
|
* S390 version
|
2008-07-14 01:58:56 -06:00
|
|
|
* Copyright IBM Corp. 1999, 2008
|
2005-04-16 16:20:36 -06:00
|
|
|
* Author(s): Hartmut Penner (hp@de.ibm.com),
|
|
|
|
* Martin Schwidefsky (schwidefsky@de.ibm.com),
|
|
|
|
* Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
|
|
|
|
*
|
|
|
|
* Derived from "arch/i386/kernel/time.c"
|
|
|
|
* Copyright (C) 1991, 1992, 1995 Linus Torvalds
|
|
|
|
*/
|
|
|
|
|
2008-12-25 05:39:38 -07:00
|
|
|
#define KMSG_COMPONENT "time"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
|
2011-01-05 04:47:28 -07:00
|
|
|
#include <linux/kernel_stat.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/param.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/interrupt.h>
|
2008-12-25 05:38:37 -07:00
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/stop_machine.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/time.h>
|
2011-12-21 16:09:50 -07:00
|
|
|
#include <linux/device.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/profile.h>
|
|
|
|
#include <linux/timex.h>
|
|
|
|
#include <linux/notifier.h>
|
2012-09-04 13:27:48 -06:00
|
|
|
#include <linux/timekeeper_internal.h>
|
2008-04-16 23:46:25 -06:00
|
|
|
#include <linux/clockchips.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/gfp.h>
|
2011-01-05 04:47:25 -07:00
|
|
|
#include <linux/kprobes.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <asm/uaccess.h>
|
2016-05-31 02:16:24 -06:00
|
|
|
#include <asm/facility.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <asm/delay.h>
|
|
|
|
#include <asm/div64.h>
|
2008-12-25 05:38:36 -07:00
|
|
|
#include <asm/vdso.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <asm/irq.h>
|
2006-10-06 08:38:35 -06:00
|
|
|
#include <asm/irq_regs.h>
|
2012-07-20 03:15:08 -06:00
|
|
|
#include <asm/vtimer.h>
|
2007-02-05 13:18:19 -07:00
|
|
|
#include <asm/etr.h>
|
2008-04-16 23:46:26 -06:00
|
|
|
#include <asm/cio.h>
|
2011-10-30 08:17:13 -06:00
|
|
|
#include "entry.h"
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* change this if you have some constant time drift */
|
|
|
|
#define USECS_PER_JIFFY ((unsigned long) 1000000/HZ)
|
|
|
|
#define CLK_TICKS_PER_JIFFY ((unsigned long) USECS_PER_JIFFY << 12)
|
|
|
|
|
2009-04-14 07:36:28 -06:00
|
|
|
u64 sched_clock_base_cc = -1; /* Force to data section. */
|
2009-09-11 02:28:31 -06:00
|
|
|
EXPORT_SYMBOL_GPL(sched_clock_base_cc);
|
2009-04-14 07:36:28 -06:00
|
|
|
|
2008-04-16 23:46:25 -06:00
|
|
|
static DEFINE_PER_CPU(struct clock_event_device, comparators);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-05-13 02:58:41 -06:00
|
|
|
ATOMIC_NOTIFIER_HEAD(s390_epoch_delta_notifier);
|
|
|
|
EXPORT_SYMBOL(s390_epoch_delta_notifier);
|
|
|
|
|
2016-05-31 02:16:24 -06:00
|
|
|
unsigned char ptff_function_mask[16];
|
|
|
|
unsigned long lpar_offset;
|
2016-05-31 04:47:03 -06:00
|
|
|
unsigned long initial_leap_seconds;
|
2016-05-31 02:16:24 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get time offsets with PTFF
|
|
|
|
*/
|
|
|
|
void __init ptff_init(void)
|
|
|
|
{
|
|
|
|
struct ptff_qto qto;
|
2016-05-31 04:47:03 -06:00
|
|
|
struct ptff_qui qui;
|
2016-05-31 02:16:24 -06:00
|
|
|
|
|
|
|
if (!test_facility(28))
|
|
|
|
return;
|
|
|
|
ptff(&ptff_function_mask, sizeof(ptff_function_mask), PTFF_QAF);
|
|
|
|
|
|
|
|
/* get LPAR offset */
|
|
|
|
if (ptff_query(PTFF_QTO) && ptff(&qto, sizeof(qto), PTFF_QTO) == 0)
|
|
|
|
lpar_offset = qto.tod_epoch_difference;
|
2016-05-31 04:47:03 -06:00
|
|
|
|
|
|
|
/* get initial leap seconds */
|
|
|
|
if (ptff_query(PTFF_QUI) && ptff(&qui, sizeof(qui), PTFF_QUI) == 0)
|
|
|
|
initial_leap_seconds = (unsigned long)
|
|
|
|
((long) qui.old_leap * 4096000000L);
|
2016-05-31 02:16:24 -06:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Scheduler clock - returns current time in nanosec units.
|
|
|
|
*/
|
2014-10-22 04:42:38 -06:00
|
|
|
unsigned long long notrace sched_clock(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2013-01-30 01:49:40 -07:00
|
|
|
return tod_to_ns(get_tod_clock_monotonic());
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2014-10-22 04:42:38 -06:00
|
|
|
NOKPROBE_SYMBOL(sched_clock);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-02-01 04:06:33 -07:00
|
|
|
/*
|
|
|
|
* Monotonic_clock - returns # of nanoseconds passed since time_init()
|
|
|
|
*/
|
|
|
|
unsigned long long monotonic_clock(void)
|
|
|
|
{
|
|
|
|
return sched_clock();
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(monotonic_clock);
|
|
|
|
|
2015-04-08 19:04:41 -06:00
|
|
|
void tod_to_timeval(__u64 todval, struct timespec64 *xt)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
unsigned long long sec;
|
|
|
|
|
|
|
|
sec = todval >> 12;
|
|
|
|
do_div(sec, 1000000);
|
2010-03-08 04:25:19 -07:00
|
|
|
xt->tv_sec = sec;
|
2005-04-16 16:20:36 -06:00
|
|
|
todval -= (sec * 1000000) << 12;
|
2010-03-08 04:25:19 -07:00
|
|
|
xt->tv_nsec = ((todval * 1000) >> 12);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2009-08-18 07:43:31 -06:00
|
|
|
EXPORT_SYMBOL(tod_to_timeval);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-04-16 23:46:25 -06:00
|
|
|
void clock_comparator_work(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-04-16 23:46:25 -06:00
|
|
|
struct clock_event_device *cd;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-04-16 23:46:25 -06:00
|
|
|
S390_lowcore.clock_comparator = -1ULL;
|
s390: Replace __get_cpu_var uses
__get_cpu_var() is used for multiple purposes in the kernel source. One of
them is address calculation via the form &__get_cpu_var(x). This calculates
the address for the instance of the percpu variable of the current processor
based on an offset.
Other use cases are for storing and retrieving data from the current
processors percpu area. __get_cpu_var() can be used as an lvalue when
writing data or on the right side of an assignment.
__get_cpu_var() is defined as :
#define __get_cpu_var(var) (*this_cpu_ptr(&(var)))
__get_cpu_var() always only does an address determination. However, store
and retrieve operations could use a segment prefix (or global register on
other platforms) to avoid the address calculation.
this_cpu_write() and this_cpu_read() can directly take an offset into a
percpu area and use optimized assembly code to read and write per cpu
variables.
This patch converts __get_cpu_var into either an explicit address
calculation using this_cpu_ptr() or into a use of this_cpu operations that
use the offset. Thereby address calculations are avoided and less registers
are used when code is generated.
At the end of the patch set all uses of __get_cpu_var have been removed so
the macro is removed too.
The patch set includes passes over all arches as well. Once these operations
are used throughout then specialized macros can be defined in non -x86
arches as well in order to optimize per cpu access by f.e. using a global
register that may be set to the per cpu base.
Transformations done to __get_cpu_var()
1. Determine the address of the percpu instance of the current processor.
DEFINE_PER_CPU(int, y);
int *x = &__get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(&y);
2. Same as #1 but this time an array structure is involved.
DEFINE_PER_CPU(int, y[20]);
int *x = __get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(y);
3. Retrieve the content of the current processors instance of a per cpu
variable.
DEFINE_PER_CPU(int, y);
int x = __get_cpu_var(y)
Converts to
int x = __this_cpu_read(y);
4. Retrieve the content of a percpu struct
DEFINE_PER_CPU(struct mystruct, y);
struct mystruct x = __get_cpu_var(y);
Converts to
memcpy(&x, this_cpu_ptr(&y), sizeof(x));
5. Assignment to a per cpu variable
DEFINE_PER_CPU(int, y)
__get_cpu_var(y) = x;
Converts to
this_cpu_write(y, x);
6. Increment/Decrement etc of a per cpu variable
DEFINE_PER_CPU(int, y);
__get_cpu_var(y)++
Converts to
this_cpu_inc(y)
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
CC: linux390@de.ibm.com
Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
2014-08-17 11:30:45 -06:00
|
|
|
cd = this_cpu_ptr(&comparators);
|
2008-04-16 23:46:25 -06:00
|
|
|
cd->event_handler(cd);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-04-16 23:46:25 -06:00
|
|
|
* Fixup the clock comparator.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2008-04-16 23:46:25 -06:00
|
|
|
static void fixup_clock_comparator(unsigned long long delta)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-04-16 23:46:25 -06:00
|
|
|
/* If nobody is waiting there's nothing to fix. */
|
|
|
|
if (S390_lowcore.clock_comparator == -1ULL)
|
2005-04-16 16:20:36 -06:00
|
|
|
return;
|
2008-04-16 23:46:25 -06:00
|
|
|
S390_lowcore.clock_comparator += delta;
|
|
|
|
set_clock_comparator(S390_lowcore.clock_comparator);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2013-11-22 04:04:18 -07:00
|
|
|
static int s390_next_event(unsigned long delta,
|
2008-04-16 23:46:25 -06:00
|
|
|
struct clock_event_device *evt)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2013-11-22 04:04:18 -07:00
|
|
|
S390_lowcore.clock_comparator = get_tod_clock() + delta;
|
2008-04-16 23:46:25 -06:00
|
|
|
set_clock_comparator(S390_lowcore.clock_comparator);
|
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-02-05 13:18:19 -07:00
|
|
|
/*
|
|
|
|
* Set up lowcore and control register of the current cpu to
|
|
|
|
* enable TOD clock and clock comparator interrupts.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
void init_cpu_timer(void)
|
|
|
|
{
|
2008-04-16 23:46:25 -06:00
|
|
|
struct clock_event_device *cd;
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
S390_lowcore.clock_comparator = -1ULL;
|
|
|
|
set_clock_comparator(S390_lowcore.clock_comparator);
|
|
|
|
|
|
|
|
cpu = smp_processor_id();
|
|
|
|
cd = &per_cpu(comparators, cpu);
|
|
|
|
cd->name = "comparator";
|
2013-11-22 04:04:18 -07:00
|
|
|
cd->features = CLOCK_EVT_FEAT_ONESHOT;
|
2008-04-16 23:46:25 -06:00
|
|
|
cd->mult = 16777;
|
|
|
|
cd->shift = 12;
|
|
|
|
cd->min_delta_ns = 1;
|
|
|
|
cd->max_delta_ns = LONG_MAX;
|
|
|
|
cd->rating = 400;
|
2008-12-13 03:50:26 -07:00
|
|
|
cd->cpumask = cpumask_of(cpu);
|
2013-11-22 04:04:18 -07:00
|
|
|
cd->set_next_event = s390_next_event;
|
2008-04-16 23:46:25 -06:00
|
|
|
|
|
|
|
clockevents_register_device(cd);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
|
|
|
/* Enable clock comparator timer interrupt. */
|
|
|
|
__ctl_set_bit(0,11);
|
|
|
|
|
2008-07-14 01:58:56 -06:00
|
|
|
/* Always allow the timing alert external interrupt. */
|
2007-02-05 13:18:19 -07:00
|
|
|
__ctl_set_bit(0, 4);
|
|
|
|
}
|
|
|
|
|
2012-03-11 09:59:31 -06:00
|
|
|
static void clock_comparator_interrupt(struct ext_code ext_code,
|
2010-10-25 08:10:38 -06:00
|
|
|
unsigned int param32,
|
|
|
|
unsigned long param64)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
2013-01-02 07:18:18 -07:00
|
|
|
inc_irq_stat(IRQEXT_CLK);
|
2008-10-03 13:54:59 -06:00
|
|
|
if (S390_lowcore.clock_comparator == -1ULL)
|
|
|
|
set_clock_comparator(S390_lowcore.clock_comparator);
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
|
2008-07-14 01:58:56 -06:00
|
|
|
static void etr_timing_alert(struct etr_irq_parm *);
|
|
|
|
static void stp_timing_alert(struct stp_irq_parm *);
|
|
|
|
|
2012-03-11 09:59:31 -06:00
|
|
|
static void timing_alert_interrupt(struct ext_code ext_code,
|
2010-10-25 08:10:38 -06:00
|
|
|
unsigned int param32, unsigned long param64)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
2013-01-02 07:18:18 -07:00
|
|
|
inc_irq_stat(IRQEXT_TLA);
|
2010-10-25 08:10:38 -06:00
|
|
|
if (param32 & 0x00c40000)
|
|
|
|
etr_timing_alert((struct etr_irq_parm *) ¶m32);
|
|
|
|
if (param32 & 0x00038000)
|
|
|
|
stp_timing_alert((struct stp_irq_parm *) ¶m32);
|
2008-07-14 01:58:56 -06:00
|
|
|
}
|
|
|
|
|
2007-02-05 13:18:19 -07:00
|
|
|
static void etr_reset(void);
|
2008-07-14 01:58:56 -06:00
|
|
|
static void stp_reset(void);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
2015-04-08 19:04:41 -06:00
|
|
|
void read_persistent_clock64(struct timespec64 *ts)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
2016-05-31 04:47:03 -06:00
|
|
|
__u64 clock;
|
|
|
|
|
|
|
|
clock = get_tod_clock() - initial_leap_seconds;
|
|
|
|
tod_to_timeval(clock - TOD_UNIX_EPOCH, ts);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2007-02-05 13:18:19 -07:00
|
|
|
|
2015-04-08 19:04:41 -06:00
|
|
|
void read_boot_clock64(struct timespec64 *ts)
|
2009-08-14 07:47:32 -06:00
|
|
|
{
|
2016-05-31 04:47:03 -06:00
|
|
|
__u64 clock;
|
|
|
|
|
|
|
|
clock = sched_clock_base_cc - initial_leap_seconds;
|
|
|
|
tod_to_timeval(clock - TOD_UNIX_EPOCH, ts);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2009-04-21 13:24:00 -06:00
|
|
|
static cycle_t read_tod_clock(struct clocksource *cs)
|
2006-10-06 08:38:48 -06:00
|
|
|
{
|
2013-01-30 01:49:40 -07:00
|
|
|
return get_tod_clock();
|
2006-10-06 08:38:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct clocksource clocksource_tod = {
|
|
|
|
.name = "tod",
|
2007-11-05 03:10:14 -07:00
|
|
|
.rating = 400,
|
2006-10-06 08:38:48 -06:00
|
|
|
.read = read_tod_clock,
|
|
|
|
.mask = -1ULL,
|
|
|
|
.mult = 1000,
|
|
|
|
.shift = 12,
|
2007-02-16 02:27:39 -07:00
|
|
|
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
|
2006-10-06 08:38:48 -06:00
|
|
|
};
|
|
|
|
|
2009-08-14 07:47:21 -06:00
|
|
|
struct clocksource * __init clocksource_default_clock(void)
|
|
|
|
{
|
|
|
|
return &clocksource_tod;
|
|
|
|
}
|
2006-10-06 08:38:48 -06:00
|
|
|
|
2013-11-22 02:04:53 -07:00
|
|
|
void update_vsyscall(struct timekeeper *tk)
|
2008-12-25 05:38:36 -07:00
|
|
|
{
|
2013-11-22 02:04:53 -07:00
|
|
|
u64 nsecps;
|
|
|
|
|
2015-03-19 03:09:06 -06:00
|
|
|
if (tk->tkr_mono.clock != &clocksource_tod)
|
2008-12-25 05:38:36 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Make userspace gettimeofday spin until we're done. */
|
|
|
|
++vdso_data->tb_update_count;
|
|
|
|
smp_wmb();
|
2015-03-19 03:09:06 -06:00
|
|
|
vdso_data->xtime_tod_stamp = tk->tkr_mono.cycle_last;
|
2013-11-22 02:04:53 -07:00
|
|
|
vdso_data->xtime_clock_sec = tk->xtime_sec;
|
2015-03-19 03:09:06 -06:00
|
|
|
vdso_data->xtime_clock_nsec = tk->tkr_mono.xtime_nsec;
|
2013-11-22 02:04:53 -07:00
|
|
|
vdso_data->wtom_clock_sec =
|
|
|
|
tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
|
2015-03-19 03:09:06 -06:00
|
|
|
vdso_data->wtom_clock_nsec = tk->tkr_mono.xtime_nsec +
|
|
|
|
+ ((u64) tk->wall_to_monotonic.tv_nsec << tk->tkr_mono.shift);
|
|
|
|
nsecps = (u64) NSEC_PER_SEC << tk->tkr_mono.shift;
|
2013-11-22 02:04:53 -07:00
|
|
|
while (vdso_data->wtom_clock_nsec >= nsecps) {
|
|
|
|
vdso_data->wtom_clock_nsec -= nsecps;
|
|
|
|
vdso_data->wtom_clock_sec++;
|
|
|
|
}
|
2014-08-29 04:31:45 -06:00
|
|
|
|
|
|
|
vdso_data->xtime_coarse_sec = tk->xtime_sec;
|
|
|
|
vdso_data->xtime_coarse_nsec =
|
2015-03-19 03:09:06 -06:00
|
|
|
(long)(tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift);
|
2014-08-29 04:31:45 -06:00
|
|
|
vdso_data->wtom_coarse_sec =
|
|
|
|
vdso_data->xtime_coarse_sec + tk->wall_to_monotonic.tv_sec;
|
|
|
|
vdso_data->wtom_coarse_nsec =
|
|
|
|
vdso_data->xtime_coarse_nsec + tk->wall_to_monotonic.tv_nsec;
|
|
|
|
while (vdso_data->wtom_coarse_nsec >= NSEC_PER_SEC) {
|
|
|
|
vdso_data->wtom_coarse_nsec -= NSEC_PER_SEC;
|
|
|
|
vdso_data->wtom_coarse_sec++;
|
|
|
|
}
|
|
|
|
|
2015-03-19 03:09:06 -06:00
|
|
|
vdso_data->tk_mult = tk->tkr_mono.mult;
|
|
|
|
vdso_data->tk_shift = tk->tkr_mono.shift;
|
2008-12-25 05:38:36 -07:00
|
|
|
smp_wmb();
|
|
|
|
++vdso_data->tb_update_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern struct timezone sys_tz;
|
|
|
|
|
|
|
|
void update_vsyscall_tz(void)
|
|
|
|
{
|
|
|
|
/* Make userspace gettimeofday spin until we're done. */
|
|
|
|
++vdso_data->tb_update_count;
|
|
|
|
smp_wmb();
|
|
|
|
vdso_data->tz_minuteswest = sys_tz.tz_minuteswest;
|
|
|
|
vdso_data->tz_dsttime = sys_tz.tz_dsttime;
|
|
|
|
smp_wmb();
|
|
|
|
++vdso_data->tb_update_count;
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Initialize the TOD clock and the CPU timer of
|
|
|
|
* the boot cpu.
|
|
|
|
*/
|
|
|
|
void __init time_init(void)
|
|
|
|
{
|
2009-04-14 07:36:28 -06:00
|
|
|
/* Reset time synchronization interfaces. */
|
|
|
|
etr_reset();
|
|
|
|
stp_reset();
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* request the clock comparator external interrupt */
|
2014-03-31 07:24:08 -06:00
|
|
|
if (register_external_irq(EXT_IRQ_CLK_COMP, clock_comparator_interrupt))
|
|
|
|
panic("Couldn't request external interrupt 0x1004");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-07-14 01:58:56 -06:00
|
|
|
/* request the timing alert external interrupt */
|
2014-03-31 07:24:08 -06:00
|
|
|
if (register_external_irq(EXT_IRQ_TIMING_ALERT, timing_alert_interrupt))
|
2007-02-05 13:18:19 -07:00
|
|
|
panic("Couldn't request external interrupt 0x1406");
|
|
|
|
|
2015-03-11 22:16:37 -06:00
|
|
|
if (__clocksource_register(&clocksource_tod) != 0)
|
2009-04-14 07:36:29 -06:00
|
|
|
panic("Could not register TOD clock source");
|
|
|
|
|
2007-02-05 13:18:19 -07:00
|
|
|
/* Enable TOD clock interrupts on the boot cpu. */
|
|
|
|
init_cpu_timer();
|
2009-04-14 07:36:29 -06:00
|
|
|
|
2008-12-25 05:39:25 -07:00
|
|
|
/* Enable cpu timer interrupts on the boot cpu. */
|
2005-04-16 16:20:36 -06:00
|
|
|
vtime_init();
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
|
2008-07-14 01:58:56 -06:00
|
|
|
/*
|
|
|
|
* The time is "clock". old is what we think the time is.
|
|
|
|
* Adjust the value by a multiple of jiffies and add the delta to ntp.
|
|
|
|
* "delay" is an approximation how long the synchronization took. If
|
|
|
|
* the time correction is positive, then "delay" is subtracted from
|
|
|
|
* the time difference and only the remaining part is passed to ntp.
|
|
|
|
*/
|
|
|
|
static unsigned long long adjust_time(unsigned long long old,
|
|
|
|
unsigned long long clock,
|
|
|
|
unsigned long long delay)
|
|
|
|
{
|
|
|
|
unsigned long long delta, ticks;
|
|
|
|
struct timex adjust;
|
|
|
|
|
|
|
|
if (clock > old) {
|
|
|
|
/* It is later than we thought. */
|
|
|
|
delta = ticks = clock - old;
|
|
|
|
delta = ticks = (delta < delay) ? 0 : delta - delay;
|
|
|
|
delta -= do_div(ticks, CLK_TICKS_PER_JIFFY);
|
|
|
|
adjust.offset = ticks * (1000000 / HZ);
|
|
|
|
} else {
|
|
|
|
/* It is earlier than we thought. */
|
|
|
|
delta = ticks = old - clock;
|
|
|
|
delta -= do_div(ticks, CLK_TICKS_PER_JIFFY);
|
|
|
|
delta = -delta;
|
|
|
|
adjust.offset = -ticks * (1000000 / HZ);
|
|
|
|
}
|
2008-11-27 03:05:56 -07:00
|
|
|
sched_clock_base_cc += delta;
|
2008-07-14 01:58:56 -06:00
|
|
|
if (adjust.offset != 0) {
|
2008-12-25 05:39:38 -07:00
|
|
|
pr_notice("The ETR interface has adjusted the clock "
|
|
|
|
"by %li microseconds\n", adjust.offset);
|
2008-07-14 01:58:56 -06:00
|
|
|
adjust.modes = ADJ_OFFSET_SINGLESHOT;
|
|
|
|
do_adjtimex(&adjust);
|
|
|
|
}
|
|
|
|
return delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEFINE_PER_CPU(atomic_t, clock_sync_word);
|
2009-03-26 08:24:21 -06:00
|
|
|
static DEFINE_MUTEX(clock_sync_mutex);
|
2008-07-14 01:58:56 -06:00
|
|
|
static unsigned long clock_sync_flags;
|
|
|
|
|
|
|
|
#define CLOCK_SYNC_HAS_ETR 0
|
|
|
|
#define CLOCK_SYNC_HAS_STP 1
|
|
|
|
#define CLOCK_SYNC_ETR 2
|
|
|
|
#define CLOCK_SYNC_STP 3
|
|
|
|
|
|
|
|
/*
|
2016-05-31 02:16:24 -06:00
|
|
|
* The get_clock function for the physical clock. It will get the current
|
|
|
|
* TOD clock, subtract the LPAR offset and write the result to *clock.
|
|
|
|
* The function returns 0 if the clock is in sync with the external time
|
|
|
|
* source. If the clock mode is local it will return -EOPNOTSUPP and
|
|
|
|
* -EAGAIN if the clock is not in sync with the external reference.
|
2008-07-14 01:58:56 -06:00
|
|
|
*/
|
2016-05-31 02:16:24 -06:00
|
|
|
int get_phys_clock(unsigned long long *clock)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
|
|
|
atomic_t *sw_ptr;
|
|
|
|
unsigned int sw0, sw1;
|
|
|
|
|
|
|
|
sw_ptr = &get_cpu_var(clock_sync_word);
|
|
|
|
sw0 = atomic_read(sw_ptr);
|
2016-05-31 02:16:24 -06:00
|
|
|
*clock = get_tod_clock() - lpar_offset;
|
2008-07-14 01:58:56 -06:00
|
|
|
sw1 = atomic_read(sw_ptr);
|
2009-12-07 04:52:14 -07:00
|
|
|
put_cpu_var(clock_sync_word);
|
2008-07-14 01:58:56 -06:00
|
|
|
if (sw0 == sw1 && (sw0 & 0x80000000U))
|
|
|
|
/* Success: time is in sync. */
|
|
|
|
return 0;
|
|
|
|
if (!test_bit(CLOCK_SYNC_HAS_ETR, &clock_sync_flags) &&
|
|
|
|
!test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags))
|
2012-09-06 07:13:34 -06:00
|
|
|
return -EOPNOTSUPP;
|
2008-07-14 01:58:56 -06:00
|
|
|
if (!test_bit(CLOCK_SYNC_ETR, &clock_sync_flags) &&
|
|
|
|
!test_bit(CLOCK_SYNC_STP, &clock_sync_flags))
|
|
|
|
return -EACCES;
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
2016-05-31 02:16:24 -06:00
|
|
|
EXPORT_SYMBOL(get_phys_clock);
|
2008-07-14 01:58:56 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make get_sync_clock return -EAGAIN.
|
|
|
|
*/
|
|
|
|
static void disable_sync_clock(void *dummy)
|
|
|
|
{
|
s390: Replace __get_cpu_var uses
__get_cpu_var() is used for multiple purposes in the kernel source. One of
them is address calculation via the form &__get_cpu_var(x). This calculates
the address for the instance of the percpu variable of the current processor
based on an offset.
Other use cases are for storing and retrieving data from the current
processors percpu area. __get_cpu_var() can be used as an lvalue when
writing data or on the right side of an assignment.
__get_cpu_var() is defined as :
#define __get_cpu_var(var) (*this_cpu_ptr(&(var)))
__get_cpu_var() always only does an address determination. However, store
and retrieve operations could use a segment prefix (or global register on
other platforms) to avoid the address calculation.
this_cpu_write() and this_cpu_read() can directly take an offset into a
percpu area and use optimized assembly code to read and write per cpu
variables.
This patch converts __get_cpu_var into either an explicit address
calculation using this_cpu_ptr() or into a use of this_cpu operations that
use the offset. Thereby address calculations are avoided and less registers
are used when code is generated.
At the end of the patch set all uses of __get_cpu_var have been removed so
the macro is removed too.
The patch set includes passes over all arches as well. Once these operations
are used throughout then specialized macros can be defined in non -x86
arches as well in order to optimize per cpu access by f.e. using a global
register that may be set to the per cpu base.
Transformations done to __get_cpu_var()
1. Determine the address of the percpu instance of the current processor.
DEFINE_PER_CPU(int, y);
int *x = &__get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(&y);
2. Same as #1 but this time an array structure is involved.
DEFINE_PER_CPU(int, y[20]);
int *x = __get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(y);
3. Retrieve the content of the current processors instance of a per cpu
variable.
DEFINE_PER_CPU(int, y);
int x = __get_cpu_var(y)
Converts to
int x = __this_cpu_read(y);
4. Retrieve the content of a percpu struct
DEFINE_PER_CPU(struct mystruct, y);
struct mystruct x = __get_cpu_var(y);
Converts to
memcpy(&x, this_cpu_ptr(&y), sizeof(x));
5. Assignment to a per cpu variable
DEFINE_PER_CPU(int, y)
__get_cpu_var(y) = x;
Converts to
this_cpu_write(y, x);
6. Increment/Decrement etc of a per cpu variable
DEFINE_PER_CPU(int, y);
__get_cpu_var(y)++
Converts to
this_cpu_inc(y)
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
CC: linux390@de.ibm.com
Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
2014-08-17 11:30:45 -06:00
|
|
|
atomic_t *sw_ptr = this_cpu_ptr(&clock_sync_word);
|
2008-07-14 01:58:56 -06:00
|
|
|
/*
|
|
|
|
* Clear the in-sync bit 2^31. All get_sync_clock calls will
|
|
|
|
* fail until the sync bit is turned back on. In addition
|
|
|
|
* increase the "sequence" counter to avoid the race of an
|
|
|
|
* etr event and the complete recovery against get_sync_clock.
|
|
|
|
*/
|
2015-04-23 17:12:32 -06:00
|
|
|
atomic_andnot(0x80000000, sw_ptr);
|
2008-07-14 01:58:56 -06:00
|
|
|
atomic_inc(sw_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make get_sync_clock return 0 again.
|
|
|
|
* Needs to be called from a context disabled for preemption.
|
|
|
|
*/
|
|
|
|
static void enable_sync_clock(void)
|
|
|
|
{
|
s390: Replace __get_cpu_var uses
__get_cpu_var() is used for multiple purposes in the kernel source. One of
them is address calculation via the form &__get_cpu_var(x). This calculates
the address for the instance of the percpu variable of the current processor
based on an offset.
Other use cases are for storing and retrieving data from the current
processors percpu area. __get_cpu_var() can be used as an lvalue when
writing data or on the right side of an assignment.
__get_cpu_var() is defined as :
#define __get_cpu_var(var) (*this_cpu_ptr(&(var)))
__get_cpu_var() always only does an address determination. However, store
and retrieve operations could use a segment prefix (or global register on
other platforms) to avoid the address calculation.
this_cpu_write() and this_cpu_read() can directly take an offset into a
percpu area and use optimized assembly code to read and write per cpu
variables.
This patch converts __get_cpu_var into either an explicit address
calculation using this_cpu_ptr() or into a use of this_cpu operations that
use the offset. Thereby address calculations are avoided and less registers
are used when code is generated.
At the end of the patch set all uses of __get_cpu_var have been removed so
the macro is removed too.
The patch set includes passes over all arches as well. Once these operations
are used throughout then specialized macros can be defined in non -x86
arches as well in order to optimize per cpu access by f.e. using a global
register that may be set to the per cpu base.
Transformations done to __get_cpu_var()
1. Determine the address of the percpu instance of the current processor.
DEFINE_PER_CPU(int, y);
int *x = &__get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(&y);
2. Same as #1 but this time an array structure is involved.
DEFINE_PER_CPU(int, y[20]);
int *x = __get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(y);
3. Retrieve the content of the current processors instance of a per cpu
variable.
DEFINE_PER_CPU(int, y);
int x = __get_cpu_var(y)
Converts to
int x = __this_cpu_read(y);
4. Retrieve the content of a percpu struct
DEFINE_PER_CPU(struct mystruct, y);
struct mystruct x = __get_cpu_var(y);
Converts to
memcpy(&x, this_cpu_ptr(&y), sizeof(x));
5. Assignment to a per cpu variable
DEFINE_PER_CPU(int, y)
__get_cpu_var(y) = x;
Converts to
this_cpu_write(y, x);
6. Increment/Decrement etc of a per cpu variable
DEFINE_PER_CPU(int, y);
__get_cpu_var(y)++
Converts to
this_cpu_inc(y)
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
CC: linux390@de.ibm.com
Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
2014-08-17 11:30:45 -06:00
|
|
|
atomic_t *sw_ptr = this_cpu_ptr(&clock_sync_word);
|
2015-04-23 17:12:32 -06:00
|
|
|
atomic_or(0x80000000, sw_ptr);
|
2008-07-14 01:58:56 -06:00
|
|
|
}
|
|
|
|
|
2009-03-26 08:24:21 -06:00
|
|
|
/*
|
|
|
|
* Function to check if the clock is in sync.
|
|
|
|
*/
|
|
|
|
static inline int check_sync_clock(void)
|
|
|
|
{
|
|
|
|
atomic_t *sw_ptr;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
sw_ptr = &get_cpu_var(clock_sync_word);
|
|
|
|
rc = (atomic_read(sw_ptr) & 0x80000000U) != 0;
|
2009-12-07 04:52:14 -07:00
|
|
|
put_cpu_var(clock_sync_word);
|
2009-03-26 08:24:21 -06:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-12-25 05:38:37 -07:00
|
|
|
/* Single threaded workqueue used for etr and stp sync events */
|
|
|
|
static struct workqueue_struct *time_sync_wq;
|
|
|
|
|
|
|
|
static void __init time_init_wq(void)
|
|
|
|
{
|
2009-01-23 08:40:26 -07:00
|
|
|
if (time_sync_wq)
|
|
|
|
return;
|
|
|
|
time_sync_wq = create_singlethread_workqueue("timesync");
|
2008-12-25 05:38:37 -07:00
|
|
|
}
|
|
|
|
|
2007-02-05 13:18:19 -07:00
|
|
|
/*
|
|
|
|
* External Time Reference (ETR) code.
|
|
|
|
*/
|
|
|
|
static int etr_port0_online;
|
|
|
|
static int etr_port1_online;
|
2008-07-14 01:58:56 -06:00
|
|
|
static int etr_steai_available;
|
2007-02-05 13:18:19 -07:00
|
|
|
|
|
|
|
static int __init early_parse_etr(char *p)
|
|
|
|
{
|
|
|
|
if (strncmp(p, "off", 3) == 0)
|
|
|
|
etr_port0_online = etr_port1_online = 0;
|
|
|
|
else if (strncmp(p, "port0", 5) == 0)
|
|
|
|
etr_port0_online = 1;
|
|
|
|
else if (strncmp(p, "port1", 5) == 0)
|
|
|
|
etr_port1_online = 1;
|
|
|
|
else if (strncmp(p, "on", 2) == 0)
|
|
|
|
etr_port0_online = etr_port1_online = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_param("etr", early_parse_etr);
|
|
|
|
|
|
|
|
enum etr_event {
|
|
|
|
ETR_EVENT_PORT0_CHANGE,
|
|
|
|
ETR_EVENT_PORT1_CHANGE,
|
|
|
|
ETR_EVENT_PORT_ALERT,
|
|
|
|
ETR_EVENT_SYNC_CHECK,
|
|
|
|
ETR_EVENT_SWITCH_LOCAL,
|
|
|
|
ETR_EVENT_UPDATE,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Valid bit combinations of the eacr register are (x = don't care):
|
|
|
|
* e0 e1 dp p0 p1 ea es sl
|
|
|
|
* 0 0 x 0 0 0 0 0 initial, disabled state
|
|
|
|
* 0 0 x 0 1 1 0 0 port 1 online
|
|
|
|
* 0 0 x 1 0 1 0 0 port 0 online
|
|
|
|
* 0 0 x 1 1 1 0 0 both ports online
|
|
|
|
* 0 1 x 0 1 1 0 0 port 1 online and usable, ETR or PPS mode
|
|
|
|
* 0 1 x 0 1 1 0 1 port 1 online, usable and ETR mode
|
|
|
|
* 0 1 x 0 1 1 1 0 port 1 online, usable, PPS mode, in-sync
|
|
|
|
* 0 1 x 0 1 1 1 1 port 1 online, usable, ETR mode, in-sync
|
|
|
|
* 0 1 x 1 1 1 0 0 both ports online, port 1 usable
|
|
|
|
* 0 1 x 1 1 1 1 0 both ports online, port 1 usable, PPS mode, in-sync
|
|
|
|
* 0 1 x 1 1 1 1 1 both ports online, port 1 usable, ETR mode, in-sync
|
|
|
|
* 1 0 x 1 0 1 0 0 port 0 online and usable, ETR or PPS mode
|
|
|
|
* 1 0 x 1 0 1 0 1 port 0 online, usable and ETR mode
|
|
|
|
* 1 0 x 1 0 1 1 0 port 0 online, usable, PPS mode, in-sync
|
|
|
|
* 1 0 x 1 0 1 1 1 port 0 online, usable, ETR mode, in-sync
|
|
|
|
* 1 0 x 1 1 1 0 0 both ports online, port 0 usable
|
|
|
|
* 1 0 x 1 1 1 1 0 both ports online, port 0 usable, PPS mode, in-sync
|
|
|
|
* 1 0 x 1 1 1 1 1 both ports online, port 0 usable, ETR mode, in-sync
|
|
|
|
* 1 1 x 1 1 1 1 0 both ports online & usable, ETR, in-sync
|
|
|
|
* 1 1 x 1 1 1 1 1 both ports online & usable, ETR, in-sync
|
|
|
|
*/
|
|
|
|
static struct etr_eacr etr_eacr;
|
|
|
|
static u64 etr_tolec; /* time of last eacr update */
|
|
|
|
static struct etr_aib etr_port0;
|
|
|
|
static int etr_port0_uptodate;
|
|
|
|
static struct etr_aib etr_port1;
|
|
|
|
static int etr_port1_uptodate;
|
|
|
|
static unsigned long etr_events;
|
|
|
|
static struct timer_list etr_timer;
|
|
|
|
|
|
|
|
static void etr_timeout(unsigned long dummy);
|
2007-04-27 08:01:58 -06:00
|
|
|
static void etr_work_fn(struct work_struct *work);
|
2008-12-25 05:38:38 -07:00
|
|
|
static DEFINE_MUTEX(etr_work_mutex);
|
2007-04-27 08:01:58 -06:00
|
|
|
static DECLARE_WORK(etr_work, etr_work_fn);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset ETR attachment.
|
|
|
|
*/
|
|
|
|
static void etr_reset(void)
|
|
|
|
{
|
|
|
|
etr_eacr = (struct etr_eacr) {
|
|
|
|
.e0 = 0, .e1 = 0, ._pad0 = 4, .dp = 0,
|
|
|
|
.p0 = 0, .p1 = 0, ._pad1 = 0, .ea = 0,
|
|
|
|
.es = 0, .sl = 0 };
|
2008-07-14 01:58:56 -06:00
|
|
|
if (etr_setr(&etr_eacr) == 0) {
|
2013-01-30 01:49:40 -07:00
|
|
|
etr_tolec = get_tod_clock();
|
2008-07-14 01:58:56 -06:00
|
|
|
set_bit(CLOCK_SYNC_HAS_ETR, &clock_sync_flags);
|
2009-03-26 08:24:21 -06:00
|
|
|
if (etr_port0_online && etr_port1_online)
|
|
|
|
set_bit(CLOCK_SYNC_ETR, &clock_sync_flags);
|
2008-07-14 01:58:56 -06:00
|
|
|
} else if (etr_port0_online || etr_port1_online) {
|
2016-03-03 21:49:57 -07:00
|
|
|
pr_warn("The real or virtual hardware system does not provide an ETR interface\n");
|
2008-07-14 01:58:56 -06:00
|
|
|
etr_port0_online = etr_port1_online = 0;
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-27 08:01:58 -06:00
|
|
|
static int __init etr_init(void)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
struct etr_aib aib;
|
|
|
|
|
2008-07-14 01:58:56 -06:00
|
|
|
if (!test_bit(CLOCK_SYNC_HAS_ETR, &clock_sync_flags))
|
2007-04-27 08:01:58 -06:00
|
|
|
return 0;
|
2008-12-25 05:38:37 -07:00
|
|
|
time_init_wq();
|
2007-02-05 13:18:19 -07:00
|
|
|
/* Check if this machine has the steai instruction. */
|
|
|
|
if (etr_steai(&aib, ETR_STEAI_STEPPING_PORT) == 0)
|
2008-07-14 01:58:56 -06:00
|
|
|
etr_steai_available = 1;
|
2007-02-05 13:18:19 -07:00
|
|
|
setup_timer(&etr_timer, etr_timeout, 0UL);
|
|
|
|
if (etr_port0_online) {
|
|
|
|
set_bit(ETR_EVENT_PORT0_CHANGE, &etr_events);
|
2008-12-25 05:38:37 -07:00
|
|
|
queue_work(time_sync_wq, &etr_work);
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
if (etr_port1_online) {
|
|
|
|
set_bit(ETR_EVENT_PORT1_CHANGE, &etr_events);
|
2008-12-25 05:38:37 -07:00
|
|
|
queue_work(time_sync_wq, &etr_work);
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
2007-04-27 08:01:58 -06:00
|
|
|
return 0;
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
|
2007-04-27 08:01:58 -06:00
|
|
|
arch_initcall(etr_init);
|
|
|
|
|
2007-02-05 13:18:19 -07:00
|
|
|
/*
|
|
|
|
* Two sorts of ETR machine checks. The architecture reads:
|
|
|
|
* "When a machine-check niterruption occurs and if a switch-to-local or
|
|
|
|
* ETR-sync-check interrupt request is pending but disabled, this pending
|
|
|
|
* disabled interruption request is indicated and is cleared".
|
|
|
|
* Which means that we can get etr_switch_to_local events from the machine
|
|
|
|
* check handler although the interruption condition is disabled. Lovely..
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch to local machine check. This is called when the last usable
|
|
|
|
* ETR port goes inactive. After switch to local the clock is not in sync.
|
|
|
|
*/
|
2015-10-09 05:48:03 -06:00
|
|
|
int etr_switch_to_local(void)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
if (!etr_eacr.sl)
|
2015-10-09 05:48:03 -06:00
|
|
|
return 0;
|
2009-03-26 08:24:21 -06:00
|
|
|
disable_sync_clock(NULL);
|
2010-07-27 11:29:38 -06:00
|
|
|
if (!test_and_set_bit(ETR_EVENT_SWITCH_LOCAL, &etr_events)) {
|
|
|
|
etr_eacr.es = etr_eacr.sl = 0;
|
|
|
|
etr_setr(&etr_eacr);
|
2015-10-09 05:48:03 -06:00
|
|
|
return 1;
|
2010-07-27 11:29:38 -06:00
|
|
|
}
|
2015-10-09 05:48:03 -06:00
|
|
|
return 0;
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ETR sync check machine check. This is called when the ETR OTE and the
|
|
|
|
* local clock OTE are farther apart than the ETR sync check tolerance.
|
|
|
|
* After a ETR sync check the clock is not in sync. The machine check
|
|
|
|
* is broadcasted to all cpus at the same time.
|
|
|
|
*/
|
2015-10-09 05:48:03 -06:00
|
|
|
int etr_sync_check(void)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
if (!etr_eacr.es)
|
2015-10-09 05:48:03 -06:00
|
|
|
return 0;
|
2009-03-26 08:24:21 -06:00
|
|
|
disable_sync_clock(NULL);
|
2010-07-27 11:29:38 -06:00
|
|
|
if (!test_and_set_bit(ETR_EVENT_SYNC_CHECK, &etr_events)) {
|
|
|
|
etr_eacr.es = 0;
|
|
|
|
etr_setr(&etr_eacr);
|
2015-10-09 05:48:03 -06:00
|
|
|
return 1;
|
2010-07-27 11:29:38 -06:00
|
|
|
}
|
2015-10-09 05:48:03 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void etr_queue_work(void)
|
|
|
|
{
|
|
|
|
queue_work(time_sync_wq, &etr_work);
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-07-14 01:58:56 -06:00
|
|
|
* ETR timing alert. There are two causes:
|
2007-02-05 13:18:19 -07:00
|
|
|
* 1) port state change, check the usability of the port
|
|
|
|
* 2) port alert, one of the ETR-data-validity bits (v1-v2 bits of the
|
|
|
|
* sldr-status word) or ETR-data word 1 (edf1) or ETR-data word 3 (edf3)
|
|
|
|
* or ETR-data word 4 (edf4) has changed.
|
|
|
|
*/
|
2008-07-14 01:58:56 -06:00
|
|
|
static void etr_timing_alert(struct etr_irq_parm *intparm)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
if (intparm->pc0)
|
|
|
|
/* ETR port 0 state change. */
|
|
|
|
set_bit(ETR_EVENT_PORT0_CHANGE, &etr_events);
|
|
|
|
if (intparm->pc1)
|
|
|
|
/* ETR port 1 state change. */
|
|
|
|
set_bit(ETR_EVENT_PORT1_CHANGE, &etr_events);
|
|
|
|
if (intparm->eai)
|
|
|
|
/*
|
|
|
|
* ETR port alert on either port 0, 1 or both.
|
|
|
|
* Both ports are not up-to-date now.
|
|
|
|
*/
|
|
|
|
set_bit(ETR_EVENT_PORT_ALERT, &etr_events);
|
2008-12-25 05:38:37 -07:00
|
|
|
queue_work(time_sync_wq, &etr_work);
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void etr_timeout(unsigned long dummy)
|
|
|
|
{
|
|
|
|
set_bit(ETR_EVENT_UPDATE, &etr_events);
|
2008-12-25 05:38:37 -07:00
|
|
|
queue_work(time_sync_wq, &etr_work);
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the etr mode is pss.
|
|
|
|
*/
|
|
|
|
static inline int etr_mode_is_pps(struct etr_eacr eacr)
|
|
|
|
{
|
|
|
|
return eacr.es && !eacr.sl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the etr mode is etr.
|
|
|
|
*/
|
|
|
|
static inline int etr_mode_is_etr(struct etr_eacr eacr)
|
|
|
|
{
|
|
|
|
return eacr.es && eacr.sl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the port can be used for TOD synchronization.
|
|
|
|
* For PPS mode the port has to receive OTEs. For ETR mode
|
|
|
|
* the port has to receive OTEs, the ETR stepping bit has to
|
|
|
|
* be zero and the validity bits for data frame 1, 2, and 3
|
|
|
|
* have to be 1.
|
|
|
|
*/
|
|
|
|
static int etr_port_valid(struct etr_aib *aib, int port)
|
|
|
|
{
|
|
|
|
unsigned int psc;
|
|
|
|
|
|
|
|
/* Check that this port is receiving OTEs. */
|
|
|
|
if (aib->tsp == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
psc = port ? aib->esw.psc1 : aib->esw.psc0;
|
|
|
|
if (psc == etr_lpsc_pps_mode)
|
|
|
|
return 1;
|
|
|
|
if (psc == etr_lpsc_operational_step)
|
|
|
|
return !aib->esw.y && aib->slsw.v1 &&
|
|
|
|
aib->slsw.v2 && aib->slsw.v3;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if two ports are on the same network.
|
|
|
|
*/
|
|
|
|
static int etr_compare_network(struct etr_aib *aib1, struct etr_aib *aib2)
|
|
|
|
{
|
|
|
|
// FIXME: any other fields we have to compare?
|
|
|
|
return aib1->edf1.net_id == aib2->edf1.net_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wrapper for etr_stei that converts physical port states
|
|
|
|
* to logical port states to be consistent with the output
|
|
|
|
* of stetr (see etr_psc vs. etr_lpsc).
|
|
|
|
*/
|
|
|
|
static void etr_steai_cv(struct etr_aib *aib, unsigned int func)
|
|
|
|
{
|
|
|
|
BUG_ON(etr_steai(aib, func) != 0);
|
|
|
|
/* Convert port state to logical port state. */
|
|
|
|
if (aib->esw.psc0 == 1)
|
|
|
|
aib->esw.psc0 = 2;
|
|
|
|
else if (aib->esw.psc0 == 0 && aib->esw.p == 0)
|
|
|
|
aib->esw.psc0 = 1;
|
|
|
|
if (aib->esw.psc1 == 1)
|
|
|
|
aib->esw.psc1 = 2;
|
|
|
|
else if (aib->esw.psc1 == 0 && aib->esw.p == 1)
|
|
|
|
aib->esw.psc1 = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the aib a2 is still connected to the same attachment as
|
|
|
|
* aib a1, the etv values differ by one and a2 is valid.
|
|
|
|
*/
|
|
|
|
static int etr_aib_follows(struct etr_aib *a1, struct etr_aib *a2, int p)
|
|
|
|
{
|
|
|
|
int state_a1, state_a2;
|
|
|
|
|
|
|
|
/* Paranoia check: e0/e1 should better be the same. */
|
|
|
|
if (a1->esw.eacr.e0 != a2->esw.eacr.e0 ||
|
|
|
|
a1->esw.eacr.e1 != a2->esw.eacr.e1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Still connected to the same etr ? */
|
|
|
|
state_a1 = p ? a1->esw.psc1 : a1->esw.psc0;
|
|
|
|
state_a2 = p ? a2->esw.psc1 : a2->esw.psc0;
|
|
|
|
if (state_a1 == etr_lpsc_operational_step) {
|
|
|
|
if (state_a2 != etr_lpsc_operational_step ||
|
|
|
|
a1->edf1.net_id != a2->edf1.net_id ||
|
|
|
|
a1->edf1.etr_id != a2->edf1.etr_id ||
|
|
|
|
a1->edf1.etr_pn != a2->edf1.etr_pn)
|
|
|
|
return 0;
|
|
|
|
} else if (state_a2 != etr_lpsc_pps_mode)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* The ETV value of a2 needs to be ETV of a1 + 1. */
|
|
|
|
if (a1->edf2.etv + 1 != a2->edf2.etv)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!etr_port_valid(a2, p))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-07-14 01:58:56 -06:00
|
|
|
struct clock_sync_data {
|
2008-12-25 05:38:37 -07:00
|
|
|
atomic_t cpus;
|
2008-04-16 23:46:25 -06:00
|
|
|
int in_sync;
|
|
|
|
unsigned long long fixup_cc;
|
2008-12-25 05:38:37 -07:00
|
|
|
int etr_port;
|
|
|
|
struct etr_aib *etr_aib;
|
2008-07-14 01:58:56 -06:00
|
|
|
};
|
2008-04-16 23:46:25 -06:00
|
|
|
|
2008-12-25 05:38:37 -07:00
|
|
|
static void clock_sync_cpu(struct clock_sync_data *sync)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
2008-12-25 05:38:37 -07:00
|
|
|
atomic_dec(&sync->cpus);
|
2008-07-14 01:58:56 -06:00
|
|
|
enable_sync_clock();
|
2007-02-05 13:18:19 -07:00
|
|
|
/*
|
|
|
|
* This looks like a busy wait loop but it isn't. etr_sync_cpus
|
|
|
|
* is called on all other cpus while the TOD clocks is stopped.
|
|
|
|
* __udelay will stop the cpu on an enabled wait psw until the
|
|
|
|
* TOD is running again.
|
|
|
|
*/
|
2008-07-14 01:58:56 -06:00
|
|
|
while (sync->in_sync == 0) {
|
2007-02-05 13:18:19 -07:00
|
|
|
__udelay(1);
|
2007-02-21 02:55:15 -07:00
|
|
|
/*
|
|
|
|
* A different cpu changes *in_sync. Therefore use
|
|
|
|
* barrier() to force memory access.
|
|
|
|
*/
|
|
|
|
barrier();
|
|
|
|
}
|
2008-07-14 01:58:56 -06:00
|
|
|
if (sync->in_sync != 1)
|
2007-02-05 13:18:19 -07:00
|
|
|
/* Didn't work. Clear per-cpu in sync bit again. */
|
2008-07-14 01:58:56 -06:00
|
|
|
disable_sync_clock(NULL);
|
2007-02-05 13:18:19 -07:00
|
|
|
/*
|
|
|
|
* This round of TOD syncing is done. Set the clock comparator
|
|
|
|
* to the next tick and let the processor continue.
|
|
|
|
*/
|
2008-07-14 01:58:56 -06:00
|
|
|
fixup_clock_comparator(sync->fixup_cc);
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-03-30 19:57:33 -06:00
|
|
|
* Sync the TOD clock using the port referred to by aibp. This port
|
2007-02-05 13:18:19 -07:00
|
|
|
* has to be enabled and the other port has to be disabled. The
|
|
|
|
* last eacr update has to be more than 1.6 seconds in the past.
|
|
|
|
*/
|
2008-12-25 05:38:37 -07:00
|
|
|
static int etr_sync_clock(void *data)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
2008-12-25 05:38:37 -07:00
|
|
|
static int first;
|
2015-05-13 02:58:41 -06:00
|
|
|
unsigned long long clock, old_clock, clock_delta, delay, delta;
|
2008-12-25 05:38:37 -07:00
|
|
|
struct clock_sync_data *etr_sync;
|
|
|
|
struct etr_aib *sync_port, *aib;
|
2016-05-31 02:16:24 -06:00
|
|
|
struct ptff_qto qto;
|
2008-12-25 05:38:37 -07:00
|
|
|
int port;
|
2007-02-05 13:18:19 -07:00
|
|
|
int rc;
|
|
|
|
|
2008-12-25 05:38:37 -07:00
|
|
|
etr_sync = data;
|
2007-02-05 13:18:19 -07:00
|
|
|
|
2008-12-25 05:38:37 -07:00
|
|
|
if (xchg(&first, 1) == 1) {
|
|
|
|
/* Slave */
|
|
|
|
clock_sync_cpu(etr_sync);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait until all other cpus entered the sync function. */
|
|
|
|
while (atomic_read(&etr_sync->cpus) != 0)
|
|
|
|
cpu_relax();
|
|
|
|
|
|
|
|
port = etr_sync->etr_port;
|
|
|
|
aib = etr_sync->etr_aib;
|
|
|
|
sync_port = (port == 0) ? &etr_port0 : &etr_port1;
|
2008-07-14 01:58:56 -06:00
|
|
|
enable_sync_clock();
|
2007-02-05 13:18:19 -07:00
|
|
|
|
|
|
|
/* Set clock to next OTE. */
|
|
|
|
__ctl_set_bit(14, 21);
|
|
|
|
__ctl_set_bit(0, 29);
|
|
|
|
clock = ((unsigned long long) (aib->edf2.etv + 1)) << 32;
|
2013-01-30 01:49:40 -07:00
|
|
|
old_clock = get_tod_clock();
|
|
|
|
if (set_tod_clock(clock) == 0) {
|
2007-02-05 13:18:19 -07:00
|
|
|
__udelay(1); /* Wait for the clock to start. */
|
|
|
|
__ctl_clear_bit(0, 29);
|
|
|
|
__ctl_clear_bit(14, 21);
|
|
|
|
etr_stetr(aib);
|
|
|
|
/* Adjust Linux timing variables. */
|
|
|
|
delay = (unsigned long long)
|
|
|
|
(aib->edf2.etv - sync_port->edf2.etv) << 32;
|
2008-07-14 01:58:56 -06:00
|
|
|
delta = adjust_time(old_clock, clock, delay);
|
2015-05-13 02:58:41 -06:00
|
|
|
clock_delta = clock - old_clock;
|
|
|
|
atomic_notifier_call_chain(&s390_epoch_delta_notifier, 0,
|
|
|
|
&clock_delta);
|
2008-12-25 05:38:37 -07:00
|
|
|
etr_sync->fixup_cc = delta;
|
2008-04-16 23:46:25 -06:00
|
|
|
fixup_clock_comparator(delta);
|
2007-02-05 13:18:19 -07:00
|
|
|
/* Verify that the clock is properly set. */
|
|
|
|
if (!etr_aib_follows(sync_port, aib, port)) {
|
|
|
|
/* Didn't work. */
|
2008-07-14 01:58:56 -06:00
|
|
|
disable_sync_clock(NULL);
|
2008-12-25 05:38:37 -07:00
|
|
|
etr_sync->in_sync = -EAGAIN;
|
2007-02-05 13:18:19 -07:00
|
|
|
rc = -EAGAIN;
|
|
|
|
} else {
|
2016-05-31 02:16:24 -06:00
|
|
|
if (ptff_query(PTFF_QTO) &&
|
|
|
|
ptff(&qto, sizeof(qto), PTFF_QTO) == 0)
|
|
|
|
/* Update LPAR offset */
|
|
|
|
lpar_offset = qto.tod_epoch_difference;
|
2008-12-25 05:38:37 -07:00
|
|
|
etr_sync->in_sync = 1;
|
2007-02-05 13:18:19 -07:00
|
|
|
rc = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Could not set the clock ?!? */
|
|
|
|
__ctl_clear_bit(0, 29);
|
|
|
|
__ctl_clear_bit(14, 21);
|
2008-07-14 01:58:56 -06:00
|
|
|
disable_sync_clock(NULL);
|
2008-12-25 05:38:37 -07:00
|
|
|
etr_sync->in_sync = -EAGAIN;
|
2007-02-05 13:18:19 -07:00
|
|
|
rc = -EAGAIN;
|
|
|
|
}
|
2008-12-25 05:38:37 -07:00
|
|
|
xchg(&first, 0);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int etr_sync_clock_stop(struct etr_aib *aib, int port)
|
|
|
|
{
|
|
|
|
struct clock_sync_data etr_sync;
|
|
|
|
struct etr_aib *sync_port;
|
|
|
|
int follows;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Check if the current aib is adjacent to the sync port aib. */
|
|
|
|
sync_port = (port == 0) ? &etr_port0 : &etr_port1;
|
|
|
|
follows = etr_aib_follows(sync_port, aib, port);
|
|
|
|
memcpy(sync_port, aib, sizeof(*aib));
|
|
|
|
if (!follows)
|
|
|
|
return -EAGAIN;
|
|
|
|
memset(&etr_sync, 0, sizeof(etr_sync));
|
|
|
|
etr_sync.etr_aib = aib;
|
|
|
|
etr_sync.etr_port = port;
|
|
|
|
get_online_cpus();
|
|
|
|
atomic_set(&etr_sync.cpus, num_online_cpus() - 1);
|
2011-05-23 02:24:36 -06:00
|
|
|
rc = stop_machine(etr_sync_clock, &etr_sync, cpu_online_mask);
|
2008-12-25 05:38:37 -07:00
|
|
|
put_online_cpus();
|
2007-02-05 13:18:19 -07:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle the immediate effects of the different events.
|
|
|
|
* The port change event is used for online/offline changes.
|
|
|
|
*/
|
|
|
|
static struct etr_eacr etr_handle_events(struct etr_eacr eacr)
|
|
|
|
{
|
|
|
|
if (test_and_clear_bit(ETR_EVENT_SYNC_CHECK, &etr_events))
|
|
|
|
eacr.es = 0;
|
|
|
|
if (test_and_clear_bit(ETR_EVENT_SWITCH_LOCAL, &etr_events))
|
|
|
|
eacr.es = eacr.sl = 0;
|
|
|
|
if (test_and_clear_bit(ETR_EVENT_PORT_ALERT, &etr_events))
|
|
|
|
etr_port0_uptodate = etr_port1_uptodate = 0;
|
|
|
|
|
|
|
|
if (test_and_clear_bit(ETR_EVENT_PORT0_CHANGE, &etr_events)) {
|
|
|
|
if (eacr.e0)
|
|
|
|
/*
|
|
|
|
* Port change of an enabled port. We have to
|
|
|
|
* assume that this can have caused an stepping
|
|
|
|
* port switch.
|
|
|
|
*/
|
2013-01-30 01:49:40 -07:00
|
|
|
etr_tolec = get_tod_clock();
|
2007-02-05 13:18:19 -07:00
|
|
|
eacr.p0 = etr_port0_online;
|
|
|
|
if (!eacr.p0)
|
|
|
|
eacr.e0 = 0;
|
|
|
|
etr_port0_uptodate = 0;
|
|
|
|
}
|
|
|
|
if (test_and_clear_bit(ETR_EVENT_PORT1_CHANGE, &etr_events)) {
|
|
|
|
if (eacr.e1)
|
|
|
|
/*
|
|
|
|
* Port change of an enabled port. We have to
|
|
|
|
* assume that this can have caused an stepping
|
|
|
|
* port switch.
|
|
|
|
*/
|
2013-01-30 01:49:40 -07:00
|
|
|
etr_tolec = get_tod_clock();
|
2007-02-05 13:18:19 -07:00
|
|
|
eacr.p1 = etr_port1_online;
|
|
|
|
if (!eacr.p1)
|
|
|
|
eacr.e1 = 0;
|
|
|
|
etr_port1_uptodate = 0;
|
|
|
|
}
|
|
|
|
clear_bit(ETR_EVENT_UPDATE, &etr_events);
|
|
|
|
return eacr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up a timer that expires after the etr_tolec + 1.6 seconds if
|
|
|
|
* one of the ports needs an update.
|
|
|
|
*/
|
|
|
|
static void etr_set_tolec_timeout(unsigned long long now)
|
|
|
|
{
|
|
|
|
unsigned long micros;
|
|
|
|
|
|
|
|
if ((!etr_eacr.p0 || etr_port0_uptodate) &&
|
|
|
|
(!etr_eacr.p1 || etr_port1_uptodate))
|
|
|
|
return;
|
|
|
|
micros = (now > etr_tolec) ? ((now - etr_tolec) >> 12) : 0;
|
|
|
|
micros = (micros > 1600000) ? 0 : 1600000 - micros;
|
|
|
|
mod_timer(&etr_timer, jiffies + (micros * HZ) / 1000000 + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up a time that expires after 1/2 second.
|
|
|
|
*/
|
|
|
|
static void etr_set_sync_timeout(void)
|
|
|
|
{
|
|
|
|
mod_timer(&etr_timer, jiffies + HZ/2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the aib information for one or both ports.
|
|
|
|
*/
|
|
|
|
static struct etr_eacr etr_handle_update(struct etr_aib *aib,
|
|
|
|
struct etr_eacr eacr)
|
|
|
|
{
|
|
|
|
/* With both ports disabled the aib information is useless. */
|
|
|
|
if (!eacr.e0 && !eacr.e1)
|
|
|
|
return eacr;
|
|
|
|
|
2007-04-27 08:01:58 -06:00
|
|
|
/* Update port0 or port1 with aib stored in etr_work_fn. */
|
2007-02-05 13:18:19 -07:00
|
|
|
if (aib->esw.q == 0) {
|
|
|
|
/* Information for port 0 stored. */
|
|
|
|
if (eacr.p0 && !etr_port0_uptodate) {
|
|
|
|
etr_port0 = *aib;
|
|
|
|
if (etr_port0_online)
|
|
|
|
etr_port0_uptodate = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Information for port 1 stored. */
|
|
|
|
if (eacr.p1 && !etr_port1_uptodate) {
|
|
|
|
etr_port1 = *aib;
|
|
|
|
if (etr_port0_online)
|
|
|
|
etr_port1_uptodate = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not try to get the alternate port aib if the clock
|
|
|
|
* is not in sync yet.
|
|
|
|
*/
|
2010-07-27 11:29:38 -06:00
|
|
|
if (!eacr.es || !check_sync_clock())
|
2007-02-05 13:18:19 -07:00
|
|
|
return eacr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If steai is available we can get the information about
|
|
|
|
* the other port immediately. If only stetr is available the
|
|
|
|
* data-port bit toggle has to be used.
|
|
|
|
*/
|
2008-07-14 01:58:56 -06:00
|
|
|
if (etr_steai_available) {
|
2007-02-05 13:18:19 -07:00
|
|
|
if (eacr.p0 && !etr_port0_uptodate) {
|
|
|
|
etr_steai_cv(&etr_port0, ETR_STEAI_PORT_0);
|
|
|
|
etr_port0_uptodate = 1;
|
|
|
|
}
|
|
|
|
if (eacr.p1 && !etr_port1_uptodate) {
|
|
|
|
etr_steai_cv(&etr_port1, ETR_STEAI_PORT_1);
|
|
|
|
etr_port1_uptodate = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* One port was updated above, if the other
|
|
|
|
* port is not uptodate toggle dp bit.
|
|
|
|
*/
|
|
|
|
if ((eacr.p0 && !etr_port0_uptodate) ||
|
|
|
|
(eacr.p1 && !etr_port1_uptodate))
|
|
|
|
eacr.dp ^= 1;
|
|
|
|
else
|
|
|
|
eacr.dp = 0;
|
|
|
|
}
|
|
|
|
return eacr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write new etr control register if it differs from the current one.
|
|
|
|
* Return 1 if etr_tolec has been updated as well.
|
|
|
|
*/
|
|
|
|
static void etr_update_eacr(struct etr_eacr eacr)
|
|
|
|
{
|
|
|
|
int dp_changed;
|
|
|
|
|
|
|
|
if (memcmp(&etr_eacr, &eacr, sizeof(eacr)) == 0)
|
|
|
|
/* No change, return. */
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* The disable of an active port of the change of the data port
|
|
|
|
* bit can/will cause a change in the data port.
|
|
|
|
*/
|
|
|
|
dp_changed = etr_eacr.e0 > eacr.e0 || etr_eacr.e1 > eacr.e1 ||
|
|
|
|
(etr_eacr.dp ^ eacr.dp) != 0;
|
|
|
|
etr_eacr = eacr;
|
|
|
|
etr_setr(&etr_eacr);
|
|
|
|
if (dp_changed)
|
2013-01-30 01:49:40 -07:00
|
|
|
etr_tolec = get_tod_clock();
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-12-25 05:38:37 -07:00
|
|
|
* ETR work. In this function you'll find the main logic. In
|
2007-02-05 13:18:19 -07:00
|
|
|
* particular this is the only function that calls etr_update_eacr(),
|
|
|
|
* it "controls" the etr control register.
|
|
|
|
*/
|
2007-04-27 08:01:58 -06:00
|
|
|
static void etr_work_fn(struct work_struct *work)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
unsigned long long now;
|
|
|
|
struct etr_eacr eacr;
|
|
|
|
struct etr_aib aib;
|
|
|
|
int sync_port;
|
|
|
|
|
2008-12-25 05:38:38 -07:00
|
|
|
/* prevent multiple execution. */
|
|
|
|
mutex_lock(&etr_work_mutex);
|
|
|
|
|
2007-02-05 13:18:19 -07:00
|
|
|
/* Create working copy of etr_eacr. */
|
|
|
|
eacr = etr_eacr;
|
|
|
|
|
|
|
|
/* Check for the different events and their immediate effects. */
|
|
|
|
eacr = etr_handle_events(eacr);
|
|
|
|
|
|
|
|
/* Check if ETR is supposed to be active. */
|
|
|
|
eacr.ea = eacr.p0 || eacr.p1;
|
|
|
|
if (!eacr.ea) {
|
|
|
|
/* Both ports offline. Reset everything. */
|
|
|
|
eacr.dp = eacr.es = eacr.sl = 0;
|
2008-07-15 13:55:59 -06:00
|
|
|
on_each_cpu(disable_sync_clock, NULL, 1);
|
2007-02-05 13:18:19 -07:00
|
|
|
del_timer_sync(&etr_timer);
|
|
|
|
etr_update_eacr(eacr);
|
2008-12-25 05:38:38 -07:00
|
|
|
goto out_unlock;
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Store aib to get the current ETR status word. */
|
|
|
|
BUG_ON(etr_stetr(&aib) != 0);
|
|
|
|
etr_port0.esw = etr_port1.esw = aib.esw; /* Copy status word. */
|
2013-01-30 01:49:40 -07:00
|
|
|
now = get_tod_clock();
|
2007-02-05 13:18:19 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the port information if the last stepping port change
|
|
|
|
* or data port change is older than 1.6 seconds.
|
|
|
|
*/
|
|
|
|
if (now >= etr_tolec + (1600000 << 12))
|
|
|
|
eacr = etr_handle_update(&aib, eacr);
|
|
|
|
|
|
|
|
/*
|
2011-03-30 19:57:33 -06:00
|
|
|
* Select ports to enable. The preferred synchronization mode is PPS.
|
2007-02-05 13:18:19 -07:00
|
|
|
* If a port can be enabled depends on a number of things:
|
|
|
|
* 1) The port needs to be online and uptodate. A port is not
|
|
|
|
* disabled just because it is not uptodate, but it is only
|
|
|
|
* enabled if it is uptodate.
|
|
|
|
* 2) The port needs to have the same mode (pps / etr).
|
|
|
|
* 3) The port needs to be usable -> etr_port_valid() == 1
|
|
|
|
* 4) To enable the second port the clock needs to be in sync.
|
|
|
|
* 5) If both ports are useable and are ETR ports, the network id
|
|
|
|
* has to be the same.
|
|
|
|
* The eacr.sl bit is used to indicate etr mode vs. pps mode.
|
|
|
|
*/
|
|
|
|
if (eacr.p0 && aib.esw.psc0 == etr_lpsc_pps_mode) {
|
|
|
|
eacr.sl = 0;
|
|
|
|
eacr.e0 = 1;
|
|
|
|
if (!etr_mode_is_pps(etr_eacr))
|
|
|
|
eacr.es = 0;
|
|
|
|
if (!eacr.es || !eacr.p1 || aib.esw.psc1 != etr_lpsc_pps_mode)
|
|
|
|
eacr.e1 = 0;
|
|
|
|
// FIXME: uptodate checks ?
|
|
|
|
else if (etr_port0_uptodate && etr_port1_uptodate)
|
|
|
|
eacr.e1 = 1;
|
|
|
|
sync_port = (etr_port0_uptodate &&
|
|
|
|
etr_port_valid(&etr_port0, 0)) ? 0 : -1;
|
|
|
|
} else if (eacr.p1 && aib.esw.psc1 == etr_lpsc_pps_mode) {
|
|
|
|
eacr.sl = 0;
|
|
|
|
eacr.e0 = 0;
|
|
|
|
eacr.e1 = 1;
|
|
|
|
if (!etr_mode_is_pps(etr_eacr))
|
|
|
|
eacr.es = 0;
|
|
|
|
sync_port = (etr_port1_uptodate &&
|
|
|
|
etr_port_valid(&etr_port1, 1)) ? 1 : -1;
|
|
|
|
} else if (eacr.p0 && aib.esw.psc0 == etr_lpsc_operational_step) {
|
|
|
|
eacr.sl = 1;
|
|
|
|
eacr.e0 = 1;
|
|
|
|
if (!etr_mode_is_etr(etr_eacr))
|
|
|
|
eacr.es = 0;
|
|
|
|
if (!eacr.es || !eacr.p1 ||
|
|
|
|
aib.esw.psc1 != etr_lpsc_operational_alt)
|
|
|
|
eacr.e1 = 0;
|
|
|
|
else if (etr_port0_uptodate && etr_port1_uptodate &&
|
|
|
|
etr_compare_network(&etr_port0, &etr_port1))
|
|
|
|
eacr.e1 = 1;
|
|
|
|
sync_port = (etr_port0_uptodate &&
|
|
|
|
etr_port_valid(&etr_port0, 0)) ? 0 : -1;
|
|
|
|
} else if (eacr.p1 && aib.esw.psc1 == etr_lpsc_operational_step) {
|
|
|
|
eacr.sl = 1;
|
|
|
|
eacr.e0 = 0;
|
|
|
|
eacr.e1 = 1;
|
|
|
|
if (!etr_mode_is_etr(etr_eacr))
|
|
|
|
eacr.es = 0;
|
|
|
|
sync_port = (etr_port1_uptodate &&
|
|
|
|
etr_port_valid(&etr_port1, 1)) ? 1 : -1;
|
|
|
|
} else {
|
|
|
|
/* Both ports not usable. */
|
|
|
|
eacr.es = eacr.sl = 0;
|
|
|
|
sync_port = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the clock is in sync just update the eacr and return.
|
|
|
|
* If there is no valid sync port wait for a port update.
|
|
|
|
*/
|
2010-07-27 11:29:38 -06:00
|
|
|
if ((eacr.es && check_sync_clock()) || sync_port < 0) {
|
2007-02-05 13:18:19 -07:00
|
|
|
etr_update_eacr(eacr);
|
|
|
|
etr_set_tolec_timeout(now);
|
2008-12-25 05:38:38 -07:00
|
|
|
goto out_unlock;
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare control register for clock syncing
|
|
|
|
* (reset data port bit, set sync check control.
|
|
|
|
*/
|
|
|
|
eacr.dp = 0;
|
|
|
|
eacr.es = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update eacr and try to synchronize the clock. If the update
|
|
|
|
* of eacr caused a stepping port switch (or if we have to
|
2011-03-30 19:57:33 -06:00
|
|
|
* assume that a stepping port switch has occurred) or the
|
2007-02-05 13:18:19 -07:00
|
|
|
* clock syncing failed, reset the sync check control bit
|
|
|
|
* and set up a timer to try again after 0.5 seconds
|
|
|
|
*/
|
|
|
|
etr_update_eacr(eacr);
|
|
|
|
if (now < etr_tolec + (1600000 << 12) ||
|
2008-12-25 05:38:37 -07:00
|
|
|
etr_sync_clock_stop(&aib, sync_port) != 0) {
|
2007-02-05 13:18:19 -07:00
|
|
|
/* Sync failed. Try again in 1/2 second. */
|
|
|
|
eacr.es = 0;
|
|
|
|
etr_update_eacr(eacr);
|
|
|
|
etr_set_sync_timeout();
|
|
|
|
} else
|
|
|
|
etr_set_tolec_timeout(now);
|
2008-12-25 05:38:38 -07:00
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&etr_work_mutex);
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sysfs interface functions
|
|
|
|
*/
|
2011-12-21 16:09:50 -07:00
|
|
|
static struct bus_type etr_subsys = {
|
|
|
|
.name = "etr",
|
|
|
|
.dev_name = "etr",
|
2007-02-05 13:18:19 -07:00
|
|
|
};
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static struct device etr_port0_dev = {
|
2007-02-05 13:18:19 -07:00
|
|
|
.id = 0,
|
2011-12-21 16:09:50 -07:00
|
|
|
.bus = &etr_subsys,
|
2007-02-05 13:18:19 -07:00
|
|
|
};
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static struct device etr_port1_dev = {
|
2007-02-05 13:18:19 -07:00
|
|
|
.id = 1,
|
2011-12-21 16:09:50 -07:00
|
|
|
.bus = &etr_subsys,
|
2007-02-05 13:18:19 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2011-12-21 16:09:50 -07:00
|
|
|
* ETR subsys attributes
|
2007-02-05 13:18:19 -07:00
|
|
|
*/
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t etr_stepping_port_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-01-05 04:47:58 -07:00
|
|
|
char *buf)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
return sprintf(buf, "%i\n", etr_port0.esw.p);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(stepping_port, 0400, etr_stepping_port_show, NULL);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t etr_stepping_mode_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-01-05 04:47:58 -07:00
|
|
|
char *buf)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
char *mode_str;
|
|
|
|
|
|
|
|
if (etr_mode_is_pps(etr_eacr))
|
|
|
|
mode_str = "pps";
|
|
|
|
else if (etr_mode_is_etr(etr_eacr))
|
|
|
|
mode_str = "etr";
|
|
|
|
else
|
|
|
|
mode_str = "local";
|
|
|
|
return sprintf(buf, "%s\n", mode_str);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(stepping_mode, 0400, etr_stepping_mode_show, NULL);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ETR port attributes
|
|
|
|
*/
|
2011-12-21 16:09:50 -07:00
|
|
|
static inline struct etr_aib *etr_aib_from_dev(struct device *dev)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
if (dev == &etr_port0_dev)
|
|
|
|
return etr_port0_online ? &etr_port0 : NULL;
|
|
|
|
else
|
|
|
|
return etr_port1_online ? &etr_port1 : NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t etr_online_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2008-07-01 10:48:41 -06:00
|
|
|
char *buf)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
unsigned int online;
|
|
|
|
|
|
|
|
online = (dev == &etr_port0_dev) ? etr_port0_online : etr_port1_online;
|
|
|
|
return sprintf(buf, "%i\n", online);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t etr_online_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2008-07-01 10:48:41 -06:00
|
|
|
const char *buf, size_t count)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
unsigned int value;
|
|
|
|
|
|
|
|
value = simple_strtoul(buf, NULL, 0);
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return -EINVAL;
|
2008-07-14 01:58:56 -06:00
|
|
|
if (!test_bit(CLOCK_SYNC_HAS_ETR, &clock_sync_flags))
|
|
|
|
return -EOPNOTSUPP;
|
2009-03-26 08:24:21 -06:00
|
|
|
mutex_lock(&clock_sync_mutex);
|
2007-02-05 13:18:19 -07:00
|
|
|
if (dev == &etr_port0_dev) {
|
|
|
|
if (etr_port0_online == value)
|
2009-03-26 08:24:21 -06:00
|
|
|
goto out; /* Nothing to do. */
|
2007-02-05 13:18:19 -07:00
|
|
|
etr_port0_online = value;
|
2009-03-26 08:24:21 -06:00
|
|
|
if (etr_port0_online && etr_port1_online)
|
|
|
|
set_bit(CLOCK_SYNC_ETR, &clock_sync_flags);
|
|
|
|
else
|
|
|
|
clear_bit(CLOCK_SYNC_ETR, &clock_sync_flags);
|
2007-02-05 13:18:19 -07:00
|
|
|
set_bit(ETR_EVENT_PORT0_CHANGE, &etr_events);
|
2008-12-25 05:38:37 -07:00
|
|
|
queue_work(time_sync_wq, &etr_work);
|
2007-02-05 13:18:19 -07:00
|
|
|
} else {
|
|
|
|
if (etr_port1_online == value)
|
2009-03-26 08:24:21 -06:00
|
|
|
goto out; /* Nothing to do. */
|
2007-02-05 13:18:19 -07:00
|
|
|
etr_port1_online = value;
|
2009-03-26 08:24:21 -06:00
|
|
|
if (etr_port0_online && etr_port1_online)
|
|
|
|
set_bit(CLOCK_SYNC_ETR, &clock_sync_flags);
|
|
|
|
else
|
|
|
|
clear_bit(CLOCK_SYNC_ETR, &clock_sync_flags);
|
2007-02-05 13:18:19 -07:00
|
|
|
set_bit(ETR_EVENT_PORT1_CHANGE, &etr_events);
|
2008-12-25 05:38:37 -07:00
|
|
|
queue_work(time_sync_wq, &etr_work);
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
2009-03-26 08:24:21 -06:00
|
|
|
out:
|
|
|
|
mutex_unlock(&clock_sync_mutex);
|
2007-02-05 13:18:19 -07:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(online, 0600, etr_online_show, etr_online_store);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t etr_stepping_control_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2008-07-01 10:48:41 -06:00
|
|
|
char *buf)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
return sprintf(buf, "%i\n", (dev == &etr_port0_dev) ?
|
|
|
|
etr_eacr.e0 : etr_eacr.e1);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(stepping_control, 0400, etr_stepping_control_show, NULL);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t etr_mode_code_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
if (!etr_port0_online && !etr_port1_online)
|
|
|
|
/* Status word is not uptodate if both ports are offline. */
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", (dev == &etr_port0_dev) ?
|
|
|
|
etr_port0.esw.psc0 : etr_port0.esw.psc1);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(state_code, 0400, etr_mode_code_show, NULL);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t etr_untuned_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
struct etr_aib *aib = etr_aib_from_dev(dev);
|
|
|
|
|
|
|
|
if (!aib || !aib->slsw.v1)
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", aib->edf1.u);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(untuned, 0400, etr_untuned_show, NULL);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t etr_network_id_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
struct etr_aib *aib = etr_aib_from_dev(dev);
|
|
|
|
|
|
|
|
if (!aib || !aib->slsw.v1)
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", aib->edf1.net_id);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(network, 0400, etr_network_id_show, NULL);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t etr_id_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
struct etr_aib *aib = etr_aib_from_dev(dev);
|
|
|
|
|
|
|
|
if (!aib || !aib->slsw.v1)
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", aib->edf1.etr_id);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(id, 0400, etr_id_show, NULL);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t etr_port_number_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
struct etr_aib *aib = etr_aib_from_dev(dev);
|
|
|
|
|
|
|
|
if (!aib || !aib->slsw.v1)
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", aib->edf1.etr_pn);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(port, 0400, etr_port_number_show, NULL);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t etr_coupled_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
struct etr_aib *aib = etr_aib_from_dev(dev);
|
|
|
|
|
|
|
|
if (!aib || !aib->slsw.v3)
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", aib->edf3.c);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(coupled, 0400, etr_coupled_show, NULL);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t etr_local_time_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
struct etr_aib *aib = etr_aib_from_dev(dev);
|
|
|
|
|
|
|
|
if (!aib || !aib->slsw.v3)
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", aib->edf3.blto);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(local_time, 0400, etr_local_time_show, NULL);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t etr_utc_offset_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
|
|
|
struct etr_aib *aib = etr_aib_from_dev(dev);
|
|
|
|
|
|
|
|
if (!aib || !aib->slsw.v3)
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", aib->edf3.buo);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(utc_offset, 0400, etr_utc_offset_show, NULL);
|
2007-02-05 13:18:19 -07:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static struct device_attribute *etr_port_attributes[] = {
|
|
|
|
&dev_attr_online,
|
|
|
|
&dev_attr_stepping_control,
|
|
|
|
&dev_attr_state_code,
|
|
|
|
&dev_attr_untuned,
|
|
|
|
&dev_attr_network,
|
|
|
|
&dev_attr_id,
|
|
|
|
&dev_attr_port,
|
|
|
|
&dev_attr_coupled,
|
|
|
|
&dev_attr_local_time,
|
|
|
|
&dev_attr_utc_offset,
|
2007-02-05 13:18:19 -07:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static int __init etr_register_port(struct device *dev)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
2011-12-21 16:09:50 -07:00
|
|
|
struct device_attribute **attr;
|
2007-02-05 13:18:19 -07:00
|
|
|
int rc;
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
rc = device_register(dev);
|
2007-02-05 13:18:19 -07:00
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
for (attr = etr_port_attributes; *attr; attr++) {
|
2011-12-21 16:09:50 -07:00
|
|
|
rc = device_create_file(dev, *attr);
|
2007-02-05 13:18:19 -07:00
|
|
|
if (rc)
|
|
|
|
goto out_unreg;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
out_unreg:
|
|
|
|
for (; attr >= etr_port_attributes; attr--)
|
2011-12-21 16:09:50 -07:00
|
|
|
device_remove_file(dev, *attr);
|
|
|
|
device_unregister(dev);
|
2007-02-05 13:18:19 -07:00
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static void __init etr_unregister_port(struct device *dev)
|
2007-02-05 13:18:19 -07:00
|
|
|
{
|
2011-12-21 16:09:50 -07:00
|
|
|
struct device_attribute **attr;
|
2007-02-05 13:18:19 -07:00
|
|
|
|
|
|
|
for (attr = etr_port_attributes; *attr; attr++)
|
2011-12-21 16:09:50 -07:00
|
|
|
device_remove_file(dev, *attr);
|
|
|
|
device_unregister(dev);
|
2007-02-05 13:18:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init etr_init_sysfs(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
rc = subsys_system_register(&etr_subsys, NULL);
|
2007-02-05 13:18:19 -07:00
|
|
|
if (rc)
|
|
|
|
goto out;
|
2011-12-21 16:09:50 -07:00
|
|
|
rc = device_create_file(etr_subsys.dev_root, &dev_attr_stepping_port);
|
2007-02-05 13:18:19 -07:00
|
|
|
if (rc)
|
2011-12-21 16:09:50 -07:00
|
|
|
goto out_unreg_subsys;
|
|
|
|
rc = device_create_file(etr_subsys.dev_root, &dev_attr_stepping_mode);
|
2007-02-05 13:18:19 -07:00
|
|
|
if (rc)
|
|
|
|
goto out_remove_stepping_port;
|
|
|
|
rc = etr_register_port(&etr_port0_dev);
|
|
|
|
if (rc)
|
|
|
|
goto out_remove_stepping_mode;
|
|
|
|
rc = etr_register_port(&etr_port1_dev);
|
|
|
|
if (rc)
|
|
|
|
goto out_remove_port0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_remove_port0:
|
|
|
|
etr_unregister_port(&etr_port0_dev);
|
|
|
|
out_remove_stepping_mode:
|
2011-12-21 16:09:50 -07:00
|
|
|
device_remove_file(etr_subsys.dev_root, &dev_attr_stepping_mode);
|
2007-02-05 13:18:19 -07:00
|
|
|
out_remove_stepping_port:
|
2011-12-21 16:09:50 -07:00
|
|
|
device_remove_file(etr_subsys.dev_root, &dev_attr_stepping_port);
|
|
|
|
out_unreg_subsys:
|
|
|
|
bus_unregister(&etr_subsys);
|
2007-02-05 13:18:19 -07:00
|
|
|
out:
|
|
|
|
return rc;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-02-05 13:18:19 -07:00
|
|
|
device_initcall(etr_init_sysfs);
|
2008-07-14 01:58:56 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Server Time Protocol (STP) code.
|
|
|
|
*/
|
2016-03-17 15:23:00 -06:00
|
|
|
static bool stp_online;
|
2008-07-14 01:58:56 -06:00
|
|
|
static struct stp_sstpi stp_info;
|
|
|
|
static void *stp_page;
|
|
|
|
|
|
|
|
static void stp_work_fn(struct work_struct *work);
|
2008-12-25 05:38:38 -07:00
|
|
|
static DEFINE_MUTEX(stp_work_mutex);
|
2008-07-14 01:58:56 -06:00
|
|
|
static DECLARE_WORK(stp_work, stp_work_fn);
|
2009-04-14 07:36:19 -06:00
|
|
|
static struct timer_list stp_timer;
|
2008-07-14 01:58:56 -06:00
|
|
|
|
|
|
|
static int __init early_parse_stp(char *p)
|
|
|
|
{
|
2016-03-17 15:23:00 -06:00
|
|
|
return kstrtobool(p, &stp_online);
|
2008-07-14 01:58:56 -06:00
|
|
|
}
|
|
|
|
early_param("stp", early_parse_stp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset STP attachment.
|
|
|
|
*/
|
2008-08-01 08:39:19 -06:00
|
|
|
static void __init stp_reset(void)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2009-06-22 04:08:03 -06:00
|
|
|
stp_page = (void *) get_zeroed_page(GFP_ATOMIC);
|
2016-05-31 01:09:57 -06:00
|
|
|
rc = chsc_sstpc(stp_page, STP_OP_CTRL, 0x0000, NULL);
|
2008-10-10 13:33:29 -06:00
|
|
|
if (rc == 0)
|
2008-07-14 01:58:56 -06:00
|
|
|
set_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags);
|
|
|
|
else if (stp_online) {
|
2016-03-03 21:49:57 -07:00
|
|
|
pr_warn("The real or virtual hardware system does not provide an STP interface\n");
|
2009-06-22 04:08:03 -06:00
|
|
|
free_page((unsigned long) stp_page);
|
2008-07-14 01:58:56 -06:00
|
|
|
stp_page = NULL;
|
|
|
|
stp_online = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-14 07:36:19 -06:00
|
|
|
static void stp_timeout(unsigned long dummy)
|
|
|
|
{
|
|
|
|
queue_work(time_sync_wq, &stp_work);
|
|
|
|
}
|
|
|
|
|
2008-07-14 01:58:56 -06:00
|
|
|
static int __init stp_init(void)
|
|
|
|
{
|
2008-12-25 05:38:37 -07:00
|
|
|
if (!test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags))
|
|
|
|
return 0;
|
2009-04-14 07:36:19 -06:00
|
|
|
setup_timer(&stp_timer, stp_timeout, 0UL);
|
2008-12-25 05:38:37 -07:00
|
|
|
time_init_wq();
|
|
|
|
if (!stp_online)
|
|
|
|
return 0;
|
|
|
|
queue_work(time_sync_wq, &stp_work);
|
2008-07-14 01:58:56 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
arch_initcall(stp_init);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* STP timing alert. There are three causes:
|
|
|
|
* 1) timing status change
|
|
|
|
* 2) link availability change
|
|
|
|
* 3) time control parameter change
|
|
|
|
* In all three cases we are only interested in the clock source state.
|
|
|
|
* If a STP clock source is now available use it.
|
|
|
|
*/
|
|
|
|
static void stp_timing_alert(struct stp_irq_parm *intparm)
|
|
|
|
{
|
|
|
|
if (intparm->tsc || intparm->lac || intparm->tcpc)
|
2008-12-25 05:38:37 -07:00
|
|
|
queue_work(time_sync_wq, &stp_work);
|
2008-07-14 01:58:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* STP sync check machine check. This is called when the timing state
|
|
|
|
* changes from the synchronized state to the unsynchronized state.
|
|
|
|
* After a STP sync check the clock is not in sync. The machine check
|
|
|
|
* is broadcasted to all cpus at the same time.
|
|
|
|
*/
|
2015-10-09 05:48:03 -06:00
|
|
|
int stp_sync_check(void)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
|
|
|
disable_sync_clock(NULL);
|
2015-10-09 05:48:03 -06:00
|
|
|
return 1;
|
2008-07-14 01:58:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* STP island condition machine check. This is called when an attached
|
|
|
|
* server attempts to communicate over an STP link and the servers
|
|
|
|
* have matching CTN ids and have a valid stratum-1 configuration
|
|
|
|
* but the configurations do not match.
|
|
|
|
*/
|
2015-10-09 05:48:03 -06:00
|
|
|
int stp_island_check(void)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
|
|
|
disable_sync_clock(NULL);
|
2015-10-09 05:48:03 -06:00
|
|
|
return 1;
|
2008-07-14 01:58:56 -06:00
|
|
|
}
|
|
|
|
|
2015-10-09 05:48:03 -06:00
|
|
|
void stp_queue_work(void)
|
|
|
|
{
|
|
|
|
queue_work(time_sync_wq, &stp_work);
|
|
|
|
}
|
2008-12-25 05:38:37 -07:00
|
|
|
|
|
|
|
static int stp_sync_clock(void *data)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
2008-12-25 05:38:37 -07:00
|
|
|
static int first;
|
2015-05-13 02:58:41 -06:00
|
|
|
unsigned long long old_clock, delta, new_clock, clock_delta;
|
2008-12-25 05:38:37 -07:00
|
|
|
struct clock_sync_data *stp_sync;
|
2016-05-31 02:16:24 -06:00
|
|
|
struct ptff_qto qto;
|
2008-07-14 01:58:56 -06:00
|
|
|
int rc;
|
|
|
|
|
2008-12-25 05:38:37 -07:00
|
|
|
stp_sync = data;
|
2008-07-14 01:58:56 -06:00
|
|
|
|
2008-12-25 05:38:37 -07:00
|
|
|
if (xchg(&first, 1) == 1) {
|
|
|
|
/* Slave */
|
|
|
|
clock_sync_cpu(stp_sync);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-14 01:58:56 -06:00
|
|
|
|
2008-12-25 05:38:37 -07:00
|
|
|
/* Wait until all other cpus entered the sync function. */
|
|
|
|
while (atomic_read(&stp_sync->cpus) != 0)
|
|
|
|
cpu_relax();
|
2008-07-14 01:58:56 -06:00
|
|
|
|
|
|
|
enable_sync_clock();
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
if (stp_info.todoff[0] || stp_info.todoff[1] ||
|
|
|
|
stp_info.todoff[2] || stp_info.todoff[3] ||
|
|
|
|
stp_info.tmd != 2) {
|
2013-01-30 01:49:40 -07:00
|
|
|
old_clock = get_tod_clock();
|
2016-05-31 01:09:57 -06:00
|
|
|
rc = chsc_sstpc(stp_page, STP_OP_SYNC, 0, &clock_delta);
|
2008-07-14 01:58:56 -06:00
|
|
|
if (rc == 0) {
|
2016-05-31 01:09:57 -06:00
|
|
|
new_clock = old_clock + clock_delta;
|
2015-05-13 02:58:41 -06:00
|
|
|
delta = adjust_time(old_clock, new_clock, 0);
|
2016-05-31 02:16:24 -06:00
|
|
|
if (ptff_query(PTFF_QTO) &&
|
|
|
|
ptff(&qto, sizeof(qto), PTFF_QTO) == 0)
|
|
|
|
/* Update LPAR offset */
|
|
|
|
lpar_offset = qto.tod_epoch_difference;
|
2015-05-13 02:58:41 -06:00
|
|
|
atomic_notifier_call_chain(&s390_epoch_delta_notifier,
|
|
|
|
0, &clock_delta);
|
2008-07-14 01:58:56 -06:00
|
|
|
fixup_clock_comparator(delta);
|
|
|
|
rc = chsc_sstpi(stp_page, &stp_info,
|
|
|
|
sizeof(struct stp_sstpi));
|
|
|
|
if (rc == 0 && stp_info.tmd != 2)
|
|
|
|
rc = -EAGAIN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rc) {
|
|
|
|
disable_sync_clock(NULL);
|
2008-12-25 05:38:37 -07:00
|
|
|
stp_sync->in_sync = -EAGAIN;
|
2008-07-14 01:58:56 -06:00
|
|
|
} else
|
2008-12-25 05:38:37 -07:00
|
|
|
stp_sync->in_sync = 1;
|
|
|
|
xchg(&first, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-14 01:58:56 -06:00
|
|
|
|
2008-12-25 05:38:37 -07:00
|
|
|
/*
|
|
|
|
* STP work. Check for the STP state and take over the clock
|
|
|
|
* synchronization if the STP clock source is usable.
|
|
|
|
*/
|
|
|
|
static void stp_work_fn(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct clock_sync_data stp_sync;
|
|
|
|
int rc;
|
|
|
|
|
2008-12-25 05:38:38 -07:00
|
|
|
/* prevent multiple execution. */
|
|
|
|
mutex_lock(&stp_work_mutex);
|
|
|
|
|
2008-12-25 05:38:37 -07:00
|
|
|
if (!stp_online) {
|
2016-05-31 01:09:57 -06:00
|
|
|
chsc_sstpc(stp_page, STP_OP_CTRL, 0x0000, NULL);
|
2009-04-14 07:36:19 -06:00
|
|
|
del_timer_sync(&stp_timer);
|
2008-12-25 05:38:38 -07:00
|
|
|
goto out_unlock;
|
2008-12-25 05:38:37 -07:00
|
|
|
}
|
|
|
|
|
2016-05-31 01:09:57 -06:00
|
|
|
rc = chsc_sstpc(stp_page, STP_OP_CTRL, 0xb0e0, NULL);
|
2008-12-25 05:38:37 -07:00
|
|
|
if (rc)
|
2008-12-25 05:38:38 -07:00
|
|
|
goto out_unlock;
|
2008-12-25 05:38:37 -07:00
|
|
|
|
|
|
|
rc = chsc_sstpi(stp_page, &stp_info, sizeof(struct stp_sstpi));
|
|
|
|
if (rc || stp_info.c == 0)
|
2008-12-25 05:38:38 -07:00
|
|
|
goto out_unlock;
|
2008-12-25 05:38:37 -07:00
|
|
|
|
2009-03-26 08:24:21 -06:00
|
|
|
/* Skip synchronization if the clock is already in sync. */
|
|
|
|
if (check_sync_clock())
|
|
|
|
goto out_unlock;
|
|
|
|
|
2008-12-25 05:38:37 -07:00
|
|
|
memset(&stp_sync, 0, sizeof(stp_sync));
|
|
|
|
get_online_cpus();
|
|
|
|
atomic_set(&stp_sync.cpus, num_online_cpus() - 1);
|
2011-05-23 02:24:36 -06:00
|
|
|
stop_machine(stp_sync_clock, &stp_sync, cpu_online_mask);
|
2008-12-25 05:38:37 -07:00
|
|
|
put_online_cpus();
|
2008-12-25 05:38:38 -07:00
|
|
|
|
2009-04-14 07:36:19 -06:00
|
|
|
if (!check_sync_clock())
|
|
|
|
/*
|
|
|
|
* There is a usable clock but the synchonization failed.
|
|
|
|
* Retry after a second.
|
|
|
|
*/
|
|
|
|
mod_timer(&stp_timer, jiffies + HZ);
|
|
|
|
|
2008-12-25 05:38:38 -07:00
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&stp_work_mutex);
|
2008-07-14 01:58:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-12-21 16:09:50 -07:00
|
|
|
* STP subsys sysfs interface functions
|
2008-07-14 01:58:56 -06:00
|
|
|
*/
|
2011-12-21 16:09:50 -07:00
|
|
|
static struct bus_type stp_subsys = {
|
|
|
|
.name = "stp",
|
|
|
|
.dev_name = "stp",
|
2008-07-14 01:58:56 -06:00
|
|
|
};
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t stp_ctn_id_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-01-05 04:47:58 -07:00
|
|
|
char *buf)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
|
|
|
if (!stp_online)
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%016llx\n",
|
|
|
|
*(unsigned long long *) stp_info.ctnid);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(ctn_id, 0400, stp_ctn_id_show, NULL);
|
2008-07-14 01:58:56 -06:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t stp_ctn_type_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-01-05 04:47:58 -07:00
|
|
|
char *buf)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
|
|
|
if (!stp_online)
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", stp_info.ctn);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(ctn_type, 0400, stp_ctn_type_show, NULL);
|
2008-07-14 01:58:56 -06:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t stp_dst_offset_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-01-05 04:47:58 -07:00
|
|
|
char *buf)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
|
|
|
if (!stp_online || !(stp_info.vbits & 0x2000))
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", (int)(s16) stp_info.dsto);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(dst_offset, 0400, stp_dst_offset_show, NULL);
|
2008-07-14 01:58:56 -06:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t stp_leap_seconds_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-01-05 04:47:58 -07:00
|
|
|
char *buf)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
|
|
|
if (!stp_online || !(stp_info.vbits & 0x8000))
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", (int)(s16) stp_info.leaps);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(leap_seconds, 0400, stp_leap_seconds_show, NULL);
|
2008-07-14 01:58:56 -06:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t stp_stratum_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-01-05 04:47:58 -07:00
|
|
|
char *buf)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
|
|
|
if (!stp_online)
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", (int)(s16) stp_info.stratum);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(stratum, 0400, stp_stratum_show, NULL);
|
2008-07-14 01:58:56 -06:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t stp_time_offset_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-01-05 04:47:58 -07:00
|
|
|
char *buf)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
|
|
|
if (!stp_online || !(stp_info.vbits & 0x0800))
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", (int) stp_info.tto);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(time_offset, 0400, stp_time_offset_show, NULL);
|
2008-07-14 01:58:56 -06:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t stp_time_zone_offset_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-01-05 04:47:58 -07:00
|
|
|
char *buf)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
|
|
|
if (!stp_online || !(stp_info.vbits & 0x4000))
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", (int)(s16) stp_info.tzo);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(time_zone_offset, 0400,
|
2008-07-14 01:58:56 -06:00
|
|
|
stp_time_zone_offset_show, NULL);
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t stp_timing_mode_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-01-05 04:47:58 -07:00
|
|
|
char *buf)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
|
|
|
if (!stp_online)
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", stp_info.tmd);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(timing_mode, 0400, stp_timing_mode_show, NULL);
|
2008-07-14 01:58:56 -06:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t stp_timing_state_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-01-05 04:47:58 -07:00
|
|
|
char *buf)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
|
|
|
if (!stp_online)
|
|
|
|
return -ENODATA;
|
|
|
|
return sprintf(buf, "%i\n", stp_info.tst);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static DEVICE_ATTR(timing_state, 0400, stp_timing_state_show, NULL);
|
2008-07-14 01:58:56 -06:00
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t stp_online_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-01-05 04:47:58 -07:00
|
|
|
char *buf)
|
2008-07-14 01:58:56 -06:00
|
|
|
{
|
|
|
|
return sprintf(buf, "%i\n", stp_online);
|
|
|
|
}
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static ssize_t stp_online_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2008-07-14 01:58:56 -06:00
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned int value;
|
|
|
|
|
|
|
|
value = simple_strtoul(buf, NULL, 0);
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
if (!test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags))
|
|
|
|
return -EOPNOTSUPP;
|
2009-03-26 08:24:21 -06:00
|
|
|
mutex_lock(&clock_sync_mutex);
|
2008-07-14 01:58:56 -06:00
|
|
|
stp_online = value;
|
2009-03-26 08:24:21 -06:00
|
|
|
if (stp_online)
|
|
|
|
set_bit(CLOCK_SYNC_STP, &clock_sync_flags);
|
|
|
|
else
|
|
|
|
clear_bit(CLOCK_SYNC_STP, &clock_sync_flags);
|
2008-12-25 05:38:37 -07:00
|
|
|
queue_work(time_sync_wq, &stp_work);
|
2009-03-26 08:24:21 -06:00
|
|
|
mutex_unlock(&clock_sync_mutex);
|
2008-07-14 01:58:56 -06:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-12-21 16:09:50 -07:00
|
|
|
* Can't use DEVICE_ATTR because the attribute should be named
|
|
|
|
* stp/online but dev_attr_online already exists in this file ..
|
2008-07-14 01:58:56 -06:00
|
|
|
*/
|
2011-12-21 16:09:50 -07:00
|
|
|
static struct device_attribute dev_attr_stp_online = {
|
2008-07-14 01:58:56 -06:00
|
|
|
.attr = { .name = "online", .mode = 0600 },
|
|
|
|
.show = stp_online_show,
|
|
|
|
.store = stp_online_store,
|
|
|
|
};
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
static struct device_attribute *stp_attributes[] = {
|
|
|
|
&dev_attr_ctn_id,
|
|
|
|
&dev_attr_ctn_type,
|
|
|
|
&dev_attr_dst_offset,
|
|
|
|
&dev_attr_leap_seconds,
|
|
|
|
&dev_attr_stp_online,
|
|
|
|
&dev_attr_stratum,
|
|
|
|
&dev_attr_time_offset,
|
|
|
|
&dev_attr_time_zone_offset,
|
|
|
|
&dev_attr_timing_mode,
|
|
|
|
&dev_attr_timing_state,
|
2008-07-14 01:58:56 -06:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init stp_init_sysfs(void)
|
|
|
|
{
|
2011-12-21 16:09:50 -07:00
|
|
|
struct device_attribute **attr;
|
2008-07-14 01:58:56 -06:00
|
|
|
int rc;
|
|
|
|
|
2011-12-21 16:09:50 -07:00
|
|
|
rc = subsys_system_register(&stp_subsys, NULL);
|
2008-07-14 01:58:56 -06:00
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
for (attr = stp_attributes; *attr; attr++) {
|
2011-12-21 16:09:50 -07:00
|
|
|
rc = device_create_file(stp_subsys.dev_root, *attr);
|
2008-07-14 01:58:56 -06:00
|
|
|
if (rc)
|
|
|
|
goto out_unreg;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
out_unreg:
|
|
|
|
for (; attr >= stp_attributes; attr--)
|
2011-12-21 16:09:50 -07:00
|
|
|
device_remove_file(stp_subsys.dev_root, *attr);
|
|
|
|
bus_unregister(&stp_subsys);
|
2008-07-14 01:58:56 -06:00
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_initcall(stp_init_sysfs);
|