blob: 8867276ca17f58732ce05802c8b24bc0ab58c4e8 [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
Vishwanatha Subbannae2fb5562017-09-13 18:34:06 +053021 // TODO: openbmc/openbmc#2285
22 /* if (this->callBack)
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053023 {
24 this->callBack(value);
Vishwanatha Subbannae2fb5562017-09-13 18:34:06 +053025 }*/
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053026 }
27 else
28 {
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053029 // Call into Manager to let know that we will unbind.
30 // Need to do this before doing un-bind since it will
31 // result in slave error if Master is un-bound
Vishwanatha Subbannae2fb5562017-09-13 18:34:06 +053032 /*if (this->callBack)
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053033 {
34 this->callBack(value);
Vishwanatha Subbannae2fb5562017-09-13 18:34:06 +053035 }*/
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053036
37 // Do the unbind.
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053038 device.unBind();
39 }
40 }
Edward A. James5e177972017-10-25 15:50:31 -050041 else if (value && !device.bound())
42 {
43 // Existing error watch is on a dead file descriptor.
44 // TODO: openbmc/openbmc#2285
45 // removeErrorWatch();
46
47 /*
48 * In it's constructor, Status checks Device::bound() to see if OCC is
49 * active or not.
50 * Device::bound() checks for occX-dev0 directory.
51 * We will lose occX-dev0 directories during FSI rescan.
52 * So, if we start this application (and construct Status), and then
53 * later do FSI rescan, we will end up with occActive = true and device
54 * NOT bound. Lets correct that situation here.
55 */
56 device.bind();
57
58 // Add error watch again
59 // TODO: openbmc/openbmc#2285
60 // addErrorWatch();
61 }
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053062 return Base::Status::occActive(value);
63}
64
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053065// Callback handler when a device error is reported.
Eddie James482e31f2017-09-14 13:17:17 -050066void Status::deviceErrorHandler(bool error)
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053067{
Eddie James482e31f2017-09-14 13:17:17 -050068 // Make sure we have an error
69 if (error)
70 {
71 // This would deem OCC inactive
72 this->occActive(false);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053073
Eddie James482e31f2017-09-14 13:17:17 -050074 // Reset the OCC
75 this->resetOCC();
76 }
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053077}
78
79// Sends message to host control command handler to reset OCC
80void Status::resetOCC()
81{
82 using namespace phosphor::logging;
83 constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0";
84 constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host";
85
86 // This will throw exception on failure
87 auto service = getService(bus, CONTROL_HOST_PATH, CONTROL_HOST_INTF);
88
89 auto method = bus.new_method_call(service.c_str(),
90 CONTROL_HOST_PATH,
91 CONTROL_HOST_INTF,
92 "Execute");
93 // OCC Reset control command
94 method.append(convertForMessage(
95 Control::Host::Command::OCCReset).c_str());
96
97 // OCC Sensor ID for callout reasons
98 method.append(sdbusplus::message::variant<uint8_t>(
99 sensorMap.at(instance)));
100 bus.call_noreply(method);
101 return;
102}
103
104// Handler called by Host control command handler to convey the
105// status of the executed command
106void Status::hostControlEvent(sdbusplus::message::message& msg)
107{
108 using namespace phosphor::logging;
109
110 std::string cmdCompleted{};
111 std::string cmdStatus{};
112
113 msg.read(cmdCompleted, cmdStatus);
114
115 log<level::DEBUG>("Host control signal values",
116 entry("COMMAND=%s",cmdCompleted.c_str()),
117 entry("STATUS=%s",cmdStatus.c_str()));
118
119 if(Control::Host::convertResultFromString(cmdStatus) !=
120 Control::Host::Result::Success)
121 {
122 if(Control::Host::convertCommandFromString(cmdCompleted) ==
123 Control::Host::Command::OCCReset)
124 {
125 // Must be a Timeout. Log an Erorr trace
126 log<level::ERR>("Error resetting the OCC.",
127 entry("PATH=%s", path.c_str()),
Gunnar Millsf4aedeb2017-10-25 09:19:13 -0500128 entry("SENSORID=0x%X",sensorMap.at(instance)));
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530129 }
130 }
131 return;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530132}
133
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530134} // namespace occ
135} // namespace open_power