From: Vladimir Oltean <olteanv@gmail.com>
To: kuba@kernel.org, davem@davemloft.net, netdev@vger.kernel.org
Cc: richardcochran@gmail.com, jacob.e.keller@intel.com,
yangbo.lu@nxp.com, xiaoliang.yang_1@nxp.com, po.liu@nxp.com,
UNGLinuxDriver@microchip.com
Subject: Re: [PATCH net-next 3/3] net: mscc: ocelot: add support for PTP waveform configuration
Date: Fri, 17 Jul 2020 00:36:22 +0300 [thread overview]
Message-ID: <20200716213622.zlsmaz56io4d6vgl@skbuf> (raw)
In-Reply-To: <20200716212032.1024188-4-olteanv@gmail.com>
On Fri, Jul 17, 2020 at 12:20:32AM +0300, Vladimir Oltean wrote:
> For PPS output (perout period is 1.000000000), accept the new "phase"
> parameter from the periodic output request structure.
>
> For both PPS and freeform output, accept the new "on" argument for
> specifying the duty cycle of the generated signal. Preserve the old
> defaults for this "on" time: 1 us for PPS, and half the period for
> freeform output.
>
> Also preserve the old behavior that accepted the "phase" via the "start"
> argument.
>
> Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
> ---
> drivers/net/ethernet/mscc/ocelot_ptp.c | 74 +++++++++++++++++---------
> 1 file changed, 50 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/net/ethernet/mscc/ocelot_ptp.c b/drivers/net/ethernet/mscc/ocelot_ptp.c
> index 62188772a75d..1e08fe4daaef 100644
> --- a/drivers/net/ethernet/mscc/ocelot_ptp.c
> +++ b/drivers/net/ethernet/mscc/ocelot_ptp.c
> @@ -184,18 +184,20 @@ int ocelot_ptp_enable(struct ptp_clock_info *ptp,
> struct ptp_clock_request *rq, int on)
> {
> struct ocelot *ocelot = container_of(ptp, struct ocelot, ptp_info);
> - struct timespec64 ts_start, ts_period;
> + struct timespec64 ts_phase, ts_period;
> enum ocelot_ptp_pins ptp_pin;
> unsigned long flags;
> bool pps = false;
> int pin = -1;
> + s64 wf_high;
> + s64 wf_low;
> u32 val;
> - s64 ns;
>
> switch (rq->type) {
> case PTP_CLK_REQ_PEROUT:
> /* Reject requests with unsupported flags */
> - if (rq->perout.flags)
> + if (rq->perout.flags & ~(PTP_PEROUT_DUTY_CYCLE |
> + PTP_PEROUT_PHASE))
> return -EOPNOTSUPP;
>
> pin = ptp_find_pin(ocelot->ptp_clock, PTP_PF_PEROUT,
> @@ -211,22 +213,12 @@ int ocelot_ptp_enable(struct ptp_clock_info *ptp,
> else
> return -EBUSY;
>
> - ts_start.tv_sec = rq->perout.start.sec;
> - ts_start.tv_nsec = rq->perout.start.nsec;
> ts_period.tv_sec = rq->perout.period.sec;
> ts_period.tv_nsec = rq->perout.period.nsec;
>
> if (ts_period.tv_sec == 1 && ts_period.tv_nsec == 0)
> pps = true;
>
> - if (ts_start.tv_sec || (ts_start.tv_nsec && !pps)) {
> - dev_warn(ocelot->dev,
> - "Absolute start time not supported!\n");
> - dev_warn(ocelot->dev,
> - "Accept nsec for PPS phase adjustment, otherwise start time should be 0 0.\n");
> - return -EINVAL;
> - }
> -
> /* Handle turning off */
> if (!on) {
> spin_lock_irqsave(&ocelot->ptp_clock_lock, flags);
> @@ -236,16 +228,48 @@ int ocelot_ptp_enable(struct ptp_clock_info *ptp,
> break;
> }
>
> + if (rq->perout.flags & PTP_PEROUT_PHASE) {
> + ts_phase.tv_sec = rq->perout.phase.sec;
> + ts_phase.tv_nsec = rq->perout.phase.nsec;
> + } else {
> + /* Compatibility */
> + ts_phase.tv_sec = rq->perout.start.sec;
> + ts_phase.tv_nsec = rq->perout.start.nsec;
> + }
> + if (ts_phase.tv_sec || (ts_phase.tv_nsec && !pps)) {
> + dev_warn(ocelot->dev,
> + "Absolute start time not supported!\n");
> + dev_warn(ocelot->dev,
> + "Accept nsec for PPS phase adjustment, otherwise start time should be 0 0.\n");
> + return -EINVAL;
> + }
> +
> + /* Calculate waveform high and low times */
> + if (rq->perout.flags & PTP_PEROUT_DUTY_CYCLE) {
> + struct timespec64 ts_on;
> +
> + ts_on.tv_sec = rq->perout.on.sec;
> + ts_on.tv_nsec = rq->perout.on.nsec;
> +
> + wf_high = timespec64_to_ns(&ts_on);
> + } else {
> + if (pps) {
> + wf_high = 1000;
> + } else {
> + wf_high = timespec64_to_ns(&ts_period);
> + wf_high = div_s64(wf_high, 2);
> + }
> + }
> +
> + wf_low = timespec64_to_ns(&ts_period);
> + wf_low -= wf_high;
> +
> /* Handle PPS request */
> if (pps) {
> spin_lock_irqsave(&ocelot->ptp_clock_lock, flags);
> - /* Pulse generated perout.start.nsec after TOD has
> - * increased seconds.
> - * Pulse width is set to 1us.
> - */
> - ocelot_write_rix(ocelot, ts_start.tv_nsec,
> + ocelot_write_rix(ocelot, ts_phase.tv_nsec,
> PTP_PIN_WF_LOW_PERIOD, ptp_pin);
> - ocelot_write_rix(ocelot, NSEC_PER_SEC / 2,
Damn. I had this patch in my tree:
diff --git a/drivers/net/ethernet/mscc/ocelot_ptp.c b/drivers/net/ethernet/mscc/ocelot_ptp.c
index a3088a1676ed..62188772a75d 100644
--- a/drivers/net/ethernet/mscc/ocelot_ptp.c
+++ b/drivers/net/ethernet/mscc/ocelot_ptp.c
@@ -245,7 +245,7 @@ int ocelot_ptp_enable(struct ptp_clock_info *ptp,
*/
ocelot_write_rix(ocelot, ts_start.tv_nsec,
PTP_PIN_WF_LOW_PERIOD, ptp_pin);
- ocelot_write_rix(ocelot, 1000,
+ ocelot_write_rix(ocelot, NSEC_PER_SEC / 2,
PTP_PIN_WF_HIGH_PERIOD, ptp_pin);
val = PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_CLOCK);
val |= PTP_PIN_CFG_SYNC;
which I used for testing until I exposed this into an ioctl. I knew I
forgot to do something, and that was to squash that patch into this one.
So I'll need to send a v2, because otherwise this doesn't apply to
mainline. Please review taking this into consideration.
> + ocelot_write_rix(ocelot, wf_high,
> PTP_PIN_WF_HIGH_PERIOD, ptp_pin);
> val = PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_CLOCK);
> val |= PTP_PIN_CFG_SYNC;
> @@ -255,14 +279,16 @@ int ocelot_ptp_enable(struct ptp_clock_info *ptp,
> }
>
> /* Handle periodic clock */
> - ns = timespec64_to_ns(&ts_period);
> - ns = ns >> 1;
> - if (ns > 0x3fffffff || ns <= 0x6)
> + if (wf_high > 0x3fffffff || wf_high <= 0x6)
> + return -EINVAL;
> + if (wf_low > 0x3fffffff || wf_low <= 0x6)
> return -EINVAL;
>
> spin_lock_irqsave(&ocelot->ptp_clock_lock, flags);
> - ocelot_write_rix(ocelot, ns, PTP_PIN_WF_LOW_PERIOD, ptp_pin);
> - ocelot_write_rix(ocelot, ns, PTP_PIN_WF_HIGH_PERIOD, ptp_pin);
> + ocelot_write_rix(ocelot, wf_low, PTP_PIN_WF_LOW_PERIOD,
> + ptp_pin);
> + ocelot_write_rix(ocelot, wf_high, PTP_PIN_WF_HIGH_PERIOD,
> + ptp_pin);
> val = PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_CLOCK);
> ocelot_write_rix(ocelot, val, PTP_PIN_CFG, ptp_pin);
> spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags);
> --
> 2.25.1
>
Thanks,
-Vladimir
next prev parent reply other threads:[~2020-07-16 21:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-16 21:20 [PATCH net-next 0/3] Fully describe the waveform for PTP periodic output Vladimir Oltean
2020-07-16 21:20 ` [PATCH net-next 1/3] ptp: add ability to configure duty cycle for " Vladimir Oltean
2020-07-16 21:36 ` Jacob Keller
2020-07-16 21:49 ` Vladimir Oltean
2020-07-16 22:09 ` Vladimir Oltean
2020-07-16 23:56 ` Jacob Keller
2020-07-16 21:20 ` [PATCH net-next 2/3] ptp: introduce a phase offset in the periodic output request Vladimir Oltean
2020-07-16 21:40 ` Jacob Keller
2020-07-16 21:20 ` [PATCH net-next 3/3] net: mscc: ocelot: add support for PTP waveform configuration Vladimir Oltean
2020-07-16 21:36 ` Vladimir Oltean [this message]
2020-07-16 22:29 ` Jakub Kicinski
2020-07-16 21:31 ` [PATCH net-next 0/3] Fully describe the waveform for PTP periodic output Jacob Keller
2020-07-16 22:28 ` Jakub Kicinski
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=20200716213622.zlsmaz56io4d6vgl@skbuf \
--to=olteanv@gmail.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=davem@davemloft.net \
--cc=jacob.e.keller@intel.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=po.liu@nxp.com \
--cc=richardcochran@gmail.com \
--cc=xiaoliang.yang_1@nxp.com \
--cc=yangbo.lu@nxp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.