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" |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 6 | #include "sdbusplus.hpp" |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 7 | |
| 8 | #include <fstream> |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 9 | #include <sdbusplus/bus.hpp> |
| 10 | #include <sdbusplus/server.hpp> |
| 11 | #include <sdbusplus/server/object.hpp> |
| 12 | #include <sdeventplus/clock.hpp> |
| 13 | #include <sdeventplus/event.hpp> |
| 14 | #include <sdeventplus/utility/timer.hpp> |
| 15 | |
| 16 | namespace phosphor |
| 17 | { |
| 18 | namespace nvme |
| 19 | { |
| 20 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 21 | /** @class Nvme |
| 22 | * @brief Nvme manager implementation. |
| 23 | */ |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 24 | class Nvme |
| 25 | { |
| 26 | public: |
| 27 | Nvme() = delete; |
| 28 | Nvme(const Nvme&) = delete; |
| 29 | Nvme& operator=(const Nvme&) = delete; |
| 30 | Nvme(Nvme&&) = delete; |
| 31 | Nvme& operator=(Nvme&&) = delete; |
| 32 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 33 | /** @brief Constructs Nvme |
| 34 | * |
| 35 | * @param[in] bus - Handle to system dbus |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 36 | * @param[in] objPath - The dbus path of nvme |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 37 | */ |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 38 | Nvme(sdbusplus::bus::bus& bus) : |
| 39 | bus(bus), _event(sdeventplus::Event::get_default()), |
| 40 | _timer(_event, std::bind(&Nvme::read, this)) |
| 41 | { |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 42 | // read json file |
| 43 | configs = getNvmeConfig(); |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 44 | } |
| 45 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 46 | /** |
| 47 | * Structure for keeping nvme configure data required by nvme monitoring |
| 48 | */ |
| 49 | struct NVMeConfig |
| 50 | { |
| 51 | std::string index; |
| 52 | uint8_t busID; |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 53 | std::string faultLedGroupPath; |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 54 | uint8_t presentPin; |
| 55 | uint8_t pwrGoodPin; |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 56 | std::string locateLedControllerBusName; |
| 57 | std::string locateLedControllerPath; |
| 58 | std::string locateLedGroupPath; |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 59 | int8_t criticalHigh; |
| 60 | int8_t criticalLow; |
| 61 | int8_t maxValue; |
| 62 | int8_t minValue; |
| 63 | int8_t warningHigh; |
| 64 | int8_t warningLow; |
| 65 | }; |
| 66 | |
| 67 | /** |
| 68 | * Structure for keeping nvme data required by nvme monitoring |
| 69 | */ |
| 70 | struct NVMeData |
| 71 | { |
| 72 | bool present; /* Whether or not the nvme is present */ |
| 73 | std::string vendor; /* The nvme manufacturer */ |
| 74 | std::string serialNumber; /* The nvme serial number */ |
| 75 | std::string smartWarnings; /* Indicates smart warnings for the state */ |
| 76 | std::string statusFlags; /* Indicates the status of the drives */ |
| 77 | std::string |
| 78 | driveLifeUsed; /* A vendor specific estimate of the percentage */ |
| 79 | int8_t sensorValue; /* Sensor value, if sensor value didn't be |
| 80 | update, means sensor failure, default set to |
| 81 | 129(0x81) accroding to NVMe-MI SPEC*/ |
| 82 | }; |
| 83 | |
| 84 | /** @brief Setup polling timer in a sd event loop and attach to D-Bus |
| 85 | * event loop. |
| 86 | */ |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 87 | void run(); |
| 88 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 89 | /** @brief Get GPIO value of nvme by sysfs */ |
| 90 | std::string getGPIOValueOfNvme(const std::string& fullPath); |
| 91 | /** @brief Map of the object NvmeSSD */ |
| 92 | std::unordered_map<std::string, std::shared_ptr<phosphor::nvme::NvmeSSD>> |
| 93 | nvmes; |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 94 | |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 95 | /** @brief Set locate and fault LED status of SSD |
| 96 | * |
| 97 | * @param[in] config - Nvme configure data |
| 98 | * @param[in] success - Success or not that get NVMe Info by SMbus |
| 99 | * @param[in] nvmeData - Nvme information |
| 100 | */ |
| 101 | void setLEDsStatus(const phosphor::nvme::Nvme::NVMeConfig& config, |
| 102 | bool success, |
| 103 | const phosphor::nvme::Nvme::NVMeData& nvmeData); |
| 104 | |
| 105 | /** @brief Set SSD fault LED status */ |
| 106 | void setFaultLED(const std::string& locateLedGroupPath, |
| 107 | const std::string& ledPath, bool request); |
| 108 | /** @brief Set SSD locate LED status */ |
| 109 | void setLocateLED(const std::string& ledPath, |
| 110 | const std::string& locateLedBusName, |
| 111 | const std::string& locateLedPath, bool ispresent); |
| 112 | /** @brief Get Identify State*/ |
| 113 | bool getLEDGroupState(const std::string& ledPath); |
| 114 | |
| 115 | /** @brief Set inventory properties of nvme */ |
| 116 | void setNvmeInventoryProperties( |
| 117 | bool present, const phosphor::nvme::Nvme::NVMeData& nvmeData, |
| 118 | const std::string& inventoryPath); |
| 119 | |
| 120 | void createNVMeInventory(); |
| 121 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 122 | private: |
| 123 | /** @brief sdbusplus bus client connection. */ |
| 124 | sdbusplus::bus::bus& bus; |
| 125 | /** @brief the Event Loop structure */ |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 126 | sdeventplus::Event _event; |
| 127 | /** @brief Read Timer */ |
| 128 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _timer; |
| 129 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 130 | std::vector<phosphor::nvme::Nvme::NVMeConfig> configs; |
| 131 | |
| 132 | /** @brief Set up initial configuration value of NVMe */ |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 133 | void init(); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 134 | /** @brief Monitor NVMe drives every one second */ |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 135 | void read(); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 136 | |
| 137 | std::vector<phosphor::nvme::Nvme::NVMeConfig> getNvmeConfig(); |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 138 | }; |
| 139 | } // namespace nvme |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 140 | } // namespace phosphor |