]>
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> |
73da16c2 | 22 | #include <linux/vmalloc.h> |
5a0e3ad6 | 23 | #include <linux/slab.h> |
68f512f2 BH |
24 | #include <linux/rtnetlink.h> |
25 | #include <linux/sched.h> | |
1da177e4 | 26 | |
4ec93edb | 27 | /* |
1da177e4 LT |
28 | * Some useful ethtool_ops methods that're device independent. |
29 | * If we find that all drivers want to do the same thing here, | |
30 | * we can turn these into dev_() function calls. | |
31 | */ | |
32 | ||
33 | u32 ethtool_op_get_link(struct net_device *dev) | |
34 | { | |
35 | return netif_carrier_ok(dev) ? 1 : 0; | |
36 | } | |
97f8aefb | 37 | EXPORT_SYMBOL(ethtool_op_get_link); |
1da177e4 LT |
38 | |
39 | u32 ethtool_op_get_tx_csum(struct net_device *dev) | |
40 | { | |
8648b305 | 41 | return (dev->features & NETIF_F_ALL_CSUM) != 0; |
1da177e4 | 42 | } |
8a729fce | 43 | EXPORT_SYMBOL(ethtool_op_get_tx_csum); |
1da177e4 LT |
44 | |
45 | int ethtool_op_set_tx_csum(struct net_device *dev, u32 data) | |
46 | { | |
47 | if (data) | |
48 | dev->features |= NETIF_F_IP_CSUM; | |
49 | else | |
50 | dev->features &= ~NETIF_F_IP_CSUM; | |
51 | ||
52 | return 0; | |
53 | } | |
9a279ea3 | 54 | EXPORT_SYMBOL(ethtool_op_set_tx_csum); |
1da177e4 | 55 | |
69f6a0fa JM |
56 | int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data) |
57 | { | |
58 | if (data) | |
59 | dev->features |= NETIF_F_HW_CSUM; | |
60 | else | |
61 | dev->features &= ~NETIF_F_HW_CSUM; | |
62 | ||
63 | return 0; | |
64 | } | |
97f8aefb | 65 | EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum); |
6460d948 MC |
66 | |
67 | int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data) | |
68 | { | |
69 | if (data) | |
70 | dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; | |
71 | else | |
72 | dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM); | |
73 | ||
74 | return 0; | |
75 | } | |
97f8aefb | 76 | EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum); |
6460d948 | 77 | |
1da177e4 LT |
78 | u32 ethtool_op_get_sg(struct net_device *dev) |
79 | { | |
80 | return (dev->features & NETIF_F_SG) != 0; | |
81 | } | |
97f8aefb | 82 | EXPORT_SYMBOL(ethtool_op_get_sg); |
1da177e4 LT |
83 | |
84 | int ethtool_op_set_sg(struct net_device *dev, u32 data) | |
85 | { | |
86 | if (data) | |
87 | dev->features |= NETIF_F_SG; | |
88 | else | |
89 | dev->features &= ~NETIF_F_SG; | |
90 | ||
91 | return 0; | |
92 | } | |
97f8aefb | 93 | EXPORT_SYMBOL(ethtool_op_set_sg); |
1da177e4 LT |
94 | |
95 | u32 ethtool_op_get_tso(struct net_device *dev) | |
96 | { | |
97 | return (dev->features & NETIF_F_TSO) != 0; | |
98 | } | |
97f8aefb | 99 | EXPORT_SYMBOL(ethtool_op_get_tso); |
1da177e4 LT |
100 | |
101 | int ethtool_op_set_tso(struct net_device *dev, u32 data) | |
102 | { | |
103 | if (data) | |
104 | dev->features |= NETIF_F_TSO; | |
105 | else | |
106 | dev->features &= ~NETIF_F_TSO; | |
107 | ||
108 | return 0; | |
109 | } | |
97f8aefb | 110 | EXPORT_SYMBOL(ethtool_op_set_tso); |
1da177e4 | 111 | |
e89e9cf5 AR |
112 | u32 ethtool_op_get_ufo(struct net_device *dev) |
113 | { | |
114 | return (dev->features & NETIF_F_UFO) != 0; | |
115 | } | |
97f8aefb | 116 | EXPORT_SYMBOL(ethtool_op_get_ufo); |
e89e9cf5 AR |
117 | |
118 | int ethtool_op_set_ufo(struct net_device *dev, u32 data) | |
119 | { | |
120 | if (data) | |
121 | dev->features |= NETIF_F_UFO; | |
122 | else | |
123 | dev->features &= ~NETIF_F_UFO; | |
124 | return 0; | |
125 | } | |
97f8aefb | 126 | EXPORT_SYMBOL(ethtool_op_set_ufo); |
e89e9cf5 | 127 | |
3ae7c0b2 JG |
128 | /* the following list of flags are the same as their associated |
129 | * NETIF_F_xxx values in include/linux/netdevice.h | |
130 | */ | |
131 | static const u32 flags_dup_features = | |
d5dbda23 JG |
132 | (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | ETH_FLAG_NTUPLE | |
133 | ETH_FLAG_RXHASH); | |
3ae7c0b2 JG |
134 | |
135 | u32 ethtool_op_get_flags(struct net_device *dev) | |
136 | { | |
137 | /* in the future, this function will probably contain additional | |
138 | * handling for flags which are not so easily handled | |
139 | * by a simple masking operation | |
140 | */ | |
141 | ||
142 | return dev->features & flags_dup_features; | |
143 | } | |
97f8aefb | 144 | EXPORT_SYMBOL(ethtool_op_get_flags); |
3ae7c0b2 | 145 | |
673e63c6 SG |
146 | /* Check if device can enable (or disable) particular feature coded in "data" |
147 | * argument. Flags "supported" describe features that can be toggled by device. | |
148 | * If feature can not be toggled, it state (enabled or disabled) must match | |
149 | * hardcoded device features state, otherwise flags are marked as invalid. | |
150 | */ | |
151 | bool ethtool_invalid_flags(struct net_device *dev, u32 data, u32 supported) | |
152 | { | |
153 | u32 features = dev->features & flags_dup_features; | |
154 | /* "data" can contain only flags_dup_features bits, | |
155 | * see __ethtool_set_flags */ | |
156 | ||
157 | return (features & ~supported) != (data & ~supported); | |
158 | } | |
159 | EXPORT_SYMBOL(ethtool_invalid_flags); | |
160 | ||
1437ce39 | 161 | int ethtool_op_set_flags(struct net_device *dev, u32 data, u32 supported) |
3ae7c0b2 | 162 | { |
673e63c6 | 163 | if (ethtool_invalid_flags(dev, data, supported)) |
1437ce39 | 164 | return -EINVAL; |
0d643e1f | 165 | |
1437ce39 BH |
166 | dev->features = ((dev->features & ~flags_dup_features) | |
167 | (data & flags_dup_features)); | |
3ae7c0b2 JG |
168 | return 0; |
169 | } | |
97f8aefb | 170 | EXPORT_SYMBOL(ethtool_op_set_flags); |
3ae7c0b2 | 171 | |
15682bc4 PWJ |
172 | void ethtool_ntuple_flush(struct net_device *dev) |
173 | { | |
174 | struct ethtool_rx_ntuple_flow_spec_container *fsc, *f; | |
175 | ||
176 | list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) { | |
177 | list_del(&fsc->list); | |
178 | kfree(fsc); | |
179 | } | |
180 | dev->ethtool_ntuple_list.count = 0; | |
181 | } | |
182 | EXPORT_SYMBOL(ethtool_ntuple_flush); | |
183 | ||
1da177e4 LT |
184 | /* Handlers for each ethtool command */ |
185 | ||
5455c699 MM |
186 | #define ETHTOOL_DEV_FEATURE_WORDS 1 |
187 | ||
4e4db200 MM |
188 | static void ethtool_get_features_compat(struct net_device *dev, |
189 | struct ethtool_get_features_block *features) | |
190 | { | |
191 | if (!dev->ethtool_ops) | |
192 | return; | |
193 | ||
194 | /* getting RX checksum */ | |
195 | if (dev->ethtool_ops->get_rx_csum) | |
196 | if (dev->ethtool_ops->get_rx_csum(dev)) | |
197 | features[0].active |= NETIF_F_RXCSUM; | |
39fc0ce5 MM |
198 | |
199 | /* mark legacy-changeable features */ | |
200 | if (dev->ethtool_ops->set_sg) | |
201 | features[0].available |= NETIF_F_SG; | |
202 | if (dev->ethtool_ops->set_tx_csum) | |
203 | features[0].available |= NETIF_F_ALL_CSUM; | |
204 | if (dev->ethtool_ops->set_tso) | |
205 | features[0].available |= NETIF_F_ALL_TSO; | |
206 | if (dev->ethtool_ops->set_rx_csum) | |
207 | features[0].available |= NETIF_F_RXCSUM; | |
208 | if (dev->ethtool_ops->set_flags) | |
209 | features[0].available |= flags_dup_features; | |
210 | } | |
211 | ||
212 | static int ethtool_set_feature_compat(struct net_device *dev, | |
213 | int (*legacy_set)(struct net_device *, u32), | |
214 | struct ethtool_set_features_block *features, u32 mask) | |
215 | { | |
216 | u32 do_set; | |
217 | ||
218 | if (!legacy_set) | |
219 | return 0; | |
220 | ||
221 | if (!(features[0].valid & mask)) | |
222 | return 0; | |
223 | ||
224 | features[0].valid &= ~mask; | |
225 | ||
226 | do_set = !!(features[0].requested & mask); | |
227 | ||
228 | if (legacy_set(dev, do_set) < 0) | |
229 | netdev_info(dev, | |
230 | "Legacy feature change (%s) failed for 0x%08x\n", | |
231 | do_set ? "set" : "clear", mask); | |
232 | ||
233 | return 1; | |
234 | } | |
235 | ||
236 | static int ethtool_set_features_compat(struct net_device *dev, | |
237 | struct ethtool_set_features_block *features) | |
238 | { | |
239 | int compat; | |
240 | ||
241 | if (!dev->ethtool_ops) | |
242 | return 0; | |
243 | ||
244 | compat = ethtool_set_feature_compat(dev, dev->ethtool_ops->set_sg, | |
245 | features, NETIF_F_SG); | |
246 | compat |= ethtool_set_feature_compat(dev, dev->ethtool_ops->set_tx_csum, | |
247 | features, NETIF_F_ALL_CSUM); | |
248 | compat |= ethtool_set_feature_compat(dev, dev->ethtool_ops->set_tso, | |
249 | features, NETIF_F_ALL_TSO); | |
250 | compat |= ethtool_set_feature_compat(dev, dev->ethtool_ops->set_rx_csum, | |
251 | features, NETIF_F_RXCSUM); | |
252 | compat |= ethtool_set_feature_compat(dev, dev->ethtool_ops->set_flags, | |
253 | features, flags_dup_features); | |
254 | ||
255 | return compat; | |
4e4db200 MM |
256 | } |
257 | ||
5455c699 MM |
258 | static int ethtool_get_features(struct net_device *dev, void __user *useraddr) |
259 | { | |
260 | struct ethtool_gfeatures cmd = { | |
261 | .cmd = ETHTOOL_GFEATURES, | |
262 | .size = ETHTOOL_DEV_FEATURE_WORDS, | |
263 | }; | |
264 | struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS] = { | |
265 | { | |
266 | .available = dev->hw_features, | |
267 | .requested = dev->wanted_features, | |
268 | .active = dev->features, | |
269 | .never_changed = NETIF_F_NEVER_CHANGE, | |
270 | }, | |
271 | }; | |
272 | u32 __user *sizeaddr; | |
273 | u32 copy_size; | |
274 | ||
4e4db200 MM |
275 | ethtool_get_features_compat(dev, features); |
276 | ||
5455c699 MM |
277 | sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size); |
278 | if (get_user(copy_size, sizeaddr)) | |
279 | return -EFAULT; | |
280 | ||
281 | if (copy_size > ETHTOOL_DEV_FEATURE_WORDS) | |
282 | copy_size = ETHTOOL_DEV_FEATURE_WORDS; | |
283 | ||
284 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) | |
285 | return -EFAULT; | |
286 | useraddr += sizeof(cmd); | |
287 | if (copy_to_user(useraddr, features, copy_size * sizeof(*features))) | |
288 | return -EFAULT; | |
289 | ||
290 | return 0; | |
291 | } | |
292 | ||
293 | static int ethtool_set_features(struct net_device *dev, void __user *useraddr) | |
294 | { | |
295 | struct ethtool_sfeatures cmd; | |
296 | struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS]; | |
297 | int ret = 0; | |
298 | ||
299 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) | |
300 | return -EFAULT; | |
301 | useraddr += sizeof(cmd); | |
302 | ||
303 | if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS) | |
304 | return -EINVAL; | |
305 | ||
306 | if (copy_from_user(features, useraddr, sizeof(features))) | |
307 | return -EFAULT; | |
308 | ||
309 | if (features[0].valid & ~NETIF_F_ETHTOOL_BITS) | |
310 | return -EINVAL; | |
311 | ||
39fc0ce5 MM |
312 | if (ethtool_set_features_compat(dev, features)) |
313 | ret |= ETHTOOL_F_COMPAT; | |
314 | ||
5455c699 MM |
315 | if (features[0].valid & ~dev->hw_features) { |
316 | features[0].valid &= dev->hw_features; | |
317 | ret |= ETHTOOL_F_UNSUPPORTED; | |
318 | } | |
319 | ||
320 | dev->wanted_features &= ~features[0].valid; | |
321 | dev->wanted_features |= features[0].valid & features[0].requested; | |
6cb6a27c | 322 | __netdev_update_features(dev); |
5455c699 MM |
323 | |
324 | if ((dev->wanted_features ^ dev->features) & features[0].valid) | |
325 | ret |= ETHTOOL_F_WISH; | |
326 | ||
327 | return ret; | |
328 | } | |
329 | ||
330 | static const char netdev_features_strings[ETHTOOL_DEV_FEATURE_WORDS * 32][ETH_GSTRING_LEN] = { | |
331 | /* NETIF_F_SG */ "tx-scatter-gather", | |
332 | /* NETIF_F_IP_CSUM */ "tx-checksum-ipv4", | |
333 | /* NETIF_F_NO_CSUM */ "tx-checksum-unneeded", | |
334 | /* NETIF_F_HW_CSUM */ "tx-checksum-ip-generic", | |
335 | /* NETIF_F_IPV6_CSUM */ "tx_checksum-ipv6", | |
336 | /* NETIF_F_HIGHDMA */ "highdma", | |
337 | /* NETIF_F_FRAGLIST */ "tx-scatter-gather-fraglist", | |
338 | /* NETIF_F_HW_VLAN_TX */ "tx-vlan-hw-insert", | |
339 | ||
340 | /* NETIF_F_HW_VLAN_RX */ "rx-vlan-hw-parse", | |
341 | /* NETIF_F_HW_VLAN_FILTER */ "rx-vlan-filter", | |
342 | /* NETIF_F_VLAN_CHALLENGED */ "vlan-challenged", | |
343 | /* NETIF_F_GSO */ "tx-generic-segmentation", | |
344 | /* NETIF_F_LLTX */ "tx-lockless", | |
345 | /* NETIF_F_NETNS_LOCAL */ "netns-local", | |
346 | /* NETIF_F_GRO */ "rx-gro", | |
347 | /* NETIF_F_LRO */ "rx-lro", | |
348 | ||
349 | /* NETIF_F_TSO */ "tx-tcp-segmentation", | |
350 | /* NETIF_F_UFO */ "tx-udp-fragmentation", | |
351 | /* NETIF_F_GSO_ROBUST */ "tx-gso-robust", | |
352 | /* NETIF_F_TSO_ECN */ "tx-tcp-ecn-segmentation", | |
353 | /* NETIF_F_TSO6 */ "tx-tcp6-segmentation", | |
354 | /* NETIF_F_FSO */ "tx-fcoe-segmentation", | |
355 | "", | |
356 | "", | |
357 | ||
358 | /* NETIF_F_FCOE_CRC */ "tx-checksum-fcoe-crc", | |
359 | /* NETIF_F_SCTP_CSUM */ "tx-checksum-sctp", | |
360 | /* NETIF_F_FCOE_MTU */ "fcoe-mtu", | |
361 | /* NETIF_F_NTUPLE */ "rx-ntuple-filter", | |
362 | /* NETIF_F_RXHASH */ "rx-hashing", | |
e83d360d | 363 | /* NETIF_F_RXCSUM */ "rx-checksum", |
c6e1a0d1 | 364 | /* NETIF_F_NOCACHE_COPY */ "tx-nocache-copy" |
5455c699 MM |
365 | "", |
366 | }; | |
367 | ||
340ae165 MM |
368 | static int __ethtool_get_sset_count(struct net_device *dev, int sset) |
369 | { | |
370 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
371 | ||
5455c699 MM |
372 | if (sset == ETH_SS_FEATURES) |
373 | return ARRAY_SIZE(netdev_features_strings); | |
374 | ||
340ae165 MM |
375 | if (ops && ops->get_sset_count && ops->get_strings) |
376 | return ops->get_sset_count(dev, sset); | |
377 | else | |
378 | return -EOPNOTSUPP; | |
379 | } | |
380 | ||
381 | static void __ethtool_get_strings(struct net_device *dev, | |
382 | u32 stringset, u8 *data) | |
383 | { | |
384 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
385 | ||
5455c699 MM |
386 | if (stringset == ETH_SS_FEATURES) |
387 | memcpy(data, netdev_features_strings, | |
388 | sizeof(netdev_features_strings)); | |
389 | else | |
390 | /* ops->get_strings is valid because checked earlier */ | |
391 | ops->get_strings(dev, stringset, data); | |
340ae165 MM |
392 | } |
393 | ||
0a417704 MM |
394 | static u32 ethtool_get_feature_mask(u32 eth_cmd) |
395 | { | |
396 | /* feature masks of legacy discrete ethtool ops */ | |
397 | ||
398 | switch (eth_cmd) { | |
399 | case ETHTOOL_GTXCSUM: | |
400 | case ETHTOOL_STXCSUM: | |
401 | return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM; | |
e83d360d MM |
402 | case ETHTOOL_GRXCSUM: |
403 | case ETHTOOL_SRXCSUM: | |
404 | return NETIF_F_RXCSUM; | |
0a417704 MM |
405 | case ETHTOOL_GSG: |
406 | case ETHTOOL_SSG: | |
407 | return NETIF_F_SG; | |
408 | case ETHTOOL_GTSO: | |
409 | case ETHTOOL_STSO: | |
410 | return NETIF_F_ALL_TSO; | |
411 | case ETHTOOL_GUFO: | |
412 | case ETHTOOL_SUFO: | |
413 | return NETIF_F_UFO; | |
414 | case ETHTOOL_GGSO: | |
415 | case ETHTOOL_SGSO: | |
416 | return NETIF_F_GSO; | |
417 | case ETHTOOL_GGRO: | |
418 | case ETHTOOL_SGRO: | |
419 | return NETIF_F_GRO; | |
420 | default: | |
421 | BUG(); | |
422 | } | |
423 | } | |
424 | ||
425 | static void *__ethtool_get_one_feature_actor(struct net_device *dev, u32 ethcmd) | |
426 | { | |
427 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
428 | ||
429 | if (!ops) | |
430 | return NULL; | |
431 | ||
432 | switch (ethcmd) { | |
433 | case ETHTOOL_GTXCSUM: | |
434 | return ops->get_tx_csum; | |
e83d360d MM |
435 | case ETHTOOL_GRXCSUM: |
436 | return ops->get_rx_csum; | |
0a417704 MM |
437 | case ETHTOOL_SSG: |
438 | return ops->get_sg; | |
439 | case ETHTOOL_STSO: | |
440 | return ops->get_tso; | |
441 | case ETHTOOL_SUFO: | |
442 | return ops->get_ufo; | |
443 | default: | |
444 | return NULL; | |
445 | } | |
446 | } | |
447 | ||
e83d360d MM |
448 | static u32 __ethtool_get_rx_csum_oldbug(struct net_device *dev) |
449 | { | |
450 | return !!(dev->features & NETIF_F_ALL_CSUM); | |
451 | } | |
452 | ||
0a417704 MM |
453 | static int ethtool_get_one_feature(struct net_device *dev, |
454 | char __user *useraddr, u32 ethcmd) | |
455 | { | |
86794881 | 456 | u32 mask = ethtool_get_feature_mask(ethcmd); |
0a417704 MM |
457 | struct ethtool_value edata = { |
458 | .cmd = ethcmd, | |
86794881 | 459 | .data = !!(dev->features & mask), |
0a417704 | 460 | }; |
0a417704 | 461 | |
86794881 MM |
462 | /* compatibility with discrete get_ ops */ |
463 | if (!(dev->hw_features & mask)) { | |
464 | u32 (*actor)(struct net_device *); | |
465 | ||
466 | actor = __ethtool_get_one_feature_actor(dev, ethcmd); | |
467 | ||
e83d360d MM |
468 | /* bug compatibility with old get_rx_csum */ |
469 | if (ethcmd == ETHTOOL_GRXCSUM && !actor) | |
470 | actor = __ethtool_get_rx_csum_oldbug; | |
471 | ||
86794881 MM |
472 | if (actor) |
473 | edata.data = actor(dev); | |
474 | } | |
0a417704 MM |
475 | |
476 | if (copy_to_user(useraddr, &edata, sizeof(edata))) | |
477 | return -EFAULT; | |
478 | return 0; | |
479 | } | |
480 | ||
481 | static int __ethtool_set_tx_csum(struct net_device *dev, u32 data); | |
e83d360d | 482 | static int __ethtool_set_rx_csum(struct net_device *dev, u32 data); |
0a417704 MM |
483 | static int __ethtool_set_sg(struct net_device *dev, u32 data); |
484 | static int __ethtool_set_tso(struct net_device *dev, u32 data); | |
485 | static int __ethtool_set_ufo(struct net_device *dev, u32 data); | |
486 | ||
487 | static int ethtool_set_one_feature(struct net_device *dev, | |
488 | void __user *useraddr, u32 ethcmd) | |
489 | { | |
490 | struct ethtool_value edata; | |
491 | u32 mask; | |
492 | ||
493 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
494 | return -EFAULT; | |
495 | ||
86794881 MM |
496 | mask = ethtool_get_feature_mask(ethcmd); |
497 | mask &= dev->hw_features; | |
498 | if (mask) { | |
499 | if (edata.data) | |
500 | dev->wanted_features |= mask; | |
501 | else | |
502 | dev->wanted_features &= ~mask; | |
503 | ||
6cb6a27c | 504 | __netdev_update_features(dev); |
86794881 MM |
505 | return 0; |
506 | } | |
507 | ||
508 | /* Driver is not converted to ndo_fix_features or does not | |
509 | * support changing this offload. In the latter case it won't | |
510 | * have corresponding ethtool_ops field set. | |
511 | * | |
512 | * Following part is to be removed after all drivers advertise | |
513 | * their changeable features in netdev->hw_features and stop | |
514 | * using discrete offload setting ops. | |
515 | */ | |
516 | ||
0a417704 MM |
517 | switch (ethcmd) { |
518 | case ETHTOOL_STXCSUM: | |
519 | return __ethtool_set_tx_csum(dev, edata.data); | |
e83d360d MM |
520 | case ETHTOOL_SRXCSUM: |
521 | return __ethtool_set_rx_csum(dev, edata.data); | |
0a417704 MM |
522 | case ETHTOOL_SSG: |
523 | return __ethtool_set_sg(dev, edata.data); | |
524 | case ETHTOOL_STSO: | |
525 | return __ethtool_set_tso(dev, edata.data); | |
526 | case ETHTOOL_SUFO: | |
527 | return __ethtool_set_ufo(dev, edata.data); | |
0a417704 MM |
528 | default: |
529 | return -EOPNOTSUPP; | |
530 | } | |
531 | } | |
532 | ||
27660515 | 533 | int __ethtool_set_flags(struct net_device *dev, u32 data) |
da8ac86c MM |
534 | { |
535 | u32 changed; | |
536 | ||
537 | if (data & ~flags_dup_features) | |
538 | return -EINVAL; | |
539 | ||
540 | /* legacy set_flags() op */ | |
541 | if (dev->ethtool_ops->set_flags) { | |
542 | if (unlikely(dev->hw_features & flags_dup_features)) | |
543 | netdev_warn(dev, | |
544 | "driver BUG: mixed hw_features and set_flags()\n"); | |
545 | return dev->ethtool_ops->set_flags(dev, data); | |
546 | } | |
547 | ||
548 | /* allow changing only bits set in hw_features */ | |
549 | changed = (data ^ dev->wanted_features) & flags_dup_features; | |
550 | if (changed & ~dev->hw_features) | |
551 | return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP; | |
552 | ||
553 | dev->wanted_features = | |
554 | (dev->wanted_features & ~changed) | data; | |
555 | ||
6cb6a27c | 556 | __netdev_update_features(dev); |
da8ac86c MM |
557 | |
558 | return 0; | |
559 | } | |
560 | ||
1da177e4 LT |
561 | static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) |
562 | { | |
8e557421 | 563 | struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET }; |
1da177e4 LT |
564 | int err; |
565 | ||
566 | if (!dev->ethtool_ops->get_settings) | |
567 | return -EOPNOTSUPP; | |
568 | ||
569 | err = dev->ethtool_ops->get_settings(dev, &cmd); | |
570 | if (err < 0) | |
571 | return err; | |
572 | ||
573 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) | |
574 | return -EFAULT; | |
575 | return 0; | |
576 | } | |
577 | ||
578 | static int ethtool_set_settings(struct net_device *dev, void __user *useraddr) | |
579 | { | |
580 | struct ethtool_cmd cmd; | |
581 | ||
582 | if (!dev->ethtool_ops->set_settings) | |
583 | return -EOPNOTSUPP; | |
584 | ||
585 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) | |
586 | return -EFAULT; | |
587 | ||
588 | return dev->ethtool_ops->set_settings(dev, &cmd); | |
589 | } | |
590 | ||
97f8aefb | 591 | static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, |
592 | void __user *useraddr) | |
1da177e4 LT |
593 | { |
594 | struct ethtool_drvinfo info; | |
76fd8593 | 595 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 | 596 | |
1da177e4 LT |
597 | memset(&info, 0, sizeof(info)); |
598 | info.cmd = ETHTOOL_GDRVINFO; | |
01414802 BH |
599 | if (ops && ops->get_drvinfo) { |
600 | ops->get_drvinfo(dev, &info); | |
601 | } else if (dev->dev.parent && dev->dev.parent->driver) { | |
602 | strlcpy(info.bus_info, dev_name(dev->dev.parent), | |
603 | sizeof(info.bus_info)); | |
604 | strlcpy(info.driver, dev->dev.parent->driver->name, | |
605 | sizeof(info.driver)); | |
606 | } else { | |
607 | return -EOPNOTSUPP; | |
608 | } | |
1da177e4 | 609 | |
723b2f57 JG |
610 | /* |
611 | * this method of obtaining string set info is deprecated; | |
d17792eb | 612 | * Use ETHTOOL_GSSET_INFO instead. |
723b2f57 | 613 | */ |
01414802 | 614 | if (ops && ops->get_sset_count) { |
ff03d49f JG |
615 | int rc; |
616 | ||
617 | rc = ops->get_sset_count(dev, ETH_SS_TEST); | |
618 | if (rc >= 0) | |
619 | info.testinfo_len = rc; | |
620 | rc = ops->get_sset_count(dev, ETH_SS_STATS); | |
621 | if (rc >= 0) | |
622 | info.n_stats = rc; | |
339bf024 JG |
623 | rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS); |
624 | if (rc >= 0) | |
625 | info.n_priv_flags = rc; | |
ff03d49f | 626 | } |
01414802 | 627 | if (ops && ops->get_regs_len) |
1da177e4 | 628 | info.regdump_len = ops->get_regs_len(dev); |
01414802 | 629 | if (ops && ops->get_eeprom_len) |
1da177e4 LT |
630 | info.eedump_len = ops->get_eeprom_len(dev); |
631 | ||
632 | if (copy_to_user(useraddr, &info, sizeof(info))) | |
633 | return -EFAULT; | |
634 | return 0; | |
635 | } | |
636 | ||
f5c445ed | 637 | static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, |
97f8aefb | 638 | void __user *useraddr) |
723b2f57 JG |
639 | { |
640 | struct ethtool_sset_info info; | |
723b2f57 JG |
641 | u64 sset_mask; |
642 | int i, idx = 0, n_bits = 0, ret, rc; | |
643 | u32 *info_buf = NULL; | |
644 | ||
723b2f57 JG |
645 | if (copy_from_user(&info, useraddr, sizeof(info))) |
646 | return -EFAULT; | |
647 | ||
648 | /* store copy of mask, because we zero struct later on */ | |
649 | sset_mask = info.sset_mask; | |
650 | if (!sset_mask) | |
651 | return 0; | |
652 | ||
653 | /* calculate size of return buffer */ | |
d17792eb | 654 | n_bits = hweight64(sset_mask); |
723b2f57 JG |
655 | |
656 | memset(&info, 0, sizeof(info)); | |
657 | info.cmd = ETHTOOL_GSSET_INFO; | |
658 | ||
659 | info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER); | |
660 | if (!info_buf) | |
661 | return -ENOMEM; | |
662 | ||
663 | /* | |
664 | * fill return buffer based on input bitmask and successful | |
665 | * get_sset_count return | |
666 | */ | |
667 | for (i = 0; i < 64; i++) { | |
668 | if (!(sset_mask & (1ULL << i))) | |
669 | continue; | |
670 | ||
340ae165 | 671 | rc = __ethtool_get_sset_count(dev, i); |
723b2f57 JG |
672 | if (rc >= 0) { |
673 | info.sset_mask |= (1ULL << i); | |
674 | info_buf[idx++] = rc; | |
675 | } | |
676 | } | |
677 | ||
678 | ret = -EFAULT; | |
679 | if (copy_to_user(useraddr, &info, sizeof(info))) | |
680 | goto out; | |
681 | ||
682 | useraddr += offsetof(struct ethtool_sset_info, data); | |
683 | if (copy_to_user(useraddr, info_buf, idx * sizeof(u32))) | |
684 | goto out; | |
685 | ||
686 | ret = 0; | |
687 | ||
688 | out: | |
689 | kfree(info_buf); | |
690 | return ret; | |
691 | } | |
692 | ||
97f8aefb | 693 | static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, |
bf988435 | 694 | u32 cmd, void __user *useraddr) |
0853ad66 | 695 | { |
bf988435 BH |
696 | struct ethtool_rxnfc info; |
697 | size_t info_size = sizeof(info); | |
0853ad66 | 698 | |
59089d8d | 699 | if (!dev->ethtool_ops->set_rxnfc) |
0853ad66 SB |
700 | return -EOPNOTSUPP; |
701 | ||
bf988435 BH |
702 | /* struct ethtool_rxnfc was originally defined for |
703 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data | |
704 | * members. User-space might still be using that | |
705 | * definition. */ | |
706 | if (cmd == ETHTOOL_SRXFH) | |
707 | info_size = (offsetof(struct ethtool_rxnfc, data) + | |
708 | sizeof(info.data)); | |
709 | ||
710 | if (copy_from_user(&info, useraddr, info_size)) | |
0853ad66 SB |
711 | return -EFAULT; |
712 | ||
bf988435 | 713 | return dev->ethtool_ops->set_rxnfc(dev, &info); |
0853ad66 SB |
714 | } |
715 | ||
97f8aefb | 716 | static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, |
bf988435 | 717 | u32 cmd, void __user *useraddr) |
0853ad66 SB |
718 | { |
719 | struct ethtool_rxnfc info; | |
bf988435 | 720 | size_t info_size = sizeof(info); |
59089d8d SB |
721 | const struct ethtool_ops *ops = dev->ethtool_ops; |
722 | int ret; | |
723 | void *rule_buf = NULL; | |
0853ad66 | 724 | |
59089d8d | 725 | if (!ops->get_rxnfc) |
0853ad66 SB |
726 | return -EOPNOTSUPP; |
727 | ||
bf988435 BH |
728 | /* struct ethtool_rxnfc was originally defined for |
729 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data | |
730 | * members. User-space might still be using that | |
731 | * definition. */ | |
732 | if (cmd == ETHTOOL_GRXFH) | |
733 | info_size = (offsetof(struct ethtool_rxnfc, data) + | |
734 | sizeof(info.data)); | |
735 | ||
736 | if (copy_from_user(&info, useraddr, info_size)) | |
0853ad66 SB |
737 | return -EFAULT; |
738 | ||
59089d8d SB |
739 | if (info.cmd == ETHTOOL_GRXCLSRLALL) { |
740 | if (info.rule_cnt > 0) { | |
db048b69 | 741 | if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32)) |
ae6df5f9 | 742 | rule_buf = kzalloc(info.rule_cnt * sizeof(u32), |
db048b69 | 743 | GFP_USER); |
59089d8d SB |
744 | if (!rule_buf) |
745 | return -ENOMEM; | |
746 | } | |
747 | } | |
0853ad66 | 748 | |
59089d8d SB |
749 | ret = ops->get_rxnfc(dev, &info, rule_buf); |
750 | if (ret < 0) | |
751 | goto err_out; | |
752 | ||
753 | ret = -EFAULT; | |
bf988435 | 754 | if (copy_to_user(useraddr, &info, info_size)) |
59089d8d SB |
755 | goto err_out; |
756 | ||
757 | if (rule_buf) { | |
758 | useraddr += offsetof(struct ethtool_rxnfc, rule_locs); | |
759 | if (copy_to_user(useraddr, rule_buf, | |
760 | info.rule_cnt * sizeof(u32))) | |
761 | goto err_out; | |
762 | } | |
763 | ret = 0; | |
764 | ||
765 | err_out: | |
c9caceca | 766 | kfree(rule_buf); |
59089d8d SB |
767 | |
768 | return ret; | |
0853ad66 SB |
769 | } |
770 | ||
a5b6ee29 BH |
771 | static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev, |
772 | void __user *useraddr) | |
773 | { | |
774 | struct ethtool_rxfh_indir *indir; | |
775 | u32 table_size; | |
776 | size_t full_size; | |
777 | int ret; | |
778 | ||
779 | if (!dev->ethtool_ops->get_rxfh_indir) | |
780 | return -EOPNOTSUPP; | |
781 | ||
782 | if (copy_from_user(&table_size, | |
783 | useraddr + offsetof(struct ethtool_rxfh_indir, size), | |
784 | sizeof(table_size))) | |
785 | return -EFAULT; | |
786 | ||
787 | if (table_size > | |
788 | (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index)) | |
789 | return -ENOMEM; | |
790 | full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size; | |
b00916b1 | 791 | indir = kzalloc(full_size, GFP_USER); |
a5b6ee29 BH |
792 | if (!indir) |
793 | return -ENOMEM; | |
794 | ||
795 | indir->cmd = ETHTOOL_GRXFHINDIR; | |
796 | indir->size = table_size; | |
797 | ret = dev->ethtool_ops->get_rxfh_indir(dev, indir); | |
798 | if (ret) | |
799 | goto out; | |
800 | ||
801 | if (copy_to_user(useraddr, indir, full_size)) | |
802 | ret = -EFAULT; | |
803 | ||
804 | out: | |
805 | kfree(indir); | |
806 | return ret; | |
807 | } | |
808 | ||
809 | static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev, | |
810 | void __user *useraddr) | |
811 | { | |
812 | struct ethtool_rxfh_indir *indir; | |
813 | u32 table_size; | |
814 | size_t full_size; | |
815 | int ret; | |
816 | ||
817 | if (!dev->ethtool_ops->set_rxfh_indir) | |
818 | return -EOPNOTSUPP; | |
819 | ||
820 | if (copy_from_user(&table_size, | |
821 | useraddr + offsetof(struct ethtool_rxfh_indir, size), | |
822 | sizeof(table_size))) | |
823 | return -EFAULT; | |
824 | ||
825 | if (table_size > | |
826 | (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index)) | |
827 | return -ENOMEM; | |
828 | full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size; | |
829 | indir = kmalloc(full_size, GFP_USER); | |
830 | if (!indir) | |
831 | return -ENOMEM; | |
832 | ||
833 | if (copy_from_user(indir, useraddr, full_size)) { | |
834 | ret = -EFAULT; | |
835 | goto out; | |
836 | } | |
837 | ||
838 | ret = dev->ethtool_ops->set_rxfh_indir(dev, indir); | |
839 | ||
840 | out: | |
841 | kfree(indir); | |
842 | return ret; | |
843 | } | |
844 | ||
e8589118 | 845 | static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list, |
97f8aefb | 846 | struct ethtool_rx_ntuple_flow_spec *spec, |
847 | struct ethtool_rx_ntuple_flow_spec_container *fsc) | |
15682bc4 | 848 | { |
15682bc4 PWJ |
849 | |
850 | /* don't add filters forever */ | |
e8589118 PW |
851 | if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) { |
852 | /* free the container */ | |
853 | kfree(fsc); | |
854 | return; | |
855 | } | |
15682bc4 PWJ |
856 | |
857 | /* Copy the whole filter over */ | |
858 | fsc->fs.flow_type = spec->flow_type; | |
859 | memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u)); | |
860 | memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u)); | |
861 | ||
862 | fsc->fs.vlan_tag = spec->vlan_tag; | |
863 | fsc->fs.vlan_tag_mask = spec->vlan_tag_mask; | |
864 | fsc->fs.data = spec->data; | |
865 | fsc->fs.data_mask = spec->data_mask; | |
866 | fsc->fs.action = spec->action; | |
867 | ||
868 | /* add to the list */ | |
869 | list_add_tail_rcu(&fsc->list, &list->list); | |
870 | list->count++; | |
15682bc4 PWJ |
871 | } |
872 | ||
be2902da BH |
873 | /* |
874 | * ethtool does not (or did not) set masks for flow parameters that are | |
875 | * not specified, so if both value and mask are 0 then this must be | |
876 | * treated as equivalent to a mask with all bits set. Implement that | |
877 | * here rather than in drivers. | |
878 | */ | |
879 | static void rx_ntuple_fix_masks(struct ethtool_rx_ntuple_flow_spec *fs) | |
880 | { | |
881 | struct ethtool_tcpip4_spec *entry = &fs->h_u.tcp_ip4_spec; | |
882 | struct ethtool_tcpip4_spec *mask = &fs->m_u.tcp_ip4_spec; | |
883 | ||
884 | if (fs->flow_type != TCP_V4_FLOW && | |
885 | fs->flow_type != UDP_V4_FLOW && | |
886 | fs->flow_type != SCTP_V4_FLOW) | |
887 | return; | |
888 | ||
889 | if (!(entry->ip4src | mask->ip4src)) | |
890 | mask->ip4src = htonl(0xffffffff); | |
891 | if (!(entry->ip4dst | mask->ip4dst)) | |
892 | mask->ip4dst = htonl(0xffffffff); | |
893 | if (!(entry->psrc | mask->psrc)) | |
894 | mask->psrc = htons(0xffff); | |
895 | if (!(entry->pdst | mask->pdst)) | |
896 | mask->pdst = htons(0xffff); | |
897 | if (!(entry->tos | mask->tos)) | |
898 | mask->tos = 0xff; | |
899 | if (!(fs->vlan_tag | fs->vlan_tag_mask)) | |
900 | fs->vlan_tag_mask = 0xffff; | |
901 | if (!(fs->data | fs->data_mask)) | |
902 | fs->data_mask = 0xffffffffffffffffULL; | |
903 | } | |
904 | ||
97f8aefb | 905 | static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev, |
906 | void __user *useraddr) | |
15682bc4 PWJ |
907 | { |
908 | struct ethtool_rx_ntuple cmd; | |
909 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
e8589118 | 910 | struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL; |
15682bc4 PWJ |
911 | int ret; |
912 | ||
5d9f11cf AD |
913 | if (!ops->set_rx_ntuple) |
914 | return -EOPNOTSUPP; | |
915 | ||
15682bc4 PWJ |
916 | if (!(dev->features & NETIF_F_NTUPLE)) |
917 | return -EINVAL; | |
918 | ||
919 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) | |
920 | return -EFAULT; | |
921 | ||
be2902da BH |
922 | rx_ntuple_fix_masks(&cmd.fs); |
923 | ||
15682bc4 PWJ |
924 | /* |
925 | * Cache filter in dev struct for GET operation only if | |
926 | * the underlying driver doesn't have its own GET operation, and | |
e8589118 PW |
927 | * only if the filter was added successfully. First make sure we |
928 | * can allocate the filter, then continue if successful. | |
15682bc4 | 929 | */ |
e8589118 PW |
930 | if (!ops->get_rx_ntuple) { |
931 | fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC); | |
932 | if (!fsc) | |
15682bc4 | 933 | return -ENOMEM; |
e8589118 PW |
934 | } |
935 | ||
936 | ret = ops->set_rx_ntuple(dev, &cmd); | |
937 | if (ret) { | |
938 | kfree(fsc); | |
939 | return ret; | |
940 | } | |
941 | ||
942 | if (!ops->get_rx_ntuple) | |
943 | __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc); | |
15682bc4 PWJ |
944 | |
945 | return ret; | |
946 | } | |
947 | ||
948 | static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr) | |
949 | { | |
950 | struct ethtool_gstrings gstrings; | |
951 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
952 | struct ethtool_rx_ntuple_flow_spec_container *fsc; | |
953 | u8 *data; | |
954 | char *p; | |
955 | int ret, i, num_strings = 0; | |
956 | ||
957 | if (!ops->get_sset_count) | |
958 | return -EOPNOTSUPP; | |
959 | ||
960 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) | |
961 | return -EFAULT; | |
962 | ||
963 | ret = ops->get_sset_count(dev, gstrings.string_set); | |
964 | if (ret < 0) | |
965 | return ret; | |
966 | ||
967 | gstrings.len = ret; | |
968 | ||
b00916b1 | 969 | data = kzalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER); |
15682bc4 PWJ |
970 | if (!data) |
971 | return -ENOMEM; | |
972 | ||
973 | if (ops->get_rx_ntuple) { | |
974 | /* driver-specific filter grab */ | |
975 | ret = ops->get_rx_ntuple(dev, gstrings.string_set, data); | |
976 | goto copy; | |
977 | } | |
978 | ||
979 | /* default ethtool filter grab */ | |
980 | i = 0; | |
981 | p = (char *)data; | |
982 | list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) { | |
983 | sprintf(p, "Filter %d:\n", i); | |
984 | p += ETH_GSTRING_LEN; | |
985 | num_strings++; | |
986 | ||
987 | switch (fsc->fs.flow_type) { | |
988 | case TCP_V4_FLOW: | |
989 | sprintf(p, "\tFlow Type: TCP\n"); | |
990 | p += ETH_GSTRING_LEN; | |
991 | num_strings++; | |
992 | break; | |
993 | case UDP_V4_FLOW: | |
994 | sprintf(p, "\tFlow Type: UDP\n"); | |
995 | p += ETH_GSTRING_LEN; | |
996 | num_strings++; | |
997 | break; | |
998 | case SCTP_V4_FLOW: | |
999 | sprintf(p, "\tFlow Type: SCTP\n"); | |
1000 | p += ETH_GSTRING_LEN; | |
1001 | num_strings++; | |
1002 | break; | |
1003 | case AH_ESP_V4_FLOW: | |
1004 | sprintf(p, "\tFlow Type: AH ESP\n"); | |
1005 | p += ETH_GSTRING_LEN; | |
1006 | num_strings++; | |
1007 | break; | |
1008 | case ESP_V4_FLOW: | |
1009 | sprintf(p, "\tFlow Type: ESP\n"); | |
1010 | p += ETH_GSTRING_LEN; | |
1011 | num_strings++; | |
1012 | break; | |
1013 | case IP_USER_FLOW: | |
1014 | sprintf(p, "\tFlow Type: Raw IP\n"); | |
1015 | p += ETH_GSTRING_LEN; | |
1016 | num_strings++; | |
1017 | break; | |
1018 | case IPV4_FLOW: | |
1019 | sprintf(p, "\tFlow Type: IPv4\n"); | |
1020 | p += ETH_GSTRING_LEN; | |
1021 | num_strings++; | |
1022 | break; | |
1023 | default: | |
1024 | sprintf(p, "\tFlow Type: Unknown\n"); | |
1025 | p += ETH_GSTRING_LEN; | |
1026 | num_strings++; | |
1027 | goto unknown_filter; | |
ccbd6a5a | 1028 | } |
15682bc4 PWJ |
1029 | |
1030 | /* now the rest of the filters */ | |
1031 | switch (fsc->fs.flow_type) { | |
1032 | case TCP_V4_FLOW: | |
1033 | case UDP_V4_FLOW: | |
1034 | case SCTP_V4_FLOW: | |
1035 | sprintf(p, "\tSrc IP addr: 0x%x\n", | |
97f8aefb | 1036 | fsc->fs.h_u.tcp_ip4_spec.ip4src); |
15682bc4 PWJ |
1037 | p += ETH_GSTRING_LEN; |
1038 | num_strings++; | |
1039 | sprintf(p, "\tSrc IP mask: 0x%x\n", | |
97f8aefb | 1040 | fsc->fs.m_u.tcp_ip4_spec.ip4src); |
15682bc4 PWJ |
1041 | p += ETH_GSTRING_LEN; |
1042 | num_strings++; | |
1043 | sprintf(p, "\tDest IP addr: 0x%x\n", | |
97f8aefb | 1044 | fsc->fs.h_u.tcp_ip4_spec.ip4dst); |
15682bc4 PWJ |
1045 | p += ETH_GSTRING_LEN; |
1046 | num_strings++; | |
1047 | sprintf(p, "\tDest IP mask: 0x%x\n", | |
97f8aefb | 1048 | fsc->fs.m_u.tcp_ip4_spec.ip4dst); |
15682bc4 PWJ |
1049 | p += ETH_GSTRING_LEN; |
1050 | num_strings++; | |
1051 | sprintf(p, "\tSrc Port: %d, mask: 0x%x\n", | |
97f8aefb | 1052 | fsc->fs.h_u.tcp_ip4_spec.psrc, |
1053 | fsc->fs.m_u.tcp_ip4_spec.psrc); | |
15682bc4 PWJ |
1054 | p += ETH_GSTRING_LEN; |
1055 | num_strings++; | |
1056 | sprintf(p, "\tDest Port: %d, mask: 0x%x\n", | |
97f8aefb | 1057 | fsc->fs.h_u.tcp_ip4_spec.pdst, |
1058 | fsc->fs.m_u.tcp_ip4_spec.pdst); | |
15682bc4 PWJ |
1059 | p += ETH_GSTRING_LEN; |
1060 | num_strings++; | |
1061 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", | |
97f8aefb | 1062 | fsc->fs.h_u.tcp_ip4_spec.tos, |
1063 | fsc->fs.m_u.tcp_ip4_spec.tos); | |
15682bc4 PWJ |
1064 | p += ETH_GSTRING_LEN; |
1065 | num_strings++; | |
1066 | break; | |
1067 | case AH_ESP_V4_FLOW: | |
1068 | case ESP_V4_FLOW: | |
1069 | sprintf(p, "\tSrc IP addr: 0x%x\n", | |
97f8aefb | 1070 | fsc->fs.h_u.ah_ip4_spec.ip4src); |
15682bc4 PWJ |
1071 | p += ETH_GSTRING_LEN; |
1072 | num_strings++; | |
1073 | sprintf(p, "\tSrc IP mask: 0x%x\n", | |
97f8aefb | 1074 | fsc->fs.m_u.ah_ip4_spec.ip4src); |
15682bc4 PWJ |
1075 | p += ETH_GSTRING_LEN; |
1076 | num_strings++; | |
1077 | sprintf(p, "\tDest IP addr: 0x%x\n", | |
97f8aefb | 1078 | fsc->fs.h_u.ah_ip4_spec.ip4dst); |
15682bc4 PWJ |
1079 | p += ETH_GSTRING_LEN; |
1080 | num_strings++; | |
1081 | sprintf(p, "\tDest IP mask: 0x%x\n", | |
97f8aefb | 1082 | fsc->fs.m_u.ah_ip4_spec.ip4dst); |
15682bc4 PWJ |
1083 | p += ETH_GSTRING_LEN; |
1084 | num_strings++; | |
1085 | sprintf(p, "\tSPI: %d, mask: 0x%x\n", | |
97f8aefb | 1086 | fsc->fs.h_u.ah_ip4_spec.spi, |
1087 | fsc->fs.m_u.ah_ip4_spec.spi); | |
15682bc4 PWJ |
1088 | p += ETH_GSTRING_LEN; |
1089 | num_strings++; | |
1090 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", | |
97f8aefb | 1091 | fsc->fs.h_u.ah_ip4_spec.tos, |
1092 | fsc->fs.m_u.ah_ip4_spec.tos); | |
15682bc4 PWJ |
1093 | p += ETH_GSTRING_LEN; |
1094 | num_strings++; | |
1095 | break; | |
1096 | case IP_USER_FLOW: | |
1097 | sprintf(p, "\tSrc IP addr: 0x%x\n", | |
e0de7c93 | 1098 | fsc->fs.h_u.usr_ip4_spec.ip4src); |
15682bc4 PWJ |
1099 | p += ETH_GSTRING_LEN; |
1100 | num_strings++; | |
1101 | sprintf(p, "\tSrc IP mask: 0x%x\n", | |
e0de7c93 | 1102 | fsc->fs.m_u.usr_ip4_spec.ip4src); |
15682bc4 PWJ |
1103 | p += ETH_GSTRING_LEN; |
1104 | num_strings++; | |
1105 | sprintf(p, "\tDest IP addr: 0x%x\n", | |
e0de7c93 | 1106 | fsc->fs.h_u.usr_ip4_spec.ip4dst); |
15682bc4 PWJ |
1107 | p += ETH_GSTRING_LEN; |
1108 | num_strings++; | |
1109 | sprintf(p, "\tDest IP mask: 0x%x\n", | |
e0de7c93 | 1110 | fsc->fs.m_u.usr_ip4_spec.ip4dst); |
15682bc4 PWJ |
1111 | p += ETH_GSTRING_LEN; |
1112 | num_strings++; | |
1113 | break; | |
1114 | case IPV4_FLOW: | |
1115 | sprintf(p, "\tSrc IP addr: 0x%x\n", | |
97f8aefb | 1116 | fsc->fs.h_u.usr_ip4_spec.ip4src); |
15682bc4 PWJ |
1117 | p += ETH_GSTRING_LEN; |
1118 | num_strings++; | |
1119 | sprintf(p, "\tSrc IP mask: 0x%x\n", | |
97f8aefb | 1120 | fsc->fs.m_u.usr_ip4_spec.ip4src); |
15682bc4 PWJ |
1121 | p += ETH_GSTRING_LEN; |
1122 | num_strings++; | |
1123 | sprintf(p, "\tDest IP addr: 0x%x\n", | |
97f8aefb | 1124 | fsc->fs.h_u.usr_ip4_spec.ip4dst); |
15682bc4 PWJ |
1125 | p += ETH_GSTRING_LEN; |
1126 | num_strings++; | |
1127 | sprintf(p, "\tDest IP mask: 0x%x\n", | |
97f8aefb | 1128 | fsc->fs.m_u.usr_ip4_spec.ip4dst); |
15682bc4 PWJ |
1129 | p += ETH_GSTRING_LEN; |
1130 | num_strings++; | |
1131 | sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n", | |
97f8aefb | 1132 | fsc->fs.h_u.usr_ip4_spec.l4_4_bytes, |
1133 | fsc->fs.m_u.usr_ip4_spec.l4_4_bytes); | |
15682bc4 PWJ |
1134 | p += ETH_GSTRING_LEN; |
1135 | num_strings++; | |
1136 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", | |
97f8aefb | 1137 | fsc->fs.h_u.usr_ip4_spec.tos, |
1138 | fsc->fs.m_u.usr_ip4_spec.tos); | |
15682bc4 PWJ |
1139 | p += ETH_GSTRING_LEN; |
1140 | num_strings++; | |
1141 | sprintf(p, "\tIP Version: %d, mask: 0x%x\n", | |
97f8aefb | 1142 | fsc->fs.h_u.usr_ip4_spec.ip_ver, |
1143 | fsc->fs.m_u.usr_ip4_spec.ip_ver); | |
15682bc4 PWJ |
1144 | p += ETH_GSTRING_LEN; |
1145 | num_strings++; | |
1146 | sprintf(p, "\tProtocol: %d, mask: 0x%x\n", | |
97f8aefb | 1147 | fsc->fs.h_u.usr_ip4_spec.proto, |
1148 | fsc->fs.m_u.usr_ip4_spec.proto); | |
15682bc4 PWJ |
1149 | p += ETH_GSTRING_LEN; |
1150 | num_strings++; | |
1151 | break; | |
ccbd6a5a | 1152 | } |
15682bc4 | 1153 | sprintf(p, "\tVLAN: %d, mask: 0x%x\n", |
97f8aefb | 1154 | fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask); |
15682bc4 PWJ |
1155 | p += ETH_GSTRING_LEN; |
1156 | num_strings++; | |
1157 | sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data); | |
1158 | p += ETH_GSTRING_LEN; | |
1159 | num_strings++; | |
1160 | sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask); | |
1161 | p += ETH_GSTRING_LEN; | |
1162 | num_strings++; | |
1163 | if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP) | |
1164 | sprintf(p, "\tAction: Drop\n"); | |
1165 | else | |
1166 | sprintf(p, "\tAction: Direct to queue %d\n", | |
97f8aefb | 1167 | fsc->fs.action); |
15682bc4 PWJ |
1168 | p += ETH_GSTRING_LEN; |
1169 | num_strings++; | |
1170 | unknown_filter: | |
1171 | i++; | |
1172 | } | |
1173 | copy: | |
1174 | /* indicate to userspace how many strings we actually have */ | |
1175 | gstrings.len = num_strings; | |
1176 | ret = -EFAULT; | |
1177 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) | |
1178 | goto out; | |
1179 | useraddr += sizeof(gstrings); | |
1180 | if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN)) | |
1181 | goto out; | |
1182 | ret = 0; | |
1183 | ||
1184 | out: | |
1185 | kfree(data); | |
1186 | return ret; | |
1187 | } | |
1188 | ||
1da177e4 LT |
1189 | static int ethtool_get_regs(struct net_device *dev, char __user *useraddr) |
1190 | { | |
1191 | struct ethtool_regs regs; | |
76fd8593 | 1192 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 LT |
1193 | void *regbuf; |
1194 | int reglen, ret; | |
1195 | ||
1196 | if (!ops->get_regs || !ops->get_regs_len) | |
1197 | return -EOPNOTSUPP; | |
1198 | ||
1199 | if (copy_from_user(®s, useraddr, sizeof(regs))) | |
1200 | return -EFAULT; | |
1201 | ||
1202 | reglen = ops->get_regs_len(dev); | |
1203 | if (regs.len > reglen) | |
1204 | regs.len = reglen; | |
1205 | ||
b7c7d01a | 1206 | regbuf = vzalloc(reglen); |
1da177e4 LT |
1207 | if (!regbuf) |
1208 | return -ENOMEM; | |
1209 | ||
1210 | ops->get_regs(dev, ®s, regbuf); | |
1211 | ||
1212 | ret = -EFAULT; | |
1213 | if (copy_to_user(useraddr, ®s, sizeof(regs))) | |
1214 | goto out; | |
1215 | useraddr += offsetof(struct ethtool_regs, data); | |
1216 | if (copy_to_user(useraddr, regbuf, regs.len)) | |
1217 | goto out; | |
1218 | ret = 0; | |
1219 | ||
1220 | out: | |
a77f5db3 | 1221 | vfree(regbuf); |
1da177e4 LT |
1222 | return ret; |
1223 | } | |
1224 | ||
d73d3a8c BH |
1225 | static int ethtool_reset(struct net_device *dev, char __user *useraddr) |
1226 | { | |
1227 | struct ethtool_value reset; | |
1228 | int ret; | |
1229 | ||
1230 | if (!dev->ethtool_ops->reset) | |
1231 | return -EOPNOTSUPP; | |
1232 | ||
1233 | if (copy_from_user(&reset, useraddr, sizeof(reset))) | |
1234 | return -EFAULT; | |
1235 | ||
1236 | ret = dev->ethtool_ops->reset(dev, &reset.data); | |
1237 | if (ret) | |
1238 | return ret; | |
1239 | ||
1240 | if (copy_to_user(useraddr, &reset, sizeof(reset))) | |
1241 | return -EFAULT; | |
1242 | return 0; | |
1243 | } | |
1244 | ||
1da177e4 LT |
1245 | static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) |
1246 | { | |
8e557421 | 1247 | struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; |
1da177e4 LT |
1248 | |
1249 | if (!dev->ethtool_ops->get_wol) | |
1250 | return -EOPNOTSUPP; | |
1251 | ||
1252 | dev->ethtool_ops->get_wol(dev, &wol); | |
1253 | ||
1254 | if (copy_to_user(useraddr, &wol, sizeof(wol))) | |
1255 | return -EFAULT; | |
1256 | return 0; | |
1257 | } | |
1258 | ||
1259 | static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) | |
1260 | { | |
1261 | struct ethtool_wolinfo wol; | |
1262 | ||
1263 | if (!dev->ethtool_ops->set_wol) | |
1264 | return -EOPNOTSUPP; | |
1265 | ||
1266 | if (copy_from_user(&wol, useraddr, sizeof(wol))) | |
1267 | return -EFAULT; | |
1268 | ||
1269 | return dev->ethtool_ops->set_wol(dev, &wol); | |
1270 | } | |
1271 | ||
1da177e4 LT |
1272 | static int ethtool_nway_reset(struct net_device *dev) |
1273 | { | |
1274 | if (!dev->ethtool_ops->nway_reset) | |
1275 | return -EOPNOTSUPP; | |
1276 | ||
1277 | return dev->ethtool_ops->nway_reset(dev); | |
1278 | } | |
1279 | ||
e596e6e4 BH |
1280 | static int ethtool_get_link(struct net_device *dev, char __user *useraddr) |
1281 | { | |
1282 | struct ethtool_value edata = { .cmd = ETHTOOL_GLINK }; | |
1283 | ||
1284 | if (!dev->ethtool_ops->get_link) | |
1285 | return -EOPNOTSUPP; | |
1286 | ||
1287 | edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev); | |
1288 | ||
1289 | if (copy_to_user(useraddr, &edata, sizeof(edata))) | |
1290 | return -EFAULT; | |
1291 | return 0; | |
1292 | } | |
1293 | ||
1da177e4 LT |
1294 | static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr) |
1295 | { | |
1296 | struct ethtool_eeprom eeprom; | |
76fd8593 | 1297 | const struct ethtool_ops *ops = dev->ethtool_ops; |
b131dd5d MSB |
1298 | void __user *userbuf = useraddr + sizeof(eeprom); |
1299 | u32 bytes_remaining; | |
1da177e4 | 1300 | u8 *data; |
b131dd5d | 1301 | int ret = 0; |
1da177e4 LT |
1302 | |
1303 | if (!ops->get_eeprom || !ops->get_eeprom_len) | |
1304 | return -EOPNOTSUPP; | |
1305 | ||
1306 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) | |
1307 | return -EFAULT; | |
1308 | ||
1309 | /* Check for wrap and zero */ | |
1310 | if (eeprom.offset + eeprom.len <= eeprom.offset) | |
1311 | return -EINVAL; | |
1312 | ||
1313 | /* Check for exceeding total eeprom len */ | |
1314 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) | |
1315 | return -EINVAL; | |
1316 | ||
b131dd5d | 1317 | data = kmalloc(PAGE_SIZE, GFP_USER); |
1da177e4 LT |
1318 | if (!data) |
1319 | return -ENOMEM; | |
1320 | ||
b131dd5d MSB |
1321 | bytes_remaining = eeprom.len; |
1322 | while (bytes_remaining > 0) { | |
1323 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); | |
1324 | ||
1325 | ret = ops->get_eeprom(dev, &eeprom, data); | |
1326 | if (ret) | |
1327 | break; | |
1328 | if (copy_to_user(userbuf, data, eeprom.len)) { | |
1329 | ret = -EFAULT; | |
1330 | break; | |
1331 | } | |
1332 | userbuf += eeprom.len; | |
1333 | eeprom.offset += eeprom.len; | |
1334 | bytes_remaining -= eeprom.len; | |
1335 | } | |
1da177e4 | 1336 | |
c5835df9 MSB |
1337 | eeprom.len = userbuf - (useraddr + sizeof(eeprom)); |
1338 | eeprom.offset -= eeprom.len; | |
1339 | if (copy_to_user(useraddr, &eeprom, sizeof(eeprom))) | |
1340 | ret = -EFAULT; | |
1341 | ||
1da177e4 LT |
1342 | kfree(data); |
1343 | return ret; | |
1344 | } | |
1345 | ||
1346 | static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr) | |
1347 | { | |
1348 | struct ethtool_eeprom eeprom; | |
76fd8593 | 1349 | const struct ethtool_ops *ops = dev->ethtool_ops; |
b131dd5d MSB |
1350 | void __user *userbuf = useraddr + sizeof(eeprom); |
1351 | u32 bytes_remaining; | |
1da177e4 | 1352 | u8 *data; |
b131dd5d | 1353 | int ret = 0; |
1da177e4 LT |
1354 | |
1355 | if (!ops->set_eeprom || !ops->get_eeprom_len) | |
1356 | return -EOPNOTSUPP; | |
1357 | ||
1358 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) | |
1359 | return -EFAULT; | |
1360 | ||
1361 | /* Check for wrap and zero */ | |
1362 | if (eeprom.offset + eeprom.len <= eeprom.offset) | |
1363 | return -EINVAL; | |
1364 | ||
1365 | /* Check for exceeding total eeprom len */ | |
1366 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) | |
1367 | return -EINVAL; | |
1368 | ||
b131dd5d | 1369 | data = kmalloc(PAGE_SIZE, GFP_USER); |
1da177e4 LT |
1370 | if (!data) |
1371 | return -ENOMEM; | |
1372 | ||
b131dd5d MSB |
1373 | bytes_remaining = eeprom.len; |
1374 | while (bytes_remaining > 0) { | |
1375 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); | |
1376 | ||
1377 | if (copy_from_user(data, userbuf, eeprom.len)) { | |
1378 | ret = -EFAULT; | |
1379 | break; | |
1380 | } | |
1381 | ret = ops->set_eeprom(dev, &eeprom, data); | |
1382 | if (ret) | |
1383 | break; | |
1384 | userbuf += eeprom.len; | |
1385 | eeprom.offset += eeprom.len; | |
1386 | bytes_remaining -= eeprom.len; | |
1387 | } | |
1da177e4 | 1388 | |
1da177e4 LT |
1389 | kfree(data); |
1390 | return ret; | |
1391 | } | |
1392 | ||
97f8aefb | 1393 | static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, |
1394 | void __user *useraddr) | |
1da177e4 | 1395 | { |
8e557421 | 1396 | struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; |
1da177e4 LT |
1397 | |
1398 | if (!dev->ethtool_ops->get_coalesce) | |
1399 | return -EOPNOTSUPP; | |
1400 | ||
1401 | dev->ethtool_ops->get_coalesce(dev, &coalesce); | |
1402 | ||
1403 | if (copy_to_user(useraddr, &coalesce, sizeof(coalesce))) | |
1404 | return -EFAULT; | |
1405 | return 0; | |
1406 | } | |
1407 | ||
97f8aefb | 1408 | static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, |
1409 | void __user *useraddr) | |
1da177e4 LT |
1410 | { |
1411 | struct ethtool_coalesce coalesce; | |
1412 | ||
fa04ae5c | 1413 | if (!dev->ethtool_ops->set_coalesce) |
1da177e4 LT |
1414 | return -EOPNOTSUPP; |
1415 | ||
1416 | if (copy_from_user(&coalesce, useraddr, sizeof(coalesce))) | |
1417 | return -EFAULT; | |
1418 | ||
1419 | return dev->ethtool_ops->set_coalesce(dev, &coalesce); | |
1420 | } | |
1421 | ||
1422 | static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr) | |
1423 | { | |
8e557421 | 1424 | struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM }; |
1da177e4 LT |
1425 | |
1426 | if (!dev->ethtool_ops->get_ringparam) | |
1427 | return -EOPNOTSUPP; | |
1428 | ||
1429 | dev->ethtool_ops->get_ringparam(dev, &ringparam); | |
1430 | ||
1431 | if (copy_to_user(useraddr, &ringparam, sizeof(ringparam))) | |
1432 | return -EFAULT; | |
1433 | return 0; | |
1434 | } | |
1435 | ||
1436 | static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr) | |
1437 | { | |
1438 | struct ethtool_ringparam ringparam; | |
1439 | ||
1440 | if (!dev->ethtool_ops->set_ringparam) | |
1441 | return -EOPNOTSUPP; | |
1442 | ||
1443 | if (copy_from_user(&ringparam, useraddr, sizeof(ringparam))) | |
1444 | return -EFAULT; | |
1445 | ||
1446 | return dev->ethtool_ops->set_ringparam(dev, &ringparam); | |
1447 | } | |
1448 | ||
1449 | static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr) | |
1450 | { | |
1451 | struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM }; | |
1452 | ||
1453 | if (!dev->ethtool_ops->get_pauseparam) | |
1454 | return -EOPNOTSUPP; | |
1455 | ||
1456 | dev->ethtool_ops->get_pauseparam(dev, &pauseparam); | |
1457 | ||
1458 | if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam))) | |
1459 | return -EFAULT; | |
1460 | return 0; | |
1461 | } | |
1462 | ||
1463 | static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr) | |
1464 | { | |
1465 | struct ethtool_pauseparam pauseparam; | |
1466 | ||
e1b90c41 | 1467 | if (!dev->ethtool_ops->set_pauseparam) |
1da177e4 LT |
1468 | return -EOPNOTSUPP; |
1469 | ||
1470 | if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam))) | |
1471 | return -EFAULT; | |
1472 | ||
1473 | return dev->ethtool_ops->set_pauseparam(dev, &pauseparam); | |
1474 | } | |
1475 | ||
1da177e4 LT |
1476 | static int __ethtool_set_sg(struct net_device *dev, u32 data) |
1477 | { | |
1478 | int err; | |
1479 | ||
5e5069b4 RL |
1480 | if (!dev->ethtool_ops->set_sg) |
1481 | return -EOPNOTSUPP; | |
1482 | ||
0a417704 MM |
1483 | if (data && !(dev->features & NETIF_F_ALL_CSUM)) |
1484 | return -EINVAL; | |
1485 | ||
1da177e4 LT |
1486 | if (!data && dev->ethtool_ops->set_tso) { |
1487 | err = dev->ethtool_ops->set_tso(dev, 0); | |
1488 | if (err) | |
1489 | return err; | |
1490 | } | |
1491 | ||
e89e9cf5 AR |
1492 | if (!data && dev->ethtool_ops->set_ufo) { |
1493 | err = dev->ethtool_ops->set_ufo(dev, 0); | |
1494 | if (err) | |
1495 | return err; | |
1496 | } | |
1da177e4 LT |
1497 | return dev->ethtool_ops->set_sg(dev, data); |
1498 | } | |
1499 | ||
0a417704 | 1500 | static int __ethtool_set_tx_csum(struct net_device *dev, u32 data) |
1da177e4 | 1501 | { |
1da177e4 LT |
1502 | int err; |
1503 | ||
1504 | if (!dev->ethtool_ops->set_tx_csum) | |
1505 | return -EOPNOTSUPP; | |
1506 | ||
0a417704 | 1507 | if (!data && dev->ethtool_ops->set_sg) { |
1da177e4 LT |
1508 | err = __ethtool_set_sg(dev, 0); |
1509 | if (err) | |
1510 | return err; | |
1511 | } | |
1512 | ||
0a417704 | 1513 | return dev->ethtool_ops->set_tx_csum(dev, data); |
1da177e4 LT |
1514 | } |
1515 | ||
e83d360d | 1516 | static int __ethtool_set_rx_csum(struct net_device *dev, u32 data) |
b240a0e5 | 1517 | { |
b240a0e5 HX |
1518 | if (!dev->ethtool_ops->set_rx_csum) |
1519 | return -EOPNOTSUPP; | |
1520 | ||
e83d360d | 1521 | if (!data) |
b240a0e5 HX |
1522 | dev->features &= ~NETIF_F_GRO; |
1523 | ||
e83d360d | 1524 | return dev->ethtool_ops->set_rx_csum(dev, data); |
b240a0e5 HX |
1525 | } |
1526 | ||
0a417704 | 1527 | static int __ethtool_set_tso(struct net_device *dev, u32 data) |
1da177e4 | 1528 | { |
1da177e4 LT |
1529 | if (!dev->ethtool_ops->set_tso) |
1530 | return -EOPNOTSUPP; | |
1531 | ||
0a417704 | 1532 | if (data && !(dev->features & NETIF_F_SG)) |
1da177e4 LT |
1533 | return -EINVAL; |
1534 | ||
0a417704 | 1535 | return dev->ethtool_ops->set_tso(dev, data); |
1da177e4 LT |
1536 | } |
1537 | ||
0a417704 | 1538 | static int __ethtool_set_ufo(struct net_device *dev, u32 data) |
e89e9cf5 | 1539 | { |
e89e9cf5 AR |
1540 | if (!dev->ethtool_ops->set_ufo) |
1541 | return -EOPNOTSUPP; | |
0a417704 | 1542 | if (data && !(dev->features & NETIF_F_SG)) |
e89e9cf5 | 1543 | return -EINVAL; |
0a417704 | 1544 | if (data && !((dev->features & NETIF_F_GEN_CSUM) || |
79032644 MM |
1545 | (dev->features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM)) |
1546 | == (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) | |
e89e9cf5 | 1547 | return -EINVAL; |
0a417704 | 1548 | return dev->ethtool_ops->set_ufo(dev, data); |
b240a0e5 HX |
1549 | } |
1550 | ||
1da177e4 LT |
1551 | static int ethtool_self_test(struct net_device *dev, char __user *useraddr) |
1552 | { | |
1553 | struct ethtool_test test; | |
76fd8593 | 1554 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 | 1555 | u64 *data; |
ff03d49f | 1556 | int ret, test_len; |
1da177e4 | 1557 | |
a9828ec6 | 1558 | if (!ops->self_test || !ops->get_sset_count) |
1da177e4 LT |
1559 | return -EOPNOTSUPP; |
1560 | ||
a9828ec6 | 1561 | test_len = ops->get_sset_count(dev, ETH_SS_TEST); |
ff03d49f JG |
1562 | if (test_len < 0) |
1563 | return test_len; | |
1564 | WARN_ON(test_len == 0); | |
1565 | ||
1da177e4 LT |
1566 | if (copy_from_user(&test, useraddr, sizeof(test))) |
1567 | return -EFAULT; | |
1568 | ||
ff03d49f JG |
1569 | test.len = test_len; |
1570 | data = kmalloc(test_len * sizeof(u64), GFP_USER); | |
1da177e4 LT |
1571 | if (!data) |
1572 | return -ENOMEM; | |
1573 | ||
1574 | ops->self_test(dev, &test, data); | |
1575 | ||
1576 | ret = -EFAULT; | |
1577 | if (copy_to_user(useraddr, &test, sizeof(test))) | |
1578 | goto out; | |
1579 | useraddr += sizeof(test); | |
1580 | if (copy_to_user(useraddr, data, test.len * sizeof(u64))) | |
1581 | goto out; | |
1582 | ret = 0; | |
1583 | ||
1584 | out: | |
1585 | kfree(data); | |
1586 | return ret; | |
1587 | } | |
1588 | ||
1589 | static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) | |
1590 | { | |
1591 | struct ethtool_gstrings gstrings; | |
1da177e4 LT |
1592 | u8 *data; |
1593 | int ret; | |
1594 | ||
1da177e4 LT |
1595 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) |
1596 | return -EFAULT; | |
1597 | ||
340ae165 | 1598 | ret = __ethtool_get_sset_count(dev, gstrings.string_set); |
a9828ec6 BH |
1599 | if (ret < 0) |
1600 | return ret; | |
1601 | ||
1602 | gstrings.len = ret; | |
1da177e4 LT |
1603 | |
1604 | data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER); | |
1605 | if (!data) | |
1606 | return -ENOMEM; | |
1607 | ||
340ae165 | 1608 | __ethtool_get_strings(dev, gstrings.string_set, data); |
1da177e4 LT |
1609 | |
1610 | ret = -EFAULT; | |
1611 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) | |
1612 | goto out; | |
1613 | useraddr += sizeof(gstrings); | |
1614 | if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN)) | |
1615 | goto out; | |
1616 | ret = 0; | |
1617 | ||
340ae165 | 1618 | out: |
1da177e4 LT |
1619 | kfree(data); |
1620 | return ret; | |
1621 | } | |
1622 | ||
1623 | static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) | |
1624 | { | |
1625 | struct ethtool_value id; | |
68f512f2 BH |
1626 | static bool busy; |
1627 | int rc; | |
1da177e4 | 1628 | |
68f512f2 | 1629 | if (!dev->ethtool_ops->set_phys_id && !dev->ethtool_ops->phys_id) |
1da177e4 LT |
1630 | return -EOPNOTSUPP; |
1631 | ||
68f512f2 BH |
1632 | if (busy) |
1633 | return -EBUSY; | |
1634 | ||
1da177e4 LT |
1635 | if (copy_from_user(&id, useraddr, sizeof(id))) |
1636 | return -EFAULT; | |
1637 | ||
68f512f2 BH |
1638 | if (!dev->ethtool_ops->set_phys_id) |
1639 | /* Do it the old way */ | |
1640 | return dev->ethtool_ops->phys_id(dev, id.data); | |
1641 | ||
1642 | rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE); | |
1643 | if (rc && rc != -EINVAL) | |
1644 | return rc; | |
1645 | ||
1646 | /* Drop the RTNL lock while waiting, but prevent reentry or | |
1647 | * removal of the device. | |
1648 | */ | |
1649 | busy = true; | |
1650 | dev_hold(dev); | |
1651 | rtnl_unlock(); | |
1652 | ||
1653 | if (rc == 0) { | |
1654 | /* Driver will handle this itself */ | |
1655 | schedule_timeout_interruptible( | |
1656 | id.data ? id.data : MAX_SCHEDULE_TIMEOUT); | |
1657 | } else { | |
1658 | /* Driver expects to be called periodically */ | |
1659 | do { | |
1660 | rtnl_lock(); | |
1661 | rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_ON); | |
1662 | rtnl_unlock(); | |
1663 | if (rc) | |
1664 | break; | |
1665 | schedule_timeout_interruptible(HZ / 2); | |
1666 | ||
1667 | rtnl_lock(); | |
1668 | rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_OFF); | |
1669 | rtnl_unlock(); | |
1670 | if (rc) | |
1671 | break; | |
1672 | schedule_timeout_interruptible(HZ / 2); | |
1673 | } while (!signal_pending(current) && | |
1674 | (id.data == 0 || --id.data != 0)); | |
1675 | } | |
1676 | ||
1677 | rtnl_lock(); | |
1678 | dev_put(dev); | |
1679 | busy = false; | |
1680 | ||
1681 | (void)dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE); | |
1682 | return rc; | |
1da177e4 LT |
1683 | } |
1684 | ||
1685 | static int ethtool_get_stats(struct net_device *dev, void __user *useraddr) | |
1686 | { | |
1687 | struct ethtool_stats stats; | |
76fd8593 | 1688 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 | 1689 | u64 *data; |
ff03d49f | 1690 | int ret, n_stats; |
1da177e4 | 1691 | |
a9828ec6 | 1692 | if (!ops->get_ethtool_stats || !ops->get_sset_count) |
1da177e4 LT |
1693 | return -EOPNOTSUPP; |
1694 | ||
a9828ec6 | 1695 | n_stats = ops->get_sset_count(dev, ETH_SS_STATS); |
ff03d49f JG |
1696 | if (n_stats < 0) |
1697 | return n_stats; | |
1698 | WARN_ON(n_stats == 0); | |
1699 | ||
1da177e4 LT |
1700 | if (copy_from_user(&stats, useraddr, sizeof(stats))) |
1701 | return -EFAULT; | |
1702 | ||
ff03d49f JG |
1703 | stats.n_stats = n_stats; |
1704 | data = kmalloc(n_stats * sizeof(u64), GFP_USER); | |
1da177e4 LT |
1705 | if (!data) |
1706 | return -ENOMEM; | |
1707 | ||
1708 | ops->get_ethtool_stats(dev, &stats, data); | |
1709 | ||
1710 | ret = -EFAULT; | |
1711 | if (copy_to_user(useraddr, &stats, sizeof(stats))) | |
1712 | goto out; | |
1713 | useraddr += sizeof(stats); | |
1714 | if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64))) | |
1715 | goto out; | |
1716 | ret = 0; | |
1717 | ||
1718 | out: | |
1719 | kfree(data); | |
1720 | return ret; | |
1721 | } | |
1722 | ||
0bf0519d | 1723 | static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr) |
a6f9a705 JW |
1724 | { |
1725 | struct ethtool_perm_addr epaddr; | |
a6f9a705 | 1726 | |
313674af | 1727 | if (copy_from_user(&epaddr, useraddr, sizeof(epaddr))) |
a6f9a705 JW |
1728 | return -EFAULT; |
1729 | ||
313674af MW |
1730 | if (epaddr.size < dev->addr_len) |
1731 | return -ETOOSMALL; | |
1732 | epaddr.size = dev->addr_len; | |
a6f9a705 | 1733 | |
a6f9a705 | 1734 | if (copy_to_user(useraddr, &epaddr, sizeof(epaddr))) |
313674af | 1735 | return -EFAULT; |
a6f9a705 | 1736 | useraddr += sizeof(epaddr); |
313674af MW |
1737 | if (copy_to_user(useraddr, dev->perm_addr, epaddr.size)) |
1738 | return -EFAULT; | |
1739 | return 0; | |
a6f9a705 JW |
1740 | } |
1741 | ||
13c99b24 JG |
1742 | static int ethtool_get_value(struct net_device *dev, char __user *useraddr, |
1743 | u32 cmd, u32 (*actor)(struct net_device *)) | |
3ae7c0b2 | 1744 | { |
8e557421 | 1745 | struct ethtool_value edata = { .cmd = cmd }; |
3ae7c0b2 | 1746 | |
13c99b24 | 1747 | if (!actor) |
3ae7c0b2 JG |
1748 | return -EOPNOTSUPP; |
1749 | ||
13c99b24 | 1750 | edata.data = actor(dev); |
3ae7c0b2 JG |
1751 | |
1752 | if (copy_to_user(useraddr, &edata, sizeof(edata))) | |
1753 | return -EFAULT; | |
1754 | return 0; | |
1755 | } | |
1756 | ||
13c99b24 JG |
1757 | static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr, |
1758 | void (*actor)(struct net_device *, u32)) | |
3ae7c0b2 JG |
1759 | { |
1760 | struct ethtool_value edata; | |
1761 | ||
13c99b24 | 1762 | if (!actor) |
3ae7c0b2 JG |
1763 | return -EOPNOTSUPP; |
1764 | ||
1765 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1766 | return -EFAULT; | |
1767 | ||
13c99b24 | 1768 | actor(dev, edata.data); |
339bf024 JG |
1769 | return 0; |
1770 | } | |
1771 | ||
13c99b24 JG |
1772 | static int ethtool_set_value(struct net_device *dev, char __user *useraddr, |
1773 | int (*actor)(struct net_device *, u32)) | |
339bf024 JG |
1774 | { |
1775 | struct ethtool_value edata; | |
1776 | ||
13c99b24 | 1777 | if (!actor) |
339bf024 JG |
1778 | return -EOPNOTSUPP; |
1779 | ||
1780 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1781 | return -EFAULT; | |
1782 | ||
13c99b24 | 1783 | return actor(dev, edata.data); |
339bf024 JG |
1784 | } |
1785 | ||
97f8aefb | 1786 | static noinline_for_stack int ethtool_flash_device(struct net_device *dev, |
1787 | char __user *useraddr) | |
05c6a8d7 AK |
1788 | { |
1789 | struct ethtool_flash efl; | |
1790 | ||
1791 | if (copy_from_user(&efl, useraddr, sizeof(efl))) | |
1792 | return -EFAULT; | |
1793 | ||
1794 | if (!dev->ethtool_ops->flash_device) | |
1795 | return -EOPNOTSUPP; | |
1796 | ||
1797 | return dev->ethtool_ops->flash_device(dev, &efl); | |
1798 | } | |
1799 | ||
1da177e4 LT |
1800 | /* The main entry point in this file. Called from net/core/dev.c */ |
1801 | ||
881d966b | 1802 | int dev_ethtool(struct net *net, struct ifreq *ifr) |
1da177e4 | 1803 | { |
881d966b | 1804 | struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); |
1da177e4 LT |
1805 | void __user *useraddr = ifr->ifr_data; |
1806 | u32 ethcmd; | |
1807 | int rc; | |
04ed3e74 | 1808 | u32 old_features; |
1da177e4 | 1809 | |
1da177e4 LT |
1810 | if (!dev || !netif_device_present(dev)) |
1811 | return -ENODEV; | |
1812 | ||
97f8aefb | 1813 | if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) |
1da177e4 LT |
1814 | return -EFAULT; |
1815 | ||
01414802 BH |
1816 | if (!dev->ethtool_ops) { |
1817 | /* ETHTOOL_GDRVINFO does not require any driver support. | |
1818 | * It is also unprivileged and does not change anything, | |
1819 | * so we can take a shortcut to it. */ | |
1820 | if (ethcmd == ETHTOOL_GDRVINFO) | |
1821 | return ethtool_get_drvinfo(dev, useraddr); | |
1822 | else | |
1823 | return -EOPNOTSUPP; | |
1824 | } | |
1825 | ||
75f3123c | 1826 | /* Allow some commands to be done by anyone */ |
97f8aefb | 1827 | switch (ethcmd) { |
0fdc100b | 1828 | case ETHTOOL_GSET: |
75f3123c | 1829 | case ETHTOOL_GDRVINFO: |
75f3123c | 1830 | case ETHTOOL_GMSGLVL: |
75f3123c SH |
1831 | case ETHTOOL_GCOALESCE: |
1832 | case ETHTOOL_GRINGPARAM: | |
1833 | case ETHTOOL_GPAUSEPARAM: | |
1834 | case ETHTOOL_GRXCSUM: | |
1835 | case ETHTOOL_GTXCSUM: | |
1836 | case ETHTOOL_GSG: | |
1837 | case ETHTOOL_GSTRINGS: | |
75f3123c SH |
1838 | case ETHTOOL_GTSO: |
1839 | case ETHTOOL_GPERMADDR: | |
1840 | case ETHTOOL_GUFO: | |
1841 | case ETHTOOL_GGSO: | |
1cab819b | 1842 | case ETHTOOL_GGRO: |
339bf024 JG |
1843 | case ETHTOOL_GFLAGS: |
1844 | case ETHTOOL_GPFLAGS: | |
0853ad66 | 1845 | case ETHTOOL_GRXFH: |
59089d8d SB |
1846 | case ETHTOOL_GRXRINGS: |
1847 | case ETHTOOL_GRXCLSRLCNT: | |
1848 | case ETHTOOL_GRXCLSRULE: | |
1849 | case ETHTOOL_GRXCLSRLALL: | |
5455c699 | 1850 | case ETHTOOL_GFEATURES: |
75f3123c SH |
1851 | break; |
1852 | default: | |
1853 | if (!capable(CAP_NET_ADMIN)) | |
1854 | return -EPERM; | |
1855 | } | |
1856 | ||
97f8aefb | 1857 | if (dev->ethtool_ops->begin) { |
1858 | rc = dev->ethtool_ops->begin(dev); | |
1859 | if (rc < 0) | |
1da177e4 | 1860 | return rc; |
97f8aefb | 1861 | } |
d8a33ac4 SH |
1862 | old_features = dev->features; |
1863 | ||
1da177e4 LT |
1864 | switch (ethcmd) { |
1865 | case ETHTOOL_GSET: | |
1866 | rc = ethtool_get_settings(dev, useraddr); | |
1867 | break; | |
1868 | case ETHTOOL_SSET: | |
1869 | rc = ethtool_set_settings(dev, useraddr); | |
1870 | break; | |
1871 | case ETHTOOL_GDRVINFO: | |
1872 | rc = ethtool_get_drvinfo(dev, useraddr); | |
1da177e4 LT |
1873 | break; |
1874 | case ETHTOOL_GREGS: | |
1875 | rc = ethtool_get_regs(dev, useraddr); | |
1876 | break; | |
1877 | case ETHTOOL_GWOL: | |
1878 | rc = ethtool_get_wol(dev, useraddr); | |
1879 | break; | |
1880 | case ETHTOOL_SWOL: | |
1881 | rc = ethtool_set_wol(dev, useraddr); | |
1882 | break; | |
1883 | case ETHTOOL_GMSGLVL: | |
13c99b24 JG |
1884 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1885 | dev->ethtool_ops->get_msglevel); | |
1da177e4 LT |
1886 | break; |
1887 | case ETHTOOL_SMSGLVL: | |
13c99b24 JG |
1888 | rc = ethtool_set_value_void(dev, useraddr, |
1889 | dev->ethtool_ops->set_msglevel); | |
1da177e4 LT |
1890 | break; |
1891 | case ETHTOOL_NWAY_RST: | |
1892 | rc = ethtool_nway_reset(dev); | |
1893 | break; | |
1894 | case ETHTOOL_GLINK: | |
e596e6e4 | 1895 | rc = ethtool_get_link(dev, useraddr); |
1da177e4 LT |
1896 | break; |
1897 | case ETHTOOL_GEEPROM: | |
1898 | rc = ethtool_get_eeprom(dev, useraddr); | |
1899 | break; | |
1900 | case ETHTOOL_SEEPROM: | |
1901 | rc = ethtool_set_eeprom(dev, useraddr); | |
1902 | break; | |
1903 | case ETHTOOL_GCOALESCE: | |
1904 | rc = ethtool_get_coalesce(dev, useraddr); | |
1905 | break; | |
1906 | case ETHTOOL_SCOALESCE: | |
1907 | rc = ethtool_set_coalesce(dev, useraddr); | |
1908 | break; | |
1909 | case ETHTOOL_GRINGPARAM: | |
1910 | rc = ethtool_get_ringparam(dev, useraddr); | |
1911 | break; | |
1912 | case ETHTOOL_SRINGPARAM: | |
1913 | rc = ethtool_set_ringparam(dev, useraddr); | |
1914 | break; | |
1915 | case ETHTOOL_GPAUSEPARAM: | |
1916 | rc = ethtool_get_pauseparam(dev, useraddr); | |
1917 | break; | |
1918 | case ETHTOOL_SPAUSEPARAM: | |
1919 | rc = ethtool_set_pauseparam(dev, useraddr); | |
1920 | break; | |
1da177e4 LT |
1921 | case ETHTOOL_TEST: |
1922 | rc = ethtool_self_test(dev, useraddr); | |
1923 | break; | |
1924 | case ETHTOOL_GSTRINGS: | |
1925 | rc = ethtool_get_strings(dev, useraddr); | |
1926 | break; | |
1927 | case ETHTOOL_PHYS_ID: | |
1928 | rc = ethtool_phys_id(dev, useraddr); | |
1929 | break; | |
1930 | case ETHTOOL_GSTATS: | |
1931 | rc = ethtool_get_stats(dev, useraddr); | |
1932 | break; | |
a6f9a705 JW |
1933 | case ETHTOOL_GPERMADDR: |
1934 | rc = ethtool_get_perm_addr(dev, useraddr); | |
1935 | break; | |
3ae7c0b2 | 1936 | case ETHTOOL_GFLAGS: |
13c99b24 | 1937 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1896e61f SS |
1938 | (dev->ethtool_ops->get_flags ? |
1939 | dev->ethtool_ops->get_flags : | |
1940 | ethtool_op_get_flags)); | |
3ae7c0b2 JG |
1941 | break; |
1942 | case ETHTOOL_SFLAGS: | |
da8ac86c | 1943 | rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags); |
3ae7c0b2 | 1944 | break; |
339bf024 | 1945 | case ETHTOOL_GPFLAGS: |
13c99b24 JG |
1946 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1947 | dev->ethtool_ops->get_priv_flags); | |
339bf024 JG |
1948 | break; |
1949 | case ETHTOOL_SPFLAGS: | |
13c99b24 JG |
1950 | rc = ethtool_set_value(dev, useraddr, |
1951 | dev->ethtool_ops->set_priv_flags); | |
339bf024 | 1952 | break; |
0853ad66 | 1953 | case ETHTOOL_GRXFH: |
59089d8d SB |
1954 | case ETHTOOL_GRXRINGS: |
1955 | case ETHTOOL_GRXCLSRLCNT: | |
1956 | case ETHTOOL_GRXCLSRULE: | |
1957 | case ETHTOOL_GRXCLSRLALL: | |
bf988435 | 1958 | rc = ethtool_get_rxnfc(dev, ethcmd, useraddr); |
0853ad66 SB |
1959 | break; |
1960 | case ETHTOOL_SRXFH: | |
59089d8d SB |
1961 | case ETHTOOL_SRXCLSRLDEL: |
1962 | case ETHTOOL_SRXCLSRLINS: | |
bf988435 | 1963 | rc = ethtool_set_rxnfc(dev, ethcmd, useraddr); |
0853ad66 | 1964 | break; |
05c6a8d7 AK |
1965 | case ETHTOOL_FLASHDEV: |
1966 | rc = ethtool_flash_device(dev, useraddr); | |
1967 | break; | |
d73d3a8c BH |
1968 | case ETHTOOL_RESET: |
1969 | rc = ethtool_reset(dev, useraddr); | |
1970 | break; | |
15682bc4 PWJ |
1971 | case ETHTOOL_SRXNTUPLE: |
1972 | rc = ethtool_set_rx_ntuple(dev, useraddr); | |
1973 | break; | |
1974 | case ETHTOOL_GRXNTUPLE: | |
1975 | rc = ethtool_get_rx_ntuple(dev, useraddr); | |
1976 | break; | |
723b2f57 JG |
1977 | case ETHTOOL_GSSET_INFO: |
1978 | rc = ethtool_get_sset_info(dev, useraddr); | |
1979 | break; | |
a5b6ee29 BH |
1980 | case ETHTOOL_GRXFHINDIR: |
1981 | rc = ethtool_get_rxfh_indir(dev, useraddr); | |
1982 | break; | |
1983 | case ETHTOOL_SRXFHINDIR: | |
1984 | rc = ethtool_set_rxfh_indir(dev, useraddr); | |
1985 | break; | |
5455c699 MM |
1986 | case ETHTOOL_GFEATURES: |
1987 | rc = ethtool_get_features(dev, useraddr); | |
1988 | break; | |
1989 | case ETHTOOL_SFEATURES: | |
1990 | rc = ethtool_set_features(dev, useraddr); | |
1991 | break; | |
0a417704 | 1992 | case ETHTOOL_GTXCSUM: |
e83d360d | 1993 | case ETHTOOL_GRXCSUM: |
0a417704 MM |
1994 | case ETHTOOL_GSG: |
1995 | case ETHTOOL_GTSO: | |
1996 | case ETHTOOL_GUFO: | |
1997 | case ETHTOOL_GGSO: | |
1998 | case ETHTOOL_GGRO: | |
1999 | rc = ethtool_get_one_feature(dev, useraddr, ethcmd); | |
2000 | break; | |
2001 | case ETHTOOL_STXCSUM: | |
e83d360d | 2002 | case ETHTOOL_SRXCSUM: |
0a417704 MM |
2003 | case ETHTOOL_SSG: |
2004 | case ETHTOOL_STSO: | |
2005 | case ETHTOOL_SUFO: | |
2006 | case ETHTOOL_SGSO: | |
2007 | case ETHTOOL_SGRO: | |
2008 | rc = ethtool_set_one_feature(dev, useraddr, ethcmd); | |
2009 | break; | |
1da177e4 | 2010 | default: |
61a44b9c | 2011 | rc = -EOPNOTSUPP; |
1da177e4 | 2012 | } |
4ec93edb | 2013 | |
e71a4783 | 2014 | if (dev->ethtool_ops->complete) |
1da177e4 | 2015 | dev->ethtool_ops->complete(dev); |
d8a33ac4 SH |
2016 | |
2017 | if (old_features != dev->features) | |
2018 | netdev_features_change(dev); | |
2019 | ||
1da177e4 | 2020 | return rc; |
1da177e4 | 2021 | } |