]> bbs.cooldavid.org Git - net-next-2.6.git/blob - net/core/ethtool.c
ethtool: Don't flush n-tuple list from ethtool_reset()
[net-next-2.6.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         ret = dev->ethtool_ops->reset(dev, &reset.data);
658         if (ret)
659                 return ret;
660
661         if (copy_to_user(useraddr, &reset, sizeof(reset)))
662                 return -EFAULT;
663         return 0;
664 }
665
666 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
667 {
668         struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
669
670         if (!dev->ethtool_ops->get_wol)
671                 return -EOPNOTSUPP;
672
673         dev->ethtool_ops->get_wol(dev, &wol);
674
675         if (copy_to_user(useraddr, &wol, sizeof(wol)))
676                 return -EFAULT;
677         return 0;
678 }
679
680 static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
681 {
682         struct ethtool_wolinfo wol;
683
684         if (!dev->ethtool_ops->set_wol)
685                 return -EOPNOTSUPP;
686
687         if (copy_from_user(&wol, useraddr, sizeof(wol)))
688                 return -EFAULT;
689
690         return dev->ethtool_ops->set_wol(dev, &wol);
691 }
692
693 static int ethtool_nway_reset(struct net_device *dev)
694 {
695         if (!dev->ethtool_ops->nway_reset)
696                 return -EOPNOTSUPP;
697
698         return dev->ethtool_ops->nway_reset(dev);
699 }
700
701 static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
702 {
703         struct ethtool_eeprom eeprom;
704         const struct ethtool_ops *ops = dev->ethtool_ops;
705         void __user *userbuf = useraddr + sizeof(eeprom);
706         u32 bytes_remaining;
707         u8 *data;
708         int ret = 0;
709
710         if (!ops->get_eeprom || !ops->get_eeprom_len)
711                 return -EOPNOTSUPP;
712
713         if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
714                 return -EFAULT;
715
716         /* Check for wrap and zero */
717         if (eeprom.offset + eeprom.len <= eeprom.offset)
718                 return -EINVAL;
719
720         /* Check for exceeding total eeprom len */
721         if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
722                 return -EINVAL;
723
724         data = kmalloc(PAGE_SIZE, GFP_USER);
725         if (!data)
726                 return -ENOMEM;
727
728         bytes_remaining = eeprom.len;
729         while (bytes_remaining > 0) {
730                 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
731
732                 ret = ops->get_eeprom(dev, &eeprom, data);
733                 if (ret)
734                         break;
735                 if (copy_to_user(userbuf, data, eeprom.len)) {
736                         ret = -EFAULT;
737                         break;
738                 }
739                 userbuf += eeprom.len;
740                 eeprom.offset += eeprom.len;
741                 bytes_remaining -= eeprom.len;
742         }
743
744         eeprom.len = userbuf - (useraddr + sizeof(eeprom));
745         eeprom.offset -= eeprom.len;
746         if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
747                 ret = -EFAULT;
748
749         kfree(data);
750         return ret;
751 }
752
753 static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
754 {
755         struct ethtool_eeprom eeprom;
756         const struct ethtool_ops *ops = dev->ethtool_ops;
757         void __user *userbuf = useraddr + sizeof(eeprom);
758         u32 bytes_remaining;
759         u8 *data;
760         int ret = 0;
761
762         if (!ops->set_eeprom || !ops->get_eeprom_len)
763                 return -EOPNOTSUPP;
764
765         if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
766                 return -EFAULT;
767
768         /* Check for wrap and zero */
769         if (eeprom.offset + eeprom.len <= eeprom.offset)
770                 return -EINVAL;
771
772         /* Check for exceeding total eeprom len */
773         if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
774                 return -EINVAL;
775
776         data = kmalloc(PAGE_SIZE, GFP_USER);
777         if (!data)
778                 return -ENOMEM;
779
780         bytes_remaining = eeprom.len;
781         while (bytes_remaining > 0) {
782                 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
783
784                 if (copy_from_user(data, userbuf, eeprom.len)) {
785                         ret = -EFAULT;
786                         break;
787                 }
788                 ret = ops->set_eeprom(dev, &eeprom, data);
789                 if (ret)
790                         break;
791                 userbuf += eeprom.len;
792                 eeprom.offset += eeprom.len;
793                 bytes_remaining -= eeprom.len;
794         }
795
796         kfree(data);
797         return ret;
798 }
799
800 /*
801  * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
802  */
803 static noinline int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
804 {
805         struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
806
807         if (!dev->ethtool_ops->get_coalesce)
808                 return -EOPNOTSUPP;
809
810         dev->ethtool_ops->get_coalesce(dev, &coalesce);
811
812         if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
813                 return -EFAULT;
814         return 0;
815 }
816
817 /*
818  * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
819  */
820 static noinline int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
821 {
822         struct ethtool_coalesce coalesce;
823
824         if (!dev->ethtool_ops->set_coalesce)
825                 return -EOPNOTSUPP;
826
827         if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
828                 return -EFAULT;
829
830         return dev->ethtool_ops->set_coalesce(dev, &coalesce);
831 }
832
833 static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
834 {
835         struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
836
837         if (!dev->ethtool_ops->get_ringparam)
838                 return -EOPNOTSUPP;
839
840         dev->ethtool_ops->get_ringparam(dev, &ringparam);
841
842         if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
843                 return -EFAULT;
844         return 0;
845 }
846
847 static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
848 {
849         struct ethtool_ringparam ringparam;
850
851         if (!dev->ethtool_ops->set_ringparam)
852                 return -EOPNOTSUPP;
853
854         if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
855                 return -EFAULT;
856
857         return dev->ethtool_ops->set_ringparam(dev, &ringparam);
858 }
859
860 static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
861 {
862         struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
863
864         if (!dev->ethtool_ops->get_pauseparam)
865                 return -EOPNOTSUPP;
866
867         dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
868
869         if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
870                 return -EFAULT;
871         return 0;
872 }
873
874 static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
875 {
876         struct ethtool_pauseparam pauseparam;
877
878         if (!dev->ethtool_ops->set_pauseparam)
879                 return -EOPNOTSUPP;
880
881         if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
882                 return -EFAULT;
883
884         return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
885 }
886
887 static int __ethtool_set_sg(struct net_device *dev, u32 data)
888 {
889         int err;
890
891         if (!data && dev->ethtool_ops->set_tso) {
892                 err = dev->ethtool_ops->set_tso(dev, 0);
893                 if (err)
894                         return err;
895         }
896
897         if (!data && dev->ethtool_ops->set_ufo) {
898                 err = dev->ethtool_ops->set_ufo(dev, 0);
899                 if (err)
900                         return err;
901         }
902         return dev->ethtool_ops->set_sg(dev, data);
903 }
904
905 static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
906 {
907         struct ethtool_value edata;
908         int err;
909
910         if (!dev->ethtool_ops->set_tx_csum)
911                 return -EOPNOTSUPP;
912
913         if (copy_from_user(&edata, useraddr, sizeof(edata)))
914                 return -EFAULT;
915
916         if (!edata.data && dev->ethtool_ops->set_sg) {
917                 err = __ethtool_set_sg(dev, 0);
918                 if (err)
919                         return err;
920         }
921
922         return dev->ethtool_ops->set_tx_csum(dev, edata.data);
923 }
924
925 static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
926 {
927         struct ethtool_value edata;
928
929         if (!dev->ethtool_ops->set_rx_csum)
930                 return -EOPNOTSUPP;
931
932         if (copy_from_user(&edata, useraddr, sizeof(edata)))
933                 return -EFAULT;
934
935         if (!edata.data && dev->ethtool_ops->set_sg)
936                 dev->features &= ~NETIF_F_GRO;
937
938         return dev->ethtool_ops->set_rx_csum(dev, edata.data);
939 }
940
941 static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
942 {
943         struct ethtool_value edata;
944
945         if (!dev->ethtool_ops->set_sg)
946                 return -EOPNOTSUPP;
947
948         if (copy_from_user(&edata, useraddr, sizeof(edata)))
949                 return -EFAULT;
950
951         if (edata.data &&
952             !(dev->features & NETIF_F_ALL_CSUM))
953                 return -EINVAL;
954
955         return __ethtool_set_sg(dev, edata.data);
956 }
957
958 static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
959 {
960         struct ethtool_value edata;
961
962         if (!dev->ethtool_ops->set_tso)
963                 return -EOPNOTSUPP;
964
965         if (copy_from_user(&edata, useraddr, sizeof(edata)))
966                 return -EFAULT;
967
968         if (edata.data && !(dev->features & NETIF_F_SG))
969                 return -EINVAL;
970
971         return dev->ethtool_ops->set_tso(dev, edata.data);
972 }
973
974 static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
975 {
976         struct ethtool_value edata;
977
978         if (!dev->ethtool_ops->set_ufo)
979                 return -EOPNOTSUPP;
980         if (copy_from_user(&edata, useraddr, sizeof(edata)))
981                 return -EFAULT;
982         if (edata.data && !(dev->features & NETIF_F_SG))
983                 return -EINVAL;
984         if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
985                 return -EINVAL;
986         return dev->ethtool_ops->set_ufo(dev, edata.data);
987 }
988
989 static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
990 {
991         struct ethtool_value edata = { ETHTOOL_GGSO };
992
993         edata.data = dev->features & NETIF_F_GSO;
994         if (copy_to_user(useraddr, &edata, sizeof(edata)))
995                  return -EFAULT;
996         return 0;
997 }
998
999 static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
1000 {
1001         struct ethtool_value edata;
1002
1003         if (copy_from_user(&edata, useraddr, sizeof(edata)))
1004                 return -EFAULT;
1005         if (edata.data)
1006                 dev->features |= NETIF_F_GSO;
1007         else
1008                 dev->features &= ~NETIF_F_GSO;
1009         return 0;
1010 }
1011
1012 static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
1013 {
1014         struct ethtool_value edata = { ETHTOOL_GGRO };
1015
1016         edata.data = dev->features & NETIF_F_GRO;
1017         if (copy_to_user(useraddr, &edata, sizeof(edata)))
1018                  return -EFAULT;
1019         return 0;
1020 }
1021
1022 static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
1023 {
1024         struct ethtool_value edata;
1025
1026         if (copy_from_user(&edata, useraddr, sizeof(edata)))
1027                 return -EFAULT;
1028
1029         if (edata.data) {
1030                 if (!dev->ethtool_ops->get_rx_csum ||
1031                     !dev->ethtool_ops->get_rx_csum(dev))
1032                         return -EINVAL;
1033                 dev->features |= NETIF_F_GRO;
1034         } else
1035                 dev->features &= ~NETIF_F_GRO;
1036
1037         return 0;
1038 }
1039
1040 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1041 {
1042         struct ethtool_test test;
1043         const struct ethtool_ops *ops = dev->ethtool_ops;
1044         u64 *data;
1045         int ret, test_len;
1046
1047         if (!ops->self_test || !ops->get_sset_count)
1048                 return -EOPNOTSUPP;
1049
1050         test_len = ops->get_sset_count(dev, ETH_SS_TEST);
1051         if (test_len < 0)
1052                 return test_len;
1053         WARN_ON(test_len == 0);
1054
1055         if (copy_from_user(&test, useraddr, sizeof(test)))
1056                 return -EFAULT;
1057
1058         test.len = test_len;
1059         data = kmalloc(test_len * sizeof(u64), GFP_USER);
1060         if (!data)
1061                 return -ENOMEM;
1062
1063         ops->self_test(dev, &test, data);
1064
1065         ret = -EFAULT;
1066         if (copy_to_user(useraddr, &test, sizeof(test)))
1067                 goto out;
1068         useraddr += sizeof(test);
1069         if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1070                 goto out;
1071         ret = 0;
1072
1073  out:
1074         kfree(data);
1075         return ret;
1076 }
1077
1078 static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1079 {
1080         struct ethtool_gstrings gstrings;
1081         const struct ethtool_ops *ops = dev->ethtool_ops;
1082         u8 *data;
1083         int ret;
1084
1085         if (!ops->get_strings || !ops->get_sset_count)
1086                 return -EOPNOTSUPP;
1087
1088         if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1089                 return -EFAULT;
1090
1091         ret = ops->get_sset_count(dev, gstrings.string_set);
1092         if (ret < 0)
1093                 return ret;
1094
1095         gstrings.len = ret;
1096
1097         data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1098         if (!data)
1099                 return -ENOMEM;
1100
1101         ops->get_strings(dev, gstrings.string_set, data);
1102
1103         ret = -EFAULT;
1104         if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1105                 goto out;
1106         useraddr += sizeof(gstrings);
1107         if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1108                 goto out;
1109         ret = 0;
1110
1111  out:
1112         kfree(data);
1113         return ret;
1114 }
1115
1116 static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1117 {
1118         struct ethtool_value id;
1119
1120         if (!dev->ethtool_ops->phys_id)
1121                 return -EOPNOTSUPP;
1122
1123         if (copy_from_user(&id, useraddr, sizeof(id)))
1124                 return -EFAULT;
1125
1126         return dev->ethtool_ops->phys_id(dev, id.data);
1127 }
1128
1129 static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1130 {
1131         struct ethtool_stats stats;
1132         const struct ethtool_ops *ops = dev->ethtool_ops;
1133         u64 *data;
1134         int ret, n_stats;
1135
1136         if (!ops->get_ethtool_stats || !ops->get_sset_count)
1137                 return -EOPNOTSUPP;
1138
1139         n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
1140         if (n_stats < 0)
1141                 return n_stats;
1142         WARN_ON(n_stats == 0);
1143
1144         if (copy_from_user(&stats, useraddr, sizeof(stats)))
1145                 return -EFAULT;
1146
1147         stats.n_stats = n_stats;
1148         data = kmalloc(n_stats * sizeof(u64), GFP_USER);
1149         if (!data)
1150                 return -ENOMEM;
1151
1152         ops->get_ethtool_stats(dev, &stats, data);
1153
1154         ret = -EFAULT;
1155         if (copy_to_user(useraddr, &stats, sizeof(stats)))
1156                 goto out;
1157         useraddr += sizeof(stats);
1158         if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1159                 goto out;
1160         ret = 0;
1161
1162  out:
1163         kfree(data);
1164         return ret;
1165 }
1166
1167 static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
1168 {
1169         struct ethtool_perm_addr epaddr;
1170
1171         if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
1172                 return -EFAULT;
1173
1174         if (epaddr.size < dev->addr_len)
1175                 return -ETOOSMALL;
1176         epaddr.size = dev->addr_len;
1177
1178         if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
1179                 return -EFAULT;
1180         useraddr += sizeof(epaddr);
1181         if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1182                 return -EFAULT;
1183         return 0;
1184 }
1185
1186 static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1187                              u32 cmd, u32 (*actor)(struct net_device *))
1188 {
1189         struct ethtool_value edata = { .cmd = cmd };
1190
1191         if (!actor)
1192                 return -EOPNOTSUPP;
1193
1194         edata.data = actor(dev);
1195
1196         if (copy_to_user(useraddr, &edata, sizeof(edata)))
1197                 return -EFAULT;
1198         return 0;
1199 }
1200
1201 static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1202                              void (*actor)(struct net_device *, u32))
1203 {
1204         struct ethtool_value edata;
1205
1206         if (!actor)
1207                 return -EOPNOTSUPP;
1208
1209         if (copy_from_user(&edata, useraddr, sizeof(edata)))
1210                 return -EFAULT;
1211
1212         actor(dev, edata.data);
1213         return 0;
1214 }
1215
1216 static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1217                              int (*actor)(struct net_device *, u32))
1218 {
1219         struct ethtool_value edata;
1220
1221         if (!actor)
1222                 return -EOPNOTSUPP;
1223
1224         if (copy_from_user(&edata, useraddr, sizeof(edata)))
1225                 return -EFAULT;
1226
1227         return actor(dev, edata.data);
1228 }
1229
1230 /*
1231  * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
1232  */
1233 static noinline int ethtool_flash_device(struct net_device *dev, char __user *useraddr)
1234 {
1235         struct ethtool_flash efl;
1236
1237         if (copy_from_user(&efl, useraddr, sizeof(efl)))
1238                 return -EFAULT;
1239
1240         if (!dev->ethtool_ops->flash_device)
1241                 return -EOPNOTSUPP;
1242
1243         return dev->ethtool_ops->flash_device(dev, &efl);
1244 }
1245
1246 /* The main entry point in this file.  Called from net/core/dev.c */
1247
1248 int dev_ethtool(struct net *net, struct ifreq *ifr)
1249 {
1250         struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
1251         void __user *useraddr = ifr->ifr_data;
1252         u32 ethcmd;
1253         int rc;
1254         unsigned long old_features;
1255
1256         if (!dev || !netif_device_present(dev))
1257                 return -ENODEV;
1258
1259         if (!dev->ethtool_ops)
1260                 return -EOPNOTSUPP;
1261
1262         if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
1263                 return -EFAULT;
1264
1265         /* Allow some commands to be done by anyone */
1266         switch(ethcmd) {
1267         case ETHTOOL_GDRVINFO:
1268         case ETHTOOL_GMSGLVL:
1269         case ETHTOOL_GCOALESCE:
1270         case ETHTOOL_GRINGPARAM:
1271         case ETHTOOL_GPAUSEPARAM:
1272         case ETHTOOL_GRXCSUM:
1273         case ETHTOOL_GTXCSUM:
1274         case ETHTOOL_GSG:
1275         case ETHTOOL_GSTRINGS:
1276         case ETHTOOL_GTSO:
1277         case ETHTOOL_GPERMADDR:
1278         case ETHTOOL_GUFO:
1279         case ETHTOOL_GGSO:
1280         case ETHTOOL_GGRO:
1281         case ETHTOOL_GFLAGS:
1282         case ETHTOOL_GPFLAGS:
1283         case ETHTOOL_GRXFH:
1284         case ETHTOOL_GRXRINGS:
1285         case ETHTOOL_GRXCLSRLCNT:
1286         case ETHTOOL_GRXCLSRULE:
1287         case ETHTOOL_GRXCLSRLALL:
1288                 break;
1289         default:
1290                 if (!capable(CAP_NET_ADMIN))
1291                         return -EPERM;
1292         }
1293
1294         if (dev->ethtool_ops->begin)
1295                 if ((rc = dev->ethtool_ops->begin(dev)) < 0)
1296                         return rc;
1297
1298         old_features = dev->features;
1299
1300         switch (ethcmd) {
1301         case ETHTOOL_GSET:
1302                 rc = ethtool_get_settings(dev, useraddr);
1303                 break;
1304         case ETHTOOL_SSET:
1305                 rc = ethtool_set_settings(dev, useraddr);
1306                 break;
1307         case ETHTOOL_GDRVINFO:
1308                 rc = ethtool_get_drvinfo(dev, useraddr);
1309                 break;
1310         case ETHTOOL_GREGS:
1311                 rc = ethtool_get_regs(dev, useraddr);
1312                 break;
1313         case ETHTOOL_GWOL:
1314                 rc = ethtool_get_wol(dev, useraddr);
1315                 break;
1316         case ETHTOOL_SWOL:
1317                 rc = ethtool_set_wol(dev, useraddr);
1318                 break;
1319         case ETHTOOL_GMSGLVL:
1320                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1321                                        dev->ethtool_ops->get_msglevel);
1322                 break;
1323         case ETHTOOL_SMSGLVL:
1324                 rc = ethtool_set_value_void(dev, useraddr,
1325                                        dev->ethtool_ops->set_msglevel);
1326                 break;
1327         case ETHTOOL_NWAY_RST:
1328                 rc = ethtool_nway_reset(dev);
1329                 break;
1330         case ETHTOOL_GLINK:
1331                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1332                                        dev->ethtool_ops->get_link);
1333                 break;
1334         case ETHTOOL_GEEPROM:
1335                 rc = ethtool_get_eeprom(dev, useraddr);
1336                 break;
1337         case ETHTOOL_SEEPROM:
1338                 rc = ethtool_set_eeprom(dev, useraddr);
1339                 break;
1340         case ETHTOOL_GCOALESCE:
1341                 rc = ethtool_get_coalesce(dev, useraddr);
1342                 break;
1343         case ETHTOOL_SCOALESCE:
1344                 rc = ethtool_set_coalesce(dev, useraddr);
1345                 break;
1346         case ETHTOOL_GRINGPARAM:
1347                 rc = ethtool_get_ringparam(dev, useraddr);
1348                 break;
1349         case ETHTOOL_SRINGPARAM:
1350                 rc = ethtool_set_ringparam(dev, useraddr);
1351                 break;
1352         case ETHTOOL_GPAUSEPARAM:
1353                 rc = ethtool_get_pauseparam(dev, useraddr);
1354                 break;
1355         case ETHTOOL_SPAUSEPARAM:
1356                 rc = ethtool_set_pauseparam(dev, useraddr);
1357                 break;
1358         case ETHTOOL_GRXCSUM:
1359                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1360                                        (dev->ethtool_ops->get_rx_csum ?
1361                                         dev->ethtool_ops->get_rx_csum :
1362                                         ethtool_op_get_rx_csum));
1363                 break;
1364         case ETHTOOL_SRXCSUM:
1365                 rc = ethtool_set_rx_csum(dev, useraddr);
1366                 break;
1367         case ETHTOOL_GTXCSUM:
1368                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1369                                        (dev->ethtool_ops->get_tx_csum ?
1370                                         dev->ethtool_ops->get_tx_csum :
1371                                         ethtool_op_get_tx_csum));
1372                 break;
1373         case ETHTOOL_STXCSUM:
1374                 rc = ethtool_set_tx_csum(dev, useraddr);
1375                 break;
1376         case ETHTOOL_GSG:
1377                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1378                                        (dev->ethtool_ops->get_sg ?
1379                                         dev->ethtool_ops->get_sg :
1380                                         ethtool_op_get_sg));
1381                 break;
1382         case ETHTOOL_SSG:
1383                 rc = ethtool_set_sg(dev, useraddr);
1384                 break;
1385         case ETHTOOL_GTSO:
1386                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1387                                        (dev->ethtool_ops->get_tso ?
1388                                         dev->ethtool_ops->get_tso :
1389                                         ethtool_op_get_tso));
1390                 break;
1391         case ETHTOOL_STSO:
1392                 rc = ethtool_set_tso(dev, useraddr);
1393                 break;
1394         case ETHTOOL_TEST:
1395                 rc = ethtool_self_test(dev, useraddr);
1396                 break;
1397         case ETHTOOL_GSTRINGS:
1398                 rc = ethtool_get_strings(dev, useraddr);
1399                 break;
1400         case ETHTOOL_PHYS_ID:
1401                 rc = ethtool_phys_id(dev, useraddr);
1402                 break;
1403         case ETHTOOL_GSTATS:
1404                 rc = ethtool_get_stats(dev, useraddr);
1405                 break;
1406         case ETHTOOL_GPERMADDR:
1407                 rc = ethtool_get_perm_addr(dev, useraddr);
1408                 break;
1409         case ETHTOOL_GUFO:
1410                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1411                                        (dev->ethtool_ops->get_ufo ?
1412                                         dev->ethtool_ops->get_ufo :
1413                                         ethtool_op_get_ufo));
1414                 break;
1415         case ETHTOOL_SUFO:
1416                 rc = ethtool_set_ufo(dev, useraddr);
1417                 break;
1418         case ETHTOOL_GGSO:
1419                 rc = ethtool_get_gso(dev, useraddr);
1420                 break;
1421         case ETHTOOL_SGSO:
1422                 rc = ethtool_set_gso(dev, useraddr);
1423                 break;
1424         case ETHTOOL_GFLAGS:
1425                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1426                                        (dev->ethtool_ops->get_flags ?
1427                                         dev->ethtool_ops->get_flags :
1428                                         ethtool_op_get_flags));
1429                 break;
1430         case ETHTOOL_SFLAGS:
1431                 rc = ethtool_set_value(dev, useraddr,
1432                                        dev->ethtool_ops->set_flags);
1433                 break;
1434         case ETHTOOL_GPFLAGS:
1435                 rc = ethtool_get_value(dev, useraddr, ethcmd,
1436                                        dev->ethtool_ops->get_priv_flags);
1437                 break;
1438         case ETHTOOL_SPFLAGS:
1439                 rc = ethtool_set_value(dev, useraddr,
1440                                        dev->ethtool_ops->set_priv_flags);
1441                 break;
1442         case ETHTOOL_GRXFH:
1443         case ETHTOOL_GRXRINGS:
1444         case ETHTOOL_GRXCLSRLCNT:
1445         case ETHTOOL_GRXCLSRULE:
1446         case ETHTOOL_GRXCLSRLALL:
1447                 rc = ethtool_get_rxnfc(dev, useraddr);
1448                 break;
1449         case ETHTOOL_SRXFH:
1450         case ETHTOOL_SRXCLSRLDEL:
1451         case ETHTOOL_SRXCLSRLINS:
1452                 rc = ethtool_set_rxnfc(dev, useraddr);
1453                 break;
1454         case ETHTOOL_GGRO:
1455                 rc = ethtool_get_gro(dev, useraddr);
1456                 break;
1457         case ETHTOOL_SGRO:
1458                 rc = ethtool_set_gro(dev, useraddr);
1459                 break;
1460         case ETHTOOL_FLASHDEV:
1461                 rc = ethtool_flash_device(dev, useraddr);
1462                 break;
1463         case ETHTOOL_RESET:
1464                 rc = ethtool_reset(dev, useraddr);
1465                 break;
1466         case ETHTOOL_SRXNTUPLE:
1467                 rc = ethtool_set_rx_ntuple(dev, useraddr);
1468                 break;
1469         case ETHTOOL_GRXNTUPLE:
1470                 rc = ethtool_get_rx_ntuple(dev, useraddr);
1471                 break;
1472         default:
1473                 rc = -EOPNOTSUPP;
1474         }
1475
1476         if (dev->ethtool_ops->complete)
1477                 dev->ethtool_ops->complete(dev);
1478
1479         if (old_features != dev->features)
1480                 netdev_features_change(dev);
1481
1482         return rc;
1483 }
1484
1485 EXPORT_SYMBOL(ethtool_op_get_link);
1486 EXPORT_SYMBOL(ethtool_op_get_sg);
1487 EXPORT_SYMBOL(ethtool_op_get_tso);
1488 EXPORT_SYMBOL(ethtool_op_set_sg);
1489 EXPORT_SYMBOL(ethtool_op_set_tso);
1490 EXPORT_SYMBOL(ethtool_op_set_tx_csum);
1491 EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
1492 EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
1493 EXPORT_SYMBOL(ethtool_op_set_ufo);
1494 EXPORT_SYMBOL(ethtool_op_get_ufo);
1495 EXPORT_SYMBOL(ethtool_op_set_flags);
1496 EXPORT_SYMBOL(ethtool_op_get_flags);