From 30110fe5b18999bddc5721dc5611f542f6feeabd Mon Sep 17 00:00:00 2001 From: Cheng C Yang Date: Thu, 17 Oct 2019 10:51:29 +0800 Subject: Fix keeping printing i2c error issue i2cget function in cold redundancy will keep printing i2c error message in BMC debug console when there is only one PSU in the system. Add a ping flag to fix this. Tested: Only insert one PSU, BMC console will not keep printing i2c error message. Change-Id: I639b7fe036fd383fbdbc4c4868c77560cc91a63c Signed-off-by: Cheng C Yang --- psu-manager/include/utility.hpp | 2 ++ psu-manager/src/cold_redundancy.cpp | 9 ++++-- 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> powerSupplies; -static uint8_t pmbusNum = 7; static std::vector 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(*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( + "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( + "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( + "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( + "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; } -- cgit v1.2.3