Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 3 | #include "dbus_types.hpp" |
| 4 | #include "dbus_watcher.hpp" |
| 5 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 6 | #include <filesystem> |
George Liu | 9ac0d9b | 2022-07-15 10:57:38 +0800 | [diff] [blame] | 7 | #include <fstream> |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 8 | #include <phosphor-logging/log.hpp> |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 9 | #include <sdbusplus/bus.hpp> |
| 10 | #include <sdbusplus/bus/match.hpp> |
| 11 | |
| 12 | namespace openpower |
| 13 | { |
| 14 | namespace pels |
| 15 | { |
| 16 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 17 | /** |
| 18 | * @class DataInterface |
| 19 | * |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame] | 20 | * A base class for gathering data about the system for use |
| 21 | * in PELs. Implemented this way to facilitate mocking. |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 22 | */ |
| 23 | class DataInterfaceBase |
| 24 | { |
| 25 | public: |
| 26 | DataInterfaceBase() = default; |
| 27 | virtual ~DataInterfaceBase() = default; |
| 28 | DataInterfaceBase(const DataInterfaceBase&) = default; |
| 29 | DataInterfaceBase& operator=(const DataInterfaceBase&) = default; |
| 30 | DataInterfaceBase(DataInterfaceBase&&) = default; |
| 31 | DataInterfaceBase& operator=(DataInterfaceBase&&) = default; |
| 32 | |
| 33 | /** |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame] | 34 | * @brief Returns the machine Type/Model |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 35 | * |
| 36 | * @return string - The machine Type/Model string |
| 37 | */ |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 38 | virtual std::string getMachineTypeModel() const = 0; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 39 | |
| 40 | /** |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame] | 41 | * @brief Returns the machine serial number |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 42 | * |
| 43 | * @return string - The machine serial number |
| 44 | */ |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 45 | virtual std::string getMachineSerialNumber() const = 0; |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame] | 46 | |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 47 | /** |
Matt Spinler | cce1411 | 2019-12-11 14:20:36 -0600 | [diff] [blame] | 48 | * @brief Says if the system is managed by a hardware |
| 49 | * management console. |
| 50 | * @return bool - If the system is HMC managed |
| 51 | */ |
| 52 | virtual bool isHMCManaged() const |
| 53 | { |
| 54 | return _hmcManaged; |
| 55 | } |
| 56 | |
| 57 | /** |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 58 | * @brief Says if the host is up and running |
| 59 | * |
| 60 | * @return bool - If the host is running |
| 61 | */ |
| 62 | virtual bool isHostUp() const |
| 63 | { |
| 64 | return _hostUp; |
| 65 | } |
| 66 | |
| 67 | using HostStateChangeFunc = std::function<void(bool)>; |
| 68 | |
| 69 | /** |
| 70 | * @brief Register a callback function that will get |
| 71 | * called on all host on/off transitions. |
| 72 | * |
| 73 | * The void(bool) function will get passed the new |
| 74 | * value of the host state. |
| 75 | * |
| 76 | * @param[in] name - The subscription name |
| 77 | * @param[in] func - The function to run |
| 78 | */ |
| 79 | void subscribeToHostStateChange(const std::string& name, |
| 80 | HostStateChangeFunc func) |
| 81 | { |
| 82 | _hostChangeCallbacks[name] = func; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @brief Unsubscribe from host state changes. |
| 87 | * |
| 88 | * @param[in] name - The subscription name |
| 89 | */ |
| 90 | void unsubscribeFromHostStateChange(const std::string& name) |
| 91 | { |
| 92 | _hostChangeCallbacks.erase(name); |
| 93 | } |
| 94 | |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 95 | /** |
| 96 | * @brief Returns the BMC firmware version |
| 97 | * |
| 98 | * @return std::string - The BMC version |
| 99 | */ |
| 100 | virtual std::string getBMCFWVersion() const |
| 101 | { |
| 102 | return _bmcFWVersion; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @brief Returns the server firmware version |
| 107 | * |
| 108 | * @return std::string - The server firmware version |
| 109 | */ |
| 110 | virtual std::string getServerFWVersion() const |
| 111 | { |
| 112 | return _serverFWVersion; |
| 113 | } |
| 114 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 115 | /** |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 116 | * @brief Returns the BMC FW version ID |
| 117 | * |
| 118 | * @return std::string - The BMC FW version ID |
| 119 | */ |
| 120 | virtual std::string getBMCFWVersionID() const |
| 121 | { |
| 122 | return _bmcFWVersionID; |
| 123 | } |
| 124 | |
| 125 | /** |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 126 | * @brief Returns the process name given its PID. |
| 127 | * |
| 128 | * @param[in] pid - The PID value as a string |
| 129 | * |
| 130 | * @return std::optional<std::string> - The name, or std::nullopt |
| 131 | */ |
| 132 | std::optional<std::string> getProcessName(const std::string& pid) const |
| 133 | { |
| 134 | namespace fs = std::filesystem; |
| 135 | |
| 136 | fs::path path{"/proc"}; |
| 137 | path /= fs::path{pid} / "exe"; |
| 138 | |
| 139 | if (fs::exists(path)) |
| 140 | { |
| 141 | return fs::read_symlink(path); |
| 142 | } |
| 143 | |
| 144 | return std::nullopt; |
| 145 | } |
| 146 | |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 147 | /** |
George Liu | 9ac0d9b | 2022-07-15 10:57:38 +0800 | [diff] [blame] | 148 | * @brief Returns the time the system was running. |
| 149 | * |
| 150 | * @return std::optional<uint64_t> - The System uptime or std::nullopt |
| 151 | */ |
| 152 | std::optional<uint64_t> getUptimeInSeconds() const |
| 153 | { |
| 154 | std::ifstream versionFile{"/proc/uptime"}; |
| 155 | std::string line{}; |
| 156 | |
| 157 | std::getline(versionFile, line); |
| 158 | auto pos = line.find(" "); |
| 159 | if (pos == std::string::npos) |
| 160 | { |
| 161 | return std::nullopt; |
| 162 | } |
| 163 | |
| 164 | uint64_t seconds = atol(line.substr(0, pos).c_str()); |
| 165 | if (seconds == 0) |
| 166 | { |
| 167 | return std::nullopt; |
| 168 | } |
| 169 | |
| 170 | return seconds; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * @brief Returns the time the system was running. |
| 175 | * |
| 176 | * @param[in] seconds - The number of seconds the system has been running |
| 177 | * |
| 178 | * @return std::string - days/hours/minutes/seconds |
| 179 | */ |
| 180 | std::string getBMCUptime(uint64_t seconds) const |
| 181 | { |
| 182 | time_t t(seconds); |
| 183 | tm* p = gmtime(&t); |
| 184 | |
| 185 | std::string uptime = std::to_string(p->tm_year - 70) + "y " + |
| 186 | std::to_string(p->tm_yday) + "d " + |
| 187 | std::to_string(p->tm_hour) + "h " + |
| 188 | std::to_string(p->tm_min) + "m " + |
| 189 | std::to_string(p->tm_sec) + "s"; |
| 190 | |
| 191 | return uptime; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * @brief Returns the system load average over the past 1 minute, 5 minutes |
| 196 | * and 15 minutes. |
| 197 | * |
| 198 | * @return std::string - The system load average |
| 199 | */ |
| 200 | std::string getBMCLoadAvg() const |
| 201 | { |
| 202 | std::string loadavg{}; |
| 203 | |
| 204 | std::ifstream loadavgFile{"/proc/loadavg"}; |
| 205 | std::string line; |
| 206 | std::getline(loadavgFile, line); |
| 207 | |
| 208 | size_t count = 3; |
| 209 | for (size_t i = 0; i < count; i++) |
| 210 | { |
| 211 | auto pos = line.find(" "); |
| 212 | if (pos == std::string::npos) |
| 213 | { |
| 214 | return {}; |
| 215 | } |
| 216 | |
| 217 | if (i != count - 1) |
| 218 | { |
| 219 | loadavg.append(line.substr(0, pos + 1)); |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | loadavg.append(line.substr(0, pos)); |
| 224 | } |
| 225 | |
| 226 | line = line.substr(pos + 1); |
| 227 | } |
| 228 | |
| 229 | return loadavg; |
| 230 | } |
| 231 | |
| 232 | /** |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 233 | * @brief Returns the 'send event logs to host' setting. |
| 234 | * |
| 235 | * @return bool - If sending PELs to the host is enabled. |
| 236 | */ |
| 237 | virtual bool getHostPELEnablement() const |
| 238 | { |
| 239 | return _sendPELsToHost; |
| 240 | } |
| 241 | |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 242 | /** |
| 243 | * @brief Returns the BMC state |
| 244 | * |
| 245 | * @return std::string - The BMC state property value |
| 246 | */ |
| 247 | virtual std::string getBMCState() const |
| 248 | { |
| 249 | return _bmcState; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * @brief Returns the Chassis state |
| 254 | * |
| 255 | * @return std::string - The chassis state property value |
| 256 | */ |
| 257 | virtual std::string getChassisState() const |
| 258 | { |
| 259 | return _chassisState; |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * @brief Returns the chassis requested power |
| 264 | * transition value. |
| 265 | * |
| 266 | * @return std::string - The chassis transition property |
| 267 | */ |
| 268 | virtual std::string getChassisTransition() const |
| 269 | { |
| 270 | return _chassisTransition; |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * @brief Returns the Host state |
| 275 | * |
| 276 | * @return std::string - The Host state property value |
| 277 | */ |
| 278 | virtual std::string getHostState() const |
| 279 | { |
| 280 | return _hostState; |
| 281 | } |
| 282 | |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 283 | /** |
Sumit Kumar | 2c36fdd | 2021-09-21 03:12:11 -0500 | [diff] [blame] | 284 | * @brief Returns the Boot state |
| 285 | * |
| 286 | * @return std::string - The Boot state property value |
| 287 | */ |
| 288 | virtual std::string getBootState() const |
| 289 | { |
| 290 | return _bootState; |
| 291 | } |
| 292 | |
| 293 | /** |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 294 | * @brief Returns the motherboard CCIN |
| 295 | * |
| 296 | * @return std::string The motherboard CCIN |
| 297 | */ |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 298 | virtual std::string getMotherboardCCIN() const = 0; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 299 | |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 300 | /** |
Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 301 | * @brief Returns the system IM |
| 302 | * |
| 303 | * @return std::string The system IM |
| 304 | */ |
| 305 | virtual std::vector<uint8_t> getSystemIMKeyword() const = 0; |
| 306 | |
| 307 | /** |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 308 | * @brief Get the fields from the inventory necessary for doing |
| 309 | * a callout on an inventory path. |
| 310 | * |
| 311 | * @param[in] inventoryPath - The item to get the data for |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 312 | * @param[out] fruPartNumber - Filled in with the VINI/FN keyword |
| 313 | * @param[out] ccin - Filled in with the VINI/CC keyword |
| 314 | * @param[out] serialNumber - Filled in with the VINI/SN keyword |
| 315 | */ |
| 316 | virtual void getHWCalloutFields(const std::string& inventoryPath, |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 317 | std::string& fruPartNumber, |
| 318 | std::string& ccin, |
| 319 | std::string& serialNumber) const = 0; |
| 320 | |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 321 | /** |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 322 | * @brief Get the location code for an inventory item. |
| 323 | * |
| 324 | * @param[in] inventoryPath - The item to get the data for |
| 325 | * |
| 326 | * @return std::string - The location code |
| 327 | */ |
| 328 | virtual std::string |
| 329 | getLocationCode(const std::string& inventoryPath) const = 0; |
| 330 | |
| 331 | /** |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 332 | * @brief Get the list of system type names the system is called. |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 333 | * |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 334 | * @return std::vector<std::string> - The list of names |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 335 | */ |
Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 336 | virtual std::vector<std::string> getSystemNames() const = 0; |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 337 | |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 338 | /** |
| 339 | * @brief Fills in the placeholder 'Ufcs' in the passed in location |
| 340 | * code with the machine feature code and serial number, which |
| 341 | * is needed to create a valid location code. |
| 342 | * |
| 343 | * @param[in] locationCode - Location code value starting with Ufcs-, and |
| 344 | * if that isn't present it will be added first. |
| 345 | * |
| 346 | * @param[in] node - The node number the location is on. |
| 347 | * |
| 348 | * @return std::string - The expanded location code |
| 349 | */ |
| 350 | virtual std::string expandLocationCode(const std::string& locationCode, |
| 351 | uint16_t node) const = 0; |
| 352 | |
| 353 | /** |
| 354 | * @brief Returns the inventory path for the FRU that the location |
| 355 | * code represents. |
| 356 | * |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 357 | * @param[in] locationCode - If an expanded location code, then the |
| 358 | * full location code. |
| 359 | * If not expanded, a location code value |
| 360 | * starting with Ufcs-, and if that isn't |
| 361 | * present it will be added first. |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 362 | * |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 363 | * @param[in] node - The node number the location is on. Ignored if the |
| 364 | * expanded location code is passed in. |
| 365 | * |
| 366 | * @param[in] expanded - If the location code already has the relevent |
| 367 | * VPD fields embedded in it. |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 368 | * |
| 369 | * @return std::string - The inventory D-Bus object |
| 370 | */ |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 371 | virtual std::string getInventoryFromLocCode(const std::string& LocationCode, |
| 372 | uint16_t node, |
| 373 | bool expanded) const = 0; |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 374 | |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 375 | /** |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 376 | * @brief Sets the Asserted property on the LED group passed in. |
| 377 | * |
| 378 | * @param[in] ledGroup - The LED group D-Bus path |
| 379 | * @param[in] value - The value to set it to |
| 380 | */ |
| 381 | virtual void assertLEDGroup(const std::string& ledGroup, |
| 382 | bool value) const = 0; |
| 383 | |
Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 384 | /** |
| 385 | * @brief Sets the Functional property on the OperationalStatus |
| 386 | * interface on a D-Bus object. |
| 387 | * |
| 388 | * @param[in] objectPath - The D-Bus object path |
| 389 | * @param[in] functional - The value |
| 390 | */ |
| 391 | virtual void setFunctional(const std::string& objectPath, |
| 392 | bool functional) const = 0; |
| 393 | |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 394 | /** |
Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 395 | * @brief Sets the critical association on the D-Bus object. |
| 396 | * |
| 397 | * @param[in] objectPath - The D-Bus object path |
| 398 | */ |
| 399 | virtual void |
| 400 | setCriticalAssociation(const std::string& objectPath) const = 0; |
| 401 | |
| 402 | /** |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 403 | * @brief Returns the manufacturing QuiesceOnError property |
| 404 | * |
| 405 | * @return bool - Manufacturing QuiesceOnError property |
| 406 | */ |
| 407 | virtual bool getQuiesceOnError() const = 0; |
| 408 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 409 | /** |
| 410 | * @brief Split location code into base and connector segments |
| 411 | * |
| 412 | * A location code that ends in '-Tx', where 'x' is a number, |
| 413 | * represents a connector, such as a USB cable connector. |
| 414 | * |
| 415 | * This function splits the passed in location code into a |
| 416 | * base and connector segment. e.g.: |
| 417 | * P0-T1 -> ['P0', '-T1'] |
| 418 | * P0 -> ['P0', ''] |
| 419 | * |
| 420 | * @param[in] locationCode - location code to split |
| 421 | * @return pair<string, string> - The base and connector segments |
| 422 | */ |
| 423 | static std::pair<std::string, std::string> |
| 424 | extractConnectorFromLocCode(const std::string& locationCode); |
| 425 | |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 426 | /** |
| 427 | * @brief Returns the dump status |
| 428 | * |
| 429 | * @return bool dump status |
| 430 | */ |
| 431 | virtual std::vector<bool> |
| 432 | checkDumpStatus(const std::vector<std::string>& type) const = 0; |
| 433 | |
Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 434 | /** |
| 435 | * @brief Create guard record |
| 436 | * |
| 437 | * @param[in] binPath: phal devtree binary path used as key |
| 438 | * @param[in] type: Guard type |
| 439 | * @param[in] logPath: error log entry object path |
| 440 | */ |
| 441 | virtual void createGuardRecord(const std::vector<uint8_t>& binPath, |
| 442 | const std::string& type, |
| 443 | const std::string& logPath) const = 0; |
| 444 | |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 445 | /** |
| 446 | * @brief Create Progress SRC property on the boot progress |
| 447 | * interface on a D-Bus object. |
| 448 | * |
| 449 | * @param[in] priSRC - Primary SRC value (e.g. BD8D1001) |
| 450 | * @param[in] srcStruct - Full SRC base structure |
| 451 | */ |
| 452 | virtual void |
| 453 | createProgressSRC(const uint64_t& priSRC, |
| 454 | const std::vector<uint8_t>& srcStruct) const = 0; |
| 455 | |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 456 | /** |
| 457 | * @brief Get the list of unresolved OpenBMC event log ids that have an |
| 458 | * associated hardware isolation entry. |
| 459 | * |
| 460 | * @return std::vector<uint32_t> - The list of log ids |
| 461 | */ |
| 462 | virtual std::vector<uint32_t> getLogIDWithHwIsolation() const = 0; |
| 463 | |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame] | 464 | protected: |
| 465 | /** |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 466 | * @brief Sets the host on/off state and runs any |
| 467 | * callback functions (if there was a change). |
| 468 | */ |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 469 | void setHostUp(bool hostUp) |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 470 | { |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 471 | if (_hostUp != hostUp) |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 472 | { |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 473 | _hostUp = hostUp; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 474 | |
| 475 | for (auto& [name, func] : _hostChangeCallbacks) |
| 476 | { |
| 477 | try |
| 478 | { |
| 479 | func(_hostUp); |
| 480 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 481 | catch (const std::exception& e) |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 482 | { |
| 483 | using namespace phosphor::logging; |
| 484 | log<level::ERR>("A host state change callback threw " |
| 485 | "an exception"); |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | /** |
Matt Spinler | cce1411 | 2019-12-11 14:20:36 -0600 | [diff] [blame] | 492 | * @brief The hardware management console status. Always kept |
| 493 | * up to date. |
| 494 | */ |
| 495 | bool _hmcManaged = false; |
| 496 | |
| 497 | /** |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 498 | * @brief The host up status. Always kept up to date. |
| 499 | */ |
| 500 | bool _hostUp = false; |
| 501 | |
| 502 | /** |
| 503 | * @brief The map of host state change subscriber |
| 504 | * names to callback functions. |
| 505 | */ |
| 506 | std::map<std::string, HostStateChangeFunc> _hostChangeCallbacks; |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 507 | |
| 508 | /** |
| 509 | * @brief The BMC firmware version string |
| 510 | */ |
| 511 | std::string _bmcFWVersion; |
| 512 | |
| 513 | /** |
| 514 | * @brief The server firmware version string |
| 515 | */ |
| 516 | std::string _serverFWVersion; |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 517 | |
| 518 | /** |
| 519 | * @brief The BMC firmware version ID string |
| 520 | */ |
| 521 | std::string _bmcFWVersionID; |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 522 | |
| 523 | /** |
| 524 | * @brief If sending PELs is enabled. |
| 525 | * |
| 526 | * This is usually set to false in manufacturing test. |
| 527 | */ |
| 528 | bool _sendPELsToHost = true; |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 529 | |
| 530 | /** |
| 531 | * @brief The BMC state property |
| 532 | */ |
| 533 | std::string _bmcState; |
| 534 | |
| 535 | /** |
| 536 | * @brief The Chassis current power state property |
| 537 | */ |
| 538 | std::string _chassisState; |
| 539 | |
| 540 | /** |
| 541 | * @brief The Chassis requested power transition property |
| 542 | */ |
| 543 | std::string _chassisTransition; |
| 544 | |
| 545 | /** |
| 546 | * @brief The host state property |
| 547 | */ |
| 548 | std::string _hostState; |
Sumit Kumar | 2c36fdd | 2021-09-21 03:12:11 -0500 | [diff] [blame] | 549 | |
| 550 | /** |
| 551 | * @brief The boot state property |
| 552 | */ |
| 553 | std::string _bootState; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 554 | }; |
| 555 | |
| 556 | /** |
| 557 | * @class DataInterface |
| 558 | * |
| 559 | * Concrete implementation of DataInterfaceBase. |
| 560 | */ |
| 561 | class DataInterface : public DataInterfaceBase |
| 562 | { |
| 563 | public: |
| 564 | DataInterface() = delete; |
| 565 | ~DataInterface() = default; |
| 566 | DataInterface(const DataInterface&) = default; |
| 567 | DataInterface& operator=(const DataInterface&) = default; |
| 568 | DataInterface(DataInterface&&) = default; |
| 569 | DataInterface& operator=(DataInterface&&) = default; |
| 570 | |
| 571 | /** |
| 572 | * @brief Constructor |
| 573 | * |
| 574 | * @param[in] bus - The sdbusplus bus object |
| 575 | */ |
| 576 | explicit DataInterface(sdbusplus::bus::bus& bus); |
| 577 | |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 578 | /** |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 579 | * @brief Finds the D-Bus service name that hosts the |
| 580 | * passed in path and interface. |
| 581 | * |
| 582 | * @param[in] objectPath - The D-Bus object path |
| 583 | * @param[in] interface - The D-Bus interface |
| 584 | */ |
| 585 | DBusService getService(const std::string& objectPath, |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 586 | const std::string& interface) const; |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 587 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 588 | /** |
| 589 | * @brief Wrapper for the 'GetAll' properties method call |
| 590 | * |
| 591 | * @param[in] service - The D-Bus service to call it on |
| 592 | * @param[in] objectPath - The D-Bus object path |
| 593 | * @param[in] interface - The interface to get the props on |
| 594 | * |
| 595 | * @return DBusPropertyMap - The property results |
| 596 | */ |
| 597 | DBusPropertyMap getAllProperties(const std::string& service, |
| 598 | const std::string& objectPath, |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 599 | const std::string& interface) const; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 600 | /** |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 601 | * @brief Wrapper for the 'Get' properties method call |
| 602 | * |
| 603 | * @param[in] service - The D-Bus service to call it on |
| 604 | * @param[in] objectPath - The D-Bus object path |
| 605 | * @param[in] interface - The interface to get the property on |
| 606 | * @param[in] property - The property name |
| 607 | * @param[out] value - Filled in with the property value. |
| 608 | */ |
| 609 | void getProperty(const std::string& service, const std::string& objectPath, |
| 610 | const std::string& interface, const std::string& property, |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 611 | DBusValue& value) const; |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 612 | /** |
| 613 | * @brief Returns the machine Type/Model |
| 614 | * |
| 615 | * @return string - The machine Type/Model string |
| 616 | */ |
| 617 | std::string getMachineTypeModel() const override; |
| 618 | |
| 619 | /** |
| 620 | * @brief Returns the machine serial number |
| 621 | * |
| 622 | * @return string - The machine serial number |
| 623 | */ |
| 624 | std::string getMachineSerialNumber() const override; |
| 625 | |
| 626 | /** |
| 627 | * @brief Returns the motherboard CCIN |
| 628 | * |
| 629 | * @return std::string The motherboard CCIN |
| 630 | */ |
| 631 | std::string getMotherboardCCIN() const override; |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 632 | |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 633 | /** |
Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 634 | * @brief Returns the system IM |
| 635 | * |
| 636 | * @return std::vector The system IM keyword in 4 byte vector |
| 637 | */ |
| 638 | std::vector<uint8_t> getSystemIMKeyword() const override; |
| 639 | |
| 640 | /** |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 641 | * @brief Get the fields from the inventory necessary for doing |
| 642 | * a callout on an inventory path. |
| 643 | * |
| 644 | * @param[in] inventoryPath - The item to get the data for |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 645 | * @param[out] fruPartNumber - Filled in with the VINI/FN keyword |
| 646 | * @param[out] ccin - Filled in with the VINI/CC keyword |
| 647 | * @param[out] serialNumber - Filled in with the VINI/SN keyword |
| 648 | */ |
| 649 | void getHWCalloutFields(const std::string& inventoryPath, |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 650 | std::string& fruPartNumber, std::string& ccin, |
| 651 | std::string& serialNumber) const override; |
| 652 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 653 | /** |
| 654 | * @brief Get the location code for an inventory item. |
| 655 | * |
| 656 | * Throws an exception if the inventory item doesn't have the |
| 657 | * location code interface. |
| 658 | * |
| 659 | * @param[in] inventoryPath - The item to get the data for |
| 660 | * |
| 661 | * @return std::string - The location code |
| 662 | */ |
| 663 | std::string |
| 664 | getLocationCode(const std::string& inventoryPath) const override; |
| 665 | |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 666 | /** |
Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 667 | * @brief Get the list of system type names the system is called. |
| 668 | * |
| 669 | * @return std::vector<std::string> - The list of names |
| 670 | */ |
| 671 | std::vector<std::string> getSystemNames() const override; |
| 672 | |
| 673 | /** |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 674 | * @brief Fills in the placeholder 'Ufcs' in the passed in location |
| 675 | * code with the machine feature code and serial number, which |
| 676 | * is needed to create a valid location code. |
| 677 | * |
| 678 | * @param[in] locationCode - Location code value starting with Ufcs-, and |
| 679 | * if that isn't present it will be added first. |
| 680 | * |
| 681 | * @param[in] node - The node number the location is one. |
| 682 | * |
| 683 | * @return std::string - The expanded location code |
| 684 | */ |
| 685 | std::string expandLocationCode(const std::string& locationCode, |
| 686 | uint16_t node) const override; |
| 687 | |
| 688 | /** |
| 689 | * @brief Returns the inventory path for the FRU that the location |
| 690 | * code represents. |
| 691 | * |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 692 | * @param[in] locationCode - If an expanded location code, then the |
| 693 | * full location code. |
| 694 | * If not expanded, a location code value |
| 695 | * starting with Ufcs-, and if that isn't |
| 696 | * present it will be added first. |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 697 | * |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 698 | * @param[in] node - The node number the location is on. Ignored if the |
| 699 | * expanded location code is passed in. |
| 700 | * |
| 701 | * @param[in] expanded - If the location code already has the relevent |
| 702 | * VPD fields embedded in it. |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 703 | * |
| 704 | * @return std::string - The inventory D-Bus object |
| 705 | */ |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 706 | std::string getInventoryFromLocCode(const std::string& locationCode, |
| 707 | uint16_t node, |
| 708 | bool expanded) const override; |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 709 | |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 710 | /** |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 711 | * @brief Sets the Asserted property on the LED group passed in. |
| 712 | * |
| 713 | * @param[in] ledGroup - The LED group D-Bus path |
| 714 | * @param[in] value - The value to set it to |
| 715 | */ |
| 716 | void assertLEDGroup(const std::string& ledGroup, bool value) const override; |
| 717 | |
Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 718 | /** |
| 719 | * @brief Sets the Functional property on the OperationalStatus |
| 720 | * interface on a D-Bus object. |
| 721 | * |
| 722 | * @param[in] objectPath - The D-Bus object path |
| 723 | * @param[in] functional - The value |
| 724 | */ |
| 725 | void setFunctional(const std::string& objectPath, |
| 726 | bool functional) const override; |
| 727 | |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 728 | /** |
Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 729 | * @brief Sets the critical association on the D-Bus object. |
| 730 | * |
| 731 | * @param[in] objectPath - The D-Bus object path |
| 732 | */ |
| 733 | void setCriticalAssociation(const std::string& objectPath) const override; |
| 734 | |
| 735 | /** |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 736 | * @brief Returns the manufacturing QuiesceOnError property |
| 737 | * |
| 738 | * @return bool - Manufacturing QuiesceOnError property |
| 739 | */ |
| 740 | bool getQuiesceOnError() const override; |
| 741 | |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 742 | /** |
| 743 | * @brief Returns the dump status |
| 744 | * |
| 745 | * @param[in] type - The dump type to check for |
| 746 | * |
| 747 | * @return bool dump status |
| 748 | */ |
| 749 | std::vector<bool> |
| 750 | checkDumpStatus(const std::vector<std::string>& type) const override; |
| 751 | |
Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 752 | /** |
| 753 | * @brief Create guard record |
| 754 | * |
| 755 | * @param[in] binPath: phal devtree binary path used as key |
| 756 | * @param[in] type: Guard type |
| 757 | * @param[in] logPath: error log entry object path |
| 758 | */ |
| 759 | void createGuardRecord(const std::vector<uint8_t>& binPath, |
| 760 | const std::string& type, |
| 761 | const std::string& logPath) const override; |
| 762 | |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 763 | /** |
| 764 | * @brief Create Progress SRC property on the boot progress |
| 765 | * interface on a D-Bus object. |
| 766 | * |
| 767 | * @param[in] priSRC - Primary SRC value |
| 768 | * @param[in] srcStruct - Full SRC base structure |
| 769 | */ |
| 770 | void |
| 771 | createProgressSRC(const uint64_t& priSRC, |
| 772 | const std::vector<uint8_t>& srcStruct) const override; |
| 773 | |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 774 | /** |
| 775 | * @brief Get the list of unresolved OpenBMC event log ids that have an |
| 776 | * associated hardware isolation entry. |
| 777 | * |
| 778 | * @return std::vector<uint32_t> - The list of log ids |
| 779 | */ |
| 780 | std::vector<uint32_t> getLogIDWithHwIsolation() const override; |
| 781 | |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 782 | private: |
| 783 | /** |
| 784 | * @brief Reads the BMC firmware version string and puts it into |
| 785 | * _bmcFWVersion. |
| 786 | */ |
| 787 | void readBMCFWVersion(); |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 788 | |
| 789 | /** |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 790 | * @brief Reads the server firmware version string and puts it into |
| 791 | * _serverFWVersion. |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 792 | */ |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 793 | void readServerFWVersion(); |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 794 | |
| 795 | /** |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 796 | * @brief Reads the BMC firmware version ID and puts it into |
| 797 | * _bmcFWVersionID. |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 798 | */ |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 799 | void readBMCFWVersionID(); |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 800 | |
| 801 | /** |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 802 | * @brief Finds all D-Bus paths that contain any of the interfaces |
| 803 | * passed in, by using GetSubTreePaths. |
| 804 | * |
| 805 | * @param[in] interfaces - The desired interfaces |
| 806 | * |
| 807 | * @return The D-Bus paths. |
| 808 | */ |
| 809 | DBusPathList getPaths(const DBusInterfaceList& interfaces) const; |
| 810 | |
| 811 | /** |
| 812 | * @brief The interfacesAdded callback used on the inventory to |
| 813 | * find the D-Bus object that has the motherboard interface. |
| 814 | * When the motherboard is found, it then adds a PropertyWatcher |
| 815 | * for the motherboard CCIN. |
| 816 | */ |
| 817 | void motherboardIfaceAdded(sdbusplus::message::message& msg); |
| 818 | |
| 819 | /** |
Matt Spinler | 0e4d72e | 2020-08-05 12:36:53 -0500 | [diff] [blame] | 820 | * @brief Adds the Ufcs- prefix to the location code passed in |
| 821 | * if necessary. |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 822 | * |
Matt Spinler | 0e4d72e | 2020-08-05 12:36:53 -0500 | [diff] [blame] | 823 | * Needed because the location codes that come back from the |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 824 | * message registry and device callout JSON don't have it. |
| 825 | * |
| 826 | * @param[in] - The location code without a prefix, like P1-C1 |
| 827 | * |
| 828 | * @return std::string - The location code with the prefix |
| 829 | */ |
| 830 | static std::string addLocationCodePrefix(const std::string& locationCode); |
| 831 | |
| 832 | /** |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 833 | * @brief The D-Bus property or interface watchers that have callbacks |
| 834 | * registered that will set members in this class when |
| 835 | * they change. |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 836 | */ |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 837 | std::vector<std::unique_ptr<DBusWatcher>> _properties; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 838 | |
| 839 | /** |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 840 | * @brief The sdbusplus bus object for making D-Bus calls. |
| 841 | */ |
| 842 | sdbusplus::bus::bus& _bus; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 843 | |
| 844 | /** |
| 845 | * @brief The interfacesAdded match object used to wait for inventory |
| 846 | * interfaces to show up, so that the object with the motherboard |
| 847 | * interface can be found. After it is found, this object is |
| 848 | * deleted. |
| 849 | */ |
| 850 | std::unique_ptr<sdbusplus::bus::match_t> _inventoryIfacesAddedMatch; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 851 | }; |
| 852 | |
| 853 | } // namespace pels |
| 854 | } // namespace openpower |