mirror of https://gitee.com/openkylin/linux.git
ethtool: Add generic options for tunables
This patch adds new ethtool cmd, ETHTOOL_GTUNABLE & ETHTOOL_STUNABLE for getting tunable values from driver. Add get_tunable and set_tunable to ethtool_ops. Driver implements these functions for getting/setting tunable value. Signed-off-by: Govindarajulu Varadarajan <_govind@gmx.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
a03bb56e67
commit
f0db9b0734
|
@ -257,6 +257,10 @@ struct ethtool_ops {
|
|||
struct ethtool_eeprom *, u8 *);
|
||||
int (*get_eee)(struct net_device *, struct ethtool_eee *);
|
||||
int (*set_eee)(struct net_device *, struct ethtool_eee *);
|
||||
int (*get_tunable)(struct net_device *,
|
||||
const struct ethtool_tunable *, void *);
|
||||
int (*set_tunable)(struct net_device *,
|
||||
const struct ethtool_tunable *, const void *);
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -209,6 +209,32 @@ struct ethtool_value {
|
|||
__u32 data;
|
||||
};
|
||||
|
||||
enum tunable_id {
|
||||
ETHTOOL_ID_UNSPEC,
|
||||
ETHTOOL_RX_COPYBREAK,
|
||||
};
|
||||
|
||||
enum tunable_type_id {
|
||||
ETHTOOL_TUNABLE_UNSPEC,
|
||||
ETHTOOL_TUNABLE_U8,
|
||||
ETHTOOL_TUNABLE_U16,
|
||||
ETHTOOL_TUNABLE_U32,
|
||||
ETHTOOL_TUNABLE_U64,
|
||||
ETHTOOL_TUNABLE_STRING,
|
||||
ETHTOOL_TUNABLE_S8,
|
||||
ETHTOOL_TUNABLE_S16,
|
||||
ETHTOOL_TUNABLE_S32,
|
||||
ETHTOOL_TUNABLE_S64,
|
||||
};
|
||||
|
||||
struct ethtool_tunable {
|
||||
__u32 cmd;
|
||||
__u32 id;
|
||||
__u32 type_id;
|
||||
__u32 len;
|
||||
void *data[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* struct ethtool_regs - hardware register dump
|
||||
* @cmd: Command number = %ETHTOOL_GREGS
|
||||
|
@ -1152,6 +1178,8 @@ enum ethtool_sfeatures_retval_bits {
|
|||
|
||||
#define ETHTOOL_GRSSH 0x00000046 /* Get RX flow hash configuration */
|
||||
#define ETHTOOL_SRSSH 0x00000047 /* Set RX flow hash configuration */
|
||||
#define ETHTOOL_GTUNABLE 0x00000048 /* Get tunable configuration */
|
||||
#define ETHTOOL_STUNABLE 0x00000049 /* Set tunable configuration */
|
||||
|
||||
/* compatibility with older code */
|
||||
#define SPARC_ETH_GSET ETHTOOL_GSET
|
||||
|
|
|
@ -1621,6 +1621,80 @@ static int ethtool_get_module_eeprom(struct net_device *dev,
|
|||
modinfo.eeprom_len);
|
||||
}
|
||||
|
||||
static int ethtool_tunable_valid(const struct ethtool_tunable *tuna)
|
||||
{
|
||||
switch (tuna->id) {
|
||||
case ETHTOOL_RX_COPYBREAK:
|
||||
if (tuna->len != sizeof(u32) ||
|
||||
tuna->type_id != ETHTOOL_TUNABLE_U32)
|
||||
return -EINVAL;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr)
|
||||
{
|
||||
int ret;
|
||||
struct ethtool_tunable tuna;
|
||||
const struct ethtool_ops *ops = dev->ethtool_ops;
|
||||
void *data;
|
||||
|
||||
if (!ops->get_tunable)
|
||||
return -EOPNOTSUPP;
|
||||
if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
|
||||
return -EFAULT;
|
||||
ret = ethtool_tunable_valid(&tuna);
|
||||
if (ret)
|
||||
return ret;
|
||||
data = kmalloc(tuna.len, GFP_USER);
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
ret = ops->get_tunable(dev, &tuna, data);
|
||||
if (ret)
|
||||
goto out;
|
||||
useraddr += sizeof(tuna);
|
||||
ret = -EFAULT;
|
||||
if (copy_to_user(useraddr, data, tuna.len))
|
||||
goto out;
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
kfree(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr)
|
||||
{
|
||||
int ret;
|
||||
struct ethtool_tunable tuna;
|
||||
const struct ethtool_ops *ops = dev->ethtool_ops;
|
||||
void *data;
|
||||
|
||||
if (!ops->set_tunable)
|
||||
return -EOPNOTSUPP;
|
||||
if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
|
||||
return -EFAULT;
|
||||
ret = ethtool_tunable_valid(&tuna);
|
||||
if (ret)
|
||||
return ret;
|
||||
data = kmalloc(tuna.len, GFP_USER);
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
useraddr += sizeof(tuna);
|
||||
ret = -EFAULT;
|
||||
if (copy_from_user(data, useraddr, tuna.len))
|
||||
goto out;
|
||||
ret = ops->set_tunable(dev, &tuna, data);
|
||||
|
||||
out:
|
||||
kfree(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* The main entry point in this file. Called from net/core/dev_ioctl.c */
|
||||
|
||||
int dev_ethtool(struct net *net, struct ifreq *ifr)
|
||||
|
@ -1670,6 +1744,7 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)
|
|||
case ETHTOOL_GCHANNELS:
|
||||
case ETHTOOL_GET_TS_INFO:
|
||||
case ETHTOOL_GEEE:
|
||||
case ETHTOOL_GTUNABLE:
|
||||
break;
|
||||
default:
|
||||
if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
|
||||
|
@ -1857,6 +1932,12 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)
|
|||
case ETHTOOL_GMODULEEEPROM:
|
||||
rc = ethtool_get_module_eeprom(dev, useraddr);
|
||||
break;
|
||||
case ETHTOOL_GTUNABLE:
|
||||
rc = ethtool_get_tunable(dev, useraddr);
|
||||
break;
|
||||
case ETHTOOL_STUNABLE:
|
||||
rc = ethtool_set_tunable(dev, useraddr);
|
||||
break;
|
||||
default:
|
||||
rc = -EOPNOTSUPP;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue