History

net: ethtool: Add a command to expose current time stamping layer

Time stamping on network packets may happen either in the MAC or in the PHY, but not both. In preparation for making the choice selectable, expose both the current layers via ethtool. In accordance with the kernel implementation as it stands, the current layer will always read as "phy" when a PHY time stamping device is present. Future patches will allow changing the current layer administratively.

Kory Maincent committed 3 years ago

Commit 11d55be1 parent acec05f8 files · +149 −1Browse files

Unified · Split

8 files
  1. Documentation/networking/ethtool-netlink.rst +23 −0
  2. include/uapi/linux/ethtool_netlink.h +14 −0
  3. include/uapi/linux/net_tstamp.h +10 −0
  4. net/ethtool/Makefile +1 −1
  5. net/ethtool/common.h +1 −0
  6. net/ethtool/netlink.c +10 −0
  7. net/ethtool/netlink.h +2 −0
  8. net/ethtool/ts.c +88 −0
Documentation/networking/ethtool-netlink.rst+23−0
@@ -225,6 +225,7 @@ Userspace to kernel: · 224 unmodified lines
225 ``ETHTOOL_MSG_RSS_GET`` get RSS settings225 ``ETHTOOL_MSG_RSS_GET`` get RSS settings
226 ``ETHTOOL_MSG_MM_GET`` get MAC merge layer state226 ``ETHTOOL_MSG_MM_GET`` get MAC merge layer state
227 ``ETHTOOL_MSG_MM_SET`` set MAC merge layer parameters227 ``ETHTOOL_MSG_MM_SET`` set MAC merge layer parameters
228 ``ETHTOOL_MSG_TS_GET`` get current timestamping
228 ===================================== =================================229 ===================================== =================================
229 230
230Kernel to userspace:231Kernel to userspace:
@@ -268,6 +269,7 @@ Kernel to userspace: · 37 unmodified lines
268 ``ETHTOOL_MSG_PSE_GET_REPLY`` PSE parameters269 ``ETHTOOL_MSG_PSE_GET_REPLY`` PSE parameters
269 ``ETHTOOL_MSG_RSS_GET_REPLY`` RSS settings270 ``ETHTOOL_MSG_RSS_GET_REPLY`` RSS settings
270 ``ETHTOOL_MSG_MM_GET_REPLY`` MAC merge layer status271 ``ETHTOOL_MSG_MM_GET_REPLY`` MAC merge layer status
272 ``ETHTOOL_MSG_TS_GET_REPLY`` current timestamping
271 ======================================== =================================273 ======================================== =================================
272 274
273``GET`` requests are sent by userspace applications to retrieve device275``GET`` requests are sent by userspace applications to retrieve device
@@ -1994,6 +1996,26 @@ The attributes are propagated to the driver through the following structure: · 1720 unmodified lines
1994.. kernel-doc:: include/linux/ethtool.h1996.. kernel-doc:: include/linux/ethtool.h
1995 :identifiers: ethtool_mm_cfg1997 :identifiers: ethtool_mm_cfg
1996 1998
1999TS_GET
2000======
2001
2002Gets current timestamping.
2003
2004Request contents:
2005
2006 ================================= ====== ====================
2007 ``ETHTOOL_A_TS_HEADER`` nested request header
2008 ================================= ====== ====================
2009
2010Kernel response contents:
2011
2012 ======================= ====== ==============================
2013 ``ETHTOOL_A_TS_HEADER`` nested reply header
2014 ``ETHTOOL_A_TS_LAYER`` u32 current timestamping
2015 ======================= ====== ==============================
2016
2017This command get the current timestamp layer.
2018
1997Request translation2019Request translation
1998===================2020===================
1999 2021
@@ -2100,4 +2122,5 @@ are netlink only. · 100 unmodified lines
2100 n/a ``ETHTOOL_MSG_PLCA_GET_STATUS``2122 n/a ``ETHTOOL_MSG_PLCA_GET_STATUS``
2101 n/a ``ETHTOOL_MSG_MM_GET``2123 n/a ``ETHTOOL_MSG_MM_GET``
2102 n/a ``ETHTOOL_MSG_MM_SET``2124 n/a ``ETHTOOL_MSG_MM_SET``
2125 n/a ``ETHTOOL_MSG_TS_GET``
2103 =================================== =====================================2126 =================================== =====================================
include/uapi/linux/ethtool_netlink.h+14−0
@@ -57,6 +57,7 @@ enum { · 56 unmodified lines
57 ETHTOOL_MSG_PLCA_GET_STATUS,57 ETHTOOL_MSG_PLCA_GET_STATUS,
58 ETHTOOL_MSG_MM_GET,58 ETHTOOL_MSG_MM_GET,
59 ETHTOOL_MSG_MM_SET,59 ETHTOOL_MSG_MM_SET,
60 ETHTOOL_MSG_TS_GET,
60 61
61 /* add new constants above here */62 /* add new constants above here */
62 __ETHTOOL_MSG_USER_CNT,63 __ETHTOOL_MSG_USER_CNT,
@@ -109,6 +110,7 @@ enum { · 46 unmodified lines
109 ETHTOOL_MSG_PLCA_NTF,110 ETHTOOL_MSG_PLCA_NTF,
110 ETHTOOL_MSG_MM_GET_REPLY,111 ETHTOOL_MSG_MM_GET_REPLY,
111 ETHTOOL_MSG_MM_NTF,112 ETHTOOL_MSG_MM_NTF,
113 ETHTOOL_MSG_TS_GET_REPLY,
112 114
113 /* add new constants above here */115 /* add new constants above here */
114 __ETHTOOL_MSG_KERNEL_CNT,116 __ETHTOOL_MSG_KERNEL_CNT,
@@ -975,6 +977,18 @@ enum { · 860 unmodified lines
975 ETHTOOL_A_MM_MAX = (__ETHTOOL_A_MM_CNT - 1)977 ETHTOOL_A_MM_MAX = (__ETHTOOL_A_MM_CNT - 1)
976};978};
977 979
980/* TS LAYER */
981
982enum {
983 ETHTOOL_A_TS_UNSPEC,
984 ETHTOOL_A_TS_HEADER, /* nest - _A_HEADER_* */
985 ETHTOOL_A_TS_LAYER, /* u32 */
986
987 /* add new constants above here */
988 __ETHTOOL_A_TS_CNT,
989 ETHTOOL_A_TS_MAX = (__ETHTOOL_A_TS_CNT - 1)
990};
991
978/* generic netlink info */992/* generic netlink info */
979#define ETHTOOL_GENL_NAME "ethtool"993#define ETHTOOL_GENL_NAME "ethtool"
980#define ETHTOOL_GENL_VERSION 1994#define ETHTOOL_GENL_VERSION 1
include/uapi/linux/net_tstamp.h+10−0
@@ -13,6 +13,16 @@ · 12 unmodified lines
13#include <linux/types.h>13#include <linux/types.h>
14#include <linux/socket.h> /* for SO_TIMESTAMPING */14#include <linux/socket.h> /* for SO_TIMESTAMPING */
15 15
16/* Layer of the TIMESTAMPING provider */
17enum timestamping_layer {
18 NO_TIMESTAMPING,
19 SOFTWARE_TIMESTAMPING,
20 MAC_TIMESTAMPING,
21 PHY_TIMESTAMPING,
22
23 __TIMESTAMPING_COUNT,
24};
25
16/* SO_TIMESTAMPING flags */26/* SO_TIMESTAMPING flags */
17enum {27enum {
18 SOF_TIMESTAMPING_TX_HARDWARE = (1<<0),28 SOF_TIMESTAMPING_TX_HARDWARE = (1<<0),
net/ethtool/Makefile+1−1
@@ -8,4 +8,4 @@ ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o rss.o \ · 7 unmodified lines
8 linkstate.o debug.o wol.o features.o privflags.o rings.o \8 linkstate.o debug.o wol.o features.o privflags.o rings.o \
9 channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \9 channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \
10 tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \10 tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \
11 module.o pse-pd.o plca.o mm.o11 module.o pse-pd.o plca.o mm.o ts.o
net/ethtool/common.h+1−0
@@ -35,6 +35,7 @@ extern const char wol_mode_names[][ETH_GSTRING_LEN]; · 34 unmodified lines
35extern const char sof_timestamping_names[][ETH_GSTRING_LEN];35extern const char sof_timestamping_names[][ETH_GSTRING_LEN];
36extern const char ts_tx_type_names[][ETH_GSTRING_LEN];36extern const char ts_tx_type_names[][ETH_GSTRING_LEN];
37extern const char ts_rx_filter_names[][ETH_GSTRING_LEN];37extern const char ts_rx_filter_names[][ETH_GSTRING_LEN];
38extern const char ts_layer_names[][ETH_GSTRING_LEN];
38extern const char udp_tunnel_type_names[][ETH_GSTRING_LEN];39extern const char udp_tunnel_type_names[][ETH_GSTRING_LEN];
39 40
40int __ethtool_get_link(struct net_device *dev);41int __ethtool_get_link(struct net_device *dev);
net/ethtool/netlink.c+10−0
@@ -306,6 +306,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { · 305 unmodified lines
306 [ETHTOOL_MSG_PLCA_GET_STATUS] = &ethnl_plca_status_request_ops,306 [ETHTOOL_MSG_PLCA_GET_STATUS] = &ethnl_plca_status_request_ops,
307 [ETHTOOL_MSG_MM_GET] = &ethnl_mm_request_ops,307 [ETHTOOL_MSG_MM_GET] = &ethnl_mm_request_ops,
308 [ETHTOOL_MSG_MM_SET] = &ethnl_mm_request_ops,308 [ETHTOOL_MSG_MM_SET] = &ethnl_mm_request_ops,
309 [ETHTOOL_MSG_TS_GET] = &ethnl_ts_request_ops,
309};310};
310 311
311static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)312static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
@@ -1128,6 +1129,15 @@ static const struct genl_ops ethtool_genl_ops[] = { · 816 unmodified lines
1128 .policy = ethnl_mm_set_policy,1129 .policy = ethnl_mm_set_policy,
1129 .maxattr = ARRAY_SIZE(ethnl_mm_set_policy) - 1,1130 .maxattr = ARRAY_SIZE(ethnl_mm_set_policy) - 1,
1130 },1131 },
1132 {
1133 .cmd = ETHTOOL_MSG_TS_GET,
1134 .doit = ethnl_default_doit,
1135 .start = ethnl_default_start,
1136 .dumpit = ethnl_default_dumpit,
1137 .done = ethnl_default_done,
1138 .policy = ethnl_ts_get_policy,
1139 .maxattr = ARRAY_SIZE(ethnl_ts_get_policy) - 1,
1140 },
1131};1141};
1132 1142
1133static const struct genl_multicast_group ethtool_nl_mcgrps[] = {1143static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/netlink.h+2−0
@@ -395,6 +395,7 @@ extern const struct ethnl_request_ops ethnl_rss_request_ops; · 394 unmodified lines
395extern const struct ethnl_request_ops ethnl_plca_cfg_request_ops;395extern const struct ethnl_request_ops ethnl_plca_cfg_request_ops;
396extern const struct ethnl_request_ops ethnl_plca_status_request_ops;396extern const struct ethnl_request_ops ethnl_plca_status_request_ops;
397extern const struct ethnl_request_ops ethnl_mm_request_ops;397extern const struct ethnl_request_ops ethnl_mm_request_ops;
398extern const struct ethnl_request_ops ethnl_ts_request_ops;
398 399
399extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1];400extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1];
400extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1];401extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1];
@@ -441,6 +442,7 @@ extern const struct nla_policy ethnl_plca_set_cfg_policy[ETHTOOL_A_PLCA_MAX + 1] · 40 unmodified lines
441extern const struct nla_policy ethnl_plca_get_status_policy[ETHTOOL_A_PLCA_HEADER + 1];442extern const struct nla_policy ethnl_plca_get_status_policy[ETHTOOL_A_PLCA_HEADER + 1];
442extern const struct nla_policy ethnl_mm_get_policy[ETHTOOL_A_MM_HEADER + 1];443extern const struct nla_policy ethnl_mm_get_policy[ETHTOOL_A_MM_HEADER + 1];
443extern const struct nla_policy ethnl_mm_set_policy[ETHTOOL_A_MM_MAX + 1];444extern const struct nla_policy ethnl_mm_set_policy[ETHTOOL_A_MM_MAX + 1];
445extern const struct nla_policy ethnl_ts_get_policy[ETHTOOL_A_TS_HEADER + 1];
444 446
445int ethnl_set_features(struct sk_buff *skb, struct genl_info *info);447int ethnl_set_features(struct sk_buff *skb, struct genl_info *info);
446int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info);448int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info);
net/ethtool/ts.c+88−0
@@ -0,0 +1,88 @@
1// SPDX-License-Identifier: GPL-2.0-only
2
3#include <linux/net_tstamp.h>
4#include <linux/phy.h>
5
6#include "netlink.h"
7#include "common.h"
8#include "bitset.h"
9
10struct ts_req_info {
11 struct ethnl_req_info base;
12};
13
14struct ts_reply_data {
15 struct ethnl_reply_data base;
16 enum timestamping_layer ts_layer;
17};
18
19#define TS_REPDATA(__reply_base) \
20 container_of(__reply_base, struct ts_reply_data, base)
21
22/* TS_GET */
23const struct nla_policy ethnl_ts_get_policy[] = {
24 [ETHTOOL_A_TS_HEADER] =
25 NLA_POLICY_NESTED(ethnl_header_policy),
26};
27
28static int ts_prepare_data(const struct ethnl_req_info *req_base,
29 struct ethnl_reply_data *reply_base,
30 const struct genl_info *info)
31{
32 struct ts_reply_data *data = TS_REPDATA(reply_base);
33 struct net_device *dev = reply_base->dev;
34 const struct ethtool_ops *ops = dev->ethtool_ops;
35 int ret;
36
37 ret = ethnl_ops_begin(dev);
38 if (ret < 0)
39 return ret;
40
41 if (phy_has_tsinfo(dev->phydev)) {
42 data->ts_layer = PHY_TIMESTAMPING;
43 } else if (ops->get_ts_info) {
44 struct ethtool_ts_info ts_info = {0};
45
46 ops->get_ts_info(dev, &ts_info);
47 if (ts_info.so_timestamping &
48 SOF_TIMESTAMPING_HARDWARE_MASK)
49 data->ts_layer = MAC_TIMESTAMPING;
50
51 if (ts_info.so_timestamping &
52 SOF_TIMESTAMPING_SOFTWARE_MASK)
53 data->ts_layer = SOFTWARE_TIMESTAMPING;
54 } else {
55 data->ts_layer = NO_TIMESTAMPING;
56 }
57
58 ethnl_ops_complete(dev);
59
60 return ret;
61}
62
63static int ts_reply_size(const struct ethnl_req_info *req_base,
64 const struct ethnl_reply_data *reply_base)
65{
66 return nla_total_size(sizeof(u32));
67}
68
69static int ts_fill_reply(struct sk_buff *skb,
70 const struct ethnl_req_info *req_base,
71 const struct ethnl_reply_data *reply_base)
72{
73 struct ts_reply_data *data = TS_REPDATA(reply_base);
74
75 return nla_put_u32(skb, ETHTOOL_A_TS_LAYER, data->ts_layer);
76}
77
78const struct ethnl_request_ops ethnl_ts_request_ops = {
79 .request_cmd = ETHTOOL_MSG_TS_GET,
80 .reply_cmd = ETHTOOL_MSG_TS_GET_REPLY,
81 .hdr_attr = ETHTOOL_A_TS_HEADER,
82 .req_info_size = sizeof(struct ts_req_info),
83 .reply_data_size = sizeof(struct ts_reply_data),
84
85 .prepare_data = ts_prepare_data,
86 .reply_size = ts_reply_size,
87 .fill_reply = ts_fill_reply,
88};

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t