psu-ng: Add Availability support to power supplies
Add support for determining if a power supply is considered 'available'
or not, and set the Available D-Bus property on the
xyz.openbmc_project.State.Decorator.Availability interface with the
result.
A power supply is considered unavailable if any of the following are
true:
- it isn't present
- there is a input fault active
- there is a Vin UV fault active
- there is a PS KILL fault active
- there is a Iout OC fault active
The latter four faults are the faults where it can't provide good
output power, hence the PS is unavailable. These faults also don't
call out the power supply directly, so the Functional property won't
get set to false, unlike other faults.
The Available D-Bus property is then able to be used in Redfish
responses for the heath and state properties in the power supply
schema.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I349eddb8c052cf238276c832af0dde9e49f6d3f0
diff --git a/phosphor-power-supply/util.hpp b/phosphor-power-supply/util.hpp
index 40fe5ca..ff9f13d 100644
--- a/phosphor-power-supply/util.hpp
+++ b/phosphor-power-supply/util.hpp
@@ -15,6 +15,14 @@
namespace phosphor::power::psu
{
+using Property = std::string;
+using Value = std::variant<bool, std::string>;
+using PropertyMap = std::map<Property, Value>;
+using Interface = std::string;
+using InterfaceMap = std::map<Interface, PropertyMap>;
+using Object = sdbusplus::message::object_path;
+using ObjectMap = std::map<Object, InterfaceMap>;
+
class Util : public UtilBase
{
public:
@@ -35,18 +43,11 @@
{
using InternalFailure =
sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
- using Property = std::string;
- using Value = std::variant<bool, std::string>;
- // Association between property and its value
- using PropertyMap = std::map<Property, Value>;
PropertyMap invProp;
invProp.emplace("Present", present);
invProp.emplace("PrettyName", name);
- using Interface = std::string;
- // Association between interface and the D-Bus property map
- using InterfaceMap = std::map<Interface, PropertyMap>;
InterfaceMap invIntf;
invIntf.emplace("xyz.openbmc_project.Inventory.Item",
std::move(invProp));
@@ -55,9 +56,6 @@
invIntf.emplace(extraIface, PropertyMap());
- using Object = sdbusplus::message::object_path;
- // Association between object and the interface map
- using ObjectMap = std::map<Object, InterfaceMap>;
ObjectMap invObj;
invObj.emplace(std::move(invpath), std::move(invIntf));
@@ -89,6 +87,42 @@
elog<InternalFailure>();
}
}
+
+ void setAvailable(sdbusplus::bus::bus& bus, const std::string& invpath,
+ bool available) const override
+ {
+ PropertyMap invProp;
+ InterfaceMap invIntf;
+ ObjectMap invObj;
+
+ invProp.emplace(AVAILABLE_PROP, available);
+ invIntf.emplace(AVAILABILITY_IFACE, std::move(invProp));
+
+ invObj.emplace(std::move(invpath), std::move(invIntf));
+
+ try
+ {
+
+ auto invService = phosphor::power::util::getService(
+ INVENTORY_OBJ_PATH, INVENTORY_MGR_IFACE, bus);
+
+ auto invMsg =
+ bus.new_method_call(invService.c_str(), INVENTORY_OBJ_PATH,
+ INVENTORY_MGR_IFACE, "Notify");
+ invMsg.append(std::move(invObj));
+ auto invMgrResponseMsg = bus.call(invMsg);
+ }
+ catch (const sdbusplus::exception::exception& e)
+ {
+ using namespace phosphor::logging;
+ log<level::ERR>(
+ fmt::format("Error in inventory manager call to update "
+ "availability interface: {}",
+ e.what())
+ .c_str());
+ throw;
+ }
+ }
};
std::unique_ptr<GPIOInterfaceBase> createGPIO(const std::string& namedGpio);