From dfd42d139357b23fb7629bea3bc39918a660cd4c Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Tue, 22 Feb 2011 02:54:26 +0000 Subject: net/ethtool: official interface for changing ethtool params (bug #195479) Implement a consistent interface for changing ethtool parameters, as suggested in bug 195479. All variable names are based on the long option to ethtool to set each group of parameters. Multiple entries seperated by newlines are permitted for variable values. Signed-off-by: Robin H. Johnson X-Gentoo-Bug: 195479 --- doc/net.example.Linux.in | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ net/Makefile.Linux | 4 +-- net/ethtool.sh | 54 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 net/ethtool.sh diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in index d3b97c5e..69c9ba64 100644 --- a/doc/net.example.Linux.in +++ b/doc/net.example.Linux.in @@ -980,6 +980,72 @@ #ifplugd_eth0="--api-mode=wlan" # man ifplugd for more options +#----------------------------------------------------------------------------- +# Interface hardware tuning & configuration via ethtool +# If you need to change explicit hardware settings on your network card prior +# to bringing the interface up, the following is available. +# +# For a full listing of settings, please consulting ethtool(8) and the output +# of "ethtool --help". +# +# Multiple entries (seperated by newlines) are supported in all of the +# variables as some settings cannot be changed at the same time. +# +# Valid variable name fragments: change pause coalesce ring offload +# change_eeprom identify nfc flash rxfh_indir ntuple + +# Set Wake-On-Lan to listen for SecureOn MagicPacket(tm), the message level to +# notify us of WOL changes, and the SecureOn password to 'DE:AD:BE:EF:CA:FE'. +#ethtool_change_eth0="wol gs +#msglvl wol on +#sopass DE:AD:BE:EF:CA:FE" + +# Disable pause auto-negotiation and explicitly enable RX and TX pause. +#ethtool_pause_eth0="autoneg off +#rx on tx on" + +# Enasble adaptive RX and TX coalescing +#ethtool_coalesce_eth0="adaptive-rx on adaptive-tx on" + +# Change ring buffer settings +#ethtool_ring_eth0="" + +# Enable all offload settings +#ethtool_offload_eth0="rx on tx on sg on tso on ufo on gso on gro on lro on" + +# Change specific bytes in the EEPROM +#ethtool_change_eeprom_eth0="" + +# Run the identify sequence on the interface for 1 second (does not return until completion) +#ethtool_identify_eth0="1" + +# Configure receive network flow classification +#ethtool_nfc_eth0=" +#rx-flow-hash tcp4 f +#rx-flow-hash udp4 s" + +# Flash firmware to all regions +#ethtool_flash_eth0="/some/path/firmware1 0" + +# Flash firmware to region 1 +#ethtool_flash_eth0="/some/path/firmware2 1" + +# Set receive flow hash indirection table for even balancing between N receive queues +#ethtool_rxfh_indir_eth0="equal 4" + +# Configure Rx ntuple filters and actions +#ethtool_ntuple_eth0="" + +# Additionally, there is a special control variable, if you need to change the +# order of option processing. The default order is: +# flash change-eeprom change pause coalesce ring offload identify nfc rxfh-indir ntuple + +# Set global order to default +#ethtool_order="flash change-eeprom change pause coalesce ring offload identify nfc rxfh-indir ntuple" + +# Hypothetical network card that requires a change-eeprom toggle to enable flashing +#ethtool_order_eth0="change-eeprom flash change pause coalesce ring offload nfc rxfh-indir ntuple" + ############################################################################## # ADVANCED CONFIGURATION # diff --git a/net/Makefile.Linux b/net/Makefile.Linux index 7006d74c..f7fb0870 100644 --- a/net/Makefile.Linux +++ b/net/Makefile.Linux @@ -1,7 +1,7 @@ SRCS+= iwconfig.sh.in INC+= adsl.sh apipa.sh arping.sh bonding.sh br2684ctl.sh bridge.sh \ - ccwgroup.sh clip.sh iproute2.sh ifplugd.sh ip6to4.sh ipppd.sh \ - iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh udhcpc.sh \ + ccwgroup.sh clip.sh ethtool.sh iproute2.sh ifplugd.sh ip6to4.sh \ + ipppd.sh iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh udhcpc.sh \ vlan.sh .SUFFIXES: .sh.Linux.in diff --git a/net/ethtool.sh b/net/ethtool.sh new file mode 100644 index 00000000..64b44a62 --- /dev/null +++ b/net/ethtool.sh @@ -0,0 +1,54 @@ +# Copyright (c) 2011 by Gentoo Foundation +# All rights reserved. Released under the 2-clause BSD license. + +_ethtool() { + echo /usr/sbin/ethtool +} + +ethtool_depend() +{ + program $(_ethtool) + before interface +} + +# This is just to trim whitespace, do not add any quoting! +_trim() { + echo $* +} + +ethtool_pre_start() { + local order opt OFS="${OIFS}" + eval order=\$ethtool_order_${IFVAR} + [ -z "${order}" ] && eval order=\$ethtool_order + [ -z "${order}" ] && order="flash change-eeprom change pause coalesce ring offload identify nfc rxfh-indir ntuple" + # ethtool options not used: --driver, --register-dump, --eeprom-dump, --negotiate, --test, --statistics + eindent + for opt in ${order} ; do + local args + eval args=\$ethtool_${opt//-/_}_${IFVAR} + + # Skip everything if no arguments + [ -z "${args}" ] && continue + + # Split on \n + local IFS="$__IFS" + + for p in ${args} ; do + IFS="${OIFS}" + local args_pretty="$(_trim "${p}")" + # Do nothing if empty + [ -z "${args_prety}" ] && continue + args_pretty="--${opt} $IFACE ${args_pretty}" + args="--${opt} $IFACE ${args}" + ebegin "ethtool ${args_pretty}" + $(_ethtool) ${args} + rc=$? + eend $rc "ethtool exit code $rc" + # TODO: ethtool has MANY different exit codes, with no + # documentation as to which ones are fatal or not. For now we + # simply print the exit code and don't stop the start sequence. + done + IFS="${OIFS}" + done + eoutdent +} -- cgit v1.2.3