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 | |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 3 | #include "occ_manager.hpp" |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 4 | #include "occ_sensor.hpp" |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 5 | #include "powermode.hpp" |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 6 | #include "utils.hpp" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 7 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 8 | #include <fmt/core.h> |
| 9 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 10 | #include <phosphor-logging/log.hpp> |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 11 | |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 12 | #include <filesystem> |
| 13 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 14 | namespace open_power |
| 15 | { |
| 16 | namespace occ |
| 17 | { |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 18 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 19 | using namespace phosphor::logging; |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 20 | |
| 21 | // Handles updates to occActive property |
| 22 | bool Status::occActive(bool value) |
| 23 | { |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 24 | if (value != this->occActive()) |
| 25 | { |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 26 | log<level::INFO>(fmt::format("Status::occActive OCC{} changed to {}", |
| 27 | instance, value) |
| 28 | .c_str()); |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 29 | if (value) |
| 30 | { |
Eddie James | aced309 | 2022-04-22 16:19:30 -0500 | [diff] [blame] | 31 | // Set the device active |
| 32 | device.setActive(true); |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 33 | |
Chris Cain | 6d8f37a | 2022-04-29 13:46:01 -0500 | [diff] [blame] | 34 | // Update the OCC active sensor |
| 35 | Base::Status::occActive(value); |
| 36 | |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 37 | // Start watching for errors |
| 38 | addErrorWatch(); |
| 39 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 40 | // Reset last OCC state |
| 41 | lastState = 0; |
| 42 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 43 | if (device.master()) |
| 44 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 45 | // Update powercap bounds from OCC |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 46 | manager.updatePcapBounds(); |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 47 | } |
| 48 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 49 | // Call into Manager to let know that we have bound |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 50 | if (this->managerCallBack) |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 51 | { |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 52 | this->managerCallBack(instance, value); |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 53 | } |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 54 | } |
| 55 | else |
| 56 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 57 | #ifdef POWER10 |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 58 | if (pmode && device.master()) |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 59 | { |
| 60 | // Prevent mode changes |
| 61 | pmode->setMasterActive(false); |
| 62 | } |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 63 | if (safeStateDelayTimer.isEnabled()) |
| 64 | { |
| 65 | // stop safe delay timer |
| 66 | safeStateDelayTimer.setEnabled(false); |
| 67 | } |
| 68 | #endif |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 69 | // Call into Manager to let know that we will unbind. |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 70 | if (this->managerCallBack) |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 71 | { |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 72 | this->managerCallBack(instance, value); |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 73 | } |
| 74 | |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 75 | // Stop watching for errors |
| 76 | removeErrorWatch(); |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 77 | |
Eddie James | aced309 | 2022-04-22 16:19:30 -0500 | [diff] [blame] | 78 | // Set the device inactive |
| 79 | device.setActive(false); |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 80 | } |
| 81 | } |
Eddie James | aced309 | 2022-04-22 16:19:30 -0500 | [diff] [blame] | 82 | else if (value && !device.active()) |
Edward A. James | 5e17797 | 2017-10-25 15:50:31 -0500 | [diff] [blame] | 83 | { |
| 84 | // Existing error watch is on a dead file descriptor. |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 85 | removeErrorWatch(); |
Edward A. James | 5e17797 | 2017-10-25 15:50:31 -0500 | [diff] [blame] | 86 | |
| 87 | /* |
| 88 | * In it's constructor, Status checks Device::bound() to see if OCC is |
| 89 | * active or not. |
| 90 | * Device::bound() checks for occX-dev0 directory. |
| 91 | * We will lose occX-dev0 directories during FSI rescan. |
| 92 | * So, if we start this application (and construct Status), and then |
| 93 | * later do FSI rescan, we will end up with occActive = true and device |
| 94 | * NOT bound. Lets correct that situation here. |
| 95 | */ |
Eddie James | aced309 | 2022-04-22 16:19:30 -0500 | [diff] [blame] | 96 | device.setActive(true); |
Edward A. James | 5e17797 | 2017-10-25 15:50:31 -0500 | [diff] [blame] | 97 | |
| 98 | // Add error watch again |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 99 | addErrorWatch(); |
Edward A. James | 5e17797 | 2017-10-25 15:50:31 -0500 | [diff] [blame] | 100 | } |
Eddie James | aced309 | 2022-04-22 16:19:30 -0500 | [diff] [blame] | 101 | else if (!value && device.active()) |
Eddie James | 6d6d1b3 | 2019-04-22 10:45:08 -0500 | [diff] [blame] | 102 | { |
| 103 | removeErrorWatch(); |
| 104 | |
| 105 | // In the event that the application never receives the active signal |
| 106 | // even though the OCC is active (this can occur if the BMC is rebooted |
| 107 | // with the host on, since the initial OCC driver probe will discover |
| 108 | // the OCCs), this application needs to be able to unbind the device |
| 109 | // when we get the OCC inactive signal. |
Eddie James | aced309 | 2022-04-22 16:19:30 -0500 | [diff] [blame] | 110 | device.setActive(false); |
Eddie James | 6d6d1b3 | 2019-04-22 10:45:08 -0500 | [diff] [blame] | 111 | } |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 112 | return Base::Status::occActive(value); |
| 113 | } |
| 114 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 115 | // Callback handler when a device error is reported. |
Eddie James | 9789e71 | 2022-05-25 15:43:40 -0500 | [diff] [blame] | 116 | void Status::deviceError(Error::Descriptor d) |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 117 | { |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 118 | #ifdef POWER10 |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 119 | if (pmode && device.master()) |
| 120 | { |
| 121 | // Prevent mode changes |
| 122 | pmode->setMasterActive(false); |
| 123 | } |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 124 | #endif |
| 125 | |
Eddie James | 9789e71 | 2022-05-25 15:43:40 -0500 | [diff] [blame] | 126 | if (d.log) |
| 127 | { |
| 128 | FFDC::createOCCResetPEL(instance, d.path, d.err, d.callout); |
| 129 | } |
| 130 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 131 | // This would deem OCC inactive |
| 132 | this->occActive(false); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 133 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 134 | // Reset the OCC |
| 135 | this->resetOCC(); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | // Sends message to host control command handler to reset OCC |
| 139 | void Status::resetOCC() |
| 140 | { |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 141 | log<level::INFO>( |
| 142 | fmt::format(">>Status::resetOCC() - requesting reset for OCC{}", |
| 143 | instance) |
| 144 | .c_str()); |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 145 | #ifdef PLDM |
| 146 | if (resetCallBack) |
| 147 | { |
| 148 | this->resetCallBack(instance); |
| 149 | } |
| 150 | #else |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 151 | constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0"; |
| 152 | constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host"; |
| 153 | |
| 154 | // This will throw exception on failure |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 155 | auto service = utils::getService(CONTROL_HOST_PATH, CONTROL_HOST_INTF); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 156 | |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 157 | auto& bus = utils::getBus(); |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 158 | auto method = bus.new_method_call(service.c_str(), CONTROL_HOST_PATH, |
| 159 | CONTROL_HOST_INTF, "Execute"); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 160 | // OCC Reset control command |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 161 | method.append(convertForMessage(Control::Host::Command::OCCReset).c_str()); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 162 | |
| 163 | // OCC Sensor ID for callout reasons |
Patrick Williams | e096270 | 2020-05-13 17:50:22 -0500 | [diff] [blame] | 164 | method.append(std::variant<uint8_t>(std::get<0>(sensorMap.at(instance)))); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 165 | bus.call_noreply(method); |
| 166 | return; |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 167 | #endif |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | // Handler called by Host control command handler to convey the |
| 171 | // status of the executed command |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 172 | void Status::hostControlEvent(sdbusplus::message_t& msg) |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 173 | { |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 174 | std::string cmdCompleted{}; |
| 175 | std::string cmdStatus{}; |
| 176 | |
| 177 | msg.read(cmdCompleted, cmdStatus); |
| 178 | |
| 179 | log<level::DEBUG>("Host control signal values", |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 180 | entry("COMMAND=%s", cmdCompleted.c_str()), |
| 181 | entry("STATUS=%s", cmdStatus.c_str())); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 182 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 183 | if (Control::Host::convertResultFromString(cmdStatus) != |
| 184 | Control::Host::Result::Success) |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 185 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 186 | if (Control::Host::convertCommandFromString(cmdCompleted) == |
| 187 | Control::Host::Command::OCCReset) |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 188 | { |
Gunnar Mills | 85e6520 | 2018-04-08 15:01:54 -0500 | [diff] [blame] | 189 | // Must be a Timeout. Log an Error trace |
Alexander Filippov | 1d69e19 | 2019-03-21 18:12:07 +0300 | [diff] [blame] | 190 | log<level::ERR>( |
| 191 | "Error resetting the OCC.", entry("PATH=%s", path.c_str()), |
| 192 | entry("SENSORID=0x%X", std::get<0>(sensorMap.at(instance)))); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | return; |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 196 | } |
| 197 | |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 198 | // Called from Manager::pollerTimerExpired() in preperation to POLL OCC. |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 199 | void Status::readOccState() |
| 200 | { |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 201 | currentOccReadRetriesCount = occReadRetries; |
| 202 | occReadStateNow(); |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 203 | } |
| 204 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 205 | #ifdef POWER10 |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 206 | // Special processing that needs to happen once the OCCs change to ACTIVE state |
| 207 | void Status::occsWentActive() |
| 208 | { |
| 209 | CmdStatus status = CmdStatus::SUCCESS; |
| 210 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 211 | status = pmode->sendModeChange(); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 212 | if (status != CmdStatus::SUCCESS) |
| 213 | { |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 214 | log<level::ERR>( |
| 215 | fmt::format( |
| 216 | "Status::occsWentActive: OCC mode change failed with status {}", |
| 217 | status) |
| 218 | .c_str()); |
Chris Cain | c567dc8 | 2022-04-01 15:09:17 -0500 | [diff] [blame] | 219 | |
| 220 | // Disable and reset to try recovering |
| 221 | deviceError(); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 222 | } |
| 223 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 224 | status = pmode->sendIpsData(); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 225 | if (status != CmdStatus::SUCCESS) |
| 226 | { |
| 227 | log<level::ERR>( |
| 228 | fmt::format( |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 229 | "Status::occsWentActive: Sending Idle Power Save Config data failed with status {}", |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 230 | status) |
| 231 | .c_str()); |
Chris Cain | c567dc8 | 2022-04-01 15:09:17 -0500 | [diff] [blame] | 232 | |
| 233 | if (status == CmdStatus::COMM_FAILURE) |
| 234 | { |
| 235 | // Disable and reset to try recovering |
| 236 | deviceError(); |
| 237 | } |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 241 | // Send Ambient and Altitude to the OCC |
| 242 | CmdStatus Status::sendAmbient(const uint8_t inTemp, const uint16_t inAltitude) |
| 243 | { |
| 244 | CmdStatus status = CmdStatus::FAILURE; |
| 245 | bool ambientValid = true; |
| 246 | uint8_t ambientTemp = inTemp; |
| 247 | uint16_t altitude = inAltitude; |
| 248 | |
| 249 | if (ambientTemp == 0xFF) |
| 250 | { |
| 251 | // Get latest readings from manager |
| 252 | manager.getAmbientData(ambientValid, ambientTemp, altitude); |
| 253 | log<level::DEBUG>( |
| 254 | fmt::format("sendAmbient: valid: {}, Ambient: {}C, altitude: {}m", |
| 255 | ambientValid, ambientTemp, altitude) |
| 256 | .c_str()); |
| 257 | } |
| 258 | |
| 259 | std::vector<std::uint8_t> cmd, rsp; |
| 260 | cmd.reserve(11); |
| 261 | cmd.push_back(uint8_t(CmdType::SEND_AMBIENT)); |
| 262 | cmd.push_back(0x00); // Data Length (2 bytes) |
| 263 | cmd.push_back(0x08); // |
| 264 | cmd.push_back(0x00); // Version |
| 265 | cmd.push_back(ambientValid ? 0 : 0xFF); // Ambient Status |
| 266 | cmd.push_back(ambientTemp); // Ambient Temperature |
| 267 | cmd.push_back(altitude >> 8); // Altitude in meters (2 bytes) |
| 268 | cmd.push_back(altitude & 0xFF); // |
| 269 | cmd.push_back(0x00); // Reserved (3 bytes) |
| 270 | cmd.push_back(0x00); |
| 271 | cmd.push_back(0x00); |
| 272 | log<level::DEBUG>(fmt::format("sendAmbient: SEND_AMBIENT " |
| 273 | "command to OCC{} ({} bytes)", |
| 274 | instance, cmd.size()) |
| 275 | .c_str()); |
| 276 | status = occCmd.send(cmd, rsp); |
| 277 | if (status == CmdStatus::SUCCESS) |
| 278 | { |
| 279 | if (rsp.size() == 5) |
| 280 | { |
| 281 | if (RspStatus::SUCCESS != RspStatus(rsp[2])) |
| 282 | { |
| 283 | log<level::ERR>( |
| 284 | fmt::format( |
Chris Cain | c567dc8 | 2022-04-01 15:09:17 -0500 | [diff] [blame] | 285 | "sendAmbient: SEND_AMBIENT failed with rspStatus 0x{:02X}", |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 286 | rsp[2]) |
| 287 | .c_str()); |
| 288 | dump_hex(rsp); |
| 289 | status = CmdStatus::FAILURE; |
| 290 | } |
| 291 | } |
| 292 | else |
| 293 | { |
Chris Cain | c567dc8 | 2022-04-01 15:09:17 -0500 | [diff] [blame] | 294 | log<level::ERR>( |
| 295 | fmt::format( |
| 296 | "sendAmbient: INVALID SEND_AMBIENT response length:{}", |
| 297 | rsp.size()) |
| 298 | .c_str()); |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 299 | dump_hex(rsp); |
| 300 | status = CmdStatus::FAILURE; |
| 301 | } |
| 302 | } |
| 303 | else |
| 304 | { |
Chris Cain | c567dc8 | 2022-04-01 15:09:17 -0500 | [diff] [blame] | 305 | log<level::ERR>( |
| 306 | fmt::format( |
| 307 | "sendAmbient: SEND_AMBIENT FAILED! with status 0x{:02X}", |
| 308 | status) |
| 309 | .c_str()); |
| 310 | |
| 311 | if (status == CmdStatus::COMM_FAILURE) |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 312 | { |
Chris Cain | c567dc8 | 2022-04-01 15:09:17 -0500 | [diff] [blame] | 313 | // Disable and reset to try recovering |
| 314 | deviceError(); |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
| 318 | return status; |
| 319 | } |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 320 | |
| 321 | // Called when safe timer expires to determine if OCCs need to be reset |
| 322 | void Status::safeStateDelayExpired() |
| 323 | { |
| 324 | if (this->occActive()) |
| 325 | { |
| 326 | log<level::INFO>( |
| 327 | fmt::format( |
| 328 | "safeStateDelayExpired: OCC{} is in SAFE state, requesting reset", |
| 329 | instance) |
| 330 | .c_str()); |
| 331 | // Disable and reset to try recovering |
Eddie James | 9789e71 | 2022-05-25 15:43:40 -0500 | [diff] [blame] | 332 | deviceError(Error::Descriptor(SAFE_ERROR_PATH)); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 333 | } |
| 334 | } |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 335 | #endif // POWER10 |
| 336 | |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 337 | fs::path Status::getHwmonPath() |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 338 | { |
| 339 | using namespace std::literals::string_literals; |
| 340 | |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 341 | if (!fs::exists(hwmonPath)) |
| 342 | { |
| 343 | static bool tracedFail[8] = {0}; |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 344 | |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 345 | if (!hwmonPath.empty()) |
| 346 | { |
| 347 | log<level::ERR>( |
| 348 | fmt::format("Status::getHwmonPath(): path no longer exists: {}", |
| 349 | hwmonPath.c_str()) |
| 350 | .c_str()); |
| 351 | hwmonPath.clear(); |
| 352 | } |
| 353 | |
| 354 | // Build the base HWMON path |
Patrick Williams | a49c987 | 2023-05-10 07:50:35 -0500 | [diff] [blame^] | 355 | fs::path prefixPath = fs::path{OCC_HWMON_PATH + "occ-hwmon."s + |
| 356 | std::to_string(instance + 1) + |
| 357 | "/hwmon/"s}; |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 358 | |
| 359 | // Get the hwmonXX directory name |
| 360 | try |
| 361 | { |
| 362 | // there should only be one directory |
| 363 | const int numDirs = std::distance( |
| 364 | fs::directory_iterator(prefixPath), fs::directory_iterator{}); |
| 365 | if (numDirs == 1) |
| 366 | { |
| 367 | hwmonPath = *fs::directory_iterator(prefixPath); |
| 368 | tracedFail[instance] = false; |
| 369 | } |
| 370 | else |
| 371 | { |
| 372 | if (!tracedFail[instance]) |
| 373 | { |
| 374 | log<level::ERR>( |
| 375 | fmt::format( |
| 376 | "Status::getHwmonPath(): Found multiple ({}) hwmon paths!", |
| 377 | numDirs) |
| 378 | .c_str()); |
| 379 | tracedFail[instance] = true; |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | catch (const fs::filesystem_error& e) |
| 384 | { |
| 385 | if (!tracedFail[instance]) |
| 386 | { |
| 387 | log<level::ERR>( |
| 388 | fmt::format( |
| 389 | "Status::getHwmonPath(): error accessing {}: {}", |
| 390 | prefixPath.c_str(), e.what()) |
| 391 | .c_str()); |
| 392 | tracedFail[instance] = true; |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | return hwmonPath; |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 398 | } |
| 399 | |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 400 | // Called to read state and upon failure to read after occReadStateFailTimer. |
| 401 | void Status::occReadStateNow() |
| 402 | { |
| 403 | unsigned int state; |
| 404 | const fs::path filename = |
| 405 | fs::path(DEV_PATH) / |
| 406 | fs::path(sysfsName + "." + std::to_string(instance + 1)) / "occ_state"; |
| 407 | |
| 408 | std::ifstream file; |
| 409 | bool goodFile = false; |
| 410 | |
| 411 | // open file. |
| 412 | file.open(filename, std::ios::in); |
| 413 | const int openErrno = errno; |
| 414 | |
| 415 | // File is open and state can be used. |
| 416 | if (file.is_open() && file.good()) |
| 417 | { |
| 418 | goodFile = true; |
| 419 | file >> state; |
| 420 | |
| 421 | if (state != lastState) |
| 422 | { |
| 423 | // Trace OCC state changes |
| 424 | log<level::INFO>( |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 425 | fmt::format( |
| 426 | "Status::readOccState: OCC{} state 0x{:02X} (lastState: 0x{:02X})", |
| 427 | instance, state, lastState) |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 428 | .c_str()); |
| 429 | lastState = state; |
| 430 | #ifdef POWER10 |
| 431 | if (OccState(state) == OccState::ACTIVE) |
| 432 | { |
| 433 | if (pmode && device.master()) |
| 434 | { |
| 435 | // Set the master OCC on the PowerMode object |
| 436 | pmode->setMasterOcc(path); |
| 437 | // Enable mode changes |
| 438 | pmode->setMasterActive(); |
| 439 | |
| 440 | // Special processing by master OCC when it goes active |
| 441 | occsWentActive(); |
| 442 | } |
| 443 | |
| 444 | CmdStatus status = sendAmbient(); |
| 445 | if (status != CmdStatus::SUCCESS) |
| 446 | { |
| 447 | log<level::ERR>( |
| 448 | fmt::format( |
| 449 | "readOccState: Sending Ambient failed with status {}", |
| 450 | status) |
| 451 | .c_str()); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | // If OCC in known Good State. |
| 456 | if ((OccState(state) == OccState::ACTIVE) || |
| 457 | (OccState(state) == OccState::CHARACTERIZATION) || |
| 458 | (OccState(state) == OccState::OBSERVATION)) |
| 459 | { |
| 460 | // Good OCC State then sensors valid again |
| 461 | stateValid = true; |
| 462 | |
| 463 | if (safeStateDelayTimer.isEnabled()) |
| 464 | { |
| 465 | // stop safe delay timer (no longer in SAFE state) |
| 466 | safeStateDelayTimer.setEnabled(false); |
| 467 | } |
| 468 | } |
| 469 | // Else not Valid state We would be in SAFE mode. |
| 470 | // This captures both SAFE mode, and 0x00, or other invalid |
| 471 | // state values. |
| 472 | else |
| 473 | { |
| 474 | if (!safeStateDelayTimer.isEnabled()) |
| 475 | { |
| 476 | // start safe delay timer (before requesting reset) |
| 477 | using namespace std::literals::chrono_literals; |
| 478 | safeStateDelayTimer.restartOnce(60s); |
| 479 | } |
| 480 | // Not valid state, update sensors to Nan & not functional. |
| 481 | stateValid = false; |
| 482 | } |
| 483 | #else |
| 484 | // Before P10 state not checked, only used good file open. |
| 485 | stateValid = true; |
| 486 | #endif |
| 487 | } |
| 488 | } |
| 489 | file.close(); |
| 490 | |
| 491 | // if failed to Read a state or not a valid state -> Attempt retry |
| 492 | // after 1 Second delay if allowed. |
| 493 | if ((!goodFile) || (!stateValid)) |
| 494 | { |
| 495 | if (!goodFile) |
| 496 | { |
| 497 | // If not able to read, OCC may be offline |
| 498 | log<level::ERR>( |
| 499 | fmt::format("Status::readOccState: open failed (errno={})", |
| 500 | openErrno) |
| 501 | .c_str()); |
| 502 | } |
| 503 | else |
| 504 | { |
| 505 | // else this failed due to state not valid. |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 506 | if (state != lastState) |
| 507 | { |
| 508 | log<level::ERR>( |
| 509 | fmt::format( |
| 510 | "Status::readOccState: OCC{} Invalid state 0x{:02X} (last state: 0x{:02X})", |
| 511 | instance, state, lastState) |
| 512 | .c_str()); |
| 513 | } |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | #ifdef READ_OCC_SENSORS |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 517 | manager.setSensorValueToNaN(instance); |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 518 | #endif |
| 519 | |
| 520 | // See occReadRetries for number of retry attempts. |
| 521 | if (currentOccReadRetriesCount > 0) |
| 522 | { |
| 523 | --currentOccReadRetriesCount; |
| 524 | #ifdef POWER10 |
| 525 | using namespace std::chrono_literals; |
| 526 | occReadStateFailTimer.restartOnce(1s); |
| 527 | #endif |
| 528 | } |
| 529 | else |
| 530 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 531 | #ifdef POWER10 |
| 532 | if (!stateValid && occActive()) |
| 533 | { |
| 534 | if (!safeStateDelayTimer.isEnabled()) |
| 535 | { |
| 536 | log<level::ERR>( |
| 537 | "Starting 60 sec delay timer before requesting a reset"); |
| 538 | // start safe delay timer (before requesting reset) |
| 539 | using namespace std::literals::chrono_literals; |
| 540 | safeStateDelayTimer.restartOnce(60s); |
| 541 | } |
| 542 | } |
| 543 | #else |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 544 | // State could not be determined, set it to NO State. |
| 545 | lastState = 0; |
| 546 | |
| 547 | // Disable the ability to send Failed actions until OCC is |
| 548 | // Active again. |
| 549 | stateValid = false; |
| 550 | |
| 551 | // Disable and reset to try recovering |
| 552 | deviceError(); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 553 | #endif |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 558 | } // namespace occ |
| 559 | } // namespace open_power |