meta-facebook: yosemite4: Support host power control
Description:
Support following host power control
- host power on
- host power off
- host power cycle
- host power reset
Design:
Do host power control using PLDM effecters' state command to BIC
Test Case:
Do host power on/off/cycle/reset by phosphor-state-manager
Test Log:
root@yosemite4:~# busctl set-property xyz.openbmc_project.State.Host1 /xyz/openbmc_project/state/host1 xyz.openbmc_project.State.Host RequestedHostTransition s "xyz.openbmc_project.State.Host.Transition.Off"
root@yosemite4:~# journalctl --since "10 second ago"
...
Jul 31 00:13:30 yosemite4 phosphor-host-state-manager[543]: Host state transition request of xyz.openbmc_project.State.Host.Transition.Off
...
Jul 31 00:13:30 yosemite4 host-poweroff[849]: pldmtool: Tx: 85 02 39 00 00 01 00 02
root@yosemite4:~# busctl set-property xyz.openbmc_project.State.Host1 /xyz/openbmc_project/state/host1 xyz.openbmc_project.State.Host RequestedHostTransition s "xyz.openbmc_project.State.Host.Transition.On"root@yosemite4:~# journalctl --since "10 second ago"
...
Jul 31 00:14:38 yosemite4 phosphor-host-state-manager[543]: Host state transition request of xyz.openbmc_project.State.Host.Transition.On
...
Jul 31 00:14:38 yosemite4 host-poweron[862]: pldmtool: Tx: 86 02 39 00 00 01 00 01
root@yosemite4:~# busctl set-property xyz.openbmc_project.State.Host1 /xyz/openbmc_project/state/host1 xyz.openbmc_project.State.Host RequestedHostTransition s "xyz.openbmc_project.State.Host.Transition.Reboot"
root@yosemite4:~# journalctl --since "10 second ago"
...
Jul 31 00:14:57 yosemite4 phosphor-host-state-manager[543]: Host state transition request of xyz.openbmc_project.State.Host.Transition.Reboot
...
Jul 31 00:14:57 yosemite4 host-powercycle[877]: pldmtool: Tx: 87 02 39 00 00 01 00 03
root@yosemite4:~# busctl set-property xyz.openbmc_project.State.Host1 /xyz/openbmc_project/state/host1 xyz.openbmc_project.State.Host RequestedHostTransition s "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"
root@yosemite4:~# journalctl --since "10 second ago"
...
Jul 31 00:18:03 yosemite4 phosphor-host-state-manager[543]: Host state transition request of xyz.openbmc_project.State.Host.Transition.ForceWarmReboot
...
Jul 31 00:18:03 yosemite4 host-powerreset[925]: pldmtool: Tx: 89 02 39 00 00 01 00 04
Change-Id: I289061863817883aa21ff03f10c1d81037d9aadb
Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powercycle b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powercycle
index 03b779c..ffa7e40 100644
--- a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powercycle
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powercycle
@@ -1,8 +1,18 @@
#!/bin/bash
+# shellcheck disable=SC2120
+
# Provide source directive to shellcheck.
# shellcheck source=meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd
source /usr/libexec/phosphor-state-manager/power-cmd
-# TODO: host power cycle
-echo "Host power cycle is not support for now"
\ No newline at end of file
+# TODO: check power status before do power cycle
+# Set state effecter state: Entity ID 0x0000 for host power control, 0x3 for power cycle
+GETEID=$(busctl call "$MCTP_BUS_NAME" "$MCTP_OBJ_PATH" "$MCTP_INTF_NAME" LearnEndpoint say "mctpi2c$(($1-1))" 1 0x20)
+EID=$(echo "$GETEID" | awk '{print $2}')
+if ! pldmtool raw -m "$EID" -d 0x80 0x02 0x39 0x00 0x00 0x01 0x00 0x03
+then
+ echo "Failed to set host$1 power cycle"
+else
+ echo "Host is power cycle"
+fi
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweroff b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweroff
index 82ed6af..2955050 100644
--- a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweroff
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweroff
@@ -1,8 +1,18 @@
#!/bin/bash
+# shellcheck disable=SC2120
+
# Provide source directive to shellcheck.
# shellcheck source=meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd
source /usr/libexec/phosphor-state-manager/power-cmd
-# TODO: host power off
-echo "Host power off is not support for now"
\ No newline at end of file
+# TODO: check power status before do power off
+# Set state effecter state: Entity ID 0x0000 for host power control, 0x2 for power off
+GETEID=$(busctl call "$MCTP_BUS_NAME" "$MCTP_OBJ_PATH" "$MCTP_INTF_NAME" LearnEndpoint say "mctpi2c$(($1-1))" 1 0x20)
+EID=$(echo "$GETEID" | awk '{print $2}')
+if ! pldmtool raw -m "$EID" -d 0x80 0x02 0x39 0x00 0x00 0x01 0x00 0x02
+then
+ echo "Failed to set host$1 power off"
+else
+ echo "Host is power off"
+fi
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweron b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweron
index bc3d9df..915ee76 100644
--- a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweron
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweron
@@ -4,5 +4,13 @@
# shellcheck source=meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd
source /usr/libexec/phosphor-state-manager/power-cmd
-# TODO: host power on
-echo "Host power on is not support for now"
\ No newline at end of file
+# TODO: check power status before do power on
+# Set state effecter state: Entity ID 0x0000 for host power control, 0x1 for power on
+GETEID=$(busctl call "$MCTP_BUS_NAME" "$MCTP_OBJ_PATH" "$MCTP_INTF_NAME" LearnEndpoint say "mctpi2c$(($1-1))" 1 0x20)
+EID=$(echo "$GETEID" | awk '{print $2}')
+if ! pldmtool raw -m "$EID" -d 0x80 0x02 0x39 0x00 0x00 0x01 0x00 0x01
+then
+ echo "Failed to set host$1 power on"
+else
+ echo "Host is power on"
+fi
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powerreset b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powerreset
index 72536f9..c060105 100644
--- a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powerreset
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powerreset
@@ -1,8 +1,18 @@
#!/bin/bash
+# shellcheck disable=SC2120
+
# Provide source directive to shellcheck.
# shellcheck source=meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd
source /usr/libexec/phosphor-state-manager/power-cmd
-# TODO: host power reset
-echo "Host power reset is not support for now"
\ No newline at end of file
+# TODO: check power status before do power reset
+# Set state effecter state: Entity ID 0x0000 for host power control, 0x4 for power reset
+GETEID=$(busctl call "$MCTP_BUS_NAME" "$MCTP_OBJ_PATH" "$MCTP_INTF_NAME" LearnEndpoint say "mctpi2c$(($1-1))" 1 0x20)
+EID=$(echo "$GETEID" | awk '{print $2}')
+if ! pldmtool raw -m "$EID" -d 0x80 0x02 0x39 0x00 0x00 0x01 0x00 0x04
+then
+ echo "Failed to set host$1 power reset"
+else
+ echo "Host is power reset"
+fi
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/power-cmd b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/power-cmd
index 417dfdb..759ed98 100644
--- a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/power-cmd
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/power-cmd
@@ -13,3 +13,6 @@
export CHASSIS_PROPERTY_NAME="CurrentPowerState"
export CHASSIS_ON_PROPERTY="xyz.openbmc_project.State.Chassis.PowerState.On"
export CHASSIS_OFF_PROPERTY="xyz.openbmc_project.State.Chassis.PowerState.Off"
+export MCTP_BUS_NAME="xyz.openbmc_project.MCTP"
+export MCTP_OBJ_PATH="/xyz/openbmc_project/mctp"
+export MCTP_INTF_NAME="au.com.CodeConstruct.MCTP"