]>
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> | |
c8f3a8c3 RC |
20 | #include <linux/net_tstamp.h> |
21 | #include <linux/phy.h> | |
d17792eb | 22 | #include <linux/bitops.h> |
97f8aefb | 23 | #include <linux/uaccess.h> |
73da16c2 | 24 | #include <linux/vmalloc.h> |
e679c9c1 | 25 | #include <linux/sfp.h> |
5a0e3ad6 | 26 | #include <linux/slab.h> |
68f512f2 | 27 | #include <linux/rtnetlink.h> |
174cd4b1 | 28 | #include <linux/sched/signal.h> |
960fb622 | 29 | #include <linux/net.h> |
1da177e4 | 30 | |
4ec93edb | 31 | /* |
1da177e4 LT |
32 | * Some useful ethtool_ops methods that're device independent. |
33 | * If we find that all drivers want to do the same thing here, | |
34 | * we can turn these into dev_() function calls. | |
35 | */ | |
36 | ||
37 | u32 ethtool_op_get_link(struct net_device *dev) | |
38 | { | |
39 | return netif_carrier_ok(dev) ? 1 : 0; | |
40 | } | |
97f8aefb | 41 | EXPORT_SYMBOL(ethtool_op_get_link); |
1da177e4 | 42 | |
02eacbd0 RC |
43 | int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) |
44 | { | |
45 | info->so_timestamping = | |
46 | SOF_TIMESTAMPING_TX_SOFTWARE | | |
47 | SOF_TIMESTAMPING_RX_SOFTWARE | | |
48 | SOF_TIMESTAMPING_SOFTWARE; | |
49 | info->phc_index = -1; | |
50 | return 0; | |
51 | } | |
52 | EXPORT_SYMBOL(ethtool_op_get_ts_info); | |
53 | ||
1da177e4 LT |
54 | /* Handlers for each ethtool command */ |
55 | ||
475414f6 | 56 | #define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32) |
5455c699 | 57 | |
9d921549 MM |
58 | static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = { |
59 | [NETIF_F_SG_BIT] = "tx-scatter-gather", | |
60 | [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4", | |
9d921549 MM |
61 | [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic", |
62 | [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6", | |
63 | [NETIF_F_HIGHDMA_BIT] = "highdma", | |
64 | [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist", | |
788dfcac | 65 | [NETIF_F_HW_VLAN_CTAG_TX_BIT] = "tx-vlan-hw-insert", |
9d921549 | 66 | |
788dfcac FLVC |
67 | [NETIF_F_HW_VLAN_CTAG_RX_BIT] = "rx-vlan-hw-parse", |
68 | [NETIF_F_HW_VLAN_CTAG_FILTER_BIT] = "rx-vlan-filter", | |
2d6577f1 DM |
69 | [NETIF_F_HW_VLAN_STAG_TX_BIT] = "tx-vlan-stag-hw-insert", |
70 | [NETIF_F_HW_VLAN_STAG_RX_BIT] = "rx-vlan-stag-hw-parse", | |
71 | [NETIF_F_HW_VLAN_STAG_FILTER_BIT] = "rx-vlan-stag-filter", | |
9d921549 MM |
72 | [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged", |
73 | [NETIF_F_GSO_BIT] = "tx-generic-segmentation", | |
74 | [NETIF_F_LLTX_BIT] = "tx-lockless", | |
75 | [NETIF_F_NETNS_LOCAL_BIT] = "netns-local", | |
76 | [NETIF_F_GRO_BIT] = "rx-gro", | |
fb1f5f79 | 77 | [NETIF_F_GRO_HW_BIT] = "rx-gro-hw", |
9d921549 MM |
78 | [NETIF_F_LRO_BIT] = "rx-lro", |
79 | ||
80 | [NETIF_F_TSO_BIT] = "tx-tcp-segmentation", | |
9d921549 MM |
81 | [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust", |
82 | [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation", | |
cbc53e08 | 83 | [NETIF_F_TSO_MANGLEID_BIT] = "tx-tcp-mangleid-segmentation", |
9d921549 MM |
84 | [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation", |
85 | [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation", | |
68c33163 | 86 | [NETIF_F_GSO_GRE_BIT] = "tx-gre-segmentation", |
518f213d | 87 | [NETIF_F_GSO_GRE_CSUM_BIT] = "tx-gre-csum-segmentation", |
7e13318d TH |
88 | [NETIF_F_GSO_IPXIP4_BIT] = "tx-ipxip4-segmentation", |
89 | [NETIF_F_GSO_IPXIP6_BIT] = "tx-ipxip6-segmentation", | |
73136267 | 90 | [NETIF_F_GSO_UDP_TUNNEL_BIT] = "tx-udp_tnl-segmentation", |
518f213d | 91 | [NETIF_F_GSO_UDP_TUNNEL_CSUM_BIT] = "tx-udp_tnl-csum-segmentation", |
802ab55a | 92 | [NETIF_F_GSO_PARTIAL_BIT] = "tx-gso-partial", |
90017acc | 93 | [NETIF_F_GSO_SCTP_BIT] = "tx-sctp-segmentation", |
c7ef8f0c | 94 | [NETIF_F_GSO_ESP_BIT] = "tx-esp-segmentation", |
83aa025f | 95 | [NETIF_F_GSO_UDP_L4_BIT] = "tx-udp-segmentation", |
9d921549 MM |
96 | |
97 | [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc", | |
53692b1d | 98 | [NETIF_F_SCTP_CRC_BIT] = "tx-checksum-sctp", |
9d921549 MM |
99 | [NETIF_F_FCOE_MTU_BIT] = "fcoe-mtu", |
100 | [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter", | |
101 | [NETIF_F_RXHASH_BIT] = "rx-hashing", | |
102 | [NETIF_F_RXCSUM_BIT] = "rx-checksum", | |
103 | [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy", | |
104 | [NETIF_F_LOOPBACK_BIT] = "loopback", | |
36eabda3 | 105 | [NETIF_F_RXFCS_BIT] = "rx-fcs", |
5e0c03c8 | 106 | [NETIF_F_RXALL_BIT] = "rx-all", |
a6cc0cfa | 107 | [NETIF_F_HW_L2FW_DOFFLOAD_BIT] = "l2-fwd-offload", |
1c78c64e | 108 | [NETIF_F_HW_TC_BIT] = "hw-tc-offload", |
c7ef8f0c SK |
109 | [NETIF_F_HW_ESP_BIT] = "esp-hw-offload", |
110 | [NETIF_F_HW_ESP_TX_CSUM_BIT] = "esp-tx-csum-hw-offload", | |
d764a122 | 111 | [NETIF_F_RX_UDP_TUNNEL_PORT_BIT] = "rx-udp_tunnel-port-offload", |
e0be6bea | 112 | [NETIF_F_HW_TLS_RECORD_BIT] = "tls-hw-record", |
9d921549 MM |
113 | }; |
114 | ||
892311f6 EP |
115 | static const char |
116 | rss_hash_func_strings[ETH_RSS_HASH_FUNCS_COUNT][ETH_GSTRING_LEN] = { | |
117 | [ETH_RSS_HASH_TOP_BIT] = "toeplitz", | |
118 | [ETH_RSS_HASH_XOR_BIT] = "xor", | |
abb521e3 | 119 | [ETH_RSS_HASH_CRC32_BIT] = "crc32", |
892311f6 EP |
120 | }; |
121 | ||
a4244b0c HHZ |
122 | static const char |
123 | tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN] = { | |
124 | [ETHTOOL_ID_UNSPEC] = "Unspec", | |
125 | [ETHTOOL_RX_COPYBREAK] = "rx-copybreak", | |
126 | [ETHTOOL_TX_COPYBREAK] = "tx-copybreak", | |
e1577c1c | 127 | [ETHTOOL_PFC_PREVENTION_TOUT] = "pfc-prevention-tout", |
a4244b0c HHZ |
128 | }; |
129 | ||
968ad9da RL |
130 | static const char |
131 | phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN] = { | |
132 | [ETHTOOL_ID_UNSPEC] = "Unspec", | |
65feddd5 | 133 | [ETHTOOL_PHY_DOWNSHIFT] = "phy-downshift", |
968ad9da RL |
134 | }; |
135 | ||
5455c699 MM |
136 | static int ethtool_get_features(struct net_device *dev, void __user *useraddr) |
137 | { | |
138 | struct ethtool_gfeatures cmd = { | |
139 | .cmd = ETHTOOL_GFEATURES, | |
140 | .size = ETHTOOL_DEV_FEATURE_WORDS, | |
141 | }; | |
475414f6 | 142 | struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS]; |
5455c699 MM |
143 | u32 __user *sizeaddr; |
144 | u32 copy_size; | |
475414f6 MM |
145 | int i; |
146 | ||
147 | /* in case feature bits run out again */ | |
09da71b1 | 148 | BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t)); |
475414f6 MM |
149 | |
150 | for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) { | |
09da71b1 MM |
151 | features[i].available = (u32)(dev->hw_features >> (32 * i)); |
152 | features[i].requested = (u32)(dev->wanted_features >> (32 * i)); | |
153 | features[i].active = (u32)(dev->features >> (32 * i)); | |
154 | features[i].never_changed = | |
155 | (u32)(NETIF_F_NEVER_CHANGE >> (32 * i)); | |
475414f6 | 156 | } |
5455c699 MM |
157 | |
158 | sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size); | |
159 | if (get_user(copy_size, sizeaddr)) | |
160 | return -EFAULT; | |
161 | ||
162 | if (copy_size > ETHTOOL_DEV_FEATURE_WORDS) | |
163 | copy_size = ETHTOOL_DEV_FEATURE_WORDS; | |
164 | ||
165 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) | |
166 | return -EFAULT; | |
167 | useraddr += sizeof(cmd); | |
168 | if (copy_to_user(useraddr, features, copy_size * sizeof(*features))) | |
169 | return -EFAULT; | |
170 | ||
171 | return 0; | |
172 | } | |
173 | ||
174 | static int ethtool_set_features(struct net_device *dev, void __user *useraddr) | |
175 | { | |
176 | struct ethtool_sfeatures cmd; | |
177 | struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS]; | |
475414f6 MM |
178 | netdev_features_t wanted = 0, valid = 0; |
179 | int i, ret = 0; | |
5455c699 MM |
180 | |
181 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) | |
182 | return -EFAULT; | |
183 | useraddr += sizeof(cmd); | |
184 | ||
185 | if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS) | |
186 | return -EINVAL; | |
187 | ||
188 | if (copy_from_user(features, useraddr, sizeof(features))) | |
189 | return -EFAULT; | |
190 | ||
475414f6 | 191 | for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) { |
09da71b1 MM |
192 | valid |= (netdev_features_t)features[i].valid << (32 * i); |
193 | wanted |= (netdev_features_t)features[i].requested << (32 * i); | |
475414f6 MM |
194 | } |
195 | ||
196 | if (valid & ~NETIF_F_ETHTOOL_BITS) | |
5455c699 MM |
197 | return -EINVAL; |
198 | ||
475414f6 MM |
199 | if (valid & ~dev->hw_features) { |
200 | valid &= dev->hw_features; | |
5455c699 MM |
201 | ret |= ETHTOOL_F_UNSUPPORTED; |
202 | } | |
203 | ||
475414f6 MM |
204 | dev->wanted_features &= ~valid; |
205 | dev->wanted_features |= wanted & valid; | |
6cb6a27c | 206 | __netdev_update_features(dev); |
5455c699 | 207 | |
475414f6 | 208 | if ((dev->wanted_features ^ dev->features) & valid) |
5455c699 MM |
209 | ret |= ETHTOOL_F_WISH; |
210 | ||
211 | return ret; | |
212 | } | |
213 | ||
340ae165 MM |
214 | static int __ethtool_get_sset_count(struct net_device *dev, int sset) |
215 | { | |
216 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
217 | ||
5455c699 MM |
218 | if (sset == ETH_SS_FEATURES) |
219 | return ARRAY_SIZE(netdev_features_strings); | |
220 | ||
892311f6 EP |
221 | if (sset == ETH_SS_RSS_HASH_FUNCS) |
222 | return ARRAY_SIZE(rss_hash_func_strings); | |
223 | ||
a4244b0c HHZ |
224 | if (sset == ETH_SS_TUNABLES) |
225 | return ARRAY_SIZE(tunable_strings); | |
226 | ||
968ad9da RL |
227 | if (sset == ETH_SS_PHY_TUNABLES) |
228 | return ARRAY_SIZE(phy_tunable_strings); | |
229 | ||
f3a40945 AL |
230 | if (sset == ETH_SS_PHY_STATS) { |
231 | if (dev->phydev) | |
c59530d0 | 232 | return phy_ethtool_get_sset_count(dev->phydev); |
f3a40945 AL |
233 | else |
234 | return -EOPNOTSUPP; | |
235 | } | |
236 | ||
c03a14e8 | 237 | if (ops->get_sset_count && ops->get_strings) |
340ae165 MM |
238 | return ops->get_sset_count(dev, sset); |
239 | else | |
240 | return -EOPNOTSUPP; | |
241 | } | |
242 | ||
243 | static void __ethtool_get_strings(struct net_device *dev, | |
244 | u32 stringset, u8 *data) | |
245 | { | |
246 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
247 | ||
5455c699 MM |
248 | if (stringset == ETH_SS_FEATURES) |
249 | memcpy(data, netdev_features_strings, | |
250 | sizeof(netdev_features_strings)); | |
892311f6 EP |
251 | else if (stringset == ETH_SS_RSS_HASH_FUNCS) |
252 | memcpy(data, rss_hash_func_strings, | |
253 | sizeof(rss_hash_func_strings)); | |
a4244b0c HHZ |
254 | else if (stringset == ETH_SS_TUNABLES) |
255 | memcpy(data, tunable_strings, sizeof(tunable_strings)); | |
968ad9da RL |
256 | else if (stringset == ETH_SS_PHY_TUNABLES) |
257 | memcpy(data, phy_tunable_strings, sizeof(phy_tunable_strings)); | |
f3a40945 | 258 | else if (stringset == ETH_SS_PHY_STATS) { |
c59530d0 FF |
259 | if (dev->phydev) |
260 | phy_ethtool_get_strings(dev->phydev, data); | |
261 | else | |
f3a40945 | 262 | return; |
f3a40945 | 263 | } else |
5455c699 MM |
264 | /* ops->get_strings is valid because checked earlier */ |
265 | ops->get_strings(dev, stringset, data); | |
340ae165 MM |
266 | } |
267 | ||
c8f44aff | 268 | static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd) |
0a417704 MM |
269 | { |
270 | /* feature masks of legacy discrete ethtool ops */ | |
271 | ||
272 | switch (eth_cmd) { | |
273 | case ETHTOOL_GTXCSUM: | |
274 | case ETHTOOL_STXCSUM: | |
a188222b | 275 | return NETIF_F_CSUM_MASK | NETIF_F_SCTP_CRC; |
e83d360d MM |
276 | case ETHTOOL_GRXCSUM: |
277 | case ETHTOOL_SRXCSUM: | |
278 | return NETIF_F_RXCSUM; | |
0a417704 MM |
279 | case ETHTOOL_GSG: |
280 | case ETHTOOL_SSG: | |
281 | return NETIF_F_SG; | |
282 | case ETHTOOL_GTSO: | |
283 | case ETHTOOL_STSO: | |
284 | return NETIF_F_ALL_TSO; | |
0a417704 MM |
285 | case ETHTOOL_GGSO: |
286 | case ETHTOOL_SGSO: | |
287 | return NETIF_F_GSO; | |
288 | case ETHTOOL_GGRO: | |
289 | case ETHTOOL_SGRO: | |
290 | return NETIF_F_GRO; | |
291 | default: | |
292 | BUG(); | |
293 | } | |
294 | } | |
295 | ||
0a417704 MM |
296 | static int ethtool_get_one_feature(struct net_device *dev, |
297 | char __user *useraddr, u32 ethcmd) | |
298 | { | |
c8f44aff | 299 | netdev_features_t mask = ethtool_get_feature_mask(ethcmd); |
0a417704 MM |
300 | struct ethtool_value edata = { |
301 | .cmd = ethcmd, | |
86794881 | 302 | .data = !!(dev->features & mask), |
0a417704 | 303 | }; |
0a417704 | 304 | |
0a417704 MM |
305 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
306 | return -EFAULT; | |
307 | return 0; | |
308 | } | |
309 | ||
0a417704 MM |
310 | static int ethtool_set_one_feature(struct net_device *dev, |
311 | void __user *useraddr, u32 ethcmd) | |
312 | { | |
313 | struct ethtool_value edata; | |
c8f44aff | 314 | netdev_features_t mask; |
0a417704 MM |
315 | |
316 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
317 | return -EFAULT; | |
318 | ||
86794881 MM |
319 | mask = ethtool_get_feature_mask(ethcmd); |
320 | mask &= dev->hw_features; | |
bc5787c6 MM |
321 | if (!mask) |
322 | return -EOPNOTSUPP; | |
86794881 | 323 | |
bc5787c6 MM |
324 | if (edata.data) |
325 | dev->wanted_features |= mask; | |
326 | else | |
327 | dev->wanted_features &= ~mask; | |
86794881 | 328 | |
bc5787c6 | 329 | __netdev_update_features(dev); |
86794881 | 330 | |
bc5787c6 MM |
331 | return 0; |
332 | } | |
333 | ||
02b3a552 MM |
334 | #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \ |
335 | ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH) | |
f646968f PM |
336 | #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_CTAG_RX | \ |
337 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_NTUPLE | \ | |
338 | NETIF_F_RXHASH) | |
bc5787c6 MM |
339 | |
340 | static u32 __ethtool_get_flags(struct net_device *dev) | |
341 | { | |
02b3a552 MM |
342 | u32 flags = 0; |
343 | ||
8a73125c DF |
344 | if (dev->features & NETIF_F_LRO) |
345 | flags |= ETH_FLAG_LRO; | |
346 | if (dev->features & NETIF_F_HW_VLAN_CTAG_RX) | |
347 | flags |= ETH_FLAG_RXVLAN; | |
348 | if (dev->features & NETIF_F_HW_VLAN_CTAG_TX) | |
349 | flags |= ETH_FLAG_TXVLAN; | |
350 | if (dev->features & NETIF_F_NTUPLE) | |
351 | flags |= ETH_FLAG_NTUPLE; | |
352 | if (dev->features & NETIF_F_RXHASH) | |
353 | flags |= ETH_FLAG_RXHASH; | |
02b3a552 MM |
354 | |
355 | return flags; | |
0a417704 MM |
356 | } |
357 | ||
bc5787c6 | 358 | static int __ethtool_set_flags(struct net_device *dev, u32 data) |
da8ac86c | 359 | { |
c8f44aff | 360 | netdev_features_t features = 0, changed; |
da8ac86c | 361 | |
02b3a552 | 362 | if (data & ~ETH_ALL_FLAGS) |
da8ac86c MM |
363 | return -EINVAL; |
364 | ||
8a73125c DF |
365 | if (data & ETH_FLAG_LRO) |
366 | features |= NETIF_F_LRO; | |
367 | if (data & ETH_FLAG_RXVLAN) | |
368 | features |= NETIF_F_HW_VLAN_CTAG_RX; | |
369 | if (data & ETH_FLAG_TXVLAN) | |
370 | features |= NETIF_F_HW_VLAN_CTAG_TX; | |
371 | if (data & ETH_FLAG_NTUPLE) | |
372 | features |= NETIF_F_NTUPLE; | |
373 | if (data & ETH_FLAG_RXHASH) | |
374 | features |= NETIF_F_RXHASH; | |
02b3a552 | 375 | |
da8ac86c | 376 | /* allow changing only bits set in hw_features */ |
02b3a552 | 377 | changed = (features ^ dev->features) & ETH_ALL_FEATURES; |
da8ac86c MM |
378 | if (changed & ~dev->hw_features) |
379 | return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP; | |
380 | ||
381 | dev->wanted_features = | |
02b3a552 | 382 | (dev->wanted_features & ~changed) | (features & changed); |
da8ac86c | 383 | |
6cb6a27c | 384 | __netdev_update_features(dev); |
da8ac86c MM |
385 | |
386 | return 0; | |
387 | } | |
388 | ||
5a6cd6de AB |
389 | /* Given two link masks, AND them together and save the result in dst. */ |
390 | void ethtool_intersect_link_masks(struct ethtool_link_ksettings *dst, | |
391 | struct ethtool_link_ksettings *src) | |
392 | { | |
393 | unsigned int size = BITS_TO_LONGS(__ETHTOOL_LINK_MODE_MASK_NBITS); | |
394 | unsigned int idx = 0; | |
395 | ||
396 | for (; idx < size; idx++) { | |
397 | dst->link_modes.supported[idx] &= | |
398 | src->link_modes.supported[idx]; | |
399 | dst->link_modes.advertising[idx] &= | |
400 | src->link_modes.advertising[idx]; | |
401 | } | |
402 | } | |
403 | EXPORT_SYMBOL(ethtool_intersect_link_masks); | |
404 | ||
6d62b4d5 PR |
405 | void ethtool_convert_legacy_u32_to_link_mode(unsigned long *dst, |
406 | u32 legacy_u32) | |
3f1ac7a7 DD |
407 | { |
408 | bitmap_zero(dst, __ETHTOOL_LINK_MODE_MASK_NBITS); | |
409 | dst[0] = legacy_u32; | |
410 | } | |
6d62b4d5 | 411 | EXPORT_SYMBOL(ethtool_convert_legacy_u32_to_link_mode); |
3f1ac7a7 DD |
412 | |
413 | /* return false if src had higher bits set. lower bits always updated. */ | |
6d62b4d5 PR |
414 | bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32, |
415 | const unsigned long *src) | |
3f1ac7a7 DD |
416 | { |
417 | bool retval = true; | |
418 | ||
419 | /* TODO: following test will soon always be true */ | |
420 | if (__ETHTOOL_LINK_MODE_MASK_NBITS > 32) { | |
421 | __ETHTOOL_DECLARE_LINK_MODE_MASK(ext); | |
422 | ||
423 | bitmap_zero(ext, __ETHTOOL_LINK_MODE_MASK_NBITS); | |
424 | bitmap_fill(ext, 32); | |
425 | bitmap_complement(ext, ext, __ETHTOOL_LINK_MODE_MASK_NBITS); | |
426 | if (bitmap_intersects(ext, src, | |
427 | __ETHTOOL_LINK_MODE_MASK_NBITS)) { | |
428 | /* src mask goes beyond bit 31 */ | |
429 | retval = false; | |
430 | } | |
431 | } | |
432 | *legacy_u32 = src[0]; | |
433 | return retval; | |
434 | } | |
6d62b4d5 | 435 | EXPORT_SYMBOL(ethtool_convert_link_mode_to_legacy_u32); |
3f1ac7a7 DD |
436 | |
437 | /* return false if legacy contained non-0 deprecated fields | |
95491e3c | 438 | * maxtxpkt/maxrxpkt. rest of ksettings always updated |
3f1ac7a7 DD |
439 | */ |
440 | static bool | |
441 | convert_legacy_settings_to_link_ksettings( | |
442 | struct ethtool_link_ksettings *link_ksettings, | |
443 | const struct ethtool_cmd *legacy_settings) | |
444 | { | |
445 | bool retval = true; | |
446 | ||
447 | memset(link_ksettings, 0, sizeof(*link_ksettings)); | |
448 | ||
449 | /* This is used to tell users that driver is still using these | |
450 | * deprecated legacy fields, and they should not use | |
451 | * %ETHTOOL_GLINKSETTINGS/%ETHTOOL_SLINKSETTINGS | |
452 | */ | |
95491e3c | 453 | if (legacy_settings->maxtxpkt || |
3f1ac7a7 DD |
454 | legacy_settings->maxrxpkt) |
455 | retval = false; | |
456 | ||
6d62b4d5 | 457 | ethtool_convert_legacy_u32_to_link_mode( |
3f1ac7a7 DD |
458 | link_ksettings->link_modes.supported, |
459 | legacy_settings->supported); | |
6d62b4d5 | 460 | ethtool_convert_legacy_u32_to_link_mode( |
3f1ac7a7 DD |
461 | link_ksettings->link_modes.advertising, |
462 | legacy_settings->advertising); | |
6d62b4d5 | 463 | ethtool_convert_legacy_u32_to_link_mode( |
3f1ac7a7 DD |
464 | link_ksettings->link_modes.lp_advertising, |
465 | legacy_settings->lp_advertising); | |
466 | link_ksettings->base.speed | |
467 | = ethtool_cmd_speed(legacy_settings); | |
468 | link_ksettings->base.duplex | |
469 | = legacy_settings->duplex; | |
470 | link_ksettings->base.port | |
471 | = legacy_settings->port; | |
472 | link_ksettings->base.phy_address | |
473 | = legacy_settings->phy_address; | |
474 | link_ksettings->base.autoneg | |
475 | = legacy_settings->autoneg; | |
476 | link_ksettings->base.mdio_support | |
477 | = legacy_settings->mdio_support; | |
478 | link_ksettings->base.eth_tp_mdix | |
479 | = legacy_settings->eth_tp_mdix; | |
480 | link_ksettings->base.eth_tp_mdix_ctrl | |
481 | = legacy_settings->eth_tp_mdix_ctrl; | |
482 | return retval; | |
483 | } | |
484 | ||
485 | /* return false if ksettings link modes had higher bits | |
486 | * set. legacy_settings always updated (best effort) | |
487 | */ | |
488 | static bool | |
489 | convert_link_ksettings_to_legacy_settings( | |
490 | struct ethtool_cmd *legacy_settings, | |
491 | const struct ethtool_link_ksettings *link_ksettings) | |
492 | { | |
493 | bool retval = true; | |
494 | ||
495 | memset(legacy_settings, 0, sizeof(*legacy_settings)); | |
496 | /* this also clears the deprecated fields in legacy structure: | |
497 | * __u8 transceiver; | |
498 | * __u32 maxtxpkt; | |
499 | * __u32 maxrxpkt; | |
500 | */ | |
501 | ||
6d62b4d5 | 502 | retval &= ethtool_convert_link_mode_to_legacy_u32( |
3f1ac7a7 DD |
503 | &legacy_settings->supported, |
504 | link_ksettings->link_modes.supported); | |
6d62b4d5 | 505 | retval &= ethtool_convert_link_mode_to_legacy_u32( |
3f1ac7a7 DD |
506 | &legacy_settings->advertising, |
507 | link_ksettings->link_modes.advertising); | |
6d62b4d5 | 508 | retval &= ethtool_convert_link_mode_to_legacy_u32( |
3f1ac7a7 DD |
509 | &legacy_settings->lp_advertising, |
510 | link_ksettings->link_modes.lp_advertising); | |
511 | ethtool_cmd_speed_set(legacy_settings, link_ksettings->base.speed); | |
512 | legacy_settings->duplex | |
513 | = link_ksettings->base.duplex; | |
514 | legacy_settings->port | |
515 | = link_ksettings->base.port; | |
516 | legacy_settings->phy_address | |
517 | = link_ksettings->base.phy_address; | |
518 | legacy_settings->autoneg | |
519 | = link_ksettings->base.autoneg; | |
520 | legacy_settings->mdio_support | |
521 | = link_ksettings->base.mdio_support; | |
522 | legacy_settings->eth_tp_mdix | |
523 | = link_ksettings->base.eth_tp_mdix; | |
524 | legacy_settings->eth_tp_mdix_ctrl | |
525 | = link_ksettings->base.eth_tp_mdix_ctrl; | |
19cab887 FF |
526 | legacy_settings->transceiver |
527 | = link_ksettings->base.transceiver; | |
3f1ac7a7 DD |
528 | return retval; |
529 | } | |
530 | ||
531 | /* number of 32-bit words to store the user's link mode bitmaps */ | |
532 | #define __ETHTOOL_LINK_MODE_MASK_NU32 \ | |
533 | DIV_ROUND_UP(__ETHTOOL_LINK_MODE_MASK_NBITS, 32) | |
534 | ||
535 | /* layout of the struct passed from/to userland */ | |
536 | struct ethtool_link_usettings { | |
537 | struct ethtool_link_settings base; | |
538 | struct { | |
539 | __u32 supported[__ETHTOOL_LINK_MODE_MASK_NU32]; | |
540 | __u32 advertising[__ETHTOOL_LINK_MODE_MASK_NU32]; | |
541 | __u32 lp_advertising[__ETHTOOL_LINK_MODE_MASK_NU32]; | |
542 | } link_modes; | |
543 | }; | |
544 | ||
545 | /* Internal kernel helper to query a device ethtool_link_settings. | |
546 | * | |
547 | * Backward compatibility note: for compatibility with legacy drivers | |
548 | * that implement only the ethtool_cmd API, this has to work with both | |
549 | * drivers implementing get_link_ksettings API and drivers | |
550 | * implementing get_settings API. When drivers implement get_settings | |
551 | * and report ethtool_cmd deprecated fields | |
552 | * (transceiver/maxrxpkt/maxtxpkt), these fields are silently ignored | |
553 | * because the resulting struct ethtool_link_settings does not report them. | |
554 | */ | |
555 | int __ethtool_get_link_ksettings(struct net_device *dev, | |
556 | struct ethtool_link_ksettings *link_ksettings) | |
557 | { | |
558 | int err; | |
559 | struct ethtool_cmd cmd; | |
560 | ||
561 | ASSERT_RTNL(); | |
562 | ||
563 | if (dev->ethtool_ops->get_link_ksettings) { | |
564 | memset(link_ksettings, 0, sizeof(*link_ksettings)); | |
565 | return dev->ethtool_ops->get_link_ksettings(dev, | |
566 | link_ksettings); | |
567 | } | |
568 | ||
569 | /* driver doesn't support %ethtool_link_ksettings API. revert to | |
570 | * legacy %ethtool_cmd API, unless it's not supported either. | |
571 | * TODO: remove when ethtool_ops::get_settings disappears internally | |
572 | */ | |
3237fc63 DD |
573 | if (!dev->ethtool_ops->get_settings) |
574 | return -EOPNOTSUPP; | |
575 | ||
576 | memset(&cmd, 0, sizeof(cmd)); | |
577 | cmd.cmd = ETHTOOL_GSET; | |
578 | err = dev->ethtool_ops->get_settings(dev, &cmd); | |
3f1ac7a7 DD |
579 | if (err < 0) |
580 | return err; | |
581 | ||
582 | /* we ignore deprecated fields transceiver/maxrxpkt/maxtxpkt | |
583 | */ | |
584 | convert_legacy_settings_to_link_ksettings(link_ksettings, &cmd); | |
585 | return err; | |
586 | } | |
587 | EXPORT_SYMBOL(__ethtool_get_link_ksettings); | |
588 | ||
589 | /* convert ethtool_link_usettings in user space to a kernel internal | |
590 | * ethtool_link_ksettings. return 0 on success, errno on error. | |
591 | */ | |
592 | static int load_link_ksettings_from_user(struct ethtool_link_ksettings *to, | |
593 | const void __user *from) | |
594 | { | |
595 | struct ethtool_link_usettings link_usettings; | |
596 | ||
597 | if (copy_from_user(&link_usettings, from, sizeof(link_usettings))) | |
598 | return -EFAULT; | |
599 | ||
600 | memcpy(&to->base, &link_usettings.base, sizeof(to->base)); | |
3aa56885 YN |
601 | bitmap_from_arr32(to->link_modes.supported, |
602 | link_usettings.link_modes.supported, | |
603 | __ETHTOOL_LINK_MODE_MASK_NBITS); | |
604 | bitmap_from_arr32(to->link_modes.advertising, | |
605 | link_usettings.link_modes.advertising, | |
606 | __ETHTOOL_LINK_MODE_MASK_NBITS); | |
607 | bitmap_from_arr32(to->link_modes.lp_advertising, | |
608 | link_usettings.link_modes.lp_advertising, | |
609 | __ETHTOOL_LINK_MODE_MASK_NBITS); | |
3f1ac7a7 DD |
610 | |
611 | return 0; | |
612 | } | |
613 | ||
614 | /* convert a kernel internal ethtool_link_ksettings to | |
615 | * ethtool_link_usettings in user space. return 0 on success, errno on | |
616 | * error. | |
617 | */ | |
618 | static int | |
619 | store_link_ksettings_for_user(void __user *to, | |
620 | const struct ethtool_link_ksettings *from) | |
621 | { | |
622 | struct ethtool_link_usettings link_usettings; | |
623 | ||
624 | memcpy(&link_usettings.base, &from->base, sizeof(link_usettings)); | |
3aa56885 YN |
625 | bitmap_to_arr32(link_usettings.link_modes.supported, |
626 | from->link_modes.supported, | |
627 | __ETHTOOL_LINK_MODE_MASK_NBITS); | |
628 | bitmap_to_arr32(link_usettings.link_modes.advertising, | |
629 | from->link_modes.advertising, | |
630 | __ETHTOOL_LINK_MODE_MASK_NBITS); | |
631 | bitmap_to_arr32(link_usettings.link_modes.lp_advertising, | |
632 | from->link_modes.lp_advertising, | |
633 | __ETHTOOL_LINK_MODE_MASK_NBITS); | |
3f1ac7a7 DD |
634 | |
635 | if (copy_to_user(to, &link_usettings, sizeof(link_usettings))) | |
636 | return -EFAULT; | |
637 | ||
638 | return 0; | |
639 | } | |
640 | ||
641 | /* Query device for its ethtool_link_settings. | |
642 | * | |
643 | * Backward compatibility note: this function must fail when driver | |
644 | * does not implement ethtool::get_link_ksettings, even if legacy | |
645 | * ethtool_ops::get_settings is implemented. This tells new versions | |
646 | * of ethtool that they should use the legacy API %ETHTOOL_GSET for | |
647 | * this driver, so that they can correctly access the ethtool_cmd | |
648 | * deprecated fields (transceiver/maxrxpkt/maxtxpkt), until no driver | |
649 | * implements ethtool_ops::get_settings anymore. | |
650 | */ | |
651 | static int ethtool_get_link_ksettings(struct net_device *dev, | |
652 | void __user *useraddr) | |
653 | { | |
654 | int err = 0; | |
655 | struct ethtool_link_ksettings link_ksettings; | |
656 | ||
657 | ASSERT_RTNL(); | |
658 | ||
659 | if (!dev->ethtool_ops->get_link_ksettings) | |
660 | return -EOPNOTSUPP; | |
661 | ||
662 | /* handle bitmap nbits handshake */ | |
663 | if (copy_from_user(&link_ksettings.base, useraddr, | |
664 | sizeof(link_ksettings.base))) | |
665 | return -EFAULT; | |
666 | ||
667 | if (__ETHTOOL_LINK_MODE_MASK_NU32 | |
668 | != link_ksettings.base.link_mode_masks_nwords) { | |
669 | /* wrong link mode nbits requested */ | |
670 | memset(&link_ksettings, 0, sizeof(link_ksettings)); | |
793cf87d | 671 | link_ksettings.base.cmd = ETHTOOL_GLINKSETTINGS; |
3f1ac7a7 DD |
672 | /* send back number of words required as negative val */ |
673 | compiletime_assert(__ETHTOOL_LINK_MODE_MASK_NU32 <= S8_MAX, | |
674 | "need too many bits for link modes!"); | |
675 | link_ksettings.base.link_mode_masks_nwords | |
676 | = -((s8)__ETHTOOL_LINK_MODE_MASK_NU32); | |
677 | ||
678 | /* copy the base fields back to user, not the link | |
679 | * mode bitmaps | |
680 | */ | |
681 | if (copy_to_user(useraddr, &link_ksettings.base, | |
682 | sizeof(link_ksettings.base))) | |
683 | return -EFAULT; | |
684 | ||
685 | return 0; | |
686 | } | |
687 | ||
688 | /* handshake successful: user/kernel agree on | |
689 | * link_mode_masks_nwords | |
690 | */ | |
691 | ||
692 | memset(&link_ksettings, 0, sizeof(link_ksettings)); | |
693 | err = dev->ethtool_ops->get_link_ksettings(dev, &link_ksettings); | |
694 | if (err < 0) | |
695 | return err; | |
696 | ||
697 | /* make sure we tell the right values to user */ | |
698 | link_ksettings.base.cmd = ETHTOOL_GLINKSETTINGS; | |
699 | link_ksettings.base.link_mode_masks_nwords | |
700 | = __ETHTOOL_LINK_MODE_MASK_NU32; | |
701 | ||
702 | return store_link_ksettings_for_user(useraddr, &link_ksettings); | |
703 | } | |
704 | ||
705 | /* Update device ethtool_link_settings. | |
706 | * | |
707 | * Backward compatibility note: this function must fail when driver | |
708 | * does not implement ethtool::set_link_ksettings, even if legacy | |
709 | * ethtool_ops::set_settings is implemented. This tells new versions | |
710 | * of ethtool that they should use the legacy API %ETHTOOL_SSET for | |
711 | * this driver, so that they can correctly update the ethtool_cmd | |
712 | * deprecated fields (transceiver/maxrxpkt/maxtxpkt), until no driver | |
713 | * implements ethtool_ops::get_settings anymore. | |
714 | */ | |
715 | static int ethtool_set_link_ksettings(struct net_device *dev, | |
716 | void __user *useraddr) | |
717 | { | |
718 | int err; | |
719 | struct ethtool_link_ksettings link_ksettings; | |
720 | ||
721 | ASSERT_RTNL(); | |
722 | ||
723 | if (!dev->ethtool_ops->set_link_ksettings) | |
724 | return -EOPNOTSUPP; | |
725 | ||
726 | /* make sure nbits field has expected value */ | |
727 | if (copy_from_user(&link_ksettings.base, useraddr, | |
728 | sizeof(link_ksettings.base))) | |
729 | return -EFAULT; | |
730 | ||
731 | if (__ETHTOOL_LINK_MODE_MASK_NU32 | |
732 | != link_ksettings.base.link_mode_masks_nwords) | |
733 | return -EINVAL; | |
734 | ||
735 | /* copy the whole structure, now that we know it has expected | |
736 | * format | |
737 | */ | |
738 | err = load_link_ksettings_from_user(&link_ksettings, useraddr); | |
739 | if (err) | |
740 | return err; | |
741 | ||
742 | /* re-check nwords field, just in case */ | |
743 | if (__ETHTOOL_LINK_MODE_MASK_NU32 | |
744 | != link_ksettings.base.link_mode_masks_nwords) | |
745 | return -EINVAL; | |
746 | ||
747 | return dev->ethtool_ops->set_link_ksettings(dev, &link_ksettings); | |
748 | } | |
749 | ||
3f1ac7a7 DD |
750 | /* Query device for its ethtool_cmd settings. |
751 | * | |
752 | * Backward compatibility note: for compatibility with legacy ethtool, | |
753 | * this has to work with both drivers implementing get_link_ksettings | |
754 | * API and drivers implementing get_settings API. When drivers | |
755 | * implement get_link_ksettings and report higher link mode bits, a | |
756 | * kernel warning is logged once (with name of 1st driver/device) to | |
757 | * recommend user to upgrade ethtool, but the command is successful | |
758 | * (only the lower link mode bits reported back to user). | |
759 | */ | |
4bc71cb9 JP |
760 | static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) |
761 | { | |
4bc71cb9 JP |
762 | struct ethtool_cmd cmd; |
763 | ||
3f1ac7a7 DD |
764 | ASSERT_RTNL(); |
765 | ||
766 | if (dev->ethtool_ops->get_link_ksettings) { | |
767 | /* First, use link_ksettings API if it is supported */ | |
768 | int err; | |
769 | struct ethtool_link_ksettings link_ksettings; | |
770 | ||
771 | memset(&link_ksettings, 0, sizeof(link_ksettings)); | |
772 | err = dev->ethtool_ops->get_link_ksettings(dev, | |
773 | &link_ksettings); | |
774 | if (err < 0) | |
775 | return err; | |
71891e2d SH |
776 | convert_link_ksettings_to_legacy_settings(&cmd, |
777 | &link_ksettings); | |
3f1ac7a7 DD |
778 | |
779 | /* send a sensible cmd tag back to user */ | |
780 | cmd.cmd = ETHTOOL_GSET; | |
781 | } else { | |
3f1ac7a7 DD |
782 | /* driver doesn't support %ethtool_link_ksettings |
783 | * API. revert to legacy %ethtool_cmd API, unless it's | |
784 | * not supported either. | |
785 | */ | |
3237fc63 DD |
786 | int err; |
787 | ||
788 | if (!dev->ethtool_ops->get_settings) | |
789 | return -EOPNOTSUPP; | |
790 | ||
791 | memset(&cmd, 0, sizeof(cmd)); | |
792 | cmd.cmd = ETHTOOL_GSET; | |
793 | err = dev->ethtool_ops->get_settings(dev, &cmd); | |
3f1ac7a7 DD |
794 | if (err < 0) |
795 | return err; | |
796 | } | |
1da177e4 LT |
797 | |
798 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) | |
799 | return -EFAULT; | |
3f1ac7a7 | 800 | |
1da177e4 LT |
801 | return 0; |
802 | } | |
803 | ||
3f1ac7a7 DD |
804 | /* Update device link settings with given ethtool_cmd. |
805 | * | |
806 | * Backward compatibility note: for compatibility with legacy ethtool, | |
807 | * this has to work with both drivers implementing set_link_ksettings | |
808 | * API and drivers implementing set_settings API. When drivers | |
809 | * implement set_link_ksettings and user's request updates deprecated | |
810 | * ethtool_cmd fields (transceiver/maxrxpkt/maxtxpkt), a kernel | |
811 | * warning is logged once (with name of 1st driver/device) to | |
812 | * recommend user to upgrade ethtool, and the request is rejected. | |
813 | */ | |
1da177e4 LT |
814 | static int ethtool_set_settings(struct net_device *dev, void __user *useraddr) |
815 | { | |
816 | struct ethtool_cmd cmd; | |
817 | ||
3f1ac7a7 | 818 | ASSERT_RTNL(); |
1da177e4 LT |
819 | |
820 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) | |
821 | return -EFAULT; | |
822 | ||
3f1ac7a7 DD |
823 | /* first, try new %ethtool_link_ksettings API. */ |
824 | if (dev->ethtool_ops->set_link_ksettings) { | |
825 | struct ethtool_link_ksettings link_ksettings; | |
826 | ||
827 | if (!convert_legacy_settings_to_link_ksettings(&link_ksettings, | |
828 | &cmd)) | |
829 | return -EINVAL; | |
830 | ||
831 | link_ksettings.base.cmd = ETHTOOL_SLINKSETTINGS; | |
832 | link_ksettings.base.link_mode_masks_nwords | |
833 | = __ETHTOOL_LINK_MODE_MASK_NU32; | |
834 | return dev->ethtool_ops->set_link_ksettings(dev, | |
835 | &link_ksettings); | |
836 | } | |
837 | ||
838 | /* legacy %ethtool_cmd API */ | |
839 | ||
840 | /* TODO: return -EOPNOTSUPP when ethtool_ops::get_settings | |
841 | * disappears internally | |
842 | */ | |
843 | ||
844 | if (!dev->ethtool_ops->set_settings) | |
845 | return -EOPNOTSUPP; | |
846 | ||
1da177e4 LT |
847 | return dev->ethtool_ops->set_settings(dev, &cmd); |
848 | } | |
849 | ||
97f8aefb | 850 | static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, |
851 | void __user *useraddr) | |
1da177e4 LT |
852 | { |
853 | struct ethtool_drvinfo info; | |
76fd8593 | 854 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 | 855 | |
1da177e4 LT |
856 | memset(&info, 0, sizeof(info)); |
857 | info.cmd = ETHTOOL_GDRVINFO; | |
c03a14e8 | 858 | if (ops->get_drvinfo) { |
01414802 BH |
859 | ops->get_drvinfo(dev, &info); |
860 | } else if (dev->dev.parent && dev->dev.parent->driver) { | |
861 | strlcpy(info.bus_info, dev_name(dev->dev.parent), | |
862 | sizeof(info.bus_info)); | |
863 | strlcpy(info.driver, dev->dev.parent->driver->name, | |
864 | sizeof(info.driver)); | |
865 | } else { | |
866 | return -EOPNOTSUPP; | |
867 | } | |
1da177e4 | 868 | |
723b2f57 JG |
869 | /* |
870 | * this method of obtaining string set info is deprecated; | |
d17792eb | 871 | * Use ETHTOOL_GSSET_INFO instead. |
723b2f57 | 872 | */ |
c03a14e8 | 873 | if (ops->get_sset_count) { |
ff03d49f JG |
874 | int rc; |
875 | ||
876 | rc = ops->get_sset_count(dev, ETH_SS_TEST); | |
877 | if (rc >= 0) | |
878 | info.testinfo_len = rc; | |
879 | rc = ops->get_sset_count(dev, ETH_SS_STATS); | |
880 | if (rc >= 0) | |
881 | info.n_stats = rc; | |
339bf024 JG |
882 | rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS); |
883 | if (rc >= 0) | |
884 | info.n_priv_flags = rc; | |
ff03d49f | 885 | } |
c03a14e8 | 886 | if (ops->get_regs_len) |
1da177e4 | 887 | info.regdump_len = ops->get_regs_len(dev); |
c03a14e8 | 888 | if (ops->get_eeprom_len) |
1da177e4 LT |
889 | info.eedump_len = ops->get_eeprom_len(dev); |
890 | ||
891 | if (copy_to_user(useraddr, &info, sizeof(info))) | |
892 | return -EFAULT; | |
893 | return 0; | |
894 | } | |
895 | ||
f5c445ed | 896 | static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, |
97f8aefb | 897 | void __user *useraddr) |
723b2f57 JG |
898 | { |
899 | struct ethtool_sset_info info; | |
723b2f57 JG |
900 | u64 sset_mask; |
901 | int i, idx = 0, n_bits = 0, ret, rc; | |
902 | u32 *info_buf = NULL; | |
903 | ||
723b2f57 JG |
904 | if (copy_from_user(&info, useraddr, sizeof(info))) |
905 | return -EFAULT; | |
906 | ||
907 | /* store copy of mask, because we zero struct later on */ | |
908 | sset_mask = info.sset_mask; | |
909 | if (!sset_mask) | |
910 | return 0; | |
911 | ||
912 | /* calculate size of return buffer */ | |
d17792eb | 913 | n_bits = hweight64(sset_mask); |
723b2f57 JG |
914 | |
915 | memset(&info, 0, sizeof(info)); | |
916 | info.cmd = ETHTOOL_GSSET_INFO; | |
917 | ||
918 | info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER); | |
919 | if (!info_buf) | |
920 | return -ENOMEM; | |
921 | ||
922 | /* | |
923 | * fill return buffer based on input bitmask and successful | |
924 | * get_sset_count return | |
925 | */ | |
926 | for (i = 0; i < 64; i++) { | |
927 | if (!(sset_mask & (1ULL << i))) | |
928 | continue; | |
929 | ||
340ae165 | 930 | rc = __ethtool_get_sset_count(dev, i); |
723b2f57 JG |
931 | if (rc >= 0) { |
932 | info.sset_mask |= (1ULL << i); | |
933 | info_buf[idx++] = rc; | |
934 | } | |
935 | } | |
936 | ||
937 | ret = -EFAULT; | |
938 | if (copy_to_user(useraddr, &info, sizeof(info))) | |
939 | goto out; | |
940 | ||
941 | useraddr += offsetof(struct ethtool_sset_info, data); | |
942 | if (copy_to_user(useraddr, info_buf, idx * sizeof(u32))) | |
943 | goto out; | |
944 | ||
945 | ret = 0; | |
946 | ||
947 | out: | |
948 | kfree(info_buf); | |
949 | return ret; | |
950 | } | |
951 | ||
97f8aefb | 952 | static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, |
bf988435 | 953 | u32 cmd, void __user *useraddr) |
0853ad66 | 954 | { |
bf988435 BH |
955 | struct ethtool_rxnfc info; |
956 | size_t info_size = sizeof(info); | |
55664f32 | 957 | int rc; |
0853ad66 | 958 | |
59089d8d | 959 | if (!dev->ethtool_ops->set_rxnfc) |
0853ad66 SB |
960 | return -EOPNOTSUPP; |
961 | ||
bf988435 BH |
962 | /* struct ethtool_rxnfc was originally defined for |
963 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data | |
964 | * members. User-space might still be using that | |
965 | * definition. */ | |
966 | if (cmd == ETHTOOL_SRXFH) | |
967 | info_size = (offsetof(struct ethtool_rxnfc, data) + | |
968 | sizeof(info.data)); | |
969 | ||
970 | if (copy_from_user(&info, useraddr, info_size)) | |
0853ad66 SB |
971 | return -EFAULT; |
972 | ||
55664f32 BH |
973 | rc = dev->ethtool_ops->set_rxnfc(dev, &info); |
974 | if (rc) | |
975 | return rc; | |
976 | ||
977 | if (cmd == ETHTOOL_SRXCLSRLINS && | |
978 | copy_to_user(useraddr, &info, info_size)) | |
979 | return -EFAULT; | |
980 | ||
981 | return 0; | |
0853ad66 SB |
982 | } |
983 | ||
97f8aefb | 984 | static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, |
bf988435 | 985 | u32 cmd, void __user *useraddr) |
0853ad66 SB |
986 | { |
987 | struct ethtool_rxnfc info; | |
bf988435 | 988 | size_t info_size = sizeof(info); |
59089d8d SB |
989 | const struct ethtool_ops *ops = dev->ethtool_ops; |
990 | int ret; | |
991 | void *rule_buf = NULL; | |
0853ad66 | 992 | |
59089d8d | 993 | if (!ops->get_rxnfc) |
0853ad66 SB |
994 | return -EOPNOTSUPP; |
995 | ||
bf988435 BH |
996 | /* struct ethtool_rxnfc was originally defined for |
997 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data | |
998 | * members. User-space might still be using that | |
999 | * definition. */ | |
1000 | if (cmd == ETHTOOL_GRXFH) | |
1001 | info_size = (offsetof(struct ethtool_rxnfc, data) + | |
1002 | sizeof(info.data)); | |
1003 | ||
1004 | if (copy_from_user(&info, useraddr, info_size)) | |
0853ad66 SB |
1005 | return -EFAULT; |
1006 | ||
84a1d9c4 EC |
1007 | /* If FLOW_RSS was requested then user-space must be using the |
1008 | * new definition, as FLOW_RSS is newer. | |
1009 | */ | |
1010 | if (cmd == ETHTOOL_GRXFH && info.flow_type & FLOW_RSS) { | |
1011 | info_size = sizeof(info); | |
1012 | if (copy_from_user(&info, useraddr, info_size)) | |
1013 | return -EFAULT; | |
1014 | } | |
1015 | ||
59089d8d SB |
1016 | if (info.cmd == ETHTOOL_GRXCLSRLALL) { |
1017 | if (info.rule_cnt > 0) { | |
db048b69 | 1018 | if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32)) |
ae6df5f9 | 1019 | rule_buf = kzalloc(info.rule_cnt * sizeof(u32), |
db048b69 | 1020 | GFP_USER); |
59089d8d SB |
1021 | if (!rule_buf) |
1022 | return -ENOMEM; | |
1023 | } | |
1024 | } | |
0853ad66 | 1025 | |
59089d8d SB |
1026 | ret = ops->get_rxnfc(dev, &info, rule_buf); |
1027 | if (ret < 0) | |
1028 | goto err_out; | |
1029 | ||
1030 | ret = -EFAULT; | |
bf988435 | 1031 | if (copy_to_user(useraddr, &info, info_size)) |
59089d8d SB |
1032 | goto err_out; |
1033 | ||
1034 | if (rule_buf) { | |
1035 | useraddr += offsetof(struct ethtool_rxnfc, rule_locs); | |
1036 | if (copy_to_user(useraddr, rule_buf, | |
1037 | info.rule_cnt * sizeof(u32))) | |
1038 | goto err_out; | |
1039 | } | |
1040 | ret = 0; | |
1041 | ||
1042 | err_out: | |
c9caceca | 1043 | kfree(rule_buf); |
59089d8d SB |
1044 | |
1045 | return ret; | |
0853ad66 SB |
1046 | } |
1047 | ||
3de0b592 VD |
1048 | static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr, |
1049 | struct ethtool_rxnfc *rx_rings, | |
1050 | u32 size) | |
1051 | { | |
fb95cd8d | 1052 | int i; |
3de0b592 VD |
1053 | |
1054 | if (copy_from_user(indir, useraddr, size * sizeof(indir[0]))) | |
fb95cd8d | 1055 | return -EFAULT; |
3de0b592 VD |
1056 | |
1057 | /* Validate ring indices */ | |
fb95cd8d BH |
1058 | for (i = 0; i < size; i++) |
1059 | if (indir[i] >= rx_rings->data) | |
1060 | return -EINVAL; | |
1061 | ||
1062 | return 0; | |
3de0b592 VD |
1063 | } |
1064 | ||
ba905f5e | 1065 | u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly; |
960fb622 ED |
1066 | |
1067 | void netdev_rss_key_fill(void *buffer, size_t len) | |
1068 | { | |
1069 | BUG_ON(len > sizeof(netdev_rss_key)); | |
1070 | net_get_random_once(netdev_rss_key, sizeof(netdev_rss_key)); | |
1071 | memcpy(buffer, netdev_rss_key, len); | |
1072 | } | |
1073 | EXPORT_SYMBOL(netdev_rss_key_fill); | |
1074 | ||
d4ab4286 KJ |
1075 | static int ethtool_get_max_rxfh_channel(struct net_device *dev, u32 *max) |
1076 | { | |
1077 | u32 dev_size, current_max = 0; | |
1078 | u32 *indir; | |
1079 | int ret; | |
1080 | ||
1081 | if (!dev->ethtool_ops->get_rxfh_indir_size || | |
1082 | !dev->ethtool_ops->get_rxfh) | |
1083 | return -EOPNOTSUPP; | |
1084 | dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev); | |
1085 | if (dev_size == 0) | |
1086 | return -EOPNOTSUPP; | |
1087 | ||
1088 | indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER); | |
1089 | if (!indir) | |
1090 | return -ENOMEM; | |
1091 | ||
1092 | ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL, NULL); | |
1093 | if (ret) | |
1094 | goto out; | |
1095 | ||
1096 | while (dev_size--) | |
1097 | current_max = max(current_max, indir[dev_size]); | |
1098 | ||
1099 | *max = current_max; | |
1100 | ||
1101 | out: | |
1102 | kfree(indir); | |
1103 | return ret; | |
1104 | } | |
1105 | ||
a5b6ee29 BH |
1106 | static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev, |
1107 | void __user *useraddr) | |
1108 | { | |
7850f63f BH |
1109 | u32 user_size, dev_size; |
1110 | u32 *indir; | |
a5b6ee29 BH |
1111 | int ret; |
1112 | ||
7850f63f | 1113 | if (!dev->ethtool_ops->get_rxfh_indir_size || |
fe62d001 | 1114 | !dev->ethtool_ops->get_rxfh) |
7850f63f BH |
1115 | return -EOPNOTSUPP; |
1116 | dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev); | |
1117 | if (dev_size == 0) | |
a5b6ee29 BH |
1118 | return -EOPNOTSUPP; |
1119 | ||
7850f63f | 1120 | if (copy_from_user(&user_size, |
a5b6ee29 | 1121 | useraddr + offsetof(struct ethtool_rxfh_indir, size), |
7850f63f | 1122 | sizeof(user_size))) |
a5b6ee29 BH |
1123 | return -EFAULT; |
1124 | ||
7850f63f BH |
1125 | if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size), |
1126 | &dev_size, sizeof(dev_size))) | |
1127 | return -EFAULT; | |
1128 | ||
1129 | /* If the user buffer size is 0, this is just a query for the | |
1130 | * device table size. Otherwise, if it's smaller than the | |
1131 | * device table size it's an error. | |
1132 | */ | |
1133 | if (user_size < dev_size) | |
1134 | return user_size == 0 ? 0 : -EINVAL; | |
1135 | ||
1136 | indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER); | |
a5b6ee29 BH |
1137 | if (!indir) |
1138 | return -ENOMEM; | |
1139 | ||
892311f6 | 1140 | ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL, NULL); |
a5b6ee29 BH |
1141 | if (ret) |
1142 | goto out; | |
1143 | ||
7850f63f BH |
1144 | if (copy_to_user(useraddr + |
1145 | offsetof(struct ethtool_rxfh_indir, ring_index[0]), | |
1146 | indir, dev_size * sizeof(indir[0]))) | |
a5b6ee29 BH |
1147 | ret = -EFAULT; |
1148 | ||
1149 | out: | |
1150 | kfree(indir); | |
1151 | return ret; | |
1152 | } | |
1153 | ||
1154 | static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev, | |
1155 | void __user *useraddr) | |
1156 | { | |
7850f63f BH |
1157 | struct ethtool_rxnfc rx_rings; |
1158 | u32 user_size, dev_size, i; | |
1159 | u32 *indir; | |
c03a14e8 | 1160 | const struct ethtool_ops *ops = dev->ethtool_ops; |
a5b6ee29 | 1161 | int ret; |
3de0b592 | 1162 | u32 ringidx_offset = offsetof(struct ethtool_rxfh_indir, ring_index[0]); |
a5b6ee29 | 1163 | |
fe62d001 | 1164 | if (!ops->get_rxfh_indir_size || !ops->set_rxfh || |
c03a14e8 | 1165 | !ops->get_rxnfc) |
7850f63f | 1166 | return -EOPNOTSUPP; |
c03a14e8 JP |
1167 | |
1168 | dev_size = ops->get_rxfh_indir_size(dev); | |
7850f63f | 1169 | if (dev_size == 0) |
a5b6ee29 BH |
1170 | return -EOPNOTSUPP; |
1171 | ||
7850f63f | 1172 | if (copy_from_user(&user_size, |
a5b6ee29 | 1173 | useraddr + offsetof(struct ethtool_rxfh_indir, size), |
7850f63f | 1174 | sizeof(user_size))) |
a5b6ee29 BH |
1175 | return -EFAULT; |
1176 | ||
278bc429 | 1177 | if (user_size != 0 && user_size != dev_size) |
7850f63f BH |
1178 | return -EINVAL; |
1179 | ||
1180 | indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER); | |
a5b6ee29 BH |
1181 | if (!indir) |
1182 | return -ENOMEM; | |
1183 | ||
7850f63f | 1184 | rx_rings.cmd = ETHTOOL_GRXRINGS; |
c03a14e8 | 1185 | ret = ops->get_rxnfc(dev, &rx_rings, NULL); |
7850f63f BH |
1186 | if (ret) |
1187 | goto out; | |
278bc429 BH |
1188 | |
1189 | if (user_size == 0) { | |
1190 | for (i = 0; i < dev_size; i++) | |
1191 | indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data); | |
1192 | } else { | |
3de0b592 VD |
1193 | ret = ethtool_copy_validate_indir(indir, |
1194 | useraddr + ringidx_offset, | |
1195 | &rx_rings, | |
1196 | dev_size); | |
1197 | if (ret) | |
1198 | goto out; | |
1199 | } | |
1200 | ||
892311f6 | 1201 | ret = ops->set_rxfh(dev, indir, NULL, ETH_RSS_HASH_NO_CHANGE); |
d4ab4286 KJ |
1202 | if (ret) |
1203 | goto out; | |
1204 | ||
1205 | /* indicate whether rxfh was set to default */ | |
1206 | if (user_size == 0) | |
1207 | dev->priv_flags &= ~IFF_RXFH_CONFIGURED; | |
1208 | else | |
1209 | dev->priv_flags |= IFF_RXFH_CONFIGURED; | |
3de0b592 VD |
1210 | |
1211 | out: | |
1212 | kfree(indir); | |
1213 | return ret; | |
1214 | } | |
1215 | ||
1216 | static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev, | |
1217 | void __user *useraddr) | |
1218 | { | |
1219 | int ret; | |
1220 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
f062a384 | 1221 | u32 user_indir_size, user_key_size; |
3de0b592 | 1222 | u32 dev_indir_size = 0, dev_key_size = 0; |
f062a384 | 1223 | struct ethtool_rxfh rxfh; |
3de0b592 | 1224 | u32 total_size; |
f062a384 | 1225 | u32 indir_bytes; |
3de0b592 | 1226 | u32 *indir = NULL; |
892311f6 | 1227 | u8 dev_hfunc = 0; |
3de0b592 VD |
1228 | u8 *hkey = NULL; |
1229 | u8 *rss_config; | |
1230 | ||
892311f6 | 1231 | if (!ops->get_rxfh) |
3de0b592 VD |
1232 | return -EOPNOTSUPP; |
1233 | ||
1234 | if (ops->get_rxfh_indir_size) | |
1235 | dev_indir_size = ops->get_rxfh_indir_size(dev); | |
3de0b592 VD |
1236 | if (ops->get_rxfh_key_size) |
1237 | dev_key_size = ops->get_rxfh_key_size(dev); | |
1238 | ||
f062a384 | 1239 | if (copy_from_user(&rxfh, useraddr, sizeof(rxfh))) |
3de0b592 | 1240 | return -EFAULT; |
f062a384 BH |
1241 | user_indir_size = rxfh.indir_size; |
1242 | user_key_size = rxfh.key_size; | |
3de0b592 | 1243 | |
f062a384 | 1244 | /* Check that reserved fields are 0 for now */ |
84a1d9c4 | 1245 | if (rxfh.rsvd8[0] || rxfh.rsvd8[1] || rxfh.rsvd8[2] || rxfh.rsvd32) |
f062a384 | 1246 | return -EINVAL; |
84a1d9c4 EC |
1247 | /* Most drivers don't handle rss_context, check it's 0 as well */ |
1248 | if (rxfh.rss_context && !ops->get_rxfh_context) | |
1249 | return -EOPNOTSUPP; | |
f062a384 BH |
1250 | |
1251 | rxfh.indir_size = dev_indir_size; | |
1252 | rxfh.key_size = dev_key_size; | |
1253 | if (copy_to_user(useraddr, &rxfh, sizeof(rxfh))) | |
3de0b592 VD |
1254 | return -EFAULT; |
1255 | ||
3de0b592 VD |
1256 | if ((user_indir_size && (user_indir_size != dev_indir_size)) || |
1257 | (user_key_size && (user_key_size != dev_key_size))) | |
1258 | return -EINVAL; | |
1259 | ||
1260 | indir_bytes = user_indir_size * sizeof(indir[0]); | |
1261 | total_size = indir_bytes + user_key_size; | |
1262 | rss_config = kzalloc(total_size, GFP_USER); | |
1263 | if (!rss_config) | |
1264 | return -ENOMEM; | |
1265 | ||
1266 | if (user_indir_size) | |
1267 | indir = (u32 *)rss_config; | |
1268 | ||
1269 | if (user_key_size) | |
1270 | hkey = rss_config + indir_bytes; | |
1271 | ||
84a1d9c4 EC |
1272 | if (rxfh.rss_context) |
1273 | ret = dev->ethtool_ops->get_rxfh_context(dev, indir, hkey, | |
1274 | &dev_hfunc, | |
1275 | rxfh.rss_context); | |
1276 | else | |
1277 | ret = dev->ethtool_ops->get_rxfh(dev, indir, hkey, &dev_hfunc); | |
892311f6 EP |
1278 | if (ret) |
1279 | goto out; | |
3de0b592 | 1280 | |
892311f6 EP |
1281 | if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh, hfunc), |
1282 | &dev_hfunc, sizeof(rxfh.hfunc))) { | |
1283 | ret = -EFAULT; | |
1284 | } else if (copy_to_user(useraddr + | |
1285 | offsetof(struct ethtool_rxfh, rss_config[0]), | |
1286 | rss_config, total_size)) { | |
1287 | ret = -EFAULT; | |
1288 | } | |
1289 | out: | |
3de0b592 VD |
1290 | kfree(rss_config); |
1291 | ||
1292 | return ret; | |
1293 | } | |
1294 | ||
1295 | static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, | |
1296 | void __user *useraddr) | |
1297 | { | |
1298 | int ret; | |
1299 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
1300 | struct ethtool_rxnfc rx_rings; | |
f062a384 BH |
1301 | struct ethtool_rxfh rxfh; |
1302 | u32 dev_indir_size = 0, dev_key_size = 0, i; | |
3de0b592 VD |
1303 | u32 *indir = NULL, indir_bytes = 0; |
1304 | u8 *hkey = NULL; | |
1305 | u8 *rss_config; | |
3de0b592 | 1306 | u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]); |
84a1d9c4 | 1307 | bool delete = false; |
3de0b592 | 1308 | |
892311f6 | 1309 | if (!ops->get_rxnfc || !ops->set_rxfh) |
3de0b592 VD |
1310 | return -EOPNOTSUPP; |
1311 | ||
1312 | if (ops->get_rxfh_indir_size) | |
1313 | dev_indir_size = ops->get_rxfh_indir_size(dev); | |
3de0b592 | 1314 | if (ops->get_rxfh_key_size) |
d340c862 | 1315 | dev_key_size = ops->get_rxfh_key_size(dev); |
3de0b592 | 1316 | |
f062a384 | 1317 | if (copy_from_user(&rxfh, useraddr, sizeof(rxfh))) |
3de0b592 VD |
1318 | return -EFAULT; |
1319 | ||
f062a384 | 1320 | /* Check that reserved fields are 0 for now */ |
84a1d9c4 | 1321 | if (rxfh.rsvd8[0] || rxfh.rsvd8[1] || rxfh.rsvd8[2] || rxfh.rsvd32) |
f062a384 | 1322 | return -EINVAL; |
84a1d9c4 EC |
1323 | /* Most drivers don't handle rss_context, check it's 0 as well */ |
1324 | if (rxfh.rss_context && !ops->set_rxfh_context) | |
1325 | return -EOPNOTSUPP; | |
f062a384 | 1326 | |
892311f6 EP |
1327 | /* If either indir, hash key or function is valid, proceed further. |
1328 | * Must request at least one change: indir size, hash key or function. | |
3de0b592 | 1329 | */ |
f062a384 BH |
1330 | if ((rxfh.indir_size && |
1331 | rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE && | |
1332 | rxfh.indir_size != dev_indir_size) || | |
1333 | (rxfh.key_size && (rxfh.key_size != dev_key_size)) || | |
1334 | (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE && | |
892311f6 | 1335 | rxfh.key_size == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE)) |
3de0b592 VD |
1336 | return -EINVAL; |
1337 | ||
f062a384 | 1338 | if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) |
3de0b592 VD |
1339 | indir_bytes = dev_indir_size * sizeof(indir[0]); |
1340 | ||
f062a384 | 1341 | rss_config = kzalloc(indir_bytes + rxfh.key_size, GFP_USER); |
3de0b592 VD |
1342 | if (!rss_config) |
1343 | return -ENOMEM; | |
1344 | ||
1345 | rx_rings.cmd = ETHTOOL_GRXRINGS; | |
1346 | ret = ops->get_rxnfc(dev, &rx_rings, NULL); | |
1347 | if (ret) | |
1348 | goto out; | |
1349 | ||
84a1d9c4 EC |
1350 | /* rxfh.indir_size == 0 means reset the indir table to default (master |
1351 | * context) or delete the context (other RSS contexts). | |
f062a384 | 1352 | * rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE means leave it unchanged. |
3de0b592 | 1353 | */ |
f062a384 BH |
1354 | if (rxfh.indir_size && |
1355 | rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) { | |
3de0b592 VD |
1356 | indir = (u32 *)rss_config; |
1357 | ret = ethtool_copy_validate_indir(indir, | |
1358 | useraddr + rss_cfg_offset, | |
1359 | &rx_rings, | |
f062a384 | 1360 | rxfh.indir_size); |
3de0b592 | 1361 | if (ret) |
7850f63f | 1362 | goto out; |
f062a384 | 1363 | } else if (rxfh.indir_size == 0) { |
84a1d9c4 EC |
1364 | if (rxfh.rss_context == 0) { |
1365 | indir = (u32 *)rss_config; | |
1366 | for (i = 0; i < dev_indir_size; i++) | |
1367 | indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data); | |
1368 | } else { | |
1369 | delete = true; | |
1370 | } | |
3de0b592 | 1371 | } |
278bc429 | 1372 | |
f062a384 | 1373 | if (rxfh.key_size) { |
3de0b592 VD |
1374 | hkey = rss_config + indir_bytes; |
1375 | if (copy_from_user(hkey, | |
1376 | useraddr + rss_cfg_offset + indir_bytes, | |
f062a384 | 1377 | rxfh.key_size)) { |
3de0b592 VD |
1378 | ret = -EFAULT; |
1379 | goto out; | |
278bc429 | 1380 | } |
7850f63f BH |
1381 | } |
1382 | ||
84a1d9c4 EC |
1383 | if (rxfh.rss_context) |
1384 | ret = ops->set_rxfh_context(dev, indir, hkey, rxfh.hfunc, | |
1385 | &rxfh.rss_context, delete); | |
1386 | else | |
1387 | ret = ops->set_rxfh(dev, indir, hkey, rxfh.hfunc); | |
d4ab4286 KJ |
1388 | if (ret) |
1389 | goto out; | |
1390 | ||
84a1d9c4 EC |
1391 | if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh, rss_context), |
1392 | &rxfh.rss_context, sizeof(rxfh.rss_context))) | |
1393 | ret = -EFAULT; | |
1394 | ||
1395 | if (!rxfh.rss_context) { | |
1396 | /* indicate whether rxfh was set to default */ | |
1397 | if (rxfh.indir_size == 0) | |
1398 | dev->priv_flags &= ~IFF_RXFH_CONFIGURED; | |
1399 | else if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) | |
1400 | dev->priv_flags |= IFF_RXFH_CONFIGURED; | |
1401 | } | |
a5b6ee29 BH |
1402 | |
1403 | out: | |
3de0b592 | 1404 | kfree(rss_config); |
a5b6ee29 BH |
1405 | return ret; |
1406 | } | |
1407 | ||
1da177e4 LT |
1408 | static int ethtool_get_regs(struct net_device *dev, char __user *useraddr) |
1409 | { | |
1410 | struct ethtool_regs regs; | |
76fd8593 | 1411 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 LT |
1412 | void *regbuf; |
1413 | int reglen, ret; | |
1414 | ||
1415 | if (!ops->get_regs || !ops->get_regs_len) | |
1416 | return -EOPNOTSUPP; | |
1417 | ||
1418 | if (copy_from_user(®s, useraddr, sizeof(regs))) | |
1419 | return -EFAULT; | |
1420 | ||
1421 | reglen = ops->get_regs_len(dev); | |
1422 | if (regs.len > reglen) | |
1423 | regs.len = reglen; | |
1424 | ||
3808d348 SG |
1425 | regbuf = NULL; |
1426 | if (reglen) { | |
1427 | regbuf = vzalloc(reglen); | |
1428 | if (!regbuf) | |
1429 | return -ENOMEM; | |
1430 | } | |
1da177e4 LT |
1431 | |
1432 | ops->get_regs(dev, ®s, regbuf); | |
1433 | ||
1434 | ret = -EFAULT; | |
1435 | if (copy_to_user(useraddr, ®s, sizeof(regs))) | |
1436 | goto out; | |
1437 | useraddr += offsetof(struct ethtool_regs, data); | |
67ae7cf1 | 1438 | if (regbuf && copy_to_user(useraddr, regbuf, regs.len)) |
1da177e4 LT |
1439 | goto out; |
1440 | ret = 0; | |
1441 | ||
1442 | out: | |
a77f5db3 | 1443 | vfree(regbuf); |
1da177e4 LT |
1444 | return ret; |
1445 | } | |
1446 | ||
d73d3a8c BH |
1447 | static int ethtool_reset(struct net_device *dev, char __user *useraddr) |
1448 | { | |
1449 | struct ethtool_value reset; | |
1450 | int ret; | |
1451 | ||
1452 | if (!dev->ethtool_ops->reset) | |
1453 | return -EOPNOTSUPP; | |
1454 | ||
1455 | if (copy_from_user(&reset, useraddr, sizeof(reset))) | |
1456 | return -EFAULT; | |
1457 | ||
1458 | ret = dev->ethtool_ops->reset(dev, &reset.data); | |
1459 | if (ret) | |
1460 | return ret; | |
1461 | ||
1462 | if (copy_to_user(useraddr, &reset, sizeof(reset))) | |
1463 | return -EFAULT; | |
1464 | return 0; | |
1465 | } | |
1466 | ||
1da177e4 LT |
1467 | static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) |
1468 | { | |
8e557421 | 1469 | struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; |
1da177e4 LT |
1470 | |
1471 | if (!dev->ethtool_ops->get_wol) | |
1472 | return -EOPNOTSUPP; | |
1473 | ||
1474 | dev->ethtool_ops->get_wol(dev, &wol); | |
1475 | ||
1476 | if (copy_to_user(useraddr, &wol, sizeof(wol))) | |
1477 | return -EFAULT; | |
1478 | return 0; | |
1479 | } | |
1480 | ||
1481 | static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) | |
1482 | { | |
1483 | struct ethtool_wolinfo wol; | |
1484 | ||
1485 | if (!dev->ethtool_ops->set_wol) | |
1486 | return -EOPNOTSUPP; | |
1487 | ||
1488 | if (copy_from_user(&wol, useraddr, sizeof(wol))) | |
1489 | return -EFAULT; | |
1490 | ||
1491 | return dev->ethtool_ops->set_wol(dev, &wol); | |
1492 | } | |
1493 | ||
80f12ecc YM |
1494 | static int ethtool_get_eee(struct net_device *dev, char __user *useraddr) |
1495 | { | |
1496 | struct ethtool_eee edata; | |
1497 | int rc; | |
1498 | ||
1499 | if (!dev->ethtool_ops->get_eee) | |
1500 | return -EOPNOTSUPP; | |
1501 | ||
1502 | memset(&edata, 0, sizeof(struct ethtool_eee)); | |
1503 | edata.cmd = ETHTOOL_GEEE; | |
1504 | rc = dev->ethtool_ops->get_eee(dev, &edata); | |
1505 | ||
1506 | if (rc) | |
1507 | return rc; | |
1508 | ||
1509 | if (copy_to_user(useraddr, &edata, sizeof(edata))) | |
1510 | return -EFAULT; | |
1511 | ||
1512 | return 0; | |
1513 | } | |
1514 | ||
1515 | static int ethtool_set_eee(struct net_device *dev, char __user *useraddr) | |
1516 | { | |
1517 | struct ethtool_eee edata; | |
1518 | ||
1519 | if (!dev->ethtool_ops->set_eee) | |
1520 | return -EOPNOTSUPP; | |
1521 | ||
1522 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
1523 | return -EFAULT; | |
1524 | ||
1525 | return dev->ethtool_ops->set_eee(dev, &edata); | |
1526 | } | |
1527 | ||
1da177e4 LT |
1528 | static int ethtool_nway_reset(struct net_device *dev) |
1529 | { | |
1530 | if (!dev->ethtool_ops->nway_reset) | |
1531 | return -EOPNOTSUPP; | |
1532 | ||
1533 | return dev->ethtool_ops->nway_reset(dev); | |
1534 | } | |
1535 | ||
e596e6e4 BH |
1536 | static int ethtool_get_link(struct net_device *dev, char __user *useraddr) |
1537 | { | |
1538 | struct ethtool_value edata = { .cmd = ETHTOOL_GLINK }; | |
1539 | ||
1540 | if (!dev->ethtool_ops->get_link) | |
1541 | return -EOPNOTSUPP; | |
1542 | ||
1543 | edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev); | |
1544 | ||
1545 | if (copy_to_user(useraddr, &edata, sizeof(edata))) | |
1546 | return -EFAULT; | |
1547 | return 0; | |
1548 | } | |
1549 | ||
081d094e BH |
1550 | static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr, |
1551 | int (*getter)(struct net_device *, | |
1552 | struct ethtool_eeprom *, u8 *), | |
1553 | u32 total_len) | |
1da177e4 LT |
1554 | { |
1555 | struct ethtool_eeprom eeprom; | |
b131dd5d MSB |
1556 | void __user *userbuf = useraddr + sizeof(eeprom); |
1557 | u32 bytes_remaining; | |
1da177e4 | 1558 | u8 *data; |
b131dd5d | 1559 | int ret = 0; |
1da177e4 | 1560 | |
1da177e4 LT |
1561 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) |
1562 | return -EFAULT; | |
1563 | ||
1564 | /* Check for wrap and zero */ | |
1565 | if (eeprom.offset + eeprom.len <= eeprom.offset) | |
1566 | return -EINVAL; | |
1567 | ||
1568 | /* Check for exceeding total eeprom len */ | |
081d094e | 1569 | if (eeprom.offset + eeprom.len > total_len) |
1da177e4 LT |
1570 | return -EINVAL; |
1571 | ||
b131dd5d | 1572 | data = kmalloc(PAGE_SIZE, GFP_USER); |
1da177e4 LT |
1573 | if (!data) |
1574 | return -ENOMEM; | |
1575 | ||
b131dd5d MSB |
1576 | bytes_remaining = eeprom.len; |
1577 | while (bytes_remaining > 0) { | |
1578 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); | |
1579 | ||
081d094e | 1580 | ret = getter(dev, &eeprom, data); |
b131dd5d MSB |
1581 | if (ret) |
1582 | break; | |
1583 | if (copy_to_user(userbuf, data, eeprom.len)) { | |
1584 | ret = -EFAULT; | |
1585 | break; | |
1586 | } | |
1587 | userbuf += eeprom.len; | |
1588 | eeprom.offset += eeprom.len; | |
1589 | bytes_remaining -= eeprom.len; | |
1590 | } | |
1da177e4 | 1591 | |
c5835df9 MSB |
1592 | eeprom.len = userbuf - (useraddr + sizeof(eeprom)); |
1593 | eeprom.offset -= eeprom.len; | |
1594 | if (copy_to_user(useraddr, &eeprom, sizeof(eeprom))) | |
1595 | ret = -EFAULT; | |
1596 | ||
1da177e4 LT |
1597 | kfree(data); |
1598 | return ret; | |
1599 | } | |
1600 | ||
081d094e BH |
1601 | static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr) |
1602 | { | |
1603 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
1604 | ||
e0fb6fb6 GR |
1605 | if (!ops->get_eeprom || !ops->get_eeprom_len || |
1606 | !ops->get_eeprom_len(dev)) | |
081d094e BH |
1607 | return -EOPNOTSUPP; |
1608 | ||
1609 | return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom, | |
1610 | ops->get_eeprom_len(dev)); | |
1611 | } | |
1612 | ||
1da177e4 LT |
1613 | static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr) |
1614 | { | |
1615 | struct ethtool_eeprom eeprom; | |
76fd8593 | 1616 | const struct ethtool_ops *ops = dev->ethtool_ops; |
b131dd5d MSB |
1617 | void __user *userbuf = useraddr + sizeof(eeprom); |
1618 | u32 bytes_remaining; | |
1da177e4 | 1619 | u8 *data; |
b131dd5d | 1620 | int ret = 0; |
1da177e4 | 1621 | |
e0fb6fb6 GR |
1622 | if (!ops->set_eeprom || !ops->get_eeprom_len || |
1623 | !ops->get_eeprom_len(dev)) | |
1da177e4 LT |
1624 | return -EOPNOTSUPP; |
1625 | ||
1626 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) | |
1627 | return -EFAULT; | |
1628 | ||
1629 | /* Check for wrap and zero */ | |
1630 | if (eeprom.offset + eeprom.len <= eeprom.offset) | |
1631 | return -EINVAL; | |
1632 | ||
1633 | /* Check for exceeding total eeprom len */ | |
1634 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) | |
1635 | return -EINVAL; | |
1636 | ||
b131dd5d | 1637 | data = kmalloc(PAGE_SIZE, GFP_USER); |
1da177e4 LT |
1638 | if (!data) |
1639 | return -ENOMEM; | |
1640 | ||
b131dd5d MSB |
1641 | bytes_remaining = eeprom.len; |
1642 | while (bytes_remaining > 0) { | |
1643 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); | |
1644 | ||
1645 | if (copy_from_user(data, userbuf, eeprom.len)) { | |
1646 | ret = -EFAULT; | |
1647 | break; | |
1648 | } | |
1649 | ret = ops->set_eeprom(dev, &eeprom, data); | |
1650 | if (ret) | |
1651 | break; | |
1652 | userbuf += eeprom.len; | |
1653 | eeprom.offset += eeprom.len; | |
1654 | bytes_remaining -= eeprom.len; | |
1655 | } | |
1da177e4 | 1656 | |
1da177e4 LT |
1657 | kfree(data); |
1658 | return ret; | |
1659 | } | |
1660 | ||
97f8aefb | 1661 | static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, |
1662 | void __user *useraddr) | |
1da177e4 | 1663 | { |
8e557421 | 1664 | struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; |
1da177e4 LT |
1665 | |
1666 | if (!dev->ethtool_ops->get_coalesce) | |
1667 | return -EOPNOTSUPP; | |
1668 | ||
1669 | dev->ethtool_ops->get_coalesce(dev, &coalesce); | |
1670 | ||
1671 | if (copy_to_user(useraddr, &coalesce, sizeof(coalesce))) | |
1672 | return -EFAULT; | |
1673 | return 0; | |
1674 | } | |
1675 | ||
97f8aefb | 1676 | static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, |
1677 | void __user *useraddr) | |
1da177e4 LT |
1678 | { |
1679 | struct ethtool_coalesce coalesce; | |
1680 | ||
fa04ae5c | 1681 | if (!dev->ethtool_ops->set_coalesce) |
1da177e4 LT |
1682 | return -EOPNOTSUPP; |
1683 | ||
1684 | if (copy_from_user(&coalesce, useraddr, sizeof(coalesce))) | |
1685 | return -EFAULT; | |
1686 | ||
1687 | return dev->ethtool_ops->set_coalesce(dev, &coalesce); | |
1688 | } | |
1689 | ||
1690 | static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr) | |
1691 | { | |
8e557421 | 1692 | struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM }; |
1da177e4 LT |
1693 | |
1694 | if (!dev->ethtool_ops->get_ringparam) | |
1695 | return -EOPNOTSUPP; | |
1696 | ||
1697 | dev->ethtool_ops->get_ringparam(dev, &ringparam); | |
1698 | ||
1699 | if (copy_to_user(useraddr, &ringparam, sizeof(ringparam))) | |
1700 | return -EFAULT; | |
1701 | return 0; | |
1702 | } | |
1703 | ||
1704 | static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr) | |
1705 | { | |
37e2d99b | 1706 | struct ethtool_ringparam ringparam, max = { .cmd = ETHTOOL_GRINGPARAM }; |
1da177e4 | 1707 | |
37e2d99b | 1708 | if (!dev->ethtool_ops->set_ringparam || !dev->ethtool_ops->get_ringparam) |
1da177e4 LT |
1709 | return -EOPNOTSUPP; |
1710 | ||
1711 | if (copy_from_user(&ringparam, useraddr, sizeof(ringparam))) | |
1712 | return -EFAULT; | |
1713 | ||
37e2d99b EE |
1714 | dev->ethtool_ops->get_ringparam(dev, &max); |
1715 | ||
1716 | /* ensure new ring parameters are within the maximums */ | |
1717 | if (ringparam.rx_pending > max.rx_max_pending || | |
1718 | ringparam.rx_mini_pending > max.rx_mini_max_pending || | |
1719 | ringparam.rx_jumbo_pending > max.rx_jumbo_max_pending || | |
1720 | ringparam.tx_pending > max.tx_max_pending) | |
1721 | return -EINVAL; | |
1722 | ||
1da177e4 LT |
1723 | return dev->ethtool_ops->set_ringparam(dev, &ringparam); |
1724 | } | |
1725 | ||
8b5933c3 | 1726 | static noinline_for_stack int ethtool_get_channels(struct net_device *dev, |
1727 | void __user *useraddr) | |
1728 | { | |
1729 | struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS }; | |
1730 | ||
1731 | if (!dev->ethtool_ops->get_channels) | |
1732 | return -EOPNOTSUPP; | |
1733 | ||
1734 | dev->ethtool_ops->get_channels(dev, &channels); | |
1735 | ||
1736 | if (copy_to_user(useraddr, &channels, sizeof(channels))) | |
1737 | return -EFAULT; | |
1738 | return 0; | |
1739 | } | |
1740 | ||
1741 | static noinline_for_stack int ethtool_set_channels(struct net_device *dev, | |
1742 | void __user *useraddr) | |
1743 | { | |
31a86d13 | 1744 | struct ethtool_channels channels, max = { .cmd = ETHTOOL_GCHANNELS }; |
d4ab4286 | 1745 | u32 max_rx_in_use = 0; |
8b5933c3 | 1746 | |
8bf36862 | 1747 | if (!dev->ethtool_ops->set_channels || !dev->ethtool_ops->get_channels) |
8b5933c3 | 1748 | return -EOPNOTSUPP; |
1749 | ||
1750 | if (copy_from_user(&channels, useraddr, sizeof(channels))) | |
1751 | return -EFAULT; | |
1752 | ||
8bf36862 KJ |
1753 | dev->ethtool_ops->get_channels(dev, &max); |
1754 | ||
1755 | /* ensure new counts are within the maximums */ | |
1756 | if ((channels.rx_count > max.max_rx) || | |
1757 | (channels.tx_count > max.max_tx) || | |
1758 | (channels.combined_count > max.max_combined) || | |
1759 | (channels.other_count > max.max_other)) | |
1760 | return -EINVAL; | |
1761 | ||
d4ab4286 KJ |
1762 | /* ensure the new Rx count fits within the configured Rx flow |
1763 | * indirection table settings */ | |
1764 | if (netif_is_rxfh_configured(dev) && | |
1765 | !ethtool_get_max_rxfh_channel(dev, &max_rx_in_use) && | |
1766 | (channels.combined_count + channels.rx_count) <= max_rx_in_use) | |
1767 | return -EINVAL; | |
1768 | ||
8b5933c3 | 1769 | return dev->ethtool_ops->set_channels(dev, &channels); |
1770 | } | |
1771 | ||
1da177e4 LT |
1772 | static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr) |
1773 | { | |
1774 | struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM }; | |
1775 | ||
1776 | if (!dev->ethtool_ops->get_pauseparam) | |
1777 | return -EOPNOTSUPP; | |
1778 | ||
1779 | dev->ethtool_ops->get_pauseparam(dev, &pauseparam); | |
1780 | ||
1781 | if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam))) | |
1782 | return -EFAULT; | |
1783 | return 0; | |
1784 | } | |
1785 | ||
1786 | static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr) | |
1787 | { | |
1788 | struct ethtool_pauseparam pauseparam; | |
1789 | ||
e1b90c41 | 1790 | if (!dev->ethtool_ops->set_pauseparam) |
1da177e4 LT |
1791 | return -EOPNOTSUPP; |
1792 | ||
1793 | if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam))) | |
1794 | return -EFAULT; | |
1795 | ||
1796 | return dev->ethtool_ops->set_pauseparam(dev, &pauseparam); | |
1797 | } | |
1798 | ||
1da177e4 LT |
1799 | static int ethtool_self_test(struct net_device *dev, char __user *useraddr) |
1800 | { | |
1801 | struct ethtool_test test; | |
76fd8593 | 1802 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 | 1803 | u64 *data; |
ff03d49f | 1804 | int ret, test_len; |
1da177e4 | 1805 | |
a9828ec6 | 1806 | if (!ops->self_test || !ops->get_sset_count) |
1da177e4 LT |
1807 | return -EOPNOTSUPP; |
1808 | ||
a9828ec6 | 1809 | test_len = ops->get_sset_count(dev, ETH_SS_TEST); |
ff03d49f JG |
1810 | if (test_len < 0) |
1811 | return test_len; | |
1812 | WARN_ON(test_len == 0); | |
1813 | ||
1da177e4 LT |
1814 | if (copy_from_user(&test, useraddr, sizeof(test))) |
1815 | return -EFAULT; | |
1816 | ||
ff03d49f JG |
1817 | test.len = test_len; |
1818 | data = kmalloc(test_len * sizeof(u64), GFP_USER); | |
1da177e4 LT |
1819 | if (!data) |
1820 | return -ENOMEM; | |
1821 | ||
1822 | ops->self_test(dev, &test, data); | |
1823 | ||
1824 | ret = -EFAULT; | |
1825 | if (copy_to_user(useraddr, &test, sizeof(test))) | |
1826 | goto out; | |
1827 | useraddr += sizeof(test); | |
1828 | if (copy_to_user(useraddr, data, test.len * sizeof(u64))) | |
1829 | goto out; | |
1830 | ret = 0; | |
1831 | ||
1832 | out: | |
1833 | kfree(data); | |
1834 | return ret; | |
1835 | } | |
1836 | ||
1837 | static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) | |
1838 | { | |
1839 | struct ethtool_gstrings gstrings; | |
1da177e4 LT |
1840 | u8 *data; |
1841 | int ret; | |
1842 | ||
1da177e4 LT |
1843 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) |
1844 | return -EFAULT; | |
1845 | ||
340ae165 | 1846 | ret = __ethtool_get_sset_count(dev, gstrings.string_set); |
a9828ec6 BH |
1847 | if (ret < 0) |
1848 | return ret; | |
4d1ceea8 AS |
1849 | if (ret > S32_MAX / ETH_GSTRING_LEN) |
1850 | return -ENOMEM; | |
1851 | WARN_ON_ONCE(!ret); | |
a9828ec6 BH |
1852 | |
1853 | gstrings.len = ret; | |
4d1ceea8 AS |
1854 | data = vzalloc(gstrings.len * ETH_GSTRING_LEN); |
1855 | if (gstrings.len && !data) | |
1da177e4 LT |
1856 | return -ENOMEM; |
1857 | ||
340ae165 | 1858 | __ethtool_get_strings(dev, gstrings.string_set, data); |
1da177e4 LT |
1859 | |
1860 | ret = -EFAULT; | |
1861 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) | |
1862 | goto out; | |
1863 | useraddr += sizeof(gstrings); | |
4d1ceea8 AS |
1864 | if (gstrings.len && |
1865 | copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN)) | |
1da177e4 LT |
1866 | goto out; |
1867 | ret = 0; | |
1868 | ||
340ae165 | 1869 | out: |
4d1ceea8 | 1870 | vfree(data); |
1da177e4 LT |
1871 | return ret; |
1872 | } | |
1873 | ||
1874 | static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) | |
1875 | { | |
1876 | struct ethtool_value id; | |
68f512f2 | 1877 | static bool busy; |
c03a14e8 | 1878 | const struct ethtool_ops *ops = dev->ethtool_ops; |
68f512f2 | 1879 | int rc; |
1da177e4 | 1880 | |
c03a14e8 | 1881 | if (!ops->set_phys_id) |
1da177e4 LT |
1882 | return -EOPNOTSUPP; |
1883 | ||
68f512f2 BH |
1884 | if (busy) |
1885 | return -EBUSY; | |
1886 | ||
1da177e4 LT |
1887 | if (copy_from_user(&id, useraddr, sizeof(id))) |
1888 | return -EFAULT; | |
1889 | ||
c03a14e8 | 1890 | rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE); |
fce55922 | 1891 | if (rc < 0) |
68f512f2 BH |
1892 | return rc; |
1893 | ||
1894 | /* Drop the RTNL lock while waiting, but prevent reentry or | |
1895 | * removal of the device. | |
1896 | */ | |
1897 | busy = true; | |
1898 | dev_hold(dev); | |
1899 | rtnl_unlock(); | |
1900 | ||
1901 | if (rc == 0) { | |
1902 | /* Driver will handle this itself */ | |
1903 | schedule_timeout_interruptible( | |
143780c6 | 1904 | id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT); |
68f512f2 | 1905 | } else { |
fce55922 AB |
1906 | /* Driver expects to be called at twice the frequency in rc */ |
1907 | int n = rc * 2, i, interval = HZ / n; | |
1908 | ||
1909 | /* Count down seconds */ | |
68f512f2 | 1910 | do { |
fce55922 AB |
1911 | /* Count down iterations per second */ |
1912 | i = n; | |
1913 | do { | |
1914 | rtnl_lock(); | |
c03a14e8 | 1915 | rc = ops->set_phys_id(dev, |
fce55922 AB |
1916 | (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON); |
1917 | rtnl_unlock(); | |
1918 | if (rc) | |
1919 | break; | |
1920 | schedule_timeout_interruptible(interval); | |
1921 | } while (!signal_pending(current) && --i != 0); | |
68f512f2 BH |
1922 | } while (!signal_pending(current) && |
1923 | (id.data == 0 || --id.data != 0)); | |
1924 | } | |
1925 | ||
1926 | rtnl_lock(); | |
1927 | dev_put(dev); | |
1928 | busy = false; | |
1929 | ||
c03a14e8 | 1930 | (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE); |
68f512f2 | 1931 | return rc; |
1da177e4 LT |
1932 | } |
1933 | ||
1934 | static int ethtool_get_stats(struct net_device *dev, void __user *useraddr) | |
1935 | { | |
1936 | struct ethtool_stats stats; | |
76fd8593 | 1937 | const struct ethtool_ops *ops = dev->ethtool_ops; |
1da177e4 | 1938 | u64 *data; |
ff03d49f | 1939 | int ret, n_stats; |
1da177e4 | 1940 | |
a9828ec6 | 1941 | if (!ops->get_ethtool_stats || !ops->get_sset_count) |
1da177e4 LT |
1942 | return -EOPNOTSUPP; |
1943 | ||
a9828ec6 | 1944 | n_stats = ops->get_sset_count(dev, ETH_SS_STATS); |
ff03d49f JG |
1945 | if (n_stats < 0) |
1946 | return n_stats; | |
4d1ceea8 AS |
1947 | if (n_stats > S32_MAX / sizeof(u64)) |
1948 | return -ENOMEM; | |
1949 | WARN_ON_ONCE(!n_stats); | |
1da177e4 LT |
1950 | if (copy_from_user(&stats, useraddr, sizeof(stats))) |
1951 | return -EFAULT; | |
1952 | ||
ff03d49f | 1953 | stats.n_stats = n_stats; |
4d1ceea8 AS |
1954 | data = vzalloc(n_stats * sizeof(u64)); |
1955 | if (n_stats && !data) | |
1da177e4 LT |
1956 | return -ENOMEM; |
1957 | ||
1958 | ops->get_ethtool_stats(dev, &stats, data); | |
1959 | ||
1960 | ret = -EFAULT; | |
1961 | if (copy_to_user(useraddr, &stats, sizeof(stats))) | |
1962 | goto out; | |
1963 | useraddr += sizeof(stats); | |
4d1ceea8 | 1964 | if (n_stats && copy_to_user(useraddr, data, n_stats * sizeof(u64))) |
1da177e4 LT |
1965 | goto out; |
1966 | ret = 0; | |
1967 | ||
1968 | out: | |
4d1ceea8 | 1969 | vfree(data); |
1da177e4 LT |
1970 | return ret; |
1971 | } | |
1972 | ||
f3a40945 AL |
1973 | static int ethtool_get_phy_stats(struct net_device *dev, void __user *useraddr) |
1974 | { | |
1975 | struct ethtool_stats stats; | |
1976 | struct phy_device *phydev = dev->phydev; | |
1977 | u64 *data; | |
1978 | int ret, n_stats; | |
1979 | ||
1980 | if (!phydev) | |
1981 | return -EOPNOTSUPP; | |
1982 | ||
c59530d0 | 1983 | n_stats = phy_ethtool_get_sset_count(dev->phydev); |
f3a40945 AL |
1984 | if (n_stats < 0) |
1985 | return n_stats; | |
4d1ceea8 AS |
1986 | if (n_stats > S32_MAX / sizeof(u64)) |
1987 | return -ENOMEM; | |
1988 | WARN_ON_ONCE(!n_stats); | |
f3a40945 AL |
1989 | |
1990 | if (copy_from_user(&stats, useraddr, sizeof(stats))) | |
1991 | return -EFAULT; | |
1992 | ||
1993 | stats.n_stats = n_stats; | |
4d1ceea8 AS |
1994 | data = vzalloc(n_stats * sizeof(u64)); |
1995 | if (n_stats && !data) | |
f3a40945 AL |
1996 | return -ENOMEM; |
1997 | ||
c59530d0 FF |
1998 | ret = phy_ethtool_get_stats(dev->phydev, &stats, data); |
1999 | if (ret < 0) | |
2000 | return ret; | |
f3a40945 AL |
2001 | |
2002 | ret = -EFAULT; | |
2003 | if (copy_to_user(useraddr, &stats, sizeof(stats))) | |
2004 | goto out; | |
2005 | useraddr += sizeof(stats); | |
4d1ceea8 | 2006 | if (n_stats && copy_to_user(useraddr, data, n_stats * sizeof(u64))) |
f3a40945 AL |
2007 | goto out; |
2008 | ret = 0; | |
2009 | ||
2010 | out: | |
4d1ceea8 | 2011 | vfree(data); |
f3a40945 AL |
2012 | return ret; |
2013 | } | |
2014 | ||
0bf0519d | 2015 | static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr) |
a6f9a705 JW |
2016 | { |
2017 | struct ethtool_perm_addr epaddr; | |
a6f9a705 | 2018 | |
313674af | 2019 | if (copy_from_user(&epaddr, useraddr, sizeof(epaddr))) |
a6f9a705 JW |
2020 | return -EFAULT; |
2021 | ||
313674af MW |
2022 | if (epaddr.size < dev->addr_len) |
2023 | return -ETOOSMALL; | |
2024 | epaddr.size = dev->addr_len; | |
a6f9a705 | 2025 | |
a6f9a705 | 2026 | if (copy_to_user(useraddr, &epaddr, sizeof(epaddr))) |
313674af | 2027 | return -EFAULT; |
a6f9a705 | 2028 | useraddr += sizeof(epaddr); |
313674af MW |
2029 | if (copy_to_user(useraddr, dev->perm_addr, epaddr.size)) |
2030 | return -EFAULT; | |
2031 | return 0; | |
a6f9a705 JW |
2032 | } |
2033 | ||
13c99b24 JG |
2034 | static int ethtool_get_value(struct net_device *dev, char __user *useraddr, |
2035 | u32 cmd, u32 (*actor)(struct net_device *)) | |
3ae7c0b2 | 2036 | { |
8e557421 | 2037 | struct ethtool_value edata = { .cmd = cmd }; |
3ae7c0b2 | 2038 | |
13c99b24 | 2039 | if (!actor) |
3ae7c0b2 JG |
2040 | return -EOPNOTSUPP; |
2041 | ||
13c99b24 | 2042 | edata.data = actor(dev); |
3ae7c0b2 JG |
2043 | |
2044 | if (copy_to_user(useraddr, &edata, sizeof(edata))) | |
2045 | return -EFAULT; | |
2046 | return 0; | |
2047 | } | |
2048 | ||
13c99b24 JG |
2049 | static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr, |
2050 | void (*actor)(struct net_device *, u32)) | |
3ae7c0b2 JG |
2051 | { |
2052 | struct ethtool_value edata; | |
2053 | ||
13c99b24 | 2054 | if (!actor) |
3ae7c0b2 JG |
2055 | return -EOPNOTSUPP; |
2056 | ||
2057 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
2058 | return -EFAULT; | |
2059 | ||
13c99b24 | 2060 | actor(dev, edata.data); |
339bf024 JG |
2061 | return 0; |
2062 | } | |
2063 | ||
13c99b24 JG |
2064 | static int ethtool_set_value(struct net_device *dev, char __user *useraddr, |
2065 | int (*actor)(struct net_device *, u32)) | |
339bf024 JG |
2066 | { |
2067 | struct ethtool_value edata; | |
2068 | ||
13c99b24 | 2069 | if (!actor) |
339bf024 JG |
2070 | return -EOPNOTSUPP; |
2071 | ||
2072 | if (copy_from_user(&edata, useraddr, sizeof(edata))) | |
2073 | return -EFAULT; | |
2074 | ||
13c99b24 | 2075 | return actor(dev, edata.data); |
339bf024 JG |
2076 | } |
2077 | ||
97f8aefb | 2078 | static noinline_for_stack int ethtool_flash_device(struct net_device *dev, |
2079 | char __user *useraddr) | |
05c6a8d7 AK |
2080 | { |
2081 | struct ethtool_flash efl; | |
2082 | ||
2083 | if (copy_from_user(&efl, useraddr, sizeof(efl))) | |
2084 | return -EFAULT; | |
2085 | ||
2086 | if (!dev->ethtool_ops->flash_device) | |
2087 | return -EOPNOTSUPP; | |
2088 | ||
786f5281 BH |
2089 | efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0; |
2090 | ||
05c6a8d7 AK |
2091 | return dev->ethtool_ops->flash_device(dev, &efl); |
2092 | } | |
2093 | ||
29dd54b7 AC |
2094 | static int ethtool_set_dump(struct net_device *dev, |
2095 | void __user *useraddr) | |
2096 | { | |
2097 | struct ethtool_dump dump; | |
2098 | ||
2099 | if (!dev->ethtool_ops->set_dump) | |
2100 | return -EOPNOTSUPP; | |
2101 | ||
2102 | if (copy_from_user(&dump, useraddr, sizeof(dump))) | |
2103 | return -EFAULT; | |
2104 | ||
2105 | return dev->ethtool_ops->set_dump(dev, &dump); | |
2106 | } | |
2107 | ||
2108 | static int ethtool_get_dump_flag(struct net_device *dev, | |
2109 | void __user *useraddr) | |
2110 | { | |
2111 | int ret; | |
2112 | struct ethtool_dump dump; | |
2113 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
2114 | ||
c03a14e8 | 2115 | if (!ops->get_dump_flag) |
29dd54b7 AC |
2116 | return -EOPNOTSUPP; |
2117 | ||
2118 | if (copy_from_user(&dump, useraddr, sizeof(dump))) | |
2119 | return -EFAULT; | |
2120 | ||
2121 | ret = ops->get_dump_flag(dev, &dump); | |
2122 | if (ret) | |
2123 | return ret; | |
2124 | ||
2125 | if (copy_to_user(useraddr, &dump, sizeof(dump))) | |
2126 | return -EFAULT; | |
2127 | return 0; | |
2128 | } | |
2129 | ||
2130 | static int ethtool_get_dump_data(struct net_device *dev, | |
2131 | void __user *useraddr) | |
2132 | { | |
2133 | int ret; | |
2134 | __u32 len; | |
2135 | struct ethtool_dump dump, tmp; | |
2136 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
2137 | void *data = NULL; | |
2138 | ||
c03a14e8 | 2139 | if (!ops->get_dump_data || !ops->get_dump_flag) |
29dd54b7 AC |
2140 | return -EOPNOTSUPP; |
2141 | ||
2142 | if (copy_from_user(&dump, useraddr, sizeof(dump))) | |
2143 | return -EFAULT; | |
2144 | ||
2145 | memset(&tmp, 0, sizeof(tmp)); | |
2146 | tmp.cmd = ETHTOOL_GET_DUMP_FLAG; | |
2147 | ret = ops->get_dump_flag(dev, &tmp); | |
2148 | if (ret) | |
2149 | return ret; | |
2150 | ||
c590b5e2 | 2151 | len = min(tmp.len, dump.len); |
29dd54b7 AC |
2152 | if (!len) |
2153 | return -EFAULT; | |
2154 | ||
c590b5e2 MS |
2155 | /* Don't ever let the driver think there's more space available |
2156 | * than it requested with .get_dump_flag(). | |
2157 | */ | |
2158 | dump.len = len; | |
2159 | ||
2160 | /* Always allocate enough space to hold the whole thing so that the | |
2161 | * driver does not need to check the length and bother with partial | |
2162 | * dumping. | |
2163 | */ | |
29dd54b7 AC |
2164 | data = vzalloc(tmp.len); |
2165 | if (!data) | |
2166 | return -ENOMEM; | |
2167 | ret = ops->get_dump_data(dev, &dump, data); | |
2168 | if (ret) | |
2169 | goto out; | |
2170 | ||
c590b5e2 MS |
2171 | /* There are two sane possibilities: |
2172 | * 1. The driver's .get_dump_data() does not touch dump.len. | |
2173 | * 2. Or it may set dump.len to how much it really writes, which | |
2174 | * should be tmp.len (or len if it can do a partial dump). | |
2175 | * In any case respond to userspace with the actual length of data | |
2176 | * it's receiving. | |
2177 | */ | |
2178 | WARN_ON(dump.len != len && dump.len != tmp.len); | |
2179 | dump.len = len; | |
2180 | ||
29dd54b7 AC |
2181 | if (copy_to_user(useraddr, &dump, sizeof(dump))) { |
2182 | ret = -EFAULT; | |
2183 | goto out; | |
2184 | } | |
2185 | useraddr += offsetof(struct ethtool_dump, data); | |
2186 | if (copy_to_user(useraddr, data, len)) | |
2187 | ret = -EFAULT; | |
2188 | out: | |
2189 | vfree(data); | |
2190 | return ret; | |
2191 | } | |
2192 | ||
c8f3a8c3 RC |
2193 | static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr) |
2194 | { | |
2195 | int err = 0; | |
2196 | struct ethtool_ts_info info; | |
2197 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
2198 | struct phy_device *phydev = dev->phydev; | |
2199 | ||
2200 | memset(&info, 0, sizeof(info)); | |
2201 | info.cmd = ETHTOOL_GET_TS_INFO; | |
2202 | ||
2203 | if (phydev && phydev->drv && phydev->drv->ts_info) { | |
c8f3a8c3 | 2204 | err = phydev->drv->ts_info(phydev, &info); |
c03a14e8 | 2205 | } else if (ops->get_ts_info) { |
c8f3a8c3 | 2206 | err = ops->get_ts_info(dev, &info); |
c8f3a8c3 RC |
2207 | } else { |
2208 | info.so_timestamping = | |
2209 | SOF_TIMESTAMPING_RX_SOFTWARE | | |
2210 | SOF_TIMESTAMPING_SOFTWARE; | |
2211 | info.phc_index = -1; | |
2212 | } | |
2213 | ||
2214 | if (err) | |
2215 | return err; | |
2216 | ||
2217 | if (copy_to_user(useraddr, &info, sizeof(info))) | |
2218 | err = -EFAULT; | |
2219 | ||
2220 | return err; | |
2221 | } | |
2222 | ||
2f438366 ES |
2223 | static int __ethtool_get_module_info(struct net_device *dev, |
2224 | struct ethtool_modinfo *modinfo) | |
2225 | { | |
2226 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
2227 | struct phy_device *phydev = dev->phydev; | |
2228 | ||
e679c9c1 RK |
2229 | if (dev->sfp_bus) |
2230 | return sfp_get_module_info(dev->sfp_bus, modinfo); | |
2231 | ||
2f438366 ES |
2232 | if (phydev && phydev->drv && phydev->drv->module_info) |
2233 | return phydev->drv->module_info(phydev, modinfo); | |
2234 | ||
2235 | if (ops->get_module_info) | |
2236 | return ops->get_module_info(dev, modinfo); | |
2237 | ||
2238 | return -EOPNOTSUPP; | |
2239 | } | |
2240 | ||
41c3cb6d SH |
2241 | static int ethtool_get_module_info(struct net_device *dev, |
2242 | void __user *useraddr) | |
2243 | { | |
2244 | int ret; | |
2245 | struct ethtool_modinfo modinfo; | |
41c3cb6d SH |
2246 | |
2247 | if (copy_from_user(&modinfo, useraddr, sizeof(modinfo))) | |
2248 | return -EFAULT; | |
2249 | ||
2f438366 | 2250 | ret = __ethtool_get_module_info(dev, &modinfo); |
41c3cb6d SH |
2251 | if (ret) |
2252 | return ret; | |
2253 | ||
2254 | if (copy_to_user(useraddr, &modinfo, sizeof(modinfo))) | |
2255 | return -EFAULT; | |
2256 | ||
2257 | return 0; | |
2258 | } | |
2259 | ||
2f438366 ES |
2260 | static int __ethtool_get_module_eeprom(struct net_device *dev, |
2261 | struct ethtool_eeprom *ee, u8 *data) | |
2262 | { | |
2263 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
2264 | struct phy_device *phydev = dev->phydev; | |
2265 | ||
e679c9c1 RK |
2266 | if (dev->sfp_bus) |
2267 | return sfp_get_module_eeprom(dev->sfp_bus, ee, data); | |
2268 | ||
2f438366 ES |
2269 | if (phydev && phydev->drv && phydev->drv->module_eeprom) |
2270 | return phydev->drv->module_eeprom(phydev, ee, data); | |
2271 | ||
2272 | if (ops->get_module_eeprom) | |
2273 | return ops->get_module_eeprom(dev, ee, data); | |
2274 | ||
2275 | return -EOPNOTSUPP; | |
2276 | } | |
2277 | ||
41c3cb6d SH |
2278 | static int ethtool_get_module_eeprom(struct net_device *dev, |
2279 | void __user *useraddr) | |
2280 | { | |
2281 | int ret; | |
2282 | struct ethtool_modinfo modinfo; | |
41c3cb6d | 2283 | |
2f438366 | 2284 | ret = __ethtool_get_module_info(dev, &modinfo); |
41c3cb6d SH |
2285 | if (ret) |
2286 | return ret; | |
2287 | ||
2f438366 ES |
2288 | return ethtool_get_any_eeprom(dev, useraddr, |
2289 | __ethtool_get_module_eeprom, | |
41c3cb6d SH |
2290 | modinfo.eeprom_len); |
2291 | } | |
2292 | ||
f0db9b07 GV |
2293 | static int ethtool_tunable_valid(const struct ethtool_tunable *tuna) |
2294 | { | |
2295 | switch (tuna->id) { | |
2296 | case ETHTOOL_RX_COPYBREAK: | |
1255a505 | 2297 | case ETHTOOL_TX_COPYBREAK: |
f0db9b07 GV |
2298 | if (tuna->len != sizeof(u32) || |
2299 | tuna->type_id != ETHTOOL_TUNABLE_U32) | |
2300 | return -EINVAL; | |
2301 | break; | |
e1577c1c IK |
2302 | case ETHTOOL_PFC_PREVENTION_TOUT: |
2303 | if (tuna->len != sizeof(u16) || | |
2304 | tuna->type_id != ETHTOOL_TUNABLE_U16) | |
2305 | return -EINVAL; | |
2306 | break; | |
f0db9b07 GV |
2307 | default: |
2308 | return -EINVAL; | |
2309 | } | |
2310 | ||
2311 | return 0; | |
2312 | } | |
2313 | ||
2314 | static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr) | |
2315 | { | |
2316 | int ret; | |
2317 | struct ethtool_tunable tuna; | |
2318 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
2319 | void *data; | |
2320 | ||
2321 | if (!ops->get_tunable) | |
2322 | return -EOPNOTSUPP; | |
2323 | if (copy_from_user(&tuna, useraddr, sizeof(tuna))) | |
2324 | return -EFAULT; | |
2325 | ret = ethtool_tunable_valid(&tuna); | |
2326 | if (ret) | |
2327 | return ret; | |
2328 | data = kmalloc(tuna.len, GFP_USER); | |
2329 | if (!data) | |
2330 | return -ENOMEM; | |
2331 | ret = ops->get_tunable(dev, &tuna, data); | |
2332 | if (ret) | |
2333 | goto out; | |
2334 | useraddr += sizeof(tuna); | |
2335 | ret = -EFAULT; | |
2336 | if (copy_to_user(useraddr, data, tuna.len)) | |
2337 | goto out; | |
2338 | ret = 0; | |
2339 | ||
2340 | out: | |
2341 | kfree(data); | |
2342 | return ret; | |
2343 | } | |
2344 | ||
2345 | static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr) | |
2346 | { | |
2347 | int ret; | |
2348 | struct ethtool_tunable tuna; | |
2349 | const struct ethtool_ops *ops = dev->ethtool_ops; | |
2350 | void *data; | |
2351 | ||
2352 | if (!ops->set_tunable) | |
2353 | return -EOPNOTSUPP; | |
2354 | if (copy_from_user(&tuna, useraddr, sizeof(tuna))) | |
2355 | return -EFAULT; | |
2356 | ret = ethtool_tunable_valid(&tuna); | |
2357 | if (ret) | |
2358 | return ret; | |
f0db9b07 | 2359 | useraddr += sizeof(tuna); |
30e7e3ec AV |
2360 | data = memdup_user(useraddr, tuna.len); |
2361 | if (IS_ERR(data)) | |
2362 | return PTR_ERR(data); | |
f0db9b07 GV |
2363 | ret = ops->set_tunable(dev, &tuna, data); |
2364 | ||
f0db9b07 GV |
2365 | kfree(data); |
2366 | return ret; | |
2367 | } | |
2368 | ||
421797b1 KL |
2369 | static int ethtool_get_per_queue_coalesce(struct net_device *dev, |
2370 | void __user *useraddr, | |
2371 | struct ethtool_per_queue_op *per_queue_opt) | |
2372 | { | |
2373 | u32 bit; | |
2374 | int ret; | |
2375 | DECLARE_BITMAP(queue_mask, MAX_NUM_QUEUE); | |
2376 | ||
2377 | if (!dev->ethtool_ops->get_per_queue_coalesce) | |
2378 | return -EOPNOTSUPP; | |
2379 | ||
2380 | useraddr += sizeof(*per_queue_opt); | |
2381 | ||
3aa56885 YN |
2382 | bitmap_from_arr32(queue_mask, per_queue_opt->queue_mask, |
2383 | MAX_NUM_QUEUE); | |
421797b1 KL |
2384 | |
2385 | for_each_set_bit(bit, queue_mask, MAX_NUM_QUEUE) { | |
2386 | struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; | |
2387 | ||
2388 | ret = dev->ethtool_ops->get_per_queue_coalesce(dev, bit, &coalesce); | |
2389 | if (ret != 0) | |
2390 | return ret; | |
2391 | if (copy_to_user(useraddr, &coalesce, sizeof(coalesce))) | |
2392 | return -EFAULT; | |
2393 | useraddr += sizeof(coalesce); | |
2394 | } | |
2395 | ||
2396 | return 0; | |
2397 | } | |
2398 | ||
f38d138a KL |
2399 | static int ethtool_set_per_queue_coalesce(struct net_device *dev, |
2400 | void __user *useraddr, | |
2401 | struct ethtool_per_queue_op *per_queue_opt) | |
2402 | { | |
2403 | u32 bit; | |
2404 | int i, ret = 0; | |
2405 | int n_queue; | |
2406 | struct ethtool_coalesce *backup = NULL, *tmp = NULL; | |
2407 | DECLARE_BITMAP(queue_mask, MAX_NUM_QUEUE); | |
2408 | ||
2409 | if ((!dev->ethtool_ops->set_per_queue_coalesce) || | |
2410 | (!dev->ethtool_ops->get_per_queue_coalesce)) | |
2411 | return -EOPNOTSUPP; | |
2412 | ||
2413 | useraddr += sizeof(*per_queue_opt); | |
2414 | ||
3aa56885 | 2415 | bitmap_from_arr32(queue_mask, per_queue_opt->queue_mask, MAX_NUM_QUEUE); |
f38d138a KL |
2416 | n_queue = bitmap_weight(queue_mask, MAX_NUM_QUEUE); |
2417 | tmp = backup = kmalloc_array(n_queue, sizeof(*backup), GFP_KERNEL); | |
2418 | if (!backup) | |
2419 | return -ENOMEM; | |
2420 | ||
2421 | for_each_set_bit(bit, queue_mask, MAX_NUM_QUEUE) { | |
2422 | struct ethtool_coalesce coalesce; | |
2423 | ||
2424 | ret = dev->ethtool_ops->get_per_queue_coalesce(dev, bit, tmp); | |
2425 | if (ret != 0) | |
2426 | goto roll_back; | |
2427 | ||
2428 | tmp++; | |
2429 | ||
2430 | if (copy_from_user(&coalesce, useraddr, sizeof(coalesce))) { | |
2431 | ret = -EFAULT; | |
2432 | goto roll_back; | |
2433 | } | |
2434 | ||
2435 | ret = dev->ethtool_ops->set_per_queue_coalesce(dev, bit, &coalesce); | |
2436 | if (ret != 0) | |
2437 | goto roll_back; | |
2438 | ||
2439 | useraddr += sizeof(coalesce); | |
2440 | } | |
2441 | ||
2442 | roll_back: | |
2443 | if (ret != 0) { | |
2444 | tmp = backup; | |
2445 | for_each_set_bit(i, queue_mask, bit) { | |
2446 | dev->ethtool_ops->set_per_queue_coalesce(dev, i, tmp); | |
2447 | tmp++; | |
2448 | } | |
2449 | } | |
2450 | kfree(backup); | |
2451 | ||
2452 | return ret; | |
2453 | } | |
2454 | ||
ac2c7ad0 KL |
2455 | static int ethtool_set_per_queue(struct net_device *dev, void __user *useraddr) |
2456 | { | |
2457 | struct ethtool_per_queue_op per_queue_opt; | |
2458 | ||
2459 | if (copy_from_user(&per_queue_opt, useraddr, sizeof(per_queue_opt))) | |
2460 | return -EFAULT; | |
2461 | ||
2462 | switch (per_queue_opt.sub_command) { | |
421797b1 KL |
2463 | case ETHTOOL_GCOALESCE: |
2464 | return ethtool_get_per_queue_coalesce(dev, useraddr, &per_queue_opt); | |
f38d138a KL |
2465 | case ETHTOOL_SCOALESCE: |
2466 | return ethtool_set_per_queue_coalesce(dev, useraddr, &per_queue_opt); | |
ac2c7ad0 KL |
2467 | default: |
2468 | return -EOPNOTSUPP; | |
2469 | }; | |
2470 | } | |
2471 | ||
968ad9da RL |
2472 | static int ethtool_phy_tunable_valid(const struct ethtool_tunable *tuna) |
2473 | { | |
2474 | switch (tuna->id) { | |
65feddd5 RL |
2475 | case ETHTOOL_PHY_DOWNSHIFT: |
2476 | if (tuna->len != sizeof(u8) || | |
2477 | tuna->type_id != ETHTOOL_TUNABLE_U8) | |
2478 | return -EINVAL; | |
2479 | break; | |
968ad9da RL |
2480 | default: |
2481 | return -EINVAL; | |
2482 | } | |
2483 | ||
2484 | return 0; | |
2485 | } | |
2486 | ||
2487 | static int get_phy_tunable(struct net_device *dev, void __user *useraddr) | |
2488 | { | |
2489 | int ret; | |
2490 | struct ethtool_tunable tuna; | |
2491 | struct phy_device *phydev = dev->phydev; | |
2492 | void *data; | |
2493 | ||
2494 | if (!(phydev && phydev->drv && phydev->drv->get_tunable)) | |
2495 | return -EOPNOTSUPP; | |
2496 | ||
2497 | if (copy_from_user(&tuna, useraddr, sizeof(tuna))) | |
2498 | return -EFAULT; | |
2499 | ret = ethtool_phy_tunable_valid(&tuna); | |
2500 | if (ret) | |
2501 | return ret; | |
2502 | data = kmalloc(tuna.len, GFP_USER); | |
2503 | if (!data) | |
2504 | return -ENOMEM; | |
4b65246b | 2505 | mutex_lock(&phydev->lock); |
968ad9da | 2506 | ret = phydev->drv->get_tunable(phydev, &tuna, data); |
4b65246b | 2507 | mutex_unlock(&phydev->lock); |
968ad9da RL |
2508 | if (ret) |
2509 | goto out; | |
2510 | useraddr += sizeof(tuna); | |
2511 | ret = -EFAULT; | |
2512 | if (copy_to_user(useraddr, data, tuna.len)) | |
2513 | goto out; | |
2514 | ret = 0; | |
2515 | ||
2516 | out: | |
2517 | kfree(data); | |
2518 | return ret; | |
2519 | } | |
2520 | ||
2521 | static int set_phy_tunable(struct net_device *dev, void __user *useraddr) | |
2522 | { | |
2523 | int ret; | |
2524 | struct ethtool_tunable tuna; | |
2525 | struct phy_device *phydev = dev->phydev; | |
2526 | void *data; | |
2527 | ||
2528 | if (!(phydev && phydev->drv && phydev->drv->set_tunable)) | |
2529 | return -EOPNOTSUPP; | |
2530 | if (copy_from_user(&tuna, useraddr, sizeof(tuna))) | |
2531 | return -EFAULT; | |
2532 | ret = ethtool_phy_tunable_valid(&tuna); | |
2533 | if (ret) | |
2534 | return ret; | |
968ad9da | 2535 | useraddr += sizeof(tuna); |
30e7e3ec AV |
2536 | data = memdup_user(useraddr, tuna.len); |
2537 | if (IS_ERR(data)) | |
2538 | return PTR_ERR(data); | |
4b65246b | 2539 | mutex_lock(&phydev->lock); |
968ad9da | 2540 | ret = phydev->drv->set_tunable(phydev, &tuna, data); |
4b65246b | 2541 | mutex_unlock(&phydev->lock); |
968ad9da | 2542 | |
968ad9da RL |
2543 | kfree(data); |
2544 | return ret; | |
2545 | } | |
2546 | ||
1a5f3da2 VSR |
2547 | static int ethtool_get_fecparam(struct net_device *dev, void __user *useraddr) |
2548 | { | |
2549 | struct ethtool_fecparam fecparam = { ETHTOOL_GFECPARAM }; | |
a6d50512 | 2550 | int rc; |
1a5f3da2 VSR |
2551 | |
2552 | if (!dev->ethtool_ops->get_fecparam) | |
2553 | return -EOPNOTSUPP; | |
2554 | ||
a6d50512 EC |
2555 | rc = dev->ethtool_ops->get_fecparam(dev, &fecparam); |
2556 | if (rc) | |
2557 | return rc; | |
1a5f3da2 VSR |
2558 | |
2559 | if (copy_to_user(useraddr, &fecparam, sizeof(fecparam))) | |
2560 | return -EFAULT; | |
2561 | return 0; | |
2562 | } | |
2563 | ||
2564 | static int ethtool_set_fecparam(struct net_device *dev, void __user *useraddr) | |
2565 | { | |
2566 | struct ethtool_fecparam fecparam; | |
2567 | ||
2568 | if (!dev->ethtool_ops->set_fecparam) | |
2569 | return -EOPNOTSUPP; | |
2570 | ||
2571 | if (copy_from_user(&fecparam, useraddr, sizeof(fecparam))) | |
2572 | return -EFAULT; | |
2573 | ||
2574 | return dev->ethtool_ops->set_fecparam(dev, &fecparam); | |
2575 | } | |
2576 | ||
600fed5e | 2577 | /* The main entry point in this file. Called from net/core/dev_ioctl.c */ |
1da177e4 | 2578 | |
881d966b | 2579 | int dev_ethtool(struct net *net, struct ifreq *ifr) |
1da177e4 | 2580 | { |
881d966b | 2581 | struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); |
1da177e4 | 2582 | void __user *useraddr = ifr->ifr_data; |
ac2c7ad0 | 2583 | u32 ethcmd, sub_cmd; |
1da177e4 | 2584 | int rc; |
b29d3145 | 2585 | netdev_features_t old_features; |
1da177e4 | 2586 | |
1da177e4 LT |
2587 | if (!dev || !netif_device_present(dev)) |
2588 | return -ENODEV; | |
2589 | ||
97f8aefb | 2590 | if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) |
1da177e4 LT |
2591 | return -EFAULT; |
2592 | ||
ac2c7ad0 KL |
2593 | if (ethcmd == ETHTOOL_PERQUEUE) { |
2594 | if (copy_from_user(&sub_cmd, useraddr + sizeof(ethcmd), sizeof(sub_cmd))) | |
2595 | return -EFAULT; | |
2596 | } else { | |
2597 | sub_cmd = ethcmd; | |
2598 | } | |
75f3123c | 2599 | /* Allow some commands to be done by anyone */ |
ac2c7ad0 | 2600 | switch (sub_cmd) { |
0fdc100b | 2601 | case ETHTOOL_GSET: |
75f3123c | 2602 | case ETHTOOL_GDRVINFO: |
75f3123c | 2603 | case ETHTOOL_GMSGLVL: |
2da45db2 | 2604 | case ETHTOOL_GLINK: |
75f3123c SH |
2605 | case ETHTOOL_GCOALESCE: |
2606 | case ETHTOOL_GRINGPARAM: | |
2607 | case ETHTOOL_GPAUSEPARAM: | |
2608 | case ETHTOOL_GRXCSUM: | |
2609 | case ETHTOOL_GTXCSUM: | |
2610 | case ETHTOOL_GSG: | |
f80400a2 | 2611 | case ETHTOOL_GSSET_INFO: |
75f3123c | 2612 | case ETHTOOL_GSTRINGS: |
2da45db2 | 2613 | case ETHTOOL_GSTATS: |
f3a40945 | 2614 | case ETHTOOL_GPHYSTATS: |
75f3123c SH |
2615 | case ETHTOOL_GTSO: |
2616 | case ETHTOOL_GPERMADDR: | |
75f3123c | 2617 | case ETHTOOL_GGSO: |
1cab819b | 2618 | case ETHTOOL_GGRO: |
339bf024 JG |
2619 | case ETHTOOL_GFLAGS: |
2620 | case ETHTOOL_GPFLAGS: | |
0853ad66 | 2621 | case ETHTOOL_GRXFH: |
59089d8d SB |
2622 | case ETHTOOL_GRXRINGS: |
2623 | case ETHTOOL_GRXCLSRLCNT: | |
2624 | case ETHTOOL_GRXCLSRULE: | |
2625 | case ETHTOOL_GRXCLSRLALL: | |
2da45db2 | 2626 | case ETHTOOL_GRXFHINDIR: |
3de0b592 | 2627 | case ETHTOOL_GRSSH: |
5455c699 | 2628 | case ETHTOOL_GFEATURES: |
2da45db2 | 2629 | case ETHTOOL_GCHANNELS: |
c8f3a8c3 | 2630 | case ETHTOOL_GET_TS_INFO: |
2da45db2 | 2631 | case ETHTOOL_GEEE: |
f0db9b07 | 2632 | case ETHTOOL_GTUNABLE: |
968ad9da | 2633 | case ETHTOOL_PHY_GTUNABLE: |
8006f6bf | 2634 | case ETHTOOL_GLINKSETTINGS: |
1a5f3da2 | 2635 | case ETHTOOL_GFECPARAM: |
75f3123c SH |
2636 | break; |
2637 | default: | |
5e1fccc0 | 2638 | if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) |
75f3123c SH |
2639 | return -EPERM; |
2640 | } | |
2641 | ||
97f8aefb | 2642 | if (dev->ethtool_ops->begin) { |
2643 | rc = dev->ethtool_ops->begin(dev); | |
2644 | if (rc < 0) | |
1da177e4 | 2645 | return rc; |
97f8aefb | 2646 | } |
d8a33ac4 SH |
2647 | old_features = dev->features; |
2648 | ||
1da177e4 LT |
2649 | switch (ethcmd) { |
2650 | case ETHTOOL_GSET: | |
2651 | rc = ethtool_get_settings(dev, useraddr); | |
2652 | break; | |
2653 | case ETHTOOL_SSET: | |
2654 | rc = ethtool_set_settings(dev, useraddr); | |
2655 | break; | |
2656 | case ETHTOOL_GDRVINFO: | |
2657 | rc = ethtool_get_drvinfo(dev, useraddr); | |
1da177e4 LT |
2658 | break; |
2659 | case ETHTOOL_GREGS: | |
2660 | rc = ethtool_get_regs(dev, useraddr); | |
2661 | break; | |
2662 | case ETHTOOL_GWOL: | |
2663 | rc = ethtool_get_wol(dev, useraddr); | |
2664 | break; | |
2665 | case ETHTOOL_SWOL: | |
2666 | rc = ethtool_set_wol(dev, useraddr); | |
2667 | break; | |
2668 | case ETHTOOL_GMSGLVL: | |
13c99b24 JG |
2669 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
2670 | dev->ethtool_ops->get_msglevel); | |
1da177e4 LT |
2671 | break; |
2672 | case ETHTOOL_SMSGLVL: | |
13c99b24 JG |
2673 | rc = ethtool_set_value_void(dev, useraddr, |
2674 | dev->ethtool_ops->set_msglevel); | |
1da177e4 | 2675 | break; |
80f12ecc YM |
2676 | case ETHTOOL_GEEE: |
2677 | rc = ethtool_get_eee(dev, useraddr); | |
2678 | break; | |
2679 | case ETHTOOL_SEEE: | |
2680 | rc = ethtool_set_eee(dev, useraddr); | |
2681 | break; | |
1da177e4 LT |
2682 | case ETHTOOL_NWAY_RST: |
2683 | rc = ethtool_nway_reset(dev); | |
2684 | break; | |
2685 | case ETHTOOL_GLINK: | |
e596e6e4 | 2686 | rc = ethtool_get_link(dev, useraddr); |
1da177e4 LT |
2687 | break; |
2688 | case ETHTOOL_GEEPROM: | |
2689 | rc = ethtool_get_eeprom(dev, useraddr); | |
2690 | break; | |
2691 | case ETHTOOL_SEEPROM: | |
2692 | rc = ethtool_set_eeprom(dev, useraddr); | |
2693 | break; | |
2694 | case ETHTOOL_GCOALESCE: | |
2695 | rc = ethtool_get_coalesce(dev, useraddr); | |
2696 | break; | |
2697 | case ETHTOOL_SCOALESCE: | |
2698 | rc = ethtool_set_coalesce(dev, useraddr); | |
2699 | break; | |
2700 | case ETHTOOL_GRINGPARAM: | |
2701 | rc = ethtool_get_ringparam(dev, useraddr); | |
2702 | break; | |
2703 | case ETHTOOL_SRINGPARAM: | |
2704 | rc = ethtool_set_ringparam(dev, useraddr); | |
2705 | break; | |
2706 | case ETHTOOL_GPAUSEPARAM: | |
2707 | rc = ethtool_get_pauseparam(dev, useraddr); | |
2708 | break; | |
2709 | case ETHTOOL_SPAUSEPARAM: | |
2710 | rc = ethtool_set_pauseparam(dev, useraddr); | |
2711 | break; | |
1da177e4 LT |
2712 | case ETHTOOL_TEST: |
2713 | rc = ethtool_self_test(dev, useraddr); | |
2714 | break; | |
2715 | case ETHTOOL_GSTRINGS: | |
2716 | rc = ethtool_get_strings(dev, useraddr); | |
2717 | break; | |
2718 | case ETHTOOL_PHYS_ID: | |
2719 | rc = ethtool_phys_id(dev, useraddr); | |
2720 | break; | |
2721 | case ETHTOOL_GSTATS: | |
2722 | rc = ethtool_get_stats(dev, useraddr); | |
2723 | break; | |
a6f9a705 JW |
2724 | case ETHTOOL_GPERMADDR: |
2725 | rc = ethtool_get_perm_addr(dev, useraddr); | |
2726 | break; | |
3ae7c0b2 | 2727 | case ETHTOOL_GFLAGS: |
13c99b24 | 2728 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
bc5787c6 | 2729 | __ethtool_get_flags); |
3ae7c0b2 JG |
2730 | break; |
2731 | case ETHTOOL_SFLAGS: | |
da8ac86c | 2732 | rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags); |
3ae7c0b2 | 2733 | break; |
339bf024 | 2734 | case ETHTOOL_GPFLAGS: |
13c99b24 JG |
2735 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
2736 | dev->ethtool_ops->get_priv_flags); | |
339bf024 JG |
2737 | break; |
2738 | case ETHTOOL_SPFLAGS: | |
13c99b24 JG |
2739 | rc = ethtool_set_value(dev, useraddr, |
2740 | dev->ethtool_ops->set_priv_flags); | |
339bf024 | 2741 | break; |
0853ad66 | 2742 | case ETHTOOL_GRXFH: |
59089d8d SB |
2743 | case ETHTOOL_GRXRINGS: |
2744 | case ETHTOOL_GRXCLSRLCNT: | |
2745 | case ETHTOOL_GRXCLSRULE: | |
2746 | case ETHTOOL_GRXCLSRLALL: | |
bf988435 | 2747 | rc = ethtool_get_rxnfc(dev, ethcmd, useraddr); |
0853ad66 SB |
2748 | break; |
2749 | case ETHTOOL_SRXFH: | |
59089d8d SB |
2750 | case ETHTOOL_SRXCLSRLDEL: |
2751 | case ETHTOOL_SRXCLSRLINS: | |
bf988435 | 2752 | rc = ethtool_set_rxnfc(dev, ethcmd, useraddr); |
0853ad66 | 2753 | break; |
05c6a8d7 AK |
2754 | case ETHTOOL_FLASHDEV: |
2755 | rc = ethtool_flash_device(dev, useraddr); | |
2756 | break; | |
d73d3a8c BH |
2757 | case ETHTOOL_RESET: |
2758 | rc = ethtool_reset(dev, useraddr); | |
2759 | break; | |
723b2f57 JG |
2760 | case ETHTOOL_GSSET_INFO: |
2761 | rc = ethtool_get_sset_info(dev, useraddr); | |
2762 | break; | |
a5b6ee29 BH |
2763 | case ETHTOOL_GRXFHINDIR: |
2764 | rc = ethtool_get_rxfh_indir(dev, useraddr); | |
2765 | break; | |
2766 | case ETHTOOL_SRXFHINDIR: | |
2767 | rc = ethtool_set_rxfh_indir(dev, useraddr); | |
2768 | break; | |
3de0b592 VD |
2769 | case ETHTOOL_GRSSH: |
2770 | rc = ethtool_get_rxfh(dev, useraddr); | |
2771 | break; | |
2772 | case ETHTOOL_SRSSH: | |
2773 | rc = ethtool_set_rxfh(dev, useraddr); | |
2774 | break; | |
5455c699 MM |
2775 | case ETHTOOL_GFEATURES: |
2776 | rc = ethtool_get_features(dev, useraddr); | |
2777 | break; | |
2778 | case ETHTOOL_SFEATURES: | |
2779 | rc = ethtool_set_features(dev, useraddr); | |
2780 | break; | |
0a417704 | 2781 | case ETHTOOL_GTXCSUM: |
e83d360d | 2782 | case ETHTOOL_GRXCSUM: |
0a417704 MM |
2783 | case ETHTOOL_GSG: |
2784 | case ETHTOOL_GTSO: | |
0a417704 MM |
2785 | case ETHTOOL_GGSO: |
2786 | case ETHTOOL_GGRO: | |
2787 | rc = ethtool_get_one_feature(dev, useraddr, ethcmd); | |
2788 | break; | |
2789 | case ETHTOOL_STXCSUM: | |
e83d360d | 2790 | case ETHTOOL_SRXCSUM: |
0a417704 MM |
2791 | case ETHTOOL_SSG: |
2792 | case ETHTOOL_STSO: | |
0a417704 MM |
2793 | case ETHTOOL_SGSO: |
2794 | case ETHTOOL_SGRO: | |
2795 | rc = ethtool_set_one_feature(dev, useraddr, ethcmd); | |
2796 | break; | |
8b5933c3 | 2797 | case ETHTOOL_GCHANNELS: |
2798 | rc = ethtool_get_channels(dev, useraddr); | |
2799 | break; | |
2800 | case ETHTOOL_SCHANNELS: | |
2801 | rc = ethtool_set_channels(dev, useraddr); | |
2802 | break; | |
29dd54b7 AC |
2803 | case ETHTOOL_SET_DUMP: |
2804 | rc = ethtool_set_dump(dev, useraddr); | |
2805 | break; | |
2806 | case ETHTOOL_GET_DUMP_FLAG: | |
2807 | rc = ethtool_get_dump_flag(dev, useraddr); | |
2808 | break; | |
2809 | case ETHTOOL_GET_DUMP_DATA: | |
2810 | rc = ethtool_get_dump_data(dev, useraddr); | |
2811 | break; | |
c8f3a8c3 RC |
2812 | case ETHTOOL_GET_TS_INFO: |
2813 | rc = ethtool_get_ts_info(dev, useraddr); | |
2814 | break; | |
41c3cb6d SH |
2815 | case ETHTOOL_GMODULEINFO: |
2816 | rc = ethtool_get_module_info(dev, useraddr); | |
2817 | break; | |
2818 | case ETHTOOL_GMODULEEEPROM: | |
2819 | rc = ethtool_get_module_eeprom(dev, useraddr); | |
2820 | break; | |
f0db9b07 GV |
2821 | case ETHTOOL_GTUNABLE: |
2822 | rc = ethtool_get_tunable(dev, useraddr); | |
2823 | break; | |
2824 | case ETHTOOL_STUNABLE: | |
2825 | rc = ethtool_set_tunable(dev, useraddr); | |
2826 | break; | |
f3a40945 AL |
2827 | case ETHTOOL_GPHYSTATS: |
2828 | rc = ethtool_get_phy_stats(dev, useraddr); | |
2829 | break; | |
ac2c7ad0 KL |
2830 | case ETHTOOL_PERQUEUE: |
2831 | rc = ethtool_set_per_queue(dev, useraddr); | |
2832 | break; | |
3f1ac7a7 DD |
2833 | case ETHTOOL_GLINKSETTINGS: |
2834 | rc = ethtool_get_link_ksettings(dev, useraddr); | |
2835 | break; | |
2836 | case ETHTOOL_SLINKSETTINGS: | |
2837 | rc = ethtool_set_link_ksettings(dev, useraddr); | |
2838 | break; | |
968ad9da RL |
2839 | case ETHTOOL_PHY_GTUNABLE: |
2840 | rc = get_phy_tunable(dev, useraddr); | |
2841 | break; | |
2842 | case ETHTOOL_PHY_STUNABLE: | |
2843 | rc = set_phy_tunable(dev, useraddr); | |
2844 | break; | |
1a5f3da2 VSR |
2845 | case ETHTOOL_GFECPARAM: |
2846 | rc = ethtool_get_fecparam(dev, useraddr); | |
2847 | break; | |
2848 | case ETHTOOL_SFECPARAM: | |
2849 | rc = ethtool_set_fecparam(dev, useraddr); | |
2850 | break; | |
1da177e4 | 2851 | default: |
61a44b9c | 2852 | rc = -EOPNOTSUPP; |
1da177e4 | 2853 | } |
4ec93edb | 2854 | |
e71a4783 | 2855 | if (dev->ethtool_ops->complete) |
1da177e4 | 2856 | dev->ethtool_ops->complete(dev); |
d8a33ac4 SH |
2857 | |
2858 | if (old_features != dev->features) | |
2859 | netdev_features_change(dev); | |
2860 | ||
1da177e4 | 2861 | return rc; |
1da177e4 | 2862 | } |