blob: 36520b544aaaee6acb2411d39646ae7cbdd7c23d [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.
66void Status::deviceErrorHandler()
67{
68 // This would deem OCC inactive
69 this->occActive(false);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053070
71 // Reset the OCC
72 this->resetOCC();
73}
74
75// Sends message to host control command handler to reset OCC
76void Status::resetOCC()
77{
78 using namespace phosphor::logging;
79 constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0";
80 constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host";
81
82 // This will throw exception on failure
83 auto service = getService(bus, CONTROL_HOST_PATH, CONTROL_HOST_INTF);
84
85 auto method = bus.new_method_call(service.c_str(),
86 CONTROL_HOST_PATH,
87 CONTROL_HOST_INTF,
88 "Execute");
89 // OCC Reset control command
90 method.append(convertForMessage(
91 Control::Host::Command::OCCReset).c_str());
92
93 // OCC Sensor ID for callout reasons
94 method.append(sdbusplus::message::variant<uint8_t>(
95 sensorMap.at(instance)));
96 bus.call_noreply(method);
97 return;
98}
99
100// Handler called by Host control command handler to convey the
101// status of the executed command
102void Status::hostControlEvent(sdbusplus::message::message& msg)
103{
104 using namespace phosphor::logging;
105
106 std::string cmdCompleted{};
107 std::string cmdStatus{};
108
109 msg.read(cmdCompleted, cmdStatus);
110
111 log<level::DEBUG>("Host control signal values",
112 entry("COMMAND=%s",cmdCompleted.c_str()),
113 entry("STATUS=%s",cmdStatus.c_str()));
114
115 if(Control::Host::convertResultFromString(cmdStatus) !=
116 Control::Host::Result::Success)
117 {
118 if(Control::Host::convertCommandFromString(cmdCompleted) ==
119 Control::Host::Command::OCCReset)
120 {
121 // Must be a Timeout. Log an Erorr trace
122 log<level::ERR>("Error resetting the OCC.",
123 entry("PATH=%s", path.c_str()),
Gunnar Millsf4aedeb2017-10-25 09:19:13 -0500124 entry("SENSORID=0x%X",sensorMap.at(instance)));
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530125 }
126 }
127 return;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530128}
129
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530130} // namespace occ
131} // namespace open_power