mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
95 lines
1.6 KiB
Bash
95 lines
1.6 KiB
Bash
# arg1: port ifname, ex: eth0
|
|
get_max_port_speed() {
|
|
if [ -z "$1" ]; then
|
|
echo 0
|
|
return
|
|
fi
|
|
|
|
local ifname="$1"
|
|
local phycap="$(ethtool $ifname | grep -A 10 "Supported link modes" | grep 00 | tail -n 1 | awk '{print$NF}')"
|
|
local speed=1000
|
|
|
|
case "$phycap" in
|
|
10000*) speed=10000 ;;
|
|
5000*) speed=5000 ;;
|
|
2500*) speed=2500 ;;
|
|
1000*) speed=1000 ;;
|
|
100*) speed=100 ;;
|
|
10*) speed=10 ;;
|
|
esac
|
|
|
|
echo $speed
|
|
}
|
|
|
|
# arg1: port ifname, ex: eth0
|
|
# arg2: port enabled, ex: 1
|
|
power_updown() {
|
|
local ifname="$1"
|
|
local enabled=$2
|
|
|
|
local updown="up"
|
|
[ $enabled -eq 0 ] && updown="down"
|
|
ip link set dev $ifname $updown
|
|
}
|
|
|
|
# arg1: port ifname, ex: eth0
|
|
# arg2: port enabled, ex: 1
|
|
# arg3: port speed, ex: 1000
|
|
# arg4: port duplex, ex: full
|
|
# arg5: port autoneg, ex: on
|
|
# arg6: port eee, ex: 0
|
|
# arg7: port pause, ex: 0
|
|
set_port_settings() {
|
|
local ifname="$1"
|
|
local enabled=$2
|
|
local speed="$3"
|
|
local duplex=$4
|
|
local autoneg=$5
|
|
local eee=$6
|
|
local pause=$7
|
|
|
|
[ -d /sys/class/net/$ifname ] || return
|
|
|
|
[ $autoneg -eq 1 ] && autoneg="on" || autoneg="off"
|
|
ethtool --change $ifname speed $speed duplex $duplex autoneg $autoneg
|
|
|
|
[ $eee -eq 1 ] && eee="on" || eee="off"
|
|
ethtool --set-eee $ifname eee $eee 2>/dev/null
|
|
|
|
case $pause in
|
|
off|0)
|
|
pause=0x0
|
|
auto=off
|
|
rx=off
|
|
tx=off
|
|
;;
|
|
on|1)
|
|
pause=0x2
|
|
auto=off
|
|
rx=on
|
|
tx=on
|
|
;;
|
|
auto)
|
|
pause=0x1
|
|
auto=on
|
|
rx=on
|
|
tx=on
|
|
;;
|
|
tx)
|
|
pause=0x3
|
|
auto=off
|
|
rx=off
|
|
tx=on
|
|
;;
|
|
rx)
|
|
pause=0x4
|
|
auto=off
|
|
rx=on
|
|
tx=off
|
|
;;
|
|
esac
|
|
|
|
ethtool --pause $ifname autoneg $auto rx $rx tx $tx 2>/dev/null
|
|
|
|
power_updown $ifname $enabled
|
|
}
|