From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DDAF1F00A10; Sat, 5 Dec 2026 10:32:39 +0000 (UTC) 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== Subject: Re: [PATCH net-next v5 3/4] net: phy: realtek: add PTP clock support for RTL8127a 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 Date: Sat, 05 Dec 2026 10:32:39 +0000 Message-ID: <179646675915.3146.5244202742063380412@kernel.org> In-Reply-To: <20261201094454.1150-4-javen_xu@realsil.com.cn> References: <20261201094454.1150-4-javen_xu@realsil.com.cn> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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