netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] ptp: ocp: Add ptp_ocp_adjtime_coarse for large adjustments
@ 2022-02-28 20:39 Jonathan Lemon
  2022-03-01 12:51 ` Richard Cochran
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jonathan Lemon @ 2022-02-28 20:39 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, richardcochran, kernel-team

In ("ptp: ocp: Have FPGA fold in ns adjustment for adjtime."), the
ns adjustment was written to the FPGA register, so the clock could
accurately perform adjustments.

However, the adjtime() call passes in a s64, while the clock adjustment
registers use a s32.  When trying to perform adjustments with a large
value (37 sec), things fail.

Examine the incoming delta, and if larger than 1 sec, use the original
(coarse) adjustment method.  If smaller than 1 sec, then allow the
FPGA to fold in the changes over a 1 second window.

Fixes: 6d59d4fa1789 ("ptp: ocp: Have FPGA fold in ns adjustment for adjtime.")
Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>
---
 drivers/ptp/ptp_ocp.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 0f1b5a7d2a89..17ad5f0d13b2 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -607,7 +607,7 @@ ptp_ocp_settime(struct ptp_clock_info *ptp_info, const struct timespec64 *ts)
 }
 
 static void
-__ptp_ocp_adjtime_locked(struct ptp_ocp *bp, u64 adj_val)
+__ptp_ocp_adjtime_locked(struct ptp_ocp *bp, u32 adj_val)
 {
 	u32 select, ctrl;
 
@@ -615,7 +615,7 @@ __ptp_ocp_adjtime_locked(struct ptp_ocp *bp, u64 adj_val)
 	iowrite32(OCP_SELECT_CLK_REG, &bp->reg->select);
 
 	iowrite32(adj_val, &bp->reg->offset_ns);
-	iowrite32(adj_val & 0x7f, &bp->reg->offset_window_ns);
+	iowrite32(NSEC_PER_SEC, &bp->reg->offset_window_ns);
 
 	ctrl = OCP_CTRL_ADJUST_OFFSET | OCP_CTRL_ENABLE;
 	iowrite32(ctrl, &bp->reg->ctrl);
@@ -624,6 +624,22 @@ __ptp_ocp_adjtime_locked(struct ptp_ocp *bp, u64 adj_val)
 	iowrite32(select >> 16, &bp->reg->select);
 }
 
+static void
+ptp_ocp_adjtime_coarse(struct ptp_ocp *bp, u64 delta_ns)
+{
+	struct timespec64 ts;
+	unsigned long flags;
+	int err;
+
+	spin_lock_irqsave(&bp->lock, flags);
+	err = __ptp_ocp_gettime_locked(bp, &ts, NULL);
+	if (likely(!err)) {
+		timespec64_add_ns(&ts, delta_ns);
+		__ptp_ocp_settime_locked(bp, &ts);
+	}
+	spin_unlock_irqrestore(&bp->lock, flags);
+}
+
 static int
 ptp_ocp_adjtime(struct ptp_clock_info *ptp_info, s64 delta_ns)
 {
@@ -631,6 +647,11 @@ ptp_ocp_adjtime(struct ptp_clock_info *ptp_info, s64 delta_ns)
 	unsigned long flags;
 	u32 adj_ns, sign;
 
+	if (delta_ns > NSEC_PER_SEC || -delta_ns > NSEC_PER_SEC) {
+		ptp_ocp_adjtime_coarse(bp, delta_ns);
+		return 0;
+	}
+
 	sign = delta_ns < 0 ? BIT(31) : 0;
 	adj_ns = sign ? -delta_ns : delta_ns;
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] ptp: ocp: Add ptp_ocp_adjtime_coarse for large adjustments
  2022-02-28 20:39 [PATCH net-next] ptp: ocp: Add ptp_ocp_adjtime_coarse for large adjustments Jonathan Lemon
@ 2022-03-01 12:51 ` Richard Cochran
  2022-03-02  2:21 ` Jakub Kicinski
  2022-03-02 18:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: Richard Cochran @ 2022-03-01 12:51 UTC (permalink / raw)
  To: Jonathan Lemon; +Cc: netdev, davem, kuba, kernel-team

On Mon, Feb 28, 2022 at 12:39:57PM -0800, Jonathan Lemon wrote:
> In ("ptp: ocp: Have FPGA fold in ns adjustment for adjtime."), the
> ns adjustment was written to the FPGA register, so the clock could
> accurately perform adjustments.
> 
> However, the adjtime() call passes in a s64, while the clock adjustment
> registers use a s32.  When trying to perform adjustments with a large
> value (37 sec), things fail.
> 
> Examine the incoming delta, and if larger than 1 sec, use the original
> (coarse) adjustment method.  If smaller than 1 sec, then allow the
> FPGA to fold in the changes over a 1 second window.
> 
> Fixes: 6d59d4fa1789 ("ptp: ocp: Have FPGA fold in ns adjustment for adjtime.")
> Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>

Acked-by: Richard Cochran <richardcochran@gmail.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] ptp: ocp: Add ptp_ocp_adjtime_coarse for large adjustments
  2022-02-28 20:39 [PATCH net-next] ptp: ocp: Add ptp_ocp_adjtime_coarse for large adjustments Jonathan Lemon
  2022-03-01 12:51 ` Richard Cochran
