From: Javen <javen_xu@realsil.com.cn>
To: Andrew Lunn <andrew@lunn.ch>
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>
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 [thread overview]
Message-ID: <43e9de91177b4ffaa7b1c22c45109578@realsil.com.cn> (raw)
In-Reply-To: <07ddc9e6-2604-47d4-9e68-eedfaa4ee142@lunn.ch>
>
>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
next prev parent reply other threads:[~2026-11-30 3:37 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 9:02 [PATCH net-next v4 0/3] net: phy: realtek: add PTP support " javen
2026-11-25 9:02 ` [PATCH net-next v4 1/3] r8169: hold MDIO bus lock while loading firmware javen
2026-11-29 9:50 ` netdev-bot+sashiko
2026-11-25 9:02 ` [PATCH net-next v4 2/3] net: phy: realtek: add PTP clock support for RTL8127a javen
2026-11-29 9:50 ` netdev-bot+sashiko
2026-11-25 9:02 ` [PATCH net-next v4 3/3] net: phy: realtek: add hardware timestamping " javen
2026-11-25 9:43 ` Vladimir Oltean
2026-11-26 6:13 ` Javen
2026-11-26 14:08 ` Andrew Lunn
2026-11-30 3:35 ` Javen [this message]
2026-11-29 9:50 ` 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=43e9de91177b4ffaa7b1c22c45109578@realsil.com.cn \
--to=javen_xu@realsil.com.cn \
--cc=andrew@lunn.ch \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--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
all inboxes | Powered by JetHome®