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