Skip to content

Commit

Permalink
ethernet: handle ethtool offload as independent structure
Browse files Browse the repository at this point in the history
  • Loading branch information
wipawel committed Oct 9, 2014
1 parent 58ee700 commit 055b6f1
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 61 deletions.
44 changes: 28 additions & 16 deletions client/compat.c
Expand Up @@ -200,10 +200,36 @@ __ni_compat_optional_tristate(const char *name, xml_node_t *node, ni_tristate_t
}
}

static void
__ni_compat_generate_eth_offload_node(xml_node_t *parent, const ni_ethtool_offload_t *offload)
{
xml_node_t *node;

if (!parent || !offload)
return;

/* generate offload and other information */
node = xml_node_new("offload", NULL);

__ni_compat_optional_tristate("rx-csum", node, offload->rx_csum);
__ni_compat_optional_tristate("tx-csum", node, offload->tx_csum);
__ni_compat_optional_tristate("scatter-gather", node, offload->scatter_gather);
__ni_compat_optional_tristate("tso", node, offload->tso);
__ni_compat_optional_tristate("ufo", node, offload->ufo);
__ni_compat_optional_tristate("gso", node, offload->gso);
__ni_compat_optional_tristate("gro", node, offload->gro);
__ni_compat_optional_tristate("lro", node, offload->lro);

if (node->children)
xml_node_add_child(parent, node);
else
xml_node_free(node);

}

static void
__ni_compat_generate_eth_node(xml_node_t *child, const ni_ethernet_t *eth)
{
xml_node_t *offload;
const char *ptr;

/* generate common <ethernet> node settings */
Expand Down Expand Up @@ -242,21 +268,7 @@ __ni_compat_generate_eth_node(xml_node_t *child, const ni_ethernet_t *eth)
xml_node_free(wol);
}

/* generate offload and other information */
offload = xml_node_new("offload", NULL);
__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
xml_node_free(offload);
__ni_compat_generate_eth_offload_node(child, &eth->offload);
}

static ni_bool_t
Expand Down
53 changes: 27 additions & 26 deletions client/suse/compat-suse.c
Expand Up @@ -1442,32 +1442,33 @@ try_add_ethtool_common(ni_netdev_t *dev, const char *opt, const char *val)
}

static void
try_add_ethtool_offload(ni_netdev_t *dev, const char *opt, const char *val)
try_add_ethtool_offload(ni_ethtool_offload_t *offload, const char *opt, const char *val)
{
ni_ethernet_t *eth = ni_netdev_get_ethernet(dev);
if (ni_string_eq(opt, "rx")) {
ni_parse_ethtool_onoff(val, &eth->offload.rx_csum);
} else
if (ni_string_eq(opt, "tx")) {
ni_parse_ethtool_onoff(val, &eth->offload.tx_csum);
} else
if (ni_string_eq(opt, "sg")) {
ni_parse_ethtool_onoff(val, &eth->offload.scatter_gather);
} else
if (ni_string_eq(opt, "tso")) {
ni_parse_ethtool_onoff(val, &eth->offload.tso);
} else
if (ni_string_eq(opt, "ufo")) {
ni_parse_ethtool_onoff(val, &eth->offload.ufo);
} else
if (ni_string_eq(opt, "gso")) {
ni_parse_ethtool_onoff(val, &eth->offload.gso);
} else
if (ni_string_eq(opt, "gro")) {
ni_parse_ethtool_onoff(val, &eth->offload.gro);
} else
if (ni_string_eq(opt, "lro")) {
ni_parse_ethtool_onoff(val, &eth->offload.lro);
if (offload) {
if (ni_string_eq(opt, "rx")) {
ni_parse_ethtool_onoff(val, &offload->rx_csum);
} else
if (ni_string_eq(opt, "tx")) {
ni_parse_ethtool_onoff(val, &offload->tx_csum);
} else
if (ni_string_eq(opt, "sg")) {
ni_parse_ethtool_onoff(val, &offload->scatter_gather);
} else
if (ni_string_eq(opt, "tso")) {
ni_parse_ethtool_onoff(val, &offload->tso);
} else
if (ni_string_eq(opt, "ufo")) {
ni_parse_ethtool_onoff(val, &offload->ufo);
} else
if (ni_string_eq(opt, "gso")) {
ni_parse_ethtool_onoff(val, &offload->gso);
} else
if (ni_string_eq(opt, "gro")) {
ni_parse_ethtool_onoff(val, &offload->gro);
} else
if (ni_string_eq(opt, "lro")) {
ni_parse_ethtool_onoff(val, &offload->lro);
}
}
}

Expand All @@ -1479,7 +1480,7 @@ try_add_ethtool_options(ni_netdev_t *dev, const char *type,

if (ni_string_eq(type, "-K") || ni_string_eq(type, "--offload")) {
for (i = start; (i + 1) < opts->count; i+=2) {
try_add_ethtool_offload(dev, opts->data[i],
try_add_ethtool_offload(&dev->ethernet->offload, opts->data[i],
opts->data[i + 1]);
}
} else
Expand Down
23 changes: 12 additions & 11 deletions include/wicked/ethernet.h
Expand Up @@ -44,6 +44,17 @@ typedef struct ni_ethernet_wol {
ni_hwaddr_t sopass;
} ni_ethernet_wol_t;

typedef struct ni_ethtool_offload {
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;
} ni_ethtool_offload_t;

struct ni_ethernet {
ni_hwaddr_t permanent_address;
unsigned int link_speed;
Expand All @@ -52,17 +63,7 @@ struct ni_ethernet {
ni_tristate_t autoneg_enable;

ni_ethernet_wol_t wol;

struct {
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;
ni_ethtool_offload_t offload;

unsigned int identify_time;
};
Expand Down
25 changes: 17 additions & 8 deletions src/ethernet.c
Expand Up @@ -65,6 +65,7 @@

static int __ni_system_ethernet_get(const char *, ni_ethernet_t *);
static int __ni_system_ethernet_set(const char *, const ni_ethernet_t *);
static void ni_ethtool_offload_init(ni_ethtool_offload_t *);

/*
* Allocate ethernet struct
Expand All @@ -79,14 +80,8 @@ ni_ethernet_new(void)
ether->wol.options = __NI_ETHERNET_WOL_DEFAULT;
ni_link_address_init(&ether->wol.sopass);
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;
ni_ethtool_offload_init(&ether->offload);

return ether;
}

Expand Down Expand Up @@ -520,6 +515,20 @@ __ni_ethtool_set_wol(const char *ifname, const ni_ethernet_wol_t *wol)
return 0;
}

static void
ni_ethtool_offload_init(ni_ethtool_offload_t *offload)
{
if (offload) {
offload->rx_csum = NI_TRISTATE_DEFAULT;
offload->tx_csum = NI_TRISTATE_DEFAULT;
offload->scatter_gather = NI_TRISTATE_DEFAULT;
offload->tso = NI_TRISTATE_DEFAULT;
offload->ufo = NI_TRISTATE_DEFAULT;
offload->gso = NI_TRISTATE_DEFAULT;
offload->gro = NI_TRISTATE_DEFAULT;
offload->lro = NI_TRISTATE_DEFAULT;
}
}
/*
* Handle ethtool stats
*/
Expand Down

0 comments on commit 055b6f1

Please sign in to comment.