tcp: fix return value for partial writes
[linux-2.6/btrfs-unstable.git] / arch / s390 / kernel / time.c
blob0bfcc492987ebe7f87fba5d0f69c5faa346a8514
1 /*
2 * Time of day based timer functions.
4 * S390 version
5 * Copyright IBM Corp. 1999, 2008
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)
10 * Derived from "arch/i386/kernel/time.c"
11 * Copyright (C) 1991, 1992, 1995 Linus Torvalds
14 #define KMSG_COMPONENT "time"
15 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
17 #include <linux/kernel_stat.h>
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>
26 #include <linux/cpu.h>
27 #include <linux/stop_machine.h>
28 #include <linux/time.h>
29 #include <linux/device.h>
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>
37 #include <linux/timekeeper_internal.h>
38 #include <linux/clockchips.h>
39 #include <linux/gfp.h>
40 #include <linux/kprobes.h>
41 #include <asm/uaccess.h>
42 #include <asm/facility.h>
43 #include <asm/delay.h>
44 #include <asm/div64.h>
45 #include <asm/vdso.h>
46 #include <asm/irq.h>
47 #include <asm/irq_regs.h>
48 #include <asm/vtimer.h>
49 #include <asm/stp.h>
50 #include <asm/cio.h>
51 #include "entry.h"
53 u64 sched_clock_base_cc = -1; /* Force to data section. */
54 EXPORT_SYMBOL_GPL(sched_clock_base_cc);
56 static DEFINE_PER_CPU(struct clock_event_device, comparators);
58 ATOMIC_NOTIFIER_HEAD(s390_epoch_delta_notifier);
59 EXPORT_SYMBOL(s390_epoch_delta_notifier);
61 unsigned char ptff_function_mask[16];
62 unsigned long lpar_offset;
63 unsigned long initial_leap_seconds;
66 * Get time offsets with PTFF
68 void __init ptff_init(void)
70 struct ptff_qto qto;
71 struct ptff_qui qui;
73 if (!test_facility(28))
74 return;
75 ptff(&ptff_function_mask, sizeof(ptff_function_mask), PTFF_QAF);
77 /* get LPAR offset */
78 if (ptff_query(PTFF_QTO) && ptff(&qto, sizeof(qto), PTFF_QTO) == 0)
79 lpar_offset = qto.tod_epoch_difference;
81 /* get initial leap seconds */
82 if (ptff_query(PTFF_QUI) && ptff(&qui, sizeof(qui), PTFF_QUI) == 0)
83 initial_leap_seconds = (unsigned long)
84 ((long) qui.old_leap * 4096000000L);
88 * Scheduler clock - returns current time in nanosec units.
90 unsigned long long notrace sched_clock(void)
92 return tod_to_ns(get_tod_clock_monotonic());
94 NOKPROBE_SYMBOL(sched_clock);
97 * Monotonic_clock - returns # of nanoseconds passed since time_init()
99 unsigned long long monotonic_clock(void)
101 return sched_clock();
103 EXPORT_SYMBOL(monotonic_clock);
105 void tod_to_timeval(__u64 todval, struct timespec64 *xt)
107 unsigned long long sec;
109 sec = todval >> 12;
110 do_div(sec, 1000000);
111 xt->tv_sec = sec;
112 todval -= (sec * 1000000) << 12;
113 xt->tv_nsec = ((todval * 1000) >> 12);
115 EXPORT_SYMBOL(tod_to_timeval);
117 void clock_comparator_work(void)
119 struct clock_event_device *cd;
121 S390_lowcore.clock_comparator = -1ULL;
122 cd = this_cpu_ptr(&comparators);
123 cd->event_handler(cd);
127 * Fixup the clock comparator.
129 static void fixup_clock_comparator(unsigned long long delta)
131 /* If nobody is waiting there's nothing to fix. */
132 if (S390_lowcore.clock_comparator == -1ULL)
133 return;
134 S390_lowcore.clock_comparator += delta;
135 set_clock_comparator(S390_lowcore.clock_comparator);
138 static int s390_next_event(unsigned long delta,
139 struct clock_event_device *evt)
141 S390_lowcore.clock_comparator = get_tod_clock() + delta;
142 set_clock_comparator(S390_lowcore.clock_comparator);
143 return 0;
147 * Set up lowcore and control register of the current cpu to
148 * enable TOD clock and clock comparator interrupts.
150 void init_cpu_timer(void)
152 struct clock_event_device *cd;
153 int cpu;
155 S390_lowcore.clock_comparator = -1ULL;
156 set_clock_comparator(S390_lowcore.clock_comparator);
158 cpu = smp_processor_id();
159 cd = &per_cpu(comparators, cpu);
160 cd->name = "comparator";
161 cd->features = CLOCK_EVT_FEAT_ONESHOT;
162 cd->mult = 16777;
163 cd->shift = 12;
164 cd->min_delta_ns = 1;
165 cd->max_delta_ns = LONG_MAX;
166 cd->rating = 400;
167 cd->cpumask = cpumask_of(cpu);
168 cd->set_next_event = s390_next_event;
170 clockevents_register_device(cd);
172 /* Enable clock comparator timer interrupt. */
173 __ctl_set_bit(0,11);
175 /* Always allow the timing alert external interrupt. */
176 __ctl_set_bit(0, 4);
179 static void clock_comparator_interrupt(struct ext_code ext_code,
180 unsigned int param32,
181 unsigned long param64)
183 inc_irq_stat(IRQEXT_CLK);
184 if (S390_lowcore.clock_comparator == -1ULL)
185 set_clock_comparator(S390_lowcore.clock_comparator);
188 static void stp_timing_alert(struct stp_irq_parm *);
190 static void timing_alert_interrupt(struct ext_code ext_code,
191 unsigned int param32, unsigned long param64)
193 inc_irq_stat(IRQEXT_TLA);
194 if (param32 & 0x00038000)
195 stp_timing_alert((struct stp_irq_parm *) &param32);
198 static void stp_reset(void);
200 void read_persistent_clock64(struct timespec64 *ts)
202 __u64 clock;
204 clock = get_tod_clock() - initial_leap_seconds;
205 tod_to_timeval(clock - TOD_UNIX_EPOCH, ts);
208 void read_boot_clock64(struct timespec64 *ts)
210 __u64 clock;
212 clock = sched_clock_base_cc - initial_leap_seconds;
213 tod_to_timeval(clock - TOD_UNIX_EPOCH, ts);
216 static cycle_t read_tod_clock(struct clocksource *cs)
218 return get_tod_clock();
221 static struct clocksource clocksource_tod = {
222 .name = "tod",
223 .rating = 400,
224 .read = read_tod_clock,
225 .mask = -1ULL,
226 .mult = 1000,
227 .shift = 12,
228 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
231 struct clocksource * __init clocksource_default_clock(void)
233 return &clocksource_tod;
236 void update_vsyscall(struct timekeeper *tk)
238 u64 nsecps;
240 if (tk->tkr_mono.clock != &clocksource_tod)
241 return;
243 /* Make userspace gettimeofday spin until we're done. */
244 ++vdso_data->tb_update_count;
245 smp_wmb();
246 vdso_data->xtime_tod_stamp = tk->tkr_mono.cycle_last;
247 vdso_data->xtime_clock_sec = tk->xtime_sec;
248 vdso_data->xtime_clock_nsec = tk->tkr_mono.xtime_nsec;
249 vdso_data->wtom_clock_sec =
250 tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
251 vdso_data->wtom_clock_nsec = tk->tkr_mono.xtime_nsec +
252 + ((u64) tk->wall_to_monotonic.tv_nsec << tk->tkr_mono.shift);
253 nsecps = (u64) NSEC_PER_SEC << tk->tkr_mono.shift;
254 while (vdso_data->wtom_clock_nsec >= nsecps) {
255 vdso_data->wtom_clock_nsec -= nsecps;
256 vdso_data->wtom_clock_sec++;
259 vdso_data->xtime_coarse_sec = tk->xtime_sec;
260 vdso_data->xtime_coarse_nsec =
261 (long)(tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift);
262 vdso_data->wtom_coarse_sec =
263 vdso_data->xtime_coarse_sec + tk->wall_to_monotonic.tv_sec;
264 vdso_data->wtom_coarse_nsec =
265 vdso_data->xtime_coarse_nsec + tk->wall_to_monotonic.tv_nsec;
266 while (vdso_data->wtom_coarse_nsec >= NSEC_PER_SEC) {
267 vdso_data->wtom_coarse_nsec -= NSEC_PER_SEC;
268 vdso_data->wtom_coarse_sec++;
271 vdso_data->tk_mult = tk->tkr_mono.mult;
272 vdso_data->tk_shift = tk->tkr_mono.shift;
273 smp_wmb();
274 ++vdso_data->tb_update_count;
277 extern struct timezone sys_tz;
279 void update_vsyscall_tz(void)
281 vdso_data->tz_minuteswest = sys_tz.tz_minuteswest;
282 vdso_data->tz_dsttime = sys_tz.tz_dsttime;
286 * Initialize the TOD clock and the CPU timer of
287 * the boot cpu.
289 void __init time_init(void)
291 /* Reset time synchronization interfaces. */
292 stp_reset();
294 /* request the clock comparator external interrupt */
295 if (register_external_irq(EXT_IRQ_CLK_COMP, clock_comparator_interrupt))
296 panic("Couldn't request external interrupt 0x1004");
298 /* request the timing alert external interrupt */
299 if (register_external_irq(EXT_IRQ_TIMING_ALERT, timing_alert_interrupt))
300 panic("Couldn't request external interrupt 0x1406");
302 if (__clocksource_register(&clocksource_tod) != 0)
303 panic("Could not register TOD clock source");
305 /* Enable TOD clock interrupts on the boot cpu. */
306 init_cpu_timer();
308 /* Enable cpu timer interrupts on the boot cpu. */
309 vtime_init();
312 static DEFINE_PER_CPU(atomic_t, clock_sync_word);
313 static DEFINE_MUTEX(clock_sync_mutex);
314 static unsigned long clock_sync_flags;
316 #define CLOCK_SYNC_HAS_STP 0
317 #define CLOCK_SYNC_STP 1
320 * The get_clock function for the physical clock. It will get the current
321 * TOD clock, subtract the LPAR offset and write the result to *clock.
322 * The function returns 0 if the clock is in sync with the external time
323 * source. If the clock mode is local it will return -EOPNOTSUPP and
324 * -EAGAIN if the clock is not in sync with the external reference.
326 int get_phys_clock(unsigned long long *clock)
328 atomic_t *sw_ptr;
329 unsigned int sw0, sw1;
331 sw_ptr = &get_cpu_var(clock_sync_word);
332 sw0 = atomic_read(sw_ptr);
333 *clock = get_tod_clock() - lpar_offset;
334 sw1 = atomic_read(sw_ptr);
335 put_cpu_var(clock_sync_word);
336 if (sw0 == sw1 && (sw0 & 0x80000000U))
337 /* Success: time is in sync. */
338 return 0;
339 if (!test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags))
340 return -EOPNOTSUPP;
341 if (!test_bit(CLOCK_SYNC_STP, &clock_sync_flags))
342 return -EACCES;
343 return -EAGAIN;
345 EXPORT_SYMBOL(get_phys_clock);
348 * Make get_phys_clock() return -EAGAIN.
350 static void disable_sync_clock(void *dummy)
352 atomic_t *sw_ptr = this_cpu_ptr(&clock_sync_word);
354 * Clear the in-sync bit 2^31. All get_phys_clock calls will
355 * fail until the sync bit is turned back on. In addition
356 * increase the "sequence" counter to avoid the race of an
357 * stp event and the complete recovery against get_phys_clock.
359 atomic_andnot(0x80000000, sw_ptr);
360 atomic_inc(sw_ptr);
364 * Make get_phys_clock() return 0 again.
365 * Needs to be called from a context disabled for preemption.
367 static void enable_sync_clock(void)
369 atomic_t *sw_ptr = this_cpu_ptr(&clock_sync_word);
370 atomic_or(0x80000000, sw_ptr);
374 * Function to check if the clock is in sync.
376 static inline int check_sync_clock(void)
378 atomic_t *sw_ptr;
379 int rc;
381 sw_ptr = &get_cpu_var(clock_sync_word);
382 rc = (atomic_read(sw_ptr) & 0x80000000U) != 0;
383 put_cpu_var(clock_sync_word);
384 return rc;
387 /* Single threaded workqueue used for stp sync events */
388 static struct workqueue_struct *time_sync_wq;
390 static void __init time_init_wq(void)
392 if (time_sync_wq)
393 return;
394 time_sync_wq = create_singlethread_workqueue("timesync");
397 struct clock_sync_data {
398 atomic_t cpus;
399 int in_sync;
400 unsigned long long fixup_cc;
403 static void clock_sync_cpu(struct clock_sync_data *sync)
405 atomic_dec(&sync->cpus);
406 enable_sync_clock();
407 while (sync->in_sync == 0) {
408 __udelay(1);
410 * A different cpu changes *in_sync. Therefore use
411 * barrier() to force memory access.
413 barrier();
415 if (sync->in_sync != 1)
416 /* Didn't work. Clear per-cpu in sync bit again. */
417 disable_sync_clock(NULL);
419 * This round of TOD syncing is done. Set the clock comparator
420 * to the next tick and let the processor continue.
422 fixup_clock_comparator(sync->fixup_cc);
426 * Server Time Protocol (STP) code.
428 static bool stp_online;
429 static struct stp_sstpi stp_info;
430 static void *stp_page;
432 static void stp_work_fn(struct work_struct *work);
433 static DEFINE_MUTEX(stp_work_mutex);
434 static DECLARE_WORK(stp_work, stp_work_fn);
435 static struct timer_list stp_timer;
437 static int __init early_parse_stp(char *p)
439 return kstrtobool(p, &stp_online);
441 early_param("stp", early_parse_stp);
444 * Reset STP attachment.
446 static void __init stp_reset(void)
448 int rc;
450 stp_page = (void *) get_zeroed_page(GFP_ATOMIC);
451 rc = chsc_sstpc(stp_page, STP_OP_CTRL, 0x0000, NULL);
452 if (rc == 0)
453 set_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags);
454 else if (stp_online) {
455 pr_warn("The real or virtual hardware system does not provide an STP interface\n");
456 free_page((unsigned long) stp_page);
457 stp_page = NULL;
458 stp_online = 0;
462 static void stp_timeout(unsigned long dummy)
464 queue_work(time_sync_wq, &stp_work);
467 static int __init stp_init(void)
469 if (!test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags))
470 return 0;
471 setup_timer(&stp_timer, stp_timeout, 0UL);
472 time_init_wq();
473 if (!stp_online)
474 return 0;
475 queue_work(time_sync_wq, &stp_work);
476 return 0;
479 arch_initcall(stp_init);
482 * STP timing alert. There are three causes:
483 * 1) timing status change
484 * 2) link availability change
485 * 3) time control parameter change
486 * In all three cases we are only interested in the clock source state.
487 * If a STP clock source is now available use it.
489 static void stp_timing_alert(struct stp_irq_parm *intparm)
491 if (intparm->tsc || intparm->lac || intparm->tcpc)
492 queue_work(time_sync_wq, &stp_work);
496 * STP sync check machine check. This is called when the timing state
497 * changes from the synchronized state to the unsynchronized state.
498 * After a STP sync check the clock is not in sync. The machine check
499 * is broadcasted to all cpus at the same time.
501 int stp_sync_check(void)
503 disable_sync_clock(NULL);
504 return 1;
508 * STP island condition machine check. This is called when an attached
509 * server attempts to communicate over an STP link and the servers
510 * have matching CTN ids and have a valid stratum-1 configuration
511 * but the configurations do not match.
513 int stp_island_check(void)
515 disable_sync_clock(NULL);
516 return 1;
519 void stp_queue_work(void)
521 queue_work(time_sync_wq, &stp_work);
524 static int stp_sync_clock(void *data)
526 static int first;
527 unsigned long long clock_delta;
528 struct clock_sync_data *stp_sync;
529 struct ptff_qto qto;
530 int rc;
532 stp_sync = data;
534 if (xchg(&first, 1) == 1) {
535 /* Slave */
536 clock_sync_cpu(stp_sync);
537 return 0;
540 /* Wait until all other cpus entered the sync function. */
541 while (atomic_read(&stp_sync->cpus) != 0)
542 cpu_relax();
544 enable_sync_clock();
546 rc = 0;
547 if (stp_info.todoff[0] || stp_info.todoff[1] ||
548 stp_info.todoff[2] || stp_info.todoff[3] ||
549 stp_info.tmd != 2) {
550 rc = chsc_sstpc(stp_page, STP_OP_SYNC, 0, &clock_delta);
551 if (rc == 0) {
552 /* fixup the monotonic sched clock */
553 sched_clock_base_cc += clock_delta;
554 if (ptff_query(PTFF_QTO) &&
555 ptff(&qto, sizeof(qto), PTFF_QTO) == 0)
556 /* Update LPAR offset */
557 lpar_offset = qto.tod_epoch_difference;
558 atomic_notifier_call_chain(&s390_epoch_delta_notifier,
559 0, &clock_delta);
560 stp_sync->fixup_cc = clock_delta;
561 fixup_clock_comparator(clock_delta);
562 rc = chsc_sstpi(stp_page, &stp_info,
563 sizeof(struct stp_sstpi));
564 if (rc == 0 && stp_info.tmd != 2)
565 rc = -EAGAIN;
568 if (rc) {
569 disable_sync_clock(NULL);
570 stp_sync->in_sync = -EAGAIN;
571 } else
572 stp_sync->in_sync = 1;
573 xchg(&first, 0);
574 return 0;
578 * STP work. Check for the STP state and take over the clock
579 * synchronization if the STP clock source is usable.
581 static void stp_work_fn(struct work_struct *work)
583 struct clock_sync_data stp_sync;
584 int rc;
586 /* prevent multiple execution. */
587 mutex_lock(&stp_work_mutex);
589 if (!stp_online) {
590 chsc_sstpc(stp_page, STP_OP_CTRL, 0x0000, NULL);
591 del_timer_sync(&stp_timer);
592 goto out_unlock;
595 rc = chsc_sstpc(stp_page, STP_OP_CTRL, 0xb0e0, NULL);
596 if (rc)
597 goto out_unlock;
599 rc = chsc_sstpi(stp_page, &stp_info, sizeof(struct stp_sstpi));
600 if (rc || stp_info.c == 0)
601 goto out_unlock;
603 /* Skip synchronization if the clock is already in sync. */
604 if (check_sync_clock())
605 goto out_unlock;
607 memset(&stp_sync, 0, sizeof(stp_sync));
608 get_online_cpus();
609 atomic_set(&stp_sync.cpus, num_online_cpus() - 1);
610 stop_machine(stp_sync_clock, &stp_sync, cpu_online_mask);
611 put_online_cpus();
613 if (!check_sync_clock())
615 * There is a usable clock but the synchonization failed.
616 * Retry after a second.
618 mod_timer(&stp_timer, jiffies + HZ);
620 out_unlock:
621 mutex_unlock(&stp_work_mutex);
625 * STP subsys sysfs interface functions
627 static struct bus_type stp_subsys = {
628 .name = "stp",
629 .dev_name = "stp",
632 static ssize_t stp_ctn_id_show(struct device *dev,
633 struct device_attribute *attr,
634 char *buf)
636 if (!stp_online)
637 return -ENODATA;
638 return sprintf(buf, "%016llx\n",
639 *(unsigned long long *) stp_info.ctnid);
642 static DEVICE_ATTR(ctn_id, 0400, stp_ctn_id_show, NULL);
644 static ssize_t stp_ctn_type_show(struct device *dev,
645 struct device_attribute *attr,
646 char *buf)
648 if (!stp_online)
649 return -ENODATA;
650 return sprintf(buf, "%i\n", stp_info.ctn);
653 static DEVICE_ATTR(ctn_type, 0400, stp_ctn_type_show, NULL);
655 static ssize_t stp_dst_offset_show(struct device *dev,
656 struct device_attribute *attr,
657 char *buf)
659 if (!stp_online || !(stp_info.vbits & 0x2000))
660 return -ENODATA;
661 return sprintf(buf, "%i\n", (int)(s16) stp_info.dsto);
664 static DEVICE_ATTR(dst_offset, 0400, stp_dst_offset_show, NULL);
666 static ssize_t stp_leap_seconds_show(struct device *dev,
667 struct device_attribute *attr,
668 char *buf)
670 if (!stp_online || !(stp_info.vbits & 0x8000))
671 return -ENODATA;
672 return sprintf(buf, "%i\n", (int)(s16) stp_info.leaps);
675 static DEVICE_ATTR(leap_seconds, 0400, stp_leap_seconds_show, NULL);
677 static ssize_t stp_stratum_show(struct device *dev,
678 struct device_attribute *attr,
679 char *buf)
681 if (!stp_online)
682 return -ENODATA;
683 return sprintf(buf, "%i\n", (int)(s16) stp_info.stratum);
686 static DEVICE_ATTR(stratum, 0400, stp_stratum_show, NULL);
688 static ssize_t stp_time_offset_show(struct device *dev,
689 struct device_attribute *attr,
690 char *buf)
692 if (!stp_online || !(stp_info.vbits & 0x0800))
693 return -ENODATA;
694 return sprintf(buf, "%i\n", (int) stp_info.tto);
697 static DEVICE_ATTR(time_offset, 0400, stp_time_offset_show, NULL);
699 static ssize_t stp_time_zone_offset_show(struct device *dev,
700 struct device_attribute *attr,
701 char *buf)
703 if (!stp_online || !(stp_info.vbits & 0x4000))
704 return -ENODATA;
705 return sprintf(buf, "%i\n", (int)(s16) stp_info.tzo);
708 static DEVICE_ATTR(time_zone_offset, 0400,
709 stp_time_zone_offset_show, NULL);
711 static ssize_t stp_timing_mode_show(struct device *dev,
712 struct device_attribute *attr,
713 char *buf)
715 if (!stp_online)
716 return -ENODATA;
717 return sprintf(buf, "%i\n", stp_info.tmd);
720 static DEVICE_ATTR(timing_mode, 0400, stp_timing_mode_show, NULL);
722 static ssize_t stp_timing_state_show(struct device *dev,
723 struct device_attribute *attr,
724 char *buf)
726 if (!stp_online)
727 return -ENODATA;
728 return sprintf(buf, "%i\n", stp_info.tst);
731 static DEVICE_ATTR(timing_state, 0400, stp_timing_state_show, NULL);
733 static ssize_t stp_online_show(struct device *dev,
734 struct device_attribute *attr,
735 char *buf)
737 return sprintf(buf, "%i\n", stp_online);
740 static ssize_t stp_online_store(struct device *dev,
741 struct device_attribute *attr,
742 const char *buf, size_t count)
744 unsigned int value;
746 value = simple_strtoul(buf, NULL, 0);
747 if (value != 0 && value != 1)
748 return -EINVAL;
749 if (!test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags))
750 return -EOPNOTSUPP;
751 mutex_lock(&clock_sync_mutex);
752 stp_online = value;
753 if (stp_online)
754 set_bit(CLOCK_SYNC_STP, &clock_sync_flags);
755 else
756 clear_bit(CLOCK_SYNC_STP, &clock_sync_flags);
757 queue_work(time_sync_wq, &stp_work);
758 mutex_unlock(&clock_sync_mutex);
759 return count;
763 * Can't use DEVICE_ATTR because the attribute should be named
764 * stp/online but dev_attr_online already exists in this file ..
766 static struct device_attribute dev_attr_stp_online = {
767 .attr = { .name = "online", .mode = 0600 },
768 .show = stp_online_show,
769 .store = stp_online_store,
772 static struct device_attribute *stp_attributes[] = {
773 &dev_attr_ctn_id,
774 &dev_attr_ctn_type,
775 &dev_attr_dst_offset,
776 &dev_attr_leap_seconds,
777 &dev_attr_stp_online,
778 &dev_attr_stratum,
779 &dev_attr_time_offset,
780 &dev_attr_time_zone_offset,
781 &dev_attr_timing_mode,
782 &dev_attr_timing_state,
783 NULL
786 static int __init stp_init_sysfs(void)
788 struct device_attribute **attr;
789 int rc;
791 rc = subsys_system_register(&stp_subsys, NULL);
792 if (rc)
793 goto out;
794 for (attr = stp_attributes; *attr; attr++) {
795 rc = device_create_file(stp_subsys.dev_root, *attr);
796 if (rc)
797 goto out_unreg;
799 return 0;
800 out_unreg:
801 for (; attr >= stp_attributes; attr--)
802 device_remove_file(stp_subsys.dev_root, *attr);
803 bus_unregister(&stp_subsys);
804 out:
805 return rc;
808 device_initcall(stp_init_sysfs);