mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 06:15:47 +00:00
netdev-linux: Introduce netdev_linux_ethtool_set_flag().
There will be a caller added soon.
This commit is contained in:
@@ -90,6 +90,15 @@ COVERAGE_DEFINE(netdev_ethtool);
|
||||
#define ADVERTISED_Asym_Pause (1 << 14)
|
||||
#endif
|
||||
|
||||
/* These were introduced in Linux 2.6.24, so they might be missing if we
|
||||
* have old headers. */
|
||||
#ifndef ETHTOOL_GFLAGS
|
||||
#define ETHTOOL_GFLAGS 0x00000025 /* Get flags bitmap(ethtool_value) */
|
||||
#endif
|
||||
#ifndef ETHTOOL_SFLAGS
|
||||
#define ETHTOOL_SFLAGS 0x00000026 /* Set flags bitmap(ethtool_value) */
|
||||
#endif
|
||||
|
||||
/* This was introduced in Linux 2.6.25, so it might be missing if we have old
|
||||
* headers. */
|
||||
#ifndef TC_RTAB_SIZE
|
||||
@@ -4210,6 +4219,51 @@ netdev_linux_do_ethtool(const char *name, struct ethtool_cmd *ecmd,
|
||||
}
|
||||
}
|
||||
|
||||
/* Modifies the 'flag' bit in ethtool's flags field for 'netdev'. If
|
||||
* 'enable' is true, the bit is set. Otherwise, it is cleared. */
|
||||
int
|
||||
netdev_linux_ethtool_set_flag(struct netdev *netdev, uint32_t flag,
|
||||
const char *flag_name, bool enable)
|
||||
{
|
||||
const char *netdev_name = netdev_get_name(netdev);
|
||||
struct ethtool_value evalue;
|
||||
uint32_t new_flags;
|
||||
int error;
|
||||
|
||||
memset(&evalue, 0, sizeof evalue);
|
||||
error = netdev_linux_do_ethtool(netdev_name,
|
||||
(struct ethtool_cmd *)&evalue,
|
||||
ETHTOOL_GFLAGS, "ETHTOOL_GFLAGS");
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
evalue.data = new_flags = (evalue.data & ~flag) | (enable ? flag : 0);
|
||||
error = netdev_linux_do_ethtool(netdev_name,
|
||||
(struct ethtool_cmd *)&evalue,
|
||||
ETHTOOL_SFLAGS, "ETHTOOL_SFLAGS");
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
memset(&evalue, 0, sizeof evalue);
|
||||
error = netdev_linux_do_ethtool(netdev_name,
|
||||
(struct ethtool_cmd *)&evalue,
|
||||
ETHTOOL_GFLAGS, "ETHTOOL_GFLAGS");
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (new_flags != evalue.data) {
|
||||
VLOG_WARN_RL(&rl, "attempt to %s ethtool %s flag on network "
|
||||
"device %s failed", enable ? "enable" : "disable",
|
||||
flag_name, netdev_name);
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
netdev_linux_do_ioctl(const char *name, struct ifreq *ifr, int cmd,
|
||||
const char *cmd_name)
|
||||
|
@@ -17,9 +17,13 @@
|
||||
#ifndef NETDEV_LINUX_H
|
||||
#define NETDEV_LINUX_H 1
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/* These functions are Linux specific, so they should be used directly only by
|
||||
* Linux-specific code. */
|
||||
|
||||
struct netdev;
|
||||
struct netdev_stats;
|
||||
struct rtnl_link_stats;
|
||||
struct rtnl_link_stats64;
|
||||
@@ -31,4 +35,7 @@ void netdev_stats_from_rtnl_link_stats64(struct netdev_stats *dst,
|
||||
void netdev_stats_to_rtnl_link_stats64(struct rtnl_link_stats64 *dst,
|
||||
const struct netdev_stats *src);
|
||||
|
||||
int netdev_linux_ethtool_set_flag(struct netdev *netdev, uint32_t flag,
|
||||
const char *flag_name, bool enable);
|
||||
|
||||
#endif /* netdev-linux.h */
|
||||
|
Reference in New Issue
Block a user