blob: 94b8c4c0495352706f2971715fe23bcfdc73d86a [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();
Andrew Geissler715595b2017-08-16 15:48:50 -050045
46 // Indicate the hub FSI scan needs to be done again
47 hubFsiScanDone = false;
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053048 }
49 }
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053050 return Base::Status::occActive(value);
51}
52
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053053// Callback handler when a device error is reported.
54void Status::deviceErrorHandler()
55{
56 // This would deem OCC inactive
57 this->occActive(false);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053058
59 // Reset the OCC
60 this->resetOCC();
61}
62
63// Sends message to host control command handler to reset OCC
64void Status::resetOCC()
65{
66 using namespace phosphor::logging;
67 constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0";
68 constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host";
69
70 // This will throw exception on failure
71 auto service = getService(bus, CONTROL_HOST_PATH, CONTROL_HOST_INTF);
72
73 auto method = bus.new_method_call(service.c_str(),
74 CONTROL_HOST_PATH,
75 CONTROL_HOST_INTF,
76 "Execute");
77 // OCC Reset control command
78 method.append(convertForMessage(
79 Control::Host::Command::OCCReset).c_str());
80
81 // OCC Sensor ID for callout reasons
82 method.append(sdbusplus::message::variant<uint8_t>(
83 sensorMap.at(instance)));
84 bus.call_noreply(method);
85 return;
86}
87
88// Handler called by Host control command handler to convey the
89// status of the executed command
90void Status::hostControlEvent(sdbusplus::message::message& msg)
91{
92 using namespace phosphor::logging;
93
94 std::string cmdCompleted{};
95 std::string cmdStatus{};
96
97 msg.read(cmdCompleted, cmdStatus);
98
99 log<level::DEBUG>("Host control signal values",
100 entry("COMMAND=%s",cmdCompleted.c_str()),
101 entry("STATUS=%s",cmdStatus.c_str()));
102
103 if(Control::Host::convertResultFromString(cmdStatus) !=
104 Control::Host::Result::Success)
105 {
106 if(Control::Host::convertCommandFromString(cmdCompleted) ==
107 Control::Host::Command::OCCReset)
108 {
109 // Must be a Timeout. Log an Erorr trace
110 log<level::ERR>("Error resetting the OCC.",
111 entry("PATH=%s", path.c_str()),
112 entry("SensorID=0x%X",sensorMap.at(instance)));
113 }
114 }
115 return;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530116}
117
Vishwanatha Subbannad2981052017-08-09 21:42:10 +0530118// Scans the secondary FSI hub to make sure /dev/occ files are populated
119// Write "1" to achieve that
120void Status::scanHubFSI()
121{
122 std::ofstream file(FSI_SCAN_FILE, std::ios::out);
123 file << fsiReScan;
124 file.close();
125
126 // Hub FSI scan has been done. No need to do this for all the OCCs
127 hubFsiScanDone = true;
128 return;
129}
130
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530131} // namespace occ
132} // namespace open_power