Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame^] | 5 | #include "nvmes.hpp" |
| 6 | |
| 7 | #include <fstream> |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 8 | #include <sdbusplus/bus.hpp> |
| 9 | #include <sdbusplus/server.hpp> |
| 10 | #include <sdbusplus/server/object.hpp> |
| 11 | #include <sdeventplus/clock.hpp> |
| 12 | #include <sdeventplus/event.hpp> |
| 13 | #include <sdeventplus/utility/timer.hpp> |
| 14 | |
| 15 | namespace phosphor |
| 16 | { |
| 17 | namespace nvme |
| 18 | { |
| 19 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame^] | 20 | /** @class Nvme |
| 21 | * @brief Nvme manager implementation. |
| 22 | */ |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 23 | class Nvme |
| 24 | { |
| 25 | public: |
| 26 | Nvme() = delete; |
| 27 | Nvme(const Nvme&) = delete; |
| 28 | Nvme& operator=(const Nvme&) = delete; |
| 29 | Nvme(Nvme&&) = delete; |
| 30 | Nvme& operator=(Nvme&&) = delete; |
| 31 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame^] | 32 | /** @brief Constructs Nvme |
| 33 | * |
| 34 | * @param[in] bus - Handle to system dbus |
| 35 | * @param[in] objPath - The Dbus path of nvme |
| 36 | */ |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 37 | Nvme(sdbusplus::bus::bus& bus) : |
| 38 | bus(bus), _event(sdeventplus::Event::get_default()), |
| 39 | _timer(_event, std::bind(&Nvme::read, this)) |
| 40 | { |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame^] | 41 | // read json file |
| 42 | configs = getNvmeConfig(); |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 43 | } |
| 44 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame^] | 45 | /** |
| 46 | * Structure for keeping nvme configure data required by nvme monitoring |
| 47 | */ |
| 48 | struct NVMeConfig |
| 49 | { |
| 50 | std::string index; |
| 51 | uint8_t busID; |
| 52 | uint8_t presentPin; |
| 53 | uint8_t pwrGoodPin; |
| 54 | int8_t criticalHigh; |
| 55 | int8_t criticalLow; |
| 56 | int8_t maxValue; |
| 57 | int8_t minValue; |
| 58 | int8_t warningHigh; |
| 59 | int8_t warningLow; |
| 60 | }; |
| 61 | |
| 62 | /** |
| 63 | * Structure for keeping nvme data required by nvme monitoring |
| 64 | */ |
| 65 | struct NVMeData |
| 66 | { |
| 67 | bool present; /* Whether or not the nvme is present */ |
| 68 | std::string vendor; /* The nvme manufacturer */ |
| 69 | std::string serialNumber; /* The nvme serial number */ |
| 70 | std::string smartWarnings; /* Indicates smart warnings for the state */ |
| 71 | std::string statusFlags; /* Indicates the status of the drives */ |
| 72 | std::string |
| 73 | driveLifeUsed; /* A vendor specific estimate of the percentage */ |
| 74 | int8_t sensorValue; /* Sensor value, if sensor value didn't be |
| 75 | update, means sensor failure, default set to |
| 76 | 129(0x81) accroding to NVMe-MI SPEC*/ |
| 77 | }; |
| 78 | |
| 79 | /** @brief Setup polling timer in a sd event loop and attach to D-Bus |
| 80 | * event loop. |
| 81 | */ |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 82 | void run(); |
| 83 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame^] | 84 | /** @brief Get GPIO value of nvme by sysfs */ |
| 85 | std::string getGPIOValueOfNvme(const std::string& fullPath); |
| 86 | /** @brief Map of the object NvmeSSD */ |
| 87 | std::unordered_map<std::string, std::shared_ptr<phosphor::nvme::NvmeSSD>> |
| 88 | nvmes; |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 89 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame^] | 90 | private: |
| 91 | /** @brief sdbusplus bus client connection. */ |
| 92 | sdbusplus::bus::bus& bus; |
| 93 | /** @brief the Event Loop structure */ |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 94 | sdeventplus::Event _event; |
| 95 | /** @brief Read Timer */ |
| 96 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _timer; |
| 97 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame^] | 98 | std::vector<phosphor::nvme::Nvme::NVMeConfig> configs; |
| 99 | |
| 100 | /** @brief Set up initial configuration value of NVMe */ |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 101 | void init(); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame^] | 102 | /** @brief Monitor NVMe drives every one second */ |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 103 | void read(); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame^] | 104 | |
| 105 | std::vector<phosphor::nvme::Nvme::NVMeConfig> getNvmeConfig(); |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 106 | }; |
| 107 | } // namespace nvme |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame^] | 108 | } // namespace phosphor |