blob: 5d42fae520d95b23b3d20d0770d8a1ad5b826ca0 [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
Ben Hutchings1437ce32010-06-30 02:44:32 +0000147int ethtool_op_set_flags(struct net_device *dev, u32 data, u32 supported)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700148{
Ben Hutchings1437ce32010-06-30 02:44:32 +0000149 if (data & ~supported)
150 return -EINVAL;
Peter Waskiewicz0d643e12010-02-12 13:48:25 +0000151
Ben Hutchings1437ce32010-06-30 02:44:32 +0000152 dev->features = ((dev->features & ~flags_dup_features) |
153 (data & flags_dup_features));
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700154 return 0;
155}
chavey97f8aef2010-04-07 21:54:42 -0700156EXPORT_SYMBOL(ethtool_op_set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700157
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800158void ethtool_ntuple_flush(struct net_device *dev)
159{
160 struct ethtool_rx_ntuple_flow_spec_container *fsc, *f;
161
162 list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) {
163 list_del(&fsc->list);
164 kfree(fsc);
165 }
166 dev->ethtool_ntuple_list.count = 0;
167}
168EXPORT_SYMBOL(ethtool_ntuple_flush);
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170/* Handlers for each ethtool command */
171
172static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
173{
Roland Dreier8e557422010-02-11 12:14:23 -0800174 struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 int err;
176
177 if (!dev->ethtool_ops->get_settings)
178 return -EOPNOTSUPP;
179
180 err = dev->ethtool_ops->get_settings(dev, &cmd);
181 if (err < 0)
182 return err;
183
184 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
185 return -EFAULT;
186 return 0;
187}
188
189static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
190{
191 struct ethtool_cmd cmd;
192
193 if (!dev->ethtool_ops->set_settings)
194 return -EOPNOTSUPP;
195
196 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
197 return -EFAULT;
198
199 return dev->ethtool_ops->set_settings(dev, &cmd);
200}
201
chavey97f8aef2010-04-07 21:54:42 -0700202static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
203 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
205 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700206 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
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
Jeff Garzik723b2f52010-03-03 22:51:50 +0000215 /*
216 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000217 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000218 */
Jeff Garzikff03d492007-08-15 16:01:08 -0700219 if (ops->get_sset_count) {
220 int rc;
221
222 rc = ops->get_sset_count(dev, ETH_SS_TEST);
223 if (rc >= 0)
224 info.testinfo_len = rc;
225 rc = ops->get_sset_count(dev, ETH_SS_STATS);
226 if (rc >= 0)
227 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700228 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
229 if (rc >= 0)
230 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 if (ops->get_regs_len)
233 info.regdump_len = ops->get_regs_len(dev);
234 if (ops->get_eeprom_len)
235 info.eedump_len = ops->get_eeprom_len(dev);
236
237 if (copy_to_user(useraddr, &info, sizeof(info)))
238 return -EFAULT;
239 return 0;
240}
241
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800242static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
chavey97f8aef2010-04-07 21:54:42 -0700243 void __user *useraddr)
Jeff Garzik723b2f52010-03-03 22:51:50 +0000244{
245 struct ethtool_sset_info info;
246 const struct ethtool_ops *ops = dev->ethtool_ops;
247 u64 sset_mask;
248 int i, idx = 0, n_bits = 0, ret, rc;
249 u32 *info_buf = NULL;
250
251 if (!ops->get_sset_count)
252 return -EOPNOTSUPP;
253
254 if (copy_from_user(&info, useraddr, sizeof(info)))
255 return -EFAULT;
256
257 /* store copy of mask, because we zero struct later on */
258 sset_mask = info.sset_mask;
259 if (!sset_mask)
260 return 0;
261
262 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000263 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000264
265 memset(&info, 0, sizeof(info));
266 info.cmd = ETHTOOL_GSSET_INFO;
267
268 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
269 if (!info_buf)
270 return -ENOMEM;
271
272 /*
273 * fill return buffer based on input bitmask and successful
274 * get_sset_count return
275 */
276 for (i = 0; i < 64; i++) {
277 if (!(sset_mask & (1ULL << i)))
278 continue;
279
280 rc = ops->get_sset_count(dev, i);
281 if (rc >= 0) {
282 info.sset_mask |= (1ULL << i);
283 info_buf[idx++] = rc;
284 }
285 }
286
287 ret = -EFAULT;
288 if (copy_to_user(useraddr, &info, sizeof(info)))
289 goto out;
290
291 useraddr += offsetof(struct ethtool_sset_info, data);
292 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
293 goto out;
294
295 ret = 0;
296
297out:
298 kfree(info_buf);
299 return ret;
300}
301
chavey97f8aef2010-04-07 21:54:42 -0700302static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
303 void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700304{
305 struct ethtool_rxnfc cmd;
306
Santwona Behera59089d82009-02-20 00:58:13 -0800307 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700308 return -EOPNOTSUPP;
309
310 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
311 return -EFAULT;
312
Santwona Behera59089d82009-02-20 00:58:13 -0800313 return dev->ethtool_ops->set_rxnfc(dev, &cmd);
Santwona Behera0853ad62008-07-02 03:47:41 -0700314}
315
chavey97f8aef2010-04-07 21:54:42 -0700316static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
317 void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700318{
319 struct ethtool_rxnfc info;
Santwona Behera59089d82009-02-20 00:58:13 -0800320 const struct ethtool_ops *ops = dev->ethtool_ops;
321 int ret;
322 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700323
Santwona Behera59089d82009-02-20 00:58:13 -0800324 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700325 return -EOPNOTSUPP;
326
327 if (copy_from_user(&info, useraddr, sizeof(info)))
328 return -EFAULT;
329
Santwona Behera59089d82009-02-20 00:58:13 -0800330 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
331 if (info.rule_cnt > 0) {
332 rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
333 GFP_USER);
334 if (!rule_buf)
335 return -ENOMEM;
336 }
337 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700338
Santwona Behera59089d82009-02-20 00:58:13 -0800339 ret = ops->get_rxnfc(dev, &info, rule_buf);
340 if (ret < 0)
341 goto err_out;
342
343 ret = -EFAULT;
Santwona Behera0853ad62008-07-02 03:47:41 -0700344 if (copy_to_user(useraddr, &info, sizeof(info)))
Santwona Behera59089d82009-02-20 00:58:13 -0800345 goto err_out;
346
347 if (rule_buf) {
348 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
349 if (copy_to_user(useraddr, rule_buf,
350 info.rule_cnt * sizeof(u32)))
351 goto err_out;
352 }
353 ret = 0;
354
355err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700356 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800357
358 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700359}
360
Peter Waskiewicze8589112010-02-12 13:48:05 +0000361static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
chavey97f8aef2010-04-07 21:54:42 -0700362 struct ethtool_rx_ntuple_flow_spec *spec,
363 struct ethtool_rx_ntuple_flow_spec_container *fsc)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800364{
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800365
366 /* don't add filters forever */
Peter Waskiewicze8589112010-02-12 13:48:05 +0000367 if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
368 /* free the container */
369 kfree(fsc);
370 return;
371 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800372
373 /* Copy the whole filter over */
374 fsc->fs.flow_type = spec->flow_type;
375 memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
376 memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
377
378 fsc->fs.vlan_tag = spec->vlan_tag;
379 fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
380 fsc->fs.data = spec->data;
381 fsc->fs.data_mask = spec->data_mask;
382 fsc->fs.action = spec->action;
383
384 /* add to the list */
385 list_add_tail_rcu(&fsc->list, &list->list);
386 list->count++;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800387}
388
chavey97f8aef2010-04-07 21:54:42 -0700389static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev,
390 void __user *useraddr)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800391{
392 struct ethtool_rx_ntuple cmd;
393 const struct ethtool_ops *ops = dev->ethtool_ops;
Peter Waskiewicze8589112010-02-12 13:48:05 +0000394 struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800395 int ret;
396
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800397 if (!(dev->features & NETIF_F_NTUPLE))
398 return -EINVAL;
399
400 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
401 return -EFAULT;
402
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800403 /*
404 * Cache filter in dev struct for GET operation only if
405 * the underlying driver doesn't have its own GET operation, and
Peter Waskiewicze8589112010-02-12 13:48:05 +0000406 * only if the filter was added successfully. First make sure we
407 * can allocate the filter, then continue if successful.
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800408 */
Peter Waskiewicze8589112010-02-12 13:48:05 +0000409 if (!ops->get_rx_ntuple) {
410 fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
411 if (!fsc)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800412 return -ENOMEM;
Peter Waskiewicze8589112010-02-12 13:48:05 +0000413 }
414
415 ret = ops->set_rx_ntuple(dev, &cmd);
416 if (ret) {
417 kfree(fsc);
418 return ret;
419 }
420
421 if (!ops->get_rx_ntuple)
422 __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800423
424 return ret;
425}
426
427static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
428{
429 struct ethtool_gstrings gstrings;
430 const struct ethtool_ops *ops = dev->ethtool_ops;
431 struct ethtool_rx_ntuple_flow_spec_container *fsc;
432 u8 *data;
433 char *p;
434 int ret, i, num_strings = 0;
435
436 if (!ops->get_sset_count)
437 return -EOPNOTSUPP;
438
439 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
440 return -EFAULT;
441
442 ret = ops->get_sset_count(dev, gstrings.string_set);
443 if (ret < 0)
444 return ret;
445
446 gstrings.len = ret;
447
448 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
449 if (!data)
450 return -ENOMEM;
451
452 if (ops->get_rx_ntuple) {
453 /* driver-specific filter grab */
454 ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
455 goto copy;
456 }
457
458 /* default ethtool filter grab */
459 i = 0;
460 p = (char *)data;
461 list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
462 sprintf(p, "Filter %d:\n", i);
463 p += ETH_GSTRING_LEN;
464 num_strings++;
465
466 switch (fsc->fs.flow_type) {
467 case TCP_V4_FLOW:
468 sprintf(p, "\tFlow Type: TCP\n");
469 p += ETH_GSTRING_LEN;
470 num_strings++;
471 break;
472 case UDP_V4_FLOW:
473 sprintf(p, "\tFlow Type: UDP\n");
474 p += ETH_GSTRING_LEN;
475 num_strings++;
476 break;
477 case SCTP_V4_FLOW:
478 sprintf(p, "\tFlow Type: SCTP\n");
479 p += ETH_GSTRING_LEN;
480 num_strings++;
481 break;
482 case AH_ESP_V4_FLOW:
483 sprintf(p, "\tFlow Type: AH ESP\n");
484 p += ETH_GSTRING_LEN;
485 num_strings++;
486 break;
487 case ESP_V4_FLOW:
488 sprintf(p, "\tFlow Type: ESP\n");
489 p += ETH_GSTRING_LEN;
490 num_strings++;
491 break;
492 case IP_USER_FLOW:
493 sprintf(p, "\tFlow Type: Raw IP\n");
494 p += ETH_GSTRING_LEN;
495 num_strings++;
496 break;
497 case IPV4_FLOW:
498 sprintf(p, "\tFlow Type: IPv4\n");
499 p += ETH_GSTRING_LEN;
500 num_strings++;
501 break;
502 default:
503 sprintf(p, "\tFlow Type: Unknown\n");
504 p += ETH_GSTRING_LEN;
505 num_strings++;
506 goto unknown_filter;
Joe Perchesccbd6a52010-05-14 10:58:26 +0000507 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800508
509 /* now the rest of the filters */
510 switch (fsc->fs.flow_type) {
511 case TCP_V4_FLOW:
512 case UDP_V4_FLOW:
513 case SCTP_V4_FLOW:
514 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700515 fsc->fs.h_u.tcp_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800516 p += ETH_GSTRING_LEN;
517 num_strings++;
518 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700519 fsc->fs.m_u.tcp_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800520 p += ETH_GSTRING_LEN;
521 num_strings++;
522 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700523 fsc->fs.h_u.tcp_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800524 p += ETH_GSTRING_LEN;
525 num_strings++;
526 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700527 fsc->fs.m_u.tcp_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800528 p += ETH_GSTRING_LEN;
529 num_strings++;
530 sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700531 fsc->fs.h_u.tcp_ip4_spec.psrc,
532 fsc->fs.m_u.tcp_ip4_spec.psrc);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800533 p += ETH_GSTRING_LEN;
534 num_strings++;
535 sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700536 fsc->fs.h_u.tcp_ip4_spec.pdst,
537 fsc->fs.m_u.tcp_ip4_spec.pdst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800538 p += ETH_GSTRING_LEN;
539 num_strings++;
540 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700541 fsc->fs.h_u.tcp_ip4_spec.tos,
542 fsc->fs.m_u.tcp_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800543 p += ETH_GSTRING_LEN;
544 num_strings++;
545 break;
546 case AH_ESP_V4_FLOW:
547 case ESP_V4_FLOW:
548 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700549 fsc->fs.h_u.ah_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800550 p += ETH_GSTRING_LEN;
551 num_strings++;
552 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700553 fsc->fs.m_u.ah_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800554 p += ETH_GSTRING_LEN;
555 num_strings++;
556 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700557 fsc->fs.h_u.ah_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800558 p += ETH_GSTRING_LEN;
559 num_strings++;
560 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700561 fsc->fs.m_u.ah_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800562 p += ETH_GSTRING_LEN;
563 num_strings++;
564 sprintf(p, "\tSPI: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700565 fsc->fs.h_u.ah_ip4_spec.spi,
566 fsc->fs.m_u.ah_ip4_spec.spi);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800567 p += ETH_GSTRING_LEN;
568 num_strings++;
569 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700570 fsc->fs.h_u.ah_ip4_spec.tos,
571 fsc->fs.m_u.ah_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800572 p += ETH_GSTRING_LEN;
573 num_strings++;
574 break;
575 case IP_USER_FLOW:
576 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700577 fsc->fs.h_u.raw_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800578 p += ETH_GSTRING_LEN;
579 num_strings++;
580 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700581 fsc->fs.m_u.raw_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800582 p += ETH_GSTRING_LEN;
583 num_strings++;
584 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700585 fsc->fs.h_u.raw_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800586 p += ETH_GSTRING_LEN;
587 num_strings++;
588 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700589 fsc->fs.m_u.raw_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800590 p += ETH_GSTRING_LEN;
591 num_strings++;
592 break;
593 case IPV4_FLOW:
594 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700595 fsc->fs.h_u.usr_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.usr_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.usr_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.usr_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800608 p += ETH_GSTRING_LEN;
609 num_strings++;
610 sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700611 fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
612 fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800613 p += ETH_GSTRING_LEN;
614 num_strings++;
615 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700616 fsc->fs.h_u.usr_ip4_spec.tos,
617 fsc->fs.m_u.usr_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800618 p += ETH_GSTRING_LEN;
619 num_strings++;
620 sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700621 fsc->fs.h_u.usr_ip4_spec.ip_ver,
622 fsc->fs.m_u.usr_ip4_spec.ip_ver);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800623 p += ETH_GSTRING_LEN;
624 num_strings++;
625 sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700626 fsc->fs.h_u.usr_ip4_spec.proto,
627 fsc->fs.m_u.usr_ip4_spec.proto);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800628 p += ETH_GSTRING_LEN;
629 num_strings++;
630 break;
Joe Perchesccbd6a52010-05-14 10:58:26 +0000631 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800632 sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700633 fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800634 p += ETH_GSTRING_LEN;
635 num_strings++;
636 sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
637 p += ETH_GSTRING_LEN;
638 num_strings++;
639 sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
640 p += ETH_GSTRING_LEN;
641 num_strings++;
642 if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
643 sprintf(p, "\tAction: Drop\n");
644 else
645 sprintf(p, "\tAction: Direct to queue %d\n",
chavey97f8aef2010-04-07 21:54:42 -0700646 fsc->fs.action);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800647 p += ETH_GSTRING_LEN;
648 num_strings++;
649unknown_filter:
650 i++;
651 }
652copy:
653 /* indicate to userspace how many strings we actually have */
654 gstrings.len = num_strings;
655 ret = -EFAULT;
656 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
657 goto out;
658 useraddr += sizeof(gstrings);
659 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
660 goto out;
661 ret = 0;
662
663out:
664 kfree(data);
665 return ret;
666}
667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
669{
670 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700671 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 void *regbuf;
673 int reglen, ret;
674
675 if (!ops->get_regs || !ops->get_regs_len)
676 return -EOPNOTSUPP;
677
678 if (copy_from_user(&regs, useraddr, sizeof(regs)))
679 return -EFAULT;
680
681 reglen = ops->get_regs_len(dev);
682 if (regs.len > reglen)
683 regs.len = reglen;
684
685 regbuf = kmalloc(reglen, GFP_USER);
686 if (!regbuf)
687 return -ENOMEM;
688
689 ops->get_regs(dev, &regs, regbuf);
690
691 ret = -EFAULT;
692 if (copy_to_user(useraddr, &regs, sizeof(regs)))
693 goto out;
694 useraddr += offsetof(struct ethtool_regs, data);
695 if (copy_to_user(useraddr, regbuf, regs.len))
696 goto out;
697 ret = 0;
698
699 out:
700 kfree(regbuf);
701 return ret;
702}
703
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000704static int ethtool_reset(struct net_device *dev, char __user *useraddr)
705{
706 struct ethtool_value reset;
707 int ret;
708
709 if (!dev->ethtool_ops->reset)
710 return -EOPNOTSUPP;
711
712 if (copy_from_user(&reset, useraddr, sizeof(reset)))
713 return -EFAULT;
714
715 ret = dev->ethtool_ops->reset(dev, &reset.data);
716 if (ret)
717 return ret;
718
719 if (copy_to_user(useraddr, &reset, sizeof(reset)))
720 return -EFAULT;
721 return 0;
722}
723
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
725{
Roland Dreier8e557422010-02-11 12:14:23 -0800726 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728 if (!dev->ethtool_ops->get_wol)
729 return -EOPNOTSUPP;
730
731 dev->ethtool_ops->get_wol(dev, &wol);
732
733 if (copy_to_user(useraddr, &wol, sizeof(wol)))
734 return -EFAULT;
735 return 0;
736}
737
738static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
739{
740 struct ethtool_wolinfo wol;
741
742 if (!dev->ethtool_ops->set_wol)
743 return -EOPNOTSUPP;
744
745 if (copy_from_user(&wol, useraddr, sizeof(wol)))
746 return -EFAULT;
747
748 return dev->ethtool_ops->set_wol(dev, &wol);
749}
750
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751static int ethtool_nway_reset(struct net_device *dev)
752{
753 if (!dev->ethtool_ops->nway_reset)
754 return -EOPNOTSUPP;
755
756 return dev->ethtool_ops->nway_reset(dev);
757}
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
760{
761 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700762 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700763 void __user *userbuf = useraddr + sizeof(eeprom);
764 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700766 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768 if (!ops->get_eeprom || !ops->get_eeprom_len)
769 return -EOPNOTSUPP;
770
771 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
772 return -EFAULT;
773
774 /* Check for wrap and zero */
775 if (eeprom.offset + eeprom.len <= eeprom.offset)
776 return -EINVAL;
777
778 /* Check for exceeding total eeprom len */
779 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
780 return -EINVAL;
781
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700782 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 if (!data)
784 return -ENOMEM;
785
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700786 bytes_remaining = eeprom.len;
787 while (bytes_remaining > 0) {
788 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700790 ret = ops->get_eeprom(dev, &eeprom, data);
791 if (ret)
792 break;
793 if (copy_to_user(userbuf, data, eeprom.len)) {
794 ret = -EFAULT;
795 break;
796 }
797 userbuf += eeprom.len;
798 eeprom.offset += eeprom.len;
799 bytes_remaining -= eeprom.len;
800 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -0700802 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
803 eeprom.offset -= eeprom.len;
804 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
805 ret = -EFAULT;
806
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 kfree(data);
808 return ret;
809}
810
811static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
812{
813 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700814 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700815 void __user *userbuf = useraddr + sizeof(eeprom);
816 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700818 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820 if (!ops->set_eeprom || !ops->get_eeprom_len)
821 return -EOPNOTSUPP;
822
823 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
824 return -EFAULT;
825
826 /* Check for wrap and zero */
827 if (eeprom.offset + eeprom.len <= eeprom.offset)
828 return -EINVAL;
829
830 /* Check for exceeding total eeprom len */
831 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
832 return -EINVAL;
833
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700834 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 if (!data)
836 return -ENOMEM;
837
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700838 bytes_remaining = eeprom.len;
839 while (bytes_remaining > 0) {
840 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700842 if (copy_from_user(data, userbuf, eeprom.len)) {
843 ret = -EFAULT;
844 break;
845 }
846 ret = ops->set_eeprom(dev, &eeprom, data);
847 if (ret)
848 break;
849 userbuf += eeprom.len;
850 eeprom.offset += eeprom.len;
851 bytes_remaining -= eeprom.len;
852 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 kfree(data);
855 return ret;
856}
857
chavey97f8aef2010-04-07 21:54:42 -0700858static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
859 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860{
Roland Dreier8e557422010-02-11 12:14:23 -0800861 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
863 if (!dev->ethtool_ops->get_coalesce)
864 return -EOPNOTSUPP;
865
866 dev->ethtool_ops->get_coalesce(dev, &coalesce);
867
868 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
869 return -EFAULT;
870 return 0;
871}
872
chavey97f8aef2010-04-07 21:54:42 -0700873static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
874 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
876 struct ethtool_coalesce coalesce;
877
David S. Millerfa04ae52005-06-06 15:07:19 -0700878 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 return -EOPNOTSUPP;
880
881 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
882 return -EFAULT;
883
884 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
885}
886
887static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
888{
Roland Dreier8e557422010-02-11 12:14:23 -0800889 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
891 if (!dev->ethtool_ops->get_ringparam)
892 return -EOPNOTSUPP;
893
894 dev->ethtool_ops->get_ringparam(dev, &ringparam);
895
896 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
897 return -EFAULT;
898 return 0;
899}
900
901static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
902{
903 struct ethtool_ringparam ringparam;
904
905 if (!dev->ethtool_ops->set_ringparam)
906 return -EOPNOTSUPP;
907
908 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
909 return -EFAULT;
910
911 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
912}
913
914static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
915{
916 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
917
918 if (!dev->ethtool_ops->get_pauseparam)
919 return -EOPNOTSUPP;
920
921 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
922
923 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
924 return -EFAULT;
925 return 0;
926}
927
928static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
929{
930 struct ethtool_pauseparam pauseparam;
931
Jeff Garzike1b90c42006-07-17 12:54:40 -0400932 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 return -EOPNOTSUPP;
934
935 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
936 return -EFAULT;
937
938 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
939}
940
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941static int __ethtool_set_sg(struct net_device *dev, u32 data)
942{
943 int err;
944
945 if (!data && dev->ethtool_ops->set_tso) {
946 err = dev->ethtool_ops->set_tso(dev, 0);
947 if (err)
948 return err;
949 }
950
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700951 if (!data && dev->ethtool_ops->set_ufo) {
952 err = dev->ethtool_ops->set_ufo(dev, 0);
953 if (err)
954 return err;
955 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 return dev->ethtool_ops->set_sg(dev, data);
957}
958
959static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
960{
961 struct ethtool_value edata;
962 int err;
963
964 if (!dev->ethtool_ops->set_tx_csum)
965 return -EOPNOTSUPP;
966
967 if (copy_from_user(&edata, useraddr, sizeof(edata)))
968 return -EFAULT;
969
970 if (!edata.data && dev->ethtool_ops->set_sg) {
971 err = __ethtool_set_sg(dev, 0);
972 if (err)
973 return err;
974 }
975
976 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
977}
chavey97f8aef2010-04-07 21:54:42 -0700978EXPORT_SYMBOL(ethtool_op_set_tx_csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
Herbert Xub240a0e2008-12-15 23:44:31 -0800980static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
981{
982 struct ethtool_value edata;
983
984 if (!dev->ethtool_ops->set_rx_csum)
985 return -EOPNOTSUPP;
986
987 if (copy_from_user(&edata, useraddr, sizeof(edata)))
988 return -EFAULT;
989
990 if (!edata.data && dev->ethtool_ops->set_sg)
991 dev->features &= ~NETIF_F_GRO;
992
993 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
994}
995
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
997{
998 struct ethtool_value edata;
999
1000 if (!dev->ethtool_ops->set_sg)
1001 return -EOPNOTSUPP;
1002
1003 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1004 return -EFAULT;
1005
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001006 if (edata.data &&
Herbert Xu8648b302006-06-17 22:06:05 -07001007 !(dev->features & NETIF_F_ALL_CSUM))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 return -EINVAL;
1009
1010 return __ethtool_set_sg(dev, edata.data);
1011}
1012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
1014{
1015 struct ethtool_value edata;
1016
1017 if (!dev->ethtool_ops->set_tso)
1018 return -EOPNOTSUPP;
1019
1020 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1021 return -EFAULT;
1022
1023 if (edata.data && !(dev->features & NETIF_F_SG))
1024 return -EINVAL;
1025
1026 return dev->ethtool_ops->set_tso(dev, edata.data);
1027}
1028
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001029static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
1030{
1031 struct ethtool_value edata;
1032
1033 if (!dev->ethtool_ops->set_ufo)
1034 return -EOPNOTSUPP;
1035 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1036 return -EFAULT;
1037 if (edata.data && !(dev->features & NETIF_F_SG))
1038 return -EINVAL;
1039 if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
1040 return -EINVAL;
1041 return dev->ethtool_ops->set_ufo(dev, edata.data);
1042}
1043
Herbert Xu37c31852006-06-22 03:07:29 -07001044static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
1045{
1046 struct ethtool_value edata = { ETHTOOL_GGSO };
1047
1048 edata.data = dev->features & NETIF_F_GSO;
1049 if (copy_to_user(useraddr, &edata, sizeof(edata)))
chavey97f8aef2010-04-07 21:54:42 -07001050 return -EFAULT;
Herbert Xu37c31852006-06-22 03:07:29 -07001051 return 0;
1052}
1053
1054static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
1055{
1056 struct ethtool_value edata;
1057
1058 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1059 return -EFAULT;
1060 if (edata.data)
1061 dev->features |= NETIF_F_GSO;
1062 else
1063 dev->features &= ~NETIF_F_GSO;
1064 return 0;
1065}
1066
Herbert Xub240a0e2008-12-15 23:44:31 -08001067static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
1068{
1069 struct ethtool_value edata = { ETHTOOL_GGRO };
1070
1071 edata.data = dev->features & NETIF_F_GRO;
1072 if (copy_to_user(useraddr, &edata, sizeof(edata)))
chavey97f8aef2010-04-07 21:54:42 -07001073 return -EFAULT;
Herbert Xub240a0e2008-12-15 23:44:31 -08001074 return 0;
1075}
1076
1077static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
1078{
1079 struct ethtool_value edata;
1080
1081 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1082 return -EFAULT;
1083
1084 if (edata.data) {
1085 if (!dev->ethtool_ops->get_rx_csum ||
1086 !dev->ethtool_ops->get_rx_csum(dev))
1087 return -EINVAL;
1088 dev->features |= NETIF_F_GRO;
1089 } else
1090 dev->features &= ~NETIF_F_GRO;
1091
1092 return 0;
1093}
1094
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1096{
1097 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001098 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001100 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001102 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001103 return -EOPNOTSUPP;
1104
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001105 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -07001106 if (test_len < 0)
1107 return test_len;
1108 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
1110 if (copy_from_user(&test, useraddr, sizeof(test)))
1111 return -EFAULT;
1112
Jeff Garzikff03d492007-08-15 16:01:08 -07001113 test.len = test_len;
1114 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 if (!data)
1116 return -ENOMEM;
1117
1118 ops->self_test(dev, &test, data);
1119
1120 ret = -EFAULT;
1121 if (copy_to_user(useraddr, &test, sizeof(test)))
1122 goto out;
1123 useraddr += sizeof(test);
1124 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1125 goto out;
1126 ret = 0;
1127
1128 out:
1129 kfree(data);
1130 return ret;
1131}
1132
1133static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1134{
1135 struct ethtool_gstrings gstrings;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001136 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 u8 *data;
1138 int ret;
1139
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001140 if (!ops->get_strings || !ops->get_sset_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 return -EOPNOTSUPP;
1142
1143 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1144 return -EFAULT;
1145
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001146 ret = ops->get_sset_count(dev, gstrings.string_set);
1147 if (ret < 0)
1148 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001149
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001150 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
1152 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1153 if (!data)
1154 return -ENOMEM;
1155
1156 ops->get_strings(dev, gstrings.string_set, data);
1157
1158 ret = -EFAULT;
1159 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1160 goto out;
1161 useraddr += sizeof(gstrings);
1162 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1163 goto out;
1164 ret = 0;
1165
1166 out:
1167 kfree(data);
1168 return ret;
1169}
1170
1171static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1172{
1173 struct ethtool_value id;
1174
1175 if (!dev->ethtool_ops->phys_id)
1176 return -EOPNOTSUPP;
1177
1178 if (copy_from_user(&id, useraddr, sizeof(id)))
1179 return -EFAULT;
1180
1181 return dev->ethtool_ops->phys_id(dev, id.data);
1182}
1183
1184static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1185{
1186 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001187 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001189 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001191 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001192 return -EOPNOTSUPP;
1193
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001194 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001195 if (n_stats < 0)
1196 return n_stats;
1197 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
1199 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1200 return -EFAULT;
1201
Jeff Garzikff03d492007-08-15 16:01:08 -07001202 stats.n_stats = n_stats;
1203 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 if (!data)
1205 return -ENOMEM;
1206
1207 ops->get_ethtool_stats(dev, &stats, data);
1208
1209 ret = -EFAULT;
1210 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1211 goto out;
1212 useraddr += sizeof(stats);
1213 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1214 goto out;
1215 ret = 0;
1216
1217 out:
1218 kfree(data);
1219 return ret;
1220}
1221
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001222static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001223{
1224 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001225
Matthew Wilcox313674a2007-07-31 14:00:29 -07001226 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001227 return -EFAULT;
1228
Matthew Wilcox313674a2007-07-31 14:00:29 -07001229 if (epaddr.size < dev->addr_len)
1230 return -ETOOSMALL;
1231 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001232
Jon Wetzela6f9a702005-08-20 17:15:54 -07001233 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001234 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001235 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001236 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1237 return -EFAULT;
1238 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001239}
1240
Jeff Garzik13c99b22007-08-15 16:01:56 -07001241static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1242 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001243{
Roland Dreier8e557422010-02-11 12:14:23 -08001244 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001245
Jeff Garzik13c99b22007-08-15 16:01:56 -07001246 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001247 return -EOPNOTSUPP;
1248
Jeff Garzik13c99b22007-08-15 16:01:56 -07001249 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001250
1251 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1252 return -EFAULT;
1253 return 0;
1254}
1255
Jeff Garzik13c99b22007-08-15 16:01:56 -07001256static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1257 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001258{
1259 struct ethtool_value edata;
1260
Jeff Garzik13c99b22007-08-15 16:01:56 -07001261 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001262 return -EOPNOTSUPP;
1263
1264 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1265 return -EFAULT;
1266
Jeff Garzik13c99b22007-08-15 16:01:56 -07001267 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001268 return 0;
1269}
1270
Jeff Garzik13c99b22007-08-15 16:01:56 -07001271static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1272 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001273{
1274 struct ethtool_value edata;
1275
Jeff Garzik13c99b22007-08-15 16:01:56 -07001276 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001277 return -EOPNOTSUPP;
1278
1279 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1280 return -EFAULT;
1281
Jeff Garzik13c99b22007-08-15 16:01:56 -07001282 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001283}
1284
chavey97f8aef2010-04-07 21:54:42 -07001285static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1286 char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001287{
1288 struct ethtool_flash efl;
1289
1290 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1291 return -EFAULT;
1292
1293 if (!dev->ethtool_ops->flash_device)
1294 return -EOPNOTSUPP;
1295
1296 return dev->ethtool_ops->flash_device(dev, &efl);
1297}
1298
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299/* The main entry point in this file. Called from net/core/dev.c */
1300
Eric W. Biederman881d9662007-09-17 11:56:21 -07001301int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001303 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 void __user *useraddr = ifr->ifr_data;
1305 u32 ethcmd;
1306 int rc;
Stephen Hemminger81e81572005-05-29 14:14:35 -07001307 unsigned long old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 if (!dev || !netif_device_present(dev))
1310 return -ENODEV;
1311
1312 if (!dev->ethtool_ops)
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001313 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
chavey97f8aef2010-04-07 21:54:42 -07001315 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 return -EFAULT;
1317
Stephen Hemminger75f31232006-09-28 15:13:37 -07001318 /* Allow some commands to be done by anyone */
chavey97f8aef2010-04-07 21:54:42 -07001319 switch (ethcmd) {
Stephen Hemminger75f31232006-09-28 15:13:37 -07001320 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001321 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001322 case ETHTOOL_GCOALESCE:
1323 case ETHTOOL_GRINGPARAM:
1324 case ETHTOOL_GPAUSEPARAM:
1325 case ETHTOOL_GRXCSUM:
1326 case ETHTOOL_GTXCSUM:
1327 case ETHTOOL_GSG:
1328 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001329 case ETHTOOL_GTSO:
1330 case ETHTOOL_GPERMADDR:
1331 case ETHTOOL_GUFO:
1332 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001333 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001334 case ETHTOOL_GFLAGS:
1335 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001336 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001337 case ETHTOOL_GRXRINGS:
1338 case ETHTOOL_GRXCLSRLCNT:
1339 case ETHTOOL_GRXCLSRULE:
1340 case ETHTOOL_GRXCLSRLALL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001341 break;
1342 default:
1343 if (!capable(CAP_NET_ADMIN))
1344 return -EPERM;
1345 }
1346
chavey97f8aef2010-04-07 21:54:42 -07001347 if (dev->ethtool_ops->begin) {
1348 rc = dev->ethtool_ops->begin(dev);
1349 if (rc < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 return rc;
chavey97f8aef2010-04-07 21:54:42 -07001351 }
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001352 old_features = dev->features;
1353
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 switch (ethcmd) {
1355 case ETHTOOL_GSET:
1356 rc = ethtool_get_settings(dev, useraddr);
1357 break;
1358 case ETHTOOL_SSET:
1359 rc = ethtool_set_settings(dev, useraddr);
1360 break;
1361 case ETHTOOL_GDRVINFO:
1362 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 break;
1364 case ETHTOOL_GREGS:
1365 rc = ethtool_get_regs(dev, useraddr);
1366 break;
1367 case ETHTOOL_GWOL:
1368 rc = ethtool_get_wol(dev, useraddr);
1369 break;
1370 case ETHTOOL_SWOL:
1371 rc = ethtool_set_wol(dev, useraddr);
1372 break;
1373 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001374 rc = ethtool_get_value(dev, useraddr, ethcmd,
1375 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 break;
1377 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001378 rc = ethtool_set_value_void(dev, useraddr,
1379 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 break;
1381 case ETHTOOL_NWAY_RST:
1382 rc = ethtool_nway_reset(dev);
1383 break;
1384 case ETHTOOL_GLINK:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001385 rc = ethtool_get_value(dev, useraddr, ethcmd,
1386 dev->ethtool_ops->get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 break;
1388 case ETHTOOL_GEEPROM:
1389 rc = ethtool_get_eeprom(dev, useraddr);
1390 break;
1391 case ETHTOOL_SEEPROM:
1392 rc = ethtool_set_eeprom(dev, useraddr);
1393 break;
1394 case ETHTOOL_GCOALESCE:
1395 rc = ethtool_get_coalesce(dev, useraddr);
1396 break;
1397 case ETHTOOL_SCOALESCE:
1398 rc = ethtool_set_coalesce(dev, useraddr);
1399 break;
1400 case ETHTOOL_GRINGPARAM:
1401 rc = ethtool_get_ringparam(dev, useraddr);
1402 break;
1403 case ETHTOOL_SRINGPARAM:
1404 rc = ethtool_set_ringparam(dev, useraddr);
1405 break;
1406 case ETHTOOL_GPAUSEPARAM:
1407 rc = ethtool_get_pauseparam(dev, useraddr);
1408 break;
1409 case ETHTOOL_SPAUSEPARAM:
1410 rc = ethtool_set_pauseparam(dev, useraddr);
1411 break;
1412 case ETHTOOL_GRXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001413 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001414 (dev->ethtool_ops->get_rx_csum ?
1415 dev->ethtool_ops->get_rx_csum :
1416 ethtool_op_get_rx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 break;
1418 case ETHTOOL_SRXCSUM:
Herbert Xub240a0e2008-12-15 23:44:31 -08001419 rc = ethtool_set_rx_csum(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 break;
1421 case ETHTOOL_GTXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001422 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001423 (dev->ethtool_ops->get_tx_csum ?
1424 dev->ethtool_ops->get_tx_csum :
1425 ethtool_op_get_tx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 break;
1427 case ETHTOOL_STXCSUM:
1428 rc = ethtool_set_tx_csum(dev, useraddr);
1429 break;
1430 case ETHTOOL_GSG:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001431 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001432 (dev->ethtool_ops->get_sg ?
1433 dev->ethtool_ops->get_sg :
1434 ethtool_op_get_sg));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 break;
1436 case ETHTOOL_SSG:
1437 rc = ethtool_set_sg(dev, useraddr);
1438 break;
1439 case ETHTOOL_GTSO:
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_tso ?
1442 dev->ethtool_ops->get_tso :
1443 ethtool_op_get_tso));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 break;
1445 case ETHTOOL_STSO:
1446 rc = ethtool_set_tso(dev, useraddr);
1447 break;
1448 case ETHTOOL_TEST:
1449 rc = ethtool_self_test(dev, useraddr);
1450 break;
1451 case ETHTOOL_GSTRINGS:
1452 rc = ethtool_get_strings(dev, useraddr);
1453 break;
1454 case ETHTOOL_PHYS_ID:
1455 rc = ethtool_phys_id(dev, useraddr);
1456 break;
1457 case ETHTOOL_GSTATS:
1458 rc = ethtool_get_stats(dev, useraddr);
1459 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001460 case ETHTOOL_GPERMADDR:
1461 rc = ethtool_get_perm_addr(dev, useraddr);
1462 break;
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001463 case ETHTOOL_GUFO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001464 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001465 (dev->ethtool_ops->get_ufo ?
1466 dev->ethtool_ops->get_ufo :
1467 ethtool_op_get_ufo));
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001468 break;
1469 case ETHTOOL_SUFO:
1470 rc = ethtool_set_ufo(dev, useraddr);
1471 break;
Herbert Xu37c31852006-06-22 03:07:29 -07001472 case ETHTOOL_GGSO:
1473 rc = ethtool_get_gso(dev, useraddr);
1474 break;
1475 case ETHTOOL_SGSO:
1476 rc = ethtool_set_gso(dev, useraddr);
1477 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001478 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001479 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001480 (dev->ethtool_ops->get_flags ?
1481 dev->ethtool_ops->get_flags :
1482 ethtool_op_get_flags));
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001483 break;
1484 case ETHTOOL_SFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001485 rc = ethtool_set_value(dev, useraddr,
1486 dev->ethtool_ops->set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001487 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001488 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001489 rc = ethtool_get_value(dev, useraddr, ethcmd,
1490 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001491 break;
1492 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001493 rc = ethtool_set_value(dev, useraddr,
1494 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001495 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001496 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001497 case ETHTOOL_GRXRINGS:
1498 case ETHTOOL_GRXCLSRLCNT:
1499 case ETHTOOL_GRXCLSRULE:
1500 case ETHTOOL_GRXCLSRLALL:
1501 rc = ethtool_get_rxnfc(dev, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001502 break;
1503 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001504 case ETHTOOL_SRXCLSRLDEL:
1505 case ETHTOOL_SRXCLSRLINS:
1506 rc = ethtool_set_rxnfc(dev, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001507 break;
Herbert Xub240a0e2008-12-15 23:44:31 -08001508 case ETHTOOL_GGRO:
1509 rc = ethtool_get_gro(dev, useraddr);
1510 break;
1511 case ETHTOOL_SGRO:
1512 rc = ethtool_set_gro(dev, useraddr);
1513 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001514 case ETHTOOL_FLASHDEV:
1515 rc = ethtool_flash_device(dev, useraddr);
1516 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001517 case ETHTOOL_RESET:
1518 rc = ethtool_reset(dev, useraddr);
1519 break;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001520 case ETHTOOL_SRXNTUPLE:
1521 rc = ethtool_set_rx_ntuple(dev, useraddr);
1522 break;
1523 case ETHTOOL_GRXNTUPLE:
1524 rc = ethtool_get_rx_ntuple(dev, useraddr);
1525 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001526 case ETHTOOL_GSSET_INFO:
1527 rc = ethtool_get_sset_info(dev, useraddr);
1528 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001530 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001532
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001533 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001535
1536 if (old_features != dev->features)
1537 netdev_features_change(dev);
1538
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540}