Commit b566967c authored by David S. Miller's avatar David S. Miller

Merge branch 'ptp-virtual-clock-improvements'

Miroslav Lichvar says:

====================
Virtual PTP clock improvements and fix

v2:
- dropped patch changing initial time of virtual clocks

The first patch fixes an oops when unloading a driver with PTP clock and
enabled virtual clocks.

The other patches add missing features to make synchronization with
virtual clocks work as well as with the physical clock.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 52cc6ffc 21fad630
...@@ -317,11 +317,18 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, ...@@ -317,11 +317,18 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
} }
EXPORT_SYMBOL(ptp_clock_register); EXPORT_SYMBOL(ptp_clock_register);
static int unregister_vclock(struct device *dev, void *data)
{
struct ptp_clock *ptp = dev_get_drvdata(dev);
ptp_vclock_unregister(info_to_vclock(ptp->info));
return 0;
}
int ptp_clock_unregister(struct ptp_clock *ptp) int ptp_clock_unregister(struct ptp_clock *ptp)
{ {
if (ptp_vclock_in_use(ptp)) { if (ptp_vclock_in_use(ptp)) {
pr_err("ptp: virtual clock in use\n"); device_for_each_child(&ptp->dev, NULL, unregister_vclock);
return -EBUSY;
} }
ptp->defunct = 1; ptp->defunct = 1;
......
...@@ -57,6 +57,30 @@ static int ptp_vclock_gettime(struct ptp_clock_info *ptp, ...@@ -57,6 +57,30 @@ static int ptp_vclock_gettime(struct ptp_clock_info *ptp,
return 0; return 0;
} }
static int ptp_vclock_gettimex(struct ptp_clock_info *ptp,
struct timespec64 *ts,
struct ptp_system_timestamp *sts)
{
struct ptp_vclock *vclock = info_to_vclock(ptp);
struct ptp_clock *pptp = vclock->pclock;
struct timespec64 pts;
unsigned long flags;
int err;
u64 ns;
err = pptp->info->gettimex64(pptp->info, &pts, sts);
if (err)
return err;
spin_lock_irqsave(&vclock->lock, flags);
ns = timecounter_cyc2time(&vclock->tc, timespec64_to_ns(&pts));
spin_unlock_irqrestore(&vclock->lock, flags);
*ts = ns_to_timespec64(ns);
return 0;
}
static int ptp_vclock_settime(struct ptp_clock_info *ptp, static int ptp_vclock_settime(struct ptp_clock_info *ptp,
const struct timespec64 *ts) const struct timespec64 *ts)
{ {
...@@ -71,6 +95,28 @@ static int ptp_vclock_settime(struct ptp_clock_info *ptp, ...@@ -71,6 +95,28 @@ static int ptp_vclock_settime(struct ptp_clock_info *ptp,
return 0; return 0;
} }
static int ptp_vclock_getcrosststamp(struct ptp_clock_info *ptp,
struct system_device_crosststamp *xtstamp)
{
struct ptp_vclock *vclock = info_to_vclock(ptp);
struct ptp_clock *pptp = vclock->pclock;
unsigned long flags;
int err;
u64 ns;
err = pptp->info->getcrosststamp(pptp->info, xtstamp);
if (err)
return err;
spin_lock_irqsave(&vclock->lock, flags);
ns = timecounter_cyc2time(&vclock->tc, ktime_to_ns(xtstamp->device));
spin_unlock_irqrestore(&vclock->lock, flags);
xtstamp->device = ns_to_ktime(ns);
return 0;
}
static long ptp_vclock_refresh(struct ptp_clock_info *ptp) static long ptp_vclock_refresh(struct ptp_clock_info *ptp)
{ {
struct ptp_vclock *vclock = info_to_vclock(ptp); struct ptp_vclock *vclock = info_to_vclock(ptp);
...@@ -84,11 +130,9 @@ static long ptp_vclock_refresh(struct ptp_clock_info *ptp) ...@@ -84,11 +130,9 @@ static long ptp_vclock_refresh(struct ptp_clock_info *ptp)
static const struct ptp_clock_info ptp_vclock_info = { static const struct ptp_clock_info ptp_vclock_info = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "ptp virtual clock", .name = "ptp virtual clock",
/* The maximum ppb value that long scaled_ppm can support */ .max_adj = 500000000,
.max_adj = 32767999,
.adjfine = ptp_vclock_adjfine, .adjfine = ptp_vclock_adjfine,
.adjtime = ptp_vclock_adjtime, .adjtime = ptp_vclock_adjtime,
.gettime64 = ptp_vclock_gettime,
.settime64 = ptp_vclock_settime, .settime64 = ptp_vclock_settime,
.do_aux_work = ptp_vclock_refresh, .do_aux_work = ptp_vclock_refresh,
}; };
...@@ -124,6 +168,12 @@ struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock) ...@@ -124,6 +168,12 @@ struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock)
vclock->pclock = pclock; vclock->pclock = pclock;
vclock->info = ptp_vclock_info; vclock->info = ptp_vclock_info;
if (pclock->info->gettimex64)
vclock->info.gettimex64 = ptp_vclock_gettimex;
else
vclock->info.gettime64 = ptp_vclock_gettime;
if (pclock->info->getcrosststamp)
vclock->info.getcrosststamp = ptp_vclock_getcrosststamp;
vclock->cc = ptp_vclock_cc; vclock->cc = ptp_vclock_cc;
snprintf(vclock->info.name, PTP_CLOCK_NAME_LEN, "ptp%d_virt", snprintf(vclock->info.name, PTP_CLOCK_NAME_LEN, "ptp%d_virt",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment