blob: 26f29794fd06e96e9127ba878e63df990610ad81 [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
Edward A. James9fd2bdc2017-11-08 16:18:57 -060020 // Start watching for errors
21 addErrorWatch();
22
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053023 // Call into Manager to let know that we have bound
Edward A. James9fd2bdc2017-11-08 16:18:57 -060024 if (this->callBack)
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053025 {
26 this->callBack(value);
Edward A. James9fd2bdc2017-11-08 16:18:57 -060027 }
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053028 }
29 else
30 {
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053031 // Call into Manager to let know that we will unbind.
Edward A. James9fd2bdc2017-11-08 16:18:57 -060032 if (this->callBack)
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053033 {
34 this->callBack(value);
Edward A. James9fd2bdc2017-11-08 16:18:57 -060035 }
36
37 // Stop watching for errors
38 removeErrorWatch();
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053039
40 // Do the unbind.
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053041 device.unBind();
42 }
43 }
Edward A. James5e177972017-10-25 15:50:31 -050044 else if (value && !device.bound())
45 {
46 // Existing error watch is on a dead file descriptor.
Edward A. James9fd2bdc2017-11-08 16:18:57 -060047 removeErrorWatch();
Edward A. James5e177972017-10-25 15:50:31 -050048
49 /*
50 * In it's constructor, Status checks Device::bound() to see if OCC is
51 * active or not.
52 * Device::bound() checks for occX-dev0 directory.
53 * We will lose occX-dev0 directories during FSI rescan.
54 * So, if we start this application (and construct Status), and then
55 * later do FSI rescan, we will end up with occActive = true and device
56 * NOT bound. Lets correct that situation here.
57 */
58 device.bind();
59
60 // Add error watch again
Edward A. James9fd2bdc2017-11-08 16:18:57 -060061 addErrorWatch();
Edward A. James5e177972017-10-25 15:50:31 -050062 }
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053063 return Base::Status::occActive(value);
64}
65
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053066// Callback handler when a device error is reported.
Eddie James482e31f2017-09-14 13:17:17 -050067void Status::deviceErrorHandler(bool error)
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053068{
Eddie James482e31f2017-09-14 13:17:17 -050069 // Make sure we have an error
70 if (error)
71 {
72 // This would deem OCC inactive
73 this->occActive(false);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053074
Eddie James482e31f2017-09-14 13:17:17 -050075 // Reset the OCC
76 this->resetOCC();
77 }
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053078}
79
80// Sends message to host control command handler to reset OCC
81void Status::resetOCC()
82{
83 using namespace phosphor::logging;
84 constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0";
85 constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host";
86
87 // This will throw exception on failure
88 auto service = getService(bus, CONTROL_HOST_PATH, CONTROL_HOST_INTF);
89
90 auto method = bus.new_method_call(service.c_str(),
91 CONTROL_HOST_PATH,
92 CONTROL_HOST_INTF,
93 "Execute");
94 // OCC Reset control command
95 method.append(convertForMessage(
96 Control::Host::Command::OCCReset).c_str());
97
98 // OCC Sensor ID for callout reasons
99 method.append(sdbusplus::message::variant<uint8_t>(
100 sensorMap.at(instance)));
101 bus.call_noreply(method);
102 return;
103}
104
105// Handler called by Host control command handler to convey the
106// status of the executed command
107void Status::hostControlEvent(sdbusplus::message::message& msg)
108{
109 using namespace phosphor::logging;
110
111 std::string cmdCompleted{};
112 std::string cmdStatus{};
113
114 msg.read(cmdCompleted, cmdStatus);
115
116 log<level::DEBUG>("Host control signal values",
117 entry("COMMAND=%s",cmdCompleted.c_str()),
118 entry("STATUS=%s",cmdStatus.c_str()));
119
120 if(Control::Host::convertResultFromString(cmdStatus) !=
121 Control::Host::Result::Success)
122 {
123 if(Control::Host::convertCommandFromString(cmdCompleted) ==
124 Control::Host::Command::OCCReset)
125 {
Gunnar Mills85e65202018-04-08 15:01:54 -0500126 // Must be a Timeout. Log an Error trace
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530127 log<level::ERR>("Error resetting the OCC.",
128 entry("PATH=%s", path.c_str()),
Gunnar Millsf4aedeb2017-10-25 09:19:13 -0500129 entry("SENSORID=0x%X",sensorMap.at(instance)));
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530130 }
131 }
132 return;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530133}
134
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530135} // namespace occ
136} // namespace open_power