From b64f41dc6ba4cc0c29b4b867d9b151d4d44ae835 Mon Sep 17 00:00:00 2001 From: Rahul Thakur Date: Wed, 26 Jul 2023 15:30:34 +0530 Subject: [PATCH] ethmngr: deprecate ports uci file port to be setup from network uci device section instead --- ethmngr/Makefile | 4 - .../files/broadcom/lib/ethernet/broadcom.sh | 144 ------------------ ethmngr/files/common/etc/config/ports | 0 ethmngr/files/common/etc/init.d/ethmngr | 26 +--- .../etc/uci-defaults/15-ports-config-generate | 81 ---------- ethmngr/files/linux/lib/ethernet/linux.sh | 95 ------------ 6 files changed, 2 insertions(+), 348 deletions(-) delete mode 100644 ethmngr/files/broadcom/lib/ethernet/broadcom.sh delete mode 100644 ethmngr/files/common/etc/config/ports delete mode 100644 ethmngr/files/common/etc/uci-defaults/15-ports-config-generate delete mode 100644 ethmngr/files/linux/lib/ethernet/linux.sh diff --git a/ethmngr/Makefile b/ethmngr/Makefile index bfd5db039..5052a4922 100644 --- a/ethmngr/Makefile +++ b/ethmngr/Makefile @@ -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 diff --git a/ethmngr/files/broadcom/lib/ethernet/broadcom.sh b/ethmngr/files/broadcom/lib/ethernet/broadcom.sh deleted file mode 100644 index 0f39eca22..000000000 --- a/ethmngr/files/broadcom/lib/ethernet/broadcom.sh +++ /dev/null @@ -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 -} diff --git a/ethmngr/files/common/etc/config/ports b/ethmngr/files/common/etc/config/ports deleted file mode 100644 index e69de29bb..000000000 diff --git a/ethmngr/files/common/etc/init.d/ethmngr b/ethmngr/files/common/etc/init.d/ethmngr index 0259ec23f..9374f778e 100755 --- a/ethmngr/files/common/etc/init.d/ethmngr +++ b/ethmngr/files/common/etc/init.d/ethmngr @@ -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 } diff --git a/ethmngr/files/common/etc/uci-defaults/15-ports-config-generate b/ethmngr/files/common/etc/uci-defaults/15-ports-config-generate deleted file mode 100644 index 2327df8cf..000000000 --- a/ethmngr/files/common/etc/uci-defaults/15-ports-config-generate +++ /dev/null @@ -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 diff --git a/ethmngr/files/linux/lib/ethernet/linux.sh b/ethmngr/files/linux/lib/ethernet/linux.sh deleted file mode 100644 index 75e904ce0..000000000 --- a/ethmngr/files/linux/lib/ethernet/linux.sh +++ /dev/null @@ -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 -}