blob: 6788c54867ae1ae8a5597e52b9c0832ac9bd6503 [file] [log] [blame]
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05301#include <phosphor-logging/log.hpp>
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +05302#include "occ_status.hpp"
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +05303#include "occ_sensor.hpp"
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05304#include "utils.hpp"
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +05305namespace open_power
6{
7namespace occ
8{
9
10// Handles updates to occActive property
11bool Status::occActive(bool value)
12{
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053013 if (value != this->occActive())
14 {
15 if (value)
16 {
17 // Bind the device
18 device.bind();
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053019
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053020 // Call into Manager to let know that we have bound
21 if (this->callBack)
22 {
23 this->callBack(value);
24 }
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053025 }
26 else
27 {
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053028 // Call into Manager to let know that we will unbind.
29 // Need to do this before doing un-bind since it will
30 // result in slave error if Master is un-bound
31 if (this->callBack)
32 {
33 this->callBack(value);
34 }
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053035
36 // Do the unbind.
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053037 device.unBind();
38 }
39 }
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053040 return Base::Status::occActive(value);
41}
42
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053043// Callback handler when a device error is reported.
44void Status::deviceErrorHandler()
45{
46 // This would deem OCC inactive
47 this->occActive(false);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053048
49 // Reset the OCC
50 this->resetOCC();
51}
52
53// Sends message to host control command handler to reset OCC
54void Status::resetOCC()
55{
56 using namespace phosphor::logging;
57 constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0";
58 constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host";
59
60 // This will throw exception on failure
61 auto service = getService(bus, CONTROL_HOST_PATH, CONTROL_HOST_INTF);
62
63 auto method = bus.new_method_call(service.c_str(),
64 CONTROL_HOST_PATH,
65 CONTROL_HOST_INTF,
66 "Execute");
67 // OCC Reset control command
68 method.append(convertForMessage(
69 Control::Host::Command::OCCReset).c_str());
70
71 // OCC Sensor ID for callout reasons
72 method.append(sdbusplus::message::variant<uint8_t>(
73 sensorMap.at(instance)));
74 bus.call_noreply(method);
75 return;
76}
77
78// Handler called by Host control command handler to convey the
79// status of the executed command
80void Status::hostControlEvent(sdbusplus::message::message& msg)
81{
82 using namespace phosphor::logging;
83
84 std::string cmdCompleted{};
85 std::string cmdStatus{};
86
87 msg.read(cmdCompleted, cmdStatus);
88
89 log<level::DEBUG>("Host control signal values",
90 entry("COMMAND=%s",cmdCompleted.c_str()),
91 entry("STATUS=%s",cmdStatus.c_str()));
92
93 if(Control::Host::convertResultFromString(cmdStatus) !=
94 Control::Host::Result::Success)
95 {
96 if(Control::Host::convertCommandFromString(cmdCompleted) ==
97 Control::Host::Command::OCCReset)
98 {
99 // Must be a Timeout. Log an Erorr trace
100 log<level::ERR>("Error resetting the OCC.",
101 entry("PATH=%s", path.c_str()),
102 entry("SensorID=0x%X",sensorMap.at(instance)));
103 }
104 }
105 return;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530106}
107
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530108} // namespace occ
109} // namespace open_power