Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[pandora-kernel.git] / net / core / ethtool.c
1 /*
2  * net/core/ethtool.c - Ethtool ioctl handler
3  * Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx>
4  *
5  * This file is where we call all the ethtool_ops commands to get
6  * the information ethtool needs.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  */
13
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/capability.h>
17 #include <linux/errno.h>
18 #include <linux/ethtool.h>
19 #include <linux/netdevice.h>
20 #include <asm/uaccess.h>
21
22 /*
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
28 u32 ethtool_op_get_link(struct net_device *dev)
29 {
30         return netif_carrier_ok(dev) ? 1 : 0;
31 }
32
33 u32 ethtool_op_get_rx_csum(struct net_device *dev)
34 {
35         return (dev->features & NETIF_F_ALL_CSUM) != 0;
36 }
37 EXPORT_SYMBOL(ethtool_op_get_rx_csum);
38
39 u32 ethtool_op_get_tx_csum(struct net_device *dev)
40 {
41         return (dev->features & NETIF_F_ALL_CSUM) != 0;
42 }
43 EXPORT_SYMBOL(ethtool_op_get_tx_csum);
44
45 int 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
55 int 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 }
64
65 int 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
75 u32 ethtool_op_get_sg(struct net_device *dev)
76 {
77         return (dev->features & NETIF_F_SG) != 0;
78 }
79
80 int 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
90 u32 ethtool_op_get_tso(struct net_device *dev)
91 {
92         return (dev->features & NETIF_F_TSO) != 0;
93 }
94
95 int 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
105 u32 ethtool_op_get_ufo(struct net_device *dev)
106 {
107         return (dev->features & NETIF_F_UFO) != 0;
108 }
109
110 int 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
119 /* the following list of flags are the same as their associated
120  * NETIF_F_xxx values in include/linux/netdevice.h
121  */
122 static const u32 flags_dup_features =
123         (ETH_FLAG_LRO | ETH_FLAG_NTUPLE);
124
125 u32 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
135 int ethtool_op_set_flags(struct net_device *dev, u32 data)
136 {
137         const struct ethtool_ops *ops = dev->ethtool_ops;
138
139         if (data & ETH_FLAG_LRO)
140                 dev->features |= NETIF_F_LRO;
141         else
142                 dev->features &= ~NETIF_F_LRO;
143
144         if (data & ETH_FLAG_NTUPLE) {
145                 if (!ops->set_rx_ntuple)
146                         return -EOPNOTSUPP;
147                 dev->features |= NETIF_F_NTUPLE;
148         } else {
149                 /* safe to clear regardless */
150                 dev->features &= ~NETIF_F_NTUPLE;
151         }
152
153         return 0;
154 }
155
156 void 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 }
166 EXPORT_SYMBOL(ethtool_ntuple_flush);
167
168 /* Handlers for each ethtool command */
169
170 static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
171 {
172         struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
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
187 static 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
200 /*
201  * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
202  */
203 static noinline int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
204 {
205         struct ethtool_drvinfo info;
206         const struct ethtool_ops *ops = dev->ethtool_ops;
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
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;
224                 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
225                 if (rc >= 0)
226                         info.n_priv_flags = rc;
227         }
228         if (ops->get_regs_len)
229                 info.regdump_len = ops->get_regs_len(dev);
230         if (ops->get_eeprom_len)
231                 info.eedump_len = ops->get_eeprom_len(dev);
232
233         if (copy_to_user(useraddr, &info, sizeof(info)))
234                 return -EFAULT;
235         return 0;
236 }
237
238 /*
239  * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
240  */
241 static noinline int ethtool_set_rxnfc(struct net_device *dev, void __user *useraddr)
242 {
243         struct ethtool_rxnfc cmd;
244
245         if (!dev->ethtool_ops->set_rxnfc)
246                 return -EOPNOTSUPP;
247
248         if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
249                 return -EFAULT;
250
251         return dev->ethtool_ops->set_rxnfc(dev, &cmd);
252 }
253
254 /*
255  * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
256  */
257 static noinline int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr)
258 {
259         struct ethtool_rxnfc info;
260         const struct ethtool_ops *ops = dev->ethtool_ops;
261         int ret;
262         void *rule_buf = NULL;
263
264         if (!ops->get_rxnfc)
265                 return -EOPNOTSUPP;
266
267         if (copy_from_user(&info, useraddr, sizeof(info)))
268                 return -EFAULT;
269
270         if (info.cmd == ETHTOOL_GRXCLSRLALL) {
271                 if (info.rule_cnt > 0) {
272                         rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
273                                            GFP_USER);
274                         if (!rule_buf)
275                                 return -ENOMEM;
276                 }
277         }
278
279         ret = ops->get_rxnfc(dev, &info, rule_buf);
280         if (ret < 0)
281                 goto err_out;
282
283         ret = -EFAULT;
284         if (copy_to_user(useraddr, &info, sizeof(info)))
285                 goto err_out;
286
287         if (rule_buf) {
288                 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
289                 if (copy_to_user(useraddr, rule_buf,
290                                  info.rule_cnt * sizeof(u32)))
291                         goto err_out;
292         }
293         ret = 0;
294
295 err_out:
296         kfree(rule_buf);
297
298         return ret;
299 }
300
301 static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
302                               struct ethtool_rx_ntuple_flow_spec *spec,
303                               struct ethtool_rx_ntuple_flow_spec_container *fsc)
304 {
305
306         /* don't add filters forever */
307         if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
308                 /* free the container */
309                 kfree(fsc);
310                 return;
311         }
312
313         /* Copy the whole filter over */
314         fsc->fs.flow_type = spec->flow_type;
315         memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
316         memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
317
318         fsc->fs.vlan_tag = spec->vlan_tag;
319         fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
320         fsc->fs.data = spec->data;
321         fsc->fs.data_mask = spec->data_mask;
322         fsc->fs.action = spec->action;
323
324         /* add to the list */
325         list_add_tail_rcu(&fsc->list, &list->list);
326         list->count++;
327 }
328
329 /*
330  * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
331  */
332 static noinline int ethtool_set_rx_ntuple(struct net_device *dev, void __user *useraddr)
333 {
334         struct ethtool_rx_ntuple cmd;
335         const struct ethtool_ops *ops = dev->ethtool_ops;
336         struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
337         int ret;
338
339         if (!(dev->features & NETIF_F_NTUPLE))
340                 return -EINVAL;
341
342         if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
343                 return -EFAULT;
344
345         /*
346          * Cache filter in dev struct for GET operation only if
347          * the underlying driver doesn't have its own GET operation, and
348          * only if the filter was added successfully.  First make sure we
349          * can allocate the filter, then continue if successful.
350          */
351         if (!ops->get_rx_ntuple) {
352                 fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
353                 if (!fsc)
354                         return -ENOMEM;
355         }
356
357         ret = ops->set_rx_ntuple(dev, &cmd);
358         if (ret) {
359                 kfree(fsc);
360                 return ret;
361         }
362
363         if (!ops->get_rx_ntuple)
364                 __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
365
366         return ret;
367 }
368
369 static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
370 {
371         struct ethtool_gstrings gstrings;
372         const struct ethtool_ops *ops = dev->ethtool_ops;
373         struct ethtool_rx_ntuple_flow_spec_container *fsc;
374         u8 *data;
375         char *p;
376         int ret, i, num_strings = 0;
377
378         if (!ops->get_sset_count)
379                 return -EOPNOTSUPP;
380
381         if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
382                 return -EFAULT;
383
384         ret = ops->get_sset_count(dev, gstrings.string_set);
385         if (ret < 0)
386                 return ret;
387
388         gstrings.len = ret;
389
390         data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
391         if (!data)
392                 return -ENOMEM;
393
394         if (ops->get_rx_ntuple) {
395                 /* driver-specific filter grab */
396                 ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
397                 goto copy;
398         }
399
400         /* default ethtool filter grab */
401         i = 0;
402         p = (char *)data;
403         list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
404                 sprintf(p, "Filter %d:\n", i);
405                 p += ETH_GSTRING_LEN;
406                 num_strings++;
407
408                 switch (fsc->fs.flow_type) {
409                 case TCP_V4_FLOW:
410                         sprintf(p, "\tFlow Type: TCP\n");
411                         p += ETH_GSTRING_LEN;
412                         num_strings++;
413                         break;
414                 case UDP_V4_FLOW:
415                         sprintf(p, "\tFlow Type: UDP\n");
416                         p += ETH_GSTRING_LEN;
417                         num_strings++;
418                         break;
419                 case SCTP_V4_FLOW:
420                         sprintf(p, "\tFlow Type: SCTP\n");
421                         p += ETH_GSTRING_LEN;
422                         num_strings++;
423                         break;
424                 case AH_ESP_V4_FLOW:
425                         sprintf(p, "\tFlow Type: AH ESP\n");
426                         p += ETH_GSTRING_LEN;
427                         num_strings++;
428                         break;
429                 case ESP_V4_FLOW:
430                         sprintf(p, "\tFlow Type: ESP\n");
431                         p += ETH_GSTRING_LEN;
432                         num_strings++;
433                         break;
434                 case IP_USER_FLOW:
435                         sprintf(p, "\tFlow Type: Raw IP\n");
436                         p += ETH_GSTRING_LEN;
437                         num_strings++;
438                         break;
439                 case IPV4_FLOW:
440                         sprintf(p, "\tFlow Type: IPv4\n");
441                         p += ETH_GSTRING_LEN;
442                         num_strings++;
443                         break;
444                 default:
445                         sprintf(p, "\tFlow Type: Unknown\n");
446                         p += ETH_GSTRING_LEN;
447                         num_strings++;
448                         goto unknown_filter;
449                 };
450
451                 /* now the rest of the filters */
452                 switch (fsc->fs.flow_type) {
453                 case TCP_V4_FLOW:
454                 case UDP_V4_FLOW:
455                 case SCTP_V4_FLOW:
456                         sprintf(p, "\tSrc IP addr: 0x%x\n",
457                                 fsc->fs.h_u.tcp_ip4_spec.ip4src);
458                         p += ETH_GSTRING_LEN;
459                         num_strings++;
460                         sprintf(p, "\tSrc IP mask: 0x%x\n",
461                                 fsc->fs.m_u.tcp_ip4_spec.ip4src);
462                         p += ETH_GSTRING_LEN;
463                         num_strings++;
464                         sprintf(p, "\tDest IP addr: 0x%x\n",
465                                 fsc->fs.h_u.tcp_ip4_spec.ip4dst);
466                         p += ETH_GSTRING_LEN;
467                         num_strings++;
468                         sprintf(p, "\tDest IP mask: 0x%x\n",
469                                 fsc->fs.m_u.tcp_ip4_spec.ip4dst);
470                         p += ETH_GSTRING_LEN;
471                         num_strings++;
472                         sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
473                                 fsc->fs.h_u.tcp_ip4_spec.psrc,
474                                 fsc->fs.m_u.tcp_ip4_spec.psrc);
475                         p += ETH_GSTRING_LEN;
476                         num_strings++;
477                         sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
478                                 fsc->fs.h_u.tcp_ip4_spec.pdst,
479                                 fsc->fs.m_u.tcp_ip4_spec.pdst);
480                         p += ETH_GSTRING_LEN;
481                         num_strings++;
482                         sprintf(p, "\tTOS: %d, mask: 0x%x\n",
483                                 fsc->fs.h_u.tcp_ip4_spec.tos,
484                                 fsc->fs.m_u.tcp_ip4_spec.tos);
485                         p += ETH_GSTRING_LEN;
486                         num_strings++;
487                         break;
488                 case AH_ESP_V4_FLOW:
489                 case ESP_V4_FLOW:
490                         sprintf(p, "\tSrc IP addr: 0x%x\n",
491                                 fsc->fs.h_u.ah_ip4_spec.ip4src);
492                         p += ETH_GSTRING_LEN;
493                         num_strings++;
494                         sprintf(p, "\tSrc IP mask: 0x%x\n",
495                                 fsc->fs.m_u.ah_ip4_spec.ip4src);
496                         p += ETH_GSTRING_LEN;
497                         num_strings++;
498                         sprintf(p, "\tDest IP addr: 0x%x\n",
499                                 fsc->fs.h_u.ah_ip4_spec.ip4dst);
500                         p += ETH_GSTRING_LEN;
501                         num_strings++;
502                         sprintf(p, "\tDest IP mask: 0x%x\n",
503                                 fsc->fs.m_u.ah_ip4_spec.ip4dst);
504                         p += ETH_GSTRING_LEN;
505                         num_strings++;
506                         sprintf(p, "\tSPI: %d, mask: 0x%x\n",
507                                 fsc->fs.h_u.ah_ip4_spec.spi,
508                                 fsc->fs.m_u.ah_ip4_spec.spi);
509                         p += ETH_GSTRING_LEN;
510                         num_strings++;
511                         sprintf(p, "\tTOS: %d, mask: 0x%x\n",
512                                 fsc->fs.h_u.ah_ip4_spec.tos,
513                                 fsc->fs.m_u.ah_ip4_spec.tos);
514                         p += ETH_GSTRING_LEN;
515                         num_strings++;
516                         break;
517                 case IP_USER_FLOW:
518                         sprintf(p, "\tSrc IP addr: 0x%x\n",
519                                 fsc->fs.h_u.raw_ip4_spec.ip4src);
520                         p += ETH_GSTRING_LEN;
521                         num_strings++;
522                         sprintf(p, "\tSrc IP mask: 0x%x\n",
523                                 fsc->fs.m_u.raw_ip4_spec.ip4src);
524                         p += ETH_GSTRING_LEN;
525                         num_strings++;
526                         sprintf(p, "\tDest IP addr: 0x%x\n",
527                                 fsc->fs.h_u.raw_ip4_spec.ip4dst);
528                         p += ETH_GSTRING_LEN;
529                         num_strings++;
530                         sprintf(p, "\tDest IP mask: 0x%x\n",
531                                 fsc->fs.m_u.raw_ip4_spec.ip4dst);
532                         p += ETH_GSTRING_LEN;
533                         num_strings++;
534                         break;
535                 case IPV4_FLOW:
536                         sprintf(p, "\tSrc IP addr: 0x%x\n",
537                                 fsc->fs.h_u.usr_ip4_spec.ip4src);
538                         p += ETH_GSTRING_LEN;
539                         num_strings++;
540                         sprintf(p, "\tSrc IP mask: 0x%x\n",
541                                 fsc->fs.m_u.usr_ip4_spec.ip4src);
542                         p += ETH_GSTRING_LEN;
543                         num_strings++;
544                         sprintf(p, "\tDest IP addr: 0x%x\n",
545                                 fsc->fs.h_u.usr_ip4_spec.ip4dst);
546                         p += ETH_GSTRING_LEN;
547                         num_strings++;
548                         sprintf(p, "\tDest IP mask: 0x%x\n",
549                                 fsc->fs.m_u.usr_ip4_spec.ip4dst);
550                         p += ETH_GSTRING_LEN;
551                         num_strings++;
552                         sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
553                                 fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
554                                 fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
555                         p += ETH_GSTRING_LEN;
556                         num_strings++;
557                         sprintf(p, "\tTOS: %d, mask: 0x%x\n",
558                                 fsc->fs.h_u.usr_ip4_spec.tos,
559                                 fsc->fs.m_u.usr_ip4_spec.tos);
560                         p += ETH_GSTRING_LEN;
561                         num_strings++;
562                         sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
563                                 fsc->fs.h_u.usr_ip4_spec.ip_ver,
564                                 fsc->fs.m_u.usr_ip4_spec.ip_ver);
565                         p += ETH_GSTRING_LEN;
566                         num_strings++;
567                         sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
568                                 fsc->fs.h_u.usr_ip4_spec.proto,
569                                 fsc->fs.m_u.usr_ip4_spec.proto);
570                         p += ETH_GSTRING_LEN;
571                         num_strings++;
572                         break;
573                 };
574                 sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
575                         fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
576                 p += ETH_GSTRING_LEN;
577                 num_strings++;
578                 sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
579                 p += ETH_GSTRING_LEN;
580                 num_strings++;
581                 sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
582                 p += ETH_GSTRING_LEN;
583                 num_strings++;
584                 if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
585                         sprintf(p, "\tAction: Drop\n");
586                 else
587                         sprintf(p, "\tAction: Direct to queue %d\n",
588                                 fsc->fs.action);
589                 p += ETH_GSTRING_LEN;
590                 num_strings++;
591 unknown_filter:
592                 i++;
593         }
594 copy:
595         /* indicate to userspace how many strings we actually have */
596         gstrings.len = num_strings;
597         ret = -EFAULT;
598         if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
599                 goto out;
600         useraddr += sizeof(gstrings);
601         if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
602                 goto out;
603         ret = 0;
604
605 out:
606         kfree(data);
607         return ret;
608 }
609
610 static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
611 {
612         struct ethtool_regs regs;
613         const struct ethtool_ops *ops = dev->ethtool_ops;
614         void *regbuf;
615         int reglen, ret;
616
617         if (!ops->get_regs || !ops->get_regs_len)
618                 return -EOPNOTSUPP;
619
620         if (copy_from_user(&regs, useraddr, sizeof(regs)))
621                 return -EFAULT;
622
623         reglen = ops->get_regs_len(dev);
624         if (regs.len > reglen)
625                 regs.len = reglen;
626
627         regbuf = kmalloc(reglen, GFP_USER);
628         if (!regbuf)
629                 return -ENOMEM;
630
631         ops->get_regs(dev, &regs, regbuf);
632
633         ret = -EFAULT;
634         if (copy_to_user(useraddr, &regs, sizeof(regs)))
635                 goto out;
636         useraddr += offsetof(struct ethtool_regs, data);
637         if (copy_to_user(useraddr, regbuf, regs.len))
638                 goto out;
639         ret = 0;
640
641  out:
642         kfree(regbuf);
643         return ret;
644 }
645
646 static int ethtool_reset(struct net_device *dev, char __user *useraddr)
647 {
648         struct ethtool_value reset;
649         int ret;
650
651         if (!dev->ethtool_ops->reset)
652                 return -EOPNOTSUPP;
653
654         if (copy_from_user(&reset, useraddr, sizeof(reset)))
655                 return -EFAULT;
656
657         /* Clear ethtool n-tuple list */
658         ethtool_ntuple_flush(dev);
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
669 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
670 {
671         struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
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
683 static 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
696 static 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
704 static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
705 {
706         struct ethtool_eeprom eeprom;
707         const struct ethtool_ops *ops = dev->ethtool_ops;
708         void __user *userbuf = useraddr + sizeof(eeprom);
709         u32 bytes_remaining;
710         u8 *data;
711         int ret = 0;
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
727         data = kmalloc(PAGE_SIZE, GFP_USER);
728         if (!data)
729                 return -ENOMEM;
730
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         }
746
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
752         kfree(data);
753         return ret;
754 }
755
756 static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
757 {
758         struct ethtool_eeprom eeprom;
759         const struct ethtool_ops *ops = dev->ethtool_ops;
760         void __user *userbuf = useraddr + sizeof(eeprom);
761         u32 bytes_remaining;
762         u8 *data;
763         int ret = 0;
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
779         data = kmalloc(PAGE_SIZE, GFP_USER);
780         if (!data)
781                 return -ENOMEM;
782
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         }
798
799         kfree(data);
800         return ret;
801 }
802
803 /*
804  * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
805  */
806 static noinline int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
807 {
808         struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
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
820 /*
821  * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
822  */
823 static noinline int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
824 {
825         struct ethtool_coalesce coalesce;
826
827         if (!dev->ethtool_ops->set_coalesce)
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
836 static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
837 {
838         struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
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
850 static 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
863 static 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
877 static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
878 {
879         struct ethtool_pauseparam pauseparam;
880
881         if (!dev->ethtool_ops->set_pauseparam)
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
890 static 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
900         if (!data && dev->ethtool_ops->set_ufo) {
901                 err = dev->ethtool_ops->set_ufo(dev, 0);
902                 if (err)
903                         return err;
904         }
905         return dev->ethtool_ops->set_sg(dev, data);
906 }
907
908 static 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
928 static 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
944 static 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
954         if (edata.data &&
955             !(dev->features & NETIF_F_ALL_CSUM))
956                 return -EINVAL;
957
958         return __ethtool_set_sg(dev, edata.data);
959 }
960
961 static 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
977 static 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
992 static 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
1002 static 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
1015 static 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
1025 static 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
1043 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1044 {
1045         struct ethtool_test test;
1046         const struct ethtool_ops *ops = dev->ethtool_ops;
1047         u64 *data;
1048         int ret, test_len;
1049
1050         if (!ops->self_test || !ops->get_sset_count)
1051                 return -EOPNOTSUPP;
1052
1053         test_len = ops->get_sset_count(dev, ETH_SS_TEST);
1054         if (test_len < 0)
1055                 return test_len;
1056         WARN_ON(test_len == 0);
1057
1058         if (copy_from_user(&test, useraddr, sizeof(test)))
1059                 return -EFAULT;
1060
1061         test.len = test_len;
1062         data = kmalloc(test_len * sizeof(u64), GFP_USER);
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
1081 static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1082 {
1083         struct ethtool_gstrings gstrings;
1084         const struct ethtool_ops *ops = dev->ethtool_ops;
1085         u8 *data;
1086         int ret;
1087
1088         if (!ops->get_strings || !ops->get_sset_count)
1089                 return -EOPNOTSUPP;
1090
1091         if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1092                 return -EFAULT;
1093
1094         ret = ops->get_sset_count(dev, gstrings.string_set);
1095         if (ret < 0)
1096                 return ret;
1097
1098         gstrings.len = ret;
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
1119 static 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
1132 static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1133 {
1134         struct ethtool_stats stats;
1135         const struct ethtool_ops *ops = dev->ethtool_ops;
1136         u64 *data;
1137         int ret, n_stats;
1138
1139         if (!ops->get_ethtool_stats || !ops->get_sset_count)
1140                 return -EOPNOTSUPP;
1141
1142         n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
1143         if (n_stats < 0)
1144                 return n_stats;
1145         WARN_ON(n_stats == 0);
1146
1147         if (copy_from_user(&stats, useraddr, sizeof(stats)))
1148                 return -EFAULT;
1149
1150         stats.n_stats = n_stats;
1151         data = kmalloc(n_stats * sizeof(u64), GFP_USER);
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
1170 static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
1171 {
1172         struct ethtool_perm_addr epaddr;
1173
1174         if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
1175                 return -EFAULT;
1176
1177         if (epaddr.size < dev->addr_len)
1178                 return -ETOOSMALL;
1179         epaddr.size = dev->addr_len;
1180
1181         if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
1182                 return -EFAULT;
1183         useraddr += sizeof(epaddr);
1184         if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1185                 return -EFAULT;
1186         return 0;
1187 }
1188
1189 static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1190                              u32 cmd, u32 (*actor)(struct net_device *))
1191 {
1192         struct ethtool_value edata = { .cmd = cmd };
1193
1194         if (!actor)
1195                 return -EOPNOTSUPP;
1196
1197         edata.data = actor(dev);
1198
1199         if (copy_to_user(useraddr, &edata, sizeof(edata)))
1200                 return -EFAULT;
1201         return 0;
1202 }
1203
1204 static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1205                              void (*actor)(struct net_device *, u32))
1206 {
1207         struct ethtool_value edata;
1208
1209         if (!actor)
1210                 return -EOPNOTSUPP;
1211
1212         if (copy_from_user(&edata, useraddr, sizeof(edata)))
1213                 return -EFAULT;
1214
1215         actor(dev, edata.data);
1216         return 0;
1217 }
1218
1219 static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1220                              int (*actor)(struct net_device *, u32))
1221 {
1222         struct ethtool_value edata;
1223
1224         if (!actor)
1225                 return -EOPNOTSUPP;
1226
1227         if (copy_from_user(&edata, useraddr, sizeof(edata)))
1228                 return -EFAULT;
1229
1230         return actor(dev, edata.data);
1231 }
1232
1233 /*
1234  * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
1235  */
1236 static noinline int ethtool_flash_device(struct net_device *dev, char __user *useraddr)
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
1249 /* The main entry point in this file.  Called from net/core/dev.c */
1250
1251 int dev_ethtool(struct net *net, struct ifreq *ifr)
1252 {
1253         struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
1254         void __user *useraddr = ifr->ifr_data;
1255         u32 ethcmd;
1256         int rc;
1257         unsigned long old_features;
1258
1259         if (!dev || !netif_device_present(dev))
1260                 return -ENODEV;
1261
1262         if (!dev->ethtool_ops)
1263                 return -EOPNOTSUPP;
1264
1265         if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
1266                 return -EFAULT;
1267
1268         /* Allow some commands to be done by anyone */
1269         switch(ethcmd) {
1270         case ETHTOOL_GDRVINFO:
1271         case ETHTOOL_GMSGLVL:
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:
1279         case ETHTOOL_GTSO:
1280         case ETHTOOL_GPERMADDR:
1281         case ETHTOOL_GUFO:
1282         case ETHTOOL_GGSO:
1283         case ETHTOOL_GGRO:
1284         case ETHTOOL_GFLAGS:
1285         case ETHTOOL_GPFLAGS:
1286         case ETHTOOL_GRXFH:
1287         case ETHTOOL_GRXRINGS:
1288         case ETHTOOL_GRXCLSRLCNT:
1289         case ETHTOOL_GRXCLSRULE:
1290         case ETHTOOL_GRXCLSRLALL:
1291                 break;
1292         default:
1293                 if (!capable(CAP_NET_ADMIN))
1294                         return -EPERM;
1295         }
1296
1297         if (dev->ethtool_ops->begin)
1298                 if ((rc = dev->ethtool_ops->begin(dev)) < 0)
1299                         return rc;
1300
1301         old_features = dev->features;
1302
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);
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:
1323                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1324                                        dev->ethtool_ops->get_msglevel);
1325                 break;
1326         case ETHTOOL_SMSGLVL:
1327                 rc = ethtool_set_value_void(dev, useraddr,
1328                                        dev->ethtool_ops->set_msglevel);
1329                 break;
1330         case ETHTOOL_NWAY_RST:
1331                 rc = ethtool_nway_reset(dev);
1332                 break;
1333         case ETHTOOL_GLINK:
1334                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1335                                        dev->ethtool_ops->get_link);
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:
1362                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1363                                        (dev->ethtool_ops->get_rx_csum ?
1364                                         dev->ethtool_ops->get_rx_csum :
1365                                         ethtool_op_get_rx_csum));
1366                 break;
1367         case ETHTOOL_SRXCSUM:
1368                 rc = ethtool_set_rx_csum(dev, useraddr);
1369                 break;
1370         case ETHTOOL_GTXCSUM:
1371                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1372                                        (dev->ethtool_ops->get_tx_csum ?
1373                                         dev->ethtool_ops->get_tx_csum :
1374                                         ethtool_op_get_tx_csum));
1375                 break;
1376         case ETHTOOL_STXCSUM:
1377                 rc = ethtool_set_tx_csum(dev, useraddr);
1378                 break;
1379         case ETHTOOL_GSG:
1380                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1381                                        (dev->ethtool_ops->get_sg ?
1382                                         dev->ethtool_ops->get_sg :
1383                                         ethtool_op_get_sg));
1384                 break;
1385         case ETHTOOL_SSG:
1386                 rc = ethtool_set_sg(dev, useraddr);
1387                 break;
1388         case ETHTOOL_GTSO:
1389                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1390                                        (dev->ethtool_ops->get_tso ?
1391                                         dev->ethtool_ops->get_tso :
1392                                         ethtool_op_get_tso));
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;
1409         case ETHTOOL_GPERMADDR:
1410                 rc = ethtool_get_perm_addr(dev, useraddr);
1411                 break;
1412         case ETHTOOL_GUFO:
1413                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1414                                        (dev->ethtool_ops->get_ufo ?
1415                                         dev->ethtool_ops->get_ufo :
1416                                         ethtool_op_get_ufo));
1417                 break;
1418         case ETHTOOL_SUFO:
1419                 rc = ethtool_set_ufo(dev, useraddr);
1420                 break;
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;
1427         case ETHTOOL_GFLAGS:
1428                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1429                                        (dev->ethtool_ops->get_flags ?
1430                                         dev->ethtool_ops->get_flags :
1431                                         ethtool_op_get_flags));
1432                 break;
1433         case ETHTOOL_SFLAGS:
1434                 rc = ethtool_set_value(dev, useraddr,
1435                                        dev->ethtool_ops->set_flags);
1436                 break;
1437         case ETHTOOL_GPFLAGS:
1438                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1439                                        dev->ethtool_ops->get_priv_flags);
1440                 break;
1441         case ETHTOOL_SPFLAGS:
1442                 rc = ethtool_set_value(dev, useraddr,
1443                                        dev->ethtool_ops->set_priv_flags);
1444                 break;
1445         case ETHTOOL_GRXFH:
1446         case ETHTOOL_GRXRINGS:
1447         case ETHTOOL_GRXCLSRLCNT:
1448         case ETHTOOL_GRXCLSRULE:
1449         case ETHTOOL_GRXCLSRLALL:
1450                 rc = ethtool_get_rxnfc(dev, useraddr);
1451                 break;
1452         case ETHTOOL_SRXFH:
1453         case ETHTOOL_SRXCLSRLDEL:
1454         case ETHTOOL_SRXCLSRLINS:
1455                 rc = ethtool_set_rxnfc(dev, useraddr);
1456                 break;
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;
1463         case ETHTOOL_FLASHDEV:
1464                 rc = ethtool_flash_device(dev, useraddr);
1465                 break;
1466         case ETHTOOL_RESET:
1467                 rc = ethtool_reset(dev, useraddr);
1468                 break;
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;
1475         default:
1476                 rc = -EOPNOTSUPP;
1477         }
1478
1479         if (dev->ethtool_ops->complete)
1480                 dev->ethtool_ops->complete(dev);
1481
1482         if (old_features != dev->features)
1483                 netdev_features_change(dev);
1484
1485         return rc;
1486 }
1487
1488 EXPORT_SYMBOL(ethtool_op_get_link);
1489 EXPORT_SYMBOL(ethtool_op_get_sg);
1490 EXPORT_SYMBOL(ethtool_op_get_tso);
1491 EXPORT_SYMBOL(ethtool_op_set_sg);
1492 EXPORT_SYMBOL(ethtool_op_set_tso);
1493 EXPORT_SYMBOL(ethtool_op_set_tx_csum);
1494 EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
1495 EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
1496 EXPORT_SYMBOL(ethtool_op_set_ufo);
1497 EXPORT_SYMBOL(ethtool_op_get_ufo);
1498 EXPORT_SYMBOL(ethtool_op_set_flags);
1499 EXPORT_SYMBOL(ethtool_op_get_flags);