/* // Copyright (c) 2019 Intel Corporation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. */ #include #include #include const constexpr char* psuInterface = "/xyz/openbmc_project/inventory/system/powersupply/"; const constexpr int secondsInOneDay = 86400; const constexpr uint8_t bmcSpecific = 0; using Association = std::tuple; class ColdRedundancy : sdbusplus::xyz::openbmc_project::Control::server::PowerSupplyRedundancy { public: ColdRedundancy( boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer, std::shared_ptr& dbusConnection, std::vector>& matches); ~ColdRedundancy() { objServer.remove_interface(association); }; uint8_t pSUNumber() const override; void createPSU(boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer, std::shared_ptr& dbusConnection); private: bool crSupported = true; bool crEnabled = true; bool rotationEnabled = true; std::string rotationAlgo = "xyz.openbmc_project.Control.PowerSupplyRedundancy.Algo.bmcSpecific"; uint8_t psOrder; uint8_t numberOfPSU = 0; uint32_t rotationPeriod = 7 * secondsInOneDay; uint8_t redundancyPSURequire = 1; void startRotateCR(void); void startCRCheck(void); void rotateCR(void); void configCR(bool reConfig); void checkCR(void); void reRanking(void); void putWarmRedundant(void); void keepAliveCheck(void); void checkRedundancyEvent(); sdbusplus::asio::object_server& objServer; std::shared_ptr& systemBus; boost::asio::steady_timer timerRotation; boost::asio::steady_timer timerCheck; boost::asio::steady_timer warmRedundantTimer1; boost::asio::steady_timer warmRedundantTimer2; boost::asio::steady_timer keepAliveTimer; boost::asio::steady_timer filterTimer; boost::asio::steady_timer puRedundantTimer; std::shared_ptr association; std::vector associationsOk; std::vector associationsWarning; std::vector associationsNonCrit; std::vector associationsCrit; }; constexpr const uint8_t pmbusCmdCRSupport = 0xd0; class PowerSupply { public: PowerSupply( std::string name, uint8_t bus, uint8_t address, const std::shared_ptr& dbusConnection); ~PowerSupply(); std::string name; uint8_t order = 0; uint8_t bus; uint8_t address; PSUState state = PSUState::normal; };