blob: b0f84f5ddda8456ff8f69442d453e112340a6bfa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Matthew Wilcox61a44b92007-07-31 14:00:02 -07006 * the information ethtool needs.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Matthew Wilcox61a44b92007-07-31 14:00:02 -07008 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
13
14#include <linux/module.h>
15#include <linux/types.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -080016#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/errno.h>
18#include <linux/ethtool.h>
19#include <linux/netdevice.h>
Richard Cochranc8f3a8c2012-04-03 22:59:17 +000020#include <linux/net_tstamp.h>
21#include <linux/phy.h>
Jeff Garzikd17792e2010-03-04 08:21:53 +000022#include <linux/bitops.h>
chavey97f8aef2010-04-07 21:54:42 -070023#include <linux/uaccess.h>
David S. Miller73da16c2010-09-21 16:12:11 -070024#include <linux/vmalloc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Ben Hutchings68f512f2011-04-02 00:35:15 +010026#include <linux/rtnetlink.h>
27#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090029/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 * Some useful ethtool_ops methods that're device independent.
31 * If we find that all drivers want to do the same thing here,
32 * we can turn these into dev_() function calls.
33 */
34
35u32 ethtool_op_get_link(struct net_device *dev)
36{
37 return netif_carrier_ok(dev) ? 1 : 0;
38}
chavey97f8aef2010-04-07 21:54:42 -070039EXPORT_SYMBOL(ethtool_op_get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Richard Cochran02eacbd2012-04-03 22:59:22 +000041int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
42{
43 info->so_timestamping =
44 SOF_TIMESTAMPING_TX_SOFTWARE |
45 SOF_TIMESTAMPING_RX_SOFTWARE |
46 SOF_TIMESTAMPING_SOFTWARE;
47 info->phc_index = -1;
48 return 0;
49}
50EXPORT_SYMBOL(ethtool_op_get_ts_info);
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052/* Handlers for each ethtool command */
53
Michał Mirosław475414f2011-11-15 15:29:55 +000054#define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32)
Michał Mirosław5455c692011-02-15 16:59:17 +000055
Michał Mirosław9d921542011-11-15 15:29:55 +000056static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = {
57 [NETIF_F_SG_BIT] = "tx-scatter-gather",
58 [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4",
Michał Mirosław9d921542011-11-15 15:29:55 +000059 [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic",
60 [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6",
61 [NETIF_F_HIGHDMA_BIT] = "highdma",
62 [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist",
Fernando Luis Vazquez Cao788dfca2013-06-17 11:28:03 +090063 [NETIF_F_HW_VLAN_CTAG_TX_BIT] = "tx-vlan-hw-insert",
Michał Mirosław9d921542011-11-15 15:29:55 +000064
Fernando Luis Vazquez Cao788dfca2013-06-17 11:28:03 +090065 [NETIF_F_HW_VLAN_CTAG_RX_BIT] = "rx-vlan-hw-parse",
66 [NETIF_F_HW_VLAN_CTAG_FILTER_BIT] = "rx-vlan-filter",
David S. Miller2d6577f2013-04-19 16:08:23 -040067 [NETIF_F_HW_VLAN_STAG_TX_BIT] = "tx-vlan-stag-hw-insert",
68 [NETIF_F_HW_VLAN_STAG_RX_BIT] = "rx-vlan-stag-hw-parse",
69 [NETIF_F_HW_VLAN_STAG_FILTER_BIT] = "rx-vlan-stag-filter",
Michał Mirosław9d921542011-11-15 15:29:55 +000070 [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged",
71 [NETIF_F_GSO_BIT] = "tx-generic-segmentation",
72 [NETIF_F_LLTX_BIT] = "tx-lockless",
73 [NETIF_F_NETNS_LOCAL_BIT] = "netns-local",
74 [NETIF_F_GRO_BIT] = "rx-gro",
75 [NETIF_F_LRO_BIT] = "rx-lro",
76
77 [NETIF_F_TSO_BIT] = "tx-tcp-segmentation",
78 [NETIF_F_UFO_BIT] = "tx-udp-fragmentation",
79 [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust",
80 [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation",
81 [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation",
82 [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation",
Pravin B Shelar68c33162013-02-14 14:02:41 +000083 [NETIF_F_GSO_GRE_BIT] = "tx-gre-segmentation",
Eric Dumazetcb32f512013-10-19 11:42:57 -070084 [NETIF_F_GSO_IPIP_BIT] = "tx-ipip-segmentation",
Eric Dumazet61c1db72013-10-20 20:47:30 -070085 [NETIF_F_GSO_SIT_BIT] = "tx-sit-segmentation",
Pravin B Shelar73136262013-03-07 13:21:51 +000086 [NETIF_F_GSO_UDP_TUNNEL_BIT] = "tx-udp_tnl-segmentation",
Michał Mirosław9d921542011-11-15 15:29:55 +000087
88 [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc",
89 [NETIF_F_SCTP_CSUM_BIT] = "tx-checksum-sctp",
90 [NETIF_F_FCOE_MTU_BIT] = "fcoe-mtu",
91 [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter",
92 [NETIF_F_RXHASH_BIT] = "rx-hashing",
93 [NETIF_F_RXCSUM_BIT] = "rx-checksum",
94 [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy",
95 [NETIF_F_LOOPBACK_BIT] = "loopback",
Ben Greear36eabda32012-02-11 15:39:14 +000096 [NETIF_F_RXFCS_BIT] = "rx-fcs",
Ben Greear5e0c03c2012-02-11 15:39:45 +000097 [NETIF_F_RXALL_BIT] = "rx-all",
John Fastabenda6cc0cf2013-11-06 09:54:46 -080098 [NETIF_F_HW_L2FW_DOFFLOAD_BIT] = "l2-fwd-offload",
Jiri Pirkod0290212014-04-02 23:09:31 +020099 [NETIF_F_BUSY_POLL_BIT] = "busy-poll",
Michał Mirosław9d921542011-11-15 15:29:55 +0000100};
101
Michał Mirosław5455c692011-02-15 16:59:17 +0000102static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
103{
104 struct ethtool_gfeatures cmd = {
105 .cmd = ETHTOOL_GFEATURES,
106 .size = ETHTOOL_DEV_FEATURE_WORDS,
107 };
Michał Mirosław475414f2011-11-15 15:29:55 +0000108 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
Michał Mirosław5455c692011-02-15 16:59:17 +0000109 u32 __user *sizeaddr;
110 u32 copy_size;
Michał Mirosław475414f2011-11-15 15:29:55 +0000111 int i;
112
113 /* in case feature bits run out again */
Michał Mirosław09da71b2011-11-16 14:32:03 +0000114 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
Michał Mirosław475414f2011-11-15 15:29:55 +0000115
116 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
Michał Mirosław09da71b2011-11-16 14:32:03 +0000117 features[i].available = (u32)(dev->hw_features >> (32 * i));
118 features[i].requested = (u32)(dev->wanted_features >> (32 * i));
119 features[i].active = (u32)(dev->features >> (32 * i));
120 features[i].never_changed =
121 (u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
Michał Mirosław475414f2011-11-15 15:29:55 +0000122 }
Michał Mirosław5455c692011-02-15 16:59:17 +0000123
124 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
125 if (get_user(copy_size, sizeaddr))
126 return -EFAULT;
127
128 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
129 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
130
131 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
132 return -EFAULT;
133 useraddr += sizeof(cmd);
134 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
135 return -EFAULT;
136
137 return 0;
138}
139
140static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
141{
142 struct ethtool_sfeatures cmd;
143 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
Michał Mirosław475414f2011-11-15 15:29:55 +0000144 netdev_features_t wanted = 0, valid = 0;
145 int i, ret = 0;
Michał Mirosław5455c692011-02-15 16:59:17 +0000146
147 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
148 return -EFAULT;
149 useraddr += sizeof(cmd);
150
151 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
152 return -EINVAL;
153
154 if (copy_from_user(features, useraddr, sizeof(features)))
155 return -EFAULT;
156
Michał Mirosław475414f2011-11-15 15:29:55 +0000157 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
Michał Mirosław09da71b2011-11-16 14:32:03 +0000158 valid |= (netdev_features_t)features[i].valid << (32 * i);
159 wanted |= (netdev_features_t)features[i].requested << (32 * i);
Michał Mirosław475414f2011-11-15 15:29:55 +0000160 }
161
162 if (valid & ~NETIF_F_ETHTOOL_BITS)
Michał Mirosław5455c692011-02-15 16:59:17 +0000163 return -EINVAL;
164
Michał Mirosław475414f2011-11-15 15:29:55 +0000165 if (valid & ~dev->hw_features) {
166 valid &= dev->hw_features;
Michał Mirosław5455c692011-02-15 16:59:17 +0000167 ret |= ETHTOOL_F_UNSUPPORTED;
168 }
169
Michał Mirosław475414f2011-11-15 15:29:55 +0000170 dev->wanted_features &= ~valid;
171 dev->wanted_features |= wanted & valid;
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700172 __netdev_update_features(dev);
Michał Mirosław5455c692011-02-15 16:59:17 +0000173
Michał Mirosław475414f2011-11-15 15:29:55 +0000174 if ((dev->wanted_features ^ dev->features) & valid)
Michał Mirosław5455c692011-02-15 16:59:17 +0000175 ret |= ETHTOOL_F_WISH;
176
177 return ret;
178}
179
Michał Mirosław340ae162011-02-15 16:59:16 +0000180static int __ethtool_get_sset_count(struct net_device *dev, int sset)
181{
182 const struct ethtool_ops *ops = dev->ethtool_ops;
183
Michał Mirosław5455c692011-02-15 16:59:17 +0000184 if (sset == ETH_SS_FEATURES)
185 return ARRAY_SIZE(netdev_features_strings);
186
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000187 if (ops->get_sset_count && ops->get_strings)
Michał Mirosław340ae162011-02-15 16:59:16 +0000188 return ops->get_sset_count(dev, sset);
189 else
190 return -EOPNOTSUPP;
191}
192
193static void __ethtool_get_strings(struct net_device *dev,
194 u32 stringset, u8 *data)
195{
196 const struct ethtool_ops *ops = dev->ethtool_ops;
197
Michał Mirosław5455c692011-02-15 16:59:17 +0000198 if (stringset == ETH_SS_FEATURES)
199 memcpy(data, netdev_features_strings,
200 sizeof(netdev_features_strings));
201 else
202 /* ops->get_strings is valid because checked earlier */
203 ops->get_strings(dev, stringset, data);
Michał Mirosław340ae162011-02-15 16:59:16 +0000204}
205
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000206static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
Michał Mirosław0a417702011-02-15 16:59:17 +0000207{
208 /* feature masks of legacy discrete ethtool ops */
209
210 switch (eth_cmd) {
211 case ETHTOOL_GTXCSUM:
212 case ETHTOOL_STXCSUM:
213 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
Michał Mirosławe83d3602011-02-15 16:59:18 +0000214 case ETHTOOL_GRXCSUM:
215 case ETHTOOL_SRXCSUM:
216 return NETIF_F_RXCSUM;
Michał Mirosław0a417702011-02-15 16:59:17 +0000217 case ETHTOOL_GSG:
218 case ETHTOOL_SSG:
219 return NETIF_F_SG;
220 case ETHTOOL_GTSO:
221 case ETHTOOL_STSO:
222 return NETIF_F_ALL_TSO;
223 case ETHTOOL_GUFO:
224 case ETHTOOL_SUFO:
225 return NETIF_F_UFO;
226 case ETHTOOL_GGSO:
227 case ETHTOOL_SGSO:
228 return NETIF_F_GSO;
229 case ETHTOOL_GGRO:
230 case ETHTOOL_SGRO:
231 return NETIF_F_GRO;
232 default:
233 BUG();
234 }
235}
236
Michał Mirosław0a417702011-02-15 16:59:17 +0000237static int ethtool_get_one_feature(struct net_device *dev,
238 char __user *useraddr, u32 ethcmd)
239{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000240 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
Michał Mirosław0a417702011-02-15 16:59:17 +0000241 struct ethtool_value edata = {
242 .cmd = ethcmd,
Michał Mirosław86794882011-02-15 16:59:17 +0000243 .data = !!(dev->features & mask),
Michał Mirosław0a417702011-02-15 16:59:17 +0000244 };
Michał Mirosław0a417702011-02-15 16:59:17 +0000245
Michał Mirosław0a417702011-02-15 16:59:17 +0000246 if (copy_to_user(useraddr, &edata, sizeof(edata)))
247 return -EFAULT;
248 return 0;
249}
250
Michał Mirosław0a417702011-02-15 16:59:17 +0000251static int ethtool_set_one_feature(struct net_device *dev,
252 void __user *useraddr, u32 ethcmd)
253{
254 struct ethtool_value edata;
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000255 netdev_features_t mask;
Michał Mirosław0a417702011-02-15 16:59:17 +0000256
257 if (copy_from_user(&edata, useraddr, sizeof(edata)))
258 return -EFAULT;
259
Michał Mirosław86794882011-02-15 16:59:17 +0000260 mask = ethtool_get_feature_mask(ethcmd);
261 mask &= dev->hw_features;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000262 if (!mask)
Michał Mirosław0a417702011-02-15 16:59:17 +0000263 return -EOPNOTSUPP;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000264
265 if (edata.data)
266 dev->wanted_features |= mask;
267 else
268 dev->wanted_features &= ~mask;
269
270 __netdev_update_features(dev);
271
272 return 0;
Michał Mirosław0a417702011-02-15 16:59:17 +0000273}
274
Michał Mirosław02b3a552011-11-15 15:29:55 +0000275#define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
276 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
Patrick McHardyf6469682013-04-19 02:04:27 +0000277#define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_CTAG_RX | \
278 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_NTUPLE | \
279 NETIF_F_RXHASH)
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000280
281static u32 __ethtool_get_flags(struct net_device *dev)
282{
Michał Mirosław02b3a552011-11-15 15:29:55 +0000283 u32 flags = 0;
284
Dragos Foianu8a731252013-07-13 14:43:00 +0100285 if (dev->features & NETIF_F_LRO)
286 flags |= ETH_FLAG_LRO;
287 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
288 flags |= ETH_FLAG_RXVLAN;
289 if (dev->features & NETIF_F_HW_VLAN_CTAG_TX)
290 flags |= ETH_FLAG_TXVLAN;
291 if (dev->features & NETIF_F_NTUPLE)
292 flags |= ETH_FLAG_NTUPLE;
293 if (dev->features & NETIF_F_RXHASH)
294 flags |= ETH_FLAG_RXHASH;
Michał Mirosław02b3a552011-11-15 15:29:55 +0000295
296 return flags;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000297}
298
299static int __ethtool_set_flags(struct net_device *dev, u32 data)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000300{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000301 netdev_features_t features = 0, changed;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000302
Michał Mirosław02b3a552011-11-15 15:29:55 +0000303 if (data & ~ETH_ALL_FLAGS)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000304 return -EINVAL;
305
Dragos Foianu8a731252013-07-13 14:43:00 +0100306 if (data & ETH_FLAG_LRO)
307 features |= NETIF_F_LRO;
308 if (data & ETH_FLAG_RXVLAN)
309 features |= NETIF_F_HW_VLAN_CTAG_RX;
310 if (data & ETH_FLAG_TXVLAN)
311 features |= NETIF_F_HW_VLAN_CTAG_TX;
312 if (data & ETH_FLAG_NTUPLE)
313 features |= NETIF_F_NTUPLE;
314 if (data & ETH_FLAG_RXHASH)
315 features |= NETIF_F_RXHASH;
Michał Mirosław02b3a552011-11-15 15:29:55 +0000316
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000317 /* allow changing only bits set in hw_features */
Michał Mirosław02b3a552011-11-15 15:29:55 +0000318 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000319 if (changed & ~dev->hw_features)
320 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
321
322 dev->wanted_features =
Michał Mirosław02b3a552011-11-15 15:29:55 +0000323 (dev->wanted_features & ~changed) | (features & changed);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000324
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700325 __netdev_update_features(dev);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000326
327 return 0;
328}
329
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000330int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000332 ASSERT_RTNL();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000334 if (!dev->ethtool_ops->get_settings)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 return -EOPNOTSUPP;
336
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000337 memset(cmd, 0, sizeof(struct ethtool_cmd));
338 cmd->cmd = ETHTOOL_GSET;
339 return dev->ethtool_ops->get_settings(dev, cmd);
340}
341EXPORT_SYMBOL(__ethtool_get_settings);
342
343static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
344{
345 int err;
346 struct ethtool_cmd cmd;
347
348 err = __ethtool_get_settings(dev, &cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 if (err < 0)
350 return err;
351
352 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
353 return -EFAULT;
354 return 0;
355}
356
357static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
358{
359 struct ethtool_cmd cmd;
360
361 if (!dev->ethtool_ops->set_settings)
362 return -EOPNOTSUPP;
363
364 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
365 return -EFAULT;
366
367 return dev->ethtool_ops->set_settings(dev, &cmd);
368}
369
chavey97f8aef2010-04-07 21:54:42 -0700370static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
371 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372{
373 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700374 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 memset(&info, 0, sizeof(info));
377 info.cmd = ETHTOOL_GDRVINFO;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000378 if (ops->get_drvinfo) {
Ben Hutchings01414802010-08-17 02:31:15 -0700379 ops->get_drvinfo(dev, &info);
380 } else if (dev->dev.parent && dev->dev.parent->driver) {
381 strlcpy(info.bus_info, dev_name(dev->dev.parent),
382 sizeof(info.bus_info));
383 strlcpy(info.driver, dev->dev.parent->driver->name,
384 sizeof(info.driver));
385 } else {
386 return -EOPNOTSUPP;
387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Jeff Garzik723b2f52010-03-03 22:51:50 +0000389 /*
390 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000391 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000392 */
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000393 if (ops->get_sset_count) {
Jeff Garzikff03d492007-08-15 16:01:08 -0700394 int rc;
395
396 rc = ops->get_sset_count(dev, ETH_SS_TEST);
397 if (rc >= 0)
398 info.testinfo_len = rc;
399 rc = ops->get_sset_count(dev, ETH_SS_STATS);
400 if (rc >= 0)
401 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700402 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
403 if (rc >= 0)
404 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700405 }
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000406 if (ops->get_regs_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 info.regdump_len = ops->get_regs_len(dev);
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000408 if (ops->get_eeprom_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 info.eedump_len = ops->get_eeprom_len(dev);
410
411 if (copy_to_user(useraddr, &info, sizeof(info)))
412 return -EFAULT;
413 return 0;
414}
415
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800416static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
chavey97f8aef2010-04-07 21:54:42 -0700417 void __user *useraddr)
Jeff Garzik723b2f52010-03-03 22:51:50 +0000418{
419 struct ethtool_sset_info info;
Jeff Garzik723b2f52010-03-03 22:51:50 +0000420 u64 sset_mask;
421 int i, idx = 0, n_bits = 0, ret, rc;
422 u32 *info_buf = NULL;
423
Jeff Garzik723b2f52010-03-03 22:51:50 +0000424 if (copy_from_user(&info, useraddr, sizeof(info)))
425 return -EFAULT;
426
427 /* store copy of mask, because we zero struct later on */
428 sset_mask = info.sset_mask;
429 if (!sset_mask)
430 return 0;
431
432 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000433 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000434
435 memset(&info, 0, sizeof(info));
436 info.cmd = ETHTOOL_GSSET_INFO;
437
438 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
439 if (!info_buf)
440 return -ENOMEM;
441
442 /*
443 * fill return buffer based on input bitmask and successful
444 * get_sset_count return
445 */
446 for (i = 0; i < 64; i++) {
447 if (!(sset_mask & (1ULL << i)))
448 continue;
449
Michał Mirosław340ae162011-02-15 16:59:16 +0000450 rc = __ethtool_get_sset_count(dev, i);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000451 if (rc >= 0) {
452 info.sset_mask |= (1ULL << i);
453 info_buf[idx++] = rc;
454 }
455 }
456
457 ret = -EFAULT;
458 if (copy_to_user(useraddr, &info, sizeof(info)))
459 goto out;
460
461 useraddr += offsetof(struct ethtool_sset_info, data);
462 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
463 goto out;
464
465 ret = 0;
466
467out:
468 kfree(info_buf);
469 return ret;
470}
471
chavey97f8aef2010-04-07 21:54:42 -0700472static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000473 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700474{
Ben Hutchingsbf988432010-06-28 08:45:58 +0000475 struct ethtool_rxnfc info;
476 size_t info_size = sizeof(info);
Ben Hutchings55664f32012-01-03 12:04:51 +0000477 int rc;
Santwona Behera0853ad62008-07-02 03:47:41 -0700478
Santwona Behera59089d82009-02-20 00:58:13 -0800479 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700480 return -EOPNOTSUPP;
481
Ben Hutchingsbf988432010-06-28 08:45:58 +0000482 /* struct ethtool_rxnfc was originally defined for
483 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
484 * members. User-space might still be using that
485 * definition. */
486 if (cmd == ETHTOOL_SRXFH)
487 info_size = (offsetof(struct ethtool_rxnfc, data) +
488 sizeof(info.data));
489
490 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700491 return -EFAULT;
492
Ben Hutchings55664f32012-01-03 12:04:51 +0000493 rc = dev->ethtool_ops->set_rxnfc(dev, &info);
494 if (rc)
495 return rc;
496
497 if (cmd == ETHTOOL_SRXCLSRLINS &&
498 copy_to_user(useraddr, &info, info_size))
499 return -EFAULT;
500
501 return 0;
Santwona Behera0853ad62008-07-02 03:47:41 -0700502}
503
chavey97f8aef2010-04-07 21:54:42 -0700504static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000505 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700506{
507 struct ethtool_rxnfc info;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000508 size_t info_size = sizeof(info);
Santwona Behera59089d82009-02-20 00:58:13 -0800509 const struct ethtool_ops *ops = dev->ethtool_ops;
510 int ret;
511 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700512
Santwona Behera59089d82009-02-20 00:58:13 -0800513 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700514 return -EOPNOTSUPP;
515
Ben Hutchingsbf988432010-06-28 08:45:58 +0000516 /* struct ethtool_rxnfc was originally defined for
517 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
518 * members. User-space might still be using that
519 * definition. */
520 if (cmd == ETHTOOL_GRXFH)
521 info_size = (offsetof(struct ethtool_rxnfc, data) +
522 sizeof(info.data));
523
524 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700525 return -EFAULT;
526
Santwona Behera59089d82009-02-20 00:58:13 -0800527 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
528 if (info.rule_cnt > 0) {
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000529 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
Kees Cookae6df5f2010-10-07 10:03:48 +0000530 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000531 GFP_USER);
Santwona Behera59089d82009-02-20 00:58:13 -0800532 if (!rule_buf)
533 return -ENOMEM;
534 }
535 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700536
Santwona Behera59089d82009-02-20 00:58:13 -0800537 ret = ops->get_rxnfc(dev, &info, rule_buf);
538 if (ret < 0)
539 goto err_out;
540
541 ret = -EFAULT;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000542 if (copy_to_user(useraddr, &info, info_size))
Santwona Behera59089d82009-02-20 00:58:13 -0800543 goto err_out;
544
545 if (rule_buf) {
546 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
547 if (copy_to_user(useraddr, rule_buf,
548 info.rule_cnt * sizeof(u32)))
549 goto err_out;
550 }
551 ret = 0;
552
553err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700554 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800555
556 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700557}
558
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530559static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr,
560 struct ethtool_rxnfc *rx_rings,
561 u32 size)
562{
Ben Hutchingsfb95cd82014-05-15 00:46:45 +0100563 int i;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530564
565 if (copy_from_user(indir, useraddr, size * sizeof(indir[0])))
Ben Hutchingsfb95cd82014-05-15 00:46:45 +0100566 return -EFAULT;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530567
568 /* Validate ring indices */
Ben Hutchingsfb95cd82014-05-15 00:46:45 +0100569 for (i = 0; i < size; i++)
570 if (indir[i] >= rx_rings->data)
571 return -EINVAL;
572
573 return 0;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530574}
575
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000576static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
577 void __user *useraddr)
578{
Ben Hutchings7850f632011-12-15 13:55:01 +0000579 u32 user_size, dev_size;
580 u32 *indir;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000581 int ret;
582
Ben Hutchings7850f632011-12-15 13:55:01 +0000583 if (!dev->ethtool_ops->get_rxfh_indir_size ||
Ben Hutchingsfe62d002014-05-15 01:25:27 +0100584 !dev->ethtool_ops->get_rxfh)
Ben Hutchings7850f632011-12-15 13:55:01 +0000585 return -EOPNOTSUPP;
586 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
587 if (dev_size == 0)
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000588 return -EOPNOTSUPP;
589
Ben Hutchings7850f632011-12-15 13:55:01 +0000590 if (copy_from_user(&user_size,
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000591 useraddr + offsetof(struct ethtool_rxfh_indir, size),
Ben Hutchings7850f632011-12-15 13:55:01 +0000592 sizeof(user_size)))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000593 return -EFAULT;
594
Ben Hutchings7850f632011-12-15 13:55:01 +0000595 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
596 &dev_size, sizeof(dev_size)))
597 return -EFAULT;
598
599 /* If the user buffer size is 0, this is just a query for the
600 * device table size. Otherwise, if it's smaller than the
601 * device table size it's an error.
602 */
603 if (user_size < dev_size)
604 return user_size == 0 ? 0 : -EINVAL;
605
606 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000607 if (!indir)
608 return -ENOMEM;
609
Ben Hutchingsfe62d002014-05-15 01:25:27 +0100610 ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000611 if (ret)
612 goto out;
613
Ben Hutchings7850f632011-12-15 13:55:01 +0000614 if (copy_to_user(useraddr +
615 offsetof(struct ethtool_rxfh_indir, ring_index[0]),
616 indir, dev_size * sizeof(indir[0])))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000617 ret = -EFAULT;
618
619out:
620 kfree(indir);
621 return ret;
622}
623
624static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
625 void __user *useraddr)
626{
Ben Hutchings7850f632011-12-15 13:55:01 +0000627 struct ethtool_rxnfc rx_rings;
628 u32 user_size, dev_size, i;
629 u32 *indir;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000630 const struct ethtool_ops *ops = dev->ethtool_ops;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000631 int ret;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530632 u32 ringidx_offset = offsetof(struct ethtool_rxfh_indir, ring_index[0]);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000633
Ben Hutchingsfe62d002014-05-15 01:25:27 +0100634 if (!ops->get_rxfh_indir_size || !ops->set_rxfh ||
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000635 !ops->get_rxnfc)
Ben Hutchings7850f632011-12-15 13:55:01 +0000636 return -EOPNOTSUPP;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000637
638 dev_size = ops->get_rxfh_indir_size(dev);
Ben Hutchings7850f632011-12-15 13:55:01 +0000639 if (dev_size == 0)
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000640 return -EOPNOTSUPP;
641
Ben Hutchings7850f632011-12-15 13:55:01 +0000642 if (copy_from_user(&user_size,
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000643 useraddr + offsetof(struct ethtool_rxfh_indir, size),
Ben Hutchings7850f632011-12-15 13:55:01 +0000644 sizeof(user_size)))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000645 return -EFAULT;
646
Ben Hutchings278bc422011-12-15 13:56:49 +0000647 if (user_size != 0 && user_size != dev_size)
Ben Hutchings7850f632011-12-15 13:55:01 +0000648 return -EINVAL;
649
650 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000651 if (!indir)
652 return -ENOMEM;
653
Ben Hutchings7850f632011-12-15 13:55:01 +0000654 rx_rings.cmd = ETHTOOL_GRXRINGS;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000655 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
Ben Hutchings7850f632011-12-15 13:55:01 +0000656 if (ret)
657 goto out;
Ben Hutchings278bc422011-12-15 13:56:49 +0000658
659 if (user_size == 0) {
660 for (i = 0; i < dev_size; i++)
661 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
662 } else {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530663 ret = ethtool_copy_validate_indir(indir,
664 useraddr + ringidx_offset,
665 &rx_rings,
666 dev_size);
667 if (ret)
Ben Hutchings7850f632011-12-15 13:55:01 +0000668 goto out;
Ben Hutchings7850f632011-12-15 13:55:01 +0000669 }
670
Ben Hutchingsfe62d002014-05-15 01:25:27 +0100671 ret = ops->set_rxfh(dev, indir, NULL);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000672
673out:
674 kfree(indir);
675 return ret;
676}
677
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530678static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev,
679 void __user *useraddr)
680{
681 int ret;
682 const struct ethtool_ops *ops = dev->ethtool_ops;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100683 u32 user_indir_size, user_key_size;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530684 u32 dev_indir_size = 0, dev_key_size = 0;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100685 struct ethtool_rxfh rxfh;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530686 u32 total_size;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100687 u32 indir_bytes;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530688 u32 *indir = NULL;
689 u8 *hkey = NULL;
690 u8 *rss_config;
691
692 if (!(dev->ethtool_ops->get_rxfh_indir_size ||
693 dev->ethtool_ops->get_rxfh_key_size) ||
694 !dev->ethtool_ops->get_rxfh)
695 return -EOPNOTSUPP;
696
697 if (ops->get_rxfh_indir_size)
698 dev_indir_size = ops->get_rxfh_indir_size(dev);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530699 if (ops->get_rxfh_key_size)
700 dev_key_size = ops->get_rxfh_key_size(dev);
701
702 if ((dev_key_size + dev_indir_size) == 0)
703 return -EOPNOTSUPP;
704
Ben Hutchingsf062a382014-05-15 16:28:07 +0100705 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530706 return -EFAULT;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100707 user_indir_size = rxfh.indir_size;
708 user_key_size = rxfh.key_size;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530709
Ben Hutchingsf062a382014-05-15 16:28:07 +0100710 /* Check that reserved fields are 0 for now */
711 if (rxfh.rss_context || rxfh.rsvd[0] || rxfh.rsvd[1])
712 return -EINVAL;
713
714 rxfh.indir_size = dev_indir_size;
715 rxfh.key_size = dev_key_size;
716 if (copy_to_user(useraddr, &rxfh, sizeof(rxfh)))
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530717 return -EFAULT;
718
719 /* If the user buffer size is 0, this is just a query for the
720 * device table size and key size. Otherwise, if the User size is
721 * not equal to device table size or key size it's an error.
722 */
723 if (!user_indir_size && !user_key_size)
724 return 0;
725
726 if ((user_indir_size && (user_indir_size != dev_indir_size)) ||
727 (user_key_size && (user_key_size != dev_key_size)))
728 return -EINVAL;
729
730 indir_bytes = user_indir_size * sizeof(indir[0]);
731 total_size = indir_bytes + user_key_size;
732 rss_config = kzalloc(total_size, GFP_USER);
733 if (!rss_config)
734 return -ENOMEM;
735
736 if (user_indir_size)
737 indir = (u32 *)rss_config;
738
739 if (user_key_size)
740 hkey = rss_config + indir_bytes;
741
742 ret = dev->ethtool_ops->get_rxfh(dev, indir, hkey);
743 if (!ret) {
744 if (copy_to_user(useraddr +
745 offsetof(struct ethtool_rxfh, rss_config[0]),
746 rss_config, total_size))
747 ret = -EFAULT;
748 }
749
750 kfree(rss_config);
751
752 return ret;
753}
754
755static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
756 void __user *useraddr)
757{
758 int ret;
759 const struct ethtool_ops *ops = dev->ethtool_ops;
760 struct ethtool_rxnfc rx_rings;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100761 struct ethtool_rxfh rxfh;
762 u32 dev_indir_size = 0, dev_key_size = 0, i;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530763 u32 *indir = NULL, indir_bytes = 0;
764 u8 *hkey = NULL;
765 u8 *rss_config;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530766 u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]);
767
768 if (!(ops->get_rxfh_indir_size || ops->get_rxfh_key_size) ||
769 !ops->get_rxnfc || !ops->set_rxfh)
770 return -EOPNOTSUPP;
771
772 if (ops->get_rxfh_indir_size)
773 dev_indir_size = ops->get_rxfh_indir_size(dev);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530774 if (ops->get_rxfh_key_size)
775 dev_key_size = dev->ethtool_ops->get_rxfh_key_size(dev);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530776 if ((dev_key_size + dev_indir_size) == 0)
777 return -EOPNOTSUPP;
778
Ben Hutchingsf062a382014-05-15 16:28:07 +0100779 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530780 return -EFAULT;
781
Ben Hutchingsf062a382014-05-15 16:28:07 +0100782 /* Check that reserved fields are 0 for now */
783 if (rxfh.rss_context || rxfh.rsvd[0] || rxfh.rsvd[1])
784 return -EINVAL;
785
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530786 /* If either indir or hash key is valid, proceed further.
Ben Hutchings61d88c62014-05-19 01:29:42 +0100787 * It is not valid to request that both be unchanged.
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530788 */
Ben Hutchingsf062a382014-05-15 16:28:07 +0100789 if ((rxfh.indir_size &&
790 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE &&
791 rxfh.indir_size != dev_indir_size) ||
792 (rxfh.key_size && (rxfh.key_size != dev_key_size)) ||
793 (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE &&
794 rxfh.key_size == 0))
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530795 return -EINVAL;
796
Ben Hutchingsf062a382014-05-15 16:28:07 +0100797 if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE)
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530798 indir_bytes = dev_indir_size * sizeof(indir[0]);
799
Ben Hutchingsf062a382014-05-15 16:28:07 +0100800 rss_config = kzalloc(indir_bytes + rxfh.key_size, GFP_USER);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530801 if (!rss_config)
802 return -ENOMEM;
803
804 rx_rings.cmd = ETHTOOL_GRXRINGS;
805 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
806 if (ret)
807 goto out;
808
Ben Hutchingsf062a382014-05-15 16:28:07 +0100809 /* rxfh.indir_size == 0 means reset the indir table to default.
810 * rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE means leave it unchanged.
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530811 */
Ben Hutchingsf062a382014-05-15 16:28:07 +0100812 if (rxfh.indir_size &&
813 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530814 indir = (u32 *)rss_config;
815 ret = ethtool_copy_validate_indir(indir,
816 useraddr + rss_cfg_offset,
817 &rx_rings,
Ben Hutchingsf062a382014-05-15 16:28:07 +0100818 rxfh.indir_size);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530819 if (ret)
820 goto out;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100821 } else if (rxfh.indir_size == 0) {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530822 indir = (u32 *)rss_config;
823 for (i = 0; i < dev_indir_size; i++)
824 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
825 }
826
Ben Hutchingsf062a382014-05-15 16:28:07 +0100827 if (rxfh.key_size) {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530828 hkey = rss_config + indir_bytes;
829 if (copy_from_user(hkey,
830 useraddr + rss_cfg_offset + indir_bytes,
Ben Hutchingsf062a382014-05-15 16:28:07 +0100831 rxfh.key_size)) {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530832 ret = -EFAULT;
833 goto out;
834 }
835 }
836
837 ret = ops->set_rxfh(dev, indir, hkey);
838
839out:
840 kfree(rss_config);
841 return ret;
842}
843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
845{
846 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700847 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 void *regbuf;
849 int reglen, ret;
850
851 if (!ops->get_regs || !ops->get_regs_len)
852 return -EOPNOTSUPP;
853
854 if (copy_from_user(&regs, useraddr, sizeof(regs)))
855 return -EFAULT;
856
857 reglen = ops->get_regs_len(dev);
858 if (regs.len > reglen)
859 regs.len = reglen;
860
Eugene Teob7c7d012011-01-24 21:05:17 -0800861 regbuf = vzalloc(reglen);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700862 if (reglen && !regbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 return -ENOMEM;
864
865 ops->get_regs(dev, &regs, regbuf);
866
867 ret = -EFAULT;
868 if (copy_to_user(useraddr, &regs, sizeof(regs)))
869 goto out;
870 useraddr += offsetof(struct ethtool_regs, data);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700871 if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 goto out;
873 ret = 0;
874
875 out:
Ben Hutchingsa77f5db2010-09-20 08:42:17 +0000876 vfree(regbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 return ret;
878}
879
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000880static int ethtool_reset(struct net_device *dev, char __user *useraddr)
881{
882 struct ethtool_value reset;
883 int ret;
884
885 if (!dev->ethtool_ops->reset)
886 return -EOPNOTSUPP;
887
888 if (copy_from_user(&reset, useraddr, sizeof(reset)))
889 return -EFAULT;
890
891 ret = dev->ethtool_ops->reset(dev, &reset.data);
892 if (ret)
893 return ret;
894
895 if (copy_to_user(useraddr, &reset, sizeof(reset)))
896 return -EFAULT;
897 return 0;
898}
899
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
901{
Roland Dreier8e557422010-02-11 12:14:23 -0800902 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
904 if (!dev->ethtool_ops->get_wol)
905 return -EOPNOTSUPP;
906
907 dev->ethtool_ops->get_wol(dev, &wol);
908
909 if (copy_to_user(useraddr, &wol, sizeof(wol)))
910 return -EFAULT;
911 return 0;
912}
913
914static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
915{
916 struct ethtool_wolinfo wol;
917
918 if (!dev->ethtool_ops->set_wol)
919 return -EOPNOTSUPP;
920
921 if (copy_from_user(&wol, useraddr, sizeof(wol)))
922 return -EFAULT;
923
924 return dev->ethtool_ops->set_wol(dev, &wol);
925}
926
Yuval Mintz80f12ec2012-06-06 17:13:06 +0000927static int ethtool_get_eee(struct net_device *dev, char __user *useraddr)
928{
929 struct ethtool_eee edata;
930 int rc;
931
932 if (!dev->ethtool_ops->get_eee)
933 return -EOPNOTSUPP;
934
935 memset(&edata, 0, sizeof(struct ethtool_eee));
936 edata.cmd = ETHTOOL_GEEE;
937 rc = dev->ethtool_ops->get_eee(dev, &edata);
938
939 if (rc)
940 return rc;
941
942 if (copy_to_user(useraddr, &edata, sizeof(edata)))
943 return -EFAULT;
944
945 return 0;
946}
947
948static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
949{
950 struct ethtool_eee edata;
951
952 if (!dev->ethtool_ops->set_eee)
953 return -EOPNOTSUPP;
954
955 if (copy_from_user(&edata, useraddr, sizeof(edata)))
956 return -EFAULT;
957
958 return dev->ethtool_ops->set_eee(dev, &edata);
959}
960
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961static int ethtool_nway_reset(struct net_device *dev)
962{
963 if (!dev->ethtool_ops->nway_reset)
964 return -EOPNOTSUPP;
965
966 return dev->ethtool_ops->nway_reset(dev);
967}
968
Ben Hutchingse596e6e2010-12-09 12:08:35 +0000969static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
970{
971 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
972
973 if (!dev->ethtool_ops->get_link)
974 return -EOPNOTSUPP;
975
976 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
977
978 if (copy_to_user(useraddr, &edata, sizeof(edata)))
979 return -EFAULT;
980 return 0;
981}
982
Ben Hutchings081d0942012-04-12 00:42:12 +0000983static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr,
984 int (*getter)(struct net_device *,
985 struct ethtool_eeprom *, u8 *),
986 u32 total_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987{
988 struct ethtool_eeprom eeprom;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700989 void __user *userbuf = useraddr + sizeof(eeprom);
990 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700992 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
995 return -EFAULT;
996
997 /* Check for wrap and zero */
998 if (eeprom.offset + eeprom.len <= eeprom.offset)
999 return -EINVAL;
1000
1001 /* Check for exceeding total eeprom len */
Ben Hutchings081d0942012-04-12 00:42:12 +00001002 if (eeprom.offset + eeprom.len > total_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 return -EINVAL;
1004
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001005 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 if (!data)
1007 return -ENOMEM;
1008
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001009 bytes_remaining = eeprom.len;
1010 while (bytes_remaining > 0) {
1011 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Ben Hutchings081d0942012-04-12 00:42:12 +00001013 ret = getter(dev, &eeprom, data);
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001014 if (ret)
1015 break;
1016 if (copy_to_user(userbuf, data, eeprom.len)) {
1017 ret = -EFAULT;
1018 break;
1019 }
1020 userbuf += eeprom.len;
1021 eeprom.offset += eeprom.len;
1022 bytes_remaining -= eeprom.len;
1023 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -07001025 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
1026 eeprom.offset -= eeprom.len;
1027 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
1028 ret = -EFAULT;
1029
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 kfree(data);
1031 return ret;
1032}
1033
Ben Hutchings081d0942012-04-12 00:42:12 +00001034static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
1035{
1036 const struct ethtool_ops *ops = dev->ethtool_ops;
1037
Guenter Roecke0fb6fb2014-10-30 20:50:15 -07001038 if (!ops->get_eeprom || !ops->get_eeprom_len ||
1039 !ops->get_eeprom_len(dev))
Ben Hutchings081d0942012-04-12 00:42:12 +00001040 return -EOPNOTSUPP;
1041
1042 return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom,
1043 ops->get_eeprom_len(dev));
1044}
1045
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
1047{
1048 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001049 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001050 void __user *userbuf = useraddr + sizeof(eeprom);
1051 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001053 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
Guenter Roecke0fb6fb2014-10-30 20:50:15 -07001055 if (!ops->set_eeprom || !ops->get_eeprom_len ||
1056 !ops->get_eeprom_len(dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 return -EOPNOTSUPP;
1058
1059 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1060 return -EFAULT;
1061
1062 /* Check for wrap and zero */
1063 if (eeprom.offset + eeprom.len <= eeprom.offset)
1064 return -EINVAL;
1065
1066 /* Check for exceeding total eeprom len */
1067 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
1068 return -EINVAL;
1069
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001070 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 if (!data)
1072 return -ENOMEM;
1073
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001074 bytes_remaining = eeprom.len;
1075 while (bytes_remaining > 0) {
1076 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001078 if (copy_from_user(data, userbuf, eeprom.len)) {
1079 ret = -EFAULT;
1080 break;
1081 }
1082 ret = ops->set_eeprom(dev, &eeprom, data);
1083 if (ret)
1084 break;
1085 userbuf += eeprom.len;
1086 eeprom.offset += eeprom.len;
1087 bytes_remaining -= eeprom.len;
1088 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 kfree(data);
1091 return ret;
1092}
1093
chavey97f8aef2010-04-07 21:54:42 -07001094static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
1095 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096{
Roland Dreier8e557422010-02-11 12:14:23 -08001097 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 if (!dev->ethtool_ops->get_coalesce)
1100 return -EOPNOTSUPP;
1101
1102 dev->ethtool_ops->get_coalesce(dev, &coalesce);
1103
1104 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
1105 return -EFAULT;
1106 return 0;
1107}
1108
chavey97f8aef2010-04-07 21:54:42 -07001109static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
1110 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111{
1112 struct ethtool_coalesce coalesce;
1113
David S. Millerfa04ae52005-06-06 15:07:19 -07001114 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 return -EOPNOTSUPP;
1116
1117 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
1118 return -EFAULT;
1119
1120 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
1121}
1122
1123static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
1124{
Roland Dreier8e557422010-02-11 12:14:23 -08001125 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
1127 if (!dev->ethtool_ops->get_ringparam)
1128 return -EOPNOTSUPP;
1129
1130 dev->ethtool_ops->get_ringparam(dev, &ringparam);
1131
1132 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
1133 return -EFAULT;
1134 return 0;
1135}
1136
1137static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
1138{
1139 struct ethtool_ringparam ringparam;
1140
1141 if (!dev->ethtool_ops->set_ringparam)
1142 return -EOPNOTSUPP;
1143
1144 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
1145 return -EFAULT;
1146
1147 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
1148}
1149
amit salecha8b5933c2011-04-07 01:58:42 +00001150static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
1151 void __user *useraddr)
1152{
1153 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
1154
1155 if (!dev->ethtool_ops->get_channels)
1156 return -EOPNOTSUPP;
1157
1158 dev->ethtool_ops->get_channels(dev, &channels);
1159
1160 if (copy_to_user(useraddr, &channels, sizeof(channels)))
1161 return -EFAULT;
1162 return 0;
1163}
1164
1165static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
1166 void __user *useraddr)
1167{
1168 struct ethtool_channels channels;
1169
1170 if (!dev->ethtool_ops->set_channels)
1171 return -EOPNOTSUPP;
1172
1173 if (copy_from_user(&channels, useraddr, sizeof(channels)))
1174 return -EFAULT;
1175
1176 return dev->ethtool_ops->set_channels(dev, &channels);
1177}
1178
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
1180{
1181 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
1182
1183 if (!dev->ethtool_ops->get_pauseparam)
1184 return -EOPNOTSUPP;
1185
1186 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
1187
1188 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
1189 return -EFAULT;
1190 return 0;
1191}
1192
1193static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
1194{
1195 struct ethtool_pauseparam pauseparam;
1196
Jeff Garzike1b90c42006-07-17 12:54:40 -04001197 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 return -EOPNOTSUPP;
1199
1200 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
1201 return -EFAULT;
1202
1203 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
1204}
1205
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1207{
1208 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001209 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001211 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001213 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001214 return -EOPNOTSUPP;
1215
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001216 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -07001217 if (test_len < 0)
1218 return test_len;
1219 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
1221 if (copy_from_user(&test, useraddr, sizeof(test)))
1222 return -EFAULT;
1223
Jeff Garzikff03d492007-08-15 16:01:08 -07001224 test.len = test_len;
1225 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 if (!data)
1227 return -ENOMEM;
1228
1229 ops->self_test(dev, &test, data);
1230
1231 ret = -EFAULT;
1232 if (copy_to_user(useraddr, &test, sizeof(test)))
1233 goto out;
1234 useraddr += sizeof(test);
1235 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1236 goto out;
1237 ret = 0;
1238
1239 out:
1240 kfree(data);
1241 return ret;
1242}
1243
1244static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1245{
1246 struct ethtool_gstrings gstrings;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 u8 *data;
1248 int ret;
1249
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1251 return -EFAULT;
1252
Michał Mirosław340ae162011-02-15 16:59:16 +00001253 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001254 if (ret < 0)
1255 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001256
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001257 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
1259 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1260 if (!data)
1261 return -ENOMEM;
1262
Michał Mirosław340ae162011-02-15 16:59:16 +00001263 __ethtool_get_strings(dev, gstrings.string_set, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
1265 ret = -EFAULT;
1266 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1267 goto out;
1268 useraddr += sizeof(gstrings);
1269 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1270 goto out;
1271 ret = 0;
1272
Michał Mirosław340ae162011-02-15 16:59:16 +00001273out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 kfree(data);
1275 return ret;
1276}
1277
1278static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1279{
1280 struct ethtool_value id;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001281 static bool busy;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001282 const struct ethtool_ops *ops = dev->ethtool_ops;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001283 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001285 if (!ops->set_phys_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 return -EOPNOTSUPP;
1287
Ben Hutchings68f512f2011-04-02 00:35:15 +01001288 if (busy)
1289 return -EBUSY;
1290
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 if (copy_from_user(&id, useraddr, sizeof(id)))
1292 return -EFAULT;
1293
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001294 rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001295 if (rc < 0)
Ben Hutchings68f512f2011-04-02 00:35:15 +01001296 return rc;
1297
1298 /* Drop the RTNL lock while waiting, but prevent reentry or
1299 * removal of the device.
1300 */
1301 busy = true;
1302 dev_hold(dev);
1303 rtnl_unlock();
1304
1305 if (rc == 0) {
1306 /* Driver will handle this itself */
1307 schedule_timeout_interruptible(
Allan, Bruce W143780c2011-04-11 13:01:59 +00001308 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001309 } else {
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001310 /* Driver expects to be called at twice the frequency in rc */
1311 int n = rc * 2, i, interval = HZ / n;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001312
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001313 /* Count down seconds */
1314 do {
1315 /* Count down iterations per second */
1316 i = n;
1317 do {
1318 rtnl_lock();
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001319 rc = ops->set_phys_id(dev,
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001320 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1321 rtnl_unlock();
1322 if (rc)
1323 break;
1324 schedule_timeout_interruptible(interval);
1325 } while (!signal_pending(current) && --i != 0);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001326 } while (!signal_pending(current) &&
1327 (id.data == 0 || --id.data != 0));
1328 }
1329
1330 rtnl_lock();
1331 dev_put(dev);
1332 busy = false;
1333
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001334 (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001335 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336}
1337
1338static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1339{
1340 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001341 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001343 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001345 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001346 return -EOPNOTSUPP;
1347
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001348 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001349 if (n_stats < 0)
1350 return n_stats;
1351 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
1353 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1354 return -EFAULT;
1355
Jeff Garzikff03d492007-08-15 16:01:08 -07001356 stats.n_stats = n_stats;
1357 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 if (!data)
1359 return -ENOMEM;
1360
1361 ops->get_ethtool_stats(dev, &stats, data);
1362
1363 ret = -EFAULT;
1364 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1365 goto out;
1366 useraddr += sizeof(stats);
1367 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1368 goto out;
1369 ret = 0;
1370
1371 out:
1372 kfree(data);
1373 return ret;
1374}
1375
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001376static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001377{
1378 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001379
Matthew Wilcox313674a2007-07-31 14:00:29 -07001380 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001381 return -EFAULT;
1382
Matthew Wilcox313674a2007-07-31 14:00:29 -07001383 if (epaddr.size < dev->addr_len)
1384 return -ETOOSMALL;
1385 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001386
Jon Wetzela6f9a702005-08-20 17:15:54 -07001387 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001388 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001389 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001390 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1391 return -EFAULT;
1392 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001393}
1394
Jeff Garzik13c99b22007-08-15 16:01:56 -07001395static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1396 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001397{
Roland Dreier8e557422010-02-11 12:14:23 -08001398 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001399
Jeff Garzik13c99b22007-08-15 16:01:56 -07001400 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001401 return -EOPNOTSUPP;
1402
Jeff Garzik13c99b22007-08-15 16:01:56 -07001403 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001404
1405 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1406 return -EFAULT;
1407 return 0;
1408}
1409
Jeff Garzik13c99b22007-08-15 16:01:56 -07001410static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1411 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001412{
1413 struct ethtool_value edata;
1414
Jeff Garzik13c99b22007-08-15 16:01:56 -07001415 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001416 return -EOPNOTSUPP;
1417
1418 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1419 return -EFAULT;
1420
Jeff Garzik13c99b22007-08-15 16:01:56 -07001421 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001422 return 0;
1423}
1424
Jeff Garzik13c99b22007-08-15 16:01:56 -07001425static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1426 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001427{
1428 struct ethtool_value edata;
1429
Jeff Garzik13c99b22007-08-15 16:01:56 -07001430 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001431 return -EOPNOTSUPP;
1432
1433 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1434 return -EFAULT;
1435
Jeff Garzik13c99b22007-08-15 16:01:56 -07001436 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001437}
1438
chavey97f8aef2010-04-07 21:54:42 -07001439static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1440 char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001441{
1442 struct ethtool_flash efl;
1443
1444 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1445 return -EFAULT;
1446
1447 if (!dev->ethtool_ops->flash_device)
1448 return -EOPNOTSUPP;
1449
Ben Hutchings786f5282012-02-01 09:32:25 +00001450 efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
1451
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001452 return dev->ethtool_ops->flash_device(dev, &efl);
1453}
1454
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001455static int ethtool_set_dump(struct net_device *dev,
1456 void __user *useraddr)
1457{
1458 struct ethtool_dump dump;
1459
1460 if (!dev->ethtool_ops->set_dump)
1461 return -EOPNOTSUPP;
1462
1463 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1464 return -EFAULT;
1465
1466 return dev->ethtool_ops->set_dump(dev, &dump);
1467}
1468
1469static int ethtool_get_dump_flag(struct net_device *dev,
1470 void __user *useraddr)
1471{
1472 int ret;
1473 struct ethtool_dump dump;
1474 const struct ethtool_ops *ops = dev->ethtool_ops;
1475
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001476 if (!ops->get_dump_flag)
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001477 return -EOPNOTSUPP;
1478
1479 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1480 return -EFAULT;
1481
1482 ret = ops->get_dump_flag(dev, &dump);
1483 if (ret)
1484 return ret;
1485
1486 if (copy_to_user(useraddr, &dump, sizeof(dump)))
1487 return -EFAULT;
1488 return 0;
1489}
1490
1491static int ethtool_get_dump_data(struct net_device *dev,
1492 void __user *useraddr)
1493{
1494 int ret;
1495 __u32 len;
1496 struct ethtool_dump dump, tmp;
1497 const struct ethtool_ops *ops = dev->ethtool_ops;
1498 void *data = NULL;
1499
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001500 if (!ops->get_dump_data || !ops->get_dump_flag)
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001501 return -EOPNOTSUPP;
1502
1503 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1504 return -EFAULT;
1505
1506 memset(&tmp, 0, sizeof(tmp));
1507 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
1508 ret = ops->get_dump_flag(dev, &tmp);
1509 if (ret)
1510 return ret;
1511
Michal Schmidtc590b5e2013-07-01 17:23:30 +02001512 len = min(tmp.len, dump.len);
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001513 if (!len)
1514 return -EFAULT;
1515
Michal Schmidtc590b5e2013-07-01 17:23:30 +02001516 /* Don't ever let the driver think there's more space available
1517 * than it requested with .get_dump_flag().
1518 */
1519 dump.len = len;
1520
1521 /* Always allocate enough space to hold the whole thing so that the
1522 * driver does not need to check the length and bother with partial
1523 * dumping.
1524 */
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001525 data = vzalloc(tmp.len);
1526 if (!data)
1527 return -ENOMEM;
1528 ret = ops->get_dump_data(dev, &dump, data);
1529 if (ret)
1530 goto out;
1531
Michal Schmidtc590b5e2013-07-01 17:23:30 +02001532 /* There are two sane possibilities:
1533 * 1. The driver's .get_dump_data() does not touch dump.len.
1534 * 2. Or it may set dump.len to how much it really writes, which
1535 * should be tmp.len (or len if it can do a partial dump).
1536 * In any case respond to userspace with the actual length of data
1537 * it's receiving.
1538 */
1539 WARN_ON(dump.len != len && dump.len != tmp.len);
1540 dump.len = len;
1541
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001542 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1543 ret = -EFAULT;
1544 goto out;
1545 }
1546 useraddr += offsetof(struct ethtool_dump, data);
1547 if (copy_to_user(useraddr, data, len))
1548 ret = -EFAULT;
1549out:
1550 vfree(data);
1551 return ret;
1552}
1553
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001554static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
1555{
1556 int err = 0;
1557 struct ethtool_ts_info info;
1558 const struct ethtool_ops *ops = dev->ethtool_ops;
1559 struct phy_device *phydev = dev->phydev;
1560
1561 memset(&info, 0, sizeof(info));
1562 info.cmd = ETHTOOL_GET_TS_INFO;
1563
1564 if (phydev && phydev->drv && phydev->drv->ts_info) {
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001565 err = phydev->drv->ts_info(phydev, &info);
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001566 } else if (ops->get_ts_info) {
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001567 err = ops->get_ts_info(dev, &info);
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001568 } else {
1569 info.so_timestamping =
1570 SOF_TIMESTAMPING_RX_SOFTWARE |
1571 SOF_TIMESTAMPING_SOFTWARE;
1572 info.phc_index = -1;
1573 }
1574
1575 if (err)
1576 return err;
1577
1578 if (copy_to_user(useraddr, &info, sizeof(info)))
1579 err = -EFAULT;
1580
1581 return err;
1582}
1583
Stuart Hodgson41c3cb62012-04-19 09:44:42 +01001584static int ethtool_get_module_info(struct net_device *dev,
1585 void __user *useraddr)
1586{
1587 int ret;
1588 struct ethtool_modinfo modinfo;
1589 const struct ethtool_ops *ops = dev->ethtool_ops;
1590
1591 if (!ops->get_module_info)
1592 return -EOPNOTSUPP;
1593
1594 if (copy_from_user(&modinfo, useraddr, sizeof(modinfo)))
1595 return -EFAULT;
1596
1597 ret = ops->get_module_info(dev, &modinfo);
1598 if (ret)
1599 return ret;
1600
1601 if (copy_to_user(useraddr, &modinfo, sizeof(modinfo)))
1602 return -EFAULT;
1603
1604 return 0;
1605}
1606
1607static int ethtool_get_module_eeprom(struct net_device *dev,
1608 void __user *useraddr)
1609{
1610 int ret;
1611 struct ethtool_modinfo modinfo;
1612 const struct ethtool_ops *ops = dev->ethtool_ops;
1613
1614 if (!ops->get_module_info || !ops->get_module_eeprom)
1615 return -EOPNOTSUPP;
1616
1617 ret = ops->get_module_info(dev, &modinfo);
1618 if (ret)
1619 return ret;
1620
1621 return ethtool_get_any_eeprom(dev, useraddr, ops->get_module_eeprom,
1622 modinfo.eeprom_len);
1623}
1624
Govindarajulu Varadarajanf0db9b02014-09-03 03:17:20 +05301625static int ethtool_tunable_valid(const struct ethtool_tunable *tuna)
1626{
1627 switch (tuna->id) {
1628 case ETHTOOL_RX_COPYBREAK:
Eric Dumazet1255a502014-10-05 12:35:21 +03001629 case ETHTOOL_TX_COPYBREAK:
Govindarajulu Varadarajanf0db9b02014-09-03 03:17:20 +05301630 if (tuna->len != sizeof(u32) ||
1631 tuna->type_id != ETHTOOL_TUNABLE_U32)
1632 return -EINVAL;
1633 break;
1634 default:
1635 return -EINVAL;
1636 }
1637
1638 return 0;
1639}
1640
1641static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr)
1642{
1643 int ret;
1644 struct ethtool_tunable tuna;
1645 const struct ethtool_ops *ops = dev->ethtool_ops;
1646 void *data;
1647
1648 if (!ops->get_tunable)
1649 return -EOPNOTSUPP;
1650 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
1651 return -EFAULT;
1652 ret = ethtool_tunable_valid(&tuna);
1653 if (ret)
1654 return ret;
1655 data = kmalloc(tuna.len, GFP_USER);
1656 if (!data)
1657 return -ENOMEM;
1658 ret = ops->get_tunable(dev, &tuna, data);
1659 if (ret)
1660 goto out;
1661 useraddr += sizeof(tuna);
1662 ret = -EFAULT;
1663 if (copy_to_user(useraddr, data, tuna.len))
1664 goto out;
1665 ret = 0;
1666
1667out:
1668 kfree(data);
1669 return ret;
1670}
1671
1672static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr)
1673{
1674 int ret;
1675 struct ethtool_tunable tuna;
1676 const struct ethtool_ops *ops = dev->ethtool_ops;
1677 void *data;
1678
1679 if (!ops->set_tunable)
1680 return -EOPNOTSUPP;
1681 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
1682 return -EFAULT;
1683 ret = ethtool_tunable_valid(&tuna);
1684 if (ret)
1685 return ret;
1686 data = kmalloc(tuna.len, GFP_USER);
1687 if (!data)
1688 return -ENOMEM;
1689 useraddr += sizeof(tuna);
1690 ret = -EFAULT;
1691 if (copy_from_user(data, useraddr, tuna.len))
1692 goto out;
1693 ret = ops->set_tunable(dev, &tuna, data);
1694
1695out:
1696 kfree(data);
1697 return ret;
1698}
1699
Yan Burman600fed52013-06-03 02:03:34 +00001700/* The main entry point in this file. Called from net/core/dev_ioctl.c */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Eric W. Biederman881d9662007-09-17 11:56:21 -07001702int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001704 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 void __user *useraddr = ifr->ifr_data;
1706 u32 ethcmd;
1707 int rc;
Bjørn Morkb29d3142013-05-01 23:06:42 +00001708 netdev_features_t old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 if (!dev || !netif_device_present(dev))
1711 return -ENODEV;
1712
chavey97f8aef2010-04-07 21:54:42 -07001713 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 return -EFAULT;
1715
Stephen Hemminger75f31232006-09-28 15:13:37 -07001716 /* Allow some commands to be done by anyone */
chavey97f8aef2010-04-07 21:54:42 -07001717 switch (ethcmd) {
stephen hemminger0fdc1002010-08-23 10:24:18 +00001718 case ETHTOOL_GSET:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001719 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001720 case ETHTOOL_GMSGLVL:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001721 case ETHTOOL_GLINK:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001722 case ETHTOOL_GCOALESCE:
1723 case ETHTOOL_GRINGPARAM:
1724 case ETHTOOL_GPAUSEPARAM:
1725 case ETHTOOL_GRXCSUM:
1726 case ETHTOOL_GTXCSUM:
1727 case ETHTOOL_GSG:
Michał Mirosławf80400a2012-01-22 00:20:40 +00001728 case ETHTOOL_GSSET_INFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001729 case ETHTOOL_GSTRINGS:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001730 case ETHTOOL_GSTATS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001731 case ETHTOOL_GTSO:
1732 case ETHTOOL_GPERMADDR:
1733 case ETHTOOL_GUFO:
1734 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001735 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001736 case ETHTOOL_GFLAGS:
1737 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001738 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001739 case ETHTOOL_GRXRINGS:
1740 case ETHTOOL_GRXCLSRLCNT:
1741 case ETHTOOL_GRXCLSRULE:
1742 case ETHTOOL_GRXCLSRLALL:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001743 case ETHTOOL_GRXFHINDIR:
Venkata Duvvuru3de0b592014-04-21 15:37:59 +05301744 case ETHTOOL_GRSSH:
Michał Mirosław5455c692011-02-15 16:59:17 +00001745 case ETHTOOL_GFEATURES:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001746 case ETHTOOL_GCHANNELS:
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001747 case ETHTOOL_GET_TS_INFO:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001748 case ETHTOOL_GEEE:
Govindarajulu Varadarajanf0db9b02014-09-03 03:17:20 +05301749 case ETHTOOL_GTUNABLE:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001750 break;
1751 default:
Eric W. Biederman5e1fccc2012-11-16 03:03:04 +00001752 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
Stephen Hemminger75f31232006-09-28 15:13:37 -07001753 return -EPERM;
1754 }
1755
chavey97f8aef2010-04-07 21:54:42 -07001756 if (dev->ethtool_ops->begin) {
1757 rc = dev->ethtool_ops->begin(dev);
1758 if (rc < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 return rc;
chavey97f8aef2010-04-07 21:54:42 -07001760 }
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001761 old_features = dev->features;
1762
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 switch (ethcmd) {
1764 case ETHTOOL_GSET:
1765 rc = ethtool_get_settings(dev, useraddr);
1766 break;
1767 case ETHTOOL_SSET:
1768 rc = ethtool_set_settings(dev, useraddr);
1769 break;
1770 case ETHTOOL_GDRVINFO:
1771 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 break;
1773 case ETHTOOL_GREGS:
1774 rc = ethtool_get_regs(dev, useraddr);
1775 break;
1776 case ETHTOOL_GWOL:
1777 rc = ethtool_get_wol(dev, useraddr);
1778 break;
1779 case ETHTOOL_SWOL:
1780 rc = ethtool_set_wol(dev, useraddr);
1781 break;
1782 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001783 rc = ethtool_get_value(dev, useraddr, ethcmd,
1784 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 break;
1786 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001787 rc = ethtool_set_value_void(dev, useraddr,
1788 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 break;
Yuval Mintz80f12ec2012-06-06 17:13:06 +00001790 case ETHTOOL_GEEE:
1791 rc = ethtool_get_eee(dev, useraddr);
1792 break;
1793 case ETHTOOL_SEEE:
1794 rc = ethtool_set_eee(dev, useraddr);
1795 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 case ETHTOOL_NWAY_RST:
1797 rc = ethtool_nway_reset(dev);
1798 break;
1799 case ETHTOOL_GLINK:
Ben Hutchingse596e6e2010-12-09 12:08:35 +00001800 rc = ethtool_get_link(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 break;
1802 case ETHTOOL_GEEPROM:
1803 rc = ethtool_get_eeprom(dev, useraddr);
1804 break;
1805 case ETHTOOL_SEEPROM:
1806 rc = ethtool_set_eeprom(dev, useraddr);
1807 break;
1808 case ETHTOOL_GCOALESCE:
1809 rc = ethtool_get_coalesce(dev, useraddr);
1810 break;
1811 case ETHTOOL_SCOALESCE:
1812 rc = ethtool_set_coalesce(dev, useraddr);
1813 break;
1814 case ETHTOOL_GRINGPARAM:
1815 rc = ethtool_get_ringparam(dev, useraddr);
1816 break;
1817 case ETHTOOL_SRINGPARAM:
1818 rc = ethtool_set_ringparam(dev, useraddr);
1819 break;
1820 case ETHTOOL_GPAUSEPARAM:
1821 rc = ethtool_get_pauseparam(dev, useraddr);
1822 break;
1823 case ETHTOOL_SPAUSEPARAM:
1824 rc = ethtool_set_pauseparam(dev, useraddr);
1825 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 case ETHTOOL_TEST:
1827 rc = ethtool_self_test(dev, useraddr);
1828 break;
1829 case ETHTOOL_GSTRINGS:
1830 rc = ethtool_get_strings(dev, useraddr);
1831 break;
1832 case ETHTOOL_PHYS_ID:
1833 rc = ethtool_phys_id(dev, useraddr);
1834 break;
1835 case ETHTOOL_GSTATS:
1836 rc = ethtool_get_stats(dev, useraddr);
1837 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001838 case ETHTOOL_GPERMADDR:
1839 rc = ethtool_get_perm_addr(dev, useraddr);
1840 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001841 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001842 rc = ethtool_get_value(dev, useraddr, ethcmd,
Michał Mirosławbc5787c62011-11-15 15:29:55 +00001843 __ethtool_get_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001844 break;
1845 case ETHTOOL_SFLAGS:
Michał Mirosławda8ac86c2011-02-15 16:59:18 +00001846 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001847 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001848 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001849 rc = ethtool_get_value(dev, useraddr, ethcmd,
1850 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001851 break;
1852 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001853 rc = ethtool_set_value(dev, useraddr,
1854 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001855 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001856 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001857 case ETHTOOL_GRXRINGS:
1858 case ETHTOOL_GRXCLSRLCNT:
1859 case ETHTOOL_GRXCLSRULE:
1860 case ETHTOOL_GRXCLSRLALL:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001861 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001862 break;
1863 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001864 case ETHTOOL_SRXCLSRLDEL:
1865 case ETHTOOL_SRXCLSRLINS:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001866 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001867 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001868 case ETHTOOL_FLASHDEV:
1869 rc = ethtool_flash_device(dev, useraddr);
1870 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001871 case ETHTOOL_RESET:
1872 rc = ethtool_reset(dev, useraddr);
1873 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001874 case ETHTOOL_GSSET_INFO:
1875 rc = ethtool_get_sset_info(dev, useraddr);
1876 break;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +00001877 case ETHTOOL_GRXFHINDIR:
1878 rc = ethtool_get_rxfh_indir(dev, useraddr);
1879 break;
1880 case ETHTOOL_SRXFHINDIR:
1881 rc = ethtool_set_rxfh_indir(dev, useraddr);
1882 break;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +05301883 case ETHTOOL_GRSSH:
1884 rc = ethtool_get_rxfh(dev, useraddr);
1885 break;
1886 case ETHTOOL_SRSSH:
1887 rc = ethtool_set_rxfh(dev, useraddr);
1888 break;
Michał Mirosław5455c692011-02-15 16:59:17 +00001889 case ETHTOOL_GFEATURES:
1890 rc = ethtool_get_features(dev, useraddr);
1891 break;
1892 case ETHTOOL_SFEATURES:
1893 rc = ethtool_set_features(dev, useraddr);
1894 break;
Michał Mirosław0a417702011-02-15 16:59:17 +00001895 case ETHTOOL_GTXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001896 case ETHTOOL_GRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001897 case ETHTOOL_GSG:
1898 case ETHTOOL_GTSO:
1899 case ETHTOOL_GUFO:
1900 case ETHTOOL_GGSO:
1901 case ETHTOOL_GGRO:
1902 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1903 break;
1904 case ETHTOOL_STXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001905 case ETHTOOL_SRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001906 case ETHTOOL_SSG:
1907 case ETHTOOL_STSO:
1908 case ETHTOOL_SUFO:
1909 case ETHTOOL_SGSO:
1910 case ETHTOOL_SGRO:
1911 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1912 break;
amit salecha8b5933c2011-04-07 01:58:42 +00001913 case ETHTOOL_GCHANNELS:
1914 rc = ethtool_get_channels(dev, useraddr);
1915 break;
1916 case ETHTOOL_SCHANNELS:
1917 rc = ethtool_set_channels(dev, useraddr);
1918 break;
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001919 case ETHTOOL_SET_DUMP:
1920 rc = ethtool_set_dump(dev, useraddr);
1921 break;
1922 case ETHTOOL_GET_DUMP_FLAG:
1923 rc = ethtool_get_dump_flag(dev, useraddr);
1924 break;
1925 case ETHTOOL_GET_DUMP_DATA:
1926 rc = ethtool_get_dump_data(dev, useraddr);
1927 break;
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001928 case ETHTOOL_GET_TS_INFO:
1929 rc = ethtool_get_ts_info(dev, useraddr);
1930 break;
Stuart Hodgson41c3cb62012-04-19 09:44:42 +01001931 case ETHTOOL_GMODULEINFO:
1932 rc = ethtool_get_module_info(dev, useraddr);
1933 break;
1934 case ETHTOOL_GMODULEEEPROM:
1935 rc = ethtool_get_module_eeprom(dev, useraddr);
1936 break;
Govindarajulu Varadarajanf0db9b02014-09-03 03:17:20 +05301937 case ETHTOOL_GTUNABLE:
1938 rc = ethtool_get_tunable(dev, useraddr);
1939 break;
1940 case ETHTOOL_STUNABLE:
1941 rc = ethtool_set_tunable(dev, useraddr);
1942 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001944 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001946
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001947 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001949
1950 if (old_features != dev->features)
1951 netdev_features_change(dev);
1952
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954}