]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - net/core/ethtool.c
net/ethtool: introduce a new ioctl for per queue setting
[mirror_ubuntu-bionic-kernel.git] / net / core / ethtool.c
1 /*
2 * net/core/ethtool.c - Ethtool ioctl handler
3 * Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx>
4 *
5 * This file is where we call all the ethtool_ops commands to get
6 * the information ethtool needs.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/capability.h>
17 #include <linux/errno.h>
18 #include <linux/ethtool.h>
19 #include <linux/netdevice.h>
20 #include <linux/net_tstamp.h>
21 #include <linux/phy.h>
22 #include <linux/bitops.h>
23 #include <linux/uaccess.h>
24 #include <linux/vmalloc.h>
25 #include <linux/slab.h>
26 #include <linux/rtnetlink.h>
27 #include <linux/sched.h>
28 #include <linux/net.h>
29
30 /*
31 * Some useful ethtool_ops methods that're device independent.
32 * If we find that all drivers want to do the same thing here,
33 * we can turn these into dev_() function calls.
34 */
35
36 u32 ethtool_op_get_link(struct net_device *dev)
37 {
38 return netif_carrier_ok(dev) ? 1 : 0;
39 }
40 EXPORT_SYMBOL(ethtool_op_get_link);
41
42 int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
43 {
44 info->so_timestamping =
45 SOF_TIMESTAMPING_TX_SOFTWARE |
46 SOF_TIMESTAMPING_RX_SOFTWARE |
47 SOF_TIMESTAMPING_SOFTWARE;
48 info->phc_index = -1;
49 return 0;
50 }
51 EXPORT_SYMBOL(ethtool_op_get_ts_info);
52
53 /* Handlers for each ethtool command */
54
55 #define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32)
56
57 static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = {
58 [NETIF_F_SG_BIT] = "tx-scatter-gather",
59 [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4",
60 [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic",
61 [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6",
62 [NETIF_F_HIGHDMA_BIT] = "highdma",
63 [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist",
64 [NETIF_F_HW_VLAN_CTAG_TX_BIT] = "tx-vlan-hw-insert",
65
66 [NETIF_F_HW_VLAN_CTAG_RX_BIT] = "rx-vlan-hw-parse",
67 [NETIF_F_HW_VLAN_CTAG_FILTER_BIT] = "rx-vlan-filter",
68 [NETIF_F_HW_VLAN_STAG_TX_BIT] = "tx-vlan-stag-hw-insert",
69 [NETIF_F_HW_VLAN_STAG_RX_BIT] = "rx-vlan-stag-hw-parse",
70 [NETIF_F_HW_VLAN_STAG_FILTER_BIT] = "rx-vlan-stag-filter",
71 [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged",
72 [NETIF_F_GSO_BIT] = "tx-generic-segmentation",
73 [NETIF_F_LLTX_BIT] = "tx-lockless",
74 [NETIF_F_NETNS_LOCAL_BIT] = "netns-local",
75 [NETIF_F_GRO_BIT] = "rx-gro",
76 [NETIF_F_LRO_BIT] = "rx-lro",
77
78 [NETIF_F_TSO_BIT] = "tx-tcp-segmentation",
79 [NETIF_F_UFO_BIT] = "tx-udp-fragmentation",
80 [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust",
81 [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation",
82 [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation",
83 [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation",
84 [NETIF_F_GSO_GRE_BIT] = "tx-gre-segmentation",
85 [NETIF_F_GSO_IPIP_BIT] = "tx-ipip-segmentation",
86 [NETIF_F_GSO_SIT_BIT] = "tx-sit-segmentation",
87 [NETIF_F_GSO_UDP_TUNNEL_BIT] = "tx-udp_tnl-segmentation",
88
89 [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc",
90 [NETIF_F_SCTP_CRC_BIT] = "tx-checksum-sctp",
91 [NETIF_F_FCOE_MTU_BIT] = "fcoe-mtu",
92 [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter",
93 [NETIF_F_RXHASH_BIT] = "rx-hashing",
94 [NETIF_F_RXCSUM_BIT] = "rx-checksum",
95 [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy",
96 [NETIF_F_LOOPBACK_BIT] = "loopback",
97 [NETIF_F_RXFCS_BIT] = "rx-fcs",
98 [NETIF_F_RXALL_BIT] = "rx-all",
99 [NETIF_F_HW_L2FW_DOFFLOAD_BIT] = "l2-fwd-offload",
100 [NETIF_F_BUSY_POLL_BIT] = "busy-poll",
101 [NETIF_F_HW_TC_BIT] = "hw-tc-offload",
102 };
103
104 static const char
105 rss_hash_func_strings[ETH_RSS_HASH_FUNCS_COUNT][ETH_GSTRING_LEN] = {
106 [ETH_RSS_HASH_TOP_BIT] = "toeplitz",
107 [ETH_RSS_HASH_XOR_BIT] = "xor",
108 };
109
110 static const char
111 tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN] = {
112 [ETHTOOL_ID_UNSPEC] = "Unspec",
113 [ETHTOOL_RX_COPYBREAK] = "rx-copybreak",
114 [ETHTOOL_TX_COPYBREAK] = "tx-copybreak",
115 };
116
117 static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
118 {
119 struct ethtool_gfeatures cmd = {
120 .cmd = ETHTOOL_GFEATURES,
121 .size = ETHTOOL_DEV_FEATURE_WORDS,
122 };
123 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
124 u32 __user *sizeaddr;
125 u32 copy_size;
126 int i;
127
128 /* in case feature bits run out again */
129 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
130
131 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
132 features[i].available = (u32)(dev->hw_features >> (32 * i));
133 features[i].requested = (u32)(dev->wanted_features >> (32 * i));
134 features[i].active = (u32)(dev->features >> (32 * i));
135 features[i].never_changed =
136 (u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
137 }
138
139 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
140 if (get_user(copy_size, sizeaddr))
141 return -EFAULT;
142
143 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
144 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
145
146 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
147 return -EFAULT;
148 useraddr += sizeof(cmd);
149 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
150 return -EFAULT;
151
152 return 0;
153 }
154
155 static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
156 {
157 struct ethtool_sfeatures cmd;
158 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
159 netdev_features_t wanted = 0, valid = 0;
160 int i, ret = 0;
161
162 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
163 return -EFAULT;
164 useraddr += sizeof(cmd);
165
166 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
167 return -EINVAL;
168
169 if (copy_from_user(features, useraddr, sizeof(features)))
170 return -EFAULT;
171
172 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
173 valid |= (netdev_features_t)features[i].valid << (32 * i);
174 wanted |= (netdev_features_t)features[i].requested << (32 * i);
175 }
176
177 if (valid & ~NETIF_F_ETHTOOL_BITS)
178 return -EINVAL;
179
180 if (valid & ~dev->hw_features) {
181 valid &= dev->hw_features;
182 ret |= ETHTOOL_F_UNSUPPORTED;
183 }
184
185 dev->wanted_features &= ~valid;
186 dev->wanted_features |= wanted & valid;
187 __netdev_update_features(dev);
188
189 if ((dev->wanted_features ^ dev->features) & valid)
190 ret |= ETHTOOL_F_WISH;
191
192 return ret;
193 }
194
195 static int phy_get_sset_count(struct phy_device *phydev)
196 {
197 int ret;
198
199 if (phydev->drv->get_sset_count &&
200 phydev->drv->get_strings &&
201 phydev->drv->get_stats) {
202 mutex_lock(&phydev->lock);
203 ret = phydev->drv->get_sset_count(phydev);
204 mutex_unlock(&phydev->lock);
205
206 return ret;
207 }
208
209 return -EOPNOTSUPP;
210 }
211
212 static int __ethtool_get_sset_count(struct net_device *dev, int sset)
213 {
214 const struct ethtool_ops *ops = dev->ethtool_ops;
215
216 if (sset == ETH_SS_FEATURES)
217 return ARRAY_SIZE(netdev_features_strings);
218
219 if (sset == ETH_SS_RSS_HASH_FUNCS)
220 return ARRAY_SIZE(rss_hash_func_strings);
221
222 if (sset == ETH_SS_TUNABLES)
223 return ARRAY_SIZE(tunable_strings);
224
225 if (sset == ETH_SS_PHY_STATS) {
226 if (dev->phydev)
227 return phy_get_sset_count(dev->phydev);
228 else
229 return -EOPNOTSUPP;
230 }
231
232 if (ops->get_sset_count && ops->get_strings)
233 return ops->get_sset_count(dev, sset);
234 else
235 return -EOPNOTSUPP;
236 }
237
238 static void __ethtool_get_strings(struct net_device *dev,
239 u32 stringset, u8 *data)
240 {
241 const struct ethtool_ops *ops = dev->ethtool_ops;
242
243 if (stringset == ETH_SS_FEATURES)
244 memcpy(data, netdev_features_strings,
245 sizeof(netdev_features_strings));
246 else if (stringset == ETH_SS_RSS_HASH_FUNCS)
247 memcpy(data, rss_hash_func_strings,
248 sizeof(rss_hash_func_strings));
249 else if (stringset == ETH_SS_TUNABLES)
250 memcpy(data, tunable_strings, sizeof(tunable_strings));
251 else if (stringset == ETH_SS_PHY_STATS) {
252 struct phy_device *phydev = dev->phydev;
253
254 if (phydev) {
255 mutex_lock(&phydev->lock);
256 phydev->drv->get_strings(phydev, data);
257 mutex_unlock(&phydev->lock);
258 } else {
259 return;
260 }
261 } else
262 /* ops->get_strings is valid because checked earlier */
263 ops->get_strings(dev, stringset, data);
264 }
265
266 static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
267 {
268 /* feature masks of legacy discrete ethtool ops */
269
270 switch (eth_cmd) {
271 case ETHTOOL_GTXCSUM:
272 case ETHTOOL_STXCSUM:
273 return NETIF_F_CSUM_MASK | NETIF_F_SCTP_CRC;
274 case ETHTOOL_GRXCSUM:
275 case ETHTOOL_SRXCSUM:
276 return NETIF_F_RXCSUM;
277 case ETHTOOL_GSG:
278 case ETHTOOL_SSG:
279 return NETIF_F_SG;
280 case ETHTOOL_GTSO:
281 case ETHTOOL_STSO:
282 return NETIF_F_ALL_TSO;
283 case ETHTOOL_GUFO:
284 case ETHTOOL_SUFO:
285 return NETIF_F_UFO;
286 case ETHTOOL_GGSO:
287 case ETHTOOL_SGSO:
288 return NETIF_F_GSO;
289 case ETHTOOL_GGRO:
290 case ETHTOOL_SGRO:
291 return NETIF_F_GRO;
292 default:
293 BUG();
294 }
295 }
296
297 static int ethtool_get_one_feature(struct net_device *dev,
298 char __user *useraddr, u32 ethcmd)
299 {
300 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
301 struct ethtool_value edata = {
302 .cmd = ethcmd,
303 .data = !!(dev->features & mask),
304 };
305
306 if (copy_to_user(useraddr, &edata, sizeof(edata)))
307 return -EFAULT;
308 return 0;
309 }
310
311 static int ethtool_set_one_feature(struct net_device *dev,
312 void __user *useraddr, u32 ethcmd)
313 {
314 struct ethtool_value edata;
315 netdev_features_t mask;
316
317 if (copy_from_user(&edata, useraddr, sizeof(edata)))
318 return -EFAULT;
319
320 mask = ethtool_get_feature_mask(ethcmd);
321 mask &= dev->hw_features;
322 if (!mask)
323 return -EOPNOTSUPP;
324
325 if (edata.data)
326 dev->wanted_features |= mask;
327 else
328 dev->wanted_features &= ~mask;
329
330 __netdev_update_features(dev);
331
332 return 0;
333 }
334
335 #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
336 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
337 #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_CTAG_RX | \
338 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_NTUPLE | \
339 NETIF_F_RXHASH)
340
341 static u32 __ethtool_get_flags(struct net_device *dev)
342 {
343 u32 flags = 0;
344
345 if (dev->features & NETIF_F_LRO)
346 flags |= ETH_FLAG_LRO;
347 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
348 flags |= ETH_FLAG_RXVLAN;
349 if (dev->features & NETIF_F_HW_VLAN_CTAG_TX)
350 flags |= ETH_FLAG_TXVLAN;
351 if (dev->features & NETIF_F_NTUPLE)
352 flags |= ETH_FLAG_NTUPLE;
353 if (dev->features & NETIF_F_RXHASH)
354 flags |= ETH_FLAG_RXHASH;
355
356 return flags;
357 }
358
359 static int __ethtool_set_flags(struct net_device *dev, u32 data)
360 {
361 netdev_features_t features = 0, changed;
362
363 if (data & ~ETH_ALL_FLAGS)
364 return -EINVAL;
365
366 if (data & ETH_FLAG_LRO)
367 features |= NETIF_F_LRO;
368 if (data & ETH_FLAG_RXVLAN)
369 features |= NETIF_F_HW_VLAN_CTAG_RX;
370 if (data & ETH_FLAG_TXVLAN)
371 features |= NETIF_F_HW_VLAN_CTAG_TX;
372 if (data & ETH_FLAG_NTUPLE)
373 features |= NETIF_F_NTUPLE;
374 if (data & ETH_FLAG_RXHASH)
375 features |= NETIF_F_RXHASH;
376
377 /* allow changing only bits set in hw_features */
378 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
379 if (changed & ~dev->hw_features)
380 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
381
382 dev->wanted_features =
383 (dev->wanted_features & ~changed) | (features & changed);
384
385 __netdev_update_features(dev);
386
387 return 0;
388 }
389
390 int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
391 {
392 ASSERT_RTNL();
393
394 if (!dev->ethtool_ops->get_settings)
395 return -EOPNOTSUPP;
396
397 memset(cmd, 0, sizeof(struct ethtool_cmd));
398 cmd->cmd = ETHTOOL_GSET;
399 return dev->ethtool_ops->get_settings(dev, cmd);
400 }
401 EXPORT_SYMBOL(__ethtool_get_settings);
402
403 static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
404 {
405 int err;
406 struct ethtool_cmd cmd;
407
408 err = __ethtool_get_settings(dev, &cmd);
409 if (err < 0)
410 return err;
411
412 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
413 return -EFAULT;
414 return 0;
415 }
416
417 static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
418 {
419 struct ethtool_cmd cmd;
420
421 if (!dev->ethtool_ops->set_settings)
422 return -EOPNOTSUPP;
423
424 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
425 return -EFAULT;
426
427 return dev->ethtool_ops->set_settings(dev, &cmd);
428 }
429
430 static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
431 void __user *useraddr)
432 {
433 struct ethtool_drvinfo info;
434 const struct ethtool_ops *ops = dev->ethtool_ops;
435
436 memset(&info, 0, sizeof(info));
437 info.cmd = ETHTOOL_GDRVINFO;
438 if (ops->get_drvinfo) {
439 ops->get_drvinfo(dev, &info);
440 } else if (dev->dev.parent && dev->dev.parent->driver) {
441 strlcpy(info.bus_info, dev_name(dev->dev.parent),
442 sizeof(info.bus_info));
443 strlcpy(info.driver, dev->dev.parent->driver->name,
444 sizeof(info.driver));
445 } else {
446 return -EOPNOTSUPP;
447 }
448
449 /*
450 * this method of obtaining string set info is deprecated;
451 * Use ETHTOOL_GSSET_INFO instead.
452 */
453 if (ops->get_sset_count) {
454 int rc;
455
456 rc = ops->get_sset_count(dev, ETH_SS_TEST);
457 if (rc >= 0)
458 info.testinfo_len = rc;
459 rc = ops->get_sset_count(dev, ETH_SS_STATS);
460 if (rc >= 0)
461 info.n_stats = rc;
462 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
463 if (rc >= 0)
464 info.n_priv_flags = rc;
465 }
466 if (ops->get_regs_len)
467 info.regdump_len = ops->get_regs_len(dev);
468 if (ops->get_eeprom_len)
469 info.eedump_len = ops->get_eeprom_len(dev);
470
471 if (copy_to_user(useraddr, &info, sizeof(info)))
472 return -EFAULT;
473 return 0;
474 }
475
476 static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
477 void __user *useraddr)
478 {
479 struct ethtool_sset_info info;
480 u64 sset_mask;
481 int i, idx = 0, n_bits = 0, ret, rc;
482 u32 *info_buf = NULL;
483
484 if (copy_from_user(&info, useraddr, sizeof(info)))
485 return -EFAULT;
486
487 /* store copy of mask, because we zero struct later on */
488 sset_mask = info.sset_mask;
489 if (!sset_mask)
490 return 0;
491
492 /* calculate size of return buffer */
493 n_bits = hweight64(sset_mask);
494
495 memset(&info, 0, sizeof(info));
496 info.cmd = ETHTOOL_GSSET_INFO;
497
498 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
499 if (!info_buf)
500 return -ENOMEM;
501
502 /*
503 * fill return buffer based on input bitmask and successful
504 * get_sset_count return
505 */
506 for (i = 0; i < 64; i++) {
507 if (!(sset_mask & (1ULL << i)))
508 continue;
509
510 rc = __ethtool_get_sset_count(dev, i);
511 if (rc >= 0) {
512 info.sset_mask |= (1ULL << i);
513 info_buf[idx++] = rc;
514 }
515 }
516
517 ret = -EFAULT;
518 if (copy_to_user(useraddr, &info, sizeof(info)))
519 goto out;
520
521 useraddr += offsetof(struct ethtool_sset_info, data);
522 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
523 goto out;
524
525 ret = 0;
526
527 out:
528 kfree(info_buf);
529 return ret;
530 }
531
532 static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
533 u32 cmd, void __user *useraddr)
534 {
535 struct ethtool_rxnfc info;
536 size_t info_size = sizeof(info);
537 int rc;
538
539 if (!dev->ethtool_ops->set_rxnfc)
540 return -EOPNOTSUPP;
541
542 /* struct ethtool_rxnfc was originally defined for
543 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
544 * members. User-space might still be using that
545 * definition. */
546 if (cmd == ETHTOOL_SRXFH)
547 info_size = (offsetof(struct ethtool_rxnfc, data) +
548 sizeof(info.data));
549
550 if (copy_from_user(&info, useraddr, info_size))
551 return -EFAULT;
552
553 rc = dev->ethtool_ops->set_rxnfc(dev, &info);
554 if (rc)
555 return rc;
556
557 if (cmd == ETHTOOL_SRXCLSRLINS &&
558 copy_to_user(useraddr, &info, info_size))
559 return -EFAULT;
560
561 return 0;
562 }
563
564 static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
565 u32 cmd, void __user *useraddr)
566 {
567 struct ethtool_rxnfc info;
568 size_t info_size = sizeof(info);
569 const struct ethtool_ops *ops = dev->ethtool_ops;
570 int ret;
571 void *rule_buf = NULL;
572
573 if (!ops->get_rxnfc)
574 return -EOPNOTSUPP;
575
576 /* struct ethtool_rxnfc was originally defined for
577 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
578 * members. User-space might still be using that
579 * definition. */
580 if (cmd == ETHTOOL_GRXFH)
581 info_size = (offsetof(struct ethtool_rxnfc, data) +
582 sizeof(info.data));
583
584 if (copy_from_user(&info, useraddr, info_size))
585 return -EFAULT;
586
587 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
588 if (info.rule_cnt > 0) {
589 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
590 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
591 GFP_USER);
592 if (!rule_buf)
593 return -ENOMEM;
594 }
595 }
596
597 ret = ops->get_rxnfc(dev, &info, rule_buf);
598 if (ret < 0)
599 goto err_out;
600
601 ret = -EFAULT;
602 if (copy_to_user(useraddr, &info, info_size))
603 goto err_out;
604
605 if (rule_buf) {
606 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
607 if (copy_to_user(useraddr, rule_buf,
608 info.rule_cnt * sizeof(u32)))
609 goto err_out;
610 }
611 ret = 0;
612
613 err_out:
614 kfree(rule_buf);
615
616 return ret;
617 }
618
619 static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr,
620 struct ethtool_rxnfc *rx_rings,
621 u32 size)
622 {
623 int i;
624
625 if (copy_from_user(indir, useraddr, size * sizeof(indir[0])))
626 return -EFAULT;
627
628 /* Validate ring indices */
629 for (i = 0; i < size; i++)
630 if (indir[i] >= rx_rings->data)
631 return -EINVAL;
632
633 return 0;
634 }
635
636 u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly;
637
638 void netdev_rss_key_fill(void *buffer, size_t len)
639 {
640 BUG_ON(len > sizeof(netdev_rss_key));
641 net_get_random_once(netdev_rss_key, sizeof(netdev_rss_key));
642 memcpy(buffer, netdev_rss_key, len);
643 }
644 EXPORT_SYMBOL(netdev_rss_key_fill);
645
646 static int ethtool_get_max_rxfh_channel(struct net_device *dev, u32 *max)
647 {
648 u32 dev_size, current_max = 0;
649 u32 *indir;
650 int ret;
651
652 if (!dev->ethtool_ops->get_rxfh_indir_size ||
653 !dev->ethtool_ops->get_rxfh)
654 return -EOPNOTSUPP;
655 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
656 if (dev_size == 0)
657 return -EOPNOTSUPP;
658
659 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
660 if (!indir)
661 return -ENOMEM;
662
663 ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL, NULL);
664 if (ret)
665 goto out;
666
667 while (dev_size--)
668 current_max = max(current_max, indir[dev_size]);
669
670 *max = current_max;
671
672 out:
673 kfree(indir);
674 return ret;
675 }
676
677 static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
678 void __user *useraddr)
679 {
680 u32 user_size, dev_size;
681 u32 *indir;
682 int ret;
683
684 if (!dev->ethtool_ops->get_rxfh_indir_size ||
685 !dev->ethtool_ops->get_rxfh)
686 return -EOPNOTSUPP;
687 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
688 if (dev_size == 0)
689 return -EOPNOTSUPP;
690
691 if (copy_from_user(&user_size,
692 useraddr + offsetof(struct ethtool_rxfh_indir, size),
693 sizeof(user_size)))
694 return -EFAULT;
695
696 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
697 &dev_size, sizeof(dev_size)))
698 return -EFAULT;
699
700 /* If the user buffer size is 0, this is just a query for the
701 * device table size. Otherwise, if it's smaller than the
702 * device table size it's an error.
703 */
704 if (user_size < dev_size)
705 return user_size == 0 ? 0 : -EINVAL;
706
707 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
708 if (!indir)
709 return -ENOMEM;
710
711 ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL, NULL);
712 if (ret)
713 goto out;
714
715 if (copy_to_user(useraddr +
716 offsetof(struct ethtool_rxfh_indir, ring_index[0]),
717 indir, dev_size * sizeof(indir[0])))
718 ret = -EFAULT;
719
720 out:
721 kfree(indir);
722 return ret;
723 }
724
725 static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
726 void __user *useraddr)
727 {
728 struct ethtool_rxnfc rx_rings;
729 u32 user_size, dev_size, i;
730 u32 *indir;
731 const struct ethtool_ops *ops = dev->ethtool_ops;
732 int ret;
733 u32 ringidx_offset = offsetof(struct ethtool_rxfh_indir, ring_index[0]);
734
735 if (!ops->get_rxfh_indir_size || !ops->set_rxfh ||
736 !ops->get_rxnfc)
737 return -EOPNOTSUPP;
738
739 dev_size = ops->get_rxfh_indir_size(dev);
740 if (dev_size == 0)
741 return -EOPNOTSUPP;
742
743 if (copy_from_user(&user_size,
744 useraddr + offsetof(struct ethtool_rxfh_indir, size),
745 sizeof(user_size)))
746 return -EFAULT;
747
748 if (user_size != 0 && user_size != dev_size)
749 return -EINVAL;
750
751 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
752 if (!indir)
753 return -ENOMEM;
754
755 rx_rings.cmd = ETHTOOL_GRXRINGS;
756 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
757 if (ret)
758 goto out;
759
760 if (user_size == 0) {
761 for (i = 0; i < dev_size; i++)
762 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
763 } else {
764 ret = ethtool_copy_validate_indir(indir,
765 useraddr + ringidx_offset,
766 &rx_rings,
767 dev_size);
768 if (ret)
769 goto out;
770 }
771
772 ret = ops->set_rxfh(dev, indir, NULL, ETH_RSS_HASH_NO_CHANGE);
773 if (ret)
774 goto out;
775
776 /* indicate whether rxfh was set to default */
777 if (user_size == 0)
778 dev->priv_flags &= ~IFF_RXFH_CONFIGURED;
779 else
780 dev->priv_flags |= IFF_RXFH_CONFIGURED;
781
782 out:
783 kfree(indir);
784 return ret;
785 }
786
787 static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev,
788 void __user *useraddr)
789 {
790 int ret;
791 const struct ethtool_ops *ops = dev->ethtool_ops;
792 u32 user_indir_size, user_key_size;
793 u32 dev_indir_size = 0, dev_key_size = 0;
794 struct ethtool_rxfh rxfh;
795 u32 total_size;
796 u32 indir_bytes;
797 u32 *indir = NULL;
798 u8 dev_hfunc = 0;
799 u8 *hkey = NULL;
800 u8 *rss_config;
801
802 if (!ops->get_rxfh)
803 return -EOPNOTSUPP;
804
805 if (ops->get_rxfh_indir_size)
806 dev_indir_size = ops->get_rxfh_indir_size(dev);
807 if (ops->get_rxfh_key_size)
808 dev_key_size = ops->get_rxfh_key_size(dev);
809
810 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
811 return -EFAULT;
812 user_indir_size = rxfh.indir_size;
813 user_key_size = rxfh.key_size;
814
815 /* Check that reserved fields are 0 for now */
816 if (rxfh.rss_context || rxfh.rsvd8[0] || rxfh.rsvd8[1] ||
817 rxfh.rsvd8[2] || rxfh.rsvd32)
818 return -EINVAL;
819
820 rxfh.indir_size = dev_indir_size;
821 rxfh.key_size = dev_key_size;
822 if (copy_to_user(useraddr, &rxfh, sizeof(rxfh)))
823 return -EFAULT;
824
825 if ((user_indir_size && (user_indir_size != dev_indir_size)) ||
826 (user_key_size && (user_key_size != dev_key_size)))
827 return -EINVAL;
828
829 indir_bytes = user_indir_size * sizeof(indir[0]);
830 total_size = indir_bytes + user_key_size;
831 rss_config = kzalloc(total_size, GFP_USER);
832 if (!rss_config)
833 return -ENOMEM;
834
835 if (user_indir_size)
836 indir = (u32 *)rss_config;
837
838 if (user_key_size)
839 hkey = rss_config + indir_bytes;
840
841 ret = dev->ethtool_ops->get_rxfh(dev, indir, hkey, &dev_hfunc);
842 if (ret)
843 goto out;
844
845 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh, hfunc),
846 &dev_hfunc, sizeof(rxfh.hfunc))) {
847 ret = -EFAULT;
848 } else if (copy_to_user(useraddr +
849 offsetof(struct ethtool_rxfh, rss_config[0]),
850 rss_config, total_size)) {
851 ret = -EFAULT;
852 }
853 out:
854 kfree(rss_config);
855
856 return ret;
857 }
858
859 static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
860 void __user *useraddr)
861 {
862 int ret;
863 const struct ethtool_ops *ops = dev->ethtool_ops;
864 struct ethtool_rxnfc rx_rings;
865 struct ethtool_rxfh rxfh;
866 u32 dev_indir_size = 0, dev_key_size = 0, i;
867 u32 *indir = NULL, indir_bytes = 0;
868 u8 *hkey = NULL;
869 u8 *rss_config;
870 u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]);
871
872 if (!ops->get_rxnfc || !ops->set_rxfh)
873 return -EOPNOTSUPP;
874
875 if (ops->get_rxfh_indir_size)
876 dev_indir_size = ops->get_rxfh_indir_size(dev);
877 if (ops->get_rxfh_key_size)
878 dev_key_size = ops->get_rxfh_key_size(dev);
879
880 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
881 return -EFAULT;
882
883 /* Check that reserved fields are 0 for now */
884 if (rxfh.rss_context || rxfh.rsvd8[0] || rxfh.rsvd8[1] ||
885 rxfh.rsvd8[2] || rxfh.rsvd32)
886 return -EINVAL;
887
888 /* If either indir, hash key or function is valid, proceed further.
889 * Must request at least one change: indir size, hash key or function.
890 */
891 if ((rxfh.indir_size &&
892 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE &&
893 rxfh.indir_size != dev_indir_size) ||
894 (rxfh.key_size && (rxfh.key_size != dev_key_size)) ||
895 (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE &&
896 rxfh.key_size == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE))
897 return -EINVAL;
898
899 if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE)
900 indir_bytes = dev_indir_size * sizeof(indir[0]);
901
902 rss_config = kzalloc(indir_bytes + rxfh.key_size, GFP_USER);
903 if (!rss_config)
904 return -ENOMEM;
905
906 rx_rings.cmd = ETHTOOL_GRXRINGS;
907 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
908 if (ret)
909 goto out;
910
911 /* rxfh.indir_size == 0 means reset the indir table to default.
912 * rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE means leave it unchanged.
913 */
914 if (rxfh.indir_size &&
915 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) {
916 indir = (u32 *)rss_config;
917 ret = ethtool_copy_validate_indir(indir,
918 useraddr + rss_cfg_offset,
919 &rx_rings,
920 rxfh.indir_size);
921 if (ret)
922 goto out;
923 } else if (rxfh.indir_size == 0) {
924 indir = (u32 *)rss_config;
925 for (i = 0; i < dev_indir_size; i++)
926 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
927 }
928
929 if (rxfh.key_size) {
930 hkey = rss_config + indir_bytes;
931 if (copy_from_user(hkey,
932 useraddr + rss_cfg_offset + indir_bytes,
933 rxfh.key_size)) {
934 ret = -EFAULT;
935 goto out;
936 }
937 }
938
939 ret = ops->set_rxfh(dev, indir, hkey, rxfh.hfunc);
940 if (ret)
941 goto out;
942
943 /* indicate whether rxfh was set to default */
944 if (rxfh.indir_size == 0)
945 dev->priv_flags &= ~IFF_RXFH_CONFIGURED;
946 else if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE)
947 dev->priv_flags |= IFF_RXFH_CONFIGURED;
948
949 out:
950 kfree(rss_config);
951 return ret;
952 }
953
954 static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
955 {
956 struct ethtool_regs regs;
957 const struct ethtool_ops *ops = dev->ethtool_ops;
958 void *regbuf;
959 int reglen, ret;
960
961 if (!ops->get_regs || !ops->get_regs_len)
962 return -EOPNOTSUPP;
963
964 if (copy_from_user(&regs, useraddr, sizeof(regs)))
965 return -EFAULT;
966
967 reglen = ops->get_regs_len(dev);
968 if (regs.len > reglen)
969 regs.len = reglen;
970
971 regbuf = vzalloc(reglen);
972 if (reglen && !regbuf)
973 return -ENOMEM;
974
975 ops->get_regs(dev, &regs, regbuf);
976
977 ret = -EFAULT;
978 if (copy_to_user(useraddr, &regs, sizeof(regs)))
979 goto out;
980 useraddr += offsetof(struct ethtool_regs, data);
981 if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
982 goto out;
983 ret = 0;
984
985 out:
986 vfree(regbuf);
987 return ret;
988 }
989
990 static int ethtool_reset(struct net_device *dev, char __user *useraddr)
991 {
992 struct ethtool_value reset;
993 int ret;
994
995 if (!dev->ethtool_ops->reset)
996 return -EOPNOTSUPP;
997
998 if (copy_from_user(&reset, useraddr, sizeof(reset)))
999 return -EFAULT;
1000
1001 ret = dev->ethtool_ops->reset(dev, &reset.data);
1002 if (ret)
1003 return ret;
1004
1005 if (copy_to_user(useraddr, &reset, sizeof(reset)))
1006 return -EFAULT;
1007 return 0;
1008 }
1009
1010 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
1011 {
1012 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
1013
1014 if (!dev->ethtool_ops->get_wol)
1015 return -EOPNOTSUPP;
1016
1017 dev->ethtool_ops->get_wol(dev, &wol);
1018
1019 if (copy_to_user(useraddr, &wol, sizeof(wol)))
1020 return -EFAULT;
1021 return 0;
1022 }
1023
1024 static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
1025 {
1026 struct ethtool_wolinfo wol;
1027
1028 if (!dev->ethtool_ops->set_wol)
1029 return -EOPNOTSUPP;
1030
1031 if (copy_from_user(&wol, useraddr, sizeof(wol)))
1032 return -EFAULT;
1033
1034 return dev->ethtool_ops->set_wol(dev, &wol);
1035 }
1036
1037 static int ethtool_get_eee(struct net_device *dev, char __user *useraddr)
1038 {
1039 struct ethtool_eee edata;
1040 int rc;
1041
1042 if (!dev->ethtool_ops->get_eee)
1043 return -EOPNOTSUPP;
1044
1045 memset(&edata, 0, sizeof(struct ethtool_eee));
1046 edata.cmd = ETHTOOL_GEEE;
1047 rc = dev->ethtool_ops->get_eee(dev, &edata);
1048
1049 if (rc)
1050 return rc;
1051
1052 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1053 return -EFAULT;
1054
1055 return 0;
1056 }
1057
1058 static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
1059 {
1060 struct ethtool_eee edata;
1061
1062 if (!dev->ethtool_ops->set_eee)
1063 return -EOPNOTSUPP;
1064
1065 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1066 return -EFAULT;
1067
1068 return dev->ethtool_ops->set_eee(dev, &edata);
1069 }
1070
1071 static int ethtool_nway_reset(struct net_device *dev)
1072 {
1073 if (!dev->ethtool_ops->nway_reset)
1074 return -EOPNOTSUPP;
1075
1076 return dev->ethtool_ops->nway_reset(dev);
1077 }
1078
1079 static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
1080 {
1081 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
1082
1083 if (!dev->ethtool_ops->get_link)
1084 return -EOPNOTSUPP;
1085
1086 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
1087
1088 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1089 return -EFAULT;
1090 return 0;
1091 }
1092
1093 static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr,
1094 int (*getter)(struct net_device *,
1095 struct ethtool_eeprom *, u8 *),
1096 u32 total_len)
1097 {
1098 struct ethtool_eeprom eeprom;
1099 void __user *userbuf = useraddr + sizeof(eeprom);
1100 u32 bytes_remaining;
1101 u8 *data;
1102 int ret = 0;
1103
1104 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1105 return -EFAULT;
1106
1107 /* Check for wrap and zero */
1108 if (eeprom.offset + eeprom.len <= eeprom.offset)
1109 return -EINVAL;
1110
1111 /* Check for exceeding total eeprom len */
1112 if (eeprom.offset + eeprom.len > total_len)
1113 return -EINVAL;
1114
1115 data = kmalloc(PAGE_SIZE, GFP_USER);
1116 if (!data)
1117 return -ENOMEM;
1118
1119 bytes_remaining = eeprom.len;
1120 while (bytes_remaining > 0) {
1121 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
1122
1123 ret = getter(dev, &eeprom, data);
1124 if (ret)
1125 break;
1126 if (copy_to_user(userbuf, data, eeprom.len)) {
1127 ret = -EFAULT;
1128 break;
1129 }
1130 userbuf += eeprom.len;
1131 eeprom.offset += eeprom.len;
1132 bytes_remaining -= eeprom.len;
1133 }
1134
1135 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
1136 eeprom.offset -= eeprom.len;
1137 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
1138 ret = -EFAULT;
1139
1140 kfree(data);
1141 return ret;
1142 }
1143
1144 static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
1145 {
1146 const struct ethtool_ops *ops = dev->ethtool_ops;
1147
1148 if (!ops->get_eeprom || !ops->get_eeprom_len ||
1149 !ops->get_eeprom_len(dev))
1150 return -EOPNOTSUPP;
1151
1152 return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom,
1153 ops->get_eeprom_len(dev));
1154 }
1155
1156 static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
1157 {
1158 struct ethtool_eeprom eeprom;
1159 const struct ethtool_ops *ops = dev->ethtool_ops;
1160 void __user *userbuf = useraddr + sizeof(eeprom);
1161 u32 bytes_remaining;
1162 u8 *data;
1163 int ret = 0;
1164
1165 if (!ops->set_eeprom || !ops->get_eeprom_len ||
1166 !ops->get_eeprom_len(dev))
1167 return -EOPNOTSUPP;
1168
1169 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1170 return -EFAULT;
1171
1172 /* Check for wrap and zero */
1173 if (eeprom.offset + eeprom.len <= eeprom.offset)
1174 return -EINVAL;
1175
1176 /* Check for exceeding total eeprom len */
1177 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
1178 return -EINVAL;
1179
1180 data = kmalloc(PAGE_SIZE, GFP_USER);
1181 if (!data)
1182 return -ENOMEM;
1183
1184 bytes_remaining = eeprom.len;
1185 while (bytes_remaining > 0) {
1186 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
1187
1188 if (copy_from_user(data, userbuf, eeprom.len)) {
1189 ret = -EFAULT;
1190 break;
1191 }
1192 ret = ops->set_eeprom(dev, &eeprom, data);
1193 if (ret)
1194 break;
1195 userbuf += eeprom.len;
1196 eeprom.offset += eeprom.len;
1197 bytes_remaining -= eeprom.len;
1198 }
1199
1200 kfree(data);
1201 return ret;
1202 }
1203
1204 static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
1205 void __user *useraddr)
1206 {
1207 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
1208
1209 if (!dev->ethtool_ops->get_coalesce)
1210 return -EOPNOTSUPP;
1211
1212 dev->ethtool_ops->get_coalesce(dev, &coalesce);
1213
1214 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
1215 return -EFAULT;
1216 return 0;
1217 }
1218
1219 static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
1220 void __user *useraddr)
1221 {
1222 struct ethtool_coalesce coalesce;
1223
1224 if (!dev->ethtool_ops->set_coalesce)
1225 return -EOPNOTSUPP;
1226
1227 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
1228 return -EFAULT;
1229
1230 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
1231 }
1232
1233 static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
1234 {
1235 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
1236
1237 if (!dev->ethtool_ops->get_ringparam)
1238 return -EOPNOTSUPP;
1239
1240 dev->ethtool_ops->get_ringparam(dev, &ringparam);
1241
1242 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
1243 return -EFAULT;
1244 return 0;
1245 }
1246
1247 static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
1248 {
1249 struct ethtool_ringparam ringparam;
1250
1251 if (!dev->ethtool_ops->set_ringparam)
1252 return -EOPNOTSUPP;
1253
1254 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
1255 return -EFAULT;
1256
1257 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
1258 }
1259
1260 static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
1261 void __user *useraddr)
1262 {
1263 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
1264
1265 if (!dev->ethtool_ops->get_channels)
1266 return -EOPNOTSUPP;
1267
1268 dev->ethtool_ops->get_channels(dev, &channels);
1269
1270 if (copy_to_user(useraddr, &channels, sizeof(channels)))
1271 return -EFAULT;
1272 return 0;
1273 }
1274
1275 static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
1276 void __user *useraddr)
1277 {
1278 struct ethtool_channels channels, max;
1279 u32 max_rx_in_use = 0;
1280
1281 if (!dev->ethtool_ops->set_channels || !dev->ethtool_ops->get_channels)
1282 return -EOPNOTSUPP;
1283
1284 if (copy_from_user(&channels, useraddr, sizeof(channels)))
1285 return -EFAULT;
1286
1287 dev->ethtool_ops->get_channels(dev, &max);
1288
1289 /* ensure new counts are within the maximums */
1290 if ((channels.rx_count > max.max_rx) ||
1291 (channels.tx_count > max.max_tx) ||
1292 (channels.combined_count > max.max_combined) ||
1293 (channels.other_count > max.max_other))
1294 return -EINVAL;
1295
1296 /* ensure the new Rx count fits within the configured Rx flow
1297 * indirection table settings */
1298 if (netif_is_rxfh_configured(dev) &&
1299 !ethtool_get_max_rxfh_channel(dev, &max_rx_in_use) &&
1300 (channels.combined_count + channels.rx_count) <= max_rx_in_use)
1301 return -EINVAL;
1302
1303 return dev->ethtool_ops->set_channels(dev, &channels);
1304 }
1305
1306 static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
1307 {
1308 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
1309
1310 if (!dev->ethtool_ops->get_pauseparam)
1311 return -EOPNOTSUPP;
1312
1313 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
1314
1315 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
1316 return -EFAULT;
1317 return 0;
1318 }
1319
1320 static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
1321 {
1322 struct ethtool_pauseparam pauseparam;
1323
1324 if (!dev->ethtool_ops->set_pauseparam)
1325 return -EOPNOTSUPP;
1326
1327 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
1328 return -EFAULT;
1329
1330 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
1331 }
1332
1333 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1334 {
1335 struct ethtool_test test;
1336 const struct ethtool_ops *ops = dev->ethtool_ops;
1337 u64 *data;
1338 int ret, test_len;
1339
1340 if (!ops->self_test || !ops->get_sset_count)
1341 return -EOPNOTSUPP;
1342
1343 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
1344 if (test_len < 0)
1345 return test_len;
1346 WARN_ON(test_len == 0);
1347
1348 if (copy_from_user(&test, useraddr, sizeof(test)))
1349 return -EFAULT;
1350
1351 test.len = test_len;
1352 data = kmalloc(test_len * sizeof(u64), GFP_USER);
1353 if (!data)
1354 return -ENOMEM;
1355
1356 ops->self_test(dev, &test, data);
1357
1358 ret = -EFAULT;
1359 if (copy_to_user(useraddr, &test, sizeof(test)))
1360 goto out;
1361 useraddr += sizeof(test);
1362 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1363 goto out;
1364 ret = 0;
1365
1366 out:
1367 kfree(data);
1368 return ret;
1369 }
1370
1371 static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1372 {
1373 struct ethtool_gstrings gstrings;
1374 u8 *data;
1375 int ret;
1376
1377 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1378 return -EFAULT;
1379
1380 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
1381 if (ret < 0)
1382 return ret;
1383
1384 gstrings.len = ret;
1385
1386 data = kcalloc(gstrings.len, ETH_GSTRING_LEN, GFP_USER);
1387 if (!data)
1388 return -ENOMEM;
1389
1390 __ethtool_get_strings(dev, gstrings.string_set, data);
1391
1392 ret = -EFAULT;
1393 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1394 goto out;
1395 useraddr += sizeof(gstrings);
1396 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1397 goto out;
1398 ret = 0;
1399
1400 out:
1401 kfree(data);
1402 return ret;
1403 }
1404
1405 static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1406 {
1407 struct ethtool_value id;
1408 static bool busy;
1409 const struct ethtool_ops *ops = dev->ethtool_ops;
1410 int rc;
1411
1412 if (!ops->set_phys_id)
1413 return -EOPNOTSUPP;
1414
1415 if (busy)
1416 return -EBUSY;
1417
1418 if (copy_from_user(&id, useraddr, sizeof(id)))
1419 return -EFAULT;
1420
1421 rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
1422 if (rc < 0)
1423 return rc;
1424
1425 /* Drop the RTNL lock while waiting, but prevent reentry or
1426 * removal of the device.
1427 */
1428 busy = true;
1429 dev_hold(dev);
1430 rtnl_unlock();
1431
1432 if (rc == 0) {
1433 /* Driver will handle this itself */
1434 schedule_timeout_interruptible(
1435 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
1436 } else {
1437 /* Driver expects to be called at twice the frequency in rc */
1438 int n = rc * 2, i, interval = HZ / n;
1439
1440 /* Count down seconds */
1441 do {
1442 /* Count down iterations per second */
1443 i = n;
1444 do {
1445 rtnl_lock();
1446 rc = ops->set_phys_id(dev,
1447 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1448 rtnl_unlock();
1449 if (rc)
1450 break;
1451 schedule_timeout_interruptible(interval);
1452 } while (!signal_pending(current) && --i != 0);
1453 } while (!signal_pending(current) &&
1454 (id.data == 0 || --id.data != 0));
1455 }
1456
1457 rtnl_lock();
1458 dev_put(dev);
1459 busy = false;
1460
1461 (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
1462 return rc;
1463 }
1464
1465 static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1466 {
1467 struct ethtool_stats stats;
1468 const struct ethtool_ops *ops = dev->ethtool_ops;
1469 u64 *data;
1470 int ret, n_stats;
1471
1472 if (!ops->get_ethtool_stats || !ops->get_sset_count)
1473 return -EOPNOTSUPP;
1474
1475 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
1476 if (n_stats < 0)
1477 return n_stats;
1478 WARN_ON(n_stats == 0);
1479
1480 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1481 return -EFAULT;
1482
1483 stats.n_stats = n_stats;
1484 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
1485 if (!data)
1486 return -ENOMEM;
1487
1488 ops->get_ethtool_stats(dev, &stats, data);
1489
1490 ret = -EFAULT;
1491 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1492 goto out;
1493 useraddr += sizeof(stats);
1494 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1495 goto out;
1496 ret = 0;
1497
1498 out:
1499 kfree(data);
1500 return ret;
1501 }
1502
1503 static int ethtool_get_phy_stats(struct net_device *dev, void __user *useraddr)
1504 {
1505 struct ethtool_stats stats;
1506 struct phy_device *phydev = dev->phydev;
1507 u64 *data;
1508 int ret, n_stats;
1509
1510 if (!phydev)
1511 return -EOPNOTSUPP;
1512
1513 n_stats = phy_get_sset_count(phydev);
1514
1515 if (n_stats < 0)
1516 return n_stats;
1517 WARN_ON(n_stats == 0);
1518
1519 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1520 return -EFAULT;
1521
1522 stats.n_stats = n_stats;
1523 data = kmalloc_array(n_stats, sizeof(u64), GFP_USER);
1524 if (!data)
1525 return -ENOMEM;
1526
1527 mutex_lock(&phydev->lock);
1528 phydev->drv->get_stats(phydev, &stats, data);
1529 mutex_unlock(&phydev->lock);
1530
1531 ret = -EFAULT;
1532 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1533 goto out;
1534 useraddr += sizeof(stats);
1535 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1536 goto out;
1537 ret = 0;
1538
1539 out:
1540 kfree(data);
1541 return ret;
1542 }
1543
1544 static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
1545 {
1546 struct ethtool_perm_addr epaddr;
1547
1548 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
1549 return -EFAULT;
1550
1551 if (epaddr.size < dev->addr_len)
1552 return -ETOOSMALL;
1553 epaddr.size = dev->addr_len;
1554
1555 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
1556 return -EFAULT;
1557 useraddr += sizeof(epaddr);
1558 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1559 return -EFAULT;
1560 return 0;
1561 }
1562
1563 static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1564 u32 cmd, u32 (*actor)(struct net_device *))
1565 {
1566 struct ethtool_value edata = { .cmd = cmd };
1567
1568 if (!actor)
1569 return -EOPNOTSUPP;
1570
1571 edata.data = actor(dev);
1572
1573 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1574 return -EFAULT;
1575 return 0;
1576 }
1577
1578 static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1579 void (*actor)(struct net_device *, u32))
1580 {
1581 struct ethtool_value edata;
1582
1583 if (!actor)
1584 return -EOPNOTSUPP;
1585
1586 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1587 return -EFAULT;
1588
1589 actor(dev, edata.data);
1590 return 0;
1591 }
1592
1593 static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1594 int (*actor)(struct net_device *, u32))
1595 {
1596 struct ethtool_value edata;
1597
1598 if (!actor)
1599 return -EOPNOTSUPP;
1600
1601 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1602 return -EFAULT;
1603
1604 return actor(dev, edata.data);
1605 }
1606
1607 static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1608 char __user *useraddr)
1609 {
1610 struct ethtool_flash efl;
1611
1612 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1613 return -EFAULT;
1614
1615 if (!dev->ethtool_ops->flash_device)
1616 return -EOPNOTSUPP;
1617
1618 efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
1619
1620 return dev->ethtool_ops->flash_device(dev, &efl);
1621 }
1622
1623 static int ethtool_set_dump(struct net_device *dev,
1624 void __user *useraddr)
1625 {
1626 struct ethtool_dump dump;
1627
1628 if (!dev->ethtool_ops->set_dump)
1629 return -EOPNOTSUPP;
1630
1631 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1632 return -EFAULT;
1633
1634 return dev->ethtool_ops->set_dump(dev, &dump);
1635 }
1636
1637 static int ethtool_get_dump_flag(struct net_device *dev,
1638 void __user *useraddr)
1639 {
1640 int ret;
1641 struct ethtool_dump dump;
1642 const struct ethtool_ops *ops = dev->ethtool_ops;
1643
1644 if (!ops->get_dump_flag)
1645 return -EOPNOTSUPP;
1646
1647 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1648 return -EFAULT;
1649
1650 ret = ops->get_dump_flag(dev, &dump);
1651 if (ret)
1652 return ret;
1653
1654 if (copy_to_user(useraddr, &dump, sizeof(dump)))
1655 return -EFAULT;
1656 return 0;
1657 }
1658
1659 static int ethtool_get_dump_data(struct net_device *dev,
1660 void __user *useraddr)
1661 {
1662 int ret;
1663 __u32 len;
1664 struct ethtool_dump dump, tmp;
1665 const struct ethtool_ops *ops = dev->ethtool_ops;
1666 void *data = NULL;
1667
1668 if (!ops->get_dump_data || !ops->get_dump_flag)
1669 return -EOPNOTSUPP;
1670
1671 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1672 return -EFAULT;
1673
1674 memset(&tmp, 0, sizeof(tmp));
1675 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
1676 ret = ops->get_dump_flag(dev, &tmp);
1677 if (ret)
1678 return ret;
1679
1680 len = min(tmp.len, dump.len);
1681 if (!len)
1682 return -EFAULT;
1683
1684 /* Don't ever let the driver think there's more space available
1685 * than it requested with .get_dump_flag().
1686 */
1687 dump.len = len;
1688
1689 /* Always allocate enough space to hold the whole thing so that the
1690 * driver does not need to check the length and bother with partial
1691 * dumping.
1692 */
1693 data = vzalloc(tmp.len);
1694 if (!data)
1695 return -ENOMEM;
1696 ret = ops->get_dump_data(dev, &dump, data);
1697 if (ret)
1698 goto out;
1699
1700 /* There are two sane possibilities:
1701 * 1. The driver's .get_dump_data() does not touch dump.len.
1702 * 2. Or it may set dump.len to how much it really writes, which
1703 * should be tmp.len (or len if it can do a partial dump).
1704 * In any case respond to userspace with the actual length of data
1705 * it's receiving.
1706 */
1707 WARN_ON(dump.len != len && dump.len != tmp.len);
1708 dump.len = len;
1709
1710 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1711 ret = -EFAULT;
1712 goto out;
1713 }
1714 useraddr += offsetof(struct ethtool_dump, data);
1715 if (copy_to_user(useraddr, data, len))
1716 ret = -EFAULT;
1717 out:
1718 vfree(data);
1719 return ret;
1720 }
1721
1722 static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
1723 {
1724 int err = 0;
1725 struct ethtool_ts_info info;
1726 const struct ethtool_ops *ops = dev->ethtool_ops;
1727 struct phy_device *phydev = dev->phydev;
1728
1729 memset(&info, 0, sizeof(info));
1730 info.cmd = ETHTOOL_GET_TS_INFO;
1731
1732 if (phydev && phydev->drv && phydev->drv->ts_info) {
1733 err = phydev->drv->ts_info(phydev, &info);
1734 } else if (ops->get_ts_info) {
1735 err = ops->get_ts_info(dev, &info);
1736 } else {
1737 info.so_timestamping =
1738 SOF_TIMESTAMPING_RX_SOFTWARE |
1739 SOF_TIMESTAMPING_SOFTWARE;
1740 info.phc_index = -1;
1741 }
1742
1743 if (err)
1744 return err;
1745
1746 if (copy_to_user(useraddr, &info, sizeof(info)))
1747 err = -EFAULT;
1748
1749 return err;
1750 }
1751
1752 static int __ethtool_get_module_info(struct net_device *dev,
1753 struct ethtool_modinfo *modinfo)
1754 {
1755 const struct ethtool_ops *ops = dev->ethtool_ops;
1756 struct phy_device *phydev = dev->phydev;
1757
1758 if (phydev && phydev->drv && phydev->drv->module_info)
1759 return phydev->drv->module_info(phydev, modinfo);
1760
1761 if (ops->get_module_info)
1762 return ops->get_module_info(dev, modinfo);
1763
1764 return -EOPNOTSUPP;
1765 }
1766
1767 static int ethtool_get_module_info(struct net_device *dev,
1768 void __user *useraddr)
1769 {
1770 int ret;
1771 struct ethtool_modinfo modinfo;
1772
1773 if (copy_from_user(&modinfo, useraddr, sizeof(modinfo)))
1774 return -EFAULT;
1775
1776 ret = __ethtool_get_module_info(dev, &modinfo);
1777 if (ret)
1778 return ret;
1779
1780 if (copy_to_user(useraddr, &modinfo, sizeof(modinfo)))
1781 return -EFAULT;
1782
1783 return 0;
1784 }
1785
1786 static int __ethtool_get_module_eeprom(struct net_device *dev,
1787 struct ethtool_eeprom *ee, u8 *data)
1788 {
1789 const struct ethtool_ops *ops = dev->ethtool_ops;
1790 struct phy_device *phydev = dev->phydev;
1791
1792 if (phydev && phydev->drv && phydev->drv->module_eeprom)
1793 return phydev->drv->module_eeprom(phydev, ee, data);
1794
1795 if (ops->get_module_eeprom)
1796 return ops->get_module_eeprom(dev, ee, data);
1797
1798 return -EOPNOTSUPP;
1799 }
1800
1801 static int ethtool_get_module_eeprom(struct net_device *dev,
1802 void __user *useraddr)
1803 {
1804 int ret;
1805 struct ethtool_modinfo modinfo;
1806
1807 ret = __ethtool_get_module_info(dev, &modinfo);
1808 if (ret)
1809 return ret;
1810
1811 return ethtool_get_any_eeprom(dev, useraddr,
1812 __ethtool_get_module_eeprom,
1813 modinfo.eeprom_len);
1814 }
1815
1816 static int ethtool_tunable_valid(const struct ethtool_tunable *tuna)
1817 {
1818 switch (tuna->id) {
1819 case ETHTOOL_RX_COPYBREAK:
1820 case ETHTOOL_TX_COPYBREAK:
1821 if (tuna->len != sizeof(u32) ||
1822 tuna->type_id != ETHTOOL_TUNABLE_U32)
1823 return -EINVAL;
1824 break;
1825 default:
1826 return -EINVAL;
1827 }
1828
1829 return 0;
1830 }
1831
1832 static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr)
1833 {
1834 int ret;
1835 struct ethtool_tunable tuna;
1836 const struct ethtool_ops *ops = dev->ethtool_ops;
1837 void *data;
1838
1839 if (!ops->get_tunable)
1840 return -EOPNOTSUPP;
1841 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
1842 return -EFAULT;
1843 ret = ethtool_tunable_valid(&tuna);
1844 if (ret)
1845 return ret;
1846 data = kmalloc(tuna.len, GFP_USER);
1847 if (!data)
1848 return -ENOMEM;
1849 ret = ops->get_tunable(dev, &tuna, data);
1850 if (ret)
1851 goto out;
1852 useraddr += sizeof(tuna);
1853 ret = -EFAULT;
1854 if (copy_to_user(useraddr, data, tuna.len))
1855 goto out;
1856 ret = 0;
1857
1858 out:
1859 kfree(data);
1860 return ret;
1861 }
1862
1863 static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr)
1864 {
1865 int ret;
1866 struct ethtool_tunable tuna;
1867 const struct ethtool_ops *ops = dev->ethtool_ops;
1868 void *data;
1869
1870 if (!ops->set_tunable)
1871 return -EOPNOTSUPP;
1872 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
1873 return -EFAULT;
1874 ret = ethtool_tunable_valid(&tuna);
1875 if (ret)
1876 return ret;
1877 data = kmalloc(tuna.len, GFP_USER);
1878 if (!data)
1879 return -ENOMEM;
1880 useraddr += sizeof(tuna);
1881 ret = -EFAULT;
1882 if (copy_from_user(data, useraddr, tuna.len))
1883 goto out;
1884 ret = ops->set_tunable(dev, &tuna, data);
1885
1886 out:
1887 kfree(data);
1888 return ret;
1889 }
1890
1891 static int ethtool_set_per_queue(struct net_device *dev, void __user *useraddr)
1892 {
1893 struct ethtool_per_queue_op per_queue_opt;
1894
1895 if (copy_from_user(&per_queue_opt, useraddr, sizeof(per_queue_opt)))
1896 return -EFAULT;
1897
1898 switch (per_queue_opt.sub_command) {
1899
1900 default:
1901 return -EOPNOTSUPP;
1902 };
1903 }
1904
1905 /* The main entry point in this file. Called from net/core/dev_ioctl.c */
1906
1907 int dev_ethtool(struct net *net, struct ifreq *ifr)
1908 {
1909 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
1910 void __user *useraddr = ifr->ifr_data;
1911 u32 ethcmd, sub_cmd;
1912 int rc;
1913 netdev_features_t old_features;
1914
1915 if (!dev || !netif_device_present(dev))
1916 return -ENODEV;
1917
1918 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
1919 return -EFAULT;
1920
1921 if (ethcmd == ETHTOOL_PERQUEUE) {
1922 if (copy_from_user(&sub_cmd, useraddr + sizeof(ethcmd), sizeof(sub_cmd)))
1923 return -EFAULT;
1924 } else {
1925 sub_cmd = ethcmd;
1926 }
1927 /* Allow some commands to be done by anyone */
1928 switch (sub_cmd) {
1929 case ETHTOOL_GSET:
1930 case ETHTOOL_GDRVINFO:
1931 case ETHTOOL_GMSGLVL:
1932 case ETHTOOL_GLINK:
1933 case ETHTOOL_GCOALESCE:
1934 case ETHTOOL_GRINGPARAM:
1935 case ETHTOOL_GPAUSEPARAM:
1936 case ETHTOOL_GRXCSUM:
1937 case ETHTOOL_GTXCSUM:
1938 case ETHTOOL_GSG:
1939 case ETHTOOL_GSSET_INFO:
1940 case ETHTOOL_GSTRINGS:
1941 case ETHTOOL_GSTATS:
1942 case ETHTOOL_GPHYSTATS:
1943 case ETHTOOL_GTSO:
1944 case ETHTOOL_GPERMADDR:
1945 case ETHTOOL_GUFO:
1946 case ETHTOOL_GGSO:
1947 case ETHTOOL_GGRO:
1948 case ETHTOOL_GFLAGS:
1949 case ETHTOOL_GPFLAGS:
1950 case ETHTOOL_GRXFH:
1951 case ETHTOOL_GRXRINGS:
1952 case ETHTOOL_GRXCLSRLCNT:
1953 case ETHTOOL_GRXCLSRULE:
1954 case ETHTOOL_GRXCLSRLALL:
1955 case ETHTOOL_GRXFHINDIR:
1956 case ETHTOOL_GRSSH:
1957 case ETHTOOL_GFEATURES:
1958 case ETHTOOL_GCHANNELS:
1959 case ETHTOOL_GET_TS_INFO:
1960 case ETHTOOL_GEEE:
1961 case ETHTOOL_GTUNABLE:
1962 break;
1963 default:
1964 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1965 return -EPERM;
1966 }
1967
1968 if (dev->ethtool_ops->begin) {
1969 rc = dev->ethtool_ops->begin(dev);
1970 if (rc < 0)
1971 return rc;
1972 }
1973 old_features = dev->features;
1974
1975 switch (ethcmd) {
1976 case ETHTOOL_GSET:
1977 rc = ethtool_get_settings(dev, useraddr);
1978 break;
1979 case ETHTOOL_SSET:
1980 rc = ethtool_set_settings(dev, useraddr);
1981 break;
1982 case ETHTOOL_GDRVINFO:
1983 rc = ethtool_get_drvinfo(dev, useraddr);
1984 break;
1985 case ETHTOOL_GREGS:
1986 rc = ethtool_get_regs(dev, useraddr);
1987 break;
1988 case ETHTOOL_GWOL:
1989 rc = ethtool_get_wol(dev, useraddr);
1990 break;
1991 case ETHTOOL_SWOL:
1992 rc = ethtool_set_wol(dev, useraddr);
1993 break;
1994 case ETHTOOL_GMSGLVL:
1995 rc = ethtool_get_value(dev, useraddr, ethcmd,
1996 dev->ethtool_ops->get_msglevel);
1997 break;
1998 case ETHTOOL_SMSGLVL:
1999 rc = ethtool_set_value_void(dev, useraddr,
2000 dev->ethtool_ops->set_msglevel);
2001 break;
2002 case ETHTOOL_GEEE:
2003 rc = ethtool_get_eee(dev, useraddr);
2004 break;
2005 case ETHTOOL_SEEE:
2006 rc = ethtool_set_eee(dev, useraddr);
2007 break;
2008 case ETHTOOL_NWAY_RST:
2009 rc = ethtool_nway_reset(dev);
2010 break;
2011 case ETHTOOL_GLINK:
2012 rc = ethtool_get_link(dev, useraddr);
2013 break;
2014 case ETHTOOL_GEEPROM:
2015 rc = ethtool_get_eeprom(dev, useraddr);
2016 break;
2017 case ETHTOOL_SEEPROM:
2018 rc = ethtool_set_eeprom(dev, useraddr);
2019 break;
2020 case ETHTOOL_GCOALESCE:
2021 rc = ethtool_get_coalesce(dev, useraddr);
2022 break;
2023 case ETHTOOL_SCOALESCE:
2024 rc = ethtool_set_coalesce(dev, useraddr);
2025 break;
2026 case ETHTOOL_GRINGPARAM:
2027 rc = ethtool_get_ringparam(dev, useraddr);
2028 break;
2029 case ETHTOOL_SRINGPARAM:
2030 rc = ethtool_set_ringparam(dev, useraddr);
2031 break;
2032 case ETHTOOL_GPAUSEPARAM:
2033 rc = ethtool_get_pauseparam(dev, useraddr);
2034 break;
2035 case ETHTOOL_SPAUSEPARAM:
2036 rc = ethtool_set_pauseparam(dev, useraddr);
2037 break;
2038 case ETHTOOL_TEST:
2039 rc = ethtool_self_test(dev, useraddr);
2040 break;
2041 case ETHTOOL_GSTRINGS:
2042 rc = ethtool_get_strings(dev, useraddr);
2043 break;
2044 case ETHTOOL_PHYS_ID:
2045 rc = ethtool_phys_id(dev, useraddr);
2046 break;
2047 case ETHTOOL_GSTATS:
2048 rc = ethtool_get_stats(dev, useraddr);
2049 break;
2050 case ETHTOOL_GPERMADDR:
2051 rc = ethtool_get_perm_addr(dev, useraddr);
2052 break;
2053 case ETHTOOL_GFLAGS:
2054 rc = ethtool_get_value(dev, useraddr, ethcmd,
2055 __ethtool_get_flags);
2056 break;
2057 case ETHTOOL_SFLAGS:
2058 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
2059 break;
2060 case ETHTOOL_GPFLAGS:
2061 rc = ethtool_get_value(dev, useraddr, ethcmd,
2062 dev->ethtool_ops->get_priv_flags);
2063 break;
2064 case ETHTOOL_SPFLAGS:
2065 rc = ethtool_set_value(dev, useraddr,
2066 dev->ethtool_ops->set_priv_flags);
2067 break;
2068 case ETHTOOL_GRXFH:
2069 case ETHTOOL_GRXRINGS:
2070 case ETHTOOL_GRXCLSRLCNT:
2071 case ETHTOOL_GRXCLSRULE:
2072 case ETHTOOL_GRXCLSRLALL:
2073 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
2074 break;
2075 case ETHTOOL_SRXFH:
2076 case ETHTOOL_SRXCLSRLDEL:
2077 case ETHTOOL_SRXCLSRLINS:
2078 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
2079 break;
2080 case ETHTOOL_FLASHDEV:
2081 rc = ethtool_flash_device(dev, useraddr);
2082 break;
2083 case ETHTOOL_RESET:
2084 rc = ethtool_reset(dev, useraddr);
2085 break;
2086 case ETHTOOL_GSSET_INFO:
2087 rc = ethtool_get_sset_info(dev, useraddr);
2088 break;
2089 case ETHTOOL_GRXFHINDIR:
2090 rc = ethtool_get_rxfh_indir(dev, useraddr);
2091 break;
2092 case ETHTOOL_SRXFHINDIR:
2093 rc = ethtool_set_rxfh_indir(dev, useraddr);
2094 break;
2095 case ETHTOOL_GRSSH:
2096 rc = ethtool_get_rxfh(dev, useraddr);
2097 break;
2098 case ETHTOOL_SRSSH:
2099 rc = ethtool_set_rxfh(dev, useraddr);
2100 break;
2101 case ETHTOOL_GFEATURES:
2102 rc = ethtool_get_features(dev, useraddr);
2103 break;
2104 case ETHTOOL_SFEATURES:
2105 rc = ethtool_set_features(dev, useraddr);
2106 break;
2107 case ETHTOOL_GTXCSUM:
2108 case ETHTOOL_GRXCSUM:
2109 case ETHTOOL_GSG:
2110 case ETHTOOL_GTSO:
2111 case ETHTOOL_GUFO:
2112 case ETHTOOL_GGSO:
2113 case ETHTOOL_GGRO:
2114 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
2115 break;
2116 case ETHTOOL_STXCSUM:
2117 case ETHTOOL_SRXCSUM:
2118 case ETHTOOL_SSG:
2119 case ETHTOOL_STSO:
2120 case ETHTOOL_SUFO:
2121 case ETHTOOL_SGSO:
2122 case ETHTOOL_SGRO:
2123 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
2124 break;
2125 case ETHTOOL_GCHANNELS:
2126 rc = ethtool_get_channels(dev, useraddr);
2127 break;
2128 case ETHTOOL_SCHANNELS:
2129 rc = ethtool_set_channels(dev, useraddr);
2130 break;
2131 case ETHTOOL_SET_DUMP:
2132 rc = ethtool_set_dump(dev, useraddr);
2133 break;
2134 case ETHTOOL_GET_DUMP_FLAG:
2135 rc = ethtool_get_dump_flag(dev, useraddr);
2136 break;
2137 case ETHTOOL_GET_DUMP_DATA:
2138 rc = ethtool_get_dump_data(dev, useraddr);
2139 break;
2140 case ETHTOOL_GET_TS_INFO:
2141 rc = ethtool_get_ts_info(dev, useraddr);
2142 break;
2143 case ETHTOOL_GMODULEINFO:
2144 rc = ethtool_get_module_info(dev, useraddr);
2145 break;
2146 case ETHTOOL_GMODULEEEPROM:
2147 rc = ethtool_get_module_eeprom(dev, useraddr);
2148 break;
2149 case ETHTOOL_GTUNABLE:
2150 rc = ethtool_get_tunable(dev, useraddr);
2151 break;
2152 case ETHTOOL_STUNABLE:
2153 rc = ethtool_set_tunable(dev, useraddr);
2154 break;
2155 case ETHTOOL_GPHYSTATS:
2156 rc = ethtool_get_phy_stats(dev, useraddr);
2157 break;
2158 case ETHTOOL_PERQUEUE:
2159 rc = ethtool_set_per_queue(dev, useraddr);
2160 break;
2161 default:
2162 rc = -EOPNOTSUPP;
2163 }
2164
2165 if (dev->ethtool_ops->complete)
2166 dev->ethtool_ops->complete(dev);
2167
2168 if (old_features != dev->features)
2169 netdev_features_change(dev);
2170
2171 return rc;
2172 }