blob: c2c4baefc4f472e9cf6e37c7bbe35cf5b58940cc [file] [log] [blame]
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +05301#include "occ_status.hpp"
Gunnar Mills94df8c92018-09-14 14:50:03 -05002
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +05303#include "occ_sensor.hpp"
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05304#include "utils.hpp"
Gunnar Mills94df8c92018-09-14 14:50:03 -05005
6#include <phosphor-logging/log.hpp>
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +05307namespace open_power
8{
9namespace occ
10{
11
12// Handles updates to occActive property
13bool Status::occActive(bool value)
14{
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053015 if (value != this->occActive())
16 {
17 if (value)
18 {
19 // Bind the device
20 device.bind();
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053021
Edward A. James9fd2bdc2017-11-08 16:18:57 -060022 // Start watching for errors
23 addErrorWatch();
24
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053025 // Call into Manager to let know that we have bound
Edward A. James9fd2bdc2017-11-08 16:18:57 -060026 if (this->callBack)
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053027 {
28 this->callBack(value);
Edward A. James9fd2bdc2017-11-08 16:18:57 -060029 }
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053030 }
31 else
32 {
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053033 // Call into Manager to let know that we will unbind.
Edward A. James9fd2bdc2017-11-08 16:18:57 -060034 if (this->callBack)
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053035 {
36 this->callBack(value);
Edward A. James9fd2bdc2017-11-08 16:18:57 -060037 }
38
39 // Stop watching for errors
40 removeErrorWatch();
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053041
42 // Do the unbind.
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053043 device.unBind();
44 }
45 }
Edward A. James5e177972017-10-25 15:50:31 -050046 else if (value && !device.bound())
47 {
48 // Existing error watch is on a dead file descriptor.
Edward A. James9fd2bdc2017-11-08 16:18:57 -060049 removeErrorWatch();
Edward A. James5e177972017-10-25 15:50:31 -050050
51 /*
52 * In it's constructor, Status checks Device::bound() to see if OCC is
53 * active or not.
54 * Device::bound() checks for occX-dev0 directory.
55 * We will lose occX-dev0 directories during FSI rescan.
56 * So, if we start this application (and construct Status), and then
57 * later do FSI rescan, we will end up with occActive = true and device
58 * NOT bound. Lets correct that situation here.
59 */
60 device.bind();
61
62 // Add error watch again
Edward A. James9fd2bdc2017-11-08 16:18:57 -060063 addErrorWatch();
Edward A. James5e177972017-10-25 15:50:31 -050064 }
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053065 return Base::Status::occActive(value);
66}
67
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053068// Callback handler when a device error is reported.
Eddie James482e31f2017-09-14 13:17:17 -050069void Status::deviceErrorHandler(bool error)
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053070{
Eddie James482e31f2017-09-14 13:17:17 -050071 // Make sure we have an error
72 if (error)
73 {
74 // This would deem OCC inactive
75 this->occActive(false);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053076
Eddie James482e31f2017-09-14 13:17:17 -050077 // Reset the OCC
78 this->resetOCC();
79 }
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053080}
81
82// Sends message to host control command handler to reset OCC
83void Status::resetOCC()
84{
85 using namespace phosphor::logging;
86 constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0";
87 constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host";
88
89 // This will throw exception on failure
90 auto service = getService(bus, CONTROL_HOST_PATH, CONTROL_HOST_INTF);
91
Gunnar Mills94df8c92018-09-14 14:50:03 -050092 auto method = bus.new_method_call(service.c_str(), CONTROL_HOST_PATH,
93 CONTROL_HOST_INTF, "Execute");
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053094 // OCC Reset control command
Gunnar Mills94df8c92018-09-14 14:50:03 -050095 method.append(convertForMessage(Control::Host::Command::OCCReset).c_str());
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053096
97 // OCC Sensor ID for callout reasons
Gunnar Mills94df8c92018-09-14 14:50:03 -050098 method.append(sdbusplus::message::variant<uint8_t>(sensorMap.at(instance)));
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053099 bus.call_noreply(method);
100 return;
101}
102
103// Handler called by Host control command handler to convey the
104// status of the executed command
105void Status::hostControlEvent(sdbusplus::message::message& msg)
106{
107 using namespace phosphor::logging;
108
109 std::string cmdCompleted{};
110 std::string cmdStatus{};
111
112 msg.read(cmdCompleted, cmdStatus);
113
114 log<level::DEBUG>("Host control signal values",
Gunnar Mills94df8c92018-09-14 14:50:03 -0500115 entry("COMMAND=%s", cmdCompleted.c_str()),
116 entry("STATUS=%s", cmdStatus.c_str()));
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530117
Gunnar Mills94df8c92018-09-14 14:50:03 -0500118 if (Control::Host::convertResultFromString(cmdStatus) !=
119 Control::Host::Result::Success)
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530120 {
Gunnar Mills94df8c92018-09-14 14:50:03 -0500121 if (Control::Host::convertCommandFromString(cmdCompleted) ==
122 Control::Host::Command::OCCReset)
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530123 {
Gunnar Mills85e65202018-04-08 15:01:54 -0500124 // Must be a Timeout. Log an Error trace
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530125 log<level::ERR>("Error resetting the OCC.",
Gunnar Mills94df8c92018-09-14 14:50:03 -0500126 entry("PATH=%s", path.c_str()),
127 entry("SENSORID=0x%X", sensorMap.at(instance)));
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530128 }
129 }
130 return;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530131}
132
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530133} // namespace occ
134} // namespace open_power