Article View: linux.kernel.netdev
Article #24110Re: [PATCH net-next v4 2/3] net: phy: realtek: add PTP clock support for RTL8127a
From: netdev-bot+sashiko
Date: Sun, 29 Nov 2026 09:50
Date: Sun, 29 Nov 2026 09:50
166 lines
13267 bytes
13267 bytes
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
Technical Details
Message-ID:
<179594581280.3146.11285763012972937249@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373442-linux-kernel-netdev=dewy.ruReferences:
<20261125090217.1198-3-javen_xu@realsil.com.cn>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373442-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev 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 Organization: Usenet Network Message-ID: <179594581280.3146.11285763012972937249@kernel.org> References: <20261125090217.1198-3-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="1143635"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:+kUS0UIfRoHeDaWCB0fgRJnEpsw= sha256:VdAh3C3S9/9lYDioPfol0UToEEA9T1e4fcZcvqcrAVQ= sha1:+XP5AGLZnKeMKx4pzYowBIK11bY= sha256:wjwhw5uGf/BANYB8sTmIwPx11SlSqY8gpHKj7WCbWb4= 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 D3D0E125F99; Sun, 29 Nov 2026 12:50:31 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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 2ryuVMBNS2_b; Sun, 29 Nov 2026 12:50:27 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373442-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 7FA6D125F96; Sun, 29 Nov 2026 12:50:19 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 66429264DB; Sun, 29 Nov 2026 09:50:15 +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=1795945815; b=eys3nF+lTAnTiLjjJgy4X7g0aeUXcbEFkTg0/4Ov4AM4X+9nU7+fBq88x3UR4udPrORP Y0E1RjNvxixKkccGgNT+Kcq2E2wh+4Oq5HyoeO1nNwI5kxwH9Ex02KqPrF6QGH7+myr6q 7v4TP7Vnn/ihsrHPXV6ka6Pg7s/ufar/GVorMlBaXlXRxpH3yw1XbX3rt8WpCDP98dOCN +To594obCmgSHj0RzuOekjaBXNQaEvF8u+yj28izgHOU/G/QUca4pHOAtR+urDx0WlAAd qwKKx/Y5oEUnABWKBDhhz+OSN5NVPnB5UdpVF7ERJQc9blURlKc9CzGVmo7bIRU3xIw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795945815; 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=zr6U5qVA5+IoVISytsi1lpSc5a4ElP8vuTD2mxlpJ3o=; b=VNlqE6Fxc2pYbwe0yVWeucogfCSFs/Foi5LMY3+G5hbAlHdYfW0TO3NvRe2KWskXSASy AOXR4J5UByK13UEJeTg3FFz2sdXBJQRaTarR4gf0TMHFdhYiJUlIf5afHTsC8lpNj1409 hAc6XjTX7ShKitM0XDGs6Ff9kzwfJ2wS3XaYLANmdal1uq7DtJPLG3YLWw2AwA9UN40x3 47xSY+Ow6DNUCMhDUjdp0zEed/aH1x3Dy477qaGo0IpmwsC/SAaX3UochOXL/v7lTqP4y rC6JuJPqGvJv2Ca+/JYtji003/L8UNn94o6AB69bSLI5SeJNJ/RYwGxSwjcaZakDHTQ== 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=XyUZQbKa; 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 3E3C7606A32E; Sun, 29 Nov 2026 09:50:15 +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=XyUZQbKa 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=1795945814; b=iIjHAqM2J/cEAAbOWACZSP/sTHdKytDYiajxnjY520irL/n5UAuldyHmg/mM7kA5SKMa 9d0kgsQv94vlTld3gac3ctdAM8QRNKbKWT9bfR5FIMyC0TZHMQ/CrthwL/DbhXYfT+Gpg fZp9VV8zdj/po+h6QLv3KtOX5S0spCjcXjr9Bm3cZybV5KwV1VHAt05swlqBAOBsPNR4k p4BOsTx+l03pN53CPD0MtiFy2LKBu9ox2fWs88PMl8xIdAc2ic61BaUYfw3SVS/GtNw4H B4+3zq9zDAeZd6RQ/S2yYYNz7XzLPnfGLoz61Q45YqRwx9MdnFakxfbUQLPUrxLh8eA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795945814; 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=zr6U5qVA5+IoVISytsi1lpSc5a4ElP8vuTD2mxlpJ3o=; b=t3bX0AtRDltkaQz1ixHhQ0bolbMl2/ZCRqe3ZvWMheuxrXyCViBqZqbcl8TpFlRaYvFu CPtDiqTo1jSUWw4a9uzu4PZ2OBBWGfYVajAE79GkUz2LlAQkSnPv2dq3KIc/4iG7uLH0/ WIEFZtySKUwmsoq/I7nHExtd4RsFkru0Mst9QqXK3C2wYq4XJk+s0y961zhCbtlnJnGIy 3ZKMQ57oTFKV7jJaJiUiBCTlvi9lSWEDbTmz8NQKmsx2Ss5ums7DC52yUwkMbtvtIlc3k acJ46fdJh0WrVecV0u7yej6TGrCyxvaQEoY8fijbsru2jGWq7iLv2Wp+4KwbLykLu/Q== 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=XyUZQbKa; 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 5E197606A32F; Sun, 29 Nov 2026 09:50:14 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E91F1F000C1; Sun, 29 Nov 2026 09:50:13 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795945814; bh=zr6U5qVA5+IoVISytsi1lpSc5a4ElP8vuTD2mxlpJ3o=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=XyUZQbKa2uz+eJIO/L27uvEYQcncPM/JWnqsr3kd6Kd2qUz9DP3KdpRXqLLMlQs1Y glyOujpB5fC+nYLGvHcP1uGH4Vpzb/R7gKqXnN40hOu/1IY5bcOJ15Dgap7K5l85fD XSwdpaR/Z//yW2qz7ue6jbT5FIbvAoleN1eGN4NTF1xq26DcW9ZPgUhFJLlMee0Ug1 iirCmUtGZq/TajH92xV8ol2kchCB2E/vcI6zOcO2UQL4V2J/nUvntQYfn5V/uE4OVS T220Qe+QPMcZqVy3xpgRPETgy5TtyhZuMCnJLqTimTF6cIHhNAOxoc0eoDfkWiIguw gSpyO/zk+PtKA== 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: <20261125090217.1198-3-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