Article View: linux.kernel.netdev
Article #24346RE: [PATCH net-next v4 3/3] net: phy: realtek: add hardware timestamping for RTL8127a
From: Javen
Date: Mon, 30 Nov 2026 03:35
Date: Mon, 30 Nov 2026 03:35
203 lines
16998 bytes
16998 bytes
>
>On Thu, Nov 26, 2026 at 06:13:55AM +0000, Javen wrote:
>> >
>> >
>> >On Wed, Nov 25, 2026 at 05:02:16PM +0800, javen wrote:
>> >> + phydev->default_timestamp = true;
>> >
>> >Enabling new instances of phydev->default_timestamp is not an option
>> >that you have. Did you research why it exists?
>>
>> Hi Vladimir,
>>
>
>> Thanks for review. I understand that phydev->default_timestamp was
>> introduced to preserve legacy behavior. However, RTL8127A doesn't
>> support mac ptp. The PHY is the only hardware timestamping block
>> available on this link. Without setting default_timestamp = true, the
>> current core framework simply breaks for this PHY-only chip.
>> How would you prefer handling such hardware without mac ptp? Any
>> suggestion would be great helpful.
>
>That sounds like something is broken somewhere. This should only come into
>effect when there are two stampers available, e.g. a Marvell PHY connected to
>a Marvell Switch. As far as i remember, the PHY one is partially broken, so you
>want to use the MAC one, if available.
>
>However, if there is no choice, i would not expect default_timestamp to do
>anything.
>
>Please spend some time to understand what is going on here.
Hi Andrew,
I think the problem is in how the core picks the default timestamp.
When both mac and phy support ptp timestamp, and the user has not selected a provider(dev->hwprov is NULL), the core uses the mac. It uses the phy only if the phy driver sets default_timestamp, which is kept for the old behaviour.
static inline bool phy_is_default_hwtstamp(struct phy_device *phydev)
{
return phy_has_hwtstamp(phydev) && phydev->default_timestamp;
}
But this does not check if the MAC support timestamp. RTL8127 is the PHY only. Without default_timestamp, the core still picks the MAC, and the hardware timestamping does not work.
- skb_clone_tx_timestamp() and skb_defer_rx_timestamp() return early,
so no packet reaches the PHY
- ethtool -T reports software timestamping only
- SIOCSHWTSTAMP and SIOCGHWTSTAMP return -EOPNOTSUPP
- tsconfig-set also returns -EOPNOTSUPP, so the user cannot select
the PHY by hand either
I think that when mac cannot support timestamp but phy support, phy should be the default timestamp. I have prepared patch below. If the mac has hwtstamp NDOs, nothing changes.
diff --git a/net/core/dev.h b/net/core/dev.h
index 4e9e8cd15697..7bc3c65c249d 100644
--- a/net/core/dev.h
+++ b/net/core/dev.h
@@ -418,5 +418,6 @@ int dev_set_hwtstamp_phylib(struct net_device *dev,
int dev_get_hwtstamp_phylib(struct net_device *dev,
struct kernel_hwtstamp_config *cfg);
int net_hwtstamp_validate(const struct kernel_hwtstamp_config *cfg);
+bool dev_phy_is_default_hwtstamp(struct net_device *dev);
#endif
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index f6029f60c1dc..db345fe13744 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -32,6 +32,16 @@ static int dev_ifname(struct net *net, struct ifreq *ifr)
return netdev_get_name(net, ifr->ifr_name, ifr->ifr_ifindex);
}
+bool dev_phy_is_default_hwtstamp(struct net_device *dev)
+{
+ struct phy_device *phydev = dev->phydev;
+
+ if (phy_is_default_hwtstamp(phydev))
+ return true;
+
+ return phy_has_hwtstamp(phydev) && !dev->netdev_ops->ndo_hwtstamp_set;
+}
+
/*
* Perform a SIOCGIFCONF call. This structure will change
* size eventually, and there is nothing I can do about it.
@@ -274,7 +284,7 @@ int dev_get_hwtstamp_phylib(struct net_device *dev,
return -EOPNOTSUPP;
}
- if (phy_is_default_hwtstamp(dev->phydev))
+ if (dev_phy_is_default_hwtstamp(dev))
return phy_hwtstamp_get(dev->phydev, cfg);
if (!dev->netdev_ops->ndo_hwtstamp_get)
@@ -351,7 +361,7 @@ int dev_set_hwtstamp_phylib(struct net_device *dev,
cfg->qualifier = hwprov->desc.qualifier;
} else {
- phy_ts = phy_is_default_hwtstamp(dev->phydev);
+ phy_ts = dev_phy_is_default_hwtstamp(dev);
if (phy_ts)
phydev = dev->phydev;
}
diff --git a/net/core/timestamping.c b/net/core/timestamping.c
index a50a7ef49ae8..4dcf803b0bb3 100644
--- a/net/core/timestamping.c
+++ b/net/core/timestamping.c
@@ -10,6 +10,7 @@
#include <linux/skbuff.h>
#include <linux/export.h>
#include <linux/ptp_clock_kernel.h>
+#include "dev.h"
static unsigned int classify(const struct sk_buff *skb)
{
@@ -43,7 +44,7 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
phydev = hwprov->phydev;
} else {
phydev = skb->dev->phydev;
- if (!phy_is_default_hwtstamp(phydev)) {
+ if (!dev_phy_is_default_hwtstamp(skb->dev)) {
rcu_read_unlock();
return;
}
@@ -86,7 +87,7 @@ bool skb_defer_rx_timestamp(struct sk_buff *skb)
phydev = hwprov->phydev;
} else {
phydev = skb->dev->phydev;
- if (!phy_is_default_hwtstamp(phydev)) {
+ if (!dev_phy_is_default_hwtstamp(skb->dev)) {
rcu_read_unlock();
return false;
}
diff --git a/net/ethtool/common.c b/net/ethtool/common.c
index ec67fbd6bb86..b15446daef58 100644
--- a/net/ethtool/common.c
+++ b/net/ethtool/common.c
@@ -1089,7 +1089,7 @@ int __ethtool_get_ts_info(struct net_device *dev,
struct phy_device *phydev = dev->phydev;
ethtool_init_tsinfo(info);
- if (phy_is_default_hwtstamp(phydev) &&
+ if (dev_phy_is_default_hwtstamp(dev) &&
phy_has_tsinfo(phydev)) {
err = phy_ts_info(phydev, info);
/* Report the phc source only if we have a real
diff --git a/net/ethtool/tsconfig.c b/net/ethtool/tsconfig.c
index 2db0e7ba8b9f..b099329ada06 100644
--- a/net/ethtool/tsconfig.c
+++ b/net/ethtool/tsconfig.c
@@ -44,7 +44,7 @@ static int tsconfig_prepare_data(const struct ethnl_req_info *req_base,
int ret;
if (!dev->netdev_ops->ndo_hwtstamp_get &&
- !phy_is_default_hwtstamp(dev->phydev) &&
+ !dev_phy_is_default_hwtstamp(dev) &&
!netdev_ops_lock_dereference(dev->hwprov, dev))
return -EOPNOTSUPP;
@@ -306,7 +306,7 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base,
return -ENODEV;
if (!dev->netdev_ops->ndo_hwtstamp_set &&
- !phy_is_default_hwtstamp(dev->phydev) &&
+ !dev_phy_is_default_hwtstamp(dev) &&
!netdev_ops_lock_dereference(dev->hwprov, dev))
return -EOPNOTSUPP;
--
2.43.0
I tested it on RTL8127A with net-next. With this patch, and with default_timestamp removed from the Realtek PHY driver, ptp4l works with PHY hardware timestamps.
I also have a question about the approach. Would you prefer:
1) a new helper in net/core, as in the patch above, or
2) changing phy_is_default_hwtstamp() itself?
For 2), phy_is_default_hwtstamp() only gets the phydev, so it would have to check the MAC through phydev->attached_dev. Then include/linux/phy.h would need to include linux/netdevice.h, which it does not do today.
Any advice would be appreciated.
Thanks,
Javen
>
> Andrew
Technical Details
Message-ID:
<43e9de91177b4ffaa7b1c22c45109578@realsil.com.cn>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373812-linux-kernel-netdev=dewy.ruReferences:
<20261125090217.1198-1-javen_xu@realsil.com.cn> <20261125090217.1198-1-javen_xu@realsil.com.cn> <20261125090217.1198-4-javen_xu@realsil.com.cn> <20261125090217.1198-4-javen_xu@realsil.com.cn> <awathfkR13ZQH6g9@lxl00025.wbi.nxp.com> <15f473435a41440da45c6d070edc1128@realsil.com.cn> <07ddc9e6-2604-47d4-9e68-eedfaa4ee142@lunn.ch>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373812-linux-kernel-netdev=dewy.ru From: javen_xu@realsil.com.cn (Javen) Newsgroups: linux.kernel.netdev Subject: RE: [PATCH net-next v4 3/3] net: phy: realtek: add hardware timestamping for RTL8127a Date: Mon, 30 Nov 2026 03:35:34 +0000 Organization: Usenet Network Message-ID: <43e9de91177b4ffaa7b1c22c45109578@realsil.com.cn> References: <20261125090217.1198-1-javen_xu@realsil.com.cn> <20261125090217.1198-1-javen_xu@realsil.com.cn> <20261125090217.1198-4-javen_xu@realsil.com.cn> <20261125090217.1198-4-javen_xu@realsil.com.cn> <awathfkR13ZQH6g9@lxl00025.wbi.nxp.com> <15f473435a41440da45c6d070edc1128@realsil.com.cn> <07ddc9e6-2604-47d4-9e68-eedfaa4ee142@lunn.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Injection-Info: usenet.network; logging-data="1322611"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:cf+N2ysYAw1bTU2WaUoXwIKPRxM= sha256:Q4KGuRjt7Js6dtgDejKVP/gzcBi/loRvRywRYu1p1so= sha1:95bvhonsJNgCYSPhXcHMYrwzftM= sha256:6yHK+H4w6Bl7xOkQNGhGhv8v6A08RXzRweqjbWDc4SU= Content-Language: zh-CN 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 B59D8125F93; Mon, 30 Nov 2026 06:37:32 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.151 X-Spam-Status: No, score=-3.151 tagged_above=-9999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=realsil.com.cn 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 WMqPT0-ui8Ku; Mon, 30 Nov 2026 06:37:29 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-373812-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=realsil.com.cn X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 6291A125F08; Mon, 30 Nov 2026 06:37:20 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id D3D136006FD; Mon, 30 Nov 2026 03:37:19 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1796009837; b=oM4Pl0lYvXL0HWfNh1Rs8+5xvpoHifRnSiLKgoe/W5FnoMDcicGGXgDODdZ+aHTv5v1K xxzp4wIe73MPBivs+erRWu0k9ubUlA/bdw6tOY7CF4bHaA7EeARqIJ4ZEdlN3oiGrVh1Z jrtPNhfvJHgl+QUxQtUj46ZEczWPGfUHgT4Iqp073PEyuarFUOmmh8CJc0C16EJGJAkOX DzmSd5icz/Ux0Tn5OtW7T+s7Tznx35ahGCbGJ4u8z+d/8FKQ9CyWizgI6grBAdj8Sbq0o +prif8nSYL31DbaC7OMhz+nnYAxK79ZiZitafV5HX7KLmCrDJ5gZsqREAmBsvnTp5ew== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796009837; h=X-Original-To:Received:DMARC-Filter:X-SpamFilter-By:DKIM-Signature: Received:Received:Received:From:To:CC:Subject:Thread-Topic: Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language: Content-Language:Content-Type:Content-Transfer-Encoding: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version; bh=VpNM+D8+ypXneGf9ksskoLaFUoO0ctYWOVVQdJS5sXs=; b=GLhUHssOVEhY9TK7Ene44nOpYarOKScfl0rrLHHCGtPKcg/J+kEccfgz5GkMStPcDkGA tRIqClQj4w1EbYoMghKwndg7s9sYA4f6EG+NwWmGaNIpDHG3Ad7eFlt6L2/Rit36/BPgi DG/LbfPt4yj5ZJGSVFRRn6L5s2bhRCxu6Ayj3a73QrXUo9O2oznaEbOTkqn2C9zvQn5l0 6p0blQ2JE9xmqVcDmwpezcdeqs+BHHxLNx9I9Xr2ojrJpX+KI70QKi1yPXW8ezjDtRc3H aQ7CL4h54gvHJf6HiVPYM75RYJLMUSWi5C4h0o4nCTpNdiLHK9MrluHVGewUR0m2TxQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=realsil.com.cn header.i=@realsil.com.cn header.a=rsa-sha256 header.s=dkim header.b=ET29753K; dmarc=pass header.from=realsil.com.cn; spf=pass smtp.mailfrom=realsil.com.cn; arc=fail 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 2FCB5606A325; Mon, 30 Nov 2026 03:37:17 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=realsil.com.cn header.i=@realsil.com.cn header.a=rsa-sha256 header.s=dkim header.b=ET29753K X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=211.75.126.72 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796009831; b=gmgqUSKHthWUWHvZ+JavI3NJCfJjgsaTc3vVTfgrSzlW00vMQzlJANH3zKNBsvd9kWxk 7Fa/6NUUh9hIIl2k8CEytJBKSgrztqS7z387ttdcVqERfbECfeg8NtBDpv3MYR+Pnjlfo 3DCPtTrSEw5f04EDQng1rwTmJy81lBaqkmUiLGe8wu4azzxc9JseCdTWiYZHDwjBs//dS 93OQTOxT+tIAiLZ17t6E7qYdlMuUphRlGkb5zDEuYi7oVJ3t9RuhC7lxQifAleTEwTQ9X FbJ4GI3DDrRFAzFc7xznAdto+sr6cKp0/QGstYIxFkM+utpwRqAQrxumxTIBAuPJURA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796009831; h=DMARC-Filter:X-SpamFilter-By:DKIM-Signature:Received:Received: Received:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID: References:In-Reply-To:Accept-Language:Content-Language: x-originating-ip:Content-Type:Content-Transfer-Encoding:MIME-Version; bh=VpNM+D8+ypXneGf9ksskoLaFUoO0ctYWOVVQdJS5sXs=; b=a0bOHN9K1P+j1ugvnQ2G0b+WP9pkxJoB6qjcSj0uQOpAOyckwh8wjbRnqsr6YqTyUdkE Eo2nXB/W8AvbpAxMWgXtcy7Ktkqr6xFMcM+MNdODsxDOXrSWcu5h9CILHUpkjPOe0M1DE 2CDXXHwglITCZsZfz5h2vRZChN/ih7xWxfqiEw6q1ly/VmoRmKeqC9TEwsF6ffSaYtQ8d tEoKb4Hr9OPjrgv8EV8s0zk/TxzbzR+tlFITGEvzw0XygjpcMR54ANTTzrEJxUvaw3cwW xDBemTCJKWBRwn48b/JckDWXdyzv4rXOCFmHgLYe5kNU/0RyCQ6tAn8YwySRtMlCk/w== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=realsil.com.cn; spf=pass smtp.mailfrom=realsil.com.cn; dkim=pass header.d=realsil.com.cn header.i=@realsil.com.cn header.a=rsa-sha256 header.s=dkim header.b=ET29753K; arc=none smtp.remote-ip=211.75.126.72 X-Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41592606A31C; Mon, 30 Nov 2026 03:37:09 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 41592606A31C X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=realsil.com.cn X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=realsil.com.cn X-SpamFilter-By: ArmorX SpamTrap 5.80 with qID 6AU3ZXhL43024735, This message is accepted by code: ctloc85258 X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=realsil.com.cn; s=dkim; t=1796009734; bh=VpNM+D8+ypXneGf9ksskoLaFUoO0ctYWOVVQdJS5sXs=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:Content-Transfer-Encoding:MIME-Version; b=ET29753KuvF4ACMSVN9BvykHO8ZPHD6bgvEbkzKa7yxuLxo4yfMRFcJYQL2tbYY8u URuwqati6rA7N+V8OHcm4ksz/4qGNxk6wY/GSPQgj7TAQT2c+VmLVt1TvJRwAvTWQ0 yYbxNWHlSNbCe8IwE2DYvfjmYiNyFENuo+IfHPJ3j5iH1Txs6p9w1LP81tpFsEJZSO NJ5Rv1Z4slSC08yGL4CLnRDQEQPcEjmmkzTxldAmf0O91WSxuhPmrntLKAjY3KX3Et TvOQzonxPldUz4dMd+2BP2IoVGqSRO56zYRwKcW4YnPwnZLbL+qFzEXV6I2pf07IfU Xy+kPMaZyeXJw== X-Received: from RS-EX-MBS4.realsil.com.cn ([172.29.17.104]) by rtits2.realtek.com.tw (8.15.2/3.29/5.94) with ESMTPS id 6AU3ZXhL43024735 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 30 Nov 2026 11:35:34 +0800 X-Received: from RS-EX-MBS3.realsil.com.cn (172.29.17.103) by RS-EX-MBS4.realsil.com.cn (172.29.17.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Mon, 30 Nov 2026 11:35:34 +0800 X-Received: from RS-EX-MBS3.realsil.com.cn ([172.29.17.103]) by RS-EX-MBS3.realsil.com.cn ([172.29.17.103]) with mapi id 15.02.2562.056; Mon, 30 Nov 2026 11:35:34 +0800 X-CC: Vladimir Oltean <vladimir.oltean@nxp.com>, "hkallweit1@gmail.com" <hkallweit1@gmail.com>, "linux@armlinux.org.uk" <linux@armlinux.org.uk>, "davem@davemloft.net" <davem@davemloft.net>, "edumazet@google.com" <edumazet@google.com>, "kuba@kernel.org" <kuba@kernel.org>, "pabeni@redhat.com" <pabeni@redhat.com>, "nb@tipi-net.de" <nb@tipi-net.de>, "maxime.chevallier@bootlin.com" <maxime.chevallier@bootlin.com>, "netdev@vger.kernel.org" <netdev@vger.kernel.org>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>, "daniel@makrotopia.org" <daniel@makrotopia.org> X-Thread-Topic: [PATCH net-next v4 3/3] net: phy: realtek: add hardware timestamping for RTL8127a X-Thread-Index: AQHdfLusREI69QMHwUie9alKwtUlK7c+iZ7RgAFTcXCAAAKPgIAGGtww X-In-Reply-To: <07ddc9e6-2604-47d4-9e68-eedfaa4ee142@lunn.ch> X-Accept-Language: zh-CN, en-US 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