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