| Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 1 | #include "occ_status.hpp" | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 2 |  | 
| 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" | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 5 |  | 
|  | 6 | #include <phosphor-logging/log.hpp> | 
| Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 7 | namespace open_power | 
|  | 8 | { | 
|  | 9 | namespace occ | 
|  | 10 | { | 
|  | 11 |  | 
|  | 12 | // Handles updates to occActive property | 
|  | 13 | bool Status::occActive(bool value) | 
|  | 14 | { | 
| Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 15 | if (value != this->occActive()) | 
|  | 16 | { | 
|  | 17 | if (value) | 
|  | 18 | { | 
|  | 19 | // Bind the device | 
|  | 20 | device.bind(); | 
| Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 21 |  | 
| Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 22 | // Start watching for errors | 
|  | 23 | addErrorWatch(); | 
|  | 24 |  | 
| Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 25 | // Call into Manager to let know that we have bound | 
| Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 26 | if (this->callBack) | 
| Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 27 | { | 
|  | 28 | this->callBack(value); | 
| Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 29 | } | 
| Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 30 | } | 
|  | 31 | else | 
|  | 32 | { | 
| Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 33 | // Call into Manager to let know that we will unbind. | 
| Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 34 | if (this->callBack) | 
| Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 35 | { | 
|  | 36 | this->callBack(value); | 
| Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 37 | } | 
|  | 38 |  | 
|  | 39 | // Stop watching for errors | 
|  | 40 | removeErrorWatch(); | 
| Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 41 |  | 
|  | 42 | // Do the unbind. | 
| Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 43 | device.unBind(); | 
|  | 44 | } | 
|  | 45 | } | 
| Edward A. James | 5e17797 | 2017-10-25 15:50:31 -0500 | [diff] [blame] | 46 | else if (value && !device.bound()) | 
|  | 47 | { | 
|  | 48 | // Existing error watch is on a dead file descriptor. | 
| Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 49 | removeErrorWatch(); | 
| Edward A. James | 5e17797 | 2017-10-25 15:50:31 -0500 | [diff] [blame] | 50 |  | 
|  | 51 | /* | 
|  | 52 | * In it's constructor, Status checks Device::bound() to see if OCC is | 
|  | 53 | * active or not. | 
|  | 54 | * Device::bound() checks for occX-dev0 directory. | 
|  | 55 | * We will lose occX-dev0 directories during FSI rescan. | 
|  | 56 | * So, if we start this application (and construct Status), and then | 
|  | 57 | * later do FSI rescan, we will end up with occActive = true and device | 
|  | 58 | * NOT bound. Lets correct that situation here. | 
|  | 59 | */ | 
|  | 60 | device.bind(); | 
|  | 61 |  | 
|  | 62 | // Add error watch again | 
| Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 63 | addErrorWatch(); | 
| Edward A. James | 5e17797 | 2017-10-25 15:50:31 -0500 | [diff] [blame] | 64 | } | 
| Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 65 | return Base::Status::occActive(value); | 
|  | 66 | } | 
|  | 67 |  | 
| Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 68 | // Callback handler when a device error is reported. | 
| Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 69 | void Status::deviceErrorHandler(bool error) | 
| Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 70 | { | 
| Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 71 | // Make sure we have an error | 
|  | 72 | if (error) | 
|  | 73 | { | 
|  | 74 | // This would deem OCC inactive | 
|  | 75 | this->occActive(false); | 
| Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 76 |  | 
| Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 77 | // Reset the OCC | 
|  | 78 | this->resetOCC(); | 
|  | 79 | } | 
| Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 80 | } | 
|  | 81 |  | 
|  | 82 | // Sends message to host control command handler to reset OCC | 
|  | 83 | void Status::resetOCC() | 
|  | 84 | { | 
|  | 85 | using namespace phosphor::logging; | 
|  | 86 | constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0"; | 
|  | 87 | constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host"; | 
|  | 88 |  | 
|  | 89 | // This will throw exception on failure | 
|  | 90 | auto service = getService(bus, CONTROL_HOST_PATH, CONTROL_HOST_INTF); | 
|  | 91 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 92 | auto method = bus.new_method_call(service.c_str(), CONTROL_HOST_PATH, | 
|  | 93 | CONTROL_HOST_INTF, "Execute"); | 
| Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 94 | // OCC Reset control command | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 95 | method.append(convertForMessage(Control::Host::Command::OCCReset).c_str()); | 
| Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 96 |  | 
|  | 97 | // OCC Sensor ID for callout reasons | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 98 | method.append(sdbusplus::message::variant<uint8_t>(sensorMap.at(instance))); | 
| Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 99 | bus.call_noreply(method); | 
|  | 100 | return; | 
|  | 101 | } | 
|  | 102 |  | 
|  | 103 | // Handler called by Host control command handler to convey the | 
|  | 104 | // status of the executed command | 
|  | 105 | void Status::hostControlEvent(sdbusplus::message::message& msg) | 
|  | 106 | { | 
|  | 107 | using namespace phosphor::logging; | 
|  | 108 |  | 
|  | 109 | std::string cmdCompleted{}; | 
|  | 110 | std::string cmdStatus{}; | 
|  | 111 |  | 
|  | 112 | msg.read(cmdCompleted, cmdStatus); | 
|  | 113 |  | 
|  | 114 | log<level::DEBUG>("Host control signal values", | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 115 | entry("COMMAND=%s", cmdCompleted.c_str()), | 
|  | 116 | entry("STATUS=%s", cmdStatus.c_str())); | 
| Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 117 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 118 | if (Control::Host::convertResultFromString(cmdStatus) != | 
|  | 119 | Control::Host::Result::Success) | 
| Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 120 | { | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 121 | if (Control::Host::convertCommandFromString(cmdCompleted) == | 
|  | 122 | Control::Host::Command::OCCReset) | 
| Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 123 | { | 
| Gunnar Mills | 85e6520 | 2018-04-08 15:01:54 -0500 | [diff] [blame] | 124 | // Must be a Timeout. Log an Error trace | 
| Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 125 | log<level::ERR>("Error resetting the OCC.", | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 126 | entry("PATH=%s", path.c_str()), | 
|  | 127 | entry("SENSORID=0x%X", sensorMap.at(instance))); | 
| Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 128 | } | 
|  | 129 | } | 
|  | 130 | return; | 
| Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 131 | } | 
|  | 132 |  | 
| Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 133 | } // namespace occ | 
|  | 134 | } // namespace open_power |