blob: 75e4ffeb8cc99dae9c03c07c39962b17c4453f43 [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,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000321 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700322{
Ben Hutchingsbf988432010-06-28 08:45:58 +0000323 struct ethtool_rxnfc info;
324 size_t info_size = sizeof(info);
Santwona Behera0853ad62008-07-02 03:47:41 -0700325
Santwona Behera59089d82009-02-20 00:58:13 -0800326 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700327 return -EOPNOTSUPP;
328
Ben Hutchingsbf988432010-06-28 08:45:58 +0000329 /* struct ethtool_rxnfc was originally defined for
330 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
331 * members. User-space might still be using that
332 * definition. */
333 if (cmd == ETHTOOL_SRXFH)
334 info_size = (offsetof(struct ethtool_rxnfc, data) +
335 sizeof(info.data));
336
337 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700338 return -EFAULT;
339
Ben Hutchingsbf988432010-06-28 08:45:58 +0000340 return dev->ethtool_ops->set_rxnfc(dev, &info);
Santwona Behera0853ad62008-07-02 03:47:41 -0700341}
342
chavey97f8aef2010-04-07 21:54:42 -0700343static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000344 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700345{
346 struct ethtool_rxnfc info;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000347 size_t info_size = sizeof(info);
Santwona Behera59089d82009-02-20 00:58:13 -0800348 const struct ethtool_ops *ops = dev->ethtool_ops;
349 int ret;
350 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700351
Santwona Behera59089d82009-02-20 00:58:13 -0800352 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700353 return -EOPNOTSUPP;
354
Ben Hutchingsbf988432010-06-28 08:45:58 +0000355 /* struct ethtool_rxnfc was originally defined for
356 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
357 * members. User-space might still be using that
358 * definition. */
359 if (cmd == ETHTOOL_GRXFH)
360 info_size = (offsetof(struct ethtool_rxnfc, data) +
361 sizeof(info.data));
362
363 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700364 return -EFAULT;
365
Santwona Behera59089d82009-02-20 00:58:13 -0800366 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
367 if (info.rule_cnt > 0) {
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000368 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
369 rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
370 GFP_USER);
Santwona Behera59089d82009-02-20 00:58:13 -0800371 if (!rule_buf)
372 return -ENOMEM;
373 }
374 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700375
Santwona Behera59089d82009-02-20 00:58:13 -0800376 ret = ops->get_rxnfc(dev, &info, rule_buf);
377 if (ret < 0)
378 goto err_out;
379
380 ret = -EFAULT;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000381 if (copy_to_user(useraddr, &info, info_size))
Santwona Behera59089d82009-02-20 00:58:13 -0800382 goto err_out;
383
384 if (rule_buf) {
385 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
386 if (copy_to_user(useraddr, rule_buf,
387 info.rule_cnt * sizeof(u32)))
388 goto err_out;
389 }
390 ret = 0;
391
392err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700393 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800394
395 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700396}
397
Peter Waskiewicze8589112010-02-12 13:48:05 +0000398static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
chavey97f8aef2010-04-07 21:54:42 -0700399 struct ethtool_rx_ntuple_flow_spec *spec,
400 struct ethtool_rx_ntuple_flow_spec_container *fsc)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800401{
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800402
403 /* don't add filters forever */
Peter Waskiewicze8589112010-02-12 13:48:05 +0000404 if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
405 /* free the container */
406 kfree(fsc);
407 return;
408 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800409
410 /* Copy the whole filter over */
411 fsc->fs.flow_type = spec->flow_type;
412 memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
413 memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
414
415 fsc->fs.vlan_tag = spec->vlan_tag;
416 fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
417 fsc->fs.data = spec->data;
418 fsc->fs.data_mask = spec->data_mask;
419 fsc->fs.action = spec->action;
420
421 /* add to the list */
422 list_add_tail_rcu(&fsc->list, &list->list);
423 list->count++;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800424}
425
chavey97f8aef2010-04-07 21:54:42 -0700426static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev,
427 void __user *useraddr)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800428{
429 struct ethtool_rx_ntuple cmd;
430 const struct ethtool_ops *ops = dev->ethtool_ops;
Peter Waskiewicze8589112010-02-12 13:48:05 +0000431 struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800432 int ret;
433
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800434 if (!(dev->features & NETIF_F_NTUPLE))
435 return -EINVAL;
436
437 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
438 return -EFAULT;
439
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800440 /*
441 * Cache filter in dev struct for GET operation only if
442 * the underlying driver doesn't have its own GET operation, and
Peter Waskiewicze8589112010-02-12 13:48:05 +0000443 * only if the filter was added successfully. First make sure we
444 * can allocate the filter, then continue if successful.
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800445 */
Peter Waskiewicze8589112010-02-12 13:48:05 +0000446 if (!ops->get_rx_ntuple) {
447 fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
448 if (!fsc)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800449 return -ENOMEM;
Peter Waskiewicze8589112010-02-12 13:48:05 +0000450 }
451
452 ret = ops->set_rx_ntuple(dev, &cmd);
453 if (ret) {
454 kfree(fsc);
455 return ret;
456 }
457
458 if (!ops->get_rx_ntuple)
459 __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800460
461 return ret;
462}
463
464static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
465{
466 struct ethtool_gstrings gstrings;
467 const struct ethtool_ops *ops = dev->ethtool_ops;
468 struct ethtool_rx_ntuple_flow_spec_container *fsc;
469 u8 *data;
470 char *p;
471 int ret, i, num_strings = 0;
472
473 if (!ops->get_sset_count)
474 return -EOPNOTSUPP;
475
476 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
477 return -EFAULT;
478
479 ret = ops->get_sset_count(dev, gstrings.string_set);
480 if (ret < 0)
481 return ret;
482
483 gstrings.len = ret;
484
485 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
486 if (!data)
487 return -ENOMEM;
488
489 if (ops->get_rx_ntuple) {
490 /* driver-specific filter grab */
491 ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
492 goto copy;
493 }
494
495 /* default ethtool filter grab */
496 i = 0;
497 p = (char *)data;
498 list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
499 sprintf(p, "Filter %d:\n", i);
500 p += ETH_GSTRING_LEN;
501 num_strings++;
502
503 switch (fsc->fs.flow_type) {
504 case TCP_V4_FLOW:
505 sprintf(p, "\tFlow Type: TCP\n");
506 p += ETH_GSTRING_LEN;
507 num_strings++;
508 break;
509 case UDP_V4_FLOW:
510 sprintf(p, "\tFlow Type: UDP\n");
511 p += ETH_GSTRING_LEN;
512 num_strings++;
513 break;
514 case SCTP_V4_FLOW:
515 sprintf(p, "\tFlow Type: SCTP\n");
516 p += ETH_GSTRING_LEN;
517 num_strings++;
518 break;
519 case AH_ESP_V4_FLOW:
520 sprintf(p, "\tFlow Type: AH ESP\n");
521 p += ETH_GSTRING_LEN;
522 num_strings++;
523 break;
524 case ESP_V4_FLOW:
525 sprintf(p, "\tFlow Type: ESP\n");
526 p += ETH_GSTRING_LEN;
527 num_strings++;
528 break;
529 case IP_USER_FLOW:
530 sprintf(p, "\tFlow Type: Raw IP\n");
531 p += ETH_GSTRING_LEN;
532 num_strings++;
533 break;
534 case IPV4_FLOW:
535 sprintf(p, "\tFlow Type: IPv4\n");
536 p += ETH_GSTRING_LEN;
537 num_strings++;
538 break;
539 default:
540 sprintf(p, "\tFlow Type: Unknown\n");
541 p += ETH_GSTRING_LEN;
542 num_strings++;
543 goto unknown_filter;
Joe Perchesccbd6a52010-05-14 10:58:26 +0000544 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800545
546 /* now the rest of the filters */
547 switch (fsc->fs.flow_type) {
548 case TCP_V4_FLOW:
549 case UDP_V4_FLOW:
550 case SCTP_V4_FLOW:
551 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700552 fsc->fs.h_u.tcp_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800553 p += ETH_GSTRING_LEN;
554 num_strings++;
555 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700556 fsc->fs.m_u.tcp_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800557 p += ETH_GSTRING_LEN;
558 num_strings++;
559 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700560 fsc->fs.h_u.tcp_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800561 p += ETH_GSTRING_LEN;
562 num_strings++;
563 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700564 fsc->fs.m_u.tcp_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800565 p += ETH_GSTRING_LEN;
566 num_strings++;
567 sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700568 fsc->fs.h_u.tcp_ip4_spec.psrc,
569 fsc->fs.m_u.tcp_ip4_spec.psrc);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800570 p += ETH_GSTRING_LEN;
571 num_strings++;
572 sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700573 fsc->fs.h_u.tcp_ip4_spec.pdst,
574 fsc->fs.m_u.tcp_ip4_spec.pdst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800575 p += ETH_GSTRING_LEN;
576 num_strings++;
577 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700578 fsc->fs.h_u.tcp_ip4_spec.tos,
579 fsc->fs.m_u.tcp_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800580 p += ETH_GSTRING_LEN;
581 num_strings++;
582 break;
583 case AH_ESP_V4_FLOW:
584 case ESP_V4_FLOW:
585 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700586 fsc->fs.h_u.ah_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800587 p += ETH_GSTRING_LEN;
588 num_strings++;
589 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700590 fsc->fs.m_u.ah_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800591 p += ETH_GSTRING_LEN;
592 num_strings++;
593 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700594 fsc->fs.h_u.ah_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800595 p += ETH_GSTRING_LEN;
596 num_strings++;
597 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700598 fsc->fs.m_u.ah_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800599 p += ETH_GSTRING_LEN;
600 num_strings++;
601 sprintf(p, "\tSPI: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700602 fsc->fs.h_u.ah_ip4_spec.spi,
603 fsc->fs.m_u.ah_ip4_spec.spi);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800604 p += ETH_GSTRING_LEN;
605 num_strings++;
606 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700607 fsc->fs.h_u.ah_ip4_spec.tos,
608 fsc->fs.m_u.ah_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800609 p += ETH_GSTRING_LEN;
610 num_strings++;
611 break;
612 case IP_USER_FLOW:
613 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700614 fsc->fs.h_u.raw_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800615 p += ETH_GSTRING_LEN;
616 num_strings++;
617 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700618 fsc->fs.m_u.raw_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800619 p += ETH_GSTRING_LEN;
620 num_strings++;
621 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700622 fsc->fs.h_u.raw_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800623 p += ETH_GSTRING_LEN;
624 num_strings++;
625 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700626 fsc->fs.m_u.raw_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800627 p += ETH_GSTRING_LEN;
628 num_strings++;
629 break;
630 case IPV4_FLOW:
631 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700632 fsc->fs.h_u.usr_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800633 p += ETH_GSTRING_LEN;
634 num_strings++;
635 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700636 fsc->fs.m_u.usr_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800637 p += ETH_GSTRING_LEN;
638 num_strings++;
639 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700640 fsc->fs.h_u.usr_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800641 p += ETH_GSTRING_LEN;
642 num_strings++;
643 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700644 fsc->fs.m_u.usr_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800645 p += ETH_GSTRING_LEN;
646 num_strings++;
647 sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700648 fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
649 fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800650 p += ETH_GSTRING_LEN;
651 num_strings++;
652 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700653 fsc->fs.h_u.usr_ip4_spec.tos,
654 fsc->fs.m_u.usr_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800655 p += ETH_GSTRING_LEN;
656 num_strings++;
657 sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700658 fsc->fs.h_u.usr_ip4_spec.ip_ver,
659 fsc->fs.m_u.usr_ip4_spec.ip_ver);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800660 p += ETH_GSTRING_LEN;
661 num_strings++;
662 sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700663 fsc->fs.h_u.usr_ip4_spec.proto,
664 fsc->fs.m_u.usr_ip4_spec.proto);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800665 p += ETH_GSTRING_LEN;
666 num_strings++;
667 break;
Joe Perchesccbd6a52010-05-14 10:58:26 +0000668 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800669 sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700670 fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800671 p += ETH_GSTRING_LEN;
672 num_strings++;
673 sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
674 p += ETH_GSTRING_LEN;
675 num_strings++;
676 sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
677 p += ETH_GSTRING_LEN;
678 num_strings++;
679 if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
680 sprintf(p, "\tAction: Drop\n");
681 else
682 sprintf(p, "\tAction: Direct to queue %d\n",
chavey97f8aef2010-04-07 21:54:42 -0700683 fsc->fs.action);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800684 p += ETH_GSTRING_LEN;
685 num_strings++;
686unknown_filter:
687 i++;
688 }
689copy:
690 /* indicate to userspace how many strings we actually have */
691 gstrings.len = num_strings;
692 ret = -EFAULT;
693 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
694 goto out;
695 useraddr += sizeof(gstrings);
696 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
697 goto out;
698 ret = 0;
699
700out:
701 kfree(data);
702 return ret;
703}
704
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
706{
707 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700708 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 void *regbuf;
710 int reglen, ret;
711
712 if (!ops->get_regs || !ops->get_regs_len)
713 return -EOPNOTSUPP;
714
715 if (copy_from_user(&regs, useraddr, sizeof(regs)))
716 return -EFAULT;
717
718 reglen = ops->get_regs_len(dev);
719 if (regs.len > reglen)
720 regs.len = reglen;
721
722 regbuf = kmalloc(reglen, GFP_USER);
723 if (!regbuf)
724 return -ENOMEM;
725
726 ops->get_regs(dev, &regs, regbuf);
727
728 ret = -EFAULT;
729 if (copy_to_user(useraddr, &regs, sizeof(regs)))
730 goto out;
731 useraddr += offsetof(struct ethtool_regs, data);
732 if (copy_to_user(useraddr, regbuf, regs.len))
733 goto out;
734 ret = 0;
735
736 out:
737 kfree(regbuf);
738 return ret;
739}
740
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000741static int ethtool_reset(struct net_device *dev, char __user *useraddr)
742{
743 struct ethtool_value reset;
744 int ret;
745
746 if (!dev->ethtool_ops->reset)
747 return -EOPNOTSUPP;
748
749 if (copy_from_user(&reset, useraddr, sizeof(reset)))
750 return -EFAULT;
751
752 ret = dev->ethtool_ops->reset(dev, &reset.data);
753 if (ret)
754 return ret;
755
756 if (copy_to_user(useraddr, &reset, sizeof(reset)))
757 return -EFAULT;
758 return 0;
759}
760
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
762{
Roland Dreier8e557422010-02-11 12:14:23 -0800763 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 if (!dev->ethtool_ops->get_wol)
766 return -EOPNOTSUPP;
767
768 dev->ethtool_ops->get_wol(dev, &wol);
769
770 if (copy_to_user(useraddr, &wol, sizeof(wol)))
771 return -EFAULT;
772 return 0;
773}
774
775static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
776{
777 struct ethtool_wolinfo wol;
778
779 if (!dev->ethtool_ops->set_wol)
780 return -EOPNOTSUPP;
781
782 if (copy_from_user(&wol, useraddr, sizeof(wol)))
783 return -EFAULT;
784
785 return dev->ethtool_ops->set_wol(dev, &wol);
786}
787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788static int ethtool_nway_reset(struct net_device *dev)
789{
790 if (!dev->ethtool_ops->nway_reset)
791 return -EOPNOTSUPP;
792
793 return dev->ethtool_ops->nway_reset(dev);
794}
795
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
797{
798 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700799 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700800 void __user *userbuf = useraddr + sizeof(eeprom);
801 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700803 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 if (!ops->get_eeprom || !ops->get_eeprom_len)
806 return -EOPNOTSUPP;
807
808 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
809 return -EFAULT;
810
811 /* Check for wrap and zero */
812 if (eeprom.offset + eeprom.len <= eeprom.offset)
813 return -EINVAL;
814
815 /* Check for exceeding total eeprom len */
816 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
817 return -EINVAL;
818
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700819 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 if (!data)
821 return -ENOMEM;
822
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700823 bytes_remaining = eeprom.len;
824 while (bytes_remaining > 0) {
825 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700827 ret = ops->get_eeprom(dev, &eeprom, data);
828 if (ret)
829 break;
830 if (copy_to_user(userbuf, data, eeprom.len)) {
831 ret = -EFAULT;
832 break;
833 }
834 userbuf += eeprom.len;
835 eeprom.offset += eeprom.len;
836 bytes_remaining -= eeprom.len;
837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -0700839 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
840 eeprom.offset -= eeprom.len;
841 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
842 ret = -EFAULT;
843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 kfree(data);
845 return ret;
846}
847
848static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
849{
850 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700851 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700852 void __user *userbuf = useraddr + sizeof(eeprom);
853 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700855 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
857 if (!ops->set_eeprom || !ops->get_eeprom_len)
858 return -EOPNOTSUPP;
859
860 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
861 return -EFAULT;
862
863 /* Check for wrap and zero */
864 if (eeprom.offset + eeprom.len <= eeprom.offset)
865 return -EINVAL;
866
867 /* Check for exceeding total eeprom len */
868 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
869 return -EINVAL;
870
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700871 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 if (!data)
873 return -ENOMEM;
874
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700875 bytes_remaining = eeprom.len;
876 while (bytes_remaining > 0) {
877 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700879 if (copy_from_user(data, userbuf, eeprom.len)) {
880 ret = -EFAULT;
881 break;
882 }
883 ret = ops->set_eeprom(dev, &eeprom, data);
884 if (ret)
885 break;
886 userbuf += eeprom.len;
887 eeprom.offset += eeprom.len;
888 bytes_remaining -= eeprom.len;
889 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 kfree(data);
892 return ret;
893}
894
chavey97f8aef2010-04-07 21:54:42 -0700895static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
896 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897{
Roland Dreier8e557422010-02-11 12:14:23 -0800898 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
900 if (!dev->ethtool_ops->get_coalesce)
901 return -EOPNOTSUPP;
902
903 dev->ethtool_ops->get_coalesce(dev, &coalesce);
904
905 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
906 return -EFAULT;
907 return 0;
908}
909
chavey97f8aef2010-04-07 21:54:42 -0700910static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
911 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912{
913 struct ethtool_coalesce coalesce;
914
David S. Millerfa04ae52005-06-06 15:07:19 -0700915 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 return -EOPNOTSUPP;
917
918 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
919 return -EFAULT;
920
921 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
922}
923
924static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
925{
Roland Dreier8e557422010-02-11 12:14:23 -0800926 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 if (!dev->ethtool_ops->get_ringparam)
929 return -EOPNOTSUPP;
930
931 dev->ethtool_ops->get_ringparam(dev, &ringparam);
932
933 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
934 return -EFAULT;
935 return 0;
936}
937
938static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
939{
940 struct ethtool_ringparam ringparam;
941
942 if (!dev->ethtool_ops->set_ringparam)
943 return -EOPNOTSUPP;
944
945 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
946 return -EFAULT;
947
948 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
949}
950
951static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
952{
953 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
954
955 if (!dev->ethtool_ops->get_pauseparam)
956 return -EOPNOTSUPP;
957
958 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
959
960 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
961 return -EFAULT;
962 return 0;
963}
964
965static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
966{
967 struct ethtool_pauseparam pauseparam;
968
Jeff Garzike1b90c42006-07-17 12:54:40 -0400969 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 return -EOPNOTSUPP;
971
972 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
973 return -EFAULT;
974
975 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
976}
977
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978static int __ethtool_set_sg(struct net_device *dev, u32 data)
979{
980 int err;
981
982 if (!data && dev->ethtool_ops->set_tso) {
983 err = dev->ethtool_ops->set_tso(dev, 0);
984 if (err)
985 return err;
986 }
987
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700988 if (!data && dev->ethtool_ops->set_ufo) {
989 err = dev->ethtool_ops->set_ufo(dev, 0);
990 if (err)
991 return err;
992 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 return dev->ethtool_ops->set_sg(dev, data);
994}
995
996static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
997{
998 struct ethtool_value edata;
999 int err;
1000
1001 if (!dev->ethtool_ops->set_tx_csum)
1002 return -EOPNOTSUPP;
1003
1004 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1005 return -EFAULT;
1006
1007 if (!edata.data && dev->ethtool_ops->set_sg) {
1008 err = __ethtool_set_sg(dev, 0);
1009 if (err)
1010 return err;
1011 }
1012
1013 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
1014}
chavey97f8aef2010-04-07 21:54:42 -07001015EXPORT_SYMBOL(ethtool_op_set_tx_csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
Herbert Xub240a0e2008-12-15 23:44:31 -08001017static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
1018{
1019 struct ethtool_value edata;
1020
1021 if (!dev->ethtool_ops->set_rx_csum)
1022 return -EOPNOTSUPP;
1023
1024 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1025 return -EFAULT;
1026
1027 if (!edata.data && dev->ethtool_ops->set_sg)
1028 dev->features &= ~NETIF_F_GRO;
1029
1030 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
1031}
1032
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
1034{
1035 struct ethtool_value edata;
1036
1037 if (!dev->ethtool_ops->set_sg)
1038 return -EOPNOTSUPP;
1039
1040 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1041 return -EFAULT;
1042
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001043 if (edata.data &&
Herbert Xu8648b302006-06-17 22:06:05 -07001044 !(dev->features & NETIF_F_ALL_CSUM))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 return -EINVAL;
1046
1047 return __ethtool_set_sg(dev, edata.data);
1048}
1049
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
1051{
1052 struct ethtool_value edata;
1053
1054 if (!dev->ethtool_ops->set_tso)
1055 return -EOPNOTSUPP;
1056
1057 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1058 return -EFAULT;
1059
1060 if (edata.data && !(dev->features & NETIF_F_SG))
1061 return -EINVAL;
1062
1063 return dev->ethtool_ops->set_tso(dev, edata.data);
1064}
1065
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001066static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
1067{
1068 struct ethtool_value edata;
1069
1070 if (!dev->ethtool_ops->set_ufo)
1071 return -EOPNOTSUPP;
1072 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1073 return -EFAULT;
1074 if (edata.data && !(dev->features & NETIF_F_SG))
1075 return -EINVAL;
1076 if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
1077 return -EINVAL;
1078 return dev->ethtool_ops->set_ufo(dev, edata.data);
1079}
1080
Herbert Xu37c31852006-06-22 03:07:29 -07001081static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
1082{
1083 struct ethtool_value edata = { ETHTOOL_GGSO };
1084
1085 edata.data = dev->features & NETIF_F_GSO;
1086 if (copy_to_user(useraddr, &edata, sizeof(edata)))
chavey97f8aef2010-04-07 21:54:42 -07001087 return -EFAULT;
Herbert Xu37c31852006-06-22 03:07:29 -07001088 return 0;
1089}
1090
1091static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
1092{
1093 struct ethtool_value edata;
1094
1095 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1096 return -EFAULT;
1097 if (edata.data)
1098 dev->features |= NETIF_F_GSO;
1099 else
1100 dev->features &= ~NETIF_F_GSO;
1101 return 0;
1102}
1103
Herbert Xub240a0e2008-12-15 23:44:31 -08001104static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
1105{
1106 struct ethtool_value edata = { ETHTOOL_GGRO };
1107
1108 edata.data = dev->features & NETIF_F_GRO;
1109 if (copy_to_user(useraddr, &edata, sizeof(edata)))
chavey97f8aef2010-04-07 21:54:42 -07001110 return -EFAULT;
Herbert Xub240a0e2008-12-15 23:44:31 -08001111 return 0;
1112}
1113
1114static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
1115{
1116 struct ethtool_value edata;
1117
1118 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1119 return -EFAULT;
1120
1121 if (edata.data) {
1122 if (!dev->ethtool_ops->get_rx_csum ||
1123 !dev->ethtool_ops->get_rx_csum(dev))
1124 return -EINVAL;
1125 dev->features |= NETIF_F_GRO;
1126 } else
1127 dev->features &= ~NETIF_F_GRO;
1128
1129 return 0;
1130}
1131
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1133{
1134 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001135 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001137 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001139 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001140 return -EOPNOTSUPP;
1141
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001142 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -07001143 if (test_len < 0)
1144 return test_len;
1145 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
1147 if (copy_from_user(&test, useraddr, sizeof(test)))
1148 return -EFAULT;
1149
Jeff Garzikff03d492007-08-15 16:01:08 -07001150 test.len = test_len;
1151 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 if (!data)
1153 return -ENOMEM;
1154
1155 ops->self_test(dev, &test, data);
1156
1157 ret = -EFAULT;
1158 if (copy_to_user(useraddr, &test, sizeof(test)))
1159 goto out;
1160 useraddr += sizeof(test);
1161 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1162 goto out;
1163 ret = 0;
1164
1165 out:
1166 kfree(data);
1167 return ret;
1168}
1169
1170static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1171{
1172 struct ethtool_gstrings gstrings;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001173 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 u8 *data;
1175 int ret;
1176
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001177 if (!ops->get_strings || !ops->get_sset_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 return -EOPNOTSUPP;
1179
1180 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1181 return -EFAULT;
1182
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001183 ret = ops->get_sset_count(dev, gstrings.string_set);
1184 if (ret < 0)
1185 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001186
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001187 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
1189 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1190 if (!data)
1191 return -ENOMEM;
1192
1193 ops->get_strings(dev, gstrings.string_set, data);
1194
1195 ret = -EFAULT;
1196 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1197 goto out;
1198 useraddr += sizeof(gstrings);
1199 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1200 goto out;
1201 ret = 0;
1202
1203 out:
1204 kfree(data);
1205 return ret;
1206}
1207
1208static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1209{
1210 struct ethtool_value id;
1211
1212 if (!dev->ethtool_ops->phys_id)
1213 return -EOPNOTSUPP;
1214
1215 if (copy_from_user(&id, useraddr, sizeof(id)))
1216 return -EFAULT;
1217
1218 return dev->ethtool_ops->phys_id(dev, id.data);
1219}
1220
1221static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1222{
1223 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001224 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001226 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001228 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001229 return -EOPNOTSUPP;
1230
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001231 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001232 if (n_stats < 0)
1233 return n_stats;
1234 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
1236 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1237 return -EFAULT;
1238
Jeff Garzikff03d492007-08-15 16:01:08 -07001239 stats.n_stats = n_stats;
1240 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 if (!data)
1242 return -ENOMEM;
1243
1244 ops->get_ethtool_stats(dev, &stats, data);
1245
1246 ret = -EFAULT;
1247 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1248 goto out;
1249 useraddr += sizeof(stats);
1250 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1251 goto out;
1252 ret = 0;
1253
1254 out:
1255 kfree(data);
1256 return ret;
1257}
1258
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001259static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001260{
1261 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001262
Matthew Wilcox313674a2007-07-31 14:00:29 -07001263 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001264 return -EFAULT;
1265
Matthew Wilcox313674a2007-07-31 14:00:29 -07001266 if (epaddr.size < dev->addr_len)
1267 return -ETOOSMALL;
1268 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001269
Jon Wetzela6f9a702005-08-20 17:15:54 -07001270 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001271 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001272 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001273 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1274 return -EFAULT;
1275 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001276}
1277
Jeff Garzik13c99b22007-08-15 16:01:56 -07001278static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1279 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001280{
Roland Dreier8e557422010-02-11 12:14:23 -08001281 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001282
Jeff Garzik13c99b22007-08-15 16:01:56 -07001283 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001284 return -EOPNOTSUPP;
1285
Jeff Garzik13c99b22007-08-15 16:01:56 -07001286 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001287
1288 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1289 return -EFAULT;
1290 return 0;
1291}
1292
Jeff Garzik13c99b22007-08-15 16:01:56 -07001293static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1294 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001295{
1296 struct ethtool_value edata;
1297
Jeff Garzik13c99b22007-08-15 16:01:56 -07001298 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001299 return -EOPNOTSUPP;
1300
1301 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1302 return -EFAULT;
1303
Jeff Garzik13c99b22007-08-15 16:01:56 -07001304 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001305 return 0;
1306}
1307
Jeff Garzik13c99b22007-08-15 16:01:56 -07001308static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1309 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001310{
1311 struct ethtool_value edata;
1312
Jeff Garzik13c99b22007-08-15 16:01:56 -07001313 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001314 return -EOPNOTSUPP;
1315
1316 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1317 return -EFAULT;
1318
Jeff Garzik13c99b22007-08-15 16:01:56 -07001319 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001320}
1321
chavey97f8aef2010-04-07 21:54:42 -07001322static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1323 char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001324{
1325 struct ethtool_flash efl;
1326
1327 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1328 return -EFAULT;
1329
1330 if (!dev->ethtool_ops->flash_device)
1331 return -EOPNOTSUPP;
1332
1333 return dev->ethtool_ops->flash_device(dev, &efl);
1334}
1335
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336/* The main entry point in this file. Called from net/core/dev.c */
1337
Eric W. Biederman881d9662007-09-17 11:56:21 -07001338int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001340 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 void __user *useraddr = ifr->ifr_data;
1342 u32 ethcmd;
1343 int rc;
Stephen Hemminger81e81572005-05-29 14:14:35 -07001344 unsigned long old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 if (!dev || !netif_device_present(dev))
1347 return -ENODEV;
1348
1349 if (!dev->ethtool_ops)
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001350 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
chavey97f8aef2010-04-07 21:54:42 -07001352 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 return -EFAULT;
1354
Stephen Hemminger75f31232006-09-28 15:13:37 -07001355 /* Allow some commands to be done by anyone */
chavey97f8aef2010-04-07 21:54:42 -07001356 switch (ethcmd) {
Stephen Hemminger75f31232006-09-28 15:13:37 -07001357 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001358 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001359 case ETHTOOL_GCOALESCE:
1360 case ETHTOOL_GRINGPARAM:
1361 case ETHTOOL_GPAUSEPARAM:
1362 case ETHTOOL_GRXCSUM:
1363 case ETHTOOL_GTXCSUM:
1364 case ETHTOOL_GSG:
1365 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001366 case ETHTOOL_GTSO:
1367 case ETHTOOL_GPERMADDR:
1368 case ETHTOOL_GUFO:
1369 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001370 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001371 case ETHTOOL_GFLAGS:
1372 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001373 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001374 case ETHTOOL_GRXRINGS:
1375 case ETHTOOL_GRXCLSRLCNT:
1376 case ETHTOOL_GRXCLSRULE:
1377 case ETHTOOL_GRXCLSRLALL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001378 break;
1379 default:
1380 if (!capable(CAP_NET_ADMIN))
1381 return -EPERM;
1382 }
1383
chavey97f8aef2010-04-07 21:54:42 -07001384 if (dev->ethtool_ops->begin) {
1385 rc = dev->ethtool_ops->begin(dev);
1386 if (rc < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 return rc;
chavey97f8aef2010-04-07 21:54:42 -07001388 }
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001389 old_features = dev->features;
1390
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 switch (ethcmd) {
1392 case ETHTOOL_GSET:
1393 rc = ethtool_get_settings(dev, useraddr);
1394 break;
1395 case ETHTOOL_SSET:
1396 rc = ethtool_set_settings(dev, useraddr);
1397 break;
1398 case ETHTOOL_GDRVINFO:
1399 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 break;
1401 case ETHTOOL_GREGS:
1402 rc = ethtool_get_regs(dev, useraddr);
1403 break;
1404 case ETHTOOL_GWOL:
1405 rc = ethtool_get_wol(dev, useraddr);
1406 break;
1407 case ETHTOOL_SWOL:
1408 rc = ethtool_set_wol(dev, useraddr);
1409 break;
1410 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001411 rc = ethtool_get_value(dev, useraddr, ethcmd,
1412 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 break;
1414 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001415 rc = ethtool_set_value_void(dev, useraddr,
1416 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 break;
1418 case ETHTOOL_NWAY_RST:
1419 rc = ethtool_nway_reset(dev);
1420 break;
1421 case ETHTOOL_GLINK:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001422 rc = ethtool_get_value(dev, useraddr, ethcmd,
1423 dev->ethtool_ops->get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 break;
1425 case ETHTOOL_GEEPROM:
1426 rc = ethtool_get_eeprom(dev, useraddr);
1427 break;
1428 case ETHTOOL_SEEPROM:
1429 rc = ethtool_set_eeprom(dev, useraddr);
1430 break;
1431 case ETHTOOL_GCOALESCE:
1432 rc = ethtool_get_coalesce(dev, useraddr);
1433 break;
1434 case ETHTOOL_SCOALESCE:
1435 rc = ethtool_set_coalesce(dev, useraddr);
1436 break;
1437 case ETHTOOL_GRINGPARAM:
1438 rc = ethtool_get_ringparam(dev, useraddr);
1439 break;
1440 case ETHTOOL_SRINGPARAM:
1441 rc = ethtool_set_ringparam(dev, useraddr);
1442 break;
1443 case ETHTOOL_GPAUSEPARAM:
1444 rc = ethtool_get_pauseparam(dev, useraddr);
1445 break;
1446 case ETHTOOL_SPAUSEPARAM:
1447 rc = ethtool_set_pauseparam(dev, useraddr);
1448 break;
1449 case ETHTOOL_GRXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001450 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001451 (dev->ethtool_ops->get_rx_csum ?
1452 dev->ethtool_ops->get_rx_csum :
1453 ethtool_op_get_rx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 break;
1455 case ETHTOOL_SRXCSUM:
Herbert Xub240a0e2008-12-15 23:44:31 -08001456 rc = ethtool_set_rx_csum(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 break;
1458 case ETHTOOL_GTXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001459 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001460 (dev->ethtool_ops->get_tx_csum ?
1461 dev->ethtool_ops->get_tx_csum :
1462 ethtool_op_get_tx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 break;
1464 case ETHTOOL_STXCSUM:
1465 rc = ethtool_set_tx_csum(dev, useraddr);
1466 break;
1467 case ETHTOOL_GSG:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001468 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001469 (dev->ethtool_ops->get_sg ?
1470 dev->ethtool_ops->get_sg :
1471 ethtool_op_get_sg));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 break;
1473 case ETHTOOL_SSG:
1474 rc = ethtool_set_sg(dev, useraddr);
1475 break;
1476 case ETHTOOL_GTSO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001477 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001478 (dev->ethtool_ops->get_tso ?
1479 dev->ethtool_ops->get_tso :
1480 ethtool_op_get_tso));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 break;
1482 case ETHTOOL_STSO:
1483 rc = ethtool_set_tso(dev, useraddr);
1484 break;
1485 case ETHTOOL_TEST:
1486 rc = ethtool_self_test(dev, useraddr);
1487 break;
1488 case ETHTOOL_GSTRINGS:
1489 rc = ethtool_get_strings(dev, useraddr);
1490 break;
1491 case ETHTOOL_PHYS_ID:
1492 rc = ethtool_phys_id(dev, useraddr);
1493 break;
1494 case ETHTOOL_GSTATS:
1495 rc = ethtool_get_stats(dev, useraddr);
1496 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001497 case ETHTOOL_GPERMADDR:
1498 rc = ethtool_get_perm_addr(dev, useraddr);
1499 break;
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001500 case ETHTOOL_GUFO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001501 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001502 (dev->ethtool_ops->get_ufo ?
1503 dev->ethtool_ops->get_ufo :
1504 ethtool_op_get_ufo));
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001505 break;
1506 case ETHTOOL_SUFO:
1507 rc = ethtool_set_ufo(dev, useraddr);
1508 break;
Herbert Xu37c31852006-06-22 03:07:29 -07001509 case ETHTOOL_GGSO:
1510 rc = ethtool_get_gso(dev, useraddr);
1511 break;
1512 case ETHTOOL_SGSO:
1513 rc = ethtool_set_gso(dev, useraddr);
1514 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001515 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001516 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001517 (dev->ethtool_ops->get_flags ?
1518 dev->ethtool_ops->get_flags :
1519 ethtool_op_get_flags));
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001520 break;
1521 case ETHTOOL_SFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001522 rc = ethtool_set_value(dev, useraddr,
1523 dev->ethtool_ops->set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001524 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001525 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001526 rc = ethtool_get_value(dev, useraddr, ethcmd,
1527 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001528 break;
1529 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001530 rc = ethtool_set_value(dev, useraddr,
1531 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001532 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001533 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001534 case ETHTOOL_GRXRINGS:
1535 case ETHTOOL_GRXCLSRLCNT:
1536 case ETHTOOL_GRXCLSRULE:
1537 case ETHTOOL_GRXCLSRLALL:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001538 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001539 break;
1540 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001541 case ETHTOOL_SRXCLSRLDEL:
1542 case ETHTOOL_SRXCLSRLINS:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001543 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001544 break;
Herbert Xub240a0e2008-12-15 23:44:31 -08001545 case ETHTOOL_GGRO:
1546 rc = ethtool_get_gro(dev, useraddr);
1547 break;
1548 case ETHTOOL_SGRO:
1549 rc = ethtool_set_gro(dev, useraddr);
1550 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001551 case ETHTOOL_FLASHDEV:
1552 rc = ethtool_flash_device(dev, useraddr);
1553 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001554 case ETHTOOL_RESET:
1555 rc = ethtool_reset(dev, useraddr);
1556 break;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001557 case ETHTOOL_SRXNTUPLE:
1558 rc = ethtool_set_rx_ntuple(dev, useraddr);
1559 break;
1560 case ETHTOOL_GRXNTUPLE:
1561 rc = ethtool_get_rx_ntuple(dev, useraddr);
1562 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001563 case ETHTOOL_GSSET_INFO:
1564 rc = ethtool_get_sset_info(dev, useraddr);
1565 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001567 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001569
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001570 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001572
1573 if (old_features != dev->features)
1574 netdev_features_change(dev);
1575
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}