xref: /OK3568_Linux_fs/kernel/net/ethtool/coalesce.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun 
3*4882a593Smuzhiyun #include "netlink.h"
4*4882a593Smuzhiyun #include "common.h"
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun struct coalesce_req_info {
7*4882a593Smuzhiyun 	struct ethnl_req_info		base;
8*4882a593Smuzhiyun };
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun struct coalesce_reply_data {
11*4882a593Smuzhiyun 	struct ethnl_reply_data		base;
12*4882a593Smuzhiyun 	struct ethtool_coalesce		coalesce;
13*4882a593Smuzhiyun 	u32				supported_params;
14*4882a593Smuzhiyun };
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #define COALESCE_REPDATA(__reply_base) \
17*4882a593Smuzhiyun 	container_of(__reply_base, struct coalesce_reply_data, base)
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #define __SUPPORTED_OFFSET ETHTOOL_A_COALESCE_RX_USECS
attr_to_mask(unsigned int attr_type)20*4882a593Smuzhiyun static u32 attr_to_mask(unsigned int attr_type)
21*4882a593Smuzhiyun {
22*4882a593Smuzhiyun 	return BIT(attr_type - __SUPPORTED_OFFSET);
23*4882a593Smuzhiyun }
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /* build time check that indices in ethtool_ops::supported_coalesce_params
26*4882a593Smuzhiyun  * match corresponding attribute types with an offset
27*4882a593Smuzhiyun  */
28*4882a593Smuzhiyun #define __CHECK_SUPPORTED_OFFSET(x) \
29*4882a593Smuzhiyun 	static_assert((ETHTOOL_ ## x) == \
30*4882a593Smuzhiyun 		      BIT((ETHTOOL_A_ ## x) - __SUPPORTED_OFFSET))
31*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_RX_USECS);
32*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_RX_MAX_FRAMES);
33*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_RX_USECS_IRQ);
34*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_RX_MAX_FRAMES_IRQ);
35*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_TX_USECS);
36*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_TX_MAX_FRAMES);
37*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_TX_USECS_IRQ);
38*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_TX_MAX_FRAMES_IRQ);
39*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_STATS_BLOCK_USECS);
40*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_USE_ADAPTIVE_RX);
41*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_USE_ADAPTIVE_TX);
42*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_PKT_RATE_LOW);
43*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_RX_USECS_LOW);
44*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_RX_MAX_FRAMES_LOW);
45*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_TX_USECS_LOW);
46*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_TX_MAX_FRAMES_LOW);
47*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_PKT_RATE_HIGH);
48*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_RX_USECS_HIGH);
49*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_RX_MAX_FRAMES_HIGH);
50*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_TX_USECS_HIGH);
51*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_TX_MAX_FRAMES_HIGH);
52*4882a593Smuzhiyun __CHECK_SUPPORTED_OFFSET(COALESCE_RATE_SAMPLE_INTERVAL);
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun const struct nla_policy ethnl_coalesce_get_policy[] = {
55*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_HEADER]		=
56*4882a593Smuzhiyun 		NLA_POLICY_NESTED(ethnl_header_policy),
57*4882a593Smuzhiyun };
58*4882a593Smuzhiyun 
coalesce_prepare_data(const struct ethnl_req_info * req_base,struct ethnl_reply_data * reply_base,struct genl_info * info)59*4882a593Smuzhiyun static int coalesce_prepare_data(const struct ethnl_req_info *req_base,
60*4882a593Smuzhiyun 				 struct ethnl_reply_data *reply_base,
61*4882a593Smuzhiyun 				 struct genl_info *info)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun 	struct coalesce_reply_data *data = COALESCE_REPDATA(reply_base);
64*4882a593Smuzhiyun 	struct net_device *dev = reply_base->dev;
65*4882a593Smuzhiyun 	int ret;
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun 	if (!dev->ethtool_ops->get_coalesce)
68*4882a593Smuzhiyun 		return -EOPNOTSUPP;
69*4882a593Smuzhiyun 	data->supported_params = dev->ethtool_ops->supported_coalesce_params;
70*4882a593Smuzhiyun 	ret = ethnl_ops_begin(dev);
71*4882a593Smuzhiyun 	if (ret < 0)
72*4882a593Smuzhiyun 		return ret;
73*4882a593Smuzhiyun 	ret = dev->ethtool_ops->get_coalesce(dev, &data->coalesce);
74*4882a593Smuzhiyun 	ethnl_ops_complete(dev);
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 	return ret;
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun 
coalesce_reply_size(const struct ethnl_req_info * req_base,const struct ethnl_reply_data * reply_base)79*4882a593Smuzhiyun static int coalesce_reply_size(const struct ethnl_req_info *req_base,
80*4882a593Smuzhiyun 			       const struct ethnl_reply_data *reply_base)
81*4882a593Smuzhiyun {
82*4882a593Smuzhiyun 	return nla_total_size(sizeof(u32)) +	/* _RX_USECS */
83*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _RX_MAX_FRAMES */
84*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _RX_USECS_IRQ */
85*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _RX_MAX_FRAMES_IRQ */
86*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _TX_USECS */
87*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _TX_MAX_FRAMES */
88*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _TX_USECS_IRQ */
89*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _TX_MAX_FRAMES_IRQ */
90*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _STATS_BLOCK_USECS */
91*4882a593Smuzhiyun 	       nla_total_size(sizeof(u8)) +	/* _USE_ADAPTIVE_RX */
92*4882a593Smuzhiyun 	       nla_total_size(sizeof(u8)) +	/* _USE_ADAPTIVE_TX */
93*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _PKT_RATE_LOW */
94*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _RX_USECS_LOW */
95*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _RX_MAX_FRAMES_LOW */
96*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _TX_USECS_LOW */
97*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _TX_MAX_FRAMES_LOW */
98*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _PKT_RATE_HIGH */
99*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _RX_USECS_HIGH */
100*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _RX_MAX_FRAMES_HIGH */
101*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _TX_USECS_HIGH */
102*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32)) +	/* _TX_MAX_FRAMES_HIGH */
103*4882a593Smuzhiyun 	       nla_total_size(sizeof(u32));	/* _RATE_SAMPLE_INTERVAL */
104*4882a593Smuzhiyun }
105*4882a593Smuzhiyun 
coalesce_put_u32(struct sk_buff * skb,u16 attr_type,u32 val,u32 supported_params)106*4882a593Smuzhiyun static bool coalesce_put_u32(struct sk_buff *skb, u16 attr_type, u32 val,
107*4882a593Smuzhiyun 			     u32 supported_params)
108*4882a593Smuzhiyun {
109*4882a593Smuzhiyun 	if (!val && !(supported_params & attr_to_mask(attr_type)))
110*4882a593Smuzhiyun 		return false;
111*4882a593Smuzhiyun 	return nla_put_u32(skb, attr_type, val);
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun 
coalesce_put_bool(struct sk_buff * skb,u16 attr_type,u32 val,u32 supported_params)114*4882a593Smuzhiyun static bool coalesce_put_bool(struct sk_buff *skb, u16 attr_type, u32 val,
115*4882a593Smuzhiyun 			      u32 supported_params)
116*4882a593Smuzhiyun {
117*4882a593Smuzhiyun 	if (!val && !(supported_params & attr_to_mask(attr_type)))
118*4882a593Smuzhiyun 		return false;
119*4882a593Smuzhiyun 	return nla_put_u8(skb, attr_type, !!val);
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun 
coalesce_fill_reply(struct sk_buff * skb,const struct ethnl_req_info * req_base,const struct ethnl_reply_data * reply_base)122*4882a593Smuzhiyun static int coalesce_fill_reply(struct sk_buff *skb,
123*4882a593Smuzhiyun 			       const struct ethnl_req_info *req_base,
124*4882a593Smuzhiyun 			       const struct ethnl_reply_data *reply_base)
125*4882a593Smuzhiyun {
126*4882a593Smuzhiyun 	const struct coalesce_reply_data *data = COALESCE_REPDATA(reply_base);
127*4882a593Smuzhiyun 	const struct ethtool_coalesce *coal = &data->coalesce;
128*4882a593Smuzhiyun 	u32 supported = data->supported_params;
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun 	if (coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_USECS,
131*4882a593Smuzhiyun 			     coal->rx_coalesce_usecs, supported) ||
132*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_MAX_FRAMES,
133*4882a593Smuzhiyun 			     coal->rx_max_coalesced_frames, supported) ||
134*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_USECS_IRQ,
135*4882a593Smuzhiyun 			     coal->rx_coalesce_usecs_irq, supported) ||
136*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_MAX_FRAMES_IRQ,
137*4882a593Smuzhiyun 			     coal->rx_max_coalesced_frames_irq, supported) ||
138*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_USECS,
139*4882a593Smuzhiyun 			     coal->tx_coalesce_usecs, supported) ||
140*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_MAX_FRAMES,
141*4882a593Smuzhiyun 			     coal->tx_max_coalesced_frames, supported) ||
142*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_USECS_IRQ,
143*4882a593Smuzhiyun 			     coal->tx_coalesce_usecs_irq, supported) ||
144*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_MAX_FRAMES_IRQ,
145*4882a593Smuzhiyun 			     coal->tx_max_coalesced_frames_irq, supported) ||
146*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_STATS_BLOCK_USECS,
147*4882a593Smuzhiyun 			     coal->stats_block_coalesce_usecs, supported) ||
148*4882a593Smuzhiyun 	    coalesce_put_bool(skb, ETHTOOL_A_COALESCE_USE_ADAPTIVE_RX,
149*4882a593Smuzhiyun 			      coal->use_adaptive_rx_coalesce, supported) ||
150*4882a593Smuzhiyun 	    coalesce_put_bool(skb, ETHTOOL_A_COALESCE_USE_ADAPTIVE_TX,
151*4882a593Smuzhiyun 			      coal->use_adaptive_tx_coalesce, supported) ||
152*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_PKT_RATE_LOW,
153*4882a593Smuzhiyun 			     coal->pkt_rate_low, supported) ||
154*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_USECS_LOW,
155*4882a593Smuzhiyun 			     coal->rx_coalesce_usecs_low, supported) ||
156*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_MAX_FRAMES_LOW,
157*4882a593Smuzhiyun 			     coal->rx_max_coalesced_frames_low, supported) ||
158*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_USECS_LOW,
159*4882a593Smuzhiyun 			     coal->tx_coalesce_usecs_low, supported) ||
160*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_MAX_FRAMES_LOW,
161*4882a593Smuzhiyun 			     coal->tx_max_coalesced_frames_low, supported) ||
162*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_PKT_RATE_HIGH,
163*4882a593Smuzhiyun 			     coal->pkt_rate_high, supported) ||
164*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_USECS_HIGH,
165*4882a593Smuzhiyun 			     coal->rx_coalesce_usecs_high, supported) ||
166*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RX_MAX_FRAMES_HIGH,
167*4882a593Smuzhiyun 			     coal->rx_max_coalesced_frames_high, supported) ||
168*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_USECS_HIGH,
169*4882a593Smuzhiyun 			     coal->tx_coalesce_usecs_high, supported) ||
170*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH,
171*4882a593Smuzhiyun 			     coal->tx_max_coalesced_frames_high, supported) ||
172*4882a593Smuzhiyun 	    coalesce_put_u32(skb, ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL,
173*4882a593Smuzhiyun 			     coal->rate_sample_interval, supported))
174*4882a593Smuzhiyun 		return -EMSGSIZE;
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun 	return 0;
177*4882a593Smuzhiyun }
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun const struct ethnl_request_ops ethnl_coalesce_request_ops = {
180*4882a593Smuzhiyun 	.request_cmd		= ETHTOOL_MSG_COALESCE_GET,
181*4882a593Smuzhiyun 	.reply_cmd		= ETHTOOL_MSG_COALESCE_GET_REPLY,
182*4882a593Smuzhiyun 	.hdr_attr		= ETHTOOL_A_COALESCE_HEADER,
183*4882a593Smuzhiyun 	.req_info_size		= sizeof(struct coalesce_req_info),
184*4882a593Smuzhiyun 	.reply_data_size	= sizeof(struct coalesce_reply_data),
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun 	.prepare_data		= coalesce_prepare_data,
187*4882a593Smuzhiyun 	.reply_size		= coalesce_reply_size,
188*4882a593Smuzhiyun 	.fill_reply		= coalesce_fill_reply,
189*4882a593Smuzhiyun };
190*4882a593Smuzhiyun 
191*4882a593Smuzhiyun /* COALESCE_SET */
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun const struct nla_policy ethnl_coalesce_set_policy[] = {
194*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_HEADER]		=
195*4882a593Smuzhiyun 		NLA_POLICY_NESTED(ethnl_header_policy),
196*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_RX_USECS]		= { .type = NLA_U32 },
197*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_RX_MAX_FRAMES]	= { .type = NLA_U32 },
198*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_RX_USECS_IRQ]	= { .type = NLA_U32 },
199*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_IRQ]	= { .type = NLA_U32 },
200*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_TX_USECS]		= { .type = NLA_U32 },
201*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_TX_MAX_FRAMES]	= { .type = NLA_U32 },
202*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_TX_USECS_IRQ]	= { .type = NLA_U32 },
203*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_IRQ]	= { .type = NLA_U32 },
204*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_STATS_BLOCK_USECS]	= { .type = NLA_U32 },
205*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_USE_ADAPTIVE_RX]	= { .type = NLA_U8 },
206*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_USE_ADAPTIVE_TX]	= { .type = NLA_U8 },
207*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_PKT_RATE_LOW]	= { .type = NLA_U32 },
208*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_RX_USECS_LOW]	= { .type = NLA_U32 },
209*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_LOW]	= { .type = NLA_U32 },
210*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_TX_USECS_LOW]	= { .type = NLA_U32 },
211*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_LOW]	= { .type = NLA_U32 },
212*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_PKT_RATE_HIGH]	= { .type = NLA_U32 },
213*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_RX_USECS_HIGH]	= { .type = NLA_U32 },
214*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_HIGH]	= { .type = NLA_U32 },
215*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_TX_USECS_HIGH]	= { .type = NLA_U32 },
216*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH]	= { .type = NLA_U32 },
217*4882a593Smuzhiyun 	[ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL] = { .type = NLA_U32 },
218*4882a593Smuzhiyun };
219*4882a593Smuzhiyun 
ethnl_set_coalesce(struct sk_buff * skb,struct genl_info * info)220*4882a593Smuzhiyun int ethnl_set_coalesce(struct sk_buff *skb, struct genl_info *info)
221*4882a593Smuzhiyun {
222*4882a593Smuzhiyun 	struct ethtool_coalesce coalesce = {};
223*4882a593Smuzhiyun 	struct ethnl_req_info req_info = {};
224*4882a593Smuzhiyun 	struct nlattr **tb = info->attrs;
225*4882a593Smuzhiyun 	const struct ethtool_ops *ops;
226*4882a593Smuzhiyun 	struct net_device *dev;
227*4882a593Smuzhiyun 	u32 supported_params;
228*4882a593Smuzhiyun 	bool mod = false;
229*4882a593Smuzhiyun 	int ret;
230*4882a593Smuzhiyun 	u16 a;
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun 	ret = ethnl_parse_header_dev_get(&req_info,
233*4882a593Smuzhiyun 					 tb[ETHTOOL_A_COALESCE_HEADER],
234*4882a593Smuzhiyun 					 genl_info_net(info), info->extack,
235*4882a593Smuzhiyun 					 true);
236*4882a593Smuzhiyun 	if (ret < 0)
237*4882a593Smuzhiyun 		return ret;
238*4882a593Smuzhiyun 	dev = req_info.dev;
239*4882a593Smuzhiyun 	ops = dev->ethtool_ops;
240*4882a593Smuzhiyun 	ret = -EOPNOTSUPP;
241*4882a593Smuzhiyun 	if (!ops->get_coalesce || !ops->set_coalesce)
242*4882a593Smuzhiyun 		goto out_dev;
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun 	/* make sure that only supported parameters are present */
245*4882a593Smuzhiyun 	supported_params = ops->supported_coalesce_params;
246*4882a593Smuzhiyun 	for (a = ETHTOOL_A_COALESCE_RX_USECS; a < __ETHTOOL_A_COALESCE_CNT; a++)
247*4882a593Smuzhiyun 		if (tb[a] && !(supported_params & attr_to_mask(a))) {
248*4882a593Smuzhiyun 			ret = -EINVAL;
249*4882a593Smuzhiyun 			NL_SET_ERR_MSG_ATTR(info->extack, tb[a],
250*4882a593Smuzhiyun 					    "cannot modify an unsupported parameter");
251*4882a593Smuzhiyun 			goto out_dev;
252*4882a593Smuzhiyun 		}
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun 	rtnl_lock();
255*4882a593Smuzhiyun 	ret = ethnl_ops_begin(dev);
256*4882a593Smuzhiyun 	if (ret < 0)
257*4882a593Smuzhiyun 		goto out_rtnl;
258*4882a593Smuzhiyun 	ret = ops->get_coalesce(dev, &coalesce);
259*4882a593Smuzhiyun 	if (ret < 0)
260*4882a593Smuzhiyun 		goto out_ops;
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.rx_coalesce_usecs,
263*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_RX_USECS], &mod);
264*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.rx_max_coalesced_frames,
265*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES], &mod);
266*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.rx_coalesce_usecs_irq,
267*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_RX_USECS_IRQ], &mod);
268*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.rx_max_coalesced_frames_irq,
269*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_IRQ], &mod);
270*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.tx_coalesce_usecs,
271*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_TX_USECS], &mod);
272*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.tx_max_coalesced_frames,
273*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES], &mod);
274*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.tx_coalesce_usecs_irq,
275*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_TX_USECS_IRQ], &mod);
276*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.tx_max_coalesced_frames_irq,
277*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_IRQ], &mod);
278*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.stats_block_coalesce_usecs,
279*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_STATS_BLOCK_USECS], &mod);
280*4882a593Smuzhiyun 	ethnl_update_bool32(&coalesce.use_adaptive_rx_coalesce,
281*4882a593Smuzhiyun 			    tb[ETHTOOL_A_COALESCE_USE_ADAPTIVE_RX], &mod);
282*4882a593Smuzhiyun 	ethnl_update_bool32(&coalesce.use_adaptive_tx_coalesce,
283*4882a593Smuzhiyun 			    tb[ETHTOOL_A_COALESCE_USE_ADAPTIVE_TX], &mod);
284*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.pkt_rate_low,
285*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_PKT_RATE_LOW], &mod);
286*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.rx_coalesce_usecs_low,
287*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_RX_USECS_LOW], &mod);
288*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.rx_max_coalesced_frames_low,
289*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_LOW], &mod);
290*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.tx_coalesce_usecs_low,
291*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_TX_USECS_LOW], &mod);
292*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.tx_max_coalesced_frames_low,
293*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_LOW], &mod);
294*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.pkt_rate_high,
295*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_PKT_RATE_HIGH], &mod);
296*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.rx_coalesce_usecs_high,
297*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_RX_USECS_HIGH], &mod);
298*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.rx_max_coalesced_frames_high,
299*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_HIGH], &mod);
300*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.tx_coalesce_usecs_high,
301*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_TX_USECS_HIGH], &mod);
302*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.tx_max_coalesced_frames_high,
303*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH], &mod);
304*4882a593Smuzhiyun 	ethnl_update_u32(&coalesce.rate_sample_interval,
305*4882a593Smuzhiyun 			 tb[ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL], &mod);
306*4882a593Smuzhiyun 	ret = 0;
307*4882a593Smuzhiyun 	if (!mod)
308*4882a593Smuzhiyun 		goto out_ops;
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun 	ret = dev->ethtool_ops->set_coalesce(dev, &coalesce);
311*4882a593Smuzhiyun 	if (ret < 0)
312*4882a593Smuzhiyun 		goto out_ops;
313*4882a593Smuzhiyun 	ethtool_notify(dev, ETHTOOL_MSG_COALESCE_NTF, NULL);
314*4882a593Smuzhiyun 
315*4882a593Smuzhiyun out_ops:
316*4882a593Smuzhiyun 	ethnl_ops_complete(dev);
317*4882a593Smuzhiyun out_rtnl:
318*4882a593Smuzhiyun 	rtnl_unlock();
319*4882a593Smuzhiyun out_dev:
320*4882a593Smuzhiyun 	dev_put(dev);
321*4882a593Smuzhiyun 	return ret;
322*4882a593Smuzhiyun }
323