-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvme_manager.hpp
168 lines (145 loc) · 5.52 KB
/
nvme_manager.hpp
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#pragma once
#include "config.h"
#include "nvmes.hpp"
#include "sdbusplus.hpp"
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server.hpp>
#include <sdbusplus/server/object.hpp>
#include <sdeventplus/clock.hpp>
#include <sdeventplus/event.hpp>
#include <sdeventplus/utility/timer.hpp>
#include <fstream>
namespace phosphor
{
namespace nvme
{
/** @class Nvme
* @brief Nvme manager implementation.
*/
class Nvme
{
public:
Nvme() = delete;
Nvme(const Nvme&) = delete;
Nvme& operator=(const Nvme&) = delete;
Nvme(Nvme&&) = delete;
Nvme& operator=(Nvme&&) = delete;
/** @brief Constructs Nvme
*
* @param[in] bus - Handle to system dbus
* @param[in] objPath - The dbus path of nvme
*/
Nvme(sdbusplus::bus_t& bus) :
bus(bus), _event(sdeventplus::Event::get_default()),
_timer(_event, std::bind(&Nvme::read, this))
{
// read json file
configs = getNvmeConfig();
}
/**
* Structure for keeping nvme configure data required by nvme monitoring
*/
struct NVMeConfig
{
std::string index;
uint8_t busID;
std::string faultLedGroupPath;
uint16_t presentPin;
uint16_t pwrGoodPin;
std::string locateLedControllerBusName;
std::string locateLedControllerPath;
std::string locateLedGroupPath;
int8_t criticalHigh;
int8_t criticalLow;
int8_t maxValue;
int8_t minValue;
int8_t warningHigh;
int8_t warningLow;
};
/**
* Structure for keeping nvme data required by nvme monitoring
*/
struct NVMeData
{
bool present; /* Whether or not the nvme is present */
std::string vendor; /* The nvme manufacturer */
std::string serialNumber; /* The nvme serial number */
std::string modelNumber; /* The nvme model number */
std::string smartWarnings; /* Indicates smart warnings for the state */
std::string statusFlags; /* Indicates the status of the drives */
std::string
driveLifeUsed; /* A vendor specific estimate of the percentage */
int8_t sensorValue; /* Sensor value, if sensor value didn't be
update, means sensor failure, default set to
129(0x81) according to NVMe-MI SPEC*/
int8_t wcTemp; /* Indicates over temperature warning threshold.
This is intended to initially match the temperature
reported in the WCTEMP field in the NVMe Identify
Controller data structure */
};
/** @brief Setup polling timer in a sd event loop and attach to D-Bus
* event loop.
*/
void run();
/** @brief Get GPIO value of nvme by sysfs */
std::string getGPIOValueOfNvme(const std::string& fullPath);
/** @brief Map of the object NvmeSSD */
std::unordered_map<std::string, std::shared_ptr<phosphor::nvme::NvmeSSD>>
nvmes;
/** @brief Set locate and fault LED status of SSD
*
* @param[in] config - Nvme configure data
* @param[in] success - Success or not that get NVMe Info by SMbus
* @param[in] nvmeData - Nvme information
*/
void setLEDsStatus(const phosphor::nvme::Nvme::NVMeConfig& config,
bool success,
const phosphor::nvme::Nvme::NVMeData& nvmeData);
/** @brief Set SSD fault LED status */
void setFaultLED(const std::string& locateLedGroupPath,
const std::string& ledPath, bool request);
/** @brief Set SSD locate LED status */
void setLocateLED(const std::string& ledPath,
const std::string& locateLedBusName,
const std::string& locateLedPath, bool ispresent);
/** @brief Get Identify State*/
bool getLEDGroupState(const std::string& ledPath);
/** @brief Set inventory properties of nvme */
void setNvmeInventoryProperties(
NVMeConfig& config, bool present,
const phosphor::nvme::Nvme::NVMeData& nvmeData,
const std::string& inventoryPath);
void createNVMeInventory();
/** @brief read NVMe information via Smbus */
bool getNVMeInfobyBusID(int busID,
phosphor::nvme::Nvme::NVMeData& nvmeData);
/** @brief read and update NVME data to dbus */
void readNvmeData(NVMeConfig& config, bool isPwrGood);
private:
/** @brief sdbusplus bus client connection. */
sdbusplus::bus_t& bus;
/** @brief the Event Loop structure */
sdeventplus::Event _event;
/** @brief Read Timer */
sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _timer;
std::vector<phosphor::nvme::Nvme::NVMeConfig> configs;
/** @brief error status for Smbus */
std::unordered_map<int, bool> isErrorSmbus;
/** @brief error status for LED */
std::unordered_map<std::string, bool> isError;
/** @brief error status for NVMe power*/
std::unordered_map<std::string, bool> isErrorPower;
/** @brief Set up initial configuration value of NVMe */
void init();
/** @brief Monitor NVMe drives every one second */
void read();
std::vector<phosphor::nvme::Nvme::NVMeConfig> getNvmeConfig();
/** @brief Monitor interval in second */
size_t monitorIntervalSec;
/** @brief Maximum smbus error retry */
uint16_t maxSmbusErrorRetry;
/** @brief Map of each NVMe smbus error count */
std::unordered_map<int, uint16_t> nvmeSmbusErrCnt;
};
} // namespace nvme
} // namespace phosphor