1# OpenBMC Server Power Recovery 2 3Author: Andrew Geissler (geissonator) 4 5Other contributors: 6 7Created: October 11th, 2021 8 9## Problem Description 10Modern computer systems have a feature, automated power-on recovery, which 11in essence is the ability to tell your system what to do when it hits 12issues with power to the system. If the system had a black out (i.e. power 13was completely cut to the system), should it automatically power the system 14on? Should it leave it off? Or maybe the user would like the system to 15go to whichever state it was at before the power loss. 16 17There are also instances where the user may not want automatic power recovery 18to occur. For example, some systems have op-panels, and on these op-panels 19there can be a pin hole reset. This is a manual mechanism for the user to 20force a hard reset to the BMC in situations where it is hung or not responding. 21In these situations, the user may wish for the system to not automatically 22power on the system, because they want to debug the reason for the BMC error. 23 24A brownout is another scenario that commonly utilizes automated power-on 25recovery features. A brownout is a scenario where BMC firmware detects (or is 26told) that chassis power can no longer be supported, but power to the BMC 27will be retained. On some systems, it's desired to utilize the automated 28power-on feature to turn chassis power back on as soon as the brownout condition 29ends. 30 31Some system owners may chose to attach an Uninterrupted Power Supply (UPS) to 32their system. A UPS continues to provide power to a system through a blackout 33or brownout scenario. A UPS has a limited amount of power so it's main 34purpose is to handle brief power interruptions or to allow for an orderly 35shutdown of the host firmware. 36 37The goal of this design document is to describe how OpenBMC firmware will 38deal with these questions. 39 40## Background and References 41The BMC already implements a limited subset of function in this area. 42The [PowerRestorePolicy][pdi-restore] property out in phosphor-dbus-interface 43defines the function capability. 44 45In smaller servers, this feature is commonly found within the Advanced 46Configuration and Power Interface (ACPI). 47 48[openbmc/phosphor-state-manager][state-mgr] supports this property as defined 49in the phosphor-dbus-interface. 50 51## Requirements 52 53### Automated Power-On Recovery 54OpenBMC software must ensure it persists the state of power to the chassis so 55it can know what to restore it to if necessary 56 57OpenBMC software must provide support for the following options: 58- Do nothing when power is lost to the system (this will be the 59 default) 60- Always power the system on and boot the host 61- Always power the system off (previous power was on, power is now off, run 62 all chassis power off services to ensure a clean state of software and 63 hardware) 64- Restore the previous state of the chassis power and host 65 66These options are only checked and enforced in situations where the BMC does 67not detect that chassis power is already on to the system when it comes out 68of reboot. 69 70OpenBMC software must also support the concept of a one_time power restore 71policy. This is a separate instance of the `PowerRestorePolicy` which will 72be hosted under a D-Bus object path which ends with "one_time". If this 73one_time setting is not the default, `None`, then software will execute 74the policy defined under it, and then reset the one_time property to `None`. 75This one_time feature is a way for software to utilize automated power-on 76recovery function for other areas like firmware update scenarios where a 77certain power on behavior is desired once an update has completed. 78 79### BMC and System Recovery Paths 80In situations where the BMC or the system have gotten into a bad state, and 81the user has initiated some form of manual reset which is detectable by the 82BMC as being user initiated, the BMC software must: 83- Fill in appropriate `RebootCause` within the [BMC state interface][bmc-state] 84 - At a minimum, `PinholeReset` will be added. Others can be added as needed 85- Log an error indicating a user initiated forced reset has occurred 86- Not log an error indicating a blackout has occurred if chassis power was on 87 prior to the pin hole reset 88- Not implement any power recovery policy on the system 89- Turn power recovery back on once BMC has a normal reboot 90 91### Brownout 92As noted above, a brownout condition is when AC power can not continue to be 93supplied to the chassis, but the BMC can continue to have power and run. 94 95When this condition occurs, the BMC must: 96- Power system off as quickly as situations requires (or gracefully handle 97 the loss of power if it occurred without warning) 98- Log an error indicating the brownout event has occurred 99- Support the ability for host firmware to indicate a one-time power restore 100 policy if they wish for when the brownout completes 101- Identify when a brownout condition has completed 102- Wait for the brownout to complete and implement the one-time power restore 103 policy. If no one-time policy is defined then run the standard power restore 104 policy defined for the system 105 106BMC firmware must also be able to: 107- Discover if system is in a brownout situation 108 - Run when the BMC first comes up to know if it should implement any automated 109 power-on recovery 110- Not run any power-on recovery logic when a brownout is occurring 111- Tell the host firmware that it is a automated power-on recovery initiated 112 boot when that firmware is what boots the system 113 114### Uninterruptible Power Supply (UPS) 115When a UPS is present and a blackout or brownout condition occurs, the BMC must: 116- Log an error to indicate the condition has occurred 117- If host firmware is running, notify the host firmware of this utility failure 118 condition (this behavior is build-time configurable) 119- If the UPS battery power becomes low and if host firmware is running, notify 120 the host firmware of the condition, indicating a quick power off is required 121 (this behavior is build-time configurable) 122- Log an error if the UPS battery power becomes low and a power loss to the 123 entire system is imminent(i.e. a blackout scenario where BMC will also lose 124 power and UPS is about to run out of power) 125- Not execute any automated power-on recovery logic to prevent power on/off 126 thrasing (this behavior is build-time configurable) 127 128## Proposed Design 129 130### Automated Power-On Recovery 131An application will be run after the chassis and host states have been 132determined which will only run if the chassis power is not on. 133 134This application will look for the one_time setting and use it if its value 135is not `None`. If it does use the one_time setting then it will reset it 136to `None` once it has read it. Otherwise the application will read the 137persistent value of the `PowerRestorePolicy`. The application will then 138run the logic as defined in the Requirements above. 139 140This function will be hosted in phosphor-state-manger and potentially 141x86-power-control. 142 143### BMC and System Recovery Paths 144The BMC state manager application currently looks at a file in the 145sysfs to try and determine the cause of a BMC reboot. It then puts this 146reason in the `RebootCause` property. 147 148One possible cause of a BMC reset is an external reset (EXTRST). There are 149a variety of reasons an external reset can occur. Some systems are adding 150GPIOs to provide additional detail on these types of resets. 151 152A new GPIO name will be added to the [device-tree-gpio-naming.md][dev-tree] 153which reports whether a pin hole reset has occurred on the previous reboot of 154the BMC. The BMC state manager application will enhance its support of the 155`RebootCause` to look for this GPIO and if present, read it and set 156`RebootCause` accordingly when it can either not determine the reason for 157the reboot via the sysfs or sysfs reports a EXTRST reason (in which case 158the GPIO will be utilized to enhance the reboot reason). 159 160If the power recovery software sees the `PinholeReset` reason within the 161`RebootCause` then it will not implement any of its policy. Future BMC 162reboots which are not pin hole reset caused, will cause `RebootCause` to go 163back to a default and therefore power recovery policy will be re-enabled on that 164BMC boot. 165 166The phosphor-state-manager chassis software will not log a blackout error 167if it sees the `PinholeReset` reason (or any other reason that indicates a user 168initiated a reset of the system). 169 170### Brownout 171The existing `xyz.openbmc_project.State.Chassis` interface will be enhanced to 172support a `CurrentPowerStatus` property. The existing 173phosphor-chassis-state-manager, which is instantiated per instance of chassis in 174the system, will support a read of this property. The following will be the 175possible returned values for the power status of the target chassis: 176- `Undefined` 177- `BrownOut` 178- `UninterruptiblePowerSupply` 179- `Good` 180 181The phosphor-psu-monitor application within the phosphor-power repository will 182be responsible for monitoring for brownout conditions. It will support a 183per-chassis interface which represents the status of the power going into 184the target chassis. This interface will be generic in that other applications 185could host it to report the status of the power. The state-manager software 186will utilize mapper to look for all implementations of the interface for its 187chassis and aggregate the status (i.e. if any reports a brownout, then 188`BrownOut` will be returned). This interface will be defined in a later update 189to this document. 190 191The application(s) responsible for detecting and reporting chassis power will 192run on startup and discover the correct state for their property. These 193applications will log an error when a brownout occurs and initiate the fast 194power off. 195 196If the system design needs it, the existing one-time function provided by 197phosphor-state-manager for auto power on policy will be utilized for when 198the brownout completes. 199 200When the phosphor-power application detects that a brownout condition has 201completed it will reset its interface representing power status to good and 202start the state-manager service which executes the automated power-on logic. 203 204phosphor-state-manager will ensure automated power-on recovery logic is only run 205when the power supply interface reports the power status is good. If there are 206multiple chassis and/or host instances in the system then the host instances 207associated with the chassis(s) with a bad power status will be the only ones 208prevented from booting. 209 210### Uninterruptible Power Supply (UPS) 211A new phosphor-dbus-interface will be defined to represent a UPS. A BMC 212application will implement one of these per UPS attached to the system. 213This application will monitor UPS status and monitor for the following: 214- UPS utility fail (system power has failed and UPS is providing system power) 215- UPS battery low (UPS is about to run out of power) 216 217If the application sees power has been lost and the system is running on 218UPS battery power then it will monitor for the power remaining in the UPS and 219notify the host that a shutdown is required if needed. This application 220will also be responsible for logging an error indicating the UPS backup power 221has been switched to and set the appropriate property in their interface to 222indicate the scenario is present when the system can no longer remain on. 223phosphor-state-manager will query mapper for implementation of this new UPS 224interface and utilize them in combination with power supply brownout status 225when determining the value to return for its `CurrentPowerStatus`. 226 227Similar to the above brownout scenario, phosphor-state-manager will ensure 228automated power-on recovery logic is not run if `PowerStatus` is not set to 229`Good`. This behavior will be build-time configurable within 230phosphor-state-manager. 231 232## Alternatives Considered 233None, this is a pretty basic feature that does not have a lot of alternatives 234(other then just not doing it). 235 236## Impacts 237None 238 239## Testing 240The control of this policy can already bet set via the Redfish API. 241``` 242# Power Restore Policy 243curl -k -X PATCH -d '{"PowerRestorePolicy":"AlwaysOn"}' https://${bmc}/redfish/v1/Systems/system 244curl -k -X PATCH -d '{"PowerRestorePolicy":"AlwaysOff"}' https://${bmc}/redfish/v1/Systems/system 245curl -k -X PATCH -d '{"PowerRestorePolicy":"LastState"}' https://${bmc}/redfish/v1/Systems/system 246``` 247For testing, each policy should be set and verified. The one_time aspect should 248also be checked for each possible value and verified to only be used once. 249 250Validate that when multiple black outs occur, the firmware continues to try 251and power on the system when policy is `AlwaysOn` or `Restore`. 252 253On supported systems, a pin hole reset should be done with a system that has 254a policy set to always power on. Tester should verify system does not 255automatically power on after a pin hole reset. Verify it does automatically 256power on when a normal reboot of the BMC is done. 257 258A brownout condition should be injected into a system and appropriate paths 259should be verified: 260- Error log generated 261- Host notified (if running and notification possible) 262- System quickly powered off 263- Power recovery function is not run while a brownout is present 264- System automatically powers back on when brownout condition ends (assuming a 265 one-time or system auto power-on recovery policy of `AlwaysOn` or `Restore`) 266 267Plug a UPS into a system and ensure when power is cut to the system that an 268error is logged and the host is notified and allowed to power off. 269 270[pdi-restore]:https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Control/Power/RestorePolicy.interface.yaml 271[state-mgr]: https://github.com/openbmc/phosphor-state-manager 272[bmc-state]:https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/State/BMC.interface.yaml 273[dev-tree]:https://github.com/openbmc/docs/blob/master/designs/device-tree-gpio-naming.md 274