> >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