#include <linux/ip.h>
#include <linux/types.h>
#include <linux/ethtool.h>
+#include <linux/mii.h>
#include <linux/pkt_sched.h>
#include <linux/rtnetlink.h>
#include <linux/sockios.h>
return error;
}
+static int
+netdev_linux_get_miimon(const struct netdev *netdev_, bool *miimon)
+{
+ int error;
+ struct ifreq ifr;
+ const char *name = netdev_get_name(netdev_);
+
+ *miimon = false;
+ memset(&ifr, 0, sizeof ifr);
+
+ error = netdev_linux_do_ioctl(name, &ifr, SIOCGMIIPHY, "SIOCGMIIPHY");
+ if (!error) {
+ struct mii_ioctl_data *data = (struct mii_ioctl_data *)&ifr.ifr_data;
+
+ /* data->phy_id is filled out by previous SIOCGMIIPHY ioctl call. */
+ data->reg_num = MII_BMSR;
+ error = netdev_linux_do_ioctl(name, &ifr, SIOCGMIIREG, "SIOCGMIIREG");
+
+ if (!error) {
+ *miimon = !!(data->val_out & BMSR_LSTATUS);
+ } else {
+ VLOG_WARN_RL(&rl, "%s: failed to query MII", name);
+ }
+ } else {
+ struct ethtool_cmd ecmd;
+ struct ethtool_value *eval = (struct ethtool_value *) &ecmd;
+
+ VLOG_DBG_RL(&rl, "%s: failed to query MII, falling back to ethtool",
+ name);
+
+ memset(&ecmd, 0, sizeof ecmd);
+ error = netdev_linux_do_ethtool(name, &ecmd, ETHTOOL_GLINK,
+ "ETHTOOL_GLINK");
+ if (!error) {
+ *miimon = !!eval->data;
+ } else {
+ VLOG_WARN_RL(&rl, "%s: ethtool link status failed", name);
+ }
+ }
+
+ return error;
+}
+
/* Check whether we can we use RTM_GETLINK to get network device statistics.
* In pre-2.6.19 kernels, this was only available if wireless extensions were
* enabled. */
netdev_linux_get_mtu, \
netdev_linux_get_ifindex, \
netdev_linux_get_carrier, \
+ netdev_linux_get_miimon, \
netdev_linux_get_stats, \
SET_STATS, \
\
int updelay, downdelay; /* Delay before iface goes up/down, in ms. */
bool bond_compat_is_stale; /* Need to call port_update_bond_compat()? */
bool bond_fake_iface; /* Fake a bond interface for legacy compat? */
+ bool miimon; /* Use miimon instead of carrier? */
+ long long int bond_miimon_interval; /* Miimon status refresh interval. */
+ long long int bond_miimon_next_update; /* Time of next miimon update. */
long long int bond_next_fake_iface_update; /* Time of next update. */
struct netdev_monitor *monitor; /* Tracks carrier up/down status. */
/* Nothing to do. */
return;
}
- VLOG_INFO_RL(&rl, "interface %s: carrier %s",
- iface->name, carrier ? "detected" : "dropped");
+ VLOG_INFO_RL(&rl, "interface %s: link state %s",
+ iface->name, carrier ? "up" : "down");
if (carrier == iface->enabled) {
iface->delay_expires = LLONG_MAX;
VLOG_INFO_RL(&rl, "interface %s: will not be %s",
if (port->n_ifaces >= 2) {
char *devname;
- /* Track carrier going up and down on interfaces. */
- while (!netdev_monitor_poll(port->monitor, &devname)) {
- struct iface *iface;
+ if (port->monitor) {
+ assert(!port->miimon);
- iface = port_lookup_iface(port, devname);
- if (iface) {
- bool carrier = netdev_get_carrier(iface->netdev);
+ /* Track carrier going up and down on interfaces. */
+ while (!netdev_monitor_poll(port->monitor, &devname)) {
+ struct iface *iface;
+
+ iface = port_lookup_iface(port, devname);
+ if (iface) {
+ bool up = netdev_get_carrier(iface->netdev);
+
+ bond_link_status_update(iface, up);
+ port_update_bond_compat(port);
+ }
+ free(devname);
+ }
+ } else {
+ assert(port->miimon);
- bond_link_status_update(iface, carrier);
- port_update_bond_compat(port);
+ if (time_msec() >= port->bond_miimon_next_update) {
+ for (j = 0; j < port->n_ifaces; j++) {
+ struct iface *iface = port->ifaces[j];
+ bool up = netdev_get_miimon(iface->netdev);
+
+ bond_link_status_update(iface, up);
+ port_update_bond_compat(port);
+ }
+ port->bond_miimon_next_update = time_msec() +
+ port->bond_miimon_interval;
}
- free(devname);
}
for (j = 0; j < port->n_ifaces; j++) {
if (port->n_ifaces < 2) {
continue;
}
- netdev_monitor_poll_wait(port->monitor);
+
+ if (port->monitor) {
+ netdev_monitor_poll_wait(port->monitor);
+ }
+
+ if (port->miimon) {
+ poll_timer_wait_until(port->bond_miimon_next_update);
+ }
+
for (j = 0; j < port->n_ifaces; j++) {
struct iface *iface = port->ifaces[j];
if (iface->delay_expires != LLONG_MAX) {
ds_put_format(&ds, "bond_mode: %s\n",
bond_mode_to_string(port->bond_mode));
+ ds_put_format(&ds, "bond-detect-mode: %s\n",
+ port->miimon ? "miimon" : "carrier");
ds_put_format(&ds, "updelay: %d ms\n", port->updelay);
ds_put_format(&ds, "downdelay: %d ms\n", port->downdelay);
static void
port_reconfigure(struct port *port, const struct ovsrec_port *cfg)
{
+ const char *detect_mode;
struct shash new_ifaces;
- long long int next_rebalance;
+ long long int next_rebalance, miimon_next_update;
unsigned long *trunks;
int vlan;
size_t i;
port->bond_next_rebalance = next_rebalance;
}
+ detect_mode = get_port_other_config(cfg, "bond-detect-mode",
+ "carrier");
+
+ if (!strcmp(detect_mode, "carrier")) {
+ port->miimon = false;
+ } else if (!strcmp(detect_mode, "miimon")) {
+ port->miimon = true;
+ } else {
+ port->miimon = false;
+ VLOG_WARN("port %s: unsupported bond-detect-mode %s, defaulting to "
+ "carrier", port->name, detect_mode);
+ }
+
+ port->bond_miimon_interval = atoi(
+ get_port_other_config(cfg, "bond-miimon-interval", "200"));
+ if (port->bond_miimon_interval < 100) {
+ port->bond_miimon_interval = 100;
+ }
+ miimon_next_update = time_msec() + port->bond_miimon_interval;
+ if (port->bond_miimon_next_update > miimon_next_update) {
+ port->bond_miimon_next_update = miimon_next_update;
+ }
+
if (!port->cfg->bond_mode ||
!strcmp(port->cfg->bond_mode, bond_mode_to_string(BM_SLB))) {
port->bond_mode = BM_SLB;
port->bond_compat_is_stale = true;
port->bond_fake_iface = port->cfg->bond_fake_iface;
- port->monitor = netdev_monitor_create();
- for (i = 0; i < port->n_ifaces; i++) {
- netdev_monitor_add(port->monitor, port->ifaces[i]->netdev);
+ if (!port->miimon) {
+ port->monitor = netdev_monitor_create();
+ for (i = 0; i < port->n_ifaces; i++) {
+ netdev_monitor_add(port->monitor, port->ifaces[i]->netdev);
+ }
}
}
}