core: merge NM_PLATFORM_LINK_DUPLEX_UNSET and UNKNOWN

They have basically the same use, except that certain places handled
one but not the other.
This commit is contained in:
Thomas Haller 2016-11-22 12:59:11 +01:00 committed by Francesco Giudici
parent 417f5ad6ed
commit d5a743a619
3 changed files with 33 additions and 45 deletions

View file

@ -782,35 +782,23 @@ supplicant_interface_init (NMDeviceEthernet *self)
return TRUE;
}
static const char *
link_duplex_to_string (NMPlatformLinkDuplexType duplex)
{
switch (duplex) {
case NM_PLATFORM_LINK_DUPLEX_FULL:
return "full";
break;
case NM_PLATFORM_LINK_DUPLEX_HALF:
return "half";
break;
default:
return "unknown";
break;
}
}
NM_UTILS_LOOKUP_STR_DEFINE_STATIC (link_duplex_to_string, NMPlatformLinkDuplexType,
NM_UTILS_LOOKUP_DEFAULT_WARN (NULL),
NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_LINK_DUPLEX_UNKNOWN, "unknown"),
NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_LINK_DUPLEX_FULL, "full"),
NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_LINK_DUPLEX_HALF, "half"),
);
static NMPlatformLinkDuplexType
link_duplex_to_platform (const char *duplex)
{
if (!duplex)
return NM_PLATFORM_LINK_DUPLEX_UNSET;
return NM_PLATFORM_LINK_DUPLEX_UNKNOWN;
if (nm_streq (duplex, "full"))
return NM_PLATFORM_LINK_DUPLEX_FULL;
if (nm_streq (duplex, "half"))
return NM_PLATFORM_LINK_DUPLEX_HALF;
return NM_PLATFORM_LINK_DUPLEX_UNKNOWN;
g_return_val_if_reached (NM_PLATFORM_LINK_DUPLEX_UNKNOWN);
}
static void
@ -818,9 +806,12 @@ link_negotiation_set (NMDevice *device)
{
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device);
NMSettingWired *s_wired;
gboolean autoneg = TRUE, link_autoneg;
NMPlatformLinkDuplexType link_duplex, duplex = NM_PLATFORM_LINK_DUPLEX_UNSET;
guint32 speed = 0, link_speed;
gboolean autoneg = TRUE;
gboolean link_autoneg;
NMPlatformLinkDuplexType duplex = NM_PLATFORM_LINK_DUPLEX_UNKNOWN;
NMPlatformLinkDuplexType link_duplex;
guint32 speed = 0;
guint32 link_speed;
s_wired = (NMSettingWired *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_WIRED);
if (s_wired) {
@ -842,19 +833,23 @@ link_negotiation_set (NMDevice *device)
}
/* If link negotiation setting are already in place do nothing and return with success */
if (autoneg != link_autoneg)
goto set_link;
if ( (!!autoneg == !!link_autoneg)
&& (!speed || (speed == link_speed))
&& (!duplex || (duplex == link_duplex))) {
_LOGD (LOGD_DEVICE, "set-link: link negotiation is already configured");
return;
}
if (speed && (speed != link_speed))
goto set_link;
if (autoneg)
_LOGD (LOGD_DEVICE, "set-link: configure autonegotiation");
else {
_LOGD (LOGD_DEVICE, "set-link: configure static negotiation (%u Mbit%s - %s duplex%s)",
speed ?: link_speed,
speed ? "" : "*",
duplex ? link_duplex_to_string (duplex) : link_duplex_to_string (link_duplex),
duplex ? "" : "*");
}
if (duplex && (duplex != link_duplex))
goto set_link;
_LOGW (LOGD_DEVICE, "set-link: link negotiation is already configured");
return;
set_link:
if (!nm_platform_ethtool_set_link_settings (NM_PLATFORM_GET,
nm_device_get_iface (device),
autoneg,
@ -863,14 +858,6 @@ set_link:
_LOGW (LOGD_DEVICE, "set-link: failure to set link negotiation");
return;
}
if (autoneg)
_LOGD (LOGD_DEVICE, "set-link: configure autonegotiation");
else {
_LOGD (LOGD_DEVICE, "set-link: configure static negotiation (%u Mbit - %s duplex)",
speed ?: link_speed,
duplex ? link_duplex_to_string (duplex) : link_duplex_to_string (link_duplex));
}
}
static gboolean

View file

@ -339,8 +339,10 @@ nmp_utils_ethtool_set_link_settings (const char *ifname, gboolean autoneg, guint
case NM_PLATFORM_LINK_DUPLEX_FULL:
edata.duplex = DUPLEX_FULL;
break;
default: /* NM_PLATFORM_LINK_DUPLEX_UNSET */
case NM_PLATFORM_LINK_DUPLEX_UNKNOWN:
break;
default:
g_return_val_if_reached (FALSE);
}
}

View file

@ -482,10 +482,9 @@ typedef struct {
} NMPlatformTunProperties;
typedef enum {
NM_PLATFORM_LINK_DUPLEX_UNSET = 0,
NM_PLATFORM_LINK_DUPLEX_UNKNOWN,
NM_PLATFORM_LINK_DUPLEX_HALF,
NM_PLATFORM_LINK_DUPLEX_FULL,
NM_PLATFORM_LINK_DUPLEX_UNKNOWN,
} NMPlatformLinkDuplexType;
/*****************************************************************************/