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