Skip to content

Commit

Permalink
schema: use tristate for ethtool offload flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mtomaschewski committed Mar 20, 2014
1 parent ffa8d28 commit b0c2e02
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 83 deletions.
29 changes: 14 additions & 15 deletions client/compat.c
Expand Up @@ -195,13 +195,11 @@ ni_compat_netdev_client_info_set(ni_netdev_t *dev, const char *filename)
* Functions for generating XML
*/
static void
__ni_compat_ethtool_tristate(const char *name, xml_node_t *node, ni_ether_tristate_t flag)
__ni_compat_optional_tristate(const char *name, xml_node_t *node, ni_tristate_t flag)
{
if (flag == NI_ETHERNET_SETTING_ENABLE)
xml_node_new_element(name, node, "enable");
else
if (flag == NI_ETHERNET_SETTING_DISABLE)
xml_node_new_element(name, node, "disable");
if (ni_tristate_is_set(flag)) {
xml_node_new_element(name, node, ni_tristate_to_name(flag));
}
}

static void
Expand All @@ -224,18 +222,19 @@ __ni_compat_generate_eth_node(xml_node_t *child, const ni_ethernet_t *eth)
if (eth->duplex == NI_ETHERNET_DUPLEX_FULL) {
xml_node_new_element("duplex", child, "full");
}
__ni_compat_ethtool_tristate("autoneg-enable", child, eth->autoneg_enable);
__ni_compat_optional_tristate("autoneg-enable", child, eth->autoneg_enable);

/* generate offload and other information */
offload = xml_node_new("offload", NULL);
__ni_compat_ethtool_tristate("rx-csum", offload, eth->offload.rx_csum);
__ni_compat_ethtool_tristate("tx-csum", offload, eth->offload.tx_csum);
__ni_compat_ethtool_tristate("scatter-gather", child, eth->offload.scatter_gather);
__ni_compat_ethtool_tristate("tso", offload, eth->offload.tso);
__ni_compat_ethtool_tristate("ufo", offload, eth->offload.ufo);
__ni_compat_ethtool_tristate("gso", offload, eth->offload.gso);
__ni_compat_ethtool_tristate("gro", offload, eth->offload.gro);
__ni_compat_ethtool_tristate("lro", offload, eth->offload.lro);
__ni_compat_optional_tristate("rx-csum", offload, eth->offload.rx_csum);
__ni_compat_optional_tristate("tx-csum", offload, eth->offload.tx_csum);
__ni_compat_optional_tristate("scatter-gather", offload,
eth->offload.scatter_gather);
__ni_compat_optional_tristate("tso", offload, eth->offload.tso);
__ni_compat_optional_tristate("ufo", offload, eth->offload.ufo);
__ni_compat_optional_tristate("gso", offload, eth->offload.gso);
__ni_compat_optional_tristate("gro", offload, eth->offload.gro);
__ni_compat_optional_tristate("lro", offload, eth->offload.lro);
if (offload->children)
xml_node_add_child(child, offload);
else
Expand Down
6 changes: 3 additions & 3 deletions client/suse/compat-suse.c
Expand Up @@ -1214,13 +1214,13 @@ try_infiniband(const ni_sysconfig_t *sc, ni_compat_netdev_t *compat)
* Handle Ethernet devices
*/
static inline void
ni_parse_ethtool_onoff(const char *input, ni_ether_tristate_t *flag)
ni_parse_ethtool_onoff(const char *input, ni_tristate_t *flag)
{
if (ni_string_eq(input, "on")) {
*flag = NI_ETHERNET_SETTING_ENABLE;
*flag = NI_TRISTATE_ENABLE;
} else
if (ni_string_eq(input, "off")) {
*flag = NI_ETHERNET_SETTING_DISABLE;
*flag = NI_TRISTATE_DISABLE;
}
}

Expand Down
24 changes: 9 additions & 15 deletions include/wicked/ethernet.h
Expand Up @@ -25,28 +25,22 @@ typedef enum {
NI_ETHERNET_DUPLEX_NONE, /* autoneg not complete */
} ni_ether_duplex_t;

typedef enum {
NI_ETHERNET_SETTING_DEFAULT = 0,
NI_ETHERNET_SETTING_ENABLE,
NI_ETHERNET_SETTING_DISABLE,
} ni_ether_tristate_t;

struct ni_ethernet {
ni_hwaddr_t permanent_address;
unsigned int link_speed;
ni_ether_port_t port_type;
ni_ether_duplex_t duplex;
ni_ether_tristate_t autoneg_enable;
ni_tristate_t autoneg_enable;

struct {
ni_ether_tristate_t rx_csum;
ni_ether_tristate_t tx_csum;
ni_ether_tristate_t scatter_gather;
ni_ether_tristate_t tso;
ni_ether_tristate_t ufo;
ni_ether_tristate_t gso;
ni_ether_tristate_t gro;
ni_ether_tristate_t lro;
ni_tristate_t rx_csum;
ni_tristate_t tx_csum;
ni_tristate_t scatter_gather;
ni_tristate_t tso;
ni_tristate_t ufo;
ni_tristate_t gso;
ni_tristate_t gro;
ni_tristate_t lro;
} offload;

unsigned int identify_time;
Expand Down
5 changes: 0 additions & 5 deletions schema/ethernet.xml
Expand Up @@ -3,11 +3,6 @@
-->
<service name="ethernet" interface="org.opensuse.Network.Ethernet" object-class="netif-ethernet">
<!-- This is the linkinfo returned in interface reports -->
<define name="tristate" type="uint32" constraint="enum">
<default value="0"/>
<enable value="1"/>
<disable value="2"/>
</define>
<define name="duplex_t" type="uint32" constraint="enum">
<default value="0" />
<half value="1" />
Expand Down
86 changes: 51 additions & 35 deletions src/dbus-objects/ethernet.c
Expand Up @@ -218,70 +218,86 @@ __ni_objectmodel_ethernet_get_offload(const ni_dbus_object_t *object,
if (!(eth = __ni_objectmodel_ethernet_read_handle(object, error)))
return FALSE;

if (eth->offload.rx_csum != NI_ETHERNET_SETTING_DEFAULT)
ni_dbus_dict_add_uint32(result, "rx-csum", eth->offload.rx_csum);
if (eth->offload.tx_csum != NI_ETHERNET_SETTING_DEFAULT)
ni_dbus_dict_add_uint32(result, "tx-csum", eth->offload.tx_csum);
if (eth->offload.scatter_gather != NI_ETHERNET_SETTING_DEFAULT)
ni_dbus_dict_add_uint32(result, "scatter-gather", eth->offload.scatter_gather);
if (eth->offload.tso != NI_ETHERNET_SETTING_DEFAULT)
ni_dbus_dict_add_uint32(result, "tso", eth->offload.tso);
if (eth->offload.ufo != NI_ETHERNET_SETTING_DEFAULT)
ni_dbus_dict_add_uint32(result, "ufo", eth->offload.ufo);
if (eth->offload.gso != NI_ETHERNET_SETTING_DEFAULT)
ni_dbus_dict_add_uint32(result, "gso", eth->offload.gso);
if (eth->offload.gro != NI_ETHERNET_SETTING_DEFAULT)
ni_dbus_dict_add_uint32(result, "gro", eth->offload.gro);
if (eth->offload.lro != NI_ETHERNET_SETTING_DEFAULT)
ni_dbus_dict_add_uint32(result, "lro", eth->offload.lro);
if (ni_tristate_is_set(eth->offload.rx_csum))
ni_dbus_dict_add_int32(result, "rx-csum", eth->offload.rx_csum);
if (ni_tristate_is_set(eth->offload.tx_csum))
ni_dbus_dict_add_int32(result, "tx-csum", eth->offload.tx_csum);
if (ni_tristate_is_set(eth->offload.scatter_gather))
ni_dbus_dict_add_int32(result, "scatter-gather", eth->offload.scatter_gather);
if (ni_tristate_is_set(eth->offload.tso))
ni_dbus_dict_add_int32(result, "tso", eth->offload.tso);
if (ni_tristate_is_set(eth->offload.ufo))
ni_dbus_dict_add_int32(result, "ufo", eth->offload.ufo);
if (ni_tristate_is_set(eth->offload.gso))
ni_dbus_dict_add_int32(result, "gso", eth->offload.gso);
if (ni_tristate_is_set(eth->offload.gro))
ni_dbus_dict_add_int32(result, "gro", eth->offload.gro);
if (ni_tristate_is_set(eth->offload.lro))
ni_dbus_dict_add_int32(result, "lro", eth->offload.lro);

return TRUE;
}

static ni_bool_t
__ni_objectmodel_set_tristate(const ni_dbus_variant_t *argument,
const char *name, ni_tristate_t *flag)
{
int32_t val;

if (ni_dbus_dict_get_int32(argument, name, &val)) {
ni_tristate_set(flag, val);
return TRUE;
} else {
*flag = NI_TRISTATE_DEFAULT;
return FALSE;
}
}

static dbus_bool_t
__ni_objectmodel_ethernet_set_offload(ni_dbus_object_t *object,
const ni_dbus_property_t *property,
const ni_dbus_variant_t *argument,
DBusError *error)
{
ni_ethernet_t *eth;

if (!(eth = __ni_objectmodel_ethernet_write_handle(object, error)))
return FALSE;

if (!ni_dbus_variant_is_dict(argument))
return FALSE;

if (!ni_dbus_dict_get_uint32(argument, "rx-csum", &eth->offload.rx_csum))
eth->offload.rx_csum = NI_ETHERNET_SETTING_DEFAULT;
if (!ni_dbus_dict_get_uint32(argument, "tx-csum", &eth->offload.tx_csum))
eth->offload.tx_csum = NI_ETHERNET_SETTING_DEFAULT;
if (!ni_dbus_dict_get_uint32(argument, "scatter-gather", &eth->offload.scatter_gather))
eth->offload.scatter_gather = NI_ETHERNET_SETTING_DEFAULT;
if (!ni_dbus_dict_get_uint32(argument, "tso", &eth->offload.tso))
eth->offload.tso = NI_ETHERNET_SETTING_DEFAULT;
if (!ni_dbus_dict_get_uint32(argument, "ufo", &eth->offload.ufo))
eth->offload.ufo = NI_ETHERNET_SETTING_DEFAULT;
if (!ni_dbus_dict_get_uint32(argument, "gso", &eth->offload.gso))
eth->offload.gso = NI_ETHERNET_SETTING_DEFAULT;
if (!ni_dbus_dict_get_uint32(argument, "gro", &eth->offload.gro))
eth->offload.gro = NI_ETHERNET_SETTING_DEFAULT;
if (!ni_dbus_dict_get_uint32(argument, "lro", &eth->offload.lro))
eth->offload.lro = NI_ETHERNET_SETTING_DEFAULT;
__ni_objectmodel_set_tristate(argument, "rx-csum",
&eth->offload.rx_csum);
__ni_objectmodel_set_tristate(argument, "tx-csum",
&eth->offload.tx_csum);
__ni_objectmodel_set_tristate(argument, "scatter-gather",
&eth->offload.scatter_gather);
__ni_objectmodel_set_tristate(argument, "tso",
&eth->offload.tso);
__ni_objectmodel_set_tristate(argument, "ufo",
&eth->offload.ufo);
__ni_objectmodel_set_tristate(argument, "gso",
&eth->offload.gso);
__ni_objectmodel_set_tristate(argument, "gro",
&eth->offload.gro);
__ni_objectmodel_set_tristate(argument, "lro",
&eth->offload.lro);

return TRUE;
}



#define ETHERNET_UINT_PROPERTY(dbus_name, member_name, rw) \
NI_DBUS_GENERIC_UINT_PROPERTY(ethernet, dbus_name, member_name, rw)
#define ETHERNET_INT_PROPERTY(dbus_name, member_name, rw) \
NI_DBUS_GENERIC_INT_PROPERTY(ethernet, dbus_name, member_name, rw)

const ni_dbus_property_t ni_objectmodel_ethernet_property_table[] = {
ETHERNET_UINT_PROPERTY(link-speed, link_speed, RO),
ETHERNET_UINT_PROPERTY(port-type, port_type, RO),
ETHERNET_UINT_PROPERTY(duplex, duplex, RO),
ETHERNET_UINT_PROPERTY(autoneg-enable, autoneg_enable, RO),
ETHERNET_INT_PROPERTY(autoneg-enable, autoneg_enable, RO),

___NI_DBUS_PROPERTY(
DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING,
Expand Down
29 changes: 19 additions & 10 deletions src/ethernet.c
Expand Up @@ -27,6 +27,15 @@ ni_ethernet_new(void)
ni_ethernet_t *ether;
ether = xcalloc(1, sizeof(ni_ethernet_t));
ni_link_address_init(&ether->permanent_address);
ether->autoneg_enable = NI_TRISTATE_DEFAULT;
ether->offload.rx_csum = NI_TRISTATE_DEFAULT;
ether->offload.tx_csum = NI_TRISTATE_DEFAULT;
ether->offload.scatter_gather = NI_TRISTATE_DEFAULT;
ether->offload.tso = NI_TRISTATE_DEFAULT;
ether->offload.ufo = NI_TRISTATE_DEFAULT;
ether->offload.gso = NI_TRISTATE_DEFAULT;
ether->offload.gro = NI_TRISTATE_DEFAULT;
ether->offload.lro = NI_TRISTATE_DEFAULT;
return ether;
}

Expand Down Expand Up @@ -252,20 +261,20 @@ __ni_ethtool_get_tristate(const char *ifname, __ni_ioctl_info_t *ioc)
int value;

if ((value = __ni_ethtool_get_value(ifname, ioc)) < 0)
return NI_ETHERNET_SETTING_DEFAULT;
return NI_TRISTATE_DEFAULT;

return value? NI_ETHERNET_SETTING_ENABLE : NI_ETHERNET_SETTING_DISABLE;
return value? NI_TRISTATE_ENABLE : NI_TRISTATE_DISABLE;
}

static int
__ni_ethtool_set_tristate(const char *ifname, __ni_ioctl_info_t *ioc, int value)
{
int kern_value;

if (value == NI_ETHERNET_SETTING_DEFAULT)
if (value == NI_TRISTATE_DEFAULT)
return 0;

kern_value = (value == NI_ETHERNET_SETTING_ENABLE);
kern_value = (value == NI_TRISTATE_ENABLE);
return __ni_ethtool_set_value(ifname, ioc, kern_value);
}

Expand Down Expand Up @@ -358,7 +367,7 @@ __ni_system_ethernet_get(const char *ifname, ni_ethernet_t *ether)
ether->port_type = mapped;
}

