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 v3 2/3] net: phy: realtek: add PTP clock support for RTL8127a
Date: Sat, 21 Nov 2026 06:39:11 +0000 [thread overview]
Message-ID: <179524315156.3135.8784098981517637477@kernel.org> (raw)
In-Reply-To: <20261117060120.1175-3-javen_xu@realsil.com.cn>
Thank you for your contribution! Sashiko AI review found 7 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 5
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 commit message says the clock 'is started from the system
time unless it is already running', and the comment in…
- [Medium] The PHC is registered at PHY probe and stays available through
/dev/ptpN at all times, but none of its callbacks (gettimex64,…
- [Low] The commit message only says a PTP hardware clock is registered.
- [Low] The Kconfig help calls the PTP clock 'optional', but a failure in
the PTP block now breaks basic PHY operation.
- [Low] rtl8127a_ptp_config_init() assumes that nothing after the PHY
driver's config_init resets the PTP counter.
- [Low] rtl8127a_ptp_hwtstamp_enable() ends by setting BIT(15) of VEND2
0xa640, which the patch defines as RTL8127A_PHY_RST (lines 234-235).
- [Low] The driver never sets the hardware rate-adjust state to a known
value.
--
net: phy: realtek: add PTP clock support for RTL8127a
This adds a PTP hardware clock for the PTP block in the RTL8127A internal
PHY (RTL8261C). The clock is read, set, stepped and frequency adjusted
through vendor MMD registers, and the patch hooks into the internal NBASE-T
PHY driver's probe, remove and config_init. The clock is seeded from the
system time in config_init when the counter looks like it has been reset.
> diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c
> index ca2d515b77b36..e21d10e57a130 100644
> --- a/drivers/net/phy/realtek/realtek_main.c
> +++ b/drivers/net/phy/realtek/realtek_main.c
[ ... ]
> @@ -3413,7 +3428,9 @@ static struct phy_driver realtek_drvs[] = {
> .match_phy_device = rtl_internal_nbaset_match_phy_device,
> .name = "Realtek Internal NBASE-T PHY",
> .flags = PHY_IS_INTERNAL,
> - .probe = rtl822x_probe,
> + .probe = rtl_internal_nbaset_probe,
> + .remove = rtl8127a_ptp_remove,
> + .config_init = rtl8127a_ptp_config_init,
[Severity: Low]
This driver entry had no config_init before. After this change, the only
way config_init can fail is an error from the PTP block. The Kconfig help
calls the PTP clock optional, but rtl8127a_ptp_config_init() returns any
error from rtl8127a_ptp_gettimex64() or rtl8127a_ptp_settime(). That
includes -ETIMEDOUT from rtl8127a_ptp_poll(), which gives
RTL8127A_PTP_CLK_CFG_EXEC only 1ms to clear.
config_init is reached through phy_init_hw() on attach:
rtl_open()
r8169_phy_connect()
phylink_connect_phy()
phy_attach_direct()
phy_init_hw()
rtl8127a_ptp_config_init()
rtl8127a_ptp_gettimex64()
rtl8127a_ptp_clkadj_sts()
rtl8127a_ptp_poll()
It is also reached on resume, through mdio_bus_phy_resume() -> phy_init_hw().
Would a transient PTP block failure then stop the interface from being
opened or resumed?
In the same way, rtl_internal_nbaset_probe() returns the error from
rtl8127a_ptp_probe() as is. So an MDIO error in the disable sequence, or a
ptp_clock_register() failure, fails the whole PHY probe. Other PHY drivers
commonly fail probe when PTP registration fails, so the config_init path is
the bigger concern.
Could these paths warn and continue without a usable PHC instead?
> .get_features = rtl822x_get_features,
> .config_aneg = rtl822x_config_aneg,
> .read_status = rtl822x_read_status,
> diff --git a/drivers/net/phy/realtek/realtek_ptp.c b/drivers/net/phy/realtek/realtek_ptp.c
> new file mode 100644
> index 0000000000000..9622571249f45
> --- /dev/null
> +++ b/drivers/net/phy/realtek/realtek_ptp.c
> @@ -0,0 +1,401 @@
[ ... ]
> +static int rtl8127a_ptp_clkadj_sts(struct rtl8127a_ptp *ptp,
> + enum rtl8127a_ptp_clkadj_mode mode,
> + struct ptp_system_timestamp *sts)
> +{
> + int val, ret;
> +
> + val = rtl8127a_ptp_read(ptp, RTL8127A_PTP_CLK_CFG);
[Severity: Medium]
Can this run while the RTL8127A PCI function is runtime suspended?
The PHC is registered at PHY probe and stays reachable through /dev/ptpN.
None of gettimex64, settime64, adjtime or adjfine make sure the MAC is
powered first. The register accesses end up as plain MMIO:
phy_read_mmd()
rtl822x_read_mmd()
rtlgen_read_vend2()
__mdiobus_c45_read()
r8169_mdio_read_reg_c45()
r8168_phy_ocp_read()
r8169 runtime suspends the function 10 seconds after the interface goes down
or loses carrier:
drivers/net/ethernet/realtek/r8169_main.c:rtl8169_runtime_idle() {
...
if (!netif_running(tp->dev) || !netif_carrier_ok(tp->dev))
pm_schedule_suspend(device, 10000);
...
}
In D3hot, r8168_phy_ocp_read() would return 0xffff as data.
r8168_phy_ocp_write() is void, so after logging a timeout it drops the write
and the caller sees success. The EXEC poll below then times out on
CLK_CFG == 0xffff. Every PHC operation would fail with -ETIMEDOUT and add log
noise while the NIC is idle.
The device_link that phy_attach_direct() creates makes the PCI device the
consumer and the PHY the supplier, so PHC accesses do not resume the PCI
function. For comparison, r8169's own LED accessors wrap their MMIO in
pm_runtime_resume_and_get().
This needs runtime PM to be allowed for the device (power/control=auto, as
TLP or powertop --auto-tune set it). The existing realtek hwmon support for
this PHY has the same exposure, but the PTP path is new in this patch.
> + if (val < 0)
> + return val;
> +
> + val &= ~RTL8127A_PTP_CLK_CFG_MODE;
> + val |= RTL8127A_PTP_CLK_CFG_EXEC | mode;
[ ... ]
> +static int rtl8127a_ptp_hwtstamp_enable(struct rtl8127a_ptp *ptp, bool enable)
> +{
> + int ret;
> +
> + mutex_lock(&ptp->lock);
> +
> + ret = rtl8127a_ptp_modify(ptp, RTL8127A_PTP_SYNCE_CTL,
> + RTL8127A_PTP_SYNCE_EN, 0);
> + if (ret)
> + goto out;
[ ... ]
> + } else {
> + ret = rtl8127a_ptp_modify(ptp, RTL8127A_PTP_INER,
> + RTL8127A_PTP_INT_RX_TS |
> + RTL8127A_PTP_INT_TX_TS, 0);
> + if (ret)
> + goto out;
> +
> + ret = rtl8127a_ptp_modify(ptp, RTL8127A_PTP_CTL,
> + RTL8127A_PTP_CTL_EN, 0);
> + }
> + if (ret)
> + goto out;
> +
> + ret = rtl8127a_ptp_modify(ptp, RTL8127A_PHY_RST_CTL, 0,
> + RTL8127A_PHY_RST);
[Severity: Low]
rtl8127a_ptp_probe() and rtl8127a_ptp_remove() both call
rtl8127a_ptp_hwtstamp_enable(ptp, false). That path clears
RTL8127A_PTP_SYNCE_EN, the INER RX/TX bits and RTL8127A_PTP_CTL_EN, and then
sets RTL8127A_PHY_RST here.
So every bind and unbind of the RTL8127A internal PHY now resets the PHY and
turns off SyncE. Is that intended?
The commit message only talks about registering a PTP clock. The v3
changelog only mentions adding defines for the PHY reset register.
If firmware or a PXE/UEFI environment brought the link up or enabled SyncE,
that state would now be lost at PHY probe rather than at ifup.
The follow-up patch "net: phy: realtek: add hardware timestamping for
RTL8127a" keeps this sequence and also runs it whenever timestamping is
toggled. Its commit message doesn't mention the reset either.
Could the commit message describe and justify the PHY reset and the SyncE
disable?
[Severity: Low]
The reset is asserted with a single read-modify-write of
RTL8127A_PHY_RST_CTL, and the function then returns. Nothing deasserts
RTL8127A_PHY_RST or waits for it to self-clear, the way genphy_soft_reset()
polls BMCR_RESET.
In rtl8127a_ptp_probe(), ptp_clock_register() comes right after this call
and exposes the PTP registers to userspace. r8169 also keeps accessing PHY
registers after PHY probe.
If the bit self-clears but takes a noticeable amount of time, could accesses
made during the reset be lost or see the pre-reset counter? That covers PHC
operations and the counter read in rtl8127a_ptp_config_init().
If the bit is level-sensitive, what releases it?
> +out:
> + mutex_unlock(&ptp->lock);
> +
> + return ret;
> +}
[ ... ]
> +int rtl8127a_ptp_config_init(struct phy_device *phydev)
> +{
> + struct rtl8127a_ptp *ptp = phydev->priv;
> + struct timespec64 ts;
> + int ret;
> +
> + if (!ptp)
> + return 0;
> +
> + /* Keep the clock running across a PHY re-init, a running PTP
> + * client would otherwise see it jump. Only start it from the
> + * system time if the counter has been reset.
> + */
> + ret = rtl8127a_ptp_gettimex64(&ptp->info, &ts, NULL);
> + if (ret)
> + return ret;
> +
> + if (ts.tv_sec >= RTL8127A_PTP_RESET_SEC)
> + return 0;
[Severity: Medium]
Does this check do what the commit message says? The commit message says:
The clock is started from the system tinme unless it is already running
The comment above says the clock is only started from the system time if the
counter has been reset.
The check tests neither of those. It tests whether the free-running counter
has been running for less than 10 seconds since its last reset.
config_init first runs from phy_init_hw() at ifup:
rtl_open()
r8169_phy_connect()
phylink_connect_phy()
...
phy_init_hw()
rtl8127a_ptp_config_init()
The counter starts at power-on, or at the PHY reset that
rtl8127a_ptp_probe() triggers during r8169 probe. More than 10 seconds
before the first ifup is normal after boot, and with a delayed or manual
ifup. In that case, wouldn't the PHC never be set and keep reporting
seconds since reset, close to 1970?
Also, rtl8169_init_phy() calls phy_init_hw() before r8169_hw_phy_config()
and genphy_soft_reset():
drivers/net/ethernet/realtek/r8169_main.c:rtl8169_init_phy() {
phy_init_hw(tp->phydev);
phy_resume(tp->phydev);
r8169_hw_phy_config(tp, tp->phydev, tp->mac_version);
...
genphy_soft_reset(tp->phydev);
}
Any counter reset caused by those later steps happens after this check, so
it would go unnoticed unless another config_init follows within 10 seconds.
The heuristic can also overwrite a clock that a user deliberately set below
10 seconds.
Is there a more reliable way to tell that the counter was reset than its
current value?
> +
> + ktime_get_real_ts64(&ts);
> +
> + return rtl8127a_ptp_settime(ptp, &ts);
[Severity: Low]
This seeds the PHC on the assumption that nothing after the PHY driver's
config_init resets the PTP counter. Does that hold with r8169?
As shown above, rtl8169_init_phy() runs phy_init_hw() before
r8169_hw_phy_config(). For RTL8127A, r8169_hw_phy_config() calls
rtl8127a_1_hw_phy_config(), which starts by loading the PHY MCU firmware:
drivers/net/ethernet/realtek/r8169_phy_config.c:rtl8127a_1_hw_phy_config() {
r8169_apply_firmware(tp);
rtl8168g_enable_gphy_10m(phydev);
...
}
genphy_soft_reset() runs after that, in rtl8169_init_phy().
Suppose either the firmware load or the BMCR soft reset clears the PTP
block. Then the value written here would be wiped on every open. The PHC
would run from about 0 until some later re-init happens to see tv_sec < 10.
Whether either step resets the counter depends on the hardware and can't be
confirmed from the code. The ordering between the two drivers isn't
documented, and the PHY driver has no hook that runs after the MAC driver's
PHY setup.
> +}
> +
> +int rtl8127a_ptp_probe(struct phy_device *phydev)
> +{
[ ... ]
> + ptp->phydev = phydev;
> + ptp->info = rtl8127a_ptp_info;
> +
> + ret = rtl8127a_ptp_hwtstamp_enable(ptp, false);
> + if (ret)
> + return ret;
> +
> + ptp->clock = ptp_clock_register(&ptp->info, dev);
[Severity: Low]
Should the rate-adjust registers be set to a known value before the clock is
registered?
rtl8127a_ptp_adjfine() is the only code that writes the rate (CFG_TIME
NS_LO/NS_HI, latched with RTL8127A_PTP_RATE_WRITE). Probe doesn't write a
zero rate before ptp_clock_register(), and rtl8127a_ptp_remove() doesn't
clear it.
The driver already assumes that PTP block state survives a PHY re-init. If
the latched rate also survives the probe-time reset, a rebind leaves the
hardware running at the last offset the servo applied. Examples are rmmod
and modprobe of realtek with the interface down, or a kexec or warm reboot.
That offset can be up to max_adj, about 488 ppm. The new ptp_clock would
meanwhile report a dialed frequency of 0.
Whether the rate register survives the PHY reset isn't verified. linuxptp
writes the frequency it reads back at startup, which hides most of the
effect. Writing a zero rate at probe would avoid the mismatch.
> + if (IS_ERR(ptp->clock))
> + return PTR_ERR(ptp->clock);
> +
> + phydev->priv = ptp;
> +
> + return 0;
> +}
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117060120.1175-1-javen_xu%40realsil.com.cn
next prev parent reply other threads:[~2026-11-21 6:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 6:01 [PATCH net-next v3 0/3] net: phy: realtek: add PTP support for RTL8127a javen
2026-11-17 6:01 ` [PATCH net-next v3 1/3] r8169: hold MDIO bus lock while loading firmware javen
2026-11-21 6:39 ` netdev-bot+sashiko
2026-11-17 6:01 ` [PATCH net-next v3 2/3] net: phy: realtek: add PTP clock support for RTL8127a javen
2026-11-21 6:39 ` netdev-bot+sashiko [this message]
2026-11-17 6:01 ` [PATCH net-next v3 3/3] net: phy: realtek: add hardware timestamping " javen
2026-11-21 6:39 ` 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=179524315156.3135.8784098981517637477@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