summaryrefslogtreecommitdiff
path: root/meta-facebook/meta-bletchley
diff options
context:
space:
mode:
authorPotin Lai <potin.lai@quantatw.com>2022-10-21 14:19:25 +0300
committerPatrick Williams <patrick@stwcx.xyz>2022-10-25 01:08:32 +0300
commit2f800caba573f4b7137df426782d407ad50b8fcd (patch)
tree1ce78ac759e2a68004010d461bbd94b44672fa9f /meta-facebook/meta-bletchley
parent25cd59bcd0f4abc0fed470574aefe8b38a459884 (diff)
downloadopenbmc-2f800caba573f4b7137df426782d407ad50b8fcd.tar.xz
meta-bletchley: add bletchley-host-state-monitor service
Add a service for monitoring host power state by query port status via mdio bus. Test Results: - Poweron SLED6 root@bletchley:~# obmcutil -i=6 poweron root@bletchley:~# obmcutil -i=6 state CurrentBMCState : xyz.openbmc_project.State.BMC.BMCState.Ready CurrentPowerState : xyz.openbmc_project.State.Chassis.PowerState.On CurrentHostState : xyz.openbmc_project.State.Host.HostState.Running BootProgress : xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified OperatingSystemState: xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive root@bletchley:~# journalctl -u bletchley-host-state-monitor ... Oct 24 07:55:17 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 5 Oct 24 07:55:18 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 4 Oct 24 07:55:22 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 5 Oct 24 07:55:23 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 4 Oct 24 07:55:27 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 5 Oct 24 07:55:29 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 4 Oct 24 07:55:30 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 3 Oct 24 07:55:31 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 2 Oct 24 07:55:33 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 1 Oct 24 07:55:34 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed, update host state to ON - Poweroff SLED6 root@bletchley:~# obmcutil -i=6 poweroff root@bletchley:~# obmcutil -i=6 state CurrentBMCState : xyz.openbmc_project.State.BMC.BMCState.Ready CurrentPowerState : xyz.openbmc_project.State.Chassis.PowerState.Off CurrentHostState : xyz.openbmc_project.State.Host.HostState.Off BootProgress : xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified OperatingSystemState: xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive root@bletchley:~# journalctl -u bletchley-host-state-monitor Oct 21 09:38:21 bletchley systemd[1]: Started Bletchley host state monitoring. ... Oct 24 07:55:17 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 5 Oct 24 07:55:18 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 4 Oct 24 07:55:22 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 5 Oct 24 07:55:23 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 4 Oct 24 07:55:27 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 5 Oct 24 07:55:29 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 4 Oct 24 07:55:30 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 3 Oct 24 07:55:31 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 2 Oct 24 07:55:33 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:OFF, current:ON), check count: 1 Oct 24 07:55:34 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed, update host state to ON Oct 24 08:03:38 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:ON, current:OFF), check count: 5 Oct 24 08:03:39 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:ON, current:OFF), check count: 4 Oct 24 08:03:40 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:ON, current:OFF), check count: 3 Oct 24 08:03:42 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:ON, current:OFF), check count: 2 Oct 24 08:03:43 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed (previous:ON, current:OFF), check count: 1 Oct 24 08:03:44 bletchley bletchley-host-state-monitor[905]: SLED6: detected state changed, update host state to OFF Signed-off-by: Potin Lai <potin.lai@quantatw.com> Change-Id: I5916cd411c0d7d625b54f74c888aa380e00a1853
Diffstat (limited to 'meta-facebook/meta-bletchley')
-rw-r--r--meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/files/bletchley-host-state-monitor161
-rw-r--r--meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/files/bletchley-host-state-monitor.service50
-rw-r--r--meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/plat-svc_0.1.bb8
3 files changed, 216 insertions, 3 deletions
diff --git a/meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/files/bletchley-host-state-monitor b/meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/files/bletchley-host-state-monitor
new file mode 100644
index 0000000000..f34e4bd439
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/files/bletchley-host-state-monitor
@@ -0,0 +1,161 @@
+#!/bin/bash
+
+export PATH=$PATH:/usr/sbin:/usr/libexec
+
+# shellcheck source=meta-facebook/meta-bletchley/recipes-bletchley/plat-tools/files/bletchley-common-functions
+source /usr/libexec/bletchley-common-functions
+
+MDIO_TOOL="/usr/sbin/mdio"
+SWITCH_MDIO_BUS="1e650000.mdio-1"
+
+declare -a PORT_NUM_MAP=(10 3 2 1 7 6 5)
+
+declare -a HOST_PREVIOUS_STATE=("" "" "" "" "" "" "")
+declare -a HOST_STATE_CHANGE_CHECK=(0 0 0 0 0 0 0)
+HOST_STATE_CHANGE_CHECH_CNT=5
+
+declare -A HOST_ACPI_ST_MAP
+HOST_ACPI_ST_MAP["UNKNOW"]="Unknow"
+HOST_ACPI_ST_MAP["NOT_PRESENT"]="G3"
+HOST_ACPI_ST_MAP["AC_OFF"]="G3"
+HOST_ACPI_ST_MAP["OFF"]="G3"
+HOST_ACPI_ST_MAP["SLEEP"]="SLEEP"
+HOST_ACPI_ST_MAP["ON"]="S0_G0_D0"
+
+declare -A HOST_STATE_MAP
+HOST_STATE_MAP["UNKNOW"]="Quiesced"
+HOST_STATE_MAP["NOT_PRESENT"]="Off"
+HOST_STATE_MAP["AC_OFF"]="Off"
+HOST_STATE_MAP["OFF"]="Off"
+HOST_STATE_MAP["SLEEP"]="Standby"
+HOST_STATE_MAP["ON"]="Running"
+
+declare -A CHASSIS_PWR_STATE_MAP
+CHASSIS_PWR_STATE_MAP["UNKNOW"]="On"
+CHASSIS_PWR_STATE_MAP["NOT_PRESENT"]="Off"
+CHASSIS_PWR_STATE_MAP["AC_OFF"]="Off"
+CHASSIS_PWR_STATE_MAP["OFF"]="On"
+CHASSIS_PWR_STATE_MAP["SLEEP"]="On"
+CHASSIS_PWR_STATE_MAP["ON"]="On"
+
+is_host_ac_on()
+{
+ local HOST_ID=$1
+ local I2C_BUS
+ local P1_OUTPUT_REG
+ local P1_CONFIG_REG
+ local HOST_PWR
+ local IS_OUTPUT
+
+ I2C_BUS=$((HOST_ID-1))
+ P1_OUTPUT_REG=$(i2cget -f -y "$I2C_BUS" 0x76 0x03)
+ P1_CONFIG_REG=$(i2cget -f -y "$I2C_BUS" 0x76 0x07)
+ HOST_PWR="$(( (P1_OUTPUT_REG & 0x80)>>7 ))"
+ IS_OUTPUT="$(( (~P1_CONFIG_REG & 0x80)>>7 ))"
+
+ if [ "$((HOST_PWR & IS_OUTPUT))" -eq 1 ];then
+ return 0
+ fi
+
+ return 1
+}
+
+update_host_acpi_power_state()
+{
+ local BUS_NAME="xyz.openbmc_project.Settings"
+ local OBJ_PATH="/xyz/openbmc_project/control/host$1/acpi_power_state"
+ local DBUS_PROPERTIES_INTF_NAME="org.freedesktop.DBus.Properties"
+ local INTF_NAME="xyz.openbmc_project.Control.Power.ACPIPowerState"
+ local PROPERTY_NAME="SysACPIStatus"
+ local PROPERTY_VAL="xyz.openbmc_project.Control.Power.ACPIPowerState.ACPI.$2"
+ busctl call "$BUS_NAME" "$OBJ_PATH" "$DBUS_PROPERTIES_INTF_NAME" Set ssv "$INTF_NAME" "$PROPERTY_NAME" s "$PROPERTY_VAL"
+}
+
+update_host_state()
+{
+ local BUS_NAME="xyz.openbmc_project.State.Host$1"
+ local OBJ_PATH="/xyz/openbmc_project/state/host$1"
+ local DBUS_PROPERTIES_INTF_NAME="org.freedesktop.DBus.Properties"
+ local INTF_NAME="xyz.openbmc_project.State.Host"
+ local PROPERTY_NAME="CurrentHostState"
+ local PROPERTY_VAL="xyz.openbmc_project.State.Host.HostState.$2"
+ busctl call "$BUS_NAME" "$OBJ_PATH" "$DBUS_PROPERTIES_INTF_NAME" Set ssv "$INTF_NAME" "$PROPERTY_NAME" s "$PROPERTY_VAL"
+}
+
+update_chassis_power_state()
+{
+ local BUS_NAME="xyz.openbmc_project.State.Chassis$1"
+ local OBJ_PATH="/xyz/openbmc_project/state/chassis$1"
+ local DBUS_PROPERTIES_INTF_NAME="org.freedesktop.DBus.Properties"
+ local INTF_NAME="xyz.openbmc_project.State.Chassis"
+ local PROPERTY_NAME="CurrentPowerState"
+ local PROPERTY_VAL="xyz.openbmc_project.State.Chassis.PowerState.$2"
+ busctl call "$BUS_NAME" "$OBJ_PATH" "$DBUS_PROPERTIES_INTF_NAME" Set ssv "$INTF_NAME" "$PROPERTY_NAME" s "$PROPERTY_VAL"
+}
+
+update_sled_led_state()
+{
+ local HOST_ID=$1
+ local HOST_STATE=$2
+ case "$HOST_STATE" in
+ ON|SLEEP)
+ systemctl start obmc-led-group-start@sled"$i"_good.service
+ ;;
+ AC_OFF|OFF)
+ systemctl start obmc-led-group-stop@sled"$i"_good.service
+ ;;
+ *)
+ ;;
+ esac
+}
+
+check_host_state()
+{
+ if ! PORT_ST_VAL=$("$MDIO_TOOL" "$SWITCH_MDIO_BUS" phy "${PORT_NUM_MAP[$1]}" 0x00); then
+ # failed to get port status via mdio
+ echo "UNKNOW"
+ return 1
+ fi
+
+ if [ $((PORT_ST_VAL&16#0800)) -eq $((16#0000)) ]; then
+ echo "OFF"
+ elif [ $((PORT_ST_VAL&16#0A00)) -eq $((16#0A00)) ]; then
+ echo "ON"
+ elif [ $((PORT_ST_VAL&16#0900)) -eq $((16#0900)) ]; then
+ echo "SLEEP"
+ else
+ echo "UNKNOW"
+ fi
+ return 0
+}
+
+while true
+do
+ for i in {1..6}
+ do
+ HOST_STATE=""
+ if ! is_sled_present "$i"; then
+ HOST_STATE="NOT_PRESENT"
+ elif ! is_host_ac_on "$i"; then
+ HOST_STATE="AC_OFF"
+ else
+ HOST_STATE=$(check_host_state "$i")
+ fi
+
+ if [ "$HOST_STATE" = "${HOST_PREVIOUS_STATE[$i]}" ]; then
+ HOST_STATE_CHANGE_CHECK[$i]="$HOST_STATE_CHANGE_CHECH_CNT"
+ elif [ "${HOST_STATE_CHANGE_CHECK[$i]}" -gt "0" ]; then
+ echo "SLED$i: detected state changed (previous:${HOST_PREVIOUS_STATE[$i]}, current:$HOST_STATE), check count: ${HOST_STATE_CHANGE_CHECK[$i]}"
+ HOST_STATE_CHANGE_CHECK[$i]=$((HOST_STATE_CHANGE_CHECK[i]-1))
+ else
+ echo "SLED$i: detected state changed, update host state to $HOST_STATE"
+ update_host_acpi_power_state "$i" "${HOST_ACPI_ST_MAP[$HOST_STATE]}"
+ update_host_state "$i" "${HOST_STATE_MAP[$HOST_STATE]}"
+ update_chassis_power_state "$i" "${CHASSIS_PWR_STATE_MAP[$HOST_STATE]}"
+ update_sled_led_state "$i" "$HOST_STATE"
+ HOST_STATE_CHANGE_CHECK[$i]="$HOST_STATE_CHANGE_CHECH_CNT"
+ HOST_PREVIOUS_STATE[$i]="$HOST_STATE"
+ fi
+ done
+ sleep 1
+done \ No newline at end of file
diff --git a/meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/files/bletchley-host-state-monitor.service b/meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/files/bletchley-host-state-monitor.service
new file mode 100644
index 0000000000..bba0dc0467
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/files/bletchley-host-state-monitor.service
@@ -0,0 +1,50 @@
+[Unit]
+Description=Bletchley host state monitoring
+Wants=mapper-wait@-xyz-openbmc_project-state-chassis1.service
+After=mapper-wait@-xyz-openbmc_project-state-chassis1.service
+Wants=mapper-wait@-xyz-openbmc_project-state-chassis2.service
+After=mapper-wait@-xyz-openbmc_project-state-chassis2.service
+Wants=mapper-wait@-xyz-openbmc_project-state-chassis3.service
+After=mapper-wait@-xyz-openbmc_project-state-chassis3.service
+Wants=mapper-wait@-xyz-openbmc_project-state-chassis4.service
+After=mapper-wait@-xyz-openbmc_project-state-chassis4.service
+Wants=mapper-wait@-xyz-openbmc_project-state-chassis5.service
+After=mapper-wait@-xyz-openbmc_project-state-chassis5.service
+Wants=mapper-wait@-xyz-openbmc_project-state-chassis6.service
+After=mapper-wait@-xyz-openbmc_project-state-chassis6.service
+Wants=mapper-wait@-xyz-openbmc_project-state-host1.service
+After=mapper-wait@-xyz-openbmc_project-state-host1.service
+Wants=mapper-wait@-xyz-openbmc_project-state-host2.service
+After=mapper-wait@-xyz-openbmc_project-state-host2.service
+Wants=mapper-wait@-xyz-openbmc_project-state-host3.service
+After=mapper-wait@-xyz-openbmc_project-state-host3.service
+Wants=mapper-wait@-xyz-openbmc_project-state-host4.service
+After=mapper-wait@-xyz-openbmc_project-state-host4.service
+Wants=mapper-wait@-xyz-openbmc_project-state-host5.service
+After=mapper-wait@-xyz-openbmc_project-state-host5.service
+Wants=mapper-wait@-xyz-openbmc_project-state-host6.service
+After=mapper-wait@-xyz-openbmc_project-state-host6.service
+Wants=mapper-wait@-xyz-openbmc_project-state-host6.service
+After=mapper-wait@-xyz-openbmc_project-state-host6.service
+Wants=mapper-wait@-xyz-openbmc_project-control-host1-acpi_power_state.service
+After=mapper-wait@-xyz-openbmc_project-control-host1-acpi_power_state.service
+Wants=mapper-wait@-xyz-openbmc_project-control-host2-acpi_power_state.service
+After=mapper-wait@-xyz-openbmc_project-control-host2-acpi_power_state.service
+Wants=mapper-wait@-xyz-openbmc_project-control-host3-acpi_power_state.service
+After=mapper-wait@-xyz-openbmc_project-control-host3-acpi_power_state.service
+Wants=mapper-wait@-xyz-openbmc_project-control-host4-acpi_power_state.service
+After=mapper-wait@-xyz-openbmc_project-control-host4-acpi_power_state.service
+Wants=mapper-wait@-xyz-openbmc_project-control-host5-acpi_power_state.service
+After=mapper-wait@-xyz-openbmc_project-control-host5-acpi_power_state.service
+Wants=mapper-wait@-xyz-openbmc_project-control-host6-acpi_power_state.service
+After=mapper-wait@-xyz-openbmc_project-control-host6-acpi_power_state.service
+
+[Service]
+ExecStart=/usr/libexec/bletchley-host-state-monitor
+SyslogIdentifier=bletchley-host-state-monitor
+Type=simple
+Restart=on-failure
+RestartSec=1
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/plat-svc_0.1.bb b/meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/plat-svc_0.1.bb
index 23b2d1f460..ecf232f5fa 100644
--- a/meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/plat-svc_0.1.bb
+++ b/meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/plat-svc_0.1.bb
@@ -6,23 +6,25 @@ inherit allarch systemd obmc-phosphor-systemd
RDEPENDS:${PN} += "bash"
RDEPENDS:${PN} += "libgpiod-tools"
RDEPENDS:${PN} += "bletchley-common-functions"
+RDEPENDS:${PN} += "mdio-tools"
SRC_URI += " \
file://bletchley-early-sys-init \
file://bletchley-sys-init.service \
+ file://bletchley-host-state-monitor \
+ file://bletchley-host-state-monitor.service \
"
SYSTEMD_PACKAGES = "${PN}"
SYSTEMD_SERVICE:${PN}:append = " \
bletchley-sys-init.service \
+ bletchley-host-state-monitor.service \
"
do_install() {
install -d ${D}${libexecdir}
install -m 0755 ${WORKDIR}/bletchley-early-sys-init ${D}${libexecdir}
-
- install -d ${D}${systemd_system_unitdir}
- install -m 0644 ${WORKDIR}/bletchley-sys-init.service ${D}${systemd_system_unitdir}
+ install -m 0755 ${WORKDIR}/bletchley-host-state-monitor ${D}${libexecdir}
}
SYSTEMD_OVERRIDE:${PN}:bletchley += "bletchley-sys-init.conf:bletchley-sys-init.service.d/bletchley-sys-init.conf"