18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci#include <net/sock.h>
48c2ecf20Sopenharmony_ci#include <linux/ethtool_netlink.h>
58c2ecf20Sopenharmony_ci#include "netlink.h"
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_cistatic struct genl_family ethtool_genl_family;
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_cistatic bool ethnl_ok __read_mostly;
108c2ecf20Sopenharmony_cistatic u32 ethnl_bcast_seq;
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define ETHTOOL_FLAGS_BASIC (ETHTOOL_FLAG_COMPACT_BITSETS |	\
138c2ecf20Sopenharmony_ci			     ETHTOOL_FLAG_OMIT_REPLY)
148c2ecf20Sopenharmony_ci#define ETHTOOL_FLAGS_STATS (ETHTOOL_FLAGS_BASIC | ETHTOOL_FLAG_STATS)
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ciconst struct nla_policy ethnl_header_policy[] = {
178c2ecf20Sopenharmony_ci	[ETHTOOL_A_HEADER_DEV_INDEX]	= { .type = NLA_U32 },
188c2ecf20Sopenharmony_ci	[ETHTOOL_A_HEADER_DEV_NAME]	= { .type = NLA_NUL_STRING,
198c2ecf20Sopenharmony_ci					    .len = ALTIFNAMSIZ - 1 },
208c2ecf20Sopenharmony_ci	[ETHTOOL_A_HEADER_FLAGS]	= NLA_POLICY_MASK(NLA_U32,
218c2ecf20Sopenharmony_ci							  ETHTOOL_FLAGS_BASIC),
228c2ecf20Sopenharmony_ci};
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ciconst struct nla_policy ethnl_header_policy_stats[] = {
258c2ecf20Sopenharmony_ci	[ETHTOOL_A_HEADER_DEV_INDEX]	= { .type = NLA_U32 },
268c2ecf20Sopenharmony_ci	[ETHTOOL_A_HEADER_DEV_NAME]	= { .type = NLA_NUL_STRING,
278c2ecf20Sopenharmony_ci					    .len = ALTIFNAMSIZ - 1 },
288c2ecf20Sopenharmony_ci	[ETHTOOL_A_HEADER_FLAGS]	= NLA_POLICY_MASK(NLA_U32,
298c2ecf20Sopenharmony_ci							  ETHTOOL_FLAGS_STATS),
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/**
338c2ecf20Sopenharmony_ci * ethnl_parse_header_dev_get() - parse request header
348c2ecf20Sopenharmony_ci * @req_info:    structure to put results into
358c2ecf20Sopenharmony_ci * @header:      nest attribute with request header
368c2ecf20Sopenharmony_ci * @net:         request netns
378c2ecf20Sopenharmony_ci * @extack:      netlink extack for error reporting
388c2ecf20Sopenharmony_ci * @require_dev: fail if no device identified in header
398c2ecf20Sopenharmony_ci *
408c2ecf20Sopenharmony_ci * Parse request header in nested attribute @nest and puts results into
418c2ecf20Sopenharmony_ci * the structure pointed to by @req_info. Extack from @info is used for error
428c2ecf20Sopenharmony_ci * reporting. If req_info->dev is not null on return, reference to it has
438c2ecf20Sopenharmony_ci * been taken. If error is returned, *req_info is null initialized and no
448c2ecf20Sopenharmony_ci * reference is held.
458c2ecf20Sopenharmony_ci *
468c2ecf20Sopenharmony_ci * Return: 0 on success or negative error code
478c2ecf20Sopenharmony_ci */
488c2ecf20Sopenharmony_ciint ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
498c2ecf20Sopenharmony_ci			       const struct nlattr *header, struct net *net,
508c2ecf20Sopenharmony_ci			       struct netlink_ext_ack *extack, bool require_dev)
518c2ecf20Sopenharmony_ci{
528c2ecf20Sopenharmony_ci	struct nlattr *tb[ARRAY_SIZE(ethnl_header_policy)];
538c2ecf20Sopenharmony_ci	const struct nlattr *devname_attr;
548c2ecf20Sopenharmony_ci	struct net_device *dev = NULL;
558c2ecf20Sopenharmony_ci	u32 flags = 0;
568c2ecf20Sopenharmony_ci	int ret;
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci	if (!header) {
598c2ecf20Sopenharmony_ci		NL_SET_ERR_MSG(extack, "request header missing");
608c2ecf20Sopenharmony_ci		return -EINVAL;
618c2ecf20Sopenharmony_ci	}
628c2ecf20Sopenharmony_ci	/* No validation here, command policy should have a nested policy set
638c2ecf20Sopenharmony_ci	 * for the header, therefore validation should have already been done.
648c2ecf20Sopenharmony_ci	 */
658c2ecf20Sopenharmony_ci	ret = nla_parse_nested(tb, ARRAY_SIZE(ethnl_header_policy) - 1, header,
668c2ecf20Sopenharmony_ci			       NULL, extack);
678c2ecf20Sopenharmony_ci	if (ret < 0)
688c2ecf20Sopenharmony_ci		return ret;
698c2ecf20Sopenharmony_ci	if (tb[ETHTOOL_A_HEADER_FLAGS])
708c2ecf20Sopenharmony_ci		flags = nla_get_u32(tb[ETHTOOL_A_HEADER_FLAGS]);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	devname_attr = tb[ETHTOOL_A_HEADER_DEV_NAME];
738c2ecf20Sopenharmony_ci	if (tb[ETHTOOL_A_HEADER_DEV_INDEX]) {
748c2ecf20Sopenharmony_ci		u32 ifindex = nla_get_u32(tb[ETHTOOL_A_HEADER_DEV_INDEX]);
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci		dev = dev_get_by_index(net, ifindex);
778c2ecf20Sopenharmony_ci		if (!dev) {
788c2ecf20Sopenharmony_ci			NL_SET_ERR_MSG_ATTR(extack,
798c2ecf20Sopenharmony_ci					    tb[ETHTOOL_A_HEADER_DEV_INDEX],
808c2ecf20Sopenharmony_ci					    "no device matches ifindex");
818c2ecf20Sopenharmony_ci			return -ENODEV;
828c2ecf20Sopenharmony_ci		}
838c2ecf20Sopenharmony_ci		/* if both ifindex and ifname are passed, they must match */
848c2ecf20Sopenharmony_ci		if (devname_attr &&
858c2ecf20Sopenharmony_ci		    strncmp(dev->name, nla_data(devname_attr), IFNAMSIZ)) {
868c2ecf20Sopenharmony_ci			dev_put(dev);
878c2ecf20Sopenharmony_ci			NL_SET_ERR_MSG_ATTR(extack, header,
888c2ecf20Sopenharmony_ci					    "ifindex and name do not match");
898c2ecf20Sopenharmony_ci			return -ENODEV;
908c2ecf20Sopenharmony_ci		}
918c2ecf20Sopenharmony_ci	} else if (devname_attr) {
928c2ecf20Sopenharmony_ci		dev = dev_get_by_name(net, nla_data(devname_attr));
938c2ecf20Sopenharmony_ci		if (!dev) {
948c2ecf20Sopenharmony_ci			NL_SET_ERR_MSG_ATTR(extack, devname_attr,
958c2ecf20Sopenharmony_ci					    "no device matches name");
968c2ecf20Sopenharmony_ci			return -ENODEV;
978c2ecf20Sopenharmony_ci		}
988c2ecf20Sopenharmony_ci	} else if (require_dev) {
998c2ecf20Sopenharmony_ci		NL_SET_ERR_MSG_ATTR(extack, header,
1008c2ecf20Sopenharmony_ci				    "neither ifindex nor name specified");
1018c2ecf20Sopenharmony_ci		return -EINVAL;
1028c2ecf20Sopenharmony_ci	}
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	if (dev && !netif_device_present(dev)) {
1058c2ecf20Sopenharmony_ci		dev_put(dev);
1068c2ecf20Sopenharmony_ci		NL_SET_ERR_MSG(extack, "device not present");
1078c2ecf20Sopenharmony_ci		return -ENODEV;
1088c2ecf20Sopenharmony_ci	}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	req_info->dev = dev;
1118c2ecf20Sopenharmony_ci	req_info->flags = flags;
1128c2ecf20Sopenharmony_ci	return 0;
1138c2ecf20Sopenharmony_ci}
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/**
1168c2ecf20Sopenharmony_ci * ethnl_fill_reply_header() - Put common header into a reply message
1178c2ecf20Sopenharmony_ci * @skb:      skb with the message
1188c2ecf20Sopenharmony_ci * @dev:      network device to describe in header
1198c2ecf20Sopenharmony_ci * @attrtype: attribute type to use for the nest
1208c2ecf20Sopenharmony_ci *
1218c2ecf20Sopenharmony_ci * Create a nested attribute with attributes describing given network device.
1228c2ecf20Sopenharmony_ci *
1238c2ecf20Sopenharmony_ci * Return: 0 on success, error value (-EMSGSIZE only) on error
1248c2ecf20Sopenharmony_ci */
1258c2ecf20Sopenharmony_ciint ethnl_fill_reply_header(struct sk_buff *skb, struct net_device *dev,
1268c2ecf20Sopenharmony_ci			    u16 attrtype)
1278c2ecf20Sopenharmony_ci{
1288c2ecf20Sopenharmony_ci	struct nlattr *nest;
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci	if (!dev)
1318c2ecf20Sopenharmony_ci		return 0;
1328c2ecf20Sopenharmony_ci	nest = nla_nest_start(skb, attrtype);
1338c2ecf20Sopenharmony_ci	if (!nest)
1348c2ecf20Sopenharmony_ci		return -EMSGSIZE;
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	if (nla_put_u32(skb, ETHTOOL_A_HEADER_DEV_INDEX, (u32)dev->ifindex) ||
1378c2ecf20Sopenharmony_ci	    nla_put_string(skb, ETHTOOL_A_HEADER_DEV_NAME, dev->name))
1388c2ecf20Sopenharmony_ci		goto nla_put_failure;
1398c2ecf20Sopenharmony_ci	/* If more attributes are put into reply header, ethnl_header_size()
1408c2ecf20Sopenharmony_ci	 * must be updated to account for them.
1418c2ecf20Sopenharmony_ci	 */
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci	nla_nest_end(skb, nest);
1448c2ecf20Sopenharmony_ci	return 0;
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_cinla_put_failure:
1478c2ecf20Sopenharmony_ci	nla_nest_cancel(skb, nest);
1488c2ecf20Sopenharmony_ci	return -EMSGSIZE;
1498c2ecf20Sopenharmony_ci}
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci/**
1528c2ecf20Sopenharmony_ci * ethnl_reply_init() - Create skb for a reply and fill device identification
1538c2ecf20Sopenharmony_ci * @payload:      payload length (without netlink and genetlink header)
1548c2ecf20Sopenharmony_ci * @dev:          device the reply is about (may be null)
1558c2ecf20Sopenharmony_ci * @cmd:          ETHTOOL_MSG_* message type for reply
1568c2ecf20Sopenharmony_ci * @hdr_attrtype: attribute type for common header
1578c2ecf20Sopenharmony_ci * @info:         genetlink info of the received packet we respond to
1588c2ecf20Sopenharmony_ci * @ehdrp:        place to store payload pointer returned by genlmsg_new()
1598c2ecf20Sopenharmony_ci *
1608c2ecf20Sopenharmony_ci * Return: pointer to allocated skb on success, NULL on error
1618c2ecf20Sopenharmony_ci */
1628c2ecf20Sopenharmony_cistruct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd,
1638c2ecf20Sopenharmony_ci				 u16 hdr_attrtype, struct genl_info *info,
1648c2ecf20Sopenharmony_ci				 void **ehdrp)
1658c2ecf20Sopenharmony_ci{
1668c2ecf20Sopenharmony_ci	struct sk_buff *skb;
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	skb = genlmsg_new(payload, GFP_KERNEL);
1698c2ecf20Sopenharmony_ci	if (!skb)
1708c2ecf20Sopenharmony_ci		goto err;
1718c2ecf20Sopenharmony_ci	*ehdrp = genlmsg_put_reply(skb, info, &ethtool_genl_family, 0, cmd);
1728c2ecf20Sopenharmony_ci	if (!*ehdrp)
1738c2ecf20Sopenharmony_ci		goto err_free;
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	if (dev) {
1768c2ecf20Sopenharmony_ci		int ret;
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci		ret = ethnl_fill_reply_header(skb, dev, hdr_attrtype);
1798c2ecf20Sopenharmony_ci		if (ret < 0)
1808c2ecf20Sopenharmony_ci			goto err_free;
1818c2ecf20Sopenharmony_ci	}
1828c2ecf20Sopenharmony_ci	return skb;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_cierr_free:
1858c2ecf20Sopenharmony_ci	nlmsg_free(skb);
1868c2ecf20Sopenharmony_cierr:
1878c2ecf20Sopenharmony_ci	if (info)
1888c2ecf20Sopenharmony_ci		GENL_SET_ERR_MSG(info, "failed to setup reply message");
1898c2ecf20Sopenharmony_ci	return NULL;
1908c2ecf20Sopenharmony_ci}
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_civoid *ethnl_dump_put(struct sk_buff *skb, struct netlink_callback *cb, u8 cmd)
1938c2ecf20Sopenharmony_ci{
1948c2ecf20Sopenharmony_ci	return genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
1958c2ecf20Sopenharmony_ci			   &ethtool_genl_family, 0, cmd);
1968c2ecf20Sopenharmony_ci}
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_civoid *ethnl_bcastmsg_put(struct sk_buff *skb, u8 cmd)
1998c2ecf20Sopenharmony_ci{
2008c2ecf20Sopenharmony_ci	return genlmsg_put(skb, 0, ++ethnl_bcast_seq, &ethtool_genl_family, 0,
2018c2ecf20Sopenharmony_ci			   cmd);
2028c2ecf20Sopenharmony_ci}
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ciint ethnl_multicast(struct sk_buff *skb, struct net_device *dev)
2058c2ecf20Sopenharmony_ci{
2068c2ecf20Sopenharmony_ci	return genlmsg_multicast_netns(&ethtool_genl_family, dev_net(dev), skb,
2078c2ecf20Sopenharmony_ci				       0, ETHNL_MCGRP_MONITOR, GFP_KERNEL);
2088c2ecf20Sopenharmony_ci}
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci/* GET request helpers */
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci/**
2138c2ecf20Sopenharmony_ci * struct ethnl_dump_ctx - context structure for generic dumpit() callback
2148c2ecf20Sopenharmony_ci * @ops:        request ops of currently processed message type
2158c2ecf20Sopenharmony_ci * @req_info:   parsed request header of processed request
2168c2ecf20Sopenharmony_ci * @reply_data: data needed to compose the reply
2178c2ecf20Sopenharmony_ci * @pos_hash:   saved iteration position - hashbucket
2188c2ecf20Sopenharmony_ci * @pos_idx:    saved iteration position - index
2198c2ecf20Sopenharmony_ci *
2208c2ecf20Sopenharmony_ci * These parameters are kept in struct netlink_callback as context preserved
2218c2ecf20Sopenharmony_ci * between iterations. They are initialized by ethnl_default_start() and used
2228c2ecf20Sopenharmony_ci * in ethnl_default_dumpit() and ethnl_default_done().
2238c2ecf20Sopenharmony_ci */
2248c2ecf20Sopenharmony_cistruct ethnl_dump_ctx {
2258c2ecf20Sopenharmony_ci	const struct ethnl_request_ops	*ops;
2268c2ecf20Sopenharmony_ci	struct ethnl_req_info		*req_info;
2278c2ecf20Sopenharmony_ci	struct ethnl_reply_data		*reply_data;
2288c2ecf20Sopenharmony_ci	int				pos_hash;
2298c2ecf20Sopenharmony_ci	int				pos_idx;
2308c2ecf20Sopenharmony_ci};
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_cistatic const struct ethnl_request_ops *
2338c2ecf20Sopenharmony_ciethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
2348c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_STRSET_GET]	= &ethnl_strset_request_ops,
2358c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_LINKINFO_GET]	= &ethnl_linkinfo_request_ops,
2368c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_LINKMODES_GET]	= &ethnl_linkmodes_request_ops,
2378c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_LINKSTATE_GET]	= &ethnl_linkstate_request_ops,
2388c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_DEBUG_GET]		= &ethnl_debug_request_ops,
2398c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_WOL_GET]		= &ethnl_wol_request_ops,
2408c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_FEATURES_GET]	= &ethnl_features_request_ops,
2418c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_PRIVFLAGS_GET]	= &ethnl_privflags_request_ops,
2428c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_RINGS_GET]		= &ethnl_rings_request_ops,
2438c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_CHANNELS_GET]	= &ethnl_channels_request_ops,
2448c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_COALESCE_GET]	= &ethnl_coalesce_request_ops,
2458c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_PAUSE_GET]		= &ethnl_pause_request_ops,
2468c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_EEE_GET]		= &ethnl_eee_request_ops,
2478c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_TSINFO_GET]	= &ethnl_tsinfo_request_ops,
2488c2ecf20Sopenharmony_ci};
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_cistatic struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
2518c2ecf20Sopenharmony_ci{
2528c2ecf20Sopenharmony_ci	return (struct ethnl_dump_ctx *)cb->ctx;
2538c2ecf20Sopenharmony_ci}
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci/**
2568c2ecf20Sopenharmony_ci * ethnl_default_parse() - Parse request message
2578c2ecf20Sopenharmony_ci * @req_info:    pointer to structure to put data into
2588c2ecf20Sopenharmony_ci * @tb:		 parsed attributes
2598c2ecf20Sopenharmony_ci * @net:         request netns
2608c2ecf20Sopenharmony_ci * @request_ops: struct request_ops for request type
2618c2ecf20Sopenharmony_ci * @extack:      netlink extack for error reporting
2628c2ecf20Sopenharmony_ci * @require_dev: fail if no device identified in header
2638c2ecf20Sopenharmony_ci *
2648c2ecf20Sopenharmony_ci * Parse universal request header and call request specific ->parse_request()
2658c2ecf20Sopenharmony_ci * callback (if defined) to parse the rest of the message.
2668c2ecf20Sopenharmony_ci *
2678c2ecf20Sopenharmony_ci * Return: 0 on success or negative error code
2688c2ecf20Sopenharmony_ci */
2698c2ecf20Sopenharmony_cistatic int ethnl_default_parse(struct ethnl_req_info *req_info,
2708c2ecf20Sopenharmony_ci			       struct nlattr **tb, struct net *net,
2718c2ecf20Sopenharmony_ci			       const struct ethnl_request_ops *request_ops,
2728c2ecf20Sopenharmony_ci			       struct netlink_ext_ack *extack, bool require_dev)
2738c2ecf20Sopenharmony_ci{
2748c2ecf20Sopenharmony_ci	int ret;
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	ret = ethnl_parse_header_dev_get(req_info, tb[request_ops->hdr_attr],
2778c2ecf20Sopenharmony_ci					 net, extack, require_dev);
2788c2ecf20Sopenharmony_ci	if (ret < 0)
2798c2ecf20Sopenharmony_ci		return ret;
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	if (request_ops->parse_request) {
2828c2ecf20Sopenharmony_ci		ret = request_ops->parse_request(req_info, tb, extack);
2838c2ecf20Sopenharmony_ci		if (ret < 0)
2848c2ecf20Sopenharmony_ci			return ret;
2858c2ecf20Sopenharmony_ci	}
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci	return 0;
2888c2ecf20Sopenharmony_ci}
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci/**
2918c2ecf20Sopenharmony_ci * ethnl_init_reply_data() - Initialize reply data for GET request
2928c2ecf20Sopenharmony_ci * @reply_data: pointer to embedded struct ethnl_reply_data
2938c2ecf20Sopenharmony_ci * @ops:        instance of struct ethnl_request_ops describing the layout
2948c2ecf20Sopenharmony_ci * @dev:        network device to initialize the reply for
2958c2ecf20Sopenharmony_ci *
2968c2ecf20Sopenharmony_ci * Fills the reply data part with zeros and sets the dev member. Must be called
2978c2ecf20Sopenharmony_ci * before calling the ->fill_reply() callback (for each iteration when handling
2988c2ecf20Sopenharmony_ci * dump requests).
2998c2ecf20Sopenharmony_ci */
3008c2ecf20Sopenharmony_cistatic void ethnl_init_reply_data(struct ethnl_reply_data *reply_data,
3018c2ecf20Sopenharmony_ci				  const struct ethnl_request_ops *ops,
3028c2ecf20Sopenharmony_ci				  struct net_device *dev)
3038c2ecf20Sopenharmony_ci{
3048c2ecf20Sopenharmony_ci	memset(reply_data, 0, ops->reply_data_size);
3058c2ecf20Sopenharmony_ci	reply_data->dev = dev;
3068c2ecf20Sopenharmony_ci}
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci/* default ->doit() handler for GET type requests */
3098c2ecf20Sopenharmony_cistatic int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info)
3108c2ecf20Sopenharmony_ci{
3118c2ecf20Sopenharmony_ci	struct ethnl_reply_data *reply_data = NULL;
3128c2ecf20Sopenharmony_ci	struct ethnl_req_info *req_info = NULL;
3138c2ecf20Sopenharmony_ci	const u8 cmd = info->genlhdr->cmd;
3148c2ecf20Sopenharmony_ci	const struct ethnl_request_ops *ops;
3158c2ecf20Sopenharmony_ci	struct sk_buff *rskb;
3168c2ecf20Sopenharmony_ci	void *reply_payload;
3178c2ecf20Sopenharmony_ci	int reply_len;
3188c2ecf20Sopenharmony_ci	int ret;
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci	ops = ethnl_default_requests[cmd];
3218c2ecf20Sopenharmony_ci	if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", cmd))
3228c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
3238c2ecf20Sopenharmony_ci	req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
3248c2ecf20Sopenharmony_ci	if (!req_info)
3258c2ecf20Sopenharmony_ci		return -ENOMEM;
3268c2ecf20Sopenharmony_ci	reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
3278c2ecf20Sopenharmony_ci	if (!reply_data) {
3288c2ecf20Sopenharmony_ci		kfree(req_info);
3298c2ecf20Sopenharmony_ci		return -ENOMEM;
3308c2ecf20Sopenharmony_ci	}
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	ret = ethnl_default_parse(req_info, info->attrs, genl_info_net(info),
3338c2ecf20Sopenharmony_ci				  ops, info->extack, !ops->allow_nodev_do);
3348c2ecf20Sopenharmony_ci	if (ret < 0)
3358c2ecf20Sopenharmony_ci		goto err_dev;
3368c2ecf20Sopenharmony_ci	ethnl_init_reply_data(reply_data, ops, req_info->dev);
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci	rtnl_lock();
3398c2ecf20Sopenharmony_ci	ret = ops->prepare_data(req_info, reply_data, info);
3408c2ecf20Sopenharmony_ci	rtnl_unlock();
3418c2ecf20Sopenharmony_ci	if (ret < 0)
3428c2ecf20Sopenharmony_ci		goto err_cleanup;
3438c2ecf20Sopenharmony_ci	ret = ops->reply_size(req_info, reply_data);
3448c2ecf20Sopenharmony_ci	if (ret < 0)
3458c2ecf20Sopenharmony_ci		goto err_cleanup;
3468c2ecf20Sopenharmony_ci	reply_len = ret + ethnl_reply_header_size();
3478c2ecf20Sopenharmony_ci	ret = -ENOMEM;
3488c2ecf20Sopenharmony_ci	rskb = ethnl_reply_init(reply_len, req_info->dev, ops->reply_cmd,
3498c2ecf20Sopenharmony_ci				ops->hdr_attr, info, &reply_payload);
3508c2ecf20Sopenharmony_ci	if (!rskb)
3518c2ecf20Sopenharmony_ci		goto err_cleanup;
3528c2ecf20Sopenharmony_ci	ret = ops->fill_reply(rskb, req_info, reply_data);
3538c2ecf20Sopenharmony_ci	if (ret < 0)
3548c2ecf20Sopenharmony_ci		goto err_msg;
3558c2ecf20Sopenharmony_ci	if (ops->cleanup_data)
3568c2ecf20Sopenharmony_ci		ops->cleanup_data(reply_data);
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	genlmsg_end(rskb, reply_payload);
3598c2ecf20Sopenharmony_ci	if (req_info->dev)
3608c2ecf20Sopenharmony_ci		dev_put(req_info->dev);
3618c2ecf20Sopenharmony_ci	kfree(reply_data);
3628c2ecf20Sopenharmony_ci	kfree(req_info);
3638c2ecf20Sopenharmony_ci	return genlmsg_reply(rskb, info);
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_cierr_msg:
3668c2ecf20Sopenharmony_ci	WARN_ONCE(ret == -EMSGSIZE, "calculated message payload length (%d) not sufficient\n", reply_len);
3678c2ecf20Sopenharmony_ci	nlmsg_free(rskb);
3688c2ecf20Sopenharmony_cierr_cleanup:
3698c2ecf20Sopenharmony_ci	if (ops->cleanup_data)
3708c2ecf20Sopenharmony_ci		ops->cleanup_data(reply_data);
3718c2ecf20Sopenharmony_cierr_dev:
3728c2ecf20Sopenharmony_ci	if (req_info->dev)
3738c2ecf20Sopenharmony_ci		dev_put(req_info->dev);
3748c2ecf20Sopenharmony_ci	kfree(reply_data);
3758c2ecf20Sopenharmony_ci	kfree(req_info);
3768c2ecf20Sopenharmony_ci	return ret;
3778c2ecf20Sopenharmony_ci}
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_cistatic int ethnl_default_dump_one(struct sk_buff *skb, struct net_device *dev,
3808c2ecf20Sopenharmony_ci				  const struct ethnl_dump_ctx *ctx,
3818c2ecf20Sopenharmony_ci				  struct netlink_callback *cb)
3828c2ecf20Sopenharmony_ci{
3838c2ecf20Sopenharmony_ci	void *ehdr;
3848c2ecf20Sopenharmony_ci	int ret;
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	ehdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
3878c2ecf20Sopenharmony_ci			   &ethtool_genl_family, NLM_F_MULTI,
3888c2ecf20Sopenharmony_ci			   ctx->ops->reply_cmd);
3898c2ecf20Sopenharmony_ci	if (!ehdr)
3908c2ecf20Sopenharmony_ci		return -EMSGSIZE;
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_ci	ethnl_init_reply_data(ctx->reply_data, ctx->ops, dev);
3938c2ecf20Sopenharmony_ci	rtnl_lock();
3948c2ecf20Sopenharmony_ci	ret = ctx->ops->prepare_data(ctx->req_info, ctx->reply_data, NULL);
3958c2ecf20Sopenharmony_ci	rtnl_unlock();
3968c2ecf20Sopenharmony_ci	if (ret < 0)
3978c2ecf20Sopenharmony_ci		goto out;
3988c2ecf20Sopenharmony_ci	ret = ethnl_fill_reply_header(skb, dev, ctx->ops->hdr_attr);
3998c2ecf20Sopenharmony_ci	if (ret < 0)
4008c2ecf20Sopenharmony_ci		goto out;
4018c2ecf20Sopenharmony_ci	ret = ctx->ops->fill_reply(skb, ctx->req_info, ctx->reply_data);
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ciout:
4048c2ecf20Sopenharmony_ci	if (ctx->ops->cleanup_data)
4058c2ecf20Sopenharmony_ci		ctx->ops->cleanup_data(ctx->reply_data);
4068c2ecf20Sopenharmony_ci	ctx->reply_data->dev = NULL;
4078c2ecf20Sopenharmony_ci	if (ret < 0)
4088c2ecf20Sopenharmony_ci		genlmsg_cancel(skb, ehdr);
4098c2ecf20Sopenharmony_ci	else
4108c2ecf20Sopenharmony_ci		genlmsg_end(skb, ehdr);
4118c2ecf20Sopenharmony_ci	return ret;
4128c2ecf20Sopenharmony_ci}
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci/* Default ->dumpit() handler for GET requests. Device iteration copied from
4158c2ecf20Sopenharmony_ci * rtnl_dump_ifinfo(); we have to be more careful about device hashtable
4168c2ecf20Sopenharmony_ci * persistence as we cannot guarantee to hold RTNL lock through the whole
4178c2ecf20Sopenharmony_ci * function as rtnetnlink does.
4188c2ecf20Sopenharmony_ci */
4198c2ecf20Sopenharmony_cistatic int ethnl_default_dumpit(struct sk_buff *skb,
4208c2ecf20Sopenharmony_ci				struct netlink_callback *cb)
4218c2ecf20Sopenharmony_ci{
4228c2ecf20Sopenharmony_ci	struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb);
4238c2ecf20Sopenharmony_ci	struct net *net = sock_net(skb->sk);
4248c2ecf20Sopenharmony_ci	int s_idx = ctx->pos_idx;
4258c2ecf20Sopenharmony_ci	int h, idx = 0;
4268c2ecf20Sopenharmony_ci	int ret = 0;
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci	rtnl_lock();
4298c2ecf20Sopenharmony_ci	for (h = ctx->pos_hash; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
4308c2ecf20Sopenharmony_ci		struct hlist_head *head;
4318c2ecf20Sopenharmony_ci		struct net_device *dev;
4328c2ecf20Sopenharmony_ci		unsigned int seq;
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ci		head = &net->dev_index_head[h];
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_cirestart_chain:
4378c2ecf20Sopenharmony_ci		seq = net->dev_base_seq;
4388c2ecf20Sopenharmony_ci		cb->seq = seq;
4398c2ecf20Sopenharmony_ci		idx = 0;
4408c2ecf20Sopenharmony_ci		hlist_for_each_entry(dev, head, index_hlist) {
4418c2ecf20Sopenharmony_ci			if (idx < s_idx)
4428c2ecf20Sopenharmony_ci				goto cont;
4438c2ecf20Sopenharmony_ci			dev_hold(dev);
4448c2ecf20Sopenharmony_ci			rtnl_unlock();
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci			ret = ethnl_default_dump_one(skb, dev, ctx, cb);
4478c2ecf20Sopenharmony_ci			dev_put(dev);
4488c2ecf20Sopenharmony_ci			if (ret < 0) {
4498c2ecf20Sopenharmony_ci				if (ret == -EOPNOTSUPP)
4508c2ecf20Sopenharmony_ci					goto lock_and_cont;
4518c2ecf20Sopenharmony_ci				if (likely(skb->len))
4528c2ecf20Sopenharmony_ci					ret = skb->len;
4538c2ecf20Sopenharmony_ci				goto out;
4548c2ecf20Sopenharmony_ci			}
4558c2ecf20Sopenharmony_cilock_and_cont:
4568c2ecf20Sopenharmony_ci			rtnl_lock();
4578c2ecf20Sopenharmony_ci			if (net->dev_base_seq != seq) {
4588c2ecf20Sopenharmony_ci				s_idx = idx + 1;
4598c2ecf20Sopenharmony_ci				goto restart_chain;
4608c2ecf20Sopenharmony_ci			}
4618c2ecf20Sopenharmony_cicont:
4628c2ecf20Sopenharmony_ci			idx++;
4638c2ecf20Sopenharmony_ci		}
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	}
4668c2ecf20Sopenharmony_ci	rtnl_unlock();
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ciout:
4698c2ecf20Sopenharmony_ci	ctx->pos_hash = h;
4708c2ecf20Sopenharmony_ci	ctx->pos_idx = idx;
4718c2ecf20Sopenharmony_ci	nl_dump_check_consistent(cb, nlmsg_hdr(skb));
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci	return ret;
4748c2ecf20Sopenharmony_ci}
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci/* generic ->start() handler for GET requests */
4778c2ecf20Sopenharmony_cistatic int ethnl_default_start(struct netlink_callback *cb)
4788c2ecf20Sopenharmony_ci{
4798c2ecf20Sopenharmony_ci	const struct genl_dumpit_info *info = genl_dumpit_info(cb);
4808c2ecf20Sopenharmony_ci	struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb);
4818c2ecf20Sopenharmony_ci	struct ethnl_reply_data *reply_data;
4828c2ecf20Sopenharmony_ci	const struct ethnl_request_ops *ops;
4838c2ecf20Sopenharmony_ci	struct ethnl_req_info *req_info;
4848c2ecf20Sopenharmony_ci	struct genlmsghdr *ghdr;
4858c2ecf20Sopenharmony_ci	int ret;
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci	BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx));
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci	ghdr = nlmsg_data(cb->nlh);
4908c2ecf20Sopenharmony_ci	ops = ethnl_default_requests[ghdr->cmd];
4918c2ecf20Sopenharmony_ci	if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", ghdr->cmd))
4928c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
4938c2ecf20Sopenharmony_ci	req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
4948c2ecf20Sopenharmony_ci	if (!req_info)
4958c2ecf20Sopenharmony_ci		return -ENOMEM;
4968c2ecf20Sopenharmony_ci	reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
4978c2ecf20Sopenharmony_ci	if (!reply_data) {
4988c2ecf20Sopenharmony_ci		ret = -ENOMEM;
4998c2ecf20Sopenharmony_ci		goto free_req_info;
5008c2ecf20Sopenharmony_ci	}
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ci	ret = ethnl_default_parse(req_info, info->attrs, sock_net(cb->skb->sk),
5038c2ecf20Sopenharmony_ci				  ops, cb->extack, false);
5048c2ecf20Sopenharmony_ci	if (req_info->dev) {
5058c2ecf20Sopenharmony_ci		/* We ignore device specification in dump requests but as the
5068c2ecf20Sopenharmony_ci		 * same parser as for non-dump (doit) requests is used, it
5078c2ecf20Sopenharmony_ci		 * would take reference to the device if it finds one
5088c2ecf20Sopenharmony_ci		 */
5098c2ecf20Sopenharmony_ci		dev_put(req_info->dev);
5108c2ecf20Sopenharmony_ci		req_info->dev = NULL;
5118c2ecf20Sopenharmony_ci	}
5128c2ecf20Sopenharmony_ci	if (ret < 0)
5138c2ecf20Sopenharmony_ci		goto free_reply_data;
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_ci	ctx->ops = ops;
5168c2ecf20Sopenharmony_ci	ctx->req_info = req_info;
5178c2ecf20Sopenharmony_ci	ctx->reply_data = reply_data;
5188c2ecf20Sopenharmony_ci	ctx->pos_hash = 0;
5198c2ecf20Sopenharmony_ci	ctx->pos_idx = 0;
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci	return 0;
5228c2ecf20Sopenharmony_ci
5238c2ecf20Sopenharmony_cifree_reply_data:
5248c2ecf20Sopenharmony_ci	kfree(reply_data);
5258c2ecf20Sopenharmony_cifree_req_info:
5268c2ecf20Sopenharmony_ci	kfree(req_info);
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ci	return ret;
5298c2ecf20Sopenharmony_ci}
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_ci/* default ->done() handler for GET requests */
5328c2ecf20Sopenharmony_cistatic int ethnl_default_done(struct netlink_callback *cb)
5338c2ecf20Sopenharmony_ci{
5348c2ecf20Sopenharmony_ci	struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb);
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_ci	kfree(ctx->reply_data);
5378c2ecf20Sopenharmony_ci	kfree(ctx->req_info);
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci	return 0;
5408c2ecf20Sopenharmony_ci}
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_cistatic const struct ethnl_request_ops *
5438c2ecf20Sopenharmony_ciethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX + 1] = {
5448c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_LINKINFO_NTF]	= &ethnl_linkinfo_request_ops,
5458c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_LINKMODES_NTF]	= &ethnl_linkmodes_request_ops,
5468c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_DEBUG_NTF]		= &ethnl_debug_request_ops,
5478c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_WOL_NTF]		= &ethnl_wol_request_ops,
5488c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_FEATURES_NTF]	= &ethnl_features_request_ops,
5498c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_PRIVFLAGS_NTF]	= &ethnl_privflags_request_ops,
5508c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_RINGS_NTF]		= &ethnl_rings_request_ops,
5518c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_CHANNELS_NTF]	= &ethnl_channels_request_ops,
5528c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_COALESCE_NTF]	= &ethnl_coalesce_request_ops,
5538c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_PAUSE_NTF]		= &ethnl_pause_request_ops,
5548c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_EEE_NTF]		= &ethnl_eee_request_ops,
5558c2ecf20Sopenharmony_ci};
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_ci/* default notification handler */
5588c2ecf20Sopenharmony_cistatic void ethnl_default_notify(struct net_device *dev, unsigned int cmd,
5598c2ecf20Sopenharmony_ci				 const void *data)
5608c2ecf20Sopenharmony_ci{
5618c2ecf20Sopenharmony_ci	struct ethnl_reply_data *reply_data;
5628c2ecf20Sopenharmony_ci	const struct ethnl_request_ops *ops;
5638c2ecf20Sopenharmony_ci	struct ethnl_req_info *req_info;
5648c2ecf20Sopenharmony_ci	struct sk_buff *skb;
5658c2ecf20Sopenharmony_ci	void *reply_payload;
5668c2ecf20Sopenharmony_ci	int reply_len;
5678c2ecf20Sopenharmony_ci	int ret;
5688c2ecf20Sopenharmony_ci
5698c2ecf20Sopenharmony_ci	if (WARN_ONCE(cmd > ETHTOOL_MSG_KERNEL_MAX ||
5708c2ecf20Sopenharmony_ci		      !ethnl_default_notify_ops[cmd],
5718c2ecf20Sopenharmony_ci		      "unexpected notification type %u\n", cmd))
5728c2ecf20Sopenharmony_ci		return;
5738c2ecf20Sopenharmony_ci	ops = ethnl_default_notify_ops[cmd];
5748c2ecf20Sopenharmony_ci	req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
5758c2ecf20Sopenharmony_ci	if (!req_info)
5768c2ecf20Sopenharmony_ci		return;
5778c2ecf20Sopenharmony_ci	reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
5788c2ecf20Sopenharmony_ci	if (!reply_data) {
5798c2ecf20Sopenharmony_ci		kfree(req_info);
5808c2ecf20Sopenharmony_ci		return;
5818c2ecf20Sopenharmony_ci	}
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci	req_info->dev = dev;
5848c2ecf20Sopenharmony_ci	req_info->flags |= ETHTOOL_FLAG_COMPACT_BITSETS;
5858c2ecf20Sopenharmony_ci
5868c2ecf20Sopenharmony_ci	ethnl_init_reply_data(reply_data, ops, dev);
5878c2ecf20Sopenharmony_ci	ret = ops->prepare_data(req_info, reply_data, NULL);
5888c2ecf20Sopenharmony_ci	if (ret < 0)
5898c2ecf20Sopenharmony_ci		goto err_cleanup;
5908c2ecf20Sopenharmony_ci	ret = ops->reply_size(req_info, reply_data);
5918c2ecf20Sopenharmony_ci	if (ret < 0)
5928c2ecf20Sopenharmony_ci		goto err_cleanup;
5938c2ecf20Sopenharmony_ci	reply_len = ret + ethnl_reply_header_size();
5948c2ecf20Sopenharmony_ci	ret = -ENOMEM;
5958c2ecf20Sopenharmony_ci	skb = genlmsg_new(reply_len, GFP_KERNEL);
5968c2ecf20Sopenharmony_ci	if (!skb)
5978c2ecf20Sopenharmony_ci		goto err_cleanup;
5988c2ecf20Sopenharmony_ci	reply_payload = ethnl_bcastmsg_put(skb, cmd);
5998c2ecf20Sopenharmony_ci	if (!reply_payload)
6008c2ecf20Sopenharmony_ci		goto err_skb;
6018c2ecf20Sopenharmony_ci	ret = ethnl_fill_reply_header(skb, dev, ops->hdr_attr);
6028c2ecf20Sopenharmony_ci	if (ret < 0)
6038c2ecf20Sopenharmony_ci		goto err_msg;
6048c2ecf20Sopenharmony_ci	ret = ops->fill_reply(skb, req_info, reply_data);
6058c2ecf20Sopenharmony_ci	if (ret < 0)
6068c2ecf20Sopenharmony_ci		goto err_msg;
6078c2ecf20Sopenharmony_ci	if (ops->cleanup_data)
6088c2ecf20Sopenharmony_ci		ops->cleanup_data(reply_data);
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_ci	genlmsg_end(skb, reply_payload);
6118c2ecf20Sopenharmony_ci	kfree(reply_data);
6128c2ecf20Sopenharmony_ci	kfree(req_info);
6138c2ecf20Sopenharmony_ci	ethnl_multicast(skb, dev);
6148c2ecf20Sopenharmony_ci	return;
6158c2ecf20Sopenharmony_ci
6168c2ecf20Sopenharmony_cierr_msg:
6178c2ecf20Sopenharmony_ci	WARN_ONCE(ret == -EMSGSIZE,
6188c2ecf20Sopenharmony_ci		  "calculated message payload length (%d) not sufficient\n",
6198c2ecf20Sopenharmony_ci		  reply_len);
6208c2ecf20Sopenharmony_cierr_skb:
6218c2ecf20Sopenharmony_ci	nlmsg_free(skb);
6228c2ecf20Sopenharmony_cierr_cleanup:
6238c2ecf20Sopenharmony_ci	if (ops->cleanup_data)
6248c2ecf20Sopenharmony_ci		ops->cleanup_data(reply_data);
6258c2ecf20Sopenharmony_ci	kfree(reply_data);
6268c2ecf20Sopenharmony_ci	kfree(req_info);
6278c2ecf20Sopenharmony_ci	return;
6288c2ecf20Sopenharmony_ci}
6298c2ecf20Sopenharmony_ci
6308c2ecf20Sopenharmony_ci/* notifications */
6318c2ecf20Sopenharmony_ci
6328c2ecf20Sopenharmony_citypedef void (*ethnl_notify_handler_t)(struct net_device *dev, unsigned int cmd,
6338c2ecf20Sopenharmony_ci				       const void *data);
6348c2ecf20Sopenharmony_ci
6358c2ecf20Sopenharmony_cistatic const ethnl_notify_handler_t ethnl_notify_handlers[] = {
6368c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_LINKINFO_NTF]	= ethnl_default_notify,
6378c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_LINKMODES_NTF]	= ethnl_default_notify,
6388c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_DEBUG_NTF]		= ethnl_default_notify,
6398c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_WOL_NTF]		= ethnl_default_notify,
6408c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_FEATURES_NTF]	= ethnl_default_notify,
6418c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_PRIVFLAGS_NTF]	= ethnl_default_notify,
6428c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_RINGS_NTF]		= ethnl_default_notify,
6438c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_CHANNELS_NTF]	= ethnl_default_notify,
6448c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_COALESCE_NTF]	= ethnl_default_notify,
6458c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_PAUSE_NTF]		= ethnl_default_notify,
6468c2ecf20Sopenharmony_ci	[ETHTOOL_MSG_EEE_NTF]		= ethnl_default_notify,
6478c2ecf20Sopenharmony_ci};
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_civoid ethtool_notify(struct net_device *dev, unsigned int cmd, const void *data)
6508c2ecf20Sopenharmony_ci{
6518c2ecf20Sopenharmony_ci	if (unlikely(!ethnl_ok))
6528c2ecf20Sopenharmony_ci		return;
6538c2ecf20Sopenharmony_ci	ASSERT_RTNL();
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_ci	if (likely(cmd < ARRAY_SIZE(ethnl_notify_handlers) &&
6568c2ecf20Sopenharmony_ci		   ethnl_notify_handlers[cmd]))
6578c2ecf20Sopenharmony_ci		ethnl_notify_handlers[cmd](dev, cmd, data);
6588c2ecf20Sopenharmony_ci	else
6598c2ecf20Sopenharmony_ci		WARN_ONCE(1, "notification %u not implemented (dev=%s)\n",
6608c2ecf20Sopenharmony_ci			  cmd, netdev_name(dev));
6618c2ecf20Sopenharmony_ci}
6628c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ethtool_notify);
6638c2ecf20Sopenharmony_ci
6648c2ecf20Sopenharmony_cistatic void ethnl_notify_features(struct netdev_notifier_info *info)
6658c2ecf20Sopenharmony_ci{
6668c2ecf20Sopenharmony_ci	struct net_device *dev = netdev_notifier_info_to_dev(info);
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_ci	ethtool_notify(dev, ETHTOOL_MSG_FEATURES_NTF, NULL);
6698c2ecf20Sopenharmony_ci}
6708c2ecf20Sopenharmony_ci
6718c2ecf20Sopenharmony_cistatic int ethnl_netdev_event(struct notifier_block *this, unsigned long event,
6728c2ecf20Sopenharmony_ci			      void *ptr)
6738c2ecf20Sopenharmony_ci{
6748c2ecf20Sopenharmony_ci	switch (event) {
6758c2ecf20Sopenharmony_ci	case NETDEV_FEAT_CHANGE:
6768c2ecf20Sopenharmony_ci		ethnl_notify_features(ptr);
6778c2ecf20Sopenharmony_ci		break;
6788c2ecf20Sopenharmony_ci	}
6798c2ecf20Sopenharmony_ci
6808c2ecf20Sopenharmony_ci	return NOTIFY_DONE;
6818c2ecf20Sopenharmony_ci}
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_cistatic struct notifier_block ethnl_netdev_notifier = {
6848c2ecf20Sopenharmony_ci	.notifier_call = ethnl_netdev_event,
6858c2ecf20Sopenharmony_ci};
6868c2ecf20Sopenharmony_ci
6878c2ecf20Sopenharmony_ci/* genetlink setup */
6888c2ecf20Sopenharmony_ci
6898c2ecf20Sopenharmony_cistatic const struct genl_ops ethtool_genl_ops[] = {
6908c2ecf20Sopenharmony_ci	{
6918c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_STRSET_GET,
6928c2ecf20Sopenharmony_ci		.doit	= ethnl_default_doit,
6938c2ecf20Sopenharmony_ci		.start	= ethnl_default_start,
6948c2ecf20Sopenharmony_ci		.dumpit	= ethnl_default_dumpit,
6958c2ecf20Sopenharmony_ci		.done	= ethnl_default_done,
6968c2ecf20Sopenharmony_ci		.policy = ethnl_strset_get_policy,
6978c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_strset_get_policy) - 1,
6988c2ecf20Sopenharmony_ci	},
6998c2ecf20Sopenharmony_ci	{
7008c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_LINKINFO_GET,
7018c2ecf20Sopenharmony_ci		.doit	= ethnl_default_doit,
7028c2ecf20Sopenharmony_ci		.start	= ethnl_default_start,
7038c2ecf20Sopenharmony_ci		.dumpit	= ethnl_default_dumpit,
7048c2ecf20Sopenharmony_ci		.done	= ethnl_default_done,
7058c2ecf20Sopenharmony_ci		.policy = ethnl_linkinfo_get_policy,
7068c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_linkinfo_get_policy) - 1,
7078c2ecf20Sopenharmony_ci	},
7088c2ecf20Sopenharmony_ci	{
7098c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_LINKINFO_SET,
7108c2ecf20Sopenharmony_ci		.flags	= GENL_UNS_ADMIN_PERM,
7118c2ecf20Sopenharmony_ci		.doit	= ethnl_set_linkinfo,
7128c2ecf20Sopenharmony_ci		.policy = ethnl_linkinfo_set_policy,
7138c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_linkinfo_set_policy) - 1,
7148c2ecf20Sopenharmony_ci	},
7158c2ecf20Sopenharmony_ci	{
7168c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_LINKMODES_GET,
7178c2ecf20Sopenharmony_ci		.doit	= ethnl_default_doit,
7188c2ecf20Sopenharmony_ci		.start	= ethnl_default_start,
7198c2ecf20Sopenharmony_ci		.dumpit	= ethnl_default_dumpit,
7208c2ecf20Sopenharmony_ci		.done	= ethnl_default_done,
7218c2ecf20Sopenharmony_ci		.policy = ethnl_linkmodes_get_policy,
7228c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_linkmodes_get_policy) - 1,
7238c2ecf20Sopenharmony_ci	},
7248c2ecf20Sopenharmony_ci	{
7258c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_LINKMODES_SET,
7268c2ecf20Sopenharmony_ci		.flags	= GENL_UNS_ADMIN_PERM,
7278c2ecf20Sopenharmony_ci		.doit	= ethnl_set_linkmodes,
7288c2ecf20Sopenharmony_ci		.policy = ethnl_linkmodes_set_policy,
7298c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_linkmodes_set_policy) - 1,
7308c2ecf20Sopenharmony_ci	},
7318c2ecf20Sopenharmony_ci	{
7328c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_LINKSTATE_GET,
7338c2ecf20Sopenharmony_ci		.doit	= ethnl_default_doit,
7348c2ecf20Sopenharmony_ci		.start	= ethnl_default_start,
7358c2ecf20Sopenharmony_ci		.dumpit	= ethnl_default_dumpit,
7368c2ecf20Sopenharmony_ci		.done	= ethnl_default_done,
7378c2ecf20Sopenharmony_ci		.policy = ethnl_linkstate_get_policy,
7388c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_linkstate_get_policy) - 1,
7398c2ecf20Sopenharmony_ci	},
7408c2ecf20Sopenharmony_ci	{
7418c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_DEBUG_GET,
7428c2ecf20Sopenharmony_ci		.doit	= ethnl_default_doit,
7438c2ecf20Sopenharmony_ci		.start	= ethnl_default_start,
7448c2ecf20Sopenharmony_ci		.dumpit	= ethnl_default_dumpit,
7458c2ecf20Sopenharmony_ci		.done	= ethnl_default_done,
7468c2ecf20Sopenharmony_ci		.policy = ethnl_debug_get_policy,
7478c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_debug_get_policy) - 1,
7488c2ecf20Sopenharmony_ci	},
7498c2ecf20Sopenharmony_ci	{
7508c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_DEBUG_SET,
7518c2ecf20Sopenharmony_ci		.flags	= GENL_UNS_ADMIN_PERM,
7528c2ecf20Sopenharmony_ci		.doit	= ethnl_set_debug,
7538c2ecf20Sopenharmony_ci		.policy = ethnl_debug_set_policy,
7548c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_debug_set_policy) - 1,
7558c2ecf20Sopenharmony_ci	},
7568c2ecf20Sopenharmony_ci	{
7578c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_WOL_GET,
7588c2ecf20Sopenharmony_ci		.flags	= GENL_UNS_ADMIN_PERM,
7598c2ecf20Sopenharmony_ci		.doit	= ethnl_default_doit,
7608c2ecf20Sopenharmony_ci		.start	= ethnl_default_start,
7618c2ecf20Sopenharmony_ci		.dumpit	= ethnl_default_dumpit,
7628c2ecf20Sopenharmony_ci		.done	= ethnl_default_done,
7638c2ecf20Sopenharmony_ci		.policy = ethnl_wol_get_policy,
7648c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_wol_get_policy) - 1,
7658c2ecf20Sopenharmony_ci	},
7668c2ecf20Sopenharmony_ci	{
7678c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_WOL_SET,
7688c2ecf20Sopenharmony_ci		.flags	= GENL_UNS_ADMIN_PERM,
7698c2ecf20Sopenharmony_ci		.doit	= ethnl_set_wol,
7708c2ecf20Sopenharmony_ci		.policy = ethnl_wol_set_policy,
7718c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_wol_set_policy) - 1,
7728c2ecf20Sopenharmony_ci	},
7738c2ecf20Sopenharmony_ci	{
7748c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_FEATURES_GET,
7758c2ecf20Sopenharmony_ci		.doit	= ethnl_default_doit,
7768c2ecf20Sopenharmony_ci		.start	= ethnl_default_start,
7778c2ecf20Sopenharmony_ci		.dumpit	= ethnl_default_dumpit,
7788c2ecf20Sopenharmony_ci		.done	= ethnl_default_done,
7798c2ecf20Sopenharmony_ci		.policy = ethnl_features_get_policy,
7808c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_features_get_policy) - 1,
7818c2ecf20Sopenharmony_ci	},
7828c2ecf20Sopenharmony_ci	{
7838c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_FEATURES_SET,
7848c2ecf20Sopenharmony_ci		.flags	= GENL_UNS_ADMIN_PERM,
7858c2ecf20Sopenharmony_ci		.doit	= ethnl_set_features,
7868c2ecf20Sopenharmony_ci		.policy = ethnl_features_set_policy,
7878c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_features_set_policy) - 1,
7888c2ecf20Sopenharmony_ci	},
7898c2ecf20Sopenharmony_ci	{
7908c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_PRIVFLAGS_GET,
7918c2ecf20Sopenharmony_ci		.doit	= ethnl_default_doit,
7928c2ecf20Sopenharmony_ci		.start	= ethnl_default_start,
7938c2ecf20Sopenharmony_ci		.dumpit	= ethnl_default_dumpit,
7948c2ecf20Sopenharmony_ci		.done	= ethnl_default_done,
7958c2ecf20Sopenharmony_ci		.policy = ethnl_privflags_get_policy,
7968c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_privflags_get_policy) - 1,
7978c2ecf20Sopenharmony_ci	},
7988c2ecf20Sopenharmony_ci	{
7998c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_PRIVFLAGS_SET,
8008c2ecf20Sopenharmony_ci		.flags	= GENL_UNS_ADMIN_PERM,
8018c2ecf20Sopenharmony_ci		.doit	= ethnl_set_privflags,
8028c2ecf20Sopenharmony_ci		.policy = ethnl_privflags_set_policy,
8038c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_privflags_set_policy) - 1,
8048c2ecf20Sopenharmony_ci	},
8058c2ecf20Sopenharmony_ci	{
8068c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_RINGS_GET,
8078c2ecf20Sopenharmony_ci		.doit	= ethnl_default_doit,
8088c2ecf20Sopenharmony_ci		.start	= ethnl_default_start,
8098c2ecf20Sopenharmony_ci		.dumpit	= ethnl_default_dumpit,
8108c2ecf20Sopenharmony_ci		.done	= ethnl_default_done,
8118c2ecf20Sopenharmony_ci		.policy = ethnl_rings_get_policy,
8128c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_rings_get_policy) - 1,
8138c2ecf20Sopenharmony_ci	},
8148c2ecf20Sopenharmony_ci	{
8158c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_RINGS_SET,
8168c2ecf20Sopenharmony_ci		.flags	= GENL_UNS_ADMIN_PERM,
8178c2ecf20Sopenharmony_ci		.doit	= ethnl_set_rings,
8188c2ecf20Sopenharmony_ci		.policy = ethnl_rings_set_policy,
8198c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_rings_set_policy) - 1,
8208c2ecf20Sopenharmony_ci	},
8218c2ecf20Sopenharmony_ci	{
8228c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_CHANNELS_GET,
8238c2ecf20Sopenharmony_ci		.doit	= ethnl_default_doit,
8248c2ecf20Sopenharmony_ci		.start	= ethnl_default_start,
8258c2ecf20Sopenharmony_ci		.dumpit	= ethnl_default_dumpit,
8268c2ecf20Sopenharmony_ci		.done	= ethnl_default_done,
8278c2ecf20Sopenharmony_ci		.policy = ethnl_channels_get_policy,
8288c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_channels_get_policy) - 1,
8298c2ecf20Sopenharmony_ci	},
8308c2ecf20Sopenharmony_ci	{
8318c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_CHANNELS_SET,
8328c2ecf20Sopenharmony_ci		.flags	= GENL_UNS_ADMIN_PERM,
8338c2ecf20Sopenharmony_ci		.doit	= ethnl_set_channels,
8348c2ecf20Sopenharmony_ci		.policy = ethnl_channels_set_policy,
8358c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_channels_set_policy) - 1,
8368c2ecf20Sopenharmony_ci	},
8378c2ecf20Sopenharmony_ci	{
8388c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_COALESCE_GET,
8398c2ecf20Sopenharmony_ci		.doit	= ethnl_default_doit,
8408c2ecf20Sopenharmony_ci		.start	= ethnl_default_start,
8418c2ecf20Sopenharmony_ci		.dumpit	= ethnl_default_dumpit,
8428c2ecf20Sopenharmony_ci		.done	= ethnl_default_done,
8438c2ecf20Sopenharmony_ci		.policy = ethnl_coalesce_get_policy,
8448c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_coalesce_get_policy) - 1,
8458c2ecf20Sopenharmony_ci	},
8468c2ecf20Sopenharmony_ci	{
8478c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_COALESCE_SET,
8488c2ecf20Sopenharmony_ci		.flags	= GENL_UNS_ADMIN_PERM,
8498c2ecf20Sopenharmony_ci		.doit	= ethnl_set_coalesce,
8508c2ecf20Sopenharmony_ci		.policy = ethnl_coalesce_set_policy,
8518c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_coalesce_set_policy) - 1,
8528c2ecf20Sopenharmony_ci	},
8538c2ecf20Sopenharmony_ci	{
8548c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_PAUSE_GET,
8558c2ecf20Sopenharmony_ci		.doit	= ethnl_default_doit,
8568c2ecf20Sopenharmony_ci		.start	= ethnl_default_start,
8578c2ecf20Sopenharmony_ci		.dumpit	= ethnl_default_dumpit,
8588c2ecf20Sopenharmony_ci		.done	= ethnl_default_done,
8598c2ecf20Sopenharmony_ci		.policy = ethnl_pause_get_policy,
8608c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_pause_get_policy) - 1,
8618c2ecf20Sopenharmony_ci	},
8628c2ecf20Sopenharmony_ci	{
8638c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_PAUSE_SET,
8648c2ecf20Sopenharmony_ci		.flags	= GENL_UNS_ADMIN_PERM,
8658c2ecf20Sopenharmony_ci		.doit	= ethnl_set_pause,
8668c2ecf20Sopenharmony_ci		.policy = ethnl_pause_set_policy,
8678c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_pause_set_policy) - 1,
8688c2ecf20Sopenharmony_ci	},
8698c2ecf20Sopenharmony_ci	{
8708c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_EEE_GET,
8718c2ecf20Sopenharmony_ci		.doit	= ethnl_default_doit,
8728c2ecf20Sopenharmony_ci		.start	= ethnl_default_start,
8738c2ecf20Sopenharmony_ci		.dumpit	= ethnl_default_dumpit,
8748c2ecf20Sopenharmony_ci		.done	= ethnl_default_done,
8758c2ecf20Sopenharmony_ci		.policy = ethnl_eee_get_policy,
8768c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_eee_get_policy) - 1,
8778c2ecf20Sopenharmony_ci	},
8788c2ecf20Sopenharmony_ci	{
8798c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_EEE_SET,
8808c2ecf20Sopenharmony_ci		.flags	= GENL_UNS_ADMIN_PERM,
8818c2ecf20Sopenharmony_ci		.doit	= ethnl_set_eee,
8828c2ecf20Sopenharmony_ci		.policy = ethnl_eee_set_policy,
8838c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_eee_set_policy) - 1,
8848c2ecf20Sopenharmony_ci	},
8858c2ecf20Sopenharmony_ci	{
8868c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_TSINFO_GET,
8878c2ecf20Sopenharmony_ci		.doit	= ethnl_default_doit,
8888c2ecf20Sopenharmony_ci		.start	= ethnl_default_start,
8898c2ecf20Sopenharmony_ci		.dumpit	= ethnl_default_dumpit,
8908c2ecf20Sopenharmony_ci		.done	= ethnl_default_done,
8918c2ecf20Sopenharmony_ci		.policy = ethnl_tsinfo_get_policy,
8928c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_tsinfo_get_policy) - 1,
8938c2ecf20Sopenharmony_ci	},
8948c2ecf20Sopenharmony_ci	{
8958c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_CABLE_TEST_ACT,
8968c2ecf20Sopenharmony_ci		.flags	= GENL_UNS_ADMIN_PERM,
8978c2ecf20Sopenharmony_ci		.doit	= ethnl_act_cable_test,
8988c2ecf20Sopenharmony_ci		.policy = ethnl_cable_test_act_policy,
8998c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_cable_test_act_policy) - 1,
9008c2ecf20Sopenharmony_ci	},
9018c2ecf20Sopenharmony_ci	{
9028c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_CABLE_TEST_TDR_ACT,
9038c2ecf20Sopenharmony_ci		.flags	= GENL_UNS_ADMIN_PERM,
9048c2ecf20Sopenharmony_ci		.doit	= ethnl_act_cable_test_tdr,
9058c2ecf20Sopenharmony_ci		.policy = ethnl_cable_test_tdr_act_policy,
9068c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_cable_test_tdr_act_policy) - 1,
9078c2ecf20Sopenharmony_ci	},
9088c2ecf20Sopenharmony_ci	{
9098c2ecf20Sopenharmony_ci		.cmd	= ETHTOOL_MSG_TUNNEL_INFO_GET,
9108c2ecf20Sopenharmony_ci		.doit	= ethnl_tunnel_info_doit,
9118c2ecf20Sopenharmony_ci		.start	= ethnl_tunnel_info_start,
9128c2ecf20Sopenharmony_ci		.dumpit	= ethnl_tunnel_info_dumpit,
9138c2ecf20Sopenharmony_ci		.policy = ethnl_tunnel_info_get_policy,
9148c2ecf20Sopenharmony_ci		.maxattr = ARRAY_SIZE(ethnl_tunnel_info_get_policy) - 1,
9158c2ecf20Sopenharmony_ci	},
9168c2ecf20Sopenharmony_ci};
9178c2ecf20Sopenharmony_ci
9188c2ecf20Sopenharmony_cistatic const struct genl_multicast_group ethtool_nl_mcgrps[] = {
9198c2ecf20Sopenharmony_ci	[ETHNL_MCGRP_MONITOR] = { .name = ETHTOOL_MCGRP_MONITOR_NAME },
9208c2ecf20Sopenharmony_ci};
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_cistatic struct genl_family ethtool_genl_family __ro_after_init = {
9238c2ecf20Sopenharmony_ci	.name		= ETHTOOL_GENL_NAME,
9248c2ecf20Sopenharmony_ci	.version	= ETHTOOL_GENL_VERSION,
9258c2ecf20Sopenharmony_ci	.netnsok	= true,
9268c2ecf20Sopenharmony_ci	.parallel_ops	= true,
9278c2ecf20Sopenharmony_ci	.ops		= ethtool_genl_ops,
9288c2ecf20Sopenharmony_ci	.n_ops		= ARRAY_SIZE(ethtool_genl_ops),
9298c2ecf20Sopenharmony_ci	.mcgrps		= ethtool_nl_mcgrps,
9308c2ecf20Sopenharmony_ci	.n_mcgrps	= ARRAY_SIZE(ethtool_nl_mcgrps),
9318c2ecf20Sopenharmony_ci};
9328c2ecf20Sopenharmony_ci
9338c2ecf20Sopenharmony_ci/* module setup */
9348c2ecf20Sopenharmony_ci
9358c2ecf20Sopenharmony_cistatic int __init ethnl_init(void)
9368c2ecf20Sopenharmony_ci{
9378c2ecf20Sopenharmony_ci	int ret;
9388c2ecf20Sopenharmony_ci
9398c2ecf20Sopenharmony_ci	ret = genl_register_family(&ethtool_genl_family);
9408c2ecf20Sopenharmony_ci	if (WARN(ret < 0, "ethtool: genetlink family registration failed"))
9418c2ecf20Sopenharmony_ci		return ret;
9428c2ecf20Sopenharmony_ci	ethnl_ok = true;
9438c2ecf20Sopenharmony_ci
9448c2ecf20Sopenharmony_ci	ret = register_netdevice_notifier(&ethnl_netdev_notifier);
9458c2ecf20Sopenharmony_ci	WARN(ret < 0, "ethtool: net device notifier registration failed");
9468c2ecf20Sopenharmony_ci	return ret;
9478c2ecf20Sopenharmony_ci}
9488c2ecf20Sopenharmony_ci
9498c2ecf20Sopenharmony_cisubsys_initcall(ethnl_init);
950