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 | } |
Eddie James | 6d6d1b3 | 2019-04-22 10:45:08 -0500 | [diff] [blame] | 65 | else if (!value && device.bound()) |
| 66 | { |
| 67 | removeErrorWatch(); |
| 68 | |
| 69 | // In the event that the application never receives the active signal |
| 70 | // even though the OCC is active (this can occur if the BMC is rebooted |
| 71 | // with the host on, since the initial OCC driver probe will discover |
| 72 | // the OCCs), this application needs to be able to unbind the device |
| 73 | // when we get the OCC inactive signal. |
| 74 | device.unBind(); |
| 75 | } |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 76 | return Base::Status::occActive(value); |
| 77 | } |
| 78 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 79 | // Callback handler when a device error is reported. |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 80 | void Status::deviceErrorHandler(bool error) |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 81 | { |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 82 | // Make sure we have an error |
| 83 | if (error) |
| 84 | { |
| 85 | // This would deem OCC inactive |
| 86 | this->occActive(false); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 87 | |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 88 | // Reset the OCC |
| 89 | this->resetOCC(); |
| 90 | } |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | // Sends message to host control command handler to reset OCC |
| 94 | void Status::resetOCC() |
| 95 | { |
| 96 | using namespace phosphor::logging; |
| 97 | constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0"; |
| 98 | constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host"; |
| 99 | |
| 100 | // This will throw exception on failure |
| 101 | auto service = getService(bus, CONTROL_HOST_PATH, CONTROL_HOST_INTF); |
| 102 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 103 | auto method = bus.new_method_call(service.c_str(), CONTROL_HOST_PATH, |
| 104 | CONTROL_HOST_INTF, "Execute"); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 105 | // OCC Reset control command |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 106 | method.append(convertForMessage(Control::Host::Command::OCCReset).c_str()); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 107 | |
| 108 | // OCC Sensor ID for callout reasons |
Patrick Williams | e096270 | 2020-05-13 17:50:22 -0500 | [diff] [blame] | 109 | method.append(std::variant<uint8_t>(std::get<0>(sensorMap.at(instance)))); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 110 | bus.call_noreply(method); |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | // Handler called by Host control command handler to convey the |
| 115 | // status of the executed command |
| 116 | void Status::hostControlEvent(sdbusplus::message::message& msg) |
| 117 | { |
| 118 | using namespace phosphor::logging; |
| 119 | |
| 120 | std::string cmdCompleted{}; |
| 121 | std::string cmdStatus{}; |
| 122 | |
| 123 | msg.read(cmdCompleted, cmdStatus); |
| 124 | |
| 125 | log<level::DEBUG>("Host control signal values", |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 126 | entry("COMMAND=%s", cmdCompleted.c_str()), |
| 127 | entry("STATUS=%s", cmdStatus.c_str())); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 128 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 129 | if (Control::Host::convertResultFromString(cmdStatus) != |
| 130 | Control::Host::Result::Success) |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 131 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 132 | if (Control::Host::convertCommandFromString(cmdCompleted) == |
| 133 | Control::Host::Command::OCCReset) |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 134 | { |
Gunnar Mills | 85e6520 | 2018-04-08 15:01:54 -0500 | [diff] [blame] | 135 | // Must be a Timeout. Log an Error trace |
Alexander Filippov | 1d69e19 | 2019-03-21 18:12:07 +0300 | [diff] [blame] | 136 | log<level::ERR>( |
| 137 | "Error resetting the OCC.", entry("PATH=%s", path.c_str()), |
| 138 | entry("SENSORID=0x%X", std::get<0>(sensorMap.at(instance)))); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | return; |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 142 | } |
| 143 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 144 | } // namespace occ |
| 145 | } // namespace open_power |