switch: add switch_ctl.init to restart mt753x ports when LAN reload

This commit is contained in:
hanwckf 2023-12-19 22:56:03 +08:00
parent 96d850d02a
commit 0e1af68761
3 changed files with 23 additions and 5 deletions

View File

@ -42,8 +42,10 @@ endef
define Package/switch/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_DIR) $(1)/lib/network
$(INSTALL_BIN) $(PKG_BUILD_DIR)/switch $(1)/usr/sbin
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) $(PKG_BUILD_DIR)/switch $(1)/usr/sbin/
$(INSTALL_BIN) ./files/switch_ctl.sh $(1)/usr/sbin/
$(INSTALL_BIN) ./files/switch_ctl.init $(1)/etc/init.d/switch_ctl
endef
$(eval $(call BuildPackage,switch))

View File

@ -0,0 +1,16 @@
#!/bin/sh /etc/rc.common
START=99
USE_PROCD=1
service_triggers() {
procd_add_reload_interface_trigger "lan"
}
start_service() {
logger -t "switch_ctl" "restart mt753x all ports"
source "/usr/sbin/switch_ctl.sh"
sw_poweroff_ports "0 1 2 3 4"
sleep 3
sw_poweron_ports "0 1 2 3 4"
}

View File

@ -1,6 +1,6 @@
#!/bin/sh
[ ! -x /usr/sbin/switch ] && exit 1
[ ! -x /usr/sbin/switch ] && return
# power off ports
# $1 ports list, ex: "1 2 3"
@ -14,7 +14,7 @@ sw_poweroff_ports() {
# register 0, bit 11 is power down control bit, set to 1
set_value=$(($ori_value | 0x800))
switch phy cl22 w $p 0 $set_value
switch phy cl22 w $p 0 $set_value >/dev/null 2>&1
done
}
@ -30,7 +30,7 @@ sw_poweron_ports() {
# register 0, bit 11 is power down control bit, set to 0
set_value=$(($ori_value & ~0x800))
switch phy cl22 w $p 0 $set_value
switch phy cl22 w $p 0 $set_value >/dev/null 2>&1
done
}
# restart Auto-neg on ports
@ -45,6 +45,6 @@ sw_restart_port() {
# register 0, bit 9 is Restart Auto-Negotiation bit, set to 1
set_value=$(($ori_value | 0x200))
switch phy cl22 w $p 0 $set_value
switch phy cl22 w $p 0 $set_value >/dev/null 2>&1
done
}