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 | 38 | |
1da177e4 LT |
39 | /* Handlers for each ethtool command */ |
40 | ||
475414f6 | 41 | #define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32) |
5455c699 | 42 | |
9d921549 MM |
43 | static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = { |
44 | [NETIF_F_SG_BIT] = "tx-scatter-gather", | |
45 | [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4", | |
9d921549 MM |
46 | [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic", |
47 | [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6", | |
48 | [NETIF_F_HIGHDMA_BIT] = "highdma", | |
49 | [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist", | |
50 | [NETIF_F_HW_VLAN_TX_BIT] = "tx-vlan-hw-insert", | |
51 | ||
52 | [NETIF_F_HW_VLAN_RX_BIT] = "rx-vlan-hw-parse", | |
53 | [NETIF_F_HW_VLAN_FILTER_BIT] = "rx-vlan-filter", | |
54 | [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged", | |
55 | [NETIF_F_GSO_BIT] = "tx-generic-segmentation", | |
56 | [NETIF_F_LLTX_BIT] = "tx-lockless", | |
57 | [NETIF_F_NETNS_LOCAL_BIT] = "netns-local", | |
58 | [NETIF_F_GRO_BIT] = "rx-gro", | |
59 | [NETIF_F_LRO_BIT] = "rx-lro", | |
60 | ||
61 | [NETIF_F_TSO_BIT] = "tx-tcp-segmentation", | |
62 | [NETIF_F_UFO_BIT] = "tx-udp-fragmentation", | |
63 | [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust", | |
64 | [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation", | |
65 | [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation", | |
66 | [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation", | |
67 | ||
68 | [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc", | |
69 | [NETIF_F_SCTP_CSUM_BIT] = "tx-checksum-sctp", | |
70 | [NETIF_F_FCOE_MTU_BIT] = "fcoe-mtu", | |
71 | [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter", | |
72 | [NETIF_F_RXHASH_BIT] = "rx-hashing", | |
73 | [NETIF_F_RXCSUM_BIT] = "rx-checksum", | |
74 | [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy", | |
75 | [NETIF_F_LOOPBACK_BIT] = "loopback", | |
36eabda3 | 76 | [NETIF_F_RXFCS_BIT] = "rx-fcs", |
5e0c03c8 | 77 | [NETIF_F_RXALL_BIT] = "rx-all", |
9d921549 MM |
78 | }; |
79 | ||
5455c699 MM |
80 | static int ethtool_get_features(struct net_device *dev, void __user *useraddr) |
81 | { | |
82 | struct ethtool_gfeatures cmd = { | |
83 | .cmd = ETHTOOL_GFEATURES, | |
84 | .size = ETHTOOL_DEV_FEATURE_WORDS, | |
85 | }; | |
475414f6 | 86 | struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS]; |
5455c699 MM |
87 | u32 __user *sizeaddr; |
88 | u32 copy_size; | |
475414f6 MM |
89 | int i; |
90 | ||
91 | /* in case feature bits run out again */ | |
09da71b1 | 92 | BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t)); |
475414f6 MM |
93 | |
94 | for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) { | |
09da71b1 MM |
95 | features[i].available = (u32)(dev->hw_features >> (32 * i)); |
96 | features[i].requested = (u32)(dev->wanted_features >> (32 * i)); | |
97 | features[i].active = (u32)(dev->features >> (32 * i)); | |
98 | features[i].never_changed = | |
99 | (u32)(NETIF_F_NEVER_CHANGE >> (32 * i)); | |
475414f6 | 100 | } |
5455c699 MM |
101 | |
102 | sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size); | |
103 | if (get_user(copy_size, sizeaddr)) | |
104 | return -EFAULT; | |
105 | ||
106 | if (copy_size > ETHTOOL_DEV_FEATURE_WORDS) | |
107 | copy_size = ETHTOOL_DEV_FEATURE_WORDS; | |
108 | ||
109 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) | |
110 | return -EFAULT; | |
111 | useraddr += sizeof(cmd); | |
112 | if (copy_to_user(useraddr, features, copy_size * sizeof(*features))) | |
113 | return -EFAULT; | |
114 | ||
115 | return 0; | |
116 | } | |
117 | ||
118 | static int ethtool_set_features(struct net_device *dev, void __user *useraddr) | |
119 | { | |
120 | struct ethtool_sfeatures cmd; | |
121 | struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS]; | |
475414f6 MM |
122 | netdev_features_t wanted = 0, valid = 0; |
123 | int i, ret = 0; | |
5455c699 MM |
124 | |
125 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) | |
126 | return -EFAULT; | |
127 | useraddr += sizeof(cmd); | |
128 | ||
129 | if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS) | |
130 | return -EINVAL; | |
131 | ||
132 | if (copy_from_user(features, useraddr, sizeof(features))) | |
133 | return -EFAULT; | |
134 | ||
475414f6 | 135 | for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) { |
09da71b1 MM |
136 | valid |= (netdev_features_t)features[i].valid << (32 * i); |
137 | wanted |= (netdev_features_t)features[i].requested << (32 * i); | |
475414f6 MM |
138 | } |
139 | ||
140 | if (valid & ~NETIF_F_ETHTOOL_BITS) | |
5455c699 MM |
141 | return -EINVAL; |
142 | ||
475414f6 MM |
143 | if (valid & ~dev->hw_features) { |
144 | valid &= dev->hw_features; | |
5455c699 MM |
145 | ret |= ETHTOOL_F_UNSUPPORTED; |
146 | } | |
147 | ||
475414f6 MM |
148 | dev->wanted_features &= ~valid; |
149 | dev->wanted_features |= wanted & valid; | |
6cb6a27c | 150 | __netdev_update_features(dev); |
5455c699 | 151 | |
475414f6 | 152 | if ((dev->wanted_features ^ dev->features) & valid) |
5455c699 MM |
153 | ret |= ETHTOOL_F_WISH; |
154 | ||
155 | return ret; | |
156 | } | |
157 | ||
340ae165 MM |
158 | static int __ethtool_get_sset_count(struct net_device *dev, int sset) |
159 | { | |
160 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
161 | ||
5455c699 MM |
162 | if (sset == ETH_SS_FEATURES) |
163 | return ARRAY_SIZE(netdev_features_strings); | |
164 | ||
340ae165 MM |
165 | if (ops && ops->get_sset_count && ops->get_strings) |
166 | return ops->get_sset_count(dev, sset); | |
167 | else | |
168 | return -EOPNOTSUPP; | |
169 | } | |
170 | ||
171 | static void __ethtool_get_strings(struct net_device *dev, | |
172 | u32 stringset, u8 *data) | |
173 | { | |
174 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
175 | ||
5455c699 MM |
176 | if (stringset == ETH_SS_FEATURES) |
177 | memcpy(data, netdev_features_strings, | |
178 | sizeof(netdev_features_strings)); | |
179 | else | |
180 | /* ops->get_strings is valid because checked earlier */ | |
181 | ops->get_strings(dev, stringset, data); | |
340ae165 MM |
182 | } |
183 | ||
c8f44aff | 184 | static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd) |
0a417704 MM |
185 | { |
186 | /* feature masks of legacy discrete ethtool ops */ | |
187 | ||
188 | switch (eth_cmd) { | |
189 | case ETHTOOL_GTXCSUM: | |
190 | case ETHTOOL_STXCSUM: | |
191 | return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM; | |
e83d360d MM |
192 | case ETHTOOL_GRXCSUM: |
193 | case ETHTOOL_SRXCSUM: | |
194 | return NETIF_F_RXCSUM; | |
0a417704 MM |
195 | case ETHTOOL_GSG: |
196 | case ETHTOOL_SSG: | |
197 | return NETIF_F_SG; | |
198 | case ETHTOOL_GTSO: | |
199 | case ETHTOOL_STSO: | |
200 | return NETIF_F_ALL_TSO; | |
201 | case ETHTOOL_GUFO: | |
202 | case ETHTOOL_SUFO: | |
203 | return NETIF_F_UFO; | |
204 | case ETHTOOL_GGSO: | |
205 | case ETHTOOL_SGSO: | |
206 | return NETIF_F_GSO; | |
207 | case ETHTOOL_GGRO: | |
208 | case ETHTOOL_SGRO: | |
209 | return NETIF_F_GRO; | |
210 | default: | |
211 | BUG(); | |
212 | } | |
213 | } | |
214 | ||
0a417704 MM |
215 | static int ethtool_get_one_feature(struct net_device *dev, |
216 | char __user *useraddr, u32 ethcmd) | |
217 | { | |
c8f44aff | 218 | netdev_features_t mask = ethtool_get_feature_mask(ethcmd); |
0a417704 MM |
219 | struct ethtool_value edata = { |
220 | .cmd = ethcmd, | |
86794881 | 221 | .data = !!(dev->features & mask), |
0a417704 | 222 | }; |
0a417704 | 223 | |
0a417704 MM |
224 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
225 | return -EFAULT; | |
226 | return 0; | |
227 | } | |
228 | ||
0a417704 MM |
229 | static int ethtool_set_one_feature(struct net_device *dev, |
230 | void __user *useraddr, u32 ethcmd) | |
231 | { | |
232 | struct ethtool_value edata; | |
c8f44aff | 233 | netdev_features_t mask; |
0a417704 MM |
234 | |
235 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
236 | return -EFAULT; | |
237 | ||
86794881 MM |
238 | mask = ethtool_get_feature_mask(ethcmd); |
239 | mask &= dev->hw_features; | |
bc5787c6 MM |
240 | if (!mask) |
241 | return -EOPNOTSUPP; | |
86794881 | 242 | |
bc5787c6 MM |
243 | if (edata.data) |
244 | dev->wanted_features |= mask; | |
245 | else | |
246 | dev->wanted_features &= ~mask; | |
86794881 | 247 | |
bc5787c6 | 248 | __netdev_update_features(dev); |
86794881 | 249 | |
bc5787c6 MM |
250 | return 0; |
251 | } | |
252 | ||
02b3a552 MM |
253 | #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \ |
254 | ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH) | |
255 | #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_RX | \ | |
256 | NETIF_F_HW_VLAN_TX | NETIF_F_NTUPLE | NETIF_F_RXHASH) | |
bc5787c6 MM |
257 | |
258 | static u32 __ethtool_get_flags(struct net_device *dev) | |
259 | { | |
02b3a552 MM |
260 | u32 flags = 0; |
261 | ||
262 | if (dev->features & NETIF_F_LRO) flags |= ETH_FLAG_LRO; | |
263 | if (dev->features & NETIF_F_HW_VLAN_RX) flags |= ETH_FLAG_RXVLAN; | |
264 | if (dev->features & NETIF_F_HW_VLAN_TX) flags |= ETH_FLAG_TXVLAN; | |
265 | if (dev->features & NETIF_F_NTUPLE) flags |= ETH_FLAG_NTUPLE; | |
266 | if (dev->features & NETIF_F_RXHASH) flags |= ETH_FLAG_RXHASH; | |
267 | ||
268 | return flags; | |
0a417704 MM |
269 | } |
270 | ||
bc5787c6 | 271 | static int __ethtool_set_flags(struct net_device *dev, u32 data) |
da8ac86c | 272 | { |
c8f44aff | 273 | netdev_features_t features = 0, changed; |
da8ac86c | 274 | |
02b3a552 | 275 | if (data & ~ETH_ALL_FLAGS) |
da8ac86c MM |
276 | return -EINVAL; |
277 | ||
02b3a552 MM |
278 | if (data & ETH_FLAG_LRO) features |= NETIF_F_LRO; |
279 | if (data & ETH_FLAG_RXVLAN) features |= NETIF_F_HW_VLAN_RX; | |
280 | if (data & ETH_FLAG_TXVLAN) features |= NETIF_F_HW_VLAN_TX; | |
281 | if (data & ETH_FLAG_NTUPLE) features |= NETIF_F_NTUPLE; | |
282 | if (data & ETH_FLAG_RXHASH) features |= NETIF_F_RXHASH; | |
283 | ||
da8ac86c | 284 | /* allow changing only bits set in hw_features */ |
02b3a552 | 285 | changed = (features ^ dev->features) & ETH_ALL_FEATURES; |
da8ac86c MM |
286 | if (changed & ~dev->hw_features) |
287 | return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP; | |
288 | ||
289 | dev->wanted_features = | |
02b3a552 | 290 | (dev->wanted_features & ~changed) | (features & changed); |
da8ac86c | 291 | |
6cb6a27c | 292 | __netdev_update_features(dev); |
da8ac86c MM |
293 | |
294 | return 0; | |
295 | } | |
296 | ||
4bc71cb9 | 297 | int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
1da177e4 | 298 | { |
4bc71cb9 | 299 | ASSERT_RTNL(); |
1da177e4 | 300 | |
4bc71cb9 | 301 | if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings) |
1da177e4 LT |
302 | return -EOPNOTSUPP; |
303 | ||
4bc71cb9 JP |
304 | memset(cmd, 0, sizeof(struct ethtool_cmd)); |
305 | cmd->cmd = ETHTOOL_GSET; | |
306 | return dev->ethtool_ops->get_settings(dev, cmd); | |
307 | } | |
308 | EXPORT_SYMBOL(__ethtool_get_settings); | |
309 | ||
310 | static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) | |
311 | { | |
312 | int err; | |
313 | struct ethtool_cmd cmd; | |
314 | ||
315 | err = __ethtool_get_settings(dev, &cmd); | |
1da177e4 LT |
316 | if (err < 0) |
317 | return err; | |
318 | ||
319 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) | |
320 | return -EFAULT; | |
321 | return 0; | |
322 | } | |
323 | ||
324 | static int ethtool_set_settings(struct net_device *dev, void __user *useraddr) | |
325 | { | |
326 | struct ethtool_cmd cmd; | |
327 | ||
328 | if (!dev->ethtool_ops->set_settings) | |
329 | return -EOPNOTSUPP; | |
330 | ||
331 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) | |
332 | return -EFAULT; | |
333 | ||
334 | return dev->ethtool_ops->set_settings(dev, &cmd); | |
335 | } | |
336 | ||
97f8aefb | 337 | static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, |
338 | void __user *useraddr) | |
1da177e4 LT |
339 | { |
340 | struct ethtool_drvinfo info; | |
76fd8593 | 341 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 | 342 | |
1da177e4 LT |
343 | memset(&info, 0, sizeof(info)); |
344 | info.cmd = ETHTOOL_GDRVINFO; | |
01414802 BH |
345 | if (ops && ops->get_drvinfo) { |
346 | ops->get_drvinfo(dev, &info); | |
347 | } else if (dev->dev.parent && dev->dev.parent->driver) { | |
348 | strlcpy(info.bus_info, dev_name(dev->dev.parent), | |
349 | sizeof(info.bus_info)); | |
350 | strlcpy(info.driver, dev->dev.parent->driver->name, | |
351 | sizeof(info.driver)); | |
352 | } else { | |
353 | return -EOPNOTSUPP; | |
354 | } | |
1da177e4 | 355 | |
723b2f57 JG |
356 | /* |
357 | * this method of obtaining string set info is deprecated; | |
d17792eb | 358 | * Use ETHTOOL_GSSET_INFO instead. |
723b2f57 | 359 | */ |
01414802 | 360 | if (ops && ops->get_sset_count) { |
ff03d49f JG |
361 | int rc; |
362 | ||
363 | rc = ops->get_sset_count(dev, ETH_SS_TEST); | |
364 | if (rc >= 0) | |
365 | info.testinfo_len = rc; | |
366 | rc = ops->get_sset_count(dev, ETH_SS_STATS); | |
367 | if (rc >= 0) | |
368 | info.n_stats = rc; | |
339bf024 JG |
369 | rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS); |
370 | if (rc >= 0) | |
371 | info.n_priv_flags = rc; | |
ff03d49f | 372 | } |
01414802 | 373 | if (ops && ops->get_regs_len) |
1da177e4 | 374 | info.regdump_len = ops->get_regs_len(dev); |
01414802 | 375 | if (ops && ops->get_eeprom_len) |
1da177e4 LT |
376 | info.eedump_len = ops->get_eeprom_len(dev); |
377 | ||
378 | if (copy_to_user(useraddr, &info, sizeof(info))) | |
379 | return -EFAULT; | |
380 | return 0; | |
381 | } | |
382 | ||
f5c445ed | 383 | static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, |
97f8aefb | 384 | void __user *useraddr) |
723b2f57 JG |
385 | { |
386 | struct ethtool_sset_info info; | |
723b2f57 JG |
387 | u64 sset_mask; |
388 | int i, idx = 0, n_bits = 0, ret, rc; | |
389 | u32 *info_buf = NULL; | |
390 | ||
723b2f57 JG |
391 | if (copy_from_user(&info, useraddr, sizeof(info))) |
392 | return -EFAULT; | |
393 | ||
394 | /* store copy of mask, because we zero struct later on */ | |
395 | sset_mask = info.sset_mask; | |
396 | if (!sset_mask) | |
397 | return 0; | |
398 | ||
399 | /* calculate size of return buffer */ | |
d17792eb | 400 | n_bits = hweight64(sset_mask); |
723b2f57 JG |
401 | |
402 | memset(&info, 0, sizeof(info)); | |
403 | info.cmd = ETHTOOL_GSSET_INFO; | |
404 | ||
405 | info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER); | |
406 | if (!info_buf) | |
407 | return -ENOMEM; | |
408 | ||
409 | /* | |
410 | * fill return buffer based on input bitmask and successful | |
411 | * get_sset_count return | |
412 | */ | |
413 | for (i = 0; i < 64; i++) { | |
414 | if (!(sset_mask & (1ULL << i))) | |
415 | continue; | |
416 | ||
340ae165 | 417 | rc = __ethtool_get_sset_count(dev, i); |
723b2f57 JG |
418 | if (rc >= 0) { |
419 | info.sset_mask |= (1ULL << i); | |
420 | info_buf[idx++] = rc; | |
421 | } | |
422 | } | |
423 | ||
424 | ret = -EFAULT; | |
425 | if (copy_to_user(useraddr, &info, sizeof(info))) | |
426 | goto out; | |
427 | ||
428 | useraddr += offsetof(struct ethtool_sset_info, data); | |
429 | if (copy_to_user(useraddr, info_buf, idx * sizeof(u32))) | |
430 | goto out; | |
431 | ||
432 | ret = 0; | |
433 | ||
434 | out: | |
435 | kfree(info_buf); | |
436 | return ret; | |
437 | } | |
438 | ||
97f8aefb | 439 | static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, |
bf988435 | 440 | u32 cmd, void __user *useraddr) |
0853ad66 | 441 | { |
bf988435 BH |
442 | struct ethtool_rxnfc info; |
443 | size_t info_size = sizeof(info); | |
55664f32 | 444 | int rc; |
0853ad66 | 445 | |
59089d8d | 446 | if (!dev->ethtool_ops->set_rxnfc) |
0853ad66 SB |
447 | return -EOPNOTSUPP; |
448 | ||
bf988435 BH |
449 | /* struct ethtool_rxnfc was originally defined for |
450 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data | |
451 | * members. User-space might still be using that | |
452 | * definition. */ | |
453 | if (cmd == ETHTOOL_SRXFH) | |
454 | info_size = (offsetof(struct ethtool_rxnfc, data) + | |
455 | sizeof(info.data)); | |
456 | ||
457 | if (copy_from_user(&info, useraddr, info_size)) | |
0853ad66 SB |
458 | return -EFAULT; |
459 | ||
55664f32 BH |
460 | rc = dev->ethtool_ops->set_rxnfc(dev, &info); |
461 | if (rc) | |
462 | return rc; | |
463 | ||
464 | if (cmd == ETHTOOL_SRXCLSRLINS && | |
465 | copy_to_user(useraddr, &info, info_size)) | |
466 | return -EFAULT; | |
467 | ||
468 | return 0; | |
0853ad66 SB |
469 | } |
470 | ||
97f8aefb | 471 | static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, |
bf988435 | 472 | u32 cmd, void __user *useraddr) |
0853ad66 SB |
473 | { |
474 | struct ethtool_rxnfc info; | |
bf988435 | 475 | size_t info_size = sizeof(info); |
59089d8d SB |
476 | const struct ethtool_ops *ops = dev->ethtool_ops; |
477 | int ret; | |
478 | void *rule_buf = NULL; | |
0853ad66 | 479 | |
59089d8d | 480 | if (!ops->get_rxnfc) |
0853ad66 SB |
481 | return -EOPNOTSUPP; |
482 | ||
bf988435 BH |
483 | /* struct ethtool_rxnfc was originally defined for |
484 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data | |
485 | * members. User-space might still be using that | |
486 | * definition. */ | |
487 | if (cmd == ETHTOOL_GRXFH) | |
488 | info_size = (offsetof(struct ethtool_rxnfc, data) + | |
489 | sizeof(info.data)); | |
490 | ||
491 | if (copy_from_user(&info, useraddr, info_size)) | |
0853ad66 SB |
492 | return -EFAULT; |
493 | ||
59089d8d SB |
494 | if (info.cmd == ETHTOOL_GRXCLSRLALL) { |
495 | if (info.rule_cnt > 0) { | |
db048b69 | 496 | if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32)) |
ae6df5f9 | 497 | rule_buf = kzalloc(info.rule_cnt * sizeof(u32), |
db048b69 | 498 | GFP_USER); |
59089d8d SB |
499 | if (!rule_buf) |
500 | return -ENOMEM; | |
501 | } | |
502 | } | |
0853ad66 | 503 | |
59089d8d SB |
504 | ret = ops->get_rxnfc(dev, &info, rule_buf); |
505 | if (ret < 0) | |
506 | goto err_out; | |
507 | ||
508 | ret = -EFAULT; | |
bf988435 | 509 | if (copy_to_user(useraddr, &info, info_size)) |
59089d8d SB |
510 | goto err_out; |
511 | ||
512 | if (rule_buf) { | |
513 | useraddr += offsetof(struct ethtool_rxnfc, rule_locs); | |
514 | if (copy_to_user(useraddr, rule_buf, | |
515 | info.rule_cnt * sizeof(u32))) | |
516 | goto err_out; | |
517 | } | |
518 | ret = 0; | |
519 | ||
520 | err_out: | |
c9caceca | 521 | kfree(rule_buf); |
59089d8d SB |
522 | |
523 | return ret; | |
0853ad66 SB |
524 | } |
525 | ||
a5b6ee29 BH |
526 | static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev, |
527 | void __user *useraddr) | |
528 | { | |
7850f63f BH |
529 | u32 user_size, dev_size; |
530 | u32 *indir; | |
a5b6ee29 BH |
531 | int ret; |
532 | ||
7850f63f BH |
533 | if (!dev->ethtool_ops->get_rxfh_indir_size || |
534 | !dev->ethtool_ops->get_rxfh_indir) | |
535 | return -EOPNOTSUPP; | |
536 | dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev); | |
537 | if (dev_size == 0) | |
a5b6ee29 BH |
538 | return -EOPNOTSUPP; |
539 | ||
7850f63f | 540 | if (copy_from_user(&user_size, |
a5b6ee29 | 541 | useraddr + offsetof(struct ethtool_rxfh_indir, size), |
7850f63f | 542 | sizeof(user_size))) |
a5b6ee29 BH |
543 | return -EFAULT; |
544 | ||
7850f63f BH |
545 | if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size), |
546 | &dev_size, sizeof(dev_size))) | |
547 | return -EFAULT; | |
548 | ||
549 | /* If the user buffer size is 0, this is just a query for the | |
550 | * device table size. Otherwise, if it's smaller than the | |
551 | * device table size it's an error. | |
552 | */ | |
553 | if (user_size < dev_size) | |
554 | return user_size == 0 ? 0 : -EINVAL; | |
555 | ||
556 | indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER); | |
a5b6ee29 BH |
557 | if (!indir) |
558 | return -ENOMEM; | |
559 | ||
a5b6ee29 BH |
560 | ret = dev->ethtool_ops->get_rxfh_indir(dev, indir); |
561 | if (ret) | |
562 | goto out; | |
563 | ||
7850f63f BH |
564 | if (copy_to_user(useraddr + |
565 | offsetof(struct ethtool_rxfh_indir, ring_index[0]), | |
566 | indir, dev_size * sizeof(indir[0]))) | |
a5b6ee29 BH |
567 | ret = -EFAULT; |
568 | ||
569 | out: | |
570 | kfree(indir); | |
571 | return ret; | |
572 | } | |
573 | ||
574 | static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev, | |
575 | void __user *useraddr) | |
576 | { | |
7850f63f BH |
577 | struct ethtool_rxnfc rx_rings; |
578 | u32 user_size, dev_size, i; | |
579 | u32 *indir; | |
a5b6ee29 BH |
580 | int ret; |
581 | ||
7850f63f BH |
582 | if (!dev->ethtool_ops->get_rxfh_indir_size || |
583 | !dev->ethtool_ops->set_rxfh_indir || | |
584 | !dev->ethtool_ops->get_rxnfc) | |
585 | return -EOPNOTSUPP; | |
586 | dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev); | |
587 | if (dev_size == 0) | |
a5b6ee29 BH |
588 | return -EOPNOTSUPP; |
589 | ||
7850f63f | 590 | if (copy_from_user(&user_size, |
a5b6ee29 | 591 | useraddr + offsetof(struct ethtool_rxfh_indir, size), |
7850f63f | 592 | sizeof(user_size))) |
a5b6ee29 BH |
593 | return -EFAULT; |
594 | ||
278bc429 | 595 | if (user_size != 0 && user_size != dev_size) |
7850f63f BH |
596 | return -EINVAL; |
597 | ||
598 | indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER); | |
a5b6ee29 BH |
599 | if (!indir) |
600 | return -ENOMEM; | |
601 | ||
7850f63f BH |
602 | rx_rings.cmd = ETHTOOL_GRXRINGS; |
603 | ret = dev->ethtool_ops->get_rxnfc(dev, &rx_rings, NULL); | |
604 | if (ret) | |
605 | goto out; | |
278bc429 BH |
606 | |
607 | if (user_size == 0) { | |
608 | for (i = 0; i < dev_size; i++) | |
609 | indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data); | |
610 | } else { | |
611 | if (copy_from_user(indir, | |
612 | useraddr + | |
613 | offsetof(struct ethtool_rxfh_indir, | |
614 | ring_index[0]), | |
615 | dev_size * sizeof(indir[0]))) { | |
616 | ret = -EFAULT; | |
7850f63f BH |
617 | goto out; |
618 | } | |
278bc429 BH |
619 | |
620 | /* Validate ring indices */ | |
621 | for (i = 0; i < dev_size; i++) { | |
622 | if (indir[i] >= rx_rings.data) { | |
623 | ret = -EINVAL; | |
624 | goto out; | |
625 | } | |
626 | } | |
7850f63f BH |
627 | } |
628 | ||
a5b6ee29 BH |
629 | ret = dev->ethtool_ops->set_rxfh_indir(dev, indir); |
630 | ||
631 | out: | |
632 | kfree(indir); | |
633 | return ret; | |
634 | } | |
635 | ||
1da177e4 LT |
636 | static int ethtool_get_regs(struct net_device *dev, char __user *useraddr) |
637 | { | |
638 | struct ethtool_regs regs; | |
76fd8593 | 639 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 LT |
640 | void *regbuf; |
641 | int reglen, ret; | |
642 | ||
643 | if (!ops->get_regs || !ops->get_regs_len) | |
644 | return -EOPNOTSUPP; | |
645 | ||
646 | if (copy_from_user(®s, useraddr, sizeof(regs))) | |
647 | return -EFAULT; | |
648 | ||
649 | reglen = ops->get_regs_len(dev); | |
650 | if (regs.len > reglen) | |
651 | regs.len = reglen; | |
652 | ||
b7c7d01a | 653 | regbuf = vzalloc(reglen); |
67ae7cf1 | 654 | if (reglen && !regbuf) |
1da177e4 LT |
655 | return -ENOMEM; |
656 | ||
657 | ops->get_regs(dev, ®s, regbuf); | |
658 | ||
659 | ret = -EFAULT; | |
660 | if (copy_to_user(useraddr, ®s, sizeof(regs))) | |
661 | goto out; | |
662 | useraddr += offsetof(struct ethtool_regs, data); | |
67ae7cf1 | 663 | if (regbuf && copy_to_user(useraddr, regbuf, regs.len)) |
1da177e4 LT |
664 | goto out; |
665 | ret = 0; | |
666 | ||
667 | out: | |
a77f5db3 | 668 | vfree(regbuf); |
1da177e4 LT |
669 | return ret; |
670 | } | |
671 | ||
d73d3a8c BH |
672 | static int ethtool_reset(struct net_device *dev, char __user *useraddr) |
673 | { | |
674 | struct ethtool_value reset; | |
675 | int ret; | |
676 | ||
677 | if (!dev->ethtool_ops->reset) | |
678 | return -EOPNOTSUPP; | |
679 | ||
680 | if (copy_from_user(&reset, useraddr, sizeof(reset))) | |
681 | return -EFAULT; | |
682 | ||
683 | ret = dev->ethtool_ops->reset(dev, &reset.data); | |
684 | if (ret) | |
685 | return ret; | |
686 | ||
687 | if (copy_to_user(useraddr, &reset, sizeof(reset))) | |
688 | return -EFAULT; | |
689 | return 0; | |
690 | } | |
691 | ||
1da177e4 LT |
692 | static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) |
693 | { | |
8e557421 | 694 | struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; |
1da177e4 LT |
695 | |
696 | if (!dev->ethtool_ops->get_wol) | |
697 | return -EOPNOTSUPP; | |
698 | ||
699 | dev->ethtool_ops->get_wol(dev, &wol); | |
700 | ||
701 | if (copy_to_user(useraddr, &wol, sizeof(wol))) | |
702 | return -EFAULT; | |
703 | return 0; | |
704 | } | |
705 | ||
706 | static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) | |
707 | { | |
708 | struct ethtool_wolinfo wol; | |
709 | ||
710 | if (!dev->ethtool_ops->set_wol) | |
711 | return -EOPNOTSUPP; | |
712 | ||
713 | if (copy_from_user(&wol, useraddr, sizeof(wol))) | |
714 | return -EFAULT; | |
715 | ||
716 | return dev->ethtool_ops->set_wol(dev, &wol); | |
717 | } | |
718 | ||
1da177e4 LT |
719 | static int ethtool_nway_reset(struct net_device *dev) |
720 | { | |
721 | if (!dev->ethtool_ops->nway_reset) | |
722 | return -EOPNOTSUPP; | |
723 | ||
724 | return dev->ethtool_ops->nway_reset(dev); | |
725 | } | |
726 | ||
e596e6e4 BH |
727 | static int ethtool_get_link(struct net_device *dev, char __user *useraddr) |
728 | { | |
729 | struct ethtool_value edata = { .cmd = ETHTOOL_GLINK }; | |
730 | ||
731 | if (!dev->ethtool_ops->get_link) | |
732 | return -EOPNOTSUPP; | |
733 | ||
734 | edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev); | |
735 | ||
736 | if (copy_to_user(useraddr, &edata, sizeof(edata))) | |
737 | return -EFAULT; | |
738 | return 0; | |
739 | } | |
740 | ||
1da177e4 LT |
741 | static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr) |
742 | { | |
743 | struct ethtool_eeprom eeprom; | |
76fd8593 | 744 | const struct ethtool_ops *ops = dev->ethtool_ops; |
b131dd5d MSB |
745 | void __user *userbuf = useraddr + sizeof(eeprom); |
746 | u32 bytes_remaining; | |
1da177e4 | 747 | u8 *data; |
b131dd5d | 748 | int ret = 0; |
1da177e4 LT |
749 | |
750 | if (!ops->get_eeprom || !ops->get_eeprom_len) | |
751 | return -EOPNOTSUPP; | |
752 | ||
753 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) | |
754 | return -EFAULT; | |
755 | ||
756 | /* Check for wrap and zero */ | |
757 | if (eeprom.offset + eeprom.len <= eeprom.offset) | |
758 | return -EINVAL; | |
759 | ||
760 | /* Check for exceeding total eeprom len */ | |
761 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) | |
762 | return -EINVAL; | |
763 | ||
b131dd5d | 764 | data = kmalloc(PAGE_SIZE, GFP_USER); |
1da177e4 LT |
765 | if (!data) |
766 | return -ENOMEM; | |
767 | ||
b131dd5d MSB |
768 | bytes_remaining = eeprom.len; |
769 | while (bytes_remaining > 0) { | |
770 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); | |
771 | ||
772 | ret = ops->get_eeprom(dev, &eeprom, data); | |
773 | if (ret) | |
774 | break; | |
775 | if (copy_to_user(userbuf, data, eeprom.len)) { | |
776 | ret = -EFAULT; | |
777 | break; | |
778 | } | |
779 | userbuf += eeprom.len; | |
780 | eeprom.offset += eeprom.len; | |
781 | bytes_remaining -= eeprom.len; | |
782 | } | |
1da177e4 | 783 | |
c5835df9 MSB |
784 | eeprom.len = userbuf - (useraddr + sizeof(eeprom)); |
785 | eeprom.offset -= eeprom.len; | |
786 | if (copy_to_user(useraddr, &eeprom, sizeof(eeprom))) | |
787 | ret = -EFAULT; | |
788 | ||
1da177e4 LT |
789 | kfree(data); |
790 | return ret; | |
791 | } | |
792 | ||
793 | static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr) | |
794 | { | |
795 | struct ethtool_eeprom eeprom; | |
76fd8593 | 796 | const struct ethtool_ops *ops = dev->ethtool_ops; |
b131dd5d MSB |
797 | void __user *userbuf = useraddr + sizeof(eeprom); |
798 | u32 bytes_remaining; | |
1da177e4 | 799 | u8 *data; |
b131dd5d | 800 | int ret = 0; |
1da177e4 LT |
801 | |
802 | if (!ops->set_eeprom || !ops->get_eeprom_len) | |
803 | return -EOPNOTSUPP; | |
804 | ||
805 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) | |
806 | return -EFAULT; | |
807 | ||
808 | /* Check for wrap and zero */ | |
809 | if (eeprom.offset + eeprom.len <= eeprom.offset) | |
810 | return -EINVAL; | |
811 | ||
812 | /* Check for exceeding total eeprom len */ | |
813 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) | |
814 | return -EINVAL; | |
815 | ||
b131dd5d | 816 | data = kmalloc(PAGE_SIZE, GFP_USER); |
1da177e4 LT |
817 | if (!data) |
818 | return -ENOMEM; | |
819 | ||
b131dd5d MSB |
820 | bytes_remaining = eeprom.len; |
821 | while (bytes_remaining > 0) { | |
822 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); | |
823 | ||
824 | if (copy_from_user(data, userbuf, eeprom.len)) { | |
825 | ret = -EFAULT; | |
826 | break; | |
827 | } | |
828 | ret = ops->set_eeprom(dev, &eeprom, data); | |
829 | if (ret) | |
830 | break; | |
831 | userbuf += eeprom.len; | |
832 | eeprom.offset += eeprom.len; | |
833 | bytes_remaining -= eeprom.len; | |
834 | } | |
1da177e4 | 835 | |
1da177e4 LT |
836 | kfree(data); |
837 | return ret; | |
838 | } | |
839 | ||
97f8aefb | 840 | static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, |
841 | void __user *useraddr) | |
1da177e4 | 842 | { |
8e557421 | 843 | struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; |
1da177e4 LT |
844 | |
845 | if (!dev->ethtool_ops->get_coalesce) | |
846 | return -EOPNOTSUPP; | |
847 | ||
848 | dev->ethtool_ops->get_coalesce(dev, &coalesce); | |
849 | ||
850 | if (copy_to_user(useraddr, &coalesce, sizeof(coalesce))) | |
851 | return -EFAULT; | |
852 | return 0; | |
853 | } | |
854 | ||
97f8aefb | 855 | static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, |
856 | void __user *useraddr) | |
1da177e4 LT |
857 | { |
858 | struct ethtool_coalesce coalesce; | |
859 | ||
fa04ae5c | 860 | if (!dev->ethtool_ops->set_coalesce) |
1da177e4 LT |
861 | return -EOPNOTSUPP; |
862 | ||
863 | if (copy_from_user(&coalesce, useraddr, sizeof(coalesce))) | |
864 | return -EFAULT; | |
865 | ||
866 | return dev->ethtool_ops->set_coalesce(dev, &coalesce); | |
867 | } | |
868 | ||
869 | static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr) | |
870 | { | |
8e557421 | 871 | struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM }; |
1da177e4 LT |
872 | |
873 | if (!dev->ethtool_ops->get_ringparam) | |
874 | return -EOPNOTSUPP; | |
875 | ||
876 | dev->ethtool_ops->get_ringparam(dev, &ringparam); | |
877 | ||
878 | if (copy_to_user(useraddr, &ringparam, sizeof(ringparam))) | |
879 | return -EFAULT; | |
880 | return 0; | |
881 | } | |
882 | ||
883 | static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr) | |
884 | { | |
885 | struct ethtool_ringparam ringparam; | |
886 | ||
887 | if (!dev->ethtool_ops->set_ringparam) | |
888 | return -EOPNOTSUPP; | |
889 | ||
890 | if (copy_from_user(&ringparam, useraddr, sizeof(ringparam))) | |
891 | return -EFAULT; | |
892 | ||
893 | return dev->ethtool_ops->set_ringparam(dev, &ringparam); | |
894 | } | |
895 | ||
8b5933c3 | 896 | static noinline_for_stack int ethtool_get_channels(struct net_device *dev, |
897 | void __user *useraddr) | |
898 | { | |
899 | struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS }; | |
900 | ||
901 | if (!dev->ethtool_ops->get_channels) | |
902 | return -EOPNOTSUPP; | |
903 | ||
904 | dev->ethtool_ops->get_channels(dev, &channels); | |
905 | ||
906 | if (copy_to_user(useraddr, &channels, sizeof(channels))) | |
907 | return -EFAULT; | |
908 | return 0; | |
909 | } | |
910 | ||
911 | static noinline_for_stack int ethtool_set_channels(struct net_device *dev, | |
912 | void __user *useraddr) | |
913 | { | |
914 | struct ethtool_channels channels; | |
915 | ||
916 | if (!dev->ethtool_ops->set_channels) | |
917 | return -EOPNOTSUPP; | |
918 | ||
919 | if (copy_from_user(&channels, useraddr, sizeof(channels))) | |
920 | return -EFAULT; | |
921 | ||
922 | return dev->ethtool_ops->set_channels(dev, &channels); | |
923 | } | |
924 | ||
1da177e4 LT |
925 | static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr) |
926 | { | |
927 | struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM }; | |
928 | ||
929 | if (!dev->ethtool_ops->get_pauseparam) | |
930 | return -EOPNOTSUPP; | |
931 | ||
932 | dev->ethtool_ops->get_pauseparam(dev, &pauseparam); | |
933 | ||
934 | if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam))) | |
935 | return -EFAULT; | |
936 | return 0; | |
937 | } | |
938 | ||
939 | static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr) | |
940 | { | |
941 | struct ethtool_pauseparam pauseparam; | |
942 | ||
e1b90c41 | 943 | if (!dev->ethtool_ops->set_pauseparam) |
1da177e4 LT |
944 | return -EOPNOTSUPP; |
945 | ||
946 | if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam))) | |
947 | return -EFAULT; | |
948 | ||
949 | return dev->ethtool_ops->set_pauseparam(dev, &pauseparam); | |
950 | } | |
951 | ||
1da177e4 LT |
952 | static int ethtool_self_test(struct net_device *dev, char __user *useraddr) |
953 | { | |
954 | struct ethtool_test test; | |
76fd8593 | 955 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 | 956 | u64 *data; |
ff03d49f | 957 | int ret, test_len; |
1da177e4 | 958 | |
a9828ec6 | 959 | if (!ops->self_test || !ops->get_sset_count) |
1da177e4 LT |
960 | return -EOPNOTSUPP; |
961 | ||
a9828ec6 | 962 | test_len = ops->get_sset_count(dev, ETH_SS_TEST); |
ff03d49f JG |
963 | if (test_len < 0) |
964 | return test_len; | |
965 | WARN_ON(test_len == 0); | |
966 | ||
1da177e4 LT |
967 | if (copy_from_user(&test, useraddr, sizeof(test))) |
968 | return -EFAULT; | |
969 | ||
ff03d49f JG |
970 | test.len = test_len; |
971 | data = kmalloc(test_len * sizeof(u64), GFP_USER); | |
1da177e4 LT |
972 | if (!data) |
973 | return -ENOMEM; | |
974 | ||
975 | ops->self_test(dev, &test, data); | |
976 | ||
977 | ret = -EFAULT; | |
978 | if (copy_to_user(useraddr, &test, sizeof(test))) | |
979 | goto out; | |
980 | useraddr += sizeof(test); | |
981 | if (copy_to_user(useraddr, data, test.len * sizeof(u64))) | |
982 | goto out; | |
983 | ret = 0; | |
984 | ||
985 | out: | |
986 | kfree(data); | |
987 | return ret; | |
988 | } | |
989 | ||
990 | static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) | |
991 | { | |
992 | struct ethtool_gstrings gstrings; | |
1da177e4 LT |
993 | u8 *data; |
994 | int ret; | |
995 | ||
1da177e4 LT |
996 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) |
997 | return -EFAULT; | |
998 | ||
340ae165 | 999 | ret = __ethtool_get_sset_count(dev, gstrings.string_set); |
a9828ec6 BH |
1000 | if (ret < 0) |
1001 | return ret; | |
1002 | ||
1003 | gstrings.len = ret; | |
1da177e4 LT |
1004 | |
1005 | data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER); | |
1006 | if (!data) | |
1007 | return -ENOMEM; | |
1008 | ||
340ae165 | 1009 | __ethtool_get_strings(dev, gstrings.string_set, data); |
1da177e4 LT |
1010 | |
1011 | ret = -EFAULT; | |
1012 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) | |
1013 | goto out; | |
1014 | useraddr += sizeof(gstrings); | |
1015 | if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN)) | |
1016 | goto out; | |
1017 | ret = 0; | |
1018 | ||
340ae165 | 1019 | out: |
1da177e4 LT |
1020 | kfree(data); |
1021 | return ret; | |
1022 | } | |
1023 | ||
1024 | static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) | |
1025 | { | |
1026 | struct ethtool_value id; | |
68f512f2 BH |
1027 | static bool busy; |
1028 | int rc; | |
1da177e4 | 1029 | |
1ab7b6ac | 1030 | if (!dev->ethtool_ops->set_phys_id) |
1da177e4 LT |
1031 | return -EOPNOTSUPP; |
1032 | ||
68f512f2 BH |
1033 | if (busy) |
1034 | return -EBUSY; | |
1035 | ||
1da177e4 LT |
1036 | if (copy_from_user(&id, useraddr, sizeof(id))) |
1037 | return -EFAULT; | |
1038 | ||
68f512f2 | 1039 | rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE); |
fce55922 | 1040 | if (rc < 0) |
68f512f2 BH |
1041 | return rc; |
1042 | ||
1043 | /* Drop the RTNL lock while waiting, but prevent reentry or | |
1044 | * removal of the device. | |
1045 | */ | |
1046 | busy = true; | |
1047 | dev_hold(dev); | |
1048 | rtnl_unlock(); | |
1049 | ||
1050 | if (rc == 0) { | |
1051 | /* Driver will handle this itself */ | |
1052 | schedule_timeout_interruptible( | |
143780c6 | 1053 | id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT); |
68f512f2 | 1054 | } else { |
fce55922 AB |
1055 | /* Driver expects to be called at twice the frequency in rc */ |
1056 | int n = rc * 2, i, interval = HZ / n; | |
1057 | ||
1058 | /* Count down seconds */ | |
68f512f2 | 1059 | do { |
fce55922 AB |
1060 | /* Count down iterations per second */ |
1061 | i = n; | |
1062 | do { | |
1063 | rtnl_lock(); | |
1064 | rc = dev->ethtool_ops->set_phys_id(dev, | |
1065 | (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON); | |
1066 | rtnl_unlock(); | |
1067 | if (rc) | |
1068 | break; | |
1069 | schedule_timeout_interruptible(interval); | |
1070 | } while (!signal_pending(current) && --i != 0); | |
68f512f2 BH |
1071 | } while (!signal_pending(current) && |
1072 | (id.data == 0 || --id.data != 0)); | |
1073 | } | |
1074 | ||
1075 | rtnl_lock(); | |
1076 | dev_put(dev); | |
1077 | busy = false; | |
1078 | ||
1079 | (void)dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE); | |
1080 | return rc; | |
1da177e4 LT |
1081 | } |
1082 | ||
1083 | static int ethtool_get_stats(struct net_device *dev, void __user *useraddr) | |
1084 | { | |
1085 | struct ethtool_stats stats; | |
76fd8593 | 1086 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 | 1087 | u64 *data; |
ff03d49f | 1088 | int ret, n_stats; |
1da177e4 | 1089 | |
a9828ec6 | 1090 | if (!ops->get_ethtool_stats || !ops->get_sset_count) |
1da177e4 LT |
1091 | return -EOPNOTSUPP; |
1092 | ||
a9828ec6 | 1093 | n_stats = ops->get_sset_count(dev, ETH_SS_STATS); |
ff03d49f JG |
1094 | if (n_stats < 0) |
1095 | return n_stats; | |
1096 | WARN_ON(n_stats == 0); | |
1097 | ||
1da177e4 LT |
1098 | if (copy_from_user(&stats, useraddr, sizeof(stats))) |
1099 | return -EFAULT; | |
1100 | ||
ff03d49f JG |
1101 | stats.n_stats = n_stats; |
1102 | data = kmalloc(n_stats * sizeof(u64), GFP_USER); | |
1da177e4 LT |
1103 | if (!data) |
1104 | return -ENOMEM; | |
1105 | ||
1106 | ops->get_ethtool_stats(dev, &stats, data); | |
1107 | ||
1108 | ret = -EFAULT; | |
1109 | if (copy_to_user(useraddr, &stats, sizeof(stats))) | |
1110 | goto out; | |
1111 | useraddr += sizeof(stats); | |
1112 | if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64))) | |
1113 | goto out; | |
1114 | ret = 0; | |
1115 | ||
1116 | out: | |
1117 | kfree(data); | |
1118 | return ret; | |
1119 | } | |
1120 | ||
0bf0519d | 1121 | static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr) |
a6f9a705 JW |
1122 | { |
1123 | struct ethtool_perm_addr epaddr; | |
a6f9a705 | 1124 | |
313674af | 1125 | if (copy_from_user(&epaddr, useraddr, sizeof(epaddr))) |
a6f9a705 JW |
1126 | return -EFAULT; |
1127 | ||
313674af MW |
1128 | if (epaddr.size < dev->addr_len) |
1129 | return -ETOOSMALL; | |
1130 | epaddr.size = dev->addr_len; | |
a6f9a705 | 1131 | |
a6f9a705 | 1132 | if (copy_to_user(useraddr, &epaddr, sizeof(epaddr))) |
313674af | 1133 | return -EFAULT; |
a6f9a705 | 1134 | useraddr += sizeof(epaddr); |
313674af MW |
1135 | if (copy_to_user(useraddr, dev->perm_addr, epaddr.size)) |
1136 | return -EFAULT; | |
1137 | return 0; | |
a6f9a705 JW |
1138 | } |
1139 | ||
13c99b24 JG |
1140 | static int ethtool_get_value(struct net_device *dev, char __user *useraddr, |
1141 | u32 cmd, u32 (*actor)(struct net_device *)) | |
3ae7c0b2 | 1142 | { |
8e557421 | 1143 | struct ethtool_value edata = { .cmd = cmd }; |
3ae7c0b2 | 1144 | |
13c99b24 | 1145 | if (!actor) |
3ae7c0b2 JG |
1146 | return -EOPNOTSUPP; |
1147 | ||
13c99b24 | 1148 | edata.data = actor(dev); |
3ae7c0b2 JG |
1149 | |
1150 | if (copy_to_user(useraddr, &edata, sizeof(edata))) | |
1151 | return -EFAULT; | |
1152 | return 0; | |
1153 | } | |
1154 | ||
13c99b24 JG |
1155 | static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr, |
1156 | void (*actor)(struct net_device *, u32)) | |
3ae7c0b2 JG |
1157 | { |
1158 | struct ethtool_value edata; | |
1159 | ||
13c99b24 | 1160 | if (!actor) |
3ae7c0b2 JG |
1161 | return -EOPNOTSUPP; |
1162 | ||
1163 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1164 | return -EFAULT; | |
1165 | ||
13c99b24 | 1166 | actor(dev, edata.data); |
339bf024 JG |
1167 | return 0; |
1168 | } | |
1169 | ||
13c99b24 JG |
1170 | static int ethtool_set_value(struct net_device *dev, char __user *useraddr, |
1171 | int (*actor)(struct net_device *, u32)) | |
339bf024 JG |
1172 | { |
1173 | struct ethtool_value edata; | |
1174 | ||
13c99b24 | 1175 | if (!actor) |
339bf024 JG |
1176 | return -EOPNOTSUPP; |
1177 | ||
1178 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1179 | return -EFAULT; | |
1180 | ||
13c99b24 | 1181 | return actor(dev, edata.data); |
339bf024 JG |
1182 | } |
1183 | ||
97f8aefb | 1184 | static noinline_for_stack int ethtool_flash_device(struct net_device *dev, |
1185 | char __user *useraddr) | |
05c6a8d7 AK |
1186 | { |
1187 | struct ethtool_flash efl; | |
1188 | ||
1189 | if (copy_from_user(&efl, useraddr, sizeof(efl))) | |
1190 | return -EFAULT; | |
1191 | ||
1192 | if (!dev->ethtool_ops->flash_device) | |
1193 | return -EOPNOTSUPP; | |
1194 | ||
786f5281 BH |
1195 | efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0; |
1196 | ||
05c6a8d7 AK |
1197 | return dev->ethtool_ops->flash_device(dev, &efl); |
1198 | } | |
1199 | ||
29dd54b7 AC |
1200 | static int ethtool_set_dump(struct net_device *dev, |
1201 | void __user *useraddr) | |
1202 | { | |
1203 | struct ethtool_dump dump; | |
1204 | ||
1205 | if (!dev->ethtool_ops->set_dump) | |
1206 | return -EOPNOTSUPP; | |
1207 | ||
1208 | if (copy_from_user(&dump, useraddr, sizeof(dump))) | |
1209 | return -EFAULT; | |
1210 | ||
1211 | return dev->ethtool_ops->set_dump(dev, &dump); | |
1212 | } | |
1213 | ||
1214 | static int ethtool_get_dump_flag(struct net_device *dev, | |
1215 | void __user *useraddr) | |
1216 | { | |
1217 | int ret; | |
1218 | struct ethtool_dump dump; | |
1219 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
1220 | ||
1221 | if (!dev->ethtool_ops->get_dump_flag) | |
1222 | return -EOPNOTSUPP; | |
1223 | ||
1224 | if (copy_from_user(&dump, useraddr, sizeof(dump))) | |
1225 | return -EFAULT; | |
1226 | ||
1227 | ret = ops->get_dump_flag(dev, &dump); | |
1228 | if (ret) | |
1229 | return ret; | |
1230 | ||
1231 | if (copy_to_user(useraddr, &dump, sizeof(dump))) | |
1232 | return -EFAULT; | |
1233 | return 0; | |
1234 | } | |
1235 | ||
1236 | static int ethtool_get_dump_data(struct net_device *dev, | |
1237 | void __user *useraddr) | |
1238 | { | |
1239 | int ret; | |
1240 | __u32 len; | |
1241 | struct ethtool_dump dump, tmp; | |
1242 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
1243 | void *data = NULL; | |
1244 | ||
1245 | if (!dev->ethtool_ops->get_dump_data || | |
1246 | !dev->ethtool_ops->get_dump_flag) | |
1247 | return -EOPNOTSUPP; | |
1248 | ||
1249 | if (copy_from_user(&dump, useraddr, sizeof(dump))) | |
1250 | return -EFAULT; | |
1251 | ||
1252 | memset(&tmp, 0, sizeof(tmp)); | |
1253 | tmp.cmd = ETHTOOL_GET_DUMP_FLAG; | |
1254 | ret = ops->get_dump_flag(dev, &tmp); | |
1255 | if (ret) | |
1256 | return ret; | |
1257 | ||
1258 | len = (tmp.len > dump.len) ? dump.len : tmp.len; | |
1259 | if (!len) | |
1260 | return -EFAULT; | |
1261 | ||
1262 | data = vzalloc(tmp.len); | |
1263 | if (!data) | |
1264 | return -ENOMEM; | |
1265 | ret = ops->get_dump_data(dev, &dump, data); | |
1266 | if (ret) | |
1267 | goto out; | |
1268 | ||
1269 | if (copy_to_user(useraddr, &dump, sizeof(dump))) { | |
1270 | ret = -EFAULT; | |
1271 | goto out; | |
1272 | } | |
1273 | useraddr += offsetof(struct ethtool_dump, data); | |
1274 | if (copy_to_user(useraddr, data, len)) | |
1275 | ret = -EFAULT; | |
1276 | out: | |
1277 | vfree(data); | |
1278 | return ret; | |
1279 | } | |
1280 | ||
1da177e4 LT |
1281 | /* The main entry point in this file. Called from net/core/dev.c */ |
1282 | ||
881d966b | 1283 | int dev_ethtool(struct net *net, struct ifreq *ifr) |
1da177e4 | 1284 | { |
881d966b | 1285 | struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); |
1da177e4 LT |
1286 | void __user *useraddr = ifr->ifr_data; |
1287 | u32 ethcmd; | |
1288 | int rc; | |
04ed3e74 | 1289 | u32 old_features; |
1da177e4 | 1290 | |
1da177e4 LT |
1291 | if (!dev || !netif_device_present(dev)) |
1292 | return -ENODEV; | |
1293 | ||
97f8aefb | 1294 | if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) |
1da177e4 LT |
1295 | return -EFAULT; |
1296 | ||
01414802 BH |
1297 | if (!dev->ethtool_ops) { |
1298 | /* ETHTOOL_GDRVINFO does not require any driver support. | |
1299 | * It is also unprivileged and does not change anything, | |
1300 | * so we can take a shortcut to it. */ | |
1301 | if (ethcmd == ETHTOOL_GDRVINFO) | |
1302 | return ethtool_get_drvinfo(dev, useraddr); | |
1303 | else | |
1304 | return -EOPNOTSUPP; | |
1305 | } | |
1306 | ||
75f3123c | 1307 | /* Allow some commands to be done by anyone */ |
97f8aefb | 1308 | switch (ethcmd) { |
0fdc100b | 1309 | case ETHTOOL_GSET: |
75f3123c | 1310 | case ETHTOOL_GDRVINFO: |
75f3123c | 1311 | case ETHTOOL_GMSGLVL: |
75f3123c SH |
1312 | case ETHTOOL_GCOALESCE: |
1313 | case ETHTOOL_GRINGPARAM: | |
1314 | case ETHTOOL_GPAUSEPARAM: | |
1315 | case ETHTOOL_GRXCSUM: | |
1316 | case ETHTOOL_GTXCSUM: | |
1317 | case ETHTOOL_GSG: | |
f80400a2 | 1318 | case ETHTOOL_GSSET_INFO: |
75f3123c | 1319 | case ETHTOOL_GSTRINGS: |
75f3123c SH |
1320 | case ETHTOOL_GTSO: |
1321 | case ETHTOOL_GPERMADDR: | |
1322 | case ETHTOOL_GUFO: | |
1323 | case ETHTOOL_GGSO: | |
1cab819b | 1324 | case ETHTOOL_GGRO: |
339bf024 JG |
1325 | case ETHTOOL_GFLAGS: |
1326 | case ETHTOOL_GPFLAGS: | |
0853ad66 | 1327 | case ETHTOOL_GRXFH: |
59089d8d SB |
1328 | case ETHTOOL_GRXRINGS: |
1329 | case ETHTOOL_GRXCLSRLCNT: | |
1330 | case ETHTOOL_GRXCLSRULE: | |
1331 | case ETHTOOL_GRXCLSRLALL: | |
5455c699 | 1332 | case ETHTOOL_GFEATURES: |
75f3123c SH |
1333 | break; |
1334 | default: | |
1335 | if (!capable(CAP_NET_ADMIN)) | |
1336 | return -EPERM; | |
1337 | } | |
1338 | ||
97f8aefb | 1339 | if (dev->ethtool_ops->begin) { |
1340 | rc = dev->ethtool_ops->begin(dev); | |
1341 | if (rc < 0) | |
1da177e4 | 1342 | return rc; |
97f8aefb | 1343 | } |
d8a33ac4 SH |
1344 | old_features = dev->features; |
1345 | ||
1da177e4 LT |
1346 | switch (ethcmd) { |
1347 | case ETHTOOL_GSET: | |
1348 | rc = ethtool_get_settings(dev, useraddr); | |
1349 | break; | |
1350 | case ETHTOOL_SSET: | |
1351 | rc = ethtool_set_settings(dev, useraddr); | |
1352 | break; | |
1353 | case ETHTOOL_GDRVINFO: | |
1354 | rc = ethtool_get_drvinfo(dev, useraddr); | |
1da177e4 LT |
1355 | break; |
1356 | case ETHTOOL_GREGS: | |
1357 | rc = ethtool_get_regs(dev, useraddr); | |
1358 | break; | |
1359 | case ETHTOOL_GWOL: | |
1360 | rc = ethtool_get_wol(dev, useraddr); | |
1361 | break; | |
1362 | case ETHTOOL_SWOL: | |
1363 | rc = ethtool_set_wol(dev, useraddr); | |
1364 | break; | |
1365 | case ETHTOOL_GMSGLVL: | |
13c99b24 JG |
1366 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1367 | dev->ethtool_ops->get_msglevel); | |
1da177e4 LT |
1368 | break; |
1369 | case ETHTOOL_SMSGLVL: | |
13c99b24 JG |
1370 | rc = ethtool_set_value_void(dev, useraddr, |
1371 | dev->ethtool_ops->set_msglevel); | |
1da177e4 LT |
1372 | break; |
1373 | case ETHTOOL_NWAY_RST: | |
1374 | rc = ethtool_nway_reset(dev); | |
1375 | break; | |
1376 | case ETHTOOL_GLINK: | |
e596e6e4 | 1377 | rc = ethtool_get_link(dev, useraddr); |
1da177e4 LT |
1378 | break; |
1379 | case ETHTOOL_GEEPROM: | |
1380 | rc = ethtool_get_eeprom(dev, useraddr); | |
1381 | break; | |
1382 | case ETHTOOL_SEEPROM: | |
1383 | rc = ethtool_set_eeprom(dev, useraddr); | |
1384 | break; | |
1385 | case ETHTOOL_GCOALESCE: | |
1386 | rc = ethtool_get_coalesce(dev, useraddr); | |
1387 | break; | |
1388 | case ETHTOOL_SCOALESCE: | |
1389 | rc = ethtool_set_coalesce(dev, useraddr); | |
1390 | break; | |
1391 | case ETHTOOL_GRINGPARAM: | |
1392 | rc = ethtool_get_ringparam(dev, useraddr); | |
1393 | break; | |
1394 | case ETHTOOL_SRINGPARAM: | |
1395 | rc = ethtool_set_ringparam(dev, useraddr); | |
1396 | break; | |
1397 | case ETHTOOL_GPAUSEPARAM: | |
1398 | rc = ethtool_get_pauseparam(dev, useraddr); | |
1399 | break; | |
1400 | case ETHTOOL_SPAUSEPARAM: | |
1401 | rc = ethtool_set_pauseparam(dev, useraddr); | |
1402 | break; | |
1da177e4 LT |
1403 | case ETHTOOL_TEST: |
1404 | rc = ethtool_self_test(dev, useraddr); | |
1405 | break; | |
1406 | case ETHTOOL_GSTRINGS: | |
1407 | rc = ethtool_get_strings(dev, useraddr); | |
1408 | break; | |
1409 | case ETHTOOL_PHYS_ID: | |
1410 | rc = ethtool_phys_id(dev, useraddr); | |
1411 | break; | |
1412 | case ETHTOOL_GSTATS: | |
1413 | rc = ethtool_get_stats(dev, useraddr); | |
1414 | break; | |
a6f9a705 JW |
1415 | case ETHTOOL_GPERMADDR: |
1416 | rc = ethtool_get_perm_addr(dev, useraddr); | |
1417 | break; | |
3ae7c0b2 | 1418 | case ETHTOOL_GFLAGS: |
13c99b24 | 1419 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
bc5787c6 | 1420 | __ethtool_get_flags); |
3ae7c0b2 JG |
1421 | break; |
1422 | case ETHTOOL_SFLAGS: | |
da8ac86c | 1423 | rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags); |
3ae7c0b2 | 1424 | break; |
339bf024 | 1425 | case ETHTOOL_GPFLAGS: |
13c99b24 JG |
1426 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
1427 | dev->ethtool_ops->get_priv_flags); | |
339bf024 JG |
1428 | break; |
1429 | case ETHTOOL_SPFLAGS: | |
13c99b24 JG |
1430 | rc = ethtool_set_value(dev, useraddr, |
1431 | dev->ethtool_ops->set_priv_flags); | |
339bf024 | 1432 | break; |
0853ad66 | 1433 | case ETHTOOL_GRXFH: |
59089d8d SB |
1434 | case ETHTOOL_GRXRINGS: |
1435 | case ETHTOOL_GRXCLSRLCNT: | |
1436 | case ETHTOOL_GRXCLSRULE: | |
1437 | case ETHTOOL_GRXCLSRLALL: | |
bf988435 | 1438 | rc = ethtool_get_rxnfc(dev, ethcmd, useraddr); |
0853ad66 SB |
1439 | break; |
1440 | case ETHTOOL_SRXFH: | |
59089d8d SB |
1441 | case ETHTOOL_SRXCLSRLDEL: |
1442 | case ETHTOOL_SRXCLSRLINS: | |
bf988435 | 1443 | rc = ethtool_set_rxnfc(dev, ethcmd, useraddr); |
0853ad66 | 1444 | break; |
05c6a8d7 AK |
1445 | case ETHTOOL_FLASHDEV: |
1446 | rc = ethtool_flash_device(dev, useraddr); | |
1447 | break; | |
d73d3a8c BH |
1448 | case ETHTOOL_RESET: |
1449 | rc = ethtool_reset(dev, useraddr); | |
1450 | break; | |
723b2f57 JG |
1451 | case ETHTOOL_GSSET_INFO: |
1452 | rc = ethtool_get_sset_info(dev, useraddr); | |
1453 | break; | |
a5b6ee29 BH |
1454 | case ETHTOOL_GRXFHINDIR: |
1455 | rc = ethtool_get_rxfh_indir(dev, useraddr); | |
1456 | break; | |
1457 | case ETHTOOL_SRXFHINDIR: | |
1458 | rc = ethtool_set_rxfh_indir(dev, useraddr); | |
1459 | break; | |
5455c699 MM |
1460 | case ETHTOOL_GFEATURES: |
1461 | rc = ethtool_get_features(dev, useraddr); | |
1462 | break; | |
1463 | case ETHTOOL_SFEATURES: | |
1464 | rc = ethtool_set_features(dev, useraddr); | |
1465 | break; | |
0a417704 | 1466 | case ETHTOOL_GTXCSUM: |
e83d360d | 1467 | case ETHTOOL_GRXCSUM: |
0a417704 MM |
1468 | case ETHTOOL_GSG: |
1469 | case ETHTOOL_GTSO: | |
1470 | case ETHTOOL_GUFO: | |
1471 | case ETHTOOL_GGSO: | |
1472 | case ETHTOOL_GGRO: | |
1473 | rc = ethtool_get_one_feature(dev, useraddr, ethcmd); | |
1474 | break; | |
1475 | case ETHTOOL_STXCSUM: | |
e83d360d | 1476 | case ETHTOOL_SRXCSUM: |
0a417704 MM |
1477 | case ETHTOOL_SSG: |
1478 | case ETHTOOL_STSO: | |
1479 | case ETHTOOL_SUFO: | |
1480 | case ETHTOOL_SGSO: | |
1481 | case ETHTOOL_SGRO: | |
1482 | rc = ethtool_set_one_feature(dev, useraddr, ethcmd); | |
1483 | break; | |
8b5933c3 | 1484 | case ETHTOOL_GCHANNELS: |
1485 | rc = ethtool_get_channels(dev, useraddr); | |
1486 | break; | |
1487 | case ETHTOOL_SCHANNELS: | |
1488 | rc = ethtool_set_channels(dev, useraddr); | |
1489 | break; | |
29dd54b7 AC |
1490 | case ETHTOOL_SET_DUMP: |
1491 | rc = ethtool_set_dump(dev, useraddr); | |
1492 | break; | |
1493 | case ETHTOOL_GET_DUMP_FLAG: | |
1494 | rc = ethtool_get_dump_flag(dev, useraddr); | |
1495 | break; | |
1496 | case ETHTOOL_GET_DUMP_DATA: | |
1497 | rc = ethtool_get_dump_data(dev, useraddr); | |
1498 | break; | |
1da177e4 | 1499 | default: |
61a44b9c | 1500 | rc = -EOPNOTSUPP; |
1da177e4 | 1501 | } |
4ec93edb | 1502 | |
e71a4783 | 1503 | if (dev->ethtool_ops->complete) |
1da177e4 | 1504 | dev->ethtool_ops->complete(dev); |
d8a33ac4 SH |
1505 | |
1506 | if (old_features != dev->features) | |
1507 | netdev_features_change(dev); | |
1508 | ||
1da177e4 | 1509 | return rc; |
1da177e4 | 1510 | } |