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 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 10 | #ifdef POWER10 |
| 11 | #include <com/ibm/Host/Target/server.hpp> |
| 12 | #endif |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 13 | #include <phosphor-logging/log.hpp> |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 14 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 15 | namespace open_power |
| 16 | { |
| 17 | namespace occ |
| 18 | { |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 19 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 20 | using namespace phosphor::logging; |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 21 | |
| 22 | // Handles updates to occActive property |
| 23 | bool Status::occActive(bool value) |
| 24 | { |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 25 | if (value != this->occActive()) |
| 26 | { |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 27 | log<level::INFO>(fmt::format("Status::occActive OCC{} changed to {}", |
| 28 | instance, value) |
| 29 | .c_str()); |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 30 | if (value) |
| 31 | { |
| 32 | // Bind the device |
| 33 | device.bind(); |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 34 | |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 35 | // Start watching for errors |
| 36 | addErrorWatch(); |
| 37 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 38 | // Reset last OCC state |
| 39 | lastState = 0; |
| 40 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 41 | if (device.master()) |
| 42 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 43 | // Update powercap bounds from OCC |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame^] | 44 | manager.updatePcapBounds(); |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 45 | } |
| 46 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 47 | // Call into Manager to let know that we have bound |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 48 | if (this->managerCallBack) |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 49 | { |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 50 | this->managerCallBack(value); |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 51 | } |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 52 | } |
| 53 | else |
| 54 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 55 | #ifdef POWER10 |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 56 | if (pmode && device.master()) |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 57 | { |
| 58 | // Prevent mode changes |
| 59 | pmode->setMasterActive(false); |
| 60 | } |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 61 | if (safeStateDelayTimer.isEnabled()) |
| 62 | { |
| 63 | // stop safe delay timer |
| 64 | safeStateDelayTimer.setEnabled(false); |
| 65 | } |
| 66 | #endif |
| 67 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 68 | // Call into Manager to let know that we will unbind. |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 69 | if (this->managerCallBack) |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 70 | { |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 71 | this->managerCallBack(value); |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 72 | } |
| 73 | |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 74 | // Stop watching for errors |
| 75 | removeErrorWatch(); |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 76 | |
| 77 | // Do the unbind. |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 78 | device.unBind(); |
| 79 | } |
| 80 | } |
Edward A. James | 5e17797 | 2017-10-25 15:50:31 -0500 | [diff] [blame] | 81 | else if (value && !device.bound()) |
| 82 | { |
| 83 | // Existing error watch is on a dead file descriptor. |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 84 | removeErrorWatch(); |
Edward A. James | 5e17797 | 2017-10-25 15:50:31 -0500 | [diff] [blame] | 85 | |
| 86 | /* |
| 87 | * In it's constructor, Status checks Device::bound() to see if OCC is |
| 88 | * active or not. |
| 89 | * Device::bound() checks for occX-dev0 directory. |
| 90 | * We will lose occX-dev0 directories during FSI rescan. |
| 91 | * So, if we start this application (and construct Status), and then |
| 92 | * later do FSI rescan, we will end up with occActive = true and device |
| 93 | * NOT bound. Lets correct that situation here. |
| 94 | */ |
| 95 | device.bind(); |
| 96 | |
| 97 | // Add error watch again |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 98 | addErrorWatch(); |
Edward A. James | 5e17797 | 2017-10-25 15:50:31 -0500 | [diff] [blame] | 99 | } |
Eddie James | 6d6d1b3 | 2019-04-22 10:45:08 -0500 | [diff] [blame] | 100 | else if (!value && device.bound()) |
| 101 | { |
| 102 | removeErrorWatch(); |
| 103 | |
| 104 | // In the event that the application never receives the active signal |
| 105 | // even though the OCC is active (this can occur if the BMC is rebooted |
| 106 | // with the host on, since the initial OCC driver probe will discover |
| 107 | // the OCCs), this application needs to be able to unbind the device |
| 108 | // when we get the OCC inactive signal. |
| 109 | device.unBind(); |
| 110 | } |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 111 | return Base::Status::occActive(value); |
| 112 | } |
| 113 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 114 | // Callback handler when a device error is reported. |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 115 | void Status::deviceError() |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 116 | { |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 117 | #ifdef POWER10 |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 118 | if (pmode && device.master()) |
| 119 | { |
| 120 | // Prevent mode changes |
| 121 | pmode->setMasterActive(false); |
| 122 | } |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 123 | #endif |
| 124 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 125 | // This would deem OCC inactive |
| 126 | this->occActive(false); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 127 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 128 | // Reset the OCC |
| 129 | this->resetOCC(); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | // Sends message to host control command handler to reset OCC |
| 133 | void Status::resetOCC() |
| 134 | { |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 135 | log<level::INFO>( |
| 136 | fmt::format(">>Status::resetOCC() - requesting reset for OCC{}", |
| 137 | instance) |
| 138 | .c_str()); |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 139 | #ifdef PLDM |
| 140 | if (resetCallBack) |
| 141 | { |
| 142 | this->resetCallBack(instance); |
| 143 | } |
| 144 | #else |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 145 | constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0"; |
| 146 | constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host"; |
| 147 | |
| 148 | // This will throw exception on failure |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 149 | auto service = utils::getService(CONTROL_HOST_PATH, CONTROL_HOST_INTF); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 150 | |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 151 | auto& bus = utils::getBus(); |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 152 | auto method = bus.new_method_call(service.c_str(), CONTROL_HOST_PATH, |
| 153 | CONTROL_HOST_INTF, "Execute"); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 154 | // OCC Reset control command |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 155 | method.append(convertForMessage(Control::Host::Command::OCCReset).c_str()); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 156 | |
| 157 | // OCC Sensor ID for callout reasons |
Patrick Williams | e096270 | 2020-05-13 17:50:22 -0500 | [diff] [blame] | 158 | method.append(std::variant<uint8_t>(std::get<0>(sensorMap.at(instance)))); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 159 | bus.call_noreply(method); |
| 160 | return; |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 161 | #endif |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | // Handler called by Host control command handler to convey the |
| 165 | // status of the executed command |
| 166 | void Status::hostControlEvent(sdbusplus::message::message& msg) |
| 167 | { |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 168 | std::string cmdCompleted{}; |
| 169 | std::string cmdStatus{}; |
| 170 | |
| 171 | msg.read(cmdCompleted, cmdStatus); |
| 172 | |
| 173 | log<level::DEBUG>("Host control signal values", |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 174 | entry("COMMAND=%s", cmdCompleted.c_str()), |
| 175 | entry("STATUS=%s", cmdStatus.c_str())); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 176 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 177 | if (Control::Host::convertResultFromString(cmdStatus) != |
| 178 | Control::Host::Result::Success) |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 179 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 180 | if (Control::Host::convertCommandFromString(cmdCompleted) == |
| 181 | Control::Host::Command::OCCReset) |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 182 | { |
Gunnar Mills | 85e6520 | 2018-04-08 15:01:54 -0500 | [diff] [blame] | 183 | // Must be a Timeout. Log an Error trace |
Alexander Filippov | 1d69e19 | 2019-03-21 18:12:07 +0300 | [diff] [blame] | 184 | log<level::ERR>( |
| 185 | "Error resetting the OCC.", entry("PATH=%s", path.c_str()), |
| 186 | entry("SENSORID=0x%X", std::get<0>(sensorMap.at(instance)))); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | return; |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 190 | } |
| 191 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 192 | void Status::readOccState() |
| 193 | { |
| 194 | unsigned int state; |
| 195 | const fs::path filename = |
| 196 | fs::path(DEV_PATH) / |
| 197 | fs::path(sysfsName + "." + std::to_string(instance + 1)) / "occ_state"; |
| 198 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 199 | std::ifstream file(filename, std::ios::in); |
| 200 | const int open_errno = errno; |
| 201 | if (file) |
| 202 | { |
| 203 | file >> state; |
| 204 | if (state != lastState) |
| 205 | { |
| 206 | // Trace OCC state changes |
| 207 | log<level::INFO>( |
| 208 | fmt::format("Status::readOccState: OCC{} state 0x{:02X}", |
| 209 | instance, state) |
| 210 | .c_str()); |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 211 | if (state & 0xFFFFFFF8) |
| 212 | { |
| 213 | log<level::ERR>( |
| 214 | fmt::format("Status::readOccState: INVALID STATE from {}!!", |
| 215 | filename.c_str()) |
| 216 | .c_str()); |
| 217 | } |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 218 | lastState = state; |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 219 | |
| 220 | #ifdef POWER10 |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 221 | if (OccState(state) == OccState::ACTIVE) |
| 222 | { |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 223 | if (pmode && device.master()) |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 224 | { |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 225 | // Set the master OCC on the PowerMode object |
| 226 | pmode->setMasterOcc(path); |
| 227 | // Enable mode changes |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 228 | pmode->setMasterActive(); |
| 229 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 230 | // Special processing by master OCC when it goes active |
| 231 | occsWentActive(); |
| 232 | } |
| 233 | |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 234 | CmdStatus status = sendAmbient(); |
| 235 | if (status != CmdStatus::SUCCESS) |
| 236 | { |
| 237 | log<level::ERR>( |
| 238 | fmt::format( |
| 239 | "readOccState: Sending Ambient failed with status {}", |
| 240 | status) |
| 241 | .c_str()); |
| 242 | } |
| 243 | } |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 244 | |
| 245 | if (OccState(state) == OccState::SAFE) |
| 246 | { |
| 247 | // start safe delay timer (before requesting reset) |
| 248 | using namespace std::literals::chrono_literals; |
| 249 | safeStateDelayTimer.restartOnce(60s); |
| 250 | } |
| 251 | else if (safeStateDelayTimer.isEnabled()) |
| 252 | { |
| 253 | // stop safe delay timer (no longer in SAFE state) |
| 254 | safeStateDelayTimer.setEnabled(false); |
| 255 | } |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 256 | #endif |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 257 | } |
| 258 | file.close(); |
| 259 | } |
| 260 | else |
| 261 | { |
| 262 | // If not able to read, OCC may be offline |
| 263 | log<level::DEBUG>( |
| 264 | fmt::format("Status::readOccState: open failed (errno={})", |
| 265 | open_errno) |
| 266 | .c_str()); |
| 267 | lastState = 0; |
| 268 | } |
| 269 | } |
| 270 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 271 | #ifdef POWER10 |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 272 | // Special processing that needs to happen once the OCCs change to ACTIVE state |
| 273 | void Status::occsWentActive() |
| 274 | { |
| 275 | CmdStatus status = CmdStatus::SUCCESS; |
| 276 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 277 | status = pmode->sendModeChange(); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 278 | if (status != CmdStatus::SUCCESS) |
| 279 | { |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 280 | log<level::ERR>( |
| 281 | fmt::format( |
| 282 | "Status::occsWentActive: OCC mode change failed with status {}", |
| 283 | status) |
| 284 | .c_str()); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 285 | } |
| 286 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 287 | status = pmode->sendIpsData(); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 288 | if (status != CmdStatus::SUCCESS) |
| 289 | { |
| 290 | log<level::ERR>( |
| 291 | fmt::format( |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 292 | "Status::occsWentActive: Sending Idle Power Save Config data failed with status {}", |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 293 | status) |
| 294 | .c_str()); |
| 295 | } |
| 296 | } |
| 297 | |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 298 | // Send Ambient and Altitude to the OCC |
| 299 | CmdStatus Status::sendAmbient(const uint8_t inTemp, const uint16_t inAltitude) |
| 300 | { |
| 301 | CmdStatus status = CmdStatus::FAILURE; |
| 302 | bool ambientValid = true; |
| 303 | uint8_t ambientTemp = inTemp; |
| 304 | uint16_t altitude = inAltitude; |
| 305 | |
| 306 | if (ambientTemp == 0xFF) |
| 307 | { |
| 308 | // Get latest readings from manager |
| 309 | manager.getAmbientData(ambientValid, ambientTemp, altitude); |
| 310 | log<level::DEBUG>( |
| 311 | fmt::format("sendAmbient: valid: {}, Ambient: {}C, altitude: {}m", |
| 312 | ambientValid, ambientTemp, altitude) |
| 313 | .c_str()); |
| 314 | } |
| 315 | |
| 316 | std::vector<std::uint8_t> cmd, rsp; |
| 317 | cmd.reserve(11); |
| 318 | cmd.push_back(uint8_t(CmdType::SEND_AMBIENT)); |
| 319 | cmd.push_back(0x00); // Data Length (2 bytes) |
| 320 | cmd.push_back(0x08); // |
| 321 | cmd.push_back(0x00); // Version |
| 322 | cmd.push_back(ambientValid ? 0 : 0xFF); // Ambient Status |
| 323 | cmd.push_back(ambientTemp); // Ambient Temperature |
| 324 | cmd.push_back(altitude >> 8); // Altitude in meters (2 bytes) |
| 325 | cmd.push_back(altitude & 0xFF); // |
| 326 | cmd.push_back(0x00); // Reserved (3 bytes) |
| 327 | cmd.push_back(0x00); |
| 328 | cmd.push_back(0x00); |
| 329 | log<level::DEBUG>(fmt::format("sendAmbient: SEND_AMBIENT " |
| 330 | "command to OCC{} ({} bytes)", |
| 331 | instance, cmd.size()) |
| 332 | .c_str()); |
| 333 | status = occCmd.send(cmd, rsp); |
| 334 | if (status == CmdStatus::SUCCESS) |
| 335 | { |
| 336 | if (rsp.size() == 5) |
| 337 | { |
| 338 | if (RspStatus::SUCCESS != RspStatus(rsp[2])) |
| 339 | { |
| 340 | log<level::ERR>( |
| 341 | fmt::format( |
| 342 | "sendAmbient: SEND_AMBIENT failed with status 0x{:02X}", |
| 343 | rsp[2]) |
| 344 | .c_str()); |
| 345 | dump_hex(rsp); |
| 346 | status = CmdStatus::FAILURE; |
| 347 | } |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | log<level::ERR>("sendAmbient: INVALID SEND_AMBIENT response"); |
| 352 | dump_hex(rsp); |
| 353 | status = CmdStatus::FAILURE; |
| 354 | } |
| 355 | } |
| 356 | else |
| 357 | { |
| 358 | if (status == CmdStatus::OPEN_FAILURE) |
| 359 | { |
| 360 | // OCC not active yet |
| 361 | status = CmdStatus::SUCCESS; |
| 362 | } |
| 363 | else |
| 364 | { |
| 365 | log<level::ERR>("sendAmbient: SEND_AMBIENT FAILED!"); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | return status; |
| 370 | } |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 371 | |
| 372 | // Called when safe timer expires to determine if OCCs need to be reset |
| 373 | void Status::safeStateDelayExpired() |
| 374 | { |
| 375 | if (this->occActive()) |
| 376 | { |
| 377 | log<level::INFO>( |
| 378 | fmt::format( |
| 379 | "safeStateDelayExpired: OCC{} is in SAFE state, requesting reset", |
| 380 | instance) |
| 381 | .c_str()); |
| 382 | // Disable and reset to try recovering |
| 383 | deviceError(); |
| 384 | } |
| 385 | } |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 386 | #endif // POWER10 |
| 387 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 388 | fs::path Status::getHwmonPath() const |
| 389 | { |
| 390 | using namespace std::literals::string_literals; |
| 391 | |
| 392 | // Build the base HWMON path |
| 393 | fs::path prefixPath = fs::path{OCC_HWMON_PATH + "occ-hwmon."s + |
| 394 | std::to_string(instance + 1) + "/hwmon/"s}; |
| 395 | // Get the hwmonXX directory name, there better only be 1 dir |
| 396 | assert(std::distance(fs::directory_iterator(prefixPath), |
| 397 | fs::directory_iterator{}) == 1); |
| 398 | |
| 399 | return *fs::directory_iterator(prefixPath); |
| 400 | } |
| 401 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 402 | } // namespace occ |
| 403 | } // namespace open_power |