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