From: Richard Cochran <richardcochran@gmail.com>
To: Brandon Streiff <brandon.streiff@ni.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>,
Florian Fainelli <f.fainelli@gmail.com>,
Andrew Lunn <andrew@lunn.ch>,
Vivien Didelot <vivien.didelot@savoirfairelinux.com>,
Erik Hons <erik.hons@ni.com>
Subject: Re: [PATCH net-next RFC 2/9] net: dsa: mv88e6xxx: expose switch time as a PTP hardware clock
Date: Sun, 8 Oct 2017 10:52:38 -0400 [thread overview]
Message-ID: <20171008145238.wfsc2hd6nul2hedm@localhost> (raw)
In-Reply-To: <1506612341-18061-3-git-send-email-brandon.streiff@ni.com>
On Thu, Sep 28, 2017 at 10:25:34AM -0500, Brandon Streiff wrote:
> +static int mv88e6xxx_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
> +{
> + if (scaled_ppm == 0)
> + return 0;
> +
> + return -EOPNOTSUPP;
> +}
We really want to have an adjustable clock here. More below.
> +int mv88e6xxx_ptp_setup(struct mv88e6xxx_chip *chip)
> +{
> + /* Set up the cycle counter */
> + memset(&chip->tstamp_cc, 0, sizeof(chip->tstamp_cc));
> + chip->tstamp_cc.read = mv88e6xxx_ptp_clock_read;
> + chip->tstamp_cc.mask = CYCLECOUNTER_MASK(32);
> + /* Raw timestamps are in units of 8-ns clock periods. */
> + chip->tstamp_cc.mult = 8;
> + chip->tstamp_cc.shift = 0;
First of all, the switch can use an external clock, and so at the very
least, the period should be a macro so that if and when we support the
external clock, the macro may be converted into a variable.
Secondly, the mult/shift should be chosen to allow the finest possible
frequency adjustment. Here is what I did:
---
#define N 28
#define CC_MULT (8 << N)
int mv88e635x_setup(struct dsa_switch *ds)
{
struct mv88e6xxx_chip *ps = ds->priv;
ps->cc.read = mv88e635x_global_time_read;
ps->cc.mask = CLOCKSOURCE_MASK(32);
ps->cc.mult = CC_MULT;
ps->cc.shift = N;
timecounter_init(&ps->tc, &ps->cc, ktime_to_ns(ktime_get_real()));
...
}
static int mv88e635x_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
{
u64 adj;
u32 diff, mult;
int neg_adj = 0;
struct mv88e6xxx_chip *ps =
container_of(ptp, struct mv88e6xxx_chip, ptp_info);
if (ppb < 0) {
neg_adj = 1;
ppb = -ppb;
}
mult = CC_MULT;
adj = mult;
adj *= ppb;
diff = div_u64(adj, 1000000000ULL);
mutex_lock(&ps->clock_mutex);
timecounter_read(&ps->tc);
ps->cc.mult = neg_adj ? mult - diff : mult + diff;
mutex_unlock(&ps->clock_mutex);
return 0;
}
---
(This is the legacy adjfreq method, but you can easily convert it into
the adjfine method.)
Of course, this means that you'll have to drop the periodic output
signal code.
Thanks,
Richard
next prev parent reply other threads:[~2017-10-08 14:52 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-28 15:25 [PATCH net-next RFC 0/9] net: dsa: PTP timestamping for mv88e6xxx Brandon Streiff
2017-09-28 15:25 ` [PATCH net-next RFC 1/9] net: dsa: mv88e6xxx: add accessors for PTP/TAI registers Brandon Streiff
2017-09-28 16:29 ` Vivien Didelot
2017-10-08 14:32 ` Richard Cochran
2017-09-28 15:25 ` [PATCH net-next RFC 2/9] net: dsa: mv88e6xxx: expose switch time as a PTP hardware clock Brandon Streiff
2017-09-28 16:56 ` Andrew Lunn
2017-09-29 15:28 ` Brandon Streiff
2017-10-08 11:59 ` Richard Cochran
2017-09-28 17:03 ` Andrew Lunn
2017-09-29 15:17 ` Brandon Streiff
2017-10-08 12:07 ` Richard Cochran
2017-10-08 14:52 ` Richard Cochran [this message]
2017-09-28 15:25 ` [PATCH net-next RFC 3/9] net: dsa: mv88e6xxx: add support for GPIO configuration Brandon Streiff
2017-09-28 17:45 ` Florian Fainelli
2017-09-28 18:01 ` Andrew Lunn
2017-09-28 19:57 ` Vivien Didelot
2017-09-29 15:30 ` Brandon Streiff
2017-09-28 15:25 ` [PATCH net-next RFC 4/9] net: dsa: mv88e6xxx: add support for event capture Brandon Streiff
2017-10-08 15:06 ` Richard Cochran
2017-10-09 22:08 ` Levi Pearson
2017-10-10 1:53 ` Richard Cochran
2017-09-28 15:25 ` [PATCH net-next RFC 5/9] net: dsa: forward hardware timestamping ioctls to switch driver Brandon Streiff
2017-09-28 17:25 ` Florian Fainelli
2017-10-08 13:12 ` Richard Cochran
2017-09-28 19:31 ` Vivien Didelot
2017-09-28 15:25 ` [PATCH net-next RFC 6/9] net: dsa: forward timestamping callbacks to switch drivers Brandon Streiff
2017-09-28 17:40 ` Florian Fainelli
2017-09-29 15:30 ` Brandon Streiff
2017-09-28 15:25 ` [PATCH net-next RFC 7/9] ptp: add offset for reserved field to header Brandon Streiff
2017-09-28 15:25 ` [PATCH net-next RFC 8/9] net: dsa: mv88e6xxx: add rx/tx timestamping support Brandon Streiff
2017-10-08 14:24 ` Richard Cochran
2017-10-08 15:12 ` Richard Cochran
2017-10-08 15:29 ` Richard Cochran
2017-09-28 15:25 ` [PATCH net-next RFC 9/9] net: dsa: mv88e6xxx: add workaround for 6341 timestamping Brandon Streiff
2017-09-28 17:36 ` [PATCH net-next RFC 0/9] net: dsa: PTP timestamping for mv88e6xxx Andrew Lunn
2017-09-28 17:51 ` Florian Fainelli
2017-09-29 15:34 ` Brandon Streiff
2017-09-29 9:43 ` Richard Cochran
2017-10-08 15:38 ` Richard Cochran
2017-11-06 14:55 ` Richard Cochran
2017-11-06 15:04 ` Andrew Lunn
2017-11-07 18:15 ` Richard Cochran
2017-11-07 18:13 ` Richard Cochran
2017-11-07 20:56 ` Brandon Streiff
2017-11-08 0:09 ` Andrew Lunn
2017-11-08 3:02 ` Andrew Lunn
2017-11-08 3:23 ` Richard Cochran
2017-12-04 1:13 ` Richard Cochran
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171008145238.wfsc2hd6nul2hedm@localhost \
--to=richardcochran@gmail.com \
--cc=andrew@lunn.ch \
--cc=brandon.streiff@ni.com \
--cc=davem@davemloft.net \
--cc=erik.hons@ni.com \
--cc=f.fainelli@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=vivien.didelot@savoirfairelinux.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox