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