ether->autoneg_enable = (ecmd.autoneg? NI_ETHERNET_SETTING_ENABLE : NI_ETHERNET_SETTING_DISABLE);
ether->autoneg_enable = (ecmd.autoneg? NI_TRISTATE_ENABLE : NI_TRISTATE_DISABLE);

/* Not used yet:
phy_address
Expand All @@ -375,7 +384,7 @@ __ni_system_ethernet_get(const char *ifname, ni_ethernet_t *ether)

value = __ni_ethtool_get_value(ifname, &__ethtool_gflags);
if (value >= 0)
ether->offload.lro = (value & ETH_FLAG_LRO)? NI_ETHERNET_SETTING_ENABLE : NI_ETHERNET_SETTING_DISABLE;
ether->offload.lro = (value & ETH_FLAG_LRO)? NI_TRISTATE_ENABLE : NI_TRISTATE_DISABLE;

/* Get the permanent address */
{
Expand Down Expand Up @@ -444,10 +453,10 @@ __ni_system_ethernet_set(const char *ifname, const ni_ethernet_t *ether)
}

switch (ether->autoneg_enable) {
case NI_ETHERNET_SETTING_ENABLE:
case NI_TRISTATE_ENABLE:
ecmd.autoneg = 1;
break;
case NI_ETHERNET_SETTING_DISABLE:
case NI_TRISTATE_DISABLE:
ecmd.autoneg = 0;
break;
default: ;
Expand All @@ -466,10 +475,10 @@ __ni_system_ethernet_set(const char *ifname, const ni_ethernet_t *ether)
__ni_ethtool_set_tristate(ifname, &__ethtool_sgso, ether->offload.gso);
__ni_ethtool_set_tristate(ifname, &__ethtool_sgro, ether->offload.gro);

if (ether->offload.lro != NI_ETHERNET_SETTING_DEFAULT) {
if (ether->offload.lro != NI_TRISTATE_DEFAULT) {
value = __ni_ethtool_get_value(ifname, &__ethtool_gflags);
if (value >= 0) {
if (ether->offload.lro == NI_ETHERNET_SETTING_ENABLE)
if (ether->offload.lro == NI_TRISTATE_ENABLE)
value |= ETH_FLAG_LRO;
else
value &= ~ETH_FLAG_LRO;
Expand Down

0 comments on commit b0c2e02

Please sign in to comment.