| .. | .. |
|---|
| 41 | 41 | #include <linux/gfp.h> |
|---|
| 42 | 42 | #include <linux/kprobes.h> |
|---|
| 43 | 43 | #include <linux/uaccess.h> |
|---|
| 44 | +#include <vdso/vsyscall.h> |
|---|
| 45 | +#include <vdso/clocksource.h> |
|---|
| 46 | +#include <vdso/helpers.h> |
|---|
| 44 | 47 | #include <asm/facility.h> |
|---|
| 45 | 48 | #include <asm/delay.h> |
|---|
| 46 | 49 | #include <asm/div64.h> |
|---|
| .. | .. |
|---|
| 84 | 87 | |
|---|
| 85 | 88 | /* Initialize TOD steering parameters */ |
|---|
| 86 | 89 | tod_steering_end = *(unsigned long long *) &tod_clock_base[1]; |
|---|
| 87 | | - vdso_data->ts_end = tod_steering_end; |
|---|
| 90 | + vdso_data->arch_data.tod_steering_end = tod_steering_end; |
|---|
| 88 | 91 | |
|---|
| 89 | 92 | if (!test_facility(28)) |
|---|
| 90 | 93 | return; |
|---|
| .. | .. |
|---|
| 109 | 112 | return tod_to_ns(get_tod_clock_monotonic()); |
|---|
| 110 | 113 | } |
|---|
| 111 | 114 | NOKPROBE_SYMBOL(sched_clock); |
|---|
| 112 | | - |
|---|
| 113 | | -/* |
|---|
| 114 | | - * Monotonic_clock - returns # of nanoseconds passed since time_init() |
|---|
| 115 | | - */ |
|---|
| 116 | | -unsigned long long monotonic_clock(void) |
|---|
| 117 | | -{ |
|---|
| 118 | | - return sched_clock(); |
|---|
| 119 | | -} |
|---|
| 120 | | -EXPORT_SYMBOL(monotonic_clock); |
|---|
| 121 | 115 | |
|---|
| 122 | 116 | static void ext_to_timespec64(unsigned char *clk, struct timespec64 *xt) |
|---|
| 123 | 117 | { |
|---|
| .. | .. |
|---|
| 246 | 240 | preempt_disable(); /* protect from changes to steering parameters */ |
|---|
| 247 | 241 | now = get_tod_clock(); |
|---|
| 248 | 242 | adj = tod_steering_end - now; |
|---|
| 249 | | - if (unlikely((s64) adj >= 0)) |
|---|
| 243 | + if (unlikely((s64) adj > 0)) |
|---|
| 250 | 244 | /* |
|---|
| 251 | 245 | * manually steer by 1 cycle every 2^16 cycles. This |
|---|
| 252 | 246 | * corresponds to shifting the tod delta by 15. 1s is |
|---|
| .. | .. |
|---|
| 262 | 256 | .name = "tod", |
|---|
| 263 | 257 | .rating = 400, |
|---|
| 264 | 258 | .read = read_tod_clock, |
|---|
| 265 | | - .mask = -1ULL, |
|---|
| 259 | + .mask = CLOCKSOURCE_MASK(64), |
|---|
| 266 | 260 | .mult = 1000, |
|---|
| 267 | 261 | .shift = 12, |
|---|
| 268 | 262 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
|---|
| 263 | + .vdso_clock_mode = VDSO_CLOCKMODE_TOD, |
|---|
| 269 | 264 | }; |
|---|
| 270 | 265 | |
|---|
| 271 | 266 | struct clocksource * __init clocksource_default_clock(void) |
|---|
| 272 | 267 | { |
|---|
| 273 | 268 | return &clocksource_tod; |
|---|
| 274 | | -} |
|---|
| 275 | | - |
|---|
| 276 | | -void update_vsyscall(struct timekeeper *tk) |
|---|
| 277 | | -{ |
|---|
| 278 | | - u64 nsecps; |
|---|
| 279 | | - |
|---|
| 280 | | - if (tk->tkr_mono.clock != &clocksource_tod) |
|---|
| 281 | | - return; |
|---|
| 282 | | - |
|---|
| 283 | | - /* Make userspace gettimeofday spin until we're done. */ |
|---|
| 284 | | - ++vdso_data->tb_update_count; |
|---|
| 285 | | - smp_wmb(); |
|---|
| 286 | | - vdso_data->xtime_tod_stamp = tk->tkr_mono.cycle_last; |
|---|
| 287 | | - vdso_data->xtime_clock_sec = tk->xtime_sec; |
|---|
| 288 | | - vdso_data->xtime_clock_nsec = tk->tkr_mono.xtime_nsec; |
|---|
| 289 | | - vdso_data->wtom_clock_sec = |
|---|
| 290 | | - tk->xtime_sec + tk->wall_to_monotonic.tv_sec; |
|---|
| 291 | | - vdso_data->wtom_clock_nsec = tk->tkr_mono.xtime_nsec + |
|---|
| 292 | | - + ((u64) tk->wall_to_monotonic.tv_nsec << tk->tkr_mono.shift); |
|---|
| 293 | | - nsecps = (u64) NSEC_PER_SEC << tk->tkr_mono.shift; |
|---|
| 294 | | - while (vdso_data->wtom_clock_nsec >= nsecps) { |
|---|
| 295 | | - vdso_data->wtom_clock_nsec -= nsecps; |
|---|
| 296 | | - vdso_data->wtom_clock_sec++; |
|---|
| 297 | | - } |
|---|
| 298 | | - |
|---|
| 299 | | - vdso_data->xtime_coarse_sec = tk->xtime_sec; |
|---|
| 300 | | - vdso_data->xtime_coarse_nsec = |
|---|
| 301 | | - (long)(tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift); |
|---|
| 302 | | - vdso_data->wtom_coarse_sec = |
|---|
| 303 | | - vdso_data->xtime_coarse_sec + tk->wall_to_monotonic.tv_sec; |
|---|
| 304 | | - vdso_data->wtom_coarse_nsec = |
|---|
| 305 | | - vdso_data->xtime_coarse_nsec + tk->wall_to_monotonic.tv_nsec; |
|---|
| 306 | | - while (vdso_data->wtom_coarse_nsec >= NSEC_PER_SEC) { |
|---|
| 307 | | - vdso_data->wtom_coarse_nsec -= NSEC_PER_SEC; |
|---|
| 308 | | - vdso_data->wtom_coarse_sec++; |
|---|
| 309 | | - } |
|---|
| 310 | | - |
|---|
| 311 | | - vdso_data->tk_mult = tk->tkr_mono.mult; |
|---|
| 312 | | - vdso_data->tk_shift = tk->tkr_mono.shift; |
|---|
| 313 | | - vdso_data->hrtimer_res = hrtimer_resolution; |
|---|
| 314 | | - smp_wmb(); |
|---|
| 315 | | - ++vdso_data->tb_update_count; |
|---|
| 316 | | -} |
|---|
| 317 | | - |
|---|
| 318 | | -extern struct timezone sys_tz; |
|---|
| 319 | | - |
|---|
| 320 | | -void update_vsyscall_tz(void) |
|---|
| 321 | | -{ |
|---|
| 322 | | - vdso_data->tz_minuteswest = sys_tz.tz_minuteswest; |
|---|
| 323 | | - vdso_data->tz_dsttime = sys_tz.tz_dsttime; |
|---|
| 324 | 269 | } |
|---|
| 325 | 270 | |
|---|
| 326 | 271 | /* |
|---|
| .. | .. |
|---|
| 351 | 296 | } |
|---|
| 352 | 297 | |
|---|
| 353 | 298 | static DEFINE_PER_CPU(atomic_t, clock_sync_word); |
|---|
| 354 | | -static DEFINE_MUTEX(clock_sync_mutex); |
|---|
| 299 | +static DEFINE_MUTEX(stp_mutex); |
|---|
| 355 | 300 | static unsigned long clock_sync_flags; |
|---|
| 356 | 301 | |
|---|
| 357 | 302 | #define CLOCK_SYNC_HAS_STP 0 |
|---|
| .. | .. |
|---|
| 441 | 386 | /* Epoch overflow */ |
|---|
| 442 | 387 | tod_clock_base[0]++; |
|---|
| 443 | 388 | /* Adjust TOD steering parameters. */ |
|---|
| 444 | | - vdso_data->tb_update_count++; |
|---|
| 445 | 389 | now = get_tod_clock(); |
|---|
| 446 | 390 | adj = tod_steering_end - now; |
|---|
| 447 | 391 | if (unlikely((s64) adj >= 0)) |
|---|
| .. | .. |
|---|
| 453 | 397 | panic("TOD clock sync offset %lli is too large to drift\n", |
|---|
| 454 | 398 | tod_steering_delta); |
|---|
| 455 | 399 | tod_steering_end = now + (abs(tod_steering_delta) << 15); |
|---|
| 456 | | - vdso_data->ts_dir = (tod_steering_delta < 0) ? 0 : 1; |
|---|
| 457 | | - vdso_data->ts_end = tod_steering_end; |
|---|
| 458 | | - vdso_data->tb_update_count++; |
|---|
| 400 | + vdso_data->arch_data.tod_steering_end = tod_steering_end; |
|---|
| 401 | + vdso_data->arch_data.tod_steering_delta = tod_steering_delta; |
|---|
| 402 | + |
|---|
| 459 | 403 | /* Update LPAR offset. */ |
|---|
| 460 | 404 | if (ptff_query(PTFF_QTO) && ptff(&qto, sizeof(qto), PTFF_QTO) == 0) |
|---|
| 461 | 405 | lpar_offset = qto.tod_epoch_difference; |
|---|
| .. | .. |
|---|
| 502 | 446 | static void *stp_page; |
|---|
| 503 | 447 | |
|---|
| 504 | 448 | static void stp_work_fn(struct work_struct *work); |
|---|
| 505 | | -static DEFINE_MUTEX(stp_work_mutex); |
|---|
| 506 | 449 | static DECLARE_WORK(stp_work, stp_work_fn); |
|---|
| 507 | 450 | static struct timer_list stp_timer; |
|---|
| 508 | 451 | |
|---|
| .. | .. |
|---|
| 612 | 555 | static int stp_sync_clock(void *data) |
|---|
| 613 | 556 | { |
|---|
| 614 | 557 | struct clock_sync_data *sync = data; |
|---|
| 615 | | - unsigned long long clock_delta; |
|---|
| 558 | + unsigned long long clock_delta, flags; |
|---|
| 616 | 559 | static int first; |
|---|
| 617 | 560 | int rc; |
|---|
| 618 | 561 | |
|---|
| .. | .. |
|---|
| 625 | 568 | if (stp_info.todoff[0] || stp_info.todoff[1] || |
|---|
| 626 | 569 | stp_info.todoff[2] || stp_info.todoff[3] || |
|---|
| 627 | 570 | stp_info.tmd != 2) { |
|---|
| 571 | + flags = vdso_update_begin(); |
|---|
| 628 | 572 | rc = chsc_sstpc(stp_page, STP_OP_SYNC, 0, |
|---|
| 629 | 573 | &clock_delta); |
|---|
| 630 | 574 | if (rc == 0) { |
|---|
| .. | .. |
|---|
| 634 | 578 | if (rc == 0 && stp_info.tmd != 2) |
|---|
| 635 | 579 | rc = -EAGAIN; |
|---|
| 636 | 580 | } |
|---|
| 581 | + vdso_update_end(flags); |
|---|
| 637 | 582 | } |
|---|
| 638 | 583 | sync->in_sync = rc ? -EAGAIN : 1; |
|---|
| 639 | 584 | xchg(&first, 0); |
|---|
| .. | .. |
|---|
| 653 | 598 | return 0; |
|---|
| 654 | 599 | } |
|---|
| 655 | 600 | |
|---|
| 601 | +static int stp_clear_leap(void) |
|---|
| 602 | +{ |
|---|
| 603 | + struct __kernel_timex txc; |
|---|
| 604 | + int ret; |
|---|
| 605 | + |
|---|
| 606 | + memset(&txc, 0, sizeof(txc)); |
|---|
| 607 | + |
|---|
| 608 | + ret = do_adjtimex(&txc); |
|---|
| 609 | + if (ret < 0) |
|---|
| 610 | + return ret; |
|---|
| 611 | + |
|---|
| 612 | + txc.modes = ADJ_STATUS; |
|---|
| 613 | + txc.status &= ~(STA_INS|STA_DEL); |
|---|
| 614 | + return do_adjtimex(&txc); |
|---|
| 615 | +} |
|---|
| 616 | + |
|---|
| 617 | +static void stp_check_leap(void) |
|---|
| 618 | +{ |
|---|
| 619 | + struct stp_stzi stzi; |
|---|
| 620 | + struct stp_lsoib *lsoib = &stzi.lsoib; |
|---|
| 621 | + struct __kernel_timex txc; |
|---|
| 622 | + int64_t timediff; |
|---|
| 623 | + int leapdiff, ret; |
|---|
| 624 | + |
|---|
| 625 | + if (!stp_info.lu || !check_sync_clock()) { |
|---|
| 626 | + /* |
|---|
| 627 | + * Either a scheduled leap second was removed by the operator, |
|---|
| 628 | + * or STP is out of sync. In both cases, clear the leap second |
|---|
| 629 | + * kernel flags. |
|---|
| 630 | + */ |
|---|
| 631 | + if (stp_clear_leap() < 0) |
|---|
| 632 | + pr_err("failed to clear leap second flags\n"); |
|---|
| 633 | + return; |
|---|
| 634 | + } |
|---|
| 635 | + |
|---|
| 636 | + if (chsc_stzi(stp_page, &stzi, sizeof(stzi))) { |
|---|
| 637 | + pr_err("stzi failed\n"); |
|---|
| 638 | + return; |
|---|
| 639 | + } |
|---|
| 640 | + |
|---|
| 641 | + timediff = tod_to_ns(lsoib->nlsout - get_tod_clock()) / NSEC_PER_SEC; |
|---|
| 642 | + leapdiff = lsoib->nlso - lsoib->also; |
|---|
| 643 | + |
|---|
| 644 | + if (leapdiff != 1 && leapdiff != -1) { |
|---|
| 645 | + pr_err("Cannot schedule %d leap seconds\n", leapdiff); |
|---|
| 646 | + return; |
|---|
| 647 | + } |
|---|
| 648 | + |
|---|
| 649 | + if (timediff < 0) { |
|---|
| 650 | + if (stp_clear_leap() < 0) |
|---|
| 651 | + pr_err("failed to clear leap second flags\n"); |
|---|
| 652 | + } else if (timediff < 7200) { |
|---|
| 653 | + memset(&txc, 0, sizeof(txc)); |
|---|
| 654 | + ret = do_adjtimex(&txc); |
|---|
| 655 | + if (ret < 0) |
|---|
| 656 | + return; |
|---|
| 657 | + |
|---|
| 658 | + txc.modes = ADJ_STATUS; |
|---|
| 659 | + if (leapdiff > 0) |
|---|
| 660 | + txc.status |= STA_INS; |
|---|
| 661 | + else |
|---|
| 662 | + txc.status |= STA_DEL; |
|---|
| 663 | + ret = do_adjtimex(&txc); |
|---|
| 664 | + if (ret < 0) |
|---|
| 665 | + pr_err("failed to set leap second flags\n"); |
|---|
| 666 | + /* arm Timer to clear leap second flags */ |
|---|
| 667 | + mod_timer(&stp_timer, jiffies + msecs_to_jiffies(14400 * MSEC_PER_SEC)); |
|---|
| 668 | + } else { |
|---|
| 669 | + /* The day the leap second is scheduled for hasn't been reached. Retry |
|---|
| 670 | + * in one hour. |
|---|
| 671 | + */ |
|---|
| 672 | + mod_timer(&stp_timer, jiffies + msecs_to_jiffies(3600 * MSEC_PER_SEC)); |
|---|
| 673 | + } |
|---|
| 674 | +} |
|---|
| 675 | + |
|---|
| 656 | 676 | /* |
|---|
| 657 | 677 | * STP work. Check for the STP state and take over the clock |
|---|
| 658 | 678 | * synchronization if the STP clock source is usable. |
|---|
| .. | .. |
|---|
| 663 | 683 | int rc; |
|---|
| 664 | 684 | |
|---|
| 665 | 685 | /* prevent multiple execution. */ |
|---|
| 666 | | - mutex_lock(&stp_work_mutex); |
|---|
| 686 | + mutex_lock(&stp_mutex); |
|---|
| 667 | 687 | |
|---|
| 668 | 688 | if (!stp_online) { |
|---|
| 669 | 689 | chsc_sstpc(stp_page, STP_OP_CTRL, 0x0000, NULL); |
|---|
| .. | .. |
|---|
| 671 | 691 | goto out_unlock; |
|---|
| 672 | 692 | } |
|---|
| 673 | 693 | |
|---|
| 674 | | - rc = chsc_sstpc(stp_page, STP_OP_CTRL, 0xb0e0, NULL); |
|---|
| 694 | + rc = chsc_sstpc(stp_page, STP_OP_CTRL, 0xf0e0, NULL); |
|---|
| 675 | 695 | if (rc) |
|---|
| 676 | 696 | goto out_unlock; |
|---|
| 677 | 697 | |
|---|
| .. | .. |
|---|
| 680 | 700 | goto out_unlock; |
|---|
| 681 | 701 | |
|---|
| 682 | 702 | /* Skip synchronization if the clock is already in sync. */ |
|---|
| 683 | | - if (check_sync_clock()) |
|---|
| 684 | | - goto out_unlock; |
|---|
| 685 | | - |
|---|
| 686 | | - memset(&stp_sync, 0, sizeof(stp_sync)); |
|---|
| 687 | | - cpus_read_lock(); |
|---|
| 688 | | - atomic_set(&stp_sync.cpus, num_online_cpus() - 1); |
|---|
| 689 | | - stop_machine_cpuslocked(stp_sync_clock, &stp_sync, cpu_online_mask); |
|---|
| 690 | | - cpus_read_unlock(); |
|---|
| 703 | + if (!check_sync_clock()) { |
|---|
| 704 | + memset(&stp_sync, 0, sizeof(stp_sync)); |
|---|
| 705 | + cpus_read_lock(); |
|---|
| 706 | + atomic_set(&stp_sync.cpus, num_online_cpus() - 1); |
|---|
| 707 | + stop_machine_cpuslocked(stp_sync_clock, &stp_sync, cpu_online_mask); |
|---|
| 708 | + cpus_read_unlock(); |
|---|
| 709 | + } |
|---|
| 691 | 710 | |
|---|
| 692 | 711 | if (!check_sync_clock()) |
|---|
| 693 | 712 | /* |
|---|
| 694 | 713 | * There is a usable clock but the synchonization failed. |
|---|
| 695 | 714 | * Retry after a second. |
|---|
| 696 | 715 | */ |
|---|
| 697 | | - mod_timer(&stp_timer, jiffies + HZ); |
|---|
| 716 | + mod_timer(&stp_timer, jiffies + msecs_to_jiffies(MSEC_PER_SEC)); |
|---|
| 717 | + else if (stp_info.lu) |
|---|
| 718 | + stp_check_leap(); |
|---|
| 698 | 719 | |
|---|
| 699 | 720 | out_unlock: |
|---|
| 700 | | - mutex_unlock(&stp_work_mutex); |
|---|
| 721 | + mutex_unlock(&stp_mutex); |
|---|
| 701 | 722 | } |
|---|
| 702 | 723 | |
|---|
| 703 | 724 | /* |
|---|
| .. | .. |
|---|
| 708 | 729 | .dev_name = "stp", |
|---|
| 709 | 730 | }; |
|---|
| 710 | 731 | |
|---|
| 711 | | -static ssize_t stp_ctn_id_show(struct device *dev, |
|---|
| 732 | +static ssize_t ctn_id_show(struct device *dev, |
|---|
| 712 | 733 | struct device_attribute *attr, |
|---|
| 713 | 734 | char *buf) |
|---|
| 714 | 735 | { |
|---|
| 715 | 736 | ssize_t ret = -ENODATA; |
|---|
| 716 | 737 | |
|---|
| 717 | | - mutex_lock(&stp_work_mutex); |
|---|
| 738 | + mutex_lock(&stp_mutex); |
|---|
| 718 | 739 | if (stpinfo_valid()) |
|---|
| 719 | 740 | ret = sprintf(buf, "%016llx\n", |
|---|
| 720 | 741 | *(unsigned long long *) stp_info.ctnid); |
|---|
| 721 | | - mutex_unlock(&stp_work_mutex); |
|---|
| 742 | + mutex_unlock(&stp_mutex); |
|---|
| 722 | 743 | return ret; |
|---|
| 723 | 744 | } |
|---|
| 724 | 745 | |
|---|
| 725 | | -static DEVICE_ATTR(ctn_id, 0400, stp_ctn_id_show, NULL); |
|---|
| 746 | +static DEVICE_ATTR_RO(ctn_id); |
|---|
| 726 | 747 | |
|---|
| 727 | | -static ssize_t stp_ctn_type_show(struct device *dev, |
|---|
| 748 | +static ssize_t ctn_type_show(struct device *dev, |
|---|
| 728 | 749 | struct device_attribute *attr, |
|---|
| 729 | 750 | char *buf) |
|---|
| 730 | 751 | { |
|---|
| 731 | 752 | ssize_t ret = -ENODATA; |
|---|
| 732 | 753 | |
|---|
| 733 | | - mutex_lock(&stp_work_mutex); |
|---|
| 754 | + mutex_lock(&stp_mutex); |
|---|
| 734 | 755 | if (stpinfo_valid()) |
|---|
| 735 | 756 | ret = sprintf(buf, "%i\n", stp_info.ctn); |
|---|
| 736 | | - mutex_unlock(&stp_work_mutex); |
|---|
| 757 | + mutex_unlock(&stp_mutex); |
|---|
| 737 | 758 | return ret; |
|---|
| 738 | 759 | } |
|---|
| 739 | 760 | |
|---|
| 740 | | -static DEVICE_ATTR(ctn_type, 0400, stp_ctn_type_show, NULL); |
|---|
| 761 | +static DEVICE_ATTR_RO(ctn_type); |
|---|
| 741 | 762 | |
|---|
| 742 | | -static ssize_t stp_dst_offset_show(struct device *dev, |
|---|
| 763 | +static ssize_t dst_offset_show(struct device *dev, |
|---|
| 743 | 764 | struct device_attribute *attr, |
|---|
| 744 | 765 | char *buf) |
|---|
| 745 | 766 | { |
|---|
| 746 | 767 | ssize_t ret = -ENODATA; |
|---|
| 747 | 768 | |
|---|
| 748 | | - mutex_lock(&stp_work_mutex); |
|---|
| 769 | + mutex_lock(&stp_mutex); |
|---|
| 749 | 770 | if (stpinfo_valid() && (stp_info.vbits & 0x2000)) |
|---|
| 750 | 771 | ret = sprintf(buf, "%i\n", (int)(s16) stp_info.dsto); |
|---|
| 751 | | - mutex_unlock(&stp_work_mutex); |
|---|
| 772 | + mutex_unlock(&stp_mutex); |
|---|
| 752 | 773 | return ret; |
|---|
| 753 | 774 | } |
|---|
| 754 | 775 | |
|---|
| 755 | | -static DEVICE_ATTR(dst_offset, 0400, stp_dst_offset_show, NULL); |
|---|
| 776 | +static DEVICE_ATTR_RO(dst_offset); |
|---|
| 756 | 777 | |
|---|
| 757 | | -static ssize_t stp_leap_seconds_show(struct device *dev, |
|---|
| 778 | +static ssize_t leap_seconds_show(struct device *dev, |
|---|
| 758 | 779 | struct device_attribute *attr, |
|---|
| 759 | 780 | char *buf) |
|---|
| 760 | 781 | { |
|---|
| 761 | 782 | ssize_t ret = -ENODATA; |
|---|
| 762 | 783 | |
|---|
| 763 | | - mutex_lock(&stp_work_mutex); |
|---|
| 784 | + mutex_lock(&stp_mutex); |
|---|
| 764 | 785 | if (stpinfo_valid() && (stp_info.vbits & 0x8000)) |
|---|
| 765 | 786 | ret = sprintf(buf, "%i\n", (int)(s16) stp_info.leaps); |
|---|
| 766 | | - mutex_unlock(&stp_work_mutex); |
|---|
| 787 | + mutex_unlock(&stp_mutex); |
|---|
| 767 | 788 | return ret; |
|---|
| 768 | 789 | } |
|---|
| 769 | 790 | |
|---|
| 770 | | -static DEVICE_ATTR(leap_seconds, 0400, stp_leap_seconds_show, NULL); |
|---|
| 791 | +static DEVICE_ATTR_RO(leap_seconds); |
|---|
| 771 | 792 | |
|---|
| 772 | | -static ssize_t stp_stratum_show(struct device *dev, |
|---|
| 793 | +static ssize_t leap_seconds_scheduled_show(struct device *dev, |
|---|
| 794 | + struct device_attribute *attr, |
|---|
| 795 | + char *buf) |
|---|
| 796 | +{ |
|---|
| 797 | + struct stp_stzi stzi; |
|---|
| 798 | + ssize_t ret; |
|---|
| 799 | + |
|---|
| 800 | + mutex_lock(&stp_mutex); |
|---|
| 801 | + if (!stpinfo_valid() || !(stp_info.vbits & 0x8000) || !stp_info.lu) { |
|---|
| 802 | + mutex_unlock(&stp_mutex); |
|---|
| 803 | + return -ENODATA; |
|---|
| 804 | + } |
|---|
| 805 | + |
|---|
| 806 | + ret = chsc_stzi(stp_page, &stzi, sizeof(stzi)); |
|---|
| 807 | + mutex_unlock(&stp_mutex); |
|---|
| 808 | + if (ret < 0) |
|---|
| 809 | + return ret; |
|---|
| 810 | + |
|---|
| 811 | + if (!stzi.lsoib.p) |
|---|
| 812 | + return sprintf(buf, "0,0\n"); |
|---|
| 813 | + |
|---|
| 814 | + return sprintf(buf, "%llu,%d\n", |
|---|
| 815 | + tod_to_ns(stzi.lsoib.nlsout - TOD_UNIX_EPOCH) / NSEC_PER_SEC, |
|---|
| 816 | + stzi.lsoib.nlso - stzi.lsoib.also); |
|---|
| 817 | +} |
|---|
| 818 | + |
|---|
| 819 | +static DEVICE_ATTR_RO(leap_seconds_scheduled); |
|---|
| 820 | + |
|---|
| 821 | +static ssize_t stratum_show(struct device *dev, |
|---|
| 773 | 822 | struct device_attribute *attr, |
|---|
| 774 | 823 | char *buf) |
|---|
| 775 | 824 | { |
|---|
| 776 | 825 | ssize_t ret = -ENODATA; |
|---|
| 777 | 826 | |
|---|
| 778 | | - mutex_lock(&stp_work_mutex); |
|---|
| 827 | + mutex_lock(&stp_mutex); |
|---|
| 779 | 828 | if (stpinfo_valid()) |
|---|
| 780 | 829 | ret = sprintf(buf, "%i\n", (int)(s16) stp_info.stratum); |
|---|
| 781 | | - mutex_unlock(&stp_work_mutex); |
|---|
| 830 | + mutex_unlock(&stp_mutex); |
|---|
| 782 | 831 | return ret; |
|---|
| 783 | 832 | } |
|---|
| 784 | 833 | |
|---|
| 785 | | -static DEVICE_ATTR(stratum, 0400, stp_stratum_show, NULL); |
|---|
| 834 | +static DEVICE_ATTR_RO(stratum); |
|---|
| 786 | 835 | |
|---|
| 787 | | -static ssize_t stp_time_offset_show(struct device *dev, |
|---|
| 836 | +static ssize_t time_offset_show(struct device *dev, |
|---|
| 788 | 837 | struct device_attribute *attr, |
|---|
| 789 | 838 | char *buf) |
|---|
| 790 | 839 | { |
|---|
| 791 | 840 | ssize_t ret = -ENODATA; |
|---|
| 792 | 841 | |
|---|
| 793 | | - mutex_lock(&stp_work_mutex); |
|---|
| 842 | + mutex_lock(&stp_mutex); |
|---|
| 794 | 843 | if (stpinfo_valid() && (stp_info.vbits & 0x0800)) |
|---|
| 795 | 844 | ret = sprintf(buf, "%i\n", (int) stp_info.tto); |
|---|
| 796 | | - mutex_unlock(&stp_work_mutex); |
|---|
| 845 | + mutex_unlock(&stp_mutex); |
|---|
| 797 | 846 | return ret; |
|---|
| 798 | 847 | } |
|---|
| 799 | 848 | |
|---|
| 800 | | -static DEVICE_ATTR(time_offset, 0400, stp_time_offset_show, NULL); |
|---|
| 849 | +static DEVICE_ATTR_RO(time_offset); |
|---|
| 801 | 850 | |
|---|
| 802 | | -static ssize_t stp_time_zone_offset_show(struct device *dev, |
|---|
| 851 | +static ssize_t time_zone_offset_show(struct device *dev, |
|---|
| 803 | 852 | struct device_attribute *attr, |
|---|
| 804 | 853 | char *buf) |
|---|
| 805 | 854 | { |
|---|
| 806 | 855 | ssize_t ret = -ENODATA; |
|---|
| 807 | 856 | |
|---|
| 808 | | - mutex_lock(&stp_work_mutex); |
|---|
| 857 | + mutex_lock(&stp_mutex); |
|---|
| 809 | 858 | if (stpinfo_valid() && (stp_info.vbits & 0x4000)) |
|---|
| 810 | 859 | ret = sprintf(buf, "%i\n", (int)(s16) stp_info.tzo); |
|---|
| 811 | | - mutex_unlock(&stp_work_mutex); |
|---|
| 860 | + mutex_unlock(&stp_mutex); |
|---|
| 812 | 861 | return ret; |
|---|
| 813 | 862 | } |
|---|
| 814 | 863 | |
|---|
| 815 | | -static DEVICE_ATTR(time_zone_offset, 0400, |
|---|
| 816 | | - stp_time_zone_offset_show, NULL); |
|---|
| 864 | +static DEVICE_ATTR_RO(time_zone_offset); |
|---|
| 817 | 865 | |
|---|
| 818 | | -static ssize_t stp_timing_mode_show(struct device *dev, |
|---|
| 866 | +static ssize_t timing_mode_show(struct device *dev, |
|---|
| 819 | 867 | struct device_attribute *attr, |
|---|
| 820 | 868 | char *buf) |
|---|
| 821 | 869 | { |
|---|
| 822 | 870 | ssize_t ret = -ENODATA; |
|---|
| 823 | 871 | |
|---|
| 824 | | - mutex_lock(&stp_work_mutex); |
|---|
| 872 | + mutex_lock(&stp_mutex); |
|---|
| 825 | 873 | if (stpinfo_valid()) |
|---|
| 826 | 874 | ret = sprintf(buf, "%i\n", stp_info.tmd); |
|---|
| 827 | | - mutex_unlock(&stp_work_mutex); |
|---|
| 875 | + mutex_unlock(&stp_mutex); |
|---|
| 828 | 876 | return ret; |
|---|
| 829 | 877 | } |
|---|
| 830 | 878 | |
|---|
| 831 | | -static DEVICE_ATTR(timing_mode, 0400, stp_timing_mode_show, NULL); |
|---|
| 879 | +static DEVICE_ATTR_RO(timing_mode); |
|---|
| 832 | 880 | |
|---|
| 833 | | -static ssize_t stp_timing_state_show(struct device *dev, |
|---|
| 881 | +static ssize_t timing_state_show(struct device *dev, |
|---|
| 834 | 882 | struct device_attribute *attr, |
|---|
| 835 | 883 | char *buf) |
|---|
| 836 | 884 | { |
|---|
| 837 | 885 | ssize_t ret = -ENODATA; |
|---|
| 838 | 886 | |
|---|
| 839 | | - mutex_lock(&stp_work_mutex); |
|---|
| 887 | + mutex_lock(&stp_mutex); |
|---|
| 840 | 888 | if (stpinfo_valid()) |
|---|
| 841 | 889 | ret = sprintf(buf, "%i\n", stp_info.tst); |
|---|
| 842 | | - mutex_unlock(&stp_work_mutex); |
|---|
| 890 | + mutex_unlock(&stp_mutex); |
|---|
| 843 | 891 | return ret; |
|---|
| 844 | 892 | } |
|---|
| 845 | 893 | |
|---|
| 846 | | -static DEVICE_ATTR(timing_state, 0400, stp_timing_state_show, NULL); |
|---|
| 894 | +static DEVICE_ATTR_RO(timing_state); |
|---|
| 847 | 895 | |
|---|
| 848 | | -static ssize_t stp_online_show(struct device *dev, |
|---|
| 896 | +static ssize_t online_show(struct device *dev, |
|---|
| 849 | 897 | struct device_attribute *attr, |
|---|
| 850 | 898 | char *buf) |
|---|
| 851 | 899 | { |
|---|
| 852 | 900 | return sprintf(buf, "%i\n", stp_online); |
|---|
| 853 | 901 | } |
|---|
| 854 | 902 | |
|---|
| 855 | | -static ssize_t stp_online_store(struct device *dev, |
|---|
| 903 | +static ssize_t online_store(struct device *dev, |
|---|
| 856 | 904 | struct device_attribute *attr, |
|---|
| 857 | 905 | const char *buf, size_t count) |
|---|
| 858 | 906 | { |
|---|
| .. | .. |
|---|
| 863 | 911 | return -EINVAL; |
|---|
| 864 | 912 | if (!test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags)) |
|---|
| 865 | 913 | return -EOPNOTSUPP; |
|---|
| 866 | | - mutex_lock(&clock_sync_mutex); |
|---|
| 914 | + mutex_lock(&stp_mutex); |
|---|
| 867 | 915 | stp_online = value; |
|---|
| 868 | 916 | if (stp_online) |
|---|
| 869 | 917 | set_bit(CLOCK_SYNC_STP, &clock_sync_flags); |
|---|
| 870 | 918 | else |
|---|
| 871 | 919 | clear_bit(CLOCK_SYNC_STP, &clock_sync_flags); |
|---|
| 872 | 920 | queue_work(time_sync_wq, &stp_work); |
|---|
| 873 | | - mutex_unlock(&clock_sync_mutex); |
|---|
| 921 | + mutex_unlock(&stp_mutex); |
|---|
| 874 | 922 | return count; |
|---|
| 875 | 923 | } |
|---|
| 876 | 924 | |
|---|
| .. | .. |
|---|
| 878 | 926 | * Can't use DEVICE_ATTR because the attribute should be named |
|---|
| 879 | 927 | * stp/online but dev_attr_online already exists in this file .. |
|---|
| 880 | 928 | */ |
|---|
| 881 | | -static struct device_attribute dev_attr_stp_online = { |
|---|
| 882 | | - .attr = { .name = "online", .mode = 0600 }, |
|---|
| 883 | | - .show = stp_online_show, |
|---|
| 884 | | - .store = stp_online_store, |
|---|
| 885 | | -}; |
|---|
| 929 | +static DEVICE_ATTR_RW(online); |
|---|
| 886 | 930 | |
|---|
| 887 | 931 | static struct device_attribute *stp_attributes[] = { |
|---|
| 888 | 932 | &dev_attr_ctn_id, |
|---|
| 889 | 933 | &dev_attr_ctn_type, |
|---|
| 890 | 934 | &dev_attr_dst_offset, |
|---|
| 891 | 935 | &dev_attr_leap_seconds, |
|---|
| 892 | | - &dev_attr_stp_online, |
|---|
| 936 | + &dev_attr_online, |
|---|
| 937 | + &dev_attr_leap_seconds_scheduled, |
|---|
| 893 | 938 | &dev_attr_stratum, |
|---|
| 894 | 939 | &dev_attr_time_offset, |
|---|
| 895 | 940 | &dev_attr_time_zone_offset, |
|---|