Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Clark" <jjc@jclark.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v2 2/2] net: ethernet: ti: am65-cpts: implement PTP_SYS_OFFSET_PRECISE
Date: Sat, 21 Nov 2026 03:47:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-226601@kernel.org> (raw)
In-Reply-To: <4af45df52cdd96da920bc36d29bc341615bbe95b.1795143925.git.jjc@jclark.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] am65-cpts: missing per-pop TS_PEND delay in
  am65_cpts_fifo_pop_event()
--

commit e2b0e8be4be95c8c4617e693d71c09e33009c74e
Author: James Clark <jjc@jclark.com>

net: ethernet: ti: am65-cpts: implement PTP_SYS_OFFSET_PRECISE

This commit adds hardware-supported PTP_SYS_OFFSET_PRECISE cross-timestamping
to the TI K3 CPTS driver by routing a selected bit of the Global Timebase
Counter (GTC) to a CPTS hardware timestamp input.

> diff --git a/drivers/net/ethernet/ti/am65-cpts.c b/drivers/net/ethernet/ti/am65-cpts.c
> index 3ce3b2245efba..4987909d3bc2b 100644
> --- a/drivers/net/ethernet/ti/am65-cpts.c
> +++ b/drivers/net/ethernet/ti/am65-cpts.c
[ ... ]
> @@ -797,6 +841,243 @@ static int am65_cpts_ptp_enable(struct ptp_clock_info *ptp,
[ ... ]
> +/*
> + * Read the FIFO until it is empty, then accept the next push event. One
> + * __am65_cpts_fifo_read() takes at most AM65_CPTS_FIFO_DEPTH events, and after
> + * a burst of push edges (a request that wakes up late leaves the input enabled
> + * for many periods) more can be waiting. A push event left behind would be
> + * taken for the next attempt's. With the push input disabled no new push
> + * events arrive, so after enough passes every old one has been read even if
> + * packet events keep the FIFO busy. The lock is dropped between passes; a push
> + * event read meanwhile by the IRQ thread is ignored, as nothing is armed.
> + */
> +static int am65_cpts_gtc_push_arm(struct am65_cpts *cpts)
> +{
> +	unsigned long flags;
> +	int i;
> +
> +	for (i = 0; i < AM65_CPTS_GTC_PUSH_DRAIN_PASSES; i++) {
> +		spin_lock_irqsave(&cpts->lock, flags);
> +		__am65_cpts_fifo_read(cpts);
> +		/*
> +		 * TS_PEND is valid only once four CPTS_RFT_CLK periods plus
> +		 * four CPPI_ICLK periods have passed since a pop. Read a
> +		 * register so that the last pop has reached the CPTS, then
> +		 * wait. 100 ns is enough for clocks of 80 MHz or more.
> +		 */
> +		am65_cpts_read32(cpts, intstat_raw);
> +		ndelay(100);
> +		if (!(am65_cpts_read32(cpts, intstat_raw) &
> +		      AM65_CPTS_INTSTAT_RAW_TS_PEND)) {
> +			cpts->gtc_push_armed = true;
> +			spin_unlock_irqrestore(&cpts->lock, flags);
> +			return 0;
> +		}
> +		spin_unlock_irqrestore(&cpts->lock, flags);
> +	}
> +	return -EBUSY;
> +}

[Severity: Medium]
Does __am65_cpts_fifo_read() only pop a single disarmed GTC push event per
pass in am65_cpts_gtc_push_arm()?

When __am65_cpts_fifo_read() drains a disarmed GTC push event,
am65_cpts_gtc_push_event() returns immediately and the next loop iteration
calls am65_cpts_fifo_pop_event() without waiting for the four CPTS_RFT_CLK
plus four CPPI_ICLK periods after writing event_pop:

drivers/net/ethernet/ti/am65-cpts.c:am65_cpts_fifo_pop_event() {
	u32 r = am65_cpts_read32(cpts, intstat_raw);

	if (r & AM65_CPTS_INTSTAT_RAW_TS_PEND) {
		...
		am65_cpts_write32(cpts, AM65_CPTS_EVENT_POP, event_pop);
		return false;
	}
	return true;
}

Because TS_PEND is not valid yet on that immediate re-entry,
am65_cpts_fifo_pop_event() sees TS_PEND clear and breaks out of
__am65_cpts_fifo_read() after popping just one event.  If a request wakes
up ~3 ms late so 9 to 16 push events accumulate in the 16-entry FIFO,
AM65_CPTS_GTC_PUSH_DRAIN_PASSES (8) passes only drain 8 events and
am65_cpts_gtc_push_arm() fails with -EBUSY (aborting
am65_cpts_ptp_getcrosststamp() without retrying).  A disarmed push event
sitting ahead of an AM65_CPTS_EV_PUSH event in the FIFO can similarly cause
am65_cpts_gettime() to stop reading the FIFO early and return a stale
cpts->timestamp.

Should the post-pop register read and ndelay(100) be moved into
am65_cpts_fifo_pop_event() right after writing event_pop?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795143925.git.jjc@jclark.com?part=2

      reply	other threads:[~2026-11-21  3:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  3:46 [PATCH net-next v2 0/2] net: ethernet: ti: am65-cpts: add PTP_SYS_OFFSET_PRECISE support James Clark
2026-11-20  3:47 ` [PATCH net-next v2 1/2] dt-bindings: net: ti,k3-am654-cpts: add ti,gtc-push James Clark
2026-11-20  3:47 ` [PATCH net-next v2 2/2] net: ethernet: ti: am65-cpts: implement PTP_SYS_OFFSET_PRECISE James Clark
2026-11-21  3:47   ` sashiko-bot [this message]

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=sashiko-outbox-226601@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jjc@jclark.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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