Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: Add support for providing the PTP hardware source in tsinfo

Multi-PTP source support within a network topology has been merged,
but the hardware timestamp source is not yet exposed to users.
Currently, users only see the PTP index, which does not indicate
whether the timestamp comes from a PHY or a MAC.

Add support for reporting the hwtstamp source using a
hwtstamp-source field, alongside hwtstamp-phyindex, to describe
the origin of the hardware timestamp.

Remove HWTSTAMP_SOURCE_UNSPEC enum value as it is not used at all.

Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
Link: https://patch.msgid.link/20250519-feature_ptp_source-v4-1-5d10e19a0265@bootlin.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Kory Maincent and committed by
Paolo Abeni
4ff4d86f 3da895b2

+94 -11
+27
Documentation/netlink/specs/ethtool.yaml
··· 98 98 name: tcp-data-split 99 99 type: enum 100 100 entries: [ unknown, disabled, enabled ] 101 + - 102 + name: hwtstamp-source 103 + doc: Source of the hardware timestamp 104 + enum-name: hwtstamp-source 105 + name-prefix: hwtstamp-source- 106 + type: enum 107 + entries: 108 + - 109 + name: netdev 110 + doc: | 111 + Hardware timestamp comes from a MAC or a device 112 + which has MAC and PHY integrated 113 + value: 1 114 + - 115 + name: phylib 116 + doc: | 117 + Hardware timestamp comes from one PHY device 118 + of the network topology 101 119 102 120 attribute-sets: 103 121 - ··· 914 896 name: hwtstamp-provider 915 897 type: nest 916 898 nested-attributes: ts-hwtstamp-provider 899 + - 900 + name: hwtstamp-source 901 + type: u32 902 + enum: hwtstamp-source 903 + - 904 + name: hwtstamp-phyindex 905 + type: u32 917 906 - 918 907 name: cable-result 919 908 attr-cnt-name: __ethtool-a-cable-result-cnt ··· 2006 1981 - phc-index 2007 1982 - stats 2008 1983 - hwtstamp-provider 1984 + - hwtstamp-source 1985 + - hwtstamp-phyindex 2009 1986 dump: *tsinfo-get-op 2010 1987 - 2011 1988 name: cable-test-act
+5
include/linux/ethtool.h
··· 19 19 #include <linux/netlink.h> 20 20 #include <linux/timer_types.h> 21 21 #include <uapi/linux/ethtool.h> 22 + #include <uapi/linux/ethtool_netlink_generated.h> 22 23 #include <uapi/linux/net_tstamp.h> 23 24 24 25 #define ETHTOOL_MM_MAX_VERIFY_TIME_MS 128 ··· 831 830 * @so_timestamping: bit mask of the sum of the supported SO_TIMESTAMPING flags 832 831 * @phc_index: device index of the associated PHC, or -1 if there is none 833 832 * @phc_qualifier: qualifier of the associated PHC 833 + * @phc_source: source device of the associated PHC 834 + * @phc_phyindex: index of PHY device source of the associated PHC 834 835 * @tx_types: bit mask of the supported hwtstamp_tx_types enumeration values 835 836 * @rx_filters: bit mask of the supported hwtstamp_rx_filters enumeration values 836 837 */ ··· 841 838 u32 so_timestamping; 842 839 int phc_index; 843 840 enum hwtstamp_provider_qualifier phc_qualifier; 841 + enum hwtstamp_source phc_source; 842 + int phc_phyindex; 844 843 enum hwtstamp_tx_types tx_types; 845 844 enum hwtstamp_rx_filters rx_filters; 846 845 };
+1 -6
include/linux/net_tstamp.h
··· 4 4 #define _LINUX_NET_TIMESTAMPING_H_ 5 5 6 6 #include <uapi/linux/net_tstamp.h> 7 + #include <uapi/linux/ethtool_netlink_generated.h> 7 8 8 9 #define SOF_TIMESTAMPING_SOFTWARE_MASK (SOF_TIMESTAMPING_RX_SOFTWARE | \ 9 10 SOF_TIMESTAMPING_TX_SOFTWARE | \ ··· 13 12 #define SOF_TIMESTAMPING_HARDWARE_MASK (SOF_TIMESTAMPING_RX_HARDWARE | \ 14 13 SOF_TIMESTAMPING_TX_HARDWARE | \ 15 14 SOF_TIMESTAMPING_RAW_HARDWARE) 16 - 17 - enum hwtstamp_source { 18 - HWTSTAMP_SOURCE_UNSPEC, 19 - HWTSTAMP_SOURCE_NETDEV, 20 - HWTSTAMP_SOURCE_PHYLIB, 21 - }; 22 15 23 16 /** 24 17 * struct hwtstamp_provider_desc - hwtstamp provider description
+24 -5
net/ethtool/common.c
··· 921 921 922 922 phy = ethtool_phy_get_ts_info_by_phc(dev, info, hwprov_desc); 923 923 if (IS_ERR(phy)) 924 - err = PTR_ERR(phy); 925 - else 926 - err = 0; 924 + return PTR_ERR(phy); 925 + 926 + /* Report the phc source only if we have a real 927 + * phc source with an index. 928 + */ 929 + if (info->phc_index >= 0) { 930 + info->phc_source = HWTSTAMP_SOURCE_PHYLIB; 931 + info->phc_phyindex = phy->phyindex; 932 + } 933 + err = 0; 934 + } else if (!err && info->phc_index >= 0) { 935 + info->phc_source = HWTSTAMP_SOURCE_NETDEV; 927 936 } 928 937 929 938 info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE | ··· 956 947 957 948 ethtool_init_tsinfo(info); 958 949 if (phy_is_default_hwtstamp(phydev) && 959 - phy_has_tsinfo(phydev)) 950 + phy_has_tsinfo(phydev)) { 960 951 err = phy_ts_info(phydev, info); 961 - else if (ops->get_ts_info) 952 + /* Report the phc source only if we have a real 953 + * phc source with an index. 954 + */ 955 + if (!err && info->phc_index >= 0) { 956 + info->phc_source = HWTSTAMP_SOURCE_PHYLIB; 957 + info->phc_phyindex = phydev->phyindex; 958 + } 959 + } else if (ops->get_ts_info) { 962 960 err = ops->get_ts_info(dev, info); 961 + if (!err && info->phc_index >= 0) 962 + info->phc_source = HWTSTAMP_SOURCE_NETDEV; 963 + } 963 964 964 965 info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE | 965 966 SOF_TIMESTAMPING_SOFTWARE;
+23
net/ethtool/tsinfo.c
··· 160 160 /* _TSINFO_HWTSTAMP_PROVIDER */ 161 161 len += nla_total_size(0) + 2 * nla_total_size(sizeof(u32)); 162 162 } 163 + if (ts_info->phc_source) { 164 + len += nla_total_size(sizeof(u32)); /* _TSINFO_HWTSTAMP_SOURCE */ 165 + if (ts_info->phc_phyindex) 166 + /* _TSINFO_HWTSTAMP_PHYINDEX */ 167 + len += nla_total_size(sizeof(u32)); 168 + } 163 169 if (req_base->flags & ETHTOOL_FLAG_STATS) 164 170 len += nla_total_size(0) + /* _TSINFO_STATS */ 165 171 nla_total_size_64bit(sizeof(u64)) * ETHTOOL_TS_STAT_CNT; ··· 265 259 266 260 nla_nest_end(skb, nest); 267 261 } 262 + if (ts_info->phc_source) { 263 + if (nla_put_u32(skb, ETHTOOL_A_TSINFO_HWTSTAMP_SOURCE, 264 + ts_info->phc_source)) 265 + return -EMSGSIZE; 266 + 267 + if (ts_info->phc_phyindex && 268 + nla_put_u32(skb, ETHTOOL_A_TSINFO_HWTSTAMP_PHYINDEX, 269 + ts_info->phc_phyindex)) 270 + return -EMSGSIZE; 271 + } 268 272 if (req_base->flags & ETHTOOL_FLAG_STATS && 269 273 tsinfo_put_stats(skb, &data->stats)) 270 274 return -EMSGSIZE; ··· 362 346 if (ret < 0) 363 347 goto err; 364 348 349 + if (reply_data->ts_info.phc_index >= 0) { 350 + reply_data->ts_info.phc_source = HWTSTAMP_SOURCE_PHYLIB; 351 + reply_data->ts_info.phc_phyindex = phydev->phyindex; 352 + } 353 + 365 354 ret = ethnl_tsinfo_end_dump(skb, dev, req_info, reply_data, ehdr); 366 355 if (ret < 0) 367 356 goto err; ··· 410 389 if (ret < 0) 411 390 goto err; 412 391 392 + if (reply_data->ts_info.phc_index >= 0) 393 + reply_data->ts_info.phc_source = HWTSTAMP_SOURCE_NETDEV; 413 394 ret = ethnl_tsinfo_end_dump(skb, dev, req_info, reply_data, 414 395 ehdr); 415 396 if (ret < 0)