summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng C Yang <cheng.c.yang@intel.com>2019-10-17 05:51:29 +0300
committerYang, Cheng C <cheng.c.yang@intel.com>2019-10-21 04:10:39 +0300
commit30110fe5b18999bddc5721dc5611f542f6feeabd (patch)
treeb26ac02347f43784a3d14285ad99e37c4aa504eb
parent9c24aa3036ed82bbc0e9182e1722a5a8dd87a642 (diff)
downloadprovingground-30110fe5b18999bddc5721dc5611f542f6feeabd.tar.xz
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 <cheng.c.yang@intel.com>
-rw-r--r--psu-manager/include/utility.hpp2
-rw-r--r--psu-manager/src/cold_redundancy.cpp9
-rw-r--r--psu-manager/src/utility.cpp57
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;
}