14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/capability.h>
17 #include <linux/errno.h>
18 #include <linux/ethtool.h>
19 #include <linux/netdevice.h>
22 #include <linux/bitops.h>
25 #include <linux/slab.h>
26 #include <linux/rtnetlink.h>
27 #include <linux/sched.h>
37 return netif_carrier_ok(dev) ? 1 : 0;
54 #define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32)
93 static int ethtool_get_features(
struct net_device *
dev,
void __user *useraddr)
119 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
124 useraddr +=
sizeof(
cmd);
131 static int ethtool_set_features(
struct net_device *dev,
void __user *useraddr)
140 useraddr +=
sizeof(
cmd);
142 if (cmd.
size != ETHTOOL_DEV_FEATURE_WORDS)
171 static int __ethtool_get_sset_count(
struct net_device *dev,
int sset)
184 static void __ethtool_get_strings(
struct net_device *dev,
190 memcpy(data, netdev_features_strings,
191 sizeof(netdev_features_strings));
228 static int ethtool_get_one_feature(
struct net_device *dev,
229 char __user *useraddr,
u32 ethcmd)
242 static int ethtool_set_one_feature(
struct net_device *dev,
243 void __user *useraddr,
u32 ethcmd)
251 mask = ethtool_get_feature_mask(ethcmd);
266 #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
267 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
268 #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_RX | \
269 NETIF_F_HW_VLAN_TX | NETIF_F_NTUPLE | NETIF_F_RXHASH)
284 static int __ethtool_set_flags(
struct net_device *dev,
u32 data)
323 static int ethtool_get_settings(
struct net_device *dev,
void __user *useraddr)
337 static int ethtool_set_settings(
struct net_device *dev,
void __user *useraddr)
350 static noinline_for_stack
int ethtool_get_drvinfo(
struct net_device *dev,
351 void __user *useraddr)
360 }
else if (dev->
dev.parent && dev->
dev.parent->driver) {
362 sizeof(
info.bus_info));
364 sizeof(
info.driver));
396 static noinline_for_stack
int ethtool_get_sset_info(
struct net_device *dev,
397 void __user *useraddr)
408 sset_mask =
info.sset_mask;
418 info_buf = kzalloc(n_bits *
sizeof(
u32),
GFP_USER);
426 for (i = 0; i < 64; i++) {
427 if (!(sset_mask & (1ULL << i)))
430 rc = __ethtool_get_sset_count(dev, i);
432 info.sset_mask |= (1ULL <<
i);
433 info_buf[idx++] =
rc;
452 static noinline_for_stack
int ethtool_set_rxnfc(
struct net_device *dev,
453 u32 cmd,
void __user *useraddr)
456 size_t info_size =
sizeof(
info);
484 static noinline_for_stack
int ethtool_get_rxnfc(
struct net_device *dev,
485 u32 cmd,
void __user *useraddr)
488 size_t info_size =
sizeof(
info);
491 void *rule_buf =
NULL;
508 if (
info.rule_cnt > 0) {
510 rule_buf = kzalloc(
info.rule_cnt *
sizeof(
u32),
539 static noinline_for_stack
int ethtool_get_rxfh_indir(
struct net_device *dev,
540 void __user *useraddr)
542 u32 user_size, dev_size;
549 dev_size = dev->
ethtool_ops->get_rxfh_indir_size(dev);
559 &dev_size,
sizeof(dev_size)))
566 if (user_size < dev_size)
567 return user_size == 0 ? 0 : -
EINVAL;
569 indir = kcalloc(dev_size,
sizeof(indir[0]),
GFP_USER);
573 ret = dev->
ethtool_ops->get_rxfh_indir(dev, indir);
579 indir, dev_size *
sizeof(indir[0])))
587 static noinline_for_stack
int ethtool_set_rxfh_indir(
struct net_device *dev,
588 void __user *useraddr)
591 u32 user_size, dev_size,
i;
599 dev_size = dev->
ethtool_ops->get_rxfh_indir_size(dev);
608 if (user_size != 0 && user_size != dev_size)
611 indir = kcalloc(dev_size,
sizeof(indir[0]),
GFP_USER);
620 if (user_size == 0) {
621 for (i = 0; i < dev_size; i++)
622 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
628 dev_size *
sizeof(indir[0]))) {
634 for (i = 0; i < dev_size; i++) {
635 if (indir[i] >= rx_rings.data) {
642 ret = dev->
ethtool_ops->set_rxfh_indir(dev, indir);
649 static int ethtool_get_regs(
struct net_device *dev,
char __user *useraddr)
663 if (
regs.len > reglen)
667 if (reglen && !regbuf)
685 static int ethtool_reset(
struct net_device *dev,
char __user *useraddr)
705 static int ethtool_get_wol(
struct net_device *dev,
char __user *useraddr)
719 static int ethtool_set_wol(
struct net_device *dev,
char __user *useraddr)
732 static int ethtool_get_eee(
struct net_device *dev,
char __user *useraddr)
753 static int ethtool_set_eee(
struct net_device *dev,
char __user *useraddr)
766 static int ethtool_nway_reset(
struct net_device *dev)
774 static int ethtool_get_link(
struct net_device *dev,
char __user *useraddr)
788 static int ethtool_get_any_eeprom(
struct net_device *dev,
void __user *useraddr,
814 bytes_remaining =
eeprom.len;
815 while (bytes_remaining > 0) {
818 ret = getter(dev, &
eeprom, data);
827 bytes_remaining -=
eeprom.len;
839 static int ethtool_get_eeprom(
struct net_device *dev,
void __user *useraddr)
846 return ethtool_get_any_eeprom(dev, useraddr, ops->
get_eeprom,
850 static int ethtool_set_eeprom(
struct net_device *dev,
void __user *useraddr)
877 bytes_remaining =
eeprom.len;
878 while (bytes_remaining > 0) {
890 bytes_remaining -=
eeprom.len;
897 static noinline_for_stack
int ethtool_get_coalesce(
struct net_device *dev,
898 void __user *useraddr)
907 if (
copy_to_user(useraddr, &coalesce,
sizeof(coalesce)))
912 static noinline_for_stack
int ethtool_set_coalesce(
struct net_device *dev,
913 void __user *useraddr)
923 return dev->
ethtool_ops->set_coalesce(dev, &coalesce);
926 static int ethtool_get_ringparam(
struct net_device *dev,
void __user *useraddr)
935 if (
copy_to_user(useraddr, &ringparam,
sizeof(ringparam)))
940 static int ethtool_set_ringparam(
struct net_device *dev,
void __user *useraddr)
950 return dev->
ethtool_ops->set_ringparam(dev, &ringparam);
953 static noinline_for_stack
int ethtool_get_channels(
struct net_device *dev,
954 void __user *useraddr)
963 if (
copy_to_user(useraddr, &channels,
sizeof(channels)))
968 static noinline_for_stack
int ethtool_set_channels(
struct net_device *dev,
969 void __user *useraddr)
979 return dev->
ethtool_ops->set_channels(dev, &channels);
982 static int ethtool_get_pauseparam(
struct net_device *dev,
void __user *useraddr)
989 dev->
ethtool_ops->get_pauseparam(dev, &pauseparam);
991 if (
copy_to_user(useraddr, &pauseparam,
sizeof(pauseparam)))
996 static int ethtool_set_pauseparam(
struct net_device *dev,
void __user *useraddr)
1006 return dev->
ethtool_ops->set_pauseparam(dev, &pauseparam);
1009 static int ethtool_self_test(
struct net_device *dev,
char __user *useraddr)
1027 test.len = test_len;
1037 useraddr +=
sizeof(
test);
1047 static int ethtool_get_strings(
struct net_device *dev,
void __user *useraddr)
1056 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
1066 __ethtool_get_strings(dev, gstrings.string_set, data);
1069 if (
copy_to_user(useraddr, &gstrings,
sizeof(gstrings)))
1071 useraddr +=
sizeof(gstrings);
1081 static int ethtool_phys_id(
struct net_device *dev,
void __user *useraddr)
1127 }
while (!signal_pending(
current) && --i != 0);
1128 }
while (!signal_pending(
current) &&
1129 (
id.data == 0 || --
id.data != 0));
1140 static int ethtool_get_stats(
struct net_device *dev,
void __user *useraddr)
1158 stats.n_stats = n_stats;
1168 useraddr +=
sizeof(
stats);
1178 static int ethtool_get_perm_addr(
struct net_device *dev,
void __user *useraddr)
1191 useraddr +=
sizeof(epaddr);
1197 static int ethtool_get_value(
struct net_device *dev,
char __user *useraddr,
1205 edata.
data = actor(dev);
1212 static int ethtool_set_value_void(
struct net_device *dev,
char __user *useraddr,
1223 actor(dev, edata.
data);
1227 static int ethtool_set_value(
struct net_device *dev,
char __user *useraddr,
1238 return actor(dev, edata.
data);
1241 static noinline_for_stack
int ethtool_flash_device(
struct net_device *dev,
1242 char __user *useraddr)
1257 static int ethtool_set_dump(
struct net_device *dev,
1258 void __user *useraddr)
1271 static int ethtool_get_dump_flag(
struct net_device *dev,
1272 void __user *useraddr)
1293 static int ethtool_get_dump_data(
struct net_device *dev,
1294 void __user *useraddr)
1338 static int ethtool_get_ts_info(
struct net_device *dev,
void __user *useraddr)
1348 if (phydev && phydev->
drv && phydev->
drv->ts_info) {
1350 err = phydev->
drv->ts_info(phydev, &
info);
1357 info.so_timestamping =
1360 info.phc_index = -1;
1372 static int ethtool_get_module_info(
struct net_device *dev,
1373 void __user *useraddr)
1395 static int ethtool_get_module_eeprom(
struct net_device *dev,
1396 void __user *useraddr)
1410 modinfo.eeprom_len);
1418 void __user *useraddr = ifr->ifr_data;
1423 if (!dev || !netif_device_present(dev))
1476 rc = ethtool_get_settings(dev, useraddr);
1479 rc = ethtool_set_settings(dev, useraddr);
1482 rc = ethtool_get_drvinfo(dev, useraddr);
1485 rc = ethtool_get_regs(dev, useraddr);
1488 rc = ethtool_get_wol(dev, useraddr);
1491 rc = ethtool_set_wol(dev, useraddr);
1494 rc = ethtool_get_value(dev, useraddr, ethcmd,
1498 rc = ethtool_set_value_void(dev, useraddr,
1502 rc = ethtool_get_eee(dev, useraddr);
1505 rc = ethtool_set_eee(dev, useraddr);
1508 rc = ethtool_nway_reset(dev);
1511 rc = ethtool_get_link(dev, useraddr);
1514 rc = ethtool_get_eeprom(dev, useraddr);
1517 rc = ethtool_set_eeprom(dev, useraddr);
1520 rc = ethtool_get_coalesce(dev, useraddr);
1523 rc = ethtool_set_coalesce(dev, useraddr);
1526 rc = ethtool_get_ringparam(dev, useraddr);
1529 rc = ethtool_set_ringparam(dev, useraddr);
1532 rc = ethtool_get_pauseparam(dev, useraddr);
1535 rc = ethtool_set_pauseparam(dev, useraddr);
1538 rc = ethtool_self_test(dev, useraddr);
1541 rc = ethtool_get_strings(dev, useraddr);
1544 rc = ethtool_phys_id(dev, useraddr);
1547 rc = ethtool_get_stats(dev, useraddr);
1550 rc = ethtool_get_perm_addr(dev, useraddr);
1553 rc = ethtool_get_value(dev, useraddr, ethcmd,
1554 __ethtool_get_flags);
1557 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
1560 rc = ethtool_get_value(dev, useraddr, ethcmd,
1564 rc = ethtool_set_value(dev, useraddr,
1572 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
1577 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
1580 rc = ethtool_flash_device(dev, useraddr);
1583 rc = ethtool_reset(dev, useraddr);
1586 rc = ethtool_get_sset_info(dev, useraddr);
1589 rc = ethtool_get_rxfh_indir(dev, useraddr);
1592 rc = ethtool_set_rxfh_indir(dev, useraddr);
1595 rc = ethtool_get_features(dev, useraddr);
1598 rc = ethtool_set_features(dev, useraddr);
1607 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1616 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1619 rc = ethtool_get_channels(dev, useraddr);
1622 rc = ethtool_set_channels(dev, useraddr);
1625 rc = ethtool_set_dump(dev, useraddr);
1628 rc = ethtool_get_dump_flag(dev, useraddr);
1631 rc = ethtool_get_dump_data(dev, useraddr);
1634 rc = ethtool_get_ts_info(dev, useraddr);
1637 rc = ethtool_get_module_info(dev, useraddr);
1640 rc = ethtool_get_module_eeprom(dev, useraddr);