Article View: linux.kernel.netdev
Article #27332Re: [PATCH net-next v5 3/4] net: phy: realtek: add PTP clock support for RTL8127a
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 10:32
Date: Sat, 05 Dec 2026 10:32
263 lines
17307 bytes
17307 bytes
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 5 · Low: 1
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 does not match the code.
- [Medium] The multi-register PHC sequences are serialized only by the
private ptp->lock: rtl8127a_ptp_settime (5 CFG_TIME writes, then…
- [Medium] The PHC is registered at PHY probe (rtl_internal_nbaset_probe
-> rtl8127a_ptp_probe -> ptp_clock_register).
- [Medium] rtl8127a_ptp_hwtstamp_enable() ends by setting
RTL8127A_PHY_RST (BIT(15) of RTL8127A_PHY_RST_CTL, VEND2 0xa640) with…
- [Medium] rtl8127a_ptp_probe() calls rtl8127a_ptp_hwtstamp_enable(ptp,
false), which clears RTL8127A_PTP_CTL_EN (PTP_CTL bit 0) and…
- [Low] On every driver bind and unbind, rtl8127a_ptp_probe() and
rtl8127a_ptp_remove() call rtl8127a_ptp_hwtstamp_enable(ptp, false).
--
net: phy: realtek: add PTP clock support for RTL8127a
This patch registers a PTP hardware clock for the PTP block in the
internal PHY of RTL8127A (RTL8261C). The clock is read, set, stepped and
frequency adjusted through vendor MMD registers. A driver mutex
serializes the multi register sequences.
> Register a PTP hardware clock for it. All register accesses go through
> the normal blocking MDIO path, multi register sequences are serialized
> by a driver mutex. The frequency adjustment is cleared at probe. The
[Severity: Low]
Should the message also say what else happens at probe and remove?
Both rtl8127a_ptp_probe() and rtl8127a_ptp_remove() call
rtl8127a_ptp_hwtstamp_enable(ptp, false). That helper clears
RTL8127A_PTP_SYNCE_EN, the RX/TX timestamp interrupt enables and
RTL8127A_PTP_CTL_EN. It then always sets RTL8127A_PHY_RST:
ret = rtl8127a_ptp_modify(ptp, RTL8127A_PHY_RST_CTL, 0,
RTL8127A_PHY_RST);
So binding or unbinding the PHY driver now asserts what the v3 changelog
calls the PHY reset bit, and it turns off the PTP block enable. The
message doesn't describe either.
> clock is set from the system time when the link comes up for the first
> time after a PHY init or link loss.
[Severity: Medium]
Does this sentence still match the code? Nothing in this patch sets the
PHC from the system time.
The "Realtek Internal NBASE-T PHY" entry in realtek_drvs[] only gains
.probe and .remove, and there is no link_change_notify hook. The only
system time reads in realtek_ptp.c are the gettimex64 pre/post
timestamps.
The v5 changelog says this behaviour was dropped:
Don't set the clock from the system time on link up, leave the time
to userspace.
It looks like the commit body wasn't updated to match.
There is also a leftover field in struct rtl8127a_ptp that nothing reads
or writes:
bool time_set;
The later "net: phy: realtek: add hardware timestamping for RTL8127a"
patch adds a link_change_notify. That hook only restores timestamping,
and it doesn't use time_set either.
Could the sentence and the field be dropped?
> diff --git a/drivers/net/phy/realtek/realtek_ptp.c b/drivers/net/phy/realtek/realtek_ptp.c
> new file mode 100644
> index 0000000000000..72d0663a90c20
> --- /dev/null
> +++ b/drivers/net/phy/realtek/realtek_ptp.c
> @@ -0,0 +1,380 @@
[ ... ]
> +static int rtl8127a_ptp_hwtstamp_enable(struct rtl8127a_ptp *ptp, bool enable)
> +{
[ ... ]
> + } 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);
> + }
[Severity: Medium]
Does the PTP counter keep running while RTL8127A_PTP_CTL_EN is cleared?
rtl8127a_ptp_probe() takes this disable path before calling
ptp_clock_register(), and nothing in this patch sets CTL_EN again. Later
in the series it is only set while hardware timestamping is enabled
through hwtstamp_set.
The enable path writes RTL8127A_PTP_CTL_TYPE_3 (0x003f), which includes
bit 0. That makes CTL_EN look like the master enable of the PTP block.
If CTL_EN gates the counter, the registered PHC would be frozen whenever
timestamping is off. gettimex64 would return a stale value, and
adjtime, adjfine and settime64 would act on a disabled block.
If the counter and the CLK_CFG engine are known to work with CTL_EN
cleared, could a comment say so?
> + if (ret)
> + goto out;
> +
> + ret = rtl8127a_ptp_modify(ptp, RTL8127A_PHY_RST_CTL, 0,
> + RTL8127A_PHY_RST);
> +out:
> + mutex_unlock(&ptp->lock);
> +
> + return ret;
> +}
[Severity: Medium]
Should there be a wait after setting RTL8127A_PHY_RST? This sets bit 15
of VEND2 0xa640 and returns at once, with no delay and no poll for the
bit to self-clear.
rtl8127a_ptp_probe() goes straight on to the next step:
ret = rtl8127a_ptp_hwtstamp_enable(ptp, false);
...
ret = rtl8127a_ptp_adjfine(&ptp->info, 0);
adjfine writes CFG_TIME, triggers RATE_WRITE through CLK_CFG.EXEC, and
takes EXEC reading back as 0 to mean completion.
If this bit starts a self-clearing reset, can those writes land while the
block is still in reset, and the EXEC poll pass on a reset value of 0?
If the bit is level-sensitive instead, what deasserts it?
Other drivers that set PHY reset bits poll for completion, for example
smsc911x (PMT_CTRL_PHY_RST_), lan78xx (PMT_CTL_PHY_RST_) and igc
(IGC_PHY_RST_COMP). Later in the series this helper is also called from
hwtstamp_set and link_change_notify, still without a wait.
> +static int rtl8127a_ptp_settime(struct rtl8127a_ptp *ptp,
> + const struct timespec64 *ts)
> +{
> + int ret;
> +
> + mutex_lock(&ptp->lock);
> + ret = rtl8127a_ptp_write_time(ptp, ts);
> + if (!ret)
> + ret = rtl8127a_ptp_clkadj(ptp, RTL8127A_PTP_DIRECT_WRITE);
> + mutex_unlock(&ptp->lock);
> +
> + return ret;
> +}
[Severity: Medium]
Is ptp->lock enough to keep the staging writes and the EXEC write
together? It only serializes against other PTP callbacks. Each
phy_read_mmd()/phy_write_mmd() holds the MDIO bus lock for one access
only.
r8169 re-initializes this same PHY without taking ptp->lock:
rtl8169_up()
rtl8169_init_phy()
phy_init_hw()
r8169_hw_phy_config()
genphy_soft_reset()
rtl8169_up() runs from ndo_open, from the reset work after a TX timeout
and from resume. PHC ioctls and clock_adjtime() run in process context
without RTNL or phydev->lock.
Suppose that re-init lands between the CFG_TIME writes and the CLK_CFG
EXEC write, and clears the staging registers while the counter keeps
running. Could EXEC then apply the wrong time and still return success?
Or could the EXEC poll time out?
The same question applies to these sequences:
- the rate LO/HI writes in rtl8127a_ptp_adjfine()
- rtl8127a_ptp_adjtime()
- the EXEC-then-read sequence in rtl8127a_ptp_gettimex64()
The PTP block does seem to be affected by PHY re-init. The v3 changelog
mentions the counter being reset across re-initialization. The next
patch in the series also adds link_change_notify code commented "Restore
timestamping in case the PTP block was reset".
[ ... ]
> +static int rtl8127a_ptp_gettimex64(struct ptp_clock_info *info,
> + struct timespec64 *ts,
> + struct ptp_system_timestamp *sts)
> +{
> + struct rtl8127a_ptp *ptp = container_of(info, struct rtl8127a_ptp, info);
> + int ret;
> +
> + mutex_lock(&ptp->lock);
> + ret = rtl8127a_ptp_clkadj_sts(ptp, RTL8127A_PTP_DIRECT_READ, sts);
> + if (!ret)
> + ret = rtl8127a_ptp_read_time(ptp, RTL8127A_PTP_CFG_TIME, ts);
> + mutex_unlock(&ptp->lock);
> +
> + return ret;
> +}
[Severity: Medium]
What happens to the PHC callbacks while the NIC is runtime suspended?
The clock is registered at PHY probe and stays visible through /dev/ptpN
for as long as the driver is bound, including while the interface is
down.
The callbacks go straight to MMIO on the PCI function without taking a
runtime PM reference:
phy_read_mmd()
r8169_mdio_read_reg()
rtl_readphy()
r8168_phy_ocp_read()
r8169 schedules runtime suspend 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);
...
}
Once the function is in D3hot, CLK_CFG would read back as 0xffff and the
EXEC bit would never clear. Every PHC operation would then fail with
-ETIMEDOUT after logging OCP and poll errors. On some platforms, MMIO to
a D3hot function can also raise AER errors.
r8169 also powers the PHY down with phy_suspend() while the PHC stays
usable. There is no resume hook to restore a rate written by adjfine.
r8169's own LED helpers, such as rtl8168_led_mod_ctrl(), wrap their
register access in pm_runtime_resume_and_get(). Does the PHC path need
the same, or at least a check that the PHY is powered?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201094454.1150-1-javen_xu%40realsil.com.cn
Technical Details
Message-ID:
<179646675915.3146.5244202742063380412@kernel.org>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!peer04.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377934-linux-kernel-netdev=dewy.ruReferences:
<20261201094454.1150-4-javen_xu@realsil.com.cn>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!peer04.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377934-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v5 3/4] net: phy: realtek: add PTP clock support for RTL8127a Date: Sat, 05 Dec 2026 10:32:39 +0000 Organization: Usenet Network Message-ID: <179646675915.3146.5244202742063380412@kernel.org> References: <20261201094454.1150-4-javen_xu@realsil.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3007349"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:1GZFcdjTWQh3C2tlvVpVGSiMmJw= sha256:KzVuuVV/Zflo1FyMTaqRIbXMI/tzxXo/GJyGUW6ifqU= sha1:HskLH/LOj0mJmRGN4Fv+CXRVVjM= sha256:CmbdQQ5oZb9wLaWXFvffdOvXOBd/9S+gKmBBMWipbdc= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 75AD4117D21; Sat, 5 Dec 2026 13:32:56 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.641 X-Spam-Status: No, score=-3.641 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UU282yLixupe; Sat, 5 Dec 2026 13:32:53 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-377934-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id E9F63117A64; Sat, 5 Dec 2026 13:32:44 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 18AB1273CF; Sat, 5 Dec 2026 10:32:42 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796466761; b=ZTWFxaWU5gHHhCUClVE5mSz6W18qA2PPsegNf3EqTfuRIWoMz0V6C6NdU93eAzkSM+9J Am0RaWPUCmuo3pxul59s5SYg/SXTcuBUmh+NEHTtd1ubNhUQyV1xUk9e3cVnWICRAPa8i WDDrnX0snsI1XAY5uW+kl4yYVuCwbnJunqdQAizih0A7yEuaSUPDMp3BACEpQ9JoGoJb3 iyAbj2eSZ+jzKEySSqFnK+9ItisSKG4btKuHC1YmrDYNBpvDNlc3OTUZsh0fsum1CTe8m +0OsYr8CrIjKyj5fpFpY9Rp/1J0WQIK0GX1fC5dxFyreIUUfZ+s3y29Rohe8sqBRBGQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796466761; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=F1yr1RaJoyyL6qj+DZcY6qtpw25/Rna30uk0n0p8728=; b=piQcMr4HltZ3TWB6GiRKlFRLdchIZzBn/gLNzB1WpU0JVO27cZr3LN9GBC34t6DlAjik Xu0JzOCT0rfVpA75Iy/oG6G4KJNLZ6iMi2/vPe6pBzEDx9LtcqfMozq/YW3nmGO27LScQ HYB7f/7F4CEDsEVqhHl08rZq4V58CT6uC16P/xKIIUxxkoS0QijRavamGAzkyNZqWVDVY RHpDdIFmr0azWrwKXorxM8YphAc7kENel5qc6obS3teVdqcRKiC+lBCLBUSin2NrWIuxk YjknJk1BEezt4+Vt+X3xpDZSGhI3p1mJ2HFSul2u2APlsMd4TboJTasZnmvdk4tKELg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=chR8QDoU; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 819A4606A330; Sat, 5 Dec 2026 10:32:41 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=chR8QDoU X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796466760; b=aeP+AsLeV9OfoMku9tJJDBx9yYNjA6prZjGYjA3yOdYTfqNEjT205r1teWFy0ZG6+4h7 kcMTXjDYVWxxAS+UK+PkKDAEE1VbFSeYL77MPKhjBqJz/t0UqFcuFQ5dDtUh1dLnFsRJI GqRXjSFb2TOjJlomKANNgwwguj8iBZdGLUPfzljryouXd4IqPQRNu6twZfRHdXhQRDJ6X GIN+FsxwZJBxpn1RF967WtAzZveOYyFz2NkHeXXJCUnwDDEH4uhUALCofpdPs3i2pCLsf Y16LkkvgfY4V/XHkwKOyeiVqahQZDa9A0k+bum3R7GoQp0xLWDTSp+fpNQmzhYASyHQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796466760; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=F1yr1RaJoyyL6qj+DZcY6qtpw25/Rna30uk0n0p8728=; b=ksR/a576DDZ5c15jgZuBrFhv9vuuzpnaDw2V6ecZRwT4f6k0InWk90SqpefU8EQuiMp3 ns4cYUkvY1S3j2l7IWWcmOCH855H0AkcqPfwfl2GoECDwTKN6mOHUCa8cn/6Wm8DJmLaX HhOn01pAbUZ+brSxNiuhMK0RyYwEYd8kqpovhiY7ILNi5i5lo7YWWLPh7ZZ13Z9QlJ4Ih j9RnNtmT0/VH8kxwHy3RVg2W1U/kM4EP0DITvuf8fyUKReQyhvM6BeM8ncwLXTqhJjWvv 8UTOF9FxYRFjkGDk0sWXlQX39O/OBm8FFgoP96RmPML6r4pBqCF8oE3DxVTgtlGIkKg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=chR8QDoU; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5232606A336; Sat, 5 Dec 2026 10:32:40 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DDAF1F00A10; Sat, 5 Dec 2026 10:32:39 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796466760; bh=F1yr1RaJoyyL6qj+DZcY6qtpw25/Rna30uk0n0p8728=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=chR8QDoUydE2TX9UeDnW95T32bQOdPgpuV45bJ6glp4N+jjfwt98SYmy5qT5hlwfY CgaCg7GJVEL+fHKYyF8xPnJbJQv2OCIT7wRBx9/uMjE7HmJR8mTKvDTAasWnEYYq30 Q4Sd2QUv94z1vU5zEYGNxaqfRUI3cZ+3570QPgUU9RgjPXxsHDkc5D+CbrKzb5Ym8+ 4nNQTOXzisEox3i9aOKB9tpdMwIIRfVI1WcjeBcPmE2G3nxAb90eCQZ3eQD+C9VrBT Tn0gvjSo9ROb/eYh3cGVMULJqWh39bTH/urHqf5EDO5qQ+o+BS8uyz6Vc50gi+YRjt bLIBfkPykOMuA== X-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 X-In-Reply-To: <20261201094454.1150-4-javen_xu@realsil.com.cn> X-sashiko-severity: Medium X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-Received-Bytes: 17111