]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/core/ethtool.c
Revert "ethtool: Add n-tuple string length to drvinfo and return it"
[net-next-2.6.git] / net / core / ethtool.c
CommitLineData
1da177e4
LT
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
61a44b9c 6 * the information ethtool needs.
1da177e4 7 *
61a44b9c
MW
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.
1da177e4
LT
12 */
13
14#include <linux/module.h>
15#include <linux/types.h>
4fc268d2 16#include <linux/capability.h>
1da177e4
LT
17#include <linux/errno.h>
18#include <linux/ethtool.h>
19#include <linux/netdevice.h>
20#include <asm/uaccess.h>
21
4ec93edb 22/*
1da177e4
LT
23 * Some useful ethtool_ops methods that're device independent.
24 * If we find that all drivers want to do the same thing here,
25 * we can turn these into dev_() function calls.
26 */
27
28u32 ethtool_op_get_link(struct net_device *dev)
29{
30 return netif_carrier_ok(dev) ? 1 : 0;
31}
32
1896e61f
SS
33u32 ethtool_op_get_rx_csum(struct net_device *dev)
34{
35 return (dev->features & NETIF_F_ALL_CSUM) != 0;
36}
8a729fce 37EXPORT_SYMBOL(ethtool_op_get_rx_csum);
1896e61f 38
1da177e4
LT
39u32 ethtool_op_get_tx_csum(struct net_device *dev)
40{
8648b305 41 return (dev->features & NETIF_F_ALL_CSUM) != 0;
1da177e4 42}
8a729fce 43EXPORT_SYMBOL(ethtool_op_get_tx_csum);
1da177e4
LT
44
45int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
46{
47 if (data)
48 dev->features |= NETIF_F_IP_CSUM;
49 else
50 dev->features &= ~NETIF_F_IP_CSUM;
51
52 return 0;
53}
54
69f6a0fa
JM
55int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data)
56{
57 if (data)
58 dev->features |= NETIF_F_HW_CSUM;
59 else
60 dev->features &= ~NETIF_F_HW_CSUM;
61
62 return 0;
63}
6460d948
MC
64
65int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data)
66{
67 if (data)
68 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
69 else
70 dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
71
72 return 0;
73}
74
1da177e4
LT
75u32 ethtool_op_get_sg(struct net_device *dev)
76{
77 return (dev->features & NETIF_F_SG) != 0;
78}
79
80int ethtool_op_set_sg(struct net_device *dev, u32 data)
81{
82 if (data)
83 dev->features |= NETIF_F_SG;
84 else
85 dev->features &= ~NETIF_F_SG;
86
87 return 0;
88}
89
90u32 ethtool_op_get_tso(struct net_device *dev)
91{
92 return (dev->features & NETIF_F_TSO) != 0;
93}
94
95int ethtool_op_set_tso(struct net_device *dev, u32 data)
96{
97 if (data)
98 dev->features |= NETIF_F_TSO;
99 else
100 dev->features &= ~NETIF_F_TSO;
101
102 return 0;
103}
104
e89e9cf5
AR
105u32 ethtool_op_get_ufo(struct net_device *dev)
106{
107 return (dev->features & NETIF_F_UFO) != 0;
108}
109
110int ethtool_op_set_ufo(struct net_device *dev, u32 data)
111{
112 if (data)
113 dev->features |= NETIF_F_UFO;
114 else
115 dev->features &= ~NETIF_F_UFO;
116 return 0;
117}
118
3ae7c0b2
JG
119/* the following list of flags are the same as their associated
120 * NETIF_F_xxx values in include/linux/netdevice.h
121 */
122static const u32 flags_dup_features =
15682bc4 123 (ETH_FLAG_LRO | ETH_FLAG_NTUPLE);
3ae7c0b2
JG
124
125u32 ethtool_op_get_flags(struct net_device *dev)
126{
127 /* in the future, this function will probably contain additional
128 * handling for flags which are not so easily handled
129 * by a simple masking operation
130 */
131
132 return dev->features & flags_dup_features;
133}
134
135int ethtool_op_set_flags(struct net_device *dev, u32 data)
136{
0d643e1f
PW
137 const struct ethtool_ops *ops = dev->ethtool_ops;
138
3ae7c0b2
JG
139 if (data & ETH_FLAG_LRO)
140 dev->features |= NETIF_F_LRO;
141 else
142 dev->features &= ~NETIF_F_LRO;
143
0d643e1f
PW
144 if (data & ETH_FLAG_NTUPLE) {
145 if (!ops->set_rx_ntuple)
146 return -EOPNOTSUPP;
15682bc4 147 dev->features |= NETIF_F_NTUPLE;
0d643e1f
PW
148 } else {
149 /* safe to clear regardless */
15682bc4 150 dev->features &= ~NETIF_F_NTUPLE;
0d643e1f 151 }
15682bc4 152
3ae7c0b2
JG
153 return 0;
154}
155
15682bc4
PWJ
156void ethtool_ntuple_flush(struct net_device *dev)
157{
158 struct ethtool_rx_ntuple_flow_spec_container *fsc, *f;
159
160 list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) {
161 list_del(&fsc->list);
162 kfree(fsc);
163 }
164 dev->ethtool_ntuple_list.count = 0;
165}
166EXPORT_SYMBOL(ethtool_ntuple_flush);
167
1da177e4
LT
168/* Handlers for each ethtool command */
169
170static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
171{
8e557421 172 struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
1da177e4
LT
173 int err;
174
175 if (!dev->ethtool_ops->get_settings)
176 return -EOPNOTSUPP;
177
178 err = dev->ethtool_ops->get_settings(dev, &cmd);
179 if (err < 0)
180 return err;
181
182 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
183 return -EFAULT;
184 return 0;
185}
186
187static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
188{
189 struct ethtool_cmd cmd;
190
191 if (!dev->ethtool_ops->set_settings)
192 return -EOPNOTSUPP;
193
194 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
195 return -EFAULT;
196
197 return dev->ethtool_ops->set_settings(dev, &cmd);
198}
199
339c6e99
ED
200/*
201 * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
202 */
203static noinline int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
1da177e4
LT
204{
205 struct ethtool_drvinfo info;
76fd8593 206 const struct ethtool_ops *ops = dev->ethtool_ops;
1da177e4
LT
207
208 if (!ops->get_drvinfo)
209 return -EOPNOTSUPP;
210
211 memset(&info, 0, sizeof(info));
212 info.cmd = ETHTOOL_GDRVINFO;
213 ops->get_drvinfo(dev, &info);
214
ff03d49f
JG
215 if (ops->get_sset_count) {
216 int rc;
217
218 rc = ops->get_sset_count(dev, ETH_SS_TEST);
219 if (rc >= 0)
220 info.testinfo_len = rc;
221 rc = ops->get_sset_count(dev, ETH_SS_STATS);
222 if (rc >= 0)
223 info.n_stats = rc;
339bf024
JG
224 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
225 if (rc >= 0)
226 info.n_priv_flags = rc;
ff03d49f 227 }
1da177e4
LT
228 if (ops->get_regs_len)
229 info.regdump_len = ops->get_regs_len(dev);
230 if (ops->get_eeprom_len)
231 info.eedump_len = ops->get_eeprom_len(dev);
232
233 if (copy_to_user(useraddr, &info, sizeof(info)))
234 return -EFAULT;
235 return 0;
236}
237
339c6e99
ED
238/*
239 * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
240 */
241static noinline int ethtool_set_rxnfc(struct net_device *dev, void __user *useraddr)
0853ad66
SB
242{
243 struct ethtool_rxnfc cmd;
244
59089d8d 245 if (!dev->ethtool_ops->set_rxnfc)
0853ad66
SB
246 return -EOPNOTSUPP;
247
248 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
249 return -EFAULT;
250
59089d8d 251 return dev->ethtool_ops->set_rxnfc(dev, &cmd);
0853ad66
SB
252}
253
339c6e99
ED
254/*
255 * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
256 */
257static noinline int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr)
0853ad66
SB
258{
259 struct ethtool_rxnfc info;
59089d8d
SB
260 const struct ethtool_ops *ops = dev->ethtool_ops;
261 int ret;
262 void *rule_buf = NULL;
0853ad66 263
59089d8d 264 if (!ops->get_rxnfc)
0853ad66
SB
265 return -EOPNOTSUPP;
266
267 if (copy_from_user(&info, useraddr, sizeof(info)))
268 return -EFAULT;
269
59089d8d
SB
270 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
271 if (info.rule_cnt > 0) {
272 rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
273 GFP_USER);
274 if (!rule_buf)
275 return -ENOMEM;
276 }
277 }
0853ad66 278
59089d8d
SB
279 ret = ops->get_rxnfc(dev, &info, rule_buf);
280 if (ret < 0)
281 goto err_out;
282
283 ret = -EFAULT;
0853ad66 284 if (copy_to_user(useraddr, &info, sizeof(info)))
59089d8d
SB
285 goto err_out;
286
287 if (rule_buf) {
288 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
289 if (copy_to_user(useraddr, rule_buf,
290 info.rule_cnt * sizeof(u32)))
291 goto err_out;
292 }
293 ret = 0;
294
295err_out:
c9caceca 296 kfree(rule_buf);
59089d8d
SB
297
298 return ret;
0853ad66
SB
299}
300
e8589118
PW
301static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
302 struct ethtool_rx_ntuple_flow_spec *spec,
303 struct ethtool_rx_ntuple_flow_spec_container *fsc)
15682bc4 304{
15682bc4
PWJ
305
306 /* don't add filters forever */
e8589118
PW
307 if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
308 /* free the container */
309 kfree(fsc);
310 return;
311 }
15682bc4
PWJ
312
313 /* Copy the whole filter over */
314 fsc->fs.flow_type = spec->flow_type;
315 memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
316 memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
317
318 fsc->fs.vlan_tag = spec->vlan_tag;
319 fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
320 fsc->fs.data = spec->data;
321 fsc->fs.data_mask = spec->data_mask;
322 fsc->fs.action = spec->action;
323
324 /* add to the list */
325 list_add_tail_rcu(&fsc->list, &list->list);
326 list->count++;
15682bc4
PWJ
327}
328
339c6e99
ED
329/*
330 * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
331 */
332static noinline int ethtool_set_rx_ntuple(struct net_device *dev, void __user *useraddr)
15682bc4
PWJ
333{
334 struct ethtool_rx_ntuple cmd;
335 const struct ethtool_ops *ops = dev->ethtool_ops;
e8589118 336 struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
15682bc4
PWJ
337 int ret;
338
15682bc4
PWJ
339 if (!(dev->features & NETIF_F_NTUPLE))
340 return -EINVAL;
341
342 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
343 return -EFAULT;
344
15682bc4
PWJ
345 /*
346 * Cache filter in dev struct for GET operation only if
347 * the underlying driver doesn't have its own GET operation, and
e8589118
PW
348 * only if the filter was added successfully. First make sure we
349 * can allocate the filter, then continue if successful.
15682bc4 350 */
e8589118
PW
351 if (!ops->get_rx_ntuple) {
352 fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
353 if (!fsc)
15682bc4 354 return -ENOMEM;
e8589118
PW
355 }
356
357 ret = ops->set_rx_ntuple(dev, &cmd);
358 if (ret) {
359 kfree(fsc);
360 return ret;
361 }
362
363 if (!ops->get_rx_ntuple)
364 __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
15682bc4
PWJ
365
366 return ret;
367}
368
369static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
370{
371 struct ethtool_gstrings gstrings;
372 const struct ethtool_ops *ops = dev->ethtool_ops;
373 struct ethtool_rx_ntuple_flow_spec_container *fsc;
374 u8 *data;
375 char *p;
376 int ret, i, num_strings = 0;
377
378 if (!ops->get_sset_count)
379 return -EOPNOTSUPP;
380
381 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
382 return -EFAULT;
383
384 ret = ops->get_sset_count(dev, gstrings.string_set);
385 if (ret < 0)
386 return ret;
387
388 gstrings.len = ret;
389
390 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
391 if (!data)
392 return -ENOMEM;
393
394 if (ops->get_rx_ntuple) {
395 /* driver-specific filter grab */
396 ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
397 goto copy;
398 }
399
400 /* default ethtool filter grab */
401 i = 0;
402 p = (char *)data;
403 list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
404 sprintf(p, "Filter %d:\n", i);
405 p += ETH_GSTRING_LEN;
406 num_strings++;
407
408 switch (fsc->fs.flow_type) {
409 case TCP_V4_FLOW:
410 sprintf(p, "\tFlow Type: TCP\n");
411 p += ETH_GSTRING_LEN;
412 num_strings++;
413 break;
414 case UDP_V4_FLOW:
415 sprintf(p, "\tFlow Type: UDP\n");
416 p += ETH_GSTRING_LEN;
417 num_strings++;
418 break;
419 case SCTP_V4_FLOW:
420 sprintf(p, "\tFlow Type: SCTP\n");
421 p += ETH_GSTRING_LEN;
422 num_strings++;
423 break;
424 case AH_ESP_V4_FLOW:
425 sprintf(p, "\tFlow Type: AH ESP\n");
426 p += ETH_GSTRING_LEN;
427 num_strings++;
428 break;
429 case ESP_V4_FLOW:
430 sprintf(p, "\tFlow Type: ESP\n");
431 p += ETH_GSTRING_LEN;
432 num_strings++;
433 break;
434 case IP_USER_FLOW:
435 sprintf(p, "\tFlow Type: Raw IP\n");
436 p += ETH_GSTRING_LEN;
437 num_strings++;
438 break;
439 case IPV4_FLOW:
440 sprintf(p, "\tFlow Type: IPv4\n");
441 p += ETH_GSTRING_LEN;
442 num_strings++;
443 break;
444 default:
445 sprintf(p, "\tFlow Type: Unknown\n");
446 p += ETH_GSTRING_LEN;
447 num_strings++;
448 goto unknown_filter;
449 };
450
451 /* now the rest of the filters */
452 switch (fsc->fs.flow_type) {
453 case TCP_V4_FLOW:
454 case UDP_V4_FLOW:
455 case SCTP_V4_FLOW:
456 sprintf(p, "\tSrc IP addr: 0x%x\n",
457 fsc->fs.h_u.tcp_ip4_spec.ip4src);
458 p += ETH_GSTRING_LEN;
459 num_strings++;
460 sprintf(p, "\tSrc IP mask: 0x%x\n",
461 fsc->fs.m_u.tcp_ip4_spec.ip4src);
462 p += ETH_GSTRING_LEN;
463 num_strings++;
464 sprintf(p, "\tDest IP addr: 0x%x\n",
465 fsc->fs.h_u.tcp_ip4_spec.ip4dst);
466 p += ETH_GSTRING_LEN;
467 num_strings++;
468 sprintf(p, "\tDest IP mask: 0x%x\n",
469 fsc->fs.m_u.tcp_ip4_spec.ip4dst);
470 p += ETH_GSTRING_LEN;
471 num_strings++;
472 sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
473 fsc->fs.h_u.tcp_ip4_spec.psrc,
474 fsc->fs.m_u.tcp_ip4_spec.psrc);
475 p += ETH_GSTRING_LEN;
476 num_strings++;
477 sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
478 fsc->fs.h_u.tcp_ip4_spec.pdst,
479 fsc->fs.m_u.tcp_ip4_spec.pdst);
480 p += ETH_GSTRING_LEN;
481 num_strings++;
482 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
483 fsc->fs.h_u.tcp_ip4_spec.tos,
484 fsc->fs.m_u.tcp_ip4_spec.tos);
485 p += ETH_GSTRING_LEN;
486 num_strings++;
487 break;
488 case AH_ESP_V4_FLOW:
489 case ESP_V4_FLOW:
490 sprintf(p, "\tSrc IP addr: 0x%x\n",
491 fsc->fs.h_u.ah_ip4_spec.ip4src);
492 p += ETH_GSTRING_LEN;
493 num_strings++;
494 sprintf(p, "\tSrc IP mask: 0x%x\n",
495 fsc->fs.m_u.ah_ip4_spec.ip4src);
496 p += ETH_GSTRING_LEN;
497 num_strings++;
498 sprintf(p, "\tDest IP addr: 0x%x\n",
499 fsc->fs.h_u.ah_ip4_spec.ip4dst);
500 p += ETH_GSTRING_LEN;
501 num_strings++;
502 sprintf(p, "\tDest IP mask: 0x%x\n",
503 fsc->fs.m_u.ah_ip4_spec.ip4dst);
504 p += ETH_GSTRING_LEN;
505 num_strings++;
506 sprintf(p, "\tSPI: %d, mask: 0x%x\n",
507 fsc->fs.h_u.ah_ip4_spec.spi,
508 fsc->fs.m_u.ah_ip4_spec.spi);
509 p += ETH_GSTRING_LEN;
510 num_strings++;
511 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
512 fsc->fs.h_u.ah_ip4_spec.tos,
513 fsc->fs.m_u.ah_ip4_spec.tos);
514 p += ETH_GSTRING_LEN;
515 num_strings++;
516 break;
517 case IP_USER_FLOW:
518 sprintf(p, "\tSrc IP addr: 0x%x\n",
519 fsc->fs.h_u.raw_ip4_spec.ip4src);
520 p += ETH_GSTRING_LEN;
521 num_strings++;
522 sprintf(p, "\tSrc IP mask: 0x%x\n",
523 fsc->fs.m_u.raw_ip4_spec.ip4src);
524 p += ETH_GSTRING_LEN;
525 num_strings++;
526 sprintf(p, "\tDest IP addr: 0x%x\n",
527 fsc->fs.h_u.raw_ip4_spec.ip4dst);
528 p += ETH_GSTRING_LEN;
529 num_strings++;
530 sprintf(p, "\tDest IP mask: 0x%x\n",
531 fsc->fs.m_u.raw_ip4_spec.ip4dst);
532 p += ETH_GSTRING_LEN;
533 num_strings++;
534 break;
535 case IPV4_FLOW:
536 sprintf(p, "\tSrc IP addr: 0x%x\n",
537 fsc->fs.h_u.usr_ip4_spec.ip4src);
538 p += ETH_GSTRING_LEN;
539 num_strings++;
540 sprintf(p, "\tSrc IP mask: 0x%x\n",
541 fsc->fs.m_u.usr_ip4_spec.ip4src);
542 p += ETH_GSTRING_LEN;
543 num_strings++;
544 sprintf(p, "\tDest IP addr: 0x%x\n",
545 fsc->fs.h_u.usr_ip4_spec.ip4dst);
546 p += ETH_GSTRING_LEN;
547 num_strings++;
548 sprintf(p, "\tDest IP mask: 0x%x\n",
549 fsc->fs.m_u.usr_ip4_spec.ip4dst);
550 p += ETH_GSTRING_LEN;
551 num_strings++;
552 sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
553 fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
554 fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
555 p += ETH_GSTRING_LEN;
556 num_strings++;
557 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
558 fsc->fs.h_u.usr_ip4_spec.tos,
559 fsc->fs.m_u.usr_ip4_spec.tos);
560 p += ETH_GSTRING_LEN;
561 num_strings++;
562 sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
563 fsc->fs.h_u.usr_ip4_spec.ip_ver,
564 fsc->fs.m_u.usr_ip4_spec.ip_ver);
565 p += ETH_GSTRING_LEN;
566 num_strings++;
567 sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
568 fsc->fs.h_u.usr_ip4_spec.proto,
569 fsc->fs.m_u.usr_ip4_spec.proto);
570 p += ETH_GSTRING_LEN;
571 num_strings++;
572 break;
573 };
574 sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
575 fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
576 p += ETH_GSTRING_LEN;
577 num_strings++;
578 sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
579 p += ETH_GSTRING_LEN;
580 num_strings++;
581 sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
582 p += ETH_GSTRING_LEN;
583 num_strings++;
584 if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
585 sprintf(p, "\tAction: Drop\n");
586 else
587 sprintf(p, "\tAction: Direct to queue %d\n",
588 fsc->fs.action);
589 p += ETH_GSTRING_LEN;
590 num_strings++;
591unknown_filter:
592 i++;
593 }
594copy:
595 /* indicate to userspace how many strings we actually have */
596 gstrings.len = num_strings;
597 ret = -EFAULT;
598 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
599 goto out;
600 useraddr += sizeof(gstrings);
601 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
602 goto out;
603 ret = 0;
604
605out:
606 kfree(data);
607 return ret;
608}
609
1da177e4
LT
610static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
611{
612 struct ethtool_regs regs;
76fd8593 613 const struct ethtool_ops *ops = dev->ethtool_ops;
1da177e4
LT
614 void *regbuf;
615 int reglen, ret;
616
617 if (!ops->get_regs || !ops->get_regs_len)
618 return -EOPNOTSUPP;
619
620 if (copy_from_user(&regs, useraddr, sizeof(regs)))
621 return -EFAULT;
622
623 reglen = ops->get_regs_len(dev);
624 if (regs.len > reglen)
625 regs.len = reglen;
626
627 regbuf = kmalloc(reglen, GFP_USER);
628 if (!regbuf)
629 return -ENOMEM;
630
631 ops->get_regs(dev, &regs, regbuf);
632
633 ret = -EFAULT;
634 if (copy_to_user(useraddr, &regs, sizeof(regs)))
635 goto out;
636 useraddr += offsetof(struct ethtool_regs, data);
637 if (copy_to_user(useraddr, regbuf, regs.len))
638 goto out;
639 ret = 0;
640
641 out:
642 kfree(regbuf);
643 return ret;
644}
645
d73d3a8c
BH
646static int ethtool_reset(struct net_device *dev, char __user *useraddr)
647{
648 struct ethtool_value reset;
649 int ret;
650
651 if (!dev->ethtool_ops->reset)
652 return -EOPNOTSUPP;
653
654 if (copy_from_user(&reset, useraddr, sizeof(reset)))
655 return -EFAULT;
656
657 ret = dev->ethtool_ops->reset(dev, &reset.data);
658 if (ret)
659 return ret;
660
661 if (copy_to_user(useraddr, &reset, sizeof(reset)))
662 return -EFAULT;
663 return 0;
664}
665
1da177e4
LT
666static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
667{
8e557421 668 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
1da177e4
LT
669
670 if (!dev->ethtool_ops->get_wol)
671 return -EOPNOTSUPP;
672
673 dev->ethtool_ops->get_wol(dev, &wol);
674
675 if (copy_to_user(useraddr, &wol, sizeof(wol)))
676 return -EFAULT;
677 return 0;
678}
679
680static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
681{
682 struct ethtool_wolinfo wol;
683
684 if (!dev->ethtool_ops->set_wol)
685 return -EOPNOTSUPP;
686
687 if (copy_from_user(&wol, useraddr, sizeof(wol)))
688 return -EFAULT;
689
690 return dev->ethtool_ops->set_wol(dev, &wol);
691}
692
1da177e4
LT
693static int ethtool_nway_reset(struct net_device *dev)
694{
695 if (!dev->ethtool_ops->nway_reset)
696 return -EOPNOTSUPP;
697
698 return dev->ethtool_ops->nway_reset(dev);
699}
700
1da177e4
LT
701static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
702{
703 struct ethtool_eeprom eeprom;
76fd8593 704 const struct ethtool_ops *ops = dev->ethtool_ops;
b131dd5d
MSB
705 void __user *userbuf = useraddr + sizeof(eeprom);
706 u32 bytes_remaining;
1da177e4 707 u8 *data;
b131dd5d 708 int ret = 0;
1da177e4
LT
709
710 if (!ops->get_eeprom || !ops->get_eeprom_len)
711 return -EOPNOTSUPP;
712
713 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
714 return -EFAULT;
715
716 /* Check for wrap and zero */
717 if (eeprom.offset + eeprom.len <= eeprom.offset)
718 return -EINVAL;
719
720 /* Check for exceeding total eeprom len */
721 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
722 return -EINVAL;
723
b131dd5d 724 data = kmalloc(PAGE_SIZE, GFP_USER);
1da177e4
LT
725 if (!data)
726 return -ENOMEM;
727
b131dd5d
MSB
728 bytes_remaining = eeprom.len;
729 while (bytes_remaining > 0) {
730 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
731
732 ret = ops->get_eeprom(dev, &eeprom, data);
733 if (ret)
734 break;
735 if (copy_to_user(userbuf, data, eeprom.len)) {
736 ret = -EFAULT;
737 break;
738 }
739 userbuf += eeprom.len;
740 eeprom.offset += eeprom.len;
741 bytes_remaining -= eeprom.len;
742 }
1da177e4 743
c5835df9
MSB
744 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
745 eeprom.offset -= eeprom.len;
746 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
747 ret = -EFAULT;
748
1da177e4
LT
749 kfree(data);
750 return ret;
751}
752
753static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
754{
755 struct ethtool_eeprom eeprom;
76fd8593 756 const struct ethtool_ops *ops = dev->ethtool_ops;
b131dd5d
MSB
757 void __user *userbuf = useraddr + sizeof(eeprom);
758 u32 bytes_remaining;
1da177e4 759 u8 *data;
b131dd5d 760 int ret = 0;
1da177e4
LT
761
762 if (!ops->set_eeprom || !ops->get_eeprom_len)
763 return -EOPNOTSUPP;
764
765 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
766 return -EFAULT;
767
768 /* Check for wrap and zero */
769 if (eeprom.offset + eeprom.len <= eeprom.offset)
770 return -EINVAL;
771
772 /* Check for exceeding total eeprom len */
773 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
774 return -EINVAL;
775
b131dd5d 776 data = kmalloc(PAGE_SIZE, GFP_USER);
1da177e4
LT
777 if (!data)
778 return -ENOMEM;
779
b131dd5d
MSB
780 bytes_remaining = eeprom.len;
781 while (bytes_remaining > 0) {
782 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
783
784 if (copy_from_user(data, userbuf, eeprom.len)) {
785 ret = -EFAULT;
786 break;
787 }
788 ret = ops->set_eeprom(dev, &eeprom, data);
789 if (ret)
790 break;
791 userbuf += eeprom.len;
792 eeprom.offset += eeprom.len;
793 bytes_remaining -= eeprom.len;
794 }
1da177e4 795
1da177e4
LT
796 kfree(data);
797 return ret;
798}
799
339c6e99
ED
800/*
801 * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
802 */
803static noinline int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
1da177e4 804{
8e557421 805 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
1da177e4
LT
806
807 if (!dev->ethtool_ops->get_coalesce)
808 return -EOPNOTSUPP;
809
810 dev->ethtool_ops->get_coalesce(dev, &coalesce);
811
812 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
813 return -EFAULT;
814 return 0;
815}
816
339c6e99
ED
817/*
818 * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
819 */
820static noinline int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
1da177e4
LT
821{
822 struct ethtool_coalesce coalesce;
823
fa04ae5c 824 if (!dev->ethtool_ops->set_coalesce)
1da177e4
LT
825 return -EOPNOTSUPP;
826
827 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
828 return -EFAULT;
829
830 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
831}
832
833static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
834{
8e557421 835 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
1da177e4
LT
836
837 if (!dev->ethtool_ops->get_ringparam)
838 return -EOPNOTSUPP;
839
840 dev->ethtool_ops->get_ringparam(dev, &ringparam);
841
842 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
843 return -EFAULT;
844 return 0;
845}
846
847static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
848{
849 struct ethtool_ringparam ringparam;
850
851 if (!dev->ethtool_ops->set_ringparam)
852 return -EOPNOTSUPP;
853
854 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
855 return -EFAULT;
856
857 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
858}
859
860static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
861{
862 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
863
864 if (!dev->ethtool_ops->get_pauseparam)
865 return -EOPNOTSUPP;
866
867 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
868
869 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
870 return -EFAULT;
871 return 0;
872}
873
874static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
875{
876 struct ethtool_pauseparam pauseparam;
877
e1b90c41 878 if (!dev->ethtool_ops->set_pauseparam)
1da177e4
LT
879 return -EOPNOTSUPP;
880
881 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
882 return -EFAULT;
883
884 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
885}
886
1da177e4
LT
887static int __ethtool_set_sg(struct net_device *dev, u32 data)
888{
889 int err;
890
891 if (!data && dev->ethtool_ops->set_tso) {
892 err = dev->ethtool_ops->set_tso(dev, 0);
893 if (err)
894 return err;
895 }
896
e89e9cf5
AR
897 if (!data && dev->ethtool_ops->set_ufo) {
898 err = dev->ethtool_ops->set_ufo(dev, 0);
899 if (err)
900 return err;
901 }
1da177e4
LT
902 return dev->ethtool_ops->set_sg(dev, data);
903}
904
905static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
906{
907 struct ethtool_value edata;
908 int err;
909
910 if (!dev->ethtool_ops->set_tx_csum)
911 return -EOPNOTSUPP;
912
913 if (copy_from_user(&edata, useraddr, sizeof(edata)))
914 return -EFAULT;
915
916 if (!edata.data && dev->ethtool_ops->set_sg) {
917 err = __ethtool_set_sg(dev, 0);
918 if (err)
919 return err;
920 }
921
922 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
923}
924
b240a0e5
HX
925static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
926{
927 struct ethtool_value edata;
928
929 if (!dev->ethtool_ops->set_rx_csum)
930 return -EOPNOTSUPP;
931
932 if (copy_from_user(&edata, useraddr, sizeof(edata)))
933 return -EFAULT;
934
935 if (!edata.data && dev->ethtool_ops->set_sg)
936 dev->features &= ~NETIF_F_GRO;
937
938 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
939}
940
1da177e4
LT
941static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
942{
943 struct ethtool_value edata;
944
945 if (!dev->ethtool_ops->set_sg)
946 return -EOPNOTSUPP;
947
948 if (copy_from_user(&edata, useraddr, sizeof(edata)))
949 return -EFAULT;
950
4ec93edb 951 if (edata.data &&
8648b305 952 !(dev->features & NETIF_F_ALL_CSUM))
1da177e4
LT
953 return -EINVAL;
954
955 return __ethtool_set_sg(dev, edata.data);
956}
957
1da177e4
LT
958static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
959{
960 struct ethtool_value edata;
961
962 if (!dev->ethtool_ops->set_tso)
963 return -EOPNOTSUPP;
964
965 if (copy_from_user(&edata, useraddr, sizeof(edata)))
966 return -EFAULT;
967
968 if (edata.data && !(dev->features & NETIF_F_SG))
969 return -EINVAL;
970
971 return dev->ethtool_ops->set_tso(dev, edata.data);
972}
973
e89e9cf5
AR
974static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
975{
976 struct ethtool_value edata;
977
978 if (!dev->ethtool_ops->set_ufo)
979 return -EOPNOTSUPP;
980 if (copy_from_user(&edata, useraddr, sizeof(edata)))
981 return -EFAULT;
982 if (edata.data && !(dev->features & NETIF_F_SG))
983 return -EINVAL;
984 if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
985 return -EINVAL;
986 return dev->ethtool_ops->set_ufo(dev, edata.data);
987}
988
37c3185a
HX
989static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
990{
991 struct ethtool_value edata = { ETHTOOL_GGSO };
992
993 edata.data = dev->features & NETIF_F_GSO;
994 if (copy_to_user(useraddr, &edata, sizeof(edata)))
995 return -EFAULT;
996 return 0;
997}
998
999static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
1000{
1001 struct ethtool_value edata;
1002
1003 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1004 return -EFAULT;
1005 if (edata.data)
1006 dev->features |= NETIF_F_GSO;
1007 else
1008 dev->features &= ~NETIF_F_GSO;
1009 return 0;
1010}
1011
b240a0e5
HX
1012static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
1013{
1014 struct ethtool_value edata = { ETHTOOL_GGRO };
1015
1016 edata.data = dev->features & NETIF_F_GRO;
1017 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1018 return -EFAULT;
1019 return 0;
1020}
1021
1022static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
1023{
1024 struct ethtool_value edata;
1025
1026 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1027 return -EFAULT;
1028
1029 if (edata.data) {
1030 if (!dev->ethtool_ops->get_rx_csum ||
1031 !dev->ethtool_ops->get_rx_csum(dev))
1032 return -EINVAL;
1033 dev->features |= NETIF_F_GRO;
1034 } else
1035 dev->features &= ~NETIF_F_GRO;
1036
1037 return 0;
1038}
1039
1da177e4
LT
1040static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1041{
1042 struct ethtool_test test;
76fd8593 1043 const struct ethtool_ops *ops = dev->ethtool_ops;
1da177e4 1044 u64 *data;
ff03d49f 1045 int ret, test_len;
1da177e4 1046
a9828ec6 1047 if (!ops->self_test || !ops->get_sset_count)
1da177e4
LT
1048 return -EOPNOTSUPP;
1049
a9828ec6 1050 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
ff03d49f
JG
1051 if (test_len < 0)
1052 return test_len;
1053 WARN_ON(test_len == 0);
1054
1da177e4
LT
1055 if (copy_from_user(&test, useraddr, sizeof(test)))
1056 return -EFAULT;
1057
ff03d49f
JG
1058 test.len = test_len;
1059 data = kmalloc(test_len * sizeof(u64), GFP_USER);
1da177e4
LT
1060 if (!data)
1061 return -ENOMEM;
1062
1063 ops->self_test(dev, &test, data);
1064
1065 ret = -EFAULT;
1066 if (copy_to_user(useraddr, &test, sizeof(test)))
1067 goto out;
1068 useraddr += sizeof(test);
1069 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1070 goto out;
1071 ret = 0;
1072
1073 out:
1074 kfree(data);
1075 return ret;
1076}
1077
1078static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1079{
1080 struct ethtool_gstrings gstrings;
76fd8593 1081 const struct ethtool_ops *ops = dev->ethtool_ops;
1da177e4
LT
1082 u8 *data;
1083 int ret;
1084
a9828ec6 1085 if (!ops->get_strings || !ops->get_sset_count)
1da177e4
LT
1086 return -EOPNOTSUPP;
1087
1088 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1089 return -EFAULT;
1090
a9828ec6
BH
1091 ret = ops->get_sset_count(dev, gstrings.string_set);
1092 if (ret < 0)
1093 return ret;
1094
1095 gstrings.len = ret;
1da177e4
LT
1096
1097 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1098 if (!data)
1099 return -ENOMEM;
1100
1101 ops->get_strings(dev, gstrings.string_set, data);
1102
1103 ret = -EFAULT;
1104 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1105 goto out;
1106 useraddr += sizeof(gstrings);
1107 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1108 goto out;
1109 ret = 0;
1110
1111 out:
1112 kfree(data);
1113 return ret;
1114}
1115
1116static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1117{
1118 struct ethtool_value id;
1119
1120 if (!dev->ethtool_ops->phys_id)
1121 return -EOPNOTSUPP;
1122
1123 if (copy_from_user(&id, useraddr, sizeof(id)))
1124 return -EFAULT;
1125
1126 return dev->ethtool_ops->phys_id(dev, id.data);
1127}
1128
1129static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1130{
1131 struct ethtool_stats stats;
76fd8593 1132 const struct ethtool_ops *ops = dev->ethtool_ops;
1da177e4 1133 u64 *data;
ff03d49f 1134 int ret, n_stats;
1da177e4 1135
a9828ec6 1136 if (!ops->get_ethtool_stats || !ops->get_sset_count)
1da177e4
LT
1137 return -EOPNOTSUPP;
1138
a9828ec6 1139 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
ff03d49f
JG
1140 if (n_stats < 0)
1141 return n_stats;
1142 WARN_ON(n_stats == 0);
1143
1da177e4
LT
1144 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1145 return -EFAULT;
1146
ff03d49f
JG
1147 stats.n_stats = n_stats;
1148 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
1da177e4
LT
1149 if (!data)
1150 return -ENOMEM;
1151
1152 ops->get_ethtool_stats(dev, &stats, data);
1153
1154 ret = -EFAULT;
1155 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1156 goto out;
1157 useraddr += sizeof(stats);
1158 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1159 goto out;
1160 ret = 0;
1161
1162 out:
1163 kfree(data);
1164 return ret;
1165}
1166
0bf0519d 1167static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
a6f9a705
JW
1168{
1169 struct ethtool_perm_addr epaddr;
a6f9a705 1170
313674af 1171 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
a6f9a705
JW
1172 return -EFAULT;
1173
313674af
MW
1174 if (epaddr.size < dev->addr_len)
1175 return -ETOOSMALL;
1176 epaddr.size = dev->addr_len;
a6f9a705 1177
a6f9a705 1178 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
313674af 1179 return -EFAULT;
a6f9a705 1180 useraddr += sizeof(epaddr);
313674af
MW
1181 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1182 return -EFAULT;
1183 return 0;
a6f9a705
JW
1184}
1185
13c99b24
JG
1186static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1187 u32 cmd, u32 (*actor)(struct net_device *))
3ae7c0b2 1188{
8e557421 1189 struct ethtool_value edata = { .cmd = cmd };
3ae7c0b2 1190
13c99b24 1191 if (!actor)
3ae7c0b2
JG
1192 return -EOPNOTSUPP;
1193
13c99b24 1194 edata.data = actor(dev);
3ae7c0b2
JG
1195
1196 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1197 return -EFAULT;
1198 return 0;
1199}
1200
13c99b24
JG
1201static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1202 void (*actor)(struct net_device *, u32))
3ae7c0b2
JG
1203{
1204 struct ethtool_value edata;
1205
13c99b24 1206 if (!actor)
3ae7c0b2
JG
1207 return -EOPNOTSUPP;
1208
1209 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1210 return -EFAULT;
1211
13c99b24 1212 actor(dev, edata.data);
339bf024
JG
1213 return 0;
1214}
1215
13c99b24
JG
1216static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1217 int (*actor)(struct net_device *, u32))
339bf024
JG
1218{
1219 struct ethtool_value edata;
1220
13c99b24 1221 if (!actor)
339bf024
JG
1222 return -EOPNOTSUPP;
1223
1224 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1225 return -EFAULT;
1226
13c99b24 1227 return actor(dev, edata.data);
339bf024
JG
1228}
1229
339c6e99
ED
1230/*
1231 * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
1232 */
1233static noinline int ethtool_flash_device(struct net_device *dev, char __user *useraddr)
05c6a8d7
AK
1234{
1235 struct ethtool_flash efl;
1236
1237 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1238 return -EFAULT;
1239
1240 if (!dev->ethtool_ops->flash_device)
1241 return -EOPNOTSUPP;
1242
1243 return dev->ethtool_ops->flash_device(dev, &efl);
1244}
1245
1da177e4
LT
1246/* The main entry point in this file. Called from net/core/dev.c */
1247
881d966b 1248int dev_ethtool(struct net *net, struct ifreq *ifr)
1da177e4 1249{
881d966b 1250 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
1da177e4
LT
1251 void __user *useraddr = ifr->ifr_data;
1252 u32 ethcmd;
1253 int rc;
81e81575 1254 unsigned long old_features;
1da177e4 1255
1da177e4
LT
1256 if (!dev || !netif_device_present(dev))
1257 return -ENODEV;
1258
1259 if (!dev->ethtool_ops)
61a44b9c 1260 return -EOPNOTSUPP;
1da177e4
LT
1261
1262 if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
1263 return -EFAULT;
1264
75f3123c
SH
1265 /* Allow some commands to be done by anyone */
1266 switch(ethcmd) {
75f3123c 1267 case ETHTOOL_GDRVINFO:
75f3123c 1268 case ETHTOOL_GMSGLVL:
75f3123c
SH
1269 case ETHTOOL_GCOALESCE:
1270 case ETHTOOL_GRINGPARAM:
1271 case ETHTOOL_GPAUSEPARAM:
1272 case ETHTOOL_GRXCSUM:
1273 case ETHTOOL_GTXCSUM:
1274 case ETHTOOL_GSG:
1275 case ETHTOOL_GSTRINGS:
75f3123c
SH
1276 case ETHTOOL_GTSO:
1277 case ETHTOOL_GPERMADDR:
1278 case ETHTOOL_GUFO:
1279 case ETHTOOL_GGSO:
1cab819b 1280 case ETHTOOL_GGRO:
339bf024
JG
1281 case ETHTOOL_GFLAGS:
1282 case ETHTOOL_GPFLAGS:
0853ad66 1283 case ETHTOOL_GRXFH:
59089d8d
SB
1284 case ETHTOOL_GRXRINGS:
1285 case ETHTOOL_GRXCLSRLCNT:
1286 case ETHTOOL_GRXCLSRULE:
1287 case ETHTOOL_GRXCLSRLALL:
75f3123c
SH
1288 break;
1289 default:
1290 if (!capable(CAP_NET_ADMIN))
1291 return -EPERM;
1292 }
1293
e71a4783 1294 if (dev->ethtool_ops->begin)
1da177e4
LT
1295 if ((rc = dev->ethtool_ops->begin(dev)) < 0)
1296 return rc;
1297
d8a33ac4
SH
1298 old_features = dev->features;
1299
1da177e4
LT
1300 switch (ethcmd) {
1301 case ETHTOOL_GSET:
1302 rc = ethtool_get_settings(dev, useraddr);
1303 break;
1304 case ETHTOOL_SSET:
1305 rc = ethtool_set_settings(dev, useraddr);
1306 break;
1307 case ETHTOOL_GDRVINFO:
1308 rc = ethtool_get_drvinfo(dev, useraddr);
1da177e4
LT
1309 break;
1310 case ETHTOOL_GREGS:
1311 rc = ethtool_get_regs(dev, useraddr);
1312 break;
1313 case ETHTOOL_GWOL:
1314 rc = ethtool_get_wol(dev, useraddr);
1315 break;
1316 case ETHTOOL_SWOL:
1317 rc = ethtool_set_wol(dev, useraddr);
1318 break;
1319 case ETHTOOL_GMSGLVL:
13c99b24
JG
1320 rc = ethtool_get_value(dev, useraddr, ethcmd,
1321 dev->ethtool_ops->get_msglevel);
1da177e4
LT
1322 break;
1323 case ETHTOOL_SMSGLVL:
13c99b24
JG
1324 rc = ethtool_set_value_void(dev, useraddr,
1325 dev->ethtool_ops->set_msglevel);
1da177e4
LT
1326 break;
1327 case ETHTOOL_NWAY_RST:
1328 rc = ethtool_nway_reset(dev);
1329 break;
1330 case ETHTOOL_GLINK:
13c99b24
JG
1331 rc = ethtool_get_value(dev, useraddr, ethcmd,
1332 dev->ethtool_ops->get_link);
1da177e4
LT
1333 break;
1334 case ETHTOOL_GEEPROM:
1335 rc = ethtool_get_eeprom(dev, useraddr);
1336 break;
1337 case ETHTOOL_SEEPROM:
1338 rc = ethtool_set_eeprom(dev, useraddr);
1339 break;
1340 case ETHTOOL_GCOALESCE:
1341 rc = ethtool_get_coalesce(dev, useraddr);
1342 break;
1343 case ETHTOOL_SCOALESCE:
1344 rc = ethtool_set_coalesce(dev, useraddr);
1345 break;
1346 case ETHTOOL_GRINGPARAM:
1347 rc = ethtool_get_ringparam(dev, useraddr);
1348 break;
1349 case ETHTOOL_SRINGPARAM:
1350 rc = ethtool_set_ringparam(dev, useraddr);
1351 break;
1352 case ETHTOOL_GPAUSEPARAM:
1353 rc = ethtool_get_pauseparam(dev, useraddr);
1354 break;
1355 case ETHTOOL_SPAUSEPARAM:
1356 rc = ethtool_set_pauseparam(dev, useraddr);
1357 break;
1358 case ETHTOOL_GRXCSUM:
13c99b24 1359 rc = ethtool_get_value(dev, useraddr, ethcmd,
1896e61f
SS
1360 (dev->ethtool_ops->get_rx_csum ?
1361 dev->ethtool_ops->get_rx_csum :
1362 ethtool_op_get_rx_csum));
1da177e4
LT
1363 break;
1364 case ETHTOOL_SRXCSUM:
b240a0e5 1365 rc = ethtool_set_rx_csum(dev, useraddr);
1da177e4
LT
1366 break;
1367 case ETHTOOL_GTXCSUM:
13c99b24 1368 rc = ethtool_get_value(dev, useraddr, ethcmd,
88d3aafd
JG
1369 (dev->ethtool_ops->get_tx_csum ?
1370 dev->ethtool_ops->get_tx_csum :
1371 ethtool_op_get_tx_csum));
1da177e4
LT
1372 break;
1373 case ETHTOOL_STXCSUM:
1374 rc = ethtool_set_tx_csum(dev, useraddr);
1375 break;
1376 case ETHTOOL_GSG:
13c99b24 1377 rc = ethtool_get_value(dev, useraddr, ethcmd,
88d3aafd
JG
1378 (dev->ethtool_ops->get_sg ?
1379 dev->ethtool_ops->get_sg :
1380 ethtool_op_get_sg));
1da177e4
LT
1381 break;
1382 case ETHTOOL_SSG:
1383 rc = ethtool_set_sg(dev, useraddr);
1384 break;
1385 case ETHTOOL_GTSO:
13c99b24 1386 rc = ethtool_get_value(dev, useraddr, ethcmd,
88d3aafd
JG
1387 (dev->ethtool_ops->get_tso ?
1388 dev->ethtool_ops->get_tso :
1389 ethtool_op_get_tso));
1da177e4
LT
1390 break;
1391 case ETHTOOL_STSO:
1392 rc = ethtool_set_tso(dev, useraddr);
1393 break;
1394 case ETHTOOL_TEST:
1395 rc = ethtool_self_test(dev, useraddr);
1396 break;
1397 case ETHTOOL_GSTRINGS:
1398 rc = ethtool_get_strings(dev, useraddr);
1399 break;
1400 case ETHTOOL_PHYS_ID:
1401 rc = ethtool_phys_id(dev, useraddr);
1402 break;
1403 case ETHTOOL_GSTATS:
1404 rc = ethtool_get_stats(dev, useraddr);
1405 break;
a6f9a705
JW
1406 case ETHTOOL_GPERMADDR:
1407 rc = ethtool_get_perm_addr(dev, useraddr);
1408 break;
e89e9cf5 1409 case ETHTOOL_GUFO:
13c99b24 1410 rc = ethtool_get_value(dev, useraddr, ethcmd,
88d3aafd
JG
1411 (dev->ethtool_ops->get_ufo ?
1412 dev->ethtool_ops->get_ufo :
1413 ethtool_op_get_ufo));
e89e9cf5
AR
1414 break;
1415 case ETHTOOL_SUFO:
1416 rc = ethtool_set_ufo(dev, useraddr);
1417 break;
37c3185a
HX
1418 case ETHTOOL_GGSO:
1419 rc = ethtool_get_gso(dev, useraddr);
1420 break;
1421 case ETHTOOL_SGSO:
1422 rc = ethtool_set_gso(dev, useraddr);
1423 break;
3ae7c0b2 1424 case ETHTOOL_GFLAGS:
13c99b24 1425 rc = ethtool_get_value(dev, useraddr, ethcmd,
1896e61f
SS
1426 (dev->ethtool_ops->get_flags ?
1427 dev->ethtool_ops->get_flags :
1428 ethtool_op_get_flags));
3ae7c0b2
JG
1429 break;
1430 case ETHTOOL_SFLAGS:
13c99b24
JG
1431 rc = ethtool_set_value(dev, useraddr,
1432 dev->ethtool_ops->set_flags);
3ae7c0b2 1433 break;
339bf024 1434 case ETHTOOL_GPFLAGS:
13c99b24
JG
1435 rc = ethtool_get_value(dev, useraddr, ethcmd,
1436 dev->ethtool_ops->get_priv_flags);
339bf024
JG
1437 break;
1438 case ETHTOOL_SPFLAGS:
13c99b24
JG
1439 rc = ethtool_set_value(dev, useraddr,
1440 dev->ethtool_ops->set_priv_flags);
339bf024 1441 break;
0853ad66 1442 case ETHTOOL_GRXFH:
59089d8d
SB
1443 case ETHTOOL_GRXRINGS:
1444 case ETHTOOL_GRXCLSRLCNT:
1445 case ETHTOOL_GRXCLSRULE:
1446 case ETHTOOL_GRXCLSRLALL:
1447 rc = ethtool_get_rxnfc(dev, useraddr);
0853ad66
SB
1448 break;
1449 case ETHTOOL_SRXFH:
59089d8d
SB
1450 case ETHTOOL_SRXCLSRLDEL:
1451 case ETHTOOL_SRXCLSRLINS:
1452 rc = ethtool_set_rxnfc(dev, useraddr);
0853ad66 1453 break;
b240a0e5
HX
1454 case ETHTOOL_GGRO:
1455 rc = ethtool_get_gro(dev, useraddr);
1456 break;
1457 case ETHTOOL_SGRO:
1458 rc = ethtool_set_gro(dev, useraddr);
1459 break;
05c6a8d7
AK
1460 case ETHTOOL_FLASHDEV:
1461 rc = ethtool_flash_device(dev, useraddr);
1462 break;
d73d3a8c
BH
1463 case ETHTOOL_RESET:
1464 rc = ethtool_reset(dev, useraddr);
1465 break;
15682bc4
PWJ
1466 case ETHTOOL_SRXNTUPLE:
1467 rc = ethtool_set_rx_ntuple(dev, useraddr);
1468 break;
1469 case ETHTOOL_GRXNTUPLE:
1470 rc = ethtool_get_rx_ntuple(dev, useraddr);
1471 break;
1da177e4 1472 default:
61a44b9c 1473 rc = -EOPNOTSUPP;
1da177e4 1474 }
4ec93edb 1475
e71a4783 1476 if (dev->ethtool_ops->complete)
1da177e4 1477 dev->ethtool_ops->complete(dev);
d8a33ac4
SH
1478
1479 if (old_features != dev->features)
1480 netdev_features_change(dev);
1481
1da177e4 1482 return rc;
1da177e4
LT
1483}
1484
1da177e4
LT
1485EXPORT_SYMBOL(ethtool_op_get_link);
1486EXPORT_SYMBOL(ethtool_op_get_sg);
1487EXPORT_SYMBOL(ethtool_op_get_tso);
1da177e4
LT
1488EXPORT_SYMBOL(ethtool_op_set_sg);
1489EXPORT_SYMBOL(ethtool_op_set_tso);
1490EXPORT_SYMBOL(ethtool_op_set_tx_csum);
69f6a0fa 1491EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
6460d948 1492EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
e89e9cf5
AR
1493EXPORT_SYMBOL(ethtool_op_set_ufo);
1494EXPORT_SYMBOL(ethtool_op_get_ufo);
3ae7c0b2
JG
1495EXPORT_SYMBOL(ethtool_op_set_flags);
1496EXPORT_SYMBOL(ethtool_op_get_flags);