blob: 7eafb662ebe0c7f3ae43e2f3f6dc33c3843743d7 [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
Vishwanatha Subbannad2981052017-08-09 21:42:10 +053010bool Status::hubFsiScanDone = false;
11
12// To initiate a FSI rescan
13constexpr auto fsiReScan = "1";
14
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053015// Handles updates to occActive property
16bool Status::occActive(bool value)
17{
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053018 if (value != this->occActive())
19 {
20 if (value)
21 {
Vishwanatha Subbannad2981052017-08-09 21:42:10 +053022 if (!hubFsiScanDone)
23 {
24 // Need to do hub scan before we bind
25 this->scanHubFSI();
26 }
27
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053028 // Bind the device
29 device.bind();
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053030
31 // And watch for errors
Vishwanatha Subbannad2981052017-08-09 21:42:10 +053032 // Commenting until we solve the occ error monitoring issue
33 // TODO: openbmc/openbmc#2126
34 // device.addErrorWatch();
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053035 }
36 else
37 {
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053038 // Stop watching for errors
Vishwanatha Subbannad2981052017-08-09 21:42:10 +053039 // Commenting until we solve the occ error monitoring issue
40 // TODO: openbmc/openbmc#2126
41 // device.removeErrorWatch();
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053042
43 // Do the unbind.
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053044 device.unBind();
45 }
46 }
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053047 return Base::Status::occActive(value);
48}
49
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053050// Callback handler when a device error is reported.
51void Status::deviceErrorHandler()
52{
53 // This would deem OCC inactive
54 this->occActive(false);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053055
56 // Reset the OCC
57 this->resetOCC();
58}
59
60// Sends message to host control command handler to reset OCC
61void Status::resetOCC()
62{
63 using namespace phosphor::logging;
64 constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0";
65 constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host";
66
67 // This will throw exception on failure
68 auto service = getService(bus, CONTROL_HOST_PATH, CONTROL_HOST_INTF);
69
70 auto method = bus.new_method_call(service.c_str(),
71 CONTROL_HOST_PATH,
72 CONTROL_HOST_INTF,
73 "Execute");
74 // OCC Reset control command
75 method.append(convertForMessage(
76 Control::Host::Command::OCCReset).c_str());
77
78 // OCC Sensor ID for callout reasons
79 method.append(sdbusplus::message::variant<uint8_t>(
80 sensorMap.at(instance)));
81 bus.call_noreply(method);
82 return;
83}
84
85// Handler called by Host control command handler to convey the
86// status of the executed command
87void Status::hostControlEvent(sdbusplus::message::message& msg)
88{
89 using namespace phosphor::logging;
90
91 std::string cmdCompleted{};
92 std::string cmdStatus{};
93
94 msg.read(cmdCompleted, cmdStatus);
95
96 log<level::DEBUG>("Host control signal values",
97 entry("COMMAND=%s",cmdCompleted.c_str()),
98 entry("STATUS=%s",cmdStatus.c_str()));
99
100 if(Control::Host::convertResultFromString(cmdStatus) !=
101 Control::Host::Result::Success)
102 {
103 if(Control::Host::convertCommandFromString(cmdCompleted) ==
104 Control::Host::Command::OCCReset)
105 {
106 // Must be a Timeout. Log an Erorr trace
107 log<level::ERR>("Error resetting the OCC.",
108 entry("PATH=%s", path.c_str()),
109 entry("SensorID=0x%X",sensorMap.at(instance)));
110 }
111 }
112 return;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530113}
114
Vishwanatha Subbannad2981052017-08-09 21:42:10 +0530115// Scans the secondary FSI hub to make sure /dev/occ files are populated
116// Write "1" to achieve that
117void Status::scanHubFSI()
118{
119 std::ofstream file(FSI_SCAN_FILE, std::ios::out);
120 file << fsiReScan;
121 file.close();
122
123 // Hub FSI scan has been done. No need to do this for all the OCCs
124 hubFsiScanDone = true;
125 return;
126}
127
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530128} // namespace occ
129} // namespace open_power