Skip to content

Commit d905f9c

Browse files
kmaincentdavem330
authored andcommitted
net: ethtool: Add a command to list available time stamping layers
Introduce a new netlink message that lists all available time stamping layers on a given interface. Signed-off-by: Kory Maincent <kory.maincent@bootlin.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent bb8645b commit d905f9c

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

Documentation/networking/ethtool-netlink.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ Userspace to kernel:
226226
``ETHTOOL_MSG_MM_GET`` get MAC merge layer state
227227
``ETHTOOL_MSG_MM_SET`` set MAC merge layer parameters
228228
``ETHTOOL_MSG_TS_GET`` get current timestamping
229+
``ETHTOOL_MSG_TS_LIST_GET`` list available timestampings
229230
===================================== =================================
230231

231232
Kernel to userspace:
@@ -270,6 +271,7 @@ Kernel to userspace:
270271
``ETHTOOL_MSG_RSS_GET_REPLY`` RSS settings
271272
``ETHTOOL_MSG_MM_GET_REPLY`` MAC merge layer status
272273
``ETHTOOL_MSG_TS_GET_REPLY`` current timestamping
274+
``ETHTOOL_MSG_TS_LIST_GET_REPLY`` available timestampings
273275
======================================== =================================
274276

275277
``GET`` requests are sent by userspace applications to retrieve device
@@ -2016,6 +2018,26 @@ Kernel response contents:
20162018

20172019
This command get the current timestamp layer.
20182020

2021+
TS_LIST_GET
2022+
===========
2023+
2024+
Get the list of available timestampings.
2025+
2026+
Request contents:
2027+
2028+
================================= ====== ====================
2029+
``ETHTOOL_A_TS_HEADER`` nested request header
2030+
================================= ====== ====================
2031+
2032+
Kernel response contents:
2033+
2034+
=========================== ====== ==============================
2035+
``ETHTOOL_A_TS_HEADER`` nested reply header
2036+
``ETHTOOL_A_TS_LIST_LAYER`` binary available timestampings
2037+
=========================== ====== ==============================
2038+
2039+
This command lists all the possible timestamp layer available.
2040+
20192041
Request translation
20202042
===================
20212043

@@ -2123,4 +2145,5 @@ are netlink only.
21232145
n/a ``ETHTOOL_MSG_MM_GET``
21242146
n/a ``ETHTOOL_MSG_MM_SET``
21252147
n/a ``ETHTOOL_MSG_TS_GET``
2148+
n/a ``ETHTOOL_MSG_TS_LIST_GET``
21262149
=================================== =====================================

include/uapi/linux/ethtool_netlink.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ enum {
5858
ETHTOOL_MSG_MM_GET,
5959
ETHTOOL_MSG_MM_SET,
6060
ETHTOOL_MSG_TS_GET,
61+
ETHTOOL_MSG_TS_LIST_GET,
6162

6263
/* add new constants above here */
6364
__ETHTOOL_MSG_USER_CNT,
@@ -111,6 +112,7 @@ enum {
111112
ETHTOOL_MSG_MM_GET_REPLY,
112113
ETHTOOL_MSG_MM_NTF,
113114
ETHTOOL_MSG_TS_GET_REPLY,
115+
ETHTOOL_MSG_TS_LIST_GET_REPLY,
114116

115117
/* add new constants above here */
116118
__ETHTOOL_MSG_KERNEL_CNT,
@@ -989,6 +991,18 @@ enum {
989991
ETHTOOL_A_TS_MAX = (__ETHTOOL_A_TS_CNT - 1)
990992
};
991993

994+
/* TS LIST LAYER */
995+
996+
enum {
997+
ETHTOOL_A_TS_LIST_UNSPEC,
998+
ETHTOOL_A_TS_LIST_HEADER, /* nest - _A_HEADER_* */
999+
ETHTOOL_A_TS_LIST_LAYER, /* array, u32 */
1000+
1001+
/* add new constants above here */
1002+
__ETHTOOL_A_TS_LIST_CNT,
1003+
ETHTOOL_A_TS_LIST_MAX = (__ETHTOOL_A_TS_LIST_CNT - 1)
1004+
};
1005+
9921006
/* generic netlink info */
9931007
#define ETHTOOL_GENL_NAME "ethtool"
9941008
#define ETHTOOL_GENL_VERSION 1

net/ethtool/netlink.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
307307
[ETHTOOL_MSG_MM_GET] = &ethnl_mm_request_ops,
308308
[ETHTOOL_MSG_MM_SET] = &ethnl_mm_request_ops,
309309
[ETHTOOL_MSG_TS_GET] = &ethnl_ts_request_ops,
310+
[ETHTOOL_MSG_TS_LIST_GET] = &ethnl_ts_list_request_ops,
310311
};
311312

312313
static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
@@ -1138,6 +1139,15 @@ static const struct genl_ops ethtool_genl_ops[] = {
11381139
.policy = ethnl_ts_get_policy,
11391140
.maxattr = ARRAY_SIZE(ethnl_ts_get_policy) - 1,
11401141
},
1142+
{
1143+
.cmd = ETHTOOL_MSG_TS_LIST_GET,
1144+
.doit = ethnl_default_doit,
1145+
.start = ethnl_default_start,
1146+
.dumpit = ethnl_default_dumpit,
1147+
.done = ethnl_default_done,
1148+
.policy = ethnl_ts_get_policy,
1149+
.maxattr = ARRAY_SIZE(ethnl_ts_get_policy) - 1,
1150+
},
11411151
};
11421152

