Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * net/core/ethtool.c - Ethtool ioctl handler | |
3 | * Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx> | |
4 | * | |
5 | * This file is where we call all the ethtool_ops commands to get | |
61a44b9c | 6 | * the information ethtool needs. |
1da177e4 | 7 | * |
61a44b9c MW |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
1da177e4 LT |
12 | */ |
13 | ||
14 | #include <linux/module.h> | |
15 | #include <linux/types.h> | |
4fc268d2 | 16 | #include <linux/capability.h> |
1da177e4 LT |
17 | #include <linux/errno.h> |
18 | #include <linux/ethtool.h> | |
19 | #include <linux/netdevice.h> | |
d17792eb | 20 | #include <linux/bitops.h> |
97f8aefb | 21 | #include <linux/uaccess.h> |
5a0e3ad6 | 22 | #include <linux/slab.h> |
1da177e4 | 23 | |
4ec93edb | 24 | /* |
1da177e4 LT |
25 | * 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 | ||
30 | u32 ethtool_op_get_link(struct net_device *dev) | |
31 | { | |
32 | return netif_carrier_ok(dev) ? 1 : 0; | |
33 | } | |
97f8aefb | 34 | EXPORT_SYMBOL(ethtool_op_get_link); |
1da177e4 | 35 | |
1896e61f SS |
36 | u32 ethtool_op_get_rx_csum(struct net_device *dev) |
37 | { | |
38 | return (dev->features & NETIF_F_ALL_CSUM) != 0; | |
39 | } | |
8a729fce | 40 | EXPORT_SYMBOL(ethtool_op_get_rx_csum); |
1896e61f | 41 | |
1da177e4 LT |
42 | u32 ethtool_op_get_tx_csum(struct net_device *dev) |
43 | { | |
8648b305 | 44 | return (dev->features & NETIF_F_ALL_CSUM) != 0; |
1da177e4 | 45 | } |
8a729fce | 46 | EXPORT_SYMBOL(ethtool_op_get_tx_csum); |
1da177e4 LT |
47 | |
48 | int 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 | ||
69f6a0fa JM |
58 | int 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 | } | |
97f8aefb | 67 | EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum); |
6460d948 MC |
68 | |
69 | int 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 | } | |
97f8aefb | 78 | EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum); |
6460d948 | 79 | |
1da177e4 LT |
80 | u32 ethtool_op_get_sg(struct net_device *dev) |
81 | { | |
82 | return (dev->features & NETIF_F_SG) != 0; | |
83 | } | |
97f8aefb | 84 | EXPORT_SYMBOL(ethtool_op_get_sg); |
1da177e4 LT |
85 | |
86 | int 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 | } | |
97f8aefb | 95 | EXPORT_SYMBOL(ethtool_op_set_sg); |
1da177e4 LT |
96 | |
97 | u32 ethtool_op_get_tso(struct net_device *dev) | |
98 | { | |
99 | return (dev->features & NETIF_F_TSO) != 0; | |
100 | } | |
97f8aefb | 101 | EXPORT_SYMBOL(ethtool_op_get_tso); |
1da177e4 LT |
102 | |
103 | int 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 | } | |
97f8aefb | 112 | EXPORT_SYMBOL(ethtool_op_set_tso); |
1da177e4 | 113 | |
e89e9cf5 AR |
114 | u32 ethtool_op_get_ufo(struct net_device *dev) |
115 | { | |
116 | return (dev->features & NETIF_F_UFO) != 0; | |
117 | } | |
97f8aefb | 118 | EXPORT_SYMBOL(ethtool_op_get_ufo); |
e89e9cf5 AR |
119 | |
120 | int 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 | } | |
97f8aefb | 128 | EXPORT_SYMBOL(ethtool_op_set_ufo); |
e89e9cf5 | 129 | |
3ae7c0b2 JG |
130 | /* the following list of flags are the same as their associated |
131 | * NETIF_F_xxx values in include/linux/netdevice.h | |
132 | */ | |
133 | static const u32 flags_dup_features = | |
b00fabb4 | 134 | (ETH_FLAG_LRO | ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH); |
3ae7c0b2 JG |
135 | |
136 | u32 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 | } | |
97f8aefb | 145 | EXPORT_SYMBOL(ethtool_op_get_flags); |
3ae7c0b2 | 146 | |
1437ce39 | 147 | int ethtool_op_set_flags(struct net_device *dev, u32 data, u32 supported) |
3ae7c0b2 | 148 | { |
1437ce39 BH |
149 | if (data & ~supported) |
150 | return -EINVAL; | |
0d643e1f | 151 | |
1437ce39 BH |
152 | dev->features = ((dev->features & ~flags_dup_features) | |
153 | (data & flags_dup_features)); | |
3ae7c0b2 JG |
154 | return 0; |
155 | } | |
97f8aefb | 156 | EXPORT_SYMBOL(ethtool_op_set_flags); |
3ae7c0b2 | 157 | |
15682bc4 PWJ |
158 | void 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 | } | |
168 | EXPORT_SYMBOL(ethtool_ntuple_flush); | |
169 | ||
1da177e4 LT |
170 | /* Handlers for each ethtool command */ |
171 | ||
172 | static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) | |
173 | { | |
8e557421 | 174 | struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET }; |
1da177e4 LT |
175 | 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 | ||
189 | static 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 | ||
97f8aefb | 202 | static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, |
203 | void __user *useraddr) | |
1da177e4 LT |
204 | { |
205 | struct ethtool_drvinfo info; | |
76fd8593 | 206 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 LT |
207 | |
208 | if (!ops->get_drvinfo) | |
209 | return -EOPNOTSUPP; | |
210 | ||
211 | memset(&info, 0, sizeof(info)); | |
212 | info.cmd = ETHTOOL_GDRVINFO; | |
213 | ops->get_drvinfo(dev, &info); | |
214 | ||
723b2f57 JG |
215 | /* |
216 | * this method of obtaining string set info is deprecated; | |
d17792eb | 217 | * Use ETHTOOL_GSSET_INFO instead. |
723b2f57 | 218 | */ |
ff03d49f JG |
219 | 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; | |
339bf024 JG |
228 | rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS); |
229 | if (rc >= 0) | |
230 | info.n_priv_flags = rc; | |
ff03d49f | 231 | } |
1da177e4 LT |
232 | 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 | ||
f5c445ed | 242 | static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, |
97f8aefb | 243 | void __user *useraddr) |
723b2f57 JG |
244 | { |
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 */ | |
d17792eb | 263 | n_bits = hweight64(sset_mask); |
723b2f57 JG |
264 | |
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 | ||
297 | out: | |
298 | kfree(info_buf); | |
299 | return ret; | |
300 | } | |
301 | ||
97f8aefb | 302 | static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, |
303 | void __user *useraddr) | |
0853ad66 SB |
304 | { |
305 | struct ethtool_rxnfc cmd; | |
306 | ||
59089d8d | 307 | if (!dev->ethtool_ops->set_rxnfc) |
0853ad66 SB |
308 | return -EOPNOTSUPP; |
309 | ||
310 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) | |
311 | return -EFAULT; | |
312 | ||
59089d8d | 313 | return dev->ethtool_ops->set_rxnfc(dev, &cmd); |
0853ad66 SB |
314 | } |
315 | ||
97f8aefb | 316 | static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, |
317 | void __user *useraddr) | |
0853ad66 SB |
318 | { |
319 | struct ethtool_rxnfc info; | |
59089d8d SB |
320 | const struct ethtool_ops *ops = dev->ethtool_ops; |
321 | int ret; | |
322 | void *rule_buf = NULL; | |
0853ad66 | 323 | |
59089d8d | 324 | if (!ops->get_rxnfc) |
0853ad66 SB |
325 | return -EOPNOTSUPP; |
326 | ||
327 | if (copy_from_user(&info, useraddr, sizeof(info))) | |
328 | return -EFAULT; | |
329 | ||
59089d8d SB |
330 | 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 | } | |
0853ad66 | 338 | |
59089d8d SB |
339 | ret = ops->get_rxnfc(dev, &info, rule_buf); |
340 | if (ret < 0) | |
341 | goto err_out; | |
342 | ||
343 | ret = -EFAULT; | |
0853ad66 | 344 | if (copy_to_user(useraddr, &info, sizeof(info))) |
59089d8d SB |
345 | 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 | ||
355 | err_out: | |
c9caceca | 356 | kfree(rule_buf); |
59089d8d SB |
357 | |
358 | return ret; | |
0853ad66 SB |
359 | } |
360 | ||
e8589118 | 361 | static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list, |
97f8aefb | 362 | struct ethtool_rx_ntuple_flow_spec *spec, |
363 | struct ethtool_rx_ntuple_flow_spec_container *fsc) | |
15682bc4 | 364 | { |
15682bc4 PWJ |
365 | |
366 | /* don't add filters forever */ | |
e8589118 PW |
367 | if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) { |
368 | /* free the container */ | |
369 | kfree(fsc); | |
370 | return; | |
371 | } | |
15682bc4 PWJ |
372 | |
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++; | |
15682bc4 PWJ |
387 | } |
388 | ||
97f8aefb | 389 | static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev, |
390 | void __user *useraddr) | |
15682bc4 PWJ |
391 | { |
392 | struct ethtool_rx_ntuple cmd; | |
393 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
e8589118 | 394 | struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL; |
15682bc4 PWJ |
395 | int ret; |
396 | ||
15682bc4 PWJ |
397 | if (!(dev->features & NETIF_F_NTUPLE)) |
398 | return -EINVAL; | |
399 | ||
400 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) | |
401 | return -EFAULT; | |
402 | ||
15682bc4 PWJ |
403 | /* |
404 | * Cache filter in dev struct for GET operation only if | |
405 | * the underlying driver doesn't have its own GET operation, and | |
e8589118 PW |
406 | * only if the filter was added successfully. First make sure we |
407 | * can allocate the filter, then continue if successful. | |
15682bc4 | 408 | */ |
e8589118 PW |
409 | if (!ops->get_rx_ntuple) { |
410 | fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC); | |
411 | if (!fsc) | |
15682bc4 | 412 | return -ENOMEM; |
e8589118 PW |
413 | } |
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); | |
15682bc4 PWJ |
423 | |
424 | return ret; | |
425 | } | |
426 | ||
427 | static 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; | |
ccbd6a5a | 507 | } |
15682bc4 PWJ |
508 | |
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", | |
97f8aefb | 515 | fsc->fs.h_u.tcp_ip4_spec.ip4src); |
15682bc4 PWJ |
516 | p += ETH_GSTRING_LEN; |
517 | num_strings++; | |
518 | sprintf(p, "\tSrc IP mask: 0x%x\n", | |
97f8aefb | 519 | fsc->fs.m_u.tcp_ip4_spec.ip4src); |
15682bc4 PWJ |
520 | p += ETH_GSTRING_LEN; |
521 | num_strings++; | |
522 | sprintf(p, "\tDest IP addr: 0x%x\n", | |
97f8aefb | 523 | fsc->fs.h_u.tcp_ip4_spec.ip4dst); |
15682bc4 PWJ |
524 | p += ETH_GSTRING_LEN; |
525 | num_strings++; | |
526 | sprintf(p, "\tDest IP mask: 0x%x\n", | |
97f8aefb | 527 | fsc->fs.m_u.tcp_ip4_spec.ip4dst); |
15682bc4 PWJ |
528 | p += ETH_GSTRING_LEN; |
529 | num_strings++; | |
530 | sprintf(p, "\tSrc Port: %d, mask: 0x%x\n", | |
97f8aefb | 531 | fsc->fs.h_u.tcp_ip4_spec.psrc, |
532 | fsc->fs.m_u.tcp_ip4_spec.psrc); | |
15682bc4 PWJ |
533 | p += ETH_GSTRING_LEN; |
534 | num_strings++; | |
535 | sprintf(p, "\tDest Port: %d, mask: 0x%x\n", | |
97f8aefb | 536 | fsc->fs.h_u.tcp_ip4_spec.pdst, |
537 | fsc->fs.m_u.tcp_ip4_spec.pdst); | |
15682bc4 PWJ |
538 | p += ETH_GSTRING_LEN; |
539 | num_strings++; | |
540 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", | |
97f8aefb | 541 | fsc->fs.h_u.tcp_ip4_spec.tos, |
542 | fsc->fs.m_u.tcp_ip4_spec.tos); | |
15682bc4 PWJ |
543 | 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", | |
97f8aefb | 549 | fsc->fs.h_u.ah_ip4_spec.ip4src); |
15682bc4 PWJ |
550 | p += ETH_GSTRING_LEN; |
551 | num_strings++; | |
552 | sprintf(p, "\tSrc IP mask: 0x%x\n", | |
97f8aefb | 553 | fsc->fs.m_u.ah_ip4_spec.ip4src); |
15682bc4 PWJ |
554 | p += ETH_GSTRING_LEN; |
555 | num_strings++; | |
556 | sprintf(p, "\tDest IP addr: 0x%x\n", | |
97f8aefb | 557 | fsc->fs.h_u.ah_ip4_spec.ip4dst); |
15682bc4 PWJ |
558 | p += ETH_GSTRING_LEN; |
559 | num_strings++; | |
560 | sprintf(p, "\tDest IP mask: 0x%x\n", | |
97f8aefb | 561 | fsc->fs.m_u.ah_ip4_spec.ip4dst); |
15682bc4 PWJ |
562 | p += ETH_GSTRING_LEN; |
563 | num_strings++; | |
564 | sprintf(p, "\tSPI: %d, mask: 0x%x\n", | |
97f8aefb | 565 | fsc->fs.h_u.ah_ip4_spec.spi, |
566 | fsc->fs.m_u.ah_ip4_spec.spi); | |
15682bc4 PWJ |
567 | p += ETH_GSTRING_LEN; |
568 | num_strings++; | |
569 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", | |
97f8aefb | 570 | fsc->fs.h_u.ah_ip4_spec.tos, |
571 | fsc->fs.m_u.ah_ip4_spec.tos); | |
15682bc4 PWJ |
572 | p += ETH_GSTRING_LEN; |
573 | num_strings++; | |
574 | break; | |
575 | case IP_USER_FLOW: | |
576 | sprintf(p, "\tSrc IP addr: 0x%x\n", | |
97f8aefb | 577 | fsc->fs.h_u.raw_ip4_spec.ip4src); |
15682bc4 PWJ |
578 | p += ETH_GSTRING_LEN; |
579 | num_strings++; | |
580 | sprintf(p, "\tSrc IP mask: 0x%x\n", | |
97f8aefb | 581 | fsc->fs.m_u.raw_ip4_spec.ip4src); |
15682bc4 PWJ |
582 | p += ETH_GSTRING_LEN; |
583 | num_strings++; | |
584 | sprintf(p, "\tDest IP addr: 0x%x\n", | |
97f8aefb | 585 | fsc->fs.h_u.raw_ip4_spec.ip4dst); |
15682bc4 PWJ |
586 | p += ETH_GSTRING_LEN; |
587 | num_strings++; | |
588 | sprintf(p, "\tDest IP mask: 0x%x\n", | |
97f8aefb | 589 | fsc->fs.m_u.raw_ip4_spec.ip4dst); |
15682bc4 PWJ |
590 | p += ETH_GSTRING_LEN; |
591 | num_strings++; | |
592 | break; | |
593 | case IPV4_FLOW: | |
594 | sprintf(p, "\tSrc IP addr: 0x%x\n", | |
97f8aefb | 595 | fsc->fs.h_u.usr_ip4_spec.ip4src); |
15682bc4 PWJ |
596 | p += ETH_GSTRING_LEN; |
597 | num_strings++; | |
598 | sprintf(p, "\tSrc IP mask: 0x%x\n", | |
97f8aefb | 599 | fsc->fs.m_u.usr_ip4_spec.ip4src); |
15682bc4 PWJ |
600 | p += ETH_GSTRING_LEN; |
601 | num_strings++; | |
602 | sprintf(p, "\tDest IP addr: 0x%x\n", | |
97f8aefb | 603 | fsc->fs.h_u.usr_ip4_spec.ip4dst); |
15682bc4 PWJ |
604 | p += ETH_GSTRING_LEN; |
605 | num_strings++; | |
606 | sprintf(p, "\tDest IP mask: 0x%x\n", | |
97f8aefb | 607 | fsc->fs.m_u.usr_ip4_spec.ip4dst); |
15682bc4 PWJ |
608 | p += ETH_GSTRING_LEN; |
609 | num_strings++; | |
610 | sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n", | |
97f8aefb | 611 | fsc->fs.h_u.usr_ip4_spec.l4_4_bytes, |
612 | fsc->fs.m_u.usr_ip4_spec.l4_4_bytes); | |
15682bc4 PWJ |
613 | p += ETH_GSTRING_LEN; |
614 | num_strings++; | |
615 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", | |
97f8aefb | 616 | fsc->fs.h_u.usr_ip4_spec.tos, |
617 | fsc->fs.m_u.usr_ip4_spec.tos); | |
15682bc4 PWJ |
618 | p += ETH_GSTRING_LEN; |
619 | num_strings++; | |
620 | sprintf(p, "\tIP Version: %d, mask: 0x%x\n", | |
97f8aefb | 621 | fsc->fs.h_u.usr_ip4_spec.ip_ver, |
622 | fsc->fs.m_u.usr_ip4_spec.ip_ver); | |
15682bc4 PWJ |
623 | p += ETH_GSTRING_LEN; |
624 | num_strings++; | |
625 | sprintf(p, "\tProtocol: %d, mask: 0x%x\n", | |
97f8aefb | 626 | fsc->fs.h_u.usr_ip4_spec.proto, |
627 | fsc->fs.m_u.usr_ip4_spec.proto); | |
15682bc4 PWJ |
628 | p += ETH_GSTRING_LEN; |
629 | num_strings++; | |
630 | break; | |
ccbd6a5a | 631 | } |
15682bc4 | 632 | sprintf(p, "\tVLAN: %d, mask: 0x%x\n", |
97f8aefb | 633 | fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask); |
15682bc4 PWJ |
634 | 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", | |
97f8aefb | 646 | fsc->fs.action); |
15682bc4 PWJ |
647 | p += ETH_GSTRING_LEN; |
648 | num_strings++; | |
649 | unknown_filter: | |
650 | i++; | |
651 | } | |
652 | copy: | |
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 | ||
663 | out: | |
664 | kfree(data); | |
665 | return ret; | |
666 | } | |
667 | ||
1da177e4 LT |
668 | static int ethtool_get_regs(struct net_device *dev, char __user *useraddr) |
669 | { | |
670 | struct ethtool_regs regs; | |
76fd8593 | 671 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 LT |
672 | 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(®s, 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, ®s, regbuf); | |
690 | ||
691 | ret = -EFAULT; | |
692 | if (copy_to_user(useraddr, ®s, 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 | ||
d73d3a8c BH |
704 | static 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 | ||
1da177e4 LT |
724 | static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) |
725 | { | |
8e557421 | 726 | struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; |
1da177e4 LT |
727 | |
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 | ||
738 | static 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 | ||
1da177e4 LT |
751 | static 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 | ||
1da177e4 LT |
759 | static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr) |
760 | { | |
761 | struct ethtool_eeprom eeprom; | |
76fd8593 | 762 | const struct ethtool_ops *ops = dev->ethtool_ops; |
b131dd5d MSB |
763 | void __user *userbuf = useraddr + sizeof(eeprom); |
764 | u32 bytes_remaining; | |
1da177e4 | 765 | u8 *data; |
b131dd5d | 766 | int ret = 0; |
1da177e4 LT |
767 | |
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 | ||
b131dd5d | 782 | data = kmalloc(PAGE_SIZE, GFP_USER); |
1da177e4 LT |
783 | if (!data) |
784 | return -ENOMEM; | |
785 | ||
b131dd5d MSB |
786 | bytes_remaining = eeprom.len; |
787 | while (bytes_remaining > 0) { | |
788 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); | |
789 | ||
790 | 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 | } | |
1da177e4 | 801 | |
c5835df9 MSB |
802 | eeprom.len = userbuf - (useraddr + sizeof(eeprom)); |
803 | eeprom.offset -= eeprom.len; | |
804 | if (copy_to_user(useraddr, &eeprom, sizeof(eeprom))) | |
805 | ret = -EFAULT; | |
806 | ||
1da177e4 LT |
807 | kfree(data); |
808 | return ret; | |
809 | } | |
810 | ||
811 | static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr) | |
812 | { | |
813 | struct ethtool_eeprom eeprom; | |
76fd8593 | 814 | const struct ethtool_ops *ops = dev->ethtool_ops; |
b131dd5d MSB |
815 | void __user *userbuf = useraddr + sizeof(eeprom); |
816 | u32 bytes_remaining; | |
1da177e4 | 817 | u8 *data; |
b131dd5d | 818 | int ret = 0; |
1da177e4 LT |
819 | |
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 | ||
b131dd5d | 834 | data = kmalloc(PAGE_SIZE, GFP_USER); |
1da177e4 LT |
835 | if (!data) |
836 | return -ENOMEM; | |
837 | ||
b131dd5d MSB |
838 | bytes_remaining = eeprom.len; |
839 | while (bytes_remaining > 0) { | |
840 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); | |
841 | ||
842 | 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 | } | |
1da177e4 | 853 | |
1da177e4 LT |
854 | kfree(data); |
855 | return ret; | |
856 | } | |
857 | ||
97f8aefb | 858 | static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, |
859 | void __user *useraddr) | |
1da177e4 | 860 | { |
8e557421 | 861 | struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; |
1da177e4 LT |
862 | |
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 | ||
97f8aefb | 873 | static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, |
874 | void __user *useraddr) | |
1da177e4 LT |
875 | { |
876 | struct ethtool_coalesce coalesce; | |
877 | ||
fa04ae5c | 878 | if (!dev->ethtool_ops->set_coalesce) |
1da177e4 LT |
879 | 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 | ||
887 | static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr) | |
888 | { | |
8e557421 | 889 | struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM }; |
1da177e4 LT |
890 | |
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 | ||
901 | static 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 | ||
914 | static 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 | ||
928 | static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr) | |
929 | { | |
930 | struct ethtool_pauseparam pauseparam; | |
931 | ||
e1b90c41 | 932 | if (!dev->ethtool_ops->set_pauseparam) |
1da177e4 LT |
933 | 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 | ||
1da177e4 LT |
941 | static 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 | ||
e89e9cf5 AR |
951 | if (!data && dev->ethtool_ops->set_ufo) { |
952 | err = dev->ethtool_ops->set_ufo(dev, 0); | |
953 | if (err) | |
954 | return err; | |
955 | } | |
1da177e4 LT |
956 | return dev->ethtool_ops->set_sg(dev, data); |
957 | } | |
958 | ||
959 | static 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 | } | |
97f8aefb | 978 | EXPORT_SYMBOL(ethtool_op_set_tx_csum); |
1da177e4 | 979 | |
b240a0e5 HX |
980 | static 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 | ||
1da177e4 LT |
996 | static 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 | ||
4ec93edb | 1006 | if (edata.data && |
8648b305 | 1007 | !(dev->features & NETIF_F_ALL_CSUM)) |
1da177e4 LT |
1008 | return -EINVAL; |
1009 | ||
1010 | return __ethtool_set_sg(dev, edata.data); | |
1011 | } | |
1012 | ||
1da177e4 LT |
1013 | static 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 | ||
e89e9cf5 AR |
1029 | static 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 | ||
37c3185a HX |
1044 | static 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))) | |
97f8aefb | 1050 | return -EFAULT; |
37c3185a HX |
1051 | return 0; |
1052 | } | |
1053 | ||
1054 | static 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 | ||
b240a0e5 HX |
1067 | static 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))) | |
97f8aefb | 1073 | return -EFAULT; |
b240a0e5 HX |
1074 | return 0; |
1075 | } | |
1076 | ||
1077 | static 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 | ||
1da177e4 LT |
1095 | static int ethtool_self_test(struct net_device *dev, char __user *useraddr) |
1096 | { | |
1097 | struct ethtool_test test; | |
76fd8593 | 1098 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 | 1099 | u64 *data; |
ff03d49f | 1100 | int ret, test_len; |
1da177e4 | 1101 | |
a9828ec6 | 1102 | if (!ops->self_test || !ops->get_sset_count) |
1da177e4 LT |
1103 | return -EOPNOTSUPP; |
1104 | ||
a9828ec6 | 1105 | test_len = ops->get_sset_count(dev, ETH_SS_TEST); |
ff03d49f JG |
1106 | if (test_len < 0) |
1107 | return test_len; | |
1108 | WARN_ON(test_len == 0); | |
1109 | ||
1da177e4 LT |
1110 | if (copy_from_user(&test, useraddr, sizeof(test))) |
1111 | return -EFAULT; | |
1112 | ||
ff03d49f JG |
1113 | test.len = test_len; |
1114 | data = kmalloc(test_len * sizeof(u64), GFP_USER); | |
1da177e4 LT |
1115 | 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 | ||
1133 | static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) | |
1134 | { | |
1135 | struct ethtool_gstrings gstrings; | |
76fd8593 | 1136 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 LT |
1137 | u8 *data; |
1138 | int ret; | |
1139 | ||
a9828ec6 | 1140 | if (!ops->get_strings || !ops->get_sset_count) |
1da177e4 LT |
1141 | return -EOPNOTSUPP; |
1142 | ||
1143 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) | |
1144 | return -EFAULT; | |
1145 | ||
a9828ec6 BH |
1146 | ret = ops->get_sset_count(dev, gstrings.string_set); |
1147 | if (ret < 0) | |
1148 | return ret; | |
1149 | ||
1150 | gstrings.len = ret; | |
1da177e4 LT |
1151 | |
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 | ||
1171 | static 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 | ||
1184 | static int ethtool_get_stats(struct net_device *dev, void __user *useraddr) | |
1185 | { | |
1186 | struct ethtool_stats stats; | |
76fd8593 | 1187 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 | 1188 | u64 *data; |
ff03d49f | 1189 | int ret, n_stats; |
1da177e4 | 1190 | |
a9828ec6 | 1191 | if (!ops->get_ethtool_stats || !ops->get_sset_count) |
1da177e4 LT |
1192 | return -EOPNOTSUPP; |
1193 | ||
a9828ec6 | 1194 | n_stats = ops->get_sset_count(dev, ETH_SS_STATS); |
ff03d49f JG |
1195 | if (n_stats < 0) |
1196 | return n_stats; | |
1197 | WARN_ON(n_stats == 0); | |
1198 | ||
1da177e4 LT |
1199 | if (copy_from_user(&stats, useraddr, sizeof(stats))) |
1200 | return -EFAULT; | |
1201 | ||
ff03d49f JG |
1202 | stats.n_stats = n_stats; |
1203 | data = kmalloc(n_stats * sizeof(u64), GFP_USER); | |
1da177e4 LT |
1204 | 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 | ||
0bf0519d | 1222 | static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr) |
a6f9a705 JW |
1223 | { |
1224 | struct ethtool_perm_addr epaddr; | |
a6f9a705 | 1225 | |
313674af | 1226 | if (copy_from_user(&epaddr, useraddr, sizeof(epaddr))) |
a6f9a705 JW |
1227 | return -EFAULT; |
1228 | ||
313674af MW |
1229 | if (epaddr.size < dev->addr_len) |
1230 | return -ETOOSMALL; | |
1231 | epaddr.size = dev->addr_len; | |
a6f9a705 | 1232 | |
a6f9a705 | 1233 | if (copy_to_user(useraddr, &epaddr, sizeof(epaddr))) |
313674af | 1234 | return -EFAULT; |
a6f9a705 | 1235 | useraddr += sizeof(epaddr); |
313674af MW |
1236 | if (copy_to_user(useraddr, dev->perm_addr, epaddr.size)) |
1237 | return -EFAULT; | |
1238 | return 0; | |
a6f9a705 JW |
1239 | } |
1240 | ||
13c99b24 JG |
1241 | static int ethtool_get_value(struct net_device *dev, char __user *useraddr, |
1242 | u32 cmd, u32 (*actor)(struct net_device *)) | |
3ae7c0b2 | 1243 | { |
8e557421 | 1244 | struct ethtool_value edata = { .cmd = cmd }; |
3ae7c0b2 | 1245 | |
13c99b24 | 1246 | if (!actor) |
3ae7c0b2 JG |
1247 | return -EOPNOTSUPP; |
1248 | ||
13c99b24 | 1249 | edata.data = actor(dev); |
3ae7c0b2 JG |
1250 | |
1251 | if (copy_to_user(useraddr, &edata, sizeof(edata))) | |
1252 | return -EFAULT; | |
1253 | return 0; | |
1254 | } | |
1255 | ||
13c99b24 JG |
1256 | static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr, |
1257 | void (*actor)(struct net_device *, u32)) | |
3ae7c0b2 JG |
1258 | { |
1259 | struct ethtool_value edata; | |
1260 | ||
13c99b24 | 1261 | if (!actor) |
3ae7c0b2 JG |
1262 | return -EOPNOTSUPP; |
1263 | ||
1264 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1265 | return -EFAULT; | |
1266 | ||
13c99b24 | 1267 | actor(dev, edata.data); |
339bf024 JG |
1268 | return 0; |
1269 | } | |
1270 | ||
13c99b24 JG |
1271 | static int ethtool_set_value(struct net_device *dev, char __user *useraddr, |
1272 | int (*actor)(struct net_device *, u32)) | |
339bf024 JG |
1273 | { |
1274 | struct ethtool_value edata; | |
1275 | ||
13c99b24 | 1276 | if (!actor) |
339bf024 JG |
1277 | return -EOPNOTSUPP; |
1278 | ||
1279 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1280 | return -EFAULT; | |
1281 | ||
13c99b24 | 1282 | return actor(dev, edata.data); |
339bf024 JG |
1283 | } |
1284 | ||
97f8aefb | 1285 | static noinline_for_stack int ethtool_flash_device(struct net_device *dev, |
1286 | char __user *useraddr) | |
05c6a8d7 AK |
1287 | { |
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 | ||
1da177e4 LT |
1299 | /* The main entry point in this file. Called from net/core/dev.c */ |
1300 | ||
881d966b | 1301 | int dev_ethtool(struct net *net, struct ifreq *ifr) |
1da177e4 | 1302 | { |
881d966b | 1303 | struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); |
1da177e4 LT |
1304 | void __user *useraddr = ifr->ifr_data; |
1305 | u32 ethcmd; | |
1306 | int rc; | |
81e81575 | 1307 | unsigned long old_features; |
1da177e4 | 1308 | |
1da177e4 LT |
1309 | if (!dev || !netif_device_present(dev)) |
1310 | return -ENODEV; | |
1311 | ||
1312 | if (!dev->ethtool_ops) | |
61a44b9c | 1313 | return -EOPNOTSUPP; |
1da177e4 | 1314 | |
97f8aefb | 1315 | if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) |
1da177e4 LT |
1316 | return -EFAULT; |
1317 | ||
75f3123c | 1318 | /* Allow some commands to be done by anyone */ |
97f8aefb | 1319 | switch (ethcmd) { |
75f3123c | 1320 | case ETHTOOL_GDRVINFO: |
75f3123c | 1321 | case ETHTOOL_GMSGLVL: |
75f3123c SH |
1322 | 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: | |
75f3123c SH |
1329 | case ETHTOOL_GTSO: |
1330 | case ETHTOOL_GPERMADDR: | |
1331 | case ETHTOOL_GUFO: | |
1332 | case ETHTOOL_GGSO: | |
1cab819b | 1333 | case ETHTOOL_GGRO: |
339bf024 JG |
1334 | case ETHTOOL_GFLAGS: |
1335 | case ETHTOOL_GPFLAGS: | |
0853ad66 | 1336 | case ETHTOOL_GRXFH: |
59089d8d SB |
1337 | case ETHTOOL_GRXRINGS: |
1338 | case ETHTOOL_GRXCLSRLCNT: | |
1339 | case ETHTOOL_GRXCLSRULE: | |
1340 | case ETHTOOL_GRXCLSRLALL: | |
75f3123c SH |
1341 | break; |
1342 | default: | |
1343 | if (!capable(CAP_NET_ADMIN)) | |
1344 | return -EPERM; | |
1345 | } | |
1346 | ||
97f8aefb | 1347 | if (dev->ethtool_ops->begin) { |
1348 | rc = dev->ethtool_ops->begin(dev); | |
1349 | if (rc < 0) | |
1da177e4 | 1350 | return rc; |
97f8aefb | 1351 | } |
d8a33ac4 SH |
1352 | old_features = dev->features; |
1353 | ||
1da177e4 LT |
1354 | 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); | |
1da177e4 LT |
1363 | 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: | |
13c99b24 JG |
1374 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1375 | dev->ethtool_ops->get_msglevel); | |
1da177e4 LT |
1376 | break; |
1377 | case ETHTOOL_SMSGLVL: | |
13c99b24 JG |
1378 | rc = ethtool_set_value_void(dev, useraddr, |
1379 | dev->ethtool_ops->set_msglevel); | |
1da177e4 LT |
1380 | break; |
1381 | case ETHTOOL_NWAY_RST: | |
1382 | rc = ethtool_nway_reset(dev); | |
1383 | break; | |
1384 | case ETHTOOL_GLINK: | |
13c99b24 JG |
1385 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1386 | dev->ethtool_ops->get_link); | |
1da177e4 LT |
1387 | 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: | |
13c99b24 | 1413 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1896e61f SS |
1414 | (dev->ethtool_ops->get_rx_csum ? |
1415 | dev->ethtool_ops->get_rx_csum : | |
1416 | ethtool_op_get_rx_csum)); | |
1da177e4 LT |
1417 | break; |
1418 | case ETHTOOL_SRXCSUM: | |
b240a0e5 | 1419 | rc = ethtool_set_rx_csum(dev, useraddr); |
1da177e4 LT |
1420 | break; |
1421 | case ETHTOOL_GTXCSUM: | |
13c99b24 | 1422 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
88d3aafd JG |
1423 | (dev->ethtool_ops->get_tx_csum ? |
1424 | dev->ethtool_ops->get_tx_csum : | |
1425 | ethtool_op_get_tx_csum)); | |
1da177e4 LT |
1426 | break; |
1427 | case ETHTOOL_STXCSUM: | |
1428 | rc = ethtool_set_tx_csum(dev, useraddr); | |
1429 | break; | |
1430 | case ETHTOOL_GSG: | |
13c99b24 | 1431 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
88d3aafd JG |
1432 | (dev->ethtool_ops->get_sg ? |
1433 | dev->ethtool_ops->get_sg : | |
1434 | ethtool_op_get_sg)); | |
1da177e4 LT |
1435 | break; |
1436 | case ETHTOOL_SSG: | |
1437 | rc = ethtool_set_sg(dev, useraddr); | |
1438 | break; | |
1439 | case ETHTOOL_GTSO: | |
13c99b24 | 1440 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
88d3aafd JG |
1441 | (dev->ethtool_ops->get_tso ? |
1442 | dev->ethtool_ops->get_tso : | |
1443 | ethtool_op_get_tso)); | |
1da177e4 LT |
1444 | 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; | |
a6f9a705 JW |
1460 | case ETHTOOL_GPERMADDR: |
1461 | rc = ethtool_get_perm_addr(dev, useraddr); | |
1462 | break; | |
e89e9cf5 | 1463 | case ETHTOOL_GUFO: |
13c99b24 | 1464 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
88d3aafd JG |
1465 | (dev->ethtool_ops->get_ufo ? |
1466 | dev->ethtool_ops->get_ufo : | |
1467 | ethtool_op_get_ufo)); | |
e89e9cf5 AR |
1468 | break; |
1469 | case ETHTOOL_SUFO: | |
1470 | rc = ethtool_set_ufo(dev, useraddr); | |
1471 | break; | |
37c3185a HX |
1472 | 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; | |
3ae7c0b2 | 1478 | case ETHTOOL_GFLAGS: |
13c99b24 | 1479 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1896e61f SS |
1480 | (dev->ethtool_ops->get_flags ? |
1481 | dev->ethtool_ops->get_flags : | |
1482 | ethtool_op_get_flags)); | |
3ae7c0b2 JG |
1483 | break; |
1484 | case ETHTOOL_SFLAGS: | |
13c99b24 JG |
1485 | rc = ethtool_set_value(dev, useraddr, |
1486 | dev->ethtool_ops->set_flags); | |
3ae7c0b2 | 1487 | break; |
339bf024 | 1488 | case ETHTOOL_GPFLAGS: |
13c99b24 JG |
1489 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1490 | dev->ethtool_ops->get_priv_flags); | |
339bf024 JG |
1491 | break; |
1492 | case ETHTOOL_SPFLAGS: | |
13c99b24 JG |
1493 | rc = ethtool_set_value(dev, useraddr, |
1494 | dev->ethtool_ops->set_priv_flags); | |
339bf024 | 1495 | break; |
0853ad66 | 1496 | case ETHTOOL_GRXFH: |
59089d8d SB |
1497 | case ETHTOOL_GRXRINGS: |
1498 | case ETHTOOL_GRXCLSRLCNT: | |
1499 | case ETHTOOL_GRXCLSRULE: | |
1500 | case ETHTOOL_GRXCLSRLALL: | |
1501 | rc = ethtool_get_rxnfc(dev, useraddr); | |
0853ad66 SB |
1502 | break; |
1503 | case ETHTOOL_SRXFH: | |
59089d8d SB |
1504 | case ETHTOOL_SRXCLSRLDEL: |
1505 | case ETHTOOL_SRXCLSRLINS: | |
1506 | rc = ethtool_set_rxnfc(dev, useraddr); | |
0853ad66 | 1507 | break; |
b240a0e5 HX |
1508 | 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; | |
05c6a8d7 AK |
1514 | case ETHTOOL_FLASHDEV: |
1515 | rc = ethtool_flash_device(dev, useraddr); | |
1516 | break; | |
d73d3a8c BH |
1517 | case ETHTOOL_RESET: |
1518 | rc = ethtool_reset(dev, useraddr); | |
1519 | break; | |
15682bc4 PWJ |
1520 | 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; | |
723b2f57 JG |
1526 | case ETHTOOL_GSSET_INFO: |
1527 | rc = ethtool_get_sset_info(dev, useraddr); | |
1528 | break; | |
1da177e4 | 1529 | default: |
61a44b9c | 1530 | rc = -EOPNOTSUPP; |
1da177e4 | 1531 | } |
4ec93edb | 1532 | |
e71a4783 | 1533 | if (dev->ethtool_ops->complete) |
1da177e4 | 1534 | dev->ethtool_ops->complete(dev); |
d8a33ac4 SH |
1535 | |
1536 | if (old_features != dev->features) | |
1537 | netdev_features_change(dev); | |
1538 | ||
1da177e4 | 1539 | return rc; |
1da177e4 | 1540 | } |