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