Re: [PATCH] net: cpts: Condition WARN_ON on PTP_1588_CLOCK

From: Clay McClure
Date: Mon Apr 20 2020 - 05:36:21 EST


On Thu, Apr 16, 2020 at 02:11:45PM +0300, Grygorii Strashko wrote:

Grygorii,

> > CPTS_MOD merely implies PTP_1588_CLOCK; it is possible to build cpts
> > without PTP clock support. In that case, ptp_clock_register() returns
> > NULL and we should not WARN_ON(cpts->clock) when downing the interface.
> > The ptp_*() functions are stubbed without PTP_1588_CLOCK, so it's safe
> > to pass them a null pointer.
>
> Could you explain the purpose of the exercise (Enabling CPTS with
> PTP_1588_CLOCK disabled), pls?

Hardware timestamping with a free-running PHC _almost_ works without
PTP_1588_CLOCK, but since PHC rollover is handled by the PTP kworker
in this driver the timestamps end up not being monotonic.

And of course the moment you want to syntonize/synchronize the PHC with
another clock (say, CLOCK_REALTIME), you'll need a PTP clock device. So
you're right, there's not much point in building CPTS_MOD without
PTP_1588_CLOCK.

Given that, I wonder why all the Ethernet drivers seem to just `imply`
PTP_1588_CLOCK, rather than `depends on` it?

In any case, I was surprised to get a warning during `ifdown` but not
during `ifup`. What do you think of this change, which prints an error
like this during `ifup` if PTP_1588_CLOCK is not enabled:

[ 6.192707] 000: cpsw 4a100000.ethernet: error registering cpts device

---
diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
index 10ad706dda53..70b15039cd37 100644
--- a/drivers/net/ethernet/ti/cpts.c
+++ b/drivers/net/ethernet/ti/cpts.c
@@ -462,8 +462,8 @@ int cpts_register(struct cpts *cpts)
timecounter_init(&cpts->tc, &cpts->cc, ktime_get_real_ns());

cpts->clock = ptp_clock_register(&cpts->info, cpts->dev);
- if (IS_ERR(cpts->clock)) {
- err = PTR_ERR(cpts->clock);
+ if (IS_ERR_OR_NULL(cpts->clock)) {
+ err = cpts->clock ? PTR_ERR(cpts->clock) : -EOPNOTSUPP;
cpts->clock = NULL;
goto err_ptp;
}

-- 
Clay