blob: b7d4276fb00c3861c41b02ca96fe22495d9f060c [file] [log] [blame]
Edward A. James636577f2017-10-06 10:53:55 -05001#include "occ_presence.hpp"
Gunnar Mills94df8c92018-09-14 14:50:03 -05002
Gunnar Mills94df8c92018-09-14 14:50:03 -05003#include "occ_manager.hpp"
4
5#include <errno.h>
6#include <fcntl.h>
7#include <sys/ioctl.h>
8#include <unistd.h>
9
10#include <org/open_power/OCC/Device/error.hpp>
Patrick Williamsd8aab2a2023-04-21 11:15:54 -050011#include <phosphor-logging/elog-errors.hpp>
Gunnar Mills94df8c92018-09-14 14:50:03 -050012#include <phosphor-logging/elog.hpp>
Chris Cain37abe9b2024-10-31 17:20:31 -050013#include <phosphor-logging/lg2.hpp>
Gunnar Mills94df8c92018-09-14 14:50:03 -050014#include <xyz/openbmc_project/Common/error.hpp>
Edward A. James636577f2017-10-06 10:53:55 -050015
16namespace open_power
17{
18namespace occ
19{
20
21// Reads the occs_present file and analyzes the data
22void 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 Mills94df8c92018-09-14 14:50:03 -050033 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. James636577f2017-10-06 10:53:55 -050037 }
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 Cain37abe9b2024-10-31 17:20:31 -050049 lg2::error("OCC presence mismatch - BMC: {BNUM}, OCC: {ONUM}", "BNUM",
50 manager.getNumOCCs(), "ONUM", occsPresent);
Edward A. James636577f2017-10-06 10:53:55 -050051 if (callBack)
52 {
Eddie James9789e712022-05-25 15:43:40 -050053 callBack(occsPresent);
Edward A. James636577f2017-10-06 10:53:55 -050054 }
55 }
56}
57
58} // namespace occ
59} // namespace open_power