Skip to content

Commit 4ff4d86

Browse files
kmaincentPaolo Abeni
authored andcommitted
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 3da895b commit 4ff4d86

File tree

6 files changed

+94
-11
lines changed

6 files changed

+94
-11
lines changed

Documentation/netlink/specs/ethtool.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ definitions:
9898
name: tcp-data-split
9999
type: enum
100100
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
101119
102120
attribute-sets:
103121
-
@@ -896,6 +914,13 @@ attribute-sets:
896914
name: hwtstamp-provider
897915
type: nest
898916
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
899924
-
900925
name: cable-result
901926
attr-cnt-name: __ethtool-a-cable-result-cnt
@@ -1981,6 +2006,8 @@ operations:
19812006
- phc-index
19822007
- stats
19832008
- hwtstamp-provider
2009+
- hwtstamp-source
2010+
- hwtstamp-phyindex
19842011
dump: *tsinfo-get-op
19852012
-
19862013
name: cable-test-act

include/linux/ethtool.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/netlink.h>
2020
#include <linux/timer_types.h>
2121
#include <uapi/linux/ethtool.h>
22+
#include <uapi/linux/ethtool_netlink_generated.h>
2223
#include <uapi/linux/net_tstamp.h>
2324

2425
#define ETHTOOL_MM_MAX_VERIFY_TIME_MS 128
@@ -830,6 +831,8 @@ struct ethtool_rxfh_param {
830831
* @so_timestamping: bit mask of the sum of the supported SO_TIMESTAMPING flags
831832
* @phc_index: device index of the associated PHC, or -1 if there is none
832833
* @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
833836
* @tx_types: bit mask of the supported hwtstamp_tx_types enumeration values
834837
* @rx_filters: bit mask of the supported hwtstamp_rx_filters enumeration values
835838
*/
@@ -838,6 +841,8 @@ struct kernel_ethtool_ts_info {
838841
u32 so_timestamping;
839842
int phc_index;
840843
enum hwtstamp_provider_qualifier phc_qualifier;
844+
enum hwtstamp_source phc_source;
845+
int phc_phyindex;
841846
enum hwtstamp_tx_types tx_types;
842847
enum hwtstamp_rx_filters rx_filters;
843848
};

include/linux/net_tstamp.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#define _LINUX_NET_TIMESTAMPING_H_
55

66
#include <uapi/linux/net_tstamp.h>
7+
#include <uapi/linux/ethtool_netlink_generated.h>
78

89
#define SOF_TIMESTAMPING_SOFTWARE_MASK (SOF_TIMESTAMPING_RX_SOFTWARE | \
910
SOF_TIMESTAMPING_TX_SOFTWARE | \
@@ -13,12 +14,6 @@
1314
SOF_TIMESTAMPING_TX_HARDWARE | \
1415
SOF_TIMESTAMPING_RAW_HARDWARE)
1516

16-
enum hwtstamp_source {
17-
HWTSTAMP_SOURCE_UNSPEC,
18-
HWTSTAMP_SOURCE_NETDEV,
19-
HWTSTAMP_SOURCE_PHYLIB,
20-
};
21-
2217
/**
2318
* struct hwtstamp_provider_desc - hwtstamp provider description
2419
*

include/uapi/linux/ethtool_netlink_generated.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ enum ethtool_tcp_data_split {
3737
ETHTOOL_TCP_DATA_SPLIT_ENABLED,
3838
};
3939

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+
*/
47+
enum hwtstamp_source {
48+
HWTSTAMP_SOURCE_NETDEV = 1,
49+
HWTSTAMP_SOURCE_PHYLIB,
50+
};
51+
4052
enum {
4153
ETHTOOL_A_HEADER_UNSPEC,
4254
ETHTOOL_A_HEADER_DEV_INDEX,
@@ -401,6 +413,8 @@ enum {
401413
ETHTOOL_A_TSINFO_PHC_INDEX,
402414
ETHTOOL_A_TSINFO_STATS,
403415
ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER,
416+
ETHTOOL_A_TSINFO_HWTSTAMP_SOURCE,
417+
ETHTOOL_A_TSINFO_HWTSTAMP_PHYINDEX,
404418

405419
__ETHTOOL_A_TSINFO_CNT,
406420
ETHTOOL_A_TSINFO_MAX = (__ETHTOOL_A_TSINFO_CNT - 1)

net/ethtool/common.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -921,9 +921,18 @@ int ethtool_get_ts_info_by_phc(struct net_device *dev,
921921

922922
phy = ethtool_phy_get_ts_info_by_phc(dev, info, hwprov_desc);
923923
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;
927936
}
928937

929938
info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE |
@@ -947,10 +956,20 @@ int __ethtool_get_ts_info(struct net_device *dev,
947956

948957
ethtool_init_tsinfo(info);
949958
if (phy_is_default_hwtstamp(phydev) &&
950-
phy_has_tsinfo(phydev))
959+
phy_has_tsinfo(phydev)) {
951960
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) {
953969
err = ops->get_ts_info(dev, info);
970+
if (!err && info->phc_index >= 0)
971+
info->phc_source = HWTSTAMP_SOURCE_NETDEV;
972+
}
954973

955974
info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE |
956975
SOF_TIMESTAMPING_SOFTWARE;

net/ethtool/tsinfo.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ static int tsinfo_reply_size(const struct ethnl_req_info *req_base,
160160
/* _TSINFO_HWTSTAMP_PROVIDER */
161161
len += nla_total_size(0) + 2 * nla_total_size(sizeof(u32));
162162
}
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+
}
163169
if (req_base->flags & ETHTOOL_FLAG_STATS)
164170
len += nla_total_size(0) + /* _TSINFO_STATS */
165171
nla_total_size_64bit(sizeof(u64)) * ETHTOOL_TS_STAT_CNT;
@@ -259,6 +265,16 @@ static int tsinfo_fill_reply(struct sk_buff *skb,
259265

260266
nla_nest_end(skb, nest);
261267
}
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+
}
262278
if (req_base->flags & ETHTOOL_FLAG_STATS &&
263279
tsinfo_put_stats(skb, &data->stats))
264280
return -EMSGSIZE;
@@ -346,6 +362,11 @@ static int ethnl_tsinfo_dump_one_phydev(struct sk_buff *skb,
346362
if (ret < 0)
347363
goto err;
348364

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+
349370
ret = ethnl_tsinfo_end_dump(skb, dev, req_info, reply_data, ehdr);
350371
if (ret < 0)
351372
goto err;
@@ -389,6 +410,8 @@ static int ethnl_tsinfo_dump_one_netdev(struct sk_buff *skb,
389410
if (ret < 0)
390411
goto err;
391412

413+
if (reply_data->ts_info.phc_index >= 0)
414+
reply_data->ts_info.phc_source = HWTSTAMP_SOURCE_NETDEV;
392415
ret = ethnl_tsinfo_end_dump(skb, dev, req_info, reply_data,
393416
ehdr);
394417
if (ret < 0)

0 commit comments

Comments
 (0)