blob: a0f4964033d289b8d1b4959d4d1196ccc094bdff [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Matthew Wilcox61a44b92007-07-31 14:00:02 -07006 * the information ethtool needs.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Matthew Wilcox61a44b92007-07-31 14:00:02 -07008 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
13
14#include <linux/module.h>
15#include <linux/types.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -080016#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/errno.h>
18#include <linux/ethtool.h>
19#include <linux/netdevice.h>
Jeff Garzikd17792e2010-03-04 08:21:53 +000020#include <linux/bitops.h>
chavey97f8aef2010-04-07 21:54:42 -070021#include <linux/uaccess.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090024/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 * Some useful ethtool_ops methods that're device independent.
26 * If we find that all drivers want to do the same thing here,
27 * we can turn these into dev_() function calls.
28 */
29
30u32 ethtool_op_get_link(struct net_device *dev)
31{
32 return netif_carrier_ok(dev) ? 1 : 0;
33}
chavey97f8aef2010-04-07 21:54:42 -070034EXPORT_SYMBOL(ethtool_op_get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Sridhar Samudrala1896e612009-07-22 13:38:22 +000036u32 ethtool_op_get_rx_csum(struct net_device *dev)
37{
38 return (dev->features & NETIF_F_ALL_CSUM) != 0;
39}
Eric Dumazet8a729fc2009-07-26 23:18:11 +000040EXPORT_SYMBOL(ethtool_op_get_rx_csum);
Sridhar Samudrala1896e612009-07-22 13:38:22 +000041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042u32 ethtool_op_get_tx_csum(struct net_device *dev)
43{
Herbert Xu8648b302006-06-17 22:06:05 -070044 return (dev->features & NETIF_F_ALL_CSUM) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
Eric Dumazet8a729fc2009-07-26 23:18:11 +000046EXPORT_SYMBOL(ethtool_op_get_tx_csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
49{
50 if (data)
51 dev->features |= NETIF_F_IP_CSUM;
52 else
53 dev->features &= ~NETIF_F_IP_CSUM;
54
55 return 0;
56}
57
Jon Mason69f6a0f2005-05-29 20:27:24 -070058int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data)
59{
60 if (data)
61 dev->features |= NETIF_F_HW_CSUM;
62 else
63 dev->features &= ~NETIF_F_HW_CSUM;
64
65 return 0;
66}
chavey97f8aef2010-04-07 21:54:42 -070067EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
Michael Chan6460d942007-07-14 19:07:52 -070068
69int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data)
70{
71 if (data)
72 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
73 else
74 dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
75
76 return 0;
77}
chavey97f8aef2010-04-07 21:54:42 -070078EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
Michael Chan6460d942007-07-14 19:07:52 -070079
Linus Torvalds1da177e2005-04-16 15:20:36 -070080u32 ethtool_op_get_sg(struct net_device *dev)
81{
82 return (dev->features & NETIF_F_SG) != 0;
83}
chavey97f8aef2010-04-07 21:54:42 -070084EXPORT_SYMBOL(ethtool_op_get_sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86int ethtool_op_set_sg(struct net_device *dev, u32 data)
87{
88 if (data)
89 dev->features |= NETIF_F_SG;
90 else
91 dev->features &= ~NETIF_F_SG;
92
93 return 0;
94}
chavey97f8aef2010-04-07 21:54:42 -070095EXPORT_SYMBOL(ethtool_op_set_sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97u32 ethtool_op_get_tso(struct net_device *dev)
98{
99 return (dev->features & NETIF_F_TSO) != 0;
100}
chavey97f8aef2010-04-07 21:54:42 -0700101EXPORT_SYMBOL(ethtool_op_get_tso);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103int ethtool_op_set_tso(struct net_device *dev, u32 data)
104{
105 if (data)
106 dev->features |= NETIF_F_TSO;
107 else
108 dev->features &= ~NETIF_F_TSO;
109
110 return 0;
111}
chavey97f8aef2010-04-07 21:54:42 -0700112EXPORT_SYMBOL(ethtool_op_set_tso);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700114u32 ethtool_op_get_ufo(struct net_device *dev)
115{
116 return (dev->features & NETIF_F_UFO) != 0;
117}
chavey97f8aef2010-04-07 21:54:42 -0700118EXPORT_SYMBOL(ethtool_op_get_ufo);
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700119
120int ethtool_op_set_ufo(struct net_device *dev, u32 data)
121{
122 if (data)
123 dev->features |= NETIF_F_UFO;
124 else
125 dev->features &= ~NETIF_F_UFO;
126 return 0;
127}
chavey97f8aef2010-04-07 21:54:42 -0700128EXPORT_SYMBOL(ethtool_op_set_ufo);
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700129
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700130/* the following list of flags are the same as their associated
131 * NETIF_F_xxx values in include/linux/netdevice.h
132 */
133static const u32 flags_dup_features =
stephen hemmingerb00fabb2010-03-29 14:47:27 +0000134 (ETH_FLAG_LRO | ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700135
136u32 ethtool_op_get_flags(struct net_device *dev)
137{
138 /* in the future, this function will probably contain additional
139 * handling for flags which are not so easily handled
140 * by a simple masking operation
141 */
142
143 return dev->features & flags_dup_features;
144}
chavey97f8aef2010-04-07 21:54:42 -0700145EXPORT_SYMBOL(ethtool_op_get_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700146
147int ethtool_op_set_flags(struct net_device *dev, u32 data)
148{
Peter Waskiewicz0d643e12010-02-12 13:48:25 +0000149 const struct ethtool_ops *ops = dev->ethtool_ops;
Jeff Garzik96754782010-02-26 21:43:38 +0000150 unsigned long features = dev->features;
Peter Waskiewicz0d643e12010-02-12 13:48:25 +0000151
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700152 if (data & ETH_FLAG_LRO)
Jeff Garzik96754782010-02-26 21:43:38 +0000153 features |= NETIF_F_LRO;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700154 else
Jeff Garzik96754782010-02-26 21:43:38 +0000155 features &= ~NETIF_F_LRO;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700156
Peter Waskiewicz0d643e12010-02-12 13:48:25 +0000157 if (data & ETH_FLAG_NTUPLE) {
158 if (!ops->set_rx_ntuple)
159 return -EOPNOTSUPP;
Jeff Garzik96754782010-02-26 21:43:38 +0000160 features |= NETIF_F_NTUPLE;
Peter Waskiewicz0d643e12010-02-12 13:48:25 +0000161 } else {
162 /* safe to clear regardless */
Jeff Garzik96754782010-02-26 21:43:38 +0000163 features &= ~NETIF_F_NTUPLE;
Peter Waskiewicz0d643e12010-02-12 13:48:25 +0000164 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800165
stephen hemmingerb00fabb2010-03-29 14:47:27 +0000166 if (data & ETH_FLAG_RXHASH)
167 features |= NETIF_F_RXHASH;
168 else
169 features &= ~NETIF_F_RXHASH;
170
Jeff Garzik96754782010-02-26 21:43:38 +0000171 dev->features = features;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700172 return 0;
173}
chavey97f8aef2010-04-07 21:54:42 -0700174EXPORT_SYMBOL(ethtool_op_set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700175
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800176void ethtool_ntuple_flush(struct net_device *dev)
177{
178 struct ethtool_rx_ntuple_flow_spec_container *fsc, *f;
179
180 list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) {
181 list_del(&fsc->list);
182 kfree(fsc);
183 }
184 dev->ethtool_ntuple_list.count = 0;
185}
186EXPORT_SYMBOL(ethtool_ntuple_flush);
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188/* Handlers for each ethtool command */
189
190static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
191{
Roland Dreier8e557422010-02-11 12:14:23 -0800192 struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 int err;
194
195 if (!dev->ethtool_ops->get_settings)
196 return -EOPNOTSUPP;
197
198 err = dev->ethtool_ops->get_settings(dev, &cmd);
199 if (err < 0)
200 return err;
201
202 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
203 return -EFAULT;
204 return 0;
205}
206
207static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
208{
209 struct ethtool_cmd cmd;
210
211 if (!dev->ethtool_ops->set_settings)
212 return -EOPNOTSUPP;
213
214 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
215 return -EFAULT;
216
217 return dev->ethtool_ops->set_settings(dev, &cmd);
218}
219
chavey97f8aef2010-04-07 21:54:42 -0700220static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
221 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
223 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700224 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 if (!ops->get_drvinfo)
227 return -EOPNOTSUPP;
228
229 memset(&info, 0, sizeof(info));
230 info.cmd = ETHTOOL_GDRVINFO;
231 ops->get_drvinfo(dev, &info);
232
Jeff Garzik723b2f52010-03-03 22:51:50 +0000233 /*
234 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000235 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000236 */
Jeff Garzikff03d492007-08-15 16:01:08 -0700237 if (ops->get_sset_count) {
238 int rc;
239
240 rc = ops->get_sset_count(dev, ETH_SS_TEST);
241 if (rc >= 0)
242 info.testinfo_len = rc;
243 rc = ops->get_sset_count(dev, ETH_SS_STATS);
244 if (rc >= 0)
245 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700246 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
247 if (rc >= 0)
248 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700249 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 if (ops->get_regs_len)
251 info.regdump_len = ops->get_regs_len(dev);
252 if (ops->get_eeprom_len)
253 info.eedump_len = ops->get_eeprom_len(dev);
254
255 if (copy_to_user(useraddr, &info, sizeof(info)))
256 return -EFAULT;
257 return 0;
258}
259
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800260static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
chavey97f8aef2010-04-07 21:54:42 -0700261 void __user *useraddr)
Jeff Garzik723b2f52010-03-03 22:51:50 +0000262{
263 struct ethtool_sset_info info;
264 const struct ethtool_ops *ops = dev->ethtool_ops;
265 u64 sset_mask;
266 int i, idx = 0, n_bits = 0, ret, rc;
267 u32 *info_buf = NULL;
268
269 if (!ops->get_sset_count)
270 return -EOPNOTSUPP;
271
272 if (copy_from_user(&info, useraddr, sizeof(info)))
273 return -EFAULT;
274
275 /* store copy of mask, because we zero struct later on */
276 sset_mask = info.sset_mask;
277 if (!sset_mask)
278 return 0;
279
280 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000281 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000282
283 memset(&info, 0, sizeof(info));
284 info.cmd = ETHTOOL_GSSET_INFO;
285
286 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
287 if (!info_buf)
288 return -ENOMEM;
289
290 /*
291 * fill return buffer based on input bitmask and successful
292 * get_sset_count return
293 */
294 for (i = 0; i < 64; i++) {
295 if (!(sset_mask & (1ULL << i)))
296 continue;
297
298 rc = ops->get_sset_count(dev, i);
299 if (rc >= 0) {
300 info.sset_mask |= (1ULL << i);
301 info_buf[idx++] = rc;
302 }
303 }
304
305 ret = -EFAULT;
306 if (copy_to_user(useraddr, &info, sizeof(info)))
307 goto out;
308
309 useraddr += offsetof(struct ethtool_sset_info, data);
310 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
311 goto out;
312
313 ret = 0;
314
315out:
316 kfree(info_buf);
317 return ret;
318}
319
chavey97f8aef2010-04-07 21:54:42 -0700320static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
321 void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700322{
323 struct ethtool_rxnfc cmd;
324
Santwona Behera59089d82009-02-20 00:58:13 -0800325 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700326 return -EOPNOTSUPP;
327
328 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
329 return -EFAULT;
330
Santwona Behera59089d82009-02-20 00:58:13 -0800331 return dev->ethtool_ops->set_rxnfc(dev, &cmd);
Santwona Behera0853ad62008-07-02 03:47:41 -0700332}
333
chavey97f8aef2010-04-07 21:54:42 -0700334static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
335 void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700336{
337 struct ethtool_rxnfc info;
Santwona Behera59089d82009-02-20 00:58:13 -0800338 const struct ethtool_ops *ops = dev->ethtool_ops;
339 int ret;
340 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700341
Santwona Behera59089d82009-02-20 00:58:13 -0800342 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700343 return -EOPNOTSUPP;
344
345 if (copy_from_user(&info, useraddr, sizeof(info)))
346 return -EFAULT;
347
Santwona Behera59089d82009-02-20 00:58:13 -0800348 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
349 if (info.rule_cnt > 0) {
350 rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
351 GFP_USER);
352 if (!rule_buf)
353 return -ENOMEM;
354 }
355 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700356
Santwona Behera59089d82009-02-20 00:58:13 -0800357 ret = ops->get_rxnfc(dev, &info, rule_buf);
358 if (ret < 0)
359 goto err_out;
360
361 ret = -EFAULT;
Santwona Behera0853ad62008-07-02 03:47:41 -0700362 if (copy_to_user(useraddr, &info, sizeof(info)))
Santwona Behera59089d82009-02-20 00:58:13 -0800363 goto err_out;
364
365 if (rule_buf) {
366 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
367 if (copy_to_user(useraddr, rule_buf,
368 info.rule_cnt * sizeof(u32)))
369 goto err_out;
370 }
371 ret = 0;
372
373err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700374 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800375
376 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700377}
378
Peter Waskiewicze8589112010-02-12 13:48:05 +0000379static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
chavey97f8aef2010-04-07 21:54:42 -0700380 struct ethtool_rx_ntuple_flow_spec *spec,
381 struct ethtool_rx_ntuple_flow_spec_container *fsc)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800382{
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800383
384 /* don't add filters forever */
Peter Waskiewicze8589112010-02-12 13:48:05 +0000385 if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
386 /* free the container */
387 kfree(fsc);
388 return;
389 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800390
391 /* Copy the whole filter over */
392 fsc->fs.flow_type = spec->flow_type;
393 memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
394 memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
395
396 fsc->fs.vlan_tag = spec->vlan_tag;
397 fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
398 fsc->fs.data = spec->data;
399 fsc->fs.data_mask = spec->data_mask;
400 fsc->fs.action = spec->action;
401
402 /* add to the list */
403 list_add_tail_rcu(&fsc->list, &list->list);
404 list->count++;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800405}
406
chavey97f8aef2010-04-07 21:54:42 -0700407static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev,
408 void __user *useraddr)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800409{
410 struct ethtool_rx_ntuple cmd;
411 const struct ethtool_ops *ops = dev->ethtool_ops;
Peter Waskiewicze8589112010-02-12 13:48:05 +0000412 struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800413 int ret;
414
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800415 if (!(dev->features & NETIF_F_NTUPLE))
416 return -EINVAL;
417
418 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
419 return -EFAULT;
420
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800421 /*
422 * Cache filter in dev struct for GET operation only if
423 * the underlying driver doesn't have its own GET operation, and
Peter Waskiewicze8589112010-02-12 13:48:05 +0000424 * only if the filter was added successfully. First make sure we
425 * can allocate the filter, then continue if successful.
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800426 */
Peter Waskiewicze8589112010-02-12 13:48:05 +0000427 if (!ops->get_rx_ntuple) {
428 fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
429 if (!fsc)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800430 return -ENOMEM;
Peter Waskiewicze8589112010-02-12 13:48:05 +0000431 }
432
433 ret = ops->set_rx_ntuple(dev, &cmd);
434 if (ret) {
435 kfree(fsc);
436 return ret;
437 }
438
439 if (!ops->get_rx_ntuple)
440 __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800441
442 return ret;
443}
444
445static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
446{
447 struct ethtool_gstrings gstrings;
448 const struct ethtool_ops *ops = dev->ethtool_ops;
449 struct ethtool_rx_ntuple_flow_spec_container *fsc;
450 u8 *data;
451 char *p;
452 int ret, i, num_strings = 0;
453
454 if (!ops->get_sset_count)
455 return -EOPNOTSUPP;
456
457 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
458 return -EFAULT;
459
460 ret = ops->get_sset_count(dev, gstrings.string_set);
461 if (ret < 0)
462 return ret;
463
464 gstrings.len = ret;
465
466 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
467 if (!data)
468 return -ENOMEM;
469
470 if (ops->get_rx_ntuple) {
471 /* driver-specific filter grab */
472 ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
473 goto copy;
474 }
475
476 /* default ethtool filter grab */
477 i = 0;
478 p = (char *)data;
479 list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
480 sprintf(p, "Filter %d:\n", i);
481 p += ETH_GSTRING_LEN;
482 num_strings++;
483
484 switch (fsc->fs.flow_type) {
485 case TCP_V4_FLOW:
486 sprintf(p, "\tFlow Type: TCP\n");
487 p += ETH_GSTRING_LEN;
488 num_strings++;
489 break;
490 case UDP_V4_FLOW:
491 sprintf(p, "\tFlow Type: UDP\n");
492 p += ETH_GSTRING_LEN;
493 num_strings++;
494 break;
495 case SCTP_V4_FLOW:
496 sprintf(p, "\tFlow Type: SCTP\n");
497 p += ETH_GSTRING_LEN;
498 num_strings++;
499 break;
500 case AH_ESP_V4_FLOW:
501 sprintf(p, "\tFlow Type: AH ESP\n");
502 p += ETH_GSTRING_LEN;
503 num_strings++;
504 break;
505 case ESP_V4_FLOW:
506 sprintf(p, "\tFlow Type: ESP\n");
507 p += ETH_GSTRING_LEN;
508 num_strings++;
509 break;
510 case IP_USER_FLOW:
511 sprintf(p, "\tFlow Type: Raw IP\n");
512 p += ETH_GSTRING_LEN;
513 num_strings++;
514 break;
515 case IPV4_FLOW:
516 sprintf(p, "\tFlow Type: IPv4\n");
517 p += ETH_GSTRING_LEN;
518 num_strings++;
519 break;
520 default:
521 sprintf(p, "\tFlow Type: Unknown\n");
522 p += ETH_GSTRING_LEN;
523 num_strings++;
524 goto unknown_filter;
Joe Perchesccbd6a52010-05-14 10:58:26 +0000525 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800526
527 /* now the rest of the filters */
528 switch (fsc->fs.flow_type) {
529 case TCP_V4_FLOW:
530 case UDP_V4_FLOW:
531 case SCTP_V4_FLOW:
532 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700533 fsc->fs.h_u.tcp_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800534 p += ETH_GSTRING_LEN;
535 num_strings++;
536 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700537 fsc->fs.m_u.tcp_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800538 p += ETH_GSTRING_LEN;
539 num_strings++;
540 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700541 fsc->fs.h_u.tcp_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800542 p += ETH_GSTRING_LEN;
543 num_strings++;
544 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700545 fsc->fs.m_u.tcp_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800546 p += ETH_GSTRING_LEN;
547 num_strings++;
548 sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700549 fsc->fs.h_u.tcp_ip4_spec.psrc,
550 fsc->fs.m_u.tcp_ip4_spec.psrc);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800551 p += ETH_GSTRING_LEN;
552 num_strings++;
553 sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700554 fsc->fs.h_u.tcp_ip4_spec.pdst,
555 fsc->fs.m_u.tcp_ip4_spec.pdst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800556 p += ETH_GSTRING_LEN;
557 num_strings++;
558 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700559 fsc->fs.h_u.tcp_ip4_spec.tos,
560 fsc->fs.m_u.tcp_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800561 p += ETH_GSTRING_LEN;
562 num_strings++;
563 break;
564 case AH_ESP_V4_FLOW:
565 case ESP_V4_FLOW:
566 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700567 fsc->fs.h_u.ah_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800568 p += ETH_GSTRING_LEN;
569 num_strings++;
570 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700571 fsc->fs.m_u.ah_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800572 p += ETH_GSTRING_LEN;
573 num_strings++;
574 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700575 fsc->fs.h_u.ah_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800576 p += ETH_GSTRING_LEN;
577 num_strings++;
578 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700579 fsc->fs.m_u.ah_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800580 p += ETH_GSTRING_LEN;
581 num_strings++;
582 sprintf(p, "\tSPI: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700583 fsc->fs.h_u.ah_ip4_spec.spi,
584 fsc->fs.m_u.ah_ip4_spec.spi);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800585 p += ETH_GSTRING_LEN;
586 num_strings++;
587 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700588 fsc->fs.h_u.ah_ip4_spec.tos,
589 fsc->fs.m_u.ah_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800590 p += ETH_GSTRING_LEN;
591 num_strings++;
592 break;
593 case IP_USER_FLOW:
594 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700595 fsc->fs.h_u.raw_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800596 p += ETH_GSTRING_LEN;
597 num_strings++;
598 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700599 fsc->fs.m_u.raw_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800600 p += ETH_GSTRING_LEN;
601 num_strings++;
602 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700603 fsc->fs.h_u.raw_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800604 p += ETH_GSTRING_LEN;
605 num_strings++;
606 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700607 fsc->fs.m_u.raw_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800608 p += ETH_GSTRING_LEN;
609 num_strings++;
610 break;
611 case IPV4_FLOW:
612 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700613 fsc->fs.h_u.usr_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800614 p += ETH_GSTRING_LEN;
615 num_strings++;
616 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700617 fsc->fs.m_u.usr_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800618 p += ETH_GSTRING_LEN;
619 num_strings++;
620 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700621 fsc->fs.h_u.usr_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800622 p += ETH_GSTRING_LEN;
623 num_strings++;
624 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700625 fsc->fs.m_u.usr_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800626 p += ETH_GSTRING_LEN;
627 num_strings++;
628 sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700629 fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
630 fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800631 p += ETH_GSTRING_LEN;
632 num_strings++;
633 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700634 fsc->fs.h_u.usr_ip4_spec.tos,
635 fsc->fs.m_u.usr_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800636 p += ETH_GSTRING_LEN;
637 num_strings++;
638 sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700639 fsc->fs.h_u.usr_ip4_spec.ip_ver,
640 fsc->fs.m_u.usr_ip4_spec.ip_ver);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800641 p += ETH_GSTRING_LEN;
642 num_strings++;
643 sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700644 fsc->fs.h_u.usr_ip4_spec.proto,
645 fsc->fs.m_u.usr_ip4_spec.proto);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800646 p += ETH_GSTRING_LEN;
647 num_strings++;
648 break;
Joe Perchesccbd6a52010-05-14 10:58:26 +0000649 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800650 sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700651 fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800652 p += ETH_GSTRING_LEN;
653 num_strings++;
654 sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
655 p += ETH_GSTRING_LEN;
656 num_strings++;
657 sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
658 p += ETH_GSTRING_LEN;
659 num_strings++;
660 if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
661 sprintf(p, "\tAction: Drop\n");
662 else
663 sprintf(p, "\tAction: Direct to queue %d\n",
chavey97f8aef2010-04-07 21:54:42 -0700664 fsc->fs.action);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800665 p += ETH_GSTRING_LEN;
666 num_strings++;
667unknown_filter:
668 i++;
669 }
670copy:
671 /* indicate to userspace how many strings we actually have */
672 gstrings.len = num_strings;
673 ret = -EFAULT;
674 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
675 goto out;
676 useraddr += sizeof(gstrings);
677 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
678 goto out;
679 ret = 0;
680
681out:
682 kfree(data);
683 return ret;
684}
685
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
687{
688 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700689 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 void *regbuf;
691 int reglen, ret;
692
693 if (!ops->get_regs || !ops->get_regs_len)
694 return -EOPNOTSUPP;
695
696 if (copy_from_user(&regs, useraddr, sizeof(regs)))
697 return -EFAULT;
698
699 reglen = ops->get_regs_len(dev);
700 if (regs.len > reglen)
701 regs.len = reglen;
702
703 regbuf = kmalloc(reglen, GFP_USER);
704 if (!regbuf)
705 return -ENOMEM;
706
707 ops->get_regs(dev, &regs, regbuf);
708
709 ret = -EFAULT;
710 if (copy_to_user(useraddr, &regs, sizeof(regs)))
711 goto out;
712 useraddr += offsetof(struct ethtool_regs, data);
713 if (copy_to_user(useraddr, regbuf, regs.len))
714 goto out;
715 ret = 0;
716
717 out:
718 kfree(regbuf);
719 return ret;
720}
721
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000722static int ethtool_reset(struct net_device *dev, char __user *useraddr)
723{
724 struct ethtool_value reset;
725 int ret;
726
727 if (!dev->ethtool_ops->reset)
728 return -EOPNOTSUPP;
729
730 if (copy_from_user(&reset, useraddr, sizeof(reset)))
731 return -EFAULT;
732
733 ret = dev->ethtool_ops->reset(dev, &reset.data);
734 if (ret)
735 return ret;
736
737 if (copy_to_user(useraddr, &reset, sizeof(reset)))
738 return -EFAULT;
739 return 0;
740}
741
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
743{
Roland Dreier8e557422010-02-11 12:14:23 -0800744 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
746 if (!dev->ethtool_ops->get_wol)
747 return -EOPNOTSUPP;
748
749 dev->ethtool_ops->get_wol(dev, &wol);
750
751 if (copy_to_user(useraddr, &wol, sizeof(wol)))
752 return -EFAULT;
753 return 0;
754}
755
756static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
757{
758 struct ethtool_wolinfo wol;
759
760 if (!dev->ethtool_ops->set_wol)
761 return -EOPNOTSUPP;
762
763 if (copy_from_user(&wol, useraddr, sizeof(wol)))
764 return -EFAULT;
765
766 return dev->ethtool_ops->set_wol(dev, &wol);
767}
768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769static int ethtool_nway_reset(struct net_device *dev)
770{
771 if (!dev->ethtool_ops->nway_reset)
772 return -EOPNOTSUPP;
773
774 return dev->ethtool_ops->nway_reset(dev);
775}
776
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
778{
779 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700780 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700781 void __user *userbuf = useraddr + sizeof(eeprom);
782 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700784 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
786 if (!ops->get_eeprom || !ops->get_eeprom_len)
787 return -EOPNOTSUPP;
788
789 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
790 return -EFAULT;
791
792 /* Check for wrap and zero */
793 if (eeprom.offset + eeprom.len <= eeprom.offset)
794 return -EINVAL;
795
796 /* Check for exceeding total eeprom len */
797 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
798 return -EINVAL;
799
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700800 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 if (!data)
802 return -ENOMEM;
803
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700804 bytes_remaining = eeprom.len;
805 while (bytes_remaining > 0) {
806 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700808 ret = ops->get_eeprom(dev, &eeprom, data);
809 if (ret)
810 break;
811 if (copy_to_user(userbuf, data, eeprom.len)) {
812 ret = -EFAULT;
813 break;
814 }
815 userbuf += eeprom.len;
816 eeprom.offset += eeprom.len;
817 bytes_remaining -= eeprom.len;
818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -0700820 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
821 eeprom.offset -= eeprom.len;
822 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
823 ret = -EFAULT;
824
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 kfree(data);
826 return ret;
827}
828
829static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
830{
831 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700832 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700833 void __user *userbuf = useraddr + sizeof(eeprom);
834 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700836 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838 if (!ops->set_eeprom || !ops->get_eeprom_len)
839 return -EOPNOTSUPP;
840
841 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
842 return -EFAULT;
843
844 /* Check for wrap and zero */
845 if (eeprom.offset + eeprom.len <= eeprom.offset)
846 return -EINVAL;
847
848 /* Check for exceeding total eeprom len */
849 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
850 return -EINVAL;
851
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700852 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 if (!data)
854 return -ENOMEM;
855
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700856 bytes_remaining = eeprom.len;
857 while (bytes_remaining > 0) {
858 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700860 if (copy_from_user(data, userbuf, eeprom.len)) {
861 ret = -EFAULT;
862 break;
863 }
864 ret = ops->set_eeprom(dev, &eeprom, data);
865 if (ret)
866 break;
867 userbuf += eeprom.len;
868 eeprom.offset += eeprom.len;
869 bytes_remaining -= eeprom.len;
870 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 kfree(data);
873 return ret;
874}
875
chavey97f8aef2010-04-07 21:54:42 -0700876static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
877 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878{
Roland Dreier8e557422010-02-11 12:14:23 -0800879 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
881 if (!dev->ethtool_ops->get_coalesce)
882 return -EOPNOTSUPP;
883
884 dev->ethtool_ops->get_coalesce(dev, &coalesce);
885
886 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
887 return -EFAULT;
888 return 0;
889}
890
chavey97f8aef2010-04-07 21:54:42 -0700891static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
892 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893{
894 struct ethtool_coalesce coalesce;
895
David S. Millerfa04ae52005-06-06 15:07:19 -0700896 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 return -EOPNOTSUPP;
898
899 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
900 return -EFAULT;
901
902 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
903}
904
905static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
906{
Roland Dreier8e557422010-02-11 12:14:23 -0800907 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909 if (!dev->ethtool_ops->get_ringparam)
910 return -EOPNOTSUPP;
911
912 dev->ethtool_ops->get_ringparam(dev, &ringparam);
913
914 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
915 return -EFAULT;
916 return 0;
917}
918
919static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
920{
921 struct ethtool_ringparam ringparam;
922
923 if (!dev->ethtool_ops->set_ringparam)
924 return -EOPNOTSUPP;
925
926 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
927 return -EFAULT;
928
929 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
930}
931
932static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
933{
934 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
935
936 if (!dev->ethtool_ops->get_pauseparam)
937 return -EOPNOTSUPP;
938
939 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
940
941 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
942 return -EFAULT;
943 return 0;
944}
945
946static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
947{
948 struct ethtool_pauseparam pauseparam;
949
Jeff Garzike1b90c42006-07-17 12:54:40 -0400950 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 return -EOPNOTSUPP;
952
953 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
954 return -EFAULT;
955
956 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
957}
958
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959static int __ethtool_set_sg(struct net_device *dev, u32 data)
960{
961 int err;
962
963 if (!data && dev->ethtool_ops->set_tso) {
964 err = dev->ethtool_ops->set_tso(dev, 0);
965 if (err)
966 return err;
967 }
968
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700969 if (!data && dev->ethtool_ops->set_ufo) {
970 err = dev->ethtool_ops->set_ufo(dev, 0);
971 if (err)
972 return err;
973 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 return dev->ethtool_ops->set_sg(dev, data);
975}
976
977static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
978{
979 struct ethtool_value edata;
980 int err;
981
982 if (!dev->ethtool_ops->set_tx_csum)
983 return -EOPNOTSUPP;
984
985 if (copy_from_user(&edata, useraddr, sizeof(edata)))
986 return -EFAULT;
987
988 if (!edata.data && dev->ethtool_ops->set_sg) {
989 err = __ethtool_set_sg(dev, 0);
990 if (err)
991 return err;
992 }
993
994 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
995}
chavey97f8aef2010-04-07 21:54:42 -0700996EXPORT_SYMBOL(ethtool_op_set_tx_csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Herbert Xub240a0e2008-12-15 23:44:31 -0800998static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
999{
1000 struct ethtool_value edata;
1001
1002 if (!dev->ethtool_ops->set_rx_csum)
1003 return -EOPNOTSUPP;
1004
1005 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1006 return -EFAULT;
1007
1008 if (!edata.data && dev->ethtool_ops->set_sg)
1009 dev->features &= ~NETIF_F_GRO;
1010
1011 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
1012}
1013
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
1015{
1016 struct ethtool_value edata;
1017
1018 if (!dev->ethtool_ops->set_sg)
1019 return -EOPNOTSUPP;
1020
1021 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1022 return -EFAULT;
1023
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001024 if (edata.data &&
Herbert Xu8648b302006-06-17 22:06:05 -07001025 !(dev->features & NETIF_F_ALL_CSUM))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 return -EINVAL;
1027
1028 return __ethtool_set_sg(dev, edata.data);
1029}
1030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
1032{
1033 struct ethtool_value edata;
1034
1035 if (!dev->ethtool_ops->set_tso)
1036 return -EOPNOTSUPP;
1037
1038 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1039 return -EFAULT;
1040
1041 if (edata.data && !(dev->features & NETIF_F_SG))
1042 return -EINVAL;
1043
1044 return dev->ethtool_ops->set_tso(dev, edata.data);
1045}
1046
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001047static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
1048{
1049 struct ethtool_value edata;
1050
1051 if (!dev->ethtool_ops->set_ufo)
1052 return -EOPNOTSUPP;
1053 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1054 return -EFAULT;
1055 if (edata.data && !(dev->features & NETIF_F_SG))
1056 return -EINVAL;
1057 if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
1058 return -EINVAL;
1059 return dev->ethtool_ops->set_ufo(dev, edata.data);
1060}
1061
Herbert Xu37c31852006-06-22 03:07:29 -07001062static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
1063{
1064 struct ethtool_value edata = { ETHTOOL_GGSO };
1065
1066 edata.data = dev->features & NETIF_F_GSO;
1067 if (copy_to_user(useraddr, &edata, sizeof(edata)))
chavey97f8aef2010-04-07 21:54:42 -07001068 return -EFAULT;
Herbert Xu37c31852006-06-22 03:07:29 -07001069 return 0;
1070}
1071
1072static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
1073{
1074 struct ethtool_value edata;
1075
1076 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1077 return -EFAULT;
1078 if (edata.data)
1079 dev->features |= NETIF_F_GSO;
1080 else
1081 dev->features &= ~NETIF_F_GSO;
1082 return 0;
1083}
1084
Herbert Xub240a0e2008-12-15 23:44:31 -08001085static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
1086{
1087 struct ethtool_value edata = { ETHTOOL_GGRO };
1088
1089 edata.data = dev->features & NETIF_F_GRO;
1090 if (copy_to_user(useraddr, &edata, sizeof(edata)))
chavey97f8aef2010-04-07 21:54:42 -07001091 return -EFAULT;
Herbert Xub240a0e2008-12-15 23:44:31 -08001092 return 0;
1093}
1094
1095static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
1096{
1097 struct ethtool_value edata;
1098
1099 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1100 return -EFAULT;
1101
1102 if (edata.data) {
1103 if (!dev->ethtool_ops->get_rx_csum ||
1104 !dev->ethtool_ops->get_rx_csum(dev))
1105 return -EINVAL;
1106 dev->features |= NETIF_F_GRO;
1107 } else
1108 dev->features &= ~NETIF_F_GRO;
1109
1110 return 0;
1111}
1112
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1114{
1115 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001116 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001118 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001120 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001121 return -EOPNOTSUPP;
1122
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001123 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -07001124 if (test_len < 0)
1125 return test_len;
1126 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
1128 if (copy_from_user(&test, useraddr, sizeof(test)))
1129 return -EFAULT;
1130
Jeff Garzikff03d492007-08-15 16:01:08 -07001131 test.len = test_len;
1132 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 if (!data)
1134 return -ENOMEM;
1135
1136 ops->self_test(dev, &test, data);
1137
1138 ret = -EFAULT;
1139 if (copy_to_user(useraddr, &test, sizeof(test)))
1140 goto out;
1141 useraddr += sizeof(test);
1142 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1143 goto out;
1144 ret = 0;
1145
1146 out:
1147 kfree(data);
1148 return ret;
1149}
1150
1151static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1152{
1153 struct ethtool_gstrings gstrings;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001154 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 u8 *data;
1156 int ret;
1157
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001158 if (!ops->get_strings || !ops->get_sset_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 return -EOPNOTSUPP;
1160
1161 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1162 return -EFAULT;
1163
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001164 ret = ops->get_sset_count(dev, gstrings.string_set);
1165 if (ret < 0)
1166 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001167
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001168 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
1170 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1171 if (!data)
1172 return -ENOMEM;
1173
1174 ops->get_strings(dev, gstrings.string_set, data);
1175
1176 ret = -EFAULT;
1177 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1178 goto out;
1179 useraddr += sizeof(gstrings);
1180 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1181 goto out;
1182 ret = 0;
1183
1184 out:
1185 kfree(data);
1186 return ret;
1187}
1188
1189static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1190{
1191 struct ethtool_value id;
1192
1193 if (!dev->ethtool_ops->phys_id)
1194 return -EOPNOTSUPP;
1195
1196 if (copy_from_user(&id, useraddr, sizeof(id)))
1197 return -EFAULT;
1198
1199 return dev->ethtool_ops->phys_id(dev, id.data);
1200}
1201
1202static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1203{
1204 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001205 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001207 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001209 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001210 return -EOPNOTSUPP;
1211
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001212 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001213 if (n_stats < 0)
1214 return n_stats;
1215 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
1217 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1218 return -EFAULT;
1219
Jeff Garzikff03d492007-08-15 16:01:08 -07001220 stats.n_stats = n_stats;
1221 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 if (!data)
1223 return -ENOMEM;
1224
1225 ops->get_ethtool_stats(dev, &stats, data);
1226
1227 ret = -EFAULT;
1228 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1229 goto out;
1230 useraddr += sizeof(stats);
1231 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1232 goto out;
1233 ret = 0;
1234
1235 out:
1236 kfree(data);
1237 return ret;
1238}
1239
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001240static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001241{
1242 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001243
Matthew Wilcox313674a2007-07-31 14:00:29 -07001244 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001245 return -EFAULT;
1246
Matthew Wilcox313674a2007-07-31 14:00:29 -07001247 if (epaddr.size < dev->addr_len)
1248 return -ETOOSMALL;
1249 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001250
Jon Wetzela6f9a702005-08-20 17:15:54 -07001251 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001252 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001253 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001254 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1255 return -EFAULT;
1256 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001257}
1258
Jeff Garzik13c99b22007-08-15 16:01:56 -07001259static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1260 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001261{
Roland Dreier8e557422010-02-11 12:14:23 -08001262 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001263
Jeff Garzik13c99b22007-08-15 16:01:56 -07001264 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001265 return -EOPNOTSUPP;
1266
Jeff Garzik13c99b22007-08-15 16:01:56 -07001267 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001268
1269 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1270 return -EFAULT;
1271 return 0;
1272}
1273
Jeff Garzik13c99b22007-08-15 16:01:56 -07001274static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1275 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001276{
1277 struct ethtool_value edata;
1278
Jeff Garzik13c99b22007-08-15 16:01:56 -07001279 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001280 return -EOPNOTSUPP;
1281
1282 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1283 return -EFAULT;
1284
Jeff Garzik13c99b22007-08-15 16:01:56 -07001285 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001286 return 0;
1287}
1288
Jeff Garzik13c99b22007-08-15 16:01:56 -07001289static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1290 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001291{
1292 struct ethtool_value edata;
1293
Jeff Garzik13c99b22007-08-15 16:01:56 -07001294 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001295 return -EOPNOTSUPP;
1296
1297 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1298 return -EFAULT;
1299
Jeff Garzik13c99b22007-08-15 16:01:56 -07001300 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001301}
1302
chavey97f8aef2010-04-07 21:54:42 -07001303static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1304 char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001305{
1306 struct ethtool_flash efl;
1307
1308 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1309 return -EFAULT;
1310
1311 if (!dev->ethtool_ops->flash_device)
1312 return -EOPNOTSUPP;
1313
1314 return dev->ethtool_ops->flash_device(dev, &efl);
1315}
1316
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317/* The main entry point in this file. Called from net/core/dev.c */
1318
Eric W. Biederman881d9662007-09-17 11:56:21 -07001319int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001321 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 void __user *useraddr = ifr->ifr_data;
1323 u32 ethcmd;
1324 int rc;
Stephen Hemminger81e81572005-05-29 14:14:35 -07001325 unsigned long old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 if (!dev || !netif_device_present(dev))
1328 return -ENODEV;
1329
1330 if (!dev->ethtool_ops)
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001331 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
chavey97f8aef2010-04-07 21:54:42 -07001333 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 return -EFAULT;
1335
Stephen Hemminger75f31232006-09-28 15:13:37 -07001336 /* Allow some commands to be done by anyone */
chavey97f8aef2010-04-07 21:54:42 -07001337 switch (ethcmd) {
Stephen Hemminger75f31232006-09-28 15:13:37 -07001338 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001339 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001340 case ETHTOOL_GCOALESCE:
1341 case ETHTOOL_GRINGPARAM:
1342 case ETHTOOL_GPAUSEPARAM:
1343 case ETHTOOL_GRXCSUM:
1344 case ETHTOOL_GTXCSUM:
1345 case ETHTOOL_GSG:
1346 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001347 case ETHTOOL_GTSO:
1348 case ETHTOOL_GPERMADDR:
1349 case ETHTOOL_GUFO:
1350 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001351 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001352 case ETHTOOL_GFLAGS:
1353 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001354 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001355 case ETHTOOL_GRXRINGS:
1356 case ETHTOOL_GRXCLSRLCNT:
1357 case ETHTOOL_GRXCLSRULE:
1358 case ETHTOOL_GRXCLSRLALL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001359 break;
1360 default:
1361 if (!capable(CAP_NET_ADMIN))
1362 return -EPERM;
1363 }
1364
chavey97f8aef2010-04-07 21:54:42 -07001365 if (dev->ethtool_ops->begin) {
1366 rc = dev->ethtool_ops->begin(dev);
1367 if (rc < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 return rc;
chavey97f8aef2010-04-07 21:54:42 -07001369 }
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001370 old_features = dev->features;
1371
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 switch (ethcmd) {
1373 case ETHTOOL_GSET:
1374 rc = ethtool_get_settings(dev, useraddr);
1375 break;
1376 case ETHTOOL_SSET:
1377 rc = ethtool_set_settings(dev, useraddr);
1378 break;
1379 case ETHTOOL_GDRVINFO:
1380 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 break;
1382 case ETHTOOL_GREGS:
1383 rc = ethtool_get_regs(dev, useraddr);
1384 break;
1385 case ETHTOOL_GWOL:
1386 rc = ethtool_get_wol(dev, useraddr);
1387 break;
1388 case ETHTOOL_SWOL:
1389 rc = ethtool_set_wol(dev, useraddr);
1390 break;
1391 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001392 rc = ethtool_get_value(dev, useraddr, ethcmd,
1393 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 break;
1395 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001396 rc = ethtool_set_value_void(dev, useraddr,
1397 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 break;
1399 case ETHTOOL_NWAY_RST:
1400 rc = ethtool_nway_reset(dev);
1401 break;
1402 case ETHTOOL_GLINK:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001403 rc = ethtool_get_value(dev, useraddr, ethcmd,
1404 dev->ethtool_ops->get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 break;
1406 case ETHTOOL_GEEPROM:
1407 rc = ethtool_get_eeprom(dev, useraddr);
1408 break;
1409 case ETHTOOL_SEEPROM:
1410 rc = ethtool_set_eeprom(dev, useraddr);
1411 break;
1412 case ETHTOOL_GCOALESCE:
1413 rc = ethtool_get_coalesce(dev, useraddr);
1414 break;
1415 case ETHTOOL_SCOALESCE:
1416 rc = ethtool_set_coalesce(dev, useraddr);
1417 break;
1418 case ETHTOOL_GRINGPARAM:
1419 rc = ethtool_get_ringparam(dev, useraddr);
1420 break;
1421 case ETHTOOL_SRINGPARAM:
1422 rc = ethtool_set_ringparam(dev, useraddr);
1423 break;
1424 case ETHTOOL_GPAUSEPARAM:
1425 rc = ethtool_get_pauseparam(dev, useraddr);
1426 break;
1427 case ETHTOOL_SPAUSEPARAM:
1428 rc = ethtool_set_pauseparam(dev, useraddr);
1429 break;
1430 case ETHTOOL_GRXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001431 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001432 (dev->ethtool_ops->get_rx_csum ?
1433 dev->ethtool_ops->get_rx_csum :
1434 ethtool_op_get_rx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 break;
1436 case ETHTOOL_SRXCSUM:
Herbert Xub240a0e2008-12-15 23:44:31 -08001437 rc = ethtool_set_rx_csum(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 break;
1439 case ETHTOOL_GTXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001440 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001441 (dev->ethtool_ops->get_tx_csum ?
1442 dev->ethtool_ops->get_tx_csum :
1443 ethtool_op_get_tx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 break;
1445 case ETHTOOL_STXCSUM:
1446 rc = ethtool_set_tx_csum(dev, useraddr);
1447 break;
1448 case ETHTOOL_GSG:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001449 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001450 (dev->ethtool_ops->get_sg ?
1451 dev->ethtool_ops->get_sg :
1452 ethtool_op_get_sg));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 break;
1454 case ETHTOOL_SSG:
1455 rc = ethtool_set_sg(dev, useraddr);
1456 break;
1457 case ETHTOOL_GTSO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001458 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001459 (dev->ethtool_ops->get_tso ?
1460 dev->ethtool_ops->get_tso :
1461 ethtool_op_get_tso));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 break;
1463 case ETHTOOL_STSO:
1464 rc = ethtool_set_tso(dev, useraddr);
1465 break;
1466 case ETHTOOL_TEST:
1467 rc = ethtool_self_test(dev, useraddr);
1468 break;
1469 case ETHTOOL_GSTRINGS:
1470 rc = ethtool_get_strings(dev, useraddr);
1471 break;
1472 case ETHTOOL_PHYS_ID:
1473 rc = ethtool_phys_id(dev, useraddr);
1474 break;
1475 case ETHTOOL_GSTATS:
1476 rc = ethtool_get_stats(dev, useraddr);
1477 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001478 case ETHTOOL_GPERMADDR:
1479 rc = ethtool_get_perm_addr(dev, useraddr);
1480 break;
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001481 case ETHTOOL_GUFO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001482 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001483 (dev->ethtool_ops->get_ufo ?
1484 dev->ethtool_ops->get_ufo :
1485 ethtool_op_get_ufo));
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001486 break;
1487 case ETHTOOL_SUFO:
1488 rc = ethtool_set_ufo(dev, useraddr);
1489 break;
Herbert Xu37c31852006-06-22 03:07:29 -07001490 case ETHTOOL_GGSO:
1491 rc = ethtool_get_gso(dev, useraddr);
1492 break;
1493 case ETHTOOL_SGSO:
1494 rc = ethtool_set_gso(dev, useraddr);
1495 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001496 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001497 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001498 (dev->ethtool_ops->get_flags ?
1499 dev->ethtool_ops->get_flags :
1500 ethtool_op_get_flags));
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001501 break;
1502 case ETHTOOL_SFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001503 rc = ethtool_set_value(dev, useraddr,
1504 dev->ethtool_ops->set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001505 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001506 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001507 rc = ethtool_get_value(dev, useraddr, ethcmd,
1508 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001509 break;
1510 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001511 rc = ethtool_set_value(dev, useraddr,
1512 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001513 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001514 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001515 case ETHTOOL_GRXRINGS:
1516 case ETHTOOL_GRXCLSRLCNT:
1517 case ETHTOOL_GRXCLSRULE:
1518 case ETHTOOL_GRXCLSRLALL:
1519 rc = ethtool_get_rxnfc(dev, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001520 break;
1521 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001522 case ETHTOOL_SRXCLSRLDEL:
1523 case ETHTOOL_SRXCLSRLINS:
1524 rc = ethtool_set_rxnfc(dev, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001525 break;
Herbert Xub240a0e2008-12-15 23:44:31 -08001526 case ETHTOOL_GGRO:
1527 rc = ethtool_get_gro(dev, useraddr);
1528 break;
1529 case ETHTOOL_SGRO:
1530 rc = ethtool_set_gro(dev, useraddr);
1531 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001532 case ETHTOOL_FLASHDEV:
1533 rc = ethtool_flash_device(dev, useraddr);
1534 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001535 case ETHTOOL_RESET:
1536 rc = ethtool_reset(dev, useraddr);
1537 break;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001538 case ETHTOOL_SRXNTUPLE:
1539 rc = ethtool_set_rx_ntuple(dev, useraddr);
1540 break;
1541 case ETHTOOL_GRXNTUPLE:
1542 rc = ethtool_get_rx_ntuple(dev, useraddr);
1543 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001544 case ETHTOOL_GSSET_INFO:
1545 rc = ethtool_get_sset_info(dev, useraddr);
1546 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001548 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001550
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001551 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001553
1554 if (old_features != dev->features)
1555 netdev_features_change(dev);
1556
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558}