blob: 15ffbc834f9d6d6cdbe6a88ee805e449b178a637 [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
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053031 // Call into Manager to let know that we have bound
32 if (this->callBack)
33 {
34 this->callBack(value);
35 }
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053036 }
37 else
38 {
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053039 // Call into Manager to let know that we will unbind.
40 // Need to do this before doing un-bind since it will
41 // result in slave error if Master is un-bound
42 if (this->callBack)
43 {
44 this->callBack(value);
45 }
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053046
47 // Do the unbind.
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053048 device.unBind();
Andrew Geissler715595b2017-08-16 15:48:50 -050049
50 // Indicate the hub FSI scan needs to be done again
51 hubFsiScanDone = false;
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053052 }
53 }
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053054 return Base::Status::occActive(value);
55}
56
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053057// Callback handler when a device error is reported.
58void Status::deviceErrorHandler()
59{
60 // This would deem OCC inactive
61 this->occActive(false);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053062
63 // Reset the OCC
64 this->resetOCC();
65}
66
67// Sends message to host control command handler to reset OCC
68void Status::resetOCC()
69{
70 using namespace phosphor::logging;
71 constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0";
72 constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host";
73
74 // This will throw exception on failure
75 auto service = getService(bus, CONTROL_HOST_PATH, CONTROL_HOST_INTF);
76
77 auto method = bus.new_method_call(service.c_str(),
78 CONTROL_HOST_PATH,
79 CONTROL_HOST_INTF,
80 "Execute");
81 // OCC Reset control command
82 method.append(convertForMessage(
83 Control::Host::Command::OCCReset).c_str());
84
85 // OCC Sensor ID for callout reasons
86 method.append(sdbusplus::message::variant<uint8_t>(
87 sensorMap.at(instance)));
88 bus.call_noreply(method);
89 return;
90}
91
92// Handler called by Host control command handler to convey the
93// status of the executed command
94void Status::hostControlEvent(sdbusplus::message::message& msg)
95{
96 using namespace phosphor::logging;
97
98 std::string cmdCompleted{};
99 std::string cmdStatus{};
100
101 msg.read(cmdCompleted, cmdStatus);
102
103 log<level::DEBUG>("Host control signal values",
104 entry("COMMAND=%s",cmdCompleted.c_str()),
105 entry("STATUS=%s",cmdStatus.c_str()));
106
107 if(Control::Host::convertResultFromString(cmdStatus) !=
108 Control::Host::Result::Success)
109 {
110 if(Control::Host::convertCommandFromString(cmdCompleted) ==
111 Control::Host::Command::OCCReset)
112 {
113 // Must be a Timeout. Log an Erorr trace
114 log<level::ERR>("Error resetting the OCC.",
115 entry("PATH=%s", path.c_str()),
116 entry("SensorID=0x%X",sensorMap.at(instance)));
117 }
118 }
119 return;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530120}
121
Vishwanatha Subbannad2981052017-08-09 21:42:10 +0530122// Scans the secondary FSI hub to make sure /dev/occ files are populated
123// Write "1" to achieve that
124void Status::scanHubFSI()
125{
126 std::ofstream file(FSI_SCAN_FILE, std::ios::out);
127 file << fsiReScan;
128 file.close();
129
130 // Hub FSI scan has been done. No need to do this for all the OCCs
131 hubFsiScanDone = true;
132 return;
133}
134
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530135} // namespace occ
136} // namespace open_power