Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ CMakeFiles
install_manifest.txt
CMakeLists.txt.user
netifd.kdev4
compile_commands.json
30 changes: 30 additions & 0 deletions device.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = {
[DEV_ATTR_MASTER] = { .name = "conduit", .type = BLOBMSG_TYPE_STRING },
[DEV_ATTR_EEE] = { .name = "eee", .type = BLOBMSG_TYPE_BOOL },
[DEV_ATTR_TAGS] = { .name = "tags", .type = BLOBMSG_TYPE_ARRAY },
[DEV_ATTR_OFFLOAD] = { .name = "ethtool_offload", .type = BLOBMSG_TYPE_ARRAY },
[DEV_ATTR_RING] = { .name = "ethtool_ring", .type = BLOBMSG_TYPE_ARRAY },
[DEV_ATTR_COALESCE] = { .name = "ethtool_coalesce", .type = BLOBMSG_TYPE_ARRAY },
[DEV_ATTR_CHANNELS] = { .name = "ethtool_channels", .type = BLOBMSG_TYPE_ARRAY },
[DEV_ATTR_PRIV] = { .name = "ethtool_priv", .type = BLOBMSG_TYPE_ARRAY },
};

const struct uci_blob_param_list device_attr_list = {
Expand Down Expand Up @@ -590,6 +595,26 @@ device_init_settings(struct device *dev, struct blob_attr **tb)
free(dev->tags);
dev->tags = cur ? blob_memdup(cur) : NULL;

cur = tb[DEV_ATTR_OFFLOAD];
free(dev->ethtool_offload);
dev->ethtool_offload = cur ? blob_memdup(cur) : NULL;

cur = tb[DEV_ATTR_RING];
free(dev->ethtool_ring);
dev->ethtool_ring = cur ? blob_memdup(cur) : NULL;

cur = tb[DEV_ATTR_COALESCE];
free(dev->ethtool_coalesce);
dev->ethtool_coalesce = cur ? blob_memdup(cur) : NULL;

cur = tb[DEV_ATTR_CHANNELS];
free(dev->ethtool_channels);
dev->ethtool_channels = cur ? blob_memdup(cur) : NULL;

cur = tb[DEV_ATTR_PRIV];
free(dev->ethtool_priv);
dev->ethtool_priv = cur ? blob_memdup(cur) : NULL;

device_set_extra_vlans(dev, tb[DEV_ATTR_VLAN]);
device_set_disabled(dev, disabled);
}
Expand Down Expand Up @@ -1093,6 +1118,11 @@ device_free(struct device *dev)
free(dev->tags);
free(dev->config_auth_vlans);
free(dev->extra_vlan);
free(dev->ethtool_offload);
free(dev->ethtool_ring);
free(dev->ethtool_coalesce);
free(dev->ethtool_channels);
free(dev->ethtool_priv);
dev->type->free(dev);
__devlock--;
}
Expand Down
10 changes: 10 additions & 0 deletions device.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ enum {
DEV_ATTR_MASTER,
DEV_ATTR_EEE,
DEV_ATTR_TAGS,
DEV_ATTR_OFFLOAD,
DEV_ATTR_RING,
DEV_ATTR_COALESCE,
DEV_ATTR_CHANNELS,
DEV_ATTR_PRIV,
__DEV_ATTR_MAX,
};

Expand Down Expand Up @@ -252,6 +257,11 @@ struct device {
struct blob_attr *config_auth_vlans;
struct blob_attr *auth_vlans;
struct blob_attr *tags;
struct blob_attr *ethtool_offload;
struct blob_attr *ethtool_ring;
struct blob_attr *ethtool_coalesce;
struct blob_attr *ethtool_channels;
struct blob_attr *ethtool_priv;

char ifname[IFNAMSIZ];
int ifindex;
Expand Down
47 changes: 47 additions & 0 deletions examples/ethtool-tunables-network-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Example: Applying ethtool tunables via /etc/config/network

You can specify ethtool flags for supported family (offload, ring, coalesce, channels, priv) in a device section of `/etc/config/network`.

> This doesn't replace existing flags already handled by netifd via ethtool (like `rxpause`, `txpause`, `autoneg`), it only adds support for additional ethtool tunables.

## Example device config

```
config device
option name 'eth1'
list offload 'sg on'
list offload 'gso on'
list offload 'gro on'
list offload 'tso off'
list offload 'rx_gro_list off'
list offload 'rx_udp_gro_forwarding on'
list ring 'rx 4096'
list ring 'tx 4096'
list coalesce 'rx-usecs 50'
list coalesce 'tx-frames 128'
list channels 'rx 4'
list channels 'tx 4'
list priv 'my_custom_flag on'
option txqueuelen '10000'
```

## Supported ethtool tunable families

- `list offload` (ethtool -K)
- `list ring` (ethtool -G)
- `list coalesce` (ethtool -C)
- `list channels` (ethtool -L)
- `list priv` (ethtool --set-priv-flags)

Each list item is a key-value pair, e.g. `list offload 'tso off'`.

## How it works

- When netifd brings up the device, it parses these lists and applies them using the corresponding system_set_ethtool* handler (see `system-linux.c`).
- All settings are applied via netlink/ethtool, just as in the shell/init script, but natively in C.

## Notes

- You can specify multiple flags per family.
- If a flag is not supported by the driver, it will be ignored or logged as a warning.
- For advanced usage, refer to the system_set_ethtool* handlers in `system-linux.c` for details on what is supported.
Loading