ethmngr: deprecate ports uci file

port to be setup from network uci device section instead
This commit is contained in:
Rahul Thakur 2023-07-26 15:30:34 +05:30
parent cddf178691
commit b64f41dc6b
6 changed files with 2 additions and 348 deletions

View file

@ -44,10 +44,6 @@ endif
define Package/ethmngr/install
$(CP) ./files/common/* $(1)/
ifneq ($(CONFIG_TARGET_brcmbca),)
$(CP) ./files/broadcom/* $(1)/
else
$(CP) ./files/linux/* $(1)/
endif
ifneq ($(CONFIG_TARGET_brcmbca)$(CONFIG_TARGET_airoha)$(CONFIG_TARGET_ipq95xx)$(CONFIG_TARGET_ipq53xx)$(CONFIG_TARGET_mediatek),)
$(INSTALL_DIR) $(1)/usr/sbin

View file

@ -1,144 +0,0 @@
# arg1: port ifname, ex: eth0
get_max_port_speed() {
if [ -z "$1" ]; then
echo 0
return
fi
local ifname="$1"
local phycap="$(ethctl $ifname media-type 2>/dev/null | grep 'PHY Speed Capabilities' | awk '{print$NF}')"
local speed=1000
case "$phycap" in
10GFD*) speed=10000 ;;
5GFD*) speed=5000 ;;
2.5GFD*) speed=2500 ;;
1GFD*) speed=1000 ;;
100MFD*|100MHD*) speed=100 ;;
10MFD*|10MHD*) speed=10 ;;
esac
echo $speed
}
# arg1: port name, ex: eth0
get_port_number() {
[ -z "$1" ] && return
local ports="0 1 2 3 4 5 6 7 8"
local units="0 1"
local port="$1"
local ifname
for unit in $units; do
for prt in $ports; do
ifname="$(ethswctl getifname $unit $prt 2>/dev/null | awk '{print$NF}')"
if [ "$ifname" == "$port" ]; then
echo "$unit $prt"
return
fi
done
done
}
# arg1: port ifname, ex: eth0
reset_port() {
local ifname="$1"
ethctl $ifname phy-reset >/dev/null
}
# 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"
ethctl $ifname phy-power $updown >/dev/null
}
# 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
local unitport="$(get_port_number $ifname)"
local unit=$(echo $unitport | cut -d ' ' -f 1)
local port=$(echo $unitport | cut -d ' ' -f 2)
[ $autoneg -eq 1 ] && autoneg="on" || autoneg="off"
[ "$duplex" == "half" ] && duplex=0 || duplex=1
[ "$duplex" == 0 ] && dplx="HD" || dplx="FD"
[ "$autoneg" == "on" ] && media_type="auto" || media_type="$speed$dplx"
phycaps="$(ethctl $ifname media-type 2>/dev/null | grep 'PHY Speed Capabilities' | awk '{print$NF}')"
numofcaps="$(echo $phycaps | tr ':' ' ' | wc -w)"
# Reset the port before setting new params
reset_port $ifname
if [ "$numofcaps" == "1" ]; then
logger -t "ethmngr" "$ifname is capable of $phycaps only; not setting speed/duplex"
else
logger -t "ethmngr" "$ifname is capable of $phycaps; setting speed/duplex to $media_type"
ethctl $ifname media-type $media_type ${pyhendpoint:+ port $pyhendpoint} &>/dev/null
fi
[ $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
if [ "$auto" == "on" ]; then
# Use ethswctl utility to set pause autoneg
# as ethtool is not setting it properly
ethswctl -c pause -n $unit -p $port -v $pause 2>&1 >/dev/null
else
ethtool --pause $ifname autoneg $auto rx $rx tx $tx 2>/dev/null
fi
power_updown $ifname $enabled
}

View file

@ -9,29 +9,7 @@ PROG=/usr/sbin/ethmngr
. /lib/functions.sh
include /lib/ethernet
configure_ethernet_port(){
local cfg=$1
local ifname enabled speed duplex autoneg eee pause
config_get ifname $cfg ifname
[ -d /sys/class/net/$ifname ] || return
config_get enabled $cfg enabled 1
config_get speed $cfg speed 1000
config_get duplex $cfg duplex "full"
config_get autoneg $cfg autoneg 1
config_get eee $cfg eee 0
config_get pause $cfg pause 0
set_port_settings $ifname $enabled $speed $duplex $autoneg $eee $pause
}
start_service() {
if [ -s /etc/config/ports ]; then
config_load ports
config_foreach configure_ethernet_port ethport
fi
if [ -f $PROG ]; then
procd_open_instance
procd_set_param command ${PROG}
@ -43,8 +21,8 @@ start_service() {
reload_service() {
stop
start
}
:}
service_triggers() {
procd_add_reload_trigger ports
procd_add_reload_trigger network
}

View file

@ -1,81 +0,0 @@
#!/bin/sh
populate_config_from_db() {
. /lib/functions.sh
. /lib/network/utils.sh
include /lib/ethernet
portorder="$(db -q get hw.board.ethernetPortOrder)"
for port in $portorder; do
speed="$(get_max_port_speed $port 2>/dev/null)"
speed="${speed:-1000}"
uci add ports ethport
uci rename ports.@ethport[-1]="$(get_port_name $port)"
uci set ports.@ethport[-1].enabled=1
uci set ports.@ethport[-1].name="$(get_port_name $port)"
uci set ports.@ethport[-1].ifname="$port"
uci set ports.@ethport[-1].speed="$speed"
uci set ports.@ethport[-1].duplex="full"
uci set ports.@ethport[-1].autoneg=1
uci set ports.@ethport[-1].eee=0
if [ "$(db -q get hw.board.ethernetWanPort)" = "$port" ]; then
uci set ports.@ethport[-1].pause=1
uci set ports.@ethport[-1].uplink=1
else
uci set ports.@ethport[-1].pause=0
fi
done
uci commit ports
}
populate_config_from_device_tree() {
for path in $(find /proc/device-tree/ -name "port@*"); do
port="$(cat $path/label)"
[ -n "$port" ] || continue
[ "$port" = "cpu" ] && continue
speed=1000
if [ -e "$path/phy-mode" ]; then
phymode="$(cat $path/phy-mode)"
case "$phymode" in
10000*) speed=10000 ;;
2500*) speed=2500 ;;
esac
fi
PORT="$(echo $port | tr '[a-z]' '[A-Z]')"
uci add ports ethport
uci rename ports.@ethport[-1]="$PORT"
uci set ports.@ethport[-1].enabled=1
uci set ports.@ethport[-1].name="$PORT"
uci set ports.@ethport[-1].ifname="$port"
uci set ports.@ethport[-1].speed="$speed"
uci set ports.@ethport[-1].duplex="full"
uci set ports.@ethport[-1].autoneg=1
uci set ports.@ethport[-1].eee=0
if [ "$port" = "wan" ]; then
uci set ports.@ethport[-1].pause=1
uci set ports.@ethport[-1].uplink=1
else
uci set ports.@ethport[-1].pause=0
fi
done
uci commit ports
}
if [ -s "/etc/config/ports" ]; then
if uci -q get ports.@ethport[0] >/dev/null; then
# exit if there is any valid content
exit 0
else
rm -f /etc/config/ports
fi
fi
touch /etc/config/ports
if [ -f /sbin/db -a -n "$(db get hw.board.ethernetPortOrder 2>/dev/null)" ]; then
populate_config_from_db
elif [ -d /proc/device-tree/ ]; then
populate_config_from_device_tree
fi

View file

@ -1,95 +0,0 @@
# 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
}