Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 3 | #include "occ_manager.hpp" |
| 4 | |
| 5 | #include "i2c_occ.hpp" |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 6 | #include "occ_dbus.hpp" |
Chris Cain | 4b82f3e | 2024-04-22 14:44:29 -0500 | [diff] [blame] | 7 | #include "occ_errors.hpp" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 8 | #include "utils.hpp" |
| 9 | |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 10 | #include <phosphor-logging/elog-errors.hpp> |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 11 | #include <phosphor-logging/lg2.hpp> |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 12 | #include <xyz/openbmc_project/Common/error.hpp> |
| 13 | |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 14 | #include <chrono> |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 15 | #include <cmath> |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 16 | #include <filesystem> |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 17 | #include <fstream> |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 18 | #include <regex> |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 19 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 20 | namespace open_power |
| 21 | { |
| 22 | namespace occ |
| 23 | { |
| 24 | |
Matt Spinler | 8b8abee | 2021-08-25 15:18:21 -0500 | [diff] [blame] | 25 | constexpr uint32_t fruTypeNotAvailable = 0xFF; |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 26 | constexpr auto fruTypeSuffix = "fru_type"; |
| 27 | constexpr auto faultSuffix = "fault"; |
| 28 | constexpr auto inputSuffix = "input"; |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 29 | constexpr auto maxSuffix = "max"; |
Matt Spinler | 8b8abee | 2021-08-25 15:18:21 -0500 | [diff] [blame] | 30 | |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 31 | const auto HOST_ON_FILE = "/run/openbmc/host@0-on"; |
| 32 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 33 | using namespace phosphor::logging; |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 34 | using namespace std::literals::chrono_literals; |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 35 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 36 | template <typename T> |
| 37 | T readFile(const std::string& path) |
| 38 | { |
| 39 | std::ifstream ifs; |
| 40 | ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit | |
| 41 | std::ifstream::eofbit); |
| 42 | T data; |
| 43 | |
| 44 | try |
| 45 | { |
| 46 | ifs.open(path); |
| 47 | ifs >> data; |
| 48 | ifs.close(); |
| 49 | } |
| 50 | catch (const std::exception& e) |
| 51 | { |
| 52 | auto err = errno; |
| 53 | throw std::system_error(err, std::generic_category()); |
| 54 | } |
| 55 | |
| 56 | return data; |
| 57 | } |
| 58 | |
Chris Cain | 720a384 | 2025-01-09 10:23:36 -0600 | [diff] [blame] | 59 | void Manager::createPldmHandle() |
| 60 | { |
| 61 | #ifdef PLDM |
| 62 | pldmHandle = std::make_unique<pldm::Interface>( |
| 63 | std::bind(std::mem_fn(&Manager::updateOCCActive), this, |
| 64 | std::placeholders::_1, std::placeholders::_2), |
| 65 | std::bind(std::mem_fn(&Manager::sbeHRESETResult), this, |
| 66 | std::placeholders::_1, std::placeholders::_2), |
| 67 | std::bind(std::mem_fn(&Manager::updateOccSafeMode), this, |
| 68 | std::placeholders::_1), |
Chris Cain | c488bac | 2025-03-17 09:01:15 -0500 | [diff] [blame^] | 69 | std::bind(std::mem_fn(&Manager::hostPoweredOff), this), event); |
Chris Cain | 720a384 | 2025-01-09 10:23:36 -0600 | [diff] [blame] | 70 | #endif |
| 71 | } |
| 72 | |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 73 | // findAndCreateObjects(): |
| 74 | // Takes care of getting the required objects created and |
| 75 | // finds the available devices/processors. |
| 76 | // (function is called everytime the discoverTimer expires) |
| 77 | // - create the PowerMode object to control OCC modes |
| 78 | // - create statusObjects for each OCC device found |
| 79 | // - waits for OCC Active sensors PDRs to become available |
| 80 | // - restart discoverTimer if all data is not available yet |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 81 | void Manager::findAndCreateObjects() |
| 82 | { |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 83 | #ifndef POWER10 |
Deepak Kodihalli | 370f06b | 2017-10-25 04:26:07 -0500 | [diff] [blame] | 84 | for (auto id = 0; id < MAX_CPUS; ++id) |
| 85 | { |
Deepak Kodihalli | 30417a1 | 2017-12-04 00:54:01 -0600 | [diff] [blame] | 86 | // Create one occ per cpu |
| 87 | auto occ = std::string(OCC_NAME) + std::to_string(id); |
| 88 | createObjects(occ); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 89 | } |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 90 | #else |
Chris Cain | 613dc90 | 2022-04-08 09:56:22 -0500 | [diff] [blame] | 91 | if (!pmode) |
| 92 | { |
| 93 | // Create the power mode object |
| 94 | pmode = std::make_unique<powermode::PowerMode>( |
| 95 | *this, powermode::PMODE_PATH, powermode::PIPS_PATH, event); |
| 96 | } |
| 97 | |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 98 | if (!fs::exists(HOST_ON_FILE)) |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 99 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 100 | static bool statusObjCreated = false; |
| 101 | if (!statusObjCreated) |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 102 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 103 | // Create the OCCs based on on the /dev/occX devices |
| 104 | auto occs = findOCCsInDev(); |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 105 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 106 | if (occs.empty() || (prevOCCSearch.size() != occs.size())) |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 107 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 108 | // Something changed or no OCCs yet, try again in 10s. |
| 109 | // Note on the first pass prevOCCSearch will be empty, |
| 110 | // so there will be at least one delay to give things |
| 111 | // a chance to settle. |
| 112 | prevOCCSearch = occs; |
| 113 | |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 114 | lg2::info( |
| 115 | "Manager::findAndCreateObjects(): Waiting for OCCs (currently {QTY})", |
| 116 | "QTY", occs.size()); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 117 | |
| 118 | discoverTimer->restartOnce(10s); |
| 119 | } |
| 120 | else |
| 121 | { |
| 122 | // All OCCs appear to be available, create status objects |
| 123 | |
| 124 | // createObjects requires OCC0 first. |
| 125 | std::sort(occs.begin(), occs.end()); |
| 126 | |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 127 | lg2::info( |
| 128 | "Manager::findAndCreateObjects(): Creating {QTY} OCC Status Objects", |
| 129 | "QTY", occs.size()); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 130 | for (auto id : occs) |
| 131 | { |
| 132 | createObjects(std::string(OCC_NAME) + std::to_string(id)); |
| 133 | } |
| 134 | statusObjCreated = true; |
Chris Cain | 6d8f37a | 2022-04-29 13:46:01 -0500 | [diff] [blame] | 135 | waitingForAllOccActiveSensors = true; |
Chris Cain | c86d80f | 2023-05-04 15:49:18 -0500 | [diff] [blame] | 136 | |
| 137 | // Find/update the processor path associated with each OCC |
| 138 | for (auto& obj : statusObjects) |
| 139 | { |
| 140 | obj->updateProcAssociation(); |
| 141 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
Chris Cain | 6d8f37a | 2022-04-29 13:46:01 -0500 | [diff] [blame] | 145 | if (statusObjCreated && waitingForAllOccActiveSensors) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 146 | { |
| 147 | static bool tracedHostWait = false; |
| 148 | if (utils::isHostRunning()) |
| 149 | { |
| 150 | if (tracedHostWait) |
| 151 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 152 | lg2::info( |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 153 | "Manager::findAndCreateObjects(): Host is running"); |
| 154 | tracedHostWait = false; |
| 155 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 156 | checkAllActiveSensors(); |
| 157 | } |
| 158 | else |
| 159 | { |
| 160 | if (!tracedHostWait) |
| 161 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 162 | lg2::info( |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 163 | "Manager::findAndCreateObjects(): Waiting for host to start"); |
| 164 | tracedHostWait = true; |
| 165 | } |
| 166 | discoverTimer->restartOnce(30s); |
Chris Cain | 7651c06 | 2024-05-02 14:14:06 -0500 | [diff] [blame] | 167 | #ifdef PLDM |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 168 | if (throttlePldmTraceTimer->isEnabled()) |
Chris Cain | 7651c06 | 2024-05-02 14:14:06 -0500 | [diff] [blame] | 169 | { |
| 170 | // Host is no longer running, disable throttle timer and |
| 171 | // make sure traces are not throttled |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 172 | lg2::info("findAndCreateObjects(): disabling sensor timer"); |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 173 | throttlePldmTraceTimer->setEnabled(false); |
Chris Cain | 7651c06 | 2024-05-02 14:14:06 -0500 | [diff] [blame] | 174 | pldmHandle->setTraceThrottle(false); |
| 175 | } |
| 176 | #endif |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 177 | } |
| 178 | } |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 179 | } |
| 180 | else |
| 181 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 182 | lg2::info( |
| 183 | "Manager::findAndCreateObjects(): Waiting for {FILE} to complete...", |
| 184 | "FILE", HOST_ON_FILE); |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 185 | discoverTimer->restartOnce(10s); |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 186 | } |
| 187 | #endif |
| 188 | } |
| 189 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 190 | #ifdef POWER10 |
| 191 | // Check if all occActive sensors are available |
| 192 | void Manager::checkAllActiveSensors() |
| 193 | { |
| 194 | static bool allActiveSensorAvailable = false; |
| 195 | static bool tracedSensorWait = false; |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 196 | static bool waitingForHost = false; |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 197 | |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 198 | if (open_power::occ::utils::isHostRunning()) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 199 | { |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 200 | if (waitingForHost) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 201 | { |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 202 | waitingForHost = false; |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 203 | lg2::info("checkAllActiveSensors(): Host is now running"); |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | // Start with the assumption that all are available |
| 207 | allActiveSensorAvailable = true; |
| 208 | for (auto& obj : statusObjects) |
| 209 | { |
| 210 | if ((!obj->occActive()) && (!obj->getPldmSensorReceived())) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 211 | { |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 212 | auto instance = obj->getOccInstanceID(); |
| 213 | // Check if sensor was queued while waiting for discovery |
| 214 | auto match = queuedActiveState.find(instance); |
| 215 | if (match != queuedActiveState.end()) |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 216 | { |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 217 | queuedActiveState.erase(match); |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 218 | lg2::info( |
| 219 | "checkAllActiveSensors(): OCC{INST} is ACTIVE (queued)", |
| 220 | "INST", instance); |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 221 | obj->occActive(true); |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 222 | } |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 223 | else |
| 224 | { |
| 225 | allActiveSensorAvailable = false; |
| 226 | if (!tracedSensorWait) |
| 227 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 228 | lg2::info( |
| 229 | "checkAllActiveSensors(): Waiting on OCC{INST} Active sensor", |
| 230 | "INST", instance); |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 231 | tracedSensorWait = true; |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 232 | #ifdef PLDM |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 233 | // Make sure PLDM traces are not throttled |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 234 | pldmHandle->setTraceThrottle(false); |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 235 | // Start timer to throttle PLDM traces when timer |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 236 | // expires |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 237 | onPldmTimeoutCreatePel = false; |
| 238 | throttlePldmTraceTimer->restartOnce(5min); |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 239 | #endif |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 240 | } |
Patrick Williams | fb0a5c3 | 2024-02-28 11:27:00 -0600 | [diff] [blame] | 241 | #ifdef PLDM |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 242 | // Ignore active sensor check if the OCCs are being reset |
| 243 | if (!resetInProgress) |
| 244 | { |
| 245 | pldmHandle->checkActiveSensor(obj->getOccInstanceID()); |
| 246 | } |
Patrick Williams | fb0a5c3 | 2024-02-28 11:27:00 -0600 | [diff] [blame] | 247 | #endif |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 248 | break; |
| 249 | } |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 250 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 251 | } |
| 252 | } |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 253 | else |
| 254 | { |
| 255 | if (!waitingForHost) |
| 256 | { |
| 257 | waitingForHost = true; |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 258 | lg2::info("checkAllActiveSensors(): Waiting for host to start"); |
Chris Cain | 7651c06 | 2024-05-02 14:14:06 -0500 | [diff] [blame] | 259 | #ifdef PLDM |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 260 | if (throttlePldmTraceTimer->isEnabled()) |
Chris Cain | 7651c06 | 2024-05-02 14:14:06 -0500 | [diff] [blame] | 261 | { |
| 262 | // Host is no longer running, disable throttle timer and |
| 263 | // make sure traces are not throttled |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 264 | lg2::info("checkAllActiveSensors(): disabling sensor timer"); |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 265 | throttlePldmTraceTimer->setEnabled(false); |
Chris Cain | 7651c06 | 2024-05-02 14:14:06 -0500 | [diff] [blame] | 266 | pldmHandle->setTraceThrottle(false); |
| 267 | } |
| 268 | #endif |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 269 | } |
| 270 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 271 | |
| 272 | if (allActiveSensorAvailable) |
| 273 | { |
| 274 | // All sensors were found, disable the discovery timer |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 275 | if (discoverTimer->isEnabled()) |
| 276 | { |
Chris Cain | f55f91a | 2022-05-27 13:40:15 -0500 | [diff] [blame] | 277 | discoverTimer->setEnabled(false); |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 278 | } |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 279 | #ifdef PLDM |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 280 | if (throttlePldmTraceTimer->isEnabled()) |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 281 | { |
| 282 | // Disable throttle timer and make sure traces are not throttled |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 283 | throttlePldmTraceTimer->setEnabled(false); |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 284 | pldmHandle->setTraceThrottle(false); |
| 285 | } |
| 286 | #endif |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 287 | if (waitingForAllOccActiveSensors) |
| 288 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 289 | lg2::info( |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 290 | "checkAllActiveSensors(): OCC Active sensors are available"); |
| 291 | waitingForAllOccActiveSensors = false; |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 292 | |
| 293 | if (resetRequired) |
| 294 | { |
| 295 | initiateOccRequest(resetInstance); |
| 296 | |
| 297 | if (!waitForAllOccsTimer->isEnabled()) |
| 298 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 299 | lg2::warning( |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 300 | "occsNotAllRunning: Restarting waitForAllOccTimer"); |
| 301 | // restart occ wait timer to check status after reset |
| 302 | // completes |
| 303 | waitForAllOccsTimer->restartOnce(60s); |
| 304 | } |
| 305 | } |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 306 | } |
| 307 | queuedActiveState.clear(); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 308 | tracedSensorWait = false; |
| 309 | } |
| 310 | else |
| 311 | { |
| 312 | // Not all sensors were available, so keep waiting |
| 313 | if (!tracedSensorWait) |
| 314 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 315 | lg2::info( |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 316 | "checkAllActiveSensors(): Waiting for OCC Active sensors to become available"); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 317 | tracedSensorWait = true; |
| 318 | } |
Chris Cain | f55f91a | 2022-05-27 13:40:15 -0500 | [diff] [blame] | 319 | discoverTimer->restartOnce(10s); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | #endif |
| 323 | |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 324 | std::vector<int> Manager::findOCCsInDev() |
| 325 | { |
| 326 | std::vector<int> occs; |
| 327 | std::regex expr{R"(occ(\d+)$)"}; |
| 328 | |
| 329 | for (auto& file : fs::directory_iterator("/dev")) |
| 330 | { |
| 331 | std::smatch match; |
| 332 | std::string path{file.path().string()}; |
| 333 | if (std::regex_search(path, match, expr)) |
| 334 | { |
| 335 | auto num = std::stoi(match[1].str()); |
| 336 | |
| 337 | // /dev numbering starts at 1, ours starts at 0. |
| 338 | occs.push_back(num - 1); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | return occs; |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 343 | } |
| 344 | |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 345 | int Manager::cpuCreated(sdbusplus::message_t& msg) |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 346 | { |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 347 | namespace fs = std::filesystem; |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 348 | |
| 349 | sdbusplus::message::object_path o; |
| 350 | msg.read(o); |
| 351 | fs::path cpuPath(std::string(std::move(o))); |
| 352 | |
| 353 | auto name = cpuPath.filename().string(); |
| 354 | auto index = name.find(CPU_NAME); |
| 355 | name.replace(index, std::strlen(CPU_NAME), OCC_NAME); |
| 356 | |
| 357 | createObjects(name); |
| 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | void Manager::createObjects(const std::string& occ) |
| 363 | { |
| 364 | auto path = fs::path(OCC_CONTROL_ROOT) / occ; |
| 365 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 366 | statusObjects.emplace_back(std::make_unique<Status>( |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 367 | event, path.c_str(), *this, |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 368 | #ifdef POWER10 |
| 369 | pmode, |
| 370 | #endif |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 371 | std::bind(std::mem_fn(&Manager::statusCallBack), this, |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 372 | std::placeholders::_1, std::placeholders::_2) |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 373 | #ifdef PLDM |
| 374 | , |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 375 | // Callback will set flag indicating reset needs to be done |
| 376 | // instead of immediately issuing a reset via PLDM. |
| 377 | std::bind(std::mem_fn(&Manager::resetOccRequest), this, |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 378 | std::placeholders::_1) |
| 379 | #endif |
| 380 | )); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 381 | |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 382 | // Create the power cap monitor object |
| 383 | if (!pcap) |
| 384 | { |
| 385 | pcap = std::make_unique<open_power::occ::powercap::PowerCap>( |
| 386 | *statusObjects.back()); |
| 387 | } |
| 388 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 389 | if (statusObjects.back()->isMasterOcc()) |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 390 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 391 | lg2::info("Manager::createObjects(): OCC{INST} is the master", "INST", |
| 392 | statusObjects.back()->getOccInstanceID()); |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 393 | _pollTimer->setEnabled(false); |
| 394 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 395 | #ifdef POWER10 |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 396 | // Set the master OCC on the PowerMode object |
| 397 | pmode->setMasterOcc(path); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 398 | #endif |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 399 | } |
| 400 | |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 401 | passThroughObjects.emplace_back(std::make_unique<PassThrough>( |
| 402 | path.c_str() |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 403 | #ifdef POWER10 |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 404 | , |
| 405 | pmode |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 406 | #endif |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 407 | )); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 408 | } |
| 409 | |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 410 | // If a reset is not already outstanding, set a flag to indicate that a reset is |
| 411 | // needed. |
| 412 | void Manager::resetOccRequest(instanceID instance) |
| 413 | { |
| 414 | if (!resetRequired) |
| 415 | { |
| 416 | resetRequired = true; |
| 417 | resetInstance = instance; |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 418 | lg2::error( |
| 419 | "resetOccRequest: PM Complex reset was requested due to OCC{INST}", |
| 420 | "INST", instance); |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 421 | } |
| 422 | else if (instance != resetInstance) |
| 423 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 424 | lg2::warning( |
| 425 | "resetOccRequest: Ignoring PM Complex reset request for OCC{INST}, because reset already outstanding for OCC{RINST}", |
| 426 | "INST", instance, "RINST", resetInstance); |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
| 430 | // If a reset has not been started, initiate an OCC reset via PLDM |
| 431 | void Manager::initiateOccRequest(instanceID instance) |
| 432 | { |
| 433 | if (!resetInProgress) |
| 434 | { |
| 435 | resetInProgress = true; |
| 436 | resetInstance = instance; |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 437 | lg2::error( |
| 438 | "initiateOccRequest: Initiating PM Complex reset due to OCC{INST}", |
| 439 | "INST", instance); |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 440 | #ifdef PLDM |
| 441 | pldmHandle->resetOCC(instance); |
| 442 | #endif |
| 443 | resetRequired = false; |
| 444 | } |
| 445 | else |
| 446 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 447 | lg2::warning( |
| 448 | "initiateOccRequest: Ignoring PM Complex reset request for OCC{INST}, because reset already in process for OCC{RINST}", |
| 449 | "INST", instance, "RINST", resetInstance); |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 453 | void Manager::statusCallBack(instanceID instance, bool status) |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 454 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 455 | if (status == true) |
Eddie James | dae2d94 | 2017-12-20 10:50:03 -0600 | [diff] [blame] | 456 | { |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 457 | if (resetInProgress) |
| 458 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 459 | lg2::info( |
Chris Cain | 92dfb27 | 2025-02-13 12:20:27 -0600 | [diff] [blame] | 460 | "statusCallBack: Ignoring OCC{INST} activate because a reset has been initiated due to OCC{RINST}", |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 461 | "INST", instance, "RINST", resetInstance); |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 462 | return; |
| 463 | } |
| 464 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 465 | // OCC went active |
| 466 | ++activeCount; |
| 467 | |
| 468 | #ifdef POWER10 |
| 469 | if (activeCount == 1) |
Eddie James | dae2d94 | 2017-12-20 10:50:03 -0600 | [diff] [blame] | 470 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 471 | // First OCC went active (allow some time for all OCCs to go active) |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 472 | waitForAllOccsTimer->restartOnce(60s); |
Matt Spinler | 53f6814 | 2021-08-25 15:47:31 -0500 | [diff] [blame] | 473 | } |
| 474 | #endif |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 475 | |
| 476 | if (activeCount == statusObjects.size()) |
| 477 | { |
| 478 | #ifdef POWER10 |
| 479 | // All OCCs are now running |
| 480 | if (waitForAllOccsTimer->isEnabled()) |
| 481 | { |
| 482 | // stop occ wait timer |
| 483 | waitForAllOccsTimer->setEnabled(false); |
| 484 | } |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 485 | |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 486 | // All OCCs have been found, check if we need a reset |
| 487 | if (resetRequired) |
| 488 | { |
| 489 | initiateOccRequest(resetInstance); |
| 490 | |
| 491 | if (!waitForAllOccsTimer->isEnabled()) |
| 492 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 493 | lg2::warning( |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 494 | "occsNotAllRunning: Restarting waitForAllOccTimer"); |
| 495 | // restart occ wait timer |
| 496 | waitForAllOccsTimer->restartOnce(60s); |
| 497 | } |
| 498 | } |
| 499 | else |
| 500 | { |
| 501 | // Verify master OCC and start presence monitor |
| 502 | validateOccMaster(); |
| 503 | } |
| 504 | #else |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 505 | // Verify master OCC and start presence monitor |
| 506 | validateOccMaster(); |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 507 | #endif |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | // Start poll timer if not already started |
| 511 | if (!_pollTimer->isEnabled()) |
| 512 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 513 | lg2::info("Manager: OCCs will be polled every {TIME} seconds", |
| 514 | "TIME", pollInterval); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 515 | |
| 516 | // Send poll and start OCC poll timer |
| 517 | pollerTimerExpired(); |
| 518 | } |
| 519 | } |
| 520 | else |
| 521 | { |
| 522 | // OCC went away |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 523 | if (activeCount > 0) |
| 524 | { |
| 525 | --activeCount; |
| 526 | } |
| 527 | else |
| 528 | { |
Sheldon Bailey | b89d619 | 2025-03-05 09:33:19 -0600 | [diff] [blame] | 529 | lg2::info("OCC{INST} disabled, and no other OCCs are active", |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 530 | "INST", instance); |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 531 | } |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 532 | |
| 533 | if (activeCount == 0) |
| 534 | { |
| 535 | // No OCCs are running |
| 536 | |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 537 | if (resetInProgress) |
| 538 | { |
| 539 | // All OCC active sensors are clear (reset should be in |
| 540 | // progress) |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 541 | lg2::info( |
| 542 | "statusCallBack: Clearing resetInProgress (activeCount={COUNT}, OCC{INST}, status={STATUS})", |
| 543 | "COUNT", activeCount, "INST", instance, "STATUS", status); |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 544 | resetInProgress = false; |
| 545 | resetInstance = 255; |
| 546 | } |
| 547 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 548 | // Stop OCC poll timer |
| 549 | if (_pollTimer->isEnabled()) |
| 550 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 551 | lg2::info( |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 552 | "Manager::statusCallBack(): OCCs are not running, stopping poll timer"); |
| 553 | _pollTimer->setEnabled(false); |
| 554 | } |
| 555 | |
| 556 | #ifdef POWER10 |
| 557 | // stop wait timer |
| 558 | if (waitForAllOccsTimer->isEnabled()) |
| 559 | { |
| 560 | waitForAllOccsTimer->setEnabled(false); |
| 561 | } |
| 562 | #endif |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 563 | } |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 564 | else if (resetInProgress) |
| 565 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 566 | lg2::info( |
| 567 | "statusCallBack: Skipping clear of resetInProgress (activeCount={COUNT}, OCC{INST}, status={STATUS})", |
| 568 | "COUNT", activeCount, "INST", instance, "STATUS", status); |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 569 | } |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 570 | #ifdef READ_OCC_SENSORS |
| 571 | // Clear OCC sensors |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 572 | setSensorValueToNaN(instance); |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 573 | #endif |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 574 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 575 | |
| 576 | #ifdef POWER10 |
| 577 | if (waitingForAllOccActiveSensors) |
| 578 | { |
Chris Cain | 6d8f37a | 2022-04-29 13:46:01 -0500 | [diff] [blame] | 579 | if (utils::isHostRunning()) |
| 580 | { |
| 581 | checkAllActiveSensors(); |
| 582 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 583 | } |
| 584 | #endif |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | #ifdef I2C_OCC |
| 588 | void Manager::initStatusObjects() |
| 589 | { |
| 590 | // Make sure we have a valid path string |
| 591 | static_assert(sizeof(DEV_PATH) != 0); |
| 592 | |
| 593 | auto deviceNames = i2c_occ::getOccHwmonDevices(DEV_PATH); |
| 594 | for (auto& name : deviceNames) |
| 595 | { |
| 596 | i2c_occ::i2cToDbus(name); |
Lei YU | b5259a1 | 2017-09-01 16:22:40 +0800 | [diff] [blame] | 597 | name = std::string(OCC_NAME) + '_' + name; |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 598 | auto path = fs::path(OCC_CONTROL_ROOT) / name; |
| 599 | statusObjects.emplace_back( |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 600 | std::make_unique<Status>(event, path.c_str(), *this)); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 601 | } |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 602 | // The first device is master occ |
| 603 | pcap = std::make_unique<open_power::occ::powercap::PowerCap>( |
| 604 | *statusObjects.front()); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 605 | #ifdef POWER10 |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 606 | pmode = std::make_unique<powermode::PowerMode>(*this, powermode::PMODE_PATH, |
| 607 | powermode::PIPS_PATH); |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 608 | // Set the master OCC on the PowerMode object |
| 609 | pmode->setMasterOcc(path); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 610 | #endif |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 611 | } |
| 612 | #endif |
| 613 | |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 614 | #ifdef PLDM |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 615 | void Manager::sbeTimeout(unsigned int instance) |
| 616 | { |
Eddie James | 2a751d7 | 2022-03-04 09:16:12 -0600 | [diff] [blame] | 617 | auto obj = std::find_if(statusObjects.begin(), statusObjects.end(), |
| 618 | [instance](const auto& obj) { |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 619 | return instance == obj->getOccInstanceID(); |
| 620 | }); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 621 | |
Eddie James | cb018da | 2022-03-05 11:49:37 -0600 | [diff] [blame] | 622 | if (obj != statusObjects.end() && (*obj)->occActive()) |
Eddie James | 2a751d7 | 2022-03-04 09:16:12 -0600 | [diff] [blame] | 623 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 624 | lg2::info("SBE timeout, requesting HRESET (OCC{INST})", "INST", |
| 625 | instance); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 626 | |
Chris Cain | 720a384 | 2025-01-09 10:23:36 -0600 | [diff] [blame] | 627 | #ifdef PHAL_SUPPORT |
Eddie James | 2a751d7 | 2022-03-04 09:16:12 -0600 | [diff] [blame] | 628 | setSBEState(instance, SBE_STATE_NOT_USABLE); |
Chris Cain | 720a384 | 2025-01-09 10:23:36 -0600 | [diff] [blame] | 629 | #endif |
Eddie James | 2a751d7 | 2022-03-04 09:16:12 -0600 | [diff] [blame] | 630 | |
Chris Cain | 92dfb27 | 2025-02-13 12:20:27 -0600 | [diff] [blame] | 631 | // Stop communication with this OCC |
| 632 | (*obj)->occActive(false); |
| 633 | |
Eddie James | 2a751d7 | 2022-03-04 09:16:12 -0600 | [diff] [blame] | 634 | pldmHandle->sendHRESET(instance); |
| 635 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 636 | } |
| 637 | |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 638 | bool Manager::updateOCCActive(instanceID instance, bool status) |
| 639 | { |
Chris Cain | 7e374fb | 2022-04-07 09:47:23 -0500 | [diff] [blame] | 640 | auto obj = std::find_if(statusObjects.begin(), statusObjects.end(), |
| 641 | [instance](const auto& obj) { |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 642 | return instance == obj->getOccInstanceID(); |
| 643 | }); |
Chris Cain | 7e374fb | 2022-04-07 09:47:23 -0500 | [diff] [blame] | 644 | |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 645 | const bool hostRunning = open_power::occ::utils::isHostRunning(); |
Chris Cain | 7e374fb | 2022-04-07 09:47:23 -0500 | [diff] [blame] | 646 | if (obj != statusObjects.end()) |
| 647 | { |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 648 | if (!hostRunning && (status == true)) |
| 649 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 650 | lg2::warning( |
| 651 | "updateOCCActive: Host is not running yet (OCC{INST} active={STAT}), clearing sensor received", |
| 652 | "INST", instance, "STAT", status); |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 653 | (*obj)->setPldmSensorReceived(false); |
| 654 | if (!waitingForAllOccActiveSensors) |
| 655 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 656 | lg2::info( |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 657 | "updateOCCActive: Waiting for Host and all OCC Active Sensors"); |
| 658 | waitingForAllOccActiveSensors = true; |
| 659 | } |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 660 | #ifdef POWER10 |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 661 | discoverTimer->restartOnce(30s); |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 662 | #endif |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 663 | return false; |
| 664 | } |
| 665 | else |
| 666 | { |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 667 | (*obj)->setPldmSensorReceived(true); |
| 668 | return (*obj)->occActive(status); |
| 669 | } |
Chris Cain | 7e374fb | 2022-04-07 09:47:23 -0500 | [diff] [blame] | 670 | } |
| 671 | else |
| 672 | { |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 673 | if (hostRunning) |
| 674 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 675 | lg2::warning( |
| 676 | "updateOCCActive: No status object to update for OCC{INST} (active={STAT})", |
| 677 | "INST", instance, "STAT", status); |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 678 | } |
| 679 | else |
| 680 | { |
| 681 | if (status == true) |
| 682 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 683 | lg2::warning( |
| 684 | "updateOCCActive: No status objects and Host is not running yet (OCC{INST} active={STAT})", |
| 685 | "INST", instance, "STAT", status); |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 686 | } |
| 687 | } |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 688 | if (status == true) |
| 689 | { |
| 690 | // OCC went active |
| 691 | queuedActiveState.insert(instance); |
| 692 | } |
| 693 | else |
| 694 | { |
| 695 | auto match = queuedActiveState.find(instance); |
| 696 | if (match != queuedActiveState.end()) |
| 697 | { |
| 698 | // OCC was disabled |
| 699 | queuedActiveState.erase(match); |
| 700 | } |
| 701 | } |
Chris Cain | 7e374fb | 2022-04-07 09:47:23 -0500 | [diff] [blame] | 702 | return false; |
| 703 | } |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 704 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 705 | |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 706 | // Called upon pldm event To set powermode Safe Mode State for system. |
| 707 | void Manager::updateOccSafeMode(bool safeMode) |
| 708 | { |
| 709 | #ifdef POWER10 |
| 710 | pmode->updateDbusSafeMode(safeMode); |
| 711 | #endif |
Chris Cain | c86d80f | 2023-05-04 15:49:18 -0500 | [diff] [blame] | 712 | // Update the processor throttle status on dbus |
| 713 | for (auto& obj : statusObjects) |
| 714 | { |
| 715 | obj->updateThrottle(safeMode, THROTTLED_SAFE); |
| 716 | } |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 717 | } |
| 718 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 719 | void Manager::sbeHRESETResult(instanceID instance, bool success) |
| 720 | { |
| 721 | if (success) |
| 722 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 723 | lg2::info("HRESET succeeded (OCC{INST})", "INST", instance); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 724 | |
Chris Cain | 720a384 | 2025-01-09 10:23:36 -0600 | [diff] [blame] | 725 | #ifdef PHAL_SUPPORT |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 726 | setSBEState(instance, SBE_STATE_BOOTED); |
Chris Cain | 720a384 | 2025-01-09 10:23:36 -0600 | [diff] [blame] | 727 | #endif |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 728 | |
Chris Cain | 92dfb27 | 2025-02-13 12:20:27 -0600 | [diff] [blame] | 729 | // Re-enable communication with this OCC |
| 730 | auto obj = std::find_if(statusObjects.begin(), statusObjects.end(), |
| 731 | [instance](const auto& obj) { |
| 732 | return instance == obj->getOccInstanceID(); |
| 733 | }); |
| 734 | if (obj != statusObjects.end() && (!(*obj)->occActive())) |
| 735 | { |
| 736 | (*obj)->occActive(true); |
| 737 | } |
| 738 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 739 | return; |
| 740 | } |
| 741 | |
Chris Cain | 720a384 | 2025-01-09 10:23:36 -0600 | [diff] [blame] | 742 | #ifdef PHAL_SUPPORT |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 743 | setSBEState(instance, SBE_STATE_FAILED); |
| 744 | |
| 745 | if (sbeCanDump(instance)) |
| 746 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 747 | lg2::info("HRESET failed (OCC{INST}), triggering SBE dump", "INST", |
| 748 | instance); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 749 | |
| 750 | auto& bus = utils::getBus(); |
| 751 | uint32_t src6 = instance << 16; |
| 752 | uint32_t logId = |
| 753 | FFDC::createPEL("org.open_power.Processor.Error.SbeChipOpTimeout", |
| 754 | src6, "SBE command timeout"); |
| 755 | |
| 756 | try |
| 757 | { |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 758 | constexpr auto interface = "xyz.openbmc_project.Dump.Create"; |
| 759 | constexpr auto function = "CreateDump"; |
| 760 | |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 761 | std::string service = |
| 762 | utils::getService(OP_DUMP_OBJ_PATH, interface); |
Dhruvaraj Subhashchandran | 1173b2b | 2024-06-01 11:12:13 -0500 | [diff] [blame] | 763 | auto method = bus.new_method_call(service.c_str(), OP_DUMP_OBJ_PATH, |
| 764 | interface, function); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 765 | |
| 766 | std::map<std::string, std::variant<std::string, uint64_t>> |
| 767 | createParams{ |
| 768 | {"com.ibm.Dump.Create.CreateParameters.ErrorLogId", |
| 769 | uint64_t(logId)}, |
| 770 | {"com.ibm.Dump.Create.CreateParameters.DumpType", |
| 771 | "com.ibm.Dump.Create.DumpType.SBE"}, |
| 772 | {"com.ibm.Dump.Create.CreateParameters.FailingUnitId", |
| 773 | uint64_t(instance)}, |
| 774 | }; |
| 775 | |
| 776 | method.append(createParams); |
| 777 | |
| 778 | auto response = bus.call(method); |
| 779 | } |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 780 | catch (const sdbusplus::exception_t& e) |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 781 | { |
| 782 | constexpr auto ERROR_DUMP_DISABLED = |
| 783 | "xyz.openbmc_project.Dump.Create.Error.Disabled"; |
| 784 | if (e.name() == ERROR_DUMP_DISABLED) |
| 785 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 786 | lg2::info("Dump is disabled, skipping"); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 787 | } |
| 788 | else |
| 789 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 790 | lg2::error("Dump failed"); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 791 | } |
| 792 | } |
| 793 | } |
Chris Cain | 720a384 | 2025-01-09 10:23:36 -0600 | [diff] [blame] | 794 | #endif |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 795 | |
| 796 | // SBE Reset failed, try PM Complex reset |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 797 | lg2::error("sbeHRESETResult: Forcing PM Complex reset"); |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 798 | resetOccRequest(instance); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 799 | } |
| 800 | |
Chris Cain | 720a384 | 2025-01-09 10:23:36 -0600 | [diff] [blame] | 801 | #ifdef PHAL_SUPPORT |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 802 | bool Manager::sbeCanDump(unsigned int instance) |
| 803 | { |
| 804 | struct pdbg_target* proc = getPdbgTarget(instance); |
| 805 | |
| 806 | if (!proc) |
| 807 | { |
| 808 | // allow the dump in the error case |
| 809 | return true; |
| 810 | } |
| 811 | |
| 812 | try |
| 813 | { |
| 814 | if (!openpower::phal::sbe::isDumpAllowed(proc)) |
| 815 | { |
| 816 | return false; |
| 817 | } |
| 818 | |
| 819 | if (openpower::phal::pdbg::isSbeVitalAttnActive(proc)) |
| 820 | { |
| 821 | return false; |
| 822 | } |
| 823 | } |
| 824 | catch (openpower::phal::exception::SbeError& e) |
| 825 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 826 | lg2::info("Failed to query SBE state"); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | // allow the dump in the error case |
| 830 | return true; |
| 831 | } |
| 832 | |
| 833 | void Manager::setSBEState(unsigned int instance, enum sbe_state state) |
| 834 | { |
| 835 | struct pdbg_target* proc = getPdbgTarget(instance); |
| 836 | |
| 837 | if (!proc) |
| 838 | { |
| 839 | return; |
| 840 | } |
| 841 | |
| 842 | try |
| 843 | { |
| 844 | openpower::phal::sbe::setState(proc, state); |
| 845 | } |
| 846 | catch (const openpower::phal::exception::SbeError& e) |
| 847 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 848 | lg2::error("Failed to set SBE state: {ERROR}", "ERROR", e.what()); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | |
| 852 | struct pdbg_target* Manager::getPdbgTarget(unsigned int instance) |
| 853 | { |
| 854 | if (!pdbgInitialized) |
| 855 | { |
| 856 | try |
| 857 | { |
| 858 | openpower::phal::pdbg::init(); |
| 859 | pdbgInitialized = true; |
| 860 | } |
| 861 | catch (const openpower::phal::exception::PdbgError& e) |
| 862 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 863 | lg2::error("pdbg initialization failed"); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 864 | return nullptr; |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | struct pdbg_target* proc = nullptr; |
| 869 | pdbg_for_each_class_target("proc", proc) |
| 870 | { |
| 871 | if (pdbg_target_index(proc) == instance) |
| 872 | { |
| 873 | return proc; |
| 874 | } |
| 875 | } |
| 876 | |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 877 | lg2::error("Failed to get pdbg target"); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 878 | return nullptr; |
| 879 | } |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 880 | #endif |
Chris Cain | 720a384 | 2025-01-09 10:23:36 -0600 | [diff] [blame] | 881 | #endif |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 882 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 883 | void Manager::pollerTimerExpired() |
| 884 | { |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 885 | if (!_pollTimer) |
| 886 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 887 | lg2::error("pollerTimerExpired() ERROR: Timer not defined"); |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 888 | return; |
| 889 | } |
| 890 | |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 891 | #ifdef POWER10 |
| 892 | if (resetRequired) |
| 893 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 894 | lg2::error("pollerTimerExpired() - Initiating PM Complex reset"); |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 895 | initiateOccRequest(resetInstance); |
| 896 | |
| 897 | if (!waitForAllOccsTimer->isEnabled()) |
| 898 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 899 | lg2::warning("pollerTimerExpired: Restarting waitForAllOccTimer"); |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 900 | // restart occ wait timer |
| 901 | waitForAllOccsTimer->restartOnce(60s); |
| 902 | } |
| 903 | return; |
| 904 | } |
| 905 | #endif |
| 906 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 907 | for (auto& obj : statusObjects) |
| 908 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 909 | if (!obj->occActive()) |
| 910 | { |
| 911 | // OCC is not running yet |
| 912 | #ifdef READ_OCC_SENSORS |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 913 | auto id = obj->getOccInstanceID(); |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 914 | setSensorValueToNaN(id); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 915 | #endif |
| 916 | continue; |
| 917 | } |
| 918 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 919 | // Read sysfs to force kernel to poll OCC |
| 920 | obj->readOccState(); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 921 | |
| 922 | #ifdef READ_OCC_SENSORS |
| 923 | // Read occ sensor values |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 924 | getSensorValues(obj); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 925 | #endif |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 926 | } |
| 927 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 928 | if (activeCount > 0) |
| 929 | { |
| 930 | // Restart OCC poll timer |
| 931 | _pollTimer->restartOnce(std::chrono::seconds(pollInterval)); |
| 932 | } |
| 933 | else |
| 934 | { |
| 935 | // No OCCs running, so poll timer will not be restarted |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 936 | lg2::info( |
| 937 | "Manager::pollerTimerExpired: poll timer will not be restarted"); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 938 | } |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 939 | } |
| 940 | |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 941 | #ifdef READ_OCC_SENSORS |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame] | 942 | void Manager::readTempSensors(const fs::path& path, uint32_t occInstance) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 943 | { |
Matt Spinler | 818cc8d | 2023-10-23 11:43:39 -0500 | [diff] [blame] | 944 | // There may be more than one sensor with the same FRU type |
| 945 | // and label so make two passes: the first to read the temps |
| 946 | // from sysfs, and the second to put them on D-Bus after |
| 947 | // resolving any conflicts. |
| 948 | std::map<std::string, double> sensorData; |
| 949 | |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 950 | std::regex expr{"temp\\d+_label$"}; // Example: temp5_label |
| 951 | for (auto& file : fs::directory_iterator(path)) |
| 952 | { |
| 953 | if (!std::regex_search(file.path().string(), expr)) |
| 954 | { |
| 955 | continue; |
| 956 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 957 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 958 | uint32_t labelValue{0}; |
| 959 | |
| 960 | try |
| 961 | { |
| 962 | labelValue = readFile<uint32_t>(file.path()); |
| 963 | } |
| 964 | catch (const std::system_error& e) |
| 965 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 966 | lg2::debug( |
| 967 | "readTempSensors: Failed reading {PATH}, errno = {ERROR}", |
| 968 | "PATH", file.path().string(), "ERROR", e.code().value()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 969 | continue; |
| 970 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 971 | |
| 972 | const std::string& tempLabel = "label"; |
| 973 | const std::string filePathString = file.path().string().substr( |
| 974 | 0, file.path().string().length() - tempLabel.length()); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 975 | |
| 976 | uint32_t fruTypeValue{0}; |
| 977 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 978 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 979 | fruTypeValue = readFile<uint32_t>(filePathString + fruTypeSuffix); |
| 980 | } |
| 981 | catch (const std::system_error& e) |
| 982 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 983 | lg2::debug( |
| 984 | "readTempSensors: Failed reading {PATH}, errno = {ERROR}", |
| 985 | "PATH", filePathString + fruTypeSuffix, "ERROR", |
| 986 | e.code().value()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 987 | continue; |
| 988 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 989 | |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 990 | std::string sensorPath = |
| 991 | OCC_SENSORS_ROOT + std::string("/temperature/"); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 992 | |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 993 | std::string dvfsTempPath; |
| 994 | |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 995 | if (fruTypeValue == VRMVdd) |
| 996 | { |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 997 | sensorPath.append( |
| 998 | "vrm_vdd" + std::to_string(occInstance) + "_temp"); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 999 | } |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 1000 | else if (fruTypeValue == processorIoRing) |
| 1001 | { |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 1002 | sensorPath.append( |
| 1003 | "proc" + std::to_string(occInstance) + "_ioring_temp"); |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 1004 | dvfsTempPath = std::string{OCC_SENSORS_ROOT} + "/temperature/proc" + |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame] | 1005 | std::to_string(occInstance) + "_ioring_dvfs_temp"; |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 1006 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1007 | else |
| 1008 | { |
Matt Spinler | 14d1402 | 2021-08-25 15:38:29 -0500 | [diff] [blame] | 1009 | uint16_t type = (labelValue & 0xFF000000) >> 24; |
| 1010 | uint16_t instanceID = labelValue & 0x0000FFFF; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1011 | |
| 1012 | if (type == OCC_DIMM_TEMP_SENSOR_TYPE) |
| 1013 | { |
Matt Spinler | 8b8abee | 2021-08-25 15:18:21 -0500 | [diff] [blame] | 1014 | if (fruTypeValue == fruTypeNotAvailable) |
| 1015 | { |
| 1016 | // Not all DIMM related temps are available to read |
| 1017 | // (no _input file in this case) |
| 1018 | continue; |
| 1019 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1020 | auto iter = dimmTempSensorName.find(fruTypeValue); |
| 1021 | if (iter == dimmTempSensorName.end()) |
| 1022 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1023 | lg2::error( |
| 1024 | "readTempSensors: Fru type error! fruTypeValue = {FRU}) ", |
| 1025 | "FRU", fruTypeValue); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1026 | continue; |
| 1027 | } |
| 1028 | |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 1029 | sensorPath.append( |
| 1030 | "dimm" + std::to_string(instanceID) + iter->second); |
Matt Spinler | ad8f452 | 2023-10-25 11:14:46 -0500 | [diff] [blame] | 1031 | |
| 1032 | dvfsTempPath = std::string{OCC_SENSORS_ROOT} + "/temperature/" + |
| 1033 | dimmDVFSSensorName.at(fruTypeValue); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1034 | } |
| 1035 | else if (type == OCC_CPU_TEMP_SENSOR_TYPE) |
| 1036 | { |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 1037 | if (fruTypeValue == processorCore) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1038 | { |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 1039 | // The OCC reports small core temps, of which there are |
| 1040 | // two per big core. All current P10 systems are in big |
| 1041 | // core mode, so use a big core name. |
| 1042 | uint16_t coreNum = instanceID / 2; |
| 1043 | uint16_t tempNum = instanceID % 2; |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame] | 1044 | sensorPath.append("proc" + std::to_string(occInstance) + |
| 1045 | "_core" + std::to_string(coreNum) + "_" + |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 1046 | std::to_string(tempNum) + "_temp"); |
| 1047 | |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame] | 1048 | dvfsTempPath = |
| 1049 | std::string{OCC_SENSORS_ROOT} + "/temperature/proc" + |
| 1050 | std::to_string(occInstance) + "_core_dvfs_temp"; |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 1051 | } |
| 1052 | else |
| 1053 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1054 | continue; |
| 1055 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1056 | } |
| 1057 | else |
| 1058 | { |
| 1059 | continue; |
| 1060 | } |
| 1061 | } |
| 1062 | |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 1063 | // The dvfs temp file only needs to be read once per chip per type. |
| 1064 | if (!dvfsTempPath.empty() && |
| 1065 | !dbus::OccDBusSensors::getOccDBus().hasDvfsTemp(dvfsTempPath)) |
| 1066 | { |
| 1067 | try |
| 1068 | { |
| 1069 | auto dvfsValue = readFile<double>(filePathString + maxSuffix); |
| 1070 | |
| 1071 | dbus::OccDBusSensors::getOccDBus().setDvfsTemp( |
| 1072 | dvfsTempPath, dvfsValue * std::pow(10, -3)); |
| 1073 | } |
| 1074 | catch (const std::system_error& e) |
| 1075 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1076 | lg2::debug( |
| 1077 | "readTempSensors: Failed reading {PATH}, errno = {ERROR}", |
| 1078 | "PATH", filePathString + maxSuffix, "ERROR", |
| 1079 | e.code().value()); |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1083 | uint32_t faultValue{0}; |
| 1084 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1085 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1086 | faultValue = readFile<uint32_t>(filePathString + faultSuffix); |
| 1087 | } |
| 1088 | catch (const std::system_error& e) |
| 1089 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1090 | lg2::debug( |
| 1091 | "readTempSensors: Failed reading {PATH}, errno = {ERROR}", |
| 1092 | "PATH", filePathString + faultSuffix, "ERROR", |
| 1093 | e.code().value()); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1094 | continue; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1095 | } |
| 1096 | |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame] | 1097 | double tempValue{0}; |
| 1098 | // NOTE: if OCC sends back 0xFF, kernal sets this fault value to 1. |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1099 | if (faultValue != 0) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1100 | { |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame] | 1101 | tempValue = std::numeric_limits<double>::quiet_NaN(); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1102 | } |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame] | 1103 | else |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1104 | { |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame] | 1105 | // Read the temperature |
| 1106 | try |
Sheldon Bailey | cd0940b | 2022-04-26 14:24:05 -0500 | [diff] [blame] | 1107 | { |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame] | 1108 | tempValue = readFile<double>(filePathString + inputSuffix); |
Sheldon Bailey | cd0940b | 2022-04-26 14:24:05 -0500 | [diff] [blame] | 1109 | } |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame] | 1110 | catch (const std::system_error& e) |
Sheldon Bailey | cd0940b | 2022-04-26 14:24:05 -0500 | [diff] [blame] | 1111 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1112 | lg2::debug( |
| 1113 | "readTempSensors: Failed reading {PATH}, errno = {ERROR}", |
| 1114 | "PATH", filePathString + inputSuffix, "ERROR", |
| 1115 | e.code().value()); |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame] | 1116 | |
| 1117 | // if errno == EAGAIN(Resource temporarily unavailable) then set |
| 1118 | // temp to 0, to avoid using old temp, and affecting FAN |
| 1119 | // Control. |
| 1120 | if (e.code().value() == EAGAIN) |
| 1121 | { |
| 1122 | tempValue = 0; |
| 1123 | } |
| 1124 | // else the errno would be something like |
| 1125 | // EBADF(Bad file descriptor) |
| 1126 | // or ENOENT(No such file or directory) |
| 1127 | else |
| 1128 | { |
| 1129 | continue; |
| 1130 | } |
Sheldon Bailey | cd0940b | 2022-04-26 14:24:05 -0500 | [diff] [blame] | 1131 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1132 | } |
| 1133 | |
Matt Spinler | 818cc8d | 2023-10-23 11:43:39 -0500 | [diff] [blame] | 1134 | // If this object path already has a value, only overwite |
| 1135 | // it if the previous one was an NaN or a smaller value. |
| 1136 | auto existing = sensorData.find(sensorPath); |
| 1137 | if (existing != sensorData.end()) |
| 1138 | { |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame] | 1139 | // Multiple sensors found for this FRU type |
| 1140 | if ((std::isnan(existing->second) && (tempValue == 0)) || |
| 1141 | ((existing->second == 0) && std::isnan(tempValue))) |
| 1142 | { |
| 1143 | // One of the redundant sensors has failed (0xFF/nan), and the |
| 1144 | // other sensor has no reading (0), so set the FRU to NaN to |
| 1145 | // force fan increase |
| 1146 | tempValue = std::numeric_limits<double>::quiet_NaN(); |
| 1147 | existing->second = tempValue; |
| 1148 | } |
Matt Spinler | 818cc8d | 2023-10-23 11:43:39 -0500 | [diff] [blame] | 1149 | if (std::isnan(existing->second) || (tempValue > existing->second)) |
| 1150 | { |
| 1151 | existing->second = tempValue; |
| 1152 | } |
| 1153 | } |
| 1154 | else |
| 1155 | { |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame] | 1156 | // First sensor for this FRU type |
Matt Spinler | 818cc8d | 2023-10-23 11:43:39 -0500 | [diff] [blame] | 1157 | sensorData[sensorPath] = tempValue; |
| 1158 | } |
| 1159 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1160 | |
Matt Spinler | 818cc8d | 2023-10-23 11:43:39 -0500 | [diff] [blame] | 1161 | // Now publish the values on D-Bus. |
| 1162 | for (const auto& [objectPath, value] : sensorData) |
| 1163 | { |
| 1164 | dbus::OccDBusSensors::getOccDBus().setValue(objectPath, |
| 1165 | value * std::pow(10, -3)); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1166 | |
Matt Spinler | 818cc8d | 2023-10-23 11:43:39 -0500 | [diff] [blame] | 1167 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus( |
| 1168 | objectPath, !std::isnan(value)); |
| 1169 | |
| 1170 | if (existingSensors.find(objectPath) == existingSensors.end()) |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 1171 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1172 | dbus::OccDBusSensors::getOccDBus().setChassisAssociation( |
Chris Cain | 3523cc0 | 2024-10-30 17:19:09 -0500 | [diff] [blame] | 1173 | objectPath, {"all_sensors"}); |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 1174 | } |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame] | 1175 | existingSensors[objectPath] = occInstance; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1176 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1177 | } |
| 1178 | |
Patrick Williams | 2d6ec90 | 2025-02-01 08:22:13 -0500 | [diff] [blame] | 1179 | std::optional<std::string> Manager::getPowerLabelFunctionID( |
| 1180 | const std::string& value) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1181 | { |
| 1182 | // If the value is "system", then the FunctionID is "system". |
| 1183 | if (value == "system") |
| 1184 | { |
| 1185 | return value; |
| 1186 | } |
| 1187 | |
| 1188 | // If the value is not "system", then the label value have 3 numbers, of |
| 1189 | // which we only care about the middle one: |
| 1190 | // <sensor id>_<function id>_<apss channel> |
| 1191 | // eg: The value is "0_10_5" , then the FunctionID is "10". |
| 1192 | if (value.find("_") == std::string::npos) |
| 1193 | { |
| 1194 | return std::nullopt; |
| 1195 | } |
| 1196 | |
| 1197 | auto powerLabelValue = value.substr((value.find("_") + 1)); |
| 1198 | |
| 1199 | if (powerLabelValue.find("_") == std::string::npos) |
| 1200 | { |
| 1201 | return std::nullopt; |
| 1202 | } |
| 1203 | |
| 1204 | return powerLabelValue.substr(0, powerLabelValue.find("_")); |
| 1205 | } |
| 1206 | |
| 1207 | void Manager::readPowerSensors(const fs::path& path, uint32_t id) |
| 1208 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1209 | std::regex expr{"power\\d+_label$"}; // Example: power5_label |
| 1210 | for (auto& file : fs::directory_iterator(path)) |
| 1211 | { |
| 1212 | if (!std::regex_search(file.path().string(), expr)) |
| 1213 | { |
| 1214 | continue; |
| 1215 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1216 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1217 | std::string labelValue; |
| 1218 | try |
| 1219 | { |
| 1220 | labelValue = readFile<std::string>(file.path()); |
| 1221 | } |
| 1222 | catch (const std::system_error& e) |
| 1223 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1224 | lg2::debug( |
| 1225 | "readPowerSensors: Failed reading {PATH}, errno = {ERROR}", |
| 1226 | "PATH", file.path().string(), "ERROR", e.code().value()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1227 | continue; |
| 1228 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1229 | |
| 1230 | auto functionID = getPowerLabelFunctionID(labelValue); |
| 1231 | if (functionID == std::nullopt) |
| 1232 | { |
| 1233 | continue; |
| 1234 | } |
| 1235 | |
| 1236 | const std::string& tempLabel = "label"; |
| 1237 | const std::string filePathString = file.path().string().substr( |
| 1238 | 0, file.path().string().length() - tempLabel.length()); |
| 1239 | |
| 1240 | std::string sensorPath = OCC_SENSORS_ROOT + std::string("/power/"); |
| 1241 | |
| 1242 | auto iter = powerSensorName.find(*functionID); |
| 1243 | if (iter == powerSensorName.end()) |
| 1244 | { |
| 1245 | continue; |
| 1246 | } |
| 1247 | sensorPath.append(iter->second); |
| 1248 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1249 | double tempValue{0}; |
| 1250 | |
| 1251 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1252 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1253 | tempValue = readFile<double>(filePathString + inputSuffix); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1254 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1255 | catch (const std::system_error& e) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1256 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1257 | lg2::debug( |
| 1258 | "readPowerSensors: Failed reading {PATH}, errno = {ERROR}", |
| 1259 | "PATH", filePathString + inputSuffix, "ERROR", |
| 1260 | e.code().value()); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1261 | continue; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1262 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1263 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1264 | dbus::OccDBusSensors::getOccDBus().setUnit( |
Chris Cain | d84a833 | 2022-01-13 08:58:45 -0600 | [diff] [blame] | 1265 | sensorPath, "xyz.openbmc_project.Sensor.Value.Unit.Watts"); |
| 1266 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1267 | dbus::OccDBusSensors::getOccDBus().setValue( |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1268 | sensorPath, tempValue * std::pow(10, -3) * std::pow(10, -3)); |
| 1269 | |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 1270 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus( |
| 1271 | sensorPath, true); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1272 | |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 1273 | if (existingSensors.find(sensorPath) == existingSensors.end()) |
| 1274 | { |
Chris Cain | 3523cc0 | 2024-10-30 17:19:09 -0500 | [diff] [blame] | 1275 | std::vector<std::string> fTypeList = {"all_sensors"}; |
| 1276 | if (iter->second == "total_power") |
| 1277 | { |
Chris Cain | ff0ce40 | 2025-01-17 10:54:55 -0600 | [diff] [blame] | 1278 | // Set sensor purpose as TotalPower |
| 1279 | dbus::OccDBusSensors::getOccDBus().setPurpose( |
| 1280 | sensorPath, |
| 1281 | "xyz.openbmc_project.Sensor.Purpose.SensorPurpose.TotalPower"); |
Chris Cain | 3523cc0 | 2024-10-30 17:19:09 -0500 | [diff] [blame] | 1282 | } |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1283 | dbus::OccDBusSensors::getOccDBus().setChassisAssociation( |
Chris Cain | 3523cc0 | 2024-10-30 17:19:09 -0500 | [diff] [blame] | 1284 | sensorPath, fTypeList); |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 1285 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1286 | existingSensors[sensorPath] = id; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1287 | } |
| 1288 | return; |
| 1289 | } |
| 1290 | |
Sheldon Bailey | d2b044f | 2025-02-12 11:50:24 -0600 | [diff] [blame] | 1291 | void Manager::readExtnSensors(const fs::path& path, uint32_t id) |
| 1292 | { |
| 1293 | std::regex expr{"extn\\d+_label$"}; // Example: extn5_label |
| 1294 | for (auto& file : fs::directory_iterator(path)) |
| 1295 | { |
| 1296 | if (!std::regex_search(file.path().string(), expr)) |
| 1297 | { |
| 1298 | continue; |
| 1299 | } |
| 1300 | |
| 1301 | // Read in Label value of the sensor from file. |
| 1302 | std::string labelValue; |
| 1303 | try |
| 1304 | { |
| 1305 | labelValue = readFile<std::string>(file.path()); |
| 1306 | } |
| 1307 | catch (const std::system_error& e) |
| 1308 | { |
| 1309 | lg2::debug( |
| 1310 | "readExtnSensors:label Failed reading {PATH}, errno = {ERROR}", |
| 1311 | "PATH", file.path().string(), "ERROR", e.code().value()); |
| 1312 | continue; |
| 1313 | } |
| 1314 | const std::string& tempLabel = "label"; |
| 1315 | const std::string filePathString = file.path().string().substr( |
| 1316 | 0, file.path().string().length() - tempLabel.length()); |
| 1317 | |
| 1318 | std::string sensorPath = OCC_SENSORS_ROOT + std::string("/power/"); |
| 1319 | |
| 1320 | // Labels of EXTN sections from OCC interface Document |
| 1321 | // have different formats. |
| 1322 | // 0x464d494e : FMIN 0x46444953 : FDIS |
| 1323 | // 0x46424153 : FBAS 0x46555400 : FUT |
| 1324 | // 0x464d4158 : FMAX 0x434c4950 : CLIP |
| 1325 | // 0x4d4f4445 : MODE 0x574f4643 : WOFC |
| 1326 | // 0x574f4649 : WOFI 0x5057524d : PWRM |
| 1327 | // 0x50575250 : PWRP 0x45525248 : ERRH |
| 1328 | // Label indicating byte 5 and 6 is the current (mem,proc) power in |
| 1329 | // Watts. |
| 1330 | if ((labelValue == EXTN_LABEL_PWRM_MEMORY_POWER) || |
| 1331 | (labelValue == EXTN_LABEL_PWRP_PROCESSOR_POWER)) |
| 1332 | { |
| 1333 | // Build the dbus String for this chiplet power asset. |
| 1334 | if (labelValue == EXTN_LABEL_PWRP_PROCESSOR_POWER) |
| 1335 | { |
| 1336 | labelValue = "_power"; |
| 1337 | } |
| 1338 | else // else EXTN_LABEL_PWRM_MEMORY_POWER |
| 1339 | { |
| 1340 | labelValue = "_mem_power"; |
| 1341 | } |
| 1342 | sensorPath.append("chiplet" + std::to_string(id) + labelValue); |
| 1343 | |
| 1344 | // Read in data value of the sensor from file. |
| 1345 | // Read in as string due to different format of data in sensors. |
| 1346 | std::string extnValue; |
| 1347 | try |
| 1348 | { |
| 1349 | extnValue = readFile<std::string>(filePathString + inputSuffix); |
| 1350 | } |
| 1351 | catch (const std::system_error& e) |
| 1352 | { |
| 1353 | lg2::debug( |
| 1354 | "readExtnSensors:value Failed reading {PATH}, errno = {ERROR}", |
| 1355 | "PATH", filePathString + inputSuffix, "ERROR", |
| 1356 | e.code().value()); |
| 1357 | continue; |
| 1358 | } |
| 1359 | |
| 1360 | // For Power field, Convert last 4 bytes of hex string into number |
| 1361 | // value. |
| 1362 | std::stringstream ssData; |
| 1363 | ssData << std::hex << extnValue.substr(extnValue.length() - 4); |
| 1364 | uint16_t MyHexNumber; |
| 1365 | ssData >> MyHexNumber; |
| 1366 | |
| 1367 | // Convert output/DC power to input/AC power in Watts (round up) |
| 1368 | MyHexNumber = |
| 1369 | std::round(((MyHexNumber / (PS_DERATING_FACTOR / 100.0)))); |
| 1370 | |
Sheldon Bailey | d2b044f | 2025-02-12 11:50:24 -0600 | [diff] [blame] | 1371 | dbus::OccDBusSensors::getOccDBus().setUnit( |
| 1372 | sensorPath, "xyz.openbmc_project.Sensor.Value.Unit.Watts"); |
| 1373 | |
| 1374 | dbus::OccDBusSensors::getOccDBus().setValue(sensorPath, |
| 1375 | MyHexNumber); |
| 1376 | |
| 1377 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus( |
| 1378 | sensorPath, true); |
| 1379 | |
| 1380 | if (existingSensors.find(sensorPath) == existingSensors.end()) |
| 1381 | { |
| 1382 | dbus::OccDBusSensors::getOccDBus().setChassisAssociation( |
| 1383 | sensorPath, {"all_sensors"}); |
| 1384 | } |
| 1385 | |
Sheldon Bailey | b89d619 | 2025-03-05 09:33:19 -0600 | [diff] [blame] | 1386 | existingSensors[sensorPath] = id; |
Sheldon Bailey | d2b044f | 2025-02-12 11:50:24 -0600 | [diff] [blame] | 1387 | } // End Extended Power Sensors. |
Sheldon Bailey | d2b044f | 2025-02-12 11:50:24 -0600 | [diff] [blame] | 1388 | } // End For loop on files for Extended Sensors. |
| 1389 | return; |
| 1390 | } |
| 1391 | |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 1392 | void Manager::setSensorValueToNaN(uint32_t id) const |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1393 | { |
| 1394 | for (const auto& [sensorPath, occId] : existingSensors) |
| 1395 | { |
| 1396 | if (occId == id) |
| 1397 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1398 | dbus::OccDBusSensors::getOccDBus().setValue( |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1399 | sensorPath, std::numeric_limits<double>::quiet_NaN()); |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 1400 | |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 1401 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus( |
| 1402 | sensorPath, true); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1403 | } |
| 1404 | } |
| 1405 | return; |
| 1406 | } |
| 1407 | |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 1408 | void Manager::setSensorValueToNonFunctional(uint32_t id) const |
| 1409 | { |
| 1410 | for (const auto& [sensorPath, occId] : existingSensors) |
| 1411 | { |
| 1412 | if (occId == id) |
| 1413 | { |
| 1414 | dbus::OccDBusSensors::getOccDBus().setValue( |
| 1415 | sensorPath, std::numeric_limits<double>::quiet_NaN()); |
| 1416 | |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 1417 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus( |
| 1418 | sensorPath, false); |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 1419 | } |
| 1420 | } |
| 1421 | return; |
| 1422 | } |
| 1423 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1424 | void Manager::getSensorValues(std::unique_ptr<Status>& occ) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1425 | { |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 1426 | static bool tracedError[8] = {0}; |
| 1427 | const fs::path sensorPath = occ->getHwmonPath(); |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1428 | const uint32_t id = occ->getOccInstanceID(); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1429 | |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 1430 | if (fs::exists(sensorPath)) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1431 | { |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 1432 | // Read temperature sensors |
| 1433 | readTempSensors(sensorPath, id); |
Sheldon Bailey | b89d619 | 2025-03-05 09:33:19 -0600 | [diff] [blame] | 1434 | // Read Extended sensors |
Sheldon Bailey | d2b044f | 2025-02-12 11:50:24 -0600 | [diff] [blame] | 1435 | readExtnSensors(sensorPath, id); |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 1436 | |
| 1437 | if (occ->isMasterOcc()) |
| 1438 | { |
| 1439 | // Read power sensors |
| 1440 | readPowerSensors(sensorPath, id); |
| 1441 | } |
| 1442 | tracedError[id] = false; |
| 1443 | } |
| 1444 | else |
| 1445 | { |
| 1446 | if (!tracedError[id]) |
| 1447 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1448 | lg2::error( |
| 1449 | "Manager::getSensorValues: OCC{INST} sensor path missing: {PATH}", |
| 1450 | "INST", id, "PATH", sensorPath); |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 1451 | tracedError[id] = true; |
| 1452 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | return; |
| 1456 | } |
| 1457 | #endif |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1458 | |
| 1459 | // Read the altitude from DBus |
| 1460 | void Manager::readAltitude() |
| 1461 | { |
| 1462 | static bool traceAltitudeErr = true; |
| 1463 | |
| 1464 | utils::PropertyValue altitudeProperty{}; |
| 1465 | try |
| 1466 | { |
| 1467 | altitudeProperty = utils::getProperty(ALTITUDE_PATH, ALTITUDE_INTERFACE, |
| 1468 | ALTITUDE_PROP); |
| 1469 | auto sensorVal = std::get<double>(altitudeProperty); |
| 1470 | if (sensorVal < 0xFFFF) |
| 1471 | { |
| 1472 | if (sensorVal < 0) |
| 1473 | { |
| 1474 | altitude = 0; |
| 1475 | } |
| 1476 | else |
| 1477 | { |
| 1478 | // Round to nearest meter |
| 1479 | altitude = uint16_t(sensorVal + 0.5); |
| 1480 | } |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1481 | lg2::debug("readAltitude: sensor={VALUE} ({ALT}m)", "VALUE", |
| 1482 | sensorVal, "ALT", altitude); |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1483 | traceAltitudeErr = true; |
| 1484 | } |
| 1485 | else |
| 1486 | { |
| 1487 | if (traceAltitudeErr) |
| 1488 | { |
| 1489 | traceAltitudeErr = false; |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1490 | lg2::debug("Invalid altitude value: {ALT}", "ALT", sensorVal); |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1491 | } |
| 1492 | } |
| 1493 | } |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 1494 | catch (const sdbusplus::exception_t& e) |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1495 | { |
| 1496 | if (traceAltitudeErr) |
| 1497 | { |
| 1498 | traceAltitudeErr = false; |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1499 | lg2::info("Unable to read Altitude: {ERROR}", "ERROR", e.what()); |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1500 | } |
| 1501 | altitude = 0xFFFF; // not available |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | // Callback function when ambient temperature changes |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 1506 | void Manager::ambientCallback(sdbusplus::message_t& msg) |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1507 | { |
| 1508 | double currentTemp = 0; |
| 1509 | uint8_t truncatedTemp = 0xFF; |
| 1510 | std::string msgSensor; |
| 1511 | std::map<std::string, std::variant<double>> msgData; |
| 1512 | msg.read(msgSensor, msgData); |
| 1513 | |
| 1514 | auto valPropMap = msgData.find(AMBIENT_PROP); |
| 1515 | if (valPropMap == msgData.end()) |
| 1516 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1517 | lg2::debug("ambientCallback: Unknown ambient property changed"); |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1518 | return; |
| 1519 | } |
| 1520 | currentTemp = std::get<double>(valPropMap->second); |
| 1521 | if (std::isnan(currentTemp)) |
| 1522 | { |
| 1523 | truncatedTemp = 0xFF; |
| 1524 | } |
| 1525 | else |
| 1526 | { |
| 1527 | if (currentTemp < 0) |
| 1528 | { |
| 1529 | truncatedTemp = 0; |
| 1530 | } |
| 1531 | else |
| 1532 | { |
| 1533 | // Round to nearest degree C |
| 1534 | truncatedTemp = uint8_t(currentTemp + 0.5); |
| 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | // If ambient changes, notify OCCs |
| 1539 | if (truncatedTemp != ambient) |
| 1540 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1541 | lg2::debug("ambientCallback: Ambient change from {OLD} to {NEW}C", |
| 1542 | "OLD", ambient, "NEW", currentTemp); |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1543 | |
| 1544 | ambient = truncatedTemp; |
| 1545 | if (altitude == 0xFFFF) |
| 1546 | { |
| 1547 | // No altitude yet, try reading again |
| 1548 | readAltitude(); |
| 1549 | } |
| 1550 | |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1551 | lg2::debug("ambientCallback: Ambient: {TEMP}C, altitude: {ALT}m", |
| 1552 | "TEMP", ambient, "ALT", altitude); |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1553 | #ifdef POWER10 |
| 1554 | // Send ambient and altitude to all OCCs |
| 1555 | for (auto& obj : statusObjects) |
| 1556 | { |
| 1557 | if (obj->occActive()) |
| 1558 | { |
| 1559 | obj->sendAmbient(ambient, altitude); |
| 1560 | } |
| 1561 | } |
| 1562 | #endif // POWER10 |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | // return the current ambient and altitude readings |
| 1567 | void Manager::getAmbientData(bool& ambientValid, uint8_t& ambientTemp, |
| 1568 | uint16_t& altitudeValue) const |
| 1569 | { |
| 1570 | ambientValid = true; |
| 1571 | ambientTemp = ambient; |
| 1572 | altitudeValue = altitude; |
| 1573 | |
| 1574 | if (ambient == 0xFF) |
| 1575 | { |
| 1576 | ambientValid = false; |
| 1577 | } |
| 1578 | } |
| 1579 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1580 | #ifdef POWER10 |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 1581 | // Called when waitForAllOccsTimer expires |
| 1582 | // After the first OCC goes active, this timer will be started (60 seconds) |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1583 | void Manager::occsNotAllRunning() |
| 1584 | { |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 1585 | if (resetInProgress) |
| 1586 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1587 | lg2::warning( |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 1588 | "occsNotAllRunning: Ignoring waitForAllOccsTimer because reset is in progress"); |
| 1589 | return; |
| 1590 | } |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1591 | if (activeCount != statusObjects.size()) |
| 1592 | { |
| 1593 | // Not all OCCs went active |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1594 | lg2::warning( |
| 1595 | "occsNotAllRunning: Active OCC count ({COUNT}) does not match expected count ({EXP})", |
| 1596 | "COUNT", activeCount, "EXP", statusObjects.size()); |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 1597 | // Procs may be garded, so may be expected |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1598 | } |
| 1599 | |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 1600 | if (resetRequired) |
| 1601 | { |
| 1602 | initiateOccRequest(resetInstance); |
| 1603 | |
| 1604 | if (!waitForAllOccsTimer->isEnabled()) |
| 1605 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1606 | lg2::warning("occsNotAllRunning: Restarting waitForAllOccTimer"); |
Chris Cain | f0295f5 | 2024-09-12 15:41:14 -0500 | [diff] [blame] | 1607 | // restart occ wait timer |
| 1608 | waitForAllOccsTimer->restartOnce(60s); |
| 1609 | } |
| 1610 | } |
| 1611 | else |
| 1612 | { |
| 1613 | validateOccMaster(); |
| 1614 | } |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1615 | } |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 1616 | |
| 1617 | #ifdef PLDM |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 1618 | // Called when throttlePldmTraceTimer expires. |
Chris Cain | a19bd42 | 2024-05-24 16:39:01 -0500 | [diff] [blame] | 1619 | // If this timer expires, that indicates there are no OCC active sensor PDRs |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 1620 | // found which will trigger pldm traces to be throttled. |
| 1621 | // The second time this timer expires, a PEL will get created. |
| 1622 | void Manager::throttlePldmTraceExpired() |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 1623 | { |
Chris Cain | 7651c06 | 2024-05-02 14:14:06 -0500 | [diff] [blame] | 1624 | if (utils::isHostRunning()) |
| 1625 | { |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 1626 | if (!onPldmTimeoutCreatePel) |
| 1627 | { |
| 1628 | // Throttle traces |
| 1629 | pldmHandle->setTraceThrottle(true); |
| 1630 | // Restart timer to log a PEL when timer expires |
| 1631 | onPldmTimeoutCreatePel = true; |
| 1632 | throttlePldmTraceTimer->restartOnce(40min); |
| 1633 | } |
| 1634 | else |
| 1635 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1636 | lg2::error( |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 1637 | "throttlePldmTraceExpired(): OCC active sensors still not available!"); |
| 1638 | // Create PEL |
| 1639 | createPldmSensorPEL(); |
| 1640 | } |
Chris Cain | 7651c06 | 2024-05-02 14:14:06 -0500 | [diff] [blame] | 1641 | } |
| 1642 | else |
| 1643 | { |
| 1644 | // Make sure traces are not throttled |
| 1645 | pldmHandle->setTraceThrottle(false); |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1646 | lg2::info( |
Chris Cain | c33171b | 2024-05-24 16:14:50 -0500 | [diff] [blame] | 1647 | "throttlePldmTraceExpired(): host it not running ignoring sensor timer"); |
Chris Cain | 7651c06 | 2024-05-02 14:14:06 -0500 | [diff] [blame] | 1648 | } |
Chris Cain | 4b82f3e | 2024-04-22 14:44:29 -0500 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | void Manager::createPldmSensorPEL() |
| 1652 | { |
| 1653 | Error::Descriptor d = Error::Descriptor(MISSING_OCC_SENSORS_PATH); |
| 1654 | std::map<std::string, std::string> additionalData; |
| 1655 | |
| 1656 | additionalData.emplace("_PID", std::to_string(getpid())); |
| 1657 | |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1658 | lg2::info( |
| 1659 | "createPldmSensorPEL(): Unable to find PLDM sensors for the OCCs"); |
Chris Cain | 4b82f3e | 2024-04-22 14:44:29 -0500 | [diff] [blame] | 1660 | |
| 1661 | auto& bus = utils::getBus(); |
| 1662 | |
| 1663 | try |
| 1664 | { |
| 1665 | FFDCFiles ffdc; |
| 1666 | // Add occ-control journal traces to PEL FFDC |
| 1667 | auto occJournalFile = |
| 1668 | FFDC::addJournalEntries(ffdc, "openpower-occ-control", 40); |
| 1669 | |
| 1670 | static constexpr auto loggingObjectPath = |
| 1671 | "/xyz/openbmc_project/logging"; |
| 1672 | static constexpr auto opLoggingInterface = "org.open_power.Logging.PEL"; |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 1673 | std::string service = |
| 1674 | utils::getService(loggingObjectPath, opLoggingInterface); |
| 1675 | auto method = |
| 1676 | bus.new_method_call(service.c_str(), loggingObjectPath, |
| 1677 | opLoggingInterface, "CreatePELWithFFDCFiles"); |
Chris Cain | 4b82f3e | 2024-04-22 14:44:29 -0500 | [diff] [blame] | 1678 | |
Chris Cain | 1c3349e | 2024-04-24 14:14:11 -0500 | [diff] [blame] | 1679 | // Set level to Warning (Predictive). |
Chris Cain | 4b82f3e | 2024-04-22 14:44:29 -0500 | [diff] [blame] | 1680 | auto level = |
| 1681 | sdbusplus::xyz::openbmc_project::Logging::server::convertForMessage( |
| 1682 | sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level:: |
Chris Cain | 1c3349e | 2024-04-24 14:14:11 -0500 | [diff] [blame] | 1683 | Warning); |
Chris Cain | 4b82f3e | 2024-04-22 14:44:29 -0500 | [diff] [blame] | 1684 | |
| 1685 | method.append(d.path, level, additionalData, ffdc); |
| 1686 | bus.call(method); |
| 1687 | } |
| 1688 | catch (const sdbusplus::exception_t& e) |
| 1689 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1690 | lg2::error("Failed to create MISSING_OCC_SENSORS PEL: {ERROR}", "ERROR", |
| 1691 | e.what()); |
Chris Cain | 4b82f3e | 2024-04-22 14:44:29 -0500 | [diff] [blame] | 1692 | } |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 1693 | } |
| 1694 | #endif // PLDM |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1695 | #endif // POWER10 |
| 1696 | |
| 1697 | // Verify single master OCC and start presence monitor |
| 1698 | void Manager::validateOccMaster() |
| 1699 | { |
| 1700 | int masterInstance = -1; |
| 1701 | for (auto& obj : statusObjects) |
| 1702 | { |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1703 | auto instance = obj->getOccInstanceID(); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1704 | #ifdef POWER10 |
| 1705 | if (!obj->occActive()) |
| 1706 | { |
| 1707 | if (utils::isHostRunning()) |
| 1708 | { |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1709 | // Check if sensor was queued while waiting for discovery |
| 1710 | auto match = queuedActiveState.find(instance); |
| 1711 | if (match != queuedActiveState.end()) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1712 | { |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 1713 | queuedActiveState.erase(match); |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1714 | lg2::info("validateOccMaster: OCC{INST} is ACTIVE (queued)", |
| 1715 | "INST", instance); |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1716 | obj->occActive(true); |
| 1717 | } |
| 1718 | else |
| 1719 | { |
| 1720 | // OCC does not appear to be active yet, check active sensor |
Patrick Williams | fb0a5c3 | 2024-02-28 11:27:00 -0600 | [diff] [blame] | 1721 | #ifdef PLDM |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1722 | pldmHandle->checkActiveSensor(instance); |
Patrick Williams | fb0a5c3 | 2024-02-28 11:27:00 -0600 | [diff] [blame] | 1723 | #endif |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1724 | if (obj->occActive()) |
| 1725 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1726 | lg2::info( |
| 1727 | "validateOccMaster: OCC{INST} is ACTIVE after reading sensor", |
| 1728 | "INST", instance); |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1729 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1730 | } |
| 1731 | } |
| 1732 | else |
| 1733 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1734 | lg2::warning( |
| 1735 | "validateOccMaster: HOST is not running (OCC{INST})", |
| 1736 | "INST", instance); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1737 | return; |
| 1738 | } |
| 1739 | } |
| 1740 | #endif // POWER10 |
| 1741 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1742 | if (obj->isMasterOcc()) |
| 1743 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1744 | obj->addPresenceWatchMaster(); |
| 1745 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1746 | if (masterInstance == -1) |
| 1747 | { |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1748 | masterInstance = instance; |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1749 | } |
| 1750 | else |
| 1751 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1752 | lg2::error( |
| 1753 | "validateOccMaster: Multiple OCC masters! ({MAST1} and {MAST2})", |
| 1754 | "MAST1", masterInstance, "MAST2", instance); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1755 | // request reset |
Eddie James | 9789e71 | 2022-05-25 15:43:40 -0500 | [diff] [blame] | 1756 | obj->deviceError(Error::Descriptor(PRESENCE_ERROR_PATH)); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1757 | } |
| 1758 | } |
| 1759 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1760 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1761 | if (masterInstance < 0) |
| 1762 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1763 | lg2::error("validateOccMaster: Master OCC not found! (of {NUM} OCCs)", |
| 1764 | "NUM", statusObjects.size()); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1765 | // request reset |
Eddie James | 9789e71 | 2022-05-25 15:43:40 -0500 | [diff] [blame] | 1766 | statusObjects.front()->deviceError( |
| 1767 | Error::Descriptor(PRESENCE_ERROR_PATH)); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1768 | } |
| 1769 | else |
| 1770 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 1771 | lg2::info("validateOccMaster: OCC{INST} is master of {COUNT} OCCs", |
| 1772 | "INST", masterInstance, "COUNT", activeCount); |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 1773 | #ifdef POWER10 |
| 1774 | pmode->updateDbusSafeMode(false); |
| 1775 | #endif |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 1779 | void Manager::updatePcapBounds() const |
| 1780 | { |
| 1781 | if (pcap) |
| 1782 | { |
| 1783 | pcap->updatePcapBounds(); |
| 1784 | } |
| 1785 | } |
| 1786 | |
Chris Cain | c488bac | 2025-03-17 09:01:15 -0500 | [diff] [blame^] | 1787 | // Clean up any variables since the OCC is no longer running. |
| 1788 | // Called when pldm receives an event indicating host is powered off. |
| 1789 | void Manager::hostPoweredOff() |
| 1790 | { |
| 1791 | if (resetRequired) |
| 1792 | { |
| 1793 | lg2::info("hostPoweredOff: Clearing resetRequired for OCC{INST}", |
| 1794 | "INST", resetInstance); |
| 1795 | resetRequired = false; |
| 1796 | } |
| 1797 | if (resetInProgress) |
| 1798 | { |
| 1799 | lg2::info("hostPoweredOff: Clearing resetInProgress for OCC{INST}", |
| 1800 | "INST", resetInstance); |
| 1801 | resetInProgress = false; |
| 1802 | } |
| 1803 | resetInstance = 255; |
| 1804 | } |
| 1805 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 1806 | } // namespace occ |
| 1807 | } // namespace open_power |