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 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 31 | // Call into Manager to let know that we have bound |
| 32 | if (this->callBack) |
| 33 | { |
| 34 | this->callBack(value); |
| 35 | } |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 36 | } |
| 37 | else |
| 38 | { |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 39 | // 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 Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 46 | |
| 47 | // Do the unbind. |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 48 | device.unBind(); |
Andrew Geissler | 715595b | 2017-08-16 15:48:50 -0500 | [diff] [blame] | 49 | |
| 50 | // Indicate the hub FSI scan needs to be done again |
| 51 | hubFsiScanDone = false; |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 52 | } |
| 53 | } |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 54 | return Base::Status::occActive(value); |
| 55 | } |
| 56 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 57 | // Callback handler when a device error is reported. |
| 58 | void Status::deviceErrorHandler() |
| 59 | { |
| 60 | // This would deem OCC inactive |
| 61 | this->occActive(false); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 62 | |
| 63 | // Reset the OCC |
| 64 | this->resetOCC(); |
| 65 | } |
| 66 | |
| 67 | // Sends message to host control command handler to reset OCC |
| 68 | void 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 |
| 94 | void 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 Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 120 | } |
| 121 | |
Vishwanatha Subbanna | d298105 | 2017-08-09 21:42:10 +0530 | [diff] [blame] | 122 | // Scans the secondary FSI hub to make sure /dev/occ files are populated |
| 123 | // Write "1" to achieve that |
| 124 | void 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 Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 135 | } // namespace occ |
| 136 | } // namespace open_power |