diff options
-rw-r--r-- | psu-manager/include/utility.hpp | 2 | ||||
-rw-r--r-- | psu-manager/src/cold_redundancy.cpp | 9 | ||||
-rw-r--r-- | psu-manager/src/utility.cpp | 57 |
3 files changed, 64 insertions, 4 deletions
diff --git a/psu-manager/include/utility.hpp b/psu-manager/include/utility.hpp index 882d151..d0df858 100644 --- a/psu-manager/include/utility.hpp +++ b/psu-manager/include/utility.hpp @@ -58,3 +58,5 @@ void getPSUEvent( int i2cSet(uint8_t bus, uint8_t slaveAddr, uint8_t regAddr, uint8_t value); int i2cGet(uint8_t bus, uint8_t slaveAddr, uint8_t regAddr, int& value); +int i2cPing(int fd, uint8_t slaveAddr); +int setPingFd(int& fd, uint64_t bus); diff --git a/psu-manager/src/cold_redundancy.cpp b/psu-manager/src/cold_redundancy.cpp index 86b23b3..c8fdcd4 100644 --- a/psu-manager/src/cold_redundancy.cpp +++ b/psu-manager/src/cold_redundancy.cpp @@ -42,8 +42,8 @@ static const constexpr char* coldRedundancyPath = "/xyz/openbmc_project/control/power_supply_redundancy"; static std::vector<std::unique_ptr<PowerSupply>> powerSupplies; -static uint8_t pmbusNum = 7; static std::vector<uint64_t> addrTable = {0x50, 0x51}; +static int pingFd = -1; ColdRedundancy::ColdRedundancy( boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer, @@ -256,7 +256,7 @@ static const constexpr uint8_t fruOffsetZero = 0x00; int pingPSU(const uint8_t& addr) { int fruData = 0; - return i2cGet(pmbusNum, addr, fruOffsetZero, fruData); + return i2cPing(pingFd, addr); } void rescanPSUEntityManager( @@ -427,8 +427,11 @@ void ColdRedundancy::createPSU( "entry in configuration\n"; return; } - pmbusNum = static_cast<uint8_t>(*psuBus); addrTable = *psuAddress; + if (setPingFd(pingFd, *psuBus)) + { + return; + } keepAliveCheck(); return; } diff --git a/psu-manager/src/utility.cpp b/psu-manager/src/utility.cpp index d54c2b0..5446dd9 100644 --- a/psu-manager/src/utility.cpp +++ b/psu-manager/src/utility.cpp @@ -83,6 +83,62 @@ int i2cSet(uint8_t bus, uint8_t slaveAddr, uint8_t regAddr, uint8_t value) return 0; } +int setPingFd(int& fd, uint64_t bus) +{ + if (fd > 0) + { + ::close(fd); + } + std::string pingPath = "/dev/i2c-" + std::to_string(bus); + fd = ::open(pingPath.c_str(), O_RDWR | O_CLOEXEC); + if (fd < 0) + { + phosphor::logging::log<phosphor::logging::level::ERR>( + "Error in open!", + phosphor::logging::entry("PATH=%s", pingPath.c_str())); + return -1; + } + + unsigned long funcs = 0; + if (::ioctl(fd, I2C_FUNCS, &funcs) < 0) + { + phosphor::logging::log<phosphor::logging::level::ERR>( + "Error in I2C_FUNCS!", + phosphor::logging::entry("PATH=%s", pingPath.c_str())); + ::close(fd); + return -1; + } + + if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE)) + { + phosphor::logging::log<phosphor::logging::level::ERR>( + "i2c bus does not support read!", + phosphor::logging::entry("PATH=%s", pingPath.c_str())); + ::close(fd); + return -1; + } + return 0; +} + +int i2cPing(int fd, uint8_t slaveAddr) +{ + if (::ioctl(fd, I2C_SLAVE_FORCE, slaveAddr) < 0) + { + phosphor::logging::log<phosphor::logging::level::ERR>( + "Error in I2C_SLAVE_FORCE!", + phosphor::logging::entry("SLAVEADDR=0x%x", slaveAddr)); + ::close(fd); + return -1; + } + + if (::i2c_smbus_read_byte(fd) < 0) + { + return -1; + } + + return 0; +} + int i2cGet(uint8_t bus, uint8_t slaveAddr, uint8_t regAddr, int& value) { unsigned long funcs = 0; @@ -138,7 +194,6 @@ int i2cGet(uint8_t bus, uint8_t slaveAddr, uint8_t regAddr, int& value) ::close(fd); return -1; } - ::close(fd); return 0; } |