ptp: IEEE 1588 hardware clock support
Subsystems (17)
Richard Cochran
maintainerv10 cover ptp: IEEE 1588 hardware clock support
Here is version 10 of the PHC patch series. We missed the boat for 2.6.38, but I hope this can be merged for the next one.
Reviewers: I think its done. How can I get this merged?
Arch maintainers (arm, blackfin, powerpc, x86): I have added you on CC in the hope of getting your acks for the new syscall.
Thanks,
Richard
* Patch ChangeLog
** v10
*** posix clocks
- removed the (previously implied) default functions from the k_clocks
- made the ts parameter 'const' in clock_set functions
*** ptp hardware clocks
- updated to changed PPS kernel API
* Introduction
The aim of this patch set is to add support for PTP Hardware Clocks (PHCs) into the Linux kernel.
The first eleven patches provide infrastructure supporting dynamic POSIX clock devices. This new code will be useful for other kinds of new clocks, not just PHCs.
The last four patches implement the PHC code.
Support for obtaining timestamps from a PHC already exists via the SO_TIMESTAMPING socket option, integrated in kernel version 2.6.30. This patch set completes the picture by allow user space programs to adjust the PHC and to control its ancillary features.
* Previous Discussions
This patch set previously appeared on the netdev list. Since V5 of the character device patch set, the discussion has moved to the lkml.
- IEEE 1588 hardware clock support [V5]
http://lkml.org/lkml/2010/8/16/90
- POSIX clock tuning syscall with static clock ids
http://lkml.org/lkml/2010/8/23/49
- POSIX clock tuning syscall with dynamic clock ids
http://lkml.org/lkml/2010/9/3/119
- IEEE 1588 hardware clock support [V6]
http://lkml.org/lkml/2010/9/23/310
- Dynamic clock devices [RFC]
http://lkml.org/lkml/2010/11/4/290
- IEEE 1588 hardware clock support [V7]
http://lkml.org/lkml/2010/12/16/195
- IEEE 1588 hardware clock support [V8]
http://lkml.org/lkml/2010/12/31/128
- IEEE 1588 hardware clock support [V9]
http://lkml.org/lkml/2011/1/13/65
John Stultz (1):
time: Introduce timekeeping_inject_offset
Richard Cochran (14):
time: Correct the *settime* parameters
ntp: add ADJ_SETOFFSET mode bit
posix clocks: introduce a syscall for clock tuning.
posix_clocks: add clock_adjtime for arm
posix_clocks: add clock_adjtime for blackfin
posix_clocks: add clock_adjtime for powerpc
posix_clocks: add clock_adjtime for x86
posix clocks: cleanup the CLOCK_DISPTACH macro
posix clocks: remove useless default methods
posix clocks: introduce dynamic clocks
ptp: Added a brand new class driver for ptp clocks.
ptp: Added a clock that uses the eTSEC found on the MPC85xx.
ptp: Added a clock driver for the IXP46x.
ptp: Added a clock driver for the National Semiconductor PHYTER.
Documentation/ABI/testing/sysfs-ptp | 98 +++ Documentation/powerpc/dts-bindings/fsl/tsec.txt | 57 ++ Documentation/ptp/ptp.txt | 89 +++ Documentation/ptp/testptp.c | 352 +++++++++ Documentation/ptp/testptp.mk | 33 + arch/arm/include/asm/unistd.h | 1 + arch/arm/kernel/calls.S | 1 + arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h | 78 ++ arch/blackfin/include/asm/unistd.h | 3 +- arch/blackfin/mach-common/entry.S | 1 + arch/powerpc/boot/dts/mpc8313erdb.dts | 14 + arch/powerpc/boot/dts/mpc8572ds.dts | 14 + arch/powerpc/boot/dts/p2020ds.dts | 14 + arch/powerpc/boot/dts/p2020rdb.dts | 14 + arch/powerpc/include/asm/systbl.h | 1 + arch/powerpc/include/asm/unistd.h | 3 +- arch/x86/ia32/ia32entry.S | 1 + arch/x86/include/asm/unistd_32.h | 3 +- arch/x86/include/asm/unistd_64.h | 2 + arch/x86/kernel/syscall_table_32.S | 1 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/char/mmtimer.c | 3 +- drivers/net/Makefile | 1 + drivers/net/arm/ixp4xx_eth.c | 192 +++++- drivers/net/gianfar_ptp.c | 448 +++++++++++ drivers/net/gianfar_ptp_reg.h | 113 +++ drivers/net/phy/Kconfig | 29 + drivers/net/phy/Makefile | 1 + drivers/net/phy/dp83640.c | 896 +++++++++++++++++++++++ drivers/net/phy/dp83640_reg.h | 261 +++++++ drivers/ptp/Kconfig | 53 ++ drivers/ptp/Makefile | 7 + drivers/ptp/ptp_chardev.c | 144 ++++ drivers/ptp/ptp_clock.c | 315 ++++++++ drivers/ptp/ptp_ixp46x.c | 332 +++++++++ drivers/ptp/ptp_private.h | 85 +++ drivers/ptp/ptp_sysfs.c | 226 ++++++ include/linux/Kbuild | 1 + include/linux/posix-clock.h | 150 ++++ include/linux/posix-timers.h | 28 +- include/linux/ptp_clock.h | 79 ++ include/linux/ptp_clock_kernel.h | 141 ++++ include/linux/security.h | 9 +- include/linux/syscalls.h | 2 + include/linux/time.h | 8 +- include/linux/timex.h | 3 +- kernel/compat.c | 136 +++-- kernel/posix-cpu-timers.c | 6 + kernel/posix-timers.c | 245 ++++--- kernel/time.c | 2 +- kernel/time/Makefile | 3 +- kernel/time/ntp.c | 11 + kernel/time/posix-clock-syscalls.h | 39 + kernel/time/posix-clock.c | 432 +++++++++++ kernel/time/timekeeping.c | 38 +- security/commoncap.c | 2 +- security/security.c | 2 +- 58 files changed, 5062 insertions(+), 164 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-ptp create mode 100644 Documentation/ptp/ptp.txt create mode 100644 Documentation/ptp/testptp.c create mode 100644 Documentation/ptp/testptp.mk create mode 100644 arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h create mode 100644 drivers/net/gianfar_ptp.c create mode 100644 drivers/net/gianfar_ptp_reg.h create mode 100644 drivers/net/phy/dp83640.c create mode 100644 drivers/net/phy/dp83640_reg.h create mode 100644 drivers/ptp/Kconfig create mode 100644 drivers/ptp/Makefile create mode 100644 drivers/ptp/ptp_chardev.c create mode 100644 drivers/ptp/ptp_clock.c create mode 100644 drivers/ptp/ptp_ixp46x.c create mode 100644 drivers/ptp/ptp_private.h create mode 100644 drivers/ptp/ptp_sysfs.c create mode 100644 include/linux/posix-clock.h create mode 100644 include/linux/ptp_clock.h create mode 100644 include/linux/ptp_clock_kernel.h create mode 100644 kernel/time/posix-clock-syscalls.h create mode 100644 kernel/time/posix-clock.c
John Stultz
maintainerPATCH v10 1/15 time: Introduce timekeeping_inject_offset
This adds a kernel-internal timekeeping interface to add or subtract a fixed amount from CLOCK_REALTIME. This makes it so kernel users or interfaces trying to do so do not have to read the time, then add an offset and then call settimeofday(), which adds some extra error in comparision to just simply adding the offset in the kernel timekeeping core.
--- include/linux/time.h | 1 + kernel/time/timekeeping.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 0 deletions(-)
include/linux/time.h +1 -0
@@ -168,6 +168,7 @@ extern int timekeeping_valid_for_hres(void);extern u64 timekeeping_max_deferment (void );extern void update_wall_time (void );extern void timekeeping_leap_insert (int leapsecond); +extern int timekeeping_inject_offset (struct timespec *ts);struct tms ;extern void do_sys_times (struct tms *);
kernel/time/timekeeping.c +36 -0
@@ -387,6 +387,42 @@ int do_settimeofday(struct timespec *tv)EXPORT_SYMBOL (do_settimeofday); + +/** +* timekeeping_inject_offset - Adds or subtracts from the current time. +* @tv: pointer to the timespec variable containing the offset +* +* Adds or subtracts an offset value from the current time. +*/ +int timekeeping_inject_offset (struct timespec *ts) +{ +unsigned long flags; + +if ((unsigned long )ts->tv_nsec >=NSEC_PER_SEC ) +return -EINVAL ; + +write_seqlock_irqsave (&xtime_lock, flags); + +timekeeping_forward_now (); + + xtime =timespec_add (xtime, *ts); + wall_to_monotonic =timespec_sub (wall_to_monotonic, *ts); + + timekeeper.ntp_error =0 ; +ntp_clear (); + +update_vsyscall (&xtime, &wall_to_monotonic, timekeeper.clock, + timekeeper.mult); + +write_sequnlock_irqrestore (&xtime_lock, flags); + +/* signal hrtimers about time change */ +clock_was_set (); + +return 0 ; +} +EXPORT_SYMBOL (timekeeping_inject_offset); +/** * change_clocksource - Swaps clocksources if a new one is available *
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v10 2/15 time: Correct the *settime* parameters
In reply to Richard CochranBoth settimeofday() and clock_settime() promise with a 'const' attribute not to alter the arguments passed in. This patch adds the missing 'const' attribute into the various kernel functions implementing these calls.
--- drivers/char/mmtimer.c | 2 +- include/linux/posix-timers.h | 5 +++-- include/linux/security.h | 9 +++++---- include/linux/time.h | 5 +++-- kernel/posix-timers.c | 4 ++-- kernel/time.c | 2 +- kernel/time/timekeeping.c | 2 +- security/commoncap.c | 2 +- security/security.c | 2 +- 9 files changed, 18 insertions(+), 15 deletions(-)
drivers/char/mmtimer.c +1 -1
@@ -487,7 +487,7 @@ static int sgi_clock_get(clockid_t clockid, struct timespec *tp)return 0 ; }; -static int sgi_clock_set (clockid_t clockid,struct timespec *tp) +static int sgi_clock_set (const clockid_t clockid,const struct timespec *tp) {u64 nsec;
include/linux/posix-timers.h +3 -2
@@ -69,7 +69,8 @@ struct k_itimer {struct k_clock {int res;/* in nanoseconds */ int (*clock_getres) (const clockid_t which_clock,struct timespec *tp); -int (*clock_set) (const clockid_t which_clock,struct timespec * tp); +int (*clock_set) (const clockid_t which_clock, +const struct timespec *tp);int (*clock_get) (const clockid_t which_clock,struct timespec * tp);int (*timer_create) (struct k_itimer *timer); int (*nsleep) (const clockid_t which_clock, int flags,
@@ -89,7 +90,7 @@ void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);/* error handlers for timer_create, nanosleep and settime */ int do_posix_clock_nonanosleep (const clockid_t ,int flags,struct timespec *,struct timespec __user *); -int do_posix_clock_nosettime (const clockid_t ,struct timespec *tp); +int do_posix_clock_nosettime (const clockid_t ,const struct timespec *tp);/* function to call to trigger timer event */ int posix_timer_event (struct k_itimer *timr,int si_private);
include/linux/security.h +5 -4
@@ -53,7 +53,7 @@ struct audit_krule;*/ extern int cap_capable (struct task_struct *tsk,const struct cred *cred,int cap,int audit); -extern int cap_settime (struct timespec *ts,struct timezone *tz); +extern int cap_settime (const struct timespec *ts,const struct timezone *tz);extern int cap_ptrace_access_check (struct task_struct *child,unsigned int mode);extern int cap_ptrace_traceme (struct task_struct *parent);extern int cap_capget (struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted);
@@ -1387,7 +1387,7 @@ struct security_operations {int (*quotactl) (int cmds,int type,int id,struct super_block *sb);int (*quota_on) (struct dentry *dentry);int (*syslog) (int type); -int (*settime) (struct timespec *ts,struct timezone *tz); +int (*settime) (const struct timespec *ts,const struct timezone *tz);int (*vm_enough_memory) (struct mm_struct *mm,long pages);int (*bprm_set_creds) (struct linux_binprm *bprm);
@@ -1669,7 +1669,7 @@ int security_sysctl(struct ctl_table *table, int op);int security_quotactl (int cmds,int type,int id,struct super_block *sb);int security_quota_on (struct dentry *dentry);int security_syslog (int type); -int security_settime (struct timespec *ts,struct timezone *tz); +int security_settime (const struct timespec *ts,const struct timezone *tz);int security_vm_enough_memory (long pages);int security_vm_enough_memory_mm (struct mm_struct *mm,long pages);int security_vm_enough_memory_kern (long pages);
@@ -1904,7 +1904,8 @@ static inline int security_syslog(int type)return 0 ; } -static inline int security_settime (struct timespec *ts,struct timezone *tz) +static inline int security_settime (const struct timespec *ts, +const struct timezone *tz) {return cap_settime (ts, tz); }
include/linux/time.h +3 -2
@@ -147,8 +147,9 @@ static inline u32 arch_gettimeoffset(void) { return 0; }#endif extern void do_gettimeofday (struct timeval *tv); -extern int do_settimeofday (struct timespec *tv); -extern int do_sys_settimeofday (struct timespec *tv,struct timezone *tz); +extern int do_settimeofday (const struct timespec *tv); +extern int do_sys_settimeofday (const struct timespec *tv, +const struct timezone *tz);#define do_posix_clock_monotonic_gettime (ts) ktime_get_ts(ts)extern long do_utimes (int dfd,const char __user *filename,struct timespec *times,int flags);struct itimerval ;
kernel/posix-timers.c +2 -2
@@ -192,7 +192,7 @@ static int common_clock_get(clockid_t which_clock, struct timespec *tp) }static inline int common_clock_set (const clockid_t which_clock, -struct timespec *tp) +const struct timespec *tp) {return do_sys_settimeofday (tp,NULL ); }
@@ -928,7 +928,7 @@ void exit_itimers(struct signal_struct *sig) }/* Not available / possible... functions */ -int do_posix_clock_nosettime (const clockid_t clockid,struct timespec *tp) +int do_posix_clock_nosettime (const clockid_t clockid,const struct timespec *tp) {return -EINVAL ; }
kernel/time.c +1 -1
@@ -150,7 +150,7 @@ static inline void warp_clock(void)* various programs will get confused when the clock gets warped. */ -int do_sys_settimeofday (struct timespec *tv,struct timezone *tz) +int do_sys_settimeofday (const struct timespec *tv,const struct timezone *tz) {static int firsttime =1 ;int error =0 ;
kernel/time/timekeeping.c +1 -1
@@ -353,7 +353,7 @@ EXPORT_SYMBOL(do_gettimeofday);* * Sets the time of day to the new time and update NTP and notify hrtimers */ -int do_settimeofday (struct timespec *tv) +int do_settimeofday (const struct timespec *tv) {struct timespec ts_delta;unsigned long flags;
security/commoncap.c +1 -1
@@ -93,7 +93,7 @@ int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,* Determine whether the current process may set the system clock and timezone * information, returning 0 if permission granted, -ve if denied. */ -int cap_settime (struct timespec *ts,struct timezone *tz) +int cap_settime (const struct timespec *ts,const struct timezone *tz) {if (!capable (CAP_SYS_TIME ))return -EPERM ;
security/security.c +1 -1
@@ -202,7 +202,7 @@ int security_syslog(int type)return security_ops->syslog (type); } -int security_settime (struct timespec *ts,struct timezone *tz) +int security_settime (const struct timespec *ts,const struct timezone *tz) {return security_ops->settime (ts, tz); }
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v10 3/15 ntp: add ADJ_SETOFFSET mode bit
In reply to Richard CochranThis patch adds a new mode bit into the timex structure. When set, the bit instructs the kernel to add the given time value to the current time.
--- include/linux/timex.h | 3 ++- kernel/time/ntp.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletions(-)
include/linux/timex.h +2 -1
@@ -73,7 +73,7 @@ struct timex {long tolerance;/* clock frequency tolerance (ppm) * (read only) */ -struct timeval time;/* (read only) */ +struct timeval time;/* (read only, except for ADJ_SETOFFSET) */ long tick;/* (modified) usecs between clock ticks */ long ppsfreq;/* pps frequency (scaled ppm) (ro) */
@@ -102,6 +102,7 @@ struct timex {#define ADJ_STATUS 0x0010/* clock status */ #define ADJ_TIMECONST 0x0020/* pll time constant */ #define ADJ_TAI 0x0080/* set TAI offset */ +#define ADJ_SETOFFSET 0x0100/* add 'time' to current time */ #define ADJ_MICRO 0x1000/* select microsecond resolution */ #define ADJ_NANO 0x2000/* select nanosecond resolution */ #define ADJ_TICK 0x4000/* tick value */
kernel/time/ntp.c +11 -0
@@ -646,6 +646,17 @@ int do_adjtimex(struct timex *txc)hrtimer_cancel (&leap_timer); } +if (txc->modes &ADJ_SETOFFSET ) { +struct timespec delta; +if ((unsigned long )txc->time.tv_usec >=NSEC_PER_SEC ) +return -EINVAL ; + delta.tv_sec = txc->time.tv_sec; + delta.tv_nsec = txc->time.tv_usec; +if (!(txc->modes &ADJ_NANO )) + delta.tv_nsec *=1000 ; +timekeeping_inject_offset (&delta); + } +getnstimeofday (&ts);write_seqlock_irq (&xtime_lock);
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v10 4/15 posix clocks: introduce a syscall for clock tuning.
In reply to Richard CochranA new syscall is introduced that allows tuning of a POSIX clock. The new call, clock_adjtime, takes two parameters, the clock ID and a pointer to a struct timex. Any ADJTIMEX(2) operation may be requested via this system call, but various POSIX clocks may or may not support tuning.
--- drivers/char/mmtimer.c | 1 + include/linux/posix-timers.h | 4 + include/linux/syscalls.h | 2 + kernel/compat.c | 136 +++++++++++++++++++++++++++--------------- kernel/posix-cpu-timers.c | 6 ++ kernel/posix-timers.c | 35 +++++++++++ 6 files changed, 136 insertions(+), 48 deletions(-)
drivers/char/mmtimer.c +1 -0
@@ -767,6 +767,7 @@ static struct k_clock sgi_clock = { .res = 0, .clock_set = sgi_clock_set, .clock_get = sgi_clock_get, + .clock_adj = do_posix_clock_noadjtime, .timer_create = sgi_timer_create, .nsleep = do_posix_clock_nonanosleep, .timer_set = sgi_timer_set,
include/linux/posix-timers.h +4 -0
@@ -4,6 +4,7 @@#include <linux/spinlock.h> #include <linux/list.h> #include <linux/sched.h> +#include <linux/timex.h> union cpu_time_count {cputime_t cpu;
@@ -72,6 +73,7 @@ struct k_clock {int (*clock_set) (const clockid_t which_clock,const struct timespec *tp);int (*clock_get) (const clockid_t which_clock,struct timespec * tp); +int (*clock_adj) (const clockid_t which_clock,struct timex *tx);int (*timer_create) (struct k_itimer *timer);int (*nsleep) (const clockid_t which_clock,int flags,struct timespec *,struct timespec __user *);
@@ -91,6 +93,7 @@ void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);int do_posix_clock_nonanosleep (const clockid_t ,int flags,struct timespec *,struct timespec __user *);int do_posix_clock_nosettime (const clockid_t ,const struct timespec *tp); +int do_posix_clock_noadjtime (const clockid_t ,struct timex *tx);/* function to call to trigger timer event */ int posix_timer_event (struct k_itimer *timr,int si_private);
@@ -98,6 +101,7 @@ int posix_timer_event(struct k_itimer *timr, int si_private);int posix_cpu_clock_getres (const clockid_t which_clock,struct timespec *ts);int posix_cpu_clock_get (const clockid_t which_clock,struct timespec *ts);int posix_cpu_clock_set (const clockid_t which_clock,const struct timespec *ts); +int posix_cpu_clock_adj (const clockid_t which_clock,struct timex *tx);int posix_cpu_timer_create (struct k_itimer *timer);int posix_cpu_nsleep (const clockid_t which_clock,int flags,struct timespec *rqtp,struct timespec __user *rmtp);
include/linux/syscalls.h +2 -0
@@ -311,6 +311,8 @@ asmlinkage long sys_clock_settime(clockid_t which_clock, const struct timespec __user *tp);asmlinkage long sys_clock_gettime (clockid_t which_clock,struct timespec __user *tp); +asmlinkage long sys_clock_adjtime (clockid_t which_clock, +struct timex __user *tx);asmlinkage long sys_clock_getres (clockid_t which_clock,struct timespec __user *tp); asmlinkage long sys_clock_nanosleep(clockid_t which_clock, int flags,
kernel/compat.c +88 -48
158 lines not on this page · raw message
kernel/posix-cpu-timers.c +6 -0
@@ -207,6 +207,10 @@ int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)return error; } +int posix_cpu_clock_adj (const clockid_t which_clock,struct timex *tx) +{ +return -EOPNOTSUPP ; +}/* * Sample a per-thread clock for the given task.
@@ -1610,6 +1614,7 @@ static __init int init_posix_cpu_timers(void) .clock_getres = process_cpu_clock_getres, .clock_get = process_cpu_clock_get, .clock_set = do_posix_clock_nosettime, + .clock_adj = do_posix_clock_noadjtime, .timer_create = process_cpu_timer_create, .nsleep = process_cpu_nsleep, .nsleep_restart = process_cpu_nsleep_restart,
@@ -1618,6 +1623,7 @@ static __init int init_posix_cpu_timers(void) .clock_getres = thread_cpu_clock_getres, .clock_get = thread_cpu_clock_get, .clock_set = do_posix_clock_nosettime, + .clock_adj = do_posix_clock_noadjtime, .timer_create = thread_cpu_timer_create, .nsleep = thread_cpu_nsleep, .nsleep_restart = thread_cpu_nsleep_restart,
kernel/posix-timers.c +35 -0
@@ -203,6 +203,11 @@ static int common_timer_create(struct k_itimer *new_timer)return 0 ; } +static inline int common_clock_adj (const clockid_t which_clock,struct timex *t) +{ +return do_adjtimex (t); +} +static int no_timer_create (struct k_itimer *new_timer) {return -EOPNOTSUPP ;
@@ -279,11 +284,13 @@ static __init int init_posix_timers(void) .clock_getres = hrtimer_get_res, .clock_get = posix_ktime_get_ts, .clock_set = do_posix_clock_nosettime, + .clock_adj = do_posix_clock_noadjtime, };struct k_clock clock_monotonic_raw = { .clock_getres = hrtimer_get_res, .clock_get = posix_get_monotonic_raw, .clock_set = do_posix_clock_nosettime, + .clock_adj = do_posix_clock_noadjtime, .timer_create = no_timer_create, .nsleep = no_nsleep, };
@@ -291,6 +298,7 @@ static __init int init_posix_timers(void) .clock_getres = posix_get_coarse_res, .clock_get = posix_get_realtime_coarse, .clock_set = do_posix_clock_nosettime, + .clock_adj = do_posix_clock_noadjtime, .timer_create = no_timer_create, .nsleep = no_nsleep, };
@@ -298,6 +306,7 @@ static __init int init_posix_timers(void) .clock_getres = posix_get_coarse_res, .clock_get = posix_get_monotonic_coarse, .clock_set = do_posix_clock_nosettime, + .clock_adj = do_posix_clock_noadjtime, .timer_create = no_timer_create, .nsleep = no_nsleep, };
@@ -934,6 +943,12 @@ int do_posix_clock_nosettime(const clockid_t clockid, const struct timespec *tp) }EXPORT_SYMBOL_GPL (do_posix_clock_nosettime); +int do_posix_clock_noadjtime (const clockid_t which_clock,struct timex *t) +{ +return -EOPNOTSUPP ; +} +EXPORT_SYMBOL_GPL (do_posix_clock_noadjtime); +int do_posix_clock_nonanosleep (const clockid_t clock,int flags,struct timespec *t,struct timespec __user *r) {
@@ -975,6 +990,26 @@ SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock, } +SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock, + struct timex __user *, utx) +{ +struct timex ktx; +int err; + +if (copy_from_user (&ktx, utx,sizeof (ktx))) +return -EFAULT ; + +if (invalid_clockid (which_clock)) +return -EINVAL ; + + err =CLOCK_DISPATCH (which_clock, clock_adj, (which_clock, &ktx)); + +if (copy_to_user (utx, &ktx,sizeof (ktx))) +return -EFAULT ; + +return err; +} + SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, struct timespec __user *, tp) {
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v10 5/15 posix_clocks: add clock_adjtime for arm
In reply to Richard CochranThis patch adds the clock_adjtime system call to the arm architecture.
--- arch/arm/include/asm/unistd.h | 1 + arch/arm/kernel/calls.S | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
arch/arm/include/asm/unistd.h +1 -0
@@ -396,6 +396,7 @@#define __NR_fanotify_init (__NR_SYSCALL_BASE+367)#define __NR_fanotify_mark (__NR_SYSCALL_BASE+368)#define __NR_prlimit64 (__NR_SYSCALL_BASE+369) +#define __NR_clock_adjtime (__NR_SYSCALL_BASE+370)/* * The following SWIs are ARM private.
arch/arm/kernel/calls.S +1 -0
@@ -379,6 +379,7 @@ CALL(sys_fanotify_init) CALL(sys_fanotify_mark) CALL(sys_prlimit64) +/* 370 */ CALL(sys_clock_adjtime) #ifndef syscalls_counted .equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls #define syscalls_counted
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v10 6/15 posix_clocks: add clock_adjtime for blackfin
In reply to Richard CochranThis patch adds the clock_adjtime system call to the blackfin architecture.
--- arch/blackfin/include/asm/unistd.h | 3 ++- arch/blackfin/mach-common/entry.S | 1 + 2 files changed, 3 insertions(+), 1 deletions(-)
arch/blackfin/include/asm/unistd.h +2 -1
@@ -393,8 +393,9 @@#define __NR_fanotify_mark 372#define __NR_prlimit64 373#define __NR_cacheflush 374 +#define __NR_clock_adjtime 375 -#define __NR_syscall 375 +#define __NR_syscall 376#define NR_syscalls __NR_syscall/* Old optional stuff no one actually uses */
arch/blackfin/mach-common/entry.S +1 -0
@@ -1738,6 +1738,7 @@ ENTRY(_sys_call_table) .long _sys_fanotify_mark .long _sys_prlimit64 .long _sys_cacheflush + .long _sys_clock_adjtime /* 375 */ .rept NR_syscalls-(.-_sys_call_table)/4 .long _sys_ni_syscall
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v10 7/15 posix_clocks: add clock_adjtime for powerpc
In reply to Richard CochranThis patch adds the clock_adjtime system call to the powerpc architecture.
--- arch/powerpc/include/asm/systbl.h | 1 + arch/powerpc/include/asm/unistd.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletions(-)
arch/powerpc/include/asm/systbl.h +1 -0
@@ -348,3 +348,4 @@ COMPAT_SYS_SPU(sendmsg) COMPAT_SYS_SPU(recvmsg) COMPAT_SYS_SPU(recvmmsg) SYSCALL_SPU(accept4) +COMPAT_SYS_SPU(clock_adjtime)
arch/powerpc/include/asm/unistd.h +2 -1
@@ -367,10 +367,11 @@#define __NR_recvmsg 342#define __NR_recvmmsg 343#define __NR_accept4 344 +#define __NR_clock_adjtime 345#ifdef __KERNEL__ -#define __NR_syscalls 345 +#define __NR_syscalls 346#define __NR__exit __NR_exit#define NR_syscalls __NR_syscalls
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v10 8/15 posix_clocks: add clock_adjtime for x86
In reply to Richard CochranThis patch adds the clock_adjtime system call to the x86 architecture.
--- arch/x86/ia32/ia32entry.S | 1 + arch/x86/include/asm/unistd_32.h | 3 ++- arch/x86/include/asm/unistd_64.h | 2 ++ arch/x86/kernel/syscall_table_32.S | 1 + 4 files changed, 6 insertions(+), 1 deletions(-)
arch/x86/ia32/ia32entry.S +1 -0
@@ -851,4 +851,5 @@ ia32_sys_call_table: .quad sys_fanotify_init .quad sys32_fanotify_mark .quad sys_prlimit64 /* 340 */ + .quad compat_sys_clock_adjtime ia32_syscall_end:
arch/x86/include/asm/unistd_32.h +2 -1
@@ -346,10 +346,11 @@#define __NR_fanotify_init 338#define __NR_fanotify_mark 339#define __NR_prlimit64 340 +#define __NR_clock_adjtime 341#ifdef __KERNEL__ -#define NR_syscalls 341 +#define NR_syscalls 342#define __ARCH_WANT_IPC_PARSE_VERSION#define __ARCH_WANT_OLD_READDIR
arch/x86/include/asm/unistd_64.h +2 -0
@@ -669,6 +669,8 @@ __SYSCALL(__NR_fanotify_init, sys_fanotify_init) __SYSCALL(__NR_fanotify_mark, sys_fanotify_mark)#define __NR_prlimit64 302 __SYSCALL(__NR_prlimit64, sys_prlimit64) +#define __NR_clock_adjtime 303 +__SYSCALL(__NR_clock_adjtime, sys_clock_adjtime)#ifndef __NO_STUBS#define __ARCH_WANT_OLD_READDIR
arch/x86/kernel/syscall_table_32.S +1 -0
@@ -340,3 +340,4 @@ ENTRY(sys_call_table) .long sys_fanotify_init .long sys_fanotify_mark .long sys_prlimit64 /* 340 */ + .long sys_clock_adjtime
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v10 9/15 posix clocks: cleanup the CLOCK_DISPTACH macro
In reply to Richard CochranParaphrasing tglx:
This patch simplifies and clarifies the code, doing the normal thing with function pointer structures. Stuff which is not implemented does not magically become called via some common function. There is no point in doing that.
We fill in the various k_clock structs with the correct pointers in the first place and let the NULL case return a sensible error value. The data structure does not become larger that way. It's a little bit more init code, but that's fine if we make the code better in general. In that case it's not even more init code, it's just filling the data structures which we register.
My own words:
For now, each of the registered k_clocks has the previously NULL functions assigned to the common_xyz function, since that usage was implicitly enforced by the CLOCK_DISPTACH macro. These functions are marked with a /* default: */ comment.
--- include/linux/posix-timers.h | 14 +++ include/linux/time.h | 2 + kernel/posix-timers.c | 219 +++++++++++++++++++++++------------------- 3 files changed, 136 insertions(+), 99 deletions(-)
include/linux/posix-timers.h +14 -0
@@ -18,6 +18,18 @@ struct cpu_timer_list {int firing; }; +/* Bit fields within a clockid: +* +* The most significant 29 bits hold either a pid or a file descriptor. +* +* Bit 2 indicates whether a cpu clock refers to a thread or a process. +* +* Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3. +* +* A clockid is invalid if bits 2, 1, and 0 all set (see also CLOCK_INVALID +* in include/linux/time.h) +*/ +#define CPUCLOCK_PID (clock) ((pid_t) ~((clock) >> 3))#define CPUCLOCK_PERTHREAD (clock) \ (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
@@ -29,6 +41,8 @@ struct cpu_timer_list {#define CPUCLOCK_VIRT 1#define CPUCLOCK_SCHED 2#define CPUCLOCK_MAX 3 +#define CLOCKFD CPUCLOCK_MAX +#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)#define MAKE_PROCESS_CPUCLOCK (pid, clock) \ ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
include/linux/time.h +2 -0
@@ -303,6 +303,8 @@ struct itimerval {#define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC)#define CLOCKS_MONO CLOCK_MONOTONIC +#define CLOCK_INVALID -1 +/* * The various flags for setting POSIX.1b interval timers: */
kernel/posix-timers.c +120 -99
435 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v10 10/15 posix clocks: remove useless default methods
In reply to Richard CochranFor the k_clocks which do not allow timers or sleeping, it does not make sense to use the default "common" methods for these kinds of functions. Thus we simply remove them.
--- kernel/posix-timers.c | 15 --------------- 1 files changed, 0 insertions(+), 15 deletions(-)
kernel/posix-timers.c +0 -15
@@ -262,11 +262,6 @@ static __init int init_posix_timers(void) .clock_adj = do_posix_clock_noadjtime, .timer_create = no_timer_create, .nsleep = no_nsleep, - /* defaults: */ - .nsleep_restart = common_nsleep_restart, - .timer_del = common_timer_del, - .timer_get = common_timer_get, - .timer_set = common_timer_set, };struct k_clock clock_realtime_coarse = { .clock_getres = posix_get_coarse_res,
@@ -275,11 +270,6 @@ static __init int init_posix_timers(void) .clock_adj = do_posix_clock_noadjtime, .timer_create = no_timer_create, .nsleep = no_nsleep, - /* defaults: */ - .nsleep_restart = common_nsleep_restart, - .timer_del = common_timer_del, - .timer_get = common_timer_get, - .timer_set = common_timer_set, };struct k_clock clock_monotonic_coarse = { .clock_getres = posix_get_coarse_res,
@@ -288,11 +278,6 @@ static __init int init_posix_timers(void) .clock_adj = do_posix_clock_noadjtime, .timer_create = no_timer_create, .nsleep = no_nsleep, - /* defaults: */ - .nsleep_restart = common_nsleep_restart, - .timer_del = common_timer_del, - .timer_get = common_timer_get, - .timer_set = common_timer_set, };struct k_clock clock_posix_cpu = { .clock_getres = posix_cpu_clock_getres,
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v10 11/15 posix clocks: introduce dynamic clocks
In reply to Richard CochranThis patch adds support for adding and removing posix clocks. The clock lifetime cycle is patterned after usb devices. Each clock is represented by a standard character device. In addition, the driver may optionally implement custom character device operations.
The posix clock and timer system calls listed below now work with dynamic posix clocks, as well as the traditional static clocks. The following system calls are affected:
- clock_adjtime (brand new syscall)
- clock_gettime
- clock_getres
- clock_settime
- timer_create
- timer_delete
- timer_gettime
- timer_settime
--- include/linux/posix-clock.h | 150 +++++++++++++ include/linux/posix-timers.h | 5 +- kernel/posix-timers.c | 20 ++- kernel/time/Makefile | 3 +- kernel/time/posix-clock-syscalls.h | 39 ++++ kernel/time/posix-clock.c | 432 ++++++++++++++++++++++++++++++++++++ 6 files changed, 645 insertions(+), 4 deletions(-) create mode 100644 include/linux/posix-clock.h create mode 100644 kernel/time/posix-clock-syscalls.h create mode 100644 kernel/time/posix-clock.c
include/linux/posix-clock.h new file +150 -0
@@ -0,0 +1,150 @@ +/* +* posix-clock.h - support for dynamic clock devices +* +* Copyright (C) 2010 OMICRON electronics GmbH +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#ifndef _LINUX_POSIX_CLOCK_H_ +#define _LINUX_POSIX_CLOCK_H_ + +#include <linux/cdev.h> +#include <linux/fs.h> +#include <linux/poll.h> +#include <linux/posix-timers.h> + +struct posix_clock ; + +/** +* struct posix_clock_operations - functional interface to the clock +* +* Every posix clock is represented by a character device. Drivers may +* optionally offer extended capabilities by implementing the +* character device methods. The character device file operations are +* first handled by the clock device layer, then passed on to the +* driver by calling these functions. +* +* @owner: The clock driver should set to THIS_MODULE +* @clock_adjtime: Adjust the clock +* @clock_gettime: Read the current time +* @clock_getres: Get the clock resolution +* @clock_settime: Set the current time value +* @timer_create: Create a new timer +* @timer_delete: Remove a previously created timer +* @timer_gettime: Get remaining time and interval of a timer +* @timer_setttime: Set a timer's initial expiration and interval +* @fasync: Optional character device fasync method +* @mmap: Optional character device mmap method +* @open: Optional character device open method +* @release: Optional character device release method +* @ioctl: Optional character device ioctl method +* @read: Optional character device read method +* @poll: Optional character device poll method +*/ +struct posix_clock_operations { +struct module *owner; + +int (*clock_adjtime)(struct posix_clock *pc,struct timex *tx); + +int (*clock_gettime)(struct posix_clock *pc,struct timespec *ts); + +int (*clock_getres) (struct posix_clock *pc,struct timespec *ts); + +int (*clock_settime)(struct posix_clock *pc, +const struct timespec *ts); + +int (*timer_create) (struct posix_clock *pc,struct k_itimer *kit); + +int (*timer_delete) (struct posix_clock *pc,struct k_itimer *kit); + +void (*timer_gettime)(struct posix_clock *pc, +struct k_itimer *kit,struct itimerspec *tsp); + +int (*timer_settime)(struct posix_clock *pc, +struct k_itimer *kit,int flags, +struct itimerspec *tsp,struct itimerspec *old); +/* +* Optional character device methods: +*/ +int (*fasync) (struct posix_clock *pc, +int fd,struct file *file,int on); + +long (*ioctl) (struct posix_clock *pc, +unsigned int cmd,unsigned long arg); + +int (*mmap) (struct posix_clock *pc, +struct vm_area_struct *vma); + +int (*open) (struct posix_clock *pc,fmode_t f_mode); + +uint (*poll) (struct posix_clock *pc, +struct file *file,poll_table *wait); + +int (*release) (struct posix_clock *pc); + +ssize_t (*read) (struct posix_clock *pc, +uint flags,char __user *buf,size_t cnt); +}; + +/** +* struct posix_clock - represents a dynamic posix clock +* +* @ops: Functional interface to the clock +* @cdev: Character device instance for this clock +* @kref: Reference count. +* @mutex: Protects the 'zombie' field from concurrent access. +* @zombie: If 'zombie' is true, then the hardware has disappeared. +* @release: A function to free the structure when the reference count reaches +* zero. May be NULL if structure is statically allocated. +* +* Drivers should embed their struct posix_clock within a private +* structure, obtaining a reference to it during callbacks using +* container_of(). +*/ +struct posix_clock { +struct posix_clock_operations ops; +struct cdev cdev; +struct kref kref; +struct mutex mutex; +bool zombie; +void (*release)(struct posix_clock *clk); +}; + +/** +* posix_clock_register() - register a new clock +* @clk: Pointer to the clock. Caller must provide 'ops' and 'release' +* @devid: Allocated device id +* +* A clock driver calls this function to register itself with the +* clock device subsystem. If 'clk' points to dynamically allocated +* memory, then the caller must provide a 'release' function to free +* that memory. +* +* Returns zero on success, non-zero otherwise. +*/ +int posix_clock_register (struct posix_clock *clk,dev_t devid); + +/** +* posix_clock_unregister() - unregister a clock +* @clk: Clock instance previously registered via posix_clock_register() +* +* A clock driver calls this function to remove itself from the clock +* device subsystem. The posix_clock itself will remain (in an +* inactive state) until its reference count drops to zero, at which +* point it will be deallocated with its 'release' method. +*/ +void posix_clock_unregister (struct posix_clock *clk); + +#endif
include/linux/posix-timers.h +4 -1
@@ -33,7 +33,7 @@ struct cpu_timer_list {#define CPUCLOCK_PID (clock) ((pid_t) ~((clock) >> 3))#define CPUCLOCK_PERTHREAD (clock) \ (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0) -#define CPUCLOCK_PID_MASK 7 +#define CPUCLOCK_PERTHREAD_MASK 4#define CPUCLOCK_WHICH (clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)#define CPUCLOCK_CLOCK_MASK 3
@@ -49,6 +49,9 @@ struct cpu_timer_list {#define MAKE_THREAD_CPUCLOCK (tid, clock) \ MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK) +#define FD_TO_CLOCKID (fd) ((~(clockid_t) (fd) << 3) | CLOCKFD) +#define CLOCKID_TO_FD (clk) ((unsigned int) ~((clk) >> 3)) +/* POSIX.1b interval timer structure. */ struct k_itimer {struct list_head list;/* free/ allocate list */
kernel/posix-timers.c +18 -2
@@ -41,12 +41,15 @@#include <linux/init.h> #include <linux/compiler.h> #include <linux/idr.h> +#include <linux/posix-clock.h> #include <linux/posix-timers.h> #include <linux/syscalls.h> #include <linux/wait.h> #include <linux/workqueue.h> #include <linux/module.h> +#include "time/posix-clock-syscalls.h" +/* * Management arrays for POSIX timers. Timers are kept in slab memory * Timer ids are allocated by an external routine that keeps track of the
@@ -122,7 +125,8 @@ static DEFINE_SPINLOCK(idr_lock);#define POSIX_INV_CLOCK_ID MAX_CLOCKS#define POSIX_CPU_CLOCK_ID (MAX_CLOCKS + 1) -#define NR_CLOCK_ENTRIES (MAX_CLOCKS + 2) +#define DYNAMIC_CLOCK_ID (MAX_CLOCKS + 2) +#define NR_CLOCK_ENTRIES (MAX_CLOCKS + 3)static struct k_clock posix_clocks[NR_CLOCK_ENTRIES ];
@@ -291,6 +295,17 @@ static __init int init_posix_timers(void) .timer_del = posix_cpu_timer_del, .timer_get = posix_cpu_timer_get, }; +struct k_clock clock_posix_dynamic = { + .clock_getres = pc_clock_getres, + .clock_set = pc_clock_settime, + .clock_get = pc_clock_gettime, + .clock_adj = pc_clock_adjtime, + .timer_create = pc_timer_create, + .nsleep = no_nsleep, + .timer_set = pc_timer_settime, + .timer_del = pc_timer_delete, + .timer_get = pc_timer_gettime, + };register_posix_clock (CLOCK_REALTIME , &clock_realtime);register_posix_clock (CLOCK_MONOTONIC , &clock_monotonic);
@@ -303,6 +318,7 @@ static __init int init_posix_timers(void)* the clock returned by clockid_to_kclock() will trigger -EINVAL. */ posix_clocks[POSIX_CPU_CLOCK_ID ] = clock_posix_cpu; + posix_clocks[DYNAMIC_CLOCK_ID ] = clock_posix_dynamic; posix_timers_cache = kmem_cache_create("posix_timers_cache", sizeof (struct k_itimer), 0, SLAB_PANIC,
@@ -538,7 +554,7 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)if (clock_is_posix_cpu (id))return &posix_clocks[POSIX_CPU_CLOCK_ID ]; -return &posix_clocks[POSIX_INV_CLOCK_ID ]; +return &posix_clocks[DYNAMIC_CLOCK_ID ]; }/* Create a POSIX.1b interval timer. */
kernel/time/Makefile +2 -1
@@ -1,4 +1,5 @@ -obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o timecompare.o timeconv.o +obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o timecompare.o +obj-y += timeconv.o posix-clock.o obj-$(CONFIG_GENERIC_CLOCKEVENTS_BUILD) += clockevents.o obj-$(CONFIG_GENERIC_CLOCKEVENTS) += tick-common.o
kernel/time/posix-clock-syscalls.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* posix-clock-syscalls.h - support for dynamic clock devices +* +* Copyright (C) 2010 OMICRON electronics GmbH +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#ifndef _POSIX_CLOCK_SYSCALLS_H_ +#define _POSIX_CLOCK_SYSCALLS_H_ + +#include <linux/posix-timers.h> + +/* +* The following functions are only to be called from posix-timers.c +*/ + +int pc_clock_adjtime (clockid_t id,struct timex *tx); +int pc_clock_gettime (clockid_t id,struct timespec *ts); +int pc_clock_getres (clockid_t id,struct timespec *ts); +int pc_clock_settime (clockid_t id,const struct timespec *ts); +int pc_timer_create (struct k_itimer *kt); +int pc_timer_delete (struct k_itimer *kt); +void pc_timer_gettime (struct k_itimer *kt,struct itimerspec *ts); +int pc_timer_settime (struct k_itimer *kt,int flags, +struct itimerspec *ts,struct itimerspec *old); + +#endif
kernel/time/posix-clock.c new file +432 -0
432 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v10 12/15 ptp: Added a brand new class driver for ptp clocks.
In reply to Richard CochranThis patch adds an infrastructure for hardware clocks that implement IEEE 1588, the Precision Time Protocol (PTP). A class driver offers a registration method to particular hardware clock drivers. Each clock is presented as a standard POSIX clock.
The ancillary clock features are exposed in two different ways, via the sysfs and by a character device.
--- Documentation/ABI/testing/sysfs-ptp | 98 ++++++++++ Documentation/ptp/ptp.txt | 89 +++++++++ Documentation/ptp/testptp.c | 352 +++++++++++++++++++++++++++++++++++ Documentation/ptp/testptp.mk | 33 ++++ drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/ptp/Kconfig | 27 +++ drivers/ptp/Makefile | 6 + drivers/ptp/ptp_chardev.c | 144 ++++++++++++++ drivers/ptp/ptp_clock.c | 315 +++++++++++++++++++++++++++++++ drivers/ptp/ptp_private.h | 85 +++++++++ drivers/ptp/ptp_sysfs.c | 226 ++++++++++++++++++++++ include/linux/Kbuild | 1 + include/linux/ptp_clock.h | 79 ++++++++ include/linux/ptp_clock_kernel.h | 141 ++++++++++++++ 15 files changed, 1599 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-ptp create mode 100644 Documentation/ptp/ptp.txt create mode 100644 Documentation/ptp/testptp.c create mode 100644 Documentation/ptp/testptp.mk create mode 100644 drivers/ptp/Kconfig create mode 100644 drivers/ptp/Makefile create mode 100644 drivers/ptp/ptp_chardev.c create mode 100644 drivers/ptp/ptp_clock.c create mode 100644 drivers/ptp/ptp_private.h create mode 100644 drivers/ptp/ptp_sysfs.c create mode 100644 include/linux/ptp_clock.h create mode 100644 include/linux/ptp_clock_kernel.h
Documentation/ABI/testing/sysfs-ptp new file +98 -0
@@ -0,0 +1,98 @@ +What: /sys/class/ptp/ +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This directory contains files and directories + providing a standardized interface to the ancillary + features of PTP hardware clocks. + +What: /sys/class/ptp/ptpN/ +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This directory contains the attributes of the Nth PTP + hardware clock registered into the PTP class driver + subsystem. + +What: /sys/class/ptp/ptpN/clock_name +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the name of the PTP hardware clock + as a human readable string. + +What: /sys/class/ptp/ptpN/max_adjustment +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the PTP hardware clock's maximum + frequency adjustment value (a positive integer) in + parts per billion. + +What: /sys/class/ptp/ptpN/n_alarms +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the number of periodic or one shot + alarms offer by the PTP hardware clock. + +What: /sys/class/ptp/ptpN/n_external_timestamps +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the number of external timestamp + channels offered by the PTP hardware clock. + +What: /sys/class/ptp/ptpN/n_periodic_outputs +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the number of programmable periodic + output channels offered by the PTP hardware clock. + +What: /sys/class/ptp/ptpN/pps_avaiable +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file indicates whether the PTP hardware clock + supports a Pulse Per Second to the host CPU. Reading + "1" means that the PPS is supported, while "0" means + not supported. + +What: /sys/class/ptp/ptpN/extts_enable +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This write-only file enables or disables external + timestamps. To enable external timestamps, write the + channel index followed by a "1" into the file. + To disable external timestamps, write the channel + index followed by a "0" into the file. + +What: /sys/class/ptp/ptpN/fifo +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file provides timestamps on external events, in + the form of three integers: channel index, seconds, + and nanoseconds. + +What: /sys/class/ptp/ptpN/period +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This write-only file enables or disables periodic + outputs. To enable a periodic output, write five + integers into the file: channel index, start time + seconds, start time nanoseconds, period seconds, and + period nanoseconds. To disable a periodic output, set + all the seconds and nanoseconds values to zero. + +What: /sys/class/ptp/ptpN/pps_enable +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This write-only file enables or disables delivery of + PPS events to the Linux PPS subsystem. To enable PPS + events, write a "1" into the file. To disable events, + write a "0" into the file.
Documentation/ptp/ptp.txt new file +89 -0
89 lines not on this page · raw message
Documentation/ptp/testptp.c new file +352 -0
352 lines not on this page · raw message
Documentation/ptp/testptp.mk new file +33 -0
@@ -0,0 +1,33 @@ +# PTP 1588 clock support - User space test program +# +# Copyright (C) 2010 OMICRON electronics GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +CC = $(CROSS_COMPILE)gcc +INC = -I$(KBUILD_OUTPUT)/usr/include +CFLAGS = -Wall $(INC) +LDLIBS = -lrt +PROGS = testptp + +all: $(PROGS) + +testptp: testptp.o + +clean: + rm -f testptp.o + +distclean: clean + rm -f $(PROGS)
drivers/Kconfig +2 -0
@@ -54,6 +54,8 @@ source "drivers/spi/Kconfig" source "drivers/pps/Kconfig" +source "drivers/ptp/Kconfig" + source "drivers/gpio/Kconfig" source "drivers/w1/Kconfig"
drivers/Makefile +1 -0
@@ -76,6 +76,7 @@ obj-$(CONFIG_I2O) += message/ obj-$(CONFIG_RTC_LIB) += rtc/ obj-y += i2c/ media/ obj-$(CONFIG_PPS) += pps/ +obj-$(CONFIG_PTP_1588_CLOCK) += ptp/ obj-$(CONFIG_W1) += w1/ obj-$(CONFIG_POWER_SUPPLY) += power/ obj-$(CONFIG_HWMON) += hwmon/
drivers/ptp/Kconfig new file +27 -0
@@ -0,0 +1,27 @@ +# +# PTP clock support configuration +# + +menu "PTP clock support" + +config PTP_1588_CLOCK + tristate "PTP clock support" + depends on EXPERIMENTAL + depends on PPS + help + The IEEE 1588 standard defines a method to precisely + synchronize distributed clocks over Ethernet networks. The + standard defines a Precision Time Protocol (PTP), which can + be used to achieve synchronization within a few dozen + microseconds. In addition, with the help of special hardware + time stamping units, it can be possible to achieve + synchronization to within a few hundred nanoseconds. + + This driver adds support for PTP clocks as character + devices. If you want to use a PTP clock, then you should + also enable at least one clock driver as well. + + To compile this driver as a module, choose M here: the module + will be called ptp. + +endmenu
drivers/ptp/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# +# Makefile for PTP 1588 clock support. +# + +ptp-y := ptp_clock.o ptp_chardev.o ptp_sysfs.o +obj-$(CONFIG_PTP_1588_CLOCK) += ptp.o
drivers/ptp/ptp_chardev.c new file +144 -0
144 lines not on this page · raw message
drivers/ptp/ptp_clock.c new file +315 -0
315 lines not on this page · raw message
drivers/ptp/ptp_private.h new file +85 -0
85 lines not on this page · raw message
drivers/ptp/ptp_sysfs.c new file +226 -0
226 lines not on this page · raw message
include/linux/Kbuild +1 -0
@@ -299,6 +299,7 @@ header-y += ppp-comp.h header-y += ppp_defs.h header-y += pps.h header-y += prctl.h +header-y += ptp_clock.h header-y += ptrace.h header-y += qnx4_fs.h header-y += qnxtypes.h
include/linux/ptp_clock.h new file +79 -0
79 lines not on this page · raw message
include/linux/ptp_clock_kernel.h new file +141 -0
141 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v10 13/15 ptp: Added a clock that uses the eTSEC found on the MPC85xx.
In reply to Richard CochranThe eTSEC includes a PTP clock with quite a few features. This patch adds support for the basic clock adjustment functions, plus two external time stamps, one alarm, and the PPS callback.
--- Documentation/powerpc/dts-bindings/fsl/tsec.txt | 57 +++ arch/powerpc/boot/dts/mpc8313erdb.dts | 14 + arch/powerpc/boot/dts/mpc8572ds.dts | 14 + arch/powerpc/boot/dts/p2020ds.dts | 14 + arch/powerpc/boot/dts/p2020rdb.dts | 14 + drivers/net/Makefile | 1 + drivers/net/gianfar_ptp.c | 448 +++++++++++++++++++++++ drivers/net/gianfar_ptp_reg.h | 113 ++++++ drivers/ptp/Kconfig | 13 + 9 files changed, 688 insertions(+), 0 deletions(-) create mode 100644 drivers/net/gianfar_ptp.c create mode 100644 drivers/net/gianfar_ptp_reg.h
Documentation/powerpc/dts-bindings/fsl/tsec.txt +57 -0
@@ -74,3 +74,60 @@ Example: interrupt-parent = <&mpic>; phy-handle = <&phy0> }; + +* Gianfar PTP clock nodes + +General Properties: + + - compatible Should be "fsl,etsec-ptp" + - reg Offset and length of the register set for the device + - interrupts There should be at least two interrupts. Some devices + have as many as four PTP related interrupts. + +Clock Properties: + + - tclk-period Timer reference clock period in nanoseconds. + - tmr-prsc Prescaler, divides the output clock. + - tmr-add Frequency compensation value. + - cksel 0= external clock, 1= eTSEC system clock, 3= RTC clock input. + Currently the driver only supports choice "1". + - tmr-fiper1 Fixed interval period pulse generator. + - tmr-fiper2 Fixed interval period pulse generator. + - max-adj Maximum frequency adjustment in parts per billion. + + These properties set the operational parameters for the PTP + clock. You must choose these carefully for the clock to work right. + Here is how to figure good values: + + TimerOsc = system clock MHz + tclk_period = desired clock period nanoseconds + NominalFreq = 1000 / tclk_period MHz + FreqDivRatio = TimerOsc / NominalFreq (must be greater that 1.0) + tmr_add = ceil(2^32 / FreqDivRatio) + OutputClock = NominalFreq / tmr_prsc MHz + PulseWidth = 1 / OutputClock microseconds + FiperFreq1 = desired frequency in Hz + FiperDiv1 = 1000000 * OutputClock / FiperFreq1 + tmr_fiper1 = tmr_prsc * tclk_period * FiperDiv1 - tclk_period + max_adj = 1000000000 * (FreqDivRatio - 1.0) - 1 + + The calculation for tmr_fiper2 is the same as for tmr_fiper1. The + driver expects that tmr_fiper1 will be correctly set to produce a 1 + Pulse Per Second (PPS) signal, since this will be offered to the PPS + subsystem to synchronize the Linux clock. + +Example: + + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <12 0x8 13 0x8>; + interrupt-parent = < &ipic >; + tclk-period = <10>; + tmr-prsc = <100>; + tmr-add = <0x999999A4>; + cksel = <0x1>; + tmr-fiper1 = <0x3B9AC9F6>; + tmr-fiper2 = <0x00018696>; + max-adj = <659999998>; + };
arch/powerpc/boot/dts/mpc8313erdb.dts +14 -0
@@ -208,6 +208,20 @@ sleep = <&pmc 0x00300000>; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <12 0x8 13 0x8>; + interrupt-parent = < &ipic >; + tclk-period = <10>; + tmr-prsc = <100>; + tmr-add = <0x999999A4>; + cksel = <0x1>; + tmr-fiper1 = <0x3B9AC9F6>; + tmr-fiper2 = <0x00018696>; + max-adj = <659999998>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;
arch/powerpc/boot/dts/mpc8572ds.dts +14 -0
@@ -324,6 +324,20 @@ }; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <68 2 69 2 70 2 71 2>; + interrupt-parent = < &mpic >; + tclk-period = <5>; + tmr-prsc = <200>; + tmr-add = <0xAAAAAAAB>; + cksel = <1>; + tmr-fiper1 = <0x3B9AC9FB>; + tmr-fiper2 = <0x3B9AC9FB>; + max-adj = <499999999>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;
arch/powerpc/boot/dts/p2020ds.dts +14 -0
@@ -336,6 +336,20 @@ phy_type = "ulpi"; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <68 2 69 2 70 2>; + interrupt-parent = < &mpic >; + tclk-period = <5>; + tmr-prsc = <200>; + tmr-add = <0xCCCCCCCD>; + cksel = <1>; + tmr-fiper1 = <0x3B9AC9FB>; + tmr-fiper2 = <0x0001869B>; + max-adj = <249999999>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;
arch/powerpc/boot/dts/p2020rdb.dts +14 -0
@@ -396,6 +396,20 @@ phy_type = "ulpi"; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <68 2 69 2 70 2>; + interrupt-parent = < &mpic >; + tclk-period = <5>; + tmr-prsc = <200>; + tmr-add = <0xCCCCCCCD>; + cksel = <1>; + tmr-fiper1 = <0x3B9AC9FB>; + tmr-fiper2 = <0x0001869B>; + max-adj = <249999999>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;
drivers/net/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_ATL2) += atlx/ obj-$(CONFIG_ATL1E) += atl1e/ obj-$(CONFIG_ATL1C) += atl1c/ obj-$(CONFIG_GIANFAR) += gianfar_driver.o +obj-$(CONFIG_PTP_1588_CLOCK_GIANFAR) += gianfar_ptp.o obj-$(CONFIG_TEHUTI) += tehuti.o obj-$(CONFIG_ENIC) += enic/ obj-$(CONFIG_JME) += jme.o
drivers/net/gianfar_ptp.c new file +448 -0
448 lines not on this page · raw message
drivers/net/gianfar_ptp_reg.h new file +113 -0
113 lines not on this page · raw message
drivers/ptp/Kconfig +13 -0
@@ -24,4 +24,17 @@ config PTP_1588_CLOCK To compile this driver as a module, choose M here: the module will be called ptp. +config PTP_1588_CLOCK_GIANFAR + tristate "Freescale eTSEC as PTP clock" + depends on PTP_1588_CLOCK + depends on GIANFAR + help + This driver adds support for using the eTSEC as a PTP + clock. This clock is only useful if your PTP programs are + getting hardware time stamps on the PTP Ethernet packets + using the SO_TIMESTAMPING API. + + To compile this driver as a module, choose M here: the module + will be called gianfar_ptp. + endmenu
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v10 14/15 ptp: Added a clock driver for the IXP46x.
In reply to Richard CochranThis patch adds a driver for the hardware time stamping unit found on the IXP465. The basic clock operations and an external trigger are implemented.
--- arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h | 78 ++++++ drivers/net/arm/ixp4xx_eth.c | 192 ++++++++++++++- drivers/ptp/Kconfig | 13 + drivers/ptp/Makefile | 1 + drivers/ptp/ptp_ixp46x.c | 332 +++++++++++++++++++++++++ 5 files changed, 613 insertions(+), 3 deletions(-) create mode 100644 arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h create mode 100644 drivers/ptp/ptp_ixp46x.c
arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h new file +78 -0
@@ -0,0 +1,78 @@ +/* +* PTP 1588 clock using the IXP46X +* +* Copyright (C) 2010 OMICRON electronics GmbH +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef _IXP46X_TS_H_ +#define _IXP46X_TS_H_ + +#define DEFAULT_ADDEND 0xF0000029 +#define TICKS_NS_SHIFT 4 + +struct ixp46x_channel_ctl { +u32 ch_control;/* 0x40 Time Synchronization Channel Control */ +u32 ch_event;/* 0x44 Time Synchronization Channel Event */ +u32 tx_snap_lo;/* 0x48 Transmit Snapshot Low Register */ +u32 tx_snap_hi;/* 0x4C Transmit Snapshot High Register */ +u32 rx_snap_lo;/* 0x50 Receive Snapshot Low Register */ +u32 rx_snap_hi;/* 0x54 Receive Snapshot High Register */ +u32 src_uuid_lo;/* 0x58 Source UUID0 Low Register */ +u32 src_uuid_hi;/* 0x5C Sequence Identifier/Source UUID0 High */ +}; + +struct ixp46x_ts_regs { +u32 control;/* 0x00 Time Sync Control Register */ +u32 event;/* 0x04 Time Sync Event Register */ +u32 addend;/* 0x08 Time Sync Addend Register */ +u32 accum;/* 0x0C Time Sync Accumulator Register */ +u32 test;/* 0x10 Time Sync Test Register */ +u32 unused;/* 0x14 */ +u32 rsystime_lo;/* 0x18 RawSystemTime_Low Register */ +u32 rsystime_hi;/* 0x1C RawSystemTime_High Register */ +u32 systime_lo;/* 0x20 SystemTime_Low Register */ +u32 systime_hi;/* 0x24 SystemTime_High Register */ +u32 trgt_lo;/* 0x28 TargetTime_Low Register */ +u32 trgt_hi;/* 0x2C TargetTime_High Register */ +u32 asms_lo;/* 0x30 Auxiliary Slave Mode Snapshot Low */ +u32 asms_hi;/* 0x34 Auxiliary Slave Mode Snapshot High */ +u32 amms_lo;/* 0x38 Auxiliary Master Mode Snapshot Low */ +u32 amms_hi;/* 0x3C Auxiliary Master Mode Snapshot High */ + +struct ixp46x_channel_ctl channel[3 ]; +}; + +/* 0x00 Time Sync Control Register Bits */ +#define TSCR_AMM (1<<3) +#define TSCR_ASM (1<<2) +#define TSCR_TTM (1<<1) +#define TSCR_RST (1<<0) + +/* 0x04 Time Sync Event Register Bits */ +#define TSER_SNM (1<<3) +#define TSER_SNS (1<<2) +#define TTIPEND (1<<1) + +/* 0x40 Time Synchronization Channel Control Register Bits */ +#define MASTER_MODE (1<<0) +#define TIMESTAMP_ALL (1<<1) + +/* 0x44 Time Synchronization Channel Event Register Bits */ +#define TX_SNAPSHOT_LOCKED (1<<0) +#define RX_SNAPSHOT_LOCKED (1<<1) + +#endif
drivers/net/arm/ixp4xx_eth.c +189 -3
254 lines not on this page · raw message
drivers/ptp/Kconfig +13 -0
@@ -37,4 +37,17 @@ config PTP_1588_CLOCK_GIANFAR To compile this driver as a module, choose M here: the module will be called gianfar_ptp. +config PTP_1588_CLOCK_IXP46X + tristate "Intel IXP46x as PTP clock" + depends on PTP_1588_CLOCK + depends on IXP4XX_ETH + help + This driver adds support for using the IXP46X as a PTP + clock. This clock is only useful if your PTP programs are + getting hardware time stamps on the PTP Ethernet packets + using the SO_TIMESTAMPING API. + + To compile this driver as a module, choose M here: the module + will be called ptp_ixp46x. + endmenu
drivers/ptp/Makefile +1 -0
@@ -4,3 +4,4 @@ ptp-y := ptp_clock.o ptp_chardev.o ptp_sysfs.o obj-$(CONFIG_PTP_1588_CLOCK) += ptp.o +obj-$(CONFIG_PTP_1588_CLOCK_IXP46X) += ptp_ixp46x.o
drivers/ptp/ptp_ixp46x.c new file +332 -0
332 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v10 15/15 ptp: Added a clock driver for the National Semiconductor PHYTER.
In reply to Richard CochranThis patch adds support for the PTP clock found on the DP83640. The basic clock operations and one external time stamp have been implemented.
--- drivers/net/phy/Kconfig | 29 ++ drivers/net/phy/Makefile | 1 + drivers/net/phy/dp83640.c | 896 +++++++++++++++++++++++++++++++++++++++++ drivers/net/phy/dp83640_reg.h | 261 ++++++++++++ 4 files changed, 1187 insertions(+), 0 deletions(-) create mode 100644 drivers/net/phy/dp83640.c create mode 100644 drivers/net/phy/dp83640_reg.h
drivers/net/phy/Kconfig +29 -0
@@ -76,6 +76,35 @@ config NATIONAL_PHY ---help--- Currently supports the DP83865 PHY. +config DP83640_PHY + tristate "Driver for the National Semiconductor DP83640 PHYTER" + depends on PTP_1588_CLOCK + depends on NETWORK_PHY_TIMESTAMPING + ---help--- + Supports the DP83640 PHYTER with IEEE 1588 features. + + This driver adds support for using the DP83640 as a PTP + clock. This clock is only useful if your PTP programs are + getting hardware time stamps on the PTP Ethernet packets + using the SO_TIMESTAMPING API. + + In order for this to work, your MAC driver must also + implement the skb_tx_timetamp() function. + +config DP83640_PHY_STATUS_FRAMES + bool "DP83640 Status Frames" + default y + depends on DP83640_PHY + ---help--- + This option allows the DP83640 PHYTER driver to obtain time + stamps from the PHY via special status frames, rather than + reading over the MDIO bus. Using status frames is therefore + more efficient. However, if enabled, this option will cause + the driver to add a mutlicast address to the MAC. + + Say Y here, unless your MAC does not support multicast + destination addresses. + config STE10XP depends on PHYLIB tristate "Driver for STMicroelectronics STe10Xp PHYs"
drivers/net/phy/Makefile +1 -0
@@ -19,6 +19,7 @@ obj-$(CONFIG_FIXED_PHY) += fixed.o obj-$(CONFIG_MDIO_BITBANG) += mdio-bitbang.o obj-$(CONFIG_MDIO_GPIO) += mdio-gpio.o obj-$(CONFIG_NATIONAL_PHY) += national.o +obj-$(CONFIG_DP83640_PHY) += dp83640.o obj-$(CONFIG_STE10XP) += ste10Xp.o obj-$(CONFIG_MICREL_PHY) += micrel.o obj-$(CONFIG_MDIO_OCTEON) += mdio-octeon.o
drivers/net/phy/dp83640.c new file +896 -0
896 lines not on this page · raw message
drivers/net/phy/dp83640_reg.h new file +261 -0
261 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH V10 01/15] time: Introduce timekeeping_inject_offset
In reply to John StultzQuoted 11 lines · John Stultz
This adds a kernel-internal timekeeping interface to add or subtract a fixed amount from
CLOCK_REALTIME. This makes it so kernel users or interfaces trying to do so do not have to read the time, then add an offset and then callsettimeofday(), which adds some extra error in comparision to just simply adding the offset in the kernel timekeeping core.CC Thomas Gleixner <[email protected]>Signed-off-by John Stultz <[email protected]>Signed-off-by Richard Cochran <[email protected]>---
Hey Richard,
Something seems wrong with your mail sending script. It looks like your
sending the email under my name (John Stultz <[email protected]>).
While I appreciate you preserving the path author, and the signoffs are right, you really should send the email under your own name.
The proper style is to keep the mail-header From: the same (ie: Richard Cochran <[email protected]>), but as the first line of the mail body put:
From: Author Name <[email protected]>
thanks
-john
Richard Cochran
maintainerRe: [PATCH V10 01/15] time: Introduce timekeeping_inject_offset
Quoted 2 lines · John Stultz
While I appreciate you preserving the path author, and the signoffs are right, you really should send the email under your own name.
Guess I've been reading too much spam. It wore off on me.
Quoted 4 lines
The proper style is to keep the mail-header From: the same (ie: Richard
Cochran <[email protected]>), but as the first line of the mail body put:
From: Author Name <author-MBgCfJrXA/[email protected]>
Sorry about this. Arnd already explained this to me, and I did catch it with V9. This time I forgot.
I would like to get to the bottom of this. Here is what I did:
1. Saved your patch to disk in mbox format using Mutt.
2. git am
3. ... rebase, rebase, rebase, ...
4. git format-patch [options] 1234..abcd
5. Edit cover letter
6. for x in 00*; do mutt -H $x; done
Git format-patch places the "From: John Stultz <[email protected]>" line with the other mail headers, and so I guess mutt just faithfully
preserves this.
I don't like having to remember to fix this manually. There must be a better way...
Sorry,
Richard
Arnd Bergmann
maintainerRe: [PATCH V10 01/15] time: Introduce timekeeping_inject_offset
Quoted 9 lines · Richard Cochran
I would like to get to the bottom of this. Here is what I did:
1. Saved your patch to disk in mbox format using Mutt.
2. git am
3. ... rebase, rebase, rebase, ...
4. git format-patch [options] 1234..abcd
5. Edit cover letter
6. for x in 00*; do mutt -H $x; done
Quoted 6 lines
Git format-patch places the "From: John Stultz <[email protected]>" line with the other mail headers, and so I guess mutt just faithfully
preserves this.I don't like having to remember to fix this manually. There must be a better way...
The problem is step 6. The output of git format-patch does not work when sending with mutt. The easiest solution is to send with git send-email, which does the same as mutt -H, but gets it right.
Arnd
Re: [PATCH V10 01/15] time: Introduce timekeeping_inject_offset
Quoted 14 lines · Arnd Bergmann
Quoted 13 lines · Richard Cochran
I would like to get to the bottom of this. Here is what I did:
1. Saved your patch to disk in mbox format using Mutt.
2. git am
3. ... rebase, rebase, rebase, ...
4. git format-patch [options] 1234..abcd
5. Edit cover letter
6. for x in 00*; do mutt -H $x; doneGit format-patch places the "From: John Stultz <[email protected]>" line with the other mail headers, and so I guess mutt just faithfully preserves this.
Quoted 6 lines
Quoted 2 lines
I don't like having to remember to fix this manually. There must be a better way...
The problem is step 6. The output of git format-patch does not work when sending with mutt. The easiest solution is to send with git send-email, which does the same as mutt -H, but gets it right.
I use: formail -s sendmail -t < patches.mbox, but then, I use quilt mail to generate the mbox, not git.
Arnd Bergmann
maintainerRe: [PATCH V10 01/15] time: Introduce timekeeping_inject_offset
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines
The problem is step 6. The output of git format-patch does not work when sending with mutt. The easiest solution is to send with git send-email, which does the same as mutt -H, but gets it right.
I use: formail -s sendmail -t < patches.mbox, but then, I use quilt mail to generate the mbox, not git.
I think in that case, quilt generates the correct 'From' headers both in the actual email headers and in the body, so you can use any standard email client to send it out.
Arnd
Quoted 4 lines · Richard Cochran
Here is version 10 of the PHC patch series. We missed the boat for 2.6.38, but I hope this can be merged for the next one.
Reviewers: I think its done. How can I get this merged?
Looks pretty good. I go through the patches again and I'd like to have a ack/reviewed by from John. The whole thing can go through tip/timers.
Quoted 2 lines
Arch maintainers (arm, blackfin, powerpc, x86): I have added you on CC in the hope of getting your acks for the new syscall.
I'll take the x86 one right away. For the other archs we can apply those patches via the arch trees even during the merge window.
Thanks,
tglx
Re: [PATCH V10 12/15] ptp: Added a brand new class driver for ptp clocks.
In reply to Richard CochranQuoted 9 lines · Richard Cochran
This patch adds an infrastructure for hardware clocks that implement IEEE 1588, the Precision Time Protocol (PTP). A class driver offers a registration method to particular hardware clock drivers. Each clock is presented as a standard POSIX clock.
The ancillary clock features are exposed in two different ways, via the sysfs and by a character device.
Few issues below.
Quoted 23 lines
drivers/ptp/Kconfig new file +17
-0@@ -0,0 +1,27 @@ +# +# PTP clock support configuration +# + +menu "PTP clock support" + +config PTP_1588_CLOCK + tristate "PTP clock support" + depends on EXPERIMENTAL + depends on PPS + help + The IEEE 1588 standard defines a method to precisely + synchronize distributed clocks over Ethernet networks. The + standard defines a Precision Time Protocol (PTP), which can + be used to achieve synchronization within a few dozen + microseconds. In addition, with the help of special hardware + time stamping units, it can be possible to achieve
drivers/ptp/Kconfig line 27
Quoted 10 lines
drivers/ptp/Kconfig new file +10
-0+ synchronization to within a few hundred nanoseconds. + + This driver adds support for PTP clocks as character + devices. If you want to use a PTP clock, then you should + also enable at least one clock driver as well. + + To compile this driver as a module, choose M here: the module + will be called ptp. + +endmenu
You may want to tweak the kconfig a bit here. If I don't have pps enabled, if I go into the "PTP clock support" page, I get an empty screen.
Similarly, its not very discoverable to figure out what you need to enable to get the driver options to show up, as they depend the drivers enabled in the networking device section.
Quoted 31 lines
drivers/ptp/ptp_clock.c new file +25
-0@@ -0,0 +1,315 @@ +/* +* PTP 1588 clock support +* +* Copyright (C) 2010 OMICRON electronics GmbH +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include <linux/bitops.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h>
drivers/ptp/ptp_clock.c line 35
Quoted 10 lines
drivers/ptp/ptp_clock.c new file +10
-0+#include <linux/posix-clock.h> +#include <linux/pps_kernel.h> +#include <linux/slab.h> +#include <linux/syscalls.h> +#include <linux/uaccess.h> + +#include "ptp_private.h" + +#define PTP_MAX_ALARMS 4 +#define PTP_MAX_CLOCKS (MAX_CLOCKS/2)
Why MAX_CLOCKS/2 ? Should this scale as MAX_CLOCKS is increased? Or do you really just mean 8?
Quoted 26 lines
drivers/ptp/ptp_clock.c new file +26
-0+#define PTP_PPS_DEFAULTS (PPS_CAPTUREASSERT | PPS_OFFSETASSERT) +#define PTP_PPS_EVENT PPS_CAPTUREASSERT +#define PTP_PPS_MODE (PTP_PPS_DEFAULTS | PPS_CANWAIT | PPS_TSFMT_TSPEC) + +/* private globals */ + +static dev_t ptp_devt; +static struct class *ptp_class; + +static DECLARE_BITMAP(ptp_clocks_map, PTP_MAX_CLOCKS); +static DEFINE_MUTEX (ptp_clocks_mutex);/* protects 'ptp_clocks_map' */ + +/* time stamp event queue operations */ + +static inline int queue_free (struct timestamp_event_queue *q) +{ +return PTP_MAX_TIMESTAMPS -queue_cnt (q) -1 ; +} + +static void enqueue_external_timestamp (struct timestamp_event_queue *queue, +struct ptp_clock_event *src) +{ +struct ptp_extts_event *dst; +u32 remainder; + + dst = &queue->buf[queue->tail];
drivers/ptp/ptp_clock.c line 71
Quoted 10 lines
drivers/ptp/ptp_clock.c new file +10
-0+ + dst->index = src->index; + dst->t.sec =div_u64_rem (src->timestamp,1000000000 , &remainder); + dst->t.nsec = remainder; + +if (!queue_free (queue)) + queue->overflow++; + + queue->tail = (queue->tail +1 ) %PTP_MAX_TIMESTAMPS ; +}
So what is serializing access to the timestamp_event_queue here? I don't see any usage of tsevq_mux by the callers. Am I missing it? It looks like its called from interrupt context, so do you really need a spinlock and not a mutex here?
Quoted 52 lines
drivers/ptp/ptp_private.h new file +46
-0@@ -0,0 +1,85 @@ +/* +* PTP 1588 clock support - private declarations for the core module. +* +* Copyright (C) 2010 OMICRON electronics GmbH +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#ifndef _PTP_PRIVATE_H_ +#define _PTP_PRIVATE_H_ + +#include <linux/cdev.h> +#include <linux/device.h> +#include <linux/mutex.h> +#include <linux/posix-clock.h> +#include <linux/ptp_clock.h> +#include <linux/ptp_clock_kernel.h> +#include <linux/time.h> + +#define PTP_MAX_TIMESTAMPS 128 + +struct timestamp_event_queue { + struct ptp_extts_event buf[PTP_MAX_TIMESTAMPS]; + int head; + int tail; + int overflow; +}; + +struct ptp_clock { + struct posix_clock clock; + struct device *dev; + struct ptp_clock_info *info; + dev_t devid; + int index; /* index into clocks.map */ + struct pps_device *pps_source;
drivers/ptp/ptp_private.h line 56
Quoted 10 lines
drivers/ptp/ptp_private.h new file +10
-0+struct timestamp_event_queue tsevq;/* simple fifo for time stamps */ +struct mutex tsevq_mux;/* one process at a time reading the fifo */ +wait_queue_head_t tsev_wq; +}; + +static inline int queue_cnt (struct timestamp_event_queue *q) +{ +int cnt = q->tail - q->head; +return cnt <0 ?PTP_MAX_TIMESTAMPS + cnt : cnt; +}
This probably needs a comment as to its locking rules. Something like "Callers must hold tsevq_mux."
Quoted 61 lines
include/linux/ptp_clock.h new file +55
-0@@ -0,0 +1,79 @@ +/* +* PTP 1588 clock support - user space interface +* +* Copyright (C) 2010 OMICRON electronics GmbH +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef _PTP_CLOCK_H_ +#define _PTP_CLOCK_H_ + +#include <linux/ioctl.h> +#include <linux/types.h> + +/* PTP_xxx bits, for the flags field within the request structures. */ +#define PTP_ENABLE_FEATURE (1<<0) +#define PTP_RISING_EDGE (1<<1) +#define PTP_FALLING_EDGE (1<<2) + +/* +* struct ptp_clock_time - represents a time value +* +* The sign of the seconds field applies to the whole value. The +* nanoseconds field is always unsigned. The reserved field is +* included for sub-nanosecond resolution, should the demand for +* this ever appear. +* +*/ +struct ptp_clock_time { +__s64 sec;/* seconds */ +__u32 nsec;/* nanoseconds */ +__u32 reserved; +}; + +struct ptp_clock_caps { +int max_adj;/* Maximum frequency adjustment in parts per billon. */ +int n_alarm;/* Number of programmable alarms. */ +int n_ext_ts;/* Number of external time stamp channels. */ +int n_per_out;/* Number of programmable periodic signals. */ +int pps;/* Whether the clock supports a PPS callback. */ +}; + +struct ptp_extts_request {
include/linux/ptp_clock.h line 65
Quoted 10 lines
include/linux/ptp_clock.h new file +10
-0+unsigned int index;/* Which channel to configure. */ +unsigned int flags;/* Bit field for PTP_xxx flags. */ +}; + +struct ptp_perout_request { +struct ptp_clock_time start;/* Absolute start time. */ +struct ptp_clock_time period;/* Desired period, zero means disable. */ +unsigned int index;/* Which channel to configure. */ +unsigned int flags;/* Reserved for future use. */ +};
Since these are all new API/ABI structures, would it be wise to pad these out a bit more? You've got a couple of reserved fields, which is good, but if you think we're going to expand this at all, we may want to have a bit more wiggle room. The timex structure had something like 12 unused ints (which came in handy when the tai field was added).
Not sure what the wider opinion is on this though.
include/linux/ptp_clock.h line 77
Quoted 11 lines
include/linux/ptp_clock.h new file +11
-0+#define PTP_CLK_MAGIC '=' + +#define PTP_CLOCK_GETCAPS _IOR(PTP_CLK_MAGIC, 1, struct ptp_clock_caps) +#define PTP_EXTTS_REQUEST _IOW(PTP_CLK_MAGIC, 2, struct ptp_extts_request) +#define PTP_PEROUT_REQUEST _IOW(PTP_CLK_MAGIC, 3, struct ptp_perout_request) +#define PTP_ENABLE_PPS _IOW(PTP_CLK_MAGIC, 4, int) + +struct ptp_extts_event { +struct ptp_clock_time t;/* Time event occured. */ +unsigned int index;/* Which channel produced the event. */ +};
Same padding suggestion for this as well.
thanks
-john
Re: [PATCH V10 13/15] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
In reply to Richard CochranQuoted 5 lines · Richard Cochran
The eTSEC includes a PTP clock with quite a few features. This patch adds support for the basic clock adjustment functions, plus two external time stamps, one alarm, and the PPS callback.
This looks ok to me.
Quoted 786 lines
--- Documentation/powerpc/dts-bindings/fsl/tsec.txt | 57 +++ arch/powerpc/boot/dts/mpc8313erdb.dts | 14 + arch/powerpc/boot/dts/mpc8572ds.dts | 14 + arch/powerpc/boot/dts/p2020ds.dts | 14 + arch/powerpc/boot/dts/p2020rdb.dts | 14 + drivers/net/Makefile | 1 + drivers/net/gianfar_ptp.c | 448 +++++++++++++++++++++++ drivers/net/gianfar_ptp_reg.h | 113 ++++++ drivers/ptp/Kconfig | 13 + 9 files changed, 688 insertions(+), 0 deletions(-) create mode 100644 drivers/net/gianfar_ptp.c create mode 100644 drivers/net/gianfar_ptp_reg.hDocumentation/powerpc/dts-bindings/fsl/tsec.txt +57
-0@@ -74,3 +74,60 @@ Example: interrupt-parent = <&mpic>; phy-handle = <&phy0> }; + +* Gianfar PTP clock nodes + +General Properties: + + - compatible Should be "fsl,etsec-ptp" + - reg Offset and length of the register set for the device + - interrupts There should be at least two interrupts. Some devices + have as many as four PTP related interrupts. + +Clock Properties: + + - tclk-period Timer reference clock period in nanoseconds. + - tmr-prsc Prescaler, divides the output clock. + - tmr-add Frequency compensation value. + - cksel 0= external clock, 1= eTSEC system clock, 3= RTC clock input. + Currently the driver only supports choice "1". + - tmr-fiper1 Fixed interval period pulse generator. + - tmr-fiper2 Fixed interval period pulse generator. + - max-adj Maximum frequency adjustment in parts per billion. + + These properties set the operational parameters for the PTP + clock. You must choose these carefully for the clock to work right. + Here is how to figure good values: + + TimerOsc = system clock MHz + tclk_period = desired clock period nanoseconds + NominalFreq = 1000 / tclk_period MHz + FreqDivRatio = TimerOsc / NominalFreq (must be greater that 1.0) + tmr_add = ceil(2^32 / FreqDivRatio) + OutputClock = NominalFreq / tmr_prsc MHz + PulseWidth = 1 / OutputClock microseconds + FiperFreq1 = desired frequency in Hz + FiperDiv1 = 1000000 * OutputClock / FiperFreq1 + tmr_fiper1 = tmr_prsc * tclk_period * FiperDiv1 - tclk_period + max_adj = 1000000000 * (FreqDivRatio - 1.0) - 1 + + The calculation for tmr_fiper2 is the same as for tmr_fiper1. The + driver expects that tmr_fiper1 will be correctly set to produce a 1 + Pulse Per Second (PPS) signal, since this will be offered to the PPS + subsystem to synchronize the Linux clock. + +Example: + + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <12 0x8 13 0x8>; + interrupt-parent = < &ipic >; + tclk-period = <10>; + tmr-prsc = <100>; + tmr-add = <0x999999A4>; + cksel = <0x1>; + tmr-fiper1 = <0x3B9AC9F6>; + tmr-fiper2 = <0x00018696>; + max-adj = <659999998>; + };arch/powerpc/boot/dts/mpc8313erdb.dts +14
-0@@ -208,6 +208,20 @@ sleep = <&pmc 0x00300000>; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <12 0x8 13 0x8>; + interrupt-parent = < &ipic >; + tclk-period = <10>; + tmr-prsc = <100>; + tmr-add = <0x999999A4>; + cksel = <0x1>; + tmr-fiper1 = <0x3B9AC9F6>; + tmr-fiper2 = <0x00018696>; + max-adj = <659999998>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;arch/powerpc/boot/dts/mpc8572ds.dts +14
-0@@ -324,6 +324,20 @@ }; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <68 2 69 2 70 2 71 2>; + interrupt-parent = < &mpic >; + tclk-period = <5>; + tmr-prsc = <200>; + tmr-add = <0xAAAAAAAB>; + cksel = <1>; + tmr-fiper1 = <0x3B9AC9FB>; + tmr-fiper2 = <0x3B9AC9FB>; + max-adj = <499999999>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;arch/powerpc/boot/dts/p2020ds.dts +14
-0@@ -336,6 +336,20 @@ phy_type = "ulpi"; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <68 2 69 2 70 2>; + interrupt-parent = < &mpic >; + tclk-period = <5>; + tmr-prsc = <200>; + tmr-add = <0xCCCCCCCD>; + cksel = <1>; + tmr-fiper1 = <0x3B9AC9FB>; + tmr-fiper2 = <0x0001869B>; + max-adj = <249999999>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;arch/powerpc/boot/dts/p2020rdb.dts +14
-0@@ -396,6 +396,20 @@ phy_type = "ulpi"; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <68 2 69 2 70 2>; + interrupt-parent = < &mpic >; + tclk-period = <5>; + tmr-prsc = <200>; + tmr-add = <0xCCCCCCCD>; + cksel = <1>; + tmr-fiper1 = <0x3B9AC9FB>; + tmr-fiper2 = <0x0001869B>; + max-adj = <249999999>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;drivers/net/Makefile +1
-0@@ -31,6 +31,7 @@ obj-$(CONFIG_ATL2) += atlx/ obj-$(CONFIG_ATL1E) += atl1e/ obj-$(CONFIG_ATL1C) += atl1c/ obj-$(CONFIG_GIANFAR) += gianfar_driver.o +obj-$(CONFIG_PTP_1588_CLOCK_GIANFAR) += gianfar_ptp.o obj-$(CONFIG_TEHUTI) += tehuti.o obj-$(CONFIG_ENIC) += enic/ obj-$(CONFIG_JME) += jme.odrivers/net/gianfar_ptp.c new file +448
-0@@ -0,0 +1,448 @@ +/* +* PTP 1588 clock using the eTSEC +* +* Copyright (C) 2010 OMICRON electronics GmbH +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include <linux/device.h> +#include <linux/hrtimer.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_platform.h> +#include <linux/timex.h> +#include <linux/io.h> + +#include <linux/ptp_clock_kernel.h> + +#include "gianfar_ptp_reg.h" +#include "gianfar.h" + +#define DRIVER "gianfar_ptp" +#define N_ALARM 1/* first alarm is used internally to reset fipers */ +#define N_EXT_TS 2 +#define REG_SIZE sizeof(struct gianfar_ptp_registers) + +struct etsects { +struct gianfar_ptp_registers *regs; +struct ptp_clock *clock; +struct ptp_clock_info caps; +int irq; +u64 alarm_interval;/* for periodic alarm */ +u64 alarm_value; +u32 tclk_period;/* nanoseconds */ +u32 tmr_prsc; +u32 tmr_add; +u32 cksel; +u32 tmr_fiper1; +u32 tmr_fiper2; +}; + +/* Private globals */ +static struct etsects the_clock; +DEFINE_SPINLOCK (register_lock); + +/* +* Register access functions +*/ + +static u64 tmr_cnt_read (struct etsects *etsects) +{ +u64 ns; +u32 lo, hi; + + lo =gfar_read (&etsects->regs->tmr_cnt_l); + hi =gfar_read (&etsects->regs->tmr_cnt_h); + ns = ((u64 ) hi) <<32 ; + ns |= lo; +return ns; +} + +static void tmr_cnt_write (struct etsects *etsects,u64 ns) +{ +u32 hi = ns >>32 ; +u32 lo = ns &0xffffffff ; + +gfar_write (&etsects->regs->tmr_cnt_l, lo); +gfar_write (&etsects->regs->tmr_cnt_h, hi); +} + +static void set_alarm (struct etsects *etsects) +{ +u64 ns; +u32 lo, hi; + + ns =tmr_cnt_read (etsects) +1500000000ULL ; + ns =div_u64 (ns,1000000000UL ) *1000000000ULL ; + ns -= etsects->tclk_period; + hi = ns >>32 ; + lo = ns &0xffffffff ; +gfar_write (&etsects->regs->tmr_alarm1_l, lo); +gfar_write (&etsects->regs->tmr_alarm1_h, hi); +} + +static void set_fipers (struct etsects *etsects) +{ +u32 tmr_ctrl =gfar_read (&etsects->regs->tmr_ctrl); + +gfar_write (&etsects->regs->tmr_ctrl, tmr_ctrl & (~TE )); +gfar_write (&etsects->regs->tmr_prsc, etsects->tmr_prsc); +gfar_write (&etsects->regs->tmr_fiper1, etsects->tmr_fiper1); +gfar_write (&etsects->regs->tmr_fiper2, etsects->tmr_fiper2); +set_alarm (etsects); +gfar_write (&etsects->regs->tmr_ctrl, tmr_ctrl|TE ); +} + +/* +* Interrupt service routine +*/ + +static irqreturn_t isr (int irq,void *priv) +{ +struct etsects *etsects = priv; +struct ptp_clock_event event; +u64 ns; +u32 ack =0 , lo, hi, mask, val; + + val =gfar_read (&etsects->regs->tmr_tevent); + +if (val &ETS1 ) { + ack |=ETS1 ; + hi =gfar_read (&etsects->regs->tmr_etts1_h); + lo =gfar_read (&etsects->regs->tmr_etts1_l); + event.type =PTP_CLOCK_EXTTS ; + event.index =0 ; + event.timestamp = ((u64 ) hi) <<32 ; + event.timestamp |= lo; +ptp_clock_event (etsects->clock, &event); + } + +if (val &ETS2 ) { + ack |=ETS2 ; + hi =gfar_read (&etsects->regs->tmr_etts2_h); + lo =gfar_read (&etsects->regs->tmr_etts2_l); + event.type =PTP_CLOCK_EXTTS ; + event.index =1 ; + event.timestamp = ((u64 ) hi) <<32 ; + event.timestamp |= lo; +ptp_clock_event (etsects->clock, &event); + } + +if (val &ALM2 ) { + ack |=ALM2 ; +if (etsects->alarm_value) { + event.type =PTP_CLOCK_ALARM ; + event.index =0 ; + event.timestamp = etsects->alarm_value; +ptp_clock_event (etsects->clock, &event); + } +if (etsects->alarm_interval) { + ns = etsects->alarm_value + etsects->alarm_interval; + hi = ns >>32 ; + lo = ns &0xffffffff ; +spin_lock (®ister_lock); +gfar_write (&etsects->regs->tmr_alarm2_l, lo); +gfar_write (&etsects->regs->tmr_alarm2_h, hi); +spin_unlock (®ister_lock); + etsects->alarm_value = ns; + }else { +gfar_write (&etsects->regs->tmr_tevent,ALM2 ); +spin_lock (®ister_lock); + mask =gfar_read (&etsects->regs->tmr_temask); + mask &= ~ALM2EN ; +gfar_write (&etsects->regs->tmr_temask, mask); +spin_unlock (®ister_lock); + etsects->alarm_value =0 ; + etsects->alarm_interval =0 ; + } + } + +if (val &PP1 ) { + ack |=PP1 ; + event.type =PTP_CLOCK_PPS ; +ptp_clock_event (etsects->clock, &event); + } + +if (ack) { +gfar_write (&etsects->regs->tmr_tevent, ack); +return IRQ_HANDLED ; + }else +return IRQ_NONE ; +} + +/* +* PTP clock operations +*/ + +static int ptp_gianfar_adjfreq (struct ptp_clock_info *ptp,s32 ppb) +{ +u64 adj; +u32 diff, tmr_add; +int neg_adj =0 ; + struct etsects *etsects = container_of(ptp, struct etsects, caps); + +if (ppb <0 ) { + neg_adj =1 ; + ppb = -ppb; + } + tmr_add = etsects->tmr_add; + adj = tmr_add; + adj *= ppb; + diff =div_u64 (adj,1000000000ULL ); + + tmr_add = neg_adj ? tmr_add - diff : tmr_add + diff; + +gfar_write (&etsects->regs->tmr_add, tmr_add); + +return 0 ; +} + +static int ptp_gianfar_adjtime (struct ptp_clock_info *ptp,s64 delta) +{ +s64 now; +unsigned long flags; + struct etsects *etsects = container_of(ptp, struct etsects, caps); + +spin_lock_irqsave (®ister_lock, flags); + + now =tmr_cnt_read (etsects); + now += delta; +tmr_cnt_write (etsects, now); + +spin_unlock_irqrestore (®ister_lock, flags); + +set_fipers (etsects); + +return 0 ; +} + +static int ptp_gianfar_gettime (struct ptp_clock_info *ptp,struct timespec *ts) +{ +u64 ns; +u32 remainder; +unsigned long flags; + struct etsects *etsects = container_of(ptp, struct etsects, caps); + +spin_lock_irqsave (®ister_lock, flags); + + ns =tmr_cnt_read (etsects); + +spin_unlock_irqrestore (®ister_lock, flags); + + ts->tv_sec =div_u64_rem (ns,1000000000 , &remainder); + ts->tv_nsec = remainder; +return 0 ; +} + +static int ptp_gianfar_settime (struct ptp_clock_info *ptp, +const struct timespec *ts) +{ +u64 ns; +unsigned long flags; + struct etsects *etsects = container_of(ptp, struct etsects, caps); + + ns = ts->tv_sec *1000000000ULL ; + ns += ts->tv_nsec; + +spin_lock_irqsave (®ister_lock, flags); + +tmr_cnt_write (etsects, ns); +set_fipers (etsects); + +spin_unlock_irqrestore (®ister_lock, flags); + +return 0 ; +} + +static int ptp_gianfar_enable (struct ptp_clock_info *ptp, +struct ptp_clock_request *rq,int on) +{ + struct etsects *etsects = container_of(ptp, struct etsects, caps); +unsigned long flags; +u32 bit, mask; + +switch (rq->type) { +case PTP_CLK_REQ_EXTTS : +switch (rq->extts.index) { +case 0 : + bit =ETS1EN ; +break ; +case 1 : + bit =ETS2EN ; +break ; +default : +return -EINVAL ; + } +spin_lock_irqsave (®ister_lock, flags); + mask =gfar_read (&etsects->regs->tmr_temask); +if (on) + mask |= bit; +else + mask &= ~bit; +gfar_write (&etsects->regs->tmr_temask, mask); +spin_unlock_irqrestore (®ister_lock, flags); +return 0 ; + +case PTP_CLK_REQ_PPS : +spin_lock_irqsave (®ister_lock, flags); + mask =gfar_read (&etsects->regs->tmr_temask); +if (on) + mask |=PP1EN ; +else + mask &= ~PP1EN ; +gfar_write (&etsects->regs->tmr_temask, mask); +spin_unlock_irqrestore (®ister_lock, flags); +return 0 ; + +default : +break ; + } + +return -EOPNOTSUPP ; +} + +static struct ptp_clock_info ptp_gianfar_caps = { + .owner =THIS_MODULE , + .name ="gianfar clock" , + .max_adj =512000 , + .n_alarm =N_ALARM , + .n_ext_ts =N_EXT_TS , + .n_per_out =0 , + .pps =1 , + .adjfreq = ptp_gianfar_adjfreq, + .adjtime = ptp_gianfar_adjtime, + .gettime = ptp_gianfar_gettime, + .settime = ptp_gianfar_settime, + .enable = ptp_gianfar_enable, +}; + +/* OF device tree */ + +static int get_of_u32 (struct device_node *node,char *str,u32 *val) +{ +int plen; +const u32 *prop =of_get_property (node, str, &plen); + +if (!prop || plen !=sizeof (*prop)) +return -1 ; + *val = *prop; +return 0 ; +} + +static int gianfar_ptp_probe (struct platform_device *dev, +const struct of_device_id *match) +{ +struct device_node *node = dev->dev.of_node; +struct etsects *etsects = &the_clock; +struct timespec now; +u32 tmr_ctrl; + + etsects->caps = ptp_gianfar_caps; + +if (get_of_u32 (node,"tclk-period" , &etsects->tclk_period) || +get_of_u32 (node,"tmr-prsc" , &etsects->tmr_prsc) || +get_of_u32 (node,"tmr-add" , &etsects->tmr_add) || +get_of_u32 (node,"cksel" , &etsects->cksel) || +get_of_u32 (node,"tmr-fiper1" , &etsects->tmr_fiper1) || +get_of_u32 (node,"tmr-fiper2" , &etsects->tmr_fiper2) || +get_of_u32 (node,"max-adj" , &etsects->caps.max_adj)) { +pr_err ("device tree node missing required elements\n" ); +return -ENODEV ; + } + + etsects->irq =irq_of_parse_and_map (node,0 ); + +if (etsects->irq ==NO_IRQ ) { +pr_err ("irq not in device tree\n" ); +return -ENODEV ; + } +if (request_irq (etsects->irq, isr,0 ,DRIVER , etsects)) { +pr_err ("request_irq failed\n" ); +return -ENODEV ; + } + etsects->regs =of_iomap (node,0 ); +if (!etsects->regs) { +pr_err ("of_iomap ptp registers failed\n" ); +return -EINVAL ; + } +getnstimeofday (&now); +ptp_gianfar_settime (&etsects->caps, &now); + + tmr_ctrl = + (etsects->tclk_period &TCLK_PERIOD_MASK ) <<TCLK_PERIOD_SHIFT | + (etsects->cksel &CKSEL_MASK ) <<CKSEL_SHIFT ; + +gfar_write (&etsects->regs->tmr_ctrl, tmr_ctrl); +gfar_write (&etsects->regs->tmr_add, etsects->tmr_add); +gfar_write (&etsects->regs->tmr_prsc, etsects->tmr_prsc); +gfar_write (&etsects->regs->tmr_fiper1, etsects->tmr_fiper1); +gfar_write (&etsects->regs->tmr_fiper2, etsects->tmr_fiper2); +set_alarm (etsects); +gfar_write (&etsects->regs->tmr_ctrl, tmr_ctrl|FS |RTPE |TE ); + + etsects->clock =ptp_clock_register (&etsects->caps); + +return IS_ERR (etsects->clock) ?PTR_ERR (etsects->clock) :0 ; +} + +static int gianfar_ptp_remove (struct platform_device *dev) +{ +gfar_write (&the_clock.regs->tmr_temask,0 ); +gfar_write (&the_clock.regs->tmr_ctrl,0 ); + +ptp_clock_unregister (the_clock.clock); +free_irq (the_clock.irq, &the_clock); +iounmap (the_clock.regs); + +return 0 ; +} + +static struct of_device_id match_table[] = { + { .compatible ="fsl,etsec-ptp" }, + {}, +}; + +static struct of_platform_driver gianfar_ptp_driver = { + .driver = { + .name ="gianfar_ptp" , + .of_match_table = match_table, + .owner =THIS_MODULE , + }, + .probe = gianfar_ptp_probe, + .remove = gianfar_ptp_remove, +}; + +/* module operations */ + +static int __init ptp_gianfar_init (void ) +{ +return of_register_platform_driver (&gianfar_ptp_driver); +} + +module_init (ptp_gianfar_init); + +static void __exit ptp_gianfar_exit(void) +{ +of_unregister_platform_driver (&gianfar_ptp_driver); +} + +module_exit (ptp_gianfar_exit); + +MODULE_AUTHOR ("Richard Cochran <richard.cochran-3mrvs1K0uXizZXS1Dc/[email protected]>" ); +MODULE_DESCRIPTION ("PTP clock using the eTSEC" ); +MODULE_LICENSE ("GPL" );drivers/net/gianfar_ptp_reg.h new file +113
-0@@ -0,0 +1,113 @@ +/* gianfar_ptp_reg.h +* Generated by regen.tcl on Thu May 13 01:38:57 PM CEST 2010 +* +* PTP 1588 clock using the gianfar eTSEC +* +* Copyright (C) 2010 OMICRON electronics GmbH +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#ifndef _GIANFAR_PTP_REG_H_ +#define _GIANFAR_PTP_REG_H_ + +struct gianfar_ptp_registers { +u32 tmr_ctrl;/* Timer control register */ +u32 tmr_tevent;/* Timestamp event register */ +u32 tmr_temask;/* Timer event mask register */ +u32 tmr_pevent;/* Timestamp event register */ +u32 tmr_pemask;/* Timer event mask register */ +u32 tmr_stat;/* Timestamp status register */ +u32 tmr_cnt_h;/* Timer counter high register */ +u32 tmr_cnt_l;/* Timer counter low register */ +u32 tmr_add;/* Timer drift compensation addend register */ +u32 tmr_acc;/* Timer accumulator register */ +u32 tmr_prsc;/* Timer prescale */ +u8 res1[4 ]; +u32 tmroff_h;/* Timer offset high */ +u32 tmroff_l;/* Timer offset low */ +u8 res2[8 ]; +u32 tmr_alarm1_h;/* Timer alarm 1 high register */ +u32 tmr_alarm1_l;/* Timer alarm 1 high register */ +u32 tmr_alarm2_h;/* Timer alarm 2 high register */ +u32 tmr_alarm2_l;/* Timer alarm 2 high register */ +u8 res3[48 ]; +u32 tmr_fiper1;/* Timer fixed period interval */ +u32 tmr_fiper2;/* Timer fixed period interval */ +u32 tmr_fiper3;/* Timer fixed period interval */ +u8 res4[20 ]; +u32 tmr_etts1_h;/* Timestamp of general purpose external trigger */ +u32 tmr_etts1_l;/* Timestamp of general purpose external trigger */ +u32 tmr_etts2_h;/* Timestamp of general purpose external trigger */ +u32 tmr_etts2_l;/* Timestamp of general purpose external trigger */ +}; + +/* Bit definitions for the TMR_CTRL register */ +#define ALM1P (1<<31)/* Alarm1 output polarity */ +#define ALM2P (1<<30)/* Alarm2 output polarity */ +#define FS (1<<28)/* FIPER start indication */ +#define PP1L (1<<27)/* Fiper1 pulse loopback mode enabled. */ +#define PP2L (1<<26)/* Fiper2 pulse loopback mode enabled. */ +#define TCLK_PERIOD_SHIFT (16)/* 1588 timer reference clock period. */ +#define TCLK_PERIOD_MASK (0x3ff) +#define RTPE (1<<15)/* Record Tx Timestamp to PAL Enable. */ +#define FRD (1<<14)/* FIPER Realignment Disable */ +#define ESFDP (1<<11)/* External Tx/Rx SFD Polarity. */ +#define ESFDE (1<<10)/* External Tx/Rx SFD Enable. */ +#define ETEP2 (1<<9)/* External trigger 2 edge polarity */ +#define ETEP1 (1<<8)/* External trigger 1 edge polarity */ +#define COPH (1<<7)/* Generated clock (TSEC_1588_GCLK) output phase. */ +#define CIPH (1<<6)/* External oscillator input clock phase. */ +#define TMSR (1<<5)/* Timer soft reset. When enabled, it resets all the timer registers and state machines. */ +#define BYP (1<<3)/* Bypass drift compensated clock */ +#define TE (1<<2)/* 1588 timer enable. If not enabled, all the timer registers and state machines are disabled. */ +#define CKSEL_SHIFT (0)/* 1588 Timer reference clock source select. */ +#define CKSEL_MASK (0x3) + +/* Bit definitions for the TMR_TEVENT register */ +#define ETS2 (1<<25)/* External trigger 2 timestamp sampled */ +#define ETS1 (1<<24)/* External trigger 1 timestamp sampled */ +#define ALM2 (1<<17)/* Current time equaled alarm time register 2 */ +#define ALM1 (1<<16)/* Current time equaled alarm time register 1 */ +#define PP1 (1<<7)/* Indicates that a periodic pulse has been generated based on FIPER1 register */ +#define PP2 (1<<6)/* Indicates that a periodic pulse has been generated based on FIPER2 register */ +#define PP3 (1<<5)/* Indicates that a periodic pulse has been generated based on FIPER3 register */ + +/* Bit definitions for the TMR_TEMASK register */ +#define ETS2EN (1<<25)/* External trigger 2 timestamp sample event enable */ +#define ETS1EN (1<<24)/* External trigger 1 timestamp sample event enable */ +#define ALM2EN (1<<17)/* Timer ALM2 event enable */ +#define ALM1EN (1<<16)/* Timer ALM1 event enable */ +#define PP1EN (1<<7)/* Periodic pulse event 1 enable */ +#define PP2EN (1<<6)/* Periodic pulse event 2 enable */ + +/* Bit definitions for the TMR_PEVENT register */ +#define TXP2 (1<<9)/* Indicates that a PTP frame has been transmitted and its timestamp is stored in TXTS2 register */ +#define TXP1 (1<<8)/* Indicates that a PTP frame has been transmitted and its timestamp is stored in TXTS1 register */ +#define RXP (1<<0)/* Indicates that a PTP frame has been received */ + +/* Bit definitions for the TMR_PEMASK register */ +#define TXP2EN (1<<9)/* Transmit PTP packet event 2 enable */ +#define TXP1EN (1<<8)/* Transmit PTP packet event 1 enable */ +#define RXPEN (1<<0)/* Receive PTP packet event enable */ + +/* Bit definitions for the TMR_STAT register */ +#define STAT_VEC_SHIFT (0)/* Timer general purpose status vector */ +#define STAT_VEC_MASK (0x3f) + +/* Bit definitions for the TMR_PRSC register */ +#define PRSC_OCK_SHIFT (0)/* Output clock division/prescale factor. */ +#define PRSC_OCK_MASK (0xffff) + +#endif drivers/ptp/Kconfig +13
-0@@ -24,4 +24,17 @@ config PTP_1588_CLOCK To compile this driver as a module, choose M here: the module will be called ptp. +config PTP_1588_CLOCK_GIANFAR + tristate "Freescale eTSEC as PTP clock" + depends on PTP_1588_CLOCK + depends on GIANFAR + help + This driver adds support for using the eTSEC as a PTP + clock. This clock is only useful if your PTP programs are + getting hardware time stamps on the PTP Ethernet packets + using the SO_TIMESTAMPING API. + + To compile this driver as a module, choose M here: the module + will be called gianfar_ptp. + endmenu
Re: [PATCH V10 14/15] ptp: Added a clock driver for the IXP46x.
In reply to Richard CochranQuoted 4 lines · Richard Cochran
This patch adds a driver for the hardware time stamping unit found on the IXP465. The basic clock operations and an external trigger are implemented.
Minor nit below, but otherwise,
Quoted 5 lines
drivers/ptp/ptp_ixp46x.c new file +0
-0
[snip]
drivers/ptp/ptp_ixp46x.c line 296
Quoted 7 lines
drivers/ptp/ptp_ixp46x.c new file +7
-0+static int __init ptp_ixp_init (void ) +{ +if (!cpu_is_ixp46x ()) +return -ENODEV ; + + ixp_clock.regs = + (struct ixp46x_ts_regs __iomem *)IXP4XX_TIMESYNC_BASE_VIRT ;
Minor whitespace issue here
Re: [PATCH V10 15/15] ptp: Added a clock driver for the National Semiconductor PHYTER.
In reply to Richard CochranQuoted 5 lines · Richard Cochran
This patch adds support for the PTP clock found on the DP83640. The basic clock operations and one external time stamp have been implemented.
Richard Cochran
maintainerRe: [PATCH V10 12/15] ptp: Added a brand new class driver for ptp clocks.
In reply to John StultzQuoted 9 lines · John Stultz
On Thu, 2011-01-27 at 11:59 +0100, Richard Cochran wrote:
You may want to tweak the kconfig a bit here. If I don't have pps enabled, if I go into the "PTP clock support" page, I get an empty screen.
Similarly, its not very discoverable to figure out what you need to enable to get the driver options to show up, as they depend the drivers enabled in the networking device section.
Okay, I'll see what I can come up with.
Quoted 5 lines
drivers/ptp/ptp_clock.c line 35
Quoted 2 lines
drivers/ptp/ptp_clock.c new file +2
-0+#define PTP_MAX_ALARMS 4 +#define PTP_MAX_CLOCKS (MAX_CLOCKS/2)Why MAX_CLOCKS/2 ? Should this scale as
MAX_CLOCKSis increased? Or do you really just mean 8?
This is just left over from when I thought the PHCs would use the static clock IDs. I'll fix that.
Quoted 14 lines
Quoted 14 lines
drivers/ptp/ptp_clock.c new file +14
-0+static void enqueue_external_timestamp (struct timestamp_event_queue *queue, +struct ptp_clock_event *src) +{ +struct ptp_extts_event *dst; +u32 remainder; + + dst = &queue->buf[queue->tail]; + + dst->index = src->index; + dst->t.sec =div_u64_rem (src->timestamp,1000000000 , &remainder); + dst->t.nsec = remainder; + +if (!queue_free (queue)) + queue->overflow++;
Quoted 8 lines
drivers/ptp/ptp_clock.c line 71
Quoted 3 lines
drivers/ptp/ptp_clock.c new file +3
-0+ + queue->tail = (queue->tail +1 ) %PTP_MAX_TIMESTAMPS ; +}So what is serializing access to the
timestamp_event_queuehere? I don't see any usage oftsevq_muxby the callers. Am I missing it? It looks like its called from interrupt context, so do you really need a spinlock and not a mutex here?
The external timestamp FIFO is written only from interrupt context. The readers are from user space via read() or sysfs. The readers must hold a mutex. As you know, FIFOs with exactly one reader and one writer don't need locking.
However, looking again at my own code (after spending a long time in the posicx clock stuff), I notice that, although FIFO overflow is detected, I do not offer a way for user space to find this out or to clear the error. I'll fix that.
Quoted 21 lines
Quoted 21 lines
drivers/ptp/ptp_private.h new file +21
-0+#define PTP_MAX_TIMESTAMPS 128 + +struct timestamp_event_queue { +struct ptp_extts_event buf[PTP_MAX_TIMESTAMPS ]; +int head; +int tail; +int overflow; +}; + +struct ptp_clock { +struct posix_clock clock; +struct device *dev; +struct ptp_clock_info *info; +dev_t devid; +int index;/* index into clocks.map */ +struct pps_device *pps_source; +struct timestamp_event_queue tsevq;/* simple fifo for time stamps */ +struct mutex tsevq_mux;/* one process at a time reading the fifo */ +wait_queue_head_t tsev_wq; +}; +
Quoted 8 lines
drivers/ptp/ptp_private.h line 56
Quoted 5 lines
drivers/ptp/ptp_private.h new file +5
-0+static inline int queue_cnt (struct timestamp_event_queue *q) +{ +int cnt = q->tail - q->head; +return cnt <0 ?PTP_MAX_TIMESTAMPS + cnt : cnt; +}This probably needs a comment as to its locking rules. Something like "Callers must hold
tsevq_mux."
I'll add a comment explaining the readers mutex and why no reader/writer locking is needed.
Quoted 32 lines
Quoted 15 lines
include/linux/ptp_clock.h new file +15
-0+struct ptp_clock_time { +__s64 sec;/* seconds */ +__u32 nsec;/* nanoseconds */ +__u32 reserved; +}; + +struct ptp_clock_caps { +int max_adj;/* Maximum frequency adjustment in parts per billon. */ +int n_alarm;/* Number of programmable alarms. */ +int n_ext_ts;/* Number of external time stamp channels. */ +int n_per_out;/* Number of programmable periodic signals. */ +int pps;/* Whether the clock supports a PPS callback. */ +}; + +struct ptp_extts_request {include/linux/ptp_clock.h line 65
Quoted 10 lines
include/linux/ptp_clock.h new file +10
-0+unsigned int index;/* Which channel to configure. */ +unsigned int flags;/* Bit field for PTP_xxx flags. */ +}; + +struct ptp_perout_request { +struct ptp_clock_time start;/* Absolute start time. */ +struct ptp_clock_time period;/* Desired period, zero means disable. */ +unsigned int index;/* Which channel to configure. */ +unsigned int flags;/* Reserved for future use. */ +};Since these are all new API/ABI structures, would it be wise to pad these out a bit more? You've got a couple of reserved fields, which is good, but if you think we're going to expand this at all, we may want to have a bit more wiggle room. The timex structure had something like 12 unused ints (which came in handy when the tai field was added).
Quoted 1 line
Not sure what the wider opinion is on this though.
Okay, I'll pad them a bit more.
However, I don't intend to ever offer more than simple functionality here. A general purpose DAQ API is not so easy to define (look at comedi, for example). Also, the capabilities of the current crop of clocks varies quite a bit.
So, I think the PHC should offer a PPS, simple period outputs, and simple external timestamping. If someone want more complex DAQ like functions, then they can offer that through comedi or whatever.
Quoted 6 lines
include/linux/ptp_clock.h line 77
Quoted 4 lines
include/linux/ptp_clock.h new file +4
-0+struct ptp_extts_event { +struct ptp_clock_time t;/* Time event occured. */ +unsigned int index;/* Which channel produced the event. */ +};Same padding suggestion for this as well.
Okay, and thanks for the review,
Richard
Richard Cochran
maintainerRe: [PATCH V10 15/15] ptp: Added a clock driver for the National Semiconductor PHYTER.
In reply to john stultzQuoted 8 lines · john stultz
Quoted 5 lines · Richard Cochran
This patch adds support for the PTP clock found on the DP83640. The basic clock operations and one external time stamp have been implemented.
Signed-off-by Richard Cochran <[email protected]>Acked-by John Stultz <[email protected]>
I am going to post the PHC patches one more time, and I want to expand this driver to support mutiple PHYs. So, I would ask you to please take a second look at this driver then.
Thanks,
Richard
Richard Cochran
maintainerRe: [PATCH V10 12/15] ptp: Added a brand new class driver for ptp clocks.
In reply to Richard CochranQuoted 7 lines · Richard Cochran
Quoted 4 lines · John Stultz
So what is serializing access to the
timestamp_event_queuehere? I don't see any usage oftsevq_muxby the callers. Am I missing it? It looks like its called from interrupt context, so do you really need a spinlock and not a mutex here?The external timestamp FIFO is written only from interrupt context.
Oops, I lied. After reworking the phyter driver, I find that I want to enqueue time stamps from non-interrupt contexts, too.
So, you are right. This will need a spin lock...
Thanks,
Richard