@ 2022-03-02  2:21 ` Jakub Kicinski
  2022-03-02 16:48   ` Jonathan Lemon
  2022-03-02 18:00 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2022-03-02  2:21 UTC (permalink / raw)
  To: Jonathan Lemon; +Cc: netdev, davem, richardcochran, kernel-team

On Mon, 28 Feb 2022 12:39:57 -0800 Jonathan Lemon wrote:
> In ("ptp: ocp: Have FPGA fold in ns adjustment for adjtime."), the
> ns adjustment was written to the FPGA register, so the clock could
> accurately perform adjustments.
> 
> However, the adjtime() call passes in a s64, while the clock adjustment
> registers use a s32.  When trying to perform adjustments with a large
> value (37 sec), things fail.
> 
> Examine the incoming delta, and if larger than 1 sec, use the original
> (coarse) adjustment method.  If smaller than 1 sec, then allow the
> FPGA to fold in the changes over a 1 second window.
> 
> Fixes: 6d59d4fa1789 ("ptp: ocp: Have FPGA fold in ns adjustment for adjtime.")
> Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>

This one's tagged for net-next - do you intend for it to go to net-next,
or is that a typo?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] ptp: ocp: Add ptp_ocp_adjtime_coarse for large adjustments
  2022-03-02  2:21 ` Jakub Kicinski
@ 2022-03-02 16:48   ` Jonathan Lemon
  2022-03-02 17:56     ` Jakub Kicinski
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Lemon @ 2022-03-02 16:48 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: netdev, davem, richardcochran, kernel-team

On Tue, Mar 01, 2022 at 06:21:53PM -0800, Jakub Kicinski wrote:
> On Mon, 28 Feb 2022 12:39:57 -0800 Jonathan Lemon wrote:
> > In ("ptp: ocp: Have FPGA fold in ns adjustment for adjtime."), the
> > ns adjustment was written to the FPGA register, so the clock could
> > accurately perform adjustments.
> > 
> > However, the adjtime() call passes in a s64, while the clock adjustment
> > registers use a s32.  When trying to perform adjustments with a large
> > value (37 sec), things fail.
> > 
> > Examine the incoming delta, and if larger than 1 sec, use the original
> > (coarse) adjustment method.  If smaller than 1 sec, then allow the
> > FPGA to fold in the changes over a 1 second window.
> > 
> > Fixes: 6d59d4fa1789 ("ptp: ocp: Have FPGA fold in ns adjustment for adjtime.")
> > Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>
> 
> This one's tagged for net-next - do you intend for it to go to net-next,
> or is that a typo?

I build and test net-next, so that was my target.
-- 
Jonathan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] ptp: ocp: Add ptp_ocp_adjtime_coarse for large adjustments
  2022-03-02 16:48   ` Jonathan Lemon
@ 2022-03-02 17:56     ` Jakub Kicinski
  0 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2022-03-02 17:56 UTC (permalink / raw)
  To: Jonathan Lemon; +Cc: netdev, davem, richardcochran, kernel-team

On Wed, 2 Mar 2022 08:48:00 -0800 Jonathan Lemon wrote:
> > This one's tagged for net-next - do you intend for it to go to net-next,
> > or is that a typo?  
> 
> I build and test net-next, so that was my target.

You should develop fixes against the current tree, not -next trees.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] ptp: ocp: Add ptp_ocp_adjtime_coarse for large adjustments
  2022-02-28 20:39 [PATCH net-next] ptp: ocp: Add ptp_ocp_adjtime_coarse for large adjustments Jonathan Lemon
  2022-03-01 12:51 ` Richard Cochran
  2022-03-02  2:21 ` Jakub Kicinski
@ 2022-03-02 18:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-02 18:00 UTC (permalink / raw)
  To: Jonathan Lemon; +Cc: netdev, davem, kuba, richardcochran, kernel-team

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 28 Feb 2022 12:39:57 -0800 you wrote:
> In ("ptp: ocp: Have FPGA fold in ns adjustment for adjtime."), the
> ns adjustment was written to the FPGA register, so the clock could
> accurately perform adjustments.
> 
> However, the adjtime() call passes in a s64, while the clock adjustment
> registers use a s32.  When trying to perform adjustments with a large
> value (37 sec), things fail.
> 
> [...]

Here is the summary with links:
  - [net-next] ptp: ocp: Add ptp_ocp_adjtime_coarse for large adjustments
    https://git.kernel.org/netdev/net/c/90f8f4c0e3ce

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-03-02 18:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-28 20:39 [PATCH net-next] ptp: ocp: Add ptp_ocp_adjtime_coarse for large adjustments Jonathan Lemon
2022-03-01 12:51 ` Richard Cochran
2022-03-02  2:21 ` Jakub Kicinski
2022-03-02 16:48   ` Jonathan Lemon
2022-03-02 17:56     ` Jakub Kicinski
2022-03-02 18:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).