summaryrefslogtreecommitdiff
path: root/psu-manager/include/cold_redundancy.hpp
blob: cd7a5f667ec1880665d5b1701d93a94023a3086f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
// 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 <sdbusplus/asio/object_server.hpp>
#include <utility.hpp>
#include <xyz/openbmc_project/Control/PowerSupplyRedundancy/server.hpp>

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<std::string, std::string, std::string>;

class ColdRedundancy
    : sdbusplus::xyz::openbmc_project::Control::server::PowerSupplyRedundancy
{
  public:
    ColdRedundancy(
        boost::asio::io_service& io,
        sdbusplus::asio::object_server& objectServer,
        std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
        std::vector<std::unique_ptr<sdbusplus::bus::match::match>>& 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<sdbusplus::asio::connection>& 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<sdbusplus::asio::connection>& 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<sdbusplus::asio::dbus_interface> association;
    std::vector<Association> associationsOk;
    std::vector<Association> associationsWarning;
    std::vector<Association> associationsNonCrit;
    std::vector<Association> associationsCrit;
};

constexpr const uint8_t pmbusCmdCRSupport = 0xd0;

class PowerSupply
{
  public:
    PowerSupply(
        std::string name, uint8_t bus, uint8_t address,
        const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection);
    ~PowerSupply();
    std::string name;
    uint8_t order = 0;
    uint8_t bus;
    uint8_t address;
    PSUState state = PSUState::normal;
};