From: Michael Tremer Date: Fri, 21 Sep 2018 12:22:39 +0000 (+0200) Subject: Add support for hardware offloading X-Git-Tag: 010~46 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c3db141289f6e35b4c03e9a78fdb67dcf5712b4f;p=network.git Add support for hardware offloading Hardware offloading will now be enabled on physical and bonding devices automatically. Signed-off-by: Michael Tremer --- diff --git a/src/functions/functions.constants b/src/functions/functions.constants index 0d6cdd2f..63c5cad2 100644 --- a/src/functions/functions.constants +++ b/src/functions/functions.constants @@ -94,6 +94,30 @@ DISCOVER_NOT_SUPPORTED=2 # Default MTU DEFAULT_MTU=1500 +# A list of supported device offloading mechanisms +# that are being mapped to the ethtool command +declare -A DEVICE_SUPPORTED_OFFLOADINGS=( + [generic-receive-offload]="gro" + [generic-segmentation-offload]="gso" + [large-receive-offload]="lro" + [rx-checksumming]="rx" + [scatter-gather]="sg" + [tcp-segmentation-offload]="tso" + [tx-checksumming]="tx" + [udp-fragmentation-offload]="ufo" +) + +# These offloadings will automatically be enabled (if supported) +DEVICE_AUTO_OFFLOADINGS=( + generic-receive-offload + generic-segmentation-offload + rx-checksumming + scatter-gather + tcp-segmentation-offload + tx-checksumming + udp-fragmentation-offload +) + # The user is able to create zones that begin # with these names followed by a number. ZONE_LOCAL="net" diff --git a/src/functions/functions.device b/src/functions/functions.device index 8384273d..e8fdc826 100644 --- a/src/functions/functions.device +++ b/src/functions/functions.device @@ -974,6 +974,47 @@ device_get_link_string() { print "${s}" } +device_auto_offloading() { + local device="${1}" + assert isset device + + # Enable all offloadings that we consider a good default + local offloading + for offloading in ${DEVICE_AUTO_OFFLOADINGS[@]}; do + device_set_offloading "${device}" "${offloading}" "on" + done + + return ${EXIT_OK} +} + +device_set_offloading() { + local device="${1}" + assert isset device + + local offloading="${2}" + assert isoneof offloading ${!DEVICE_SUPPORTED_OFFLOADINGS[@]} + + local value="${3}" + assert isoneof value on off + + # Translate to ethool option + local mode="${DEVICE_SUPPORTED_OFFLOADINGS[${offloading}]}" + if ! isset mode; then + error "Unsupported offloading mode: ${offloading}" + return ${EXIT_ERROR} + fi + + # Run ethtool + if ! cmd_quiet ethtool --offload "${device}" "${mode}" "${value}"; then + log DEBUG "Could not set ${offloading} on ${device} to ${value}" + return ${EXIT_ERROR} + fi + + log DEBUG "Set ${offloading} on ${device} to ${value}" + + return ${EXIT_OK} +} + device_auto_configure_smp_affinity() { assert [ $# -eq 1 ] diff --git a/src/hooks/ports/bonding b/src/hooks/ports/bonding index 36bcf6c7..d8bc5839 100644 --- a/src/hooks/ports/bonding +++ b/src/hooks/ports/bonding @@ -175,6 +175,9 @@ hook_up() { port_settings_read "${port}" ${HOOK_SETTINGS} + # Enable hardware offloading + device_auto_offloading "${port}" + # Execute the default action hook_default_up "${port}" diff --git a/src/hooks/ports/ethernet b/src/hooks/ports/ethernet index ddc76c3c..c7750f9d 100644 --- a/src/hooks/ports/ethernet +++ b/src/hooks/ports/ethernet @@ -117,6 +117,9 @@ hook_up() { device_advertise_link_speeds "${port}" ${ADVERTISED_LINK_SPEEDS} fi + # Enable hardware offloading + device_auto_offloading "${port}" + # Bring up the device device_set_up "${port}"