diff --git a/iopsys-brcm63xx-arm/panther/base-files/lib/functions/marvell.sh b/iopsys-brcm63xx-arm/panther/base-files/lib/functions/marvell.sh index e88ca39e4c725475688b35f5fd155494bb85cef0..cd206d9d74105bff49633f74399897f538aeabe0 100644 --- a/iopsys-brcm63xx-arm/panther/base-files/lib/functions/marvell.sh +++ b/iopsys-brcm63xx-arm/panther/base-files/lib/functions/marvell.sh @@ -2,8 +2,9 @@ disable_addr_learn() { # Disable Address Learning on P0 and P6. Not sure why this is # needed. - ethctl phy ext 0x10 0xb 0x0000 - ethctl phy ext 0x16 0xb 0x0000 + # ethctl phy ext 0x10 0xb 0x0000 + # ethctl phy ext 0x16 0xb 0x0000 + echo test } port_mapping() { @@ -20,6 +21,20 @@ port_mapping() { ethctl phy ext 0x16 0x6 0x0810 } +port_mapping_copper_wan() { + # Dissallow any traffic from P6 (0x16) to any port + ethctl phy ext 0x16 0x6 0x0800 + + # Dissallow any traffic from P1 (0x11) to any port + ethctl phy ext 0x11 0x6 0x0800 + + #P0 <-> P4 + # Allow port 0 (0x10) to send to port 4 + ethctl phy ext 0x10 0x6 0x0810 + # Allow port 4 (0x14) to send to port 0 + ethctl phy ext 0x14 0x6 0x0801 +} + sfp_100() { # Set port to 100BASE-FX ethctl phy ext 0x11 0x17 0x8504 @@ -89,3 +104,32 @@ has_power() { local POWER=$(( 1 << 4 )) fiber_status $POWER } + +wan_sfp_mode () { + # check if there is a sfp-rom present and return 0 if so + # returns 2 if there is an error + i2cget -y 0 0x50 0x0 >/dev/null 2>&1 + return $? +} + +disable_ext_led () { + ethctl phy ext 0x14 0x16 0x80ee > /dev/null +} + +enable_ext_led () { + ethctl phy ext 0x14 0x16 0x8022 > /dev/null +} + +copper_speed100() { + local BIT=$((1 << 8)) + local copper_status_reg + copper_status_reg=$(ethctl phy ext 0x14 0x00 | grep mii | awk '{ print $5 }') + [ $(( copper_status_reg & BIT )) == $BIT ] && return 0 || return 1 +} + +copper_speed1000() { + local BIT=$((2 << 8)) + local copper_status_reg + copper_status_reg=$(ethctl phy ext 0x14 0x00 | grep mii | awk '{ print $5 }') + [ $(( copper_status_reg & BIT )) == $BIT ] && return 0 || return 1 +} diff --git a/iopsys-brcm63xx-arm/panther/base-files/usr/sbin/fiber_wan b/iopsys-brcm63xx-arm/panther/base-files/usr/sbin/fiber_wan index 2add2f2a354049f7eec0863b599861b915454e00..8554f56aa0c92d797216941f97a7893cf47d3316 100755 --- a/iopsys-brcm63xx-arm/panther/base-files/usr/sbin/fiber_wan +++ b/iopsys-brcm63xx-arm/panther/base-files/usr/sbin/fiber_wan @@ -3,26 +3,52 @@ . /lib/functions/marvell.sh get_link() { - # Start with 1000 Mbps - local speed=1000 - sfp_1000 + # Start with 1000 Mbps + local speed=1000 + sfp_1000 - # Toggle between 100 and 1000 Mbps until we get a link when we detect - # fiber energy. - while true; do - if has_power; then - if no_link; then - if [ $speed == 1000 ]; then - sfp_100 - speed=100 - else - sfp_1000 - speed=1000 - fi - fi - fi - sleep 5 - done + # Toggle between 100 and 1000 Mbps until we get a link when we detect + # fiber energy. + while true; do + if wan_sfp_mode; then + #map ports for sfp wan mode + port_mapping + # handle ext and wan led + enable_ext_led + + if has_power; then + if no_link; then + ubus call led.wan_speed set {\"state\":\"OFF\"} + if [ $speed == 1000 ]; then + sfp_100 + speed=100 + else + sfp_1000 + speed=1000 + fi + else + # handle sfp leds + if [ $speed == 1000 ]; then + ubus call led.wan_speed set {\"state\":\"OK\"} + else + ubus call led.wan_speed set {\"state\":\"NOTICE\"} + fi + fi + sleep 5 + else + #wan copper mode + disable_ext_led + port_mapping_copper_wan + if copper_speed1000; then + ubus call led.wan_speed set {\"state\":\"OK\"} + elif copper_speed100; then + ubus call led.wan_speed set {\"state\":\"NOTICE\"} + else + ubus call led.wan_speed set {\"state\":\"OFF\"} + fi + sleep 5 + fi + done } get_link