mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: javen_xu@realsil.com.cn
Cc: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, nb@tipi-net.de, maxime.chevallier@bootlin.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	daniel@makrotopia.org, vladimir.oltean@nxp.com
Subject: Re: [PATCH net-next v4 2/3] net: phy: realtek: add PTP clock support for RTL8127a
Date: Sun, 29 Nov 2026 09:50:12 +0000	[thread overview]
Message-ID: <179594581280.3146.11285763012972937249@kernel.org> (raw)
In-Reply-To: <20261125090217.1198-3-javen_xu@realsil.com.cn>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The driver re-seeds the PHC from CLOCK_REALTIME on the next
  link-up whenever `ptp->time_set` is false.
- [Medium] `rtl8127a_ptp_hwtstamp_enable(ptp, false)` ends by setting
  `RTL8127A_PHY_RST` (BIT(15) of PHY OCP 0xa640) at…

--

net: phy: realtek: add PTP clock support for RTL8127a

This adds a PTP hardware clock for the internal PHY of RTL8127A
(RTL8261C). The clock can be read, set, stepped and frequency adjusted
through vendor MMD registers. The frequency adjustment is cleared at
probe, and the clock is seeded from the system time on the first link up
after a PHY init or link loss.

> diff --git a/drivers/net/phy/realtek/realtek_ptp.c b/drivers/net/phy/realtek/realtek_ptp.c
> new file mode 100644
> index 0000000000000..83ee125517b00
> --- /dev/null
> +++ b/drivers/net/phy/realtek/realtek_ptp.c

[ ... ]

> +int rtl8127a_ptp_config_init(struct phy_device *phydev)
> +{
> +	struct rtl8127a_ptp *ptp = phydev->priv;
> +
> +	if (!ptp)
> +		return 0;
> +
> +	mutex_lock(&ptp->lock);
> +	ptp->time_set = false;
> +	mutex_unlock(&ptp->lock);
> +
> +	return 0;
> +}
> +
> +void rtl8127a_ptp_link_change_notify(struct phy_device *phydev)
> +{
> +	struct rtl8127a_ptp *ptp = phydev->priv;
> +	struct timespec64 ts;
> +	int ret = 0;
> +
> +	if (!ptp)
> +		return;
> +
> +	if (!phydev->link) {
> +		mutex_lock(&ptp->lock);
> +		ptp->time_set = false;
> +		mutex_unlock(&ptp->lock);
> +		return;
> +	}
> +
> +	mutex_lock(&ptp->lock);
> +
> +	if (!ptp->time_set) {
> +		ktime_get_real_ts64(&ts);
> +		ret = rtl8127a_ptp_write_time(ptp, &ts);
> +		if (!ret)
> +			ret = rtl8127a_ptp_clkadj(ptp, RTL8127A_PTP_DIRECT_WRITE);

[Severity: Medium]
Won't this overwrite a PHC time that userspace has set or disciplined?

time_set gets cleared, or is never set, in these cases:

- rtl8127a_ptp_config_init() clears it on every phy_init_hw(). In r8169,
  rtl8169_init_phy() calls phy_init_hw() from rtl8169_up(), and
  rtl8169_up() runs from both rtl_open() and rtl8169_runtime_resume().

- rtl8127a_ptp_link_change_notify() clears it on any state change with
  phydev->link == 0. That covers cable flaps and phy_stop() on ifdown.

- rtl8127a_ptp_settime64()->rtl8127a_ptp_settime() and
  rtl8127a_ptp_adjtime() never set time_set to true.

So on the first link up after any of these, the PHC is stepped to
CLOCK_REALTIME, even if the counter was never reset. For example, a
TAI based PHC maintained by ptp4l or phc2sys would be stepped back to
UTC, roughly 37 seconds off.

The v3 changelog says the clock is kept running across PHY
re-initializations, but v4 now re-seeds it after every phy_init_hw().
Is that intended?

If the counter really is reset by these events, wouldn't the rate
programmed with RTL8127A_PTP_RATE_WRITE be lost too? It is never
re-applied here.

The Kconfig help text says the clock "can be read and adjusted through
the PTP clock device". Here those adjustments are replaced without any
notice.

The same logic is still present at the end of the series. The later
commit "net: phy: realtek: add hardware timestamping for RTL8127a" only
adds re-enabling of timestamping in link_change_notify. It leaves the
time_set handling unchanged.

> +		if (ret)
> +			goto out;
> +		ptp->time_set = true;
> +	}

[ ... ]

> +	ptp->phydev = phydev;
> +	ptp->info = rtl8127a_ptp_info;
> +
> +	ret = rtl8127a_ptp_hwtstamp_enable(ptp, false);
> +	if (ret)
> +		return ret;
> +
> +	ret = rtl8127a_ptp_adjfine(&ptp->info, 0);

[Severity: Medium]
Can the PHY still be in reset when adjfine runs here?

rtl8127a_ptp_hwtstamp_enable(ptp, false) ends by setting the bit that
this patch defines as the PHY reset:

	ret = rtl8127a_ptp_modify(ptp, RTL8127A_PHY_RST_CTL, 0,
				  RTL8127A_PHY_RST);

Nothing waits for the reset to finish or for the bit to self-clear.
Right after that, rtl8127a_ptp_adjfine() writes the CFG_TIME rate
staging registers and issues a RATE_WRITE EXEC on CLK_CFG. It then
polls EXEC with only a 1 ms timeout.

If the reset is still in progress, could the staging writes be lost, or
could EXEC fail to clear? In that case probe would drop PTP with "PTP
support disabled".

rtl8127a_ptp_remove() issues the same reset while the PHC is still
registered:

	rtl8127a_ptp_hwtstamp_enable(ptp, false);
	ptp_clock_unregister(ptp->clock);

Could a concurrent clock_gettime() or clock_adjtime() then program
CLK_CFG and CFG_TIME on a PHY that is in the middle of a reset?

Nothing else in drivers/net/ touches 0xa640, so I couldn't confirm
whether this reset affects the PTP block, or how long it takes. For
comparison, genphy_soft_reset() polls BMCR_RESET before it continues.

This sequence is also unchanged at the end of the series.

> +	if (ret)
> +		return ret;

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125090217.1198-1-javen_xu%40realsil.com.cn

  reply	other threads:[~2026-11-29  9:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  9:02 [PATCH net-next v4 0/3] net: phy: realtek: add PTP " javen
2026-11-25  9:02 ` [PATCH net-next v4 1/3] r8169: hold MDIO bus lock while loading firmware javen
2026-11-29  9:50   ` netdev-bot+sashiko
2026-11-25  9:02 ` [PATCH net-next v4 2/3] net: phy: realtek: add PTP clock support for RTL8127a javen
2026-11-29  9:50   ` netdev-bot+sashiko [this message]
2026-11-25  9:02 ` [PATCH net-next v4 3/3] net: phy: realtek: add hardware timestamping " javen
2026-11-25  9:43   ` Vladimir Oltean
2026-11-26  6:13     ` Javen
2026-11-26 14:08       ` Andrew Lunn
2026-11-29  9:50   ` netdev-bot+sashiko

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=179594581280.3146.11285763012972937249@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=javen_xu@realsil.com.cn \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=maxime.chevallier@bootlin.com \
    --cc=nb@tipi-net.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=vladimir.oltean@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®