History

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.

Kory Maincent committed 1 year ago

Commit 4ff4d861 parent 3da895b6 files · +94 −11Browse files

Unified · Split

6 files
  1. Documentation/netlink/specs/ethtool.yaml +27 −0
  2. include/linux/ethtool.h +5 −0
  3. include/linux/net_tstamp.h +1 −6
  4. include/uapi/linux/ethtool_netlink_generated.h +14 −0
  5. net/ethtool/common.c +24 −5
  6. net/ethtool/tsinfo.c +23 −0
Documentation/netlink/specs/ethtool.yaml+27−0
@@ -98,6 +98,24 @@ definitions: · 97 unmodified lines
98 name: tcp-data-split98 name: tcp-data-split
99 type: enum99 type: enum
100 entries: [ unknown, disabled, enabled ]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
102attribute-sets:120attribute-sets:
103 -121 -
@@ -896,6 +914,13 @@ attribute-sets: · 792 unmodified lines
896 name: hwtstamp-provider914 name: hwtstamp-provider
897 type: nest915 type: nest
898 nested-attributes: ts-hwtstamp-provider916 nested-attributes: ts-hwtstamp-provider
917 -
918 name: hwtstamp-source
919 type: u32
920 enum: hwtstamp-source
921 -
922 name: hwtstamp-phyindex
923 type: u32
899 -924 -
900 name: cable-result925 name: cable-result
901 attr-cnt-name: __ethtool-a-cable-result-cnt926 attr-cnt-name: __ethtool-a-cable-result-cnt
@@ -1981,6 +2006,8 @@ operations: · 1079 unmodified lines
1981 - phc-index2006 - phc-index
1982 - stats2007 - stats
1983 - hwtstamp-provider2008 - hwtstamp-provider
2009 - hwtstamp-source
2010 - hwtstamp-phyindex
1984 dump: *tsinfo-get-op2011 dump: *tsinfo-get-op
1985 -2012 -
1986 name: cable-test-act2013 name: cable-test-act
include/linux/ethtool.h+5−0
@@ -19,6 +19,7 @@ · 18 unmodified lines
19#include <linux/netlink.h>19#include <linux/netlink.h>
20#include <linux/timer_types.h>20#include <linux/timer_types.h>
21#include <uapi/linux/ethtool.h>21#include <uapi/linux/ethtool.h>
22#include <uapi/linux/ethtool_netlink_generated.h>
22#include <uapi/linux/net_tstamp.h>23#include <uapi/linux/net_tstamp.h>
23 24
24#define ETHTOOL_MM_MAX_VERIFY_TIME_MS 12825#define ETHTOOL_MM_MAX_VERIFY_TIME_MS 128
@@ -830,6 +831,8 @@ struct ethtool_rxfh_param { · 805 unmodified lines
830 * @so_timestamping: bit mask of the sum of the supported SO_TIMESTAMPING flags831 * @so_timestamping: bit mask of the sum of the supported SO_TIMESTAMPING flags
831 * @phc_index: device index of the associated PHC, or -1 if there is none832 * @phc_index: device index of the associated PHC, or -1 if there is none
832 * @phc_qualifier: qualifier of the associated PHC833 * @phc_qualifier: qualifier of the associated PHC
834 * @phc_source: source device of the associated PHC
835 * @phc_phyindex: index of PHY device source of the associated PHC
833 * @tx_types: bit mask of the supported hwtstamp_tx_types enumeration values836 * @tx_types: bit mask of the supported hwtstamp_tx_types enumeration values
834 * @rx_filters: bit mask of the supported hwtstamp_rx_filters enumeration values837 * @rx_filters: bit mask of the supported hwtstamp_rx_filters enumeration values
835 */838 */
@@ -838,6 +841,8 @@ struct kernel_ethtool_ts_info { · 2 unmodified lines
838 u32 so_timestamping;841 u32 so_timestamping;
839 int phc_index;842 int phc_index;
840 enum hwtstamp_provider_qualifier phc_qualifier;843 enum hwtstamp_provider_qualifier phc_qualifier;
844 enum hwtstamp_source phc_source;
845 int phc_phyindex;
841 enum hwtstamp_tx_types tx_types;846 enum hwtstamp_tx_types tx_types;
842 enum hwtstamp_rx_filters rx_filters;847 enum hwtstamp_rx_filters rx_filters;
843};848};
include/linux/net_tstamp.h+1−6
@@ -4,6 +4,7 @@ · 3 unmodified lines
4#define _LINUX_NET_TIMESTAMPING_H_4#define _LINUX_NET_TIMESTAMPING_H_
5 5
6#include <uapi/linux/net_tstamp.h>6#include <uapi/linux/net_tstamp.h>
7#include <uapi/linux/ethtool_netlink_generated.h>
7 8
8#define SOF_TIMESTAMPING_SOFTWARE_MASK (SOF_TIMESTAMPING_RX_SOFTWARE | \9#define SOF_TIMESTAMPING_SOFTWARE_MASK (SOF_TIMESTAMPING_RX_SOFTWARE | \
9 SOF_TIMESTAMPING_TX_SOFTWARE | \10 SOF_TIMESTAMPING_TX_SOFTWARE | \
@@ -13,12 +14,6 @@ · 3 unmodified lines
13 SOF_TIMESTAMPING_TX_HARDWARE | \14 SOF_TIMESTAMPING_TX_HARDWARE | \
14 SOF_TIMESTAMPING_RAW_HARDWARE)15 SOF_TIMESTAMPING_RAW_HARDWARE)
15 16
16enum hwtstamp_source {
17 HWTSTAMP_SOURCE_UNSPEC,
18 HWTSTAMP_SOURCE_NETDEV,
19 HWTSTAMP_SOURCE_PHYLIB,
20};
21
22/**17/**
23 * struct hwtstamp_provider_desc - hwtstamp provider description18 * struct hwtstamp_provider_desc - hwtstamp provider description
24 *19 *
include/uapi/linux/ethtool_netlink_generated.h+14−0
@@ -37,6 +37,18 @@ enum ethtool_tcp_data_split { · 36 unmodified lines
37 ETHTOOL_TCP_DATA_SPLIT_ENABLED,37 ETHTOOL_TCP_DATA_SPLIT_ENABLED,
38};38};
39 39
40/**
41 * enum hwtstamp_source - Source of the hardware timestamp
42 * @HWTSTAMP_SOURCE_NETDEV: Hardware timestamp comes from a MAC or a device
43 * which has MAC and PHY integrated
44 * @HWTSTAMP_SOURCE_PHYLIB: Hardware timestamp comes from one PHY device of the
45 * network topology
46 */
47enum hwtstamp_source {
48 HWTSTAMP_SOURCE_NETDEV = 1,
49 HWTSTAMP_SOURCE_PHYLIB,
50};
51
40enum {52enum {
41 ETHTOOL_A_HEADER_UNSPEC,53 ETHTOOL_A_HEADER_UNSPEC,
42 ETHTOOL_A_HEADER_DEV_INDEX,54 ETHTOOL_A_HEADER_DEV_INDEX,
@@ -401,6 +413,8 @@ enum { · 358 unmodified lines
401 ETHTOOL_A_TSINFO_PHC_INDEX,413 ETHTOOL_A_TSINFO_PHC_INDEX,
402 ETHTOOL_A_TSINFO_STATS,414 ETHTOOL_A_TSINFO_STATS,
403 ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER,415 ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER,
416 ETHTOOL_A_TSINFO_HWTSTAMP_SOURCE,
417 ETHTOOL_A_TSINFO_HWTSTAMP_PHYINDEX,
404 418
405 __ETHTOOL_A_TSINFO_CNT,419 __ETHTOOL_A_TSINFO_CNT,
406 ETHTOOL_A_TSINFO_MAX = (__ETHTOOL_A_TSINFO_CNT - 1)420 ETHTOOL_A_TSINFO_MAX = (__ETHTOOL_A_TSINFO_CNT - 1)
net/ethtool/common.c+24−5
@@ -921,9 +921,18 @@ int ethtool_get_ts_info_by_phc(struct net_device *dev, · 920 unmodified lines
921 921
922 phy = ethtool_phy_get_ts_info_by_phc(dev, info, hwprov_desc);922 phy = ethtool_phy_get_ts_info_by_phc(dev, info, hwprov_desc);
923 if (IS_ERR(phy))923 if (IS_ERR(phy))
924 err = PTR_ERR(phy);924 return PTR_ERR(phy);
925 else925
926 err = 0;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 info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE |938 info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE |
@@ -947,10 +956,20 @@ int __ethtool_get_ts_info(struct net_device *dev, · 17 unmodified lines
947 956
948 ethtool_init_tsinfo(info);957 ethtool_init_tsinfo(info);
949 if (phy_is_default_hwtstamp(phydev) &&958 if (phy_is_default_hwtstamp(phydev) &&
950 phy_has_tsinfo(phydev))959 phy_has_tsinfo(phydev)) {
951 err = phy_ts_info(phydev, info);960 err = phy_ts_info(phydev, info);
952 else if (ops->get_ts_info)961 /* Report the phc source only if we have a real
962 * phc source with an index.
963 */
964 if (!err && info->phc_index >= 0) {
965 info->phc_source = HWTSTAMP_SOURCE_PHYLIB;
966 info->phc_phyindex = phydev->phyindex;
967 }
968 } else if (ops->get_ts_info) {
953 err = ops->get_ts_info(dev, info);969 err = ops->get_ts_info(dev, info);
970 if (!err && info->phc_index >= 0)
971 info->phc_source = HWTSTAMP_SOURCE_NETDEV;
972 }
954 973
955 info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE |974 info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE |
956 SOF_TIMESTAMPING_SOFTWARE;975 SOF_TIMESTAMPING_SOFTWARE;
net/ethtool/tsinfo.c+23−0
@@ -160,6 +160,12 @@ static int tsinfo_reply_size(const struct ethnl_req_info *req_base, · 159 unmodified lines
160 /* _TSINFO_HWTSTAMP_PROVIDER */160 /* _TSINFO_HWTSTAMP_PROVIDER */
161 len += nla_total_size(0) + 2 * nla_total_size(sizeof(u32));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 if (req_base->flags & ETHTOOL_FLAG_STATS)169 if (req_base->flags & ETHTOOL_FLAG_STATS)
164 len += nla_total_size(0) + /* _TSINFO_STATS */170 len += nla_total_size(0) + /* _TSINFO_STATS */
165 nla_total_size_64bit(sizeof(u64)) * ETHTOOL_TS_STAT_CNT;171 nla_total_size_64bit(sizeof(u64)) * ETHTOOL_TS_STAT_CNT;
@@ -259,6 +265,16 @@ static int tsinfo_fill_reply(struct sk_buff *skb, · 93 unmodified lines
259 265
260 nla_nest_end(skb, nest);266 nla_nest_end(skb, nest);
261 }267 }
268 if (ts_info->phc_source) {
269 if (nla_put_u32(skb, ETHTOOL_A_TSINFO_HWTSTAMP_SOURCE,
270 ts_info->phc_source))
271 return -EMSGSIZE;
272
273 if (ts_info->phc_phyindex &&
274 nla_put_u32(skb, ETHTOOL_A_TSINFO_HWTSTAMP_PHYINDEX,
275 ts_info->phc_phyindex))
276 return -EMSGSIZE;
277 }
262 if (req_base->flags & ETHTOOL_FLAG_STATS &&278 if (req_base->flags & ETHTOOL_FLAG_STATS &&
263 tsinfo_put_stats(skb, &data->stats))279 tsinfo_put_stats(skb, &data->stats))
264 return -EMSGSIZE;280 return -EMSGSIZE;
@@ -346,6 +362,11 @@ static int ethnl_tsinfo_dump_one_phydev(struct sk_buff *skb, · 81 unmodified lines
346 if (ret < 0)362 if (ret < 0)
347 goto err;363 goto err;
348 364
365 if (reply_data->ts_info.phc_index >= 0) {
366 reply_data->ts_info.phc_source = HWTSTAMP_SOURCE_PHYLIB;
367 reply_data->ts_info.phc_phyindex = phydev->phyindex;
368 }
369
349 ret = ethnl_tsinfo_end_dump(skb, dev, req_info, reply_data, ehdr);370 ret = ethnl_tsinfo_end_dump(skb, dev, req_info, reply_data, ehdr);
350 if (ret < 0)371 if (ret < 0)
351 goto err;372 goto err;
@@ -389,6 +410,8 @@ static int ethnl_tsinfo_dump_one_netdev(struct sk_buff *skb, · 37 unmodified lines
389 if (ret < 0)410 if (ret < 0)
390 goto err;411 goto err;
391 412
413 if (reply_data->ts_info.phc_index >= 0)
414 reply_data->ts_info.phc_source = HWTSTAMP_SOURCE_NETDEV;
392 ret = ethnl_tsinfo_end_dump(skb, dev, req_info, reply_data,415 ret = ethnl_tsinfo_end_dump(skb, dev, req_info, reply_data,
393 ehdr);416 ehdr);
394 if (ret < 0)417 if (ret < 0)