Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 1 | #include "occ_presence.hpp" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 2 | |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 3 | #include "elog-errors.hpp" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 4 | #include "occ_manager.hpp" |
| 5 | |
| 6 | #include <errno.h> |
| 7 | #include <fcntl.h> |
| 8 | #include <sys/ioctl.h> |
| 9 | #include <unistd.h> |
| 10 | |
| 11 | #include <org/open_power/OCC/Device/error.hpp> |
| 12 | #include <phosphor-logging/elog.hpp> |
| 13 | #include <phosphor-logging/log.hpp> |
| 14 | #include <xyz/openbmc_project/Common/error.hpp> |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 15 | |
| 16 | namespace open_power |
| 17 | { |
| 18 | namespace occ |
| 19 | { |
| 20 | |
| 21 | // Reads the occs_present file and analyzes the data |
| 22 | void Presence::analyzeEvent() |
| 23 | { |
| 24 | using namespace phosphor::logging; |
| 25 | using namespace sdbusplus::org::open_power::OCC::Device::Error; |
| 26 | |
| 27 | // Get the number of bytes to read |
| 28 | int len = -1; |
| 29 | auto r = ioctl(fd, FIONREAD, &len); |
| 30 | if (r < 0) |
| 31 | { |
| 32 | elog<ConfigFailure>( |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 33 | phosphor::logging::org::open_power::OCC::Device::ConfigFailure:: |
| 34 | CALLOUT_ERRNO(errno), |
| 35 | phosphor::logging::org::open_power::OCC::Device::ConfigFailure:: |
| 36 | CALLOUT_DEVICE_PATH(file.c_str())); |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | auto data = readFile(len); |
| 40 | if (data.empty()) |
| 41 | { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | // Let stoi determine the base |
| 46 | auto occsPresent = std::stoi(data, nullptr, 0); |
| 47 | if (manager.getNumOCCs() != occsPresent) |
| 48 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 49 | log<level::ERR>(fmt::format("OCC presence mismatch - BMC: {}, OCC: {}", |
| 50 | manager.getNumOCCs(), occsPresent) |
| 51 | .c_str()); |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 52 | if (callBack) |
| 53 | { |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 54 | callBack(true); |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | } // namespace occ |
| 60 | } // namespace open_power |