Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 1 | #include <phosphor-logging/log.hpp> |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 2 | #include "occ_status.hpp" |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 3 | #include "occ_sensor.hpp" |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 4 | #include "utils.hpp" |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 5 | namespace open_power |
| 6 | { |
| 7 | namespace occ |
| 8 | { |
| 9 | |
Vishwanatha Subbanna | d298105 | 2017-08-09 21:42:10 +0530 | [diff] [blame^] | 10 | bool Status::hubFsiScanDone = false; |
| 11 | |
| 12 | // To initiate a FSI rescan |
| 13 | constexpr auto fsiReScan = "1"; |
| 14 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 15 | // Handles updates to occActive property |
| 16 | bool Status::occActive(bool value) |
| 17 | { |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 18 | if (value != this->occActive()) |
| 19 | { |
| 20 | if (value) |
| 21 | { |
Vishwanatha Subbanna | d298105 | 2017-08-09 21:42:10 +0530 | [diff] [blame^] | 22 | if (!hubFsiScanDone) |
| 23 | { |
| 24 | // Need to do hub scan before we bind |
| 25 | this->scanHubFSI(); |
| 26 | } |
| 27 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 28 | // Bind the device |
| 29 | device.bind(); |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 30 | |
| 31 | // And watch for errors |
Vishwanatha Subbanna | d298105 | 2017-08-09 21:42:10 +0530 | [diff] [blame^] | 32 | // Commenting until we solve the occ error monitoring issue |
| 33 | // TODO: openbmc/openbmc#2126 |
| 34 | // device.addErrorWatch(); |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 35 | } |
| 36 | else |
| 37 | { |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 38 | // Stop watching for errors |
Vishwanatha Subbanna | d298105 | 2017-08-09 21:42:10 +0530 | [diff] [blame^] | 39 | // Commenting until we solve the occ error monitoring issue |
| 40 | // TODO: openbmc/openbmc#2126 |
| 41 | // device.removeErrorWatch(); |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 42 | |
| 43 | // Do the unbind. |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 44 | device.unBind(); |
| 45 | } |
| 46 | } |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 47 | return Base::Status::occActive(value); |
| 48 | } |
| 49 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 50 | // Callback handler when a device error is reported. |
| 51 | void Status::deviceErrorHandler() |
| 52 | { |
| 53 | // This would deem OCC inactive |
| 54 | this->occActive(false); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 55 | |
| 56 | // Reset the OCC |
| 57 | this->resetOCC(); |
| 58 | } |
| 59 | |
| 60 | // Sends message to host control command handler to reset OCC |
| 61 | void 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 |
| 87 | void 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 Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 113 | } |
| 114 | |
Vishwanatha Subbanna | d298105 | 2017-08-09 21:42:10 +0530 | [diff] [blame^] | 115 | // Scans the secondary FSI hub to make sure /dev/occ files are populated |
| 116 | // Write "1" to achieve that |
| 117 | void 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 Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 128 | } // namespace occ |
| 129 | } // namespace open_power |