blob: 715f51f321e9ccd97c6c2d661c9e4c288f48a2a9 [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>
Eric Dumazet960fb622014-11-16 06:23:05 -080028#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090030/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 * Some useful ethtool_ops methods that're device independent.
32 * If we find that all drivers want to do the same thing here,
33 * we can turn these into dev_() function calls.
34 */
35
36u32 ethtool_op_get_link(struct net_device *dev)
37{
38 return netif_carrier_ok(dev) ? 1 : 0;
39}
chavey97f8aef2010-04-07 21:54:42 -070040EXPORT_SYMBOL(ethtool_op_get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Richard Cochran02eacbd2012-04-03 22:59:22 +000042int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
43{
44 info->so_timestamping =
45 SOF_TIMESTAMPING_TX_SOFTWARE |
46 SOF_TIMESTAMPING_RX_SOFTWARE |
47 SOF_TIMESTAMPING_SOFTWARE;
48 info->phc_index = -1;
49 return 0;
50}
51EXPORT_SYMBOL(ethtool_op_get_ts_info);
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053/* Handlers for each ethtool command */
54
Michał Mirosław475414f2011-11-15 15:29:55 +000055#define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32)
Michał Mirosław5455c692011-02-15 16:59:17 +000056
Michał Mirosław9d921542011-11-15 15:29:55 +000057static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = {
58 [NETIF_F_SG_BIT] = "tx-scatter-gather",
59 [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4",
Michał Mirosław9d921542011-11-15 15:29:55 +000060 [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic",
61 [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6",
62 [NETIF_F_HIGHDMA_BIT] = "highdma",
63 [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist",
Fernando Luis Vazquez Cao788dfca2013-06-17 11:28:03 +090064 [NETIF_F_HW_VLAN_CTAG_TX_BIT] = "tx-vlan-hw-insert",
Michał Mirosław9d921542011-11-15 15:29:55 +000065
Fernando Luis Vazquez Cao788dfca2013-06-17 11:28:03 +090066 [NETIF_F_HW_VLAN_CTAG_RX_BIT] = "rx-vlan-hw-parse",
67 [NETIF_F_HW_VLAN_CTAG_FILTER_BIT] = "rx-vlan-filter",
David S. Miller2d6577f2013-04-19 16:08:23 -040068 [NETIF_F_HW_VLAN_STAG_TX_BIT] = "tx-vlan-stag-hw-insert",
69 [NETIF_F_HW_VLAN_STAG_RX_BIT] = "rx-vlan-stag-hw-parse",
70 [NETIF_F_HW_VLAN_STAG_FILTER_BIT] = "rx-vlan-stag-filter",
Michał Mirosław9d921542011-11-15 15:29:55 +000071 [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged",
72 [NETIF_F_GSO_BIT] = "tx-generic-segmentation",
73 [NETIF_F_LLTX_BIT] = "tx-lockless",
74 [NETIF_F_NETNS_LOCAL_BIT] = "netns-local",
75 [NETIF_F_GRO_BIT] = "rx-gro",
76 [NETIF_F_LRO_BIT] = "rx-lro",
77
78 [NETIF_F_TSO_BIT] = "tx-tcp-segmentation",
79 [NETIF_F_UFO_BIT] = "tx-udp-fragmentation",
80 [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust",
81 [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation",
82 [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation",
83 [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation",
Pravin B Shelar68c33162013-02-14 14:02:41 +000084 [NETIF_F_GSO_GRE_BIT] = "tx-gre-segmentation",
Eric Dumazetcb32f512013-10-19 11:42:57 -070085 [NETIF_F_GSO_IPIP_BIT] = "tx-ipip-segmentation",
Eric Dumazet61c1db72013-10-20 20:47:30 -070086 [NETIF_F_GSO_SIT_BIT] = "tx-sit-segmentation",
Pravin B Shelar73136262013-03-07 13:21:51 +000087 [NETIF_F_GSO_UDP_TUNNEL_BIT] = "tx-udp_tnl-segmentation",
Michał Mirosław9d921542011-11-15 15:29:55 +000088
89 [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc",
90 [NETIF_F_SCTP_CSUM_BIT] = "tx-checksum-sctp",
91 [NETIF_F_FCOE_MTU_BIT] = "fcoe-mtu",
92 [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter",
93 [NETIF_F_RXHASH_BIT] = "rx-hashing",
94 [NETIF_F_RXCSUM_BIT] = "rx-checksum",
95 [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy",
96 [NETIF_F_LOOPBACK_BIT] = "loopback",
Ben Greear36eabda32012-02-11 15:39:14 +000097 [NETIF_F_RXFCS_BIT] = "rx-fcs",
Ben Greear5e0c03c2012-02-11 15:39:45 +000098 [NETIF_F_RXALL_BIT] = "rx-all",
John Fastabenda6cc0cf2013-11-06 09:54:46 -080099 [NETIF_F_HW_L2FW_DOFFLOAD_BIT] = "l2-fwd-offload",
Jiri Pirkod0290212014-04-02 23:09:31 +0200100 [NETIF_F_BUSY_POLL_BIT] = "busy-poll",
Michał Mirosław9d921542011-11-15 15:29:55 +0000101};
102
Michał Mirosław5455c692011-02-15 16:59:17 +0000103static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
104{
105 struct ethtool_gfeatures cmd = {
106 .cmd = ETHTOOL_GFEATURES,
107 .size = ETHTOOL_DEV_FEATURE_WORDS,
108 };
Michał Mirosław475414f2011-11-15 15:29:55 +0000109 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
Michał Mirosław5455c692011-02-15 16:59:17 +0000110 u32 __user *sizeaddr;
111 u32 copy_size;
Michał Mirosław475414f2011-11-15 15:29:55 +0000112 int i;
113
114 /* in case feature bits run out again */
Michał Mirosław09da71b2011-11-16 14:32:03 +0000115 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
Michał Mirosław475414f2011-11-15 15:29:55 +0000116
117 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
Michał Mirosław09da71b2011-11-16 14:32:03 +0000118 features[i].available = (u32)(dev->hw_features >> (32 * i));
119 features[i].requested = (u32)(dev->wanted_features >> (32 * i));
120 features[i].active = (u32)(dev->features >> (32 * i));
121 features[i].never_changed =
122 (u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
Michał Mirosław475414f2011-11-15 15:29:55 +0000123 }
Michał Mirosław5455c692011-02-15 16:59:17 +0000124
125 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
126 if (get_user(copy_size, sizeaddr))
127 return -EFAULT;
128
129 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
130 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
131
132 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
133 return -EFAULT;
134 useraddr += sizeof(cmd);
135 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
136 return -EFAULT;
137
138 return 0;
139}
140
141static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
142{
143 struct ethtool_sfeatures cmd;
144 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
Michał Mirosław475414f2011-11-15 15:29:55 +0000145 netdev_features_t wanted = 0, valid = 0;
146 int i, ret = 0;
Michał Mirosław5455c692011-02-15 16:59:17 +0000147
148 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
149 return -EFAULT;
150 useraddr += sizeof(cmd);
151
152 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
153 return -EINVAL;
154
155 if (copy_from_user(features, useraddr, sizeof(features)))
156 return -EFAULT;
157
Michał Mirosław475414f2011-11-15 15:29:55 +0000158 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
Michał Mirosław09da71b2011-11-16 14:32:03 +0000159 valid |= (netdev_features_t)features[i].valid << (32 * i);
160 wanted |= (netdev_features_t)features[i].requested << (32 * i);
Michał Mirosław475414f2011-11-15 15:29:55 +0000161 }
162
163 if (valid & ~NETIF_F_ETHTOOL_BITS)
Michał Mirosław5455c692011-02-15 16:59:17 +0000164 return -EINVAL;
165
Michał Mirosław475414f2011-11-15 15:29:55 +0000166 if (valid & ~dev->hw_features) {
167 valid &= dev->hw_features;
Michał Mirosław5455c692011-02-15 16:59:17 +0000168 ret |= ETHTOOL_F_UNSUPPORTED;
169 }
170
Michał Mirosław475414f2011-11-15 15:29:55 +0000171 dev->wanted_features &= ~valid;
172 dev->wanted_features |= wanted & valid;
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700173 __netdev_update_features(dev);
Michał Mirosław5455c692011-02-15 16:59:17 +0000174
Michał Mirosław475414f2011-11-15 15:29:55 +0000175 if ((dev->wanted_features ^ dev->features) & valid)
Michał Mirosław5455c692011-02-15 16:59:17 +0000176 ret |= ETHTOOL_F_WISH;
177
178 return ret;
179}
180
Michał Mirosław340ae162011-02-15 16:59:16 +0000181static int __ethtool_get_sset_count(struct net_device *dev, int sset)
182{
183 const struct ethtool_ops *ops = dev->ethtool_ops;
184
Michał Mirosław5455c692011-02-15 16:59:17 +0000185 if (sset == ETH_SS_FEATURES)
186 return ARRAY_SIZE(netdev_features_strings);
187
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000188 if (ops->get_sset_count && ops->get_strings)
Michał Mirosław340ae162011-02-15 16:59:16 +0000189 return ops->get_sset_count(dev, sset);
190 else
191 return -EOPNOTSUPP;
192}
193
194static void __ethtool_get_strings(struct net_device *dev,
195 u32 stringset, u8 *data)
196{
197 const struct ethtool_ops *ops = dev->ethtool_ops;
198
Michał Mirosław5455c692011-02-15 16:59:17 +0000199 if (stringset == ETH_SS_FEATURES)
200 memcpy(data, netdev_features_strings,
201 sizeof(netdev_features_strings));
202 else
203 /* ops->get_strings is valid because checked earlier */
204 ops->get_strings(dev, stringset, data);
Michał Mirosław340ae162011-02-15 16:59:16 +0000205}
206
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000207static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
Michał Mirosław0a417702011-02-15 16:59:17 +0000208{
209 /* feature masks of legacy discrete ethtool ops */
210
211 switch (eth_cmd) {
212 case ETHTOOL_GTXCSUM:
213 case ETHTOOL_STXCSUM:
214 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
Michał Mirosławe83d3602011-02-15 16:59:18 +0000215 case ETHTOOL_GRXCSUM:
216 case ETHTOOL_SRXCSUM:
217 return NETIF_F_RXCSUM;
Michał Mirosław0a417702011-02-15 16:59:17 +0000218 case ETHTOOL_GSG:
219 case ETHTOOL_SSG:
220 return NETIF_F_SG;
221 case ETHTOOL_GTSO:
222 case ETHTOOL_STSO:
223 return NETIF_F_ALL_TSO;
224 case ETHTOOL_GUFO:
225 case ETHTOOL_SUFO:
226 return NETIF_F_UFO;
227 case ETHTOOL_GGSO:
228 case ETHTOOL_SGSO:
229 return NETIF_F_GSO;
230 case ETHTOOL_GGRO:
231 case ETHTOOL_SGRO:
232 return NETIF_F_GRO;
233 default:
234 BUG();
235 }
236}
237
Michał Mirosław0a417702011-02-15 16:59:17 +0000238static int ethtool_get_one_feature(struct net_device *dev,
239 char __user *useraddr, u32 ethcmd)
240{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000241 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
Michał Mirosław0a417702011-02-15 16:59:17 +0000242 struct ethtool_value edata = {
243 .cmd = ethcmd,
Michał Mirosław86794882011-02-15 16:59:17 +0000244 .data = !!(dev->features & mask),
Michał Mirosław0a417702011-02-15 16:59:17 +0000245 };
Michał Mirosław0a417702011-02-15 16:59:17 +0000246
Michał Mirosław0a417702011-02-15 16:59:17 +0000247 if (copy_to_user(useraddr, &edata, sizeof(edata)))
248 return -EFAULT;
249 return 0;
250}
251
Michał Mirosław0a417702011-02-15 16:59:17 +0000252static int ethtool_set_one_feature(struct net_device *dev,
253 void __user *useraddr, u32 ethcmd)
254{
255 struct ethtool_value edata;
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000256 netdev_features_t mask;
Michał Mirosław0a417702011-02-15 16:59:17 +0000257
258 if (copy_from_user(&edata, useraddr, sizeof(edata)))
259 return -EFAULT;
260
Michał Mirosław86794882011-02-15 16:59:17 +0000261 mask = ethtool_get_feature_mask(ethcmd);
262 mask &= dev->hw_features;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000263 if (!mask)
Michał Mirosław0a417702011-02-15 16:59:17 +0000264 return -EOPNOTSUPP;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000265
266 if (edata.data)
267 dev->wanted_features |= mask;
268 else
269 dev->wanted_features &= ~mask;
270
271 __netdev_update_features(dev);
272
273 return 0;
Michał Mirosław0a417702011-02-15 16:59:17 +0000274}
275
Michał Mirosław02b3a552011-11-15 15:29:55 +0000276#define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
277 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
Patrick McHardyf6469682013-04-19 02:04:27 +0000278#define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_CTAG_RX | \
279 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_NTUPLE | \
280 NETIF_F_RXHASH)
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000281
282static u32 __ethtool_get_flags(struct net_device *dev)
283{
Michał Mirosław02b3a552011-11-15 15:29:55 +0000284 u32 flags = 0;
285
Dragos Foianu8a731252013-07-13 14:43:00 +0100286 if (dev->features & NETIF_F_LRO)
287 flags |= ETH_FLAG_LRO;
288 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
289 flags |= ETH_FLAG_RXVLAN;
290 if (dev->features & NETIF_F_HW_VLAN_CTAG_TX)
291 flags |= ETH_FLAG_TXVLAN;
292 if (dev->features & NETIF_F_NTUPLE)
293 flags |= ETH_FLAG_NTUPLE;
294 if (dev->features & NETIF_F_RXHASH)
295 flags |= ETH_FLAG_RXHASH;
Michał Mirosław02b3a552011-11-15 15:29:55 +0000296
297 return flags;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000298}
299
300static int __ethtool_set_flags(struct net_device *dev, u32 data)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000301{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000302 netdev_features_t features = 0, changed;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000303
Michał Mirosław02b3a552011-11-15 15:29:55 +0000304 if (data & ~ETH_ALL_FLAGS)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000305 return -EINVAL;
306
Dragos Foianu8a731252013-07-13 14:43:00 +0100307 if (data & ETH_FLAG_LRO)
308 features |= NETIF_F_LRO;
309 if (data & ETH_FLAG_RXVLAN)
310 features |= NETIF_F_HW_VLAN_CTAG_RX;
311 if (data & ETH_FLAG_TXVLAN)
312 features |= NETIF_F_HW_VLAN_CTAG_TX;
313 if (data & ETH_FLAG_NTUPLE)
314 features |= NETIF_F_NTUPLE;
315 if (data & ETH_FLAG_RXHASH)
316 features |= NETIF_F_RXHASH;
Michał Mirosław02b3a552011-11-15 15:29:55 +0000317
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000318 /* allow changing only bits set in hw_features */
Michał Mirosław02b3a552011-11-15 15:29:55 +0000319 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000320 if (changed & ~dev->hw_features)
321 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
322
323 dev->wanted_features =
Michał Mirosław02b3a552011-11-15 15:29:55 +0000324 (dev->wanted_features & ~changed) | (features & changed);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000325
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700326 __netdev_update_features(dev);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000327
328 return 0;
329}
330
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000331int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000333 ASSERT_RTNL();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000335 if (!dev->ethtool_ops->get_settings)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 return -EOPNOTSUPP;
337
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000338 memset(cmd, 0, sizeof(struct ethtool_cmd));
339 cmd->cmd = ETHTOOL_GSET;
340 return dev->ethtool_ops->get_settings(dev, cmd);
341}
342EXPORT_SYMBOL(__ethtool_get_settings);
343
344static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
345{
346 int err;
347 struct ethtool_cmd cmd;
348
349 err = __ethtool_get_settings(dev, &cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if (err < 0)
351 return err;
352
353 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
354 return -EFAULT;
355 return 0;
356}
357
358static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
359{
360 struct ethtool_cmd cmd;
361
362 if (!dev->ethtool_ops->set_settings)
363 return -EOPNOTSUPP;
364
365 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
366 return -EFAULT;
367
368 return dev->ethtool_ops->set_settings(dev, &cmd);
369}
370
chavey97f8aef2010-04-07 21:54:42 -0700371static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
372 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
374 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700375 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 memset(&info, 0, sizeof(info));
378 info.cmd = ETHTOOL_GDRVINFO;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000379 if (ops->get_drvinfo) {
Ben Hutchings01414802010-08-17 02:31:15 -0700380 ops->get_drvinfo(dev, &info);
381 } else if (dev->dev.parent && dev->dev.parent->driver) {
382 strlcpy(info.bus_info, dev_name(dev->dev.parent),
383 sizeof(info.bus_info));
384 strlcpy(info.driver, dev->dev.parent->driver->name,
385 sizeof(info.driver));
386 } else {
387 return -EOPNOTSUPP;
388 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Jeff Garzik723b2f52010-03-03 22:51:50 +0000390 /*
391 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000392 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000393 */
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000394 if (ops->get_sset_count) {
Jeff Garzikff03d492007-08-15 16:01:08 -0700395 int rc;
396
397 rc = ops->get_sset_count(dev, ETH_SS_TEST);
398 if (rc >= 0)
399 info.testinfo_len = rc;
400 rc = ops->get_sset_count(dev, ETH_SS_STATS);
401 if (rc >= 0)
402 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700403 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
404 if (rc >= 0)
405 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700406 }
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000407 if (ops->get_regs_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 info.regdump_len = ops->get_regs_len(dev);
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000409 if (ops->get_eeprom_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 info.eedump_len = ops->get_eeprom_len(dev);
411
412 if (copy_to_user(useraddr, &info, sizeof(info)))
413 return -EFAULT;
414 return 0;
415}
416
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800417static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
chavey97f8aef2010-04-07 21:54:42 -0700418 void __user *useraddr)
Jeff Garzik723b2f52010-03-03 22:51:50 +0000419{
420 struct ethtool_sset_info info;
Jeff Garzik723b2f52010-03-03 22:51:50 +0000421 u64 sset_mask;
422 int i, idx = 0, n_bits = 0, ret, rc;
423 u32 *info_buf = NULL;
424
Jeff Garzik723b2f52010-03-03 22:51:50 +0000425 if (copy_from_user(&info, useraddr, sizeof(info)))
426 return -EFAULT;
427
428 /* store copy of mask, because we zero struct later on */
429 sset_mask = info.sset_mask;
430 if (!sset_mask)
431 return 0;
432
433 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000434 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000435
436 memset(&info, 0, sizeof(info));
437 info.cmd = ETHTOOL_GSSET_INFO;
438
439 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
440 if (!info_buf)
441 return -ENOMEM;
442
443 /*
444 * fill return buffer based on input bitmask and successful
445 * get_sset_count return
446 */
447 for (i = 0; i < 64; i++) {
448 if (!(sset_mask & (1ULL << i)))
449 continue;
450
Michał Mirosław340ae162011-02-15 16:59:16 +0000451 rc = __ethtool_get_sset_count(dev, i);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000452 if (rc >= 0) {
453 info.sset_mask |= (1ULL << i);
454 info_buf[idx++] = rc;
455 }
456 }
457
458 ret = -EFAULT;
459 if (copy_to_user(useraddr, &info, sizeof(info)))
460 goto out;
461
462 useraddr += offsetof(struct ethtool_sset_info, data);
463 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
464 goto out;
465
466 ret = 0;
467
468out:
469 kfree(info_buf);
470 return ret;
471}
472
chavey97f8aef2010-04-07 21:54:42 -0700473static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000474 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700475{
Ben Hutchingsbf988432010-06-28 08:45:58 +0000476 struct ethtool_rxnfc info;
477 size_t info_size = sizeof(info);
Ben Hutchings55664f32012-01-03 12:04:51 +0000478 int rc;
Santwona Behera0853ad62008-07-02 03:47:41 -0700479
Santwona Behera59089d82009-02-20 00:58:13 -0800480 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700481 return -EOPNOTSUPP;
482
Ben Hutchingsbf988432010-06-28 08:45:58 +0000483 /* struct ethtool_rxnfc was originally defined for
484 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
485 * members. User-space might still be using that
486 * definition. */
487 if (cmd == ETHTOOL_SRXFH)
488 info_size = (offsetof(struct ethtool_rxnfc, data) +
489 sizeof(info.data));
490
491 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700492 return -EFAULT;
493
Ben Hutchings55664f32012-01-03 12:04:51 +0000494 rc = dev->ethtool_ops->set_rxnfc(dev, &info);
495 if (rc)
496 return rc;
497
498 if (cmd == ETHTOOL_SRXCLSRLINS &&
499 copy_to_user(useraddr, &info, info_size))
500 return -EFAULT;
501
502 return 0;
Santwona Behera0853ad62008-07-02 03:47:41 -0700503}
504
chavey97f8aef2010-04-07 21:54:42 -0700505static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000506 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700507{
508 struct ethtool_rxnfc info;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000509 size_t info_size = sizeof(info);
Santwona Behera59089d82009-02-20 00:58:13 -0800510 const struct ethtool_ops *ops = dev->ethtool_ops;
511 int ret;
512 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700513
Santwona Behera59089d82009-02-20 00:58:13 -0800514 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700515 return -EOPNOTSUPP;
516
Ben Hutchingsbf988432010-06-28 08:45:58 +0000517 /* struct ethtool_rxnfc was originally defined for
518 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
519 * members. User-space might still be using that
520 * definition. */
521 if (cmd == ETHTOOL_GRXFH)
522 info_size = (offsetof(struct ethtool_rxnfc, data) +
523 sizeof(info.data));
524
525 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700526 return -EFAULT;
527
Santwona Behera59089d82009-02-20 00:58:13 -0800528 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
529 if (info.rule_cnt > 0) {
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000530 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
Kees Cookae6df5f2010-10-07 10:03:48 +0000531 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000532 GFP_USER);
Santwona Behera59089d82009-02-20 00:58:13 -0800533 if (!rule_buf)
534 return -ENOMEM;
535 }
536 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700537
Santwona Behera59089d82009-02-20 00:58:13 -0800538 ret = ops->get_rxnfc(dev, &info, rule_buf);
539 if (ret < 0)
540 goto err_out;
541
542 ret = -EFAULT;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000543 if (copy_to_user(useraddr, &info, info_size))
Santwona Behera59089d82009-02-20 00:58:13 -0800544 goto err_out;
545
546 if (rule_buf) {
547 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
548 if (copy_to_user(useraddr, rule_buf,
549 info.rule_cnt * sizeof(u32)))
550 goto err_out;
551 }
552 ret = 0;
553
554err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700555 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800556
557 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700558}
559
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530560static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr,
561 struct ethtool_rxnfc *rx_rings,
562 u32 size)
563{
Ben Hutchingsfb95cd82014-05-15 00:46:45 +0100564 int i;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530565
566 if (copy_from_user(indir, useraddr, size * sizeof(indir[0])))
Ben Hutchingsfb95cd82014-05-15 00:46:45 +0100567 return -EFAULT;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530568
569 /* Validate ring indices */
Ben Hutchingsfb95cd82014-05-15 00:46:45 +0100570 for (i = 0; i < size; i++)
571 if (indir[i] >= rx_rings->data)
572 return -EINVAL;
573
574 return 0;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530575}
576
Eric Dumazet960fb622014-11-16 06:23:05 -0800577u8 netdev_rss_key[NETDEV_RSS_KEY_LEN];
578
579void netdev_rss_key_fill(void *buffer, size_t len)
580{
581 BUG_ON(len > sizeof(netdev_rss_key));
582 net_get_random_once(netdev_rss_key, sizeof(netdev_rss_key));
583 memcpy(buffer, netdev_rss_key, len);
584}
585EXPORT_SYMBOL(netdev_rss_key_fill);
586
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000587static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
588 void __user *useraddr)
589{
Ben Hutchings7850f632011-12-15 13:55:01 +0000590 u32 user_size, dev_size;
591 u32 *indir;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000592 int ret;
593
Ben Hutchings7850f632011-12-15 13:55:01 +0000594 if (!dev->ethtool_ops->get_rxfh_indir_size ||
Ben Hutchingsfe62d002014-05-15 01:25:27 +0100595 !dev->ethtool_ops->get_rxfh)
Ben Hutchings7850f632011-12-15 13:55:01 +0000596 return -EOPNOTSUPP;
597 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
598 if (dev_size == 0)
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000599 return -EOPNOTSUPP;
600
Ben Hutchings7850f632011-12-15 13:55:01 +0000601 if (copy_from_user(&user_size,
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000602 useraddr + offsetof(struct ethtool_rxfh_indir, size),
Ben Hutchings7850f632011-12-15 13:55:01 +0000603 sizeof(user_size)))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000604 return -EFAULT;
605
Ben Hutchings7850f632011-12-15 13:55:01 +0000606 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
607 &dev_size, sizeof(dev_size)))
608 return -EFAULT;
609
610 /* If the user buffer size is 0, this is just a query for the
611 * device table size. Otherwise, if it's smaller than the
612 * device table size it's an error.
613 */
614 if (user_size < dev_size)
615 return user_size == 0 ? 0 : -EINVAL;
616
617 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000618 if (!indir)
619 return -ENOMEM;
620
Ben Hutchingsfe62d002014-05-15 01:25:27 +0100621 ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000622 if (ret)
623 goto out;
624
Ben Hutchings7850f632011-12-15 13:55:01 +0000625 if (copy_to_user(useraddr +
626 offsetof(struct ethtool_rxfh_indir, ring_index[0]),
627 indir, dev_size * sizeof(indir[0])))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000628 ret = -EFAULT;
629
630out:
631 kfree(indir);
632 return ret;
633}
634
635static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
636 void __user *useraddr)
637{
Ben Hutchings7850f632011-12-15 13:55:01 +0000638 struct ethtool_rxnfc rx_rings;
639 u32 user_size, dev_size, i;
640 u32 *indir;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000641 const struct ethtool_ops *ops = dev->ethtool_ops;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000642 int ret;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530643 u32 ringidx_offset = offsetof(struct ethtool_rxfh_indir, ring_index[0]);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000644
Ben Hutchingsfe62d002014-05-15 01:25:27 +0100645 if (!ops->get_rxfh_indir_size || !ops->set_rxfh ||
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000646 !ops->get_rxnfc)
Ben Hutchings7850f632011-12-15 13:55:01 +0000647 return -EOPNOTSUPP;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000648
649 dev_size = ops->get_rxfh_indir_size(dev);
Ben Hutchings7850f632011-12-15 13:55:01 +0000650 if (dev_size == 0)
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000651 return -EOPNOTSUPP;
652
Ben Hutchings7850f632011-12-15 13:55:01 +0000653 if (copy_from_user(&user_size,
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000654 useraddr + offsetof(struct ethtool_rxfh_indir, size),
Ben Hutchings7850f632011-12-15 13:55:01 +0000655 sizeof(user_size)))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000656 return -EFAULT;
657
Ben Hutchings278bc422011-12-15 13:56:49 +0000658 if (user_size != 0 && user_size != dev_size)
Ben Hutchings7850f632011-12-15 13:55:01 +0000659 return -EINVAL;
660
661 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000662 if (!indir)
663 return -ENOMEM;
664
Ben Hutchings7850f632011-12-15 13:55:01 +0000665 rx_rings.cmd = ETHTOOL_GRXRINGS;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000666 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
Ben Hutchings7850f632011-12-15 13:55:01 +0000667 if (ret)
668 goto out;
Ben Hutchings278bc422011-12-15 13:56:49 +0000669
670 if (user_size == 0) {
671 for (i = 0; i < dev_size; i++)
672 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
673 } else {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530674 ret = ethtool_copy_validate_indir(indir,
675 useraddr + ringidx_offset,
676 &rx_rings,
677 dev_size);
678 if (ret)
Ben Hutchings7850f632011-12-15 13:55:01 +0000679 goto out;
Ben Hutchings7850f632011-12-15 13:55:01 +0000680 }
681
Ben Hutchingsfe62d002014-05-15 01:25:27 +0100682 ret = ops->set_rxfh(dev, indir, NULL);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000683
684out:
685 kfree(indir);
686 return ret;
687}
688
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530689static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev,
690 void __user *useraddr)
691{
692 int ret;
693 const struct ethtool_ops *ops = dev->ethtool_ops;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100694 u32 user_indir_size, user_key_size;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530695 u32 dev_indir_size = 0, dev_key_size = 0;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100696 struct ethtool_rxfh rxfh;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530697 u32 total_size;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100698 u32 indir_bytes;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530699 u32 *indir = NULL;
700 u8 *hkey = NULL;
701 u8 *rss_config;
702
703 if (!(dev->ethtool_ops->get_rxfh_indir_size ||
704 dev->ethtool_ops->get_rxfh_key_size) ||
705 !dev->ethtool_ops->get_rxfh)
706 return -EOPNOTSUPP;
707
708 if (ops->get_rxfh_indir_size)
709 dev_indir_size = ops->get_rxfh_indir_size(dev);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530710 if (ops->get_rxfh_key_size)
711 dev_key_size = ops->get_rxfh_key_size(dev);
712
713 if ((dev_key_size + dev_indir_size) == 0)
714 return -EOPNOTSUPP;
715
Ben Hutchingsf062a382014-05-15 16:28:07 +0100716 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530717 return -EFAULT;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100718 user_indir_size = rxfh.indir_size;
719 user_key_size = rxfh.key_size;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530720
Ben Hutchingsf062a382014-05-15 16:28:07 +0100721 /* Check that reserved fields are 0 for now */
722 if (rxfh.rss_context || rxfh.rsvd[0] || rxfh.rsvd[1])
723 return -EINVAL;
724
725 rxfh.indir_size = dev_indir_size;
726 rxfh.key_size = dev_key_size;
727 if (copy_to_user(useraddr, &rxfh, sizeof(rxfh)))
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530728 return -EFAULT;
729
730 /* If the user buffer size is 0, this is just a query for the
731 * device table size and key size. Otherwise, if the User size is
732 * not equal to device table size or key size it's an error.
733 */
734 if (!user_indir_size && !user_key_size)
735 return 0;
736
737 if ((user_indir_size && (user_indir_size != dev_indir_size)) ||
738 (user_key_size && (user_key_size != dev_key_size)))
739 return -EINVAL;
740
741 indir_bytes = user_indir_size * sizeof(indir[0]);
742 total_size = indir_bytes + user_key_size;
743 rss_config = kzalloc(total_size, GFP_USER);
744 if (!rss_config)
745 return -ENOMEM;
746
747 if (user_indir_size)
748 indir = (u32 *)rss_config;
749
750 if (user_key_size)
751 hkey = rss_config + indir_bytes;
752
753 ret = dev->ethtool_ops->get_rxfh(dev, indir, hkey);
754 if (!ret) {
755 if (copy_to_user(useraddr +
756 offsetof(struct ethtool_rxfh, rss_config[0]),
757 rss_config, total_size))
758 ret = -EFAULT;
759 }
760
761 kfree(rss_config);
762
763 return ret;
764}
765
766static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
767 void __user *useraddr)
768{
769 int ret;
770 const struct ethtool_ops *ops = dev->ethtool_ops;
771 struct ethtool_rxnfc rx_rings;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100772 struct ethtool_rxfh rxfh;
773 u32 dev_indir_size = 0, dev_key_size = 0, i;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530774 u32 *indir = NULL, indir_bytes = 0;
775 u8 *hkey = NULL;
776 u8 *rss_config;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530777 u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]);
778
779 if (!(ops->get_rxfh_indir_size || ops->get_rxfh_key_size) ||
780 !ops->get_rxnfc || !ops->set_rxfh)
781 return -EOPNOTSUPP;
782
783 if (ops->get_rxfh_indir_size)
784 dev_indir_size = ops->get_rxfh_indir_size(dev);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530785 if (ops->get_rxfh_key_size)
786 dev_key_size = dev->ethtool_ops->get_rxfh_key_size(dev);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530787 if ((dev_key_size + dev_indir_size) == 0)
788 return -EOPNOTSUPP;
789
Ben Hutchingsf062a382014-05-15 16:28:07 +0100790 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530791 return -EFAULT;
792
Ben Hutchingsf062a382014-05-15 16:28:07 +0100793 /* Check that reserved fields are 0 for now */
794 if (rxfh.rss_context || rxfh.rsvd[0] || rxfh.rsvd[1])
795 return -EINVAL;
796
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530797 /* If either indir or hash key is valid, proceed further.
Ben Hutchings61d88c62014-05-19 01:29:42 +0100798 * It is not valid to request that both be unchanged.
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530799 */
Ben Hutchingsf062a382014-05-15 16:28:07 +0100800 if ((rxfh.indir_size &&
801 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE &&
802 rxfh.indir_size != dev_indir_size) ||
803 (rxfh.key_size && (rxfh.key_size != dev_key_size)) ||
804 (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE &&
805 rxfh.key_size == 0))
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530806 return -EINVAL;
807
Ben Hutchingsf062a382014-05-15 16:28:07 +0100808 if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE)
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530809 indir_bytes = dev_indir_size * sizeof(indir[0]);
810
Ben Hutchingsf062a382014-05-15 16:28:07 +0100811 rss_config = kzalloc(indir_bytes + rxfh.key_size, GFP_USER);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530812 if (!rss_config)
813 return -ENOMEM;
814
815 rx_rings.cmd = ETHTOOL_GRXRINGS;
816 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
817 if (ret)
818 goto out;
819
Ben Hutchingsf062a382014-05-15 16:28:07 +0100820 /* rxfh.indir_size == 0 means reset the indir table to default.
821 * rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE means leave it unchanged.
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530822 */
Ben Hutchingsf062a382014-05-15 16:28:07 +0100823 if (rxfh.indir_size &&
824 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530825 indir = (u32 *)rss_config;
826 ret = ethtool_copy_validate_indir(indir,
827 useraddr + rss_cfg_offset,
828 &rx_rings,
Ben Hutchingsf062a382014-05-15 16:28:07 +0100829 rxfh.indir_size);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530830 if (ret)
831 goto out;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100832 } else if (rxfh.indir_size == 0) {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530833 indir = (u32 *)rss_config;
834 for (i = 0; i < dev_indir_size; i++)
835 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
836 }
837
Ben Hutchingsf062a382014-05-15 16:28:07 +0100838 if (rxfh.key_size) {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530839 hkey = rss_config + indir_bytes;
840 if (copy_from_user(hkey,
841 useraddr + rss_cfg_offset + indir_bytes,
Ben Hutchingsf062a382014-05-15 16:28:07 +0100842 rxfh.key_size)) {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530843 ret = -EFAULT;
844 goto out;
845 }
846 }
847
848 ret = ops->set_rxfh(dev, indir, hkey);
849
850out:
851 kfree(rss_config);
852 return ret;
853}
854
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
856{
857 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700858 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 void *regbuf;
860 int reglen, ret;
861
862 if (!ops->get_regs || !ops->get_regs_len)
863 return -EOPNOTSUPP;
864
865 if (copy_from_user(&regs, useraddr, sizeof(regs)))
866 return -EFAULT;
867
868 reglen = ops->get_regs_len(dev);
869 if (regs.len > reglen)
870 regs.len = reglen;
871
Eugene Teob7c7d012011-01-24 21:05:17 -0800872 regbuf = vzalloc(reglen);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700873 if (reglen && !regbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 return -ENOMEM;
875
876 ops->get_regs(dev, &regs, regbuf);
877
878 ret = -EFAULT;
879 if (copy_to_user(useraddr, &regs, sizeof(regs)))
880 goto out;
881 useraddr += offsetof(struct ethtool_regs, data);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700882 if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 goto out;
884 ret = 0;
885
886 out:
Ben Hutchingsa77f5db2010-09-20 08:42:17 +0000887 vfree(regbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 return ret;
889}
890
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000891static int ethtool_reset(struct net_device *dev, char __user *useraddr)
892{
893 struct ethtool_value reset;
894 int ret;
895
896 if (!dev->ethtool_ops->reset)
897 return -EOPNOTSUPP;
898
899 if (copy_from_user(&reset, useraddr, sizeof(reset)))
900 return -EFAULT;
901
902 ret = dev->ethtool_ops->reset(dev, &reset.data);
903 if (ret)
904 return ret;
905
906 if (copy_to_user(useraddr, &reset, sizeof(reset)))
907 return -EFAULT;
908 return 0;
909}
910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
912{
Roland Dreier8e557422010-02-11 12:14:23 -0800913 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 if (!dev->ethtool_ops->get_wol)
916 return -EOPNOTSUPP;
917
918 dev->ethtool_ops->get_wol(dev, &wol);
919
920 if (copy_to_user(useraddr, &wol, sizeof(wol)))
921 return -EFAULT;
922 return 0;
923}
924
925static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
926{
927 struct ethtool_wolinfo wol;
928
929 if (!dev->ethtool_ops->set_wol)
930 return -EOPNOTSUPP;
931
932 if (copy_from_user(&wol, useraddr, sizeof(wol)))
933 return -EFAULT;
934
935 return dev->ethtool_ops->set_wol(dev, &wol);
936}
937
Yuval Mintz80f12ec2012-06-06 17:13:06 +0000938static int ethtool_get_eee(struct net_device *dev, char __user *useraddr)
939{
940 struct ethtool_eee edata;
941 int rc;
942
943 if (!dev->ethtool_ops->get_eee)
944 return -EOPNOTSUPP;
945
946 memset(&edata, 0, sizeof(struct ethtool_eee));
947 edata.cmd = ETHTOOL_GEEE;
948 rc = dev->ethtool_ops->get_eee(dev, &edata);
949
950 if (rc)
951 return rc;
952
953 if (copy_to_user(useraddr, &edata, sizeof(edata)))
954 return -EFAULT;
955
956 return 0;
957}
958
959static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
960{
961 struct ethtool_eee edata;
962
963 if (!dev->ethtool_ops->set_eee)
964 return -EOPNOTSUPP;
965
966 if (copy_from_user(&edata, useraddr, sizeof(edata)))
967 return -EFAULT;
968
969 return dev->ethtool_ops->set_eee(dev, &edata);
970}
971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972static int ethtool_nway_reset(struct net_device *dev)
973{
974 if (!dev->ethtool_ops->nway_reset)
975 return -EOPNOTSUPP;
976
977 return dev->ethtool_ops->nway_reset(dev);
978}
979
Ben Hutchingse596e6e2010-12-09 12:08:35 +0000980static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
981{
982 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
983
984 if (!dev->ethtool_ops->get_link)
985 return -EOPNOTSUPP;
986
987 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
988
989 if (copy_to_user(useraddr, &edata, sizeof(edata)))
990 return -EFAULT;
991 return 0;
992}
993
Ben Hutchings081d0942012-04-12 00:42:12 +0000994static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr,
995 int (*getter)(struct net_device *,
996 struct ethtool_eeprom *, u8 *),
997 u32 total_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998{
999 struct ethtool_eeprom eeprom;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001000 void __user *userbuf = useraddr + sizeof(eeprom);
1001 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001003 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1006 return -EFAULT;
1007
1008 /* Check for wrap and zero */
1009 if (eeprom.offset + eeprom.len <= eeprom.offset)
1010 return -EINVAL;
1011
1012 /* Check for exceeding total eeprom len */
Ben Hutchings081d0942012-04-12 00:42:12 +00001013 if (eeprom.offset + eeprom.len > total_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 return -EINVAL;
1015
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001016 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 if (!data)
1018 return -ENOMEM;
1019
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001020 bytes_remaining = eeprom.len;
1021 while (bytes_remaining > 0) {
1022 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Ben Hutchings081d0942012-04-12 00:42:12 +00001024 ret = getter(dev, &eeprom, data);
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001025 if (ret)
1026 break;
1027 if (copy_to_user(userbuf, data, eeprom.len)) {
1028 ret = -EFAULT;
1029 break;
1030 }
1031 userbuf += eeprom.len;
1032 eeprom.offset += eeprom.len;
1033 bytes_remaining -= eeprom.len;
1034 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -07001036 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
1037 eeprom.offset -= eeprom.len;
1038 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
1039 ret = -EFAULT;
1040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 kfree(data);
1042 return ret;
1043}
1044
Ben Hutchings081d0942012-04-12 00:42:12 +00001045static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
1046{
1047 const struct ethtool_ops *ops = dev->ethtool_ops;
1048
Guenter Roecke0fb6fb2014-10-30 20:50:15 -07001049 if (!ops->get_eeprom || !ops->get_eeprom_len ||
1050 !ops->get_eeprom_len(dev))
Ben Hutchings081d0942012-04-12 00:42:12 +00001051 return -EOPNOTSUPP;
1052
1053 return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom,
1054 ops->get_eeprom_len(dev));
1055}
1056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
1058{
1059 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001060 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001061 void __user *userbuf = useraddr + sizeof(eeprom);
1062 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001064 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Guenter Roecke0fb6fb2014-10-30 20:50:15 -07001066 if (!ops->set_eeprom || !ops->get_eeprom_len ||
1067 !ops->get_eeprom_len(dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 return -EOPNOTSUPP;
1069
1070 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1071 return -EFAULT;
1072
1073 /* Check for wrap and zero */
1074 if (eeprom.offset + eeprom.len <= eeprom.offset)
1075 return -EINVAL;
1076
1077 /* Check for exceeding total eeprom len */
1078 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
1079 return -EINVAL;
1080
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001081 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 if (!data)
1083 return -ENOMEM;
1084
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001085 bytes_remaining = eeprom.len;
1086 while (bytes_remaining > 0) {
1087 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001089 if (copy_from_user(data, userbuf, eeprom.len)) {
1090 ret = -EFAULT;
1091 break;
1092 }
1093 ret = ops->set_eeprom(dev, &eeprom, data);
1094 if (ret)
1095 break;
1096 userbuf += eeprom.len;
1097 eeprom.offset += eeprom.len;
1098 bytes_remaining -= eeprom.len;
1099 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 kfree(data);
1102 return ret;
1103}
1104
chavey97f8aef2010-04-07 21:54:42 -07001105static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
1106 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107{
Roland Dreier8e557422010-02-11 12:14:23 -08001108 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
1110 if (!dev->ethtool_ops->get_coalesce)
1111 return -EOPNOTSUPP;
1112
1113 dev->ethtool_ops->get_coalesce(dev, &coalesce);
1114
1115 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
1116 return -EFAULT;
1117 return 0;
1118}
1119
chavey97f8aef2010-04-07 21:54:42 -07001120static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
1121 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122{
1123 struct ethtool_coalesce coalesce;
1124
David S. Millerfa04ae52005-06-06 15:07:19 -07001125 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 return -EOPNOTSUPP;
1127
1128 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
1129 return -EFAULT;
1130
1131 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
1132}
1133
1134static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
1135{
Roland Dreier8e557422010-02-11 12:14:23 -08001136 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
1138 if (!dev->ethtool_ops->get_ringparam)
1139 return -EOPNOTSUPP;
1140
1141 dev->ethtool_ops->get_ringparam(dev, &ringparam);
1142
1143 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
1144 return -EFAULT;
1145 return 0;
1146}
1147
1148static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
1149{
1150 struct ethtool_ringparam ringparam;
1151
1152 if (!dev->ethtool_ops->set_ringparam)
1153 return -EOPNOTSUPP;
1154
1155 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
1156 return -EFAULT;
1157
1158 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
1159}
1160
amit salecha8b5933c32011-04-07 01:58:42 +00001161static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
1162 void __user *useraddr)
1163{
1164 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
1165
1166 if (!dev->ethtool_ops->get_channels)
1167 return -EOPNOTSUPP;
1168
1169 dev->ethtool_ops->get_channels(dev, &channels);
1170
1171 if (copy_to_user(useraddr, &channels, sizeof(channels)))
1172 return -EFAULT;
1173 return 0;
1174}
1175
1176static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
1177 void __user *useraddr)
1178{
1179 struct ethtool_channels channels;
1180
1181 if (!dev->ethtool_ops->set_channels)
1182 return -EOPNOTSUPP;
1183
1184 if (copy_from_user(&channels, useraddr, sizeof(channels)))
1185 return -EFAULT;
1186
1187 return dev->ethtool_ops->set_channels(dev, &channels);
1188}
1189
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
1191{
1192 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
1193
1194 if (!dev->ethtool_ops->get_pauseparam)
1195 return -EOPNOTSUPP;
1196
1197 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
1198
1199 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
1200 return -EFAULT;
1201 return 0;
1202}
1203
1204static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
1205{
1206 struct ethtool_pauseparam pauseparam;
1207
Jeff Garzike1b90c42006-07-17 12:54:40 -04001208 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 return -EOPNOTSUPP;
1210
1211 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
1212 return -EFAULT;
1213
1214 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
1215}
1216
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1218{
1219 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001220 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001222 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001224 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001225 return -EOPNOTSUPP;
1226
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001227 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -07001228 if (test_len < 0)
1229 return test_len;
1230 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
1232 if (copy_from_user(&test, useraddr, sizeof(test)))
1233 return -EFAULT;
1234
Jeff Garzikff03d492007-08-15 16:01:08 -07001235 test.len = test_len;
1236 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 if (!data)
1238 return -ENOMEM;
1239
1240 ops->self_test(dev, &test, data);
1241
1242 ret = -EFAULT;
1243 if (copy_to_user(useraddr, &test, sizeof(test)))
1244 goto out;
1245 useraddr += sizeof(test);
1246 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1247 goto out;
1248 ret = 0;
1249
1250 out:
1251 kfree(data);
1252 return ret;
1253}
1254
1255static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1256{
1257 struct ethtool_gstrings gstrings;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 u8 *data;
1259 int ret;
1260
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1262 return -EFAULT;
1263
Michał Mirosław340ae162011-02-15 16:59:16 +00001264 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001265 if (ret < 0)
1266 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001267
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001268 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
1270 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1271 if (!data)
1272 return -ENOMEM;
1273
Michał Mirosław340ae162011-02-15 16:59:16 +00001274 __ethtool_get_strings(dev, gstrings.string_set, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276 ret = -EFAULT;
1277 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1278 goto out;
1279 useraddr += sizeof(gstrings);
1280 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1281 goto out;
1282 ret = 0;
1283
Michał Mirosław340ae162011-02-15 16:59:16 +00001284out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 kfree(data);
1286 return ret;
1287}
1288
1289static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1290{
1291 struct ethtool_value id;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001292 static bool busy;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001293 const struct ethtool_ops *ops = dev->ethtool_ops;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001294 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001296 if (!ops->set_phys_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 return -EOPNOTSUPP;
1298
Ben Hutchings68f512f2011-04-02 00:35:15 +01001299 if (busy)
1300 return -EBUSY;
1301
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 if (copy_from_user(&id, useraddr, sizeof(id)))
1303 return -EFAULT;
1304
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001305 rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001306 if (rc < 0)
Ben Hutchings68f512f2011-04-02 00:35:15 +01001307 return rc;
1308
1309 /* Drop the RTNL lock while waiting, but prevent reentry or
1310 * removal of the device.
1311 */
1312 busy = true;
1313 dev_hold(dev);
1314 rtnl_unlock();
1315
1316 if (rc == 0) {
1317 /* Driver will handle this itself */
1318 schedule_timeout_interruptible(
Allan, Bruce W143780c2011-04-11 13:01:59 +00001319 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001320 } else {
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001321 /* Driver expects to be called at twice the frequency in rc */
1322 int n = rc * 2, i, interval = HZ / n;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001323
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001324 /* Count down seconds */
1325 do {
1326 /* Count down iterations per second */
1327 i = n;
1328 do {
1329 rtnl_lock();
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001330 rc = ops->set_phys_id(dev,
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001331 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1332 rtnl_unlock();
1333 if (rc)
1334 break;
1335 schedule_timeout_interruptible(interval);
1336 } while (!signal_pending(current) && --i != 0);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001337 } while (!signal_pending(current) &&
1338 (id.data == 0 || --id.data != 0));
1339 }
1340
1341 rtnl_lock();
1342 dev_put(dev);
1343 busy = false;
1344
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001345 (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001346 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
1349static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1350{
1351 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001352 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001354 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001356 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001357 return -EOPNOTSUPP;
1358
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001359 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001360 if (n_stats < 0)
1361 return n_stats;
1362 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
1364 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1365 return -EFAULT;
1366
Jeff Garzikff03d492007-08-15 16:01:08 -07001367 stats.n_stats = n_stats;
1368 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 if (!data)
1370 return -ENOMEM;
1371
1372 ops->get_ethtool_stats(dev, &stats, data);
1373
1374 ret = -EFAULT;
1375 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1376 goto out;
1377 useraddr += sizeof(stats);
1378 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1379 goto out;
1380 ret = 0;
1381
1382 out:
1383 kfree(data);
1384 return ret;
1385}
1386
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001387static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001388{
1389 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001390
Matthew Wilcox313674a2007-07-31 14:00:29 -07001391 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001392 return -EFAULT;
1393
Matthew Wilcox313674a2007-07-31 14:00:29 -07001394 if (epaddr.size < dev->addr_len)
1395 return -ETOOSMALL;
1396 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001397
Jon Wetzela6f9a702005-08-20 17:15:54 -07001398 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001399 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001400 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001401 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1402 return -EFAULT;
1403 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001404}
1405
Jeff Garzik13c99b22007-08-15 16:01:56 -07001406static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1407 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001408{
Roland Dreier8e557422010-02-11 12:14:23 -08001409 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001410
Jeff Garzik13c99b22007-08-15 16:01:56 -07001411 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001412 return -EOPNOTSUPP;
1413
Jeff Garzik13c99b22007-08-15 16:01:56 -07001414 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001415
1416 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1417 return -EFAULT;
1418 return 0;
1419}
1420
Jeff Garzik13c99b22007-08-15 16:01:56 -07001421static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1422 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001423{
1424 struct ethtool_value edata;
1425
Jeff Garzik13c99b22007-08-15 16:01:56 -07001426 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001427 return -EOPNOTSUPP;
1428
1429 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1430 return -EFAULT;
1431
Jeff Garzik13c99b22007-08-15 16:01:56 -07001432 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001433 return 0;
1434}
1435
Jeff Garzik13c99b22007-08-15 16:01:56 -07001436static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1437 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001438{
1439 struct ethtool_value edata;
1440
Jeff Garzik13c99b22007-08-15 16:01:56 -07001441 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001442 return -EOPNOTSUPP;
1443
1444 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1445 return -EFAULT;
1446
Jeff Garzik13c99b22007-08-15 16:01:56 -07001447 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001448}
1449
chavey97f8aef2010-04-07 21:54:42 -07001450static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1451 char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001452{
1453 struct ethtool_flash efl;
1454
1455 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1456 return -EFAULT;
1457
1458 if (!dev->ethtool_ops->flash_device)
1459 return -EOPNOTSUPP;
1460
Ben Hutchings786f5282012-02-01 09:32:25 +00001461 efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
1462
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001463 return dev->ethtool_ops->flash_device(dev, &efl);
1464}
1465
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001466static int ethtool_set_dump(struct net_device *dev,
1467 void __user *useraddr)
1468{
1469 struct ethtool_dump dump;
1470
1471 if (!dev->ethtool_ops->set_dump)
1472 return -EOPNOTSUPP;
1473
1474 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1475 return -EFAULT;
1476
1477 return dev->ethtool_ops->set_dump(dev, &dump);
1478}
1479
1480static int ethtool_get_dump_flag(struct net_device *dev,
1481 void __user *useraddr)
1482{
1483 int ret;
1484 struct ethtool_dump dump;
1485 const struct ethtool_ops *ops = dev->ethtool_ops;
1486
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001487 if (!ops->get_dump_flag)
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001488 return -EOPNOTSUPP;
1489
1490 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1491 return -EFAULT;
1492
1493 ret = ops->get_dump_flag(dev, &dump);
1494 if (ret)
1495 return ret;
1496
1497 if (copy_to_user(useraddr, &dump, sizeof(dump)))
1498 return -EFAULT;
1499 return 0;
1500}
1501
1502static int ethtool_get_dump_data(struct net_device *dev,
1503 void __user *useraddr)
1504{
1505 int ret;
1506 __u32 len;
1507 struct ethtool_dump dump, tmp;
1508 const struct ethtool_ops *ops = dev->ethtool_ops;
1509 void *data = NULL;
1510
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001511 if (!ops->get_dump_data || !ops->get_dump_flag)
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001512 return -EOPNOTSUPP;
1513
1514 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1515 return -EFAULT;
1516
1517 memset(&tmp, 0, sizeof(tmp));
1518 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
1519 ret = ops->get_dump_flag(dev, &tmp);
1520 if (ret)
1521 return ret;
1522
Michal Schmidtc590b5e2013-07-01 17:23:30 +02001523 len = min(tmp.len, dump.len);
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001524 if (!len)
1525 return -EFAULT;
1526
Michal Schmidtc590b5e2013-07-01 17:23:30 +02001527 /* Don't ever let the driver think there's more space available
1528 * than it requested with .get_dump_flag().
1529 */
1530 dump.len = len;
1531
1532 /* Always allocate enough space to hold the whole thing so that the
1533 * driver does not need to check the length and bother with partial
1534 * dumping.
1535 */
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001536 data = vzalloc(tmp.len);
1537 if (!data)
1538 return -ENOMEM;
1539 ret = ops->get_dump_data(dev, &dump, data);
1540 if (ret)
1541 goto out;
1542
Michal Schmidtc590b5e2013-07-01 17:23:30 +02001543 /* There are two sane possibilities:
1544 * 1. The driver's .get_dump_data() does not touch dump.len.
1545 * 2. Or it may set dump.len to how much it really writes, which
1546 * should be tmp.len (or len if it can do a partial dump).
1547 * In any case respond to userspace with the actual length of data
1548 * it's receiving.
1549 */
1550 WARN_ON(dump.len != len && dump.len != tmp.len);
1551 dump.len = len;
1552
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001553 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1554 ret = -EFAULT;
1555 goto out;
1556 }
1557 useraddr += offsetof(struct ethtool_dump, data);
1558 if (copy_to_user(useraddr, data, len))
1559 ret = -EFAULT;
1560out:
1561 vfree(data);
1562 return ret;
1563}
1564
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001565static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
1566{
1567 int err = 0;
1568 struct ethtool_ts_info info;
1569 const struct ethtool_ops *ops = dev->ethtool_ops;
1570 struct phy_device *phydev = dev->phydev;
1571
1572 memset(&info, 0, sizeof(info));
1573 info.cmd = ETHTOOL_GET_TS_INFO;
1574
1575 if (phydev && phydev->drv && phydev->drv->ts_info) {
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001576 err = phydev->drv->ts_info(phydev, &info);
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001577 } else if (ops->get_ts_info) {
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001578 err = ops->get_ts_info(dev, &info);
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001579 } else {
1580 info.so_timestamping =
1581 SOF_TIMESTAMPING_RX_SOFTWARE |
1582 SOF_TIMESTAMPING_SOFTWARE;
1583 info.phc_index = -1;
1584 }
1585
1586 if (err)
1587 return err;
1588
1589 if (copy_to_user(useraddr, &info, sizeof(info)))
1590 err = -EFAULT;
1591
1592 return err;
1593}
1594
Stuart Hodgson41c3cb62012-04-19 09:44:42 +01001595static int ethtool_get_module_info(struct net_device *dev,
1596 void __user *useraddr)
1597{
1598 int ret;
1599 struct ethtool_modinfo modinfo;
1600 const struct ethtool_ops *ops = dev->ethtool_ops;
1601
1602 if (!ops->get_module_info)
1603 return -EOPNOTSUPP;
1604
1605 if (copy_from_user(&modinfo, useraddr, sizeof(modinfo)))
1606 return -EFAULT;
1607
1608 ret = ops->get_module_info(dev, &modinfo);
1609 if (ret)
1610 return ret;
1611
1612 if (copy_to_user(useraddr, &modinfo, sizeof(modinfo)))
1613 return -EFAULT;
1614
1615 return 0;
1616}
1617
1618static int ethtool_get_module_eeprom(struct net_device *dev,
1619 void __user *useraddr)
1620{
1621 int ret;
1622 struct ethtool_modinfo modinfo;
1623 const struct ethtool_ops *ops = dev->ethtool_ops;
1624
1625 if (!ops->get_module_info || !ops->get_module_eeprom)
1626 return -EOPNOTSUPP;
1627
1628 ret = ops->get_module_info(dev, &modinfo);
1629 if (ret)
1630 return ret;
1631
1632 return ethtool_get_any_eeprom(dev, useraddr, ops->get_module_eeprom,
1633 modinfo.eeprom_len);
1634}
1635
Govindarajulu Varadarajanf0db9b02014-09-03 03:17:20 +05301636static int ethtool_tunable_valid(const struct ethtool_tunable *tuna)
1637{
1638 switch (tuna->id) {
1639 case ETHTOOL_RX_COPYBREAK:
Eric Dumazet1255a502014-10-05 12:35:21 +03001640 case ETHTOOL_TX_COPYBREAK:
Govindarajulu Varadarajanf0db9b02014-09-03 03:17:20 +05301641 if (tuna->len != sizeof(u32) ||
1642 tuna->type_id != ETHTOOL_TUNABLE_U32)
1643 return -EINVAL;
1644 break;
1645 default:
1646 return -EINVAL;
1647 }
1648
1649 return 0;
1650}
1651
1652static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr)
1653{
1654 int ret;
1655 struct ethtool_tunable tuna;
1656 const struct ethtool_ops *ops = dev->ethtool_ops;
1657 void *data;
1658
1659 if (!ops->get_tunable)
1660 return -EOPNOTSUPP;
1661 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
1662 return -EFAULT;
1663 ret = ethtool_tunable_valid(&tuna);
1664 if (ret)
1665 return ret;
1666 data = kmalloc(tuna.len, GFP_USER);
1667 if (!data)
1668 return -ENOMEM;
1669 ret = ops->get_tunable(dev, &tuna, data);
1670 if (ret)
1671 goto out;
1672 useraddr += sizeof(tuna);
1673 ret = -EFAULT;
1674 if (copy_to_user(useraddr, data, tuna.len))
1675 goto out;
1676 ret = 0;
1677
1678out:
1679 kfree(data);
1680 return ret;
1681}
1682
1683static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr)
1684{
1685 int ret;
1686 struct ethtool_tunable tuna;
1687 const struct ethtool_ops *ops = dev->ethtool_ops;
1688 void *data;
1689
1690 if (!ops->set_tunable)
1691 return -EOPNOTSUPP;
1692 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
1693 return -EFAULT;
1694 ret = ethtool_tunable_valid(&tuna);
1695 if (ret)
1696 return ret;
1697 data = kmalloc(tuna.len, GFP_USER);
1698 if (!data)
1699 return -ENOMEM;
1700 useraddr += sizeof(tuna);
1701 ret = -EFAULT;
1702 if (copy_from_user(data, useraddr, tuna.len))
1703 goto out;
1704 ret = ops->set_tunable(dev, &tuna, data);
1705
1706out:
1707 kfree(data);
1708 return ret;
1709}
1710
Yan Burman600fed52013-06-03 02:03:34 +00001711/* The main entry point in this file. Called from net/core/dev_ioctl.c */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712
Eric W. Biederman881d9662007-09-17 11:56:21 -07001713int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001715 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 void __user *useraddr = ifr->ifr_data;
1717 u32 ethcmd;
1718 int rc;
Bjørn Morkb29d3142013-05-01 23:06:42 +00001719 netdev_features_t old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 if (!dev || !netif_device_present(dev))
1722 return -ENODEV;
1723
chavey97f8aef2010-04-07 21:54:42 -07001724 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 return -EFAULT;
1726
Stephen Hemminger75f31232006-09-28 15:13:37 -07001727 /* Allow some commands to be done by anyone */
chavey97f8aef2010-04-07 21:54:42 -07001728 switch (ethcmd) {
stephen hemminger0fdc1002010-08-23 10:24:18 +00001729 case ETHTOOL_GSET:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001730 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001731 case ETHTOOL_GMSGLVL:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001732 case ETHTOOL_GLINK:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001733 case ETHTOOL_GCOALESCE:
1734 case ETHTOOL_GRINGPARAM:
1735 case ETHTOOL_GPAUSEPARAM:
1736 case ETHTOOL_GRXCSUM:
1737 case ETHTOOL_GTXCSUM:
1738 case ETHTOOL_GSG:
Michał Mirosławf80400a2012-01-22 00:20:40 +00001739 case ETHTOOL_GSSET_INFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001740 case ETHTOOL_GSTRINGS:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001741 case ETHTOOL_GSTATS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001742 case ETHTOOL_GTSO:
1743 case ETHTOOL_GPERMADDR:
1744 case ETHTOOL_GUFO:
1745 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001746 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001747 case ETHTOOL_GFLAGS:
1748 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001749 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001750 case ETHTOOL_GRXRINGS:
1751 case ETHTOOL_GRXCLSRLCNT:
1752 case ETHTOOL_GRXCLSRULE:
1753 case ETHTOOL_GRXCLSRLALL:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001754 case ETHTOOL_GRXFHINDIR:
Venkata Duvvuru3de0b592014-04-21 15:37:59 +05301755 case ETHTOOL_GRSSH:
Michał Mirosław5455c692011-02-15 16:59:17 +00001756 case ETHTOOL_GFEATURES:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001757 case ETHTOOL_GCHANNELS:
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001758 case ETHTOOL_GET_TS_INFO:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001759 case ETHTOOL_GEEE:
Govindarajulu Varadarajanf0db9b02014-09-03 03:17:20 +05301760 case ETHTOOL_GTUNABLE:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001761 break;
1762 default:
Eric W. Biederman5e1fccc2012-11-16 03:03:04 +00001763 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
Stephen Hemminger75f31232006-09-28 15:13:37 -07001764 return -EPERM;
1765 }
1766
chavey97f8aef2010-04-07 21:54:42 -07001767 if (dev->ethtool_ops->begin) {
1768 rc = dev->ethtool_ops->begin(dev);
1769 if (rc < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 return rc;
chavey97f8aef2010-04-07 21:54:42 -07001771 }
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001772 old_features = dev->features;
1773
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 switch (ethcmd) {
1775 case ETHTOOL_GSET:
1776 rc = ethtool_get_settings(dev, useraddr);
1777 break;
1778 case ETHTOOL_SSET:
1779 rc = ethtool_set_settings(dev, useraddr);
1780 break;
1781 case ETHTOOL_GDRVINFO:
1782 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 break;
1784 case ETHTOOL_GREGS:
1785 rc = ethtool_get_regs(dev, useraddr);
1786 break;
1787 case ETHTOOL_GWOL:
1788 rc = ethtool_get_wol(dev, useraddr);
1789 break;
1790 case ETHTOOL_SWOL:
1791 rc = ethtool_set_wol(dev, useraddr);
1792 break;
1793 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001794 rc = ethtool_get_value(dev, useraddr, ethcmd,
1795 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 break;
1797 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001798 rc = ethtool_set_value_void(dev, useraddr,
1799 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 break;
Yuval Mintz80f12ec2012-06-06 17:13:06 +00001801 case ETHTOOL_GEEE:
1802 rc = ethtool_get_eee(dev, useraddr);
1803 break;
1804 case ETHTOOL_SEEE:
1805 rc = ethtool_set_eee(dev, useraddr);
1806 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 case ETHTOOL_NWAY_RST:
1808 rc = ethtool_nway_reset(dev);
1809 break;
1810 case ETHTOOL_GLINK:
Ben Hutchingse596e6e2010-12-09 12:08:35 +00001811 rc = ethtool_get_link(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 break;
1813 case ETHTOOL_GEEPROM:
1814 rc = ethtool_get_eeprom(dev, useraddr);
1815 break;
1816 case ETHTOOL_SEEPROM:
1817 rc = ethtool_set_eeprom(dev, useraddr);
1818 break;
1819 case ETHTOOL_GCOALESCE:
1820 rc = ethtool_get_coalesce(dev, useraddr);
1821 break;
1822 case ETHTOOL_SCOALESCE:
1823 rc = ethtool_set_coalesce(dev, useraddr);
1824 break;
1825 case ETHTOOL_GRINGPARAM:
1826 rc = ethtool_get_ringparam(dev, useraddr);
1827 break;
1828 case ETHTOOL_SRINGPARAM:
1829 rc = ethtool_set_ringparam(dev, useraddr);
1830 break;
1831 case ETHTOOL_GPAUSEPARAM:
1832 rc = ethtool_get_pauseparam(dev, useraddr);
1833 break;
1834 case ETHTOOL_SPAUSEPARAM:
1835 rc = ethtool_set_pauseparam(dev, useraddr);
1836 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 case ETHTOOL_TEST:
1838 rc = ethtool_self_test(dev, useraddr);
1839 break;
1840 case ETHTOOL_GSTRINGS:
1841 rc = ethtool_get_strings(dev, useraddr);
1842 break;
1843 case ETHTOOL_PHYS_ID:
1844 rc = ethtool_phys_id(dev, useraddr);
1845 break;
1846 case ETHTOOL_GSTATS:
1847 rc = ethtool_get_stats(dev, useraddr);
1848 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001849 case ETHTOOL_GPERMADDR:
1850 rc = ethtool_get_perm_addr(dev, useraddr);
1851 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001852 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001853 rc = ethtool_get_value(dev, useraddr, ethcmd,
Michał Mirosławbc5787c62011-11-15 15:29:55 +00001854 __ethtool_get_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001855 break;
1856 case ETHTOOL_SFLAGS:
Michał Mirosławda8ac86c2011-02-15 16:59:18 +00001857 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001858 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001859 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001860 rc = ethtool_get_value(dev, useraddr, ethcmd,
1861 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001862 break;
1863 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001864 rc = ethtool_set_value(dev, useraddr,
1865 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001866 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001867 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001868 case ETHTOOL_GRXRINGS:
1869 case ETHTOOL_GRXCLSRLCNT:
1870 case ETHTOOL_GRXCLSRULE:
1871 case ETHTOOL_GRXCLSRLALL:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001872 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001873 break;
1874 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001875 case ETHTOOL_SRXCLSRLDEL:
1876 case ETHTOOL_SRXCLSRLINS:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001877 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001878 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001879 case ETHTOOL_FLASHDEV:
1880 rc = ethtool_flash_device(dev, useraddr);
1881 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001882 case ETHTOOL_RESET:
1883 rc = ethtool_reset(dev, useraddr);
1884 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001885 case ETHTOOL_GSSET_INFO:
1886 rc = ethtool_get_sset_info(dev, useraddr);
1887 break;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +00001888 case ETHTOOL_GRXFHINDIR:
1889 rc = ethtool_get_rxfh_indir(dev, useraddr);
1890 break;
1891 case ETHTOOL_SRXFHINDIR:
1892 rc = ethtool_set_rxfh_indir(dev, useraddr);
1893 break;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +05301894 case ETHTOOL_GRSSH:
1895 rc = ethtool_get_rxfh(dev, useraddr);
1896 break;
1897 case ETHTOOL_SRSSH:
1898 rc = ethtool_set_rxfh(dev, useraddr);
1899 break;
Michał Mirosław5455c692011-02-15 16:59:17 +00001900 case ETHTOOL_GFEATURES:
1901 rc = ethtool_get_features(dev, useraddr);
1902 break;
1903 case ETHTOOL_SFEATURES:
1904 rc = ethtool_set_features(dev, useraddr);
1905 break;
Michał Mirosław0a417702011-02-15 16:59:17 +00001906 case ETHTOOL_GTXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001907 case ETHTOOL_GRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001908 case ETHTOOL_GSG:
1909 case ETHTOOL_GTSO:
1910 case ETHTOOL_GUFO:
1911 case ETHTOOL_GGSO:
1912 case ETHTOOL_GGRO:
1913 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1914 break;
1915 case ETHTOOL_STXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001916 case ETHTOOL_SRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001917 case ETHTOOL_SSG:
1918 case ETHTOOL_STSO:
1919 case ETHTOOL_SUFO:
1920 case ETHTOOL_SGSO:
1921 case ETHTOOL_SGRO:
1922 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1923 break;
amit salecha8b5933c32011-04-07 01:58:42 +00001924 case ETHTOOL_GCHANNELS:
1925 rc = ethtool_get_channels(dev, useraddr);
1926 break;
1927 case ETHTOOL_SCHANNELS:
1928 rc = ethtool_set_channels(dev, useraddr);
1929 break;
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001930 case ETHTOOL_SET_DUMP:
1931 rc = ethtool_set_dump(dev, useraddr);
1932 break;
1933 case ETHTOOL_GET_DUMP_FLAG:
1934 rc = ethtool_get_dump_flag(dev, useraddr);
1935 break;
1936 case ETHTOOL_GET_DUMP_DATA:
1937 rc = ethtool_get_dump_data(dev, useraddr);
1938 break;
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001939 case ETHTOOL_GET_TS_INFO:
1940 rc = ethtool_get_ts_info(dev, useraddr);
1941 break;
Stuart Hodgson41c3cb62012-04-19 09:44:42 +01001942 case ETHTOOL_GMODULEINFO:
1943 rc = ethtool_get_module_info(dev, useraddr);
1944 break;
1945 case ETHTOOL_GMODULEEEPROM:
1946 rc = ethtool_get_module_eeprom(dev, useraddr);
1947 break;
Govindarajulu Varadarajanf0db9b02014-09-03 03:17:20 +05301948 case ETHTOOL_GTUNABLE:
1949 rc = ethtool_get_tunable(dev, useraddr);
1950 break;
1951 case ETHTOOL_STUNABLE:
1952 rc = ethtool_set_tunable(dev, useraddr);
1953 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001955 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001957
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001958 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001960
1961 if (old_features != dev->features)
1962 netdev_features_change(dev);
1963
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965}