]>
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, |
bf988435 | 303 | u32 cmd, void __user *useraddr) |
0853ad66 | 304 | { |
bf988435 BH |
305 | struct ethtool_rxnfc info; |
306 | size_t info_size = sizeof(info); | |
0853ad66 | 307 | |
59089d8d | 308 | if (!dev->ethtool_ops->set_rxnfc) |
0853ad66 SB |
309 | return -EOPNOTSUPP; |
310 | ||
bf988435 BH |
311 | /* struct ethtool_rxnfc was originally defined for |
312 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data | |
313 | * members. User-space might still be using that | |
314 | * definition. */ | |
315 | if (cmd == ETHTOOL_SRXFH) | |
316 | info_size = (offsetof(struct ethtool_rxnfc, data) + | |
317 | sizeof(info.data)); | |
318 | ||
319 | if (copy_from_user(&info, useraddr, info_size)) | |
0853ad66 SB |
320 | return -EFAULT; |
321 | ||
bf988435 | 322 | return dev->ethtool_ops->set_rxnfc(dev, &info); |
0853ad66 SB |
323 | } |
324 | ||
97f8aefb | 325 | static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, |
bf988435 | 326 | u32 cmd, void __user *useraddr) |
0853ad66 SB |
327 | { |
328 | struct ethtool_rxnfc info; | |
bf988435 | 329 | size_t info_size = sizeof(info); |
59089d8d SB |
330 | const struct ethtool_ops *ops = dev->ethtool_ops; |
331 | int ret; | |
332 | void *rule_buf = NULL; | |
0853ad66 | 333 | |
59089d8d | 334 | if (!ops->get_rxnfc) |
0853ad66 SB |
335 | return -EOPNOTSUPP; |
336 | ||
bf988435 BH |
337 | /* struct ethtool_rxnfc was originally defined for |
338 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data | |
339 | * members. User-space might still be using that | |
340 | * definition. */ | |
341 | if (cmd == ETHTOOL_GRXFH) | |
342 | info_size = (offsetof(struct ethtool_rxnfc, data) + | |
343 | sizeof(info.data)); | |
344 | ||
345 | if (copy_from_user(&info, useraddr, info_size)) | |
0853ad66 SB |
346 | return -EFAULT; |
347 | ||
59089d8d SB |
348 | if (info.cmd == ETHTOOL_GRXCLSRLALL) { |
349 | if (info.rule_cnt > 0) { | |
db048b69 BH |
350 | if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32)) |
351 | rule_buf = kmalloc(info.rule_cnt * sizeof(u32), | |
352 | GFP_USER); | |
59089d8d SB |
353 | if (!rule_buf) |
354 | return -ENOMEM; | |
355 | } | |
356 | } | |
0853ad66 | 357 | |
59089d8d SB |
358 | ret = ops->get_rxnfc(dev, &info, rule_buf); |
359 | if (ret < 0) | |
360 | goto err_out; | |
361 | ||
362 | ret = -EFAULT; | |
bf988435 | 363 | if (copy_to_user(useraddr, &info, info_size)) |
59089d8d SB |
364 | goto err_out; |
365 | ||
366 | if (rule_buf) { | |
367 | useraddr += offsetof(struct ethtool_rxnfc, rule_locs); | |
368 | if (copy_to_user(useraddr, rule_buf, | |
369 | info.rule_cnt * sizeof(u32))) | |
370 | goto err_out; | |
371 | } | |
372 | ret = 0; | |
373 | ||
374 | err_out: | |
c9caceca | 375 | kfree(rule_buf); |
59089d8d SB |
376 | |
377 | return ret; | |
0853ad66 SB |
378 | } |
379 | ||
a5b6ee29 BH |
380 | static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev, |
381 | void __user *useraddr) | |
382 | { | |
383 | struct ethtool_rxfh_indir *indir; | |
384 | u32 table_size; | |
385 | size_t full_size; | |
386 | int ret; | |
387 | ||
388 | if (!dev->ethtool_ops->get_rxfh_indir) | |
389 | return -EOPNOTSUPP; | |
390 | ||
391 | if (copy_from_user(&table_size, | |
392 | useraddr + offsetof(struct ethtool_rxfh_indir, size), | |
393 | sizeof(table_size))) | |
394 | return -EFAULT; | |
395 | ||
396 | if (table_size > | |
397 | (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index)) | |
398 | return -ENOMEM; | |
399 | full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size; | |
400 | indir = kmalloc(full_size, GFP_USER); | |
401 | if (!indir) | |
402 | return -ENOMEM; | |
403 | ||
404 | indir->cmd = ETHTOOL_GRXFHINDIR; | |
405 | indir->size = table_size; | |
406 | ret = dev->ethtool_ops->get_rxfh_indir(dev, indir); | |
407 | if (ret) | |
408 | goto out; | |
409 | ||
410 | if (copy_to_user(useraddr, indir, full_size)) | |
411 | ret = -EFAULT; | |
412 | ||
413 | out: | |
414 | kfree(indir); | |
415 | return ret; | |
416 | } | |
417 | ||
418 | static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev, | |
419 | void __user *useraddr) | |
420 | { | |
421 | struct ethtool_rxfh_indir *indir; | |
422 | u32 table_size; | |
423 | size_t full_size; | |
424 | int ret; | |
425 | ||
426 | if (!dev->ethtool_ops->set_rxfh_indir) | |
427 | return -EOPNOTSUPP; | |
428 | ||
429 | if (copy_from_user(&table_size, | |
430 | useraddr + offsetof(struct ethtool_rxfh_indir, size), | |
431 | sizeof(table_size))) | |
432 | return -EFAULT; | |
433 | ||
434 | if (table_size > | |
435 | (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index)) | |
436 | return -ENOMEM; | |
437 | full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size; | |
438 | indir = kmalloc(full_size, GFP_USER); | |
439 | if (!indir) | |
440 | return -ENOMEM; | |
441 | ||
442 | if (copy_from_user(indir, useraddr, full_size)) { | |
443 | ret = -EFAULT; | |
444 | goto out; | |
445 | } | |
446 | ||
447 | ret = dev->ethtool_ops->set_rxfh_indir(dev, indir); | |
448 | ||
449 | out: | |
450 | kfree(indir); | |
451 | return ret; | |
452 | } | |
453 | ||
e8589118 | 454 | static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list, |
97f8aefb | 455 | struct ethtool_rx_ntuple_flow_spec *spec, |
456 | struct ethtool_rx_ntuple_flow_spec_container *fsc) | |
15682bc4 | 457 | { |
15682bc4 PWJ |
458 | |
459 | /* don't add filters forever */ | |
e8589118 PW |
460 | if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) { |
461 | /* free the container */ | |
462 | kfree(fsc); | |
463 | return; | |
464 | } | |
15682bc4 PWJ |
465 | |
466 | /* Copy the whole filter over */ | |
467 | fsc->fs.flow_type = spec->flow_type; | |
468 | memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u)); | |
469 | memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u)); | |
470 | ||
471 | fsc->fs.vlan_tag = spec->vlan_tag; | |
472 | fsc->fs.vlan_tag_mask = spec->vlan_tag_mask; | |
473 | fsc->fs.data = spec->data; | |
474 | fsc->fs.data_mask = spec->data_mask; | |
475 | fsc->fs.action = spec->action; | |
476 | ||
477 | /* add to the list */ | |
478 | list_add_tail_rcu(&fsc->list, &list->list); | |
479 | list->count++; | |
15682bc4 PWJ |
480 | } |
481 | ||
97f8aefb | 482 | static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev, |
483 | void __user *useraddr) | |
15682bc4 PWJ |
484 | { |
485 | struct ethtool_rx_ntuple cmd; | |
486 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
e8589118 | 487 | struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL; |
15682bc4 PWJ |
488 | int ret; |
489 | ||
15682bc4 PWJ |
490 | if (!(dev->features & NETIF_F_NTUPLE)) |
491 | return -EINVAL; | |
492 | ||
493 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) | |
494 | return -EFAULT; | |
495 | ||
15682bc4 PWJ |
496 | /* |
497 | * Cache filter in dev struct for GET operation only if | |
498 | * the underlying driver doesn't have its own GET operation, and | |
e8589118 PW |
499 | * only if the filter was added successfully. First make sure we |
500 | * can allocate the filter, then continue if successful. | |
15682bc4 | 501 | */ |
e8589118 PW |
502 | if (!ops->get_rx_ntuple) { |
503 | fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC); | |
504 | if (!fsc) | |
15682bc4 | 505 | return -ENOMEM; |
e8589118 PW |
506 | } |
507 | ||
508 | ret = ops->set_rx_ntuple(dev, &cmd); | |
509 | if (ret) { | |
510 | kfree(fsc); | |
511 | return ret; | |
512 | } | |
513 | ||
514 | if (!ops->get_rx_ntuple) | |
515 | __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc); | |
15682bc4 PWJ |
516 | |
517 | return ret; | |
518 | } | |
519 | ||
520 | static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr) | |
521 | { | |
522 | struct ethtool_gstrings gstrings; | |
523 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
524 | struct ethtool_rx_ntuple_flow_spec_container *fsc; | |
525 | u8 *data; | |
526 | char *p; | |
527 | int ret, i, num_strings = 0; | |
528 | ||
529 | if (!ops->get_sset_count) | |
530 | return -EOPNOTSUPP; | |
531 | ||
532 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) | |
533 | return -EFAULT; | |
534 | ||
535 | ret = ops->get_sset_count(dev, gstrings.string_set); | |
536 | if (ret < 0) | |
537 | return ret; | |
538 | ||
539 | gstrings.len = ret; | |
540 | ||
541 | data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER); | |
542 | if (!data) | |
543 | return -ENOMEM; | |
544 | ||
545 | if (ops->get_rx_ntuple) { | |
546 | /* driver-specific filter grab */ | |
547 | ret = ops->get_rx_ntuple(dev, gstrings.string_set, data); | |
548 | goto copy; | |
549 | } | |
550 | ||
551 | /* default ethtool filter grab */ | |
552 | i = 0; | |
553 | p = (char *)data; | |
554 | list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) { | |
555 | sprintf(p, "Filter %d:\n", i); | |
556 | p += ETH_GSTRING_LEN; | |
557 | num_strings++; | |
558 | ||
559 | switch (fsc->fs.flow_type) { | |
560 | case TCP_V4_FLOW: | |
561 | sprintf(p, "\tFlow Type: TCP\n"); | |
562 | p += ETH_GSTRING_LEN; | |
563 | num_strings++; | |
564 | break; | |
565 | case UDP_V4_FLOW: | |
566 | sprintf(p, "\tFlow Type: UDP\n"); | |
567 | p += ETH_GSTRING_LEN; | |
568 | num_strings++; | |
569 | break; | |
570 | case SCTP_V4_FLOW: | |
571 | sprintf(p, "\tFlow Type: SCTP\n"); | |
572 | p += ETH_GSTRING_LEN; | |
573 | num_strings++; | |
574 | break; | |
575 | case AH_ESP_V4_FLOW: | |
576 | sprintf(p, "\tFlow Type: AH ESP\n"); | |
577 | p += ETH_GSTRING_LEN; | |
578 | num_strings++; | |
579 | break; | |
580 | case ESP_V4_FLOW: | |
581 | sprintf(p, "\tFlow Type: ESP\n"); | |
582 | p += ETH_GSTRING_LEN; | |
583 | num_strings++; | |
584 | break; | |
585 | case IP_USER_FLOW: | |
586 | sprintf(p, "\tFlow Type: Raw IP\n"); | |
587 | p += ETH_GSTRING_LEN; | |
588 | num_strings++; | |
589 | break; | |
590 | case IPV4_FLOW: | |
591 | sprintf(p, "\tFlow Type: IPv4\n"); | |
592 | p += ETH_GSTRING_LEN; | |
593 | num_strings++; | |
594 | break; | |
595 | default: | |
596 | sprintf(p, "\tFlow Type: Unknown\n"); | |
597 | p += ETH_GSTRING_LEN; | |
598 | num_strings++; | |
599 | goto unknown_filter; | |
ccbd6a5a | 600 | } |
15682bc4 PWJ |
601 | |
602 | /* now the rest of the filters */ | |
603 | switch (fsc->fs.flow_type) { | |
604 | case TCP_V4_FLOW: | |
605 | case UDP_V4_FLOW: | |
606 | case SCTP_V4_FLOW: | |
607 | sprintf(p, "\tSrc IP addr: 0x%x\n", | |
97f8aefb | 608 | fsc->fs.h_u.tcp_ip4_spec.ip4src); |
15682bc4 PWJ |
609 | p += ETH_GSTRING_LEN; |
610 | num_strings++; | |
611 | sprintf(p, "\tSrc IP mask: 0x%x\n", | |
97f8aefb | 612 | fsc->fs.m_u.tcp_ip4_spec.ip4src); |
15682bc4 PWJ |
613 | p += ETH_GSTRING_LEN; |
614 | num_strings++; | |
615 | sprintf(p, "\tDest IP addr: 0x%x\n", | |
97f8aefb | 616 | fsc->fs.h_u.tcp_ip4_spec.ip4dst); |
15682bc4 PWJ |
617 | p += ETH_GSTRING_LEN; |
618 | num_strings++; | |
619 | sprintf(p, "\tDest IP mask: 0x%x\n", | |
97f8aefb | 620 | fsc->fs.m_u.tcp_ip4_spec.ip4dst); |
15682bc4 PWJ |
621 | p += ETH_GSTRING_LEN; |
622 | num_strings++; | |
623 | sprintf(p, "\tSrc Port: %d, mask: 0x%x\n", | |
97f8aefb | 624 | fsc->fs.h_u.tcp_ip4_spec.psrc, |
625 | fsc->fs.m_u.tcp_ip4_spec.psrc); | |
15682bc4 PWJ |
626 | p += ETH_GSTRING_LEN; |
627 | num_strings++; | |
628 | sprintf(p, "\tDest Port: %d, mask: 0x%x\n", | |
97f8aefb | 629 | fsc->fs.h_u.tcp_ip4_spec.pdst, |
630 | fsc->fs.m_u.tcp_ip4_spec.pdst); | |
15682bc4 PWJ |
631 | p += ETH_GSTRING_LEN; |
632 | num_strings++; | |
633 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", | |
97f8aefb | 634 | fsc->fs.h_u.tcp_ip4_spec.tos, |
635 | fsc->fs.m_u.tcp_ip4_spec.tos); | |
15682bc4 PWJ |
636 | p += ETH_GSTRING_LEN; |
637 | num_strings++; | |
638 | break; | |
639 | case AH_ESP_V4_FLOW: | |
640 | case ESP_V4_FLOW: | |
641 | sprintf(p, "\tSrc IP addr: 0x%x\n", | |
97f8aefb | 642 | fsc->fs.h_u.ah_ip4_spec.ip4src); |
15682bc4 PWJ |
643 | p += ETH_GSTRING_LEN; |
644 | num_strings++; | |
645 | sprintf(p, "\tSrc IP mask: 0x%x\n", | |
97f8aefb | 646 | fsc->fs.m_u.ah_ip4_spec.ip4src); |
15682bc4 PWJ |
647 | p += ETH_GSTRING_LEN; |
648 | num_strings++; | |
649 | sprintf(p, "\tDest IP addr: 0x%x\n", | |
97f8aefb | 650 | fsc->fs.h_u.ah_ip4_spec.ip4dst); |
15682bc4 PWJ |
651 | p += ETH_GSTRING_LEN; |
652 | num_strings++; | |
653 | sprintf(p, "\tDest IP mask: 0x%x\n", | |
97f8aefb | 654 | fsc->fs.m_u.ah_ip4_spec.ip4dst); |
15682bc4 PWJ |
655 | p += ETH_GSTRING_LEN; |
656 | num_strings++; | |
657 | sprintf(p, "\tSPI: %d, mask: 0x%x\n", | |
97f8aefb | 658 | fsc->fs.h_u.ah_ip4_spec.spi, |
659 | fsc->fs.m_u.ah_ip4_spec.spi); | |
15682bc4 PWJ |
660 | p += ETH_GSTRING_LEN; |
661 | num_strings++; | |
662 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", | |
97f8aefb | 663 | fsc->fs.h_u.ah_ip4_spec.tos, |
664 | fsc->fs.m_u.ah_ip4_spec.tos); | |
15682bc4 PWJ |
665 | p += ETH_GSTRING_LEN; |
666 | num_strings++; | |
667 | break; | |
668 | case IP_USER_FLOW: | |
669 | sprintf(p, "\tSrc IP addr: 0x%x\n", | |
97f8aefb | 670 | fsc->fs.h_u.raw_ip4_spec.ip4src); |
15682bc4 PWJ |
671 | p += ETH_GSTRING_LEN; |
672 | num_strings++; | |
673 | sprintf(p, "\tSrc IP mask: 0x%x\n", | |
97f8aefb | 674 | fsc->fs.m_u.raw_ip4_spec.ip4src); |
15682bc4 PWJ |
675 | p += ETH_GSTRING_LEN; |
676 | num_strings++; | |
677 | sprintf(p, "\tDest IP addr: 0x%x\n", | |
97f8aefb | 678 | fsc->fs.h_u.raw_ip4_spec.ip4dst); |
15682bc4 PWJ |
679 | p += ETH_GSTRING_LEN; |
680 | num_strings++; | |
681 | sprintf(p, "\tDest IP mask: 0x%x\n", | |
97f8aefb | 682 | fsc->fs.m_u.raw_ip4_spec.ip4dst); |
15682bc4 PWJ |
683 | p += ETH_GSTRING_LEN; |
684 | num_strings++; | |
685 | break; | |
686 | case IPV4_FLOW: | |
687 | sprintf(p, "\tSrc IP addr: 0x%x\n", | |
97f8aefb | 688 | fsc->fs.h_u.usr_ip4_spec.ip4src); |
15682bc4 PWJ |
689 | p += ETH_GSTRING_LEN; |
690 | num_strings++; | |
691 | sprintf(p, "\tSrc IP mask: 0x%x\n", | |
97f8aefb | 692 | fsc->fs.m_u.usr_ip4_spec.ip4src); |
15682bc4 PWJ |
693 | p += ETH_GSTRING_LEN; |
694 | num_strings++; | |
695 | sprintf(p, "\tDest IP addr: 0x%x\n", | |
97f8aefb | 696 | fsc->fs.h_u.usr_ip4_spec.ip4dst); |
15682bc4 PWJ |
697 | p += ETH_GSTRING_LEN; |
698 | num_strings++; | |
699 | sprintf(p, "\tDest IP mask: 0x%x\n", | |
97f8aefb | 700 | fsc->fs.m_u.usr_ip4_spec.ip4dst); |
15682bc4 PWJ |
701 | p += ETH_GSTRING_LEN; |
702 | num_strings++; | |
703 | sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n", | |
97f8aefb | 704 | fsc->fs.h_u.usr_ip4_spec.l4_4_bytes, |
705 | fsc->fs.m_u.usr_ip4_spec.l4_4_bytes); | |
15682bc4 PWJ |
706 | p += ETH_GSTRING_LEN; |
707 | num_strings++; | |
708 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", | |
97f8aefb | 709 | fsc->fs.h_u.usr_ip4_spec.tos, |
710 | fsc->fs.m_u.usr_ip4_spec.tos); | |
15682bc4 PWJ |
711 | p += ETH_GSTRING_LEN; |
712 | num_strings++; | |
713 | sprintf(p, "\tIP Version: %d, mask: 0x%x\n", | |
97f8aefb | 714 | fsc->fs.h_u.usr_ip4_spec.ip_ver, |
715 | fsc->fs.m_u.usr_ip4_spec.ip_ver); | |
15682bc4 PWJ |
716 | p += ETH_GSTRING_LEN; |
717 | num_strings++; | |
718 | sprintf(p, "\tProtocol: %d, mask: 0x%x\n", | |
97f8aefb | 719 | fsc->fs.h_u.usr_ip4_spec.proto, |
720 | fsc->fs.m_u.usr_ip4_spec.proto); | |
15682bc4 PWJ |
721 | p += ETH_GSTRING_LEN; |
722 | num_strings++; | |
723 | break; | |
ccbd6a5a | 724 | } |
15682bc4 | 725 | sprintf(p, "\tVLAN: %d, mask: 0x%x\n", |
97f8aefb | 726 | fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask); |
15682bc4 PWJ |
727 | p += ETH_GSTRING_LEN; |
728 | num_strings++; | |
729 | sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data); | |
730 | p += ETH_GSTRING_LEN; | |
731 | num_strings++; | |
732 | sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask); | |
733 | p += ETH_GSTRING_LEN; | |
734 | num_strings++; | |
735 | if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP) | |
736 | sprintf(p, "\tAction: Drop\n"); | |
737 | else | |
738 | sprintf(p, "\tAction: Direct to queue %d\n", | |
97f8aefb | 739 | fsc->fs.action); |
15682bc4 PWJ |
740 | p += ETH_GSTRING_LEN; |
741 | num_strings++; | |
742 | unknown_filter: | |
743 | i++; | |
744 | } | |
745 | copy: | |
746 | /* indicate to userspace how many strings we actually have */ | |
747 | gstrings.len = num_strings; | |
748 | ret = -EFAULT; | |
749 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) | |
750 | goto out; | |
751 | useraddr += sizeof(gstrings); | |
752 | if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN)) | |
753 | goto out; | |
754 | ret = 0; | |
755 | ||
756 | out: | |
757 | kfree(data); | |
758 | return ret; | |
759 | } | |
760 | ||
1da177e4 LT |
761 | static int ethtool_get_regs(struct net_device *dev, char __user *useraddr) |
762 | { | |
763 | struct ethtool_regs regs; | |
76fd8593 | 764 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 LT |
765 | void *regbuf; |
766 | int reglen, ret; | |
767 | ||
768 | if (!ops->get_regs || !ops->get_regs_len) | |
769 | return -EOPNOTSUPP; | |
770 | ||
771 | if (copy_from_user(®s, useraddr, sizeof(regs))) | |
772 | return -EFAULT; | |
773 | ||
774 | reglen = ops->get_regs_len(dev); | |
775 | if (regs.len > reglen) | |
776 | regs.len = reglen; | |
777 | ||
778 | regbuf = kmalloc(reglen, GFP_USER); | |
779 | if (!regbuf) | |
780 | return -ENOMEM; | |
781 | ||
782 | ops->get_regs(dev, ®s, regbuf); | |
783 | ||
784 | ret = -EFAULT; | |
785 | if (copy_to_user(useraddr, ®s, sizeof(regs))) | |
786 | goto out; | |
787 | useraddr += offsetof(struct ethtool_regs, data); | |
788 | if (copy_to_user(useraddr, regbuf, regs.len)) | |
789 | goto out; | |
790 | ret = 0; | |
791 | ||
792 | out: | |
793 | kfree(regbuf); | |
794 | return ret; | |
795 | } | |
796 | ||
d73d3a8c BH |
797 | static int ethtool_reset(struct net_device *dev, char __user *useraddr) |
798 | { | |
799 | struct ethtool_value reset; | |
800 | int ret; | |
801 | ||
802 | if (!dev->ethtool_ops->reset) | |
803 | return -EOPNOTSUPP; | |
804 | ||
805 | if (copy_from_user(&reset, useraddr, sizeof(reset))) | |
806 | return -EFAULT; | |
807 | ||
808 | ret = dev->ethtool_ops->reset(dev, &reset.data); | |
809 | if (ret) | |
810 | return ret; | |
811 | ||
812 | if (copy_to_user(useraddr, &reset, sizeof(reset))) | |
813 | return -EFAULT; | |
814 | return 0; | |
815 | } | |
816 | ||
1da177e4 LT |
817 | static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) |
818 | { | |
8e557421 | 819 | struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; |
1da177e4 LT |
820 | |
821 | if (!dev->ethtool_ops->get_wol) | |
822 | return -EOPNOTSUPP; | |
823 | ||
824 | dev->ethtool_ops->get_wol(dev, &wol); | |
825 | ||
826 | if (copy_to_user(useraddr, &wol, sizeof(wol))) | |
827 | return -EFAULT; | |
828 | return 0; | |
829 | } | |
830 | ||
831 | static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) | |
832 | { | |
833 | struct ethtool_wolinfo wol; | |
834 | ||
835 | if (!dev->ethtool_ops->set_wol) | |
836 | return -EOPNOTSUPP; | |
837 | ||
838 | if (copy_from_user(&wol, useraddr, sizeof(wol))) | |
839 | return -EFAULT; | |
840 | ||
841 | return dev->ethtool_ops->set_wol(dev, &wol); | |
842 | } | |
843 | ||
1da177e4 LT |
844 | static int ethtool_nway_reset(struct net_device *dev) |
845 | { | |
846 | if (!dev->ethtool_ops->nway_reset) | |
847 | return -EOPNOTSUPP; | |
848 | ||
849 | return dev->ethtool_ops->nway_reset(dev); | |
850 | } | |
851 | ||
1da177e4 LT |
852 | static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr) |
853 | { | |
854 | struct ethtool_eeprom eeprom; | |
76fd8593 | 855 | const struct ethtool_ops *ops = dev->ethtool_ops; |
b131dd5d MSB |
856 | void __user *userbuf = useraddr + sizeof(eeprom); |
857 | u32 bytes_remaining; | |
1da177e4 | 858 | u8 *data; |
b131dd5d | 859 | int ret = 0; |
1da177e4 LT |
860 | |
861 | if (!ops->get_eeprom || !ops->get_eeprom_len) | |
862 | return -EOPNOTSUPP; | |
863 | ||
864 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) | |
865 | return -EFAULT; | |
866 | ||
867 | /* Check for wrap and zero */ | |
868 | if (eeprom.offset + eeprom.len <= eeprom.offset) | |
869 | return -EINVAL; | |
870 | ||
871 | /* Check for exceeding total eeprom len */ | |
872 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) | |
873 | return -EINVAL; | |
874 | ||
b131dd5d | 875 | data = kmalloc(PAGE_SIZE, GFP_USER); |
1da177e4 LT |
876 | if (!data) |
877 | return -ENOMEM; | |
878 | ||
b131dd5d MSB |
879 | bytes_remaining = eeprom.len; |
880 | while (bytes_remaining > 0) { | |
881 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); | |
882 | ||
883 | ret = ops->get_eeprom(dev, &eeprom, data); | |
884 | if (ret) | |
885 | break; | |
886 | if (copy_to_user(userbuf, data, eeprom.len)) { | |
887 | ret = -EFAULT; | |
888 | break; | |
889 | } | |
890 | userbuf += eeprom.len; | |
891 | eeprom.offset += eeprom.len; | |
892 | bytes_remaining -= eeprom.len; | |
893 | } | |
1da177e4 | 894 | |
c5835df9 MSB |
895 | eeprom.len = userbuf - (useraddr + sizeof(eeprom)); |
896 | eeprom.offset -= eeprom.len; | |
897 | if (copy_to_user(useraddr, &eeprom, sizeof(eeprom))) | |
898 | ret = -EFAULT; | |
899 | ||
1da177e4 LT |
900 | kfree(data); |
901 | return ret; | |
902 | } | |
903 | ||
904 | static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr) | |
905 | { | |
906 | struct ethtool_eeprom eeprom; | |
76fd8593 | 907 | const struct ethtool_ops *ops = dev->ethtool_ops; |
b131dd5d MSB |
908 | void __user *userbuf = useraddr + sizeof(eeprom); |
909 | u32 bytes_remaining; | |
1da177e4 | 910 | u8 *data; |
b131dd5d | 911 | int ret = 0; |
1da177e4 LT |
912 | |
913 | if (!ops->set_eeprom || !ops->get_eeprom_len) | |
914 | return -EOPNOTSUPP; | |
915 | ||
916 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) | |
917 | return -EFAULT; | |
918 | ||
919 | /* Check for wrap and zero */ | |
920 | if (eeprom.offset + eeprom.len <= eeprom.offset) | |
921 | return -EINVAL; | |
922 | ||
923 | /* Check for exceeding total eeprom len */ | |
924 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) | |
925 | return -EINVAL; | |
926 | ||
b131dd5d | 927 | data = kmalloc(PAGE_SIZE, GFP_USER); |
1da177e4 LT |
928 | if (!data) |
929 | return -ENOMEM; | |
930 | ||
b131dd5d MSB |
931 | bytes_remaining = eeprom.len; |
932 | while (bytes_remaining > 0) { | |
933 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); | |
934 | ||
935 | if (copy_from_user(data, userbuf, eeprom.len)) { | |
936 | ret = -EFAULT; | |
937 | break; | |
938 | } | |
939 | ret = ops->set_eeprom(dev, &eeprom, data); | |
940 | if (ret) | |
941 | break; | |
942 | userbuf += eeprom.len; | |
943 | eeprom.offset += eeprom.len; | |
944 | bytes_remaining -= eeprom.len; | |
945 | } | |
1da177e4 | 946 | |
1da177e4 LT |
947 | kfree(data); |
948 | return ret; | |
949 | } | |
950 | ||
97f8aefb | 951 | static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, |
952 | void __user *useraddr) | |
1da177e4 | 953 | { |
8e557421 | 954 | struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; |
1da177e4 LT |
955 | |
956 | if (!dev->ethtool_ops->get_coalesce) | |
957 | return -EOPNOTSUPP; | |
958 | ||
959 | dev->ethtool_ops->get_coalesce(dev, &coalesce); | |
960 | ||
961 | if (copy_to_user(useraddr, &coalesce, sizeof(coalesce))) | |
962 | return -EFAULT; | |
963 | return 0; | |
964 | } | |
965 | ||
97f8aefb | 966 | static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, |
967 | void __user *useraddr) | |
1da177e4 LT |
968 | { |
969 | struct ethtool_coalesce coalesce; | |
970 | ||
fa04ae5c | 971 | if (!dev->ethtool_ops->set_coalesce) |
1da177e4 LT |
972 | return -EOPNOTSUPP; |
973 | ||
974 | if (copy_from_user(&coalesce, useraddr, sizeof(coalesce))) | |
975 | return -EFAULT; | |
976 | ||
977 | return dev->ethtool_ops->set_coalesce(dev, &coalesce); | |
978 | } | |
979 | ||
980 | static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr) | |
981 | { | |
8e557421 | 982 | struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM }; |
1da177e4 LT |
983 | |
984 | if (!dev->ethtool_ops->get_ringparam) | |
985 | return -EOPNOTSUPP; | |
986 | ||
987 | dev->ethtool_ops->get_ringparam(dev, &ringparam); | |
988 | ||
989 | if (copy_to_user(useraddr, &ringparam, sizeof(ringparam))) | |
990 | return -EFAULT; | |
991 | return 0; | |
992 | } | |
993 | ||
994 | static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr) | |
995 | { | |
996 | struct ethtool_ringparam ringparam; | |
997 | ||
998 | if (!dev->ethtool_ops->set_ringparam) | |
999 | return -EOPNOTSUPP; | |
1000 | ||
1001 | if (copy_from_user(&ringparam, useraddr, sizeof(ringparam))) | |
1002 | return -EFAULT; | |
1003 | ||
1004 | return dev->ethtool_ops->set_ringparam(dev, &ringparam); | |
1005 | } | |
1006 | ||
1007 | static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr) | |
1008 | { | |
1009 | struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM }; | |
1010 | ||
1011 | if (!dev->ethtool_ops->get_pauseparam) | |
1012 | return -EOPNOTSUPP; | |
1013 | ||
1014 | dev->ethtool_ops->get_pauseparam(dev, &pauseparam); | |
1015 | ||
1016 | if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam))) | |
1017 | return -EFAULT; | |
1018 | return 0; | |
1019 | } | |
1020 | ||
1021 | static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr) | |
1022 | { | |
1023 | struct ethtool_pauseparam pauseparam; | |
1024 | ||
e1b90c41 | 1025 | if (!dev->ethtool_ops->set_pauseparam) |
1da177e4 LT |
1026 | return -EOPNOTSUPP; |
1027 | ||
1028 | if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam))) | |
1029 | return -EFAULT; | |
1030 | ||
1031 | return dev->ethtool_ops->set_pauseparam(dev, &pauseparam); | |
1032 | } | |
1033 | ||
1da177e4 LT |
1034 | static int __ethtool_set_sg(struct net_device *dev, u32 data) |
1035 | { | |
1036 | int err; | |
1037 | ||
1038 | if (!data && dev->ethtool_ops->set_tso) { | |
1039 | err = dev->ethtool_ops->set_tso(dev, 0); | |
1040 | if (err) | |
1041 | return err; | |
1042 | } | |
1043 | ||
e89e9cf5 AR |
1044 | if (!data && dev->ethtool_ops->set_ufo) { |
1045 | err = dev->ethtool_ops->set_ufo(dev, 0); | |
1046 | if (err) | |
1047 | return err; | |
1048 | } | |
1da177e4 LT |
1049 | return dev->ethtool_ops->set_sg(dev, data); |
1050 | } | |
1051 | ||
1052 | static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr) | |
1053 | { | |
1054 | struct ethtool_value edata; | |
1055 | int err; | |
1056 | ||
1057 | if (!dev->ethtool_ops->set_tx_csum) | |
1058 | return -EOPNOTSUPP; | |
1059 | ||
1060 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1061 | return -EFAULT; | |
1062 | ||
1063 | if (!edata.data && dev->ethtool_ops->set_sg) { | |
1064 | err = __ethtool_set_sg(dev, 0); | |
1065 | if (err) | |
1066 | return err; | |
1067 | } | |
1068 | ||
1069 | return dev->ethtool_ops->set_tx_csum(dev, edata.data); | |
1070 | } | |
97f8aefb | 1071 | EXPORT_SYMBOL(ethtool_op_set_tx_csum); |
1da177e4 | 1072 | |
b240a0e5 HX |
1073 | static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr) |
1074 | { | |
1075 | struct ethtool_value edata; | |
1076 | ||
1077 | if (!dev->ethtool_ops->set_rx_csum) | |
1078 | return -EOPNOTSUPP; | |
1079 | ||
1080 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1081 | return -EFAULT; | |
1082 | ||
1083 | if (!edata.data && dev->ethtool_ops->set_sg) | |
1084 | dev->features &= ~NETIF_F_GRO; | |
1085 | ||
1086 | return dev->ethtool_ops->set_rx_csum(dev, edata.data); | |
1087 | } | |
1088 | ||
1da177e4 LT |
1089 | static int ethtool_set_sg(struct net_device *dev, char __user *useraddr) |
1090 | { | |
1091 | struct ethtool_value edata; | |
1092 | ||
1093 | if (!dev->ethtool_ops->set_sg) | |
1094 | return -EOPNOTSUPP; | |
1095 | ||
1096 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1097 | return -EFAULT; | |
1098 | ||
4ec93edb | 1099 | if (edata.data && |
8648b305 | 1100 | !(dev->features & NETIF_F_ALL_CSUM)) |
1da177e4 LT |
1101 | return -EINVAL; |
1102 | ||
1103 | return __ethtool_set_sg(dev, edata.data); | |
1104 | } | |
1105 | ||
1da177e4 LT |
1106 | static int ethtool_set_tso(struct net_device *dev, char __user *useraddr) |
1107 | { | |
1108 | struct ethtool_value edata; | |
1109 | ||
1110 | if (!dev->ethtool_ops->set_tso) | |
1111 | return -EOPNOTSUPP; | |
1112 | ||
1113 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1114 | return -EFAULT; | |
1115 | ||
1116 | if (edata.data && !(dev->features & NETIF_F_SG)) | |
1117 | return -EINVAL; | |
1118 | ||
1119 | return dev->ethtool_ops->set_tso(dev, edata.data); | |
1120 | } | |
1121 | ||
e89e9cf5 AR |
1122 | static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr) |
1123 | { | |
1124 | struct ethtool_value edata; | |
1125 | ||
1126 | if (!dev->ethtool_ops->set_ufo) | |
1127 | return -EOPNOTSUPP; | |
1128 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1129 | return -EFAULT; | |
1130 | if (edata.data && !(dev->features & NETIF_F_SG)) | |
1131 | return -EINVAL; | |
1132 | if (edata.data && !(dev->features & NETIF_F_HW_CSUM)) | |
1133 | return -EINVAL; | |
1134 | return dev->ethtool_ops->set_ufo(dev, edata.data); | |
1135 | } | |
1136 | ||
37c3185a HX |
1137 | static int ethtool_get_gso(struct net_device *dev, char __user *useraddr) |
1138 | { | |
1139 | struct ethtool_value edata = { ETHTOOL_GGSO }; | |
1140 | ||
1141 | edata.data = dev->features & NETIF_F_GSO; | |
1142 | if (copy_to_user(useraddr, &edata, sizeof(edata))) | |
97f8aefb | 1143 | return -EFAULT; |
37c3185a HX |
1144 | return 0; |
1145 | } | |
1146 | ||
1147 | static int ethtool_set_gso(struct net_device *dev, char __user *useraddr) | |
1148 | { | |
1149 | struct ethtool_value edata; | |
1150 | ||
1151 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1152 | return -EFAULT; | |
1153 | if (edata.data) | |
1154 | dev->features |= NETIF_F_GSO; | |
1155 | else | |
1156 | dev->features &= ~NETIF_F_GSO; | |
1157 | return 0; | |
1158 | } | |
1159 | ||
b240a0e5 HX |
1160 | static int ethtool_get_gro(struct net_device *dev, char __user *useraddr) |
1161 | { | |
1162 | struct ethtool_value edata = { ETHTOOL_GGRO }; | |
1163 | ||
1164 | edata.data = dev->features & NETIF_F_GRO; | |
1165 | if (copy_to_user(useraddr, &edata, sizeof(edata))) | |
97f8aefb | 1166 | return -EFAULT; |
b240a0e5 HX |
1167 | return 0; |
1168 | } | |
1169 | ||
1170 | static int ethtool_set_gro(struct net_device *dev, char __user *useraddr) | |
1171 | { | |
1172 | struct ethtool_value edata; | |
1173 | ||
1174 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1175 | return -EFAULT; | |
1176 | ||
1177 | if (edata.data) { | |
1178 | if (!dev->ethtool_ops->get_rx_csum || | |
1179 | !dev->ethtool_ops->get_rx_csum(dev)) | |
1180 | return -EINVAL; | |
1181 | dev->features |= NETIF_F_GRO; | |
1182 | } else | |
1183 | dev->features &= ~NETIF_F_GRO; | |
1184 | ||
1185 | return 0; | |
1186 | } | |
1187 | ||
1da177e4 LT |
1188 | static int ethtool_self_test(struct net_device *dev, char __user *useraddr) |
1189 | { | |
1190 | struct ethtool_test test; | |
76fd8593 | 1191 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 | 1192 | u64 *data; |
ff03d49f | 1193 | int ret, test_len; |
1da177e4 | 1194 | |
a9828ec6 | 1195 | if (!ops->self_test || !ops->get_sset_count) |
1da177e4 LT |
1196 | return -EOPNOTSUPP; |
1197 | ||
a9828ec6 | 1198 | test_len = ops->get_sset_count(dev, ETH_SS_TEST); |
ff03d49f JG |
1199 | if (test_len < 0) |
1200 | return test_len; | |
1201 | WARN_ON(test_len == 0); | |
1202 | ||
1da177e4 LT |
1203 | if (copy_from_user(&test, useraddr, sizeof(test))) |
1204 | return -EFAULT; | |
1205 | ||
ff03d49f JG |
1206 | test.len = test_len; |
1207 | data = kmalloc(test_len * sizeof(u64), GFP_USER); | |
1da177e4 LT |
1208 | if (!data) |
1209 | return -ENOMEM; | |
1210 | ||
1211 | ops->self_test(dev, &test, data); | |
1212 | ||
1213 | ret = -EFAULT; | |
1214 | if (copy_to_user(useraddr, &test, sizeof(test))) | |
1215 | goto out; | |
1216 | useraddr += sizeof(test); | |
1217 | if (copy_to_user(useraddr, data, test.len * sizeof(u64))) | |
1218 | goto out; | |
1219 | ret = 0; | |
1220 | ||
1221 | out: | |
1222 | kfree(data); | |
1223 | return ret; | |
1224 | } | |
1225 | ||
1226 | static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) | |
1227 | { | |
1228 | struct ethtool_gstrings gstrings; | |
76fd8593 | 1229 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 LT |
1230 | u8 *data; |
1231 | int ret; | |
1232 | ||
a9828ec6 | 1233 | if (!ops->get_strings || !ops->get_sset_count) |
1da177e4 LT |
1234 | return -EOPNOTSUPP; |
1235 | ||
1236 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) | |
1237 | return -EFAULT; | |
1238 | ||
a9828ec6 BH |
1239 | ret = ops->get_sset_count(dev, gstrings.string_set); |
1240 | if (ret < 0) | |
1241 | return ret; | |
1242 | ||
1243 | gstrings.len = ret; | |
1da177e4 LT |
1244 | |
1245 | data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER); | |
1246 | if (!data) | |
1247 | return -ENOMEM; | |
1248 | ||
1249 | ops->get_strings(dev, gstrings.string_set, data); | |
1250 | ||
1251 | ret = -EFAULT; | |
1252 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) | |
1253 | goto out; | |
1254 | useraddr += sizeof(gstrings); | |
1255 | if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN)) | |
1256 | goto out; | |
1257 | ret = 0; | |
1258 | ||
1259 | out: | |
1260 | kfree(data); | |
1261 | return ret; | |
1262 | } | |
1263 | ||
1264 | static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) | |
1265 | { | |
1266 | struct ethtool_value id; | |
1267 | ||
1268 | if (!dev->ethtool_ops->phys_id) | |
1269 | return -EOPNOTSUPP; | |
1270 | ||
1271 | if (copy_from_user(&id, useraddr, sizeof(id))) | |
1272 | return -EFAULT; | |
1273 | ||
1274 | return dev->ethtool_ops->phys_id(dev, id.data); | |
1275 | } | |
1276 | ||
1277 | static int ethtool_get_stats(struct net_device *dev, void __user *useraddr) | |
1278 | { | |
1279 | struct ethtool_stats stats; | |
76fd8593 | 1280 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 | 1281 | u64 *data; |
ff03d49f | 1282 | int ret, n_stats; |
1da177e4 | 1283 | |
a9828ec6 | 1284 | if (!ops->get_ethtool_stats || !ops->get_sset_count) |
1da177e4 LT |
1285 | return -EOPNOTSUPP; |
1286 | ||
a9828ec6 | 1287 | n_stats = ops->get_sset_count(dev, ETH_SS_STATS); |
ff03d49f JG |
1288 | if (n_stats < 0) |
1289 | return n_stats; | |
1290 | WARN_ON(n_stats == 0); | |
1291 | ||
1da177e4 LT |
1292 | if (copy_from_user(&stats, useraddr, sizeof(stats))) |
1293 | return -EFAULT; | |
1294 | ||
ff03d49f JG |
1295 | stats.n_stats = n_stats; |
1296 | data = kmalloc(n_stats * sizeof(u64), GFP_USER); | |
1da177e4 LT |
1297 | if (!data) |
1298 | return -ENOMEM; | |
1299 | ||
1300 | ops->get_ethtool_stats(dev, &stats, data); | |
1301 | ||
1302 | ret = -EFAULT; | |
1303 | if (copy_to_user(useraddr, &stats, sizeof(stats))) | |
1304 | goto out; | |
1305 | useraddr += sizeof(stats); | |
1306 | if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64))) | |
1307 | goto out; | |
1308 | ret = 0; | |
1309 | ||
1310 | out: | |
1311 | kfree(data); | |
1312 | return ret; | |
1313 | } | |
1314 | ||
0bf0519d | 1315 | static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr) |
a6f9a705 JW |
1316 | { |
1317 | struct ethtool_perm_addr epaddr; | |
a6f9a705 | 1318 | |
313674af | 1319 | if (copy_from_user(&epaddr, useraddr, sizeof(epaddr))) |
a6f9a705 JW |
1320 | return -EFAULT; |
1321 | ||
313674af MW |
1322 | if (epaddr.size < dev->addr_len) |
1323 | return -ETOOSMALL; | |
1324 | epaddr.size = dev->addr_len; | |
a6f9a705 | 1325 | |
a6f9a705 | 1326 | if (copy_to_user(useraddr, &epaddr, sizeof(epaddr))) |
313674af | 1327 | return -EFAULT; |
a6f9a705 | 1328 | useraddr += sizeof(epaddr); |
313674af MW |
1329 | if (copy_to_user(useraddr, dev->perm_addr, epaddr.size)) |
1330 | return -EFAULT; | |
1331 | return 0; | |
a6f9a705 JW |
1332 | } |
1333 | ||
13c99b24 JG |
1334 | static int ethtool_get_value(struct net_device *dev, char __user *useraddr, |
1335 | u32 cmd, u32 (*actor)(struct net_device *)) | |
3ae7c0b2 | 1336 | { |
8e557421 | 1337 | struct ethtool_value edata = { .cmd = cmd }; |
3ae7c0b2 | 1338 | |
13c99b24 | 1339 | if (!actor) |
3ae7c0b2 JG |
1340 | return -EOPNOTSUPP; |
1341 | ||
13c99b24 | 1342 | edata.data = actor(dev); |
3ae7c0b2 JG |
1343 | |
1344 | if (copy_to_user(useraddr, &edata, sizeof(edata))) | |
1345 | return -EFAULT; | |
1346 | return 0; | |
1347 | } | |
1348 | ||
13c99b24 JG |
1349 | static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr, |
1350 | void (*actor)(struct net_device *, u32)) | |
3ae7c0b2 JG |
1351 | { |
1352 | struct ethtool_value edata; | |
1353 | ||
13c99b24 | 1354 | if (!actor) |
3ae7c0b2 JG |
1355 | return -EOPNOTSUPP; |
1356 | ||
1357 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1358 | return -EFAULT; | |
1359 | ||
13c99b24 | 1360 | actor(dev, edata.data); |
339bf024 JG |
1361 | return 0; |
1362 | } | |
1363 | ||
13c99b24 JG |
1364 | static int ethtool_set_value(struct net_device *dev, char __user *useraddr, |
1365 | int (*actor)(struct net_device *, u32)) | |
339bf024 JG |
1366 | { |
1367 | struct ethtool_value edata; | |
1368 | ||
13c99b24 | 1369 | if (!actor) |
339bf024 JG |
1370 | return -EOPNOTSUPP; |
1371 | ||
1372 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1373 | return -EFAULT; | |
1374 | ||
13c99b24 | 1375 | return actor(dev, edata.data); |
339bf024 JG |
1376 | } |
1377 | ||
97f8aefb | 1378 | static noinline_for_stack int ethtool_flash_device(struct net_device *dev, |
1379 | char __user *useraddr) | |
05c6a8d7 AK |
1380 | { |
1381 | struct ethtool_flash efl; | |
1382 | ||
1383 | if (copy_from_user(&efl, useraddr, sizeof(efl))) | |
1384 | return -EFAULT; | |
1385 | ||
1386 | if (!dev->ethtool_ops->flash_device) | |
1387 | return -EOPNOTSUPP; | |
1388 | ||
1389 | return dev->ethtool_ops->flash_device(dev, &efl); | |
1390 | } | |
1391 | ||
1da177e4 LT |
1392 | /* The main entry point in this file. Called from net/core/dev.c */ |
1393 | ||
881d966b | 1394 | int dev_ethtool(struct net *net, struct ifreq *ifr) |
1da177e4 | 1395 | { |
881d966b | 1396 | struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); |
1da177e4 LT |
1397 | void __user *useraddr = ifr->ifr_data; |
1398 | u32 ethcmd; | |
1399 | int rc; | |
81e81575 | 1400 | unsigned long old_features; |
1da177e4 | 1401 | |
1da177e4 LT |
1402 | if (!dev || !netif_device_present(dev)) |
1403 | return -ENODEV; | |
1404 | ||
1405 | if (!dev->ethtool_ops) | |
61a44b9c | 1406 | return -EOPNOTSUPP; |
1da177e4 | 1407 | |
97f8aefb | 1408 | if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) |
1da177e4 LT |
1409 | return -EFAULT; |
1410 | ||
75f3123c | 1411 | /* Allow some commands to be done by anyone */ |
97f8aefb | 1412 | switch (ethcmd) { |
75f3123c | 1413 | case ETHTOOL_GDRVINFO: |
75f3123c | 1414 | case ETHTOOL_GMSGLVL: |
75f3123c SH |
1415 | case ETHTOOL_GCOALESCE: |
1416 | case ETHTOOL_GRINGPARAM: | |
1417 | case ETHTOOL_GPAUSEPARAM: | |
1418 | case ETHTOOL_GRXCSUM: | |
1419 | case ETHTOOL_GTXCSUM: | |
1420 | case ETHTOOL_GSG: | |
1421 | case ETHTOOL_GSTRINGS: | |
75f3123c SH |
1422 | case ETHTOOL_GTSO: |
1423 | case ETHTOOL_GPERMADDR: | |
1424 | case ETHTOOL_GUFO: | |
1425 | case ETHTOOL_GGSO: | |
1cab819b | 1426 | case ETHTOOL_GGRO: |
339bf024 JG |
1427 | case ETHTOOL_GFLAGS: |
1428 | case ETHTOOL_GPFLAGS: | |
0853ad66 | 1429 | case ETHTOOL_GRXFH: |
59089d8d SB |
1430 | case ETHTOOL_GRXRINGS: |
1431 | case ETHTOOL_GRXCLSRLCNT: | |
1432 | case ETHTOOL_GRXCLSRULE: | |
1433 | case ETHTOOL_GRXCLSRLALL: | |
75f3123c SH |
1434 | break; |
1435 | default: | |
1436 | if (!capable(CAP_NET_ADMIN)) | |
1437 | return -EPERM; | |
1438 | } | |
1439 | ||
97f8aefb | 1440 | if (dev->ethtool_ops->begin) { |
1441 | rc = dev->ethtool_ops->begin(dev); | |
1442 | if (rc < 0) | |
1da177e4 | 1443 | return rc; |
97f8aefb | 1444 | } |
d8a33ac4 SH |
1445 | old_features = dev->features; |
1446 | ||
1da177e4 LT |
1447 | switch (ethcmd) { |
1448 | case ETHTOOL_GSET: | |
1449 | rc = ethtool_get_settings(dev, useraddr); | |
1450 | break; | |
1451 | case ETHTOOL_SSET: | |
1452 | rc = ethtool_set_settings(dev, useraddr); | |
1453 | break; | |
1454 | case ETHTOOL_GDRVINFO: | |
1455 | rc = ethtool_get_drvinfo(dev, useraddr); | |
1da177e4 LT |
1456 | break; |
1457 | case ETHTOOL_GREGS: | |
1458 | rc = ethtool_get_regs(dev, useraddr); | |
1459 | break; | |
1460 | case ETHTOOL_GWOL: | |
1461 | rc = ethtool_get_wol(dev, useraddr); | |
1462 | break; | |
1463 | case ETHTOOL_SWOL: | |
1464 | rc = ethtool_set_wol(dev, useraddr); | |
1465 | break; | |
1466 | case ETHTOOL_GMSGLVL: | |
13c99b24 JG |
1467 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1468 | dev->ethtool_ops->get_msglevel); | |
1da177e4 LT |
1469 | break; |
1470 | case ETHTOOL_SMSGLVL: | |
13c99b24 JG |
1471 | rc = ethtool_set_value_void(dev, useraddr, |
1472 | dev->ethtool_ops->set_msglevel); | |
1da177e4 LT |
1473 | break; |
1474 | case ETHTOOL_NWAY_RST: | |
1475 | rc = ethtool_nway_reset(dev); | |
1476 | break; | |
1477 | case ETHTOOL_GLINK: | |
13c99b24 JG |
1478 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1479 | dev->ethtool_ops->get_link); | |
1da177e4 LT |
1480 | break; |
1481 | case ETHTOOL_GEEPROM: | |
1482 | rc = ethtool_get_eeprom(dev, useraddr); | |
1483 | break; | |
1484 | case ETHTOOL_SEEPROM: | |
1485 | rc = ethtool_set_eeprom(dev, useraddr); | |
1486 | break; | |
1487 | case ETHTOOL_GCOALESCE: | |
1488 | rc = ethtool_get_coalesce(dev, useraddr); | |
1489 | break; | |
1490 | case ETHTOOL_SCOALESCE: | |
1491 | rc = ethtool_set_coalesce(dev, useraddr); | |
1492 | break; | |
1493 | case ETHTOOL_GRINGPARAM: | |
1494 | rc = ethtool_get_ringparam(dev, useraddr); | |
1495 | break; | |
1496 | case ETHTOOL_SRINGPARAM: | |
1497 | rc = ethtool_set_ringparam(dev, useraddr); | |
1498 | break; | |
1499 | case ETHTOOL_GPAUSEPARAM: | |
1500 | rc = ethtool_get_pauseparam(dev, useraddr); | |
1501 | break; | |
1502 | case ETHTOOL_SPAUSEPARAM: | |
1503 | rc = ethtool_set_pauseparam(dev, useraddr); | |
1504 | break; | |
1505 | case ETHTOOL_GRXCSUM: | |
13c99b24 | 1506 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1896e61f SS |
1507 | (dev->ethtool_ops->get_rx_csum ? |
1508 | dev->ethtool_ops->get_rx_csum : | |
1509 | ethtool_op_get_rx_csum)); | |
1da177e4 LT |
1510 | break; |
1511 | case ETHTOOL_SRXCSUM: | |
b240a0e5 | 1512 | rc = ethtool_set_rx_csum(dev, useraddr); |
1da177e4 LT |
1513 | break; |
1514 | case ETHTOOL_GTXCSUM: | |
13c99b24 | 1515 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
88d3aafd JG |
1516 | (dev->ethtool_ops->get_tx_csum ? |
1517 | dev->ethtool_ops->get_tx_csum : | |
1518 | ethtool_op_get_tx_csum)); | |
1da177e4 LT |
1519 | break; |
1520 | case ETHTOOL_STXCSUM: | |
1521 | rc = ethtool_set_tx_csum(dev, useraddr); | |
1522 | break; | |
1523 | case ETHTOOL_GSG: | |
13c99b24 | 1524 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
88d3aafd JG |
1525 | (dev->ethtool_ops->get_sg ? |
1526 | dev->ethtool_ops->get_sg : | |
1527 | ethtool_op_get_sg)); | |
1da177e4 LT |
1528 | break; |
1529 | case ETHTOOL_SSG: | |
1530 | rc = ethtool_set_sg(dev, useraddr); | |
1531 | break; | |
1532 | case ETHTOOL_GTSO: | |
13c99b24 | 1533 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
88d3aafd JG |
1534 | (dev->ethtool_ops->get_tso ? |
1535 | dev->ethtool_ops->get_tso : | |
1536 | ethtool_op_get_tso)); | |
1da177e4 LT |
1537 | break; |
1538 | case ETHTOOL_STSO: | |
1539 | rc = ethtool_set_tso(dev, useraddr); | |
1540 | break; | |
1541 | case ETHTOOL_TEST: | |
1542 | rc = ethtool_self_test(dev, useraddr); | |
1543 | break; | |
1544 | case ETHTOOL_GSTRINGS: | |
1545 | rc = ethtool_get_strings(dev, useraddr); | |
1546 | break; | |
1547 | case ETHTOOL_PHYS_ID: | |
1548 | rc = ethtool_phys_id(dev, useraddr); | |
1549 | break; | |
1550 | case ETHTOOL_GSTATS: | |
1551 | rc = ethtool_get_stats(dev, useraddr); | |
1552 | break; | |
a6f9a705 JW |
1553 | case ETHTOOL_GPERMADDR: |
1554 | rc = ethtool_get_perm_addr(dev, useraddr); | |
1555 | break; | |
e89e9cf5 | 1556 | case ETHTOOL_GUFO: |
13c99b24 | 1557 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
88d3aafd JG |
1558 | (dev->ethtool_ops->get_ufo ? |
1559 | dev->ethtool_ops->get_ufo : | |
1560 | ethtool_op_get_ufo)); | |
e89e9cf5 AR |
1561 | break; |
1562 | case ETHTOOL_SUFO: | |
1563 | rc = ethtool_set_ufo(dev, useraddr); | |
1564 | break; | |
37c3185a HX |
1565 | case ETHTOOL_GGSO: |
1566 | rc = ethtool_get_gso(dev, useraddr); | |
1567 | break; | |
1568 | case ETHTOOL_SGSO: | |
1569 | rc = ethtool_set_gso(dev, useraddr); | |
1570 | break; | |
3ae7c0b2 | 1571 | case ETHTOOL_GFLAGS: |
13c99b24 | 1572 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1896e61f SS |
1573 | (dev->ethtool_ops->get_flags ? |
1574 | dev->ethtool_ops->get_flags : | |
1575 | ethtool_op_get_flags)); | |
3ae7c0b2 JG |
1576 | break; |
1577 | case ETHTOOL_SFLAGS: | |
13c99b24 JG |
1578 | rc = ethtool_set_value(dev, useraddr, |
1579 | dev->ethtool_ops->set_flags); | |
3ae7c0b2 | 1580 | break; |
339bf024 | 1581 | case ETHTOOL_GPFLAGS: |
13c99b24 JG |
1582 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1583 | dev->ethtool_ops->get_priv_flags); | |
339bf024 JG |
1584 | break; |
1585 | case ETHTOOL_SPFLAGS: | |
13c99b24 JG |
1586 | rc = ethtool_set_value(dev, useraddr, |
1587 | dev->ethtool_ops->set_priv_flags); | |
339bf024 | 1588 | break; |
0853ad66 | 1589 | case ETHTOOL_GRXFH: |
59089d8d SB |
1590 | case ETHTOOL_GRXRINGS: |
1591 | case ETHTOOL_GRXCLSRLCNT: | |
1592 | case ETHTOOL_GRXCLSRULE: | |
1593 | case ETHTOOL_GRXCLSRLALL: | |
bf988435 | 1594 | rc = ethtool_get_rxnfc(dev, ethcmd, useraddr); |
0853ad66 SB |
1595 | break; |
1596 | case ETHTOOL_SRXFH: | |
59089d8d SB |
1597 | case ETHTOOL_SRXCLSRLDEL: |
1598 | case ETHTOOL_SRXCLSRLINS: | |
bf988435 | 1599 | rc = ethtool_set_rxnfc(dev, ethcmd, useraddr); |
0853ad66 | 1600 | break; |
b240a0e5 HX |
1601 | case ETHTOOL_GGRO: |
1602 | rc = ethtool_get_gro(dev, useraddr); | |
1603 | break; | |
1604 | case ETHTOOL_SGRO: | |
1605 | rc = ethtool_set_gro(dev, useraddr); | |
1606 | break; | |
05c6a8d7 AK |
1607 | case ETHTOOL_FLASHDEV: |
1608 | rc = ethtool_flash_device(dev, useraddr); | |
1609 | break; | |
d73d3a8c BH |
1610 | case ETHTOOL_RESET: |
1611 | rc = ethtool_reset(dev, useraddr); | |
1612 | break; | |
15682bc4 PWJ |
1613 | case ETHTOOL_SRXNTUPLE: |
1614 | rc = ethtool_set_rx_ntuple(dev, useraddr); | |
1615 | break; | |
1616 | case ETHTOOL_GRXNTUPLE: | |
1617 | rc = ethtool_get_rx_ntuple(dev, useraddr); | |
1618 | break; | |
723b2f57 JG |
1619 | case ETHTOOL_GSSET_INFO: |
1620 | rc = ethtool_get_sset_info(dev, useraddr); | |
1621 | break; | |
a5b6ee29 BH |
1622 | case ETHTOOL_GRXFHINDIR: |
1623 | rc = ethtool_get_rxfh_indir(dev, useraddr); | |
1624 | break; | |
1625 | case ETHTOOL_SRXFHINDIR: | |
1626 | rc = ethtool_set_rxfh_indir(dev, useraddr); | |
1627 | break; | |
1da177e4 | 1628 | default: |
61a44b9c | 1629 | rc = -EOPNOTSUPP; |
1da177e4 | 1630 | } |
4ec93edb | 1631 | |
e71a4783 | 1632 | if (dev->ethtool_ops->complete) |
1da177e4 | 1633 | dev->ethtool_ops->complete(dev); |
d8a33ac4 SH |
1634 | |
1635 | if (old_features != dev->features) | |
1636 | netdev_features_change(dev); | |
1637 | ||
1da177e4 | 1638 | return rc; |
1da177e4 | 1639 | } |