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(); |
Andrew Geissler | 715595b | 2017-08-16 15:48:50 -0500 | [diff] [blame^] | 45 | |
| 46 | // Indicate the hub FSI scan needs to be done again |
| 47 | hubFsiScanDone = false; |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 48 | } |
| 49 | } |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 50 | return Base::Status::occActive(value); |
| 51 | } |
| 52 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 53 | // Callback handler when a device error is reported. |
| 54 | void Status::deviceErrorHandler() |
| 55 | { |
| 56 | // This would deem OCC inactive |
| 57 | this->occActive(false); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 58 | |
| 59 | // Reset the OCC |
| 60 | this->resetOCC(); |
| 61 | } |
| 62 | |
| 63 | // Sends message to host control command handler to reset OCC |
| 64 | void 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 |
| 90 | void 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 Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 116 | } |
| 117 | |
Vishwanatha Subbanna | d298105 | 2017-08-09 21:42:10 +0530 | [diff] [blame] | 118 | // Scans the secondary FSI hub to make sure /dev/occ files are populated |
| 119 | // Write "1" to achieve that |
| 120 | void 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 Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 131 | } // namespace occ |
| 132 | } // namespace open_power |