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