From f8c2a151740803403a48f040c83709427c320d99 Mon Sep 17 00:00:00 2001 From: Marina Maslova Date: Thu, 16 Mar 2023 11:25:48 +0300 Subject: [PATCH] ethmngr: switch airoha to linux --- ethmngr/Makefile | 2 - ethmngr/files/airoha/lib/ethernet/airoha.sh | 208 -------------------- 2 files changed, 210 deletions(-) delete mode 100644 ethmngr/files/airoha/lib/ethernet/airoha.sh diff --git a/ethmngr/Makefile b/ethmngr/Makefile index 00a8c8be9..0d4e0686c 100644 --- a/ethmngr/Makefile +++ b/ethmngr/Makefile @@ -46,8 +46,6 @@ define Package/ethmngr/install $(CP) ./files/common/* $(1)/ ifneq ($(CONFIG_TARGET_brcmbca),) $(CP) ./files/broadcom/* $(1)/ -else ifneq ($(CONFIG_TARGET_airoha),) - $(CP) ./files/airoha/* $(1)/ else $(CP) ./files/linux/* $(1)/ endif diff --git a/ethmngr/files/airoha/lib/ethernet/airoha.sh b/ethmngr/files/airoha/lib/ethernet/airoha.sh deleted file mode 100644 index 51fc6e3a3..000000000 --- a/ethmngr/files/airoha/lib/ethernet/airoha.sh +++ /dev/null @@ -1,208 +0,0 @@ -#!/bin/sh - -. /lib/functions.sh - -unset -f switchmgr -# alias for switchmgr -switchmgr() { - "/userfs/bin/switchmgr" "$@" -} - -unset -f tc3162_get_lan_port -# get lan port port by ifname -# arg1: port ifname, ex: eth0.1 -tc3162_get_lan_port() { - [[ -z "$1" ]] && return 255 - - local ifname="$1" - local if_idx=255 - - # only for tc3162 eth switch ports (eth0.x, 0 < x < 7) - case "${ifname}" in - eth0.*) - ;; - *) - logger -t "port-management" \ - "unsupported - ${ifname} is not tc3162 switch port" - return 255 - ;; - esac - - let "if_idx=$(echo "${ifname}" | cut -f2 -d'.')" - [[ -z "${if_idx}" ]] && return 255 - [[ ${if_idx} -lt 1 || ${if_idx} -gt 6 ]] && { - logger -t "port-management" \ - "incorrect tc3162 lan port index ${if_idx} picked from ifname ${ifname}" - return 255 - } - let "if_idx=${if_idx}-1" - return ${if_idx} -} - - -unset -f tc3162_get_mapped_port -# get mapped switch port by ifname -# arg1: port ifname, ex: eth0.1 -tc3162_get_mapped_port() { - [[ -z "$1" ]] && return 255 - - local ifname="$1" - local if_idx=255 - local prtmap_procfile="/proc/tc3162/eth_portmap" - local lan_prt=255 - local port=255 - local prtmap_out_line_num=4 - local prtmap_out_line="" - - # check "lan port map" marker in portmap output string - prtmap_out_line="$(sed -n "${prtmap_out_line_num}p" ${prtmap_procfile})" - [[ ${prtmap_out_line} != "lan_port_map" ]] && return 255 - - tc3162_get_lan_port "${ifname}" - let "if_idx=$?" - [[ -z "${if_idx}" || ${if_idx} -eq 255 ]] && return - - # get lan portmapping string "lan_port mapped_port" for ifname by it's index - let "prtmap_out_line_num=${prtmap_out_line_num}+1+${if_idx}" - prtmap_out_line="$(sed -n "${prtmap_out_line_num}p" ${prtmap_procfile})" - - # get and check lan port index from lan portmapping string - lan_prt=$(echo "${prtmap_out_line}" | cut -f 1 -d' ') - [[ -z "${lan_prt}" || "${if_idx}" != "${lan_prt}" ]] && return 255 - - # get and check mapped port from lan portmapping string - let "port=$(echo "${prtmap_out_line}" | cut -f 2 -d' ')" - [[ ${port} -lt 0 || ${port} -gt 255 ]] && return 255 - - return ${port} -} - -unset -f get_max_port_speed -# arg1: port ifname, ex: eth0.1 -get_max_port_speed() { - [[ -z "$1" ]] && { echo 0; return; } - - local ifname="$1" - local port=255 - local speed=0 - - [[ -d "/sys/class/net/${ifname}" ]] || { - logger -t "port-management" "interface ${ifname} is not found" - return - } - - tc3162_get_lan_port "${ifname}" - let "port=$?" - [[ -z "${port}" || ${port} -eq 255 ]] && return - - # tc3162 capability for all ports is 1Gbps - speed=1000 - - echo $speed -} - -unset -f power_updown -# arg1: port ifname, ex: eth0.1 -# arg2: port enabled, ex: 0/1/off/on/.. -power_updown() { - [[ -z "$1" ]] && return - [[ -z "$2" ]] && return - - local ifname="$1" - local enabled="$2" - local port=255 - - [[ -d "/sys/class/net/${ifname}" ]] || { - logger -t "port-management" "interface ${ifname} is not found" - return - } - - let "enabled=$(get_bool "${enabled}" "-1")" - [[ ${enabled} -eq -1 ]] && return - - tc3162_get_lan_port "${ifname}" - let "port=$?" - [[ -z "${port}" || ${port} -eq 255 ]] && return - - switchmgr phy admin "${port}" "${enabled}" -} - -unset -f set_port_settings -# arg1: port ifname, ex: eth0.1 -# arg2: port enabled, ex: 0/1/off/on/.. -# arg3: port speed, ex: 1000 -# arg4: port duplex, ex: full -# arg5: port autoneg, ex: 0/1/off/on/.. -# arg6: port eee, ex: 0/1/off/on/.. -# arg7: port pause, ex: 0/1/off/on/.. -set_port_settings() { - [[ -z "$1" ]] && return - [[ -z "$2" ]] && return - [[ -z "$3" ]] && return - [[ -z "$4" ]] && return - [[ -z "$5" ]] && return - [[ -z "$6" ]] && return - [[ -z "$7" ]] && return - - local ifname="$1" - local enabled="$2" - local speed="$3" - local duplex="$4" - local autoneg=$5 - local eee="$6" - local pause="$7" - local port=255 - local speedmode=1 - local last_speed=0 - - [[ -d "/sys/class/net/${ifname}" ]] || { - logger -t "port-management" "interface ${ifname} is not found" - return - } - - let "enabled=$(get_bool "${enabled}" "-1")" - [[ ${enabled} -eq -1 ]] && return - - let "autoneg=$(get_bool "${autoneg}" "-1")" - [[ ${autoneg} -eq -1 ]] && return - - let "eee=$(get_bool "${eee}" "-1")" - [[ ${eee} -eq -1 ]] && return - - let "pause=$(get_bool "${pause}" "-1")" - [[ ${pause} -eq -1 ]] && return - - duplex="$(echo "${duplex}" | awk '{print tolower($0)}')" - [[ "${duplex}" != "half" && "${duplex}" != "full" ]] && return - - tc3162_get_lan_port "${ifname}" - let "port=$?" - [[ -z "${port}" || ${port} -eq 255 ]] && return - - last_speed="$(switchmgr phy maxspeed "${port}" | cut -f2 -d':')" - [[ -z "${last_speed}" || "${last_speed}" == "*Down*" ]] \ - && last_speed=${speed} - - switchmgr phy pause "${port}" "${pause}" - - # set speedmode: speed+duplex+autoneg -# FIXME: switchmgr has no separate setting for 1Gbps speed - use autoneg instead - if [[ ${autoneg} -eq 1 || ${speed} -gt 100 ]]; then - switchmgr phy speedmode ${port} "1" - else - [[ ${speed} -gt 10 ]] && let "speedmode=2" || let "speedmode=4" - [[ "${duplex}" == "half" ]] && let "speedmode=${speedmode}+1" - switchmgr phy speedmode "${port}" "${speedmode}" - fi - -# TODO: implement MAC control register manipulations (mapped ports used) for - # eee settings change - # separate (tx/rx) pause (flow control) settings change - # set speed to 1Gbps separately from autoneg mode - -# FIXME: workaround for duplex/pause settings being not applied if speed is unchanged - [[ ${last_speed} -eq ${speed} ]] && power_updown "${ifname}" 0 - - power_updown "${ifname}" ${enabled} - -} \ No newline at end of file