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" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 7 | #include "utils.hpp" |
| 8 | |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 9 | #include <phosphor-logging/elog-errors.hpp> |
| 10 | #include <phosphor-logging/log.hpp> |
| 11 | #include <xyz/openbmc_project/Common/error.hpp> |
| 12 | |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 13 | #include <chrono> |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 14 | #include <cmath> |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 15 | #include <filesystem> |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 16 | #include <fstream> |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 17 | #include <regex> |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 18 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 19 | namespace open_power |
| 20 | { |
| 21 | namespace occ |
| 22 | { |
| 23 | |
Matt Spinler | 8b8abee | 2021-08-25 15:18:21 -0500 | [diff] [blame] | 24 | constexpr uint32_t fruTypeNotAvailable = 0xFF; |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 25 | constexpr auto fruTypeSuffix = "fru_type"; |
| 26 | constexpr auto faultSuffix = "fault"; |
| 27 | constexpr auto inputSuffix = "input"; |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 28 | constexpr auto maxSuffix = "max"; |
Matt Spinler | 8b8abee | 2021-08-25 15:18:21 -0500 | [diff] [blame] | 29 | |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 30 | const auto HOST_ON_FILE = "/run/openbmc/host@0-on"; |
| 31 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 32 | using namespace phosphor::logging; |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 33 | using namespace std::literals::chrono_literals; |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 34 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 35 | template <typename T> |
| 36 | T readFile(const std::string& path) |
| 37 | { |
| 38 | std::ifstream ifs; |
| 39 | ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit | |
| 40 | std::ifstream::eofbit); |
| 41 | T data; |
| 42 | |
| 43 | try |
| 44 | { |
| 45 | ifs.open(path); |
| 46 | ifs >> data; |
| 47 | ifs.close(); |
| 48 | } |
| 49 | catch (const std::exception& e) |
| 50 | { |
| 51 | auto err = errno; |
| 52 | throw std::system_error(err, std::generic_category()); |
| 53 | } |
| 54 | |
| 55 | return data; |
| 56 | } |
| 57 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 58 | void Manager::findAndCreateObjects() |
| 59 | { |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 60 | #ifndef POWER10 |
Deepak Kodihalli | 370f06b | 2017-10-25 04:26:07 -0500 | [diff] [blame] | 61 | for (auto id = 0; id < MAX_CPUS; ++id) |
| 62 | { |
Deepak Kodihalli | 30417a1 | 2017-12-04 00:54:01 -0600 | [diff] [blame] | 63 | // Create one occ per cpu |
| 64 | auto occ = std::string(OCC_NAME) + std::to_string(id); |
| 65 | createObjects(occ); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 66 | } |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 67 | #else |
Chris Cain | 613dc90 | 2022-04-08 09:56:22 -0500 | [diff] [blame] | 68 | if (!pmode) |
| 69 | { |
| 70 | // Create the power mode object |
| 71 | pmode = std::make_unique<powermode::PowerMode>( |
| 72 | *this, powermode::PMODE_PATH, powermode::PIPS_PATH, event); |
| 73 | } |
| 74 | |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 75 | if (!fs::exists(HOST_ON_FILE)) |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 76 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 77 | static bool statusObjCreated = false; |
| 78 | if (!statusObjCreated) |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 79 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 80 | // Create the OCCs based on on the /dev/occX devices |
| 81 | auto occs = findOCCsInDev(); |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 82 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 83 | if (occs.empty() || (prevOCCSearch.size() != occs.size())) |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 84 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 85 | // Something changed or no OCCs yet, try again in 10s. |
| 86 | // Note on the first pass prevOCCSearch will be empty, |
| 87 | // so there will be at least one delay to give things |
| 88 | // a chance to settle. |
| 89 | prevOCCSearch = occs; |
| 90 | |
| 91 | log<level::INFO>( |
| 92 | fmt::format( |
| 93 | "Manager::findAndCreateObjects(): Waiting for OCCs (currently {})", |
| 94 | occs.size()) |
| 95 | .c_str()); |
| 96 | |
| 97 | discoverTimer->restartOnce(10s); |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | // All OCCs appear to be available, create status objects |
| 102 | |
| 103 | // createObjects requires OCC0 first. |
| 104 | std::sort(occs.begin(), occs.end()); |
| 105 | |
| 106 | log<level::INFO>( |
| 107 | fmt::format( |
| 108 | "Manager::findAndCreateObjects(): Creating {} OCC Status Objects", |
| 109 | occs.size()) |
| 110 | .c_str()); |
| 111 | for (auto id : occs) |
| 112 | { |
| 113 | createObjects(std::string(OCC_NAME) + std::to_string(id)); |
| 114 | } |
| 115 | statusObjCreated = true; |
Chris Cain | 6d8f37a | 2022-04-29 13:46:01 -0500 | [diff] [blame] | 116 | waitingForAllOccActiveSensors = true; |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
Chris Cain | 6d8f37a | 2022-04-29 13:46:01 -0500 | [diff] [blame] | 120 | if (statusObjCreated && waitingForAllOccActiveSensors) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 121 | { |
| 122 | static bool tracedHostWait = false; |
| 123 | if (utils::isHostRunning()) |
| 124 | { |
| 125 | if (tracedHostWait) |
| 126 | { |
| 127 | log<level::INFO>( |
| 128 | "Manager::findAndCreateObjects(): Host is running"); |
| 129 | tracedHostWait = false; |
| 130 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 131 | checkAllActiveSensors(); |
| 132 | } |
| 133 | else |
| 134 | { |
| 135 | if (!tracedHostWait) |
| 136 | { |
| 137 | log<level::INFO>( |
| 138 | "Manager::findAndCreateObjects(): Waiting for host to start"); |
| 139 | tracedHostWait = true; |
| 140 | } |
| 141 | discoverTimer->restartOnce(30s); |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 142 | } |
| 143 | } |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 144 | } |
| 145 | else |
| 146 | { |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 147 | log<level::INFO>( |
| 148 | fmt::format( |
| 149 | "Manager::findAndCreateObjects(): Waiting for {} to complete...", |
| 150 | HOST_ON_FILE) |
| 151 | .c_str()); |
| 152 | discoverTimer->restartOnce(10s); |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 153 | } |
| 154 | #endif |
| 155 | } |
| 156 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 157 | #ifdef POWER10 |
| 158 | // Check if all occActive sensors are available |
| 159 | void Manager::checkAllActiveSensors() |
| 160 | { |
| 161 | static bool allActiveSensorAvailable = false; |
| 162 | static bool tracedSensorWait = false; |
| 163 | |
| 164 | // Start with the assumption that all are available |
| 165 | allActiveSensorAvailable = true; |
| 166 | for (auto& obj : statusObjects) |
| 167 | { |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 168 | if (!obj->occActive()) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 169 | { |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 170 | if (!obj->getPldmSensorReceived()) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 171 | { |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 172 | auto instance = obj->getOccInstanceID(); |
| 173 | // Check if sensor was queued while waiting for discovery |
| 174 | auto match = queuedActiveState.find(instance); |
| 175 | if (match != queuedActiveState.end()) |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 176 | { |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 177 | queuedActiveState.erase(match); |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 178 | log<level::INFO>( |
| 179 | fmt::format( |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 180 | "checkAllActiveSensors(): OCC{} is ACTIVE (queued)", |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 181 | instance) |
| 182 | .c_str()); |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 183 | obj->occActive(true); |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 184 | } |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 185 | else |
| 186 | { |
| 187 | allActiveSensorAvailable = false; |
| 188 | if (!tracedSensorWait) |
| 189 | { |
| 190 | log<level::INFO>( |
| 191 | fmt::format( |
| 192 | "checkAllActiveSensors(): Waiting on OCC{} Active sensor", |
| 193 | instance) |
| 194 | .c_str()); |
| 195 | tracedSensorWait = true; |
| 196 | } |
| 197 | pldmHandle->checkActiveSensor(obj->getOccInstanceID()); |
| 198 | break; |
| 199 | } |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 200 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
| 204 | if (allActiveSensorAvailable) |
| 205 | { |
| 206 | // All sensors were found, disable the discovery timer |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 207 | if (discoverTimer->isEnabled()) |
| 208 | { |
Chris Cain | f55f91a | 2022-05-27 13:40:15 -0500 | [diff] [blame] | 209 | discoverTimer->setEnabled(false); |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 210 | } |
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 | if (waitingForAllOccActiveSensors) |
| 213 | { |
| 214 | log<level::INFO>( |
| 215 | "checkAllActiveSensors(): OCC Active sensors are available"); |
| 216 | waitingForAllOccActiveSensors = false; |
| 217 | } |
| 218 | queuedActiveState.clear(); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 219 | tracedSensorWait = false; |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | // Not all sensors were available, so keep waiting |
| 224 | if (!tracedSensorWait) |
| 225 | { |
| 226 | log<level::INFO>( |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 227 | "checkAllActiveSensors(): Waiting for OCC Active sensors to become available"); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 228 | tracedSensorWait = true; |
| 229 | } |
Chris Cain | f55f91a | 2022-05-27 13:40:15 -0500 | [diff] [blame] | 230 | discoverTimer->restartOnce(10s); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | #endif |
| 234 | |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 235 | std::vector<int> Manager::findOCCsInDev() |
| 236 | { |
| 237 | std::vector<int> occs; |
| 238 | std::regex expr{R"(occ(\d+)$)"}; |
| 239 | |
| 240 | for (auto& file : fs::directory_iterator("/dev")) |
| 241 | { |
| 242 | std::smatch match; |
| 243 | std::string path{file.path().string()}; |
| 244 | if (std::regex_search(path, match, expr)) |
| 245 | { |
| 246 | auto num = std::stoi(match[1].str()); |
| 247 | |
| 248 | // /dev numbering starts at 1, ours starts at 0. |
| 249 | occs.push_back(num - 1); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | return occs; |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 254 | } |
| 255 | |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 256 | int Manager::cpuCreated(sdbusplus::message_t& msg) |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 257 | { |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 258 | namespace fs = std::filesystem; |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 259 | |
| 260 | sdbusplus::message::object_path o; |
| 261 | msg.read(o); |
| 262 | fs::path cpuPath(std::string(std::move(o))); |
| 263 | |
| 264 | auto name = cpuPath.filename().string(); |
| 265 | auto index = name.find(CPU_NAME); |
| 266 | name.replace(index, std::strlen(CPU_NAME), OCC_NAME); |
| 267 | |
| 268 | createObjects(name); |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | void Manager::createObjects(const std::string& occ) |
| 274 | { |
| 275 | auto path = fs::path(OCC_CONTROL_ROOT) / occ; |
| 276 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 277 | statusObjects.emplace_back(std::make_unique<Status>( |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 278 | event, path.c_str(), *this, |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 279 | #ifdef POWER10 |
| 280 | pmode, |
| 281 | #endif |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 282 | std::bind(std::mem_fn(&Manager::statusCallBack), this, |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 283 | std::placeholders::_1, std::placeholders::_2) |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 284 | #ifdef PLDM |
| 285 | , |
| 286 | std::bind(std::mem_fn(&pldm::Interface::resetOCC), pldmHandle.get(), |
| 287 | std::placeholders::_1) |
| 288 | #endif |
| 289 | )); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 290 | |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 291 | // Create the power cap monitor object |
| 292 | if (!pcap) |
| 293 | { |
| 294 | pcap = std::make_unique<open_power::occ::powercap::PowerCap>( |
| 295 | *statusObjects.back()); |
| 296 | } |
| 297 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 298 | if (statusObjects.back()->isMasterOcc()) |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 299 | { |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 300 | log<level::INFO>( |
| 301 | fmt::format("Manager::createObjects(): OCC{} is the master", |
| 302 | statusObjects.back()->getOccInstanceID()) |
| 303 | .c_str()); |
| 304 | _pollTimer->setEnabled(false); |
| 305 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 306 | #ifdef POWER10 |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 307 | // Set the master OCC on the PowerMode object |
| 308 | pmode->setMasterOcc(path); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 309 | #endif |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | passThroughObjects.emplace_back(std::make_unique<PassThrough>(path.c_str() |
| 313 | #ifdef POWER10 |
| 314 | , |
| 315 | pmode |
| 316 | #endif |
| 317 | )); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 318 | } |
| 319 | |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 320 | void Manager::statusCallBack(instanceID instance, bool status) |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 321 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 322 | using InternalFailure = |
| 323 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 324 | |
| 325 | // At this time, it won't happen but keeping it |
| 326 | // here just in case something changes in the future |
| 327 | if ((activeCount == 0) && (!status)) |
| 328 | { |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 329 | log<level::ERR>( |
| 330 | fmt::format("Invalid update on OCCActive with OCC{}", instance) |
| 331 | .c_str()); |
| 332 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 333 | elog<InternalFailure>(); |
| 334 | } |
| 335 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 336 | if (status == true) |
Eddie James | dae2d94 | 2017-12-20 10:50:03 -0600 | [diff] [blame] | 337 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 338 | // OCC went active |
| 339 | ++activeCount; |
| 340 | |
| 341 | #ifdef POWER10 |
| 342 | if (activeCount == 1) |
Eddie James | dae2d94 | 2017-12-20 10:50:03 -0600 | [diff] [blame] | 343 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 344 | // 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] | 345 | waitForAllOccsTimer->restartOnce(60s); |
Matt Spinler | 53f6814 | 2021-08-25 15:47:31 -0500 | [diff] [blame] | 346 | } |
| 347 | #endif |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 348 | |
| 349 | if (activeCount == statusObjects.size()) |
| 350 | { |
| 351 | #ifdef POWER10 |
| 352 | // All OCCs are now running |
| 353 | if (waitForAllOccsTimer->isEnabled()) |
| 354 | { |
| 355 | // stop occ wait timer |
| 356 | waitForAllOccsTimer->setEnabled(false); |
| 357 | } |
| 358 | #endif |
| 359 | |
| 360 | // Verify master OCC and start presence monitor |
| 361 | validateOccMaster(); |
| 362 | } |
| 363 | |
| 364 | // Start poll timer if not already started |
| 365 | if (!_pollTimer->isEnabled()) |
| 366 | { |
| 367 | log<level::INFO>( |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 368 | fmt::format("Manager: OCCs will be polled every {} seconds", |
| 369 | pollInterval) |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 370 | .c_str()); |
| 371 | |
| 372 | // Send poll and start OCC poll timer |
| 373 | pollerTimerExpired(); |
| 374 | } |
| 375 | } |
| 376 | else |
| 377 | { |
| 378 | // OCC went away |
| 379 | --activeCount; |
| 380 | |
| 381 | if (activeCount == 0) |
| 382 | { |
| 383 | // No OCCs are running |
| 384 | |
| 385 | // Stop OCC poll timer |
| 386 | if (_pollTimer->isEnabled()) |
| 387 | { |
| 388 | log<level::INFO>( |
| 389 | "Manager::statusCallBack(): OCCs are not running, stopping poll timer"); |
| 390 | _pollTimer->setEnabled(false); |
| 391 | } |
| 392 | |
| 393 | #ifdef POWER10 |
| 394 | // stop wait timer |
| 395 | if (waitForAllOccsTimer->isEnabled()) |
| 396 | { |
| 397 | waitForAllOccsTimer->setEnabled(false); |
| 398 | } |
| 399 | #endif |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 400 | } |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 401 | #ifdef READ_OCC_SENSORS |
| 402 | // Clear OCC sensors |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 403 | setSensorValueToNaN(instance); |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 404 | #endif |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 405 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 406 | |
| 407 | #ifdef POWER10 |
| 408 | if (waitingForAllOccActiveSensors) |
| 409 | { |
Chris Cain | 6d8f37a | 2022-04-29 13:46:01 -0500 | [diff] [blame] | 410 | if (utils::isHostRunning()) |
| 411 | { |
| 412 | checkAllActiveSensors(); |
| 413 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 414 | } |
| 415 | #endif |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | #ifdef I2C_OCC |
| 419 | void Manager::initStatusObjects() |
| 420 | { |
| 421 | // Make sure we have a valid path string |
| 422 | static_assert(sizeof(DEV_PATH) != 0); |
| 423 | |
| 424 | auto deviceNames = i2c_occ::getOccHwmonDevices(DEV_PATH); |
| 425 | for (auto& name : deviceNames) |
| 426 | { |
| 427 | i2c_occ::i2cToDbus(name); |
Lei YU | b5259a1 | 2017-09-01 16:22:40 +0800 | [diff] [blame] | 428 | name = std::string(OCC_NAME) + '_' + name; |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 429 | auto path = fs::path(OCC_CONTROL_ROOT) / name; |
| 430 | statusObjects.emplace_back( |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 431 | std::make_unique<Status>(event, path.c_str(), *this)); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 432 | } |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 433 | // The first device is master occ |
| 434 | pcap = std::make_unique<open_power::occ::powercap::PowerCap>( |
| 435 | *statusObjects.front()); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 436 | #ifdef POWER10 |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 437 | pmode = std::make_unique<powermode::PowerMode>(*this, powermode::PMODE_PATH, |
| 438 | powermode::PIPS_PATH); |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 439 | // Set the master OCC on the PowerMode object |
| 440 | pmode->setMasterOcc(path); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 441 | #endif |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 442 | } |
| 443 | #endif |
| 444 | |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 445 | #ifdef PLDM |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 446 | void Manager::sbeTimeout(unsigned int instance) |
| 447 | { |
Eddie James | 2a751d7 | 2022-03-04 09:16:12 -0600 | [diff] [blame] | 448 | auto obj = std::find_if(statusObjects.begin(), statusObjects.end(), |
| 449 | [instance](const auto& obj) { |
| 450 | return instance == obj->getOccInstanceID(); |
| 451 | }); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 452 | |
Eddie James | cb018da | 2022-03-05 11:49:37 -0600 | [diff] [blame] | 453 | if (obj != statusObjects.end() && (*obj)->occActive()) |
Eddie James | 2a751d7 | 2022-03-04 09:16:12 -0600 | [diff] [blame] | 454 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 455 | log<level::INFO>( |
| 456 | fmt::format("SBE timeout, requesting HRESET (OCC{})", instance) |
| 457 | .c_str()); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 458 | |
Eddie James | 2a751d7 | 2022-03-04 09:16:12 -0600 | [diff] [blame] | 459 | setSBEState(instance, SBE_STATE_NOT_USABLE); |
| 460 | |
| 461 | pldmHandle->sendHRESET(instance); |
| 462 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 463 | } |
| 464 | |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 465 | bool Manager::updateOCCActive(instanceID instance, bool status) |
| 466 | { |
Chris Cain | 7e374fb | 2022-04-07 09:47:23 -0500 | [diff] [blame] | 467 | auto obj = std::find_if(statusObjects.begin(), statusObjects.end(), |
| 468 | [instance](const auto& obj) { |
| 469 | return instance == obj->getOccInstanceID(); |
| 470 | }); |
| 471 | |
| 472 | if (obj != statusObjects.end()) |
| 473 | { |
Chris Cain | 733b201 | 2022-05-04 11:54:06 -0500 | [diff] [blame] | 474 | (*obj)->setPldmSensorReceived(true); |
Chris Cain | 7e374fb | 2022-04-07 09:47:23 -0500 | [diff] [blame] | 475 | return (*obj)->occActive(status); |
| 476 | } |
| 477 | else |
| 478 | { |
| 479 | log<level::WARNING>( |
| 480 | fmt::format( |
| 481 | "Manager::updateOCCActive: No status object to update for OCC{} (active={})", |
| 482 | instance, status) |
| 483 | .c_str()); |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 484 | if (status == true) |
| 485 | { |
| 486 | // OCC went active |
| 487 | queuedActiveState.insert(instance); |
| 488 | } |
| 489 | else |
| 490 | { |
| 491 | auto match = queuedActiveState.find(instance); |
| 492 | if (match != queuedActiveState.end()) |
| 493 | { |
| 494 | // OCC was disabled |
| 495 | queuedActiveState.erase(match); |
| 496 | } |
| 497 | } |
Chris Cain | 7e374fb | 2022-04-07 09:47:23 -0500 | [diff] [blame] | 498 | return false; |
| 499 | } |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 500 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 501 | |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 502 | // Called upon pldm event To set powermode Safe Mode State for system. |
| 503 | void Manager::updateOccSafeMode(bool safeMode) |
| 504 | { |
| 505 | #ifdef POWER10 |
| 506 | pmode->updateDbusSafeMode(safeMode); |
| 507 | #endif |
| 508 | } |
| 509 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 510 | void Manager::sbeHRESETResult(instanceID instance, bool success) |
| 511 | { |
| 512 | if (success) |
| 513 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 514 | log<level::INFO>( |
| 515 | fmt::format("HRESET succeeded (OCC{})", instance).c_str()); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 516 | |
| 517 | setSBEState(instance, SBE_STATE_BOOTED); |
| 518 | |
| 519 | return; |
| 520 | } |
| 521 | |
| 522 | setSBEState(instance, SBE_STATE_FAILED); |
| 523 | |
| 524 | if (sbeCanDump(instance)) |
| 525 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 526 | log<level::INFO>( |
| 527 | fmt::format("HRESET failed (OCC{}), triggering SBE dump", instance) |
| 528 | .c_str()); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 529 | |
| 530 | auto& bus = utils::getBus(); |
| 531 | uint32_t src6 = instance << 16; |
| 532 | uint32_t logId = |
| 533 | FFDC::createPEL("org.open_power.Processor.Error.SbeChipOpTimeout", |
| 534 | src6, "SBE command timeout"); |
| 535 | |
| 536 | try |
| 537 | { |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 538 | constexpr auto path = "/org/openpower/dump"; |
| 539 | constexpr auto interface = "xyz.openbmc_project.Dump.Create"; |
| 540 | constexpr auto function = "CreateDump"; |
| 541 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 542 | std::string service = utils::getService(path, interface); |
| 543 | auto method = |
| 544 | bus.new_method_call(service.c_str(), path, interface, function); |
| 545 | |
| 546 | std::map<std::string, std::variant<std::string, uint64_t>> |
| 547 | createParams{ |
| 548 | {"com.ibm.Dump.Create.CreateParameters.ErrorLogId", |
| 549 | uint64_t(logId)}, |
| 550 | {"com.ibm.Dump.Create.CreateParameters.DumpType", |
| 551 | "com.ibm.Dump.Create.DumpType.SBE"}, |
| 552 | {"com.ibm.Dump.Create.CreateParameters.FailingUnitId", |
| 553 | uint64_t(instance)}, |
| 554 | }; |
| 555 | |
| 556 | method.append(createParams); |
| 557 | |
| 558 | auto response = bus.call(method); |
| 559 | } |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 560 | catch (const sdbusplus::exception_t& e) |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 561 | { |
| 562 | constexpr auto ERROR_DUMP_DISABLED = |
| 563 | "xyz.openbmc_project.Dump.Create.Error.Disabled"; |
| 564 | if (e.name() == ERROR_DUMP_DISABLED) |
| 565 | { |
| 566 | log<level::INFO>("Dump is disabled, skipping"); |
| 567 | } |
| 568 | else |
| 569 | { |
| 570 | log<level::ERR>("Dump failed"); |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | bool Manager::sbeCanDump(unsigned int instance) |
| 577 | { |
| 578 | struct pdbg_target* proc = getPdbgTarget(instance); |
| 579 | |
| 580 | if (!proc) |
| 581 | { |
| 582 | // allow the dump in the error case |
| 583 | return true; |
| 584 | } |
| 585 | |
| 586 | try |
| 587 | { |
| 588 | if (!openpower::phal::sbe::isDumpAllowed(proc)) |
| 589 | { |
| 590 | return false; |
| 591 | } |
| 592 | |
| 593 | if (openpower::phal::pdbg::isSbeVitalAttnActive(proc)) |
| 594 | { |
| 595 | return false; |
| 596 | } |
| 597 | } |
| 598 | catch (openpower::phal::exception::SbeError& e) |
| 599 | { |
| 600 | log<level::INFO>("Failed to query SBE state"); |
| 601 | } |
| 602 | |
| 603 | // allow the dump in the error case |
| 604 | return true; |
| 605 | } |
| 606 | |
| 607 | void Manager::setSBEState(unsigned int instance, enum sbe_state state) |
| 608 | { |
| 609 | struct pdbg_target* proc = getPdbgTarget(instance); |
| 610 | |
| 611 | if (!proc) |
| 612 | { |
| 613 | return; |
| 614 | } |
| 615 | |
| 616 | try |
| 617 | { |
| 618 | openpower::phal::sbe::setState(proc, state); |
| 619 | } |
| 620 | catch (const openpower::phal::exception::SbeError& e) |
| 621 | { |
| 622 | log<level::ERR>("Failed to set SBE state"); |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | struct pdbg_target* Manager::getPdbgTarget(unsigned int instance) |
| 627 | { |
| 628 | if (!pdbgInitialized) |
| 629 | { |
| 630 | try |
| 631 | { |
| 632 | openpower::phal::pdbg::init(); |
| 633 | pdbgInitialized = true; |
| 634 | } |
| 635 | catch (const openpower::phal::exception::PdbgError& e) |
| 636 | { |
| 637 | log<level::ERR>("pdbg initialization failed"); |
| 638 | return nullptr; |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | struct pdbg_target* proc = nullptr; |
| 643 | pdbg_for_each_class_target("proc", proc) |
| 644 | { |
| 645 | if (pdbg_target_index(proc) == instance) |
| 646 | { |
| 647 | return proc; |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | log<level::ERR>("Failed to get pdbg target"); |
| 652 | return nullptr; |
| 653 | } |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 654 | #endif |
| 655 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 656 | void Manager::pollerTimerExpired() |
| 657 | { |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 658 | if (!_pollTimer) |
| 659 | { |
| 660 | log<level::ERR>( |
| 661 | "Manager::pollerTimerExpired() ERROR: Timer not defined"); |
| 662 | return; |
| 663 | } |
| 664 | |
| 665 | for (auto& obj : statusObjects) |
| 666 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 667 | if (!obj->occActive()) |
| 668 | { |
| 669 | // OCC is not running yet |
| 670 | #ifdef READ_OCC_SENSORS |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 671 | auto id = obj->getOccInstanceID(); |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 672 | setSensorValueToNaN(id); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 673 | #endif |
| 674 | continue; |
| 675 | } |
| 676 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 677 | // Read sysfs to force kernel to poll OCC |
| 678 | obj->readOccState(); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 679 | |
| 680 | #ifdef READ_OCC_SENSORS |
| 681 | // Read occ sensor values |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 682 | getSensorValues(obj); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 683 | #endif |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 684 | } |
| 685 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 686 | if (activeCount > 0) |
| 687 | { |
| 688 | // Restart OCC poll timer |
| 689 | _pollTimer->restartOnce(std::chrono::seconds(pollInterval)); |
| 690 | } |
| 691 | else |
| 692 | { |
| 693 | // No OCCs running, so poll timer will not be restarted |
| 694 | log<level::INFO>( |
| 695 | fmt::format( |
| 696 | "Manager::pollerTimerExpired: poll timer will not be restarted") |
| 697 | .c_str()); |
| 698 | } |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 699 | } |
| 700 | |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 701 | #ifdef READ_OCC_SENSORS |
| 702 | void Manager::readTempSensors(const fs::path& path, uint32_t id) |
| 703 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 704 | std::regex expr{"temp\\d+_label$"}; // Example: temp5_label |
| 705 | for (auto& file : fs::directory_iterator(path)) |
| 706 | { |
| 707 | if (!std::regex_search(file.path().string(), expr)) |
| 708 | { |
| 709 | continue; |
| 710 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 711 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 712 | uint32_t labelValue{0}; |
| 713 | |
| 714 | try |
| 715 | { |
| 716 | labelValue = readFile<uint32_t>(file.path()); |
| 717 | } |
| 718 | catch (const std::system_error& e) |
| 719 | { |
| 720 | log<level::DEBUG>( |
| 721 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 722 | file.path().string(), e.code().value()) |
| 723 | .c_str()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 724 | continue; |
| 725 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 726 | |
| 727 | const std::string& tempLabel = "label"; |
| 728 | const std::string filePathString = file.path().string().substr( |
| 729 | 0, file.path().string().length() - tempLabel.length()); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 730 | |
| 731 | uint32_t fruTypeValue{0}; |
| 732 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 733 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 734 | fruTypeValue = readFile<uint32_t>(filePathString + fruTypeSuffix); |
| 735 | } |
| 736 | catch (const std::system_error& e) |
| 737 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 738 | log<level::DEBUG>( |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 739 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 740 | filePathString + fruTypeSuffix, e.code().value()) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 741 | .c_str()); |
| 742 | continue; |
| 743 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 744 | |
| 745 | std::string sensorPath = |
| 746 | OCC_SENSORS_ROOT + std::string("/temperature/"); |
| 747 | |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 748 | std::string dvfsTempPath; |
| 749 | |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 750 | if (fruTypeValue == VRMVdd) |
| 751 | { |
| 752 | sensorPath.append("vrm_vdd" + std::to_string(id) + "_temp"); |
| 753 | } |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 754 | else if (fruTypeValue == processorIoRing) |
| 755 | { |
| 756 | sensorPath.append("proc" + std::to_string(id) + "_ioring_temp"); |
| 757 | dvfsTempPath = std::string{OCC_SENSORS_ROOT} + "/temperature/proc" + |
| 758 | std::to_string(id) + "_ioring_dvfs_temp"; |
| 759 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 760 | else |
| 761 | { |
Matt Spinler | 14d1402 | 2021-08-25 15:38:29 -0500 | [diff] [blame] | 762 | uint16_t type = (labelValue & 0xFF000000) >> 24; |
| 763 | uint16_t instanceID = labelValue & 0x0000FFFF; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 764 | |
| 765 | if (type == OCC_DIMM_TEMP_SENSOR_TYPE) |
| 766 | { |
Matt Spinler | 8b8abee | 2021-08-25 15:18:21 -0500 | [diff] [blame] | 767 | if (fruTypeValue == fruTypeNotAvailable) |
| 768 | { |
| 769 | // Not all DIMM related temps are available to read |
| 770 | // (no _input file in this case) |
| 771 | continue; |
| 772 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 773 | auto iter = dimmTempSensorName.find(fruTypeValue); |
| 774 | if (iter == dimmTempSensorName.end()) |
| 775 | { |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 776 | log<level::ERR>( |
| 777 | fmt::format( |
| 778 | "readTempSensors: Fru type error! fruTypeValue = {}) ", |
| 779 | fruTypeValue) |
| 780 | .c_str()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 781 | continue; |
| 782 | } |
| 783 | |
| 784 | sensorPath.append("dimm" + std::to_string(instanceID) + |
| 785 | iter->second); |
| 786 | } |
| 787 | else if (type == OCC_CPU_TEMP_SENSOR_TYPE) |
| 788 | { |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 789 | if (fruTypeValue == processorCore) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 790 | { |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 791 | // The OCC reports small core temps, of which there are |
| 792 | // two per big core. All current P10 systems are in big |
| 793 | // core mode, so use a big core name. |
| 794 | uint16_t coreNum = instanceID / 2; |
| 795 | uint16_t tempNum = instanceID % 2; |
| 796 | sensorPath.append("proc" + std::to_string(id) + "_core" + |
| 797 | std::to_string(coreNum) + "_" + |
| 798 | std::to_string(tempNum) + "_temp"); |
| 799 | |
| 800 | dvfsTempPath = std::string{OCC_SENSORS_ROOT} + |
| 801 | "/temperature/proc" + std::to_string(id) + |
| 802 | "_core_dvfs_temp"; |
| 803 | } |
| 804 | else |
| 805 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 806 | continue; |
| 807 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 808 | } |
| 809 | else |
| 810 | { |
| 811 | continue; |
| 812 | } |
| 813 | } |
| 814 | |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 815 | // The dvfs temp file only needs to be read once per chip per type. |
| 816 | if (!dvfsTempPath.empty() && |
| 817 | !dbus::OccDBusSensors::getOccDBus().hasDvfsTemp(dvfsTempPath)) |
| 818 | { |
| 819 | try |
| 820 | { |
| 821 | auto dvfsValue = readFile<double>(filePathString + maxSuffix); |
| 822 | |
| 823 | dbus::OccDBusSensors::getOccDBus().setDvfsTemp( |
| 824 | dvfsTempPath, dvfsValue * std::pow(10, -3)); |
| 825 | } |
| 826 | catch (const std::system_error& e) |
| 827 | { |
| 828 | log<level::DEBUG>( |
| 829 | fmt::format( |
| 830 | "readTempSensors: Failed reading {}, errno = {}", |
| 831 | filePathString + maxSuffix, e.code().value()) |
| 832 | .c_str()); |
| 833 | } |
| 834 | } |
| 835 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 836 | uint32_t faultValue{0}; |
| 837 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 838 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 839 | faultValue = readFile<uint32_t>(filePathString + faultSuffix); |
| 840 | } |
| 841 | catch (const std::system_error& e) |
| 842 | { |
| 843 | log<level::DEBUG>( |
| 844 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 845 | filePathString + faultSuffix, e.code().value()) |
| 846 | .c_str()); |
| 847 | continue; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 848 | } |
| 849 | |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 850 | // 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] | 851 | if (faultValue != 0) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 852 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 853 | dbus::OccDBusSensors::getOccDBus().setValue( |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 854 | sensorPath, std::numeric_limits<double>::quiet_NaN()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 855 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 856 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath, |
| 857 | false); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 858 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 859 | continue; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 860 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 861 | |
| 862 | double tempValue{0}; |
| 863 | |
| 864 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 865 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 866 | tempValue = readFile<double>(filePathString + inputSuffix); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 867 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 868 | catch (const std::system_error& e) |
| 869 | { |
| 870 | log<level::DEBUG>( |
| 871 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 872 | filePathString + inputSuffix, e.code().value()) |
| 873 | .c_str()); |
Sheldon Bailey | cd0940b | 2022-04-26 14:24:05 -0500 | [diff] [blame] | 874 | |
| 875 | // if errno == EAGAIN(Resource temporarily unavailable) then set |
| 876 | // temp to 0, to avoid using old temp, and affecting FAN Control. |
| 877 | if (e.code().value() == EAGAIN) |
| 878 | { |
| 879 | tempValue = 0; |
| 880 | } |
| 881 | // else the errno would be something like |
| 882 | // EBADF(Bad file descriptor) |
| 883 | // or ENOENT(No such file or directory) |
| 884 | else |
| 885 | { |
| 886 | continue; |
| 887 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 888 | } |
| 889 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 890 | dbus::OccDBusSensors::getOccDBus().setValue( |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 891 | sensorPath, tempValue * std::pow(10, -3)); |
| 892 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 893 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath, |
| 894 | true); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 895 | |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 896 | // At this point, the sensor will be created for sure. |
| 897 | if (existingSensors.find(sensorPath) == existingSensors.end()) |
| 898 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 899 | dbus::OccDBusSensors::getOccDBus().setChassisAssociation( |
| 900 | sensorPath); |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 901 | } |
| 902 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 903 | existingSensors[sensorPath] = id; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 904 | } |
| 905 | return; |
| 906 | } |
| 907 | |
| 908 | std::optional<std::string> |
| 909 | Manager::getPowerLabelFunctionID(const std::string& value) |
| 910 | { |
| 911 | // If the value is "system", then the FunctionID is "system". |
| 912 | if (value == "system") |
| 913 | { |
| 914 | return value; |
| 915 | } |
| 916 | |
| 917 | // If the value is not "system", then the label value have 3 numbers, of |
| 918 | // which we only care about the middle one: |
| 919 | // <sensor id>_<function id>_<apss channel> |
| 920 | // eg: The value is "0_10_5" , then the FunctionID is "10". |
| 921 | if (value.find("_") == std::string::npos) |
| 922 | { |
| 923 | return std::nullopt; |
| 924 | } |
| 925 | |
| 926 | auto powerLabelValue = value.substr((value.find("_") + 1)); |
| 927 | |
| 928 | if (powerLabelValue.find("_") == std::string::npos) |
| 929 | { |
| 930 | return std::nullopt; |
| 931 | } |
| 932 | |
| 933 | return powerLabelValue.substr(0, powerLabelValue.find("_")); |
| 934 | } |
| 935 | |
| 936 | void Manager::readPowerSensors(const fs::path& path, uint32_t id) |
| 937 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 938 | std::regex expr{"power\\d+_label$"}; // Example: power5_label |
| 939 | for (auto& file : fs::directory_iterator(path)) |
| 940 | { |
| 941 | if (!std::regex_search(file.path().string(), expr)) |
| 942 | { |
| 943 | continue; |
| 944 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 945 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 946 | std::string labelValue; |
| 947 | try |
| 948 | { |
| 949 | labelValue = readFile<std::string>(file.path()); |
| 950 | } |
| 951 | catch (const std::system_error& e) |
| 952 | { |
| 953 | log<level::DEBUG>( |
| 954 | fmt::format("readPowerSensors: Failed reading {}, errno = {}", |
| 955 | file.path().string(), e.code().value()) |
| 956 | .c_str()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 957 | continue; |
| 958 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 959 | |
| 960 | auto functionID = getPowerLabelFunctionID(labelValue); |
| 961 | if (functionID == std::nullopt) |
| 962 | { |
| 963 | continue; |
| 964 | } |
| 965 | |
| 966 | const std::string& tempLabel = "label"; |
| 967 | const std::string filePathString = file.path().string().substr( |
| 968 | 0, file.path().string().length() - tempLabel.length()); |
| 969 | |
| 970 | std::string sensorPath = OCC_SENSORS_ROOT + std::string("/power/"); |
| 971 | |
| 972 | auto iter = powerSensorName.find(*functionID); |
| 973 | if (iter == powerSensorName.end()) |
| 974 | { |
| 975 | continue; |
| 976 | } |
| 977 | sensorPath.append(iter->second); |
| 978 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 979 | double tempValue{0}; |
| 980 | |
| 981 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 982 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 983 | tempValue = readFile<double>(filePathString + inputSuffix); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 984 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 985 | catch (const std::system_error& e) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 986 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 987 | log<level::DEBUG>( |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 988 | fmt::format("readPowerSensors: Failed reading {}, errno = {}", |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 989 | filePathString + inputSuffix, e.code().value()) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 990 | .c_str()); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 991 | continue; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 992 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 993 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 994 | dbus::OccDBusSensors::getOccDBus().setUnit( |
Chris Cain | d84a833 | 2022-01-13 08:58:45 -0600 | [diff] [blame] | 995 | sensorPath, "xyz.openbmc_project.Sensor.Value.Unit.Watts"); |
| 996 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 997 | dbus::OccDBusSensors::getOccDBus().setValue( |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 998 | sensorPath, tempValue * std::pow(10, -3) * std::pow(10, -3)); |
| 999 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1000 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath, |
| 1001 | true); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1002 | |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 1003 | if (existingSensors.find(sensorPath) == existingSensors.end()) |
| 1004 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1005 | dbus::OccDBusSensors::getOccDBus().setChassisAssociation( |
| 1006 | sensorPath); |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 1007 | } |
| 1008 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1009 | existingSensors[sensorPath] = id; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1010 | } |
| 1011 | return; |
| 1012 | } |
| 1013 | |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 1014 | void Manager::setSensorValueToNaN(uint32_t id) const |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1015 | { |
| 1016 | for (const auto& [sensorPath, occId] : existingSensors) |
| 1017 | { |
| 1018 | if (occId == id) |
| 1019 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1020 | dbus::OccDBusSensors::getOccDBus().setValue( |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1021 | sensorPath, std::numeric_limits<double>::quiet_NaN()); |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 1022 | |
| 1023 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath, |
| 1024 | true); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1025 | } |
| 1026 | } |
| 1027 | return; |
| 1028 | } |
| 1029 | |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 1030 | void Manager::setSensorValueToNonFunctional(uint32_t id) const |
| 1031 | { |
| 1032 | for (const auto& [sensorPath, occId] : existingSensors) |
| 1033 | { |
| 1034 | if (occId == id) |
| 1035 | { |
| 1036 | dbus::OccDBusSensors::getOccDBus().setValue( |
| 1037 | sensorPath, std::numeric_limits<double>::quiet_NaN()); |
| 1038 | |
| 1039 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath, |
| 1040 | false); |
| 1041 | } |
| 1042 | } |
| 1043 | return; |
| 1044 | } |
| 1045 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1046 | void Manager::getSensorValues(std::unique_ptr<Status>& occ) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1047 | { |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 1048 | static bool tracedError[8] = {0}; |
| 1049 | const fs::path sensorPath = occ->getHwmonPath(); |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1050 | const uint32_t id = occ->getOccInstanceID(); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1051 | |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 1052 | if (fs::exists(sensorPath)) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1053 | { |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 1054 | // Read temperature sensors |
| 1055 | readTempSensors(sensorPath, id); |
| 1056 | |
| 1057 | if (occ->isMasterOcc()) |
| 1058 | { |
| 1059 | // Read power sensors |
| 1060 | readPowerSensors(sensorPath, id); |
| 1061 | } |
| 1062 | tracedError[id] = false; |
| 1063 | } |
| 1064 | else |
| 1065 | { |
| 1066 | if (!tracedError[id]) |
| 1067 | { |
| 1068 | log<level::ERR>( |
| 1069 | fmt::format( |
| 1070 | "Manager::getSensorValues: OCC{} sensor path missing: {}", |
| 1071 | id, sensorPath.c_str()) |
| 1072 | .c_str()); |
| 1073 | tracedError[id] = true; |
| 1074 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | return; |
| 1078 | } |
| 1079 | #endif |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1080 | |
| 1081 | // Read the altitude from DBus |
| 1082 | void Manager::readAltitude() |
| 1083 | { |
| 1084 | static bool traceAltitudeErr = true; |
| 1085 | |
| 1086 | utils::PropertyValue altitudeProperty{}; |
| 1087 | try |
| 1088 | { |
| 1089 | altitudeProperty = utils::getProperty(ALTITUDE_PATH, ALTITUDE_INTERFACE, |
| 1090 | ALTITUDE_PROP); |
| 1091 | auto sensorVal = std::get<double>(altitudeProperty); |
| 1092 | if (sensorVal < 0xFFFF) |
| 1093 | { |
| 1094 | if (sensorVal < 0) |
| 1095 | { |
| 1096 | altitude = 0; |
| 1097 | } |
| 1098 | else |
| 1099 | { |
| 1100 | // Round to nearest meter |
| 1101 | altitude = uint16_t(sensorVal + 0.5); |
| 1102 | } |
| 1103 | log<level::DEBUG>(fmt::format("readAltitude: sensor={} ({}m)", |
| 1104 | sensorVal, altitude) |
| 1105 | .c_str()); |
| 1106 | traceAltitudeErr = true; |
| 1107 | } |
| 1108 | else |
| 1109 | { |
| 1110 | if (traceAltitudeErr) |
| 1111 | { |
| 1112 | traceAltitudeErr = false; |
| 1113 | log<level::DEBUG>( |
| 1114 | fmt::format("Invalid altitude value: {}", sensorVal) |
| 1115 | .c_str()); |
| 1116 | } |
| 1117 | } |
| 1118 | } |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 1119 | catch (const sdbusplus::exception_t& e) |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1120 | { |
| 1121 | if (traceAltitudeErr) |
| 1122 | { |
| 1123 | traceAltitudeErr = false; |
| 1124 | log<level::INFO>( |
| 1125 | fmt::format("Unable to read Altitude: {}", e.what()).c_str()); |
| 1126 | } |
| 1127 | altitude = 0xFFFF; // not available |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | // Callback function when ambient temperature changes |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 1132 | void Manager::ambientCallback(sdbusplus::message_t& msg) |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1133 | { |
| 1134 | double currentTemp = 0; |
| 1135 | uint8_t truncatedTemp = 0xFF; |
| 1136 | std::string msgSensor; |
| 1137 | std::map<std::string, std::variant<double>> msgData; |
| 1138 | msg.read(msgSensor, msgData); |
| 1139 | |
| 1140 | auto valPropMap = msgData.find(AMBIENT_PROP); |
| 1141 | if (valPropMap == msgData.end()) |
| 1142 | { |
| 1143 | log<level::DEBUG>("ambientCallback: Unknown ambient property changed"); |
| 1144 | return; |
| 1145 | } |
| 1146 | currentTemp = std::get<double>(valPropMap->second); |
| 1147 | if (std::isnan(currentTemp)) |
| 1148 | { |
| 1149 | truncatedTemp = 0xFF; |
| 1150 | } |
| 1151 | else |
| 1152 | { |
| 1153 | if (currentTemp < 0) |
| 1154 | { |
| 1155 | truncatedTemp = 0; |
| 1156 | } |
| 1157 | else |
| 1158 | { |
| 1159 | // Round to nearest degree C |
| 1160 | truncatedTemp = uint8_t(currentTemp + 0.5); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | // If ambient changes, notify OCCs |
| 1165 | if (truncatedTemp != ambient) |
| 1166 | { |
| 1167 | log<level::DEBUG>( |
| 1168 | fmt::format("ambientCallback: Ambient change from {} to {}C", |
| 1169 | ambient, currentTemp) |
| 1170 | .c_str()); |
| 1171 | |
| 1172 | ambient = truncatedTemp; |
| 1173 | if (altitude == 0xFFFF) |
| 1174 | { |
| 1175 | // No altitude yet, try reading again |
| 1176 | readAltitude(); |
| 1177 | } |
| 1178 | |
| 1179 | log<level::DEBUG>( |
| 1180 | fmt::format("ambientCallback: Ambient: {}C, altitude: {}m", ambient, |
| 1181 | altitude) |
| 1182 | .c_str()); |
| 1183 | #ifdef POWER10 |
| 1184 | // Send ambient and altitude to all OCCs |
| 1185 | for (auto& obj : statusObjects) |
| 1186 | { |
| 1187 | if (obj->occActive()) |
| 1188 | { |
| 1189 | obj->sendAmbient(ambient, altitude); |
| 1190 | } |
| 1191 | } |
| 1192 | #endif // POWER10 |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | // return the current ambient and altitude readings |
| 1197 | void Manager::getAmbientData(bool& ambientValid, uint8_t& ambientTemp, |
| 1198 | uint16_t& altitudeValue) const |
| 1199 | { |
| 1200 | ambientValid = true; |
| 1201 | ambientTemp = ambient; |
| 1202 | altitudeValue = altitude; |
| 1203 | |
| 1204 | if (ambient == 0xFF) |
| 1205 | { |
| 1206 | ambientValid = false; |
| 1207 | } |
| 1208 | } |
| 1209 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1210 | #ifdef POWER10 |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 1211 | // Called when waitForAllOccsTimer expires |
| 1212 | // 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] | 1213 | void Manager::occsNotAllRunning() |
| 1214 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1215 | if (activeCount != statusObjects.size()) |
| 1216 | { |
| 1217 | // Not all OCCs went active |
| 1218 | log<level::WARNING>( |
| 1219 | fmt::format( |
| 1220 | "occsNotAllRunning: Active OCC count ({}) does not match expected count ({})", |
| 1221 | activeCount, statusObjects.size()) |
| 1222 | .c_str()); |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 1223 | // Procs may be garded, so may be expected |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | validateOccMaster(); |
| 1227 | } |
| 1228 | #endif // POWER10 |
| 1229 | |
| 1230 | // Verify single master OCC and start presence monitor |
| 1231 | void Manager::validateOccMaster() |
| 1232 | { |
| 1233 | int masterInstance = -1; |
| 1234 | for (auto& obj : statusObjects) |
| 1235 | { |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1236 | auto instance = obj->getOccInstanceID(); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1237 | #ifdef POWER10 |
| 1238 | if (!obj->occActive()) |
| 1239 | { |
| 1240 | if (utils::isHostRunning()) |
| 1241 | { |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1242 | // Check if sensor was queued while waiting for discovery |
| 1243 | auto match = queuedActiveState.find(instance); |
| 1244 | if (match != queuedActiveState.end()) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1245 | { |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 1246 | queuedActiveState.erase(match); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1247 | log<level::INFO>( |
| 1248 | fmt::format( |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1249 | "validateOccMaster: OCC{} is ACTIVE (queued)", |
| 1250 | instance) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1251 | .c_str()); |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1252 | obj->occActive(true); |
| 1253 | } |
| 1254 | else |
| 1255 | { |
| 1256 | // OCC does not appear to be active yet, check active sensor |
| 1257 | pldmHandle->checkActiveSensor(instance); |
| 1258 | if (obj->occActive()) |
| 1259 | { |
| 1260 | log<level::INFO>( |
| 1261 | fmt::format( |
| 1262 | "validateOccMaster: OCC{} is ACTIVE after reading sensor", |
| 1263 | instance) |
| 1264 | .c_str()); |
| 1265 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | else |
| 1269 | { |
| 1270 | log<level::WARNING>( |
| 1271 | fmt::format( |
| 1272 | "validateOccMaster: HOST is not running (OCC{})", |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1273 | instance) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1274 | .c_str()); |
| 1275 | return; |
| 1276 | } |
| 1277 | } |
| 1278 | #endif // POWER10 |
| 1279 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1280 | if (obj->isMasterOcc()) |
| 1281 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1282 | obj->addPresenceWatchMaster(); |
| 1283 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1284 | if (masterInstance == -1) |
| 1285 | { |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1286 | masterInstance = instance; |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1287 | } |
| 1288 | else |
| 1289 | { |
| 1290 | log<level::ERR>( |
| 1291 | fmt::format( |
| 1292 | "validateOccMaster: Multiple OCC masters! ({} and {})", |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1293 | masterInstance, instance) |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1294 | .c_str()); |
| 1295 | // request reset |
Eddie James | 9789e71 | 2022-05-25 15:43:40 -0500 | [diff] [blame] | 1296 | obj->deviceError(Error::Descriptor(PRESENCE_ERROR_PATH)); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1297 | } |
| 1298 | } |
| 1299 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1300 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1301 | if (masterInstance < 0) |
| 1302 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1303 | log<level::ERR>( |
| 1304 | fmt::format("validateOccMaster: Master OCC not found! (of {} OCCs)", |
| 1305 | statusObjects.size()) |
| 1306 | .c_str()); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1307 | // request reset |
Eddie James | 9789e71 | 2022-05-25 15:43:40 -0500 | [diff] [blame] | 1308 | statusObjects.front()->deviceError( |
| 1309 | Error::Descriptor(PRESENCE_ERROR_PATH)); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1310 | } |
| 1311 | else |
| 1312 | { |
| 1313 | log<level::INFO>( |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 1314 | fmt::format("validateOccMaster: OCC{} is master of {} OCCs", |
| 1315 | masterInstance, activeCount) |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1316 | .c_str()); |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 1317 | #ifdef POWER10 |
| 1318 | pmode->updateDbusSafeMode(false); |
| 1319 | #endif |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1320 | } |
| 1321 | } |
| 1322 | |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 1323 | void Manager::updatePcapBounds() const |
| 1324 | { |
| 1325 | if (pcap) |
| 1326 | { |
| 1327 | pcap->updatePcapBounds(); |
| 1328 | } |
| 1329 | } |
| 1330 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 1331 | } // namespace occ |
| 1332 | } // namespace open_power |