11431153
static const struct genl_multicast_group ethtool_nl_mcgrps[] = {

net/ethtool/netlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ extern const struct ethnl_request_ops ethnl_plca_cfg_request_ops;
396396
extern const struct ethnl_request_ops ethnl_plca_status_request_ops;
397397
extern const struct ethnl_request_ops ethnl_mm_request_ops;
398398
extern const struct ethnl_request_ops ethnl_ts_request_ops;
399+
extern const struct ethnl_request_ops ethnl_ts_list_request_ops;
399400

400401
extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1];
401402
extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1];

net/ethtool/ts.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,76 @@ const struct ethnl_request_ops ethnl_ts_request_ops = {
8686
.reply_size = ts_reply_size,
8787
.fill_reply = ts_fill_reply,
8888
};
89+
90+
/* TS_LIST_GET */
91+
struct ts_list_reply_data {
92+
struct ethnl_reply_data base;
93+
enum timestamping_layer ts_layer[__TIMESTAMPING_COUNT];
94+
u8 num_ts;
95+
};
96+
97+
#define TS_LIST_REPDATA(__reply_base) \
98+
container_of(__reply_base, struct ts_list_reply_data, base)
99+
100+
static int ts_list_prepare_data(const struct ethnl_req_info *req_base,
101+
struct ethnl_reply_data *reply_base,
102+
const struct genl_info *info)
103+
{
104+
struct ts_list_reply_data *data = TS_LIST_REPDATA(reply_base);
105+
struct net_device *dev = reply_base->dev;
106+
const struct ethtool_ops *ops = dev->ethtool_ops;
107+
int ret, i = 0;
108+
109+
ret = ethnl_ops_begin(dev);
110+
if (ret < 0)
111+
return ret;
112+
113+
if (phy_has_tsinfo(dev->phydev))
114+
data->ts_layer[i++] = PHY_TIMESTAMPING;
115+
if (ops->get_ts_info) {
116+
struct ethtool_ts_info ts_info = {0};
117+
118+
ops->get_ts_info(dev, &ts_info);
119+
if (ts_info.so_timestamping &
120+
SOF_TIMESTAMPING_HARDWARE_MASK)
121+
data->ts_layer[i++] = MAC_TIMESTAMPING;
122+
123+
if (ts_info.so_timestamping &
124+
SOF_TIMESTAMPING_SOFTWARE_MASK)
125+
data->ts_layer[i++] = SOFTWARE_TIMESTAMPING;
126+
}
127+
128+
data->num_ts = i;
129+
ethnl_ops_complete(dev);
130+
131+
return ret;
132+
}
133+
134+
static int ts_list_reply_size(const struct ethnl_req_info *req_base,
135+
const struct ethnl_reply_data *reply_base)
136+
{
137+
struct ts_list_reply_data *data = TS_LIST_REPDATA(reply_base);
138+
139+
return nla_total_size(sizeof(u32)) * data->num_ts;
140+
}
141+
142+
static int ts_list_fill_reply(struct sk_buff *skb,
143+
const struct ethnl_req_info *req_base,
144+
const struct ethnl_reply_data *reply_base)
145+
{
146+
struct ts_list_reply_data *data = TS_LIST_REPDATA(reply_base);
147+
148+
return nla_put(skb, ETHTOOL_A_TS_LIST_LAYER, sizeof(u32) * data->num_ts, data->ts_layer);
149+
}
150+
151+
const struct ethnl_request_ops ethnl_ts_list_request_ops = {
152+
.request_cmd = ETHTOOL_MSG_TS_LIST_GET,
153+
.reply_cmd = ETHTOOL_MSG_TS_LIST_GET_REPLY,
154+
.hdr_attr = ETHTOOL_A_TS_HEADER,
155+
.req_info_size = sizeof(struct ts_req_info),
156+
.reply_data_size = sizeof(struct ts_list_reply_data),
157+
158+
.prepare_data = ts_list_prepare_data,
159+
.reply_size = ts_list_reply_size,
160+
.fill_reply = ts_list_fill_reply,
161+
};

0 commit comments

Comments
 (0)