Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include "netlink.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include "common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include "bitset.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) struct features_req_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 	struct ethnl_req_info	base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) struct features_reply_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 	struct ethnl_reply_data	base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 	u32			hw[ETHTOOL_DEV_FEATURE_WORDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	u32			wanted[ETHTOOL_DEV_FEATURE_WORDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	u32			active[ETHTOOL_DEV_FEATURE_WORDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	u32			nochange[ETHTOOL_DEV_FEATURE_WORDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	u32			all[ETHTOOL_DEV_FEATURE_WORDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define FEATURES_REPDATA(__reply_base) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	container_of(__reply_base, struct features_reply_data, base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) const struct nla_policy ethnl_features_get_policy[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	[ETHTOOL_A_FEATURES_HEADER]	=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		NLA_POLICY_NESTED(ethnl_header_policy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static void ethnl_features_to_bitmap32(u32 *dest, netdev_features_t src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		dest[i] = src >> (32 * i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static int features_prepare_data(const struct ethnl_req_info *req_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 				 struct ethnl_reply_data *reply_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 				 struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct features_reply_data *data = FEATURES_REPDATA(reply_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct net_device *dev = reply_base->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	netdev_features_t all_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	ethnl_features_to_bitmap32(data->hw, dev->hw_features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	ethnl_features_to_bitmap32(data->wanted, dev->wanted_features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	ethnl_features_to_bitmap32(data->active, dev->features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	ethnl_features_to_bitmap32(data->nochange, NETIF_F_NEVER_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	all_features = GENMASK_ULL(NETDEV_FEATURE_COUNT - 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	ethnl_features_to_bitmap32(data->all, all_features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static int features_reply_size(const struct ethnl_req_info *req_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			       const struct ethnl_reply_data *reply_base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	const struct features_reply_data *data = FEATURES_REPDATA(reply_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	bool compact = req_base->flags & ETHTOOL_FLAG_COMPACT_BITSETS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	unsigned int len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	ret = ethnl_bitset32_size(data->hw, data->all, NETDEV_FEATURE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 				  netdev_features_strings, compact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	len += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	ret = ethnl_bitset32_size(data->wanted, NULL, NETDEV_FEATURE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 				  netdev_features_strings, compact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	len += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	ret = ethnl_bitset32_size(data->active, NULL, NETDEV_FEATURE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 				  netdev_features_strings, compact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	len += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	ret = ethnl_bitset32_size(data->nochange, NULL, NETDEV_FEATURE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 				  netdev_features_strings, compact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	len += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static int features_fill_reply(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			       const struct ethnl_req_info *req_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			       const struct ethnl_reply_data *reply_base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	const struct features_reply_data *data = FEATURES_REPDATA(reply_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	bool compact = req_base->flags & ETHTOOL_FLAG_COMPACT_BITSETS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	ret = ethnl_put_bitset32(skb, ETHTOOL_A_FEATURES_HW, data->hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 				 data->all, NETDEV_FEATURE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 				 netdev_features_strings, compact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	ret = ethnl_put_bitset32(skb, ETHTOOL_A_FEATURES_WANTED, data->wanted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				 NULL, NETDEV_FEATURE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 				 netdev_features_strings, compact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	ret = ethnl_put_bitset32(skb, ETHTOOL_A_FEATURES_ACTIVE, data->active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 				 NULL, NETDEV_FEATURE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 				 netdev_features_strings, compact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	return ethnl_put_bitset32(skb, ETHTOOL_A_FEATURES_NOCHANGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 				  data->nochange, NULL, NETDEV_FEATURE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 				  netdev_features_strings, compact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) const struct ethnl_request_ops ethnl_features_request_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	.request_cmd		= ETHTOOL_MSG_FEATURES_GET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	.reply_cmd		= ETHTOOL_MSG_FEATURES_GET_REPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	.hdr_attr		= ETHTOOL_A_FEATURES_HEADER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	.req_info_size		= sizeof(struct features_req_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.reply_data_size	= sizeof(struct features_reply_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	.prepare_data		= features_prepare_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	.reply_size		= features_reply_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	.fill_reply		= features_fill_reply,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /* FEATURES_SET */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) const struct nla_policy ethnl_features_set_policy[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	[ETHTOOL_A_FEATURES_HEADER]	=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		NLA_POLICY_NESTED(ethnl_header_policy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	[ETHTOOL_A_FEATURES_WANTED]	= { .type = NLA_NESTED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static void ethnl_features_to_bitmap(unsigned long *dest, netdev_features_t val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	const unsigned int words = BITS_TO_LONGS(NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	bitmap_zero(dest, NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	for (i = 0; i < words; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		dest[i] = (unsigned long)(val >> (i * BITS_PER_LONG));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static netdev_features_t ethnl_bitmap_to_features(unsigned long *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	const unsigned int nft_bits = sizeof(netdev_features_t) * BITS_PER_BYTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	const unsigned int words = BITS_TO_LONGS(NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	netdev_features_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	for (i = 0; i < words; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		ret |= (netdev_features_t)(src[i]) << (i * BITS_PER_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	ret &= ~(netdev_features_t)0 >> (nft_bits - NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static int features_send_reply(struct net_device *dev, struct genl_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			       const unsigned long *wanted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			       const unsigned long *wanted_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			       const unsigned long *active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			       const unsigned long *active_mask, bool compact)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct sk_buff *rskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	void *reply_payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	int reply_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	reply_len = ethnl_reply_header_size();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	ret = ethnl_bitset_size(wanted, wanted_mask, NETDEV_FEATURE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 				netdev_features_strings, compact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	reply_len += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	ret = ethnl_bitset_size(active, active_mask, NETDEV_FEATURE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 				netdev_features_strings, compact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	reply_len += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	rskb = ethnl_reply_init(reply_len, dev, ETHTOOL_MSG_FEATURES_SET_REPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 				ETHTOOL_A_FEATURES_HEADER, info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 				&reply_payload);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (!rskb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	ret = ethnl_put_bitset(rskb, ETHTOOL_A_FEATURES_WANTED, wanted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			       wanted_mask, NETDEV_FEATURE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			       netdev_features_strings, compact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	ret = ethnl_put_bitset(rskb, ETHTOOL_A_FEATURES_ACTIVE, active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			       active_mask, NETDEV_FEATURE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			       netdev_features_strings, compact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	genlmsg_end(rskb, reply_payload);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	ret = genlmsg_reply(rskb, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	nlmsg_free(rskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	WARN_ONCE(1, "calculated message payload length (%d) not sufficient\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		  reply_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	GENL_SET_ERR_MSG(info, "failed to send reply message");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int ethnl_set_features(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	DECLARE_BITMAP(wanted_diff_mask, NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	DECLARE_BITMAP(active_diff_mask, NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	DECLARE_BITMAP(old_active, NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	DECLARE_BITMAP(old_wanted, NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	DECLARE_BITMAP(new_active, NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	DECLARE_BITMAP(new_wanted, NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	DECLARE_BITMAP(req_wanted, NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	DECLARE_BITMAP(req_mask, NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	struct ethnl_req_info req_info = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct nlattr **tb = info->attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	bool mod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (!tb[ETHTOOL_A_FEATURES_WANTED])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	ret = ethnl_parse_header_dev_get(&req_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 					 tb[ETHTOOL_A_FEATURES_HEADER],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 					 genl_info_net(info), info->extack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 					 true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	dev = req_info.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	ethnl_features_to_bitmap(old_active, dev->features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	ethnl_features_to_bitmap(old_wanted, dev->wanted_features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	ret = ethnl_parse_bitset(req_wanted, req_mask, NETDEV_FEATURE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 				 tb[ETHTOOL_A_FEATURES_WANTED],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				 netdev_features_strings, info->extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		goto out_rtnl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	if (ethnl_bitmap_to_features(req_mask) & ~NETIF_F_ETHTOOL_BITS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		GENL_SET_ERR_MSG(info, "attempt to change non-ethtool features");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		goto out_rtnl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	/* set req_wanted bits not in req_mask from old_wanted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	bitmap_and(req_wanted, req_wanted, req_mask, NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	bitmap_andnot(new_wanted, old_wanted, req_mask, NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	bitmap_or(req_wanted, new_wanted, req_wanted, NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (!bitmap_equal(req_wanted, old_wanted, NETDEV_FEATURE_COUNT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		dev->wanted_features &= ~dev->hw_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		dev->wanted_features |= ethnl_bitmap_to_features(req_wanted) & dev->hw_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		__netdev_update_features(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	ethnl_features_to_bitmap(new_active, dev->features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	mod = !bitmap_equal(old_active, new_active, NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (!(req_info.flags & ETHTOOL_FLAG_OMIT_REPLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		bool compact = req_info.flags & ETHTOOL_FLAG_COMPACT_BITSETS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		bitmap_xor(wanted_diff_mask, req_wanted, new_active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			   NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		bitmap_xor(active_diff_mask, old_active, new_active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			   NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		bitmap_and(wanted_diff_mask, wanted_diff_mask, req_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			   NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		bitmap_and(req_wanted, req_wanted, wanted_diff_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			   NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		bitmap_and(new_active, new_active, active_diff_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			   NETDEV_FEATURE_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		ret = features_send_reply(dev, info, req_wanted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 					  wanted_diff_mask, new_active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 					  active_diff_mask, compact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (mod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		netdev_features_change(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) out_rtnl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }