1 // SPDX-License-Identifier: GPL-2.0-only
6 struct linkstate_req_info {
7 struct ethnl_req_info base;
10 struct linkstate_reply_data {
11 struct ethnl_reply_data base;
15 #define LINKSTATE_REPDATA(__reply_base) \
16 container_of(__reply_base, struct linkstate_reply_data, base)
18 static const struct nla_policy
19 linkstate_get_policy[ETHTOOL_A_LINKSTATE_MAX + 1] = {
20 [ETHTOOL_A_LINKSTATE_UNSPEC] = { .type = NLA_REJECT },
21 [ETHTOOL_A_LINKSTATE_HEADER] = { .type = NLA_NESTED },
22 [ETHTOOL_A_LINKSTATE_LINK] = { .type = NLA_REJECT },
25 static int linkstate_prepare_data(const struct ethnl_req_info *req_base,
26 struct ethnl_reply_data *reply_base,
27 struct genl_info *info)
29 struct linkstate_reply_data *data = LINKSTATE_REPDATA(reply_base);
30 struct net_device *dev = reply_base->dev;
33 ret = ethnl_ops_begin(dev);
36 data->link = __ethtool_get_link(dev);
37 ethnl_ops_complete(dev);
42 static int linkstate_reply_size(const struct ethnl_req_info *req_base,
43 const struct ethnl_reply_data *reply_base)
45 return nla_total_size(sizeof(u8)) /* LINKSTATE_LINK */
49 static int linkstate_fill_reply(struct sk_buff *skb,
50 const struct ethnl_req_info *req_base,
51 const struct ethnl_reply_data *reply_base)
53 struct linkstate_reply_data *data = LINKSTATE_REPDATA(reply_base);
55 if (data->link >= 0 &&
56 nla_put_u8(skb, ETHTOOL_A_LINKSTATE_LINK, !!data->link))
62 const struct ethnl_request_ops ethnl_linkstate_request_ops = {
63 .request_cmd = ETHTOOL_MSG_LINKSTATE_GET,
64 .reply_cmd = ETHTOOL_MSG_LINKSTATE_GET_REPLY,
65 .hdr_attr = ETHTOOL_A_LINKSTATE_HEADER,
66 .max_attr = ETHTOOL_A_LINKSTATE_MAX,
67 .req_info_size = sizeof(struct linkstate_req_info),
68 .reply_data_size = sizeof(struct linkstate_reply_data),
69 .request_policy = linkstate_get_policy,
71 .prepare_data = linkstate_prepare_data,
72 .reply_size = linkstate_reply_size,
73 .fill_reply = linkstate_fill_reply,